forked from qt-creator/qt-creator
TextEditor: Simplify setup of line number filter
Change-Id: Ida977fc959f3fe6052151ba8e2461a64699d0a41 Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -108,7 +108,7 @@ add_qtc_plugin(TextEditor
|
|||||||
texteditoractionhandler.cpp texteditoractionhandler.h
|
texteditoractionhandler.cpp texteditoractionhandler.h
|
||||||
texteditorconstants.cpp texteditorconstants.h
|
texteditorconstants.cpp texteditorconstants.h
|
||||||
texteditoroverlay.cpp texteditoroverlay.h
|
texteditoroverlay.cpp texteditoroverlay.h
|
||||||
texteditorplugin.cpp texteditorplugin.h
|
texteditorplugin.cpp
|
||||||
texteditorsettings.cpp texteditorsettings.h
|
texteditorsettings.cpp texteditorsettings.h
|
||||||
textindenter.cpp textindenter.h
|
textindenter.cpp textindenter.h
|
||||||
textmark.cpp textmark.h
|
textmark.cpp textmark.h
|
||||||
|
@@ -12,58 +12,74 @@ using namespace Utils;
|
|||||||
|
|
||||||
namespace TextEditor::Internal {
|
namespace TextEditor::Internal {
|
||||||
|
|
||||||
LineNumberFilter::LineNumberFilter()
|
class LineNumberFilter final : public Core::ILocatorFilter
|
||||||
{
|
{
|
||||||
setId("Line in current document");
|
public:
|
||||||
setDisplayName(Tr::tr("Line in Current Document"));
|
LineNumberFilter()
|
||||||
setDescription(Tr::tr("Jumps to the given line in the current document."));
|
{
|
||||||
setDefaultSearchText(Tr::tr("<line>:<column>"));
|
setId("Line in current document");
|
||||||
setPriority(High);
|
setDisplayName(Tr::tr("Line in Current Document"));
|
||||||
setDefaultShortcutString("l");
|
setDescription(Tr::tr("Jumps to the given line in the current document."));
|
||||||
setDefaultIncludedByDefault(true);
|
setDefaultSearchText(Tr::tr("<line>:<column>"));
|
||||||
|
setPriority(High);
|
||||||
|
setDefaultShortcutString("l");
|
||||||
|
setDefaultIncludedByDefault(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
LocatorMatcherTasks matchers() final
|
||||||
|
{
|
||||||
|
using namespace Tasking;
|
||||||
|
|
||||||
|
Storage<LocatorStorage> storage;
|
||||||
|
|
||||||
|
const auto onSetup = [storage] {
|
||||||
|
const QStringList lineAndColumn = storage->input().split(':');
|
||||||
|
int sectionCount = lineAndColumn.size();
|
||||||
|
int line = 0;
|
||||||
|
int column = 0;
|
||||||
|
bool ok = false;
|
||||||
|
if (sectionCount > 0)
|
||||||
|
line = lineAndColumn.at(0).toInt(&ok);
|
||||||
|
if (ok && sectionCount > 1)
|
||||||
|
column = lineAndColumn.at(1).toInt(&ok);
|
||||||
|
if (!ok)
|
||||||
|
return;
|
||||||
|
if (EditorManager::currentEditor() && (line > 0 || column > 0)) {
|
||||||
|
QString text;
|
||||||
|
if (line > 0 && column > 0)
|
||||||
|
text = Tr::tr("Line %1, Column %2").arg(line).arg(column);
|
||||||
|
else if (line > 0)
|
||||||
|
text = Tr::tr("Line %1").arg(line);
|
||||||
|
else
|
||||||
|
text = Tr::tr("Column %1").arg(column);
|
||||||
|
LocatorFilterEntry entry;
|
||||||
|
entry.displayName = text;
|
||||||
|
entry.acceptor = [line, targetColumn = column - 1] {
|
||||||
|
IEditor *editor = EditorManager::currentEditor();
|
||||||
|
if (!editor)
|
||||||
|
return AcceptResult();
|
||||||
|
EditorManager::addCurrentPositionToNavigationHistory();
|
||||||
|
editor->gotoLine(line < 1 ? editor->currentLine() : line, targetColumn);
|
||||||
|
EditorManager::activateEditor(editor);
|
||||||
|
return AcceptResult();
|
||||||
|
};
|
||||||
|
storage->reportOutput({entry});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return {{Sync(onSetup), storage}};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ILocatorFilter *lineNumberFilter()
|
||||||
|
{
|
||||||
|
static LineNumberFilter theLineNumberFilter;
|
||||||
|
return &theLineNumberFilter;
|
||||||
}
|
}
|
||||||
|
|
||||||
LocatorMatcherTasks LineNumberFilter::matchers()
|
void setupLineNumberFilter()
|
||||||
{
|
{
|
||||||
using namespace Tasking;
|
(void) lineNumberFilter(); // Instantiate it.
|
||||||
|
|
||||||
Storage<LocatorStorage> storage;
|
|
||||||
|
|
||||||
const auto onSetup = [storage] {
|
|
||||||
const QStringList lineAndColumn = storage->input().split(':');
|
|
||||||
int sectionCount = lineAndColumn.size();
|
|
||||||
int line = 0;
|
|
||||||
int column = 0;
|
|
||||||
bool ok = false;
|
|
||||||
if (sectionCount > 0)
|
|
||||||
line = lineAndColumn.at(0).toInt(&ok);
|
|
||||||
if (ok && sectionCount > 1)
|
|
||||||
column = lineAndColumn.at(1).toInt(&ok);
|
|
||||||
if (!ok)
|
|
||||||
return;
|
|
||||||
if (EditorManager::currentEditor() && (line > 0 || column > 0)) {
|
|
||||||
QString text;
|
|
||||||
if (line > 0 && column > 0)
|
|
||||||
text = Tr::tr("Line %1, Column %2").arg(line).arg(column);
|
|
||||||
else if (line > 0)
|
|
||||||
text = Tr::tr("Line %1").arg(line);
|
|
||||||
else
|
|
||||||
text = Tr::tr("Column %1").arg(column);
|
|
||||||
LocatorFilterEntry entry;
|
|
||||||
entry.displayName = text;
|
|
||||||
entry.acceptor = [line, targetColumn = column - 1] {
|
|
||||||
IEditor *editor = EditorManager::currentEditor();
|
|
||||||
if (!editor)
|
|
||||||
return AcceptResult();
|
|
||||||
EditorManager::addCurrentPositionToNavigationHistory();
|
|
||||||
editor->gotoLine(line < 1 ? editor->currentLine() : line, targetColumn);
|
|
||||||
EditorManager::activateEditor(editor);
|
|
||||||
return AcceptResult();
|
|
||||||
};
|
|
||||||
storage->reportOutput({entry});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return {{Sync(onSetup), storage}};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace TextEditor::Internal
|
} // namespace TextEditor::Internal
|
||||||
|
@@ -7,13 +7,8 @@
|
|||||||
|
|
||||||
namespace TextEditor::Internal {
|
namespace TextEditor::Internal {
|
||||||
|
|
||||||
class LineNumberFilter : public Core::ILocatorFilter
|
Core::ILocatorFilter *lineNumberFilter();
|
||||||
{
|
|
||||||
public:
|
|
||||||
LineNumberFilter();
|
|
||||||
|
|
||||||
private:
|
void setupLineNumberFilter();
|
||||||
Core::LocatorMatcherTasks matchers() final;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace TextEditor::Internal
|
} // namespace TextEditor::Internal
|
||||||
|
@@ -7,7 +7,6 @@
|
|||||||
#include "texteditor.h"
|
#include "texteditor.h"
|
||||||
#include "texteditoractionhandler.h"
|
#include "texteditoractionhandler.h"
|
||||||
#include "texteditorconstants.h"
|
#include "texteditorconstants.h"
|
||||||
#include "texteditorplugin.h"
|
|
||||||
#include "texteditorsettings.h"
|
#include "texteditorsettings.h"
|
||||||
#include "textindenter.h"
|
#include "textindenter.h"
|
||||||
|
|
||||||
|
@@ -3,8 +3,6 @@
|
|||||||
|
|
||||||
#include "snippetprovider.h"
|
#include "snippetprovider.h"
|
||||||
|
|
||||||
#include <texteditor/texteditorplugin.h>
|
|
||||||
|
|
||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
|
|
||||||
using namespace TextEditor;
|
using namespace TextEditor;
|
||||||
|
@@ -145,7 +145,6 @@ QtcPlugin {
|
|||||||
"texteditoroverlay.cpp",
|
"texteditoroverlay.cpp",
|
||||||
"texteditoroverlay.h",
|
"texteditoroverlay.h",
|
||||||
"texteditorplugin.cpp",
|
"texteditorplugin.cpp",
|
||||||
"texteditorplugin.h",
|
|
||||||
"texteditorsettings.cpp",
|
"texteditorsettings.cpp",
|
||||||
"texteditorsettings.h",
|
"texteditorsettings.h",
|
||||||
"textindenter.cpp",
|
"textindenter.cpp",
|
||||||
|
@@ -7,7 +7,6 @@
|
|||||||
#include "displaysettings.h"
|
#include "displaysettings.h"
|
||||||
#include "fontsettings.h"
|
#include "fontsettings.h"
|
||||||
#include "linenumberfilter.h"
|
#include "linenumberfilter.h"
|
||||||
#include "texteditorplugin.h"
|
|
||||||
#include "texteditortr.h"
|
#include "texteditortr.h"
|
||||||
#include "texteditorsettings.h"
|
#include "texteditorsettings.h"
|
||||||
|
|
||||||
|
@@ -1,8 +1,6 @@
|
|||||||
// Copyright (C) 2016 The Qt Company Ltd.
|
// Copyright (C) 2016 The Qt Company Ltd.
|
||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||||
|
|
||||||
#include "texteditorplugin.h"
|
|
||||||
|
|
||||||
#include "bookmarkfilter.h"
|
#include "bookmarkfilter.h"
|
||||||
#include "bookmarkmanager.h"
|
#include "bookmarkmanager.h"
|
||||||
#include "findincurrentfile.h"
|
#include "findincurrentfile.h"
|
||||||
@@ -103,7 +101,6 @@ public:
|
|||||||
FilePath m_marginActionFileName;
|
FilePath m_marginActionFileName;
|
||||||
|
|
||||||
TextEditorSettings settings;
|
TextEditorSettings settings;
|
||||||
LineNumberFilter lineNumberFilter; // Goto line functionality for quick open
|
|
||||||
|
|
||||||
FindInFiles findInFilesFilter;
|
FindInFiles findInFilesFilter;
|
||||||
FindInCurrentFile findInCurrentFileFilter;
|
FindInCurrentFile findInCurrentFileFilter;
|
||||||
@@ -303,6 +300,7 @@ void TextEditorPlugin::initialize()
|
|||||||
|
|
||||||
setupTextMarkRegistry(this);
|
setupTextMarkRegistry(this);
|
||||||
setupOutlineFactory();
|
setupOutlineFactory();
|
||||||
|
setupLineNumberFilter(); // Goto line functionality for quick open
|
||||||
|
|
||||||
d = new TextEditorPluginPrivate;
|
d = new TextEditorPluginPrivate;
|
||||||
|
|
||||||
@@ -449,11 +447,6 @@ void TextEditorPlugin::extensionsInitialized()
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
LineNumberFilter *lineNumberFilter()
|
|
||||||
{
|
|
||||||
return &m_instance->d->lineNumberFilter;
|
|
||||||
}
|
|
||||||
|
|
||||||
ExtensionSystem::IPlugin::ShutdownFlag TextEditorPlugin::aboutToShutdown()
|
ExtensionSystem::IPlugin::ShutdownFlag TextEditorPlugin::aboutToShutdown()
|
||||||
{
|
{
|
||||||
HighlighterHelper::handleShutdown();
|
HighlighterHelper::handleShutdown();
|
||||||
|
@@ -1,13 +0,0 @@
|
|||||||
// Copyright (C) 2016 The Qt Company Ltd.
|
|
||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
namespace TextEditor::Internal {
|
|
||||||
|
|
||||||
class LineNumberFilter;
|
|
||||||
LineNumberFilter *lineNumberFilter();
|
|
||||||
|
|
||||||
} // TextEditor::Internal
|
|
@@ -6,7 +6,6 @@
|
|||||||
#include "fontsettings.h"
|
#include "fontsettings.h"
|
||||||
#include "textdocument.h"
|
#include "textdocument.h"
|
||||||
#include "texteditor.h"
|
#include "texteditor.h"
|
||||||
#include "texteditorplugin.h"
|
|
||||||
#include "texteditortr.h"
|
#include "texteditortr.h"
|
||||||
|
|
||||||
#include <coreplugin/editormanager/editormanager.h>
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
|
Reference in New Issue
Block a user