Commit 5dd8d7cd authored by Eike Ziller's avatar Eike Ziller
Browse files

Editors: Move id() from editor to document.



Change-Id: Ib81076842ab1c16832224790194b001206404d64
Reviewed-by: default avatarhjk <hjk121@nokiamail.com>
Reviewed-by: default avatarEike Ziller <eike.ziller@digia.com>
parent 424a5c14
......@@ -44,6 +44,7 @@ AndroidManifestDocument::AndroidManifestDocument(AndroidManifestEditorWidget *ed
: TextEditor::PlainTextDocument(),
m_editorWidget(editorWidget)
{
setId(Constants::ANDROID_MANIFEST_EDITOR_ID);
setMimeType(QLatin1String(Constants::ANDROID_MANIFEST_MIME_TYPE));
connect(editorWidget, SIGNAL(guiChanged()),
this, SIGNAL(changed()));
......
......@@ -44,8 +44,6 @@ using namespace Internal;
Android::Internal::AndroidManifestEditor::AndroidManifestEditor(AndroidManifestEditorWidget *editorWidget)
: Core::IEditor(editorWidget), m_toolBar(0)
{
setId(Constants::ANDROID_MANIFEST_EDITOR_ID);
m_toolBar = new QToolBar(editorWidget);
m_actionGroup = new QActionGroup(this);
connect(m_actionGroup, SIGNAL(triggered(QAction*)), this, SLOT(changeEditorPage(QAction*)));
......
......@@ -52,7 +52,6 @@ using namespace Android::Internal;
JavaEditor::JavaEditor(JavaEditorWidget *editor)
: BaseTextEditor(editor)
{
setId(Constants::JAVA_EDITOR_ID);
setContext(Core::Context(Constants::C_JAVA_EDITOR,
TextEditor::Constants::C_TEXTEDITOR));
}
......@@ -112,6 +111,7 @@ TextEditor::BaseTextEditor *JavaEditorWidget::createEditor()
JavaDocument::JavaDocument()
: TextEditor::BaseTextDocument()
{
setId(Constants::JAVA_EDITOR_ID);
setMimeType(QLatin1String(Constants::JAVA_MIMETYPE));
setSyntaxHighlighter(TextEditor::createGenericSyntaxHighlighter(Core::MimeDatabase::findByType(QLatin1String(Constants::JAVA_MIMETYPE))));
setIndenter(new JavaIndenter);
......
......@@ -40,6 +40,7 @@ AutotoolsProjectFile::AutotoolsProjectFile(AutotoolsProject *project, const QStr
Core::IDocument(project),
m_project(project)
{
setId("Autotools.ProjectFile");
setFilePath(fileName);
}
......
......@@ -43,6 +43,7 @@
#include <coreplugin/editormanager/ieditor.h>
#include <coreplugin/icontext.h>
#include <coreplugin/icore.h>
#include <coreplugin/idocument.h>
#include <cppeditor/cppeditorconstants.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/project.h>
......@@ -86,7 +87,7 @@ bool ArtisticStyle::initialize()
void ArtisticStyle::updateActions(Core::IEditor *editor)
{
m_formatFile->setEnabled(editor && editor->id() == CppEditor::Constants::CPPEDITOR_ID);
m_formatFile->setEnabled(editor && editor->document()->id() == CppEditor::Constants::CPPEDITOR_ID);
}
QList<QObject *> ArtisticStyle::autoReleaseObjects()
......
......@@ -43,6 +43,7 @@
#include <coreplugin/editormanager/ieditor.h>
#include <coreplugin/icontext.h>
#include <coreplugin/icore.h>
#include <coreplugin/idocument.h>
#include <cppeditor/cppeditorconstants.h>
#include <texteditor/basetexteditor.h>
......@@ -91,7 +92,7 @@ bool ClangFormat::initialize()
void ClangFormat::updateActions(Core::IEditor *editor)
{
const bool enabled = (editor && editor->id() == CppEditor::Constants::CPPEDITOR_ID);
const bool enabled = (editor && editor->document()->id() == CppEditor::Constants::CPPEDITOR_ID);
m_formatFile->setEnabled(enabled);
m_formatRange->setEnabled(enabled);
}
......
......@@ -43,6 +43,7 @@
#include <coreplugin/editormanager/ieditor.h>
#include <coreplugin/icontext.h>
#include <coreplugin/icore.h>
#include <coreplugin/idocument.h>
#include <cppeditor/cppeditorconstants.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/project.h>
......@@ -86,7 +87,7 @@ bool Uncrustify::initialize()
void Uncrustify::updateActions(Core::IEditor *editor)
{
m_formatFile->setEnabled(editor && editor->id() == CppEditor::Constants::CPPEDITOR_ID);
m_formatFile->setEnabled(editor && editor->document()->id() == CppEditor::Constants::CPPEDITOR_ID);
}
QList<QObject *> Uncrustify::autoReleaseObjects()
......
......@@ -205,6 +205,7 @@ public:
BinEditorDocument(BinEditorWidget *parent) :
Core::IDocument(parent)
{
setId(Core::Constants::K_DEFAULT_BINARY_EDITOR_ID);
m_widget = parent;
connect(m_widget, SIGNAL(dataRequested(quint64)),
this, SLOT(provideData(quint64)));
......@@ -340,7 +341,6 @@ class BinEditor : public Core::IEditor
public:
BinEditor(BinEditorWidget *widget)
{
setId(Core::Constants::K_DEFAULT_BINARY_EDITOR_ID);
setWidget(widget);
m_widget = widget;
m_file = new BinEditorDocument(m_widget);
......
......@@ -59,7 +59,6 @@ using namespace CMakeProjectManager::Internal;
CMakeEditor::CMakeEditor(CMakeEditorWidget *editor)
: BaseTextEditor(editor)
{
setId(CMakeProjectManager::Constants::CMAKE_EDITOR_ID);
setContext(Core::Context(CMakeProjectManager::Constants::C_CMAKEEDITOR,
TextEditor::Constants::C_TEXTEDITOR));
connect(document(), SIGNAL(changed()), this, SLOT(markAsChanged()));
......@@ -227,6 +226,7 @@ CMakeEditorWidget::Link CMakeEditorWidget::findLinkAt(const QTextCursor &cursor,
CMakeDocument::CMakeDocument()
: TextEditor::BaseTextDocument()
{
setId(CMakeProjectManager::Constants::CMAKE_EDITOR_ID);
setMimeType(QLatin1String(CMakeProjectManager::Constants::CMAKEMIMETYPE));
setSyntaxHighlighter(new CMakeHighlighter);
}
......
......@@ -763,6 +763,7 @@ void CMakeProject::createUiCodeModelSupport()
CMakeFile::CMakeFile(CMakeProject *parent, QString fileName)
: Core::IDocument(parent), m_project(parent)
{
setId("Cmake.ProjectFile");
setFilePath(fileName);
}
......
......@@ -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
......
......@@ -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);
}
}
......
......@@ -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);
}
......
......@@ -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;
......
......@@ -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;
}
......@@ -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;
......
......@@ -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.
......
......@@ -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;
......
......@@ -504,7 +504,6 @@ bool handleDoxygenContinuation(QTextCursor &cursor,
CPPEditor::CPPEditor(CPPEditorWidget *editor)
: BaseTextEditor(editor)
{
setId(CppEditor::Constants::CPPEDITOR_ID);
m_context.add(CppEditor::Constants::C_CPPEDITOR);
m_context.add(ProjectExplorer::Constants::LANG_CXX);
m_context.add(TextEditor::Constants::C_TEXTEDITOR);
......@@ -1966,6 +1965,7 @@ void CPPEditorWidget::showPreProcessorWidget()
CPPEditorDocument::CPPEditorDocument()
{
setId(CppEditor::Constants::CPPEDITOR_ID);
connect(this, SIGNAL(tabSettingsChanged()),
this, SLOT(invalidateFormatterCache()));
connect(this, SIGNAL(mimeTypeChanged()),
......
......@@ -111,10 +111,11 @@ bool QmlCppEngine::canDisplayTooltip() const
bool QmlCppEngine::setToolTipExpression(const QPoint & mousePos,
TextEditor::ITextEditor *editor, const DebuggerToolTipContext &ctx)
{
QTC_ASSERT(editor, return false);
bool success = false;
if (editor->id() == CppEditor::Constants::CPPEDITOR_ID)
if (editor->document()->id() == CppEditor::Constants::CPPEDITOR_ID)
success = d->m_cppEngine->setToolTipExpression(mousePos, editor, ctx);
else if (editor->id() == QmlJSEditor::Constants::C_QMLJSEDITOR_ID)
else if (editor->document()->id() == QmlJSEditor::Constants::C_QMLJSEDITOR_ID)
success = d->m_qmlEngine->setToolTipExpression(mousePos, editor, ctx);
return success;
}
......
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