1 /*****************************************************************************
2 * Copyright (C) 2010 Jan Lepper <krusader@users.sourceforge.net> *
3 * Copyright (C) 2010-2019 Krusader Krew [https://krusader.org] *
4 * *
5 * This file is part of Krusader [https://krusader.org]. *
6 * *
7 * Krusader is free software: you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation, either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * Krusader is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with Krusader. If not, see [http://www.gnu.org/licenses/]. *
19 *****************************************************************************/
20
21 #include "listpanelactions.h"
22
23 #include "listpanel.h"
24 #include "panelfunc.h"
25 #include "PanelView/krviewfactory.h"
26 #include "../krmainwindow.h"
27 #include "../Dialogs/krdialogs.h"
28 #include "../KViewer/krviewer.h"
29 #include "../icon.h"
30
31 // QtCore
32 #include <QSignalMapper>
33 // QtWidgets
34 #include <QActionGroup>
35
36 #include <KI18n/KLocalizedString>
37 #include <KXmlGui/KActionCollection>
38
39
ListPanelActions(QObject * parent,KrMainWindow * mainWindow)40 ListPanelActions::ListPanelActions(QObject *parent, KrMainWindow *mainWindow) :
41 ActionsBase(parent, mainWindow)
42 {
43 // set view type
44 QSignalMapper *mapper = new QSignalMapper(this);
45 connect(mapper, SIGNAL(mapped(int)), SLOT(setView(int)));
46 QActionGroup *group = new QActionGroup(this);
47 group->setExclusive(true);
48 QList<KrViewInstance*> views = KrViewFactory::registeredViews();
49 for(int i = 0; i < views.count(); i++) {
50 KrViewInstance *inst = views[i];
51 QAction *action = new QAction(Icon(inst->iconName()), inst->description(), group);
52 action->setCheckable(true);
53 connect(action, SIGNAL(triggered()), mapper, SLOT(map()));
54 mapper->setMapping(action, inst->id());
55 _mainWindow->actions()->addAction("view" + QString::number(i), action);
56 _mainWindow->actions()->setDefaultShortcut(action, inst->shortcut());
57 setViewActions.insert(inst->id(), action);
58 }
59
60 // standard actions
61 actHistoryBackward = stdAction(KStandardAction::Back, _func, SLOT(historyBackward()));
62 actHistoryForward = stdAction(KStandardAction::Forward, _func, SLOT(historyForward()));
63 //FIXME: second shortcut for up: see actDirUp
64 // KStandardAction::up( this, SLOT(dirUp()), actionCollection )->setShortcut(Qt::Key_Backspace);
65 /* Shortcut disabled because of the Terminal Emulator bug. */
66 actDirUp = stdAction(KStandardAction::Up, _func, SLOT(dirUp()));
67 actHome = stdAction(KStandardAction::Home, _func, SLOT(home()));
68
69 actCut = stdAction(KStandardAction::Cut, _func, SLOT(cut()));
70 actCut->setText(i18n("Cut to Clipboard"));
71 // removing alternative shift+del shortcut, it is used for the alternative delete files action
72 QList<QKeySequence> cutShortcuts = actCut->shortcuts();
73 cutShortcuts.removeAll(QKeySequence(Qt::SHIFT | Qt::Key_Delete));
74 _mainWindow->actions()->setDefaultShortcuts(actCut, cutShortcuts);
75 actCopy = stdAction(KStandardAction::Copy, _func, SLOT(copyToClipboard()));
76 actCopy->setText(i18n("Copy to Clipboard"));
77 actPaste = stdAction(KStandardAction::Paste, _func, SLOT(pasteFromClipboard()));
78 actPaste->setText(i18n("Paste from Clipboard"));
79
80 // Fn keys
81 actRenameF2 = action(i18n("Rename"), "edit-rename", Qt::Key_F2, _func, SLOT(rename()) , "F2_Rename");
82 actViewFileF3 = action(i18n("View File"), 0, Qt::Key_F3, _func, SLOT(view()), "F3_View");
83 actEditFileF4 = action(i18n("Edit File"), nullptr, Qt::Key_F4, _func, SLOT(editFile()), "F4_Edit");
84 actNewFileShiftF4 = action(i18n("&New Text File..."), "document-new", Qt::SHIFT + Qt::Key_F4, _func, SLOT(editNewFile()), "edit_new_file");
85 actCopyF5 = action(i18n("Copy to other panel"), nullptr, Qt::Key_F5, _func, SLOT(copyFiles()) , "F5_Copy");
86 actMoveF6 = action(i18n("Move to other panel"), 0, Qt::Key_F6, _func, SLOT(moveFiles()) , "F6_Move");
87 actCopyDelayedF5 = action(i18n("Copy delayed..."), 0, Qt::SHIFT + Qt::Key_F5, _func, SLOT(copyFilesDelayed()) , "F5_Copy_Queue");
88 actMoveDelayedShiftF6 = action(i18n("Move delayed..."), 0, Qt::SHIFT + Qt::Key_F6, _func, SLOT(moveFilesDelayed()) , "F6_Move_Queue");
89 actNewFolderF7 = action(i18n("New Folder..."), "folder-new", Qt::Key_F7, _func, SLOT(mkdir()) , "F7_Mkdir");
90 actDeleteF8 = action(i18n("Delete"), "edit-delete", Qt::Key_F8, _func, SLOT(defaultDeleteFiles()) , "F8_Delete");
91 actTerminalF9 = action(i18n("Start Terminal Here"), "utilities-terminal", Qt::Key_F9, _func, SLOT(terminal()) , "F9_Terminal");
92 action(i18n("F3 View Dialog"), 0, Qt::SHIFT + Qt::Key_F3, _func, SLOT(viewDlg()), "F3_ViewDlg");
93
94 // file operations
95 action(i18n("Right-click Menu"), 0, Qt::Key_Menu, _gui, SLOT(rightclickMenu()), "rightclick menu");
96 actProperties = action(i18n("&Properties..."), "document-properties", Qt::ALT + Qt::Key_Return, _func, SLOT(properties()), "properties");
97 actCompDirs = action(i18n("&Compare Folders"), "kr_comparedirs", Qt::ALT + Qt::SHIFT + Qt::Key_C, _gui, SLOT(compareDirs()), "compare dirs");
98 actCalculate = action(i18n("Calculate &Occupied Space"), "accessories-calculator", 0, _func, SLOT(calcSpace()), "calculate");
99 actPack = action(i18n("Pac&k..."), "archive-insert", Qt::ALT + Qt::SHIFT + Qt::Key_P, _func, SLOT(pack()), "pack");
100 actUnpack = action(i18n("&Unpack..."), "archive-extract", Qt::ALT + Qt::SHIFT + Qt::Key_U, _func, SLOT(unpack()), "unpack");
101 actCreateChecksum = action(i18n("Create Checksum..."), "document-edit-sign", 0, _func, SLOT(createChecksum()), "create checksum");
102 actMatchChecksum = action(i18n("Verify Checksum..."), "document-edit-decrypt-verify", 0, _func, SLOT(matchChecksum()), "match checksum");
103 action(i18n("New Symlink..."), 0, Qt::CTRL + Qt::ALT + Qt::Key_S, _func, SLOT(krlink()), "new symlink");
104 actTest = action(i18n("T&est Archive"), "archive-extract", Qt::ALT + Qt::SHIFT + Qt::Key_E, _func, SLOT(testArchive()), "test archives");
105 action(i18n("Alternative Delete"), "edit-delete", Qt::Key_Delete + Qt::CTRL, _func, SLOT(alternativeDeleteFiles()), "alternative delete");
106
107 // navigation
108 actRoot = action(i18n("Root"), "folder-red", Qt::CTRL + Qt::Key_Backspace, _func, SLOT(root()), "root");
109 actCdToOther = action(i18n("Go to Other Panel's Folder"), 0, Qt::CTRL + Qt::Key_Equal, _func, SLOT(cdToOtherPanel()), "cd to other panel");
110 action(i18n("&Reload"), "view-refresh", Qt::CTRL + Qt::Key_R, _func, SLOT(refresh()), "std_redisplay");
111 actCancelRefresh = action(i18n("Cancel Refresh of View"), "dialog-cancel", 0, _gui, SLOT(cancelProgress()), "cancel refresh");
112 actFTPNewConnect = action(i18n("New Net &Connection..."), "network-connect", Qt::CTRL + Qt::Key_N, _func, SLOT(newFTPconnection()), "ftp new connection");
113 actFTPDisconnect = action(i18n("Disconnect &from Net"), "network-disconnect", Qt::SHIFT + Qt::CTRL + Qt::Key_D, _func, SLOT(FTPDisconnect()), "ftp disconnect");
114 action(i18n("Sync Panels"), 0, Qt::ALT + Qt::SHIFT + Qt::Key_O, _func, SLOT(syncOtherPanel()), "sync panels");
115 actJumpBack = action(i18n("Jump Back"), "go-jump", Qt::CTRL + Qt::Key_J, _gui, SLOT(jumpBack()), "jump_back");
116 actSetJumpBack = action(i18n("Set Jump Back Point"), "go-jump-definition", Qt::CTRL + Qt::SHIFT + Qt::Key_J, _gui, SLOT(setJumpBack()), "set_jump_back");
117 actSyncBrowse = action(i18n("S&ynchron Folder Changes"), "kr_syncbrowse_off", Qt::ALT + Qt::SHIFT + Qt::Key_Y, _gui, SLOT(toggleSyncBrowse()), "sync browse");
118 actLocationBar = action(i18n("Go to Location Bar"), 0, Qt::CTRL + Qt::Key_L, _gui, SLOT(editLocation()), "location_bar");
119 toggleAction(i18n("Toggle Sidebar"), 0, Qt::ALT + Qt::Key_Down, _gui, SLOT(toggleSidebar()), "toggle sidebar");
120 action(i18n("Bookmarks"), 0, Qt::CTRL + Qt::Key_D, _gui, SLOT(openBookmarks()), "bookmarks");
121 action(i18n("Left Bookmarks"), 0, 0, this, SLOT(openLeftBookmarks()), "left bookmarks");
122 action(i18n("Right Bookmarks"), 0, 0, this, SLOT(openRightBookmarks()), "right bookmarks");
123 action(i18n("History"), 0, Qt::CTRL + Qt::Key_H, _gui, SLOT(openHistory()), "history");
124 action(i18n("Left History"), 0, Qt::ALT + Qt::CTRL + Qt::Key_Left, this, SLOT(openLeftHistory()), "left history");
125 action(i18n("Right History"), 0, Qt::ALT + Qt::CTRL + Qt::Key_Right, this, SLOT(openRightHistory()), "right history");
126 action(i18n("Media"), 0, Qt::CTRL + Qt::Key_M, _gui, SLOT(openMedia()), "media");
127 action(i18n("Left Media"), 0, Qt::CTRL + Qt::SHIFT + Qt::Key_Left, this, SLOT(openLeftMedia()), "left media");
128 action(i18n("Right Media"), 0, Qt::CTRL + Qt::SHIFT + Qt::Key_Right, this, SLOT(openRightMedia()), "right media");
129
130 // quick search bar
131 action(i18n("Find in folder..."), 0, Qt::CTRL + Qt::Key_F, _gui, SLOT(showSearchBar()), "search bar");
132 action(i18n("Select in folder..."), 0, Qt::CTRL + Qt::SHIFT + Qt::Key_S, _gui, SLOT(showSearchBarSelection()), "search bar selection");
133 action(i18n("Filter in folder..."), 0, Qt::CTRL + Qt::Key_I, _gui, SLOT(showSearchBarFilter()), "search bar filter");
134
135 // and at last we can set the tool-tips
136 actRoot->setToolTip(i18n("ROOT (/)"));
137
138 actRenameF2->setToolTip(i18n("Rename file, folder, etc."));
139 actViewFileF3->setToolTip(i18n("Open file in viewer."));
140 actEditFileF4->setToolTip(i18n("<qt><p>Edit file.</p>"
141 "<p>The editor can be defined in Konfigurator, "
142 "default is <b>internal editor</b>.</p></qt>"));
143 actCopyF5->setToolTip(i18n("Copy file from one panel to the other."));
144 actMoveF6->setToolTip(i18n("Move file from one panel to the other."));
145 actNewFolderF7->setToolTip(i18n("Create folder in current panel."));
146 actDeleteF8->setToolTip(i18n("Delete file, folder, etc."));
147 actTerminalF9->setToolTip(i18n("<qt><p>Open terminal in current folder.</p>"
148 "<p>The terminal can be defined in Konfigurator, "
149 "default is <b>konsole</b>.</p></qt>"));
150
151 }
152
activePanelChanged()153 void ListPanelActions::activePanelChanged()
154 {
155 _gui.reconnect(activePanel()->gui);
156 _func.reconnect(activePanel()->func);
157 }
158
guiUpdated()159 void ListPanelActions::guiUpdated()
160 {
161 QList<QAction*> actions;
162 foreach(QAction *action, setViewActions.values())
163 actions << action;
164 static_cast<KrMainWindow*>(_mainWindow)->plugActionList("view_actionlist", actions);
165 }
166
activePanel()167 inline KrPanel *ListPanelActions::activePanel()
168 {
169 return static_cast<KrMainWindow*>(_mainWindow)->activePanel();
170 }
171
leftPanel()172 inline KrPanel *ListPanelActions::leftPanel()
173 {
174 return static_cast<KrMainWindow*>(_mainWindow)->leftPanel();
175 }
176
rightPanel()177 inline KrPanel *ListPanelActions::rightPanel()
178 {
179 return static_cast<KrMainWindow*>(_mainWindow)->rightPanel();
180 }
181
182 // set view type
183
setView(int id)184 void ListPanelActions::setView(int id)
185 {
186 activePanel()->gui->changeType(id);
187 }
188
189 // navigation
190
openLeftBookmarks()191 void ListPanelActions::openLeftBookmarks()
192 {
193 leftPanel()->gui->openBookmarks();
194 }
195
openRightBookmarks()196 void ListPanelActions::openRightBookmarks()
197 {
198 rightPanel()->gui->openBookmarks();
199 }
200
openLeftHistory()201 void ListPanelActions::openLeftHistory()
202 {
203 leftPanel()->gui->openHistory();
204 }
205
openRightHistory()206 void ListPanelActions::openRightHistory()
207 {
208 rightPanel()->gui->openHistory();
209 }
210
openLeftMedia()211 void ListPanelActions::openLeftMedia()
212 {
213 leftPanel()->gui->openMedia();
214 }
215
openRightMedia()216 void ListPanelActions::openRightMedia()
217 {
218 rightPanel()->gui->openMedia();
219 }
220