Commit 113c5600 authored by Eike Ziller's avatar Eike Ziller
Browse files

Move displayName from IEditor to IDocument



The display name is not editor instance specific, but belongs to the
document.

Change-Id: I3c936f04a86e10e6ca30063d85036d85b4b5880e
Reviewed-by: default avatarDaniel Teske <daniel.teske@digia.com>
parent 81eba6f9
......@@ -561,7 +561,7 @@ void BazaarPlugin::showCommitWidget(const QList<VcsBase::VcsBaseClient::StatusIt
const QString msg = tr("Commit changes for \"%1\".").
arg(QDir::toNativeSeparators(m_submitRepository));
commitEditor->setDisplayName(msg);
commitEditor->document()->setDisplayName(msg);
const BranchInfo branch = m_client->synchronousBranchQuery(m_submitRepository);
commitEditor->setFields(m_submitRepository, branch,
......
......@@ -30,6 +30,7 @@
#include "branchinfo.h"
#include "bazaarcommitwidget.h"
#include <coreplugin/idocument.h>
#include <vcsbase/submitfilemodel.h>
#include <QDebug>
......@@ -40,7 +41,7 @@ CommitEditor::CommitEditor(const VcsBase::VcsBaseSubmitEditorParameters *paramet
: VcsBase::VcsBaseSubmitEditor(parameters, new BazaarCommitWidget(parent)),
m_fileModel(0)
{
setDisplayName(tr("Commit Editor"));
document()->setDisplayName(tr("Commit Editor"));
}
BazaarCommitWidget *CommitEditor::commitWidget()
......
......@@ -208,11 +208,6 @@ public:
}
}
void setFilePath(const QString &newName) {
m_widget->editor()->setDisplayName(QFileInfo(newName).fileName());
IDocument::setFilePath(newName);
}
bool open(QString *errorString, const QString &fileName, quint64 offset = 0) {
QFile file(fileName);
quint64 size = static_cast<quint64>(file.size());
......@@ -337,9 +332,8 @@ public:
widget->setEditor(this);
connect(m_widget, SIGNAL(cursorPositionChanged(int)), SLOT(updateCursorPosition(int)));
connect(m_file, SIGNAL(changed()), SIGNAL(changed()));
connect(m_addressEdit, SIGNAL(editingFinished()), SLOT(jumpToAddress()));
connect(m_widget, SIGNAL(modificationChanged(bool)), SIGNAL(changed()));
connect(m_widget, SIGNAL(modificationChanged(bool)), m_file, SIGNAL(changed()));
updateCursorPosition(m_widget->cursorPosition());
}
......@@ -358,8 +352,6 @@ public:
}
Core::IDocument *document() { return m_file; }
Core::Id id() const { return Core::Id(Core::Constants::K_DEFAULT_BINARY_EDITOR_ID); }
QString displayName() const { return m_displayName; }
void setDisplayName(const QString &title) { m_displayName = title; emit changed(); }
QWidget *toolBar() { return m_toolBar; }
......@@ -377,7 +369,6 @@ private slots:
private:
BinEditorWidget *m_widget;
QString m_displayName;
BinEditorDocument *m_file;
QToolBar *m_toolBar;
QLineEdit *m_addressEdit;
......
......@@ -31,6 +31,7 @@
#include "clearcasesubmiteditor.h"
#include "clearcasesubmiteditorwidget.h"
#include <coreplugin/idocument.h>
#include <vcsbase/submiteditorwidget.h>
#include <vcsbase/submitfilemodel.h>
......@@ -40,7 +41,7 @@ ClearCaseSubmitEditor::ClearCaseSubmitEditor(const VcsBase::VcsBaseSubmitEditorP
QWidget *parentWidget) :
VcsBase::VcsBaseSubmitEditor(parameters, new ClearCaseSubmitEditorWidget(parentWidget))
{
setDisplayName(tr("ClearCase Check In"));
document()->setDisplayName(tr("ClearCase Check In"));
}
ClearCaseSubmitEditorWidget *ClearCaseSubmitEditor::submitEditorWidget()
......
......@@ -60,7 +60,7 @@ CMakeEditor::CMakeEditor(CMakeEditorWidget *editor)
{
setContext(Core::Context(CMakeProjectManager::Constants::C_CMAKEEDITOR,
TextEditor::Constants::C_TEXTEDITOR));
connect(this, SIGNAL(changed()), this, SLOT(markAsChanged()));
connect(document(), SIGNAL(changed()), this, SLOT(markAsChanged()));
}
Core::IEditor *CMakeEditor::duplicate(QWidget *parent)
......
......@@ -85,9 +85,9 @@ using namespace ProjectExplorer;
// Who sets up the environment for cl.exe ? INCLUDEPATH and so on
// Test for form editor (loosely coupled)
static inline bool isFormWindowEditor(const QObject *o)
static inline bool isFormWindowDocument(const QObject *o)
{
return o && !qstrcmp(o->metaObject()->className(), "Designer::FormWindowEditor");
return o && !qstrcmp(o->metaObject()->className(), "Designer::Internal::FormWindowFile");
}
// Return contents of form editor (loosely coupled)
......@@ -822,8 +822,8 @@ void CMakeProject::updateCodeModelSupportFromEditor(const QString &uiFileName,
void CMakeProject::editorChanged(Core::IEditor *editor)
{
// Handle old editor
if (isFormWindowEditor(m_lastEditor)) {
disconnect(m_lastEditor, SIGNAL(changed()), this, SLOT(uiEditorContentsChanged()));
if (m_lastEditor && isFormWindowDocument(m_lastEditor->document())) {
disconnect(m_lastEditor->document(), SIGNAL(changed()), this, SLOT(uiDocumentContentsChanged()));
if (m_dirtyUic) {
const QString contents = formWindowEditorContents(m_lastEditor);
updateCodeModelSupportFromEditor(m_lastEditor->document()->filePath(), contents);
......@@ -834,8 +834,8 @@ void CMakeProject::editorChanged(Core::IEditor *editor)
m_lastEditor = editor;
// Handle new editor
if (isFormWindowEditor(editor))
connect(editor, SIGNAL(changed()), this, SLOT(uiEditorContentsChanged()));
if (editor && isFormWindowDocument(editor->document()))
connect(editor->document(), SIGNAL(changed()), this, SLOT(uiDocumentContentsChanged()));
}
void CMakeProject::editorAboutToClose(Core::IEditor *editor)
......@@ -843,8 +843,8 @@ void CMakeProject::editorAboutToClose(Core::IEditor *editor)
if (m_lastEditor == editor) {
// Oh no our editor is going to be closed
// get the content first
if (isFormWindowEditor(m_lastEditor)) {
disconnect(m_lastEditor, SIGNAL(changed()), this, SLOT(uiEditorContentsChanged()));
if (isFormWindowDocument(m_lastEditor->document())) {
disconnect(m_lastEditor->document(), SIGNAL(changed()), this, SLOT(uiDocumentContentsChanged()));
if (m_dirtyUic) {
const QString contents = formWindowEditorContents(m_lastEditor);
updateCodeModelSupportFromEditor(m_lastEditor->document()->filePath(), contents);
......@@ -855,10 +855,10 @@ void CMakeProject::editorAboutToClose(Core::IEditor *editor)
}
}
void CMakeProject::uiEditorContentsChanged()
void CMakeProject::uiDocumentContentsChanged()
{
// cast sender, get filename
if (!m_dirtyUic && isFormWindowEditor(sender()))
if (!m_dirtyUic && isFormWindowDocument(sender()))
m_dirtyUic = true;
}
......
......@@ -119,7 +119,7 @@ private slots:
void editorChanged(Core::IEditor *editor);
void editorAboutToClose(Core::IEditor *editor);
void uiEditorContentsChanged();
void uiDocumentContentsChanged();
void buildStateChanged(ProjectExplorer::Project *project);
void updateRunConfigurations();
......
......@@ -201,7 +201,7 @@ void DesignMode::currentEditorChanged(Core::IEditor *editor)
bool mimeEditorAvailable = false;
if (editor && editor->document()) {
if (editor) {
const QString mimeType = editor->document()->mimeType();
if (!mimeType.isEmpty()) {
foreach (DesignEditorInfo *editorInfo, d->m_editors) {
......@@ -220,7 +220,7 @@ void DesignMode::currentEditorChanged(Core::IEditor *editor)
}
}
if (d->m_currentEditor)
disconnect(d->m_currentEditor.data(), SIGNAL(changed()), this, SLOT(updateActions()));
disconnect(d->m_currentEditor.data()->document(), SIGNAL(changed()), this, SLOT(updateActions()));
if (!mimeEditorAvailable) {
setActiveContext(Context());
......@@ -233,7 +233,7 @@ void DesignMode::currentEditorChanged(Core::IEditor *editor)
d->m_currentEditor = editor;
if (d->m_currentEditor)
connect(d->m_currentEditor.data(), SIGNAL(changed()), this, SLOT(updateActions()));
connect(d->m_currentEditor.data()->document(), SIGNAL(changed()), this, SLOT(updateActions()));
emit actionsUpdated(d->m_currentEditor.data());
}
......
......@@ -1468,7 +1468,7 @@ IEditor *EditorManager::createEditor(const Id &editorId, const QString &fileName
IEditor *editor = factories.front()->createEditor(m_instance);
if (editor)
connect(editor, SIGNAL(changed()), m_instance, SLOT(handleEditorStateChange()));
connect(editor->document(), SIGNAL(changed()), m_instance, SLOT(handleDocumentStateChange()));
if (editor)
emit m_instance->editorCreated(editor, fileName);
return editor;
......@@ -1718,7 +1718,7 @@ IEditor *EditorManager::openEditorWithContents(const Id &editorId,
foreach (IEditor *editor, m_instance->openedEditors()) {
QString name = editor->document()->filePath();
if (name.isEmpty())
name = editor->displayName();
name = editor->document()->displayName();
else
name = QFileInfo(name).completeBaseName();
docnames << name;
......@@ -1747,10 +1747,10 @@ IEditor *EditorManager::openEditorWithContents(const Id &editorId,
return 0;
}
if (title.isEmpty())
title = edt->displayName();
if (!title.isEmpty())
edt->document()->setDisplayName(title);
edt->setDisplayName(title);
m_instance->addEditor(edt);
QApplication::restoreOverrideCursor();
return edt;
......@@ -1966,7 +1966,7 @@ void EditorManager::updateWindowTitle()
windowTitle.prepend(d->m_titleAddition + dashSep);
IEditor *curEditor = currentEditor();
if (curEditor) {
QString editorName = curEditor->displayName();
QString editorName = curEditor->document()->displayName();
if (!editorName.isEmpty())
windowTitle.prepend(editorName + dashSep);
QString filePath = QFileInfo(curEditor->document()->filePath()).absoluteFilePath();
......@@ -1978,16 +1978,16 @@ void EditorManager::updateWindowTitle()
ICore::mainWindow()->setWindowTitle(windowTitle);
}
void EditorManager::handleEditorStateChange()
void EditorManager::handleDocumentStateChange()
{
updateActions();
IEditor *theEditor = qobject_cast<IEditor *>(sender());
if (!theEditor->document()->isModified())
theEditor->document()->removeAutoSaveFile();
IDocument *document= qobject_cast<IDocument *>(sender());
if (!document->isModified())
document->removeAutoSaveFile();
IEditor *currEditor = currentEditor();
if (theEditor == currEditor) {
if (currEditor && currEditor->document() == document) {
updateWindowTitle();
emit currentEditorStateChanged(currEditor);
emit currentDocumentStateChanged();
}
}
......@@ -2032,21 +2032,6 @@ void EditorManager::updateMakeWritableWarning()
}
}
QString EditorManager::fileNameForEditor(IEditor *editor)
{
QString fileName;
if (editor) {
if (!editor->document()->filePath().isEmpty()) {
QFileInfo fileInfo(editor->document()->filePath());
fileName = fileInfo.fileName();
} else {
fileName = editor->displayName();
}
}
return fileName;
}
void EditorManager::setupSaveActions(IEditor *editor, QAction *saveAction, QAction *saveAsAction, QAction *revertToSavedAction)
{
saveAction->setEnabled(editor != 0 && editor->document()->isModified());
......@@ -2054,12 +2039,11 @@ void EditorManager::setupSaveActions(IEditor *editor, QAction *saveAction, QActi
revertToSavedAction->setEnabled(editor != 0
&& !editor->document()->filePath().isEmpty() && editor->document()->isModified());
const QString fileName = fileNameForEditor(editor);
const QString documentName = editor ? editor->document()->displayName() : QString();
QString quotedName;
if (!fileName.isEmpty())
quotedName = QLatin1Char('"') + fileName + QLatin1Char('"');
if (!quotedName.isEmpty()) {
if (!documentName.isEmpty()) {
quotedName = QLatin1Char('"') + documentName + QLatin1Char('"');
saveAction->setText(tr("&Save %1").arg(quotedName));
saveAsAction->setText(tr("Save %1 &As...").arg(quotedName));
revertToSavedAction->setText(tr("Revert %1 to Saved").arg(quotedName));
......@@ -2069,7 +2053,6 @@ void EditorManager::setupSaveActions(IEditor *editor, QAction *saveAction, QActi
void EditorManager::updateActions()
{
IEditor *curEditor = currentEditor();
const QString fileName = fileNameForEditor(curEditor);
int openedCount = d->m_editorModel->openDocumentCount();
if (curEditor) {
......@@ -2084,8 +2067,8 @@ void EditorManager::updateActions()
setCloseSplitEnabled(root, root->isSplitter());
QString quotedName;
if (!fileName.isEmpty())
quotedName = QLatin1Char('"') + fileName + QLatin1Char('"');
if (curEditor)
quotedName = QLatin1Char('"') + curEditor->document()->displayName() + QLatin1Char('"');
setupSaveActions(curEditor, d->m_saveAction, d->m_saveAsAction, d->m_revertToSavedAction);
d->m_closeCurrentEditorAction->setEnabled(curEditor != 0);
......@@ -2457,7 +2440,6 @@ Core::IEditor *EditorManager::duplicateEditor(Core::IEditor *editor)
IEditor *duplicate = editor->duplicate(0);
duplicate->restoreState(editor->saveState());
connect(duplicate, SIGNAL(changed()), this, SLOT(handleEditorStateChange()));
emit editorCreated(duplicate, duplicate->document()->filePath());
addEditor(duplicate, true);
return duplicate;
......
......@@ -188,7 +188,7 @@ public:
signals:
void currentEditorChanged(Core::IEditor *editor);
void currentEditorStateChanged(Core::IEditor *editor);
void currentDocumentStateChanged();
void editorCreated(Core::IEditor *editor, const QString &fileName);
void editorOpened(Core::IEditor *editor);
void editorAboutToClose(Core::IEditor *editor);
......@@ -213,7 +213,7 @@ private slots:
void makeCurrentEditorWritable();
void vcsOpenCurrentEditor();
void updateWindowTitle();
void handleEditorStateChange();
void handleDocumentStateChange();
void updateVariable(const QByteArray &variable);
void autoSave();
......@@ -279,7 +279,6 @@ private:
void updateAutoSave();
void setCloseSplitEnabled(Internal::SplitterOrView *splitterOrView, bool enable);
void updateMakeWritableWarning();
QString fileNameForEditor(IEditor *editor);
void setupSaveActions(IEditor *editor, QAction *saveAction, QAction *saveAsAction, QAction *revertToSavedAction);
friend class Core::Internal::MainWindow;
......
......@@ -45,8 +45,6 @@
\list
\li displayName() is used as a user visible description of the document (usually filename w/o path).
\li kind() must be the same value as the kind() of the corresponding EditorFactory.
\li The changed() signal should be emitted when the modified state of the document changes
(so /bold{not} every time the document changes, but /bold{only once}).
\li If duplication is supported, you need to ensure that all duplicates
return the same file().
\li QString preferredMode() const is the mode the editor manager should activate.
......
......@@ -51,8 +51,6 @@ public:
virtual bool open(QString *errorString, const QString &fileName, const QString &realFileName) = 0;
virtual IDocument *document() = 0;
virtual Core::Id id() const = 0;
virtual QString displayName() const = 0;
virtual void setDisplayName(const QString &title) = 0;
virtual bool duplicateSupported() const { return false; }
virtual IEditor *duplicate(QWidget * /*parent*/) { return 0; }
......@@ -69,9 +67,6 @@ public:
virtual QWidget *toolBar() = 0;
virtual bool isDesignModePreferred() const { return false; }
signals:
void changed();
};
} // namespace Core
......
......@@ -85,7 +85,7 @@ QString OpenEditorsModel::Entry::fileName() const {
}
QString OpenEditorsModel::Entry::displayName() const {
return editor ? editor->displayName() : m_displayName;
return editor ? editor->document()->displayName() : m_displayName;
}
Id OpenEditorsModel::Entry::id() const
......@@ -156,7 +156,7 @@ void OpenEditorsModel::addEntry(Entry *entry)
if (previousIndex >= 0) {
if (entry->editor && d->m_editors.at(previousIndex)->editor == 0) {
d->m_editors[previousIndex] = entry;
connect(entry->editor, SIGNAL(changed()), this, SLOT(itemChanged()));
connect(entry->editor->document(), SIGNAL(changed()), this, SLOT(itemChanged()));
}
return;
}
......@@ -171,10 +171,19 @@ void OpenEditorsModel::addEntry(Entry *entry)
beginInsertRows(QModelIndex(), row, row);
d->m_editors.insert(index, entry);
if (entry->editor)
connect(entry->editor, SIGNAL(changed()), this, SLOT(itemChanged()));
connect(entry->editor->document(), SIGNAL(changed()), this, SLOT(itemChanged()));
endInsertRows();
}
int OpenEditorsModel::findDocument(IDocument *document) const
{
for (int i = 0; i < d->m_editors.count(); ++i) {
IEditor *editor = d->m_editors.at(i)->editor;
if (editor && editor->document() == document)
return i;
}
return -1;
}
int OpenEditorsModel::findEditor(IEditor *editor) const
{
......@@ -223,7 +232,7 @@ void OpenEditorsModel::removeEditor(int idx)
d->m_editors.removeAt(idx);
endRemoveRows();
if (editor)
disconnect(editor, SIGNAL(changed()), this, SLOT(itemChanged()));
disconnect(editor->document(), SIGNAL(changed()), this, SLOT(itemChanged()));
}
void OpenEditorsModel::removeAllRestoredEditors()
......@@ -271,8 +280,6 @@ void OpenEditorsModel::makeOriginal(IEditor *duplicate)
d->m_editors[i]->editor = duplicate;
d->m_duplicateEditors.removeOne(duplicate);
d->m_duplicateEditors.append(original);
disconnect(original, SIGNAL(changed()), this, SLOT(itemChanged()));
connect(duplicate, SIGNAL(changed()), this, SLOT(itemChanged()));
}
int OpenEditorsModel::indexOfEditor(IEditor *editor) const
......@@ -282,15 +289,6 @@ int OpenEditorsModel::indexOfEditor(IEditor *editor) const
return findEditor(editor);
}
void OpenEditorsModel::emitDataChanged(IEditor *editor)
{
int idx = findEditor(editor);
if (idx < 0)
return;
QModelIndex mindex = index(idx + 1/*<no document>*/, 0);
emit dataChanged(mindex, mindex);
}
QModelIndex OpenEditorsModel::index(int row, int column, const QModelIndex &parent) const
{
Q_UNUSED(parent)
......@@ -369,17 +367,15 @@ int OpenEditorsModel::rowOfEditor(IEditor *editor) const
return findEditor(originalForDuplicate(editor)) + 1/*<no document>*/;
}
QString OpenEditorsModel::displayNameForDocument(IDocument *document) const
{
for (int i = 0; i < d->m_editors.count(); ++i)
if (d->m_editors.at(i)->editor && d->m_editors.at(i)->editor->document() == document)
return d->m_editors.at(i)->editor->displayName();
return QString();
}
void OpenEditorsModel::itemChanged()
{
emitDataChanged(qobject_cast<IEditor*>(sender()));
IDocument *document = qobject_cast<IDocument *>(sender());
int idx = findDocument(document);
if (idx < 0)
return;
QModelIndex mindex = index(idx + 1/*<no document>*/, 0);
emit dataChanged(mindex, mindex);
}
QList<OpenEditorsModel::Entry *> OpenEditorsModel::entries() const
......
......@@ -95,17 +95,15 @@ public:
void makeOriginal(IEditor *duplicate);
int indexOfEditor(IEditor *editor) const;
QString displayNameForDocument(IDocument *document) const;
private slots:
void itemChanged();
private:
void addEntry(Entry *entry);
int findDocument(IDocument *document) const;
int findEditor(IEditor *editor) const;
int findFileName(const QString &filename) const;
void removeEditor(int idx);
void emitDataChanged(IEditor *editor);
OpenEditorsModelPrivate *d;
};
......
......@@ -255,7 +255,7 @@ void OpenEditorsWindow::addHistoryItems(const QList<EditLocation> &history, Edit
if (hi.document.isNull() || documentsDone.contains(hi.document))
continue;
documentsDone.insert(hi.document.data());
QString title = model->displayNameForDocument(hi.document);
QString title = hi.document->displayName();
QTC_ASSERT(!title.isEmpty(), continue);
QTreeWidgetItem *item = new QTreeWidgetItem();
if (hi.document->isModified())
......
......@@ -207,7 +207,7 @@ EditorToolBar::~EditorToolBar()
void EditorToolBar::removeToolbarForEditor(IEditor *editor)
{
QTC_ASSERT(editor, return);
disconnect(editor, SIGNAL(changed()), this, SLOT(checkEditorStatus()));
disconnect(editor->document(), SIGNAL(changed()), this, SLOT(checkEditorStatus()));
QWidget *toolBar = editor->toolBar();
if (toolBar != 0) {
......@@ -245,7 +245,7 @@ void EditorToolBar::closeEditor()
void EditorToolBar::addEditor(IEditor *editor)
{
QTC_ASSERT(editor, return);
connect(editor, SIGNAL(changed()), this, SLOT(checkEditorStatus()));
connect(editor->document(), SIGNAL(changed()), this, SLOT(checkEditorStatus()));
QWidget *toolBar = editor->toolBar();
if (toolBar && !d->m_isStandalone)
......@@ -394,7 +394,7 @@ void EditorToolBar::updateEditorStatus(IEditor *editor)
if (editor == current)
d->m_editorList->setToolTip(
current->document()->filePath().isEmpty()
? current->displayName()
? current->document()->displayName()
: QDir::toNativeSeparators(editor->document()->filePath())
);
}
......
......@@ -133,4 +133,31 @@ void IDocument::setFilePath(const QString &filePath)
emit changed();
}
/*!
Returns the string to display for this document, e.g. in the open document combo box
and pane.
\sa setDisplayName()
*/
QString IDocument::displayName() const
{
if (!m_displayName.isEmpty())
return m_displayName;
return QFileInfo(m_filePath).fileName();
}
/*!
Sets the string that is displayed for this document, e.g. in the open document combo box
and pane, to \a name. Defaults to the file name of the file path for this document.
You can reset the display name to the default by passing an empty string.
\sa displayName()
\sa filePath()
*/
void IDocument::setDisplayName(const QString &name)
{
if (name == m_displayName)
return;
m_displayName = name;
emit changed();
}
} // namespace Core
......@@ -84,6 +84,9 @@ public:
virtual bool save(QString *errorString, const QString &fileName = QString(), bool autoSave = false) = 0;
QString filePath() const { return m_filePath; }
virtual void setFilePath(const QString &filePath);
QString displayName() const;
void setDisplayName(const QString &name);
virtual bool isFileReadOnly() const;
virtual QString defaultPath() const = 0;
......@@ -118,6 +121,7 @@ signals:
private:
QString m_filePath;
QString m_displayName;
QString m_autoSaveName;
InfoBar *m_infoBar;
bool m_hasWriteWarning;
......
......@@ -382,7 +382,7 @@ void CodepasterPlugin::finishFetch(const QString &titleDescription,
// Open editor with title.
Core::IEditor *editor = EditorManager::openEditor(fileName);
QTC_ASSERT(editor, return);
editor->setDisplayName(titleDescription);
editor->document()->setDisplayName(titleDescription);
}
CodepasterPlugin *CodepasterPlugin::instance()
......