┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/views/dolphinviewactionhandler.cpp
diff options
context:
space:
mode:
authorFelix Ernst <[email protected]>2021-05-13 16:49:27 +0000
committerNate Graham <[email protected]>2021-05-13 16:49:27 +0000
commit53a778c1ebab4473da8ae7b18fd2f2ac75b9690a (patch)
tree070949ff96d109a090337ba9d95ef4ddd45c8dcc /src/views/dolphinviewactionhandler.cpp
parent4d9ea4261a1f24e299595b897ea790eab1748fe9 (diff)
Re-arrange the contents of the hamburger menu
To improve usability, the entries in the hamburger menu are changed. Maybe the biggest fault of the previous menu contents were that there were too many actions. The new menu contents are composed of all the actions which are necessary to use Dolphin and those which are very useful and should be of interest for most users. Some menu contents change depending on the state of the application. We can be more bold in only showing what really seems necessary because this commit activates the special sub-menu of KHamburgerMenu that helps users discover all further features of Dolphin. The hamburger menu is from now on also added to the context menus in the view when both the menu bar and toolbar are hidden. This allows users to hide both of them and still use all features of Dolphin.
Diffstat (limited to 'src/views/dolphinviewactionhandler.cpp')
-rw-r--r--src/views/dolphinviewactionhandler.cpp97
1 files changed, 97 insertions, 0 deletions
diff --git a/src/views/dolphinviewactionhandler.cpp b/src/views/dolphinviewactionhandler.cpp
index 236daed5f..4acc420b0 100644
--- a/src/views/dolphinviewactionhandler.cpp
+++ b/src/views/dolphinviewactionhandler.cpp
@@ -18,6 +18,7 @@
#endif
#include <KActionCollection>
#include <KActionMenu>
+#include <KFileItemListProperties>
#include <KLocalizedString>
#include <KNewFileMenu>
#include <KPropertiesDialog>
@@ -68,6 +69,9 @@ void DolphinViewActionHandler::setCurrentView(DolphinView* view)
this, &DolphinViewActionHandler::slotZoomLevelChanged);
connect(view, &DolphinView::writeStateChanged,
this, &DolphinViewActionHandler::slotWriteStateChanged);
+ connect(view, &DolphinView::selectionChanged,
+ this, &DolphinViewActionHandler::slotSelectionChanged);
+ slotSelectionChanged(m_currentView->selectedItems());
}
DolphinView* DolphinViewActionHandler::currentView()
@@ -155,6 +159,25 @@ void DolphinViewActionHandler::createActions()
m_actionCollection->setDefaultShortcuts(copyPathAction, {Qt::CTRL | Qt::ALT | Qt::Key_C});
connect(copyPathAction, &QAction::triggered, this, &DolphinViewActionHandler::slotCopyPath);
+ // This menu makes sure that users who don't know how to open a context menu and haven't
+ // figured out how to enable the menu bar can still perform basic file manipulation.
+ // This only works if they know how to select a file.
+ // The text when nothing is selected at least implies that a selection can /somehow/ be made.
+ // This menu is by default only used in the hamburger menu but created here so users can put
+ // it on their toolbar.
+ KActionMenu *basicActionsMenu = m_actionCollection->add<KActionMenu>(QStringLiteral("basic_actions"), this);
+ // The text is set later depending on the selection in the currently active view.
+ basicActionsMenu->setPopupMode(QToolButton::InstantPopup);
+ basicActionsMenu->addAction(m_actionCollection->action(KStandardAction::name(KStandardAction::Cut)));
+ basicActionsMenu->addAction(m_actionCollection->action(KStandardAction::name(KStandardAction::Copy)));
+ basicActionsMenu->addAction(m_actionCollection->action(KStandardAction::name(KStandardAction::Paste)));
+ basicActionsMenu->addSeparator();
+ basicActionsMenu->addAction(m_actionCollection->action(KStandardAction::name(KStandardAction::RenameFile)));
+ basicActionsMenu->addAction(m_actionCollection->action(KStandardAction::name(KStandardAction::MoveToTrash)));
+ basicActionsMenu->addSeparator();
+ basicActionsMenu->addAction(m_actionCollection->action(QStringLiteral("properties")));
+ basicActionsMenu->addSeparator(); // We add one more separator because we sometimes add contextual
+ // actions in slotSelectionChanged() after the static ones above.
// View menu
KToggleAction* iconsAction = iconsModeAction();
@@ -208,6 +231,14 @@ void DolphinViewActionHandler::createActions()
m_actionCollection);
zoomOutAction->setWhatsThis(i18nc("@info:whatsthis zoom out", "This reduces the icon size."));
+ KActionMenu* zoomMenu = m_actionCollection->add<KActionMenu>(QStringLiteral("zoom"));
+ zoomMenu->setText(i18nc("@action:inmenu menu of zoom actions", "Zoom"));
+ zoomMenu->setIcon(QIcon::fromTheme(QStringLiteral("zoom")));
+ zoomMenu->setPopupMode(QToolButton::InstantPopup);
+ zoomMenu->addAction(zoomInAction);
+ zoomMenu->addAction(zoomResetAction);
+ zoomMenu->addAction(zoomOutAction);
+
KToggleAction* showPreview = m_actionCollection->add<KToggleAction>(QStringLiteral("show_preview"));
showPreview->setText(i18nc("@action:intoolbar", "Show Previews"));
showPreview->setToolTip(i18nc("@info", "Show preview of files and folders"));
@@ -709,3 +740,69 @@ void DolphinViewActionHandler::slotCopyPath()
{
m_currentView->copyPathToClipboard();
}
+
+void DolphinViewActionHandler::slotSelectionChanged(const KFileItemList& selection)
+{
+ QString basicActionsMenuText;
+ switch (selection.count()) {
+ case 0:
+ basicActionsMenuText =
+ i18nc("@action:inmenu menu with actions like copy, paste, rename. The user's selection is empty when this text is shown.",
+ "Actions for Current View");
+ break;
+ case 1:
+ basicActionsMenuText =
+ i18nc("@action:inmenu menu with actions like copy, paste, rename. %1 is the name of the singular selected file/folder.",
+ "Actions for \"%1\"", selection.first().name());
+ break;
+ case 2:
+ basicActionsMenuText =
+ i18nc("@action:inmenu menu with actions like copy, paste, rename. %1 and %2 are names of files/folders.",
+ "Actions for \"%1\" and \"%2\"", selection.first().name(), selection.last().name());
+ break;
+ case 3:
+ basicActionsMenuText =
+ i18nc("@action:inmenu menu with actions like copy, paste, rename. %1, %2 and %3 are names of files/folders.",
+ "Actions for \"%1\", \"%2\" and \"%3\"",
+ selection.first().name(), selection.at(1).name(), selection.last().name());
+ break;
+ default:
+ basicActionsMenuText = QString();
+ break;
+ }
+
+ // At some point the added clarity from the text starts being less important than the menu width.
+ if (basicActionsMenuText.isEmpty() || basicActionsMenuText.length() > 40) {
+ const KFileItemListProperties properties(selection);
+ if (properties.isFile()) {
+ basicActionsMenuText =
+ i18ncp("@action:inmenu menu with actions like copy, paste, rename. %1 is the amount of selected files/folders.",
+ "Actions for One Selected File", "Actions for %1 Selected Files", selection.count());
+ } else if (properties.isDirectory()) {
+ basicActionsMenuText =
+ i18ncp("@action:inmenu menu with actions like copy, paste, rename. %1 is the amount of selected files/folders.",
+ "Actions for One Selected Folder", "Actions for %1 Selected Folders", selection.count());
+ } else {
+ basicActionsMenuText =
+ i18ncp("@action:inmenu menu with actions like copy, paste, rename. %1 is the amount of selected files/folders.",
+ "Actions for One Selected Item", "Actions for %1 Selected Items", selection.count());
+ }
+ }
+
+ QAction *basicActionsMenu = m_actionCollection->action(QStringLiteral("basic_actions"));
+ basicActionsMenu->setText(basicActionsMenuText);
+
+ // Add or remove contextual actions
+ auto basicActionsMenuActions = basicActionsMenu->menu()->actions();
+ while (!basicActionsMenu->menu()->actions().constLast()->isSeparator()) {
+ basicActionsMenu->menu()->removeAction(basicActionsMenu->menu()->actions().last());
+ }
+ if (selection.count() == 1) {
+ if (selection.first().isLink()) {
+ basicActionsMenu->menu()->addAction(m_actionCollection->action(QStringLiteral("show_target")));
+ }
+ if (selection.first().isDir()) {
+ basicActionsMenu->menu()->addAction(m_actionCollection->action(QStringLiteral("add_to_places")));
+ }
+ }
+}