File indexing completed on 2024-04-28 05:52:03
0001 /* 0002 SPDX-FileCopyrightText: 2000 Shie Erlich <erlich@users.sourceforge.net> 0003 SPDX-FileCopyrightText: 2000 Rafi Yanai <yanai@users.sourceforge.net> 0004 SPDX-FileCopyrightText: 2011 Jan Lepper <jan_lepper@gmx.de> 0005 SPDX-FileCopyrightText: 2004-2022 Krusader Krew <https://krusader.org> 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 0010 #include "tabactions.h" 0011 0012 #include "Panel/listpanel.h" 0013 #include "krmainwindow.h" 0014 #include "panelmanager.h" 0015 0016 // QtWidgets 0017 #include <QAction> 0018 0019 #include <KI18n/KLocalizedString> 0020 0021 TabActions::TabActions(QObject *parent, KrMainWindow *mainWindow) 0022 : ActionsBase(parent, mainWindow) 0023 { 0024 actNewTab = action(i18n("New Tab"), "tab-new", Qt::ALT + Qt::CTRL + Qt::SHIFT + Qt::Key_N, SLOT(newTab()), "new_tab"); 0025 actDupTab = 0026 action(i18n("Duplicate Current Tab"), "tab-duplicate", QKeySequence::keyBindings(QKeySequence::AddTab), this, SLOT(duplicateTab()), "duplicate tab"); 0027 actMoveTabToOtherSide = 0028 action(i18n("Move Current Tab to Other Side"), nullptr, Qt::CTRL + Qt::SHIFT + Qt::Key_O, SLOT(moveTabToOtherSide()), "move_tab_to_other_side"); 0029 actMoveTabToLeft = action(i18n("Move Current Tab to the Left"), nullptr, Qt::CTRL + Qt::SHIFT + Qt::Key_PageUp, SLOT(moveTabToLeft()), "move_tab_to_left"); 0030 actMoveTabToRight = 0031 action(i18n("Move Current Tab to the Right"), nullptr, Qt::CTRL + Qt::SHIFT + Qt::Key_PageDown, SLOT(moveTabToRight()), "move_tab_to_right"); 0032 actCloseTab = action(i18n("Close Current Tab"), "tab-close", KStandardShortcut::close(), this, SLOT(closeTab()), "close tab"); 0033 actUndoCloseTab = action(i18n("Undo Close Tab"), "edit-undo", Qt::CTRL + Qt::SHIFT + Qt::Key_T, this, SLOT(undoCloseTab()), "undo_close_tab"); 0034 actUndoCloseTab->setEnabled(false); 0035 actNextTab = action(i18n("Next Tab"), QString(), KStandardShortcut::tabNext(), this, SLOT(nextTab()), "next tab"); 0036 actPreviousTab = action(i18n("Previous Tab"), QString(), KStandardShortcut::tabPrev(), this, SLOT(previousTab()), "previous tab"); 0037 actCloseInactiveTabs = action(i18n("Close Inactive Tabs"), nullptr, 0, SLOT(closeInactiveTabs()), "close inactive tabs"); 0038 actCloseDuplicatedTabs = action(i18n("Close Duplicated Tabs"), nullptr, 0, SLOT(closeDuplicatedTabs()), "close duplicated tabs"); 0039 actLockTab = action(i18n("Lock Tab"), "lock", 0, SLOT(lockTab()), "lock tab"); 0040 actPinTab = action(i18n("Pin Tab"), "pin", 0, SLOT(pinTab()), "pin tab"); 0041 } 0042 0043 inline PanelManager *TabActions::activeManager() 0044 { 0045 return dynamic_cast<PanelManager *>(static_cast<KrMainWindow *>(_mainWindow)->activeManager()); 0046 } 0047 0048 void TabActions::refreshActions() 0049 { 0050 if (!activeManager()) 0051 return; 0052 int tabCount = activeManager()->tabCount(); 0053 actCloseTab->setEnabled(tabCount > 1); 0054 actCloseInactiveTabs->setEnabled(tabCount > 1); 0055 actCloseDuplicatedTabs->setEnabled(tabCount > 1); 0056 actMoveTabToOtherSide->setEnabled(tabCount > 1); 0057 actMoveTabToLeft->setEnabled(tabCount > 1); 0058 actMoveTabToRight->setEnabled(tabCount > 1); 0059 actNextTab->setEnabled(tabCount > 1); 0060 actPreviousTab->setEnabled(tabCount > 1); 0061 bool locked = activeManager()->currentPanel()->gui->isLocked(); 0062 actLockTab->setText(locked ? i18n("Unlock Tab") : i18n("Lock Tab")); 0063 bool pinned = activeManager()->currentPanel()->gui->isPinned(); 0064 actPinTab->setText(pinned ? i18n("Unpin Tab") : i18n("Pin Tab")); 0065 } 0066 0067 void TabActions::newTab() 0068 { 0069 activeManager()->slotNewTab(); 0070 } 0071 0072 void TabActions::duplicateTab() 0073 { 0074 KrPanel *activePanel = static_cast<KrMainWindow *>(_mainWindow)->activePanel(); 0075 activeManager()->duplicateTab(activePanel->virtualPath(), activePanel); 0076 } 0077 0078 void TabActions::moveTabToOtherSide() 0079 { 0080 activeManager()->moveTabToOtherSide(); 0081 } 0082 0083 void TabActions::moveTabToLeft() 0084 { 0085 activeManager()->moveTabToLeft(); 0086 } 0087 0088 void TabActions::moveTabToRight() 0089 { 0090 activeManager()->moveTabToRight(); 0091 } 0092 0093 void TabActions::nextTab() 0094 { 0095 activeManager()->slotNextTab(); 0096 } 0097 0098 void TabActions::previousTab() 0099 { 0100 activeManager()->slotPreviousTab(); 0101 } 0102 0103 void TabActions::closeTab() 0104 { 0105 activeManager()->slotCloseTab(); 0106 } 0107 0108 void TabActions::undoCloseTab() 0109 { 0110 activeManager()->slotUndoCloseTab(); 0111 } 0112 0113 void TabActions::closeInactiveTabs() 0114 { 0115 activeManager()->slotCloseInactiveTabs(); 0116 } 0117 0118 void TabActions::closeDuplicatedTabs() 0119 { 0120 activeManager()->slotCloseDuplicatedTabs(); 0121 } 0122 0123 void TabActions::lockTab() 0124 { 0125 activeManager()->slotLockTab(); 0126 } 0127 0128 void TabActions::pinTab() 0129 { 0130 activeManager()->slotPinTab(); 0131 }