1 /***************************************************************************
2 * Copyright (C) 2008 by David Faure <faure@kde.org> *
3 * Copyright (C) 2012 by Peter Penz <peter.penz19@gmail.com> *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
21 #include "dolphinviewactionhandler.h"
23 #include "dolphindebug.h"
24 #include "kitemviews/kfileitemmodel.h"
25 #include "settings/viewpropertiesdialog.h"
26 #include "views/zoomlevelinfo.h"
29 #include <Baloo/IndexerConfig>
31 #include <KActionCollection>
32 #include <KActionMenu>
33 #include <KLocalizedString>
34 #include <KNewFileMenu>
35 #include <KPropertiesDialog>
36 #include <KProtocolManager>
41 DolphinViewActionHandler::DolphinViewActionHandler(KActionCollection
* collection
, QObject
* parent
) :
43 m_actionCollection(collection
),
44 m_currentView(nullptr),
48 Q_ASSERT(m_actionCollection
);
52 void DolphinViewActionHandler::setCurrentView(DolphinView
* view
)
57 disconnect(m_currentView
, nullptr, this, nullptr);
62 connect(view
, &DolphinView::modeChanged
,
63 this, &DolphinViewActionHandler::updateViewActions
);
64 connect(view
, &DolphinView::previewsShownChanged
,
65 this, &DolphinViewActionHandler::slotPreviewsShownChanged
);
66 connect(view
, &DolphinView::sortOrderChanged
,
67 this, &DolphinViewActionHandler::slotSortOrderChanged
);
68 connect(view
, &DolphinView::sortFoldersFirstChanged
,
69 this, &DolphinViewActionHandler::slotSortFoldersFirstChanged
);
70 connect(view
, &DolphinView::visibleRolesChanged
,
71 this, &DolphinViewActionHandler::slotVisibleRolesChanged
);
72 connect(view
, &DolphinView::groupedSortingChanged
,
73 this, &DolphinViewActionHandler::slotGroupedSortingChanged
);
74 connect(view
, &DolphinView::hiddenFilesShownChanged
,
75 this, &DolphinViewActionHandler::slotHiddenFilesShownChanged
);
76 connect(view
, &DolphinView::sortRoleChanged
,
77 this, &DolphinViewActionHandler::slotSortRoleChanged
);
78 connect(view
, &DolphinView::zoomLevelChanged
,
79 this, &DolphinViewActionHandler::slotZoomLevelChanged
);
80 connect(view
, &DolphinView::writeStateChanged
,
81 this, &DolphinViewActionHandler::slotWriteStateChanged
);
84 DolphinView
* DolphinViewActionHandler::currentView()
89 void DolphinViewActionHandler::createActions()
91 // This action doesn't appear in the GUI, it's for the shortcut only.
92 // KNewFileMenu takes care of the GUI stuff.
93 QAction
* newDirAction
= m_actionCollection
->addAction(QStringLiteral("create_dir"));
94 newDirAction
->setText(i18nc("@action", "Create Folder..."));
95 m_actionCollection
->setDefaultShortcut(newDirAction
, Qt::Key_F10
);
96 newDirAction
->setIcon(QIcon::fromTheme(QStringLiteral("folder-new")));
97 newDirAction
->setEnabled(false); // Will be enabled in slotWriteStateChanged(bool) if the current URL is writable
98 connect(newDirAction
, &QAction::triggered
, this, &DolphinViewActionHandler::createDirectoryTriggered
);
102 auto renameAction
= KStandardAction::renameFile(this, &DolphinViewActionHandler::slotRename
, m_actionCollection
);
103 renameAction
->setWhatsThis(xi18nc("@info:whatsthis", "This renames the "
104 "items in your current selection.<nl/>Renaming multiple items "
105 "at once amounts to their new names differing only in a number."));
107 auto trashAction
= KStandardAction::moveToTrash(this, &DolphinViewActionHandler::slotTrashActivated
, m_actionCollection
);
108 auto trashShortcuts
= trashAction
->shortcuts();
109 if (!trashShortcuts
.contains(QKeySequence::Delete
)) {
110 trashShortcuts
.append(QKeySequence::Delete
);
111 m_actionCollection
->setDefaultShortcuts(trashAction
, trashShortcuts
);
113 trashAction
->setWhatsThis(xi18nc("@info:whatsthis", "This moves the "
114 "items in your current selection to the <filename>Trash"
115 "</filename>.<nl/>The trash is a temporary storage where "
116 "items can be deleted from if disk space is needed."));
118 auto deleteAction
= KStandardAction::deleteFile(this, &DolphinViewActionHandler::slotDeleteItems
, m_actionCollection
);
119 auto deleteShortcuts
= deleteAction
->shortcuts();
120 if (!deleteShortcuts
.contains(Qt::SHIFT
| Qt::Key_Delete
)) {
121 deleteShortcuts
.append(Qt::SHIFT
| Qt::Key_Delete
);
122 m_actionCollection
->setDefaultShortcuts(deleteAction
, deleteShortcuts
);
124 deleteAction
->setWhatsThis(xi18nc("@info:whatsthis", "This deletes "
125 "the items in your current selection completely. They can "
126 "not be recovered by normal means."));
128 // This action is useful for being enabled when KStandardAction::MoveToTrash should be
129 // disabled and KStandardAction::DeleteFile is enabled (e.g. non-local files), so that Key_Del
130 // can be used for deleting the file (#76016). It needs to be a separate action
131 // so that the Edit menu isn't affected.
132 QAction
* deleteWithTrashShortcut
= m_actionCollection
->addAction(QStringLiteral("delete_shortcut"));
133 // The descriptive text is just for the shortcuts editor.
134 deleteWithTrashShortcut
->setText(i18nc("@action \"Move to Trash\" for non-local files, etc.", "Delete (using shortcut for Trash)"));
135 m_actionCollection
->setDefaultShortcuts(deleteWithTrashShortcut
, KStandardShortcut::moveToTrash());
136 deleteWithTrashShortcut
->setEnabled(false);
137 connect(deleteWithTrashShortcut
, &QAction::triggered
, this, &DolphinViewActionHandler::slotDeleteItems
);
139 QAction
*propertiesAction
= m_actionCollection
->addAction( QStringLiteral("properties") );
140 // Well, it's the File menu in dolphinmainwindow and the Edit menu in dolphinpart... :)
141 propertiesAction
->setText( i18nc("@action:inmenu File", "Properties") );
142 propertiesAction
->setWhatsThis(xi18nc("@info:whatsthis properties",
143 "This shows a complete list of properties of the currently "
144 "selected items in a new window.<nl/>If nothing is selected the "
145 "window will be about the currently viewed folder instead.<nl/>"
146 "You can configure advanced options there like managing "
147 "read- and write-permissions."));
148 propertiesAction
->setIcon(QIcon::fromTheme(QStringLiteral("document-properties")));
149 m_actionCollection
->setDefaultShortcuts(propertiesAction
, {Qt::ALT
+ Qt::Key_Return
, Qt::ALT
+ Qt::Key_Enter
});
150 connect(propertiesAction
, &QAction::triggered
, this, &DolphinViewActionHandler::slotProperties
);
153 KToggleAction
* iconsAction
= iconsModeAction();
154 KToggleAction
* compactAction
= compactModeAction();
155 KToggleAction
* detailsAction
= detailsModeAction();
157 iconsAction
->setWhatsThis(xi18nc("@info:whatsthis Icons view mode",
158 "<para>This switches to a view mode that focuses on the folder "
159 "and file icons. This mode makes it easy to distinguish folders "
160 "from files and to detect items with distinctive <emphasis>"
161 "file types</emphasis>.</para><para> This mode is handy to "
162 "browse through pictures when the <interface>Preview"
163 "</interface> option is enabled.</para>"));
164 compactAction
->setWhatsThis(xi18nc("@info:whatsthis Compact view mode",
165 "<para>This switches to a compact view mode that lists the folders "
166 "and files in columns with the names beside the icons. <para></para>"
167 "This helps to keep the overview in folders with many items.</para>"));
168 detailsAction
->setWhatsThis(xi18nc("@info:whatsthis Details view mode",
169 "<para>This switches to a list view mode that focuses on folder "
170 "and file details.</para><para>Click on a detail in the column "
171 "header to sort the items by it. Click again to sort the other "
172 "way around. To select which details should be displayed click "
173 "the header with the right mouse button.</para><para>You can "
174 "view the contents of a folder without leaving the current "
175 "location by clicking to the left of it. This way you can view "
176 "the contents of multiple folders in the same list.</para>"));
178 KSelectAction
* viewModeActions
= m_actionCollection
->add
<KSelectAction
>(QStringLiteral("view_mode"));
179 viewModeActions
->setText(i18nc("@action:intoolbar", "View Mode"));
180 viewModeActions
->addAction(iconsAction
);
181 viewModeActions
->addAction(compactAction
);
182 viewModeActions
->addAction(detailsAction
);
183 viewModeActions
->setToolBarMode(KSelectAction::MenuMode
);
184 connect(viewModeActions
, QOverload
<QAction
*>::of(&KSelectAction::triggered
), this, &DolphinViewActionHandler::slotViewModeActionTriggered
);
186 QAction
* zoomInAction
= KStandardAction::zoomIn(this,
187 &DolphinViewActionHandler::zoomIn
,
189 zoomInAction
->setWhatsThis(i18nc("@info:whatsthis zoom in", "This increases the icon size."));
191 QAction
* zoomOutAction
= KStandardAction::zoomOut(this,
192 &DolphinViewActionHandler::zoomOut
,
194 zoomOutAction
->setWhatsThis(i18nc("@info:whatsthis zoom in", "This reduces the icon size."));
196 KToggleAction
* showPreview
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("show_preview"));
197 showPreview
->setText(i18nc("@action:intoolbar", "Preview"));
198 showPreview
->setToolTip(i18nc("@info", "Show preview of files and folders"));
199 showPreview
->setWhatsThis(xi18nc("@info:whatsthis", "When this is "
200 "enabled, the icons are based on the actual file or folder "
201 "contents.<nl/>For example the icons of images become scaled "
202 "down versions of the images."));
203 showPreview
->setIcon(QIcon::fromTheme(QStringLiteral("view-preview")));
204 connect(showPreview
, &KToggleAction::triggered
, this, &DolphinViewActionHandler::togglePreview
);
206 KToggleAction
* sortDescending
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("descending"));
207 sortDescending
->setText(i18nc("@action:inmenu Sort", "Descending"));
208 connect(sortDescending
, &KToggleAction::triggered
, this, &DolphinViewActionHandler::toggleSortOrder
);
210 KToggleAction
* sortFoldersFirst
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("folders_first"));
211 sortFoldersFirst
->setText(i18nc("@action:inmenu Sort", "Folders First"));
212 connect(sortFoldersFirst
, &KToggleAction::triggered
, this, &DolphinViewActionHandler::toggleSortFoldersFirst
);
215 QActionGroup
* sortByActionGroup
= createFileItemRolesActionGroup(QStringLiteral("sort_by_"));
217 KActionMenu
* sortByActionMenu
= m_actionCollection
->add
<KActionMenu
>(QStringLiteral("sort"));
218 sortByActionMenu
->setIcon(QIcon::fromTheme(QStringLiteral("view-sort")));
219 sortByActionMenu
->setText(i18nc("@action:inmenu View", "Sort By"));
220 sortByActionMenu
->setDelayed(false);
222 foreach (QAction
* action
, sortByActionGroup
->actions()) {
223 sortByActionMenu
->addAction(action
);
225 sortByActionMenu
->addSeparator();
226 sortByActionMenu
->addAction(sortDescending
);
227 sortByActionMenu
->addAction(sortFoldersFirst
);
229 // View -> Additional Information
230 QActionGroup
* visibleRolesGroup
= createFileItemRolesActionGroup(QStringLiteral("show_"));
232 KActionMenu
* visibleRolesMenu
= m_actionCollection
->add
<KActionMenu
>(QStringLiteral("additional_info"));
233 visibleRolesMenu
->setText(i18nc("@action:inmenu View", "Additional Information"));
234 visibleRolesMenu
->setDelayed(false);
236 foreach (QAction
* action
, visibleRolesGroup
->actions()) {
237 visibleRolesMenu
->addAction(action
);
240 KToggleAction
* showInGroups
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("show_in_groups"));
241 showInGroups
->setIcon(QIcon::fromTheme(QStringLiteral("view-group")));
242 showInGroups
->setText(i18nc("@action:inmenu View", "Show in Groups"));
243 showInGroups
->setWhatsThis(i18nc("@info:whatsthis", "This groups files and folders by their first letter."));
244 connect(showInGroups
, &KToggleAction::triggered
, this, &DolphinViewActionHandler::toggleGroupedSorting
);
246 KToggleAction
* showHiddenFiles
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("show_hidden_files"));
247 showHiddenFiles
->setText(i18nc("@action:inmenu View", "Hidden Files"));
248 showHiddenFiles
->setToolTip(i18nc("@info", "Visibility of hidden files and folders"));
249 showHiddenFiles
->setWhatsThis(xi18nc("@info:whatsthis", "<para>When "
250 "this is enabled <emphasis>hidden</emphasis> files and folders "
251 "are visible. They will be displayed semi-transparent.</para>"
252 "<para>Hidden items only differ from other ones in that their "
253 "name starts with a \".\". In general there is no need for "
254 "users to access them which is why they are hidden.</para>"));
255 m_actionCollection
->setDefaultShortcuts(showHiddenFiles
, {Qt::ALT
+ Qt::Key_Period
, Qt::CTRL
+ Qt::Key_H
, Qt::Key_F8
});
256 connect(showHiddenFiles
, &KToggleAction::triggered
, this, &DolphinViewActionHandler::toggleShowHiddenFiles
);
258 QAction
* adjustViewProps
= m_actionCollection
->addAction(QStringLiteral("view_properties"));
259 adjustViewProps
->setText(i18nc("@action:inmenu View", "Adjust View Properties..."));
260 adjustViewProps
->setWhatsThis(i18nc("@info:whatsthis", "This opens a window "
261 "in which all folder view properties can be adjusted."));
262 connect(adjustViewProps
, &QAction::triggered
, this, &DolphinViewActionHandler::slotAdjustViewProperties
);
265 QActionGroup
* DolphinViewActionHandler::createFileItemRolesActionGroup(const QString
& groupPrefix
)
267 const bool isSortGroup
= (groupPrefix
== QLatin1String("sort_by_"));
268 Q_ASSERT(isSortGroup
|| (!isSortGroup
&& groupPrefix
== QLatin1String("show_")));
270 QActionGroup
* rolesActionGroup
= new QActionGroup(m_actionCollection
);
271 rolesActionGroup
->setExclusive(isSortGroup
);
273 connect(rolesActionGroup
, &QActionGroup::triggered
,
274 this, &DolphinViewActionHandler::slotSortTriggered
);
276 connect(rolesActionGroup
, &QActionGroup::triggered
,
277 this, &DolphinViewActionHandler::toggleVisibleRole
);
281 KActionMenu
* groupMenu
= nullptr;
282 QActionGroup
* groupMenuGroup
= nullptr;
284 bool indexingEnabled
= false;
286 Baloo::IndexerConfig config
;
287 indexingEnabled
= config
.fileIndexingEnabled();
290 const QList
<KFileItemModel::RoleInfo
> rolesInfo
= KFileItemModel::rolesInformation();
291 foreach (const KFileItemModel::RoleInfo
& info
, rolesInfo
) {
292 if (!isSortGroup
&& info
.role
== "text") {
293 // It should not be possible to hide the "text" role
297 KToggleAction
* action
= nullptr;
298 const QString name
= groupPrefix
+ info
.role
;
299 if (info
.group
.isEmpty()) {
300 action
= m_actionCollection
->add
<KToggleAction
>(name
);
301 action
->setActionGroup(rolesActionGroup
);
303 if (!groupMenu
|| info
.group
!= groupName
) {
304 groupName
= info
.group
;
305 groupMenu
= m_actionCollection
->add
<KActionMenu
>(groupName
);
306 groupMenu
->setText(groupName
);
307 groupMenu
->setActionGroup(rolesActionGroup
);
309 groupMenuGroup
= new QActionGroup(groupMenu
);
310 groupMenuGroup
->setExclusive(isSortGroup
);
312 connect(groupMenuGroup
, &QActionGroup::triggered
,
313 this, &DolphinViewActionHandler::slotSortTriggered
);
315 connect(groupMenuGroup
, &QActionGroup::triggered
,
316 this, &DolphinViewActionHandler::toggleVisibleRole
);
320 action
= new KToggleAction(groupMenu
);
321 action
->setActionGroup(groupMenuGroup
);
322 groupMenu
->addAction(action
);
324 action
->setText(info
.translation
);
325 action
->setData(info
.role
);
327 const bool enable
= (!info
.requiresBaloo
&& !info
.requiresIndexer
) ||
328 (info
.requiresBaloo
) ||
329 (info
.requiresIndexer
&& indexingEnabled
);
330 action
->setEnabled(enable
);
333 m_sortByActions
.insert(info
.role
, action
);
335 m_visibleRoles
.insert(info
.role
, action
);
339 return rolesActionGroup
;
342 void DolphinViewActionHandler::slotViewModeActionTriggered(QAction
* action
)
344 const DolphinView::Mode mode
= action
->data().value
<DolphinView::Mode
>();
345 m_currentView
->setMode(mode
);
347 QAction
* viewModeMenu
= m_actionCollection
->action(QStringLiteral("view_mode"));
348 viewModeMenu
->setIcon(action
->icon());
351 void DolphinViewActionHandler::slotRename()
353 emit
actionBeingHandled();
354 m_currentView
->renameSelectedItems();
357 void DolphinViewActionHandler::slotTrashActivated()
359 emit
actionBeingHandled();
360 m_currentView
->trashSelectedItems();
363 void DolphinViewActionHandler::slotDeleteItems()
365 emit
actionBeingHandled();
366 m_currentView
->deleteSelectedItems();
369 void DolphinViewActionHandler::togglePreview(bool show
)
371 emit
actionBeingHandled();
372 m_currentView
->setPreviewsShown(show
);
375 void DolphinViewActionHandler::slotPreviewsShownChanged(bool shown
)
378 // It is not enough to update the 'Show Preview' action, also
379 // the 'Zoom In' and 'Zoom Out' actions must be adapted.
383 QString
DolphinViewActionHandler::currentViewModeActionName() const
385 switch (m_currentView
->mode()) {
386 case DolphinView::IconsView
:
387 return QStringLiteral("icons");
388 case DolphinView::DetailsView
:
389 return QStringLiteral("details");
390 case DolphinView::CompactView
:
391 return QStringLiteral("compact");
396 return QString(); // can't happen
399 KActionCollection
* DolphinViewActionHandler::actionCollection()
401 return m_actionCollection
;
404 void DolphinViewActionHandler::updateViewActions()
406 QAction
* viewModeAction
= m_actionCollection
->action(currentViewModeActionName());
407 if (viewModeAction
) {
408 viewModeAction
->setChecked(true);
410 QAction
* viewModeMenu
= m_actionCollection
->action(QStringLiteral("view_mode"));
411 viewModeMenu
->setIcon(viewModeAction
->icon());
414 QAction
* showPreviewAction
= m_actionCollection
->action(QStringLiteral("show_preview"));
415 showPreviewAction
->setChecked(m_currentView
->previewsShown());
417 slotSortOrderChanged(m_currentView
->sortOrder());
418 slotSortFoldersFirstChanged(m_currentView
->sortFoldersFirst());
419 slotVisibleRolesChanged(m_currentView
->visibleRoles(), QList
<QByteArray
>());
420 slotGroupedSortingChanged(m_currentView
->groupedSorting());
421 slotSortRoleChanged(m_currentView
->sortRole());
422 slotZoomLevelChanged(m_currentView
->zoomLevel(), -1);
424 // Updates the "show_hidden_files" action state and icon
425 slotHiddenFilesShownChanged(m_currentView
->hiddenFilesShown());
428 void DolphinViewActionHandler::zoomIn()
430 const int level
= m_currentView
->zoomLevel();
431 m_currentView
->setZoomLevel(level
+ 1);
435 void DolphinViewActionHandler::zoomOut()
437 const int level
= m_currentView
->zoomLevel();
438 m_currentView
->setZoomLevel(level
- 1);
442 void DolphinViewActionHandler::toggleSortOrder()
444 const Qt::SortOrder order
= (m_currentView
->sortOrder() == Qt::AscendingOrder
) ?
445 Qt::DescendingOrder
:
447 m_currentView
->setSortOrder(order
);
450 void DolphinViewActionHandler::toggleSortFoldersFirst()
452 const bool sortFirst
= m_currentView
->sortFoldersFirst();
453 m_currentView
->setSortFoldersFirst(!sortFirst
);
456 void DolphinViewActionHandler::slotSortOrderChanged(Qt::SortOrder order
)
458 QAction
* descending
= m_actionCollection
->action(QStringLiteral("descending"));
459 const bool sortDescending
= (order
== Qt::DescendingOrder
);
460 descending
->setChecked(sortDescending
);
463 void DolphinViewActionHandler::slotSortFoldersFirstChanged(bool foldersFirst
)
465 m_actionCollection
->action(QStringLiteral("folders_first"))->setChecked(foldersFirst
);
468 void DolphinViewActionHandler::toggleVisibleRole(QAction
* action
)
470 emit
actionBeingHandled();
472 const QByteArray toggledRole
= action
->data().toByteArray();
474 QList
<QByteArray
> roles
= m_currentView
->visibleRoles();
476 const bool show
= action
->isChecked();
478 const int index
= roles
.indexOf(toggledRole
);
479 const bool containsInfo
= (index
>= 0);
480 if (show
&& !containsInfo
) {
481 roles
.append(toggledRole
);
482 m_currentView
->setVisibleRoles(roles
);
483 } else if (!show
&& containsInfo
) {
484 roles
.removeAt(index
);
485 m_currentView
->setVisibleRoles(roles
);
486 Q_ASSERT(roles
.indexOf(toggledRole
) < 0);
490 void DolphinViewActionHandler::slotVisibleRolesChanged(const QList
<QByteArray
>& current
,
491 const QList
<QByteArray
>& previous
)
495 const QSet
<QByteArray
> checkedRoles
= current
.toSet();
496 QHashIterator
<QByteArray
, KToggleAction
*> it(m_visibleRoles
);
497 while (it
.hasNext()) {
499 const QByteArray
& role
= it
.key();
500 KToggleAction
* action
= it
.value();
501 action
->setChecked(checkedRoles
.contains(role
));
505 void DolphinViewActionHandler::toggleGroupedSorting(bool grouped
)
507 m_currentView
->setGroupedSorting(grouped
);
510 void DolphinViewActionHandler::slotGroupedSortingChanged(bool groupedSorting
)
512 QAction
* showInGroupsAction
= m_actionCollection
->action(QStringLiteral("show_in_groups"));
513 showInGroupsAction
->setChecked(groupedSorting
);
516 void DolphinViewActionHandler::toggleShowHiddenFiles(bool show
)
518 emit
actionBeingHandled();
519 m_currentView
->setHiddenFilesShown(show
);
522 void DolphinViewActionHandler::slotHiddenFilesShownChanged(bool shown
)
524 QAction
* showHiddenFilesAction
= m_actionCollection
->action(QStringLiteral("show_hidden_files"));
525 showHiddenFilesAction
->setChecked(shown
);
527 // #374508: don't overwrite custom icons.
528 const QString iconName
= showHiddenFilesAction
->icon().name();
529 if (!iconName
.isEmpty() && iconName
!= QLatin1String("visibility") && iconName
!= QLatin1String("hint")) {
533 showHiddenFilesAction
->setIcon(QIcon::fromTheme(shown
? QStringLiteral("visibility") : QStringLiteral("hint")));
536 void DolphinViewActionHandler::slotWriteStateChanged(bool isFolderWritable
)
538 m_actionCollection
->action(QStringLiteral("create_dir"))->setEnabled(isFolderWritable
&&
539 KProtocolManager::supportsMakeDir(currentView()->url()));
542 KToggleAction
* DolphinViewActionHandler::iconsModeAction()
544 KToggleAction
* iconsView
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("icons"));
545 iconsView
->setText(i18nc("@action:inmenu View Mode", "Icons"));
546 iconsView
->setToolTip(i18nc("@info", "Icons view mode"));
547 m_actionCollection
->setDefaultShortcut(iconsView
, Qt::CTRL
+ Qt::Key_1
);
548 iconsView
->setIcon(QIcon::fromTheme(QStringLiteral("view-list-icons")));
549 iconsView
->setData(QVariant::fromValue(DolphinView::IconsView
));
553 KToggleAction
* DolphinViewActionHandler::compactModeAction()
555 KToggleAction
* iconsView
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("compact"));
556 iconsView
->setText(i18nc("@action:inmenu View Mode", "Compact"));
557 iconsView
->setToolTip(i18nc("@info", "Compact view mode"));
558 m_actionCollection
->setDefaultShortcut(iconsView
, Qt::CTRL
+ Qt::Key_2
);
559 iconsView
->setIcon(QIcon::fromTheme(QStringLiteral("view-list-details"))); // TODO: discuss with Oxygen-team the wrong (?) name
560 iconsView
->setData(QVariant::fromValue(DolphinView::CompactView
));
564 KToggleAction
* DolphinViewActionHandler::detailsModeAction()
566 KToggleAction
* detailsView
= m_actionCollection
->add
<KToggleAction
>(QStringLiteral("details"));
567 detailsView
->setText(i18nc("@action:inmenu View Mode", "Details"));
568 detailsView
->setToolTip(i18nc("@info", "Details view mode"));
569 m_actionCollection
->setDefaultShortcut(detailsView
, Qt::CTRL
+ Qt::Key_3
);
570 detailsView
->setIcon(QIcon::fromTheme(QStringLiteral("view-list-tree")));
571 detailsView
->setData(QVariant::fromValue(DolphinView::DetailsView
));
575 void DolphinViewActionHandler::slotSortRoleChanged(const QByteArray
& role
)
577 KToggleAction
* action
= m_sortByActions
.value(role
);
579 action
->setChecked(true);
581 if (!action
->icon().isNull()) {
582 QAction
* sortByMenu
= m_actionCollection
->action(QStringLiteral("sort"));
583 sortByMenu
->setIcon(action
->icon());
588 void DolphinViewActionHandler::slotZoomLevelChanged(int current
, int previous
)
592 QAction
* zoomInAction
= m_actionCollection
->action(KStandardAction::name(KStandardAction::ZoomIn
));
594 zoomInAction
->setEnabled(current
< ZoomLevelInfo::maximumLevel());
597 QAction
* zoomOutAction
= m_actionCollection
->action(KStandardAction::name(KStandardAction::ZoomOut
));
599 zoomOutAction
->setEnabled(current
> ZoomLevelInfo::minimumLevel());
603 void DolphinViewActionHandler::slotSortTriggered(QAction
* action
)
605 // The radiobuttons of the "Sort By"-menu are split between the main-menu
606 // and several sub-menus. Because of this they don't have a common
607 // action-group that assures an exclusive toggle-state between the main-menu
608 // actions and the sub-menu-actions. If an action gets checked, it must
609 // be assured that all other actions get unchecked.
610 QAction
* sortByMenu
= m_actionCollection
->action(QStringLiteral("sort"));
611 foreach (QAction
* groupAction
, sortByMenu
->menu()->actions()) {
612 KActionMenu
* actionMenu
= qobject_cast
<KActionMenu
*>(groupAction
);
614 foreach (QAction
* subAction
, actionMenu
->menu()->actions()) {
615 subAction
->setChecked(false);
617 } else if (groupAction
->actionGroup()) {
618 groupAction
->setChecked(false);
621 action
->setChecked(true);
623 // Apply the activated sort-role to the view
624 const QByteArray role
= action
->data().toByteArray();
625 m_currentView
->setSortRole(role
);
628 void DolphinViewActionHandler::slotAdjustViewProperties()
630 emit
actionBeingHandled();
631 QPointer
<ViewPropertiesDialog
> dialog
= new ViewPropertiesDialog(m_currentView
);
636 void DolphinViewActionHandler::slotProperties()
638 KPropertiesDialog
* dialog
= nullptr;
639 const KFileItemList list
= m_currentView
->selectedItems();
640 if (list
.isEmpty()) {
641 const QUrl url
= m_currentView
->url();
642 dialog
= new KPropertiesDialog(url
, m_currentView
);
644 dialog
= new KPropertiesDialog(list
, m_currentView
);
647 dialog
->setAttribute(Qt::WA_DeleteOnClose
);
650 dialog
->activateWindow();