forked from qt-creator/qt-creator
EditorManager: move all openEditor functions to one place
Remove code duplication for openEditor function that gets search result as a parameter. Change-Id: I3eb1c41b8a0fda3b2e8a4929cef1d5924295f1f5 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -50,7 +50,9 @@ std::unique_ptr<SearchHandle> QtCreatorSearch::startNewSearch(const QString &sea
|
|||||||
|
|
||||||
QObject::connect(searchResult,
|
QObject::connect(searchResult,
|
||||||
&Core::SearchResult::activated,
|
&Core::SearchResult::activated,
|
||||||
&QtCreatorSearch::openEditor);
|
[](const Core::SearchResultItem& item) {
|
||||||
|
Core::EditorManager::openEditorAtSearchResult(item);
|
||||||
|
});
|
||||||
|
|
||||||
auto searchHandle = std::unique_ptr<SearchHandle>(new QtCreatorSearchHandle(searchResult));
|
auto searchHandle = std::unique_ptr<SearchHandle>(new QtCreatorSearchHandle(searchResult));
|
||||||
|
|
||||||
@@ -61,11 +63,4 @@ std::unique_ptr<SearchHandle> QtCreatorSearch::startNewSearch(const QString &sea
|
|||||||
return searchHandle;
|
return searchHandle;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtCreatorSearch::openEditor(const Core::SearchResultItem &item)
|
|
||||||
{
|
|
||||||
Core::EditorManager::openEditorAt(QDir::fromNativeSeparators(item.path.first()),
|
|
||||||
item.mainRange.begin.line,
|
|
||||||
item.mainRange.begin.column);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace ClangRefactoring
|
} // namespace ClangRefactoring
|
||||||
|
@@ -41,10 +41,7 @@ public:
|
|||||||
QtCreatorSearch(Core::SearchResultWindow &searchResultWindow);
|
QtCreatorSearch(Core::SearchResultWindow &searchResultWindow);
|
||||||
|
|
||||||
std::unique_ptr<SearchHandle> startNewSearch(const QString &searchLabel,
|
std::unique_ptr<SearchHandle> startNewSearch(const QString &searchLabel,
|
||||||
const QString &searchTerm);
|
const QString &searchTerm);
|
||||||
|
|
||||||
private:
|
|
||||||
static void openEditor(const Core::SearchResultItem &item);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Core::SearchResultWindow &searchResultWindow;
|
Core::SearchResultWindow &searchResultWindow;
|
||||||
|
@@ -48,6 +48,7 @@
|
|||||||
#include <coreplugin/editortoolbar.h>
|
#include <coreplugin/editortoolbar.h>
|
||||||
#include <coreplugin/fileutils.h>
|
#include <coreplugin/fileutils.h>
|
||||||
#include <coreplugin/findplaceholder.h>
|
#include <coreplugin/findplaceholder.h>
|
||||||
|
#include <coreplugin/find/searchresultitem.h>
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
#include <coreplugin/imode.h>
|
#include <coreplugin/imode.h>
|
||||||
#include <coreplugin/infobar.h>
|
#include <coreplugin/infobar.h>
|
||||||
@@ -2646,6 +2647,17 @@ IEditor *EditorManager::openEditorAt(const QString &fileName, int line, int colu
|
|||||||
fileName, line, column, editorId, flags, newEditor);
|
fileName, line, column, editorId, flags, newEditor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EditorManager::openEditorAtSearchResult(const SearchResultItem &item, OpenEditorFlags flags)
|
||||||
|
{
|
||||||
|
if (item.path.empty()) {
|
||||||
|
openEditor(QDir::fromNativeSeparators(item.text), Id(), flags);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
openEditorAt(QDir::fromNativeSeparators(item.path.first()), item.mainRange.begin.line,
|
||||||
|
item.mainRange.begin.column, Id(), flags);
|
||||||
|
}
|
||||||
|
|
||||||
EditorManager::FilePathInfo EditorManager::splitLineAndColumnNumber(const QString &fullFilePath)
|
EditorManager::FilePathInfo EditorManager::splitLineAndColumnNumber(const QString &fullFilePath)
|
||||||
{
|
{
|
||||||
// :10:2 GCC/Clang-style
|
// :10:2 GCC/Clang-style
|
||||||
|
@@ -50,6 +50,7 @@ class IMode;
|
|||||||
class IVersionControl;
|
class IVersionControl;
|
||||||
|
|
||||||
class EditorToolBar;
|
class EditorToolBar;
|
||||||
|
class SearchResultItem;
|
||||||
|
|
||||||
enum MakeWritableResult {
|
enum MakeWritableResult {
|
||||||
OpenedWithVersionControl,
|
OpenedWithVersionControl,
|
||||||
@@ -114,6 +115,7 @@ public:
|
|||||||
static IEditor *openEditorAt(const QString &fileName, int line, int column = 0,
|
static IEditor *openEditorAt(const QString &fileName, int line, int column = 0,
|
||||||
Id editorId = Id(), OpenEditorFlags flags = NoFlags,
|
Id editorId = Id(), OpenEditorFlags flags = NoFlags,
|
||||||
bool *newEditor = 0);
|
bool *newEditor = 0);
|
||||||
|
static void openEditorAtSearchResult(const SearchResultItem &item, OpenEditorFlags flags = NoFlags);
|
||||||
static IEditor *openEditorWithContents(Id editorId, QString *titlePattern = 0,
|
static IEditor *openEditorWithContents(Id editorId, QString *titlePattern = 0,
|
||||||
const QByteArray &contents = QByteArray(),
|
const QByteArray &contents = QByteArray(),
|
||||||
const QString &uniqueId = QString(),
|
const QString &uniqueId = QString(),
|
||||||
|
@@ -370,7 +370,9 @@ void CppFindReferences::findAll_helper(SearchResult *search, Symbol *symbol,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
connect(search, &SearchResult::activated,
|
connect(search, &SearchResult::activated,
|
||||||
this, &CppFindReferences::openEditor);
|
[](const SearchResultItem& item) {
|
||||||
|
Core::EditorManager::openEditorAtSearchResult(item);
|
||||||
|
});
|
||||||
|
|
||||||
SearchResultWindow::instance()->popup(IOutputPane::ModeSwitch | IOutputPane::WithFocus);
|
SearchResultWindow::instance()->popup(IOutputPane::ModeSwitch | IOutputPane::WithFocus);
|
||||||
const WorkingCopy workingCopy = m_modelManager->workingCopy();
|
const WorkingCopy workingCopy = m_modelManager->workingCopy();
|
||||||
@@ -589,18 +591,6 @@ static void searchFinished(SearchResult *search, QFutureWatcher<Usage> *watcher)
|
|||||||
watcher->deleteLater();
|
watcher->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppFindReferences::openEditor(const SearchResultItem &item)
|
|
||||||
{
|
|
||||||
if (item.path.size() > 0) {
|
|
||||||
EditorManager::openEditorAt(QDir::fromNativeSeparators(item.path.first()),
|
|
||||||
item.mainRange.begin.line,
|
|
||||||
item.mainRange.begin.column);
|
|
||||||
} else {
|
|
||||||
EditorManager::openEditor(QDir::fromNativeSeparators(item.text));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
class FindMacroUsesInFile: public std::unary_function<QString, QList<Usage> >
|
class FindMacroUsesInFile: public std::unary_function<QString, QList<Usage> >
|
||||||
@@ -728,7 +718,9 @@ void CppFindReferences::findMacroUses(const CPlusPlus::Macro ¯o, const QStri
|
|||||||
SearchResultWindow::instance()->popup(IOutputPane::ModeSwitch | IOutputPane::WithFocus);
|
SearchResultWindow::instance()->popup(IOutputPane::ModeSwitch | IOutputPane::WithFocus);
|
||||||
|
|
||||||
connect(search, &SearchResult::activated,
|
connect(search, &SearchResult::activated,
|
||||||
this, &CppFindReferences::openEditor);
|
[](const Core::SearchResultItem& item) {
|
||||||
|
Core::EditorManager::openEditorAtSearchResult(item);
|
||||||
|
});
|
||||||
|
|
||||||
const Snapshot snapshot = m_modelManager->snapshot();
|
const Snapshot snapshot = m_modelManager->snapshot();
|
||||||
const WorkingCopy workingCopy = m_modelManager->workingCopy();
|
const WorkingCopy workingCopy = m_modelManager->workingCopy();
|
||||||
|
@@ -77,7 +77,6 @@ public:
|
|||||||
void renameMacroUses(const CPlusPlus::Macro ¯o, const QString &replacement = QString());
|
void renameMacroUses(const CPlusPlus::Macro ¯o, const QString &replacement = QString());
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void openEditor(const Core::SearchResultItem &item);
|
|
||||||
void onReplaceButtonClicked(const QString &text, const QList<Core::SearchResultItem> &items, bool preserveCase);
|
void onReplaceButtonClicked(const QString &text, const QList<Core::SearchResultItem> &items, bool preserveCase);
|
||||||
void searchAgain();
|
void searchAgain();
|
||||||
|
|
||||||
|
@@ -959,7 +959,9 @@ void FindReferences::displayResults(int first, int last)
|
|||||||
this, &FindReferences::onReplaceButtonClicked);
|
this, &FindReferences::onReplaceButtonClicked);
|
||||||
}
|
}
|
||||||
connect(m_currentSearch.data(), &SearchResult::activated,
|
connect(m_currentSearch.data(), &SearchResult::activated,
|
||||||
this, &FindReferences::openEditor);
|
[](const Core::SearchResultItem& item) {
|
||||||
|
Core::EditorManager::openEditorAtSearchResult(item);
|
||||||
|
});
|
||||||
connect(m_currentSearch.data(), &SearchResult::cancelled, this, &FindReferences::cancel);
|
connect(m_currentSearch.data(), &SearchResult::cancelled, this, &FindReferences::cancel);
|
||||||
connect(m_currentSearch.data(), &SearchResult::paused, this, &FindReferences::setPaused);
|
connect(m_currentSearch.data(), &SearchResult::paused, this, &FindReferences::setPaused);
|
||||||
SearchResultWindow::instance()->popup(IOutputPane::Flags(IOutputPane::ModeSwitch | IOutputPane::WithFocus));
|
SearchResultWindow::instance()->popup(IOutputPane::Flags(IOutputPane::ModeSwitch | IOutputPane::WithFocus));
|
||||||
@@ -1005,17 +1007,6 @@ void FindReferences::setPaused(bool paused)
|
|||||||
m_watcher.setPaused(paused);
|
m_watcher.setPaused(paused);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FindReferences::openEditor(const SearchResultItem &item)
|
|
||||||
{
|
|
||||||
if (item.path.size() > 0) {
|
|
||||||
EditorManager::openEditorAt(QDir::fromNativeSeparators(item.path.first()),
|
|
||||||
item.mainRange.begin.line,
|
|
||||||
item.mainRange.begin.column);
|
|
||||||
} else {
|
|
||||||
EditorManager::openEditor(QDir::fromNativeSeparators(item.text));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void FindReferences::onReplaceButtonClicked(const QString &text, const QList<SearchResultItem> &items, bool preserveCase)
|
void FindReferences::onReplaceButtonClicked(const QString &text, const QList<SearchResultItem> &items, bool preserveCase)
|
||||||
{
|
{
|
||||||
const QStringList fileNames = TextEditor::BaseFileFind::replaceAll(text, items, preserveCase);
|
const QStringList fileNames = TextEditor::BaseFileFind::replaceAll(text, items, preserveCase);
|
||||||
|
@@ -82,7 +82,6 @@ private:
|
|||||||
void searchFinished();
|
void searchFinished();
|
||||||
void cancel();
|
void cancel();
|
||||||
void setPaused(bool paused);
|
void setPaused(bool paused);
|
||||||
void openEditor(const Core::SearchResultItem &item);
|
|
||||||
void onReplaceButtonClicked(const QString &text, const QList<Core::SearchResultItem> &items, bool preserveCase);
|
void onReplaceButtonClicked(const QString &text, const QList<Core::SearchResultItem> &items, bool preserveCase);
|
||||||
|
|
||||||
QPointer<Core::SearchResult> m_currentSearch;
|
QPointer<Core::SearchResult> m_currentSearch;
|
||||||
|
@@ -448,16 +448,8 @@ void BaseFileFind::openEditor(const SearchResultItem &item)
|
|||||||
FileFindParameters parameters = result->userData().value<FileFindParameters>();
|
FileFindParameters parameters = result->userData().value<FileFindParameters>();
|
||||||
IEditor *openedEditor =
|
IEditor *openedEditor =
|
||||||
d->m_searchEngines[parameters.searchEngineIndex]->openEditor(item, parameters);
|
d->m_searchEngines[parameters.searchEngineIndex]->openEditor(item, parameters);
|
||||||
if (!openedEditor) {
|
if (!openedEditor)
|
||||||
if (item.path.size() > 0) {
|
EditorManager::openEditorAtSearchResult(item, EditorManager::DoNotSwitchToDesignMode);
|
||||||
openedEditor = EditorManager::openEditorAt(QDir::fromNativeSeparators(item.path.first()),
|
|
||||||
item.mainRange.begin.line,
|
|
||||||
item.mainRange.begin.column, Id(),
|
|
||||||
EditorManager::DoNotSwitchToDesignMode);
|
|
||||||
} else {
|
|
||||||
openedEditor = EditorManager::openEditor(QDir::fromNativeSeparators(item.text));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (d->m_currentFindSupport)
|
if (d->m_currentFindSupport)
|
||||||
d->m_currentFindSupport->clearHighlights();
|
d->m_currentFindSupport->clearHighlights();
|
||||||
d->m_currentFindSupport = 0;
|
d->m_currentFindSupport = 0;
|
||||||
|
Reference in New Issue
Block a user