Procházet zdrojové kódy

ViewWindow: add shortcut Ctrl_G,V to alternate view mode

Le Tan před 3 roky
rodič
revize
9a10b210ec

+ 1 - 0
src/core/editorconfig.h

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

+ 1 - 0
src/data/core/vnotex.json

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

+ 30 - 0
src/widgets/viewwindow.cpp

@@ -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;
     }
 

+ 2 - 0
src/widgets/viewwindowtoolbarhelper.cpp

@@ -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);