ViewWindow: add shortcut Ctrl_G,V to alternate view mode

This commit is contained in:
Le Tan 2022-10-09 12:05:33 +08:00
parent 038de48d54
commit 9a10b210ec
4 changed files with 34 additions and 0 deletions

View File

@ -64,6 +64,7 @@ namespace vnotex
ClearHighlights,
WordCount,
Attachment,
AlternateViewMode,
MaxShortcut
};
Q_ENUM(Shortcut)

View File

@ -219,6 +219,7 @@
"ApplySnippet" : "Ctrl+G, I",
"Tag" : "Ctrl+G, B",
"Attachment" : "",
"AlternateViewMode" : "Ctrl+G, V",
"WordCount" : "",
"Debug" : "F12",
"Print" : "",

View File

@ -358,6 +358,36 @@ QAction *ViewWindow::addAction(QToolBar *p_toolBar, ViewWindowToolBarHelper::Act
this, [this, menu]() {
updateViewModeMenu(menu);
});
// Add shortcut to alternate among view modes.
const auto &editorConfig = ConfigMgr::getInst().getEditorConfig();
auto shortcut = WidgetUtils::createShortcut(editorConfig.getShortcut(EditorConfig::AlternateViewMode),
this,
Qt::WidgetWithChildrenShortcut);
if (shortcut) {
connect(shortcut, &QShortcut::activated,
this, [this, act, menu] {
if (!act->isEnabled()) {
return;
}
updateViewModeMenu(menu);
auto actions = menu->actions();
int idx = -1;
for (int i = 0; i < actions.size(); ++i) {
if (actions[i]->isChecked()) {
idx = i + 1;
break;
}
}
if (idx == -1) {
return;
}
if (idx >= actions.size()) {
idx = 0;
}
actions[idx]->trigger();
});
}
break;
}

View File

@ -124,6 +124,8 @@ QAction *ViewWindowToolBarHelper::addAction(QToolBar *p_tb, Action p_action)
act = p_tb->addAction(ToolBarHelper::generateIcon("view_mode_editor.svg"),
ViewWindow::tr("View Mode"));
WidgetUtils::addActionShortcutText(act, editorConfig.getShortcut(Shortcut::AlternateViewMode));
auto toolBtn = dynamic_cast<QToolButton *>(p_tb->widgetForAction(act));
Q_ASSERT(toolBtn);
toolBtn->setPopupMode(QToolButton::InstantPopup);