Editors: Move id() from editor to document.

Change-Id: Ib81076842ab1c16832224790194b001206404d64
Reviewed-by: hjk <hjk121@nokiamail.com>
Reviewed-by: Eike Ziller <eike.ziller@digia.com>
This commit is contained in:
Eike Ziller
2014-03-05 15:58:12 +01:00
parent 424a5c1489
commit 5dd8d7cd9c
58 changed files with 96 additions and 78 deletions

View File

@@ -1432,7 +1432,7 @@ void DocumentManager::executeOpenWithMenuAction(QAction *action)
= EditorManager::documentModel()->editorsForFilePath(entry.fileName);
if (!editorsOpenForFile.isEmpty()) {
foreach (IEditor *openEditor, editorsOpenForFile) {
if (entry.editorFactory->id() == openEditor->id())
if (entry.editorFactory->id() == openEditor->document()->id())
editorsOpenForFile.removeAll(openEditor);
}
if (!EditorManager::closeEditors(editorsOpenForFile)) // don't open if cancel was pressed

View File

@@ -137,7 +137,7 @@ void DocumentModel::addEditor(IEditor *editor, bool *isNewDocument)
if (isNew) {
Entry *entry = new Entry;
entry->document = editor->document();
entry->m_id = editor->id();
entry->m_id = editor->document()->id();
addEntry(entry);
}
}

View File

@@ -1419,7 +1419,7 @@ IEditor *EditorManager::createEditor(const Id &editorId, const QString &fileName
IEditor *editor = factories.front()->createEditor();
if (editor) {
QTC_CHECK(editor->id().isValid()); // sanity check that the editor has an id set
QTC_CHECK(editor->document()->id().isValid()); // sanity check that the editor has an id set
connect(editor->document(), SIGNAL(changed()), m_instance, SLOT(handleDocumentStateChange()));
emit m_instance->editorCreated(editor, fileName);
}
@@ -1440,7 +1440,8 @@ void EditorManager::addEditor(IEditor *editor)
const bool addWatcher = !isTemporary;
DocumentManager::addDocument(editor->document(), addWatcher);
if (!isTemporary)
DocumentManager::addToRecentFiles(editor->document()->filePath(), editor->id());
DocumentManager::addToRecentFiles(editor->document()->filePath(),
editor->document()->id());
}
emit m_instance->editorOpened(editor);
}

View File

@@ -209,7 +209,7 @@ void EditorView::updateEditorHistory(IEditor *editor, QList<EditLocation> &histo
EditLocation location;
location.document = document;
location.fileName = document->filePath();
location.id = editor->id();
location.id = document->id();
location.state = QVariant(state);
for (int i = 0; i < history.size(); ++i) {
@@ -405,7 +405,7 @@ void EditorView::addCurrentPositionToNavigationHistory(IEditor *editor, const QB
EditLocation location;
location.document = document;
location.fileName = document->filePath();
location.id = editor->id();
location.id = document->id();
location.state = QVariant(state);
m_currentNavigationHistoryPosition = qMin(m_currentNavigationHistoryPosition, m_navigationHistory.size()); // paranoia
m_navigationHistory.insert(m_currentNavigationHistoryPosition, location);
@@ -460,7 +460,7 @@ void EditorView::updateCurrentPositionInNavigationHistory()
}
location->document = document;
location->fileName = document->filePath();
location->id = editor->id();
location->id = document->id();
location->state = QVariant(editor->saveState());
}
@@ -769,10 +769,10 @@ QByteArray SplitterOrView::saveState() const
stream << QByteArray("empty");
} else if (e == EditorManager::currentEditor()) {
stream << QByteArray("currenteditor")
<< e->document()->filePath() << e->id().toString() << e->saveState();
<< e->document()->filePath() << e->document()->id().toString() << e->saveState();
} else {
stream << QByteArray("editor")
<< e->document()->filePath() << e->id().toString() << e->saveState();
<< e->document()->filePath() << e->document()->id().toString() << e->saveState();
}
}
return bytes;

View File

@@ -56,14 +56,3 @@
\sa Core::EditorFactoryInterface Core::IContext
*/
void Core::IEditor::setId(Core::Id id)
{
m_id = id;
}
Core::Id Core::IEditor::id() const
{
return m_id;
}

View File

@@ -47,9 +47,6 @@ public:
IEditor(QObject *parent = 0) : IContext(parent) {}
virtual ~IEditor() {}
void setId(Core::Id id);
Core::Id id() const;
virtual bool open(QString *errorString, const QString &fileName, const QString &realFileName) = 0;
virtual IDocument *document() = 0;

View File

@@ -31,6 +31,8 @@
#include "infobar.h"
#include <utils/qtcassert.h>
#include <QFile>
#include <QFileInfo>
@@ -73,6 +75,17 @@ IDocument::~IDocument()
delete m_infoBar;
}
void IDocument::setId(Id id)
{
m_id = id;
}
Id IDocument::id() const
{
QTC_CHECK(m_id.isValid());
return m_id;
}
/*!
Used for example by EditorManager::openEditorWithContents() to set the contents
of this document.

View File

@@ -31,6 +31,8 @@
#define IDOCUMENT_H
#include "core_global.h"
#include "id.h"
#include <QObject>
namespace Core {
@@ -75,6 +77,9 @@ public:
IDocument(QObject *parent = 0);
virtual ~IDocument();
void setId(Core::Id id);
Core::Id id() const;
virtual bool save(QString *errorString, const QString &fileName = QString(), bool autoSave = false) = 0;
virtual bool setContents(const QByteArray &contents);
@@ -118,6 +123,7 @@ signals:
void filePathChanged(const QString &oldName, const QString &newName);
private:
Id m_id;
QString m_filePath;
QString m_displayName;
bool m_temporary;