Commit 83c3b6c2 authored by Daniel Teske's avatar Daniel Teske
Browse files

Line locator: Also work with editors that are derived from IEditor



IEditor has a concept of line and column number and goto line, thus this
can be done.

Change-Id: Ic2e3bdcfa2b1debf102afc21bfe9be667a0264c8
Reviewed-by: default avatarEike Ziller <eike.ziller@digia.com>
parent e485b439
......@@ -36,6 +36,7 @@
#include <QActionGroup>
#include <QToolBar>
#include <QTextBlock>
using namespace Android;
using namespace Internal;
......@@ -93,6 +94,17 @@ TextEditor::BaseTextEditorWidget *AndroidManifestEditor::textEditor() const
return widget()->textEditorWidget();
}
int AndroidManifestEditor::currentLine() const
{
return textEditor()->textCursor().blockNumber() + 1;
}
int AndroidManifestEditor::currentColumn() const
{
QTextCursor cursor = textEditor()->textCursor();
return cursor.position() - cursor.block().position() + 1;
}
void AndroidManifestEditor::changeEditorPage(QAction *action)
{
if (!widget()->setActivePage(static_cast<AndroidManifestEditorWidget::EditorPage>(action->data().toInt()))) {
......
......@@ -57,6 +57,10 @@ public:
Core::IDocument *document();
TextEditor::BaseTextEditorWidget *textEditor() const;
int currentLine() const;
int currentColumn() const;
void gotoLine(int line, int column = 0) { textEditor()->gotoLine(line, column); }
private slots:
void changeEditorPage(QAction *action);
......
......@@ -70,7 +70,7 @@ QList<LocatorFilterEntry> LineNumberFilter::matchesFor(QFutureInterface<Core::Lo
column = lineAndColumn.at(1).toInt(&ok);
if (!ok)
return value;
if (currentTextEditor() && (line > 0 || column > 0)) {
if (EditorManager::currentEditor() && (line > 0 || column > 0)) {
LineColumn data;
data.first = line;
data.second = column - 1; // column API is 0-based
......@@ -88,21 +88,13 @@ QList<LocatorFilterEntry> LineNumberFilter::matchesFor(QFutureInterface<Core::Lo
void LineNumberFilter::accept(LocatorFilterEntry selection) const
{
ITextEditor *editor = currentTextEditor();
IEditor *editor = EditorManager::currentEditor();
if (editor) {
EditorManager::addCurrentPositionToNavigationHistory();
LineColumn data = selection.internalData.value<LineColumn>();
if (data.first < 1) { // jump to column in same line
int currLine, currColumn;
editor->convertPosition(editor->position(), &currLine, &currColumn);
data.first = currLine;
}
if (data.first < 1) // jump to column in same line
data.first = editor->currentLine();
editor->gotoLine(data.first, data.second);
EditorManager::activateEditor(editor);
}
}
ITextEditor *LineNumberFilter::currentTextEditor() const
{
return qobject_cast<TextEditor::ITextEditor *>(EditorManager::currentEditor());
}
......@@ -36,10 +36,11 @@
#include <QList>
#include <QFutureInterface>
namespace TextEditor {
class ITextEditor;
namespace Core {
class IEditor;
}
namespace TextEditor {
namespace Internal {
class LineNumberFilter : public Core::ILocatorFilter
......@@ -52,9 +53,6 @@ public:
QList<Core::LocatorFilterEntry> matchesFor(QFutureInterface<Core::LocatorFilterEntry> &future, const QString &entry);
void accept(Core::LocatorFilterEntry selection) const;
void refresh(QFutureInterface<void> &) {}
private:
ITextEditor *currentTextEditor() const;
};
} // namespace Internal
......
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