forked from qt-creator/qt-creator
Bookmark: Add command to edit a bookmark
This command opens the edit dialog for the bookmark that is at the current editors text cursor. If there is no bookmark at that position a new bookmark will be added before the edit dialog is opened. Fixes: QTCREATORBUG-25696 Change-Id: I6a63a87cbbfb9d9075fac25b7ed9dd59d135b2c8 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -29,6 +29,7 @@ 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";
|
||||
|
@@ -72,6 +72,7 @@ public:
|
||||
BookmarkViewFactory m_bookmarkViewFactory;
|
||||
|
||||
QAction m_toggleAction{BookmarksPlugin::tr("Toggle Bookmark"), nullptr};
|
||||
QAction m_editAction{BookmarksPlugin::tr("Edit Bookmark"), nullptr};
|
||||
QAction m_prevAction{BookmarksPlugin::tr("Previous Bookmark"), nullptr};
|
||||
QAction m_nextAction{BookmarksPlugin::tr("Next Bookmark"), nullptr};
|
||||
QAction m_docPrevAction{BookmarksPlugin::tr("Previous Bookmark in Document"), nullptr};
|
||||
@@ -113,6 +114,14 @@ BookmarksPluginPrivate::BookmarksPluginPrivate()
|
||||
: BookmarksPlugin::tr("Ctrl+M")));
|
||||
cmd->setTouchBarIcon(Utils::Icons::MACOS_TOUCHBAR_BOOKMARK.icon());
|
||||
mbm->addAction(cmd);
|
||||
|
||||
cmd = ActionManager::registerAction(&m_editAction,
|
||||
BOOKMARKS_EDIT_ACTION,
|
||||
editorManagerContext);
|
||||
cmd->setDefaultKeySequence(QKeySequence(useMacShortcuts ? BookmarksPlugin::tr("Meta+Shift+M")
|
||||
: BookmarksPlugin::tr("Ctrl+Shift+M")));
|
||||
mbm->addAction(cmd);
|
||||
|
||||
touchBar->addAction(cmd, Core::Constants::G_TOUCHBAR_EDITOR);
|
||||
|
||||
mbm->addSeparator();
|
||||
@@ -151,6 +160,17 @@ BookmarksPluginPrivate::BookmarksPluginPrivate()
|
||||
m_bookmarkManager.toggleBookmark(editor->document()->filePath(), editor->currentLine());
|
||||
});
|
||||
|
||||
connect(&m_editAction, &QAction::triggered, this, [this] {
|
||||
BaseTextEditor *editor = BaseTextEditor::currentTextEditor();
|
||||
if (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,
|
||||
@@ -183,6 +203,7 @@ void BookmarksPluginPrivate::updateActions(bool enableToggle, int state)
|
||||
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);
|
||||
|
Reference in New Issue
Block a user