Commit 2125525e authored by Eike Ziller's avatar Eike Ziller

Move openEditorAt from BaseTextEditorWidget to EditorManager

More sensible place, gotoLine is a method in IEditor anyhow.

Change-Id: I420a6bf17060c16e6f1a4f45e0bef89379fb6bf8
Reviewed-by: default avatarDavid Schulz <david.schulz@digia.com>
parent 97ce8e40
......@@ -39,7 +39,7 @@
#include <coreplugin/actionmanager/command.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/session.h>
#include <texteditor/basetexteditor.h>
#include <texteditor/itexteditor.h>
#include <utils/tooltip/tooltip.h>
#include <utils/tooltip/tipcontents.h>
#include <utils/qtcassert.h>
......@@ -508,8 +508,8 @@ Bookmark *BookmarkManager::bookmarkForIndex(const QModelIndex &index)
bool BookmarkManager::gotoBookmark(Bookmark *bookmark)
{
using namespace TextEditor;
if (ITextEditor *editor = qobject_cast<ITextEditor *>(BaseTextEditorWidget::openEditorAt(bookmark->filePath(),
bookmark->lineNumber()))) {
if (ITextEditor *editor = qobject_cast<ITextEditor *>(EditorManager::openEditorAt(bookmark->filePath(),
bookmark->lineNumber()))) {
return (editor->currentLine() == bookmark->lineNumber());
}
return false;
......
......@@ -36,7 +36,6 @@
#include <utils/qtcassert.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/session.h>
#include <texteditor/basetexteditor.h>
#include <cpptools/cppmodelmanagerinterface.h>
#include <cpptools/cpptoolsconstants.h>
#include <coreplugin/icore.h>
......@@ -287,10 +286,7 @@ void Manager::onDocumentUpdated(CPlusPlus::Document::Ptr doc)
void Manager::gotoLocation(const QString &fileName, int line, int column)
{
bool newEditor = false;
TextEditor::BaseTextEditorWidget::openEditorAt(fileName, line, column, Core::Id(),
Core::EditorManager::IgnoreNavigationHistory,
&newEditor);
Core::EditorManager::openEditorAt(fileName, line, column);
}
void Manager::gotoLocations(const QList<QVariant> &list)
......
......@@ -1419,6 +1419,19 @@ IEditor *EditorManager::openEditor(const QString &fileName, const Id &editorId,
fileName, editorId, flags, newEditor);
}
IEditor *EditorManager::openEditorAt(const QString &fileName, int line, int column,
const Id &editorId, OpenEditorFlags flags, bool *newEditor)
{
m_instance->cutForwardNavigationHistory();
m_instance->addCurrentPositionToNavigationHistory();
OpenEditorFlags tempFlags = flags | IgnoreNavigationHistory;
Core::IEditor *editor = Core::EditorManager::openEditor(fileName, editorId,
tempFlags, newEditor);
if (editor && line != -1)
editor->gotoLine(line, column);
return editor;
}
static int extractLineNumber(QString *fileName)
{
int i = fileName->length() - 1;
......
......@@ -118,6 +118,9 @@ public:
static QString splitLineNumber(QString *fileName);
static IEditor *openEditor(const QString &fileName, const Id &editorId = Id(),
OpenEditorFlags flags = 0, bool *newEditor = 0);
static IEditor *openEditorAt(const QString &fileName, int line, int column = 0,
const Id &editorId = Id(), OpenEditorFlags flags = 0,
bool *newEditor = 0);
static IEditor *openEditorWithContents(const Id &editorId,
QString *titlePattern = 0, const QString &contents = QString());
......
......@@ -2002,10 +2002,10 @@ bool CPPEditorWidget::openCppEditorAt(const Link &link, bool inNextSplit)
return true;
}
return TextEditor::BaseTextEditorWidget::openEditorAt(link.targetFileName,
link.targetLine,
link.targetColumn,
Constants::CPPEDITOR_ID);
return Core::EditorManager::openEditorAt(link.targetFileName,
link.targetLine,
link.targetColumn,
Constants::CPPEDITOR_ID);
}
void CPPEditorWidget::semanticRehighlight(bool force)
......
......@@ -105,10 +105,10 @@ private:
if (!m_link.hasValidTarget())
return;
TextEditor::BaseTextEditorWidget::openEditorAt(m_link.targetFileName,
m_link.targetLine,
m_link.targetColumn,
Constants::CPPEDITOR_ID);
Core::EditorManager::openEditorAt(m_link.targetFileName,
m_link.targetLine,
m_link.targetColumn,
Constants::CPPEDITOR_ID);
}
CPPEditorWidget::Link m_link;
......@@ -205,10 +205,10 @@ void CppTypeHierarchyWidget::onItemClicked(const QModelIndex &index)
const TextEditor::BaseTextEditorWidget::Link link
= index.data(LinkRole).value<TextEditor::BaseTextEditorWidget::Link>();
if (link.hasValidTarget())
TextEditor::BaseTextEditorWidget::openEditorAt(link.targetFileName,
link.targetLine,
link.targetColumn,
Constants::CPPEDITOR_ID);
Core::EditorManager::openEditorAt(link.targetFileName,
link.targetLine,
link.targetColumn,
Constants::CPPEDITOR_ID);
}
// CppTypeHierarchyStackedWidget
......
......@@ -110,8 +110,8 @@ QList<Locator::FilterEntry> CppCurrentDocumentFilter::matchesFor(QFutureInterfac
void CppCurrentDocumentFilter::accept(Locator::FilterEntry selection) const
{
ModelItemInfo info = qvariant_cast<CppTools::ModelItemInfo>(selection.internalData);
TextEditor::BaseTextEditorWidget::openEditorAt(info.fileName, info.line, info.column,
Core::Id(), Core::EditorManager::ModeSwitch);
Core::EditorManager::openEditorAt(info.fileName, info.line, info.column,
Core::Id(), Core::EditorManager::ModeSwitch);
}
void CppCurrentDocumentFilter::refresh(QFutureInterface<void> &future)
......
......@@ -32,11 +32,11 @@
#include "cpptoolsconstants.h"
#include "cppmodelmanagerinterface.h"
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/icore.h>
#include <coreplugin/progressmanager/futureprogress.h>
#include <coreplugin/progressmanager/progressmanager.h>
#include <texteditor/basefilefind.h>
#include <texteditor/basetexteditor.h>
#include <utils/qtcassert.h>
#include <utils/runextensions.h>
......@@ -509,10 +509,10 @@ void CppFindReferences::setPaused(bool paused)
void CppFindReferences::openEditor(const Find::SearchResultItem &item)
{
if (item.path.size() > 0) {
TextEditor::BaseTextEditorWidget::openEditorAt(QDir::fromNativeSeparators(item.path.first()),
item.lineNumber, item.textMarkPos,
Core::Id(),
Core::EditorManager::ModeSwitch);
Core::EditorManager::openEditorAt(QDir::fromNativeSeparators(item.path.first()),
item.lineNumber, item.textMarkPos,
Core::Id(),
Core::EditorManager::ModeSwitch);
} else {
Core::EditorManager::openEditor(QDir::fromNativeSeparators(item.text),
Core::Id(), Core::EditorManager::ModeSwitch);
......
......@@ -177,8 +177,8 @@ QList<Locator::FilterEntry> CppLocatorFilter::matchesFor(QFutureInterface<Locato
void CppLocatorFilter::accept(Locator::FilterEntry selection) const
{
ModelItemInfo info = qvariant_cast<CppTools::ModelItemInfo>(selection.internalData);
TextEditor::BaseTextEditorWidget::openEditorAt(info.fileName, info.line, info.column,
Core::Id(), Core::EditorManager::ModeSwitch);
Core::EditorManager::openEditorAt(info.fileName, info.line, info.column,
Core::Id(), Core::EditorManager::ModeSwitch);
}
void CppLocatorFilter::reset()
......
......@@ -187,9 +187,9 @@ void SymbolsFindFilter::openEditor(const Find::SearchResultItem &item)
if (!item.userData.canConvert<ModelItemInfo>())
return;
ModelItemInfo info = item.userData.value<ModelItemInfo>();
TextEditor::BaseTextEditorWidget::openEditorAt(info.fileName,
info.line,
info.column);
Core::EditorManager::openEditorAt(info.fileName,
info.line,
info.column);
}
QWidget *SymbolsFindFilter::createConfigWidget()
......
......@@ -270,7 +270,7 @@ static Document::Ptr findDefinition(Function *functionDeclaration, int *line)
static inline ITextEditor *editableAt(const QString &fileName, int line, int column)
{
return qobject_cast<ITextEditor *>(TextEditor::BaseTextEditorWidget::openEditorAt(fileName, line, column));
return qobject_cast<ITextEditor *>(Core::EditorManager::openEditorAt(fileName, line, column));
}
static void addDeclaration(const Snapshot &snapshot,
......@@ -626,7 +626,7 @@ bool QtCreatorIntegration::navigateToSlot(const QString &objectName,
}
// jump to function definition, position within code
TextEditor::BaseTextEditorWidget::openEditorAt(sourceDoc->fileName(), line + 2, indentation);
Core::EditorManager::openEditorAt(sourceDoc->fileName(), line + 2, indentation);
return true;
}
......
......@@ -31,7 +31,7 @@
#include "task.h"
#include <texteditor/basetexteditor.h>
#include <coreplugin/editormanager/editormanager.h>
#include <QAction>
#include <QFileInfo>
......@@ -49,7 +49,7 @@ bool ShowInEditorTaskHandler::canHandle(const ProjectExplorer::Task &task) const
void ShowInEditorTaskHandler::handle(const ProjectExplorer::Task &task)
{
QFileInfo fi(task.file.toFileInfo());
TextEditor::BaseTextEditorWidget::openEditorAt(fi.filePath(), task.movedLine);
Core::EditorManager::openEditorAt(fi.filePath(), task.movedLine);
}
QAction *ShowInEditorTaskHandler::createAction(QObject *parent) const
......
......@@ -29,7 +29,6 @@
#include "qmljsfindreferences.h"
#include <texteditor/basetexteditor.h>
#include <texteditor/basefilefind.h>
#include <find/searchresultwindow.h>
#include <extensionsystem/pluginmanager.h>
......@@ -985,9 +984,9 @@ void FindReferences::setPaused(bool paused)
void FindReferences::openEditor(const Find::SearchResultItem &item)
{
if (item.path.size() > 0) {
TextEditor::BaseTextEditorWidget::openEditorAt(QDir::fromNativeSeparators(item.path.first()),
item.lineNumber, item.textMarkPos, Core::Id(),
Core::EditorManager::ModeSwitch);
Core::EditorManager::openEditorAt(QDir::fromNativeSeparators(item.path.first()),
item.lineNumber, item.textMarkPos, Core::Id(),
Core::EditorManager::ModeSwitch);
} else {
Core::EditorManager::openEditor(QDir::fromNativeSeparators(item.text),
Core::Id(), Core::EditorManager::ModeSwitch);
......
......@@ -31,7 +31,7 @@
#include "qmlconsoleitemdelegate.h"
#include "qmlconsoleitemmodel.h"
#include <texteditor/basetexteditor.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/manhattanstyle.h>
#include <utils/hostosinfo.h>
......@@ -231,7 +231,7 @@ void QmlConsoleView::onRowActivated(const QModelIndex &index)
QFileInfo fi(filePath);
if (fi.exists() && fi.isFile() && fi.isReadable()) {
int line = model()->data(index, QmlConsoleItemModel::LineRole).toInt();
TextEditor::BaseTextEditorWidget::openEditorAt(fi.canonicalFilePath(), line);
Core::EditorManager::openEditorAt(fi.canonicalFilePath(), line);
}
}
}
......
......@@ -30,7 +30,7 @@
#include "qmljsfunctionfilter.h"
#include "qmljslocatordata.h"
#include <texteditor/basetexteditor.h>
#include <coreplugin/editormanager/editormanager.h>
#include <QStringMatcher>
......@@ -111,6 +111,6 @@ QList<Locator::FilterEntry> FunctionFilter::matchesFor(QFutureInterface<Locator:
void FunctionFilter::accept(Locator::FilterEntry selection) const
{
const LocatorData::Entry entry = qvariant_cast<LocatorData::Entry>(selection.internalData);
TextEditor::BaseTextEditorWidget::openEditorAt(entry.fileName, entry.line, entry.column,
Core::Id(), Core::EditorManager::ModeSwitch);
Core::EditorManager::openEditorAt(entry.fileName, entry.line, entry.column,
Core::Id(), Core::EditorManager::ModeSwitch);
}
......@@ -29,11 +29,12 @@
#include "qtoutputformatter.h"
#include <texteditor/basetexteditor.h>
#include <coreplugin/editormanager/editormanager.h>
#include <projectexplorer/project.h>
#include <QUrl>
#include <QPlainTextEdit>
#include <QTextCursor>
#include <QUrl>
using namespace ProjectExplorer;
using namespace QtSupport;
......@@ -195,7 +196,7 @@ void QtOutputFormatter::handleLink(const QString &href)
const int line = qmlLineColumnLink.cap(2).toInt();
const int column = qmlLineColumnLink.cap(3).toInt();
TextEditor::BaseTextEditorWidget::openEditorAt(m_projectFinder.findFile(fileUrl), line, column - 1);
Core::EditorManager::openEditorAt(m_projectFinder.findFile(fileUrl), line, column - 1);
return;
}
......@@ -206,7 +207,7 @@ void QtOutputFormatter::handleLink(const QString &href)
if (qmlLineLink.indexIn(href) != -1) {
const QUrl fileUrl = QUrl(qmlLineLink.cap(1));
const int line = qmlLineLink.cap(2).toInt();
TextEditor::BaseTextEditorWidget::openEditorAt(m_projectFinder.findFile(fileUrl), line);
Core::EditorManager::openEditorAt(m_projectFinder.findFile(fileUrl), line);
return;
}
......@@ -233,7 +234,7 @@ void QtOutputFormatter::handleLink(const QString &href)
if (!fileName.isEmpty()) {
fileName = m_projectFinder.findFile(QUrl::fromLocalFile(fileName));
TextEditor::BaseTextEditorWidget::openEditorAt(fileName, line, 0);
Core::EditorManager::openEditorAt(fileName, line, 0);
return;
}
}
......
......@@ -36,7 +36,8 @@
#include <coreplugin/progressmanager/futureprogress.h>
#include <coreplugin/dialogs/readonlyfilesdialog.h>
#include <coreplugin/documentmanager.h>
#include <texteditor/basetexteditor.h>
#include <find/ifindsupport.h>
#include <texteditor/itexteditor.h>
#include <texteditor/refactoringchanges.h>
#include <utils/stylehelper.h>
#include <utils/qtcassert.h>
......@@ -309,11 +310,11 @@ void BaseFileFind::openEditor(const Find::SearchResultItem &item)
SearchResult *result = qobject_cast<SearchResult *>(sender());
Core::IEditor *openedEditor = 0;
if (item.path.size() > 0) {
openedEditor = TextEditor::BaseTextEditorWidget::openEditorAt(QDir::fromNativeSeparators(item.path.first()),
item.lineNumber,
item.textMarkPos,
Core::Id(),
Core::EditorManager::ModeSwitch);
openedEditor = Core::EditorManager::openEditorAt(QDir::fromNativeSeparators(item.path.first()),
item.lineNumber,
item.textMarkPos,
Core::Id(),
Core::EditorManager::ModeSwitch);
} else {
openedEditor = Core::EditorManager::openEditor(QDir::fromNativeSeparators(item.text),
Core::Id(), Core::EditorManager::ModeSwitch);
......
......@@ -154,25 +154,6 @@ private:
using namespace Internal;
Core::IEditor *BaseTextEditorWidget::openEditorAt(const QString &fileName, int line, int column,
Core::Id editorKind,
Core::EditorManager::OpenEditorFlags flags,
bool *newEditor)
{
Core::EditorManager *editorManager = Core::EditorManager::instance();
editorManager->cutForwardNavigationHistory();
editorManager->addCurrentPositionToNavigationHistory();
Core::IEditor *editor = Core::EditorManager::openEditor(fileName, editorKind,
flags, newEditor);
TextEditor::ITextEditor *texteditor = qobject_cast<TextEditor::ITextEditor *>(editor);
if (texteditor && line != -1) {
texteditor->gotoLine(line, column);
return texteditor;
}
return editor;
}
QString BaseTextEditorWidget::plainTextFromSelection(const QTextCursor &cursor) const
{
// Copy the selected text as plain text
......@@ -4918,9 +4899,8 @@ bool BaseTextEditorWidget::openLink(const Link &link, bool inNextSplit)
return true;
}
return openEditorAt(link.targetFileName, link.targetLine, link.targetColumn, Core::Id(),
Core::EditorManager::IgnoreNavigationHistory
| Core::EditorManager::ModeSwitch);
return Core::EditorManager::openEditorAt(link.targetFileName, link.targetLine, link.targetColumn,
Core::Id(), Core::EditorManager::ModeSwitch);
}
void BaseTextEditorWidget::updateLink(QMouseEvent *e)
......
......@@ -131,11 +131,6 @@ public:
BaseTextEditorWidget(QWidget *parent);
~BaseTextEditorWidget();
static Core::IEditor *openEditorAt(const QString &fileName, int line, int column = 0,
Core::Id editorId = Core::Id(),
Core::EditorManager::OpenEditorFlags flags = Core::EditorManager::IgnoreNavigationHistory,
bool *newEditor = 0);
const Utils::ChangeSet &changeSet() const;
void setChangeSet(const Utils::ChangeSet &changeSet);
......
......@@ -29,8 +29,6 @@
#include "itexteditor.h"
#include <coreplugin/editormanager/editormanager.h>
#include <QTextCodec>
using namespace TextEditor;
......@@ -66,7 +64,6 @@ QMap<QString, QTextCodec *> TextEditor::ITextEditor::openedTextEditorsEncodings(
return workingCopy;
}
ITextEditorDocument *ITextEditor::textDocument()
{
return qobject_cast<ITextEditorDocument *>(document());
......
......@@ -35,6 +35,7 @@
#include "itextmark.h"
#include <coreplugin/textdocument.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/ieditor.h>
#include <QMap>
......
......@@ -141,7 +141,7 @@ BaseTextEditorWidget *RefactoringChanges::openEditor(const QString &fileName, bo
// openEditorAt uses a 1-based line and a 0-based column!
column -= 1;
}
Core::IEditor *editor = BaseTextEditorWidget::openEditorAt(
Core::IEditor *editor = Core::EditorManager::openEditorAt(
fileName, line, column, Core::Id(), flags);
if (editor)
......
......@@ -62,7 +62,7 @@
#include <cplusplus/Overview.h>
#include <cppeditor/cppeditorconstants.h>
#include <extensionsystem/iplugin.h>
#include <texteditor/basetexteditor.h>
#include <texteditor/itexteditor.h>
#include <utils/qtcassert.h>
#include <utils/fancymainwindow.h>
......@@ -322,7 +322,7 @@ void CallgrindToolPrivate::selectFunction(const Function *func)
if (QFile::exists(func->file())) {
///TODO: custom position support?
int line = func->lineNumber();
TextEditor::BaseTextEditorWidget::openEditorAt(func->file(), qMax(line, 0));
Core::EditorManager::openEditorAt(func->file(), qMax(line, 0));
}
}
......
......@@ -41,9 +41,9 @@
#include "xmlprotocol/suppression.h"
#include <coreplugin/coreconstants.h>
#include <projectexplorer/projectexplorer.h>
#include <coreplugin/editormanager/editormanager.h>
#include <projectexplorer/project.h>
#include <texteditor/basetexteditor.h>
#include <projectexplorer/projectexplorer.h>
#include <utils/qtcassert.h>
#include <QDir>
......@@ -52,6 +52,7 @@
#include <QAction>
#include <QApplication>
#include <QClipboard>
#include <QContextMenuEvent>
#include <QLabel>
#include <QListView>
#include <QMenu>
......@@ -432,7 +433,7 @@ void MemcheckErrorDelegate::openLinkInEditor(const QString &link)
const int pathEnd = link.lastIndexOf(QLatin1Char(':'));
const QString path = link.mid(pathStart, pathEnd - pathStart);
const int line = link.mid(pathEnd + 1).toInt(0);
TextEditor::BaseTextEditorWidget::openEditorAt(path, qMax(line, 0));
Core::EditorManager::openEditorAt(path, qMax(line, 0));
}
MemcheckErrorView::MemcheckErrorView(QWidget *parent)
......
......@@ -54,15 +54,14 @@
#include <projectexplorer/session.h>
#include <projectexplorer/buildconfiguration.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/icore.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/command.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/icore.h>
#include <coreplugin/id.h>
#include <texteditor/basetexteditor.h>
#include <utils/fancymainwindow.h>
#include <utils/styledbar.h>
#include <utils/qtcassert.h>
......@@ -502,7 +501,7 @@ void MemcheckTool::suppressionActionTriggered()
const QString file = action->data().toString();
QTC_ASSERT(!file.isEmpty(), return);
TextEditor::BaseTextEditorWidget::openEditorAt(file, 0);
Core::EditorManager::openEditorAt(file, 0);
}
void MemcheckTool::parserError(const Valgrind::XmlProtocol::Error &error)
......
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