1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz19@gmail.com> *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
20 #ifndef DOLPHINCONTEXTMENU_H
21 #define DOLPHINCONTEXTMENU_H
23 #include <KFileCopyToMenu>
30 class DolphinMainWindow
;
31 class KFileItemActions
;
32 class KFileItemListProperties
;
33 class DolphinRemoveAction
;
36 * @brief Represents the context menu which appears when doing a right
37 * click on an item or the viewport of the file manager.
39 * Beside static menu entries (e. g. 'Paste' or 'Properties') two
40 * dynamic sub menus are shown when opening a context menu above
42 * - 'Open With': Contains all applications which are registered to
43 * open items of the given MIME type.
44 * - 'Actions': Contains all actions which can be applied to the
47 class DolphinContextMenu
: public QMenu
56 OpenParentFolderInNewWindow
,
57 OpenParentFolderInNewTab
61 * @parent Pointer to the main window the context menu
63 * @pos Position in screen coordinates.
64 * @fileInfo Pointer to the file item the context menu
65 * is applied. If 0 is passed, the context menu
66 * is above the viewport.
67 * @baseUrl Base URL of the viewport where the context menu
70 DolphinContextMenu(DolphinMainWindow
* parent
,
72 const KFileItem
& fileInfo
,
75 ~DolphinContextMenu() override
;
77 void setCustomActions(const QList
<QAction
*>& actions
);
80 * Opens the context menu model and returns the requested
81 * command, that should be triggered by the caller. If
82 * Command::None has been returned, either the context-menu
83 * had been closed without executing an action or an
84 * already available action from the main-window has been
90 void keyPressEvent(QKeyEvent
*ev
) override
;
91 void keyReleaseEvent(QKeyEvent
*ev
) override
;
94 void openTrashContextMenu();
95 void openTrashItemContextMenu();
96 void openItemContextMenu();
97 void openViewportContextMenu();
99 void insertDefaultItemActions(const KFileItemListProperties
&);
102 * Adds the "Show menubar" action to the menu if the
105 void addShowMenuBarAction();
107 bool placeExists(const QUrl
& url
) const;
109 QAction
* createPasteAction();
111 KFileItemListProperties
& selectedItemsProperties() const;
114 * Returns the file item for m_baseUrl.
116 KFileItem
baseFileItem();
119 * Adds "Open With" actions
121 void addOpenWithActions(KFileItemActions
& fileItemActions
);
124 * Adds actions that are provided by a KVersionControlPlugin.
126 void addVersionControlPluginActions();
129 * Adds custom actions e.g. like the "[x] Expandable Folders"-action
130 * provided in the details view.
132 void addCustomActions();
139 QString filePath
; // empty for separator
140 QString templatePath
; // same as filePath for template
153 DolphinMainWindow
* m_mainWindow
;
155 KFileItem m_fileInfo
;
158 KFileItem
* m_baseFileItem
; /// File item for m_baseUrl
160 KFileItemList m_selectedItems
;
161 mutable KFileItemListProperties
* m_selectedItemsProperties
;
164 KFileCopyToMenu m_copyToMenu
;
165 QList
<QAction
*> m_customActions
;
169 DolphinRemoveAction
* m_removeAction
; // Action that represents either 'Move To Trash' or 'Delete'