]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphincontextmenu.h
Fix icon resize animation
[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 enum Command
41 {
42 None,
43 OpenParentFolder,
44 OpenParentFolderInNewWindow,
45 OpenParentFolderInNewTab
46 };
47
48 /**
49 * @parent Pointer to the main window the context menu
50 * belongs to.
51 * @pos Position in screen coordinates.
52 * @fileInfo Pointer to the file item the context menu
53 * is applied. If 0 is passed, the context menu
54 * is above the viewport.
55 * @baseUrl Base URL of the viewport where the context menu
56 * should be opened.
57 */
58 DolphinContextMenu(DolphinMainWindow* parent,
59 const QPoint& pos,
60 const KFileItem& fileInfo,
61 const QUrl& baseUrl,
62 KFileItemActions *fileItemActions);
63
64 ~DolphinContextMenu() override;
65
66 void setCustomActions(const QList<QAction*>& actions);
67
68 /**
69 * Opens the context menu model and returns the requested
70 * command, that should be triggered by the caller. If
71 * Command::None has been returned, either the context-menu
72 * had been closed without executing an action or an
73 * already available action from the main-window has been
74 * executed.
75 */
76 Command open();
77
78 protected:
79 bool eventFilter(QObject* object, QEvent* event) override;
80
81 private:
82 void openTrashContextMenu();
83 void openTrashItemContextMenu();
84 void openItemContextMenu();
85 void openViewportContextMenu();
86
87 void insertDefaultItemActions(const KFileItemListProperties&);
88
89 /**
90 * Adds the "Show menubar" action to the menu if the
91 * menubar is hidden.
92 */
93 void addShowMenuBarAction();
94
95 bool placeExists(const QUrl& url) const;
96
97 QAction* createPasteAction();
98
99 KFileItemListProperties& selectedItemsProperties() const;
100
101 /**
102 * Returns the file item for m_baseUrl.
103 */
104 KFileItem baseFileItem();
105
106 /**
107 * Adds "Open With" actions
108 */
109 void addOpenWithActions();
110
111 /**
112 * Adds custom actions e.g. like the "[x] Expandable Folders"-action
113 * provided in the details view.
114 */
115 void addCustomActions();
116
117 private:
118 /**
119 * Add services, custom actions, plugins and version control items to the menu
120 */
121 void addAdditionalActions(const KFileItemListProperties &props);
122
123 struct Entry
124 {
125 int type;
126 QString name;
127 QString filePath; // empty for separator
128 QString templatePath; // same as filePath for template
129 QString icon;
130 QString comment;
131 };
132
133 enum ContextType
134 {
135 NoContext = 0,
136 ItemContext = 1,
137 TrashContext = 2,
138 TimelineContext = 4,
139 SearchContext = 8,
140 };
141
142 QPoint m_pos;
143 DolphinMainWindow* m_mainWindow;
144
145 KFileItem m_fileInfo;
146
147 QUrl m_baseUrl;
148 KFileItem* m_baseFileItem; /// File item for m_baseUrl
149
150 KFileItemList m_selectedItems;
151 mutable KFileItemListProperties* m_selectedItemsProperties;
152
153 int m_context;
154 KFileCopyToMenu m_copyToMenu;
155 QList<QAction*> m_customActions;
156
157 Command m_command;
158
159 DolphinRemoveAction* m_removeAction; // Action that represents either 'Move To Trash' or 'Delete'
160 void addDirectoryItemContextMenu();
161 KFileItemActions *m_fileItemActions;
162
163 };
164
165 #endif