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>
12 #include <KFileItemActions>
18 class DolphinMainWindow
;
19 class KFileItemActions
;
20 class KFileItemListProperties
;
21 class DolphinRemoveAction
;
24 * @brief Represents the context menu which appears when doing a right
25 * click on an item or the viewport of the file manager.
27 * Beside static menu entries (e. g. 'Paste' or 'Properties') two
28 * dynamic sub menus are shown when opening a context menu above
30 * - 'Open With': Contains all applications which are registered to
31 * open items of the given MIME type.
32 * - 'Actions': Contains all actions which can be applied to the
35 class DolphinContextMenu
: public QMenu
44 OpenParentFolderInNewWindow
,
45 OpenParentFolderInNewTab
49 * @parent Pointer to the main window the context menu
51 * @pos Position in screen coordinates.
52 * @fileInfo Pointer to the file item the context menu
53 * is applied. If 0 is passed, the context menu
54 * is above the viewport.
55 * @baseUrl Base URL of the viewport where the context menu
58 DolphinContextMenu(DolphinMainWindow
* parent
,
60 const KFileItem
& fileInfo
,
62 KFileItemActions
*fileItemActions
);
64 ~DolphinContextMenu() override
;
66 void setCustomActions(const QList
<QAction
*>& actions
);
69 * Opens the context menu model and returns the requested
70 * command, that should be triggered by the caller. If
71 * Command::None has been returned, either the context-menu
72 * had been closed without executing an action or an
73 * already available action from the main-window has been
79 bool eventFilter(QObject
* object
, QEvent
* event
) override
;
82 void openTrashContextMenu();
83 void openTrashItemContextMenu();
84 void openItemContextMenu();
85 void openViewportContextMenu();
87 void insertDefaultItemActions(const KFileItemListProperties
&);
90 * Adds the "Show menubar" action to the menu if the
93 void addShowMenuBarAction();
95 bool placeExists(const QUrl
& url
) const;
97 QAction
* createPasteAction();
99 KFileItemListProperties
& selectedItemsProperties() const;
102 * Returns the file item for m_baseUrl.
104 KFileItem
baseFileItem();
107 * Adds "Open With" actions
109 void addOpenWithActions();
112 * Adds custom actions e.g. like the "[x] Expandable Folders"-action
113 * provided in the details view.
115 void addCustomActions();
119 * Add services, custom actions, plugins and version control items to the menu
121 void addAdditionalActions(const KFileItemListProperties
&props
);
127 QString filePath
; // empty for separator
128 QString templatePath
; // same as filePath for template
143 DolphinMainWindow
* m_mainWindow
;
145 KFileItem m_fileInfo
;
148 KFileItem
* m_baseFileItem
; /// File item for m_baseUrl
150 KFileItemList m_selectedItems
;
151 mutable KFileItemListProperties
* m_selectedItemsProperties
;
154 KFileCopyToMenu m_copyToMenu
;
155 QList
<QAction
*> m_customActions
;
159 DolphinRemoveAction
* m_removeAction
; // Action that represents either 'Move To Trash' or 'Delete'
160 void addDirectoryItemContextMenu();
161 KFileItemActions
*m_fileItemActions
;