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
41 * @parent Pointer to the main window the context menu
43 * @fileInfo Pointer to the file item the context menu
44 * is applied. If 0 is passed, the context menu
45 * is above the viewport.
46 * @selectedItems The selected items for which the context menu
47 * is opened. This list generally includes \a fileInfo.
48 * @baseUrl Base URL of the viewport where the context menu
51 DolphinContextMenu(DolphinMainWindow
* parent
,
52 const KFileItem
& fileInfo
,
53 const KFileItemList
&selectedItems
,
55 KFileItemActions
*fileItemActions
);
57 ~DolphinContextMenu() override
;
60 bool eventFilter(QObject
* object
, QEvent
* event
) override
;
64 * Adds all the actions and menus to this menu based on all given information.
65 * This method calls the other helper methods for adding actions
66 * based on the context given in the constructor.
70 void addTrashContextMenu();
71 void addTrashItemContextMenu();
72 void addItemContextMenu();
73 void addViewportContextMenu();
75 void insertDefaultItemActions(const KFileItemListProperties
&);
77 bool placeExists(const QUrl
& url
) const;
79 QAction
* createPasteAction();
81 KFileItemListProperties
& selectedItemsProperties() const;
84 * Returns the file item for m_baseUrl.
86 KFileItem
baseFileItem();
89 * Adds "Open With" actions
91 void addOpenWithActions();
94 * Add services, custom actions, plugins and version control items to the menu
96 void addAdditionalActions(const KFileItemListProperties
&props
);
103 QString filePath
; // empty for separator
104 QString templatePath
; // same as filePath for template
118 DolphinMainWindow
* m_mainWindow
;
120 KFileItem m_fileInfo
;
123 KFileItem
* m_baseFileItem
; /// File item for m_baseUrl
125 KFileItemList m_selectedItems
;
126 mutable KFileItemListProperties
* m_selectedItemsProperties
;
129 KFileCopyToMenu m_copyToMenu
;
131 DolphinRemoveAction
* m_removeAction
; // Action that represents either 'Move To Trash' or 'Delete'
132 void addDirectoryItemContextMenu();
133 KFileItemActions
*m_fileItemActions
;