]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphincontextmenu.h
Merge branch 'release/22.04'
[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 #include <KFileItemActions>
13
14 #include <QMenu>
15 #include <QUrl>
16
17 class QAction;
18 class DolphinMainWindow;
19 class KFileItemActions;
20 class KFileItemListProperties;
21 class DolphinRemoveAction;
22
23 /**
24 * @brief Represents the context menu which appears when doing a right
25 * click on an item or the viewport of the file manager.
26 *
27 * Beside static menu entries (e. g. 'Paste' or 'Properties') two
28 * dynamic sub menus are shown when opening a context menu above
29 * an item:
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
33 * given item.
34 */
35 class DolphinContextMenu : public QMenu
36 {
37 Q_OBJECT
38
39 public:
40 /**
41 * @parent Pointer to the main window the context menu
42 * belongs to.
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
49 * should be opened.
50 */
51 DolphinContextMenu(DolphinMainWindow* parent,
52 const KFileItem& fileInfo,
53 const KFileItemList &selectedItems,
54 const QUrl& baseUrl,
55 KFileItemActions *fileItemActions);
56
57 ~DolphinContextMenu() override;
58
59 protected:
60 bool eventFilter(QObject* object, QEvent* event) override;
61
62 private:
63 /**
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.
67 */
68 void addAllActions();
69
70 void addTrashContextMenu();
71 void addTrashItemContextMenu();
72 void addItemContextMenu();
73 void addViewportContextMenu();
74
75 void insertDefaultItemActions(const KFileItemListProperties&);
76
77 bool placeExists(const QUrl& url) const;
78
79 QAction* createPasteAction();
80
81 KFileItemListProperties& selectedItemsProperties() const;
82
83 /**
84 * Returns the file item for m_baseUrl.
85 */
86 KFileItem baseFileItem();
87
88 /**
89 * Adds "Open With" actions
90 */
91 void addOpenWithActions();
92
93 /**
94 * Add services, custom actions, plugins and version control items to the menu
95 */
96 void addAdditionalActions(const KFileItemListProperties &props);
97
98 private:
99 struct Entry
100 {
101 int type;
102 QString name;
103 QString filePath; // empty for separator
104 QString templatePath; // same as filePath for template
105 QString icon;
106 QString comment;
107 };
108
109 enum ContextType
110 {
111 NoContext = 0,
112 ItemContext = 1,
113 TrashContext = 2,
114 TimelineContext = 4,
115 SearchContext = 8,
116 };
117
118 DolphinMainWindow* m_mainWindow;
119
120 KFileItem m_fileInfo;
121
122 QUrl m_baseUrl;
123 KFileItem* m_baseFileItem; /// File item for m_baseUrl
124
125 KFileItemList m_selectedItems;
126 mutable KFileItemListProperties* m_selectedItemsProperties;
127
128 int m_context;
129 KFileCopyToMenu m_copyToMenu;
130
131 DolphinRemoveAction* m_removeAction; // Action that represents either 'Move To Trash' or 'Delete'
132 void addDirectoryItemContextMenu();
133 KFileItemActions *m_fileItemActions;
134
135 };
136
137 #endif