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 void keyPressEvent(QKeyEvent
*ev
) override
;
78 void keyReleaseEvent(QKeyEvent
*ev
) override
;
81 void openTrashContextMenu();
82 void openTrashItemContextMenu();
83 void openItemContextMenu();
84 void openViewportContextMenu();
86 void insertDefaultItemActions(const KFileItemListProperties
&);
89 * Adds the "Show menubar" action to the menu if the
92 void addShowMenuBarAction();
94 bool placeExists(const QUrl
& url
) const;
96 QAction
* createPasteAction();
98 KFileItemListProperties
& selectedItemsProperties() const;
101 * Returns the file item for m_baseUrl.
103 KFileItem
baseFileItem();
106 * Adds "Open With" actions
108 void addOpenWithActions(KFileItemActions
& fileItemActions
);
111 * Adds actions that are provided by a KVersionControlPlugin.
113 void addVersionControlPluginActions();
116 * Adds custom actions e.g. like the "[x] Expandable Folders"-action
117 * provided in the details view.
119 void addCustomActions();
126 QString filePath
; // empty for separator
127 QString templatePath
; // same as filePath for template
142 DolphinMainWindow
* m_mainWindow
;
144 KFileItem m_fileInfo
;
147 KFileItem
* m_baseFileItem
; /// File item for m_baseUrl
149 KFileItemList m_selectedItems
;
150 mutable KFileItemListProperties
* m_selectedItemsProperties
;
153 KFileCopyToMenu m_copyToMenu
;
154 QList
<QAction
*> m_customActions
;
158 DolphinRemoveAction
* m_removeAction
; // Action that represents either 'Move To Trash' or 'Delete'
159 void addDirectoryItemContextMenu(KFileItemActions
&fileItemActions
);