Commit 944b6dad authored by hjk's avatar hjk
Browse files

texteditor: return information on whether openEditor actually created an

editor or re-used an existing one
parent f7e0366d
......@@ -1135,13 +1135,13 @@ static QString formatFileFilters(const Core::ICore *core, QString *selectedFilte
}
IEditor *EditorManager::openEditor(const QString &fileName, const QString &editorId,
OpenEditorFlags flags)
OpenEditorFlags flags, bool *newEditor)
{
return openEditor(0, fileName, editorId, flags);
return openEditor(0, fileName, editorId, flags, newEditor);
}
IEditor *EditorManager::openEditor(Core::Internal::EditorView *view, const QString &fileName,
const QString &editorId, OpenEditorFlags flags)
const QString &editorId, OpenEditorFlags flags, bool *newEditor)
{
if (debugEditorManager)
qDebug() << Q_FUNC_INFO << fileName << editorId;
......@@ -1149,10 +1149,13 @@ IEditor *EditorManager::openEditor(Core::Internal::EditorView *view, const QStri
if (fileName.isEmpty())
return 0;
if (newEditor)
*newEditor = false;
const QList<IEditor *> editors = editorsForFileName(fileName);
if (!editors.isEmpty()) {
if (!editors.isEmpty())
return activateEditor(view, editors.first(), flags);
}
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
IEditor *editor = createEditor(editorId, fileName);
// If we could not open the file in the requested editor, fall
......@@ -1168,7 +1171,10 @@ IEditor *EditorManager::openEditor(Core::Internal::EditorView *view, const QStri
}
addEditor(editor);
IEditor *result= activateEditor(view, editor, flags);
if (newEditor)
*newEditor = true;
IEditor *result = activateEditor(view, editor, flags);
if (editor == result)
restoreEditorState(editor);
QApplication::restoreOverrideCursor();
......
......@@ -118,7 +118,8 @@ public:
IEditor *openEditor(const QString &fileName,
const QString &editorId = QString(),
OpenEditorFlags flags = 0);
OpenEditorFlags flags = 0,
bool *newEditor = 0);
IEditor *openEditorWithContents(const QString &editorId,
QString *titlePattern = 0,
const QString &contents = QString());
......@@ -249,7 +250,8 @@ private:
IEditor *activateEditor(Core::Internal::EditorView *view, Core::IEditor *editor, OpenEditorFlags flags = 0);
IEditor *openEditor(Core::Internal::EditorView *view, const QString &fileName,
const QString &editorId = QString(),
OpenEditorFlags flags = 0);
OpenEditorFlags flags = 0,
bool *newEditor = 0);
Core::Internal::SplitterOrView *currentSplitterOrView() const;
void closeEditor(Core::IEditor *editor);
......
......@@ -1199,7 +1199,8 @@ void DebuggerPlugin::resetLocation()
void DebuggerPlugin::gotoLocation(const QString &file, int line, bool setMarker)
{
TextEditor::BaseTextEditor::openEditorAt(file, line);
bool newEditor = false;
TextEditor::BaseTextEditor::openEditorAt(file, line, 0, QString(), &newEditor);
if (setMarker) {
resetLocation();
m_locationMark = new LocationMark(file, line);
......
......@@ -125,11 +125,13 @@ protected:
ITextEditor *BaseTextEditor::openEditorAt(const QString &fileName,
int line,
int column,
const QString &editorKind)
const QString &editorKind,
bool *newEditor)
{
Core::EditorManager *editorManager = Core::EditorManager::instance();
editorManager->addCurrentPositionToNavigationHistory();
Core::IEditor *editor = editorManager->openEditor(fileName, editorKind, Core::EditorManager::IgnoreNavigationHistory);
Core::IEditor *editor = editorManager->openEditor(fileName, editorKind,
Core::EditorManager::IgnoreNavigationHistory, newEditor);
TextEditor::ITextEditor *texteditor = qobject_cast<TextEditor::ITextEditor *>(editor);
if (texteditor) {
texteditor->gotoLine(line, column);
......
......@@ -291,7 +291,8 @@ public:
~BaseTextEditor();
static ITextEditor *openEditorAt(const QString &fileName, int line, int column = 0,
const QString &editorId = QString());
const QString &editorId = QString(),
bool *newEditor = 0);
const Utils::ChangeSet &changeSet() const;
void setChangeSet(const Utils::ChangeSet &changeSet);
......
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