diff --git a/src/filewidgets/kdiroperator.h b/src/filewidgets/kdiroperator.h --- a/src/filewidgets/kdiroperator.h +++ b/src/filewidgets/kdiroperator.h @@ -424,6 +424,49 @@ */ KActionCollection *actionCollection() const; + /** + * an accessor to a collection of all available Actions. The actions + * are static, they will be there all the time. + * There are the following actions: + * + * @li popupMenu : an ActionMenu presenting a popupmenu with all actions + * @li up : changes to the parent directory + * @li back : goes back to the previous directory + * @li forward : goes forward in the history + * @li home : changes to the user's home directory + * @li reload : reloads the current directory + * @li mkdir : opens a dialog box to create a directory + * @li delete : deletes the selected files/directories + * @li sorting menu : an ActionMenu containing all sort-options + * @li by name : sorts by name + * @li by size : sorts by size + * @li by date : sorts by date + * @li by type : sorts by type + * @li descending : reverses the sort order + * @li view menu : an ActionMenu containing all actions concerning the view + * @li short view : shows a simple fileview + * @li detailed view : shows a detailed fileview (dates, permissions ,...) + * @li show hidden : shows hidden files + * @li preview : shows a preview next to the fileview + * @li properties : shows a KPropertiesDialog for the selected files + * + * The short and detailed view are in an exclusive group. The sort-by + * actions are in an exclusive group as well. Also the "separate dirs", + * "preview" and "single" actions are in an exclusive group. + * + * You can e.g. use + * \code + * actions()->value("up")->plug(someToolBar); + * \endcode + * to add a button into a toolbar, which makes the dirOperator change to + * its parent directory. + * + * @returns all available Actions + * + * @since 5.67 + */ + QHash actions() const; + /** * Sets the config object and the to be used group in KDirOperator. This * will be used to store the view's configuration. diff --git a/src/filewidgets/kdiroperator.cpp b/src/filewidgets/kdiroperator.cpp --- a/src/filewidgets/kdiroperator.cpp +++ b/src/filewidgets/kdiroperator.cpp @@ -196,6 +196,7 @@ KActionMenu *actionMenu; KActionCollection *actionCollection; + QHash actions; KNewFileMenu *newFileMenu; @@ -510,6 +511,11 @@ return d->actionCollection; } +QHash KDirOperator::actions() const +{ + return d->actions; +} + KFile::FileView KDirOperator::Private::allViews() { return static_cast(KFile::Simple | KFile::Detail | KFile::Tree | KFile::DetailTree); @@ -1928,60 +1934,74 @@ d->actionMenu = new KActionMenu(i18n("Menu"), this); d->actionCollection->addAction(QStringLiteral("popupMenu"), d->actionMenu); + d->actions[QStringLiteral("popupMenu")] = d->actionMenu; QAction *upAction = d->actionCollection->addAction(KStandardAction::Up, QStringLiteral("up"), this, SLOT(cdUp())); upAction->setText(i18n("Parent Folder")); + d->actions[QStringLiteral("up")] = upAction; QAction *backAction = d->actionCollection->addAction(KStandardAction::Back, QStringLiteral("back"), this, SLOT(back())); backAction->setShortcut(Qt::Key_Backspace); + d->actions[QStringLiteral("back")] = backAction; - d->actionCollection->addAction(KStandardAction::Forward, QStringLiteral("forward"), this, SLOT(forward())); + QAction *forwardAction = d->actionCollection->addAction(KStandardAction::Forward, QStringLiteral("forward"), this, SLOT(forward())); + d->actions[QStringLiteral("forward")] = forwardAction; QAction *homeAction = d->actionCollection->addAction(KStandardAction::Home, QStringLiteral("home"), this, SLOT(home())); homeAction->setText(i18n("Home Folder")); + d->actions[QStringLiteral("home")] = homeAction; QAction *reloadAction = d->actionCollection->addAction(KStandardAction::Redisplay, QStringLiteral("reload"), this, SLOT(rereadDir())); reloadAction->setText(i18n("Reload")); reloadAction->setShortcuts(KStandardShortcut::shortcut(KStandardShortcut::Reload)); + d->actions[QStringLiteral("reload")] = reloadAction; QAction *mkdirAction = new QAction(i18n("New Folder..."), this); d->actionCollection->addAction(QStringLiteral("mkdir"), mkdirAction); mkdirAction->setIcon(QIcon::fromTheme(QStringLiteral("folder-new"))); connect(mkdirAction, SIGNAL(triggered(bool)), this, SLOT(mkdir())); + d->actions[QStringLiteral("mkdir")] = mkdirAction; QAction *trash = new QAction(i18n("Move to Trash"), this); d->actionCollection->addAction(QStringLiteral("trash"), trash); trash->setIcon(QIcon::fromTheme(QStringLiteral("user-trash"))); trash->setShortcut(Qt::Key_Delete); connect(trash, &QAction::triggered, this, &KDirOperator::trashSelected); + d->actions[QStringLiteral("trash")] = trash; QAction *action = new QAction(i18n("Delete"), this); d->actionCollection->addAction(QStringLiteral("delete"), action); action->setIcon(QIcon::fromTheme(QStringLiteral("edit-delete"))); action->setShortcut(Qt::SHIFT + Qt::Key_Delete); connect(action, &QAction::triggered, this, &KDirOperator::deleteSelected); + d->actions[QStringLiteral("delete")] = action; // the sort menu actions KActionMenu *sortMenu = new KActionMenu(i18n("Sorting"), this); sortMenu->setIcon(QIcon::fromTheme(QStringLiteral("view-sort"))); sortMenu->setDelayed(false); d->actionCollection->addAction(QStringLiteral("sorting menu"), sortMenu); + d->actions[QStringLiteral("sorting menu")] = sortMenu; KToggleAction *byNameAction = new KToggleAction(i18n("Sort by Name"), this); d->actionCollection->addAction(QStringLiteral("by name"), byNameAction); connect(byNameAction, SIGNAL(triggered(bool)), this, SLOT(_k_slotSortByName())); + d->actions[QStringLiteral("by name")] = byNameAction; KToggleAction *bySizeAction = new KToggleAction(i18n("Sort by Size"), this); d->actionCollection->addAction(QStringLiteral("by size"), bySizeAction); connect(bySizeAction, SIGNAL(triggered(bool)), this, SLOT(_k_slotSortBySize())); + d->actions[QStringLiteral("by size")] = bySizeAction; KToggleAction *byDateAction = new KToggleAction(i18n("Sort by Date"), this); d->actionCollection->addAction(QStringLiteral("by date"), byDateAction); connect(byDateAction, SIGNAL(triggered(bool)), this, SLOT(_k_slotSortByDate())); + d->actions[QStringLiteral("by date")] = byDateAction; KToggleAction *byTypeAction = new KToggleAction(i18n("Sort by Type"), this); d->actionCollection->addAction(QStringLiteral("by type"), byTypeAction); connect(byTypeAction, SIGNAL(triggered(bool)), this, SLOT(_k_slotSortByType())); + d->actions[QStringLiteral("by type")] = byTypeAction; QActionGroup *sortOrderGroup = new QActionGroup(this); sortOrderGroup->setExclusive(true); @@ -1992,33 +2012,39 @@ connect(ascendingAction, &QAction::triggered, this, [this]() { this->d->_k_slotSortReversed(false); }); + d->actions[QStringLiteral("ascending")] = ascendingAction; KToggleAction *descendingAction = new KToggleAction(i18n("Descending"), this); d->actionCollection->addAction(QStringLiteral("descending"), descendingAction); descendingAction->setActionGroup(sortOrderGroup); connect(descendingAction, &QAction::triggered, this, [this]() { this->d->_k_slotSortReversed(true); }); + d->actions[QStringLiteral("descending")] = descendingAction; KToggleAction *dirsFirstAction = new KToggleAction(i18n("Folders First"), this); d->actionCollection->addAction(QStringLiteral("dirs first"), dirsFirstAction); connect(dirsFirstAction, SIGNAL(triggered(bool)), this, SLOT(_k_slotToggleDirsFirst())); + d->actions[QStringLiteral("dirs first")] = dirsFirstAction; // View modes that match those of Dolphin KToggleAction *iconsViewAction = new KToggleAction(i18n("Icons View"), this); iconsViewAction->setIcon(QIcon::fromTheme(QStringLiteral("view-list-icons"))); d->actionCollection->addAction(QStringLiteral("icons view"), iconsViewAction); connect(iconsViewAction, SIGNAL(triggered(bool)), this, SLOT(_k_slotIconsView())); + d->actions[QStringLiteral("icons view")] = iconsViewAction; KToggleAction *compactViewAction = new KToggleAction(i18n("Compact View"), this); compactViewAction->setIcon(QIcon::fromTheme(QStringLiteral("view-list-details"))); d->actionCollection->addAction(QStringLiteral("compact view"), compactViewAction); connect(compactViewAction, SIGNAL(triggered(bool)), this, SLOT(_k_slotCompactView())); + d->actions[QStringLiteral("compact view")] = compactViewAction; KToggleAction *detailsViewAction = new KToggleAction(i18n("Details View"), this); detailsViewAction->setIcon(QIcon::fromTheme(QStringLiteral("view-list-tree"))); d->actionCollection->addAction(QStringLiteral("details view"), detailsViewAction); connect(detailsViewAction, SIGNAL(triggered(bool)), this, SLOT(_k_slotDetailsView())); + d->actions[QStringLiteral("details view")] = detailsViewAction; QActionGroup *viewModeGroup = new QActionGroup(this); viewModeGroup->setExclusive(true); @@ -2034,14 +2060,17 @@ d->decorationMenu = new KActionMenu(i18n("Icon Position"), this); d->actionCollection->addAction(QStringLiteral("decoration menu"), d->decorationMenu); + d->actions[QStringLiteral("decoration menu")] = d->decorationMenu; d->leftAction = new KToggleAction(i18n("Next to File Name"), this); d->actionCollection->addAction(QStringLiteral("decorationAtLeft"), d->leftAction); connect(d->leftAction, SIGNAL(triggered(bool)), this, SLOT(_k_slotChangeDecorationPosition())); + d->actions[QStringLiteral("decorationAtLeft")] = d->leftAction; KToggleAction *topAction = new KToggleAction(i18n("Above File Name"), this); d->actionCollection->addAction(QStringLiteral("decorationAtTop"), topAction); connect(topAction, SIGNAL(triggered(bool)), this, SLOT(_k_slotChangeDecorationPosition())); + d->actions[QStringLiteral("decorationAtTop")] = topAction; d->decorationMenu->addAction(d->leftAction); d->decorationMenu->addAction(topAction); @@ -2055,21 +2084,25 @@ d->actionCollection->addAction(QStringLiteral("short view"), shortAction); shortAction->setIcon(QIcon::fromTheme(QStringLiteral("view-list-icons"))); connect(shortAction, SIGNAL(triggered()), SLOT(_k_slotSimpleView())); + d->actions[QStringLiteral("short view")] = shortAction; KToggleAction *detailedAction = new KToggleAction(i18n("Detailed View"), this); d->actionCollection->addAction(QStringLiteral("detailed view"), detailedAction); detailedAction->setIcon(QIcon::fromTheme(QStringLiteral("view-list-details"))); connect(detailedAction, SIGNAL(triggered()), SLOT(_k_slotDetailedView())); + d->actions[QStringLiteral("detailed view")] = detailedAction; KToggleAction *treeAction = new KToggleAction(i18n("Tree View"), this); d->actionCollection->addAction(QStringLiteral("tree view"), treeAction); treeAction->setIcon(QIcon::fromTheme(QStringLiteral("view-list-tree"))); connect(treeAction, SIGNAL(triggered()), SLOT(_k_slotTreeView())); + d->actions[QStringLiteral("tree view")] = treeAction; KToggleAction *detailedTreeAction = new KToggleAction(i18n("Detailed Tree View"), this); d->actionCollection->addAction(QStringLiteral("detailed tree view"), detailedTreeAction); detailedTreeAction->setIcon(QIcon::fromTheme(QStringLiteral("view-list-tree"))); connect(detailedTreeAction, SIGNAL(triggered()), SLOT(_k_slotDetailedTreeView())); + d->actions[QStringLiteral("detailed tree view")] = detailedTreeAction; QActionGroup *viewGroup = new QActionGroup(this); shortAction->setActionGroup(viewGroup); @@ -2080,34 +2113,40 @@ KToggleAction *allowExpansionAction = new KToggleAction(i18n("Allow Expansion in Details View"), this); d->actionCollection->addAction(QStringLiteral("allow expansion"), allowExpansionAction); connect(allowExpansionAction, SIGNAL(toggled(bool)), SLOT(_k_slotToggleAllowExpansion(bool))); + d->actions[QStringLiteral("allow expansion")] = allowExpansionAction; KToggleAction *showHiddenAction = new KToggleAction(i18n("Show Hidden Files"), this); d->actionCollection->addAction(QStringLiteral("show hidden"), showHiddenAction); showHiddenAction->setShortcuts({Qt::ALT + Qt::Key_Period, Qt::CTRL + Qt::Key_H, Qt::Key_F8}); connect(showHiddenAction, SIGNAL(toggled(bool)), SLOT(_k_slotToggleHidden(bool))); + d->actions[QStringLiteral("show hidden")] = showHiddenAction; KToggleAction *previewAction = new KToggleAction(i18n("Show Preview Panel"), this); d->actionCollection->addAction(QStringLiteral("preview"), previewAction); previewAction->setShortcut(Qt::Key_F11); connect(previewAction, SIGNAL(toggled(bool)), SLOT(_k_togglePreview(bool))); + d->actions[QStringLiteral("preview")] = previewAction; KToggleAction *inlinePreview = new KToggleAction(QIcon::fromTheme(QStringLiteral("view-preview")), i18n("Show Preview"), this); d->actionCollection->addAction(QStringLiteral("inline preview"), inlinePreview); inlinePreview->setShortcut(Qt::Key_F12); connect(inlinePreview, SIGNAL(toggled(bool)), SLOT(_k_toggleInlinePreviews(bool))); + d->actions[QStringLiteral("inline preview")] = inlinePreview; QAction *fileManager = new QAction(i18n("Open Containing Folder"), this); d->actionCollection->addAction(QStringLiteral("file manager"), fileManager); fileManager->setIcon(QIcon::fromTheme(QStringLiteral("system-file-manager"))); connect(fileManager, SIGNAL(triggered()), SLOT(_k_slotOpenFileManager())); + d->actions[QStringLiteral("file manager")] = fileManager; action = new QAction(i18n("Properties"), this); d->actionCollection->addAction(QStringLiteral("properties"), action); action->setIcon(QIcon::fromTheme(QStringLiteral("document-properties"))); action->setShortcut(Qt::ALT + Qt::Key_Return); connect(action, SIGNAL(triggered(bool)), this, SLOT(_k_slotProperties())); + d->actions[QStringLiteral("properties")] = action; // the view menu actions KActionMenu *viewMenu = new KActionMenu(i18n("&View"), this); @@ -2117,6 +2156,7 @@ // Comment following lines to hide the extra two modes viewMenu->addAction(treeAction); viewMenu->addAction(detailedTreeAction); + d->actions[QStringLiteral("view menu")] = viewMenu; // TODO: QAbstractItemView does not offer an action collection. Provide // an interface to add a custom action collection.