diff options
| author | Felix Ernst <[email protected]> | 2022-04-02 17:00:58 +0000 |
|---|---|---|
| committer | Felix Ernst <[email protected]> | 2022-04-02 17:00:58 +0000 |
| commit | b3add256945863b01cfa2bc985b61be83fc3570c (patch) | |
| tree | 22f531b43d842bf57674d33e0f22b34ec28342d1 /src/dolphincontextmenu.h | |
| parent | 0c38a27cc0f8646e246eca65fdd6dc6b5c4bb4cc (diff) | |
Refactor DolphinContextMenu so its actions are retrievable
This mostly red MR should have no visible effect. It is part of my work towards !273.
There are two calls necessary to open the DolphinContextMenu:
One to construct it and one to execute/show it.
Before this commit, the actual populating of the ContextMenu was
done on execute. This meant that the actions of the ContextMenu
couldn't be looked at or changed without first showing the Menu
to the user. It also meant that the construction itself didn't
actually do much constructing/populating at all which might seem
a bit unintuitive.
This commit changes this behaviour so the DolphinContextMenu is
actually populated fully on construction. The executing/showing of
the ContextMenu now does just that and nothing more.
Previously, some actions in the context menu were actually not
wired up to anything and instead the DolphinContextMenu or the
DolphinMainWindow executed some code after the user had clicked
such a dummy action from the ContextMenu. Now all the actions are
properly constructed beforehand and no special handling is
necessary when the ContextMenu hides itself.
This commit removes the pos parameter from the DolphinContextMenu
constructor. This parameter contained the position where the Menu
would be shown later. This information isn't necessary to have on
construction and was already part of the exec(pos) call in the
first place. The variable m_pos that stored the value is removed.
This commit also removes a "customActions" functionality that can
supposedly be used to add further custom actions to the
DolphinContextMenu but this functionality isn't ever used
anywhere so its usefulness is questionable. It also wouldn't be
difficult to re-add this functionality if it was ever required for
something.
This commit also addresses an old TODO in dolphinpart.cpp that
asked for the calls for opening the DolphinContextMenu to actually
contain the information for which items the DolphinContextMenu is
supposed to be constructed. Before this, only the item that was
directly clicked was transmitted and then DolphinContextMenu
retrieved the currently selected set of items by itself.
It makes more sense that DolphinContextMenu would be informed on
construction which items it is supposed to show context actions
for.
Most of this is necessary so we are able to show the contextual
actions anywhere else than in the ContextMenu in the future.
I am targeting 22.08 with this MR because it makes no sense to merge a refactor for the upcoming release already.
Diffstat (limited to 'src/dolphincontextmenu.h')
| -rw-r--r-- | src/dolphincontextmenu.h | 58 |
1 files changed, 15 insertions, 43 deletions
diff --git a/src/dolphincontextmenu.h b/src/dolphincontextmenu.h index e033fca6e..627a6e3b8 100644 --- a/src/dolphincontextmenu.h +++ b/src/dolphincontextmenu.h @@ -37,60 +37,42 @@ class DolphinContextMenu : public QMenu Q_OBJECT public: - enum Command - { - None, - OpenParentFolder, - OpenParentFolderInNewWindow, - OpenParentFolderInNewTab - }; - /** * @parent Pointer to the main window the context menu * belongs to. - * @pos Position in screen coordinates. * @fileInfo Pointer to the file item the context menu * is applied. If 0 is passed, the context menu * is above the viewport. + * @selectedItems The selected items for which the context menu + * is opened. This list generally includes \a fileInfo. * @baseUrl Base URL of the viewport where the context menu * should be opened. */ DolphinContextMenu(DolphinMainWindow* parent, - const QPoint& pos, const KFileItem& fileInfo, + const KFileItemList &selectedItems, const QUrl& baseUrl, KFileItemActions *fileItemActions); ~DolphinContextMenu() override; - void setCustomActions(const QList<QAction*>& actions); - - /** - * Opens the context menu model and returns the requested - * command, that should be triggered by the caller. If - * Command::None has been returned, either the context-menu - * had been closed without executing an action or an - * already available action from the main-window has been - * executed. - */ - Command open(); - protected: bool eventFilter(QObject* object, QEvent* event) override; private: - void openTrashContextMenu(); - void openTrashItemContextMenu(); - void openItemContextMenu(); - void openViewportContextMenu(); - - void insertDefaultItemActions(const KFileItemListProperties&); - /** - * Adds the "Show menubar" action to the menu if the - * menubar is hidden. + * Adds all the actions and menus to this menu based on all given information. + * This method calls the other helper methods for adding actions + * based on the context given in the constructor. */ - void addShowMenuBarAction(); + void addAllActions(); + + void addTrashContextMenu(); + void addTrashItemContextMenu(); + void addItemContextMenu(); + void addViewportContextMenu(); + + void insertDefaultItemActions(const KFileItemListProperties&); bool placeExists(const QUrl& url) const; @@ -109,17 +91,11 @@ private: void addOpenWithActions(); /** - * Adds custom actions e.g. like the "[x] Expandable Folders"-action - * provided in the details view. - */ - void addCustomActions(); - -private: - /** * Add services, custom actions, plugins and version control items to the menu */ void addAdditionalActions(const KFileItemListProperties &props); +private: struct Entry { int type; @@ -139,7 +115,6 @@ private: SearchContext = 8, }; - QPoint m_pos; DolphinMainWindow* m_mainWindow; KFileItem m_fileInfo; @@ -152,9 +127,6 @@ private: int m_context; KFileCopyToMenu m_copyToMenu; - QList<QAction*> m_customActions; - - Command m_command; DolphinRemoveAction* m_removeAction; // Action that represents either 'Move To Trash' or 'Delete' void addDirectoryItemContextMenu(); |
