aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhjk <[email protected]>2023-09-22 18:05:03 +0200
committerhjk <[email protected]>2023-09-28 11:03:02 +0000
commit963ff4381d5a3b2edb27c1d538299e23d15d8fa1 (patch)
tree50eea853ef50889b801e8e8b38a6a7ae9ce87bb7
parent776c8670d7e8124c8b78dc505b85a94d51372e54 (diff)
Bookmarks: Merge plugin into TextEditor
Change-Id: I4c9438f3596daff2c18680a731764bf5010e1e25 Reviewed-by: David Schulz <[email protected]>
-rw-r--r--src/plugins/CMakeLists.txt1
-rw-r--r--src/plugins/bookmarks/Bookmarks.json.in19
-rw-r--r--src/plugins/bookmarks/CMakeLists.txt10
-rw-r--r--src/plugins/bookmarks/bookmarks.qbs25
-rw-r--r--src/plugins/bookmarks/bookmarks_global.h26
-rw-r--r--src/plugins/bookmarks/bookmarksplugin.cpp223
-rw-r--r--src/plugins/bookmarks/bookmarksplugin.h22
-rw-r--r--src/plugins/bookmarks/bookmarkstr.h15
-rw-r--r--src/plugins/plugins.qbs1
-rw-r--r--src/plugins/texteditor/CMakeLists.txt3
-rw-r--r--src/plugins/texteditor/basefilefind.cpp2
-rw-r--r--src/plugins/texteditor/bookmark.cpp (renamed from src/plugins/bookmarks/bookmark.cpp)12
-rw-r--r--src/plugins/texteditor/bookmark.h (renamed from src/plugins/bookmarks/bookmark.h)6
-rw-r--r--src/plugins/texteditor/bookmarkfilter.cpp (renamed from src/plugins/bookmarks/bookmarkfilter.cpp)6
-rw-r--r--src/plugins/texteditor/bookmarkfilter.h (renamed from src/plugins/bookmarks/bookmarkfilter.h)4
-rw-r--r--src/plugins/texteditor/bookmarkmanager.cpp (renamed from src/plugins/bookmarks/bookmarkmanager.cpp)20
-rw-r--r--src/plugins/texteditor/bookmarkmanager.h (renamed from src/plugins/bookmarks/bookmarkmanager.h)2
-rw-r--r--src/plugins/texteditor/texteditor.qbs6
-rw-r--r--src/plugins/texteditor/texteditorconstants.h3
-rw-r--r--src/plugins/texteditor/texteditorplugin.cpp202
20 files changed, 228 insertions, 380 deletions
diff --git a/src/plugins/CMakeLists.txt b/src/plugins/CMakeLists.txt
index 8fd10b68374..d10f434eb10 100644
--- a/src/plugins/CMakeLists.txt
+++ b/src/plugins/CMakeLists.txt
@@ -22,7 +22,6 @@ add_subdirectory(silversearcher)
# Level 3: (only depends on Level 2 and below)
add_subdirectory(axivion)
-add_subdirectory(bookmarks)
add_subdirectory(cppeditor)
add_subdirectory(haskell)
add_subdirectory(help)
diff --git a/src/plugins/bookmarks/Bookmarks.json.in b/src/plugins/bookmarks/Bookmarks.json.in
deleted file mode 100644
index 46a307f517a..00000000000
--- a/src/plugins/bookmarks/Bookmarks.json.in
+++ /dev/null
@@ -1,19 +0,0 @@
-{
- "Name" : "Bookmarks",
- "Version" : "${IDE_VERSION}",
- "CompatVersion" : "${IDE_VERSION_COMPAT}",
- "Vendor" : "The Qt Company Ltd",
- "Copyright" : "(C) ${IDE_COPYRIGHT_YEAR} The Qt Company Ltd",
- "License" : [ "Commercial Usage",
- "",
- "Licensees holding valid Qt Commercial licenses may use this plugin in accordance with the Qt Commercial License Agreement provided with the Software or, alternatively, in accordance with the terms contained in a written agreement between you and The Qt Company.",
- "",
- "GNU General Public License Usage",
- "",
- "Alternatively, this plugin may be used under the terms of the GNU General Public License version 3 as published by the Free Software Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT included in the packaging of this plugin. Please review the following information to ensure the GNU General Public License requirements will be met: https://www.gnu.org/licenses/gpl-3.0.html."
- ],
- "Category" : "Core",
- "Description" : "Bookmarks in text editors.",
- "Url" : "http://www.qt.io",
- ${IDE_PLUGIN_DEPENDENCIES}
-}
diff --git a/src/plugins/bookmarks/CMakeLists.txt b/src/plugins/bookmarks/CMakeLists.txt
deleted file mode 100644
index 62a83b5adb1..00000000000
--- a/src/plugins/bookmarks/CMakeLists.txt
+++ /dev/null
@@ -1,10 +0,0 @@
-add_qtc_plugin(Bookmarks
- PLUGIN_DEPENDS Core ProjectExplorer TextEditor
- SOURCES
- bookmark.cpp bookmark.h
- bookmarkfilter.cpp bookmarkfilter.h
- bookmarkmanager.cpp bookmarkmanager.h
- bookmarks_global.h
- bookmarkstr.h
- bookmarksplugin.cpp bookmarksplugin.h
-)
diff --git a/src/plugins/bookmarks/bookmarks.qbs b/src/plugins/bookmarks/bookmarks.qbs
deleted file mode 100644
index d42fa43cdfd..00000000000
--- a/src/plugins/bookmarks/bookmarks.qbs
+++ /dev/null
@@ -1,25 +0,0 @@
-import qbs 1.0
-
-QtcPlugin {
- name: "Bookmarks"
-
- Depends { name: "Qt.widgets" }
- Depends { name: "Utils" }
-
- Depends { name: "Core" }
- Depends { name: "ProjectExplorer" }
- Depends { name: "TextEditor" }
-
- files: [
- "bookmark.cpp",
- "bookmark.h",
- "bookmarkfilter.cpp",
- "bookmarkfilter.h",
- "bookmarkmanager.cpp",
- "bookmarkmanager.h",
- "bookmarks_global.h", "bookmarkstr.h",
- "bookmarksplugin.cpp",
- "bookmarksplugin.h",
- ]
-}
-
diff --git a/src/plugins/bookmarks/bookmarks_global.h b/src/plugins/bookmarks/bookmarks_global.h
deleted file mode 100644
index 2b9727d1c6e..00000000000
--- a/src/plugins/bookmarks/bookmarks_global.h
+++ /dev/null
@@ -1,26 +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
-
-namespace Bookmarks {
-namespace Constants {
-
-const char BOOKMARKS_TOGGLE_ACTION[] = "Bookmarks.Toggle";
-const char BOOKMARKS_EDIT_ACTION[] = "Bookmarks.Edit";
-const char BOOKMARKS_MOVEUP_ACTION[] = "Bookmarks.MoveUp";
-const char BOOKMARKS_MOVEDOWN_ACTION[] = "Bookmarks.MoveDown";
-const char BOOKMARKS_EDITNOTE_ACTION[] = "Bookmarks.EditNote";
-const char BOOKMARKS_PREV_ACTION[] = "Bookmarks.Previous";
-const char BOOKMARKS_NEXT_ACTION[] = "Bookmarks.Next";
-const char BOOKMARKS_PREVDIR_ACTION[] = "Bookmarks.PreviousDirectory";
-const char BOOKMARKS_NEXTDIR_ACTION[] = "Bookmarks.NextDirectory";
-const char BOOKMARKS_PREVDOC_ACTION[] = "Bookmarks.PreviousDocument";
-const char BOOKMARKS_NEXTDOC_ACTION[] = "Bookmarks.NextDocument";
-const char BOOKMARKS_TEXT_MARK_CATEGORY[] = "Bookmarks.TextMarkCategory";
-
-const char BOOKMARKS_MENU[] = "Bookmarks.Menu";
-const char BOOKMARKS_CONTEXT[] = "Bookmarks";
-
-} // namespace Constants
-} // namespace Bookmarks
diff --git a/src/plugins/bookmarks/bookmarksplugin.cpp b/src/plugins/bookmarks/bookmarksplugin.cpp
deleted file mode 100644
index fc8f1ba7503..00000000000
--- a/src/plugins/bookmarks/bookmarksplugin.cpp
+++ /dev/null
@@ -1,223 +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
-
-#include "bookmarksplugin.h"
-
-#include "bookmarkfilter.h"
-#include "bookmarkmanager.h"
-#include "bookmarks_global.h"
-#include "bookmarkstr.h"
-
-#include <coreplugin/icore.h>
-#include <coreplugin/editormanager/ieditor.h>
-#include <coreplugin/editormanager/editormanager.h>
-#include <coreplugin/coreconstants.h>
-#include <coreplugin/actionmanager/actionmanager.h>
-#include <coreplugin/actionmanager/actioncontainer.h>
-#include <coreplugin/actionmanager/command.h>
-
-#include <texteditor/texteditor.h>
-#include <texteditor/textdocument.h>
-#include <texteditor/texteditorconstants.h>
-
-#include <utils/utilsicons.h>
-
-#include <QMenu>
-
-using namespace Core;
-using namespace TextEditor;
-using namespace Utils;
-
-using namespace Bookmarks::Constants;
-
-namespace Bookmarks::Internal {
-
-class BookmarksPluginPrivate : public QObject
-{
-public:
- BookmarksPluginPrivate();
-
- void updateActions(bool enableToggle, int stateMask);
- void editorOpened(Core::IEditor *editor);
- void editorAboutToClose(Core::IEditor *editor);
-
- void requestContextMenu(TextEditor::TextEditorWidget *widget,
- int lineNumber, QMenu *menu);
-
- BookmarkManager m_bookmarkManager;
- BookmarkFilter m_bookmarkFilter;
- BookmarkViewFactory m_bookmarkViewFactory;
-
- QAction m_toggleAction{Tr::tr("Toggle Bookmark"), nullptr};
- QAction m_editAction{Tr::tr("Edit Bookmark"), nullptr};
- QAction m_prevAction{Tr::tr("Previous Bookmark"), nullptr};
- QAction m_nextAction{Tr::tr("Next Bookmark"), nullptr};
- QAction m_docPrevAction{Tr::tr("Previous Bookmark in Document"), nullptr};
- QAction m_docNextAction{Tr::tr("Next Bookmark in Document"), nullptr};
- QAction m_editBookmarkAction{Tr::tr("Edit Bookmark"), nullptr};
- QAction m_bookmarkMarginAction{Tr::tr("Toggle Bookmark"), nullptr};
-
- int m_marginActionLineNumber = 0;
- Utils::FilePath m_marginActionFileName;
-};
-
-BookmarksPlugin::~BookmarksPlugin()
-{
- delete d;
-}
-
-void BookmarksPlugin::initialize()
-{
- d = new BookmarksPluginPrivate;
-}
-
-BookmarksPluginPrivate::BookmarksPluginPrivate()
- : m_bookmarkFilter(&m_bookmarkManager)
- , m_bookmarkViewFactory(&m_bookmarkManager)
-{
- ActionContainer *mtools = ActionManager::actionContainer(Core::Constants::M_TOOLS);
- ActionContainer *touchBar = ActionManager::actionContainer(Core::Constants::TOUCH_BAR);
- ActionContainer *mbm = ActionManager::createMenu(Id(BOOKMARKS_MENU));
- mbm->menu()->setTitle(Tr::tr("&Bookmarks"));
- mtools->addMenu(mbm);
-
- const Context editorManagerContext(Core::Constants::C_EDITORMANAGER);
-
- // Toggle
- Command *cmd = ActionManager::registerAction(&m_toggleAction, BOOKMARKS_TOGGLE_ACTION,
- editorManagerContext);
- cmd->setDefaultKeySequence(QKeySequence(useMacShortcuts ? Tr::tr("Meta+M") : Tr::tr("Ctrl+M")));
- cmd->setTouchBarIcon(Utils::Icons::MACOS_TOUCHBAR_BOOKMARK.icon());
- mbm->addAction(cmd);
- touchBar->addAction(cmd, Core::Constants::G_TOUCHBAR_EDITOR);
-
- cmd = ActionManager::registerAction(&m_editAction, BOOKMARKS_EDIT_ACTION, editorManagerContext);
- cmd->setDefaultKeySequence(
- QKeySequence(useMacShortcuts ? Tr::tr("Meta+Shift+M") : Tr::tr("Ctrl+Shift+M")));
- mbm->addAction(cmd);
-
- mbm->addSeparator();
-
- // Previous
- m_prevAction.setIcon(Utils::Icons::PREV_TOOLBAR.icon());
- m_prevAction.setIconVisibleInMenu(false);
- cmd = ActionManager::registerAction(&m_prevAction, BOOKMARKS_PREV_ACTION, editorManagerContext);
- cmd->setDefaultKeySequence(QKeySequence(useMacShortcuts ? Tr::tr("Meta+,")
- : Tr::tr("Ctrl+,")));
- mbm->addAction(cmd);
-
- // Next
- m_nextAction.setIcon(Utils::Icons::NEXT_TOOLBAR.icon());
- m_nextAction.setIconVisibleInMenu(false);
- cmd = ActionManager::registerAction(&m_nextAction, BOOKMARKS_NEXT_ACTION, editorManagerContext);
- cmd->setDefaultKeySequence(QKeySequence(useMacShortcuts ? Tr::tr("Meta+.")
- : Tr::tr("Ctrl+.")));
- mbm->addAction(cmd);
-
- mbm->addSeparator();
-
- // Previous Doc
- cmd = ActionManager::registerAction(&m_docPrevAction, BOOKMARKS_PREVDOC_ACTION,
- editorManagerContext);
- mbm->addAction(cmd);
-
- // Next Doc
- cmd = ActionManager::registerAction(&m_docNextAction, BOOKMARKS_NEXTDOC_ACTION,
- editorManagerContext);
- mbm->addAction(cmd);
-
- connect(&m_toggleAction, &QAction::triggered, this, [this] {
- IEditor *editor = EditorManager::currentEditor();
- auto widget = TextEditorWidget::fromEditor(editor);
- if (widget && editor && !editor->document()->isTemporary())
- m_bookmarkManager.toggleBookmark(editor->document()->filePath(), editor->currentLine());
- });
-
- connect(&m_editAction, &QAction::triggered, this, [this] {
- IEditor *editor = EditorManager::currentEditor();
- auto widget = TextEditorWidget::fromEditor(editor);
- if (widget && editor && !editor->document()->isTemporary()) {
- const FilePath filePath = editor->document()->filePath();
- const int line = editor->currentLine();
- if (!m_bookmarkManager.hasBookmarkInPosition(filePath, line))
- m_bookmarkManager.toggleBookmark(filePath, line);
- m_bookmarkManager.editByFileAndLine(filePath, line);
- }
- });
-
- connect(&m_prevAction, &QAction::triggered, &m_bookmarkManager, &BookmarkManager::prev);
- connect(&m_nextAction, &QAction::triggered, &m_bookmarkManager, &BookmarkManager::next);
- connect(&m_docPrevAction, &QAction::triggered,
- &m_bookmarkManager, &BookmarkManager::prevInDocument);
- connect(&m_docNextAction, &QAction::triggered,
- &m_bookmarkManager, &BookmarkManager::nextInDocument);
-
- connect(&m_editBookmarkAction, &QAction::triggered, this, [this] {
- m_bookmarkManager.editByFileAndLine(m_marginActionFileName, m_marginActionLineNumber);
- });
-
- connect(&m_bookmarkManager, &BookmarkManager::updateActions,
- this, &BookmarksPluginPrivate::updateActions);
- updateActions(false, m_bookmarkManager.state());
-
- connect(&m_bookmarkMarginAction, &QAction::triggered, this, [this] {
- m_bookmarkManager.toggleBookmark(m_marginActionFileName, m_marginActionLineNumber);
- });
-
- // EditorManager
- connect(EditorManager::instance(), &EditorManager::editorAboutToClose,
- this, &BookmarksPluginPrivate::editorAboutToClose);
- connect(EditorManager::instance(), &EditorManager::editorOpened,
- this, &BookmarksPluginPrivate::editorOpened);
-}
-
-void BookmarksPluginPrivate::updateActions(bool enableToggle, int state)
-{
- const bool hasbm = state >= BookmarkManager::HasBookMarks;
- const bool hasdocbm = state == BookmarkManager::HasBookmarksInDocument;
-
- m_toggleAction.setEnabled(enableToggle);
- m_editAction.setEnabled(enableToggle);
- m_prevAction.setEnabled(hasbm);
- m_nextAction.setEnabled(hasbm);
- m_docPrevAction.setEnabled(hasdocbm);
- m_docNextAction.setEnabled(hasdocbm);
-}
-
-void BookmarksPluginPrivate::editorOpened(IEditor *editor)
-{
- if (auto widget = TextEditorWidget::fromEditor(editor)) {
- connect(widget, &TextEditorWidget::markRequested,
- this, [this, editor](TextEditorWidget *, int line, TextMarkRequestKind kind) {
- if (kind == BookmarkRequest && !editor->document()->isTemporary())
- m_bookmarkManager.toggleBookmark(editor->document()->filePath(), line);
- });
-
- connect(widget, &TextEditorWidget::markContextMenuRequested,
- this, &BookmarksPluginPrivate::requestContextMenu);
- }
-}
-
-void BookmarksPluginPrivate::editorAboutToClose(IEditor *editor)
-{
- if (auto widget = TextEditorWidget::fromEditor(editor)) {
- disconnect(widget, &TextEditorWidget::markContextMenuRequested,
- this, &BookmarksPluginPrivate::requestContextMenu);
- }
-}
-
-void BookmarksPluginPrivate::requestContextMenu(TextEditorWidget *widget,
- int lineNumber, QMenu *menu)
-{
- if (widget->textDocument()->isTemporary())
- return;
-
- m_marginActionLineNumber = lineNumber;
- m_marginActionFileName = widget->textDocument()->filePath();
-
- menu->addAction(&m_bookmarkMarginAction);
- if (m_bookmarkManager.hasBookmarkInPosition(m_marginActionFileName, m_marginActionLineNumber))
- menu->addAction(&m_editBookmarkAction);
-}
-
-} // Bookmarks::Internal
diff --git a/src/plugins/bookmarks/bookmarksplugin.h b/src/plugins/bookmarks/bookmarksplugin.h
deleted file mode 100644
index 06764043c7b..00000000000
--- a/src/plugins/bookmarks/bookmarksplugin.h
+++ /dev/null
@@ -1,22 +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 <extensionsystem/iplugin.h>
-
-namespace Bookmarks::Internal {
-
-class BookmarksPlugin final : public ExtensionSystem::IPlugin
-{
- Q_OBJECT
- Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "Bookmarks.json")
-
- ~BookmarksPlugin() final;
-
- void initialize() final;
-
- class BookmarksPluginPrivate *d = nullptr;
-};
-
-} // Bookmarks::Internal
diff --git a/src/plugins/bookmarks/bookmarkstr.h b/src/plugins/bookmarks/bookmarkstr.h
deleted file mode 100644
index c48879d3470..00000000000
--- a/src/plugins/bookmarks/bookmarkstr.h
+++ /dev/null
@@ -1,15 +0,0 @@
-// Copyright (C) 2022 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
-
-#pragma once
-
-#include <QCoreApplication>
-
-namespace Bookmarks {
-
-struct Tr
-{
- Q_DECLARE_TR_FUNCTIONS(QtC::Bookmarks)
-};
-
-} // namespace Bookmarks
diff --git a/src/plugins/plugins.qbs b/src/plugins/plugins.qbs
index 0ea388ec705..6adaa25ae7e 100644
--- a/src/plugins/plugins.qbs
+++ b/src/plugins/plugins.qbs
@@ -12,7 +12,6 @@ Project {
"bazaar/bazaar.qbs",
"beautifier/beautifier.qbs",
"bineditor/bineditor.qbs",
- "bookmarks/bookmarks.qbs",
"boot2qt/boot2qt.qbs",
"clangcodemodel/clangcodemodel.qbs",
"clangformat/clangformat.qbs",
diff --git a/src/plugins/texteditor/CMakeLists.txt b/src/plugins/texteditor/CMakeLists.txt
index 81d562778d5..03efc189224 100644
--- a/src/plugins/texteditor/CMakeLists.txt
+++ b/src/plugins/texteditor/CMakeLists.txt
@@ -16,6 +16,9 @@ add_qtc_plugin(TextEditor
behaviorsettingspage.cpp behaviorsettingspage.h
behaviorsettingswidget.cpp behaviorsettingswidget.h
blockrange.h
+ bookmark.cpp bookmark.h
+ bookmarkfilter.cpp bookmarkfilter.h
+ bookmarkmanager.cpp bookmarkmanager.h
circularclipboard.cpp circularclipboard.h
circularclipboardassist.cpp circularclipboardassist.h
codeassist/assistenums.h
diff --git a/src/plugins/texteditor/basefilefind.cpp b/src/plugins/texteditor/basefilefind.cpp
index 91c0b8e259a..3b9d68d3c37 100644
--- a/src/plugins/texteditor/basefilefind.cpp
+++ b/src/plugins/texteditor/basefilefind.cpp
@@ -357,7 +357,7 @@ void BaseFileFind::runSearch(SearchResult *search)
d->m_futureSynchronizer.addFuture(future);
FutureProgress *progress = ProgressManager::addTask(future,
Tr::tr("Searching"),
- Constants::TASK_SEARCH);
+ Core::Constants::TASK_SEARCH);
connect(search, &SearchResult::countChanged, progress, [progress](int c) {
progress->setSubtitle(Tr::tr("%n found.", nullptr, c));
});
diff --git a/src/plugins/bookmarks/bookmark.cpp b/src/plugins/texteditor/bookmark.cpp
index 27c8365e19e..9d13d5a6b23 100644
--- a/src/plugins/bookmarks/bookmark.cpp
+++ b/src/plugins/texteditor/bookmark.cpp
@@ -4,8 +4,8 @@
#include "bookmark.h"
#include "bookmarkmanager.h"
-#include "bookmarks_global.h"
-#include "bookmarkstr.h"
+#include "texteditor_global.h"
+#include "texteditortr.h"
#include <utils/utilsicons.h>
@@ -13,16 +13,18 @@
using namespace Utils;
-namespace Bookmarks::Internal {
+namespace TextEditor::Internal {
+
+const char BOOKMARKS_TEXT_MARK_CATEGORY[] = "Bookmarks.TextMarkCategory";
Bookmark::Bookmark(int lineNumber, BookmarkManager *manager) :
- TextMark(FilePath(), lineNumber, {Tr::tr("Bookmark"), Constants::BOOKMARKS_TEXT_MARK_CATEGORY}),
+ TextMark(FilePath(), lineNumber, {Tr::tr("Bookmark"), BOOKMARKS_TEXT_MARK_CATEGORY}),
m_manager(manager)
{
setColor(Theme::Bookmarks_TextMarkColor);
setIcon(Icons::BOOKMARK_TEXTEDITOR.icon());
setDefaultToolTip(Tr::tr("Bookmark"));
- setPriority(TextEditor::TextMark::NormalPriority);
+ setPriority(TextMark::NormalPriority);
}
void Bookmark::removedFromEditor()
diff --git a/src/plugins/bookmarks/bookmark.h b/src/plugins/texteditor/bookmark.h
index 44277d19c60..1c8c522363e 100644
--- a/src/plugins/bookmarks/bookmark.h
+++ b/src/plugins/texteditor/bookmark.h
@@ -5,11 +5,11 @@
#include <texteditor/textmark.h>
-namespace Bookmarks::Internal {
+namespace TextEditor::Internal {
class BookmarkManager;
-class Bookmark : public TextEditor::TextMark
+class Bookmark : public TextMark
{
public:
Bookmark(int lineNumber, BookmarkManager *manager);
@@ -34,4 +34,4 @@ private:
QString m_lineText;
};
-} // Bookmarks::Internal
+} // TextEditor::Internal
diff --git a/src/plugins/bookmarks/bookmarkfilter.cpp b/src/plugins/texteditor/bookmarkfilter.cpp
index 1cedbade481..2756521cd89 100644
--- a/src/plugins/bookmarks/bookmarkfilter.cpp
+++ b/src/plugins/texteditor/bookmarkfilter.cpp
@@ -5,14 +5,14 @@
#include "bookmark.h"
#include "bookmarkmanager.h"
-#include "bookmarkstr.h"
+#include "texteditortr.h"
#include <utils/algorithm.h>
using namespace Core;
using namespace Utils;
-namespace Bookmarks::Internal {
+namespace TextEditor::Internal {
BookmarkFilter::BookmarkFilter(BookmarkManager *manager)
: m_manager(manager)
@@ -112,4 +112,4 @@ LocatorFilterEntries BookmarkFilter::match(const QString &input) const
return entries;
}
-} // Bookmarks::Internal
+} // TextEditor::Internal
diff --git a/src/plugins/bookmarks/bookmarkfilter.h b/src/plugins/texteditor/bookmarkfilter.h
index f85eff9b7d7..fca42dd679d 100644
--- a/src/plugins/bookmarks/bookmarkfilter.h
+++ b/src/plugins/texteditor/bookmarkfilter.h
@@ -5,7 +5,7 @@
#include <coreplugin/locator/ilocatorfilter.h>
-namespace Bookmarks::Internal {
+namespace TextEditor::Internal {
class BookmarkManager;
@@ -21,4 +21,4 @@ private:
BookmarkManager *m_manager = nullptr; // not owned
};
-} // Bookmarks::Internal
+} // TextEditor::Internal
diff --git a/src/plugins/bookmarks/bookmarkmanager.cpp b/src/plugins/texteditor/bookmarkmanager.cpp
index 18a4206afd3..1ab12cfb88d 100644
--- a/src/plugins/bookmarks/bookmarkmanager.cpp
+++ b/src/plugins/texteditor/bookmarkmanager.cpp
@@ -4,8 +4,8 @@
#include "bookmarkmanager.h"
#include "bookmark.h"
-#include "bookmarks_global.h"
-#include "bookmarkstr.h"
+#include "texteditorconstants.h"
+#include "texteditortr.h"
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/command.h>
@@ -14,8 +14,6 @@
#include <coreplugin/idocument.h>
#include <coreplugin/session.h>
-#include <texteditor/texteditor.h>
-
#include <utils/algorithm.h>
#include <utils/icon.h>
#include <utils/qtcassert.h>
@@ -35,12 +33,14 @@
#include <QSpinBox>
#include <QToolButton>
-Q_DECLARE_METATYPE(Bookmarks::Internal::Bookmark*)
+Q_DECLARE_METATYPE(TextEditor::Internal::Bookmark*)
using namespace Core;
using namespace Utils;
-namespace Bookmarks::Internal {
+namespace TextEditor::Internal {
+
+const char BOOKMARKS_CONTEXT[] = "Bookmarks";
class BookmarkDelegate : public QStyledItemDelegate
{
@@ -201,7 +201,7 @@ BookmarkView::BookmarkView(BookmarkManager *manager) :
setWindowTitle(Tr::tr("Bookmarks"));
m_bookmarkContext->setWidget(this);
- m_bookmarkContext->setContext(Context(Constants::BOOKMARKS_CONTEXT));
+ m_bookmarkContext->setContext(Context(BOOKMARKS_CONTEXT));
ICore::addContextObject(m_bookmarkContext);
@@ -223,8 +223,8 @@ BookmarkView::BookmarkView(BookmarkManager *manager) :
QList<QToolButton *> BookmarkView::createToolBarWidgets()
{
- Command *prevCmd = ActionManager::command(Constants::BOOKMARKS_PREV_ACTION);
- Command *nextCmd = ActionManager::command(Constants::BOOKMARKS_NEXT_ACTION);
+ Command *prevCmd = ActionManager::command(TextEditor::Constants::BOOKMARKS_PREV_ACTION);
+ Command *nextCmd = ActionManager::command(TextEditor::Constants::BOOKMARKS_NEXT_ACTION);
QTC_ASSERT(prevCmd && nextCmd, return {});
auto prevButton = new QToolButton(this);
prevButton->setToolButtonStyle(Qt::ToolButtonIconOnly);
@@ -827,4 +827,4 @@ NavigationView BookmarkViewFactory::createWidget()
return {view, view->createToolBarWidgets()};
}
-} // Bookmarks::Internal
+} // TextEditor::Internal
diff --git a/src/plugins/bookmarks/bookmarkmanager.h b/src/plugins/texteditor/bookmarkmanager.h
index 0455d316375..4df91094e3d 100644
--- a/src/plugins/bookmarks/bookmarkmanager.h
+++ b/src/plugins/texteditor/bookmarkmanager.h
@@ -16,7 +16,7 @@
namespace Core { class IContext; }
-namespace Bookmarks::Internal {
+namespace TextEditor::Internal {
class Bookmark;
class BookmarksPlugin;
diff --git a/src/plugins/texteditor/texteditor.qbs b/src/plugins/texteditor/texteditor.qbs
index 76644a13570..a041fbcaa66 100644
--- a/src/plugins/texteditor/texteditor.qbs
+++ b/src/plugins/texteditor/texteditor.qbs
@@ -31,6 +31,12 @@ QtcPlugin {
"behaviorsettingswidget.cpp",
"behaviorsettingswidget.h",
"blockrange.h",
+ "bookmark.cpp",
+ "bookmark.h",
+ "bookmarkfilter.cpp",
+ "bookmarkfilter.h",
+ "bookmarkmanager.cpp",
+ "bookmarkmanager.h",
"circularclipboard.cpp",
"circularclipboard.h",
"circularclipboardassist.cpp",
diff --git a/src/plugins/texteditor/texteditorconstants.h b/src/plugins/texteditor/texteditorconstants.h
index 9da6b86eb37..03433fd0e8c 100644
--- a/src/plugins/texteditor/texteditorconstants.h
+++ b/src/plugins/texteditor/texteditorconstants.h
@@ -236,6 +236,9 @@ const char TEXT_SNIPPET_GROUP_ID[] = "Text";
const char GLOBAL_SETTINGS_ID[] = "Global";
const char GENERIC_PROPOSAL_ID[] = "TextEditor.GenericProposalId";
+const char BOOKMARKS_PREV_ACTION[] = "Bookmarks.Previous";
+const char BOOKMARKS_NEXT_ACTION[] = "Bookmarks.Next";
+
/**
* Delay before tooltip will be shown near completion assistant proposal
*/
diff --git a/src/plugins/texteditor/texteditorplugin.cpp b/src/plugins/texteditor/texteditorplugin.cpp
index d0df98fb8af..f8de8503937 100644
--- a/src/plugins/texteditor/texteditorplugin.cpp
+++ b/src/plugins/texteditor/texteditorplugin.cpp
@@ -3,7 +3,8 @@
#include "texteditorplugin.h"
-#include "commentssettings.h"
+#include "bookmarkfilter.h"
+#include "bookmarkmanager.h"
#include "findincurrentfile.h"
#include "findinfiles.h"
#include "findinopenfiles.h"
@@ -18,7 +19,9 @@
#include "snippets/snippetprovider.h"
#include "tabsettings.h"
#include "textdocument.h"
+#include "textdocument.h"
#include "texteditor.h"
+#include "texteditorconstants.h"
#include "texteditorsettings.h"
#include "texteditortr.h"
@@ -30,26 +33,28 @@
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/command.h>
+#include <coreplugin/coreconstants.h>
#include <coreplugin/diffservice.h>
+#include <coreplugin/editormanager/editormanager.h>
+#include <coreplugin/editormanager/ieditor.h>
#include <coreplugin/externaltoolmanager.h>
#include <coreplugin/foldernavigationwidget.h>
#include <coreplugin/icore.h>
#include <extensionsystem/pluginmanager.h>
-#include <projectexplorer/projectpanelfactory.h>
-
#include <utils/fancylineedit.h>
#include <utils/qtcassert.h>
#include <utils/macroexpander.h>
+#include <utils/utilsicons.h>
#include <QMenu>
using namespace Core;
using namespace Utils;
+using namespace TextEditor::Constants;
-namespace TextEditor {
-namespace Internal {
+namespace TextEditor::Internal {
const char kCurrentDocumentSelection[] = "CurrentDocument:Selection";
const char kCurrentDocumentRow[] = "CurrentDocument:Row";
@@ -62,13 +67,37 @@ const char kCurrentDocumentWordUnderCursor[] = "CurrentDocument:WordUnderCursor"
class TextEditorPluginPrivate : public QObject
{
public:
+ TextEditorPluginPrivate();
+
+ void updateActions(bool enableToggle, int stateMask);
+ void editorOpened(Core::IEditor *editor);
+ void editorAboutToClose(Core::IEditor *editor);
+
+ void requestContextMenu(TextEditorWidget *widget, int lineNumber, QMenu *menu);
+
void extensionsInitialized();
- void updateSearchResultsFont(const TextEditor::FontSettings &);
- void updateSearchResultsTabWidth(const TextEditor::TabSettings &tabSettings);
+ void updateSearchResultsFont(const FontSettings &);
+ void updateSearchResultsTabWidth(const TabSettings &tabSettings);
void updateCurrentSelection(const QString &text);
void createStandardContextMenu();
+ BookmarkManager m_bookmarkManager;
+ BookmarkFilter m_bookmarkFilter{&m_bookmarkManager};
+ BookmarkViewFactory m_bookmarkViewFactory{&m_bookmarkManager};
+
+ QAction m_toggleAction{Tr::tr("Toggle Bookmark")};
+ QAction m_editAction{Tr::tr("Edit Bookmark")};
+ QAction m_prevAction{Tr::tr("Previous Bookmark")};
+ QAction m_nextAction{Tr::tr("Next Bookmark")};
+ QAction m_docPrevAction{Tr::tr("Previous Bookmark in Document")};
+ QAction m_docNextAction{Tr::tr("Next Bookmark in Document")};
+ QAction m_editBookmarkAction{Tr::tr("Edit Bookmark")};
+ QAction m_bookmarkMarginAction{Tr::tr("Toggle Bookmark")};
+
+ int m_marginActionLineNumber = 0;
+ FilePath m_marginActionFileName;
+
TextEditorSettings settings;
LineNumberFilter lineNumberFilter; // Goto line functionality for quick open
OutlineFactory outlineFactory;
@@ -82,6 +111,154 @@ public:
JsonEditorFactory jsonEditorFactory;
};
+TextEditorPluginPrivate::TextEditorPluginPrivate()
+{
+ ActionContainer *mtools = ActionManager::actionContainer(Core::Constants::M_TOOLS);
+ ActionContainer *touchBar = ActionManager::actionContainer(Core::Constants::TOUCH_BAR);
+ ActionContainer *mbm = ActionManager::createMenu(Id("Bookmarks.Menu"));
+
+ mbm->menu()->setTitle(Tr::tr("&Bookmarks"));
+ mtools->addMenu(mbm);
+
+ const Context editorManagerContext(Core::Constants::C_EDITORMANAGER);
+
+ // Toggle
+ Command *cmd = ActionManager::registerAction(&m_toggleAction, "Bookmarks.Toggle",
+ editorManagerContext);
+ cmd->setDefaultKeySequence(QKeySequence(useMacShortcuts ? Tr::tr("Meta+M") : Tr::tr("Ctrl+M")));
+ cmd->setTouchBarIcon(Icons::MACOS_TOUCHBAR_BOOKMARK.icon());
+ mbm->addAction(cmd);
+ touchBar->addAction(cmd, Core::Constants::G_TOUCHBAR_EDITOR);
+
+ cmd = ActionManager::registerAction(&m_editAction, "Bookmarks.Edit", editorManagerContext);
+ cmd->setDefaultKeySequence(
+ QKeySequence(useMacShortcuts ? Tr::tr("Meta+Shift+M") : Tr::tr("Ctrl+Shift+M")));
+ mbm->addAction(cmd);
+
+ mbm->addSeparator();
+
+ // Previous
+ m_prevAction.setIcon(Icons::PREV_TOOLBAR.icon());
+ m_prevAction.setIconVisibleInMenu(false);
+ cmd = ActionManager::registerAction(&m_prevAction, BOOKMARKS_PREV_ACTION, editorManagerContext);
+ cmd->setDefaultKeySequence(QKeySequence(useMacShortcuts ? Tr::tr("Meta+,")
+ : Tr::tr("Ctrl+,")));
+ mbm->addAction(cmd);
+
+ // Next
+ m_nextAction.setIcon(Icons::NEXT_TOOLBAR.icon());
+ m_nextAction.setIconVisibleInMenu(false);
+ cmd = ActionManager::registerAction(&m_nextAction, BOOKMARKS_NEXT_ACTION, editorManagerContext);
+ cmd->setDefaultKeySequence(QKeySequence(useMacShortcuts ? Tr::tr("Meta+.")
+ : Tr::tr("Ctrl+.")));
+ mbm->addAction(cmd);
+
+ mbm->addSeparator();
+
+ // Previous Doc
+ cmd = ActionManager::registerAction(&m_docPrevAction, "Bookmarks.PreviousDocument",
+ editorManagerContext);
+ mbm->addAction(cmd);
+
+ // Next Doc
+ cmd = ActionManager::registerAction(&m_docNextAction, "Bookmarks.NextDocument",
+ editorManagerContext);
+ mbm->addAction(cmd);
+
+ connect(&m_toggleAction, &QAction::triggered, this, [this] {
+ IEditor *editor = EditorManager::currentEditor();
+ auto widget = TextEditorWidget::fromEditor(editor);
+ if (widget && editor && !editor->document()->isTemporary())
+ m_bookmarkManager.toggleBookmark(editor->document()->filePath(), editor->currentLine());
+ });
+
+ connect(&m_editAction, &QAction::triggered, this, [this] {
+ IEditor *editor = EditorManager::currentEditor();
+ auto widget = TextEditorWidget::fromEditor(editor);
+ if (widget && editor && !editor->document()->isTemporary()) {
+ const FilePath filePath = editor->document()->filePath();
+ const int line = editor->currentLine();
+ if (!m_bookmarkManager.hasBookmarkInPosition(filePath, line))
+ m_bookmarkManager.toggleBookmark(filePath, line);
+ m_bookmarkManager.editByFileAndLine(filePath, line);
+ }
+ });
+
+ connect(&m_prevAction, &QAction::triggered, &m_bookmarkManager, &BookmarkManager::prev);
+ connect(&m_nextAction, &QAction::triggered, &m_bookmarkManager, &BookmarkManager::next);
+ connect(&m_docPrevAction, &QAction::triggered,
+ &m_bookmarkManager, &BookmarkManager::prevInDocument);
+ connect(&m_docNextAction, &QAction::triggered,
+ &m_bookmarkManager, &BookmarkManager::nextInDocument);
+
+ connect(&m_editBookmarkAction, &QAction::triggered, this, [this] {
+ m_bookmarkManager.editByFileAndLine(m_marginActionFileName, m_marginActionLineNumber);
+ });
+
+ connect(&m_bookmarkManager, &BookmarkManager::updateActions,
+ this, &TextEditorPluginPrivate::updateActions);
+ updateActions(false, m_bookmarkManager.state());
+
+ connect(&m_bookmarkMarginAction, &QAction::triggered, this, [this] {
+ m_bookmarkManager.toggleBookmark(m_marginActionFileName, m_marginActionLineNumber);
+ });
+
+ // EditorManager
+ connect(EditorManager::instance(), &EditorManager::editorAboutToClose,
+ this, &TextEditorPluginPrivate::editorAboutToClose);
+ connect(EditorManager::instance(), &EditorManager::editorOpened,
+ this, &TextEditorPluginPrivate::editorOpened);
+}
+
+void TextEditorPluginPrivate::updateActions(bool enableToggle, int state)
+{
+ const bool hasbm = state >= BookmarkManager::HasBookMarks;
+ const bool hasdocbm = state == BookmarkManager::HasBookmarksInDocument;
+
+ m_toggleAction.setEnabled(enableToggle);
+ m_editAction.setEnabled(enableToggle);
+ m_prevAction.setEnabled(hasbm);
+ m_nextAction.setEnabled(hasbm);
+ m_docPrevAction.setEnabled(hasdocbm);
+ m_docNextAction.setEnabled(hasdocbm);
+}
+
+void TextEditorPluginPrivate::editorOpened(IEditor *editor)
+{
+ if (auto widget = TextEditorWidget::fromEditor(editor)) {
+ connect(widget, &TextEditorWidget::markRequested,
+ this, [this, editor](TextEditorWidget *, int line, TextMarkRequestKind kind) {
+ if (kind == BookmarkRequest && !editor->document()->isTemporary())
+ m_bookmarkManager.toggleBookmark(editor->document()->filePath(), line);
+ });
+
+ connect(widget, &TextEditorWidget::markContextMenuRequested,
+ this, &TextEditorPluginPrivate::requestContextMenu);
+ }
+}
+
+void TextEditorPluginPrivate::editorAboutToClose(IEditor *editor)
+{
+ if (auto widget = TextEditorWidget::fromEditor(editor)) {
+ disconnect(widget, &TextEditorWidget::markContextMenuRequested,
+ this, &TextEditorPluginPrivate::requestContextMenu);
+ }
+}
+
+void TextEditorPluginPrivate::requestContextMenu(TextEditorWidget *widget,
+ int lineNumber, QMenu *menu)
+{
+ if (widget->textDocument()->isTemporary())
+ return;
+
+ m_marginActionLineNumber = lineNumber;
+ m_marginActionFileName = widget->textDocument()->filePath();
+
+ menu->addAction(&m_bookmarkMarginAction);
+ if (m_bookmarkManager.hasBookmarkInPosition(m_marginActionFileName, m_marginActionLineNumber))
+ menu->addAction(&m_editBookmarkAction);
+}
+
static TextEditorPlugin *m_instance = nullptr;
TextEditorPlugin::TextEditorPlugin()
@@ -117,9 +294,9 @@ void TextEditorPlugin::initialize()
editor->editorWidget()->invokeAssist(Completion);
});
connect(command, &Command::keySequenceChanged, [command] {
- Utils::FancyLineEdit::setCompletionShortcut(command->keySequence());
+ FancyLineEdit::setCompletionShortcut(command->keySequence());
});
- Utils::FancyLineEdit::setCompletionShortcut(command->keySequence());
+ FancyLineEdit::setCompletionShortcut(command->keySequence());
// Add shortcut for invoking function hint completion
QAction *functionHintAction = new QAction(Tr::tr("Display Function Hint"), this);
@@ -167,7 +344,7 @@ void TextEditorPluginPrivate::extensionsInitialized()
&FolderNavigationWidgetFactory::aboutToShowContextMenu,
this, [](QMenu *menu, const FilePath &filePath, bool isDir) {
if (!isDir && Core::DiffService::instance()) {
- menu->addAction(TextEditor::TextDocument::createDiffAgainstCurrentFileAction(
+ menu->addAction(TextDocument::createDiffAgainstCurrentFileAction(
menu, [filePath] { return filePath; }));
}
});
@@ -192,7 +369,7 @@ void TextEditorPlugin::extensionsInitialized()
{
d->extensionsInitialized();
- Utils::MacroExpander *expander = Utils::globalMacroExpander();
+ MacroExpander *expander = Utils::globalMacroExpander();
expander->registerVariable(kCurrentDocumentSelection,
Tr::tr("Selected text within the current document."),
@@ -341,5 +518,4 @@ void TextEditorPluginPrivate::createStandardContextMenu()
add(Constants::SWITCH_UTF8BOM, Constants::G_BOM);
}
-} // namespace Internal
-} // namespace TextEditor
+} // namespace TextEditor::Internal