+
+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")));
+ }
+ }
+}