2 * SPDX-FileCopyrightText: 2006 Peter Penz <peter.penz19@gmail.com>
3 * SPDX-FileCopyrightText: 2006 Stefan Monov <logixoul@gmail.com>
4 * SPDX-FileCopyrightText: 2006 Cvetoslav Ludmiloff <ludmiloff@gmail.com>
6 * SPDX-License-Identifier: GPL-2.0-or-later
9 #include "dolphinmainwindow.h"
11 #include "admin/workerintegration.h"
12 #include "dolphin_generalsettings.h"
13 #include "dolphinbookmarkhandler.h"
14 #include "dolphincontextmenu.h"
15 #include "dolphindockwidget.h"
16 #include "dolphinmainwindowadaptor.h"
17 #include "dolphinnavigatorswidgetaction.h"
18 #include "dolphinnewfilemenu.h"
19 #include "dolphinplacesmodelsingleton.h"
20 #include "dolphinrecenttabsmenu.h"
21 #include "dolphintabpage.h"
22 #include "dolphinurlnavigatorscontroller.h"
23 #include "dolphinviewcontainer.h"
25 #include "middleclickactioneventfilter.h"
26 #include "panels/folders/folderspanel.h"
27 #include "panels/places/placespanel.h"
28 #include "panels/terminal/terminalpanel.h"
29 #include "search/dolphinquery.h"
30 #include "selectionmode/actiontexthelper.h"
31 #include "settings/dolphinsettingsdialog.h"
32 #include "statusbar/dolphinstatusbar.h"
33 #include "views/dolphinnewfilemenuobserver.h"
34 #include "views/dolphinremoteencoding.h"
35 #include "views/dolphinviewactionhandler.h"
36 #include "views/draganddrophelper.h"
37 #include "views/viewproperties.h"
39 #include <KActionCollection>
40 #include <KActionMenu>
41 #include <KAuthorized>
42 #include <KColorSchemeManager>
45 #include <KDesktopFile>
46 #include <KDialogJobUiDelegate>
47 #include <KDualAction>
48 #include <KFileItemListProperties>
49 #include <KIO/CommandLauncherJob>
50 #include <KIO/JobUiDelegateFactory>
51 #include <KIO/OpenFileManagerWindowJob>
52 #include <KIO/OpenUrlJob>
53 #include <KJobWidgets>
54 #include <KLocalizedString>
55 #include <KMessageBox>
56 #include <KProtocolInfo>
57 #include <KProtocolManager>
58 #include <KRecentFilesAction>
59 #include <KRuntimePlatform>
61 #include <KShortcutsDialog>
62 #include <KStandardAction>
64 #include <KTerminalLauncherJob>
65 #include <KToggleAction>
67 #include <KToolBarPopupAction>
68 #include <KUrlComboBox>
69 #include <KUrlNavigator>
70 #include <KWindowSystem>
71 #include <KXMLGUIFactory>
73 #include <kwidgetsaddons_version.h>
75 #include <QApplication>
77 #include <QCloseEvent>
78 #include <QDesktopServices>
80 #include <QDomDocument>
84 #include <QPushButton>
86 #include <QStandardPaths>
88 #include <QToolButton>
89 #include <QtConcurrentRun>
90 #include <dolphindebug.h>
95 #include <KStartupInfo>
100 // Used for GeneralSettings::version() to determine whether
101 // an updated version of Dolphin is running, so as to migrate
102 // removed/renamed ...etc config entries; increment it in such
104 const int CurrentDolphinVersion
= 202;
105 // The maximum number of entries in the back/forward popup menu
106 const int MaxNumberOfNavigationentries
= 12;
107 // The maximum number of "Go to Tab" shortcuts
108 const int MaxActivateTabShortcuts
= 9;
111 DolphinMainWindow::DolphinMainWindow()
112 : KXmlGuiWindow(nullptr)
113 , m_newFileMenu(nullptr)
114 , m_tabWidget(nullptr)
115 , m_activeViewContainer(nullptr)
116 , m_actionHandler(nullptr)
117 , m_remoteEncoding(nullptr)
119 , m_bookmarkHandler(nullptr)
120 , m_disabledActionNotifier(nullptr)
121 , m_lastHandleUrlOpenJob(nullptr)
122 , m_terminalPanel(nullptr)
123 , m_placesPanel(nullptr)
124 , m_tearDownFromPlacesRequested(false)
125 , m_backAction(nullptr)
126 , m_forwardAction(nullptr)
127 , m_splitViewAction(nullptr)
128 , m_splitViewMenuAction(nullptr)
129 , m_sessionSaveTimer(nullptr)
130 , m_sessionSaveWatcher(nullptr)
131 , m_sessionSaveScheduled(false)
133 Q_INIT_RESOURCE(dolphin
);
135 new MainWindowAdaptor(this);
138 setWindowFlags(Qt::WindowContextHelpButtonHint
);
140 setComponentName(QStringLiteral("dolphin"), QGuiApplication::applicationDisplayName());
141 setObjectName(QStringLiteral("Dolphin#"));
143 setStateConfigGroup("State");
145 #if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
146 new KColorSchemeManager(this); // Sets a sensible color scheme which fixes unreadable icons and text on Windows.
149 connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::errorMessage
, this, &DolphinMainWindow::showErrorMessage
);
151 KIO::FileUndoManager
*undoManager
= KIO::FileUndoManager::self();
152 undoManager
->setUiInterface(new UndoUiInterface());
154 connect(undoManager
, &KIO::FileUndoManager::undoAvailable
, this, &DolphinMainWindow::slotUndoAvailable
);
155 connect(undoManager
, &KIO::FileUndoManager::undoTextChanged
, this, &DolphinMainWindow::slotUndoTextChanged
);
156 connect(undoManager
, &KIO::FileUndoManager::jobRecordingStarted
, this, &DolphinMainWindow::clearStatusBar
);
157 connect(undoManager
, &KIO::FileUndoManager::jobRecordingFinished
, this, &DolphinMainWindow::showCommand
);
159 const bool firstRun
= (GeneralSettings::version() < 200);
161 GeneralSettings::setViewPropsTimestamp(QDateTime::currentDateTime());
164 setAcceptDrops(true);
166 auto *navigatorsWidgetAction
= new DolphinNavigatorsWidgetAction(this);
167 actionCollection()->addAction(QStringLiteral("url_navigators"), navigatorsWidgetAction
);
168 m_tabWidget
= new DolphinTabWidget(navigatorsWidgetAction
, this);
169 m_tabWidget
->setObjectName("tabWidget");
170 connect(m_tabWidget
, &DolphinTabWidget::activeViewChanged
, this, &DolphinMainWindow::activeViewChanged
);
171 connect(m_tabWidget
, &DolphinTabWidget::tabCountChanged
, this, &DolphinMainWindow::tabCountChanged
);
172 connect(m_tabWidget
, &DolphinTabWidget::currentUrlChanged
, this, &DolphinMainWindow::updateWindowTitle
);
173 setCentralWidget(m_tabWidget
);
175 m_actionTextHelper
= new SelectionMode::ActionTextHelper(this);
178 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), m_actionTextHelper
, this);
179 connect(m_actionHandler
, &DolphinViewActionHandler::actionBeingHandled
, this, &DolphinMainWindow::clearStatusBar
);
180 connect(m_actionHandler
, &DolphinViewActionHandler::createDirectoryTriggered
, this, &DolphinMainWindow::createDirectory
);
181 connect(m_actionHandler
, &DolphinViewActionHandler::createFileTriggered
, this, &DolphinMainWindow::createFile
);
182 connect(m_actionHandler
, &DolphinViewActionHandler::selectionModeChangeTriggered
, this, &DolphinMainWindow::slotSetSelectionMode
);
184 QAction
*newDirAction
= actionCollection()->action(QStringLiteral("create_dir"));
185 Q_CHECK_PTR(newDirAction
);
186 m_newFileMenu
->setNewFolderShortcutAction(newDirAction
);
188 QAction
*newFileAction
= actionCollection()->action(QStringLiteral("create_file"));
189 Q_CHECK_PTR(newFileAction
);
190 m_newFileMenu
->setNewFileShortcutAction(newFileAction
);
192 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
193 connect(this, &DolphinMainWindow::urlChanged
, m_remoteEncoding
, &DolphinRemoteEncoding::slotAboutToOpenUrl
);
195 m_disabledActionNotifier
= new DisabledActionNotifier(this);
196 connect(m_disabledActionNotifier
, &DisabledActionNotifier::disabledActionTriggered
, this, [this](const QAction
*, QString reason
) {
197 m_activeViewContainer
->showMessage(reason
, KMessageWidget::Warning
);
202 const bool usePhoneUi
{KRuntimePlatform::runtimePlatform().contains(QLatin1String("phone"))};
203 setupGUI(Save
| Create
| ToolBar
, usePhoneUi
? QStringLiteral("dolphinuiforphones.rc") : QString() /* load the default dolphinui.rc file */);
204 stateChanged(QStringLiteral("new_file"));
206 QClipboard
*clipboard
= QApplication::clipboard();
207 connect(clipboard
, &QClipboard::dataChanged
, this, &DolphinMainWindow::updatePasteAction
);
209 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
210 toggleFilterBarAction
->setChecked(GeneralSettings::filterBar());
213 menuBar()->setVisible(false);
216 Q_ASSERT(qobject_cast
<QDockWidget
*>(m_placesPanel
->parent()));
217 m_placesPanel
->parentWidget()->hide();
218 auto settings
= GeneralSettings::self();
219 settings
->setShowZoomSlider(false); // Zooming can be done with pinch gestures instead and we are short on horizontal space.
220 settings
->setRenameInline(false); // This works around inline renaming currently not working well with virtual keyboards.
221 settings
->save(); // Otherwise the RenameInline setting is not picked up for the first time Dolphin is used.
225 const bool showMenu
= !menuBar()->isHidden();
226 QAction
*showMenuBarAction
= actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar
));
227 showMenuBarAction
->setChecked(showMenu
); // workaround for bug #171080
229 auto hamburgerMenu
= static_cast<KHamburgerMenu
*>(actionCollection()->action(KStandardAction::name(KStandardAction::HamburgerMenu
)));
230 hamburgerMenu
->setMenuBar(menuBar());
231 hamburgerMenu
->setShowMenuBarAction(showMenuBarAction
);
232 connect(hamburgerMenu
, &KHamburgerMenu::aboutToShowMenu
, this, &DolphinMainWindow::updateHamburgerMenu
);
233 hamburgerMenu
->hideActionsOf(toolBar());
234 if (GeneralSettings::version() < 201 && !toolBar()->actions().contains(hamburgerMenu
)) {
235 addHamburgerMenuToToolbar();
238 updateAllowedToolbarAreas();
240 // enable middle-click on back/forward/up to open in a new tab
241 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
242 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotToolBarActionMiddleClicked
);
243 toolBar()->installEventFilter(middleClickEventFilter
);
247 connect(KSycoca::self(), &KSycoca::databaseChanged
, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
249 QTimer::singleShot(0, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
251 m_fileItemActions
.setParentWidget(this);
252 connect(&m_fileItemActions
, &KFileItemActions::error
, this, [this](const QString
&errorMessage
) {
253 showErrorMessage(errorMessage
);
256 connect(GeneralSettings::self(), &GeneralSettings::splitViewChanged
, this, &DolphinMainWindow::slotSplitViewChanged
);
259 DolphinMainWindow::~DolphinMainWindow()
261 // This fixes a crash on Wayland when closing the mainwindow while another dialog is open.
262 disconnect(QGuiApplication::clipboard(), &QClipboard::dataChanged
, this, &DolphinMainWindow::updatePasteAction
);
264 // This fixes a crash in dolphinmainwindowtest where the connection below fires even though the KMainWindow destructor of this object is already running.
265 Q_CHECK_PTR(qobject_cast
<DolphinDockWidget
*>(m_placesPanel
->parent()));
266 disconnect(static_cast<DolphinDockWidget
*>(m_placesPanel
->parent()),
267 &DolphinDockWidget::visibilityChanged
,
269 &DolphinMainWindow::slotPlacesPanelVisibilityChanged
);
272 QVector
<DolphinViewContainer
*> DolphinMainWindow::viewContainers() const
274 QVector
<DolphinViewContainer
*> viewContainers
;
276 for (int i
= 0; i
< m_tabWidget
->count(); ++i
) {
277 DolphinTabPage
*tabPage
= m_tabWidget
->tabPageAt(i
);
279 viewContainers
<< tabPage
->primaryViewContainer();
280 if (tabPage
->splitViewEnabled()) {
281 viewContainers
<< tabPage
->secondaryViewContainer();
284 return viewContainers
;
287 void DolphinMainWindow::openDirectories(const QList
<QUrl
> &dirs
, bool splitView
)
289 m_tabWidget
->openDirectories(dirs
, splitView
);
292 void DolphinMainWindow::openDirectories(const QStringList
&dirs
, bool splitView
)
294 openDirectories(QUrl::fromStringList(dirs
), splitView
);
297 void DolphinMainWindow::openFiles(const QList
<QUrl
> &files
, bool splitView
)
299 m_tabWidget
->openFiles(files
, splitView
);
302 bool DolphinMainWindow::isFoldersPanelEnabled() const
304 return actionCollection()->action(QStringLiteral("show_folders_panel"))->isChecked();
307 bool DolphinMainWindow::isInformationPanelEnabled() const
310 return actionCollection()->action(QStringLiteral("show_information_panel"))->isChecked();
316 bool DolphinMainWindow::isSplitViewEnabledInCurrentTab() const
318 return m_tabWidget
->currentTabPage()->splitViewEnabled();
321 void DolphinMainWindow::openFiles(const QStringList
&files
, bool splitView
)
323 openFiles(QUrl::fromStringList(files
), splitView
);
326 void DolphinMainWindow::activateWindow(const QString
&activationToken
)
328 window()->setAttribute(Qt::WA_NativeWindow
, true);
330 if (KWindowSystem::isPlatformWayland()) {
331 KWindowSystem::setCurrentXdgActivationToken(activationToken
);
332 } else if (KWindowSystem::isPlatformX11()) {
334 KStartupInfo::setNewStartupId(window()->windowHandle(), activationToken
.toUtf8());
338 KWindowSystem::activateWindow(window()->windowHandle());
341 bool DolphinMainWindow::isActiveWindow()
343 return window()->isActiveWindow();
346 void DolphinMainWindow::showCommand(CommandType command
)
348 DolphinStatusBar
*statusBar
= m_activeViewContainer
->statusBar();
350 case KIO::FileUndoManager::Copy
:
351 statusBar
->setText(i18nc("@info:status", "Successfully copied."));
353 case KIO::FileUndoManager::Move
:
354 statusBar
->setText(i18nc("@info:status", "Successfully moved."));
356 case KIO::FileUndoManager::Link
:
357 statusBar
->setText(i18nc("@info:status", "Successfully linked."));
359 case KIO::FileUndoManager::Trash
:
360 statusBar
->setText(i18nc("@info:status", "Successfully moved to trash."));
362 case KIO::FileUndoManager::Rename
:
363 statusBar
->setText(i18nc("@info:status", "Successfully renamed."));
366 case KIO::FileUndoManager::Mkdir
:
367 statusBar
->setText(i18nc("@info:status", "Created folder."));
375 void DolphinMainWindow::pasteIntoFolder()
377 m_activeViewContainer
->view()->pasteIntoFolder();
380 void DolphinMainWindow::changeUrl(const QUrl
&url
)
382 if (!KProtocolManager::supportsListing(url
)) {
383 // The URL navigator only checks for validity, not
384 // if the URL can be listed. An error message is
385 // shown due to DolphinViewContainer::restoreView().
389 m_activeViewContainer
->setUrl(url
);
390 updateFileAndEditActions();
395 // will signal used urls to activities manager, too
396 m_recentFiles
->addUrl(url
, QString(), "inode/directory");
398 Q_EMIT
urlChanged(url
);
401 void DolphinMainWindow::slotTerminalDirectoryChanged(const QUrl
&url
)
403 if (m_tearDownFromPlacesRequested
&& url
== QUrl::fromLocalFile(QDir::homePath())) {
404 m_placesPanel
->proceedWithTearDown();
405 m_tearDownFromPlacesRequested
= false;
408 m_activeViewContainer
->setGrabFocusOnUrlChange(false);
410 m_activeViewContainer
->setGrabFocusOnUrlChange(true);
413 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
415 KToggleAction
*editableLocationAction
= static_cast<KToggleAction
*>(actionCollection()->action(QStringLiteral("editable_location")));
416 editableLocationAction
->setChecked(editable
);
419 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
&selection
)
421 updateFileAndEditActions();
423 const int selectedUrlsCount
= m_tabWidget
->currentTabPage()->selectedItemsCount();
425 QAction
*compareFilesAction
= actionCollection()->action(QStringLiteral("compare_files"));
426 if (selectedUrlsCount
== 2) {
427 compareFilesAction
->setEnabled(isKompareInstalled());
429 compareFilesAction
->setEnabled(false);
432 Q_EMIT
selectionChanged(selection
);
435 void DolphinMainWindow::updateHistory()
437 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
438 const int index
= urlNavigator
->historyIndex();
440 QAction
*backAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Back
));
442 backAction
->setToolTip(i18nc("@info", "Go back"));
443 backAction
->setWhatsThis(i18nc("@info:whatsthis go back", "Return to the previously viewed folder."));
444 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
447 QAction
*forwardAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Forward
));
449 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
450 forwardAction
->setWhatsThis(xi18nc("@info:whatsthis go forward", "This undoes a <interface>Go|Back</interface> action."));
451 forwardAction
->setEnabled(index
> 0);
455 void DolphinMainWindow::updateFilterBarAction(bool show
)
457 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
458 toggleFilterBarAction
->setChecked(show
);
461 void DolphinMainWindow::openNewMainWindow()
463 Dolphin::openNewWindow({m_activeViewContainer
->url()}, this);
466 void DolphinMainWindow::openNewActivatedTab()
468 // keep browsers compatibility, new tab is always after last one
469 auto openNewTabAfterLastTabConfigured
= GeneralSettings::openNewTabAfterLastTab();
470 GeneralSettings::setOpenNewTabAfterLastTab(true);
471 m_tabWidget
->openNewActivatedTab();
472 GeneralSettings::setOpenNewTabAfterLastTab(openNewTabAfterLastTabConfigured
);
475 void DolphinMainWindow::addToPlaces()
480 // If nothing is selected, act on the current dir
481 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
482 url
= m_activeViewContainer
->url();
483 name
= m_activeViewContainer
->placesText();
485 const auto dirToAdd
= m_activeViewContainer
->view()->selectedItems().first();
486 url
= dirToAdd
.url();
487 name
= dirToAdd
.name();
491 if (isSearchUrl(url
)) {
492 icon
= QStringLiteral("folder-saved-search-symbolic");
494 icon
= KIO::iconNameForUrl(url
);
496 DolphinPlacesModelSingleton::instance().placesModel()->addPlace(name
, url
, icon
);
500 DolphinTabPage
*DolphinMainWindow::openNewTab(const QUrl
&url
)
502 return m_tabWidget
->openNewTab(url
, QUrl());
505 void DolphinMainWindow::openNewTabAndActivate(const QUrl
&url
)
507 m_tabWidget
->openNewActivatedTab(url
, QUrl());
510 void DolphinMainWindow::openNewWindow(const QUrl
&url
)
512 Dolphin::openNewWindow({url
}, this);
515 void DolphinMainWindow::slotSplitViewChanged()
517 m_tabWidget
->currentTabPage()->setSplitViewEnabled(GeneralSettings::splitView(), WithAnimation
);
518 updateSplitActions();
521 void DolphinMainWindow::openInNewTab()
523 const KFileItemList
&list
= m_activeViewContainer
->view()->selectedItems();
524 bool tabCreated
= false;
526 for (const KFileItem
&item
: list
) {
527 const QUrl
&url
= DolphinView::openItemAsFolderUrl(item
);
528 if (!url
.isEmpty()) {
534 // if no new tab has been created from the selection
535 // open the current directory in a new tab
537 openNewTab(m_activeViewContainer
->url());
541 void DolphinMainWindow::openInNewWindow()
545 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
546 if (list
.isEmpty()) {
547 newWindowUrl
= m_activeViewContainer
->url();
548 } else if (list
.count() == 1) {
549 const KFileItem
&item
= list
.first();
550 newWindowUrl
= DolphinView::openItemAsFolderUrl(item
);
553 if (!newWindowUrl
.isEmpty()) {
554 Dolphin::openNewWindow({newWindowUrl
}, this);
558 void DolphinMainWindow::openInSplitView(const QUrl
&url
)
560 QUrl newSplitViewUrl
= url
;
562 if (newSplitViewUrl
.isEmpty()) {
563 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
564 if (list
.count() == 1) {
565 const KFileItem
&item
= list
.first();
566 newSplitViewUrl
= DolphinView::openItemAsFolderUrl(item
);
570 if (newSplitViewUrl
.isEmpty()) {
574 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
575 if (tabPage
->splitViewEnabled()) {
576 tabPage
->switchActiveView();
577 tabPage
->activeViewContainer()->setUrl(newSplitViewUrl
);
579 tabPage
->setSplitViewEnabled(true, WithAnimation
, newSplitViewUrl
);
584 void DolphinMainWindow::showTarget()
586 const KFileItem link
= m_activeViewContainer
->view()->selectedItems().at(0);
587 const QUrl destinationUrl
= link
.url().resolved(QUrl(link
.linkDest()));
589 auto job
= KIO::stat(destinationUrl
, KIO::StatJob::SourceSide
, KIO::StatNoDetails
);
591 connect(job
, &KJob::finished
, this, [this, destinationUrl
](KJob
*job
) {
592 KIO::StatJob
*statJob
= static_cast<KIO::StatJob
*>(job
);
594 if (statJob
->error()) {
595 m_activeViewContainer
->showMessage(job
->errorString(), KMessageWidget::Error
);
597 KIO::highlightInFileManager({destinationUrl
});
602 bool DolphinMainWindow::event(QEvent
*event
)
604 if (event
->type() == QEvent::ShortcutOverride
) {
605 const QKeyEvent
*keyEvent
= static_cast<QKeyEvent
*>(event
);
606 if (keyEvent
->key() == Qt::Key_Space
&& m_activeViewContainer
->view()->handleSpaceAsNormalKey()) {
612 return KXmlGuiWindow::event(event
);
615 void DolphinMainWindow::showEvent(QShowEvent
*event
)
617 KXmlGuiWindow::showEvent(event
);
619 if (!event
->spontaneous() && m_activeViewContainer
) {
620 m_activeViewContainer
->view()->setFocus();
624 void DolphinMainWindow::closeEvent(QCloseEvent
*event
)
626 // Find out if Dolphin is closed directly by the user or
627 // by the session manager because the session is closed
628 bool closedByUser
= true;
629 if (qApp
->isSavingSession()) {
630 closedByUser
= false;
633 if (m_tabWidget
->count() > 1 && GeneralSettings::confirmClosingMultipleTabs() && !GeneralSettings::rememberOpenedTabs() && closedByUser
) {
634 // Ask the user if he really wants to quit and close all tabs.
635 // Open a confirmation dialog with 3 buttons:
636 // QDialogButtonBox::Yes -> Quit
637 // QDialogButtonBox::No -> Close only the current tab
638 // QDialogButtonBox::Cancel -> do nothing
639 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
640 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
641 dialog
->setModal(true);
642 QDialogButtonBox
*buttons
= new QDialogButtonBox(QDialogButtonBox::Yes
| QDialogButtonBox::No
| QDialogButtonBox::Cancel
);
643 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
),
644 KGuiItem(i18nc("@action:button 'Quit Dolphin' button", "&Quit %1", QGuiApplication::applicationDisplayName()),
645 QIcon::fromTheme(QStringLiteral("application-exit"))));
646 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("C&lose Current Tab"), QIcon::fromTheme(QStringLiteral("tab-close"))));
647 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
648 buttons
->button(QDialogButtonBox::Yes
)->setDefault(true);
650 bool doNotAskAgainCheckboxResult
= false;
652 const auto result
= KMessageBox::createKMessageBox(dialog
,
654 QMessageBox::Warning
,
655 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
657 i18n("Do not ask again"),
658 &doNotAskAgainCheckboxResult
,
659 KMessageBox::Notify
);
661 if (doNotAskAgainCheckboxResult
) {
662 GeneralSettings::setConfirmClosingMultipleTabs(false);
666 case QDialogButtonBox::Yes
:
669 case QDialogButtonBox::No
:
670 // Close only the current tab
671 m_tabWidget
->closeTab();
679 if (m_terminalPanel
&& m_terminalPanel
->hasProgramRunning() && GeneralSettings::confirmClosingTerminalRunningProgram() && closedByUser
) {
680 // Ask if the user really wants to quit Dolphin with a program that is still running in the Terminal panel
681 // Open a confirmation dialog with 3 buttons:
682 // QDialogButtonBox::Yes -> Quit
683 // QDialogButtonBox::No -> Show Terminal Panel
684 // QDialogButtonBox::Cancel -> do nothing
685 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
686 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
687 dialog
->setModal(true);
688 auto standardButtons
= QDialogButtonBox::Yes
| QDialogButtonBox::Cancel
;
689 if (!m_terminalPanel
->isVisible()) {
690 standardButtons
|= QDialogButtonBox::No
;
692 QDialogButtonBox
*buttons
= new QDialogButtonBox(standardButtons
);
693 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KStandardGuiItem::quit());
694 if (!m_terminalPanel
->isVisible()) {
695 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("Show &Terminal Panel"), QIcon::fromTheme(QStringLiteral("dialog-scripts"))));
697 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
699 bool doNotAskAgainCheckboxResult
= false;
701 const auto result
= KMessageBox::createKMessageBox(
704 QMessageBox::Warning
,
705 i18n("The program '%1' is still running in the Terminal panel. Are you sure you want to quit?", m_terminalPanel
->runningProgramName()),
707 i18n("Do not ask again"),
708 &doNotAskAgainCheckboxResult
,
709 KMessageBox::Notify
| KMessageBox::Dangerous
);
711 if (doNotAskAgainCheckboxResult
) {
712 GeneralSettings::setConfirmClosingTerminalRunningProgram(false);
716 case QDialogButtonBox::Yes
:
719 case QDialogButtonBox::No
:
720 actionCollection()->action("show_terminal_panel")->trigger();
721 // Do not quit, ignore quit event
729 if (m_sessionSaveTimer
&& (m_sessionSaveTimer
->isActive() || m_sessionSaveWatcher
->isRunning())) {
730 const bool sessionSaveTimerActive
= m_sessionSaveTimer
->isActive();
732 m_sessionSaveTimer
->stop();
733 m_sessionSaveWatcher
->disconnect();
734 m_sessionSaveWatcher
->waitForFinished();
736 if (sessionSaveTimerActive
|| m_sessionSaveScheduled
) {
741 GeneralSettings::setVersion(CurrentDolphinVersion
);
742 GeneralSettings::self()->save();
744 KXmlGuiWindow::closeEvent(event
);
747 void DolphinMainWindow::slotSaveSession()
749 m_sessionSaveScheduled
= false;
751 if (m_sessionSaveWatcher
->isRunning()) {
752 // The previous session is still being saved - schedule another save.
753 m_sessionSaveWatcher
->disconnect();
754 connect(m_sessionSaveWatcher
, &QFutureWatcher
<void>::finished
, this, &DolphinMainWindow::slotSaveSession
, Qt::SingleShotConnection
);
755 m_sessionSaveScheduled
= true;
756 } else if (!m_sessionSaveTimer
->isActive()) {
757 // No point in saving the session if the timer is running (since it will save the session again when it times out).
758 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
759 KConfig
*config
= KConfigGui::sessionConfig();
760 saveGlobalProperties(config
);
761 savePropertiesInternal(config
, 1);
763 auto future
= QtConcurrent::run([config
]() {
766 m_sessionSaveWatcher
->setFuture(future
);
770 void DolphinMainWindow::setSessionAutoSaveEnabled(bool enable
)
773 if (!m_sessionSaveTimer
) {
774 m_sessionSaveTimer
= new QTimer(this);
775 m_sessionSaveWatcher
= new QFutureWatcher
<void>(this);
776 m_sessionSaveTimer
->setSingleShot(true);
777 m_sessionSaveTimer
->setInterval(22000);
779 connect(m_sessionSaveTimer
, &QTimer::timeout
, this, &DolphinMainWindow::slotSaveSession
);
782 connect(m_tabWidget
, &DolphinTabWidget::urlChanged
, m_sessionSaveTimer
, qOverload
<>(&QTimer::start
), Qt::UniqueConnection
);
783 connect(m_tabWidget
, &DolphinTabWidget::tabCountChanged
, m_sessionSaveTimer
, qOverload
<>(&QTimer::start
), Qt::UniqueConnection
);
784 connect(m_tabWidget
, &DolphinTabWidget::activeViewChanged
, m_sessionSaveTimer
, qOverload
<>(&QTimer::start
), Qt::UniqueConnection
);
785 } else if (m_sessionSaveTimer
) {
786 m_sessionSaveTimer
->stop();
787 m_sessionSaveWatcher
->disconnect();
788 m_sessionSaveScheduled
= false;
790 m_sessionSaveWatcher
->waitForFinished();
792 m_sessionSaveTimer
->deleteLater();
793 m_sessionSaveWatcher
->deleteLater();
794 m_sessionSaveTimer
= nullptr;
795 m_sessionSaveWatcher
= nullptr;
799 void DolphinMainWindow::saveProperties(KConfigGroup
&group
)
801 m_tabWidget
->saveProperties(group
);
804 void DolphinMainWindow::readProperties(const KConfigGroup
&group
)
806 m_tabWidget
->readProperties(group
);
809 void DolphinMainWindow::updateNewMenu()
811 m_newFileMenu
->checkUpToDate();
812 m_newFileMenu
->setWorkingDirectory(activeViewContainer()->url());
815 void DolphinMainWindow::createDirectory()
817 // When creating directory, namejob is being run. In network folders,
818 // this job can take long time, so instead of starting multiple namejobs,
819 // just check if we are already running one. This prevents opening multiple
820 // dialogs. BUG:481401
821 if (!m_newFileMenu
->isCreateDirectoryRunning()) {
822 m_newFileMenu
->setWorkingDirectory(activeViewContainer()->url());
823 m_newFileMenu
->createDirectory();
827 void DolphinMainWindow::createFile()
829 // Use the same logic as in createDirectory()
830 if (!m_newFileMenu
->isCreateFileRunning()) {
831 m_newFileMenu
->setWorkingDirectory(activeViewContainer()->url());
832 m_newFileMenu
->createFile();
836 void DolphinMainWindow::quit()
841 void DolphinMainWindow::showErrorMessage(const QString
&message
)
843 m_activeViewContainer
->showMessage(message
, KMessageWidget::Error
);
846 void DolphinMainWindow::slotUndoAvailable(bool available
)
848 QAction
*undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
850 undoAction
->setEnabled(available
);
854 void DolphinMainWindow::slotUndoTextChanged(const QString
&text
)
856 QAction
*undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
858 undoAction
->setText(text
);
862 void DolphinMainWindow::undo()
865 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
866 KIO::FileUndoManager::self()->undo();
869 void DolphinMainWindow::cut()
871 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
872 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CutContents
);
874 m_activeViewContainer
->view()->cutSelectedItemsToClipboard();
875 m_activeViewContainer
->setSelectionModeEnabled(false);
879 void DolphinMainWindow::copy()
881 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
882 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CopyContents
);
884 m_activeViewContainer
->view()->copySelectedItemsToClipboard();
885 m_activeViewContainer
->setSelectionModeEnabled(false);
889 void DolphinMainWindow::paste()
891 m_activeViewContainer
->view()->paste();
894 void DolphinMainWindow::find()
896 m_activeViewContainer
->setSearchBarVisible(true);
897 m_activeViewContainer
->setFocusToSearchBar();
900 void DolphinMainWindow::updateSearchAction()
902 QAction
*toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
903 toggleSearchAction
->setChecked(m_activeViewContainer
->isSearchBarVisible());
906 void DolphinMainWindow::updatePasteAction()
908 QAction
*pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
909 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
910 pasteAction
->setEnabled(pasteInfo
.first
);
911 m_disabledActionNotifier
->setDisabledReason(pasteAction
,
912 m_activeViewContainer
->rootItem().isWritable()
913 ? i18nc("@info", "Cannot paste: The clipboard is empty.")
914 : i18nc("@info", "Cannot paste: You do not have permission to write into this folder."));
915 pasteAction
->setText(pasteInfo
.second
);
918 void DolphinMainWindow::slotDirectoryLoadingCompleted()
923 void DolphinMainWindow::slotToolBarActionMiddleClicked(QAction
*action
)
925 if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Back
))) {
927 } else if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Forward
))) {
929 } else if (action
== actionCollection()->action(QStringLiteral("go_up"))) {
931 } else if (action
== actionCollection()->action(QStringLiteral("go_home"))) {
936 QAction
*DolphinMainWindow::urlNavigatorHistoryAction(const KUrlNavigator
*urlNavigator
, int historyIndex
, QObject
*parent
)
938 const QUrl url
= urlNavigator
->locationUrl(historyIndex
);
942 if (isSearchUrl(url
)) {
943 text
= Search::DolphinQuery(url
, QUrl
{}).title();
944 } else if (urlNavigator
->showFullPath()) {
945 text
= url
.toDisplayString(QUrl::PreferLocalFile
);
947 const KFilePlacesModel
*placesModel
= DolphinPlacesModelSingleton::instance().placesModel();
949 const QModelIndex closestIdx
= placesModel
->closestItem(url
);
950 if (closestIdx
.isValid()) {
951 const QUrl placeUrl
= placesModel
->url(closestIdx
);
953 text
= placesModel
->text(closestIdx
);
955 QString pathInsidePlace
= url
.path().mid(placeUrl
.path().length());
957 if (!pathInsidePlace
.isEmpty() && !pathInsidePlace
.startsWith(QLatin1Char('/'))) {
958 pathInsidePlace
.prepend(QLatin1Char('/'));
961 if (pathInsidePlace
!= QLatin1Char('/')) {
962 text
.append(pathInsidePlace
);
967 QAction
*action
= new QAction(QIcon::fromTheme(KIO::iconNameForUrl(url
)), text
, parent
);
968 action
->setData(historyIndex
);
972 void DolphinMainWindow::slotAboutToShowBackPopupMenu()
974 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
976 QMenu
*menu
= m_backAction
->popupMenu();
978 for (int i
= urlNavigator
->historyIndex() + 1; i
< urlNavigator
->historySize() && entries
< MaxNumberOfNavigationentries
; ++i
, ++entries
) {
979 QAction
*action
= urlNavigatorHistoryAction(urlNavigator
, i
, menu
);
980 menu
->addAction(action
);
984 void DolphinMainWindow::slotGoBack(QAction
*action
)
986 int gotoIndex
= action
->data().value
<int>();
987 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
988 for (int i
= gotoIndex
- urlNavigator
->historyIndex(); i
> 0; --i
) {
993 void DolphinMainWindow::slotBackForwardActionMiddleClicked(QAction
*action
)
996 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
997 openNewTab(urlNavigator
->locationUrl(action
->data().value
<int>()));
1001 void DolphinMainWindow::slotAboutToShowForwardPopupMenu()
1003 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
1005 QMenu
*menu
= m_forwardAction
->popupMenu();
1007 for (int i
= urlNavigator
->historyIndex() - 1; i
>= 0 && entries
< MaxNumberOfNavigationentries
; --i
, ++entries
) {
1008 QAction
*action
= urlNavigatorHistoryAction(urlNavigator
, i
, menu
);
1009 menu
->addAction(action
);
1013 void DolphinMainWindow::slotGoForward(QAction
*action
)
1015 int gotoIndex
= action
->data().value
<int>();
1016 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
1017 for (int i
= urlNavigator
->historyIndex() - gotoIndex
; i
> 0; --i
) {
1022 void DolphinMainWindow::slotSetSelectionMode(bool enabled
, SelectionMode::BottomBar::Contents bottomBarContents
)
1024 m_activeViewContainer
->setSelectionModeEnabled(enabled
, actionCollection(), bottomBarContents
);
1027 void DolphinMainWindow::selectAll()
1031 // if the URL navigator is editable and focused, select the whole
1032 // URL instead of all items of the view
1034 KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigator();
1035 QLineEdit
*lineEdit
= urlNavigator
->editor()->lineEdit();
1036 const bool selectUrl
= urlNavigator
->isUrlEditable() && lineEdit
->hasFocus();
1038 lineEdit
->selectAll();
1040 m_activeViewContainer
->view()->selectAll();
1044 void DolphinMainWindow::invertSelection()
1047 m_activeViewContainer
->view()->invertSelection();
1050 void DolphinMainWindow::toggleSplitView()
1052 QUrl newSplitViewUrl
;
1053 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1054 if (list
.count() == 1) {
1055 const KFileItem
&item
= list
.first();
1056 newSplitViewUrl
= DolphinView::openItemAsFolderUrl(item
);
1059 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
1060 tabPage
->setSplitViewEnabled(!tabPage
->splitViewEnabled(), WithAnimation
, newSplitViewUrl
);
1061 m_tabWidget
->updateTabName(m_tabWidget
->indexOf(tabPage
));
1062 updateViewActions();
1065 void DolphinMainWindow::popoutSplitView()
1067 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
1068 if (!tabPage
->splitViewEnabled())
1070 openNewWindow((GeneralSettings::closeActiveSplitView() ? tabPage
->activeViewContainer() : tabPage
->inactiveViewContainer())->url());
1071 tabPage
->setSplitViewEnabled(false, WithAnimation
);
1072 updateSplitActions();
1075 void DolphinMainWindow::toggleSplitStash()
1077 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
1078 tabPage
->setSplitViewEnabled(false, WithAnimation
);
1079 tabPage
->setSplitViewEnabled(true, WithAnimation
, QUrl("stash:/"));
1082 void DolphinMainWindow::copyToInactiveSplitView()
1084 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
1085 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CopyToOtherViewContents
);
1087 m_tabWidget
->copyToInactiveSplitView();
1088 m_activeViewContainer
->setSelectionModeEnabled(false);
1092 void DolphinMainWindow::moveToInactiveSplitView()
1094 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
1095 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::MoveToOtherViewContents
);
1097 m_tabWidget
->moveToInactiveSplitView();
1098 m_activeViewContainer
->setSelectionModeEnabled(false);
1102 void DolphinMainWindow::reloadView()
1105 m_activeViewContainer
->reload();
1106 m_activeViewContainer
->statusBar()->updateSpaceInfo();
1109 void DolphinMainWindow::stopLoading()
1111 m_activeViewContainer
->view()->stopLoading();
1114 void DolphinMainWindow::enableStopAction()
1116 actionCollection()->action(QStringLiteral("stop"))->setEnabled(true);
1119 void DolphinMainWindow::disableStopAction()
1121 actionCollection()->action(QStringLiteral("stop"))->setEnabled(false);
1124 void DolphinMainWindow::toggleSelectionMode()
1126 const bool checked
= !m_activeViewContainer
->isSelectionModeEnabled();
1128 m_activeViewContainer
->setSelectionModeEnabled(checked
, actionCollection(), SelectionMode::BottomBar::Contents::GeneralContents
);
1129 actionCollection()->action(QStringLiteral("toggle_selection_mode"))->setChecked(checked
);
1132 void DolphinMainWindow::showFilterBar()
1134 m_activeViewContainer
->setFilterBarVisible(true);
1137 void DolphinMainWindow::toggleFilterBar()
1139 const bool checked
= !m_activeViewContainer
->isFilterBarVisible();
1140 m_activeViewContainer
->setFilterBarVisible(checked
);
1142 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
1143 toggleFilterBarAction
->setChecked(checked
);
1146 void DolphinMainWindow::toggleEditLocation()
1150 QAction
*action
= actionCollection()->action(QStringLiteral("editable_location"));
1151 KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigator();
1152 urlNavigator
->setUrlEditable(action
->isChecked());
1155 void DolphinMainWindow::replaceLocation()
1157 KUrlNavigator
*navigator
= m_activeViewContainer
->urlNavigator();
1158 QLineEdit
*lineEdit
= navigator
->editor()->lineEdit();
1160 // If the text field currently has focus and everything is selected,
1161 // pressing the keyboard shortcut returns the whole thing to breadcrumb mode
1162 // and goes back to the view, just like how it was before this action was triggered the first time.
1163 if (navigator
->isUrlEditable() && lineEdit
->hasFocus() && lineEdit
->selectedText() == lineEdit
->text()) {
1164 navigator
->setUrlEditable(false);
1165 m_activeViewContainer
->view()->setFocus();
1167 navigator
->setUrlEditable(true);
1168 navigator
->setFocus();
1169 lineEdit
->selectAll();
1173 void DolphinMainWindow::togglePanelLockState()
1175 const bool newLockState
= !GeneralSettings::lockPanels();
1176 const auto childrenObjects
= children();
1177 for (QObject
*child
: childrenObjects
) {
1178 DolphinDockWidget
*dock
= qobject_cast
<DolphinDockWidget
*>(child
);
1180 dock
->setLocked(newLockState
);
1184 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(newLockState
);
1186 GeneralSettings::setLockPanels(newLockState
);
1189 void DolphinMainWindow::slotTerminalPanelVisibilityChanged(bool visible
)
1191 if (!visible
&& m_activeViewContainer
) {
1192 m_activeViewContainer
->view()->setFocus();
1194 // Putting focus to the Terminal is not handled here but in TerminalPanel::showEvent().
1197 void DolphinMainWindow::slotPlacesPanelVisibilityChanged(bool visible
)
1199 if (!visible
&& m_activeViewContainer
) {
1200 m_activeViewContainer
->view()->setFocus();
1203 m_placesPanel
->setFocus();
1206 void DolphinMainWindow::goBack()
1208 DolphinUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
1209 urlNavigator
->goBack();
1211 if (urlNavigator
->locationState().isEmpty()) {
1212 // An empty location state indicates a redirection URL,
1213 // which must be skipped too
1214 urlNavigator
->goBack();
1218 void DolphinMainWindow::goForward()
1220 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goForward();
1223 void DolphinMainWindow::goUp()
1225 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goUp();
1228 void DolphinMainWindow::goHome()
1230 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goHome();
1233 void DolphinMainWindow::goBackInNewTab()
1235 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
1236 const int index
= urlNavigator
->historyIndex() + 1;
1237 openNewTab(urlNavigator
->locationUrl(index
));
1240 void DolphinMainWindow::goForwardInNewTab()
1242 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
1243 const int index
= urlNavigator
->historyIndex() - 1;
1244 openNewTab(urlNavigator
->locationUrl(index
));
1247 void DolphinMainWindow::goUpInNewTab()
1249 const QUrl currentUrl
= activeViewContainer()->urlNavigator()->locationUrl();
1250 openNewTab(KIO::upUrl(currentUrl
));
1253 void DolphinMainWindow::goHomeInNewTab()
1255 openNewTab(Dolphin::homeUrl());
1258 void DolphinMainWindow::compareFiles()
1260 const KFileItemList items
= m_tabWidget
->currentTabPage()->selectedItems();
1261 if (items
.count() != 2) {
1262 // The action is disabled in this case, but it could have been triggered
1263 // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
1267 QUrl urlA
= items
.at(0).url();
1268 QUrl urlB
= items
.at(1).url();
1270 QString
command(QStringLiteral("kompare -c \""));
1271 command
.append(urlA
.toDisplayString(QUrl::PreferLocalFile
));
1272 command
.append("\" \"");
1273 command
.append(urlB
.toDisplayString(QUrl::PreferLocalFile
));
1274 command
.append('\"');
1276 KIO::CommandLauncherJob
*job
= new KIO::CommandLauncherJob(command
, this);
1277 job
->setDesktopName(QStringLiteral("org.kde.kompare"));
1281 void DolphinMainWindow::toggleShowMenuBar()
1283 const bool visible
= menuBar()->isVisible();
1284 menuBar()->setVisible(!visible
);
1287 QPointer
<QAction
> DolphinMainWindow::preferredSearchTool()
1289 m_searchTools
.clear();
1291 KService::Ptr kfind
= KService::serviceByDesktopName(QStringLiteral("org.kde.kfind"));
1297 auto *action
= new QAction(QIcon::fromTheme(kfind
->icon()), kfind
->name(), this);
1299 connect(action
, &QAction::triggered
, this, [this, kfind
] {
1300 auto *job
= new KIO::ApplicationLauncherJob(kfind
);
1301 job
->setUrls({m_activeViewContainer
->url()});
1308 void DolphinMainWindow::updateOpenPreferredSearchToolAction()
1310 QAction
*openPreferredSearchTool
= actionCollection()->action(QStringLiteral("open_preferred_search_tool"));
1311 if (!openPreferredSearchTool
) {
1314 QPointer
<QAction
> tool
= preferredSearchTool();
1316 openPreferredSearchTool
->setVisible(true);
1317 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open %1", tool
->text()));
1318 // Only override with the app icon if it is the default, i.e. the user hasn't configured one manually
1319 // https://bugs.kde.org/show_bug.cgi?id=442815
1320 if (openPreferredSearchTool
->icon().name() == QLatin1String("search")) {
1321 openPreferredSearchTool
->setIcon(tool
->icon());
1324 openPreferredSearchTool
->setVisible(false);
1325 // still visible in Shortcuts configuration window
1326 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1327 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1331 void DolphinMainWindow::openPreferredSearchTool()
1333 QPointer
<QAction
> tool
= preferredSearchTool();
1339 void DolphinMainWindow::openTerminal()
1341 openTerminalJob(m_activeViewContainer
->url());
1344 void DolphinMainWindow::openTerminalHere()
1346 QList
<QUrl
> urls
= {};
1348 const auto selectedItems
= m_activeViewContainer
->view()->selectedItems();
1349 for (const KFileItem
&item
: selectedItems
) {
1350 QUrl url
= item
.targetUrl();
1351 if (item
.isFile()) {
1352 url
.setPath(QFileInfo(url
.path()).absolutePath());
1354 if (!urls
.contains(url
)) {
1359 // No items are selected. Open a terminal window for the current location.
1360 if (urls
.count() == 0) {
1365 if (urls
.count() > 5) {
1366 QString question
= i18np("Are you sure you want to open 1 terminal window?", "Are you sure you want to open %1 terminal windows?", urls
.count());
1367 const int answer
= KMessageBox::warningContinueCancel(
1371 KGuiItem(i18ncp("@action:button", "Open %1 Terminal", "Open %1 Terminals", urls
.count()), QStringLiteral("utilities-terminal")),
1372 KStandardGuiItem::cancel(),
1373 QStringLiteral("ConfirmOpenManyTerminals"));
1374 if (answer
!= KMessageBox::PrimaryAction
&& answer
!= KMessageBox::Continue
) {
1379 for (const QUrl
&url
: std::as_const(urls
)) {
1380 openTerminalJob(url
);
1384 void DolphinMainWindow::openTerminalJob(const QUrl
&url
)
1386 if (url
.isLocalFile()) {
1387 auto job
= new KTerminalLauncherJob(QString());
1388 job
->setWorkingDirectory(url
.toLocalFile());
1393 // Not a local file, with protocol Class ":local", try stat'ing
1394 if (KProtocolInfo::protocolClass(url
.scheme()) == QLatin1String(":local")) {
1395 KIO::StatJob
*job
= KIO::mostLocalUrl(url
);
1396 KJobWidgets::setWindow(job
, this);
1397 connect(job
, &KJob::result
, this, [job
]() {
1399 if (!job
->error()) {
1400 statUrl
= job
->mostLocalUrl();
1403 auto job
= new KTerminalLauncherJob(QString());
1404 job
->setWorkingDirectory(statUrl
.isLocalFile() ? statUrl
.toLocalFile() : QDir::homePath());
1411 // Nothing worked, just use $HOME
1412 auto job
= new KTerminalLauncherJob(QString());
1413 job
->setWorkingDirectory(QDir::homePath());
1417 void DolphinMainWindow::editSettings()
1419 if (!m_settingsDialog
) {
1420 DolphinViewContainer
*container
= activeViewContainer();
1421 container
->view()->writeSettings();
1423 const QUrl url
= container
->url();
1424 DolphinSettingsDialog
*settingsDialog
= new DolphinSettingsDialog(url
, this, actionCollection());
1425 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, this, &DolphinMainWindow::refreshViews
);
1426 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, &DolphinUrlNavigatorsController::slotReadSettings
);
1427 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1428 settingsDialog
->show();
1429 m_settingsDialog
= settingsDialog
;
1431 m_settingsDialog
.data()->raise();
1435 void DolphinMainWindow::handleUrl(const QUrl
&url
)
1437 delete m_lastHandleUrlOpenJob
;
1438 m_lastHandleUrlOpenJob
= nullptr;
1440 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1441 activeViewContainer()->setUrl(url
);
1443 m_lastHandleUrlOpenJob
= new KIO::OpenUrlJob(url
);
1444 m_lastHandleUrlOpenJob
->setUiDelegate(KIO::createDefaultJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
1445 m_lastHandleUrlOpenJob
->setShowOpenOrExecuteDialog(true);
1447 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::mimeTypeFound
, this, [this, url
](const QString
&mimetype
) {
1448 if (mimetype
== QLatin1String("inode/directory")) {
1449 // If it's a dir, we'll take it from here
1450 m_lastHandleUrlOpenJob
->kill();
1451 m_lastHandleUrlOpenJob
= nullptr;
1452 activeViewContainer()->setUrl(url
);
1456 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::result
, this, [this]() {
1457 m_lastHandleUrlOpenJob
= nullptr;
1460 m_lastHandleUrlOpenJob
->start();
1464 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1466 // trash:/ is writable but we don't want to create new items in it.
1467 // TODO: remove the trash check once https://phabricator.kde.org/T8234 is implemented
1468 newFileMenu()->setEnabled(isFolderWritable
&& m_activeViewContainer
->url().scheme() != QLatin1String("trash"));
1469 // When the menu is disabled, actions in it are disabled later in the event loop, and we need to set the disabled reason after that.
1470 QTimer::singleShot(0, this, [this]() {
1471 m_disabledActionNotifier
->setDisabledReason(actionCollection()->action(QStringLiteral("create_file")),
1472 i18nc("@info", "Cannot create new file: You do not have permission to create items in this folder."));
1473 m_disabledActionNotifier
->setDisabledReason(actionCollection()->action(QStringLiteral("create_dir")),
1474 i18nc("@info", "Cannot create new folder: You do not have permission to create items in this folder."));
1478 void DolphinMainWindow::openContextMenu(const QPoint
&pos
, const KFileItem
&item
, const KFileItemList
&selectedItems
, const QUrl
&url
)
1480 QPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, item
, selectedItems
, url
, &m_fileItemActions
);
1481 contextMenu
->exec(pos
);
1483 // Delete the menu, unless it has been deleted in its own nested event loop already.
1485 contextMenu
->deleteLater();
1489 QMenu
*DolphinMainWindow::createPopupMenu()
1491 QMenu
*menu
= KXmlGuiWindow::createPopupMenu();
1493 menu
->addSeparator();
1494 menu
->addAction(actionCollection()->action(QStringLiteral("lock_panels")));
1499 void DolphinMainWindow::updateHamburgerMenu()
1501 KActionCollection
*ac
= actionCollection();
1502 auto hamburgerMenu
= static_cast<KHamburgerMenu
*>(ac
->action(KStandardAction::name(KStandardAction::HamburgerMenu
)));
1503 auto menu
= hamburgerMenu
->menu();
1505 menu
= new QMenu(this);
1506 hamburgerMenu
->setMenu(menu
);
1507 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("basic_actions"))->menu());
1508 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("zoom"))->menu());
1512 const QList
<QAction
*> toolbarActions
= toolBar()->actions();
1514 if (!toolBar()->isVisible()) {
1515 // If neither the menu bar nor the toolbar are visible, these actions should be available.
1516 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)));
1517 menu
->addAction(toolBarMenuAction());
1518 menu
->addSeparator();
1521 // This group of actions (until the next separator) contains all the most basic actions
1522 // necessary to use Dolphin effectively.
1523 menu
->addAction(ac
->action(QStringLiteral("go_back")));
1524 menu
->addAction(ac
->action(QStringLiteral("go_forward")));
1526 menu
->addMenu(m_newFileMenu
->menu());
1527 if (!toolBar()->isVisible() || !toolbarActions
.contains(ac
->action(QStringLiteral("toggle_selection_mode_tool_bar")))) {
1528 menu
->addAction(ac
->action(QStringLiteral("toggle_selection_mode")));
1530 menu
->addAction(ac
->action(QStringLiteral("basic_actions")));
1531 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Undo
)));
1532 if (!toolBar()->isVisible()
1533 || (!toolbarActions
.contains(ac
->action(QStringLiteral("toggle_search")))
1534 && !toolbarActions
.contains(ac
->action(QStringLiteral("open_preferred_search_tool"))))) {
1535 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Find
)));
1536 // This way a search action will only be added if none of the three available
1537 // search actions is present on the toolbar.
1539 if (!toolBar()->isVisible() || !toolbarActions
.contains(ac
->action(QStringLiteral("toggle_filter")))) {
1540 menu
->addAction(ac
->action(QStringLiteral("show_filter_bar")));
1541 // This way a filter action will only be added if none of the two available
1542 // filter actions is present on the toolbar.
1544 menu
->addSeparator();
1546 // The second group of actions (up until the next separator) contains actions for opening
1547 // additional views to interact with the file system.
1548 menu
->addAction(ac
->action(QStringLiteral("file_new")));
1549 menu
->addAction(ac
->action(QStringLiteral("new_tab")));
1550 if (ac
->action(QStringLiteral("undo_close_tab"))->isEnabled()) {
1551 menu
->addAction(ac
->action(QStringLiteral("closed_tabs")));
1553 menu
->addAction(ac
->action(QStringLiteral("open_terminal")));
1554 menu
->addSeparator();
1556 // The third group contains actions to change what one sees in the view
1557 // and to change the more general UI.
1558 if (!toolBar()->isVisible()
1559 || (!toolbarActions
.contains(ac
->action(QStringLiteral("icons"))) && !toolbarActions
.contains(ac
->action(QStringLiteral("compact")))
1560 && !toolbarActions
.contains(ac
->action(QStringLiteral("details"))) && !toolbarActions
.contains(ac
->action(QStringLiteral("view_mode"))))) {
1561 menu
->addAction(ac
->action(QStringLiteral("view_mode")));
1563 menu
->addAction(ac
->action(QStringLiteral("show_hidden_files")));
1564 menu
->addAction(ac
->action(QStringLiteral("sort")));
1565 menu
->addAction(ac
->action(QStringLiteral("additional_info")));
1566 if (!GeneralSettings::showStatusBar() || !GeneralSettings::showZoomSlider()) {
1567 menu
->addAction(ac
->action(QStringLiteral("zoom")));
1569 menu
->addAction(ac
->action(QStringLiteral("panels")));
1571 // The "Configure" menu is not added to the actionCollection() because there is hardly
1572 // a good reason for users to put it on their toolbar.
1573 auto configureMenu
= menu
->addMenu(QIcon::fromTheme(QStringLiteral("configure")), i18nc("@action:inmenu menu for configure actions", "Configure"));
1574 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
)));
1575 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)));
1576 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)));
1577 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Preferences
)));
1578 hamburgerMenu
->hideActionsOf(configureMenu
);
1581 void DolphinMainWindow::slotPlaceActivated(const QUrl
&url
)
1583 DolphinViewContainer
*view
= activeViewContainer();
1585 if (view
->url() == url
) {
1586 view
->clearFilterBar(); // Fixes bug 259382.
1588 // We can end up here if the user clicked a device in the Places Panel
1589 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
1592 m_activeViewContainer
->view()->setFocus(); // We always want the focus on the view after activating a place.
1594 view
->disableUrlNavigatorSelectionRequests();
1596 view
->enableUrlNavigatorSelectionRequests();
1600 void DolphinMainWindow::closedTabsCountChanged(unsigned int count
)
1602 actionCollection()->action(QStringLiteral("undo_close_tab"))->setEnabled(count
> 0);
1605 void DolphinMainWindow::activeViewChanged(DolphinViewContainer
*viewContainer
)
1607 DolphinViewContainer
*oldViewContainer
= m_activeViewContainer
;
1608 Q_ASSERT(viewContainer
);
1610 m_activeViewContainer
= viewContainer
;
1612 if (oldViewContainer
) {
1613 // Disconnect all signals between the old view container (container,
1614 // view and url navigator) and main window.
1615 oldViewContainer
->disconnect(this);
1616 oldViewContainer
->view()->disconnect(this);
1617 oldViewContainer
->urlNavigatorInternalWithHistory()->disconnect(this);
1618 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
1619 navigators
->primaryUrlNavigator()->disconnect(this);
1620 if (auto secondaryUrlNavigator
= navigators
->secondaryUrlNavigator()) {
1621 secondaryUrlNavigator
->disconnect(this);
1624 // except the requestItemInfo so that on hover the information panel can still be updated
1625 connect(oldViewContainer
->view(), &DolphinView::requestItemInfo
, this, &DolphinMainWindow::requestItemInfo
);
1627 // Disconnect other slots.
1628 disconnect(oldViewContainer
,
1629 &DolphinViewContainer::selectionModeChanged
,
1630 actionCollection()->action(QStringLiteral("toggle_selection_mode")),
1631 &QAction::setChecked
);
1634 connectViewSignals(viewContainer
);
1636 m_actionHandler
->setCurrentView(viewContainer
->view());
1639 updateFileAndEditActions();
1640 updatePasteAction();
1641 updateViewActions();
1643 updateSearchAction();
1645 const QUrl url
= viewContainer
->url();
1646 Q_EMIT
urlChanged(url
);
1649 void DolphinMainWindow::tabCountChanged(int count
)
1651 const bool enableTabActions
= (count
> 1);
1652 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1653 actionCollection()->action(QStringLiteral("activate_tab_%1").arg(i
))->setEnabled(enableTabActions
);
1655 actionCollection()->action(QStringLiteral("activate_last_tab"))->setEnabled(enableTabActions
);
1656 actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions
);
1657 actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions
);
1660 void DolphinMainWindow::updateWindowTitle()
1662 const QString newTitle
= m_activeViewContainer
->captionWindowTitle();
1663 if (windowTitle() != newTitle
) {
1664 setWindowTitle(newTitle
);
1668 void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString
&mountPath
)
1670 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1671 setViewsToHomeIfMountPathOpen(mountPath
);
1674 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectoryIsChildOf(mountPath
)) {
1675 m_tearDownFromPlacesRequested
= true;
1676 m_terminalPanel
->goHome();
1677 // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged
1679 m_placesPanel
->proceedWithTearDown();
1683 void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString
&mountPath
)
1685 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1686 setViewsToHomeIfMountPathOpen(mountPath
);
1689 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectoryIsChildOf(mountPath
)) {
1690 m_tearDownFromPlacesRequested
= false;
1691 m_terminalPanel
->goHome();
1695 void DolphinMainWindow::slotKeyBindings()
1697 KShortcutsDialog
dialog(KShortcutsEditor::AllActions
, KShortcutsEditor::LetterShortcutsAllowed
, this);
1698 dialog
.addCollection(actionCollection());
1699 if (m_terminalPanel
) {
1700 KActionCollection
*konsolePartActionCollection
= m_terminalPanel
->actionCollection();
1701 if (konsolePartActionCollection
) {
1702 dialog
.addCollection(konsolePartActionCollection
, QStringLiteral("KonsolePart"));
1708 void DolphinMainWindow::setViewsToHomeIfMountPathOpen(const QString
&mountPath
)
1710 const QVector
<DolphinViewContainer
*> theViewContainers
= viewContainers();
1711 for (DolphinViewContainer
*viewContainer
: theViewContainers
) {
1712 if (viewContainer
&& viewContainer
->url().toLocalFile().startsWith(mountPath
)) {
1713 viewContainer
->setUrl(QUrl::fromLocalFile(QDir::homePath()));
1716 disconnect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, nullptr, nullptr);
1719 void DolphinMainWindow::setupActions()
1721 auto hamburgerMenuAction
= KStandardAction::hamburgerMenu(nullptr, nullptr, actionCollection());
1723 // setup 'File' menu
1724 m_newFileMenu
= new DolphinNewFileMenu(nullptr, nullptr, this);
1725 actionCollection()->addAction(QStringLiteral("new_menu"), m_newFileMenu
);
1726 QMenu
*menu
= m_newFileMenu
->menu();
1727 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1728 menu
->setIcon(QIcon::fromTheme(QStringLiteral("list-add")));
1729 m_newFileMenu
->setPopupMode(QToolButton::InstantPopup
);
1730 connect(menu
, &QMenu::aboutToShow
, this, &DolphinMainWindow::updateNewMenu
);
1732 QAction
*newWindow
= KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow
, actionCollection());
1733 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1734 newWindow
->setToolTip(i18nc("@info", "Open a new Dolphin window"));
1735 newWindow
->setWhatsThis(xi18nc("@info:whatsthis",
1737 "window just like this one with the current location."
1738 "<nl/>You can drag and drop items between windows."));
1739 newWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1741 QAction
*newTab
= actionCollection()->addAction(QStringLiteral("new_tab"));
1742 newTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1743 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1744 newTab
->setWhatsThis(xi18nc("@info:whatsthis",
1746 "<emphasis>Tab</emphasis> with the current location."
1747 "<nl/>Tabs allow you to quickly switch between multiple locations and views within this window. "
1748 "You can drag and drop items between tabs."));
1749 actionCollection()->setDefaultShortcut(newTab
, Qt::CTRL
| Qt::Key_T
);
1750 connect(newTab
, &QAction::triggered
, this, &DolphinMainWindow::openNewActivatedTab
);
1752 QAction
*addToPlaces
= actionCollection()->addAction(QStringLiteral("add_to_places"));
1753 addToPlaces
->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new")));
1754 addToPlaces
->setText(i18nc("@action:inmenu Add current folder to places", "Add to Places"));
1755 addToPlaces
->setWhatsThis(xi18nc("@info:whatsthis",
1756 "This adds the selected folder "
1757 "to the Places panel."));
1758 connect(addToPlaces
, &QAction::triggered
, this, &DolphinMainWindow::addToPlaces
);
1760 QAction
*closeTab
= KStandardAction::close(m_tabWidget
, QOverload
<>::of(&DolphinTabWidget::closeTab
), actionCollection());
1761 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1762 closeTab
->setToolTip(i18nc("@info", "Close Tab"));
1763 closeTab
->setWhatsThis(i18nc("@info:whatsthis",
1765 "currently viewed tab. If no more tabs are left, this closes "
1766 "the whole window instead."));
1768 QAction
*quitAction
= KStandardAction::quit(this, &DolphinMainWindow::quit
, actionCollection());
1769 quitAction
->setWhatsThis(i18nc("@info:whatsthis quit", "This closes this window."));
1771 // setup 'Edit' menu
1772 KStandardAction::undo(this, &DolphinMainWindow::undo
, actionCollection());
1774 // i18n: This will be the last paragraph for the whatsthis for all three:
1775 // Cut, Copy and Paste
1776 const QString cutCopyPastePara
= xi18nc("@info:whatsthis",
1777 "<para><emphasis>Cut, "
1778 "Copy</emphasis> and <emphasis>Paste</emphasis> work between many "
1779 "applications and are among the most used commands. That's why their "
1780 "<emphasis>keyboard shortcuts</emphasis> are prominently placed right "
1781 "next to each other on the keyboard: <shortcut>Ctrl+X</shortcut>, "
1782 "<shortcut>Ctrl+C</shortcut> and <shortcut>Ctrl+V</shortcut>.</para>");
1783 QAction
*cutAction
= KStandardAction::cut(this, &DolphinMainWindow::cut
, actionCollection());
1784 m_actionTextHelper
->registerTextWhenNothingIsSelected(cutAction
, i18nc("@action", "Cut…"));
1785 cutAction
->setWhatsThis(xi18nc("@info:whatsthis cut",
1786 "This copies the items "
1787 "in your current selection to the <emphasis>clipboard</emphasis>.<nl/>"
1788 "Use the <emphasis>Paste</emphasis> action afterwards to copy them from "
1789 "the clipboard to a new location. The items will be removed from their "
1790 "initial location.")
1791 + cutCopyPastePara
);
1792 QAction
*copyAction
= KStandardAction::copy(this, &DolphinMainWindow::copy
, actionCollection());
1793 m_actionTextHelper
->registerTextWhenNothingIsSelected(copyAction
, i18nc("@action", "Copy…"));
1794 copyAction
->setWhatsThis(xi18nc("@info:whatsthis copy",
1796 "items in your current selection to the <emphasis>clipboard</emphasis>."
1797 "<nl/>Use the <emphasis>Paste</emphasis> action afterwards to copy them "
1798 "from the clipboard to a new location.")
1799 + cutCopyPastePara
);
1800 QAction
*paste
= KStandardAction::paste(this, &DolphinMainWindow::paste
, actionCollection());
1801 // The text of the paste-action is modified dynamically by Dolphin
1802 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1803 // due to the long text, the text "Paste" is used:
1804 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1805 paste
->setWhatsThis(xi18nc("@info:whatsthis paste",
1806 "This copies the items from "
1807 "your <emphasis>clipboard</emphasis> to the currently viewed folder.<nl/>"
1808 "If the items were added to the clipboard by the <emphasis>Cut</emphasis> "
1809 "action they are removed from their old location.")
1810 + cutCopyPastePara
);
1812 QAction
*copyToOtherViewAction
= actionCollection()->addAction(QStringLiteral("copy_to_inactive_split_view"));
1813 copyToOtherViewAction
->setText(i18nc("@action:inmenu", "Copy to Other View"));
1814 m_actionTextHelper
->registerTextWhenNothingIsSelected(copyToOtherViewAction
, i18nc("@action:inmenu", "Copy to Other View…"));
1815 copyToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Copy",
1816 "This copies the selected items from "
1817 "the view in focus to the other view. "
1818 "(Only available while in Split View mode.)"));
1819 copyToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
1820 copyToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Copy to Other View"));
1821 actionCollection()->setDefaultShortcut(copyToOtherViewAction
, Qt::SHIFT
| Qt::Key_F5
);
1822 connect(copyToOtherViewAction
, &QAction::triggered
, this, &DolphinMainWindow::copyToInactiveSplitView
);
1824 QAction
*moveToOtherViewAction
= actionCollection()->addAction(QStringLiteral("move_to_inactive_split_view"));
1825 moveToOtherViewAction
->setText(i18nc("@action:inmenu", "Move to Other View"));
1826 m_actionTextHelper
->registerTextWhenNothingIsSelected(moveToOtherViewAction
, i18nc("@action:inmenu", "Move to Other View…"));
1827 moveToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Move",
1828 "This moves the selected items from "
1829 "the view in focus to the other view. "
1830 "(Only available while in Split View mode.)"));
1831 moveToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-cut")));
1832 moveToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Move to Other View"));
1833 actionCollection()->setDefaultShortcut(moveToOtherViewAction
, Qt::SHIFT
| Qt::Key_F6
);
1834 connect(moveToOtherViewAction
, &QAction::triggered
, this, &DolphinMainWindow::moveToInactiveSplitView
);
1836 QAction
*showFilterBar
= actionCollection()->addAction(QStringLiteral("show_filter_bar"));
1837 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Filter…"));
1838 showFilterBar
->setToolTip(i18nc("@info:tooltip", "Show Filter Bar"));
1839 showFilterBar
->setWhatsThis(xi18nc("@info:whatsthis",
1841 "<emphasis>Filter Bar</emphasis> at the bottom of the window.<nl/> "
1842 "There you can enter text to filter the files and folders currently displayed. "
1843 "Only those that contain the text in their name will be kept in view."));
1844 showFilterBar
->setIcon(QIcon::fromTheme(QStringLiteral("view-filter")));
1845 actionCollection()->setDefaultShortcuts(showFilterBar
, {Qt::CTRL
| Qt::Key_I
, Qt::Key_Slash
});
1846 connect(showFilterBar
, &QAction::triggered
, this, &DolphinMainWindow::showFilterBar
);
1848 // toggle_filter acts as a copy of the main showFilterBar to be used mainly
1849 // in the toolbar, with no default shortcut attached, to avoid messing with
1850 // existing workflows (filter bar always open and Ctrl-I to focus)
1851 QAction
*toggleFilter
= actionCollection()->addAction(QStringLiteral("toggle_filter"));
1852 toggleFilter
->setText(i18nc("@action:inmenu", "Toggle Filter Bar"));
1853 toggleFilter
->setIconText(i18nc("@action:intoolbar", "Filter"));
1854 toggleFilter
->setIcon(showFilterBar
->icon());
1855 toggleFilter
->setToolTip(showFilterBar
->toolTip());
1856 toggleFilter
->setWhatsThis(showFilterBar
->whatsThis());
1857 toggleFilter
->setCheckable(true);
1858 connect(toggleFilter
, &QAction::triggered
, this, &DolphinMainWindow::toggleFilterBar
);
1860 QAction
*searchAction
= KStandardAction::find(this, &DolphinMainWindow::find
, actionCollection());
1861 searchAction
->setText(i18n("Search…"));
1862 searchAction
->setToolTip(i18nc("@info:tooltip", "Search for files and folders"));
1863 searchAction
->setWhatsThis(xi18nc("@info:whatsthis find",
1864 "<para>This helps you "
1865 "find files and folders by opening a <emphasis>search bar</emphasis>. "
1866 "There you can enter search terms and specify settings to find the "
1867 "items you are looking for.</para>"));
1869 // toggle_search acts as a copy of the main searchAction to be used mainly
1870 // in the toolbar, with no default shortcut attached, to avoid messing with
1871 // existing workflows (search bar always open and Ctrl-F to focus)
1872 QAction
*toggleSearchAction
= actionCollection()->addAction(QStringLiteral("toggle_search"));
1873 toggleSearchAction
->setText(i18nc("@action:inmenu", "Toggle Search Bar"));
1874 toggleSearchAction
->setIconText(i18nc("@action:intoolbar", "Search"));
1875 toggleSearchAction
->setIcon(searchAction
->icon());
1876 toggleSearchAction
->setToolTip(searchAction
->toolTip());
1877 toggleSearchAction
->setWhatsThis(searchAction
->whatsThis());
1878 toggleSearchAction
->setCheckable(true);
1879 connect(toggleSearchAction
, &QAction::triggered
, this, [this](bool checked
) {
1883 m_activeViewContainer
->setSearchBarVisible(false);
1887 QAction
*toggleSelectionModeAction
= actionCollection()->addAction(QStringLiteral("toggle_selection_mode"));
1888 // i18n: This action toggles a selection mode.
1889 toggleSelectionModeAction
->setText(i18nc("@action:inmenu", "Select Files and Folders"));
1890 // i18n: Opens a selection mode for selecting files/folders.
1891 // The text is kept so unspecific because it will be shown on the toolbar where space is at a premium.
1892 toggleSelectionModeAction
->setIconText(i18nc("@action:intoolbar", "Select"));
1893 toggleSelectionModeAction
->setWhatsThis(xi18nc(
1895 "<para>This application only knows which files or folders should be acted on if they are"
1896 " <emphasis>selected</emphasis> first. Press this to toggle a <emphasis>Selection Mode</emphasis> which makes selecting and deselecting as easy as "
1897 "pressing an item once.</para><para>While in this mode, a quick access bar at the bottom shows available actions for the currently selected items."
1899 toggleSelectionModeAction
->setIcon(QIcon::fromTheme(QStringLiteral("quickwizard")));
1900 toggleSelectionModeAction
->setCheckable(true);
1901 actionCollection()->setDefaultShortcut(toggleSelectionModeAction
, Qt::Key_Space
);
1902 connect(toggleSelectionModeAction
, &QAction::triggered
, this, &DolphinMainWindow::toggleSelectionMode
);
1904 // A special version of the toggleSelectionModeAction for the toolbar that also contains a menu
1905 // with the selectAllAction and invertSelectionAction.
1906 auto *toggleSelectionModeToolBarAction
=
1907 new KToolBarPopupAction(toggleSelectionModeAction
->icon(), toggleSelectionModeAction
->iconText(), actionCollection());
1908 toggleSelectionModeToolBarAction
->setToolTip(toggleSelectionModeAction
->text());
1909 toggleSelectionModeToolBarAction
->setWhatsThis(toggleSelectionModeAction
->whatsThis());
1910 actionCollection()->addAction(QStringLiteral("toggle_selection_mode_tool_bar"), toggleSelectionModeToolBarAction
);
1911 toggleSelectionModeToolBarAction
->setCheckable(true);
1912 toggleSelectionModeToolBarAction
->setPopupMode(KToolBarPopupAction::DelayedPopup
);
1913 connect(toggleSelectionModeToolBarAction
, &QAction::triggered
, toggleSelectionModeAction
, &QAction::trigger
);
1914 connect(toggleSelectionModeAction
, &QAction::toggled
, toggleSelectionModeToolBarAction
, &QAction::setChecked
);
1916 QAction
*selectAllAction
= KStandardAction::selectAll(this, &DolphinMainWindow::selectAll
, actionCollection());
1917 selectAllAction
->setWhatsThis(xi18nc("@info:whatsthis",
1919 "files and folders in the current location."));
1921 QAction
*invertSelection
= actionCollection()->addAction(QStringLiteral("invert_selection"));
1922 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1923 invertSelection
->setWhatsThis(xi18nc("@info:whatsthis invert",
1925 "items that you have currently <emphasis>not</emphasis> selected instead."));
1926 invertSelection
->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-invert")));
1927 actionCollection()->setDefaultShortcut(invertSelection
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1928 connect(invertSelection
, &QAction::triggered
, this, &DolphinMainWindow::invertSelection
);
1930 QMenu
*toggleSelectionModeActionMenu
= new QMenu(this);
1931 toggleSelectionModeActionMenu
->addAction(selectAllAction
);
1932 toggleSelectionModeActionMenu
->addAction(invertSelection
);
1933 toggleSelectionModeToolBarAction
->setMenu(toggleSelectionModeActionMenu
);
1935 // setup 'View' menu
1936 // (note that most of it is set up in DolphinViewActionHandler)
1938 Admin::WorkerIntegration::createActAsAdminAction(actionCollection(), this);
1940 m_splitViewAction
= actionCollection()->add
<KActionMenu
>(QStringLiteral("split_view"));
1941 m_splitViewMenuAction
= actionCollection()->addAction(QStringLiteral("split_view_menu"));
1943 m_splitViewAction
->setWhatsThis(xi18nc("@info:whatsthis split",
1944 "<para>This presents "
1945 "a second view side-by-side with the current view, so you can see "
1946 "the contents of two folders at once and easily move items between "
1947 "them.</para><para>The view that is not \"in focus\" will be dimmed. "
1948 "</para>Click this button again to close one of the views."));
1949 m_splitViewMenuAction
->setWhatsThis(m_splitViewAction
->whatsThis());
1951 // only set it for the menu version
1952 actionCollection()->setDefaultShortcut(m_splitViewMenuAction
, Qt::Key_F3
);
1954 connect(m_splitViewAction
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitView
);
1955 connect(m_splitViewMenuAction
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitView
);
1957 QAction
*popoutSplit
= actionCollection()->addAction(QStringLiteral("popout_split_view"));
1958 popoutSplit
->setWhatsThis(xi18nc("@info:whatsthis",
1959 "If the view has been split, this will pop the view in focus "
1960 "out into a new window."));
1961 popoutSplit
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1962 actionCollection()->setDefaultShortcut(popoutSplit
, Qt::SHIFT
| Qt::Key_F3
);
1963 connect(popoutSplit
, &QAction::triggered
, this, &DolphinMainWindow::popoutSplitView
);
1965 QAction
*stashSplit
= actionCollection()->addAction(QStringLiteral("split_stash"));
1966 actionCollection()->setDefaultShortcut(stashSplit
, Qt::CTRL
| Qt::Key_S
);
1967 stashSplit
->setText(i18nc("@action:intoolbar Stash", "Stash"));
1968 stashSplit
->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
1969 stashSplit
->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
1970 stashSplit
->setCheckable(false);
1971 QDBusConnectionInterface
*sessionInterface
= QDBusConnection::sessionBus().interface();
1972 stashSplit
->setVisible(sessionInterface
&& sessionInterface
->isServiceRegistered(QStringLiteral("org.kde.kio.StashNotifier")));
1973 connect(stashSplit
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitStash
);
1975 QAction
*redisplay
= KStandardAction::redisplay(this, &DolphinMainWindow::reloadView
, actionCollection());
1976 redisplay
->setToolTip(i18nc("@info:tooltip", "Refresh view"));
1977 redisplay
->setWhatsThis(xi18nc("@info:whatsthis refresh",
1978 "<para>This refreshes "
1979 "the folder view.</para>"
1980 "<para>If the contents of this folder have changed, refreshing will re-scan this folder "
1981 "and show you a newly-updated view of the files and folders contained here.</para>"
1982 "<para>If the view is split, this refreshes the one that is currently in focus.</para>"));
1984 QAction
*stop
= actionCollection()->addAction(QStringLiteral("stop"));
1985 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1986 stop
->setToolTip(i18nc("@info", "Stop loading"));
1987 stop
->setWhatsThis(i18nc("@info", "This stops the loading of the contents of the current folder."));
1988 stop
->setIcon(QIcon::fromTheme(QStringLiteral("process-stop")));
1989 connect(stop
, &QAction::triggered
, this, &DolphinMainWindow::stopLoading
);
1991 KToggleAction
*editableLocation
= actionCollection()->add
<KToggleAction
>(QStringLiteral("editable_location"));
1992 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1993 editableLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1994 "This toggles the <emphasis>Location Bar</emphasis> to be "
1995 "editable so you can directly enter a location you want to go to.<nl/>"
1996 "You can also switch to editing by clicking to the right of the "
1997 "location and switch back by confirming the edited location."));
1998 actionCollection()->setDefaultShortcut(editableLocation
, Qt::Key_F6
);
1999 connect(editableLocation
, &KToggleAction::triggered
, this, &DolphinMainWindow::toggleEditLocation
);
2001 QAction
*replaceLocation
= actionCollection()->addAction(QStringLiteral("replace_location"));
2002 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
2003 // i18n: "enter" is used both in the meaning of "writing" and "going to" a new location here.
2004 // Both meanings are useful but not necessary to understand the use of "Replace Location".
2005 // So you might want to be more verbose in your language to convey the meaning but it's up to you.
2006 replaceLocation
->setWhatsThis(xi18nc("@info:whatsthis",
2007 "This switches to editing the location and selects it "
2008 "so you can quickly enter a different location."));
2009 actionCollection()->setDefaultShortcuts(replaceLocation
, {Qt::CTRL
| Qt::Key_L
, Qt::ALT
| Qt::Key_D
});
2010 connect(replaceLocation
, &QAction::triggered
, this, &DolphinMainWindow::replaceLocation
);
2014 QScopedPointer
<QAction
> backAction(KStandardAction::back(nullptr, nullptr, nullptr));
2015 m_backAction
= new KToolBarPopupAction(backAction
->icon(), backAction
->text(), actionCollection());
2016 m_backAction
->setObjectName(backAction
->objectName());
2017 m_backAction
->setShortcuts(backAction
->shortcuts());
2019 m_backAction
->setPopupMode(KToolBarPopupAction::DelayedPopup
);
2020 connect(m_backAction
, &QAction::triggered
, this, &DolphinMainWindow::goBack
);
2021 connect(m_backAction
->popupMenu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowBackPopupMenu
);
2022 connect(m_backAction
->popupMenu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoBack
);
2023 actionCollection()->addAction(m_backAction
->objectName(), m_backAction
);
2025 auto backShortcuts
= m_backAction
->shortcuts();
2026 // Prepend this shortcut, to avoid being hidden by the two-slot UI (#371130)
2027 backShortcuts
.prepend(QKeySequence(Qt::Key_Backspace
));
2028 actionCollection()->setDefaultShortcuts(m_backAction
, backShortcuts
);
2030 DolphinRecentTabsMenu
*recentTabsMenu
= new DolphinRecentTabsMenu(this);
2031 actionCollection()->addAction(QStringLiteral("closed_tabs"), recentTabsMenu
);
2032 connect(m_tabWidget
, &DolphinTabWidget::rememberClosedTab
, recentTabsMenu
, &DolphinRecentTabsMenu::rememberClosedTab
);
2033 connect(recentTabsMenu
, &DolphinRecentTabsMenu::restoreClosedTab
, m_tabWidget
, &DolphinTabWidget::restoreClosedTab
);
2034 connect(recentTabsMenu
, &DolphinRecentTabsMenu::closedTabsCountChanged
, this, &DolphinMainWindow::closedTabsCountChanged
);
2036 QAction
*undoCloseTab
= actionCollection()->addAction(QStringLiteral("undo_close_tab"));
2037 undoCloseTab
->setText(i18nc("@action:inmenu File", "Undo close tab"));
2038 undoCloseTab
->setWhatsThis(i18nc("@info:whatsthis undo close tab", "This returns you to the previously closed tab."));
2039 actionCollection()->setDefaultShortcut(undoCloseTab
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_T
);
2040 undoCloseTab
->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo")));
2041 undoCloseTab
->setEnabled(false);
2042 connect(undoCloseTab
, &QAction::triggered
, recentTabsMenu
, &DolphinRecentTabsMenu::undoCloseTab
);
2044 auto undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
2045 undoAction
->setWhatsThis(xi18nc("@info:whatsthis",
2047 "the last change you made to files or folders.<nl/>"
2048 "Such changes include <interface>creating</interface>, <interface>renaming</interface> "
2049 "and <interface>moving</interface> them to a different location "
2050 "or to the <filename>Trash</filename>. <nl/>Any changes that cannot be undone "
2051 "will ask for your confirmation beforehand."));
2052 undoAction
->setEnabled(false); // undo should be disabled by default
2055 QScopedPointer
<QAction
> forwardAction(KStandardAction::forward(nullptr, nullptr, nullptr));
2056 m_forwardAction
= new KToolBarPopupAction(forwardAction
->icon(), forwardAction
->text(), actionCollection());
2057 m_forwardAction
->setObjectName(forwardAction
->objectName());
2058 m_forwardAction
->setShortcuts(forwardAction
->shortcuts());
2060 m_forwardAction
->setPopupMode(KToolBarPopupAction::DelayedPopup
);
2061 connect(m_forwardAction
, &QAction::triggered
, this, &DolphinMainWindow::goForward
);
2062 connect(m_forwardAction
->popupMenu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowForwardPopupMenu
);
2063 connect(m_forwardAction
->popupMenu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoForward
);
2064 actionCollection()->addAction(m_forwardAction
->objectName(), m_forwardAction
);
2065 actionCollection()->setDefaultShortcuts(m_forwardAction
, m_forwardAction
->shortcuts());
2067 // enable middle-click to open in a new tab
2068 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
2069 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotBackForwardActionMiddleClicked
);
2070 m_backAction
->popupMenu()->installEventFilter(middleClickEventFilter
);
2071 m_forwardAction
->popupMenu()->installEventFilter(middleClickEventFilter
);
2072 KStandardAction::up(this, &DolphinMainWindow::goUp
, actionCollection());
2073 QAction
*homeAction
= KStandardAction::home(this, &DolphinMainWindow::goHome
, actionCollection());
2074 homeAction
->setWhatsThis(xi18nc("@info:whatsthis",
2076 "<filename>Home</filename> folder.<nl/>Every user account "
2077 "has their own <filename>Home</filename> that contains their personal files, "
2078 "as well as hidden folders for their applications' data and configuration files."));
2080 // setup 'Tools' menu
2081 QAction
*compareFiles
= actionCollection()->addAction(QStringLiteral("compare_files"));
2082 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
2083 compareFiles
->setIcon(QIcon::fromTheme(QStringLiteral("kompare")));
2084 compareFiles
->setEnabled(false);
2085 connect(compareFiles
, &QAction::triggered
, this, &DolphinMainWindow::compareFiles
);
2087 QAction
*openPreferredSearchTool
= actionCollection()->addAction(QStringLiteral("open_preferred_search_tool"));
2088 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
2089 openPreferredSearchTool
->setWhatsThis(xi18nc("@info:whatsthis",
2090 "<para>This opens a preferred search tool for the viewed location.</para>"
2091 "<para>Use <emphasis>More Search Tools</emphasis> menu to configure it.</para>"));
2092 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
2093 actionCollection()->setDefaultShortcut(openPreferredSearchTool
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F
);
2094 connect(openPreferredSearchTool
, &QAction::triggered
, this, &DolphinMainWindow::openPreferredSearchTool
);
2096 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
2097 // Get icon of user default terminal emulator application
2098 const KConfigGroup
group(KSharedConfig::openConfig(QStringLiteral("kdeglobals"), KConfig::SimpleConfig
), QStringLiteral("General"));
2099 const QString terminalDesktopFilename
= group
.readEntry("TerminalService");
2100 // Use utilities-terminal icon from theme if readEntry() has failed
2101 const QString terminalIcon
= terminalDesktopFilename
.isEmpty() ? "utilities-terminal" : KDesktopFile(terminalDesktopFilename
).readIcon();
2103 QAction
*openTerminal
= actionCollection()->addAction(QStringLiteral("open_terminal"));
2104 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
2105 openTerminal
->setWhatsThis(xi18nc("@info:whatsthis",
2106 "<para>This opens a <emphasis>terminal</emphasis> application for the viewed location.</para>"
2107 "<para>To learn more about terminals use the help features in the terminal application.</para>"));
2108 openTerminal
->setIcon(QIcon::fromTheme(terminalIcon
));
2109 actionCollection()->setDefaultShortcut(openTerminal
, Qt::SHIFT
| Qt::Key_F4
);
2110 connect(openTerminal
, &QAction::triggered
, this, &DolphinMainWindow::openTerminal
);
2112 QAction
*openTerminalHere
= actionCollection()->addAction(QStringLiteral("open_terminal_here"));
2113 // i18n: "Here" refers to the location(s) of the currently selected item(s) or the currently viewed location if nothing is selected.
2114 openTerminalHere
->setText(i18nc("@action:inmenu Tools", "Open Terminal Here"));
2115 openTerminalHere
->setWhatsThis(xi18nc("@info:whatsthis",
2116 "<para>This opens <emphasis>terminal</emphasis> applications for the selected items' locations.</para>"
2117 "<para>To learn more about terminals use the help features in the terminal application.</para>"));
2118 openTerminalHere
->setIcon(QIcon::fromTheme(terminalIcon
));
2119 actionCollection()->setDefaultShortcut(openTerminalHere
, Qt::SHIFT
| Qt::ALT
| Qt::Key_F4
);
2120 connect(openTerminalHere
, &QAction::triggered
, this, &DolphinMainWindow::openTerminalHere
);
2123 // setup 'Bookmarks' menu
2124 KActionMenu
*bookmarkMenu
= new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this);
2125 bookmarkMenu
->setIcon(QIcon::fromTheme(QStringLiteral("bookmarks")));
2126 // Make the toolbar button version work properly on click
2127 bookmarkMenu
->setPopupMode(QToolButton::InstantPopup
);
2128 m_bookmarkHandler
= new DolphinBookmarkHandler(this, actionCollection(), bookmarkMenu
->menu(), this);
2129 actionCollection()->addAction(QStringLiteral("bookmarks"), bookmarkMenu
);
2131 // setup 'Settings' menu
2132 KToggleAction
*showMenuBar
= KStandardAction::showMenubar(nullptr, nullptr, actionCollection());
2133 showMenuBar
->setWhatsThis(xi18nc("@info:whatsthis",
2134 "<para>This switches between having a <emphasis>Menubar</emphasis> "
2135 "and having an <interface>%1</interface> button. Both "
2136 "contain mostly the same actions and configuration options.</para>"
2137 "<para>The Menubar takes up more space but allows for fast and organized access to all "
2138 "actions an application has to offer.</para><para>The %1 button "
2139 "is simpler and small which makes triggering advanced actions more time consuming.</para>",
2140 hamburgerMenuAction
->text().replace('&', "")));
2141 connect(showMenuBar
,
2142 &KToggleAction::triggered
, // Fixes #286822
2144 &DolphinMainWindow::toggleShowMenuBar
,
2145 Qt::QueuedConnection
);
2147 KStandardAction::keyBindings(this, &DolphinMainWindow::slotKeyBindings
, actionCollection());
2148 KStandardAction::preferences(this, &DolphinMainWindow::editSettings
, actionCollection());
2150 // not in menu actions
2151 QList
<QKeySequence
> nextTabKeys
= KStandardShortcut::tabNext();
2152 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
2154 QList
<QKeySequence
> prevTabKeys
= KStandardShortcut::tabPrev();
2155 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
2157 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
2158 QAction
*activateTab
= actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i
));
2159 activateTab
->setText(i18nc("@action:inmenu", "Go to Tab %1", i
+ 1));
2160 activateTab
->setEnabled(false);
2161 connect(activateTab
, &QAction::triggered
, this, [this, i
]() {
2162 m_tabWidget
->activateTab(i
);
2165 // only add default shortcuts for the first 9 tabs regardless of MaxActivateTabShortcuts
2167 actionCollection()->setDefaultShortcut(activateTab
, QStringLiteral("Alt+%1").arg(i
+ 1));
2171 QAction
*activateLastTab
= actionCollection()->addAction(QStringLiteral("activate_last_tab"));
2172 activateLastTab
->setIconText(i18nc("@action:inmenu", "Last Tab"));
2173 activateLastTab
->setText(i18nc("@action:inmenu", "Go to Last Tab"));
2174 activateLastTab
->setEnabled(false);
2175 connect(activateLastTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateLastTab
);
2176 actionCollection()->setDefaultShortcut(activateLastTab
, Qt::ALT
| Qt::Key_0
);
2178 QAction
*activateNextTab
= actionCollection()->addAction(QStringLiteral("activate_next_tab"));
2179 activateNextTab
->setIconText(i18nc("@action:inmenu", "Next Tab"));
2180 activateNextTab
->setText(i18nc("@action:inmenu", "Go to Next Tab"));
2181 activateNextTab
->setEnabled(false);
2182 connect(activateNextTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateNextTab
);
2183 actionCollection()->setDefaultShortcuts(activateNextTab
, nextTabKeys
);
2185 QAction
*activatePrevTab
= actionCollection()->addAction(QStringLiteral("activate_prev_tab"));
2186 activatePrevTab
->setIconText(i18nc("@action:inmenu", "Previous Tab"));
2187 activatePrevTab
->setText(i18nc("@action:inmenu", "Go to Previous Tab"));
2188 activatePrevTab
->setEnabled(false);
2189 connect(activatePrevTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activatePrevTab
);
2190 actionCollection()->setDefaultShortcuts(activatePrevTab
, prevTabKeys
);
2193 QAction
*showTarget
= actionCollection()->addAction(QStringLiteral("show_target"));
2194 showTarget
->setText(i18nc("@action:inmenu", "Show Target"));
2195 showTarget
->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
2196 showTarget
->setEnabled(false);
2197 connect(showTarget
, &QAction::triggered
, this, &DolphinMainWindow::showTarget
);
2199 QAction
*openInNewTab
= actionCollection()->addAction(QStringLiteral("open_in_new_tab"));
2200 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
2201 openInNewTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
2202 connect(openInNewTab
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
2204 QAction
*openInNewTabs
= actionCollection()->addAction(QStringLiteral("open_in_new_tabs"));
2205 openInNewTabs
->setText(i18nc("@action:inmenu", "Open in New Tabs"));
2206 openInNewTabs
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
2207 connect(openInNewTabs
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
2209 QAction
*openInNewWindow
= actionCollection()->addAction(QStringLiteral("open_in_new_window"));
2210 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
2211 openInNewWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
2212 connect(openInNewWindow
, &QAction::triggered
, this, &DolphinMainWindow::openInNewWindow
);
2214 QAction
*openInSplitViewAction
= actionCollection()->addAction(QStringLiteral("open_in_split_view"));
2215 openInSplitViewAction
->setText(i18nc("@action:inmenu", "Open in Split View"));
2216 openInSplitViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-split-left-right")));
2217 connect(openInSplitViewAction
, &QAction::triggered
, this, [this]() {
2218 openInSplitView(QUrl());
2221 m_recentFiles
= new KRecentFilesAction(this);
2224 void DolphinMainWindow::setupDockWidgets()
2226 const bool lock
= GeneralSettings::lockPanels();
2228 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(lock
);
2230 KDualAction
*lockLayoutAction
= actionCollection()->add
<KDualAction
>(QStringLiteral("lock_panels"));
2231 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
2232 lockLayoutAction
->setActiveIcon(QIcon::fromTheme(QStringLiteral("object-unlocked")));
2233 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
2234 lockLayoutAction
->setInactiveIcon(QIcon::fromTheme(QStringLiteral("object-locked")));
2235 lockLayoutAction
->setWhatsThis(xi18nc("@info:whatsthis",
2237 "switches between having panels <emphasis>locked</emphasis> or "
2238 "<emphasis>unlocked</emphasis>.<nl/>Unlocked panels can be "
2239 "dragged to the other side of the window and have a close "
2240 "button.<nl/>Locked panels are embedded more cleanly."));
2241 lockLayoutAction
->setActive(lock
);
2242 connect(lockLayoutAction
, &KDualAction::triggered
, this, &DolphinMainWindow::togglePanelLockState
);
2244 // Setup "Information"
2245 DolphinDockWidget
*infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
2246 infoDock
->setLocked(lock
);
2247 infoDock
->setObjectName(QStringLiteral("infoDock"));
2248 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2251 InformationPanel
*infoPanel
= new InformationPanel(infoDock
);
2252 infoPanel
->setCustomContextMenuActions({lockLayoutAction
});
2253 connect(infoPanel
, &InformationPanel::urlActivated
, this, &DolphinMainWindow::handleUrl
);
2254 infoDock
->setWidget(infoPanel
);
2256 createPanelAction(QIcon::fromTheme(QStringLiteral("documentinfo")), Qt::Key_F11
, infoDock
, QStringLiteral("show_information_panel"));
2258 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
2259 connect(this, &DolphinMainWindow::urlChanged
, infoPanel
, &InformationPanel::setUrl
);
2260 connect(this, &DolphinMainWindow::selectionChanged
, infoPanel
, &InformationPanel::setSelection
);
2261 connect(this, &DolphinMainWindow::requestItemInfo
, infoPanel
, &InformationPanel::requestDelayedItemInfo
);
2262 connect(this, &DolphinMainWindow::fileItemsChanged
, infoPanel
, &InformationPanel::slotFilesItemChanged
);
2263 connect(this, &DolphinMainWindow::settingsChanged
, infoPanel
, &InformationPanel::readSettings
);
2266 // i18n: This is the last paragraph for the "What's This"-texts of all four panels.
2267 const QString panelWhatsThis
= xi18nc("@info:whatsthis",
2269 "hide panels like this go to <interface>Menu|Panels</interface> "
2270 "or <interface>View|Panels</interface>.</para>");
2273 ->action(QStringLiteral("show_information_panel"))
2274 ->setWhatsThis(xi18nc("@info:whatsthis",
2275 "<para> This toggles the "
2276 "<emphasis>information</emphasis> panel at the right side of the "
2277 "window.</para><para>The panel provides in-depth information "
2278 "about the items your mouse is hovering over or about the selected "
2279 "items. Otherwise it informs you about the currently viewed folder.<nl/>"
2280 "For single items a preview of their contents is provided.</para>"));
2282 infoDock
->setWhatsThis(xi18nc("@info:whatsthis",
2284 "provides in-depth information about the items your mouse is "
2285 "hovering over or about the selected items. Otherwise it informs "
2286 "you about the currently viewed folder.<nl/>For single items a "
2287 "preview of their contents is provided.</para><para>You can configure "
2288 "which and how details are given here by right-clicking.</para>")
2292 DolphinDockWidget
*foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
2293 foldersDock
->setLocked(lock
);
2294 foldersDock
->setObjectName(QStringLiteral("foldersDock"));
2295 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2296 FoldersPanel
*foldersPanel
= new FoldersPanel(foldersDock
);
2297 foldersPanel
->setCustomContextMenuActions({lockLayoutAction
});
2298 foldersDock
->setWidget(foldersPanel
);
2300 createPanelAction(QIcon::fromTheme(QStringLiteral("folder")), Qt::Key_F7
, foldersDock
, QStringLiteral("show_folders_panel"));
2302 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
2303 connect(this, &DolphinMainWindow::urlChanged
, foldersPanel
, &FoldersPanel::setUrl
);
2304 connect(foldersPanel
, &FoldersPanel::folderActivated
, this, &DolphinMainWindow::changeUrl
);
2305 connect(foldersPanel
, &FoldersPanel::folderInNewTab
, this, &DolphinMainWindow::openNewTab
);
2306 connect(foldersPanel
, &FoldersPanel::folderInNewActiveTab
, this, &DolphinMainWindow::openNewTabAndActivate
);
2307 connect(foldersPanel
, &FoldersPanel::errorMessage
, this, &DolphinMainWindow::showErrorMessage
);
2310 ->action(QStringLiteral("show_folders_panel"))
2311 ->setWhatsThis(xi18nc("@info:whatsthis",
2313 "<emphasis>folders</emphasis> panel at the left side of the window."
2314 "<nl/><nl/>It shows the folders of the <emphasis>file system"
2315 "</emphasis> in a <emphasis>tree view</emphasis>."));
2316 foldersDock
->setWhatsThis(xi18nc("@info:whatsthis",
2318 "shows the folders of the <emphasis>file system</emphasis> in a "
2319 "<emphasis>tree view</emphasis>.</para><para>Click a folder to go "
2320 "there. Click the arrow to the left of a folder to see its subfolders. "
2321 "This allows quick switching between any folders.</para>")
2326 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
2327 DolphinDockWidget
*terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
2328 terminalDock
->setLocked(lock
);
2329 terminalDock
->setObjectName(QStringLiteral("terminalDock"));
2330 terminalDock
->setContentsMargins(0, 0, 0, 0);
2331 m_terminalPanel
= new TerminalPanel(terminalDock
);
2332 m_terminalPanel
->setCustomContextMenuActions({lockLayoutAction
});
2333 terminalDock
->setWidget(m_terminalPanel
);
2335 connect(m_terminalPanel
, &TerminalPanel::hideTerminalPanel
, terminalDock
, &DolphinDockWidget::hide
);
2336 connect(m_terminalPanel
, &TerminalPanel::changeUrl
, this, &DolphinMainWindow::slotTerminalDirectoryChanged
);
2337 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
, m_terminalPanel
, &TerminalPanel::dockVisibilityChanged
);
2338 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
, this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged
);
2340 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-scripts")), Qt::Key_F4
, terminalDock
, QStringLiteral("show_terminal_panel"));
2342 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
2343 connect(this, &DolphinMainWindow::urlChanged
, m_terminalPanel
, &TerminalPanel::setUrl
);
2345 if (GeneralSettings::version() < 200) {
2346 terminalDock
->hide();
2350 ->action(QStringLiteral("show_terminal_panel"))
2351 ->setWhatsThis(xi18nc("@info:whatsthis",
2352 "<para>This toggles the "
2353 "<emphasis>terminal</emphasis> panel at the bottom of the window."
2354 "<nl/>The location in the terminal will always match the folder "
2355 "view so you can navigate using either.</para><para>The terminal "
2356 "panel is not needed for basic computer usage but can be useful "
2357 "for advanced tasks. To learn more about terminals use the help features "
2358 "in a standalone terminal application like Konsole.</para>"));
2359 terminalDock
->setWhatsThis(xi18nc("@info:whatsthis",
2361 "the <emphasis>terminal</emphasis> panel. It behaves like a "
2362 "normal terminal but will match the location of the folder view "
2363 "so you can navigate using either.</para><para>The terminal panel "
2364 "is not needed for basic computer usage but can be useful for "
2365 "advanced tasks. To learn more about terminals use the help features in a "
2366 "standalone terminal application like Konsole.</para>")
2369 QAction
*focusTerminalPanel
= actionCollection()->addAction(QStringLiteral("focus_terminal_panel"));
2370 focusTerminalPanel
->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2371 focusTerminalPanel
->setToolTip(i18nc("@info:tooltip", "Move keyboard focus to and from the Terminal panel."));
2372 focusTerminalPanel
->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
2373 actionCollection()->setDefaultShortcut(focusTerminalPanel
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F4
);
2374 connect(focusTerminalPanel
, &QAction::triggered
, this, &DolphinMainWindow::toggleTerminalPanelFocus
);
2375 } // endif "shell_access" allowed
2376 #endif // HAVE_TERMINAL
2378 if (GeneralSettings::version() < 200) {
2380 foldersDock
->hide();
2384 DolphinDockWidget
*placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
2385 placesDock
->setLocked(lock
);
2386 placesDock
->setObjectName(QStringLiteral("placesDock"));
2387 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2389 m_placesPanel
= new PlacesPanel(placesDock
);
2390 m_placesPanel
->setCustomContextMenuActions({lockLayoutAction
});
2391 placesDock
->setWidget(m_placesPanel
);
2393 createPanelAction(QIcon::fromTheme(QStringLiteral("compass")), Qt::Key_F9
, placesDock
, QStringLiteral("show_places_panel"));
2395 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
2396 connect(m_placesPanel
, &PlacesPanel::placeActivated
, this, &DolphinMainWindow::slotPlaceActivated
);
2397 connect(m_placesPanel
, &PlacesPanel::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2398 connect(m_placesPanel
, &PlacesPanel::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2399 connect(m_placesPanel
, &PlacesPanel::newWindowRequested
, this, [this](const QUrl
&url
) {
2400 Dolphin::openNewWindow({url
}, this);
2402 connect(m_placesPanel
, &PlacesPanel::openInSplitViewRequested
, this, &DolphinMainWindow::openInSplitView
);
2403 connect(m_placesPanel
, &PlacesPanel::errorMessage
, this, &DolphinMainWindow::showErrorMessage
);
2404 connect(this, &DolphinMainWindow::urlChanged
, m_placesPanel
, &PlacesPanel::setUrl
);
2405 connect(placesDock
, &DolphinDockWidget::visibilityChanged
, &DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged
);
2406 connect(placesDock
, &DolphinDockWidget::visibilityChanged
, this, &DolphinMainWindow::slotPlacesPanelVisibilityChanged
);
2407 connect(this, &DolphinMainWindow::settingsChanged
, m_placesPanel
, &PlacesPanel::readSettings
);
2408 connect(m_placesPanel
, &PlacesPanel::storageTearDownRequested
, this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested
);
2409 connect(m_placesPanel
, &PlacesPanel::storageTearDownExternallyRequested
, this, &DolphinMainWindow::slotStorageTearDownExternallyRequested
);
2410 DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged(m_placesPanel
->isVisible());
2412 auto actionShowAllPlaces
= new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this);
2413 actionShowAllPlaces
->setCheckable(true);
2414 actionShowAllPlaces
->setDisabled(true);
2415 actionShowAllPlaces
->setWhatsThis(i18nc("@info:whatsthis",
2417 "all places in the places panel that have been hidden. They will "
2418 "appear semi-transparent and allow you to uncheck their \"Hide\" property."));
2420 connect(actionShowAllPlaces
, &QAction::triggered
, this, [this](bool checked
) {
2421 m_placesPanel
->setShowAll(checked
);
2423 connect(m_placesPanel
, &PlacesPanel::allPlacesShownChanged
, actionShowAllPlaces
, &QAction::setChecked
);
2426 ->action(QStringLiteral("show_places_panel"))
2427 ->setWhatsThis(xi18nc("@info:whatsthis",
2428 "<para>This toggles the "
2429 "<emphasis>places</emphasis> panel at the left side of the window."
2430 "</para><para>It allows you to go to locations you have "
2431 "bookmarked and to access disk or media attached to the computer "
2432 "or to the network. It also contains sections to find recently "
2433 "saved files or files of a certain type.</para>"));
2434 placesDock
->setWhatsThis(xi18nc("@info:whatsthis",
2435 "<para>This is the "
2436 "<emphasis>Places</emphasis> panel. It allows you to go to locations "
2437 "you have bookmarked and to access disk or media attached to the "
2438 "computer or to the network. It also contains sections to find "
2439 "recently saved files or files of a certain type.</para><para>"
2440 "Click on an entry to go there. Click with the right mouse button "
2441 "instead to open any entry in a new tab or new window.</para>"
2442 "<para>New entries can be added by dragging folders onto this panel. "
2443 "Right-click any section or entry to hide it. Right-click an empty "
2444 "space on this panel and select <interface>Show Hidden Places"
2445 "</interface> to display it again.</para>")
2448 QAction
*focusPlacesPanel
= actionCollection()->addAction(QStringLiteral("focus_places_panel"));
2449 focusPlacesPanel
->setText(i18nc("@action:inmenu View", "Focus Places Panel"));
2450 focusPlacesPanel
->setToolTip(i18nc("@info:tooltip", "Move keyboard focus to and from the Places panel."));
2451 focusPlacesPanel
->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
2452 actionCollection()->setDefaultShortcut(focusPlacesPanel
, Qt::CTRL
| Qt::Key_P
);
2453 connect(focusPlacesPanel
, &QAction::triggered
, this, &DolphinMainWindow::togglePlacesPanelFocus
);
2455 // Add actions into the "Panels" menu
2456 KActionMenu
*panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Show Panels"), this);
2457 actionCollection()->addAction(QStringLiteral("panels"), panelsMenu
);
2458 panelsMenu
->setIcon(QIcon::fromTheme(QStringLiteral("view-sidetree")));
2459 panelsMenu
->setPopupMode(QToolButton::InstantPopup
);
2460 const KActionCollection
*ac
= actionCollection();
2461 panelsMenu
->addAction(ac
->action(QStringLiteral("show_places_panel")));
2463 panelsMenu
->addAction(ac
->action(QStringLiteral("show_information_panel")));
2465 panelsMenu
->addAction(ac
->action(QStringLiteral("show_folders_panel")));
2466 panelsMenu
->addAction(ac
->action(QStringLiteral("show_terminal_panel")));
2467 panelsMenu
->addSeparator();
2468 panelsMenu
->addAction(lockLayoutAction
);
2469 panelsMenu
->addSeparator();
2470 panelsMenu
->addAction(actionShowAllPlaces
);
2471 panelsMenu
->addAction(focusPlacesPanel
);
2472 panelsMenu
->addAction(ac
->action(QStringLiteral("focus_terminal_panel")));
2474 connect(panelsMenu
->menu(), &QMenu::aboutToShow
, this, [actionShowAllPlaces
] {
2475 actionShowAllPlaces
->setEnabled(DolphinPlacesModelSingleton::instance().placesModel()->hiddenCount());
2479 void DolphinMainWindow::updateFileAndEditActions()
2481 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
2482 const KActionCollection
*col
= actionCollection();
2483 KFileItemListProperties
capabilitiesSource(list
);
2485 QAction
*renameAction
= col
->action(KStandardAction::name(KStandardAction::RenameFile
));
2486 QAction
*moveToTrashAction
= col
->action(KStandardAction::name(KStandardAction::MoveToTrash
));
2487 QAction
*deleteAction
= col
->action(KStandardAction::name(KStandardAction::DeleteFile
));
2488 QAction
*cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
2489 QAction
*duplicateAction
= col
->action(QStringLiteral("duplicate")); // see DolphinViewActionHandler
2490 QAction
*addToPlacesAction
= col
->action(QStringLiteral("add_to_places"));
2491 QAction
*copyToOtherViewAction
= col
->action(QStringLiteral("copy_to_inactive_split_view"));
2492 QAction
*moveToOtherViewAction
= col
->action(QStringLiteral("move_to_inactive_split_view"));
2493 QAction
*copyLocation
= col
->action(QStringLiteral("copy_location"));
2495 if (list
.isEmpty()) {
2496 stateChanged(QStringLiteral("has_no_selection"));
2498 // All actions that need a selection to function can be enabled because they should trigger selection mode.
2499 renameAction
->setEnabled(true);
2500 moveToTrashAction
->setEnabled(true);
2501 deleteAction
->setEnabled(true);
2502 cutAction
->setEnabled(true);
2503 duplicateAction
->setEnabled(true);
2504 addToPlacesAction
->setEnabled(true);
2505 copyLocation
->setEnabled(true);
2506 // Them triggering selection mode and not directly acting on selected items is signified by adding "…" to their text.
2507 m_actionTextHelper
->textsWhenNothingIsSelectedEnabled(true);
2510 m_actionTextHelper
->textsWhenNothingIsSelectedEnabled(false);
2511 stateChanged(QStringLiteral("has_selection"));
2513 QAction
*deleteWithTrashShortcut
= col
->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
2514 QAction
*showTarget
= col
->action(QStringLiteral("show_target"));
2516 if (list
.length() == 1 && list
.first().isDir()) {
2517 addToPlacesAction
->setEnabled(true);
2519 addToPlacesAction
->setEnabled(false);
2522 const bool enableMoveToTrash
= capabilitiesSource
.isLocal() && capabilitiesSource
.supportsMoving();
2524 renameAction
->setEnabled(capabilitiesSource
.supportsMoving());
2525 m_disabledActionNotifier
->setDisabledReason(renameAction
, i18nc("@info", "Cannot rename: You do not have permission to rename items in this folder."));
2526 deleteAction
->setEnabled(capabilitiesSource
.supportsDeleting());
2527 m_disabledActionNotifier
->setDisabledReason(deleteAction
,
2528 i18nc("@info", "Cannot delete: You do not have permission to remove items from this folder."));
2529 cutAction
->setEnabled(capabilitiesSource
.supportsMoving());
2530 m_disabledActionNotifier
->setDisabledReason(cutAction
, i18nc("@info", "Cannot cut: You do not have permission to move items from this folder."));
2531 copyLocation
->setEnabled(list
.length() == 1);
2532 showTarget
->setEnabled(list
.length() == 1 && list
.at(0).isLink());
2533 duplicateAction
->setEnabled(capabilitiesSource
.supportsWriting());
2534 m_disabledActionNotifier
->setDisabledReason(duplicateAction
,
2535 i18nc("@info", "Cannot duplicate here: You do not have permission to create items in this folder."));
2537 if (enableMoveToTrash
) {
2538 moveToTrashAction
->setEnabled(true);
2539 deleteWithTrashShortcut
->setEnabled(false);
2540 m_disabledActionNotifier
->clearDisabledReason(deleteWithTrashShortcut
);
2542 moveToTrashAction
->setEnabled(false);
2543 deleteWithTrashShortcut
->setEnabled(capabilitiesSource
.supportsDeleting());
2544 m_disabledActionNotifier
->setDisabledReason(deleteWithTrashShortcut
,
2545 i18nc("@info", "Cannot delete: You do not have permission to remove items from this folder."));
2549 if (!m_tabWidget
->currentTabPage()->splitViewEnabled()) {
2550 // No need to set the disabled reason here, as it's obvious to the user that the reason is the split view being disabled.
2551 copyToOtherViewAction
->setEnabled(false);
2552 m_disabledActionNotifier
->clearDisabledReason(copyToOtherViewAction
);
2553 moveToOtherViewAction
->setEnabled(false);
2554 m_disabledActionNotifier
->clearDisabledReason(moveToOtherViewAction
);
2555 } else if (list
.isEmpty()) {
2556 copyToOtherViewAction
->setEnabled(false);
2557 m_disabledActionNotifier
->setDisabledReason(copyToOtherViewAction
, i18nc("@info", "Cannot copy to other view: No files selected."));
2558 moveToOtherViewAction
->setEnabled(false);
2559 m_disabledActionNotifier
->setDisabledReason(moveToOtherViewAction
, i18nc("@info", "Cannot move to other view: No files selected."));
2561 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
2562 KFileItem capabilitiesDestination
;
2564 if (tabPage
->primaryViewActive()) {
2565 capabilitiesDestination
= tabPage
->secondaryViewContainer()->rootItem();
2567 capabilitiesDestination
= tabPage
->primaryViewContainer()->rootItem();
2570 const auto destUrl
= capabilitiesDestination
.url();
2571 const bool allNotTargetOrigin
= std::all_of(list
.cbegin(), list
.cend(), [destUrl
](const KFileItem
&item
) {
2572 return item
.url().adjusted(QUrl::RemoveFilename
| QUrl::StripTrailingSlash
) != destUrl
;
2575 if (!allNotTargetOrigin
) {
2576 copyToOtherViewAction
->setEnabled(false);
2577 m_disabledActionNotifier
->setDisabledReason(copyToOtherViewAction
,
2578 i18nc("@info", "Cannot copy to other view: The other view already contains these items."));
2579 moveToOtherViewAction
->setEnabled(false);
2580 m_disabledActionNotifier
->setDisabledReason(moveToOtherViewAction
,
2581 i18nc("@info", "Cannot move to other view: The other view already contains these items."));
2582 } else if (!capabilitiesDestination
.isWritable()) {
2583 copyToOtherViewAction
->setEnabled(false);
2584 m_disabledActionNotifier
->setDisabledReason(
2585 copyToOtherViewAction
,
2586 i18nc("@info", "Cannot copy to other view: You do not have permission to write into the destination folder."));
2587 moveToOtherViewAction
->setEnabled(false);
2588 m_disabledActionNotifier
->setDisabledReason(
2589 moveToOtherViewAction
,
2590 i18nc("@info", "Cannot move to other view: You do not have permission to write into the destination folder."));
2592 copyToOtherViewAction
->setEnabled(true);
2593 moveToOtherViewAction
->setEnabled(capabilitiesSource
.supportsMoving());
2594 m_disabledActionNotifier
->setDisabledReason(
2595 moveToOtherViewAction
,
2596 i18nc("@info", "Cannot move to other view: You do not have permission to move items from this folder."));
2601 void DolphinMainWindow::updateViewActions()
2603 m_actionHandler
->updateViewActions();
2605 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
2606 toggleFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
2608 updateSplitActions();
2611 void DolphinMainWindow::updateGoActions()
2613 QAction
*goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
2614 const QUrl currentUrl
= m_activeViewContainer
->url();
2615 // I think this is one of the best places to firstly be confronted
2616 // with a file system and its hierarchy. Talking about the root
2617 // directory might seem too much here but it is the question that
2618 // naturally arises in this context.
2619 goUpAction
->setWhatsThis(xi18nc("@info:whatsthis",
2621 "the folder that contains the currently viewed one.</para>"
2622 "<para>All files and folders are organized in a hierarchical "
2623 "<emphasis>file system</emphasis>. At the top of this hierarchy is "
2624 "a directory that contains all data connected to this computer"
2625 "—the <emphasis>root directory</emphasis>.</para>"));
2626 goUpAction
->setEnabled(KIO::upUrl(currentUrl
) != currentUrl
);
2629 void DolphinMainWindow::refreshViews()
2631 m_tabWidget
->refreshViews();
2633 if (GeneralSettings::modifiedStartupSettings()) {
2634 updateWindowTitle();
2637 updateSplitActions();
2639 Q_EMIT
settingsChanged();
2642 void DolphinMainWindow::clearStatusBar()
2644 m_activeViewContainer
->statusBar()->resetToDefaultText();
2647 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
*container
)
2649 connect(container
, &DolphinViewContainer::showFilterBarChanged
, this, &DolphinMainWindow::updateFilterBarAction
);
2650 connect(container
, &DolphinViewContainer::writeStateChanged
, this, &DolphinMainWindow::slotWriteStateChanged
);
2651 slotWriteStateChanged(container
->view()->isFolderWritable());
2652 connect(container
, &DolphinViewContainer::searchBarVisibilityChanged
, this, &DolphinMainWindow::updateSearchAction
);
2653 connect(container
, &DolphinViewContainer::captionChanged
, this, &DolphinMainWindow::updateWindowTitle
);
2654 connect(container
, &DolphinViewContainer::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2655 connect(container
, &DolphinViewContainer::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2657 // Make the toggled state of the selection mode actions visually follow the selection mode state of the view.
2658 auto toggleSelectionModeAction
= actionCollection()->action(QStringLiteral("toggle_selection_mode"));
2659 toggleSelectionModeAction
->setChecked(m_activeViewContainer
->isSelectionModeEnabled());
2660 connect(m_activeViewContainer
, &DolphinViewContainer::selectionModeChanged
, toggleSelectionModeAction
, &QAction::setChecked
);
2662 const DolphinView
*view
= container
->view();
2663 connect(view
, &DolphinView::selectionChanged
, this, &DolphinMainWindow::slotSelectionChanged
);
2664 connect(view
, &DolphinView::requestItemInfo
, this, &DolphinMainWindow::requestItemInfo
);
2665 connect(view
, &DolphinView::fileItemsChanged
, this, &DolphinMainWindow::fileItemsChanged
);
2666 connect(view
, &DolphinView::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2667 connect(view
, &DolphinView::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2668 connect(view
, &DolphinView::windowRequested
, this, &DolphinMainWindow::openNewWindow
);
2669 connect(view
, &DolphinView::requestContextMenu
, this, &DolphinMainWindow::openContextMenu
);
2670 connect(view
, &DolphinView::directoryLoadingStarted
, this, &DolphinMainWindow::enableStopAction
);
2671 connect(view
, &DolphinView::directoryLoadingCompleted
, this, &DolphinMainWindow::disableStopAction
);
2672 connect(view
, &DolphinView::directoryLoadingCompleted
, this, &DolphinMainWindow::slotDirectoryLoadingCompleted
);
2673 connect(view
, &DolphinView::goBackRequested
, this, &DolphinMainWindow::goBack
);
2674 connect(view
, &DolphinView::goForwardRequested
, this, &DolphinMainWindow::goForward
);
2675 connect(view
, &DolphinView::urlActivated
, this, &DolphinMainWindow::handleUrl
);
2676 connect(view
, &DolphinView::goUpRequested
, this, &DolphinMainWindow::goUp
);
2677 connect(view
, &DolphinView::doubleClickViewBackground
, this, &DolphinMainWindow::slotDoubleClickViewBackground
);
2679 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::urlChanged
, this, &DolphinMainWindow::changeUrl
);
2680 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::historyChanged
, this, &DolphinMainWindow::updateHistory
);
2682 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2683 const KUrlNavigator
*navigator
=
2684 m_tabWidget
->currentTabPage()->primaryViewActive() ? navigators
->primaryUrlNavigator() : navigators
->secondaryUrlNavigator();
2686 QAction
*editableLocactionAction
= actionCollection()->action(QStringLiteral("editable_location"));
2687 editableLocactionAction
->setChecked(navigator
->isUrlEditable());
2688 connect(navigator
, &KUrlNavigator::editableStateChanged
, this, &DolphinMainWindow::slotEditableStateChanged
);
2689 connect(navigator
, &KUrlNavigator::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2690 connect(navigator
, &KUrlNavigator::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2691 connect(navigator
, &KUrlNavigator::newWindowRequested
, this, &DolphinMainWindow::openNewWindow
);
2694 void DolphinMainWindow::updateSplitActions()
2696 QAction
*popoutSplitAction
= actionCollection()->action(QStringLiteral("popout_split_view"));
2698 auto setActionPopupMode
= [this](KActionMenu
*action
, QToolButton::ToolButtonPopupMode popupMode
) {
2699 action
->setPopupMode(popupMode
);
2700 if (auto *buttonForAction
= qobject_cast
<QToolButton
*>(toolBar()->widgetForAction(action
))) {
2701 buttonForAction
->setPopupMode(popupMode
);
2705 const DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
2706 if (tabPage
->splitViewEnabled()) {
2707 if (GeneralSettings::closeActiveSplitView() ? tabPage
->primaryViewActive() : !tabPage
->primaryViewActive()) {
2708 m_splitViewAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2709 m_splitViewAction
->setToolTip(i18nc("@info", "Close left view"));
2710 m_splitViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close")));
2711 m_splitViewMenuAction
->setText(i18nc("@action:inmenu Close left view", "Close Left View"));
2713 popoutSplitAction
->setText(i18nc("@action:intoolbar Move left view to a new window", "Pop out Left View"));
2714 popoutSplitAction
->setToolTip(i18nc("@info", "Move left view to a new window"));
2716 m_splitViewAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2717 m_splitViewAction
->setToolTip(i18nc("@info", "Close right view"));
2718 m_splitViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close")));
2719 m_splitViewMenuAction
->setText(i18nc("@action:inmenu Close left view", "Close Right View"));
2721 popoutSplitAction
->setText(i18nc("@action:intoolbar Move right view to a new window", "Pop out Right View"));
2722 popoutSplitAction
->setToolTip(i18nc("@info", "Move right view to a new window"));
2724 popoutSplitAction
->setEnabled(true);
2725 if (!m_splitViewAction
->menu()) {
2726 setActionPopupMode(m_splitViewAction
, QToolButton::MenuButtonPopup
);
2727 m_splitViewAction
->setMenu(new QMenu
);
2728 m_splitViewAction
->addAction(popoutSplitAction
);
2731 m_splitViewAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2732 m_splitViewMenuAction
->setText(m_splitViewAction
->text());
2733 m_splitViewAction
->setToolTip(i18nc("@info", "Split view"));
2734 m_splitViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-split-left-right")));
2735 popoutSplitAction
->setText(i18nc("@action:intoolbar Move view in focus to a new window", "Pop out"));
2736 popoutSplitAction
->setEnabled(false);
2737 if (m_splitViewAction
->menu()) {
2738 m_splitViewAction
->removeAction(popoutSplitAction
);
2739 m_splitViewAction
->menu()->deleteLater();
2740 m_splitViewAction
->setMenu(nullptr);
2741 setActionPopupMode(m_splitViewAction
, QToolButton::DelayedPopup
);
2745 // Update state from toolbar action
2746 m_splitViewMenuAction
->setToolTip(m_splitViewAction
->toolTip());
2747 m_splitViewMenuAction
->setIcon(m_splitViewAction
->icon());
2750 void DolphinMainWindow::updateAllowedToolbarAreas()
2752 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2753 if (toolBar()->actions().contains(navigators
)) {
2754 toolBar()->setAllowedAreas(Qt::TopToolBarArea
| Qt::BottomToolBarArea
);
2755 if (toolBarArea(toolBar()) == Qt::LeftToolBarArea
|| toolBarArea(toolBar()) == Qt::RightToolBarArea
) {
2756 addToolBar(Qt::TopToolBarArea
, toolBar());
2759 toolBar()->setAllowedAreas(Qt::AllToolBarAreas
);
2763 bool DolphinMainWindow::isKompareInstalled() const
2765 static bool initialized
= false;
2766 static bool installed
= false;
2768 // TODO: maybe replace this approach later by using a menu
2769 // plugin like kdiff3plugin.cpp
2770 installed
= !QStandardPaths::findExecutable(QStringLiteral("kompare")).isEmpty();
2776 void DolphinMainWindow::createPanelAction(const QIcon
&icon
, const QKeySequence
&shortcut
, QDockWidget
*dockWidget
, const QString
&actionName
)
2778 auto dockAction
= dockWidget
->toggleViewAction();
2779 dockAction
->setIcon(icon
);
2780 dockAction
->setEnabled(true);
2782 QAction
*panelAction
= actionCollection()->addAction(actionName
, dockAction
);
2783 actionCollection()->setDefaultShortcut(panelAction
, shortcut
);
2786 void DolphinMainWindow::setupWhatsThis()
2789 menuBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2790 "<emphasis>Menubar</emphasis>. It provides access to commands and "
2791 "configuration options. Left-click on any of the menus on this "
2792 "bar to see its contents.</para><para>The Menubar can be hidden "
2793 "by unchecking <interface>Settings|Show Menubar</interface>. Then "
2794 "most of its contents become available through a <interface>Menu"
2795 "</interface> button on the <emphasis>Toolbar</emphasis>.</para>"));
2796 toolBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2797 "<emphasis>Toolbar</emphasis>. It allows quick access to "
2798 "frequently used actions.</para><para>It is highly customizable. "
2799 "All items you see in the <interface>Menu</interface> or "
2800 "in the <interface>Menubar</interface> can be placed on the "
2801 "Toolbar. Just right-click on it and select <interface>Configure "
2802 "Toolbars…</interface> or find this action within the <interface>"
2804 "</para><para>The location of the bar and the style of its "
2805 "buttons can also be changed in the right-click menu. Right-click "
2806 "a button if you want to show or hide its text.</para>"));
2807 m_tabWidget
->setWhatsThis(xi18nc("@info:whatsthis main view",
2808 "<para>Here you can see the <emphasis>folders</emphasis> and "
2809 "<emphasis>files</emphasis> that are at the location described in "
2810 "the <interface>Location Bar</interface> above. This area is the "
2811 "central part of this application where you navigate to the files "
2812 "you want to use.</para><para>For an elaborate and general "
2813 "introduction to this application <link "
2814 "url='https://userbase.kde.org/Dolphin/File_Management#Introduction_to_Dolphin'>"
2815 "click here</link>. This will open an introductory article from "
2816 "the <emphasis>KDE UserBase Wiki</emphasis>.</para><para>For brief "
2817 "explanations of all the features of this <emphasis>view</emphasis> "
2818 "<link url='help:/dolphin/dolphin-view.html'>click here</link> "
2819 "instead. This will open a page from the <emphasis>Handbook"
2820 "</emphasis> that covers the basics.</para>"));
2823 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings
))
2824 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window "
2825 "that lists the <emphasis>keyboard shortcuts</emphasis>.<nl/>"
2826 "There you can set up key combinations to trigger an action when "
2827 "they are pressed simultaneously. All commands in this application can "
2828 "be triggered this way.</para>"));
2829 actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars
))
2830 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window in which "
2831 "you can change which buttons appear on the <emphasis>Toolbar</emphasis>.</para>"
2832 "<para>All items you see in the <interface>Menu</interface> can also be placed on the Toolbar.</para>"));
2833 actionCollection()->action(KStandardAction::name(KStandardAction::Preferences
))
2834 ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window where you can "
2835 "change a multitude of settings for this application. For an explanation "
2836 "of the various settings go to the chapter <emphasis>Configuring Dolphin"
2837 "</emphasis> in <interface>Help|Dolphin Handbook</interface>."));
2841 auto setStandardActionWhatsThis
= [this](KStandardAction::StandardAction actionId
,
2842 const QString
&whatsThis
) {
2843 // Check for the existence of an action since it can be restricted through the Kiosk system
2844 if (auto *action
= actionCollection()->action(KStandardAction::name(actionId
))) {
2845 action
->setWhatsThis(whatsThis
);
2849 // i18n: If the external link isn't available in your language it might make
2850 // sense to state the external link's language in brackets to not
2851 // frustrate the user. If there are multiple languages that the user might
2852 // know with a reasonable chance you might want to have 2 external links.
2853 // The same might be true for any external link you translate.
2854 setStandardActionWhatsThis(KStandardAction::HelpContents
, xi18nc("@info:whatsthis handbook", "<para>This opens the Handbook for this application. It provides explanations for every part of <emphasis>Dolphin</emphasis>.</para><para>If you want more elaborate introductions to the different features of <emphasis>Dolphin</emphasis> <link url='https://userbase.kde.org/Dolphin/File_Management'>click here</link>. It will open the dedicated page in the KDE UserBase Wiki.</para>"));
2855 // (The i18n call should be completely in the line following the i18n: comment without any line breaks within the i18n call or the comment might not be correctly extracted. See: https://commits.kde.org/kxmlgui/a31135046e1b3335b5d7bbbe6aa9a883ce3284c1 )
2857 setStandardActionWhatsThis(KStandardAction::WhatsThis
,
2858 xi18nc("@info:whatsthis whatsthis button",
2859 "<para>This is the button that invokes the help feature you are "
2860 "using right now! Click it, then click any component of this "
2861 "application to ask \"What's this?\" about it. The mouse cursor "
2862 "will change appearance if no help is available for a spot.</para>"
2863 "<para>There are two other ways to get help: "
2864 "The <link url='help:/dolphin/index.html'>Dolphin Handbook</link> and "
2865 "the <link url='https://userbase.kde.org/Dolphin/File_Management'>KDE "
2866 "UserBase Wiki</link>.</para><para>The \"What's this?\" help is "
2867 "missing in most other windows so don't get too used to this.</para>"));
2869 setStandardActionWhatsThis(KStandardAction::ReportBug
,
2870 xi18nc("@info:whatsthis","<para>This opens a "
2871 "window that will guide you through reporting errors or flaws "
2872 "in this application or in other KDE software.</para>"
2873 "<para>High-quality bug reports are much appreciated. To learn "
2874 "how to make your bug report as effective as possible "
2875 "<link url='https://community.kde.org/Get_Involved/Bug_Reporting'>"
2876 "click here</link>.</para>"));
2878 setStandardActionWhatsThis(KStandardAction::Donate
,
2879 xi18nc("@info:whatsthis", "<para>This opens a "
2880 "<emphasis>web page</emphasis> where you can donate to "
2881 "support the continued work on this application and many "
2882 "other projects by the <emphasis>KDE</emphasis> community.</para>"
2883 "<para>Donating is the easiest and fastest way to efficiently "
2884 "support KDE and its projects. KDE projects are available for "
2885 "free therefore your donation is needed to cover things that "
2886 "require money like servers, contributor meetings, etc.</para>"
2887 "<para><emphasis>KDE e.V.</emphasis> is the non-profit "
2888 "organization behind the KDE community.</para>"));
2890 setStandardActionWhatsThis(KStandardAction::SwitchApplicationLanguage
,
2891 xi18nc("@info:whatsthis",
2892 "With this you can change the language this application uses."
2893 "<nl/>You can even set secondary languages which will be used "
2894 "if texts are not available in your preferred language."));
2896 setStandardActionWhatsThis(KStandardAction::AboutApp
,
2897 xi18nc("@info:whatsthis","This opens a "
2898 "window that informs you about the version, license, "
2899 "used libraries and maintainers of this application."));
2901 setStandardActionWhatsThis(KStandardAction::AboutKDE
,
2902 xi18nc("@info:whatsthis","This opens a "
2903 "window with information about <emphasis>KDE</emphasis>. "
2904 "The KDE community are the people behind this free software."
2905 "<nl/>If you like using this application but don't know "
2906 "about KDE or want to see a cute dragon have a look!"));
2910 bool DolphinMainWindow::addHamburgerMenuToToolbar()
2912 QDomDocument domDocument
= KXMLGUIClient::domDocument();
2913 if (domDocument
.isNull()) {
2916 QDomNode toolbar
= domDocument
.elementsByTagName(QStringLiteral("ToolBar")).at(0);
2917 if (toolbar
.isNull()) {
2921 QDomElement hamburgerMenuElement
= domDocument
.createElement(QStringLiteral("Action"));
2922 hamburgerMenuElement
.setAttribute(QStringLiteral("name"), QStringLiteral("hamburger_menu"));
2923 toolbar
.appendChild(hamburgerMenuElement
);
2925 KXMLGUIFactory::saveConfigFile(domDocument
, xmlFile());
2929 // Make sure to also remove the <KXMLGUIFactory> and <QDomDocument> include
2930 // whenever this method is removed (maybe in the year ~2026).
2933 // Set a sane initial window size
2934 QSize
DolphinMainWindow::sizeHint() const
2936 return KXmlGuiWindow::sizeHint().expandedTo(QSize(760, 550));
2939 void DolphinMainWindow::saveNewToolbarConfig()
2941 KXmlGuiWindow::saveNewToolbarConfig(); // Applies the new config. This has to be called first
2942 // because the rest of this method decides things
2943 // based on the new config.
2944 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2945 if (!toolBar()->actions().contains(navigators
)) {
2946 m_tabWidget
->currentTabPage()->insertNavigatorsWidget(navigators
);
2948 updateAllowedToolbarAreas();
2949 (static_cast<KHamburgerMenu
*>(actionCollection()->action(KStandardAction::name(KStandardAction::HamburgerMenu
))))->hideActionsOf(toolBar());
2952 void DolphinMainWindow::toggleTerminalPanelFocus()
2954 if (!m_terminalPanel
->isVisible()) {
2955 actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger(); // Also moves focus to the panel.
2956 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2960 if (m_terminalPanel
->terminalHasFocus()) {
2961 m_activeViewContainer
->view()->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2962 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2966 m_terminalPanel
->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2967 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2970 void DolphinMainWindow::togglePlacesPanelFocus()
2972 if (!m_placesPanel
->isVisible()) {
2973 actionCollection()->action(QStringLiteral("show_places_panel"))->trigger(); // Also moves focus to the panel.
2974 actionCollection()->action(QStringLiteral("focus_places_panel"))->setText(i18nc("@action:inmenu View", "Defocus Terminal Panel"));
2978 if (m_placesPanel
->hasFocus()) {
2979 m_activeViewContainer
->view()->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2980 actionCollection()->action(QStringLiteral("focus_places_panel"))->setText(i18nc("@action:inmenu View", "Focus Places Panel"));
2984 m_placesPanel
->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2985 actionCollection()->action(QStringLiteral("focus_places_panel"))->setText(i18nc("@action:inmenu View", "Defocus Places Panel"));
2988 DolphinMainWindow::UndoUiInterface::UndoUiInterface()
2989 : KIO::FileUndoManager::UiInterface()
2993 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2997 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
*job
)
2999 DolphinMainWindow
*mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
3001 DolphinViewContainer
*container
= mainWin
->activeViewContainer();
3002 container
->showMessage(job
->errorString(), KMessageWidget::Error
);
3004 KIO::FileUndoManager::UiInterface::jobError(job
);
3008 bool DolphinMainWindow::isUrlOpen(const QString
&url
)
3010 return m_tabWidget
->isUrlOpen(QUrl::fromUserInput(url
));
3013 bool DolphinMainWindow::isItemVisibleInAnyView(const QString
&urlOfItem
)
3015 return m_tabWidget
->isItemVisibleInAnyView(QUrl::fromUserInput(urlOfItem
));
3018 void DolphinMainWindow::slotDoubleClickViewBackground(Qt::MouseButton button
)
3020 if (button
!= Qt::MouseButton::LeftButton
) {
3021 // only handle left mouse button for now
3025 GeneralSettings
*settings
= GeneralSettings::self();
3026 QString clickAction
= settings
->doubleClickViewAction();
3028 DolphinView
*view
= activeViewContainer()->view();
3029 if (view
== nullptr || clickAction
== "none") {
3033 if (clickAction
== customCommand
) {
3034 // run custom command set by the user
3035 QString path
= view
->url().toLocalFile();
3036 QString clickCustomAction
= settings
->doubleClickViewCustomAction();
3037 clickCustomAction
.replace("{path}", path
.prepend('"').append('"'));
3039 m_job
= new KIO::CommandLauncherJob(clickCustomAction
);
3040 m_job
->setUiDelegate(new KDialogJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
3044 // get the action set by the user and trigger it
3045 const KActionCollection
*actions
= actionCollection();
3046 QAction
*action
= actions
->action(clickAction
);
3047 if (action
== nullptr) {
3048 qCWarning(DolphinDebug
) << QStringLiteral("Double-click view: action `%1` was not found").arg(clickAction
);
3055 #include "moc_dolphinmainwindow.cpp"