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