Remove DocumentManager::currentFile, use DocumentManager::currentEditor

Change-Id: Ided1a14481cfbbcc49e901f3837e056582ff60e3
Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
This commit is contained in:
Daniel Teske
2015-01-16 17:45:06 +01:00
parent a6ea380870
commit 1ed12d39f1
7 changed files with 20 additions and 55 deletions

View File

@@ -152,8 +152,6 @@ struct DocumentManagerPrivate
QList<DocumentManager::RecentFile> m_recentFiles; QList<DocumentManager::RecentFile> m_recentFiles;
static const int m_maxRecentFiles = 7; static const int m_maxRecentFiles = 7;
QString m_currentFile;
QFileSystemWatcher *m_fileWatcher; // Delayed creation. QFileSystemWatcher *m_fileWatcher; // Delayed creation.
QFileSystemWatcher *m_linkWatcher; // Delayed creation (only UNIX/if a link is seen). QFileSystemWatcher *m_linkWatcher; // Delayed creation (only UNIX/if a link is seen).
bool m_blockActivated; bool m_blockActivated;
@@ -878,8 +876,8 @@ QStringList DocumentManager::getOpenFileNames(const QString &filters,
{ {
QString path = pathIn; QString path = pathIn;
if (path.isEmpty()) { if (path.isEmpty()) {
if (!d->m_currentFile.isEmpty()) if (EditorManager::currentDocument() && !EditorManager::currentDocument()->isTemporary())
path = QFileInfo(d->m_currentFile).absoluteFilePath(); path = EditorManager::currentDocument()->filePath().toString();
if (path.isEmpty() && useProjectsDirectory()) if (path.isEmpty() && useProjectsDirectory())
path = projectsDirectory(); path = projectsDirectory();
} }
@@ -1242,34 +1240,6 @@ void readSettings()
s->endGroup(); 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 Returns the initial directory for a new file dialog. If there is
@@ -1280,8 +1250,8 @@ QString DocumentManager::currentFile()
QString DocumentManager::fileDialogInitialDirectory() QString DocumentManager::fileDialogInitialDirectory()
{ {
if (!d->m_currentFile.isEmpty()) if (EditorManager::currentDocument() && !EditorManager::currentDocument()->isTemporary())
return QFileInfo(d->m_currentFile).absolutePath(); return QFileInfo(EditorManager::currentDocument()->filePath().toString()).absolutePath();
return d->m_lastVisitedDirectory; return d->m_lastVisitedDirectory;
} }

View File

@@ -83,10 +83,6 @@ public:
static void saveSettings(); static void saveSettings();
// current file
static void setCurrentFile(const QString &filePath);
static QString currentFile();
// helper functions // helper functions
static QString fixFileName(const QString &fileName, FixMode fixmode); static QString fixFileName(const QString &fileName, FixMode fixmode);
@@ -148,7 +144,6 @@ public slots:
static void executeOpenWithMenuAction(QAction *action); static void executeOpenWithMenuAction(QAction *action);
signals: signals:
void currentFileChanged(const QString &filePath);
/* Used to notify e.g. the code model to update the given files. Does *not* /* 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. */ lead to any editors to reload or any other editor manager actions. */
void filesChangedInternally(const QStringList &files); void filesChangedInternally(const QStringList &files);

View File

@@ -1576,8 +1576,6 @@ void EditorManagerPrivate::handleContextChange(const QList<IContext *> &context)
d->m_scheduledCurrentEditor = editor; d->m_scheduledCurrentEditor = editor;
QTimer::singleShot(0, d, SLOT(setCurrentEditorFromContextChange())); QTimer::singleShot(0, d, SLOT(setCurrentEditorFromContextChange()));
} else { } else {
if (editor && !editor->document()->isTemporary())
DocumentManager::setCurrentFile(editor->document()->filePath().toString());
updateActions(); updateActions();
} }
} }
@@ -1823,9 +1821,6 @@ void EditorManagerPrivate::setCurrentEditorFromContextChange()
IEditor *newCurrent = d->m_scheduledCurrentEditor; IEditor *newCurrent = d->m_scheduledCurrentEditor;
d->m_scheduledCurrentEditor = 0; d->m_scheduledCurrentEditor = 0;
setCurrentEditor(newCurrent); setCurrentEditor(newCurrent);
if (!newCurrent->document()->isTemporary())
DocumentManager::setCurrentFile(newCurrent->document()->filePath().toString());
} }
EditorView *EditorManagerPrivate::currentEditorView() EditorView *EditorManagerPrivate::currentEditorView()

View File

@@ -38,6 +38,7 @@
#include <coreplugin/fileiconprovider.h> #include <coreplugin/fileiconprovider.h>
#include <coreplugin/documentmanager.h> #include <coreplugin/documentmanager.h>
#include <coreplugin/editormanager/editormanager.h> #include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/ieditor.h>
#include <coreplugin/coreconstants.h> #include <coreplugin/coreconstants.h>
#include <coreplugin/fileutils.h> #include <coreplugin/fileutils.h>
#include <coreplugin/find/findplugin.h> #include <coreplugin/find/findplugin.h>
@@ -199,17 +200,18 @@ void FolderNavigationWidget::setAutoSynchronization(bool sync)
m_autoSync = sync; m_autoSync = sync;
if (m_autoSync) { if (m_autoSync) {
connect(Core::DocumentManager::instance(), SIGNAL(currentFileChanged(QString)), connect(Core::EditorManager::instance(), &Core::EditorManager::currentEditorChanged,
this, SLOT(setCurrentFile(QString))); this, &FolderNavigationWidget::setCurrentFile);
setCurrentFile(Core::DocumentManager::currentFile()); setCurrentFile(Core::EditorManager::currentEditor());
} else { } else {
disconnect(Core::DocumentManager::instance(), SIGNAL(currentFileChanged(QString)), disconnect(Core::EditorManager::instance(), &Core::EditorManager::currentEditorChanged,
this, SLOT(setCurrentFile(QString))); 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 // Try to find directory of current file
bool pathOpened = false; bool pathOpened = false;
if (!filePath.isEmpty()) { if (!filePath.isEmpty()) {

View File

@@ -36,6 +36,7 @@
#include <QWidget> #include <QWidget>
namespace Utils { class ListView; } namespace Utils { class ListView; }
namespace Core { class IEditor; }
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QLabel; class QLabel;
@@ -63,7 +64,7 @@ public slots:
void toggleAutoSynchronization(); void toggleAutoSynchronization();
private slots: private slots:
void setCurrentFile(const QString &filePath); void setCurrentFile(Core::IEditor *editor);
void slotOpenItem(const QModelIndex &viewIndex); void slotOpenItem(const QModelIndex &viewIndex);
void setHiddenFilesFilter(bool filter); void setHiddenFilesFilter(bool filter);
void ensureCurrentIndex(); void ensureCurrentIndex();

View File

@@ -36,7 +36,6 @@
#include "projectexplorerconstants.h" #include "projectexplorerconstants.h"
#include <utils/algorithm.h> #include <utils/algorithm.h>
#include <coreplugin/documentmanager.h>
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/editormanager/ieditor.h> #include <coreplugin/editormanager/ieditor.h>
#include <coreplugin/editormanager/editormanager.h> #include <coreplugin/editormanager/editormanager.h>
@@ -68,7 +67,7 @@ ProjectTree::ProjectTree(QObject *parent)
{ {
s_instance = this; s_instance = this;
connect(Core::DocumentManager::instance(), &Core::DocumentManager::currentFileChanged, connect(Core::EditorManager::instance(), &Core::EditorManager::currentEditorChanged,
this, &ProjectTree::documentManagerCurrentFileChanged); this, &ProjectTree::documentManagerCurrentFileChanged);
connect(qApp, &QApplication::focusChanged, connect(qApp, &QApplication::focusChanged,
@@ -167,7 +166,8 @@ Project *ProjectTree::projectForNode(Node *node)
void ProjectTree::updateFromDocumentManager(bool invalidCurrentNode) 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; Node *currentNode = 0;
if (!invalidCurrentNode && m_currentNode && m_currentNode->path() == fileName) if (!invalidCurrentNode && m_currentNode && m_currentNode->path() == fileName)

View File

@@ -335,7 +335,9 @@ void ProjectTreeWidget::setAutoSynchronization(bool sync)
if (m_autoSync) { if (m_autoSync) {
// sync from document manager // 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) if (!currentNode() || currentNode()->path() != fileName)
setCurrentItem(ProjectTreeWidget::nodeForFile(fileName)); setCurrentItem(ProjectTreeWidget::nodeForFile(fileName));
} }