]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphincontextmenu.h
Merge branch 'release/19.12'
[dolphin.git] / src / dolphincontextmenu.h
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz19@gmail.com> *
3 * *
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. *
8 * *
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. *
13 * *
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 ***************************************************************************/
19
20 #ifndef DOLPHINCONTEXTMENU_H
21 #define DOLPHINCONTEXTMENU_H
22
23 #include <KFileCopyToMenu>
24 #include <KFileItem>
25
26 #include <QMenu>
27 #include <QUrl>
28
29 class QAction;
30 class DolphinMainWindow;
31 class KFileItemActions;
32 class KFileItemListProperties;
33 class DolphinRemoveAction;
34
35 /**
36 * @brief Represents the context menu which appears when doing a right
37 * click on an item or the viewport of the file manager.
38 *
39 * Beside static menu entries (e. g. 'Paste' or 'Properties') two
40 * dynamic sub menus are shown when opening a context menu above
41 * an item:
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
45 * given item.
46 */
47 class DolphinContextMenu : public QMenu
48 {
49 Q_OBJECT
50
51 public:
52 enum Command
53 {
54 None,
55 OpenParentFolder,
56 OpenParentFolderInNewWindow,
57 OpenParentFolderInNewTab
58 };
59
60 /**
61 * @parent Pointer to the main window the context menu
62 * belongs to.
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
68 * should be opened.
69 */
70 DolphinContextMenu(DolphinMainWindow* parent,
71 const QPoint& pos,
72 const KFileItem& fileInfo,
73 const QUrl& baseUrl);
74
75 ~DolphinContextMenu() override;
76
77 void setCustomActions(const QList<QAction*>& actions);
78
79 /**
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
85 * executed.
86 */
87 Command open();
88
89 protected:
90 void keyPressEvent(QKeyEvent *ev) override;
91 void keyReleaseEvent(QKeyEvent *ev) override;
92
93 private:
94 void openTrashContextMenu();
95 void openTrashItemContextMenu();
96 void openItemContextMenu();
97 void openViewportContextMenu();
98
99 void insertDefaultItemActions(const KFileItemListProperties&);
100
101 /**
102 * Adds the "Show menubar" action to the menu if the
103 * menubar is hidden.
104 */
105 void addShowMenuBarAction();
106
107 bool placeExists(const QUrl& url) const;
108
109 QAction* createPasteAction();
110
111 KFileItemListProperties& selectedItemsProperties() const;
112
113 /**
114 * Returns the file item for m_baseUrl.
115 */
116 KFileItem baseFileItem();
117
118 /**
119 * Adds "Open With" actions
120 */
121 void addOpenWithActions(KFileItemActions& fileItemActions);
122
123 /**
124 * Adds actions that are provided by a KVersionControlPlugin.
125 */
126 void addVersionControlPluginActions();
127
128 /**
129 * Adds custom actions e.g. like the "[x] Expandable Folders"-action
130 * provided in the details view.
131 */
132 void addCustomActions();
133
134 private:
135 struct Entry
136 {
137 int type;
138 QString name;
139 QString filePath; // empty for separator
140 QString templatePath; // same as filePath for template
141 QString icon;
142 QString comment;
143 };
144
145 enum ContextType
146 {
147 NoContext = 0,
148 ItemContext = 1,
149 TrashContext = 2,
150 TimelineContext = 4,
151 SearchContext = 8,
152 };
153
154 QPoint m_pos;
155 DolphinMainWindow* m_mainWindow;
156
157 KFileItem m_fileInfo;
158
159 QUrl m_baseUrl;
160 KFileItem* m_baseFileItem; /// File item for m_baseUrl
161
162 KFileItemList m_selectedItems;
163 mutable KFileItemListProperties* m_selectedItemsProperties;
164
165 int m_context;
166 KFileCopyToMenu m_copyToMenu;
167 QList<QAction*> m_customActions;
168
169 Command m_command;
170
171 DolphinRemoveAction* m_removeAction; // Action that represents either 'Move To Trash' or 'Delete'
172 void addDirectoryItemContextMenu(KFileItemActions &fileItemActions);
173
174 };
175
176 #endif