diff --git a/src/plugins/coreplugin/documentmanager.cpp b/src/plugins/coreplugin/documentmanager.cpp index c62af65b3cb..067b4cfd5ae 100644 --- a/src/plugins/coreplugin/documentmanager.cpp +++ b/src/plugins/coreplugin/documentmanager.cpp @@ -152,8 +152,6 @@ struct DocumentManagerPrivate QList m_recentFiles; static const int m_maxRecentFiles = 7; - QString m_currentFile; - QFileSystemWatcher *m_fileWatcher; // Delayed creation. QFileSystemWatcher *m_linkWatcher; // Delayed creation (only UNIX/if a link is seen). bool m_blockActivated; @@ -878,8 +876,8 @@ QStringList DocumentManager::getOpenFileNames(const QString &filters, { QString path = pathIn; if (path.isEmpty()) { - if (!d->m_currentFile.isEmpty()) - path = QFileInfo(d->m_currentFile).absoluteFilePath(); + if (EditorManager::currentDocument() && !EditorManager::currentDocument()->isTemporary()) + path = EditorManager::currentDocument()->filePath().toString(); if (path.isEmpty() && useProjectsDirectory()) path = projectsDirectory(); } @@ -1242,34 +1240,6 @@ void readSettings() s->endGroup(); } -/*! - - The current file is the file currently opened when an editor is active, - or the selected file in case a Project Explorer is active. - - \sa currentFile - */ -void DocumentManager::setCurrentFile(const QString &filePath) -{ - if (d->m_currentFile == filePath) - return; - d->m_currentFile = filePath; - emit m_instance->currentFileChanged(d->m_currentFile); -} - -/*! - Returns the absolute path of the current file. - - The current file is the file currently opened when an editor is active, - or the selected file in case a Project Explorer is active. - - \sa setCurrentFile - */ -QString DocumentManager::currentFile() -{ - return d->m_currentFile; -} - /*! Returns the initial directory for a new file dialog. If there is @@ -1280,8 +1250,8 @@ QString DocumentManager::currentFile() QString DocumentManager::fileDialogInitialDirectory() { - if (!d->m_currentFile.isEmpty()) - return QFileInfo(d->m_currentFile).absolutePath(); + if (EditorManager::currentDocument() && !EditorManager::currentDocument()->isTemporary()) + return QFileInfo(EditorManager::currentDocument()->filePath().toString()).absolutePath(); return d->m_lastVisitedDirectory; } diff --git a/src/plugins/coreplugin/documentmanager.h b/src/plugins/coreplugin/documentmanager.h index 79c41a362bf..8fab9a05061 100644 --- a/src/plugins/coreplugin/documentmanager.h +++ b/src/plugins/coreplugin/documentmanager.h @@ -83,10 +83,6 @@ public: static void saveSettings(); - // current file - static void setCurrentFile(const QString &filePath); - static QString currentFile(); - // helper functions static QString fixFileName(const QString &fileName, FixMode fixmode); @@ -148,7 +144,6 @@ public slots: static void executeOpenWithMenuAction(QAction *action); signals: - void currentFileChanged(const QString &filePath); /* Used to notify e.g. the code model to update the given files. Does *not* lead to any editors to reload or any other editor manager actions. */ void filesChangedInternally(const QStringList &files); diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp index 8c5e79426da..766ecc175d4 100644 --- a/src/plugins/coreplugin/editormanager/editormanager.cpp +++ b/src/plugins/coreplugin/editormanager/editormanager.cpp @@ -1576,8 +1576,6 @@ void EditorManagerPrivate::handleContextChange(const QList &context) d->m_scheduledCurrentEditor = editor; QTimer::singleShot(0, d, SLOT(setCurrentEditorFromContextChange())); } else { - if (editor && !editor->document()->isTemporary()) - DocumentManager::setCurrentFile(editor->document()->filePath().toString()); updateActions(); } } @@ -1823,9 +1821,6 @@ void EditorManagerPrivate::setCurrentEditorFromContextChange() IEditor *newCurrent = d->m_scheduledCurrentEditor; d->m_scheduledCurrentEditor = 0; setCurrentEditor(newCurrent); - if (!newCurrent->document()->isTemporary()) - DocumentManager::setCurrentFile(newCurrent->document()->filePath().toString()); - } EditorView *EditorManagerPrivate::currentEditorView() diff --git a/src/plugins/projectexplorer/foldernavigationwidget.cpp b/src/plugins/projectexplorer/foldernavigationwidget.cpp index 9b440eb6986..ba733d3004b 100644 --- a/src/plugins/projectexplorer/foldernavigationwidget.cpp +++ b/src/plugins/projectexplorer/foldernavigationwidget.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -199,17 +200,18 @@ void FolderNavigationWidget::setAutoSynchronization(bool sync) m_autoSync = sync; if (m_autoSync) { - connect(Core::DocumentManager::instance(), SIGNAL(currentFileChanged(QString)), - this, SLOT(setCurrentFile(QString))); - setCurrentFile(Core::DocumentManager::currentFile()); + connect(Core::EditorManager::instance(), &Core::EditorManager::currentEditorChanged, + this, &FolderNavigationWidget::setCurrentFile); + setCurrentFile(Core::EditorManager::currentEditor()); } else { - disconnect(Core::DocumentManager::instance(), SIGNAL(currentFileChanged(QString)), - this, SLOT(setCurrentFile(QString))); + disconnect(Core::EditorManager::instance(), &Core::EditorManager::currentEditorChanged, + this, &FolderNavigationWidget::setCurrentFile); } } -void FolderNavigationWidget::setCurrentFile(const QString &filePath) +void FolderNavigationWidget::setCurrentFile(Core::IEditor *editor) { + const QString filePath = editor->document()->filePath().toString(); // Try to find directory of current file bool pathOpened = false; if (!filePath.isEmpty()) { diff --git a/src/plugins/projectexplorer/foldernavigationwidget.h b/src/plugins/projectexplorer/foldernavigationwidget.h index b499477cb31..42618e0b45f 100644 --- a/src/plugins/projectexplorer/foldernavigationwidget.h +++ b/src/plugins/projectexplorer/foldernavigationwidget.h @@ -36,6 +36,7 @@ #include namespace Utils { class ListView; } +namespace Core { class IEditor; } QT_BEGIN_NAMESPACE class QLabel; @@ -63,7 +64,7 @@ public slots: void toggleAutoSynchronization(); private slots: - void setCurrentFile(const QString &filePath); + void setCurrentFile(Core::IEditor *editor); void slotOpenItem(const QModelIndex &viewIndex); void setHiddenFilesFilter(bool filter); void ensureCurrentIndex(); diff --git a/src/plugins/projectexplorer/projecttree.cpp b/src/plugins/projectexplorer/projecttree.cpp index 3d09c34799a..53210312c77 100644 --- a/src/plugins/projectexplorer/projecttree.cpp +++ b/src/plugins/projectexplorer/projecttree.cpp @@ -36,7 +36,6 @@ #include "projectexplorerconstants.h" #include -#include #include #include #include @@ -68,7 +67,7 @@ ProjectTree::ProjectTree(QObject *parent) { s_instance = this; - connect(Core::DocumentManager::instance(), &Core::DocumentManager::currentFileChanged, + connect(Core::EditorManager::instance(), &Core::EditorManager::currentEditorChanged, this, &ProjectTree::documentManagerCurrentFileChanged); connect(qApp, &QApplication::focusChanged, @@ -167,7 +166,8 @@ Project *ProjectTree::projectForNode(Node *node) void ProjectTree::updateFromDocumentManager(bool invalidCurrentNode) { - const QString &fileName = Core::DocumentManager::currentFile(); + Core::IDocument *document = Core::EditorManager::currentDocument(); + const QString &fileName = document ? document->filePath().toString() : QString(); Node *currentNode = 0; if (!invalidCurrentNode && m_currentNode && m_currentNode->path() == fileName) diff --git a/src/plugins/projectexplorer/projecttreewidget.cpp b/src/plugins/projectexplorer/projecttreewidget.cpp index 17eaef1b44d..8dc5afe33db 100644 --- a/src/plugins/projectexplorer/projecttreewidget.cpp +++ b/src/plugins/projectexplorer/projecttreewidget.cpp @@ -335,7 +335,9 @@ void ProjectTreeWidget::setAutoSynchronization(bool sync) if (m_autoSync) { // sync from document manager - const QString &fileName = Core::DocumentManager::currentFile(); + QString fileName; + if (IDocument *doc = EditorManager::currentDocument()) + fileName = doc->filePath().toString(); if (!currentNode() || currentNode()->path() != fileName) setCurrentItem(ProjectTreeWidget::nodeForFile(fileName)); }