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

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 "viewactions.h"
0009 
0010 #include "../krmainwindow.h"
0011 #include "PanelView/krview.h"
0012 
0013 #include <KI18n/KLocalizedString>
0014 #include <KWidgetsAddons/KToggleAction>
0015 
0016 ViewActions::ViewActions(QObject *parent, KrMainWindow *mainWindow)
0017     : ActionsBase(parent, mainWindow)
0018 {
0019     // zoom
0020     actZoomIn = action(i18n("Zoom In"), "zoom-in", 0, SLOT(zoomIn()), "zoom_in");
0021     actZoomOut = action(i18n("Zoom Out"), "zoom-out", 0, SLOT(zoomOut()), "zoom_out");
0022     actDefaultZoom = action(i18n("Default Zoom"), "zoom-original", 0, SLOT(defaultZoom()), "default_zoom");
0023 
0024     // filter
0025     action(i18n("&All Files"), nullptr, Qt::SHIFT + Qt::Key_F10, SLOT(allFilter()), "all files");
0026     // actExecFilter = new QAction( i18n( "&Executables" ), SHIFT + Qt::Key_F11,
0027     //                              SLOTS, SLOT(execFilter()), actionCollection(), "exec files" );
0028     action(i18n("&Custom"), nullptr, Qt::SHIFT + Qt::Key_F12, SLOT(customFilter()), "custom files");
0029 
0030     // selection
0031     actSelect = action(i18n("Select &Group..."), "edit-select", Qt::CTRL + Qt::Key_Plus, SLOT(markGroup()), "select group");
0032     actSelectAll = action(i18n("&Select All"), "edit-select-all", Qt::ALT + Qt::Key_Plus, SLOT(markAll()), "select all");
0033     actUnselect = action(i18n("&Unselect Group..."), "kr_unselect", Qt::CTRL + Qt::Key_Minus, SLOT(unmarkGroup()), "unselect group");
0034     actUnselectAll = action(i18n("U&nselect All"), "edit-select-none", Qt::ALT + Qt::Key_Minus, SLOT(unmarkAll()), "unselect all");
0035     actInvert = action(i18n("&Invert Selection"), "edit-select-invert", Qt::ALT + Qt::Key_Asterisk, SLOT(invertSelection()), "invert");
0036     actRestoreSelection = action(i18n("Restore Selection"), nullptr, 0, SLOT(restoreSelection()), "restore_selection");
0037     actMarkSameBaseName = action(i18n("Select Files with the Same Name"), nullptr, 0, SLOT(markSameBaseName()), "select_same_base_name");
0038     actMarkSameExtension = action(i18n("Select Files with the Same Extension"), nullptr, 0, SLOT(markSameExtension()), "select_same_extension");
0039 
0040     // other stuff
0041     action(i18n("Show View Options Menu"), nullptr, 0, SLOT(showOptionsMenu()), "show_view_options_menu");
0042     action(i18n("Set Focus to the Panel"), nullptr, 0, SLOT(focusPanel()), "focus_panel");
0043     action(i18n("Apply settings to other tabs"), nullptr, 0, SLOT(applySettingsToOthers()), "view_apply_settings_to_others");
0044     actTogglePreviews = toggleAction(i18n("Show Previews"), nullptr, 0, SLOT(togglePreviews(bool)), "toggle previews");
0045     QAction *actSaveaveDefaultSettings = action(i18n("Save settings as default"), nullptr, 0, SLOT(saveDefaultSettings()), "view_save_default_settings");
0046 
0047     // tooltips
0048     actSelect->setToolTip(i18n("Select group"));
0049     actSelectAll->setToolTip(i18n("Select all files in the current folder"));
0050     actUnselectAll->setToolTip(i18n("Unselect all"));
0051     actSaveaveDefaultSettings->setToolTip(i18n("Save settings as default for new instances of this view type"));
0052 }
0053 
0054 inline KrView *ViewActions::view()
0055 {
0056     return _mainWindow->activeView();
0057 }
0058 
0059 // zoom
0060 
0061 void ViewActions::zoomIn()
0062 {
0063     view()->zoomIn();
0064 }
0065 
0066 void ViewActions::zoomOut()
0067 {
0068     view()->zoomOut();
0069 }
0070 
0071 void ViewActions::defaultZoom()
0072 {
0073     view()->setDefaultFileIconSize();
0074 }
0075 
0076 // filter
0077 
0078 void ViewActions::allFilter()
0079 {
0080     view()->setFilter(KrViewProperties::All);
0081 }
0082 
0083 void ViewActions::customFilter()
0084 {
0085     view()->setFilter(KrViewProperties::Custom);
0086 }
0087 
0088 void ViewActions::showOptionsMenu()
0089 {
0090     view()->showContextMenu();
0091 }
0092 
0093 // selection
0094 
0095 void ViewActions::markAll()
0096 {
0097     view()->changeSelection(KrQuery("*"), true);
0098 }
0099 
0100 void ViewActions::unmarkAll()
0101 {
0102     view()->unselectAll();
0103 }
0104 
0105 void ViewActions::markGroup()
0106 {
0107     view()->customSelection(true);
0108 }
0109 
0110 void ViewActions::unmarkGroup()
0111 {
0112     view()->customSelection(false);
0113 }
0114 
0115 void ViewActions::invertSelection()
0116 {
0117     view()->invertSelection();
0118 }
0119 
0120 void ViewActions::restoreSelection()
0121 {
0122     view()->restoreSelection();
0123 }
0124 
0125 void ViewActions::markSameBaseName()
0126 {
0127     view()->markSameBaseName();
0128 }
0129 
0130 void ViewActions::markSameExtension()
0131 {
0132     view()->markSameExtension();
0133 }
0134 
0135 // other stuff
0136 
0137 void ViewActions::saveDefaultSettings()
0138 {
0139     view()->saveDefaultSettings();
0140 }
0141 
0142 void ViewActions::applySettingsToOthers()
0143 {
0144     view()->applySettingsToOthers();
0145 }
0146 
0147 void ViewActions::focusPanel()
0148 {
0149     view()->widget()->setFocus();
0150 }
0151 
0152 void ViewActions::togglePreviews(bool show)
0153 {
0154     view()->showPreviews(show);
0155 }
0156 
0157 void ViewActions::refreshActions()
0158 {
0159     actDefaultZoom->setEnabled(view()->defaultFileIconSize() != view()->fileIconSize());
0160     int idx = KrView::iconSizes.indexOf(view()->fileIconSize());
0161     actZoomOut->setEnabled(idx > 0);
0162     actZoomIn->setEnabled(idx < (KrView::iconSizes.count() - 1));
0163     actRestoreSelection->setEnabled(view()->canRestoreSelection());
0164     actTogglePreviews->setChecked(view()->previewsShown());
0165 }