forked from qt-creator/qt-creator
Add keyboard shortcuts for bookmarks
Add keyboard shortcuts to move bookmarks up or down Add keyboard shortcut to sort bookmarks by filenames and line numbers Fixes: QTCREATORBUG-30286 Change-Id: Iaf40f389e51357cb7d9fdf214e3acd0765fd1201 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
committed by
Xavier BESSON (Personal)
parent
b2d08d4f09
commit
f15f048ee9
@@ -214,6 +214,14 @@ BookmarkView::BookmarkView()
|
|||||||
setDragDropMode(QAbstractItemView::DragDrop);
|
setDragDropMode(QAbstractItemView::DragDrop);
|
||||||
|
|
||||||
connect(this, &QAbstractItemView::activated, this, &BookmarkView::gotoBookmark);
|
connect(this, &QAbstractItemView::activated, this, &BookmarkView::gotoBookmark);
|
||||||
|
connect(this->selectionModel(), &QItemSelectionModel::currentRowChanged,
|
||||||
|
this, [=](const QModelIndex ¤t, const QModelIndex &previous) {
|
||||||
|
Q_UNUSED(previous)
|
||||||
|
Command *moveUpCmd = ActionManager::command(TextEditor::Constants::BOOKMARKS_MOVEUP_ACTION);
|
||||||
|
Command *moveDownCmd = ActionManager::command(TextEditor::Constants::BOOKMARKS_MOVEDOWN_ACTION);
|
||||||
|
moveUpCmd->action()->setEnabled(current.isValid());
|
||||||
|
moveDownCmd->action()->setEnabled(current.isValid());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QToolButton *> BookmarkView::createToolBarWidgets()
|
QList<QToolButton *> BookmarkView::createToolBarWidgets()
|
||||||
@@ -233,8 +241,14 @@ QList<QToolButton *> BookmarkView::createToolBarWidgets()
|
|||||||
void BookmarkView::contextMenuEvent(QContextMenuEvent *event)
|
void BookmarkView::contextMenuEvent(QContextMenuEvent *event)
|
||||||
{
|
{
|
||||||
QMenu menu;
|
QMenu menu;
|
||||||
QAction *moveUp = menu.addAction(Tr::tr("Move Up"));
|
Command *moveUpCmd = ActionManager::command(TextEditor::Constants::BOOKMARKS_MOVEUP_ACTION);
|
||||||
QAction *moveDown = menu.addAction(Tr::tr("Move Down"));
|
Command *moveDownCmd = ActionManager::command(TextEditor::Constants::BOOKMARKS_MOVEDOWN_ACTION);
|
||||||
|
menu.addAction(moveUpCmd->action());
|
||||||
|
menu.addAction(moveDownCmd->action());
|
||||||
|
menu.addSeparator();
|
||||||
|
Command *sortByFilenamesCmd = ActionManager::command(TextEditor::Constants::BOOKMARKS_SORTBYFILENAMES_ACTION);
|
||||||
|
menu.addAction(sortByFilenamesCmd->action());
|
||||||
|
menu.addSeparator();
|
||||||
QAction *edit = menu.addAction(Tr::tr("&Edit"));
|
QAction *edit = menu.addAction(Tr::tr("&Edit"));
|
||||||
menu.addSeparator();
|
menu.addSeparator();
|
||||||
QAction *remove = menu.addAction(Tr::tr("&Remove"));
|
QAction *remove = menu.addAction(Tr::tr("&Remove"));
|
||||||
@@ -243,18 +257,17 @@ void BookmarkView::contextMenuEvent(QContextMenuEvent *event)
|
|||||||
|
|
||||||
m_contextMenuIndex = indexAt(event->pos());
|
m_contextMenuIndex = indexAt(event->pos());
|
||||||
if (!m_contextMenuIndex.isValid()) {
|
if (!m_contextMenuIndex.isValid()) {
|
||||||
moveUp->setEnabled(false);
|
moveUpCmd->action()->setEnabled(false);
|
||||||
moveDown->setEnabled(false);
|
moveDownCmd->action()->setEnabled(false);
|
||||||
remove->setEnabled(false);
|
remove->setEnabled(false);
|
||||||
edit->setEnabled(false);
|
edit->setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (model()->rowCount() == 0)
|
if (model()->rowCount() == 0) {
|
||||||
removeAll->setEnabled(false);
|
removeAll->setEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
BookmarkManager *manager = &bookmarkManager();
|
BookmarkManager *manager = &bookmarkManager();
|
||||||
connect(moveUp, &QAction::triggered, manager, &BookmarkManager::moveUp);
|
|
||||||
connect(moveDown, &QAction::triggered, manager, &BookmarkManager::moveDown);
|
|
||||||
connect(remove, &QAction::triggered, this, &BookmarkView::removeFromContextMenu);
|
connect(remove, &QAction::triggered, this, &BookmarkView::removeFromContextMenu);
|
||||||
connect(removeAll, &QAction::triggered, this, &BookmarkView::removeAll);
|
connect(removeAll, &QAction::triggered, this, &BookmarkView::removeAll);
|
||||||
connect(edit, &QAction::triggered, manager, &BookmarkManager::edit);
|
connect(edit, &QAction::triggered, manager, &BookmarkManager::edit);
|
||||||
@@ -327,6 +340,7 @@ BookmarkManager::BookmarkManager(QObject *parent)
|
|||||||
|
|
||||||
const Id bookmarkMenuId = "Bookmarks.Menu";
|
const Id bookmarkMenuId = "Bookmarks.Menu";
|
||||||
const Context editorManagerContext(Core::Constants::C_EDITORMANAGER);
|
const Context editorManagerContext(Core::Constants::C_EDITORMANAGER);
|
||||||
|
const Context bookmarksContext(BOOKMARKS_CONTEXT);
|
||||||
|
|
||||||
MenuBuilder bookmarkMenu(bookmarkMenuId);
|
MenuBuilder bookmarkMenu(bookmarkMenuId);
|
||||||
bookmarkMenu.setTitle(Tr::tr("&Bookmarks"));
|
bookmarkMenu.setTitle(Tr::tr("&Bookmarks"));
|
||||||
@@ -413,6 +427,24 @@ BookmarkManager::BookmarkManager(QObject *parent)
|
|||||||
ActionContainer *touchBar = ActionManager::actionContainer(Core::Constants::TOUCH_BAR);
|
ActionContainer *touchBar = ActionManager::actionContainer(Core::Constants::TOUCH_BAR);
|
||||||
touchBar->addAction(toggleAction.command(), Core::Constants::G_TOUCHBAR_EDITOR);
|
touchBar->addAction(toggleAction.command(), Core::Constants::G_TOUCHBAR_EDITOR);
|
||||||
|
|
||||||
|
ActionBuilder moveDownAction(this, Constants::BOOKMARKS_MOVEDOWN_ACTION);
|
||||||
|
moveDownAction.setContext(bookmarksContext);
|
||||||
|
moveDownAction.setText(Tr::tr("Move Down"));
|
||||||
|
moveDownAction.setDefaultKeySequence(Tr::tr("Ctrl+Alt+."));
|
||||||
|
moveDownAction.addOnTriggered(this, [this] { moveDown(); });
|
||||||
|
|
||||||
|
ActionBuilder moveUpAction(this, Constants::BOOKMARKS_MOVEUP_ACTION);
|
||||||
|
moveUpAction.setContext(bookmarksContext);
|
||||||
|
moveUpAction.setText(Tr::tr("Move Up"));
|
||||||
|
moveUpAction.setDefaultKeySequence(Tr::tr("Ctrl+Alt+,"));
|
||||||
|
moveUpAction.addOnTriggered(this, [this] { moveUp(); });
|
||||||
|
|
||||||
|
ActionBuilder sortByFilenamesAction(this, Constants::BOOKMARKS_SORTBYFILENAMES_ACTION);
|
||||||
|
sortByFilenamesAction.setContext(bookmarksContext);
|
||||||
|
sortByFilenamesAction.setText(Tr::tr("Sort by Filenames"));
|
||||||
|
sortByFilenamesAction.setDefaultKeySequence(Tr::tr("Ctrl+Alt+P"));
|
||||||
|
sortByFilenamesAction.addOnTriggered(this, [this] { sortByFilenames(); });
|
||||||
|
|
||||||
updateActionStatus();
|
updateActionStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -889,6 +921,16 @@ void BookmarkManager::edit()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BookmarkManager::sortByFilenames()
|
||||||
|
{
|
||||||
|
beginResetModel();
|
||||||
|
std::sort(m_bookmarksList.begin(), m_bookmarksList.end(), [](const Bookmark* a, const Bookmark* b){
|
||||||
|
return a->filePath().fileName() < b->filePath().fileName()
|
||||||
|
|| (a->filePath().fileName() == b->filePath().fileName() && a->lineNumber() < b->lineNumber());
|
||||||
|
});
|
||||||
|
endResetModel();
|
||||||
|
}
|
||||||
|
|
||||||
/* Returns the bookmark at the given file and line number, or 0 if no such bookmark exists. */
|
/* Returns the bookmark at the given file and line number, or 0 if no such bookmark exists. */
|
||||||
Bookmark *BookmarkManager::findBookmark(const FilePath &filePath, int lineNumber)
|
Bookmark *BookmarkManager::findBookmark(const FilePath &filePath, int lineNumber)
|
||||||
{
|
{
|
||||||
|
@@ -75,6 +75,7 @@ public:
|
|||||||
void moveDown();
|
void moveDown();
|
||||||
void edit();
|
void edit();
|
||||||
void editByFileAndLine(const Utils::FilePath &fileName, int lineNumber);
|
void editByFileAndLine(const Utils::FilePath &fileName, int lineNumber);
|
||||||
|
void sortByFilenames();
|
||||||
bool gotoBookmark(const Bookmark *bookmark) const;
|
bool gotoBookmark(const Bookmark *bookmark) const;
|
||||||
|
|
||||||
void requestContextMenu(const Utils::FilePath &filePath, int lineNumber, QMenu *menu);
|
void requestContextMenu(const Utils::FilePath &filePath, int lineNumber, QMenu *menu);
|
||||||
|
@@ -245,6 +245,9 @@ const char GENERIC_PROPOSAL_ID[] = "TextEditor.GenericProposalId";
|
|||||||
|
|
||||||
const char BOOKMARKS_PREV_ACTION[] = "Bookmarks.Previous";
|
const char BOOKMARKS_PREV_ACTION[] = "Bookmarks.Previous";
|
||||||
const char BOOKMARKS_NEXT_ACTION[] = "Bookmarks.Next";
|
const char BOOKMARKS_NEXT_ACTION[] = "Bookmarks.Next";
|
||||||
|
const char BOOKMARKS_MOVEUP_ACTION[] = "Bookmarks.MoveUp";
|
||||||
|
const char BOOKMARKS_MOVEDOWN_ACTION[] = "Bookmarks.MoveDown";
|
||||||
|
const char BOOKMARKS_SORTBYFILENAMES_ACTION[] = "Bookmarks.SortByFilenames";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delay before tooltip will be shown near completion assistant proposal
|
* Delay before tooltip will be shown near completion assistant proposal
|
||||||
|
Reference in New Issue
Block a user