forked from qt-creator/qt-creator
Editors: Set window title for external editor windows
Change-Id: I54ed77c0f1b2122ae8833109d8dcac7d8eec7ac4 Task-number: QTCREATORBUG-9612 Reviewed-by: Daniel Teske <daniel.teske@digia.com>
This commit is contained in:
@@ -29,26 +29,99 @@
|
|||||||
|
|
||||||
#include "editorarea.h"
|
#include "editorarea.h"
|
||||||
|
|
||||||
|
#include "editormanager.h"
|
||||||
|
#include "ieditor.h"
|
||||||
|
|
||||||
#include <coreplugin/coreconstants.h>
|
#include <coreplugin/coreconstants.h>
|
||||||
#include <coreplugin/icontext.h>
|
#include <coreplugin/icontext.h>
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
EditorArea::EditorArea()
|
EditorArea::EditorArea()
|
||||||
|
: m_currentView(0),
|
||||||
|
m_currentDocument(0)
|
||||||
{
|
{
|
||||||
m_context = new IContext;
|
m_context = new IContext;
|
||||||
m_context->setContext(Context(Constants::C_EDITORMANAGER));
|
m_context->setContext(Context(Constants::C_EDITORMANAGER));
|
||||||
m_context->setWidget(this);
|
m_context->setWidget(this);
|
||||||
ICore::addContextObject(m_context);
|
ICore::addContextObject(m_context);
|
||||||
|
|
||||||
|
setCurrentView(view());
|
||||||
|
|
||||||
|
connect(qApp, &QApplication::focusChanged,
|
||||||
|
this, &EditorArea::focusChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
EditorArea::~EditorArea()
|
EditorArea::~EditorArea()
|
||||||
{
|
{
|
||||||
|
// disconnect
|
||||||
|
setCurrentView(0);
|
||||||
|
disconnect(qApp, &QApplication::focusChanged,
|
||||||
|
this, &EditorArea::focusChanged);
|
||||||
|
|
||||||
ICore::removeContextObject(m_context);
|
ICore::removeContextObject(m_context);
|
||||||
delete 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
|
} // Internal
|
||||||
} // Core
|
} // Core
|
||||||
|
|||||||
@@ -32,6 +32,8 @@
|
|||||||
|
|
||||||
#include "editorview.h"
|
#include "editorview.h"
|
||||||
|
|
||||||
|
#include <QPointer>
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
|
|
||||||
class IContext;
|
class IContext;
|
||||||
@@ -46,8 +48,19 @@ public:
|
|||||||
EditorArea();
|
EditorArea();
|
||||||
~EditorArea();
|
~EditorArea();
|
||||||
|
|
||||||
|
IDocument *currentDocument() const;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void windowTitleNeedsUpdate();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void focusChanged(QWidget *old, QWidget *now);
|
||||||
|
void setCurrentView(EditorView *view);
|
||||||
|
void updateCurrentEditor(IEditor *editor);
|
||||||
|
|
||||||
IContext *m_context;
|
IContext *m_context;
|
||||||
|
QPointer<EditorView> m_currentView;
|
||||||
|
QPointer<IDocument> m_currentDocument;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // Internal
|
} // Internal
|
||||||
|
|||||||
@@ -451,6 +451,8 @@ void EditorManagerPrivate::init()
|
|||||||
// other setup
|
// other setup
|
||||||
auto mainEditorArea = new EditorArea();
|
auto mainEditorArea = new EditorArea();
|
||||||
mainEditorArea->hide();
|
mainEditorArea->hide();
|
||||||
|
connect(mainEditorArea, &EditorArea::windowTitleNeedsUpdate,
|
||||||
|
this, &EditorManagerPrivate::updateWindowTitle);
|
||||||
connect(mainEditorArea, SIGNAL(destroyed(QObject*)), this, SLOT(editorAreaDestroyed(QObject*)));
|
connect(mainEditorArea, SIGNAL(destroyed(QObject*)), this, SLOT(editorAreaDestroyed(QObject*)));
|
||||||
d->m_editorAreas.append(mainEditorArea);
|
d->m_editorAreas.append(mainEditorArea);
|
||||||
d->m_currentView = mainEditorArea->view();
|
d->m_currentView = mainEditorArea->view();
|
||||||
@@ -491,7 +493,7 @@ void EditorManagerPrivate::init()
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget *EditorManagerPrivate::mainEditorArea()
|
EditorArea *EditorManagerPrivate::mainEditorArea()
|
||||||
{
|
{
|
||||||
return d->m_editorAreas.at(0);
|
return d->m_editorAreas.at(0);
|
||||||
}
|
}
|
||||||
@@ -1065,7 +1067,6 @@ void EditorManagerPrivate::setCurrentEditor(IEditor *editor, bool ignoreNavigati
|
|||||||
EditorView::updateEditorHistory(editor, d->m_globalHistory);
|
EditorView::updateEditorHistory(editor, d->m_globalHistory);
|
||||||
}
|
}
|
||||||
updateActions();
|
updateActions();
|
||||||
updateWindowTitle();
|
|
||||||
emit m_instance->currentEditorChanged(editor);
|
emit m_instance->currentEditorChanged(editor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1297,13 +1298,8 @@ void EditorManagerPrivate::updateActions()
|
|||||||
IDocument *curDocument = EditorManager::currentDocument();
|
IDocument *curDocument = EditorManager::currentDocument();
|
||||||
const int openedCount = DocumentModel::entryCount();
|
const int openedCount = DocumentModel::entryCount();
|
||||||
|
|
||||||
if (curDocument) {
|
if (curDocument)
|
||||||
if (HostOsInfo::isMacHost())
|
|
||||||
mainEditorArea()->window()->setWindowModified(curDocument->isModified());
|
|
||||||
updateMakeWritableWarning();
|
updateMakeWritableWarning();
|
||||||
} else /* curEditor */ if (HostOsInfo::isMacHost()) {
|
|
||||||
mainEditorArea()->window()->setWindowModified(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (EditorArea *area, d->m_editorAreas)
|
foreach (EditorArea *area, d->m_editorAreas)
|
||||||
setCloseSplitEnabled(area, area->isSplitter());
|
setCloseSplitEnabled(area, area->isSplitter());
|
||||||
@@ -1335,32 +1331,53 @@ void EditorManagerPrivate::updateActions()
|
|||||||
d->m_gotoNextSplitAction->setEnabled(hasSplitter || d->m_editorAreas.size() > 1);
|
d->m_gotoNextSplitAction->setEnabled(hasSplitter || d->m_editorAreas.size() > 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EditorManagerPrivate::updateWindowTitleForDocument(IDocument *document, QWidget *window)
|
||||||
|
{
|
||||||
|
QTC_ASSERT(window, return);
|
||||||
|
QString windowTitle;
|
||||||
|
const QString dashSep = QLatin1String(" - ");
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void EditorManagerPrivate::updateWindowTitle()
|
void EditorManagerPrivate::updateWindowTitle()
|
||||||
{
|
{
|
||||||
QString windowTitle = tr("Qt Creator");
|
EditorArea *mainArea = mainEditorArea();
|
||||||
const QString dashSep = QLatin1String(" - ");
|
IDocument *document = mainArea->currentDocument();
|
||||||
QString vcsTopic;
|
updateWindowTitleForDocument(document, mainArea->window());
|
||||||
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());
|
|
||||||
}
|
|
||||||
ICore::mainWindow()->setWindowTitle(windowTitle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorManagerPrivate::gotoNextDocHistory()
|
void EditorManagerPrivate::gotoNextDocHistory()
|
||||||
@@ -1444,7 +1461,6 @@ void EditorManagerPrivate::handleDocumentStateChange()
|
|||||||
if (!document->isModified())
|
if (!document->isModified())
|
||||||
document->removeAutoSaveFile();
|
document->removeAutoSaveFile();
|
||||||
if (EditorManager::currentDocument() == document) {
|
if (EditorManager::currentDocument() == document) {
|
||||||
updateWindowTitle();
|
|
||||||
emit m_instance->currentDocumentStateChanged();
|
emit m_instance->currentDocumentStateChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2045,7 +2061,6 @@ bool EditorManager::closeEditors(const QList<IEditor*> &editorsToClose, bool ask
|
|||||||
if (!currentEditor()) {
|
if (!currentEditor()) {
|
||||||
emit m_instance->currentEditorChanged(0);
|
emit m_instance->currentEditorChanged(0);
|
||||||
EditorManagerPrivate::updateActions();
|
EditorManagerPrivate::updateActions();
|
||||||
EditorManagerPrivate::updateWindowTitle();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return !closingFailed;
|
return !closingFailed;
|
||||||
@@ -2524,24 +2539,18 @@ qint64 EditorManager::maxTextFileSize()
|
|||||||
return qint64(3) << 24;
|
return qint64(3) << 24;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorManager::setWindowTitleAddition(const QString &addition)
|
void EditorManager::setWindowTitleAdditionHandler(WindowTitleHandler handler)
|
||||||
{
|
{
|
||||||
d->m_titleAddition = addition;
|
d->m_titleAdditionHandler = handler;
|
||||||
EditorManagerPrivate::updateWindowTitle();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString EditorManager::windowTitleAddition()
|
void EditorManager::updateWindowTitles()
|
||||||
{
|
{
|
||||||
return d->m_titleAddition;
|
foreach (EditorArea *area, d->m_editorAreas)
|
||||||
|
emit area->windowTitleNeedsUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorManager::setWindowTitleVcsTopic(const QString &topic)
|
void EditorManager::setWindowTitleVcsTopicHandler(WindowTitleHandler handler)
|
||||||
{
|
{
|
||||||
d->m_titleVcsTopic = topic;
|
d->m_titleVcsTopicHandler = handler;
|
||||||
EditorManagerPrivate::updateWindowTitle();
|
|
||||||
}
|
|
||||||
|
|
||||||
QString EditorManager::windowTitleVcsTopic()
|
|
||||||
{
|
|
||||||
return d->m_titleVcsTopic;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,6 +41,8 @@
|
|||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
@@ -93,6 +95,7 @@ class CORE_EXPORT EditorManager : public QObject
|
|||||||
public:
|
public:
|
||||||
typedef QList<IEditorFactory *> EditorFactoryList;
|
typedef QList<IEditorFactory *> EditorFactoryList;
|
||||||
typedef QList<IExternalEditor *> ExternalEditorList;
|
typedef QList<IExternalEditor *> ExternalEditorList;
|
||||||
|
typedef std::function<QString (const QString &)> WindowTitleHandler;
|
||||||
|
|
||||||
static EditorManager *instance();
|
static EditorManager *instance();
|
||||||
|
|
||||||
@@ -160,11 +163,8 @@ public:
|
|||||||
|
|
||||||
static qint64 maxTextFileSize();
|
static qint64 maxTextFileSize();
|
||||||
|
|
||||||
static void setWindowTitleAddition(const QString &addition);
|
static void setWindowTitleAdditionHandler(WindowTitleHandler handler);
|
||||||
static QString windowTitleAddition();
|
static void setWindowTitleVcsTopicHandler(WindowTitleHandler handler);
|
||||||
|
|
||||||
static void setWindowTitleVcsTopic(const QString &topic);
|
|
||||||
static QString windowTitleVcsTopic();
|
|
||||||
|
|
||||||
static void addSaveAndCloseEditorActions(QMenu *contextMenu, DocumentModel::Entry *entry);
|
static void addSaveAndCloseEditorActions(QMenu *contextMenu, DocumentModel::Entry *entry);
|
||||||
static void addNativeDirAndOpenWithActions(QMenu *contextMenu, DocumentModel::Entry *entry);
|
static void addNativeDirAndOpenWithActions(QMenu *contextMenu, DocumentModel::Entry *entry);
|
||||||
@@ -189,6 +189,7 @@ public slots:
|
|||||||
static void gotoOtherSplit();
|
static void gotoOtherSplit();
|
||||||
static void goBackInNavigationHistory();
|
static void goBackInNavigationHistory();
|
||||||
static void goForwardInNavigationHistory();
|
static void goForwardInNavigationHistory();
|
||||||
|
static void updateWindowTitles();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit EditorManager(QObject *parent);
|
explicit EditorManager(QObject *parent);
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ class EditorManagerPrivate : public QObject
|
|||||||
friend class Core::EditorManager;
|
friend class Core::EditorManager;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static QWidget *mainEditorArea();
|
static EditorArea *mainEditorArea();
|
||||||
static EditorView *currentEditorView();
|
static EditorView *currentEditorView();
|
||||||
static void setCurrentEditor(IEditor *editor, bool ignoreNavigationHistory = false);
|
static void setCurrentEditor(IEditor *editor, bool ignoreNavigationHistory = false);
|
||||||
static IEditor *openEditor(EditorView *view,
|
static IEditor *openEditor(EditorView *view,
|
||||||
@@ -105,6 +105,8 @@ public:
|
|||||||
|
|
||||||
static void updateActions();
|
static void updateActions();
|
||||||
|
|
||||||
|
static void updateWindowTitleForDocument(IDocument *document, QWidget *window);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
static bool saveDocument(Core::IDocument *document);
|
static bool saveDocument(Core::IDocument *document);
|
||||||
static bool saveDocumentAs(Core::IDocument *document);
|
static bool saveDocumentAs(Core::IDocument *document);
|
||||||
@@ -217,8 +219,8 @@ private:
|
|||||||
|
|
||||||
IDocument::ReloadSetting m_reloadSetting;
|
IDocument::ReloadSetting m_reloadSetting;
|
||||||
|
|
||||||
QString m_titleAddition;
|
EditorManager::WindowTitleHandler m_titleAdditionHandler;
|
||||||
QString m_titleVcsTopic;
|
EditorManager::WindowTitleHandler m_titleVcsTopicHandler;
|
||||||
|
|
||||||
bool m_autoSaveEnabled;
|
bool m_autoSaveEnabled;
|
||||||
int m_autoSaveInterval;
|
int m_autoSaveInterval;
|
||||||
|
|||||||
@@ -359,6 +359,7 @@ void EditorView::setCurrentEditor(IEditor *editor)
|
|||||||
m_toolBar->setCurrentEditor(0);
|
m_toolBar->setCurrentEditor(0);
|
||||||
m_infoBarDisplay->setInfoBar(0);
|
m_infoBarDisplay->setInfoBar(0);
|
||||||
m_container->setCurrentIndex(0);
|
m_container->setCurrentIndex(0);
|
||||||
|
emit currentEditorChanged(0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -373,6 +374,7 @@ void EditorView::setCurrentEditor(IEditor *editor)
|
|||||||
updateEditorHistory(editor);
|
updateEditorHistory(editor);
|
||||||
|
|
||||||
m_infoBarDisplay->setInfoBar(editor->document()->infoBar());
|
m_infoBarDisplay->setInfoBar(editor->document()->infoBar());
|
||||||
|
emit currentEditorChanged(editor);
|
||||||
}
|
}
|
||||||
|
|
||||||
int EditorView::editorCount() const
|
int EditorView::editorCount() const
|
||||||
|
|||||||
@@ -103,6 +103,9 @@ public:
|
|||||||
|
|
||||||
static void updateEditorHistory(IEditor *editor, QList<EditLocation> &history);
|
static void updateEditorHistory(IEditor *editor, QList<EditLocation> &history);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void currentEditorChanged(Core::IEditor *editor);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *);
|
void paintEvent(QPaintEvent *);
|
||||||
void mousePressEvent(QMouseEvent *e);
|
void mousePressEvent(QMouseEvent *e);
|
||||||
|
|||||||
@@ -30,6 +30,7 @@
|
|||||||
#include "editorwindow.h"
|
#include "editorwindow.h"
|
||||||
|
|
||||||
#include "editorarea.h"
|
#include "editorarea.h"
|
||||||
|
#include "editormanager_p.h"
|
||||||
|
|
||||||
#include <coreplugin/icontext.h>
|
#include <coreplugin/icontext.h>
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
@@ -55,6 +56,10 @@ EditorWindow::EditorWindow(QWidget *parent) :
|
|||||||
|
|
||||||
static int windowId = 0;
|
static int windowId = 0;
|
||||||
ICore::registerWindow(this, Context(Id("EditorManager.ExternalWindow.").withSuffix(++windowId)));
|
ICore::registerWindow(this, Context(Id("EditorManager.ExternalWindow.").withSuffix(++windowId)));
|
||||||
|
|
||||||
|
connect(m_area, &EditorArea::windowTitleNeedsUpdate,
|
||||||
|
this, &EditorWindow::updateWindowTitle);
|
||||||
|
updateWindowTitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
EditorArea *EditorWindow::editorArea() const
|
EditorArea *EditorWindow::editorArea() const
|
||||||
@@ -62,5 +67,10 @@ EditorArea *EditorWindow::editorArea() const
|
|||||||
return m_area;
|
return m_area;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EditorWindow::updateWindowTitle()
|
||||||
|
{
|
||||||
|
EditorManagerPrivate::updateWindowTitleForDocument(m_area->currentDocument(), this);
|
||||||
|
}
|
||||||
|
|
||||||
} // Internal
|
} // Internal
|
||||||
} // Core
|
} // Core
|
||||||
|
|||||||
@@ -46,6 +46,8 @@ public:
|
|||||||
EditorArea *editorArea() const;
|
EditorArea *editorArea() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void updateWindowTitle();
|
||||||
|
|
||||||
EditorArea *m_area;
|
EditorArea *m_area;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -100,6 +100,8 @@ public:
|
|||||||
void dependencies(const QString &proName, QStringList &result) const;
|
void dependencies(const QString &proName, QStringList &result) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
static QString windowTitleAddition(const QString &filePath);
|
||||||
|
|
||||||
SessionNode *m_sessionNode;
|
SessionNode *m_sessionNode;
|
||||||
QString m_sessionName;
|
QString m_sessionName;
|
||||||
bool m_virginSession;
|
bool m_virginSession;
|
||||||
@@ -134,12 +136,18 @@ SessionManager::SessionManager(QObject *parent)
|
|||||||
|
|
||||||
connect(EditorManager::instance(), SIGNAL(editorCreated(Core::IEditor*,QString)),
|
connect(EditorManager::instance(), SIGNAL(editorCreated(Core::IEditor*,QString)),
|
||||||
this, SLOT(configureEditor(Core::IEditor*,QString)));
|
this, SLOT(configureEditor(Core::IEditor*,QString)));
|
||||||
connect(ProjectExplorerPlugin::instance(), SIGNAL(currentProjectChanged(ProjectExplorer::Project*)),
|
connect(this, SIGNAL(projectAdded(ProjectExplorer::Project*)),
|
||||||
this, SLOT(updateWindowTitle()));
|
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*)),
|
connect(EditorManager::instance(), SIGNAL(editorOpened(Core::IEditor*)),
|
||||||
this, SLOT(markSessionFileDirty()));
|
this, SLOT(markSessionFileDirty()));
|
||||||
connect(EditorManager::instance(), SIGNAL(editorsClosed(QList<Core::IEditor*>)),
|
connect(EditorManager::instance(), SIGNAL(editorsClosed(QList<Core::IEditor*>)),
|
||||||
this, SLOT(markSessionFileDirty()));
|
this, SLOT(markSessionFileDirty()));
|
||||||
|
|
||||||
|
EditorManager::setWindowTitleAdditionHandler(&SessionManagerPrivate::windowTitleAddition);
|
||||||
}
|
}
|
||||||
|
|
||||||
SessionManager::~SessionManager()
|
SessionManager::~SessionManager()
|
||||||
@@ -444,6 +452,28 @@ void SessionManagerPrivate::dependencies(const QString &proName, QStringList &re
|
|||||||
result.append(proName);
|
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
|
QStringList SessionManagerPrivate::dependenciesOrder() const
|
||||||
{
|
{
|
||||||
QList<QPair<QString, QStringList> > unordered;
|
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)
|
void SessionManager::removeProjects(QList<Project *> remove)
|
||||||
{
|
{
|
||||||
QMap<QString, QStringList> resMap;
|
QMap<QString, QStringList> resMap;
|
||||||
@@ -901,7 +916,7 @@ bool SessionManager::loadSession(const QString &session)
|
|||||||
d->m_values.clear();
|
d->m_values.clear();
|
||||||
|
|
||||||
d->m_sessionName = session;
|
d->m_sessionName = session;
|
||||||
updateWindowTitle();
|
EditorManager::updateWindowTitles();
|
||||||
|
|
||||||
if (fileName.toFileInfo().exists()) {
|
if (fileName.toFileInfo().exists()) {
|
||||||
d->m_virginSession = false;
|
d->m_virginSession = false;
|
||||||
|
|||||||
@@ -144,7 +144,6 @@ private slots:
|
|||||||
static void saveActiveMode(Core::IMode *mode);
|
static void saveActiveMode(Core::IMode *mode);
|
||||||
static void clearProjectFileCache();
|
static void clearProjectFileCache();
|
||||||
static void configureEditor(Core::IEditor *editor, const QString &fileName);
|
static void configureEditor(Core::IEditor *editor, const QString &fileName);
|
||||||
static void updateWindowTitle();
|
|
||||||
static void markSessionFileDirty(bool makeDefaultVirginDirty = true);
|
static void markSessionFileDirty(bool makeDefaultVirginDirty = true);
|
||||||
static void projectDisplayNameChanged();
|
static void projectDisplayNameChanged();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -43,6 +43,7 @@
|
|||||||
#include <coreplugin/vcsmanager.h>
|
#include <coreplugin/vcsmanager.h>
|
||||||
#include <projectexplorer/projectexplorer.h>
|
#include <projectexplorer/projectexplorer.h>
|
||||||
#include <projectexplorer/project.h>
|
#include <projectexplorer/project.h>
|
||||||
|
#include <projectexplorer/session.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/synchronousprocess.h>
|
#include <utils/synchronousprocess.h>
|
||||||
|
|
||||||
@@ -196,6 +197,8 @@ class StateListener : public QObject
|
|||||||
public:
|
public:
|
||||||
explicit StateListener(QObject *parent);
|
explicit StateListener(QObject *parent);
|
||||||
|
|
||||||
|
static QString windowTitleVcsTopic(const QString &filePath);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void stateChanged(const VcsBase::Internal::State &s, Core::IVersionControl *vc);
|
void stateChanged(const VcsBase::Internal::State &s, Core::IVersionControl *vc);
|
||||||
|
|
||||||
@@ -216,6 +219,27 @@ StateListener::StateListener(QObject *parent) :
|
|||||||
connect(ProjectExplorer::ProjectExplorerPlugin::instance(),
|
connect(ProjectExplorer::ProjectExplorerPlugin::instance(),
|
||||||
SIGNAL(currentProjectChanged(ProjectExplorer::Project*)),
|
SIGNAL(currentProjectChanged(ProjectExplorer::Project*)),
|
||||||
this, SLOT(slotStateChanged()));
|
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)
|
static inline QString displayNameOfEditor(const QString &fileName)
|
||||||
@@ -300,12 +324,11 @@ void StateListener::slotStateChanged()
|
|||||||
Core::IVersionControl *vc = fileControl;
|
Core::IVersionControl *vc = fileControl;
|
||||||
if (!vc)
|
if (!vc)
|
||||||
vc = projectControl;
|
vc = projectControl;
|
||||||
if (!vc) {
|
if (!vc)
|
||||||
state.clearPatchFile(); // Need a repository to patch
|
state.clearPatchFile(); // Need a repository to patch
|
||||||
Core::EditorManager::setWindowTitleVcsTopic(QString());
|
|
||||||
}
|
|
||||||
if (debug)
|
if (debug)
|
||||||
qDebug() << state << (vc ? vc->displayName() : QLatin1String("No version control"));
|
qDebug() << state << (vc ? vc->displayName() : QLatin1String("No version control"));
|
||||||
|
Core::EditorManager::updateWindowTitles();
|
||||||
emit stateChanged(state, vc);
|
emit stateChanged(state, vc);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -586,7 +609,6 @@ void VcsBasePlugin::slotStateChanged(const VcsBase::Internal::State &newInternal
|
|||||||
d->m_state.setState(newInternalState);
|
d->m_state.setState(newInternalState);
|
||||||
updateActions(VcsEnabled);
|
updateActions(VcsEnabled);
|
||||||
}
|
}
|
||||||
Core::EditorManager::setWindowTitleVcsTopic(vc->vcsTopic(d->m_state.topLevel()));
|
|
||||||
} else {
|
} else {
|
||||||
// Some other VCS plugin or state changed: Reset us to empty state.
|
// Some other VCS plugin or state changed: Reset us to empty state.
|
||||||
const ActionState newActionState = vc ? OtherVcsEnabled : NoVcsEnabled;
|
const ActionState newActionState = vc ? OtherVcsEnabled : NoVcsEnabled;
|
||||||
|
|||||||
Reference in New Issue
Block a user