2 * SPDX-FileCopyrightText: 2006 Peter Penz <peter.penz19@gmail.com>
4 * SPDX-License-Identifier: GPL-2.0-or-later
7 #ifndef DOLPHINCONTEXTMENU_H
8 #define DOLPHINCONTEXTMENU_H
10 #include <KFileCopyToMenu>
17 class DolphinMainWindow
;
18 class KFileItemActions
;
19 class KFileItemListProperties
;
20 class DolphinRemoveAction
;
23 * @brief Represents the context menu which appears when doing a right
24 * click on an item or the viewport of the file manager.
26 * Beside static menu entries (e. g. 'Paste' or 'Properties') two
27 * dynamic sub menus are shown when opening a context menu above
29 * - 'Open With': Contains all applications which are registered to
30 * open items of the given MIME type.
31 * - 'Actions': Contains all actions which can be applied to the
34 class DolphinContextMenu
: public QMenu
43 OpenParentFolderInNewWindow
,
44 OpenParentFolderInNewTab
48 * @parent Pointer to the main window the context menu
50 * @pos Position in screen coordinates.
51 * @fileInfo Pointer to the file item the context menu
52 * is applied. If 0 is passed, the context menu
53 * is above the viewport.
54 * @baseUrl Base URL of the viewport where the context menu
57 DolphinContextMenu(DolphinMainWindow
* parent
,
59 const KFileItem
& fileInfo
,
62 ~DolphinContextMenu() override
;
64 void setCustomActions(const QList
<QAction
*>& actions
);
67 * Opens the context menu model and returns the requested
68 * command, that should be triggered by the caller. If
69 * Command::None has been returned, either the context-menu
70 * had been closed without executing an action or an
71 * already available action from the main-window has been
77 bool eventFilter(QObject
* object
, QEvent
* event
) override
;
80 void openTrashContextMenu();
81 void openTrashItemContextMenu();
82 void openItemContextMenu();
83 void openViewportContextMenu();
85 void insertDefaultItemActions(const KFileItemListProperties
&);
88 * Adds the "Show menubar" action to the menu if the
91 void addShowMenuBarAction();
93 bool placeExists(const QUrl
& url
) const;
95 QAction
* createPasteAction();
97 KFileItemListProperties
& selectedItemsProperties() const;
100 * Returns the file item for m_baseUrl.
102 KFileItem
baseFileItem();
105 * Adds "Open With" actions
107 void addOpenWithActions(KFileItemActions
& fileItemActions
);
110 * Adds custom actions e.g. like the "[x] Expandable Folders"-action
111 * provided in the details view.
113 void addCustomActions();
117 * Add services, custom actions, plugins and version control items to the menu
119 void addAdditionalActions(KFileItemActions
&fileItemActions
, const KFileItemListProperties
&props
);
125 QString filePath
; // empty for separator
126 QString templatePath
; // same as filePath for template
141 DolphinMainWindow
* m_mainWindow
;
143 KFileItem m_fileInfo
;
146 KFileItem
* m_baseFileItem
; /// File item for m_baseUrl
148 KFileItemList m_selectedItems
;
149 mutable KFileItemListProperties
* m_selectedItemsProperties
;
152 KFileCopyToMenu m_copyToMenu
;
153 QList
<QAction
*> m_customActions
;
157 DolphinRemoveAction
* m_removeAction
; // Action that represents either 'Move To Trash' or 'Delete'
158 void addDirectoryItemContextMenu(KFileItemActions
&fileItemActions
);