summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Cullmann <cullmann@kde.org>2014-01-24 11:00:28 (GMT)
committerChristoph Cullmann <cullmann@kde.org>2014-01-24 11:00:28 (GMT)
commit9b959ab779e2d329b833cde75aecc9241aa71581 (patch)
tree01c9a8c8c129ed1eeb19ad041a15e05b9da2fb43
parent16fa75486ea35e023085652020da80cc5233e723 (diff)
start to cleanup the view activation mess, less direct function calls, more relying on the signals we have anyway
-rw-r--r--kate/src/katedocmanager.cpp71
-rw-r--r--kate/src/katedocmanager.h2
-rw-r--r--kate/src/kateviewmanager.cpp128
-rw-r--r--kate/src/kateviewmanager.h26
4 files changed, 104 insertions, 123 deletions
diff --git a/kate/src/katedocmanager.cpp b/kate/src/katedocmanager.cpp
index aaaf454..1de05ad 100644
--- a/kate/src/katedocmanager.cpp
+++ b/kate/src/katedocmanager.cpp
@@ -230,7 +230,7 @@ KTextEditor::Document *KateDocManager::openUrl(const QUrl &url, const QString &e
return doc;
}
-bool KateDocManager::closeDocuments(const QList<KTextEditor::Document *> &documents, bool closeUrl)
+bool KateDocManager::closeDocuments(const QList<KTextEditor::Document *> documents, bool closeUrl)
{
if (documents.isEmpty()) {
return false;
@@ -241,13 +241,11 @@ bool KateDocManager::closeDocuments(const QList<KTextEditor::Document *> &docume
emit aboutToDeleteDocuments(documents);
int last = 0;
+ bool success = true;
foreach(KTextEditor::Document * doc, documents) {
if (closeUrl && !doc->closeUrl()) {
- return false; // get out on first error
- }
-
- for (int i = 0; i < KateApp::self()->mainWindowsCount(); i++) {
- KateApp::self()->mainWindow(i)->viewManager()->closeViews(doc);
+ success = false; // get out on first error
+ break;
}
if (closeUrl && m_tempFiles.contains(doc)) {
@@ -277,7 +275,7 @@ bool KateDocManager::closeDocuments(const QList<KTextEditor::Document *> &docume
createDoc();
}
- return true;
+ return success;
}
bool KateDocManager::closeDocument(KTextEditor::Document *doc, bool closeUrl)
@@ -294,12 +292,6 @@ bool KateDocManager::closeDocument(KTextEditor::Document *doc, bool closeUrl)
bool KateDocManager::closeDocumentList(QList<KTextEditor::Document *> documents)
{
- bool res = true;
-
- for (int i = 0; i < KateApp::self()->mainWindowsCount(); i++) {
- KateApp::self()->mainWindow(i)->viewManager()->setViewActivationBlocked(true);
- }
-
QList<KTextEditor::Document *> modifiedDocuments;
foreach(KTextEditor::Document * document, documents) {
if (document->isModified()) {
@@ -311,60 +303,25 @@ bool KateDocManager::closeDocumentList(QList<KTextEditor::Document *> documents)
return false;
}
- res = closeDocuments(documents, false); // Do not show save/discard dialog
-
- for (int i = 0; i < KateApp::self()->mainWindowsCount(); i++) {
- KateApp::self()->mainWindow(i)->viewManager()->setViewActivationBlocked(false);
- if (!KateApp::self()->mainWindow(i)->viewManager()->activeView()) {
- KateApp::self()->mainWindow(i)->viewManager()->activateView(m_docList.at(0));
- } else {
- KateApp::self()->mainWindow(i)->viewManager()->reactivateActiveView();
- }
- }
-
- return res;
+ return closeDocuments(documents, false); // Do not show save/discard dialog
}
bool KateDocManager::closeAllDocuments(bool closeUrl)
{
- bool res = true;
-
- QList<KTextEditor::Document *> docs = m_docList;
-
- for (int i = 0; i < KateApp::self()->mainWindowsCount(); i++) {
- KateApp::self()->mainWindow(i)->viewManager()->setViewActivationBlocked(true);
- }
-
- res = closeDocuments(docs, closeUrl);
-
- for (int i = 0; i < KateApp::self()->mainWindowsCount(); i++) {
- KateApp::self()->mainWindow(i)->viewManager()->setViewActivationBlocked(false);
- KateApp::self()->mainWindow(i)->viewManager()->activateView(m_docList.at(0));
- }
-
- return res;
+ /**
+ * just close all documents
+ */
+ return closeDocuments(m_docList, closeUrl);
}
bool KateDocManager::closeOtherDocuments(KTextEditor::Document *doc)
{
- bool res = true;
-
+ /**
+ * close all documents beside the passed one
+ */
QList<KTextEditor::Document *> documents = m_docList;
-
- for (int i = 0; i < KateApp::self()->mainWindowsCount(); i++) {
- KateApp::self()->mainWindow(i)->viewManager()->setViewActivationBlocked(true);
- }
-
documents.removeOne(doc);
-
- res = closeDocuments(documents);
-
- for (int i = 0; i < KateApp::self()->mainWindowsCount(); i++) {
- KateApp::self()->mainWindow(i)->viewManager()->setViewActivationBlocked(false);
- KateApp::self()->mainWindow(i)->viewManager()->activateView(m_docList.at(0));
- }
-
- return res;
+ return closeDocuments(documents);
}
/**
diff --git a/kate/src/katedocmanager.h b/kate/src/katedocmanager.h
index d1256e1..45a9b07 100644
--- a/kate/src/katedocmanager.h
+++ b/kate/src/katedocmanager.h
@@ -89,7 +89,7 @@ public:
const KateDocumentInfo &docInfo = KateDocumentInfo());
bool closeDocument(KTextEditor::Document *, bool closeUrl = true);
- bool closeDocuments(const QList<KTextEditor::Document *> &documents, bool closeUrl = true);
+ bool closeDocuments(const QList<KTextEditor::Document *> documents, bool closeUrl = true);
bool closeDocumentList(QList<KTextEditor::Document *> documents);
bool closeAllDocuments(bool closeUrl = true);
bool closeOtherDocuments(KTextEditor::Document *);
diff --git a/kate/src/kateviewmanager.cpp b/kate/src/kateviewmanager.cpp
index a915d4a..0559d10 100644
--- a/kate/src/kateviewmanager.cpp
+++ b/kate/src/kateviewmanager.cpp
@@ -50,12 +50,6 @@
#include <kactivities/resourceinstance.h>
#endif
-#include <QApplication>
-#include <QObject>
-#include <QFileInfo>
-#include <QToolButton>
-#include <QTimer>
-#include <QMenu>
#include <QStyle>
//END Includes
@@ -89,13 +83,31 @@ KateViewManager::KateViewManager(QWidget *parentW, KateMainWindow *parent)
connect(this, SIGNAL(viewChanged(KTextEditor::View*)), this, SLOT(slotViewChanged()));
connect(KateApp::self()->documentManager(), SIGNAL(documentCreatedViewManager(KTextEditor::Document*)), this, SLOT(documentCreated(KTextEditor::Document*)));
- connect(KateApp::self()->documentManager(), SIGNAL(documentDeleted(KTextEditor::Document*)), this, SLOT(documentDeleted(KTextEditor::Document*)));
-
+
+ /**
+ * before document is really deleted: cleanup all views!
+ */
+ connect(KateApp::self()->documentManager(), SIGNAL(documentWillBeDeleted(KTextEditor::Document*))
+ , this, SLOT(documentWillBeDeleted(KTextEditor::Document*)));
+
+ /**
+ * handle document deletion transactions
+ * disable view creation in between
+ * afterwards ensure we have views ;)
+ */
+ connect(KateApp::self()->documentManager(), SIGNAL(aboutToDeleteDocuments(const QList<KTextEditor::Document *> &))
+ , this, SLOT(aboutToDeleteDocuments(const QList<KTextEditor::Document *> &)));
+ connect(KateApp::self()->documentManager(), SIGNAL(documentsDeleted(const QList<KTextEditor::Document *> &))
+ , this, SLOT(documentsDeleted(const QList<KTextEditor::Document *> &)));
+
// register all already existing documents
m_blockViewCreationAndActivation = true;
+
const QList<KTextEditor::Document *> &docs = KateApp::self()->documentManager()->documentList();
- foreach(KTextEditor::Document * doc, docs)
- documentCreated(doc);
+ foreach(KTextEditor::Document * doc, docs) {
+ documentCreated(doc);
+ }
+
m_blockViewCreationAndActivation = false;
// init done
@@ -210,11 +222,6 @@ void KateViewManager::updateViewSpaceActions()
goPrev->setEnabled(viewSpaceCount() > 1);
}
-void KateViewManager::setViewActivationBlocked(bool block)
-{
- m_blockViewCreationAndActivation = block;
-}
-
void KateViewManager::slotDocumentNew()
{
createView();
@@ -367,17 +374,52 @@ void KateViewManager::documentCreated(KTextEditor::Document *doc)
}
}
-void KateViewManager::documentDeleted(KTextEditor::Document *)
+void KateViewManager::aboutToDeleteDocuments(const QList<KTextEditor::Document *> &)
{
- if (m_blockViewCreationAndActivation) {
- return;
- }
+ /**
+ * block view creation until the transaction is done
+ * this shall not stack!
+ */
+ Q_ASSERT (!m_blockViewCreationAndActivation);
+ m_blockViewCreationAndActivation = true;
+
+ /**
+ * disable updates hard (we can't use KateUpdateDisabler here, we have delayed signal
+ */
+ mainWindow()->setUpdatesEnabled(false);
+}
- // just for the case we close a document out of many and this was the active one
- // if all docs are closed, this will be handled by the documentCreated
+void KateViewManager::documentsDeleted(const QList<KTextEditor::Document *> &)
+{
+ /**
+ * again allow view creation
+ */
+ m_blockViewCreationAndActivation = false;
+
+ /**
+ * try to have active view around!
+ */
if (!activeView() && !KateApp::self()->documentManager()->documentList().isEmpty()) {
createView(KateApp::self()->documentManager()->documentList().last());
}
+
+ KTextEditor::View *const newActiveView = activeView();
+
+ /**
+ * check if we have any empty viewspaces and give them a view
+ */
+ Q_FOREACH(KateViewSpace * vs, m_viewSpaceList) {
+ if (!vs->currentView()) {
+ createView(newActiveView->document(), vs);
+ }
+ }
+
+ emit viewChanged(newActiveView);
+
+ /**
+ * enable updates hard (we can't use KateUpdateDisabler here, we have delayed signal
+ */
+ mainWindow()->setUpdatesEnabled(true);
}
void KateViewManager::documentSavedOrUploaded(KTextEditor::Document *doc, bool)
@@ -669,51 +711,21 @@ void KateViewManager::activatePrevView()
activateView(m_viewSpaceList.at(i)->currentView());
}
-void KateViewManager::closeViews(KTextEditor::Document *doc)
+void KateViewManager::documentWillBeDeleted(KTextEditor::Document *doc)
{
+ /**
+ * collect all views of that document that belong to this manager
+ */
QList<KTextEditor::View *> closeList;
- QHashIterator<KTextEditor::View *, QPair<bool, qint64> > it(m_views);
- while (it.hasNext()) {
- it.next();
- if (it.key()->document() == doc) {
- closeList.append(it.key());
+ Q_FOREACH (KTextEditor::View *v, doc->views()) {
+ if (m_views.contains(v)) {
+ closeList.append(v);
}
}
while (!closeList.isEmpty()) {
deleteView(closeList.takeFirst());
}
-
- if (m_blockViewCreationAndActivation) {
- return;
- }
-
- /**
- * disable updates hard (we can't use KateUpdateDisabler here, we have delayed signal
- */
- mainWindow()->setUpdatesEnabled(false);
- QTimer::singleShot(0, this, SLOT(slotDelayedViewChanged()));
-}
-
-void KateViewManager::slotDelayedViewChanged()
-{
- KTextEditor::View *const newActiveView = activeView();
-
- /**
- * check if we have any empty viewspaces and give them a view
- */
- Q_FOREACH(KateViewSpace * vs, m_viewSpaceList) {
- if (!vs->currentView()) {
- createView(newActiveView->document(), vs);
- }
- }
-
- emit viewChanged(newActiveView);
-
- /**
- * enable updates hard (we can't use KateUpdateDisabler here, we have delayed signal
- */
- mainWindow()->setUpdatesEnabled(true);
}
void KateViewManager::splitViewSpace(KateViewSpace *vs, // = 0
diff --git a/kate/src/kateviewmanager.h b/kate/src/kateviewmanager.h
index 5316733..d17004e 100644
--- a/kate/src/kateviewmanager.h
+++ b/kate/src/kateviewmanager.h
@@ -86,17 +86,11 @@ public Q_SLOTS:
void openUrl(const QUrl &url);
public:
-
- void setViewActivationBlocked(bool block);
-
-public:
- void closeViews(KTextEditor::Document *doc);
KateMainWindow *mainWindow();
private Q_SLOTS:
void activateView(KTextEditor::View *view);
void activateSpace(KTextEditor::View *v);
- void slotDelayedViewChanged();
public Q_SLOTS:
void slotDocumentNew();
@@ -158,10 +152,28 @@ private Q_SLOTS:
void slotViewChanged();
void documentCreated(KTextEditor::Document *doc);
- void documentDeleted(KTextEditor::Document *doc);
+ void documentWillBeDeleted(KTextEditor::Document *doc);
void documentSavedOrUploaded(KTextEditor::Document *document, bool saveAs);
+ /**
+ * This signal is emitted before the documents batch is going to be deleted
+ *
+ * note that the batch can be interupted in the middle and only some
+ * of the documents may be actually deleted. See documentsDeleted() signal.
+ *
+ * @param documents documents we want to delete, may not be deleted
+ */
+ void aboutToDeleteDocuments(const QList<KTextEditor::Document *> &documents);
+
+ /**
+ * This singnal is emitted after the documents batch was deleted
+ *
+ * This is the batch closing signal for aboutToDeleteDocuments
+ * @param documents the documents that weren't deleted after all
+ */
+ void documentsDeleted(const QList<KTextEditor::Document *> &documents);
+
public Q_SLOTS:
/**
* Splits a KateViewSpace into two in the following steps: