]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphincontextmenu.h
afd8b8c4d8d77c0679266e097519e47a0b738644
[dolphin.git] / src / dolphincontextmenu.h
1 /*
2 * SPDX-FileCopyrightText: 2006 Peter Penz <peter.penz19@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7 #ifndef DOLPHINCONTEXTMENU_H
8 #define DOLPHINCONTEXTMENU_H
9
10 #include <KFileCopyToMenu>
11 #include <KFileItem>
12
13 #include <QMenu>
14 #include <QUrl>
15
16 class QAction;
17 class DolphinMainWindow;
18 class KFileItemActions;
19 class KFileItemListProperties;
20 class DolphinRemoveAction;
21
22 /**
23 * @brief Represents the context menu which appears when doing a right
24 * click on an item or the viewport of the file manager.
25 *
26 * Beside static menu entries (e. g. 'Paste' or 'Properties') two
27 * dynamic sub menus are shown when opening a context menu above
28 * an item:
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
32 * given item.
33 */
34 class DolphinContextMenu : public QMenu
35 {
36 Q_OBJECT
37
38 public:
39 enum Command
40 {
41 None,
42 OpenParentFolder,
43 OpenParentFolderInNewWindow,
44 OpenParentFolderInNewTab
45 };
46
47 /**
48 * @parent Pointer to the main window the context menu
49 * belongs to.
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
55 * should be opened.
56 */
57 DolphinContextMenu(DolphinMainWindow* parent,
58 const QPoint& pos,
59 const KFileItem& fileInfo,
60 const QUrl& baseUrl);
61
62 ~DolphinContextMenu() override;
63
64 void setCustomActions(const QList<QAction*>& actions);
65
66 /**
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
72 * executed.
73 */
74 Command open();
75
76 protected:
77 bool eventFilter(QObject* object, QEvent* event) override;
78
79 private:
80 void openTrashContextMenu();
81 void openTrashItemContextMenu();
82 void openItemContextMenu();
83 void openViewportContextMenu();
84
85 void insertDefaultItemActions(const KFileItemListProperties&);
86
87 /**
88 * Adds the "Show menubar" action to the menu if the
89 * menubar is hidden.
90 */
91 void addShowMenuBarAction();
92
93 bool placeExists(const QUrl& url) const;
94
95 QAction* createPasteAction();
96
97 KFileItemListProperties& selectedItemsProperties() const;
98
99 /**
100 * Returns the file item for m_baseUrl.
101 */
102 KFileItem baseFileItem();
103
104 /**
105 * Adds "Open With" actions
106 */
107 void addOpenWithActions(KFileItemActions& fileItemActions);
108
109 /**
110 * Adds custom actions e.g. like the "[x] Expandable Folders"-action
111 * provided in the details view.
112 */
113 void addCustomActions();
114
115 private:
116 /**
117 * Add services, custom actions, plugins and version control items to the menu
118 */
119 void addAdditionalActions(KFileItemActions &fileItemActions, const KFileItemListProperties &props);
120
121 struct Entry
122 {
123 int type;
124 QString name;
125 QString filePath; // empty for separator
126 QString templatePath; // same as filePath for template
127 QString icon;
128 QString comment;
129 };
130
131 enum ContextType
132 {
133 NoContext = 0,
134 ItemContext = 1,
135 TrashContext = 2,
136 TimelineContext = 4,
137 SearchContext = 8,
138 };
139
140 QPoint m_pos;
141 DolphinMainWindow* m_mainWindow;
142
143 KFileItem m_fileInfo;
144
145 QUrl m_baseUrl;
146 KFileItem* m_baseFileItem; /// File item for m_baseUrl
147
148 KFileItemList m_selectedItems;
149 mutable KFileItemListProperties* m_selectedItemsProperties;
150
151 int m_context;
152 KFileCopyToMenu m_copyToMenu;
153 QList<QAction*> m_customActions;
154
155 Command m_command;
156
157 DolphinRemoveAction* m_removeAction; // Action that represents either 'Move To Trash' or 'Delete'
158 void addDirectoryItemContextMenu(KFileItemActions &fileItemActions);
159
160 };
161
162 #endif