forked from qt-creator/qt-creator
EditorManager: Small API clean-up
- Move private enum to private header - Add missing parameter to openEditorAtSearchResult - Remove convenience singular close* methods, we have {} nowadays Change-Id: Ic5b6d831a9f506ffee09b89b3358874433d62998 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -747,7 +747,7 @@ void BazaarPluginPrivate::commitFromEditor()
|
||||
// Close the submit editor
|
||||
m_submitActionTriggered = true;
|
||||
QTC_ASSERT(submitEditor(), return);
|
||||
EditorManager::closeDocument(submitEditor()->document());
|
||||
EditorManager::closeDocuments({submitEditor()->document()});
|
||||
}
|
||||
|
||||
void BazaarPluginPrivate::uncommit()
|
||||
|
@@ -198,7 +198,7 @@ OpenEditorAtCursorPosition::OpenEditorAtCursorPosition(const TestDocument &testD
|
||||
OpenEditorAtCursorPosition::~OpenEditorAtCursorPosition()
|
||||
{
|
||||
if (m_editor)
|
||||
Core::EditorManager::closeEditor(m_editor, /* askAboutModifiedEditors= */ false);
|
||||
Core::EditorManager::closeEditors({m_editor}, /* askAboutModifiedEditors= */ false);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -1643,7 +1643,7 @@ void ClearCasePluginPrivate::commitFromEditor()
|
||||
{
|
||||
m_submitActionTriggered = true;
|
||||
QTC_ASSERT(submitEditor(), return);
|
||||
EditorManager::closeDocument(submitEditor()->document());
|
||||
EditorManager::closeDocuments({submitEditor()->document()});
|
||||
}
|
||||
|
||||
QString ClearCasePluginPrivate::runCleartoolSync(const QString &workingDir,
|
||||
@@ -2712,7 +2712,7 @@ public:
|
||||
|
||||
~TestCase()
|
||||
{
|
||||
EditorManager::closeDocument(m_editor->document(), false);
|
||||
EditorManager::closeDocuments({m_editor->document()}, false);
|
||||
QCoreApplication::processEvents(); // process any pending events
|
||||
|
||||
QFile file(m_fileName);
|
||||
|
@@ -1447,9 +1447,9 @@ void EditorManagerPrivate::closeEditorOrDocument(IEditor *editor)
|
||||
[&editor](IEditor *other) {
|
||||
return editor != other && other->document() == editor->document();
|
||||
})) {
|
||||
EditorManager::closeEditor(editor);
|
||||
EditorManager::closeEditors({editor});
|
||||
} else {
|
||||
EditorManager::closeDocument(editor->document());
|
||||
EditorManager::closeDocuments({editor->document()});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2239,7 +2239,7 @@ void EditorManagerPrivate::closeEditorFromContextMenu()
|
||||
} else {
|
||||
IDocument *document = d->m_contextMenuEntry ? d->m_contextMenuEntry->document : nullptr;
|
||||
if (document)
|
||||
EditorManager::closeDocument(document);
|
||||
EditorManager::closeDocuments({document});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2784,29 +2784,6 @@ void EditorManager::revertToSaved()
|
||||
EditorManagerPrivate::revertToSaved(currentDocument());
|
||||
}
|
||||
|
||||
/*!
|
||||
Closes \a editor. If \a askAboutModifiedEditors is \c true, prompts
|
||||
users to save their changes before closing the editor.
|
||||
*/
|
||||
void EditorManager::closeEditor(IEditor *editor, bool askAboutModifiedEditors)
|
||||
{
|
||||
if (editor)
|
||||
closeEditors({editor}, askAboutModifiedEditors);
|
||||
}
|
||||
|
||||
/*!
|
||||
Closes the document specified by \a entry.
|
||||
*/
|
||||
void EditorManager::closeDocument(DocumentModel::Entry *entry)
|
||||
{
|
||||
if (!entry)
|
||||
return;
|
||||
if (entry->isSuspended)
|
||||
DocumentModelPrivate::removeEntry(entry);
|
||||
else
|
||||
closeDocuments({entry->document});
|
||||
}
|
||||
|
||||
/*!
|
||||
Closes the documents specified by \a entries.
|
||||
|
||||
@@ -2914,15 +2891,22 @@ IEditor *EditorManager::openEditorAt(const QString &fileName, int line, int colu
|
||||
Opens the document at the position of the search hit \a item in the editor
|
||||
using the settings specified by \a flags.
|
||||
*/
|
||||
void EditorManager::openEditorAtSearchResult(const SearchResultItem &item, OpenEditorFlags flags)
|
||||
void EditorManager::openEditorAtSearchResult(const SearchResultItem &item,
|
||||
Id editorId,
|
||||
OpenEditorFlags flags,
|
||||
bool *newEditor)
|
||||
{
|
||||
if (item.path.empty()) {
|
||||
openEditor(QDir::fromNativeSeparators(item.text), Id(), flags);
|
||||
openEditor(QDir::fromNativeSeparators(item.text), editorId, flags, newEditor);
|
||||
return;
|
||||
}
|
||||
|
||||
openEditorAt(QDir::fromNativeSeparators(item.path.first()), item.mainRange.begin.line,
|
||||
item.mainRange.begin.column, Id(), flags);
|
||||
openEditorAt(QDir::fromNativeSeparators(item.path.first()),
|
||||
item.mainRange.begin.line,
|
||||
item.mainRange.begin.column,
|
||||
editorId,
|
||||
flags,
|
||||
newEditor);
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -3190,17 +3174,6 @@ QList<IEditor*> EditorManager::visibleEditors()
|
||||
return editors;
|
||||
}
|
||||
|
||||
/*!
|
||||
Closes \a document. If \a askAboutModifiedEditors is \c true, prompts
|
||||
users to save their changes before closing the document.
|
||||
|
||||
Returns whether the document was closed.
|
||||
*/
|
||||
bool EditorManager::closeDocument(IDocument *document, bool askAboutModifiedEditors)
|
||||
{
|
||||
return closeDocuments({document}, askAboutModifiedEditors);
|
||||
}
|
||||
|
||||
/*!
|
||||
Closes \a documents. If \a askAboutModifiedEditors is \c true, prompts
|
||||
users to save their changes before closing the documents.
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Copyright (C) 2020 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
@@ -47,13 +47,6 @@ namespace Core {
|
||||
class IDocument;
|
||||
class SearchResultItem;
|
||||
|
||||
enum MakeWritableResult {
|
||||
OpenedWithVersionControl,
|
||||
MadeWritable,
|
||||
SavedAs,
|
||||
Failed
|
||||
};
|
||||
|
||||
namespace Internal {
|
||||
class EditorManagerPrivate;
|
||||
class MainWindow;
|
||||
@@ -98,13 +91,17 @@ public:
|
||||
int lineNumber; // extracted line number, -1 if none
|
||||
int columnNumber; // extracted column number, -1 if none
|
||||
};
|
||||
|
||||
static FilePathInfo splitLineAndColumnNumber(const QString &filePath);
|
||||
static IEditor *openEditor(const QString &fileName, Utils::Id editorId = {},
|
||||
OpenEditorFlags flags = NoFlags, bool *newEditor = nullptr);
|
||||
static IEditor *openEditorAt(const QString &fileName, int line, int column = 0,
|
||||
Utils::Id editorId = {}, OpenEditorFlags flags = NoFlags,
|
||||
bool *newEditor = nullptr);
|
||||
static void openEditorAtSearchResult(const SearchResultItem &item, OpenEditorFlags flags = NoFlags);
|
||||
static void openEditorAtSearchResult(const SearchResultItem &item,
|
||||
Utils::Id editorId = {},
|
||||
OpenEditorFlags flags = NoFlags,
|
||||
bool *newEditor = nullptr);
|
||||
static IEditor *openEditorWithContents(Utils::Id editorId, QString *titlePattern = nullptr,
|
||||
const QByteArray &contents = QByteArray(),
|
||||
const QString &uniqueId = QString(),
|
||||
@@ -125,9 +122,7 @@ public:
|
||||
static void activateEditorForEntry(DocumentModel::Entry *entry, OpenEditorFlags flags = NoFlags);
|
||||
static IEditor *activateEditorForDocument(IDocument *document, OpenEditorFlags flags = NoFlags);
|
||||
|
||||
static bool closeDocument(IDocument *document, bool askAboutModifiedEditors = true);
|
||||
static bool closeDocuments(const QList<IDocument *> &documents, bool askAboutModifiedEditors = true);
|
||||
static void closeDocument(DocumentModel::Entry *entry);
|
||||
static bool closeDocuments(const QList<DocumentModel::Entry *> &entries);
|
||||
static void closeOtherDocuments(IDocument *document);
|
||||
static bool closeAllDocuments();
|
||||
@@ -139,7 +134,6 @@ public:
|
||||
static bool saveDocument(IDocument *document);
|
||||
|
||||
static bool closeEditors(const QList<IEditor *> &editorsToClose, bool askAboutModifiedEditors = true);
|
||||
static void closeEditor(IEditor *editor, bool askAboutModifiedEditors = true);
|
||||
|
||||
static QByteArray saveState();
|
||||
static bool restoreState(const QByteArray &state);
|
||||
|
@@ -57,6 +57,8 @@ class MainWindow;
|
||||
class OpenEditorsViewFactory;
|
||||
class OpenEditorsWindow;
|
||||
|
||||
enum MakeWritableResult { OpenedWithVersionControl, MadeWritable, SavedAs, Failed };
|
||||
|
||||
class EditorManagerPrivate : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@@ -106,8 +106,7 @@ void OpenEditorsWidget::activateEditor(const QModelIndex &index)
|
||||
|
||||
void OpenEditorsWidget::closeDocument(const QModelIndex &index)
|
||||
{
|
||||
EditorManager::closeDocument(
|
||||
DocumentModel::entryAtRow(m_model->mapToSource(index).row()));
|
||||
EditorManager::closeDocuments({DocumentModel::entryAtRow(m_model->mapToSource(index).row())});
|
||||
// work around selection changes
|
||||
updateCurrentItem(EditorManager::currentEditor());
|
||||
}
|
||||
|
@@ -666,7 +666,7 @@ void CppToolsPlugin::test_modelmanager_gc_if_last_cppeditor_closed()
|
||||
helper.waitForRefreshedSourceFiles();
|
||||
|
||||
// Close file/editor
|
||||
Core::EditorManager::closeDocument(editor->document(), /*askAboutModifiedEditors=*/ false);
|
||||
Core::EditorManager::closeDocuments({editor->document()}, /*askAboutModifiedEditors=*/false);
|
||||
helper.waitForFinishedGc();
|
||||
|
||||
// Check: File is removed from the snapshpt
|
||||
@@ -705,7 +705,7 @@ void CppToolsPlugin::test_modelmanager_dont_gc_opened_files()
|
||||
QVERIFY(mm->snapshot().contains(file));
|
||||
|
||||
// Close editor
|
||||
Core::EditorManager::closeDocument(editor->document());
|
||||
Core::EditorManager::closeDocuments({editor->document()});
|
||||
helper.waitForFinishedGc();
|
||||
QVERIFY(mm->snapshot().isEmpty());
|
||||
}
|
||||
|
@@ -1424,7 +1424,7 @@ void CvsPluginPrivate::commitFromEditor()
|
||||
{
|
||||
m_submitActionTriggered = true;
|
||||
QTC_ASSERT(submitEditor(), return);
|
||||
EditorManager::closeDocument(submitEditor()->document());
|
||||
EditorManager::closeDocuments({submitEditor()->document()});
|
||||
}
|
||||
|
||||
// Run CVS. At this point, file arguments must be relative to
|
||||
|
@@ -284,7 +284,7 @@ MemoryAgent::MemoryAgent(const MemoryViewSetupData &data, DebuggerEngine *engine
|
||||
MemoryAgent::~MemoryAgent()
|
||||
{
|
||||
if (m_service && m_service->editor())
|
||||
EditorManager::closeDocument(m_service->editor()->document());
|
||||
EditorManager::closeDocuments({m_service->editor()->document()});
|
||||
if (m_service && m_service->widget()) // m_service might be set to null by closeDocument
|
||||
m_service->widget()->close();
|
||||
}
|
||||
|
@@ -75,7 +75,7 @@ SourceAgentPrivate::SourceAgentPrivate()
|
||||
SourceAgentPrivate::~SourceAgentPrivate()
|
||||
{
|
||||
if (editor)
|
||||
EditorManager::closeDocument(editor->document());
|
||||
EditorManager::closeDocuments({editor->document()});
|
||||
editor = nullptr;
|
||||
delete locationMark;
|
||||
}
|
||||
|
@@ -2035,7 +2035,7 @@ void FakeVimPluginPrivate::handleDelayedQuit(bool forced, IEditor *editor)
|
||||
if (EditorManager::hasSplitter())
|
||||
triggerAction(Core::Constants::REMOVE_CURRENT_SPLIT);
|
||||
else
|
||||
EditorManager::closeEditor(editor, !forced);
|
||||
EditorManager::closeEditors({editor}, !forced);
|
||||
}
|
||||
|
||||
void FakeVimPluginPrivate::handleDelayedQuitAll(bool forced)
|
||||
|
@@ -1405,7 +1405,7 @@ void GitPluginPrivate::commitFromEditor()
|
||||
// Close the submit editor
|
||||
m_submitActionTriggered = true;
|
||||
QTC_ASSERT(submitEditor(), return);
|
||||
EditorManager::closeDocument(submitEditor()->document());
|
||||
EditorManager::closeDocuments({submitEditor()->document()});
|
||||
}
|
||||
|
||||
bool GitPluginPrivate::submitEditorAboutToClose()
|
||||
|
@@ -676,7 +676,7 @@ void MercurialPluginPrivate::commitFromEditor()
|
||||
// Close the submit editor
|
||||
m_submitActionTriggered = true;
|
||||
QTC_ASSERT(submitEditor(), return);
|
||||
Core::EditorManager::closeDocument(submitEditor()->document());
|
||||
Core::EditorManager::closeDocuments({submitEditor()->document()});
|
||||
}
|
||||
|
||||
bool MercurialPluginPrivate::submitEditorAboutToClose()
|
||||
|
@@ -1555,7 +1555,7 @@ void PerforcePluginPrivate::commitFromEditor()
|
||||
{
|
||||
m_submitActionTriggered = true;
|
||||
QTC_ASSERT(submitEditor(), return);
|
||||
EditorManager::closeDocument(submitEditor()->document());
|
||||
EditorManager::closeDocuments({submitEditor()->document()});
|
||||
}
|
||||
|
||||
void PerforcePluginPrivate::cleanCommitMessageFile()
|
||||
|
@@ -1010,7 +1010,7 @@ void SubversionPluginPrivate::commitFromEditor()
|
||||
{
|
||||
m_submitActionTriggered = true;
|
||||
QTC_ASSERT(submitEditor(), return);
|
||||
EditorManager::closeDocument(submitEditor()->document());
|
||||
EditorManager::closeDocuments({submitEditor()->document()});
|
||||
}
|
||||
|
||||
SubversionResponse SubversionPluginPrivate::runSvn(const QString &workingDir,
|
||||
|
@@ -450,7 +450,7 @@ void BaseFileFind::openEditor(SearchResult *result, const SearchResultItem &item
|
||||
IEditor *openedEditor =
|
||||
d->m_searchEngines[parameters.searchEngineIndex]->openEditor(item, parameters);
|
||||
if (!openedEditor)
|
||||
EditorManager::openEditorAtSearchResult(item, EditorManager::DoNotSwitchToDesignMode);
|
||||
EditorManager::openEditorAtSearchResult(item, Id(), EditorManager::DoNotSwitchToDesignMode);
|
||||
if (d->m_currentFindSupport)
|
||||
d->m_currentFindSupport->clearHighlights();
|
||||
d->m_currentFindSupport = nullptr;
|
||||
|
@@ -147,7 +147,7 @@ void Internal::TextEditorPlugin::testBlockSelectionTransformation()
|
||||
}
|
||||
QCOMPARE(textEditor->textDocument()->plainText(), transformedText);
|
||||
}
|
||||
Core::EditorManager::closeDocument(editor->document(), false);
|
||||
Core::EditorManager::closeDocuments({editor->document()}, false);
|
||||
}
|
||||
|
||||
static const char text[] =
|
||||
@@ -362,7 +362,7 @@ void Internal::TextEditorPlugin::testBlockSelectionInsert()
|
||||
|
||||
QCOMPARE(textEditor->textDocument()->plainText(), transformedText);
|
||||
}
|
||||
Core::EditorManager::closeDocument(editor->document(), false);
|
||||
Core::EditorManager::closeDocuments({editor->document()}, false);
|
||||
}
|
||||
|
||||
|
||||
@@ -440,7 +440,7 @@ void Internal::TextEditorPlugin::testBlockSelectionRemove()
|
||||
|
||||
QCOMPARE(textEditor->textDocument()->plainText(), transformedText);
|
||||
}
|
||||
Core::EditorManager::closeDocument(editor->document(), false);
|
||||
Core::EditorManager::closeDocuments({editor->document()}, false);
|
||||
}
|
||||
|
||||
void Internal::TextEditorPlugin::testBlockSelectionCopy_data()
|
||||
@@ -495,7 +495,7 @@ void Internal::TextEditorPlugin::testBlockSelectionCopy()
|
||||
|
||||
QCOMPARE(QGuiApplication::clipboard()->text(), copiedText);
|
||||
}
|
||||
Core::EditorManager::closeDocument(editor->document(), false);
|
||||
Core::EditorManager::closeDocuments({editor->document()}, false);
|
||||
}
|
||||
|
||||
QString tabPolicyToString(TabSettings::TabPolicy policy)
|
||||
|
Reference in New Issue
Block a user