]> cloud.milkyroute.net Git - dolphin.git/blob - src/views/dolphinviewactionhandler.h
implement shortcut action for file creation
[dolphin.git] / src / views / dolphinviewactionhandler.h
1 /*
2 * SPDX-FileCopyrightText: 2008 David Faure <faure@kde.org>
3 * SPDX-FileCopyrightText: 2012 Peter Penz <peter.penz19@gmail.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 */
7
8 #ifndef DOLPHINVIEWACTIONHANDLER_H
9 #define DOLPHINVIEWACTIONHANDLER_H
10
11 #include "dolphin_export.h"
12 #include "selectionmode/bottombar.h"
13 #include "views/dolphinview.h"
14
15 #include <QObject>
16
17 class KToggleAction;
18 class QAction;
19 class QActionGroup;
20 class DolphinView;
21 class KActionCollection;
22 class KFileItemList;
23 namespace SelectionMode
24 {
25 class ActionTextHelper;
26 }
27
28 /**
29 * @short Handles all actions for DolphinView
30 *
31 * The action handler owns all the actions and slots related to DolphinView,
32 * but the view that it acts upon can be switched to another one
33 * (this is used in the case of split views).
34 *
35 * The purpose of this class is also to share this code between DolphinMainWindow
36 * and DolphinPart.
37 *
38 * @see DolphinView
39 * @see DolphinMainWindow
40 * @see DolphinPart
41 */
42 class DOLPHIN_EXPORT DolphinViewActionHandler : public QObject
43 {
44 Q_OBJECT
45
46 public:
47 explicit DolphinViewActionHandler(KActionCollection *collection, SelectionMode::ActionTextHelper *actionTextHelper, QObject *parent);
48
49 /**
50 * Sets the view that this action handler should work on.
51 */
52 void setCurrentView(DolphinView *view);
53
54 /**
55 * Returns the view that this action handler should work on.
56 */
57 DolphinView *currentView();
58
59 /**
60 * Returns the name of the action for the current viewmode
61 */
62 QString currentViewModeActionName() const;
63
64 /**
65 * Returns m_actionCollection
66 */
67 KActionCollection *actionCollection();
68
69 public Q_SLOTS:
70 /**
71 * Update all actions in the 'View' menu, i.e. those that depend on the
72 * settings in the current view.
73 */
74 void updateViewActions();
75
76 Q_SIGNALS:
77 /**
78 * Emitted by DolphinViewActionHandler when the user triggered an action.
79 * This is only used for clearing the statusbar in DolphinMainWindow.
80 */
81 void actionBeingHandled();
82
83 /**
84 * Emitted if the user requested creating a new directory by the F10 key.
85 * The receiver of the signal (DolphinMainWindow or DolphinPart) invokes
86 * the method createDirectory of their KNewFileMenu instance.
87 */
88 void createDirectoryTriggered();
89
90 /**
91 * Emitted if the user requested creating a new file.
92 * The receiver of the signal (DolphinMainWindow or DolphinPart) invokes
93 * the method createFile of their KNewFileMenu instance.
94 */
95 void createFileTriggered();
96
97 /** Used to request either entering or leaving of selection mode */
98 void selectionModeChangeTriggered(bool enabled, SelectionMode::BottomBar::Contents bottomBarContents = SelectionMode::BottomBar::Contents::GeneralContents);
99
100 private Q_SLOTS:
101 /**
102 * Emitted when the user requested a change of view mode
103 */
104 void slotViewModeActionTriggered(QAction *);
105
106 /**
107 * Let the user input a name for the selected item(s) and trigger
108 * a renaming afterwards.
109 */
110 void slotRename();
111
112 /**
113 * Moves the selected items of the active view to the trash.
114 * This methods adds "shift means del" handling.
115 */
116 void slotTrashActivated();
117
118 /**
119 * Deletes the selected items of the active view.
120 */
121 void slotDeleteItems();
122
123 /**
124 * Switches between showing a preview of the file content and showing the icon.
125 */
126 void togglePreview(bool);
127
128 /** Updates the state of the 'Show preview' menu action. */
129 void slotPreviewsShownChanged(bool shown);
130
131 /** Increases the size of the current set view mode. */
132 void zoomIn();
133
134 /** Decreases the size of the current set view mode. */
135 void zoomOut();
136
137 /** Resets the size of the current set view mode to default. */
138 void zoomReset();
139
140 /** Switches between a separate sorting and a mixed sorting of files and folders. */
141 void toggleSortFoldersFirst();
142
143 /**
144 * Updates the state of the 'Sort Ascending/Descending' action.
145 */
146 void slotSortOrderChanged(Qt::SortOrder order);
147
148 /**
149 * Updates the state of the 'Sort Folders First' action.
150 */
151 void slotSortFoldersFirstChanged(bool foldersFirst);
152
153 /**
154 * Switches between showing hidden files last or not.
155 */
156 void toggleSortHiddenLast();
157
158 /**
159 * Updates the state of the 'Sort Hidden Last' action.
160 */
161 void slotSortHiddenLastChanged(bool hiddenLast);
162
163 /**
164 * Updates the state of the 'Sort by' actions.
165 */
166 void slotSortRoleChanged(const QByteArray &role);
167
168 /**
169 * Updates the state of the 'Zoom In' and 'Zoom Out' actions.
170 */
171 void slotZoomLevelChanged(int current, int previous);
172
173 /**
174 * Switches on or off the displaying of additional information
175 * as specified by \a action.
176 */
177 void toggleVisibleRole(QAction *action);
178
179 /**
180 * Changes the sorting of the current view.
181 */
182 void slotSortTriggered(QAction *);
183
184 /**
185 * Updates the state of the 'Additional Information' actions.
186 */
187 void slotVisibleRolesChanged(const QList<QByteArray> &current, const QList<QByteArray> &previous);
188
189 /**
190 * Switches between sorting by groups or not.
191 */
192 void toggleGroupedSorting(bool);
193
194 /**
195 * Updates the state of the 'Categorized sorting' menu action.
196 */
197 void slotGroupedSortingChanged(bool sortCategorized);
198
199 /**
200 * Switches between showing and hiding of hidden marked files
201 */
202 void toggleShowHiddenFiles(bool);
203
204 /**
205 * Updates the state of the 'Show hidden files' menu action.
206 */
207 void slotHiddenFilesShownChanged(bool shown);
208
209 /**
210 * Updates the state of the 'Create Folder...' action.
211 */
212 void slotWriteStateChanged(bool isFolderWritable);
213
214 /**
215 * Opens the view properties dialog, which allows to modify the properties
216 * of the currently active view.
217 */
218 void slotAdjustViewProperties();
219
220 /**
221 * Begins a duplicate operation on the selected files
222 */
223 void slotDuplicate();
224
225 /**
226 * Connected to the "properties" action.
227 * Opens the properties dialog for the selected items of the
228 * active view. The properties dialog shows information
229 * like name, size and permissions.
230 */
231 void slotProperties();
232
233 /**
234 * Copies the path of the first selected KFileItem into Clipboard.
235 */
236 void slotCopyPath();
237
238 /**
239 * Changes the name of the menu that contains basic actions like "Copy", "Rename", ...
240 * The name is changed to something like "Actions for 3 Selected Items" to be extra
241 * explicit of how these basic actions are used.
242 */
243 void slotSelectionChanged(const KFileItemList &selection);
244
245 private:
246 /**
247 * Create all the actions.
248 * This is called only once (by the constructor)
249 */
250 void createActions(SelectionMode::ActionTextHelper *actionTextHelper);
251
252 /**
253 * Creates an action-group out of all roles from KFileItemModel.
254 * Dependent on the group-prefix either a radiobutton-group is
255 * created for sorting (prefix is "sort_by_") or a checkbox-group
256 * is created for additional information (prefix is "show_").
257 * The changes of actions are reported to slotSortTriggered() or
258 * toggleAdditionalInfo().
259 */
260 QActionGroup *createFileItemRolesActionGroup(const QString &groupPrefix);
261
262 /**
263 * Returns the "switch to icons mode" action.
264 * Helper method for createActions();
265 */
266 KToggleAction *iconsModeAction();
267
268 /**
269 * Returns the "switch to compact mode" action.
270 * Helper method for createActions();
271 */
272 KToggleAction *compactModeAction();
273
274 /**
275 * Returns the "switch to details mode" action.
276 * Helper method for createActions();
277 */
278 KToggleAction *detailsModeAction();
279
280 KActionCollection *m_actionCollection;
281 DolphinView *m_currentView;
282
283 QHash<QByteArray, KToggleAction *> m_sortByActions;
284 QHash<QByteArray, KToggleAction *> m_visibleRoles;
285 };
286
287 #endif /* DOLPHINVIEWACTIONHANDLER_H */