Bläddra i källkod

feature/add_viewarea_shortcut_close_other_right (#2173)

* feature/add_viewarea_shortcut_close_other_right

* delete default

* adj multi

* del blank line

* add close all and close left

* adj

* adj

* del unless
chendapao 3 år sedan
förälder
incheckning
8c0c056c47
5 ändrade filer med 121 tillägg och 15 borttagningar
  1. 2 0
      src/core/coreconfig.h
  2. 2 0
      src/data/core/vnotex.json
  3. 44 0
      src/widgets/viewarea.cpp
  4. 62 15
      src/widgets/viewsplit.cpp
  5. 11 0
      src/widgets/viewsplit.h

+ 2 - 0
src/core/coreconfig.h

@@ -24,7 +24,9 @@ namespace vnotex
             NewNote,
             NewFolder,
             CloseTab,
+            CloseAllTabs,
             CloseOtherTabs,
+            CloseTabsToTheLeft,
             CloseTabsToTheRight,
             NavigationDock,
             OutlineDock,

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

@@ -16,7 +16,9 @@
             "NewNote" : "Ctrl+Alt+N",
             "NewFolder" : "Ctrl+Alt+S",
             "CloseTab" : "Ctrl+G, X",
+            "CloseAllTabs": "",
             "CloseOtherTabs" : "",
+            "CloseTabsToTheLeft" : "",
             "CloseTabsToTheRight" : "",
             "NavigationDock" : "Ctrl+G, A",
             "OutlineDock" : "Ctrl+G, U",

+ 44 - 0
src/widgets/viewarea.cpp

@@ -819,6 +819,50 @@ void ViewArea::setupShortcuts()
         }
     }
 
+    // CloseAllTabs
+    {
+        auto shortcut = WidgetUtils::createShortcut(coreConfig.getShortcut(CoreConfig::CloseAllTabs), this);
+        if (shortcut) {
+            connect(shortcut, &QShortcut::activated,
+                    this, [this]() {
+                        getCurrentViewSplit()->closeMultipleTabs(ViewSplit::CloseTabMode::CloseAllTabs);
+                    });
+        }
+    }
+
+    // CloseOtherTabs
+    {
+        auto shortcut = WidgetUtils::createShortcut(coreConfig.getShortcut(CoreConfig::CloseOtherTabs), this);
+        if (shortcut) {
+            connect(shortcut, &QShortcut::activated,
+                    this, [this]() {
+                        getCurrentViewSplit()->closeMultipleTabs(ViewSplit::CloseTabMode::CloseOtherTabs);
+                    });
+        }
+    }
+
+    // CloseTabsToTheLeft
+    {
+        auto shortcut = WidgetUtils::createShortcut(coreConfig.getShortcut(CoreConfig::CloseTabsToTheLeft), this);
+        if (shortcut) {
+            connect(shortcut, &QShortcut::activated,
+                    this, [this]() {
+                        getCurrentViewSplit()->closeMultipleTabs(ViewSplit::CloseTabMode::CloseTabsToTheLeft);
+                    });
+        }
+    }
+
+    // CloseTabsToTheRight
+    {
+        auto shortcut = WidgetUtils::createShortcut(coreConfig.getShortcut(CoreConfig::CloseTabsToTheRight), this);
+        if (shortcut) {
+            connect(shortcut, &QShortcut::activated,
+                    this, [this]() {
+                        getCurrentViewSplit()->closeMultipleTabs(ViewSplit::CloseTabMode::CloseTabsToTheRight);
+                    });
+        }
+    }
+
     // LocateNode.
     {
         auto shortcut = WidgetUtils::createShortcut(coreConfig.getShortcut(CoreConfig::LocateNode), this);

+ 62 - 15
src/widgets/viewsplit.cpp

@@ -541,34 +541,41 @@ void ViewSplit::createContextMenuOnTabBar(QMenu *p_menu, int p_tabIdx)
                                            coreConfig.getShortcut(CoreConfig::Shortcut::CloseTab));
     }
 
+    // Close All Tabs.
+    {
+        auto closeTabAct = p_menu->addAction(tr("Close All Tabs"),
+                                             [this, p_tabIdx]() {
+                                                 closeMultipleTabs(p_tabIdx, CloseTabMode::CloseAllTabs);
+                                             });
+        WidgetUtils::addActionShortcutText(closeTabAct,
+                                           coreConfig.getShortcut(CoreConfig::Shortcut::CloseAllTabs));
+    }
+
     // Close Other Tabs.
     {
         auto closeTabAct = p_menu->addAction(tr("Close Other Tabs"),
                                              [this, p_tabIdx]() {
-                                                 QVector<ViewWindow *> windowsNeedToClose;
-                                                 int cnt = getViewWindowCount();
-                                                 for (int i = 0; i < cnt; ++i) {
-                                                     if (i != p_tabIdx) {
-                                                         windowsNeedToClose.push_back(getViewWindow(i));
-                                                     }
-                                                 }
-
-                                                 for (auto win : windowsNeedToClose) {
-                                                     emit viewWindowCloseRequested(win);
-                                                 }
+                                                 closeMultipleTabs(p_tabIdx, CloseTabMode::CloseOtherTabs);
                                              });
         WidgetUtils::addActionShortcutText(closeTabAct,
                                            coreConfig.getShortcut(CoreConfig::Shortcut::CloseOtherTabs));
     }
 
+    // Close Tabs To The Left
+    {
+        auto closeTabAct = p_menu->addAction(tr("Close Tabs To The Left"),
+                                             [this, p_tabIdx]() {
+                                                 closeMultipleTabs(p_tabIdx, CloseTabMode::CloseTabsToTheLeft);
+                                             });
+        WidgetUtils::addActionShortcutText(closeTabAct,
+                                           coreConfig.getShortcut(CoreConfig::Shortcut::CloseTabsToTheLeft));
+    }
+
     // Close Tabs To The Right.
     {
         auto closeTabAct = p_menu->addAction(tr("Close Tabs To The Right"),
                                              [this, p_tabIdx]() {
-                                                 int cnt = getViewWindowCount();
-                                                 for (int i = cnt - 1; i > p_tabIdx; --i) {
-                                                     closeTab(i);
-                                                 }
+                                                 closeMultipleTabs(p_tabIdx, CloseTabMode::CloseTabsToTheRight);
                                              });
         WidgetUtils::addActionShortcutText(closeTabAct,
                                            coreConfig.getShortcut(CoreConfig::Shortcut::CloseTabsToTheRight));
@@ -700,6 +707,46 @@ void ViewSplit::closeTab(int p_idx)
     }
 }
 
+void ViewSplit::closeMultipleTabs(CloseTabMode p_ctm)
+{
+    closeMultipleTabs(currentIndex(), p_ctm);
+}
+
+void ViewSplit::closeMultipleTabs(int p_idx, CloseTabMode p_ctm)
+{
+    QVector<ViewWindow *> windowsNeedToClose;
+    int cnt = getViewWindowCount();
+
+    switch (p_ctm) {
+    case CloseTabMode::CloseAllTabs:
+        for (int i = 0; i < cnt; i++) {
+            windowsNeedToClose.push_back(getViewWindow(i));
+        }
+        break;
+    case CloseTabMode::CloseOtherTabs:
+        for (int i = 0; i < cnt; i++) {
+            if (i != p_idx) {
+                windowsNeedToClose.push_back(getViewWindow(i));
+            }
+        }
+        break;
+    case CloseTabMode::CloseTabsToTheLeft:
+        for (int i = 0; i < p_idx; i++) {
+             windowsNeedToClose.push_back(getViewWindow(i));
+        }
+        break;
+    case CloseTabMode::CloseTabsToTheRight:
+        for (int i = cnt - 1; i > p_idx; i--) {
+             windowsNeedToClose.push_back(getViewWindow(i));
+        }
+        break;
+    }
+
+    for (auto win : windowsNeedToClose) {
+        emit viewWindowCloseRequested(win);
+    }
+}
+
 void ViewSplit::mousePressEvent(QMouseEvent *p_event)
 {
     QTabWidget::mousePressEvent(p_event);

+ 11 - 0
src/widgets/viewsplit.h

@@ -70,6 +70,15 @@ namespace vnotex
 
         void updateStateToWorkspace() const;
 
+        enum class CloseTabMode {
+            CloseAllTabs,
+            CloseOtherTabs,
+            CloseTabsToTheLeft,
+            CloseTabsToTheRight
+        };
+
+        void closeMultipleTabs(CloseTabMode p_ctm);
+
     signals:
         void viewWindowCloseRequested(ViewWindow *p_win);
 
@@ -136,6 +145,8 @@ namespace vnotex
 
         void activateNextTab(bool p_backward);
 
+        void closeMultipleTabs(int p_idx, CloseTabMode ctm);
+
         ID m_id = 0;
 
         const QVector<QSharedPointer<ViewWorkspace>> &m_allWorkspaces;