summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@digia.com>2014-07-23 15:36:55 +0200
committerEike Ziller <eike.ziller@digia.com>2014-08-13 15:47:58 +0200
commit49a8cf44daa965d421466fb9c922b08594658e2d (patch)
tree85af246435cd46478b15cb25e17785578b442003
parent2a9a014c9d78b902da6332f081b37a830bb0541d (diff)
downloadqt-creator-49a8cf44daa965d421466fb9c922b08594658e2d.tar.gz
Editors: Set window title for external editor windows
Change-Id: I54ed77c0f1b2122ae8833109d8dcac7d8eec7ac4 Task-number: QTCREATORBUG-9612 Reviewed-by: Daniel Teske <daniel.teske@digia.com>
-rw-r--r--src/plugins/coreplugin/editormanager/editorarea.cpp73
-rw-r--r--src/plugins/coreplugin/editormanager/editorarea.h13
-rw-r--r--src/plugins/coreplugin/editormanager/editormanager.cpp99
-rw-r--r--src/plugins/coreplugin/editormanager/editormanager.h11
-rw-r--r--src/plugins/coreplugin/editormanager/editormanager_p.h8
-rw-r--r--src/plugins/coreplugin/editormanager/editorview.cpp2
-rw-r--r--src/plugins/coreplugin/editormanager/editorview.h3
-rw-r--r--src/plugins/coreplugin/editormanager/editorwindow.cpp10
-rw-r--r--src/plugins/coreplugin/editormanager/editorwindow.h2
-rw-r--r--src/plugins/projectexplorer/session.cpp51
-rw-r--r--src/plugins/projectexplorer/session.h1
-rw-r--r--src/plugins/vcsbase/vcsbaseplugin.cpp30
12 files changed, 227 insertions, 76 deletions
diff --git a/src/plugins/coreplugin/editormanager/editorarea.cpp b/src/plugins/coreplugin/editormanager/editorarea.cpp
index 54c9f8b21f..b5f8956a44 100644
--- a/src/plugins/coreplugin/editormanager/editorarea.cpp
+++ b/src/plugins/coreplugin/editormanager/editorarea.cpp
@@ -29,26 +29,99 @@
#include "editorarea.h"
+#include "editormanager.h"
+#include "ieditor.h"
+
#include <coreplugin/coreconstants.h>
#include <coreplugin/icontext.h>
#include <coreplugin/icore.h>
+#include <utils/qtcassert.h>
+
+#include <QApplication>
namespace Core {
namespace Internal {
EditorArea::EditorArea()
+ : m_currentView(0),
+ m_currentDocument(0)
{
m_context = new IContext;
m_context->setContext(Context(Constants::C_EDITORMANAGER));
m_context->setWidget(this);
ICore::addContextObject(m_context);
+
+ setCurrentView(view());
+
+ connect(qApp, &QApplication::focusChanged,
+ this, &EditorArea::focusChanged);
}
EditorArea::~EditorArea()
{
+ // disconnect
+ setCurrentView(0);
+ disconnect(qApp, &QApplication::focusChanged,
+ this, &EditorArea::focusChanged);
+
ICore::removeContextObject(m_context);
delete m_context;
}
+IDocument *EditorArea::currentDocument() const
+{
+ return m_currentDocument;
+}
+
+void EditorArea::focusChanged(QWidget *old, QWidget *now)
+{
+ Q_UNUSED(old)
+ // only interesting if the focus moved within the editor area
+ if (!focusWidget() || focusWidget() != now)
+ return;
+ // find the view with focus
+ EditorView *current = findFirstView();
+ while (current) {
+ if (current->focusWidget() && current->focusWidget() == now) {
+ setCurrentView(current);
+ break;
+ }
+ current = current->findNextView();
+ }
+}
+
+void EditorArea::setCurrentView(EditorView *view)
+{
+ if (view == m_currentView)
+ return;
+ if (m_currentView) {
+ disconnect(m_currentView.data(), &EditorView::currentEditorChanged,
+ this, &EditorArea::updateCurrentEditor);
+ }
+ m_currentView = view;
+ if (m_currentView) {
+ connect(m_currentView.data(), &EditorView::currentEditorChanged,
+ this, &EditorArea::updateCurrentEditor);
+ }
+ updateCurrentEditor(m_currentView ? m_currentView->currentEditor() : 0);
+}
+
+void EditorArea::updateCurrentEditor(IEditor *editor)
+{
+ IDocument *document = editor ? editor->document() : 0;
+ if (document == m_currentDocument)
+ return;
+ if (m_currentDocument) {
+ disconnect(m_currentDocument.data(), &IDocument::changed,
+ this, &EditorArea::windowTitleNeedsUpdate);
+ }
+ m_currentDocument = document;
+ if (m_currentDocument) {
+ connect(m_currentDocument.data(), &IDocument::changed,
+ this, &EditorArea::windowTitleNeedsUpdate);
+ }
+ emit windowTitleNeedsUpdate();
+}
+
} // Internal
} // Core
diff --git a/src/plugins/coreplugin/editormanager/editorarea.h b/src/plugins/coreplugin/editormanager/editorarea.h
index 0bdffbfb69..2c9d2e04f9 100644
--- a/src/plugins/coreplugin/editormanager/editorarea.h
+++ b/src/plugins/coreplugin/editormanager/editorarea.h
@@ -32,6 +32,8 @@
#include "editorview.h"
+#include <QPointer>
+
namespace Core {
class IContext;
@@ -46,8 +48,19 @@ public:
EditorArea();
~EditorArea();
+ IDocument *currentDocument() const;
+
+signals:
+ void windowTitleNeedsUpdate();
+
private:
+ void focusChanged(QWidget *old, QWidget *now);
+ void setCurrentView(EditorView *view);
+ void updateCurrentEditor(IEditor *editor);
+
IContext *m_context;
+ QPointer<EditorView> m_currentView;
+ QPointer<IDocument> m_currentDocument;
};
} // Internal
diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp
index afffbd9f55..9e5d7715ef 100644
--- a/src/plugins/coreplugin/editormanager/editormanager.cpp
+++ b/src/plugins/coreplugin/editormanager/editormanager.cpp
@@ -451,6 +451,8 @@ void EditorManagerPrivate::init()
// other setup
auto mainEditorArea = new EditorArea();
mainEditorArea->hide();
+ connect(mainEditorArea, &EditorArea::windowTitleNeedsUpdate,
+ this, &EditorManagerPrivate::updateWindowTitle);
connect(mainEditorArea, SIGNAL(destroyed(QObject*)), this, SLOT(editorAreaDestroyed(QObject*)));
d->m_editorAreas.append(mainEditorArea);
d->m_currentView = mainEditorArea->view();
@@ -491,7 +493,7 @@ void EditorManagerPrivate::init()
});
}
-QWidget *EditorManagerPrivate::mainEditorArea()
+EditorArea *EditorManagerPrivate::mainEditorArea()
{
return d->m_editorAreas.at(0);
}
@@ -1065,7 +1067,6 @@ void EditorManagerPrivate::setCurrentEditor(IEditor *editor, bool ignoreNavigati
EditorView::updateEditorHistory(editor, d->m_globalHistory);
}
updateActions();
- updateWindowTitle();
emit m_instance->currentEditorChanged(editor);
}
@@ -1297,13 +1298,8 @@ void EditorManagerPrivate::updateActions()
IDocument *curDocument = EditorManager::currentDocument();
const int openedCount = DocumentModel::entryCount();
- if (curDocument) {
- if (HostOsInfo::isMacHost())
- mainEditorArea()->window()->setWindowModified(curDocument->isModified());
+ if (curDocument)
updateMakeWritableWarning();
- } else /* curEditor */ if (HostOsInfo::isMacHost()) {
- mainEditorArea()->window()->setWindowModified(false);
- }
foreach (EditorArea *area, d->m_editorAreas)
setCloseSplitEnabled(area, area->isSplitter());
@@ -1335,32 +1331,53 @@ void EditorManagerPrivate::updateActions()
d->m_gotoNextSplitAction->setEnabled(hasSplitter || d->m_editorAreas.size() > 1);
}
-void EditorManagerPrivate::updateWindowTitle()
+void EditorManagerPrivate::updateWindowTitleForDocument(IDocument *document, QWidget *window)
{
- QString windowTitle = tr("Qt Creator");
+ QTC_ASSERT(window, return);
+ QString windowTitle;
const QString dashSep = QLatin1String(" - ");
- QString vcsTopic;
- IDocument *document = EditorManager::currentDocument();
- if (!d->m_titleVcsTopic.isEmpty())
- vcsTopic = QLatin1String(" [") + d->m_titleVcsTopic + QLatin1Char(']');
- if (!d->m_titleAddition.isEmpty()) {
- windowTitle.prepend(dashSep);
- if (!document)
- windowTitle.prepend(vcsTopic);
- windowTitle.prepend(d->m_titleAddition);
- }
- if (document) {
- const QString documentName = document->displayName();
- if (!documentName.isEmpty())
- windowTitle.prepend(documentName + vcsTopic + dashSep);
- QString filePath = QFileInfo(document->filePath()).absoluteFilePath();
- if (!filePath.isEmpty())
- ICore::mainWindow()->setWindowFilePath(filePath);
- } else {
- ICore::mainWindow()->setWindowFilePath(QString());
+ QString filePath = document ? QFileInfo(document->filePath()).absoluteFilePath()
+ : QString();
+
+ const QString windowTitleAddition = d->m_titleAdditionHandler
+ ? d->m_titleAdditionHandler(filePath)
+ : QString();
+
+ QString windowTitleVcsTopic;
+ if (d->m_titleVcsTopicHandler)
+ windowTitleVcsTopic = d->m_titleVcsTopicHandler(filePath);
+ if (!windowTitleVcsTopic.isEmpty())
+ windowTitleVcsTopic = QStringLiteral(" [") + windowTitleVcsTopic + QStringLiteral("]");
+
+ const QString documentName = document ? document->displayName() : QString();
+
+ if (!documentName.isEmpty())
+ windowTitle.append(documentName + windowTitleVcsTopic + dashSep);
+ if (!windowTitleAddition.isEmpty()) {
+ windowTitle.append(windowTitleAddition);
+ if (documentName.isEmpty()) // vcs topic not already added
+ windowTitle.append(windowTitleVcsTopic);
+ windowTitle.append(dashSep);
+ }
+
+ windowTitle.append(tr("Qt Creator"));
+ window->window()->setWindowTitle(windowTitle);
+ window->window()->setWindowFilePath(filePath);
+
+ if (HostOsInfo::isMacHost()) {
+ if (document)
+ window->window()->setWindowModified(document->isModified());
+ else
+ window->window()->setWindowModified(false);
}
- ICore::mainWindow()->setWindowTitle(windowTitle);
+}
+
+void EditorManagerPrivate::updateWindowTitle()
+{
+ EditorArea *mainArea = mainEditorArea();
+ IDocument *document = mainArea->currentDocument();
+ updateWindowTitleForDocument(document, mainArea->window());
}
void EditorManagerPrivate::gotoNextDocHistory()
@@ -1444,7 +1461,6 @@ void EditorManagerPrivate::handleDocumentStateChange()
if (!document->isModified())
document->removeAutoSaveFile();
if (EditorManager::currentDocument() == document) {
- updateWindowTitle();
emit m_instance->currentDocumentStateChanged();
}
}
@@ -2045,7 +2061,6 @@ bool EditorManager::closeEditors(const QList<IEditor*> &editorsToClose, bool ask
if (!currentEditor()) {
emit m_instance->currentEditorChanged(0);
EditorManagerPrivate::updateActions();
- EditorManagerPrivate::updateWindowTitle();
}
return !closingFailed;
@@ -2524,24 +2539,18 @@ qint64 EditorManager::maxTextFileSize()
return qint64(3) << 24;
}
-void EditorManager::setWindowTitleAddition(const QString &addition)
+void EditorManager::setWindowTitleAdditionHandler(WindowTitleHandler handler)
{
- d->m_titleAddition = addition;
- EditorManagerPrivate::updateWindowTitle();
+ d->m_titleAdditionHandler = handler;
}
-QString EditorManager::windowTitleAddition()
+void EditorManager::updateWindowTitles()
{
- return d->m_titleAddition;
-}
-
-void EditorManager::setWindowTitleVcsTopic(const QString &topic)
-{
- d->m_titleVcsTopic = topic;
- EditorManagerPrivate::updateWindowTitle();
+ foreach (EditorArea *area, d->m_editorAreas)
+ emit area->windowTitleNeedsUpdate();
}
-QString EditorManager::windowTitleVcsTopic()
+void EditorManager::setWindowTitleVcsTopicHandler(WindowTitleHandler handler)
{
- return d->m_titleVcsTopic;
+ d->m_titleVcsTopicHandler = handler;
}
diff --git a/src/plugins/coreplugin/editormanager/editormanager.h b/src/plugins/coreplugin/editormanager/editormanager.h
index 9dcd84117d..ece8c6ef35 100644
--- a/src/plugins/coreplugin/editormanager/editormanager.h
+++ b/src/plugins/coreplugin/editormanager/editormanager.h
@@ -41,6 +41,8 @@
#include <QWidget>
#include <QMenu>
+#include <functional>
+
QT_BEGIN_NAMESPACE
QT_END_NAMESPACE
@@ -93,6 +95,7 @@ class CORE_EXPORT EditorManager : public QObject
public:
typedef QList<IEditorFactory *> EditorFactoryList;
typedef QList<IExternalEditor *> ExternalEditorList;
+ typedef std::function<QString (const QString &)> WindowTitleHandler;
static EditorManager *instance();
@@ -160,11 +163,8 @@ public:
static qint64 maxTextFileSize();
- static void setWindowTitleAddition(const QString &addition);
- static QString windowTitleAddition();
-
- static void setWindowTitleVcsTopic(const QString &topic);
- static QString windowTitleVcsTopic();
+ static void setWindowTitleAdditionHandler(WindowTitleHandler handler);
+ static void setWindowTitleVcsTopicHandler(WindowTitleHandler handler);
static void addSaveAndCloseEditorActions(QMenu *contextMenu, DocumentModel::Entry *entry);
static void addNativeDirAndOpenWithActions(QMenu *contextMenu, DocumentModel::Entry *entry);
@@ -189,6 +189,7 @@ public slots:
static void gotoOtherSplit();
static void goBackInNavigationHistory();
static void goForwardInNavigationHistory();
+ static void updateWindowTitles();
private:
explicit EditorManager(QObject *parent);
diff --git a/src/plugins/coreplugin/editormanager/editormanager_p.h b/src/plugins/coreplugin/editormanager/editormanager_p.h
index 01cb23d337..4b840d311a 100644
--- a/src/plugins/coreplugin/editormanager/editormanager_p.h
+++ b/src/plugins/coreplugin/editormanager/editormanager_p.h
@@ -67,7 +67,7 @@ class EditorManagerPrivate : public QObject
friend class Core::EditorManager;
public:
- static QWidget *mainEditorArea();
+ static EditorArea *mainEditorArea();
static EditorView *currentEditorView();
static void setCurrentEditor(IEditor *editor, bool ignoreNavigationHistory = false);
static IEditor *openEditor(EditorView *view,
@@ -105,6 +105,8 @@ public:
static void updateActions();
+ static void updateWindowTitleForDocument(IDocument *document, QWidget *window);
+
public slots:
static bool saveDocument(Core::IDocument *document);
static bool saveDocumentAs(Core::IDocument *document);
@@ -217,8 +219,8 @@ private:
IDocument::ReloadSetting m_reloadSetting;
- QString m_titleAddition;
- QString m_titleVcsTopic;
+ EditorManager::WindowTitleHandler m_titleAdditionHandler;
+ EditorManager::WindowTitleHandler m_titleVcsTopicHandler;
bool m_autoSaveEnabled;
int m_autoSaveInterval;
diff --git a/src/plugins/coreplugin/editormanager/editorview.cpp b/src/plugins/coreplugin/editormanager/editorview.cpp
index 420911dcf7..3fbb09b623 100644
--- a/src/plugins/coreplugin/editormanager/editorview.cpp
+++ b/src/plugins/coreplugin/editormanager/editorview.cpp
@@ -359,6 +359,7 @@ void EditorView::setCurrentEditor(IEditor *editor)
m_toolBar->setCurrentEditor(0);
m_infoBarDisplay->setInfoBar(0);
m_container->setCurrentIndex(0);
+ emit currentEditorChanged(0);
return;
}
@@ -373,6 +374,7 @@ void EditorView::setCurrentEditor(IEditor *editor)
updateEditorHistory(editor);
m_infoBarDisplay->setInfoBar(editor->document()->infoBar());
+ emit currentEditorChanged(editor);
}
int EditorView::editorCount() const
diff --git a/src/plugins/coreplugin/editormanager/editorview.h b/src/plugins/coreplugin/editormanager/editorview.h
index 592f3e1426..08f567e1b6 100644
--- a/src/plugins/coreplugin/editormanager/editorview.h
+++ b/src/plugins/coreplugin/editormanager/editorview.h
@@ -103,6 +103,9 @@ public:
static void updateEditorHistory(IEditor *editor, QList<EditLocation> &history);
+signals:
+ void currentEditorChanged(Core::IEditor *editor);
+
protected:
void paintEvent(QPaintEvent *);
void mousePressEvent(QMouseEvent *e);
diff --git a/src/plugins/coreplugin/editormanager/editorwindow.cpp b/src/plugins/coreplugin/editormanager/editorwindow.cpp
index a25e828101..c6036de2b0 100644
--- a/src/plugins/coreplugin/editormanager/editorwindow.cpp
+++ b/src/plugins/coreplugin/editormanager/editorwindow.cpp
@@ -30,6 +30,7 @@
#include "editorwindow.h"
#include "editorarea.h"
+#include "editormanager_p.h"
#include <coreplugin/icontext.h>
#include <coreplugin/icore.h>
@@ -55,6 +56,10 @@ EditorWindow::EditorWindow(QWidget *parent) :
static int windowId = 0;
ICore::registerWindow(this, Context(Id("EditorManager.ExternalWindow.").withSuffix(++windowId)));
+
+ connect(m_area, &EditorArea::windowTitleNeedsUpdate,
+ this, &EditorWindow::updateWindowTitle);
+ updateWindowTitle();
}
EditorArea *EditorWindow::editorArea() const
@@ -62,5 +67,10 @@ EditorArea *EditorWindow::editorArea() const
return m_area;
}
+void EditorWindow::updateWindowTitle()
+{
+ EditorManagerPrivate::updateWindowTitleForDocument(m_area->currentDocument(), this);
+}
+
} // Internal
} // Core
diff --git a/src/plugins/coreplugin/editormanager/editorwindow.h b/src/plugins/coreplugin/editormanager/editorwindow.h
index 0ab287ed8d..eecb7586a6 100644
--- a/src/plugins/coreplugin/editormanager/editorwindow.h
+++ b/src/plugins/coreplugin/editormanager/editorwindow.h
@@ -46,6 +46,8 @@ public:
EditorArea *editorArea() const;
private:
+ void updateWindowTitle();
+
EditorArea *m_area;
};
diff --git a/src/plugins/projectexplorer/session.cpp b/src/plugins/projectexplorer/session.cpp
index c69d8cc054..d73c16f795 100644
--- a/src/plugins/projectexplorer/session.cpp
+++ b/src/plugins/projectexplorer/session.cpp
@@ -100,6 +100,8 @@ public:
void dependencies(const QString &proName, QStringList &result) const;
public:
+ static QString windowTitleAddition(const QString &filePath);
+
SessionNode *m_sessionNode;
QString m_sessionName;
bool m_virginSession;
@@ -134,12 +136,18 @@ SessionManager::SessionManager(QObject *parent)
connect(EditorManager::instance(), SIGNAL(editorCreated(Core::IEditor*,QString)),
this, SLOT(configureEditor(Core::IEditor*,QString)));
- connect(ProjectExplorerPlugin::instance(), SIGNAL(currentProjectChanged(ProjectExplorer::Project*)),
- this, SLOT(updateWindowTitle()));
+ connect(this, SIGNAL(projectAdded(ProjectExplorer::Project*)),
+ EditorManager::instance(), SLOT(updateWindowTitles()));
+ connect(this, SIGNAL(projectRemoved(ProjectExplorer::Project*)),
+ EditorManager::instance(), SLOT(updateWindowTitles()));
+ connect(this, SIGNAL(projectDisplayNameChanged(ProjectExplorer::Project*)),
+ EditorManager::instance(), SLOT(updateWindowTitles()));
connect(EditorManager::instance(), SIGNAL(editorOpened(Core::IEditor*)),
this, SLOT(markSessionFileDirty()));
connect(EditorManager::instance(), SIGNAL(editorsClosed(QList<Core::IEditor*>)),
this, SLOT(markSessionFileDirty()));
+
+ EditorManager::setWindowTitleAdditionHandler(&SessionManagerPrivate::windowTitleAddition);
}
SessionManager::~SessionManager()
@@ -444,6 +452,28 @@ void SessionManagerPrivate::dependencies(const QString &proName, QStringList &re
result.append(proName);
}
+QString SessionManagerPrivate::windowTitleAddition(const QString &filePath)
+{
+ if (SessionManager::isDefaultSession(d->m_sessionName)) {
+ if (filePath.isEmpty()) {
+ // use single project's name if there is only one loaded.
+ const QList<ProjectExplorer::Project *> projects = ProjectExplorer::SessionManager::projects();
+ if (projects.size() == 1)
+ return projects.first()->displayName();
+ return QString();
+ } else if (Project *project = SessionManager::projectForFile(filePath)) {
+ return project->displayName();
+ } else {
+ return QString();
+ }
+ } else {
+ QString sessionName = d->m_sessionName;
+ if (sessionName.isEmpty())
+ sessionName = SessionManager::tr("Untitled");
+ return sessionName;
+ }
+}
+
QStringList SessionManagerPrivate::dependenciesOrder() const
{
QList<QPair<QString, QStringList> > unordered;
@@ -580,21 +610,6 @@ void SessionManager::configureEditor(Core::IEditor *editor, const QString &fileN
}
}
-void SessionManager::updateWindowTitle()
-{
- if (isDefaultSession(d->m_sessionName)) {
- if (Project *currentProject = ProjectExplorerPlugin::currentProject())
- EditorManager::setWindowTitleAddition(currentProject->displayName());
- else
- EditorManager::setWindowTitleAddition(QString());
- } else {
- QString sessionName = d->m_sessionName;
- if (sessionName.isEmpty())
- sessionName = tr("Untitled");
- EditorManager::setWindowTitleAddition(sessionName);
- }
-}
-
void SessionManager::removeProjects(QList<Project *> remove)
{
QMap<QString, QStringList> resMap;
@@ -901,7 +916,7 @@ bool SessionManager::loadSession(const QString &session)
d->m_values.clear();
d->m_sessionName = session;
- updateWindowTitle();
+ EditorManager::updateWindowTitles();
if (fileName.toFileInfo().exists()) {
d->m_virginSession = false;
diff --git a/src/plugins/projectexplorer/session.h b/src/plugins/projectexplorer/session.h
index cca7e65df1..416e07bf12 100644
--- a/src/plugins/projectexplorer/session.h
+++ b/src/plugins/projectexplorer/session.h
@@ -144,7 +144,6 @@ private slots:
static void saveActiveMode(Core::IMode *mode);
static void clearProjectFileCache();
static void configureEditor(Core::IEditor *editor, const QString &fileName);
- static void updateWindowTitle();
static void markSessionFileDirty(bool makeDefaultVirginDirty = true);
static void projectDisplayNameChanged();
};
diff --git a/src/plugins/vcsbase/vcsbaseplugin.cpp b/src/plugins/vcsbase/vcsbaseplugin.cpp
index 5db0cf47a8..609a7425cd 100644
--- a/src/plugins/vcsbase/vcsbaseplugin.cpp
+++ b/src/plugins/vcsbase/vcsbaseplugin.cpp
@@ -43,6 +43,7 @@
#include <coreplugin/vcsmanager.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/project.h>
+#include <projectexplorer/session.h>
#include <utils/qtcassert.h>
#include <utils/synchronousprocess.h>
@@ -196,6 +197,8 @@ class StateListener : public QObject
public:
explicit StateListener(QObject *parent);
+ static QString windowTitleVcsTopic(const QString &filePath);
+
signals:
void stateChanged(const VcsBase::Internal::State &s, Core::IVersionControl *vc);
@@ -216,6 +219,27 @@ StateListener::StateListener(QObject *parent) :
connect(ProjectExplorer::ProjectExplorerPlugin::instance(),
SIGNAL(currentProjectChanged(ProjectExplorer::Project*)),
this, SLOT(slotStateChanged()));
+
+ Core::EditorManager::setWindowTitleVcsTopicHandler(&StateListener::windowTitleVcsTopic);
+}
+
+QString StateListener::windowTitleVcsTopic(const QString &filePath)
+{
+ QString searchPath;
+ if (!filePath.isEmpty()) {
+ searchPath = filePath;
+ } else {
+ // use single project's information if there is only one loaded.
+ const QList<ProjectExplorer::Project *> projects = ProjectExplorer::SessionManager::projects();
+ if (projects.size() == 1)
+ searchPath = projects.first()->projectDirectory().toString();
+ }
+ if (searchPath.isEmpty())
+ return QString();
+ QString topLevelPath;
+ Core::IVersionControl *vc = Core::VcsManager::findVersionControlForDirectory(
+ searchPath, &topLevelPath);
+ return (vc && !topLevelPath.isEmpty()) ? vc->vcsTopic(topLevelPath) : QString();
}
static inline QString displayNameOfEditor(const QString &fileName)
@@ -300,12 +324,11 @@ void StateListener::slotStateChanged()
Core::IVersionControl *vc = fileControl;
if (!vc)
vc = projectControl;
- if (!vc) {
+ if (!vc)
state.clearPatchFile(); // Need a repository to patch
- Core::EditorManager::setWindowTitleVcsTopic(QString());
- }
if (debug)
qDebug() << state << (vc ? vc->displayName() : QLatin1String("No version control"));
+ Core::EditorManager::updateWindowTitles();
emit stateChanged(state, vc);
}
@@ -586,7 +609,6 @@ void VcsBasePlugin::slotStateChanged(const VcsBase::Internal::State &newInternal
d->m_state.setState(newInternalState);
updateActions(VcsEnabled);
}
- Core::EditorManager::setWindowTitleVcsTopic(vc->vcsTopic(d->m_state.topLevel()));
} else {
// Some other VCS plugin or state changed: Reset us to empty state.
const ActionState newActionState = vc ? OtherVcsEnabled : NoVcsEnabled;