File indexing completed on 2024-04-28 17:06:23

0001 /*
0002     SPDX-FileCopyrightText: 2010 Jan Lepper <krusader@users.sourceforge.net>
0003     SPDX-FileCopyrightText: 2010-2022 Krusader Krew <https://krusader.org>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #include "listpanelactions.h"
0009 
0010 #include "../Dialogs/krdialogs.h"
0011 #include "../KViewer/krviewer.h"
0012 #include "../icon.h"
0013 #include "../krmainwindow.h"
0014 #include "PanelView/krviewfactory.h"
0015 #include "listpanel.h"
0016 #include "panelfunc.h"
0017 
0018 // QtWidgets
0019 #include <QActionGroup>
0020 
0021 #include <KI18n/KLocalizedString>
0022 #include <KXmlGui/KActionCollection>
0023 
0024 ListPanelActions::ListPanelActions(QObject *parent, KrMainWindow *mainWindow)
0025     : ActionsBase(parent, mainWindow)
0026 {
0027     // set view type
0028     auto *group = new QActionGroup(this);
0029     group->setExclusive(true);
0030     QList<KrViewInstance *> views = KrViewFactory::registeredViews();
0031     for (int i = 0; i < views.count(); i++) {
0032         KrViewInstance *inst = views[i];
0033         QAction *action = new QAction(Icon(inst->iconName()), inst->description(), group);
0034         action->setCheckable(true);
0035         connect(action, &QAction::triggered, this, [=] {
0036             setView(inst->id());
0037         });
0038         _mainWindow->actions()->addAction("view" + QString::number(i), action);
0039         _mainWindow->actions()->setDefaultShortcut(action, inst->shortcut());
0040         setViewActions.insert(inst->id(), action);
0041     }
0042 
0043     // standard actions
0044     actHistoryBackward = stdAction(KStandardAction::Back, _func, SLOT(historyBackward()));
0045     actHistoryForward = stdAction(KStandardAction::Forward, _func, SLOT(historyForward()));
0046     // FIXME: second shortcut for up: see actDirUp
0047     //    KStandardAction::up( this, SLOT(dirUp()), actionCollection )->setShortcut(Qt::Key_Backspace);
0048     /* Shortcut disabled because of the Terminal Emulator bug. */
0049     actDirUp = stdAction(KStandardAction::Up, _func, SLOT(dirUp()));
0050     actHome = stdAction(KStandardAction::Home, _func, SLOT(home()));
0051 
0052     actCut = stdAction(KStandardAction::Cut, _func, SLOT(cut()));
0053     actCut->setText(i18n("Cut to Clipboard"));
0054     // removing alternative shift+del shortcut, it is used for the alternative delete files action
0055     QList<QKeySequence> cutShortcuts = actCut->shortcuts();
0056     cutShortcuts.removeAll(QKeySequence(Qt::SHIFT | Qt::Key_Delete));
0057     _mainWindow->actions()->setDefaultShortcuts(actCut, cutShortcuts);
0058     actCopy = stdAction(KStandardAction::Copy, _func, SLOT(copyToClipboard()));
0059     actCopy->setText(i18n("Copy to Clipboard"));
0060     actPaste = stdAction(KStandardAction::Paste, _func, SLOT(pasteFromClipboard()));
0061     actPaste->setText(i18n("Paste from Clipboard"));
0062 
0063     // Fn keys
0064     actRenameF2 = action(i18n("Rename"), "edit-rename", Qt::Key_F2, _func, SLOT(rename()), "F2_Rename");
0065     actViewFileF3 = action(i18n("View File"), nullptr, Qt::Key_F3, _func, SLOT(view()), "F3_View");
0066     actEditFileF4 = action(i18n("Edit File"), nullptr, Qt::Key_F4, _func, SLOT(editFile()), "F4_Edit");
0067     actNewFileShiftF4 = action(i18n("&New Text File..."), "document-new", Qt::SHIFT + Qt::Key_F4, _func, SLOT(askEditFile()), "edit_new_file");
0068     actCopyF5 = action(i18n("Copy to other panel"), nullptr, Qt::Key_F5, _func, SLOT(copyFiles()), "F5_Copy");
0069     actMoveF6 = action(i18n("Move to other panel"), nullptr, Qt::Key_F6, _func, SLOT(moveFiles()), "F6_Move");
0070     actCopyDelayedF5 = action(i18n("Copy delayed..."), nullptr, Qt::SHIFT + Qt::Key_F5, _func, SLOT(copyFilesDelayed()), "F5_Copy_Queue");
0071     actMoveDelayedShiftF6 = action(i18n("Move delayed..."), nullptr, Qt::SHIFT + Qt::Key_F6, _func, SLOT(moveFilesDelayed()), "F6_Move_Queue");
0072     actNewFolderF7 = action(i18n("New Folder..."), "folder-new", Qt::Key_F7, _func, SLOT(mkdir()), "F7_Mkdir");
0073     actDeleteF8 = action(i18n("Delete"), "edit-delete", Qt::Key_F8, _func, SLOT(defaultDeleteFiles()), "F8_Delete");
0074     actTerminalF9 = action(i18n("Start Terminal Here"), "utilities-terminal", Qt::Key_F9, _func, SLOT(terminal()), "F9_Terminal");
0075     action(i18n("F3 View Dialog"), nullptr, Qt::SHIFT + Qt::Key_F3, _func, SLOT(viewDlg()), "F3_ViewDlg");
0076 
0077     // file operations
0078     action(i18n("Right-click Menu"), nullptr, Qt::Key_Menu, _gui, SLOT(rightclickMenu()), "rightclick menu");
0079     actProperties = action(i18n("&Properties..."), "document-properties", Qt::ALT + Qt::Key_Return, _func, SLOT(properties()), "properties");
0080     actCompDirs = action(i18n("&Compare Folders"), "kr_comparedirs", Qt::ALT + Qt::SHIFT + Qt::Key_C, _gui, SLOT(compareDirs()), "compare dirs");
0081     actCalculate = action(i18n("Calculate &Occupied Space"), "accessories-calculator", 0, _func, SLOT(calcSpace()), "calculate");
0082     actPack = action(i18n("Pac&k..."), "archive-insert", Qt::ALT + Qt::SHIFT + Qt::Key_P, _func, SLOT(pack()), "pack");
0083     actUnpack = action(i18n("&Unpack..."), "archive-extract", Qt::ALT + Qt::SHIFT + Qt::Key_U, _func, SLOT(unpack()), "unpack");
0084     actCreateChecksum = action(i18n("Create Checksum..."), "document-edit-sign", 0, _func, SLOT(createChecksum()), "create checksum");
0085     actMatchChecksum = action(i18n("Verify Checksum..."), "document-edit-decrypt-verify", 0, _func, SLOT(matchChecksum()), "match checksum");
0086     action(i18n("New Symlink..."), nullptr, Qt::CTRL + Qt::ALT + Qt::Key_S, _func, SLOT(krlink()), "new symlink");
0087     actTest = action(i18n("T&est Archive"), "archive-extract", Qt::ALT + Qt::SHIFT + Qt::Key_E, _func, SLOT(testArchive()), "test archives");
0088     action(i18n("Alternative Delete"), "edit-delete", Qt::Key_Delete + Qt::CTRL, _func, SLOT(alternativeDeleteFiles()), "alternative delete");
0089 
0090     // navigation
0091     actRoot = action(i18n("Root"), "folder-red", Qt::CTRL + Qt::Key_Backspace, _func, SLOT(root()), "root");
0092     actCdToOther = action(i18n("Go to Other Panel's Folder"), nullptr, Qt::CTRL + Qt::Key_Equal, _func, SLOT(cdToOtherPanel()), "cd to other panel");
0093     action(i18n("&Reload"), "view-refresh", Qt::CTRL + Qt::Key_R, _func, SLOT(refresh()), "std_redisplay");
0094     actCancelRefresh = action(i18n("Cancel Refresh of View"), "dialog-cancel", 0, _gui, SLOT(cancelProgress()), "cancel refresh");
0095     actFTPNewConnect = action(i18n("New Net &Connection..."), "network-connect", Qt::CTRL + Qt::Key_N, _func, SLOT(newFTPconnection()), "ftp new connection");
0096     actFTPDisconnect =
0097         action(i18n("Disconnect &from Net"), "network-disconnect", Qt::SHIFT + Qt::CTRL + Qt::Key_D, _func, SLOT(FTPDisconnect()), "ftp disconnect");
0098     action(i18n("Sync Panels"), nullptr, Qt::ALT + Qt::SHIFT + Qt::Key_O, _func, SLOT(syncOtherPanel()), "sync panels");
0099     actJumpBack = action(i18n("Jump Back"), "go-jump", Qt::CTRL + Qt::Key_J, _gui, SLOT(jumpBack()), "jump_back");
0100     actSetJumpBack = action(i18n("Set Jump Back Point"), "go-jump-definition", Qt::CTRL + Qt::SHIFT + Qt::Key_J, _gui, SLOT(setJumpBack()), "set_jump_back");
0101     actSyncBrowse =
0102         action(i18n("S&ynchron Folder Changes"), "kr_syncbrowse_off", Qt::ALT + Qt::SHIFT + Qt::Key_Y, _gui, SLOT(toggleSyncBrowse()), "sync browse");
0103     actLocationBar = action(i18n("Go to Location Bar"), nullptr, Qt::CTRL + Qt::Key_L, _gui, SLOT(editLocation()), "location_bar");
0104     toggleAction(i18n("Toggle Sidebar"), nullptr, Qt::ALT + Qt::Key_Down, _gui, SLOT(toggleSidebar()), "toggle sidebar");
0105     action(i18n("Bookmarks"), nullptr, Qt::CTRL + Qt::Key_D, _gui, SLOT(openBookmarks()), "bookmarks");
0106     action(i18n("Left Bookmarks"), nullptr, 0, this, SLOT(openLeftBookmarks()), "left bookmarks");
0107     action(i18n("Right Bookmarks"), nullptr, 0, this, SLOT(openRightBookmarks()), "right bookmarks");
0108     action(i18n("History"), nullptr, Qt::CTRL + Qt::Key_H, _gui, SLOT(openHistory()), "history");
0109     action(i18n("Left History"), nullptr, Qt::ALT + Qt::CTRL + Qt::Key_Left, this, SLOT(openLeftHistory()), "left history");
0110     action(i18n("Right History"), nullptr, Qt::ALT + Qt::CTRL + Qt::Key_Right, this, SLOT(openRightHistory()), "right history");
0111     action(i18n("Media"), nullptr, Qt::CTRL + Qt::Key_M, _gui, SLOT(openMedia()), "media");
0112     action(i18n("Left Media"), nullptr, Qt::CTRL + Qt::SHIFT + Qt::Key_Left, this, SLOT(openLeftMedia()), "left media");
0113     action(i18n("Right Media"), nullptr, Qt::CTRL + Qt::SHIFT + Qt::Key_Right, this, SLOT(openRightMedia()), "right media");
0114 
0115     // quick search bar
0116     action(i18n("Find in folder..."), nullptr, Qt::CTRL + Qt::Key_F, _gui, SLOT(showSearchBar()), "search bar");
0117     action(i18n("Select in folder..."), nullptr, Qt::CTRL + Qt::SHIFT + Qt::Key_S, _gui, SLOT(showSearchBarSelection()), "search bar selection");
0118     action(i18n("Filter in folder..."), nullptr, Qt::CTRL + Qt::Key_I, _gui, SLOT(showSearchBarFilter()), "search bar filter");
0119 
0120     // and at last we can set the tool-tips
0121     actRoot->setToolTip(i18n("ROOT (/)"));
0122 
0123     actRenameF2->setToolTip(i18n("Rename file, folder, etc."));
0124     actViewFileF3->setToolTip(i18n("Open file in viewer."));
0125     actEditFileF4->setToolTip(
0126         i18n("<qt><p>Edit file.</p>"
0127              "<p>The editor can be defined in Konfigurator, "
0128              "default is <b>internal editor</b>.</p></qt>"));
0129     actCopyF5->setToolTip(i18n("Copy file from one panel to the other."));
0130     actMoveF6->setToolTip(i18n("Move file from one panel to the other."));
0131     actNewFolderF7->setToolTip(i18n("Create folder in current panel."));
0132     actDeleteF8->setToolTip(i18n("Delete file, folder, etc."));
0133     actTerminalF9->setToolTip(
0134         i18n("<qt><p>Open terminal in current folder.</p>"
0135              "<p>The terminal can be defined in Konfigurator, "
0136              "default is <b>konsole</b>.</p></qt>"));
0137 }
0138 
0139 void ListPanelActions::activePanelChanged()
0140 {
0141     _gui.reconnect(activePanel()->gui);
0142     _func.reconnect(activePanel()->func);
0143 }
0144 
0145 void ListPanelActions::guiUpdated()
0146 {
0147     QList<QAction *> actions;
0148     for (QAction *action : qAsConst(setViewActions))
0149         actions << action;
0150     static_cast<KrMainWindow *>(_mainWindow)->plugActionList("view_actionlist", actions);
0151 }
0152 
0153 inline KrPanel *ListPanelActions::activePanel()
0154 {
0155     return static_cast<KrMainWindow *>(_mainWindow)->activePanel();
0156 }
0157 
0158 inline KrPanel *ListPanelActions::leftPanel()
0159 {
0160     return static_cast<KrMainWindow *>(_mainWindow)->leftPanel();
0161 }
0162 
0163 inline KrPanel *ListPanelActions::rightPanel()
0164 {
0165     return static_cast<KrMainWindow *>(_mainWindow)->rightPanel();
0166 }
0167 
0168 // set view type
0169 
0170 void ListPanelActions::setView(int id)
0171 {
0172     activePanel()->gui->changeType(id);
0173 }
0174 
0175 // navigation
0176 
0177 void ListPanelActions::openLeftBookmarks()
0178 {
0179     leftPanel()->gui->openBookmarks();
0180 }
0181 
0182 void ListPanelActions::openRightBookmarks()
0183 {
0184     rightPanel()->gui->openBookmarks();
0185 }
0186 
0187 void ListPanelActions::openLeftHistory()
0188 {
0189     leftPanel()->gui->openHistory();
0190 }
0191 
0192 void ListPanelActions::openRightHistory()
0193 {
0194     rightPanel()->gui->openHistory();
0195 }
0196 
0197 void ListPanelActions::openLeftMedia()
0198 {
0199     leftPanel()->gui->openMedia();
0200 }
0201 
0202 void ListPanelActions::openRightMedia()
0203 {
0204     rightPanel()->gui->openMedia();
0205 }