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 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
40 * @parent Pointer to the main window the context menu
42 * @fileInfo Pointer to the file item the context menu
43 * is applied. If 0 is passed, the context menu
44 * is above the viewport.
45 * @selectedItems The selected items for which the context menu
46 * is opened. This list generally includes \a fileInfo.
47 * @baseUrl Base URL of the viewport where the context menu
50 DolphinContextMenu(DolphinMainWindow
*parent
,
51 const KFileItem
&fileInfo
,
52 const KFileItemList
&selectedItems
,
54 KFileItemActions
*fileItemActions
);
56 ~DolphinContextMenu() override
;
59 bool eventFilter(QObject
*object
, QEvent
*event
) override
;
63 * Adds all the actions and menus to this menu based on all given information.
64 * This method calls the other helper methods for adding actions
65 * based on the context given in the constructor.
69 void addTrashContextMenu();
70 void addTrashItemContextMenu();
71 void addItemContextMenu();
72 void addViewportContextMenu();
74 void insertDefaultItemActions(const KFileItemListProperties
&);
76 bool placeExists(const QUrl
&url
) const;
78 QAction
*createPasteAction();
80 KFileItemListProperties
&selectedItemsProperties() const;
83 * Returns the file item for m_baseUrl.
85 KFileItem
baseFileItem();
88 * Adds "Open With" actions
90 void addOpenWithActions();
93 * Add services, custom actions, plugins and version control items to the menu
95 void addAdditionalActions(const KFileItemListProperties
&props
);
98 void addDirectoryItemContextMenu();
99 void addOpenParentFolderActions();
104 QString filePath
; // empty for separator
105 QString templatePath
; // same as filePath for template
116 RecentlyUsedContext
= 16,
119 DolphinMainWindow
*m_mainWindow
;
121 KFileItem m_fileInfo
;
124 KFileItem
*m_baseFileItem
; /// File item for m_baseUrl
126 KFileItemList m_selectedItems
;
127 mutable KFileItemListProperties
*m_selectedItemsProperties
;
130 KFileCopyToMenu m_copyToMenu
;
132 DolphinRemoveAction
*m_removeAction
; // Action that represents either 'Move To Trash' or 'Delete'
133 KFileItemActions
*m_fileItemActions
;