1 /*****************************************************************************
2  * Copyright (C) 2000 Shie Erlich <erlich@users.sourceforge.net>             *
3  * Copyright (C) 2000 Rafi Yanai <yanai@users.sourceforge.net>               *
4  * Copyright (C) 2011 Jan Lepper <jan_lepper@gmx.de>                         *
5  * Copyright (C) 2004-2019 Krusader Krew [https://krusader.org]              *
6  *                                                                           *
7  * This file is part of Krusader [https://krusader.org].                     *
8  *                                                                           *
9  * Krusader is free software: you can redistribute it and/or modify          *
10  * it under the terms of the GNU General Public License as published by      *
11  * the Free Software Foundation, either version 2 of the License, or         *
12  * (at your option) any later version.                                       *
13  *                                                                           *
14  * Krusader is distributed in the hope that it will be useful,               *
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
17  * GNU General Public License for more details.                              *
18  *                                                                           *
19  * You should have received a copy of the GNU General Public License         *
20  * along with Krusader.  If not, see [http://www.gnu.org/licenses/].         *
21  *****************************************************************************/
22 
23 #include "tabactions.h"
24 
25 #include "krmainwindow.h"
26 #include "panelmanager.h"
27 #include "Panel/listpanel.h"
28 
29 // QtWidgets
30 #include <QAction>
31 
32 #include <KI18n/KLocalizedString>
33 
TabActions(QObject * parent,KrMainWindow * mainWindow)34 TabActions::TabActions(QObject *parent, KrMainWindow *mainWindow) : ActionsBase(parent, mainWindow)
35 {
36     actNewTab = action(i18n("New Tab"), "tab-new", QKeySequence::keyBindings(QKeySequence::AddTab), this, SLOT(newTab()), "new tab");
37     actDupTab = action(i18n("Duplicate Current Tab"), "tab-duplicate", Qt::ALT + Qt::CTRL + Qt::SHIFT + Qt::Key_N, SLOT(duplicateTab()), "duplicate tab");
38     actMoveTabToOtherSide = action(i18n("Move Current Tab to Other Side"), 0, Qt::CTRL + Qt::SHIFT + Qt::Key_O, SLOT(moveTabToOtherSide()), "move_tab_to_other_side");
39     actCloseTab = action(i18n("Close Current Tab"), "tab-close", KStandardShortcut::close(), this, SLOT(closeTab()), "close tab");
40     actNextTab = action(i18n("Next Tab"), QString(), KStandardShortcut::tabNext(), this, SLOT(nextTab()), "next tab");
41     actPreviousTab = action(i18n("Previous Tab"), QString(), KStandardShortcut::tabPrev(), this, SLOT(previousTab()), "previous tab");
42     actCloseInactiveTabs = action(i18n("Close Inactive Tabs"), 0, 0, SLOT(closeInactiveTabs()), "close inactive tabs");
43     actCloseDuplicatedTabs = action(i18n("Close Duplicated Tabs"), 0, 0, SLOT(closeDuplicatedTabs()), "close duplicated tabs");
44     actLockTab = action(i18n("Lock Tab"), "lock", 0, SLOT(lockTab()), "lock tab");
45     actPinTab = action(i18n("Pin Tab"), "pin", 0, SLOT(pinTab()), "pin tab");
46 }
47 
activeManager()48 inline PanelManager *TabActions::activeManager()
49 {
50     return static_cast<PanelManager*>(
51         static_cast<KrMainWindow*>(_mainWindow)->activeManager());
52 }
53 
refreshActions()54 void TabActions::refreshActions()
55 {
56     if (!activeManager())
57         return;
58     int tabCount = activeManager()->tabCount();
59     actCloseTab->setEnabled(tabCount > 1);
60     actCloseInactiveTabs->setEnabled(tabCount > 1);
61     actCloseDuplicatedTabs->setEnabled(tabCount > 1);
62     actMoveTabToOtherSide->setEnabled(tabCount > 1);
63     actNextTab->setEnabled(tabCount > 1);
64     actPreviousTab->setEnabled(tabCount > 1);
65     bool locked = activeManager()->currentPanel()->gui->isLocked();
66     actLockTab->setText(locked ? i18n("Unlock Tab") : i18n("Lock Tab"));
67     bool pinned = activeManager()->currentPanel()->gui->isPinned();
68     actPinTab->setText(pinned ? i18n("Unpin Tab") : i18n("Pin Tab"));
69 }
70 
newTab()71 void TabActions::newTab()
72 {
73     activeManager()->slotNewTab();
74 }
75 
duplicateTab()76 void TabActions::duplicateTab()
77 {
78     KrPanel *activePanel = static_cast<KrMainWindow*>(_mainWindow)->activePanel();
79     activeManager()->newTab(activePanel->virtualPath(), activePanel);
80 }
81 
moveTabToOtherSide()82 void TabActions::moveTabToOtherSide()
83 {
84     activeManager()->moveTabToOtherSide();
85 }
86 
nextTab()87 void TabActions::nextTab()
88 {
89     activeManager()->slotNextTab();
90 }
91 
previousTab()92 void TabActions::previousTab()
93 {
94     activeManager()->slotPreviousTab();
95 }
96 
closeTab()97 void TabActions::closeTab()
98 {
99     activeManager()->slotCloseTab();
100 }
101 
closeInactiveTabs()102 void TabActions::closeInactiveTabs()
103 {
104     activeManager()->slotCloseInactiveTabs();
105 }
106 
closeDuplicatedTabs()107 void TabActions::closeDuplicatedTabs()
108 {
109     activeManager()->slotCloseDuplicatedTabs();
110 }
111 
lockTab()112 void TabActions::lockTab()
113 {
114     activeManager()->slotLockTab();
115 }
116 
pinTab()117 void TabActions::pinTab()
118 {
119     activeManager()->slotPinTab();
120 }
121