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