Commit af99e09b authored by con's avatar con

Window title didn't show nice name for e.g. diff views.

Use the editor's displayName for the window title.
Also there were missing change signal emissions in setDisplayName
implementations.
Moves the actual handling of the window title from Session to
EditorManager (so it now is also done for the hypothetical case of no
project explorer plugin).

Task-number: QTCREATORBUG-3207
parent 14a71bc7
......@@ -218,6 +218,8 @@ struct EditorManagerPrivate {
IFile::ReloadSetting m_reloadSetting;
IFile::Utf8BomSetting m_utf8BomSetting;
QString m_titleAddition;
};
}
......@@ -530,13 +532,17 @@ void EditorManager::setCurrentEditor(IEditor *editor, bool ignoreNavigationHisto
if (m_d->m_currentEditor && !ignoreNavigationHistory)
addCurrentPositionToNavigationHistory();
if (m_d->m_currentEditor)
disconnect(m_d->m_currentEditor, SIGNAL(changed()), this, SLOT(updateWindowTitle()));
m_d->m_currentEditor = editor;
if (editor) {
if (SplitterOrView *splitterOrView = m_d->m_splitter->findView(editor))
splitterOrView->view()->setCurrentEditor(editor);
m_d->m_view->updateEditorHistory(editor); // the global view should have a complete history
connect(m_d->m_currentEditor, SIGNAL(changed()), this, SLOT(updateWindowTitle()));
}
updateActions();
updateWindowTitle();
emit currentEditorChanged(editor);
}
......@@ -847,6 +853,7 @@ bool EditorManager::closeEditors(const QList<IEditor*> &editorsToClose, bool ask
if (!currentEditor()) {
emit currentEditorChanged(0);
updateActions();
updateWindowTitle();
}
return !closingFailed;
......@@ -1569,6 +1576,26 @@ void EditorManager::makeCurrentEditorWritable()
makeEditorWritable(curEditor);
}
void EditorManager::updateWindowTitle()
{
QString windowTitle = tr("Qt Creator");
if (!m_d->m_titleAddition.isEmpty()) {
windowTitle.prepend(m_d->m_titleAddition + " - ");
}
IEditor *curEditor = currentEditor();
if (curEditor) {
QString editorName = curEditor->displayName();
if (!editorName.isEmpty())
windowTitle.prepend(editorName + " - ");
QString filePath = QFileInfo(curEditor->file()->fileName()).absoluteFilePath();
if (!filePath.isEmpty())
m_d->m_core->mainWindow()->setWindowFilePath(filePath);
} else {
m_d->m_core->mainWindow()->setWindowFilePath(QString());
}
m_d->m_core->mainWindow()->setWindowTitle(windowTitle);
}
void EditorManager::updateActions()
{
QString fName;
......@@ -2069,7 +2096,12 @@ void EditorManager::removeAllSplits()
if (!m_d->m_splitter->isSplitter())
return;
IEditor *editor = m_d->m_currentEditor;
m_d->m_currentEditor = 0; // trigger update below
{
// trigger update below
disconnect(m_d->m_currentEditor, SIGNAL(changed()),
this, SLOT(updateWindowTitle()));
m_d->m_currentEditor = 0;
}
if (editor && m_d->m_editorModel->isDuplicate(editor))
m_d->m_editorModel->makeOriginal(editor);
m_d->m_splitter->unsplitAll();
......@@ -2104,5 +2136,15 @@ qint64 EditorManager::maxTextFileSize()
{
return (qint64(3) << 24);
}
//===================EditorClosingCoreListener======================
void EditorManager::setWindowTitleAddition(const QString &addition)
{
m_d->m_titleAddition = addition;
updateWindowTitle();
}
QString EditorManager::windowTitleAddition() const
{
return m_d->m_titleAddition;
}
......@@ -208,6 +208,9 @@ public:
static qint64 maxTextFileSize();
void setWindowTitleAddition(const QString &addition);
QString windowTitleAddition() const;
signals:
void currentEditorChanged(Core::IEditor *editor);
void editorCreated(Core::IEditor *editor, const QString &fileName);
......@@ -231,6 +234,7 @@ private slots:
void handleContextChange(Core::IContext *context);
void updateActions();
void makeCurrentEditorWritable();
void updateWindowTitle();
public slots:
void goBackInNavigationHistory();
......@@ -269,7 +273,6 @@ private:
Core::Internal::EditorView *currentEditorView() const;
IEditor *pickUnusedEditor() const;
static EditorManager *m_instance;
EditorManagerPrivate *m_d;
......
......@@ -212,6 +212,7 @@ QString FormWindowEditor::displayName() const
void FormWindowEditor::setDisplayName(const QString &title)
{
d->m_textEditable.setDisplayName(title);
emit changed();
}
bool FormWindowEditor::duplicateSupported() const
......
......@@ -312,7 +312,6 @@ SessionManager::SessionManager(QObject *parent)
m_core(Core::ICore::instance()),
m_file(new SessionFile),
m_sessionNode(new Internal::SessionNodeImpl(this)),
m_currentEditor(0),
m_virginSession(true)
{
connect(m_core->modeManager(), SIGNAL(currentModeChanged(Core::IMode*)),
......@@ -324,8 +323,6 @@ SessionManager::SessionManager(QObject *parent)
this, SLOT(setEditorCodec(Core::IEditor *, QString)));
connect(ProjectExplorerPlugin::instance(), SIGNAL(currentProjectChanged(ProjectExplorer::Project *)),
this, SLOT(updateWindowTitle()));
connect(em, SIGNAL(currentEditorChanged(Core::IEditor*)),
this, SLOT(handleCurrentEditorChange(Core::IEditor*)));
connect(em, SIGNAL(editorOpened(Core::IEditor*)),
this, SLOT(markSessionFileDirty()));
connect(em, SIGNAL(editorsClosed(QList<Core::IEditor*>)),
......@@ -839,40 +836,17 @@ QString SessionManager::currentSession() const
return m_file->fileName();
}
void SessionManager::handleCurrentEditorChange(Core::IEditor *editor)
{
if (editor != m_currentEditor) {
if (m_currentEditor)
disconnect(m_currentEditor, SIGNAL(changed()), this, SLOT(updateWindowTitle()));
if (editor)
connect(editor, SIGNAL(changed()), this, SLOT(updateWindowTitle()));
m_currentEditor = editor;
}
updateWindowTitle();
}
void SessionManager::updateWindowTitle()
{
QString windowTitle = tr("Qt Creator");
if (isDefaultSession(m_sessionName)) {
if (Project *currentProject = ProjectExplorerPlugin::instance()->currentProject())
windowTitle.prepend(currentProject->displayName() + " - ");
m_core->editorManager()->setWindowTitleAddition(currentProject->displayName());
} else {
QString sessionName = m_sessionName;
if (sessionName.isEmpty())
sessionName = tr("Untitled");
windowTitle.prepend(sessionName + " - ");
}
if (m_core->editorManager()->currentEditor()) {
QFileInfo fi(m_core->editorManager()->currentEditor()->file()->fileName());
QString fileName = fi.fileName();
if (!fileName.isEmpty())
windowTitle.prepend(fileName + " - ");
m_core->mainWindow()->setWindowFilePath(fi.absoluteFilePath());
} else {
m_core->mainWindow()->setWindowFilePath(QString());
m_core->editorManager()->setWindowTitleAddition(sessionName);
}
m_core->mainWindow()->setWindowTitle(windowTitle);
}
void SessionManager::updateName(const QString &session)
......
......@@ -155,7 +155,6 @@ private slots:
void saveActiveMode(Core::IMode *mode);
void clearProjectFileCache();
void setEditorCodec(Core::IEditor *editor, const QString &fileName);
void handleCurrentEditorChange(Core::IEditor *editor);
void updateWindowTitle();
void markSessionFileDirty(bool makeDefaultVirginDirty = true);
......@@ -176,7 +175,6 @@ private:
Internal::SessionFile *m_file;
Internal::SessionNodeImpl *m_sessionNode;
QPointer<Core::IEditor> m_currentEditor;
QString m_sessionName;
bool m_virginSession;
......
......@@ -89,7 +89,7 @@ public:
Core::IFile *file() { return m_resourceFile; }
QString id() const;
QString displayName() const { return m_displayName; }
void setDisplayName(const QString &title) { m_displayName = title; }
void setDisplayName(const QString &title) { m_displayName = title; emit changed(); }
QWidget *toolBar() { return 0; }
QByteArray saveState() const { return QByteArray(); }
bool restoreState(const QByteArray &/*state*/) { return true; }
......
......@@ -2050,6 +2050,7 @@ QString BaseTextEditor::displayName() const
void BaseTextEditor::setDisplayName(const QString &title)
{
d->m_displayName = title;
emit changed();
}
BaseTextDocument *BaseTextEditor::baseTextDocument() const
......
......@@ -572,7 +572,7 @@ public:
return e->open(fileName);
}
inline QString displayName() const { return e->displayName(); }
inline void setDisplayName(const QString &title) { e->setDisplayName(title); }
inline void setDisplayName(const QString &title) { e->setDisplayName(title); emit changed(); }
inline QByteArray saveState() const { return e->saveState(); }
inline bool restoreState(const QByteArray &state) { return e->restoreState(state); }
......
......@@ -329,6 +329,7 @@ QString VCSBaseSubmitEditor::displayName() const
void VCSBaseSubmitEditor::setDisplayName(const QString &title)
{
m_d->m_displayName = title;
emit changed();
}
QString VCSBaseSubmitEditor::checkScriptWorkingDirectory() const
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment