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 "selectionmode/actiontexthelper.h"
30 #include "settings/dolphinsettingsdialog.h"
31 #include "statusbar/dolphinstatusbar.h"
32 #include "views/dolphinnewfilemenuobserver.h"
33 #include "views/dolphinremoteencoding.h"
34 #include "views/dolphinviewactionhandler.h"
35 #include "views/draganddrophelper.h"
36 #include "views/viewproperties.h"
38 #include <KActionCollection>
39 #include <KActionMenu>
40 #include <KAuthorized>
41 #include <KColorSchemeManager>
44 #include <KDialogJobUiDelegate>
45 #include <KDualAction>
46 #include <KFileItemListProperties>
47 #include <KIO/CommandLauncherJob>
48 #include <KIO/JobUiDelegateFactory>
49 #include <KIO/OpenFileManagerWindowJob>
50 #include <KIO/OpenUrlJob>
51 #include <KJobWidgets>
52 #include <KLocalizedString>
53 #include <KMessageBox>
54 #include <KProtocolInfo>
55 #include <KProtocolManager>
56 #include <KRecentFilesAction>
58 #include <KShortcutsDialog>
59 #include <KStandardAction>
61 #include <KTerminalLauncherJob>
62 #include <KToggleAction>
64 #include <KToolBarPopupAction>
65 #include <KUrlComboBox>
66 #include <KUrlNavigator>
67 #include <KWindowSystem>
68 #include <KXMLGUIFactory>
70 #include <kwidgetsaddons_version.h>
72 #include <QApplication>
74 #include <QCloseEvent>
75 #include <QDesktopServices>
77 #include <QDomDocument>
81 #include <QPushButton>
83 #include <QStandardPaths>
85 #include <QToolButton>
86 #include <QtConcurrentRun>
87 #include <dolphindebug.h>
92 #include <KStartupInfo>
97 // Used for GeneralSettings::version() to determine whether
98 // an updated version of Dolphin is running, so as to migrate
99 // removed/renamed ...etc config entries; increment it in such
101 const int CurrentDolphinVersion
= 202;
102 // The maximum number of entries in the back/forward popup menu
103 const int MaxNumberOfNavigationentries
= 12;
104 // The maximum number of "Go to Tab" shortcuts
105 const int MaxActivateTabShortcuts
= 9;
108 DolphinMainWindow::DolphinMainWindow()
109 : KXmlGuiWindow(nullptr)
110 , m_newFileMenu(nullptr)
111 , m_tabWidget(nullptr)
112 , m_activeViewContainer(nullptr)
113 , m_actionHandler(nullptr)
114 , m_remoteEncoding(nullptr)
116 , m_bookmarkHandler(nullptr)
117 , m_disabledActionNotifier(nullptr)
118 , m_lastHandleUrlOpenJob(nullptr)
119 , m_terminalPanel(nullptr)
120 , m_placesPanel(nullptr)
121 , m_tearDownFromPlacesRequested(false)
122 , m_backAction(nullptr)
123 , m_forwardAction(nullptr)
124 , m_splitViewAction(nullptr)
125 , m_splitViewMenuAction(nullptr)
126 , m_sessionSaveTimer(nullptr)
127 , m_sessionSaveWatcher(nullptr)
128 , m_sessionSaveScheduled(false)
130 Q_INIT_RESOURCE(dolphin
);
132 new MainWindowAdaptor(this);
135 setWindowFlags(Qt::WindowContextHelpButtonHint
);
137 setComponentName(QStringLiteral("dolphin"), QGuiApplication::applicationDisplayName());
138 setObjectName(QStringLiteral("Dolphin#"));
140 setStateConfigGroup("State");
142 #if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
143 new KColorSchemeManager(this); // Sets a sensible color scheme which fixes unreadable icons and text on Windows.
146 connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::errorMessage
, this, &DolphinMainWindow::showErrorMessage
);
148 KIO::FileUndoManager
*undoManager
= KIO::FileUndoManager::self();
149 undoManager
->setUiInterface(new UndoUiInterface());
151 connect(undoManager
, &KIO::FileUndoManager::undoAvailable
, this, &DolphinMainWindow::slotUndoAvailable
);
152 connect(undoManager
, &KIO::FileUndoManager::undoTextChanged
, this, &DolphinMainWindow::slotUndoTextChanged
);
153 connect(undoManager
, &KIO::FileUndoManager::jobRecordingStarted
, this, &DolphinMainWindow::clearStatusBar
);
154 connect(undoManager
, &KIO::FileUndoManager::jobRecordingFinished
, this, &DolphinMainWindow::showCommand
);
156 const bool firstRun
= (GeneralSettings::version() < 200);
158 GeneralSettings::setViewPropsTimestamp(QDateTime::currentDateTime());
161 setAcceptDrops(true);
163 auto *navigatorsWidgetAction
= new DolphinNavigatorsWidgetAction(this);
164 actionCollection()->addAction(QStringLiteral("url_navigators"), navigatorsWidgetAction
);
165 m_tabWidget
= new DolphinTabWidget(navigatorsWidgetAction
, this);
166 m_tabWidget
->setObjectName("tabWidget");
167 connect(m_tabWidget
, &DolphinTabWidget::activeViewChanged
, this, &DolphinMainWindow::activeViewChanged
);
168 connect(m_tabWidget
, &DolphinTabWidget::tabCountChanged
, this, &DolphinMainWindow::tabCountChanged
);
169 connect(m_tabWidget
, &DolphinTabWidget::currentUrlChanged
, this, &DolphinMainWindow::updateWindowTitle
);
170 setCentralWidget(m_tabWidget
);
172 m_actionTextHelper
= new SelectionMode::ActionTextHelper(this);
175 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), m_actionTextHelper
, this);
176 connect(m_actionHandler
, &DolphinViewActionHandler::actionBeingHandled
, this, &DolphinMainWindow::clearStatusBar
);
177 connect(m_actionHandler
, &DolphinViewActionHandler::createDirectoryTriggered
, this, &DolphinMainWindow::createDirectory
);
178 connect(m_actionHandler
, &DolphinViewActionHandler::selectionModeChangeTriggered
, this, &DolphinMainWindow::slotSetSelectionMode
);
180 Q_CHECK_PTR(actionCollection()->action(QStringLiteral("create_dir")));
181 m_newFileMenu
->setNewFolderShortcutAction(actionCollection()->action(QStringLiteral("create_dir")));
183 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
184 connect(this, &DolphinMainWindow::urlChanged
, m_remoteEncoding
, &DolphinRemoteEncoding::slotAboutToOpenUrl
);
186 m_disabledActionNotifier
= new DisabledActionNotifier(this);
187 connect(m_disabledActionNotifier
, &DisabledActionNotifier::disabledActionTriggered
, this, [this](const QAction
*, QString reason
) {
188 m_activeViewContainer
->showMessage(reason
, KMessageWidget::Warning
);
193 setupGUI(Save
| Create
| ToolBar
);
194 stateChanged(QStringLiteral("new_file"));
196 QClipboard
*clipboard
= QApplication::clipboard();
197 connect(clipboard
, &QClipboard::dataChanged
, this, &DolphinMainWindow::updatePasteAction
);
199 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
200 toggleFilterBarAction
->setChecked(GeneralSettings::filterBar());
203 menuBar()->setVisible(false);
206 const bool showMenu
= !menuBar()->isHidden();
207 QAction
*showMenuBarAction
= actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar
));
208 showMenuBarAction
->setChecked(showMenu
); // workaround for bug #171080
210 auto hamburgerMenu
= static_cast<KHamburgerMenu
*>(actionCollection()->action(KStandardAction::name(KStandardAction::HamburgerMenu
)));
211 hamburgerMenu
->setMenuBar(menuBar());
212 hamburgerMenu
->setShowMenuBarAction(showMenuBarAction
);
213 connect(hamburgerMenu
, &KHamburgerMenu::aboutToShowMenu
, this, &DolphinMainWindow::updateHamburgerMenu
);
214 hamburgerMenu
->hideActionsOf(toolBar());
215 if (GeneralSettings::version() < 201 && !toolBar()->actions().contains(hamburgerMenu
)) {
216 addHamburgerMenuToToolbar();
219 updateAllowedToolbarAreas();
221 // enable middle-click on back/forward/up to open in a new tab
222 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
223 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotToolBarActionMiddleClicked
);
224 toolBar()->installEventFilter(middleClickEventFilter
);
228 connect(KSycoca::self(), &KSycoca::databaseChanged
, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
230 QTimer::singleShot(0, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
232 m_fileItemActions
.setParentWidget(this);
233 connect(&m_fileItemActions
, &KFileItemActions::error
, this, [this](const QString
&errorMessage
) {
234 showErrorMessage(errorMessage
);
237 connect(GeneralSettings::self(), &GeneralSettings::splitViewChanged
, this, &DolphinMainWindow::slotSplitViewChanged
);
240 DolphinMainWindow::~DolphinMainWindow()
242 // This fixes a crash on Wayland when closing the mainwindow while another dialog is open.
243 disconnect(QGuiApplication::clipboard(), &QClipboard::dataChanged
, this, &DolphinMainWindow::updatePasteAction
);
245 // This fixes a crash in dolphinmainwindowtest where the connection below fires even though the KMainWindow destructor of this object is already running.
246 Q_CHECK_PTR(qobject_cast
<DolphinDockWidget
*>(m_placesPanel
->parent()));
247 disconnect(static_cast<DolphinDockWidget
*>(m_placesPanel
->parent()),
248 &DolphinDockWidget::visibilityChanged
,
250 &DolphinMainWindow::slotPlacesPanelVisibilityChanged
);
253 QVector
<DolphinViewContainer
*> DolphinMainWindow::viewContainers() const
255 QVector
<DolphinViewContainer
*> viewContainers
;
257 for (int i
= 0; i
< m_tabWidget
->count(); ++i
) {
258 DolphinTabPage
*tabPage
= m_tabWidget
->tabPageAt(i
);
260 viewContainers
<< tabPage
->primaryViewContainer();
261 if (tabPage
->splitViewEnabled()) {
262 viewContainers
<< tabPage
->secondaryViewContainer();
265 return viewContainers
;
268 void DolphinMainWindow::openDirectories(const QList
<QUrl
> &dirs
, bool splitView
)
270 m_tabWidget
->openDirectories(dirs
, splitView
);
273 void DolphinMainWindow::openDirectories(const QStringList
&dirs
, bool splitView
)
275 openDirectories(QUrl::fromStringList(dirs
), splitView
);
278 void DolphinMainWindow::openFiles(const QList
<QUrl
> &files
, bool splitView
)
280 m_tabWidget
->openFiles(files
, splitView
);
283 bool DolphinMainWindow::isFoldersPanelEnabled() const
285 return actionCollection()->action(QStringLiteral("show_folders_panel"))->isChecked();
288 bool DolphinMainWindow::isInformationPanelEnabled() const
291 return actionCollection()->action(QStringLiteral("show_information_panel"))->isChecked();
297 bool DolphinMainWindow::isSplitViewEnabledInCurrentTab() const
299 return m_tabWidget
->currentTabPage()->splitViewEnabled();
302 void DolphinMainWindow::openFiles(const QStringList
&files
, bool splitView
)
304 openFiles(QUrl::fromStringList(files
), splitView
);
307 void DolphinMainWindow::activateWindow(const QString
&activationToken
)
309 window()->setAttribute(Qt::WA_NativeWindow
, true);
311 if (KWindowSystem::isPlatformWayland()) {
312 KWindowSystem::setCurrentXdgActivationToken(activationToken
);
313 } else if (KWindowSystem::isPlatformX11()) {
315 KStartupInfo::setNewStartupId(window()->windowHandle(), activationToken
.toUtf8());
319 KWindowSystem::activateWindow(window()->windowHandle());
322 bool DolphinMainWindow::isActiveWindow()
324 return window()->isActiveWindow();
327 void DolphinMainWindow::showCommand(CommandType command
)
329 DolphinStatusBar
*statusBar
= m_activeViewContainer
->statusBar();
331 case KIO::FileUndoManager::Copy
:
332 statusBar
->setText(i18nc("@info:status", "Successfully copied."));
334 case KIO::FileUndoManager::Move
:
335 statusBar
->setText(i18nc("@info:status", "Successfully moved."));
337 case KIO::FileUndoManager::Link
:
338 statusBar
->setText(i18nc("@info:status", "Successfully linked."));
340 case KIO::FileUndoManager::Trash
:
341 statusBar
->setText(i18nc("@info:status", "Successfully moved to trash."));
343 case KIO::FileUndoManager::Rename
:
344 statusBar
->setText(i18nc("@info:status", "Successfully renamed."));
347 case KIO::FileUndoManager::Mkdir
:
348 statusBar
->setText(i18nc("@info:status", "Created folder."));
356 void DolphinMainWindow::pasteIntoFolder()
358 m_activeViewContainer
->view()->pasteIntoFolder();
361 void DolphinMainWindow::changeUrl(const QUrl
&url
)
363 if (!KProtocolManager::supportsListing(url
)) {
364 // The URL navigator only checks for validity, not
365 // if the URL can be listed. An error message is
366 // shown due to DolphinViewContainer::restoreView().
370 m_activeViewContainer
->setUrl(url
);
371 updateFileAndEditActions();
376 // will signal used urls to activities manager, too
377 m_recentFiles
->addUrl(url
);
379 Q_EMIT
urlChanged(url
);
382 void DolphinMainWindow::slotTerminalDirectoryChanged(const QUrl
&url
)
384 if (m_tearDownFromPlacesRequested
&& url
== QUrl::fromLocalFile(QDir::homePath())) {
385 m_placesPanel
->proceedWithTearDown();
386 m_tearDownFromPlacesRequested
= false;
389 m_activeViewContainer
->setAutoGrabFocus(false);
391 m_activeViewContainer
->setAutoGrabFocus(true);
394 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
396 KToggleAction
*editableLocationAction
= static_cast<KToggleAction
*>(actionCollection()->action(QStringLiteral("editable_location")));
397 editableLocationAction
->setChecked(editable
);
400 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
&selection
)
402 updateFileAndEditActions();
404 const int selectedUrlsCount
= m_tabWidget
->currentTabPage()->selectedItemsCount();
406 QAction
*compareFilesAction
= actionCollection()->action(QStringLiteral("compare_files"));
407 if (selectedUrlsCount
== 2) {
408 compareFilesAction
->setEnabled(isKompareInstalled());
410 compareFilesAction
->setEnabled(false);
413 Q_EMIT
selectionChanged(selection
);
416 void DolphinMainWindow::updateHistory()
418 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
419 const int index
= urlNavigator
->historyIndex();
421 QAction
*backAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Back
));
423 backAction
->setToolTip(i18nc("@info", "Go back"));
424 backAction
->setWhatsThis(i18nc("@info:whatsthis go back", "Return to the previously viewed folder."));
425 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
428 QAction
*forwardAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Forward
));
430 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
431 forwardAction
->setWhatsThis(xi18nc("@info:whatsthis go forward", "This undoes a <interface>Go|Back</interface> action."));
432 forwardAction
->setEnabled(index
> 0);
436 void DolphinMainWindow::updateFilterBarAction(bool show
)
438 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
439 toggleFilterBarAction
->setChecked(show
);
442 void DolphinMainWindow::openNewMainWindow()
444 Dolphin::openNewWindow({m_activeViewContainer
->url()}, this);
447 void DolphinMainWindow::openNewActivatedTab()
449 // keep browsers compatibility, new tab is always after last one
450 auto openNewTabAfterLastTabConfigured
= GeneralSettings::openNewTabAfterLastTab();
451 GeneralSettings::setOpenNewTabAfterLastTab(true);
452 m_tabWidget
->openNewActivatedTab();
453 GeneralSettings::setOpenNewTabAfterLastTab(openNewTabAfterLastTabConfigured
);
456 void DolphinMainWindow::addToPlaces()
461 // If nothing is selected, act on the current dir
462 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
463 url
= m_activeViewContainer
->url();
464 name
= m_activeViewContainer
->placesText();
466 const auto dirToAdd
= m_activeViewContainer
->view()->selectedItems().first();
467 url
= dirToAdd
.url();
468 name
= dirToAdd
.name();
472 if (m_activeViewContainer
->isSearchModeEnabled()) {
473 icon
= QStringLiteral("folder-saved-search-symbolic");
475 icon
= KIO::iconNameForUrl(url
);
477 DolphinPlacesModelSingleton::instance().placesModel()->addPlace(name
, url
, icon
);
481 void DolphinMainWindow::openNewTab(const QUrl
&url
)
483 m_tabWidget
->openNewTab(url
, QUrl());
486 void DolphinMainWindow::openNewTabAndActivate(const QUrl
&url
)
488 m_tabWidget
->openNewActivatedTab(url
, QUrl());
491 void DolphinMainWindow::openNewWindow(const QUrl
&url
)
493 Dolphin::openNewWindow({url
}, this);
496 void DolphinMainWindow::slotSplitViewChanged()
498 m_tabWidget
->currentTabPage()->setSplitViewEnabled(GeneralSettings::splitView(), WithAnimation
);
499 updateSplitActions();
502 void DolphinMainWindow::openInNewTab()
504 const KFileItemList
&list
= m_activeViewContainer
->view()->selectedItems();
505 bool tabCreated
= false;
507 for (const KFileItem
&item
: list
) {
508 const QUrl
&url
= DolphinView::openItemAsFolderUrl(item
);
509 if (!url
.isEmpty()) {
515 // if no new tab has been created from the selection
516 // open the current directory in a new tab
518 openNewTab(m_activeViewContainer
->url());
522 void DolphinMainWindow::openInNewWindow()
526 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
527 if (list
.isEmpty()) {
528 newWindowUrl
= m_activeViewContainer
->url();
529 } else if (list
.count() == 1) {
530 const KFileItem
&item
= list
.first();
531 newWindowUrl
= DolphinView::openItemAsFolderUrl(item
);
534 if (!newWindowUrl
.isEmpty()) {
535 Dolphin::openNewWindow({newWindowUrl
}, this);
539 void DolphinMainWindow::openInSplitView(const QUrl
&url
)
541 QUrl newSplitViewUrl
= url
;
543 if (newSplitViewUrl
.isEmpty()) {
544 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
545 if (list
.count() == 1) {
546 const KFileItem
&item
= list
.first();
547 newSplitViewUrl
= DolphinView::openItemAsFolderUrl(item
);
551 if (newSplitViewUrl
.isEmpty()) {
555 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
556 if (tabPage
->splitViewEnabled()) {
557 tabPage
->switchActiveView();
558 tabPage
->activeViewContainer()->setUrl(newSplitViewUrl
);
560 tabPage
->setSplitViewEnabled(true, WithAnimation
, newSplitViewUrl
);
565 void DolphinMainWindow::showTarget()
567 const KFileItem link
= m_activeViewContainer
->view()->selectedItems().at(0);
568 const QUrl destinationUrl
= link
.url().resolved(QUrl(link
.linkDest()));
570 auto job
= KIO::stat(destinationUrl
, KIO::StatJob::SourceSide
, KIO::StatNoDetails
);
572 connect(job
, &KJob::finished
, this, [this, destinationUrl
](KJob
*job
) {
573 KIO::StatJob
*statJob
= static_cast<KIO::StatJob
*>(job
);
575 if (statJob
->error()) {
576 m_activeViewContainer
->showMessage(job
->errorString(), KMessageWidget::Error
);
578 KIO::highlightInFileManager({destinationUrl
});
583 bool DolphinMainWindow::event(QEvent
*event
)
585 if (event
->type() == QEvent::ShortcutOverride
) {
586 const QKeyEvent
*keyEvent
= static_cast<QKeyEvent
*>(event
);
587 if (keyEvent
->key() == Qt::Key_Space
&& m_activeViewContainer
->view()->handleSpaceAsNormalKey()) {
593 return KXmlGuiWindow::event(event
);
596 void DolphinMainWindow::showEvent(QShowEvent
*event
)
598 KXmlGuiWindow::showEvent(event
);
600 if (!event
->spontaneous() && m_activeViewContainer
) {
601 m_activeViewContainer
->view()->setFocus();
605 void DolphinMainWindow::closeEvent(QCloseEvent
*event
)
607 // Find out if Dolphin is closed directly by the user or
608 // by the session manager because the session is closed
609 bool closedByUser
= true;
610 if (qApp
->isSavingSession()) {
611 closedByUser
= false;
614 if (m_tabWidget
->count() > 1 && GeneralSettings::confirmClosingMultipleTabs() && !GeneralSettings::rememberOpenedTabs() && closedByUser
) {
615 // Ask the user if he really wants to quit and close all tabs.
616 // Open a confirmation dialog with 3 buttons:
617 // QDialogButtonBox::Yes -> Quit
618 // QDialogButtonBox::No -> Close only the current tab
619 // QDialogButtonBox::Cancel -> do nothing
620 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
621 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
622 dialog
->setModal(true);
623 QDialogButtonBox
*buttons
= new QDialogButtonBox(QDialogButtonBox::Yes
| QDialogButtonBox::No
| QDialogButtonBox::Cancel
);
624 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
),
625 KGuiItem(i18nc("@action:button 'Quit Dolphin' button", "&Quit %1", QGuiApplication::applicationDisplayName()),
626 QIcon::fromTheme(QStringLiteral("application-exit"))));
627 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("C&lose Current Tab"), QIcon::fromTheme(QStringLiteral("tab-close"))));
628 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
629 buttons
->button(QDialogButtonBox::Yes
)->setDefault(true);
631 bool doNotAskAgainCheckboxResult
= false;
633 const auto result
= KMessageBox::createKMessageBox(dialog
,
635 QMessageBox::Warning
,
636 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
638 i18n("Do not ask again"),
639 &doNotAskAgainCheckboxResult
,
640 KMessageBox::Notify
);
642 if (doNotAskAgainCheckboxResult
) {
643 GeneralSettings::setConfirmClosingMultipleTabs(false);
647 case QDialogButtonBox::Yes
:
650 case QDialogButtonBox::No
:
651 // Close only the current tab
652 m_tabWidget
->closeTab();
660 if (m_terminalPanel
&& m_terminalPanel
->hasProgramRunning() && GeneralSettings::confirmClosingTerminalRunningProgram() && closedByUser
) {
661 // Ask if the user really wants to quit Dolphin with a program that is still running in the Terminal panel
662 // Open a confirmation dialog with 3 buttons:
663 // QDialogButtonBox::Yes -> Quit
664 // QDialogButtonBox::No -> Show Terminal Panel
665 // QDialogButtonBox::Cancel -> do nothing
666 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
667 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
668 dialog
->setModal(true);
669 auto standardButtons
= QDialogButtonBox::Yes
| QDialogButtonBox::Cancel
;
670 if (!m_terminalPanel
->isVisible()) {
671 standardButtons
|= QDialogButtonBox::No
;
673 QDialogButtonBox
*buttons
= new QDialogButtonBox(standardButtons
);
674 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KStandardGuiItem::quit());
675 if (!m_terminalPanel
->isVisible()) {
676 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("Show &Terminal Panel"), QIcon::fromTheme(QStringLiteral("dialog-scripts"))));
678 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
680 bool doNotAskAgainCheckboxResult
= false;
682 const auto result
= KMessageBox::createKMessageBox(
685 QMessageBox::Warning
,
686 i18n("The program '%1' is still running in the Terminal panel. Are you sure you want to quit?", m_terminalPanel
->runningProgramName()),
688 i18n("Do not ask again"),
689 &doNotAskAgainCheckboxResult
,
690 KMessageBox::Notify
| KMessageBox::Dangerous
);
692 if (doNotAskAgainCheckboxResult
) {
693 GeneralSettings::setConfirmClosingTerminalRunningProgram(false);
697 case QDialogButtonBox::Yes
:
700 case QDialogButtonBox::No
:
701 actionCollection()->action("show_terminal_panel")->trigger();
702 // Do not quit, ignore quit event
710 if (m_sessionSaveTimer
&& (m_sessionSaveTimer
->isActive() || m_sessionSaveWatcher
->isRunning())) {
711 const bool sessionSaveTimerActive
= m_sessionSaveTimer
->isActive();
713 m_sessionSaveTimer
->stop();
714 m_sessionSaveWatcher
->disconnect();
715 m_sessionSaveWatcher
->waitForFinished();
717 if (sessionSaveTimerActive
|| m_sessionSaveScheduled
) {
722 GeneralSettings::setVersion(CurrentDolphinVersion
);
723 GeneralSettings::self()->save();
725 KXmlGuiWindow::closeEvent(event
);
728 void DolphinMainWindow::slotSaveSession()
730 m_sessionSaveScheduled
= false;
732 if (m_sessionSaveWatcher
->isRunning()) {
733 // The previous session is still being saved - schedule another save.
734 m_sessionSaveWatcher
->disconnect();
735 connect(m_sessionSaveWatcher
, &QFutureWatcher
<void>::finished
, this, &DolphinMainWindow::slotSaveSession
, Qt::SingleShotConnection
);
736 m_sessionSaveScheduled
= true;
737 } else if (!m_sessionSaveTimer
->isActive()) {
738 // No point in saving the session if the timer is running (since it will save the session again when it times out).
739 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
740 KConfig
*config
= KConfigGui::sessionConfig();
741 saveGlobalProperties(config
);
742 savePropertiesInternal(config
, 1);
744 auto future
= QtConcurrent::run([config
]() {
747 m_sessionSaveWatcher
->setFuture(future
);
751 void DolphinMainWindow::setSessionAutoSaveEnabled(bool enable
)
754 if (!m_sessionSaveTimer
) {
755 m_sessionSaveTimer
= new QTimer(this);
756 m_sessionSaveWatcher
= new QFutureWatcher
<void>(this);
757 m_sessionSaveTimer
->setSingleShot(true);
758 m_sessionSaveTimer
->setInterval(22000);
760 connect(m_sessionSaveTimer
, &QTimer::timeout
, this, &DolphinMainWindow::slotSaveSession
);
763 connect(m_tabWidget
, &DolphinTabWidget::urlChanged
, m_sessionSaveTimer
, qOverload
<>(&QTimer::start
), Qt::UniqueConnection
);
764 connect(m_tabWidget
, &DolphinTabWidget::tabCountChanged
, m_sessionSaveTimer
, qOverload
<>(&QTimer::start
), Qt::UniqueConnection
);
765 connect(m_tabWidget
, &DolphinTabWidget::activeViewChanged
, m_sessionSaveTimer
, qOverload
<>(&QTimer::start
), Qt::UniqueConnection
);
766 } else if (m_sessionSaveTimer
) {
767 m_sessionSaveTimer
->stop();
768 m_sessionSaveWatcher
->disconnect();
769 m_sessionSaveScheduled
= false;
771 m_sessionSaveWatcher
->waitForFinished();
773 m_sessionSaveTimer
->deleteLater();
774 m_sessionSaveWatcher
->deleteLater();
775 m_sessionSaveTimer
= nullptr;
776 m_sessionSaveWatcher
= nullptr;
780 void DolphinMainWindow::saveProperties(KConfigGroup
&group
)
782 m_tabWidget
->saveProperties(group
);
785 void DolphinMainWindow::readProperties(const KConfigGroup
&group
)
787 m_tabWidget
->readProperties(group
);
790 void DolphinMainWindow::updateNewMenu()
792 m_newFileMenu
->checkUpToDate();
793 m_newFileMenu
->setWorkingDirectory(activeViewContainer()->url());
796 void DolphinMainWindow::createDirectory()
798 // When creating directory, namejob is being run. In network folders,
799 // this job can take long time, so instead of starting multiple namejobs,
800 // just check if we are already running one. This prevents opening multiple
801 // dialogs. BUG:481401
802 if (!m_newFileMenu
->isCreateDirectoryRunning()) {
803 m_newFileMenu
->setWorkingDirectory(activeViewContainer()->url());
804 m_newFileMenu
->createDirectory();
808 void DolphinMainWindow::quit()
813 void DolphinMainWindow::showErrorMessage(const QString
&message
)
815 m_activeViewContainer
->showMessage(message
, KMessageWidget::Error
);
818 void DolphinMainWindow::slotUndoAvailable(bool available
)
820 QAction
*undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
822 undoAction
->setEnabled(available
);
826 void DolphinMainWindow::slotUndoTextChanged(const QString
&text
)
828 QAction
*undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
830 undoAction
->setText(text
);
834 void DolphinMainWindow::undo()
837 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
838 KIO::FileUndoManager::self()->undo();
841 void DolphinMainWindow::cut()
843 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
844 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CutContents
);
846 m_activeViewContainer
->view()->cutSelectedItemsToClipboard();
847 m_activeViewContainer
->setSelectionModeEnabled(false);
851 void DolphinMainWindow::copy()
853 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
854 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CopyContents
);
856 m_activeViewContainer
->view()->copySelectedItemsToClipboard();
857 m_activeViewContainer
->setSelectionModeEnabled(false);
861 void DolphinMainWindow::paste()
863 m_activeViewContainer
->view()->paste();
866 void DolphinMainWindow::find()
868 m_activeViewContainer
->setSearchModeEnabled(true);
871 void DolphinMainWindow::updateSearchAction()
873 QAction
*toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
874 toggleSearchAction
->setChecked(m_activeViewContainer
->isSearchModeEnabled());
877 void DolphinMainWindow::updatePasteAction()
879 QAction
*pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
880 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
881 pasteAction
->setEnabled(pasteInfo
.first
);
882 m_disabledActionNotifier
->setDisabledReason(pasteAction
,
883 m_activeViewContainer
->rootItem().isWritable()
884 ? i18nc("@info", "Cannot paste: The clipboard is empty.")
885 : i18nc("@info", "Cannot paste: You do not have permission to write into this folder."));
886 pasteAction
->setText(pasteInfo
.second
);
889 void DolphinMainWindow::slotDirectoryLoadingCompleted()
894 void DolphinMainWindow::slotToolBarActionMiddleClicked(QAction
*action
)
896 if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Back
))) {
898 } else if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Forward
))) {
900 } else if (action
== actionCollection()->action(QStringLiteral("go_up"))) {
902 } else if (action
== actionCollection()->action(QStringLiteral("go_home"))) {
907 QAction
*DolphinMainWindow::urlNavigatorHistoryAction(const KUrlNavigator
*urlNavigator
, int historyIndex
, QObject
*parent
)
909 const QUrl url
= urlNavigator
->locationUrl(historyIndex
);
911 QString text
= url
.toDisplayString(QUrl::PreferLocalFile
);
913 if (!urlNavigator
->showFullPath()) {
914 const KFilePlacesModel
*placesModel
= DolphinPlacesModelSingleton::instance().placesModel();
916 const QModelIndex closestIdx
= placesModel
->closestItem(url
);
917 if (closestIdx
.isValid()) {
918 const QUrl placeUrl
= placesModel
->url(closestIdx
);
920 text
= placesModel
->text(closestIdx
);
922 QString pathInsidePlace
= url
.path().mid(placeUrl
.path().length());
924 if (!pathInsidePlace
.isEmpty() && !pathInsidePlace
.startsWith(QLatin1Char('/'))) {
925 pathInsidePlace
.prepend(QLatin1Char('/'));
928 if (pathInsidePlace
!= QLatin1Char('/')) {
929 text
.append(pathInsidePlace
);
934 QAction
*action
= new QAction(QIcon::fromTheme(KIO::iconNameForUrl(url
)), text
, parent
);
935 action
->setData(historyIndex
);
939 void DolphinMainWindow::slotAboutToShowBackPopupMenu()
941 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
943 QMenu
*menu
= m_backAction
->popupMenu();
945 for (int i
= urlNavigator
->historyIndex() + 1; i
< urlNavigator
->historySize() && entries
< MaxNumberOfNavigationentries
; ++i
, ++entries
) {
946 QAction
*action
= urlNavigatorHistoryAction(urlNavigator
, i
, menu
);
947 menu
->addAction(action
);
951 void DolphinMainWindow::slotGoBack(QAction
*action
)
953 int gotoIndex
= action
->data().value
<int>();
954 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
955 for (int i
= gotoIndex
- urlNavigator
->historyIndex(); i
> 0; --i
) {
960 void DolphinMainWindow::slotBackForwardActionMiddleClicked(QAction
*action
)
963 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
964 openNewTab(urlNavigator
->locationUrl(action
->data().value
<int>()));
968 void DolphinMainWindow::slotAboutToShowForwardPopupMenu()
970 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
972 QMenu
*menu
= m_forwardAction
->popupMenu();
973 for (int i
= urlNavigator
->historyIndex() - 1; i
>= 0 && entries
< MaxNumberOfNavigationentries
; --i
, ++entries
) {
974 QAction
*action
= urlNavigatorHistoryAction(urlNavigator
, i
, menu
);
975 menu
->addAction(action
);
979 void DolphinMainWindow::slotGoForward(QAction
*action
)
981 int gotoIndex
= action
->data().value
<int>();
982 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
983 for (int i
= urlNavigator
->historyIndex() - gotoIndex
; i
> 0; --i
) {
988 void DolphinMainWindow::slotSetSelectionMode(bool enabled
, SelectionMode::BottomBar::Contents bottomBarContents
)
990 m_activeViewContainer
->setSelectionModeEnabled(enabled
, actionCollection(), bottomBarContents
);
993 void DolphinMainWindow::selectAll()
997 // if the URL navigator is editable and focused, select the whole
998 // URL instead of all items of the view
1000 KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigator();
1001 QLineEdit
*lineEdit
= urlNavigator
->editor()->lineEdit();
1002 const bool selectUrl
= urlNavigator
->isUrlEditable() && lineEdit
->hasFocus();
1004 lineEdit
->selectAll();
1006 m_activeViewContainer
->view()->selectAll();
1010 void DolphinMainWindow::invertSelection()
1013 m_activeViewContainer
->view()->invertSelection();
1016 void DolphinMainWindow::toggleSplitView()
1018 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
1019 tabPage
->setSplitViewEnabled(!tabPage
->splitViewEnabled(), WithAnimation
);
1020 m_tabWidget
->updateTabName(m_tabWidget
->indexOf(tabPage
));
1021 updateViewActions();
1024 void DolphinMainWindow::popoutSplitView()
1026 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
1027 if (!tabPage
->splitViewEnabled())
1029 openNewWindow((GeneralSettings::closeActiveSplitView() ? tabPage
->activeViewContainer() : tabPage
->inactiveViewContainer())->url());
1030 tabPage
->setSplitViewEnabled(false, WithAnimation
);
1031 updateSplitActions();
1034 void DolphinMainWindow::toggleSplitStash()
1036 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
1037 tabPage
->setSplitViewEnabled(false, WithAnimation
);
1038 tabPage
->setSplitViewEnabled(true, WithAnimation
, QUrl("stash:/"));
1041 void DolphinMainWindow::copyToInactiveSplitView()
1043 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
1044 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CopyToOtherViewContents
);
1046 m_tabWidget
->copyToInactiveSplitView();
1047 m_activeViewContainer
->setSelectionModeEnabled(false);
1051 void DolphinMainWindow::moveToInactiveSplitView()
1053 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
1054 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::MoveToOtherViewContents
);
1056 m_tabWidget
->moveToInactiveSplitView();
1057 m_activeViewContainer
->setSelectionModeEnabled(false);
1061 void DolphinMainWindow::reloadView()
1064 m_activeViewContainer
->reload();
1065 m_activeViewContainer
->statusBar()->updateSpaceInfo();
1068 void DolphinMainWindow::stopLoading()
1070 m_activeViewContainer
->view()->stopLoading();
1073 void DolphinMainWindow::enableStopAction()
1075 actionCollection()->action(QStringLiteral("stop"))->setEnabled(true);
1078 void DolphinMainWindow::disableStopAction()
1080 actionCollection()->action(QStringLiteral("stop"))->setEnabled(false);
1083 void DolphinMainWindow::toggleSelectionMode()
1085 const bool checked
= !m_activeViewContainer
->isSelectionModeEnabled();
1087 m_activeViewContainer
->setSelectionModeEnabled(checked
, actionCollection(), SelectionMode::BottomBar::Contents::GeneralContents
);
1088 actionCollection()->action(QStringLiteral("toggle_selection_mode"))->setChecked(checked
);
1091 void DolphinMainWindow::showFilterBar()
1093 m_activeViewContainer
->setFilterBarVisible(true);
1096 void DolphinMainWindow::toggleFilterBar()
1098 const bool checked
= !m_activeViewContainer
->isFilterBarVisible();
1099 m_activeViewContainer
->setFilterBarVisible(checked
);
1101 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
1102 toggleFilterBarAction
->setChecked(checked
);
1105 void DolphinMainWindow::toggleEditLocation()
1109 QAction
*action
= actionCollection()->action(QStringLiteral("editable_location"));
1110 KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigator();
1111 urlNavigator
->setUrlEditable(action
->isChecked());
1114 void DolphinMainWindow::replaceLocation()
1116 KUrlNavigator
*navigator
= m_activeViewContainer
->urlNavigator();
1117 QLineEdit
*lineEdit
= navigator
->editor()->lineEdit();
1119 // If the text field currently has focus and everything is selected,
1120 // pressing the keyboard shortcut returns the whole thing to breadcrumb mode
1121 if (navigator
->isUrlEditable() && lineEdit
->hasFocus() && lineEdit
->selectedText() == lineEdit
->text()) {
1122 navigator
->setUrlEditable(false);
1124 navigator
->setUrlEditable(true);
1125 navigator
->setFocus();
1126 lineEdit
->selectAll();
1130 void DolphinMainWindow::togglePanelLockState()
1132 const bool newLockState
= !GeneralSettings::lockPanels();
1133 const auto childrenObjects
= children();
1134 for (QObject
*child
: childrenObjects
) {
1135 DolphinDockWidget
*dock
= qobject_cast
<DolphinDockWidget
*>(child
);
1137 dock
->setLocked(newLockState
);
1141 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(newLockState
);
1143 GeneralSettings::setLockPanels(newLockState
);
1146 void DolphinMainWindow::slotTerminalPanelVisibilityChanged(bool visible
)
1148 if (!visible
&& m_activeViewContainer
) {
1149 m_activeViewContainer
->view()->setFocus();
1151 // Putting focus to the Terminal is not handled here but in TerminalPanel::showEvent().
1154 void DolphinMainWindow::slotPlacesPanelVisibilityChanged(bool visible
)
1156 if (!visible
&& m_activeViewContainer
) {
1157 m_activeViewContainer
->view()->setFocus();
1160 m_placesPanel
->setFocus();
1163 void DolphinMainWindow::goBack()
1165 DolphinUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
1166 urlNavigator
->goBack();
1168 if (urlNavigator
->locationState().isEmpty()) {
1169 // An empty location state indicates a redirection URL,
1170 // which must be skipped too
1171 urlNavigator
->goBack();
1175 void DolphinMainWindow::goForward()
1177 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goForward();
1180 void DolphinMainWindow::goUp()
1182 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goUp();
1185 void DolphinMainWindow::goHome()
1187 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goHome();
1190 void DolphinMainWindow::goBackInNewTab()
1192 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
1193 const int index
= urlNavigator
->historyIndex() + 1;
1194 openNewTab(urlNavigator
->locationUrl(index
));
1197 void DolphinMainWindow::goForwardInNewTab()
1199 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
1200 const int index
= urlNavigator
->historyIndex() - 1;
1201 openNewTab(urlNavigator
->locationUrl(index
));
1204 void DolphinMainWindow::goUpInNewTab()
1206 const QUrl currentUrl
= activeViewContainer()->urlNavigator()->locationUrl();
1207 openNewTab(KIO::upUrl(currentUrl
));
1210 void DolphinMainWindow::goHomeInNewTab()
1212 openNewTab(Dolphin::homeUrl());
1215 void DolphinMainWindow::compareFiles()
1217 const KFileItemList items
= m_tabWidget
->currentTabPage()->selectedItems();
1218 if (items
.count() != 2) {
1219 // The action is disabled in this case, but it could have been triggered
1220 // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
1224 QUrl urlA
= items
.at(0).url();
1225 QUrl urlB
= items
.at(1).url();
1227 QString
command(QStringLiteral("kompare -c \""));
1228 command
.append(urlA
.toDisplayString(QUrl::PreferLocalFile
));
1229 command
.append("\" \"");
1230 command
.append(urlB
.toDisplayString(QUrl::PreferLocalFile
));
1231 command
.append('\"');
1233 KIO::CommandLauncherJob
*job
= new KIO::CommandLauncherJob(command
, this);
1234 job
->setDesktopName(QStringLiteral("org.kde.kompare"));
1238 void DolphinMainWindow::toggleShowMenuBar()
1240 const bool visible
= menuBar()->isVisible();
1241 menuBar()->setVisible(!visible
);
1244 QPointer
<QAction
> DolphinMainWindow::preferredSearchTool()
1246 m_searchTools
.clear();
1248 KService::Ptr kfind
= KService::serviceByDesktopName(QStringLiteral("org.kde.kfind"));
1254 auto *action
= new QAction(QIcon::fromTheme(kfind
->icon()), kfind
->name(), this);
1256 connect(action
, &QAction::triggered
, this, [this, kfind
] {
1257 auto *job
= new KIO::ApplicationLauncherJob(kfind
);
1258 job
->setUrls({m_activeViewContainer
->url()});
1265 void DolphinMainWindow::updateOpenPreferredSearchToolAction()
1267 QAction
*openPreferredSearchTool
= actionCollection()->action(QStringLiteral("open_preferred_search_tool"));
1268 if (!openPreferredSearchTool
) {
1271 QPointer
<QAction
> tool
= preferredSearchTool();
1273 openPreferredSearchTool
->setVisible(true);
1274 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open %1", tool
->text()));
1275 // Only override with the app icon if it is the default, i.e. the user hasn't configured one manually
1276 // https://bugs.kde.org/show_bug.cgi?id=442815
1277 if (openPreferredSearchTool
->icon().name() == QLatin1String("search")) {
1278 openPreferredSearchTool
->setIcon(tool
->icon());
1281 openPreferredSearchTool
->setVisible(false);
1282 // still visible in Shortcuts configuration window
1283 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1284 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1288 void DolphinMainWindow::openPreferredSearchTool()
1290 QPointer
<QAction
> tool
= preferredSearchTool();
1296 void DolphinMainWindow::openTerminal()
1298 openTerminalJob(m_activeViewContainer
->url());
1301 void DolphinMainWindow::openTerminalHere()
1303 QList
<QUrl
> urls
= {};
1305 const auto selectedItems
= m_activeViewContainer
->view()->selectedItems();
1306 for (const KFileItem
&item
: selectedItems
) {
1307 QUrl url
= item
.targetUrl();
1308 if (item
.isFile()) {
1309 url
.setPath(QFileInfo(url
.path()).absolutePath());
1311 if (!urls
.contains(url
)) {
1316 // No items are selected. Open a terminal window for the current location.
1317 if (urls
.count() == 0) {
1322 if (urls
.count() > 5) {
1323 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());
1324 const int answer
= KMessageBox::warningContinueCancel(
1328 KGuiItem(i18ncp("@action:button", "Open %1 Terminal", "Open %1 Terminals", urls
.count()), QStringLiteral("utilities-terminal")),
1329 KStandardGuiItem::cancel(),
1330 QStringLiteral("ConfirmOpenManyTerminals"));
1331 if (answer
!= KMessageBox::PrimaryAction
&& answer
!= KMessageBox::Continue
) {
1336 for (const QUrl
&url
: std::as_const(urls
)) {
1337 openTerminalJob(url
);
1341 void DolphinMainWindow::openTerminalJob(const QUrl
&url
)
1343 if (url
.isLocalFile()) {
1344 auto job
= new KTerminalLauncherJob(QString());
1345 job
->setWorkingDirectory(url
.toLocalFile());
1350 // Not a local file, with protocol Class ":local", try stat'ing
1351 if (KProtocolInfo::protocolClass(url
.scheme()) == QLatin1String(":local")) {
1352 KIO::StatJob
*job
= KIO::mostLocalUrl(url
);
1353 KJobWidgets::setWindow(job
, this);
1354 connect(job
, &KJob::result
, this, [job
]() {
1356 if (!job
->error()) {
1357 statUrl
= job
->mostLocalUrl();
1360 auto job
= new KTerminalLauncherJob(QString());
1361 job
->setWorkingDirectory(statUrl
.isLocalFile() ? statUrl
.toLocalFile() : QDir::homePath());
1368 // Nothing worked, just use $HOME
1369 auto job
= new KTerminalLauncherJob(QString());
1370 job
->setWorkingDirectory(QDir::homePath());
1374 void DolphinMainWindow::editSettings()
1376 if (!m_settingsDialog
) {
1377 DolphinViewContainer
*container
= activeViewContainer();
1378 container
->view()->writeSettings();
1380 const QUrl url
= container
->url();
1381 DolphinSettingsDialog
*settingsDialog
= new DolphinSettingsDialog(url
, this, actionCollection());
1382 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, this, &DolphinMainWindow::refreshViews
);
1383 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, &DolphinUrlNavigatorsController::slotReadSettings
);
1384 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1385 settingsDialog
->show();
1386 m_settingsDialog
= settingsDialog
;
1388 m_settingsDialog
.data()->raise();
1392 void DolphinMainWindow::handleUrl(const QUrl
&url
)
1394 delete m_lastHandleUrlOpenJob
;
1395 m_lastHandleUrlOpenJob
= nullptr;
1397 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1398 activeViewContainer()->setUrl(url
);
1400 m_lastHandleUrlOpenJob
= new KIO::OpenUrlJob(url
);
1401 m_lastHandleUrlOpenJob
->setUiDelegate(KIO::createDefaultJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
1402 m_lastHandleUrlOpenJob
->setShowOpenOrExecuteDialog(true);
1404 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::mimeTypeFound
, this, [this, url
](const QString
&mimetype
) {
1405 if (mimetype
== QLatin1String("inode/directory")) {
1406 // If it's a dir, we'll take it from here
1407 m_lastHandleUrlOpenJob
->kill();
1408 m_lastHandleUrlOpenJob
= nullptr;
1409 activeViewContainer()->setUrl(url
);
1413 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::result
, this, [this]() {
1414 m_lastHandleUrlOpenJob
= nullptr;
1417 m_lastHandleUrlOpenJob
->start();
1421 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1423 // trash:/ is writable but we don't want to create new items in it.
1424 // TODO: remove the trash check once https://phabricator.kde.org/T8234 is implemented
1425 newFileMenu()->setEnabled(isFolderWritable
&& m_activeViewContainer
->url().scheme() != QLatin1String("trash"));
1426 // 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.
1427 QTimer::singleShot(0, this, [this]() {
1428 m_disabledActionNotifier
->setDisabledReason(actionCollection()->action(QStringLiteral("create_dir")),
1429 i18nc("@info", "Cannot create new folder: You do not have permission to create items in this folder."));
1433 void DolphinMainWindow::openContextMenu(const QPoint
&pos
, const KFileItem
&item
, const KFileItemList
&selectedItems
, const QUrl
&url
)
1435 QPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, item
, selectedItems
, url
, &m_fileItemActions
);
1436 contextMenu
->exec(pos
);
1438 // Delete the menu, unless it has been deleted in its own nested event loop already.
1440 contextMenu
->deleteLater();
1444 QMenu
*DolphinMainWindow::createPopupMenu()
1446 QMenu
*menu
= KXmlGuiWindow::createPopupMenu();
1448 menu
->addSeparator();
1449 menu
->addAction(actionCollection()->action(QStringLiteral("lock_panels")));
1454 void DolphinMainWindow::updateHamburgerMenu()
1456 KActionCollection
*ac
= actionCollection();
1457 auto hamburgerMenu
= static_cast<KHamburgerMenu
*>(ac
->action(KStandardAction::name(KStandardAction::HamburgerMenu
)));
1458 auto menu
= hamburgerMenu
->menu();
1460 menu
= new QMenu(this);
1461 hamburgerMenu
->setMenu(menu
);
1462 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("basic_actions"))->menu());
1463 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("zoom"))->menu());
1467 const QList
<QAction
*> toolbarActions
= toolBar()->actions();
1469 if (!toolBar()->isVisible()) {
1470 // If neither the menu bar nor the toolbar are visible, these actions should be available.
1471 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)));
1472 menu
->addAction(toolBarMenuAction());
1473 menu
->addSeparator();
1476 // This group of actions (until the next separator) contains all the most basic actions
1477 // necessary to use Dolphin effectively.
1478 menu
->addAction(ac
->action(QStringLiteral("go_back")));
1479 menu
->addAction(ac
->action(QStringLiteral("go_forward")));
1481 menu
->addMenu(m_newFileMenu
->menu());
1482 if (!toolBar()->isVisible() || !toolbarActions
.contains(ac
->action(QStringLiteral("toggle_selection_mode_tool_bar")))) {
1483 menu
->addAction(ac
->action(QStringLiteral("toggle_selection_mode")));
1485 menu
->addAction(ac
->action(QStringLiteral("basic_actions")));
1486 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Undo
)));
1487 if (!toolBar()->isVisible()
1488 || (!toolbarActions
.contains(ac
->action(QStringLiteral("toggle_search")))
1489 && !toolbarActions
.contains(ac
->action(QStringLiteral("open_preferred_search_tool"))))) {
1490 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Find
)));
1491 // This way a search action will only be added if none of the three available
1492 // search actions is present on the toolbar.
1494 if (!toolBar()->isVisible() || !toolbarActions
.contains(ac
->action(QStringLiteral("toggle_filter")))) {
1495 menu
->addAction(ac
->action(QStringLiteral("show_filter_bar")));
1496 // This way a filter action will only be added if none of the two available
1497 // filter actions is present on the toolbar.
1499 menu
->addSeparator();
1501 // The second group of actions (up until the next separator) contains actions for opening
1502 // additional views to interact with the file system.
1503 menu
->addAction(ac
->action(QStringLiteral("file_new")));
1504 menu
->addAction(ac
->action(QStringLiteral("new_tab")));
1505 if (ac
->action(QStringLiteral("undo_close_tab"))->isEnabled()) {
1506 menu
->addAction(ac
->action(QStringLiteral("closed_tabs")));
1508 menu
->addAction(ac
->action(QStringLiteral("open_terminal")));
1509 menu
->addSeparator();
1511 // The third group contains actions to change what one sees in the view
1512 // and to change the more general UI.
1513 if (!toolBar()->isVisible()
1514 || (!toolbarActions
.contains(ac
->action(QStringLiteral("icons"))) && !toolbarActions
.contains(ac
->action(QStringLiteral("compact")))
1515 && !toolbarActions
.contains(ac
->action(QStringLiteral("details"))) && !toolbarActions
.contains(ac
->action(QStringLiteral("view_mode"))))) {
1516 menu
->addAction(ac
->action(QStringLiteral("view_mode")));
1518 menu
->addAction(ac
->action(QStringLiteral("show_hidden_files")));
1519 menu
->addAction(ac
->action(QStringLiteral("sort")));
1520 menu
->addAction(ac
->action(QStringLiteral("group")));
1521 menu
->addAction(ac
->action(QStringLiteral("additional_info")));
1522 if (!GeneralSettings::showStatusBar() || !GeneralSettings::showZoomSlider()) {
1523 menu
->addAction(ac
->action(QStringLiteral("zoom")));
1525 menu
->addAction(ac
->action(QStringLiteral("panels")));
1527 // The "Configure" menu is not added to the actionCollection() because there is hardly
1528 // a good reason for users to put it on their toolbar.
1529 auto configureMenu
= menu
->addMenu(QIcon::fromTheme(QStringLiteral("configure")), i18nc("@action:inmenu menu for configure actions", "Configure"));
1530 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
)));
1531 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)));
1532 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)));
1533 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Preferences
)));
1534 hamburgerMenu
->hideActionsOf(configureMenu
);
1537 void DolphinMainWindow::slotPlaceActivated(const QUrl
&url
)
1539 DolphinViewContainer
*view
= activeViewContainer();
1541 if (view
->url() == url
) {
1542 view
->clearFilterBar(); // Fixes bug 259382.
1544 // We can end up here if the user clicked a device in the Places Panel
1545 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
1548 view
->disableUrlNavigatorSelectionRequests();
1550 view
->enableUrlNavigatorSelectionRequests();
1554 void DolphinMainWindow::closedTabsCountChanged(unsigned int count
)
1556 actionCollection()->action(QStringLiteral("undo_close_tab"))->setEnabled(count
> 0);
1559 void DolphinMainWindow::activeViewChanged(DolphinViewContainer
*viewContainer
)
1561 DolphinViewContainer
*oldViewContainer
= m_activeViewContainer
;
1562 Q_ASSERT(viewContainer
);
1564 m_activeViewContainer
= viewContainer
;
1566 if (oldViewContainer
) {
1567 const QAction
*toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
1568 toggleSearchAction
->disconnect(oldViewContainer
);
1570 // Disconnect all signals between the old view container (container,
1571 // view and url navigator) and main window.
1572 oldViewContainer
->disconnect(this);
1573 oldViewContainer
->view()->disconnect(this);
1574 oldViewContainer
->urlNavigatorInternalWithHistory()->disconnect(this);
1575 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
1576 navigators
->primaryUrlNavigator()->disconnect(this);
1577 if (auto secondaryUrlNavigator
= navigators
->secondaryUrlNavigator()) {
1578 secondaryUrlNavigator
->disconnect(this);
1581 // except the requestItemInfo so that on hover the information panel can still be updated
1582 connect(oldViewContainer
->view(), &DolphinView::requestItemInfo
, this, &DolphinMainWindow::requestItemInfo
);
1584 // Disconnect other slots.
1585 disconnect(oldViewContainer
,
1586 &DolphinViewContainer::selectionModeChanged
,
1587 actionCollection()->action(QStringLiteral("toggle_selection_mode")),
1588 &QAction::setChecked
);
1591 connectViewSignals(viewContainer
);
1593 m_actionHandler
->setCurrentView(viewContainer
->view());
1596 updateFileAndEditActions();
1597 updatePasteAction();
1598 updateViewActions();
1600 updateSearchAction();
1602 const QUrl url
= viewContainer
->url();
1603 Q_EMIT
urlChanged(url
);
1606 void DolphinMainWindow::tabCountChanged(int count
)
1608 const bool enableTabActions
= (count
> 1);
1609 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1610 actionCollection()->action(QStringLiteral("activate_tab_%1").arg(i
))->setEnabled(enableTabActions
);
1612 actionCollection()->action(QStringLiteral("activate_last_tab"))->setEnabled(enableTabActions
);
1613 actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions
);
1614 actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions
);
1617 void DolphinMainWindow::updateWindowTitle()
1619 const QString newTitle
= m_activeViewContainer
->captionWindowTitle();
1620 if (windowTitle() != newTitle
) {
1621 setWindowTitle(newTitle
);
1625 void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString
&mountPath
)
1627 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1628 setViewsToHomeIfMountPathOpen(mountPath
);
1631 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectoryIsChildOf(mountPath
)) {
1632 m_tearDownFromPlacesRequested
= true;
1633 m_terminalPanel
->goHome();
1634 // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged
1636 m_placesPanel
->proceedWithTearDown();
1640 void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString
&mountPath
)
1642 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1643 setViewsToHomeIfMountPathOpen(mountPath
);
1646 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectoryIsChildOf(mountPath
)) {
1647 m_tearDownFromPlacesRequested
= false;
1648 m_terminalPanel
->goHome();
1652 void DolphinMainWindow::slotKeyBindings()
1654 KShortcutsDialog
dialog(KShortcutsEditor::AllActions
, KShortcutsEditor::LetterShortcutsAllowed
, this);
1655 dialog
.addCollection(actionCollection());
1656 if (m_terminalPanel
) {
1657 KActionCollection
*konsolePartActionCollection
= m_terminalPanel
->actionCollection();
1658 if (konsolePartActionCollection
) {
1659 dialog
.addCollection(konsolePartActionCollection
, QStringLiteral("KonsolePart"));
1665 void DolphinMainWindow::setViewsToHomeIfMountPathOpen(const QString
&mountPath
)
1667 const QVector
<DolphinViewContainer
*> theViewContainers
= viewContainers();
1668 for (DolphinViewContainer
*viewContainer
: theViewContainers
) {
1669 if (viewContainer
&& viewContainer
->url().toLocalFile().startsWith(mountPath
)) {
1670 viewContainer
->setUrl(QUrl::fromLocalFile(QDir::homePath()));
1673 disconnect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, nullptr, nullptr);
1676 void DolphinMainWindow::setupActions()
1678 auto hamburgerMenuAction
= KStandardAction::hamburgerMenu(nullptr, nullptr, actionCollection());
1680 // setup 'File' menu
1681 m_newFileMenu
= new DolphinNewFileMenu(nullptr, this);
1682 actionCollection()->addAction(QStringLiteral("new_menu"), m_newFileMenu
);
1683 QMenu
*menu
= m_newFileMenu
->menu();
1684 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1685 menu
->setIcon(QIcon::fromTheme(QStringLiteral("list-add")));
1686 m_newFileMenu
->setPopupMode(QToolButton::InstantPopup
);
1687 connect(menu
, &QMenu::aboutToShow
, this, &DolphinMainWindow::updateNewMenu
);
1689 QAction
*newWindow
= KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow
, actionCollection());
1690 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1691 newWindow
->setToolTip(i18nc("@info", "Open a new Dolphin window"));
1692 newWindow
->setWhatsThis(xi18nc("@info:whatsthis",
1694 "window just like this one with the current location."
1695 "<nl/>You can drag and drop items between windows."));
1696 newWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1698 QAction
*newTab
= actionCollection()->addAction(QStringLiteral("new_tab"));
1699 newTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1700 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1701 newTab
->setWhatsThis(xi18nc("@info:whatsthis",
1703 "<emphasis>Tab</emphasis> with the current location."
1704 "<nl/>Tabs allow you to quickly switch between multiple locations and views within this window. "
1705 "You can drag and drop items between tabs."));
1706 actionCollection()->setDefaultShortcut(newTab
, Qt::CTRL
| Qt::Key_T
);
1707 connect(newTab
, &QAction::triggered
, this, &DolphinMainWindow::openNewActivatedTab
);
1709 QAction
*addToPlaces
= actionCollection()->addAction(QStringLiteral("add_to_places"));
1710 addToPlaces
->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new")));
1711 addToPlaces
->setText(i18nc("@action:inmenu Add current folder to places", "Add to Places"));
1712 addToPlaces
->setWhatsThis(xi18nc("@info:whatsthis",
1713 "This adds the selected folder "
1714 "to the Places panel."));
1715 connect(addToPlaces
, &QAction::triggered
, this, &DolphinMainWindow::addToPlaces
);
1717 QAction
*closeTab
= KStandardAction::close(m_tabWidget
, QOverload
<>::of(&DolphinTabWidget::closeTab
), actionCollection());
1718 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1719 closeTab
->setToolTip(i18nc("@info", "Close Tab"));
1720 closeTab
->setWhatsThis(i18nc("@info:whatsthis",
1722 "currently viewed tab. If no more tabs are left, this closes "
1723 "the whole window instead."));
1725 QAction
*quitAction
= KStandardAction::quit(this, &DolphinMainWindow::quit
, actionCollection());
1726 quitAction
->setWhatsThis(i18nc("@info:whatsthis quit", "This closes this window."));
1728 // setup 'Edit' menu
1729 KStandardAction::undo(this, &DolphinMainWindow::undo
, actionCollection());
1731 // i18n: This will be the last paragraph for the whatsthis for all three:
1732 // Cut, Copy and Paste
1733 const QString cutCopyPastePara
= xi18nc("@info:whatsthis",
1734 "<para><emphasis>Cut, "
1735 "Copy</emphasis> and <emphasis>Paste</emphasis> work between many "
1736 "applications and are among the most used commands. That's why their "
1737 "<emphasis>keyboard shortcuts</emphasis> are prominently placed right "
1738 "next to each other on the keyboard: <shortcut>Ctrl+X</shortcut>, "
1739 "<shortcut>Ctrl+C</shortcut> and <shortcut>Ctrl+V</shortcut>.</para>");
1740 QAction
*cutAction
= KStandardAction::cut(this, &DolphinMainWindow::cut
, actionCollection());
1741 m_actionTextHelper
->registerTextWhenNothingIsSelected(cutAction
, i18nc("@action", "Cut…"));
1742 cutAction
->setWhatsThis(xi18nc("@info:whatsthis cut",
1743 "This copies the items "
1744 "in your current selection to the <emphasis>clipboard</emphasis>.<nl/>"
1745 "Use the <emphasis>Paste</emphasis> action afterwards to copy them from "
1746 "the clipboard to a new location. The items will be removed from their "
1747 "initial location.")
1748 + cutCopyPastePara
);
1749 QAction
*copyAction
= KStandardAction::copy(this, &DolphinMainWindow::copy
, actionCollection());
1750 m_actionTextHelper
->registerTextWhenNothingIsSelected(copyAction
, i18nc("@action", "Copy…"));
1751 copyAction
->setWhatsThis(xi18nc("@info:whatsthis copy",
1753 "items in your current selection to the <emphasis>clipboard</emphasis>."
1754 "<nl/>Use the <emphasis>Paste</emphasis> action afterwards to copy them "
1755 "from the clipboard to a new location.")
1756 + cutCopyPastePara
);
1757 QAction
*paste
= KStandardAction::paste(this, &DolphinMainWindow::paste
, actionCollection());
1758 // The text of the paste-action is modified dynamically by Dolphin
1759 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1760 // due to the long text, the text "Paste" is used:
1761 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1762 paste
->setWhatsThis(xi18nc("@info:whatsthis paste",
1763 "This copies the items from "
1764 "your <emphasis>clipboard</emphasis> to the currently viewed folder.<nl/>"
1765 "If the items were added to the clipboard by the <emphasis>Cut</emphasis> "
1766 "action they are removed from their old location.")
1767 + cutCopyPastePara
);
1769 QAction
*copyToOtherViewAction
= actionCollection()->addAction(QStringLiteral("copy_to_inactive_split_view"));
1770 copyToOtherViewAction
->setText(i18nc("@action:inmenu", "Copy to Other View"));
1771 m_actionTextHelper
->registerTextWhenNothingIsSelected(copyToOtherViewAction
, i18nc("@action:inmenu", "Copy to Other View…"));
1772 copyToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Copy",
1773 "This copies the selected items from "
1774 "the view in focus to the other view. "
1775 "(Only available while in Split View mode.)"));
1776 copyToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
1777 copyToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Copy to Other View"));
1778 actionCollection()->setDefaultShortcut(copyToOtherViewAction
, Qt::SHIFT
| Qt::Key_F5
);
1779 connect(copyToOtherViewAction
, &QAction::triggered
, this, &DolphinMainWindow::copyToInactiveSplitView
);
1781 QAction
*moveToOtherViewAction
= actionCollection()->addAction(QStringLiteral("move_to_inactive_split_view"));
1782 moveToOtherViewAction
->setText(i18nc("@action:inmenu", "Move to Other View"));
1783 m_actionTextHelper
->registerTextWhenNothingIsSelected(moveToOtherViewAction
, i18nc("@action:inmenu", "Move to Other View…"));
1784 moveToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Move",
1785 "This moves the selected items from "
1786 "the view in focus to the other view. "
1787 "(Only available while in Split View mode.)"));
1788 moveToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-cut")));
1789 moveToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Move to Other View"));
1790 actionCollection()->setDefaultShortcut(moveToOtherViewAction
, Qt::SHIFT
| Qt::Key_F6
);
1791 connect(moveToOtherViewAction
, &QAction::triggered
, this, &DolphinMainWindow::moveToInactiveSplitView
);
1793 QAction
*showFilterBar
= actionCollection()->addAction(QStringLiteral("show_filter_bar"));
1794 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Filter…"));
1795 showFilterBar
->setToolTip(i18nc("@info:tooltip", "Show Filter Bar"));
1796 showFilterBar
->setWhatsThis(xi18nc("@info:whatsthis",
1798 "<emphasis>Filter Bar</emphasis> at the bottom of the window.<nl/> "
1799 "There you can enter text to filter the files and folders currently displayed. "
1800 "Only those that contain the text in their name will be kept in view."));
1801 showFilterBar
->setIcon(QIcon::fromTheme(QStringLiteral("view-filter")));
1802 actionCollection()->setDefaultShortcuts(showFilterBar
, {Qt::CTRL
| Qt::Key_I
, Qt::Key_Slash
});
1803 connect(showFilterBar
, &QAction::triggered
, this, &DolphinMainWindow::showFilterBar
);
1805 // toggle_filter acts as a copy of the main showFilterBar to be used mainly
1806 // in the toolbar, with no default shortcut attached, to avoid messing with
1807 // existing workflows (filter bar always open and Ctrl-I to focus)
1808 QAction
*toggleFilter
= actionCollection()->addAction(QStringLiteral("toggle_filter"));
1809 toggleFilter
->setText(i18nc("@action:inmenu", "Toggle Filter Bar"));
1810 toggleFilter
->setIconText(i18nc("@action:intoolbar", "Filter"));
1811 toggleFilter
->setIcon(showFilterBar
->icon());
1812 toggleFilter
->setToolTip(showFilterBar
->toolTip());
1813 toggleFilter
->setWhatsThis(showFilterBar
->whatsThis());
1814 toggleFilter
->setCheckable(true);
1815 connect(toggleFilter
, &QAction::triggered
, this, &DolphinMainWindow::toggleFilterBar
);
1817 QAction
*searchAction
= KStandardAction::find(this, &DolphinMainWindow::find
, actionCollection());
1818 searchAction
->setText(i18n("Search…"));
1819 searchAction
->setToolTip(i18nc("@info:tooltip", "Search for files and folders"));
1820 searchAction
->setWhatsThis(xi18nc("@info:whatsthis find",
1821 "<para>This helps you "
1822 "find files and folders by opening a <emphasis>search bar</emphasis>. "
1823 "There you can enter search terms and specify settings to find the "
1824 "items you are looking for.</para><para>Use this help again on "
1825 "the search bar so we can have a look at it while the settings are "
1826 "explained.</para>"));
1828 // toggle_search acts as a copy of the main searchAction to be used mainly
1829 // in the toolbar, with no default shortcut attached, to avoid messing with
1830 // existing workflows (search bar always open and Ctrl-F to focus)
1831 QAction
*toggleSearchAction
= actionCollection()->addAction(QStringLiteral("toggle_search"));
1832 toggleSearchAction
->setText(i18nc("@action:inmenu", "Toggle Search Bar"));
1833 toggleSearchAction
->setIconText(i18nc("@action:intoolbar", "Search"));
1834 toggleSearchAction
->setIcon(searchAction
->icon());
1835 toggleSearchAction
->setToolTip(searchAction
->toolTip());
1836 toggleSearchAction
->setWhatsThis(searchAction
->whatsThis());
1837 toggleSearchAction
->setCheckable(true);
1839 QAction
*toggleSelectionModeAction
= actionCollection()->addAction(QStringLiteral("toggle_selection_mode"));
1840 // i18n: This action toggles a selection mode.
1841 toggleSelectionModeAction
->setText(i18nc("@action:inmenu", "Select Files and Folders"));
1842 // i18n: Opens a selection mode for selecting files/folders.
1843 // The text is kept so unspecific because it will be shown on the toolbar where space is at a premium.
1844 toggleSelectionModeAction
->setIconText(i18nc("@action:intoolbar", "Select"));
1845 toggleSelectionModeAction
->setWhatsThis(xi18nc(
1847 "<para>This application only knows which files or folders should be acted on if they are"
1848 " <emphasis>selected</emphasis> first. Press this to toggle a <emphasis>Selection Mode</emphasis> which makes selecting and deselecting as easy as "
1849 "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."
1851 toggleSelectionModeAction
->setIcon(QIcon::fromTheme(QStringLiteral("quickwizard")));
1852 toggleSelectionModeAction
->setCheckable(true);
1853 actionCollection()->setDefaultShortcut(toggleSelectionModeAction
, Qt::Key_Space
);
1854 connect(toggleSelectionModeAction
, &QAction::triggered
, this, &DolphinMainWindow::toggleSelectionMode
);
1856 // A special version of the toggleSelectionModeAction for the toolbar that also contains a menu
1857 // with the selectAllAction and invertSelectionAction.
1858 auto *toggleSelectionModeToolBarAction
=
1859 new KToolBarPopupAction(toggleSelectionModeAction
->icon(), toggleSelectionModeAction
->iconText(), actionCollection());
1860 toggleSelectionModeToolBarAction
->setToolTip(toggleSelectionModeAction
->text());
1861 toggleSelectionModeToolBarAction
->setWhatsThis(toggleSelectionModeAction
->whatsThis());
1862 actionCollection()->addAction(QStringLiteral("toggle_selection_mode_tool_bar"), toggleSelectionModeToolBarAction
);
1863 toggleSelectionModeToolBarAction
->setCheckable(true);
1864 toggleSelectionModeToolBarAction
->setPopupMode(KToolBarPopupAction::DelayedPopup
);
1865 connect(toggleSelectionModeToolBarAction
, &QAction::triggered
, toggleSelectionModeAction
, &QAction::trigger
);
1866 connect(toggleSelectionModeAction
, &QAction::toggled
, toggleSelectionModeToolBarAction
, &QAction::setChecked
);
1868 QAction
*selectAllAction
= KStandardAction::selectAll(this, &DolphinMainWindow::selectAll
, actionCollection());
1869 selectAllAction
->setWhatsThis(xi18nc("@info:whatsthis",
1871 "files and folders in the current location."));
1873 QAction
*invertSelection
= actionCollection()->addAction(QStringLiteral("invert_selection"));
1874 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1875 invertSelection
->setWhatsThis(xi18nc("@info:whatsthis invert",
1877 "items that you have currently <emphasis>not</emphasis> selected instead."));
1878 invertSelection
->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-invert")));
1879 actionCollection()->setDefaultShortcut(invertSelection
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1880 connect(invertSelection
, &QAction::triggered
, this, &DolphinMainWindow::invertSelection
);
1882 QMenu
*toggleSelectionModeActionMenu
= new QMenu(this);
1883 toggleSelectionModeActionMenu
->addAction(selectAllAction
);
1884 toggleSelectionModeActionMenu
->addAction(invertSelection
);
1885 toggleSelectionModeToolBarAction
->setMenu(toggleSelectionModeActionMenu
);
1887 // setup 'View' menu
1888 // (note that most of it is set up in DolphinViewActionHandler)
1890 Admin::WorkerIntegration::createActAsAdminAction(actionCollection(), this);
1892 m_splitViewAction
= actionCollection()->add
<KActionMenu
>(QStringLiteral("split_view"));
1893 m_splitViewMenuAction
= actionCollection()->addAction(QStringLiteral("split_view_menu"));
1895 m_splitViewAction
->setWhatsThis(xi18nc("@info:whatsthis split",
1896 "<para>This presents "
1897 "a second view side-by-side with the current view, so you can see "
1898 "the contents of two folders at once and easily move items between "
1899 "them.</para><para>The view that is not \"in focus\" will be dimmed. "
1900 "</para>Click this button again to close one of the views."));
1901 m_splitViewMenuAction
->setWhatsThis(m_splitViewAction
->whatsThis());
1903 // only set it for the menu version
1904 actionCollection()->setDefaultShortcut(m_splitViewMenuAction
, Qt::Key_F3
);
1906 connect(m_splitViewAction
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitView
);
1907 connect(m_splitViewMenuAction
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitView
);
1909 QAction
*popoutSplit
= actionCollection()->addAction(QStringLiteral("popout_split_view"));
1910 popoutSplit
->setWhatsThis(xi18nc("@info:whatsthis",
1911 "If the view has been split, this will pop the view in focus "
1912 "out into a new window."));
1913 popoutSplit
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1914 actionCollection()->setDefaultShortcut(popoutSplit
, Qt::SHIFT
| Qt::Key_F3
);
1915 connect(popoutSplit
, &QAction::triggered
, this, &DolphinMainWindow::popoutSplitView
);
1917 QAction
*stashSplit
= actionCollection()->addAction(QStringLiteral("split_stash"));
1918 actionCollection()->setDefaultShortcut(stashSplit
, Qt::CTRL
| Qt::Key_S
);
1919 stashSplit
->setText(i18nc("@action:intoolbar Stash", "Stash"));
1920 stashSplit
->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
1921 stashSplit
->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
1922 stashSplit
->setCheckable(false);
1923 QDBusConnectionInterface
*sessionInterface
= QDBusConnection::sessionBus().interface();
1924 stashSplit
->setVisible(sessionInterface
&& sessionInterface
->isServiceRegistered(QStringLiteral("org.kde.kio.StashNotifier")));
1925 connect(stashSplit
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitStash
);
1927 QAction
*redisplay
= KStandardAction::redisplay(this, &DolphinMainWindow::reloadView
, actionCollection());
1928 redisplay
->setToolTip(i18nc("@info:tooltip", "Refresh view"));
1929 redisplay
->setWhatsThis(xi18nc("@info:whatsthis refresh",
1930 "<para>This refreshes "
1931 "the folder view.</para>"
1932 "<para>If the contents of this folder have changed, refreshing will re-scan this folder "
1933 "and show you a newly-updated view of the files and folders contained here.</para>"
1934 "<para>If the view is split, this refreshes the one that is currently in focus.</para>"));
1936 QAction
*stop
= actionCollection()->addAction(QStringLiteral("stop"));
1937 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1938 stop
->setToolTip(i18nc("@info", "Stop loading"));
1939 stop
->setWhatsThis(i18nc("@info", "This stops the loading of the contents of the current folder."));
1940 stop
->setIcon(QIcon::fromTheme(QStringLiteral("process-stop")));
1941 connect(stop
, &QAction::triggered
, this, &DolphinMainWindow::stopLoading
);
1943 KToggleAction
*editableLocation
= actionCollection()->add
<KToggleAction
>(QStringLiteral("editable_location"));
1944 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1945 editableLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1946 "This toggles the <emphasis>Location Bar</emphasis> to be "
1947 "editable so you can directly enter a location you want to go to.<nl/>"
1948 "You can also switch to editing by clicking to the right of the "
1949 "location and switch back by confirming the edited location."));
1950 actionCollection()->setDefaultShortcut(editableLocation
, Qt::Key_F6
);
1951 connect(editableLocation
, &KToggleAction::triggered
, this, &DolphinMainWindow::toggleEditLocation
);
1953 QAction
*replaceLocation
= actionCollection()->addAction(QStringLiteral("replace_location"));
1954 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1955 // i18n: "enter" is used both in the meaning of "writing" and "going to" a new location here.
1956 // Both meanings are useful but not necessary to understand the use of "Replace Location".
1957 // So you might want to be more verbose in your language to convey the meaning but it's up to you.
1958 replaceLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1959 "This switches to editing the location and selects it "
1960 "so you can quickly enter a different location."));
1961 actionCollection()->setDefaultShortcuts(replaceLocation
, {Qt::CTRL
| Qt::Key_L
, Qt::ALT
| Qt::Key_D
});
1962 connect(replaceLocation
, &QAction::triggered
, this, &DolphinMainWindow::replaceLocation
);
1966 QScopedPointer
<QAction
> backAction(KStandardAction::back(nullptr, nullptr, nullptr));
1967 m_backAction
= new KToolBarPopupAction(backAction
->icon(), backAction
->text(), actionCollection());
1968 m_backAction
->setObjectName(backAction
->objectName());
1969 m_backAction
->setShortcuts(backAction
->shortcuts());
1971 m_backAction
->setPopupMode(KToolBarPopupAction::DelayedPopup
);
1972 connect(m_backAction
, &QAction::triggered
, this, &DolphinMainWindow::goBack
);
1973 connect(m_backAction
->popupMenu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowBackPopupMenu
);
1974 connect(m_backAction
->popupMenu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoBack
);
1975 actionCollection()->addAction(m_backAction
->objectName(), m_backAction
);
1977 auto backShortcuts
= m_backAction
->shortcuts();
1978 // Prepend this shortcut, to avoid being hidden by the two-slot UI (#371130)
1979 backShortcuts
.prepend(QKeySequence(Qt::Key_Backspace
));
1980 actionCollection()->setDefaultShortcuts(m_backAction
, backShortcuts
);
1982 DolphinRecentTabsMenu
*recentTabsMenu
= new DolphinRecentTabsMenu(this);
1983 actionCollection()->addAction(QStringLiteral("closed_tabs"), recentTabsMenu
);
1984 connect(m_tabWidget
, &DolphinTabWidget::rememberClosedTab
, recentTabsMenu
, &DolphinRecentTabsMenu::rememberClosedTab
);
1985 connect(recentTabsMenu
, &DolphinRecentTabsMenu::restoreClosedTab
, m_tabWidget
, &DolphinTabWidget::restoreClosedTab
);
1986 connect(recentTabsMenu
, &DolphinRecentTabsMenu::closedTabsCountChanged
, this, &DolphinMainWindow::closedTabsCountChanged
);
1988 QAction
*undoCloseTab
= actionCollection()->addAction(QStringLiteral("undo_close_tab"));
1989 undoCloseTab
->setText(i18nc("@action:inmenu File", "Undo close tab"));
1990 undoCloseTab
->setWhatsThis(i18nc("@info:whatsthis undo close tab", "This returns you to the previously closed tab."));
1991 actionCollection()->setDefaultShortcut(undoCloseTab
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_T
);
1992 undoCloseTab
->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo")));
1993 undoCloseTab
->setEnabled(false);
1994 connect(undoCloseTab
, &QAction::triggered
, recentTabsMenu
, &DolphinRecentTabsMenu::undoCloseTab
);
1996 auto undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
1997 undoAction
->setWhatsThis(xi18nc("@info:whatsthis",
1999 "the last change you made to files or folders.<nl/>"
2000 "Such changes include <interface>creating</interface>, <interface>renaming</interface> "
2001 "and <interface>moving</interface> them to a different location "
2002 "or to the <filename>Trash</filename>. <nl/>Any changes that cannot be undone "
2003 "will ask for your confirmation beforehand."));
2004 undoAction
->setEnabled(false); // undo should be disabled by default
2007 QScopedPointer
<QAction
> forwardAction(KStandardAction::forward(nullptr, nullptr, nullptr));
2008 m_forwardAction
= new KToolBarPopupAction(forwardAction
->icon(), forwardAction
->text(), actionCollection());
2009 m_forwardAction
->setObjectName(forwardAction
->objectName());
2010 m_forwardAction
->setShortcuts(forwardAction
->shortcuts());
2012 m_forwardAction
->setPopupMode(KToolBarPopupAction::DelayedPopup
);
2013 connect(m_forwardAction
, &QAction::triggered
, this, &DolphinMainWindow::goForward
);
2014 connect(m_forwardAction
->popupMenu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowForwardPopupMenu
);
2015 connect(m_forwardAction
->popupMenu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoForward
);
2016 actionCollection()->addAction(m_forwardAction
->objectName(), m_forwardAction
);
2017 actionCollection()->setDefaultShortcuts(m_forwardAction
, m_forwardAction
->shortcuts());
2019 // enable middle-click to open in a new tab
2020 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
2021 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotBackForwardActionMiddleClicked
);
2022 m_backAction
->popupMenu()->installEventFilter(middleClickEventFilter
);
2023 m_forwardAction
->popupMenu()->installEventFilter(middleClickEventFilter
);
2024 KStandardAction::up(this, &DolphinMainWindow::goUp
, actionCollection());
2025 QAction
*homeAction
= KStandardAction::home(this, &DolphinMainWindow::goHome
, actionCollection());
2026 homeAction
->setWhatsThis(xi18nc("@info:whatsthis",
2028 "<filename>Home</filename> folder.<nl/>Every user account "
2029 "has their own <filename>Home</filename> that contains their personal files, "
2030 "as well as hidden folders for their applications' data and configuration files."));
2032 // setup 'Tools' menu
2033 QAction
*compareFiles
= actionCollection()->addAction(QStringLiteral("compare_files"));
2034 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
2035 compareFiles
->setIcon(QIcon::fromTheme(QStringLiteral("kompare")));
2036 compareFiles
->setEnabled(false);
2037 connect(compareFiles
, &QAction::triggered
, this, &DolphinMainWindow::compareFiles
);
2039 QAction
*openPreferredSearchTool
= actionCollection()->addAction(QStringLiteral("open_preferred_search_tool"));
2040 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
2041 openPreferredSearchTool
->setWhatsThis(xi18nc("@info:whatsthis",
2042 "<para>This opens a preferred search tool for the viewed location.</para>"
2043 "<para>Use <emphasis>More Search Tools</emphasis> menu to configure it.</para>"));
2044 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
2045 actionCollection()->setDefaultShortcut(openPreferredSearchTool
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F
);
2046 connect(openPreferredSearchTool
, &QAction::triggered
, this, &DolphinMainWindow::openPreferredSearchTool
);
2048 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
2049 QAction
*openTerminal
= actionCollection()->addAction(QStringLiteral("open_terminal"));
2050 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
2051 openTerminal
->setWhatsThis(xi18nc("@info:whatsthis",
2052 "<para>This opens a <emphasis>terminal</emphasis> application for the viewed location.</para>"
2053 "<para>To learn more about terminals use the help features in the terminal application.</para>"));
2054 openTerminal
->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
2055 actionCollection()->setDefaultShortcut(openTerminal
, Qt::SHIFT
| Qt::Key_F4
);
2056 connect(openTerminal
, &QAction::triggered
, this, &DolphinMainWindow::openTerminal
);
2058 QAction
*openTerminalHere
= actionCollection()->addAction(QStringLiteral("open_terminal_here"));
2059 // i18n: "Here" refers to the location(s) of the currently selected item(s) or the currently viewed location if nothing is selected.
2060 openTerminalHere
->setText(i18nc("@action:inmenu Tools", "Open Terminal Here"));
2061 openTerminalHere
->setWhatsThis(xi18nc("@info:whatsthis",
2062 "<para>This opens <emphasis>terminal</emphasis> applications for the selected items' locations.</para>"
2063 "<para>To learn more about terminals use the help features in the terminal application.</para>"));
2064 openTerminalHere
->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
2065 actionCollection()->setDefaultShortcut(openTerminalHere
, Qt::SHIFT
| Qt::ALT
| Qt::Key_F4
);
2066 connect(openTerminalHere
, &QAction::triggered
, this, &DolphinMainWindow::openTerminalHere
);
2069 // setup 'Bookmarks' menu
2070 KActionMenu
*bookmarkMenu
= new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this);
2071 bookmarkMenu
->setIcon(QIcon::fromTheme(QStringLiteral("bookmarks")));
2072 // Make the toolbar button version work properly on click
2073 bookmarkMenu
->setPopupMode(QToolButton::InstantPopup
);
2074 m_bookmarkHandler
= new DolphinBookmarkHandler(this, actionCollection(), bookmarkMenu
->menu(), this);
2075 actionCollection()->addAction(QStringLiteral("bookmarks"), bookmarkMenu
);
2077 // setup 'Settings' menu
2078 KToggleAction
*showMenuBar
= KStandardAction::showMenubar(nullptr, nullptr, actionCollection());
2079 showMenuBar
->setWhatsThis(xi18nc("@info:whatsthis",
2080 "<para>This switches between having a <emphasis>Menubar</emphasis> "
2081 "and having an <interface>%1</interface> button. Both "
2082 "contain mostly the same actions and configuration options.</para>"
2083 "<para>The Menubar takes up more space but allows for fast and organized access to all "
2084 "actions an application has to offer.</para><para>The %1 button "
2085 "is simpler and small which makes triggering advanced actions more time consuming.</para>",
2086 hamburgerMenuAction
->text().replace('&', "")));
2087 connect(showMenuBar
,
2088 &KToggleAction::triggered
, // Fixes #286822
2090 &DolphinMainWindow::toggleShowMenuBar
,
2091 Qt::QueuedConnection
);
2093 KToggleAction
*showStatusBar
= KStandardAction::showStatusbar(nullptr, nullptr, actionCollection());
2094 showStatusBar
->setChecked(GeneralSettings::showStatusBar());
2095 connect(GeneralSettings::self(), &GeneralSettings::showStatusBarChanged
, showStatusBar
, &KToggleAction::setChecked
);
2096 connect(showStatusBar
, &KToggleAction::triggered
, this, [this](bool checked
) {
2097 GeneralSettings::setShowStatusBar(checked
);
2101 KStandardAction::keyBindings(this, &DolphinMainWindow::slotKeyBindings
, actionCollection());
2102 KStandardAction::preferences(this, &DolphinMainWindow::editSettings
, actionCollection());
2104 // not in menu actions
2105 QList
<QKeySequence
> nextTabKeys
= KStandardShortcut::tabNext();
2106 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
2108 QList
<QKeySequence
> prevTabKeys
= KStandardShortcut::tabPrev();
2109 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
2111 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
2112 QAction
*activateTab
= actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i
));
2113 activateTab
->setText(i18nc("@action:inmenu", "Go to Tab %1", i
+ 1));
2114 activateTab
->setEnabled(false);
2115 connect(activateTab
, &QAction::triggered
, this, [this, i
]() {
2116 m_tabWidget
->activateTab(i
);
2119 // only add default shortcuts for the first 9 tabs regardless of MaxActivateTabShortcuts
2121 actionCollection()->setDefaultShortcut(activateTab
, QStringLiteral("Alt+%1").arg(i
+ 1));
2125 QAction
*activateLastTab
= actionCollection()->addAction(QStringLiteral("activate_last_tab"));
2126 activateLastTab
->setIconText(i18nc("@action:inmenu", "Last Tab"));
2127 activateLastTab
->setText(i18nc("@action:inmenu", "Go to Last Tab"));
2128 activateLastTab
->setEnabled(false);
2129 connect(activateLastTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateLastTab
);
2130 actionCollection()->setDefaultShortcut(activateLastTab
, Qt::ALT
| Qt::Key_0
);
2132 QAction
*activateNextTab
= actionCollection()->addAction(QStringLiteral("activate_next_tab"));
2133 activateNextTab
->setIconText(i18nc("@action:inmenu", "Next Tab"));
2134 activateNextTab
->setText(i18nc("@action:inmenu", "Go to Next Tab"));
2135 activateNextTab
->setEnabled(false);
2136 connect(activateNextTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateNextTab
);
2137 actionCollection()->setDefaultShortcuts(activateNextTab
, nextTabKeys
);
2139 QAction
*activatePrevTab
= actionCollection()->addAction(QStringLiteral("activate_prev_tab"));
2140 activatePrevTab
->setIconText(i18nc("@action:inmenu", "Previous Tab"));
2141 activatePrevTab
->setText(i18nc("@action:inmenu", "Go to Previous Tab"));
2142 activatePrevTab
->setEnabled(false);
2143 connect(activatePrevTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activatePrevTab
);
2144 actionCollection()->setDefaultShortcuts(activatePrevTab
, prevTabKeys
);
2147 QAction
*showTarget
= actionCollection()->addAction(QStringLiteral("show_target"));
2148 showTarget
->setText(i18nc("@action:inmenu", "Show Target"));
2149 showTarget
->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
2150 showTarget
->setEnabled(false);
2151 connect(showTarget
, &QAction::triggered
, this, &DolphinMainWindow::showTarget
);
2153 QAction
*openInNewTab
= actionCollection()->addAction(QStringLiteral("open_in_new_tab"));
2154 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
2155 openInNewTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
2156 connect(openInNewTab
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
2158 QAction
*openInNewTabs
= actionCollection()->addAction(QStringLiteral("open_in_new_tabs"));
2159 openInNewTabs
->setText(i18nc("@action:inmenu", "Open in New Tabs"));
2160 openInNewTabs
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
2161 connect(openInNewTabs
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
2163 QAction
*openInNewWindow
= actionCollection()->addAction(QStringLiteral("open_in_new_window"));
2164 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
2165 openInNewWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
2166 connect(openInNewWindow
, &QAction::triggered
, this, &DolphinMainWindow::openInNewWindow
);
2168 QAction
*openInSplitViewAction
= actionCollection()->addAction(QStringLiteral("open_in_split_view"));
2169 openInSplitViewAction
->setText(i18nc("@action:inmenu", "Open in Split View"));
2170 openInSplitViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
2171 connect(openInSplitViewAction
, &QAction::triggered
, this, [this]() {
2172 openInSplitView(QUrl());
2175 m_recentFiles
= new KRecentFilesAction(this);
2178 void DolphinMainWindow::setupDockWidgets()
2180 const bool lock
= GeneralSettings::lockPanels();
2182 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(lock
);
2184 KDualAction
*lockLayoutAction
= actionCollection()->add
<KDualAction
>(QStringLiteral("lock_panels"));
2185 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
2186 lockLayoutAction
->setActiveIcon(QIcon::fromTheme(QStringLiteral("object-unlocked")));
2187 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
2188 lockLayoutAction
->setInactiveIcon(QIcon::fromTheme(QStringLiteral("object-locked")));
2189 lockLayoutAction
->setWhatsThis(xi18nc("@info:whatsthis",
2191 "switches between having panels <emphasis>locked</emphasis> or "
2192 "<emphasis>unlocked</emphasis>.<nl/>Unlocked panels can be "
2193 "dragged to the other side of the window and have a close "
2194 "button.<nl/>Locked panels are embedded more cleanly."));
2195 lockLayoutAction
->setActive(lock
);
2196 connect(lockLayoutAction
, &KDualAction::triggered
, this, &DolphinMainWindow::togglePanelLockState
);
2198 // Setup "Information"
2199 DolphinDockWidget
*infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
2200 infoDock
->setLocked(lock
);
2201 infoDock
->setObjectName(QStringLiteral("infoDock"));
2202 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2205 InformationPanel
*infoPanel
= new InformationPanel(infoDock
);
2206 infoPanel
->setCustomContextMenuActions({lockLayoutAction
});
2207 connect(infoPanel
, &InformationPanel::urlActivated
, this, &DolphinMainWindow::handleUrl
);
2208 infoDock
->setWidget(infoPanel
);
2210 createPanelAction(QIcon::fromTheme(QStringLiteral("documentinfo")), Qt::Key_F11
, infoDock
, QStringLiteral("show_information_panel"));
2212 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
2213 connect(this, &DolphinMainWindow::urlChanged
, infoPanel
, &InformationPanel::setUrl
);
2214 connect(this, &DolphinMainWindow::selectionChanged
, infoPanel
, &InformationPanel::setSelection
);
2215 connect(this, &DolphinMainWindow::requestItemInfo
, infoPanel
, &InformationPanel::requestDelayedItemInfo
);
2216 connect(this, &DolphinMainWindow::fileItemsChanged
, infoPanel
, &InformationPanel::slotFilesItemChanged
);
2217 connect(this, &DolphinMainWindow::settingsChanged
, infoPanel
, &InformationPanel::readSettings
);
2220 // i18n: This is the last paragraph for the "What's This"-texts of all four panels.
2221 const QString panelWhatsThis
= xi18nc("@info:whatsthis",
2223 "hide panels like this go to <interface>Menu|Panels</interface> "
2224 "or <interface>View|Panels</interface>.</para>");
2227 ->action(QStringLiteral("show_information_panel"))
2228 ->setWhatsThis(xi18nc("@info:whatsthis",
2229 "<para> This toggles the "
2230 "<emphasis>information</emphasis> panel at the right side of the "
2231 "window.</para><para>The panel provides in-depth information "
2232 "about the items your mouse is hovering over or about the selected "
2233 "items. Otherwise it informs you about the currently viewed folder.<nl/>"
2234 "For single items a preview of their contents is provided.</para>"));
2236 infoDock
->setWhatsThis(xi18nc("@info:whatsthis",
2238 "provides in-depth information about the items your mouse is "
2239 "hovering over or about the selected items. Otherwise it informs "
2240 "you about the currently viewed folder.<nl/>For single items a "
2241 "preview of their contents is provided.</para><para>You can configure "
2242 "which and how details are given here by right-clicking.</para>")
2246 DolphinDockWidget
*foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
2247 foldersDock
->setLocked(lock
);
2248 foldersDock
->setObjectName(QStringLiteral("foldersDock"));
2249 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2250 FoldersPanel
*foldersPanel
= new FoldersPanel(foldersDock
);
2251 foldersPanel
->setCustomContextMenuActions({lockLayoutAction
});
2252 foldersDock
->setWidget(foldersPanel
);
2254 createPanelAction(QIcon::fromTheme(QStringLiteral("folder")), Qt::Key_F7
, foldersDock
, QStringLiteral("show_folders_panel"));
2256 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
2257 connect(this, &DolphinMainWindow::urlChanged
, foldersPanel
, &FoldersPanel::setUrl
);
2258 connect(foldersPanel
, &FoldersPanel::folderActivated
, this, &DolphinMainWindow::changeUrl
);
2259 connect(foldersPanel
, &FoldersPanel::folderInNewTab
, this, &DolphinMainWindow::openNewTab
);
2260 connect(foldersPanel
, &FoldersPanel::folderInNewActiveTab
, this, &DolphinMainWindow::openNewTabAndActivate
);
2261 connect(foldersPanel
, &FoldersPanel::errorMessage
, this, &DolphinMainWindow::showErrorMessage
);
2264 ->action(QStringLiteral("show_folders_panel"))
2265 ->setWhatsThis(xi18nc("@info:whatsthis",
2267 "<emphasis>folders</emphasis> panel at the left side of the window."
2268 "<nl/><nl/>It shows the folders of the <emphasis>file system"
2269 "</emphasis> in a <emphasis>tree view</emphasis>."));
2270 foldersDock
->setWhatsThis(xi18nc("@info:whatsthis",
2272 "shows the folders of the <emphasis>file system</emphasis> in a "
2273 "<emphasis>tree view</emphasis>.</para><para>Click a folder to go "
2274 "there. Click the arrow to the left of a folder to see its subfolders. "
2275 "This allows quick switching between any folders.</para>")
2280 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
2281 DolphinDockWidget
*terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
2282 terminalDock
->setLocked(lock
);
2283 terminalDock
->setObjectName(QStringLiteral("terminalDock"));
2284 terminalDock
->setContentsMargins(0, 0, 0, 0);
2285 m_terminalPanel
= new TerminalPanel(terminalDock
);
2286 m_terminalPanel
->setCustomContextMenuActions({lockLayoutAction
});
2287 terminalDock
->setWidget(m_terminalPanel
);
2289 connect(m_terminalPanel
, &TerminalPanel::hideTerminalPanel
, terminalDock
, &DolphinDockWidget::hide
);
2290 connect(m_terminalPanel
, &TerminalPanel::changeUrl
, this, &DolphinMainWindow::slotTerminalDirectoryChanged
);
2291 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
, m_terminalPanel
, &TerminalPanel::dockVisibilityChanged
);
2292 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
, this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged
);
2294 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-scripts")), Qt::Key_F4
, terminalDock
, QStringLiteral("show_terminal_panel"));
2296 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
2297 connect(this, &DolphinMainWindow::urlChanged
, m_terminalPanel
, &TerminalPanel::setUrl
);
2299 if (GeneralSettings::version() < 200) {
2300 terminalDock
->hide();
2304 ->action(QStringLiteral("show_terminal_panel"))
2305 ->setWhatsThis(xi18nc("@info:whatsthis",
2306 "<para>This toggles the "
2307 "<emphasis>terminal</emphasis> panel at the bottom of the window."
2308 "<nl/>The location in the terminal will always match the folder "
2309 "view so you can navigate using either.</para><para>The terminal "
2310 "panel is not needed for basic computer usage but can be useful "
2311 "for advanced tasks. To learn more about terminals use the help features "
2312 "in a standalone terminal application like Konsole.</para>"));
2313 terminalDock
->setWhatsThis(xi18nc("@info:whatsthis",
2315 "the <emphasis>terminal</emphasis> panel. It behaves like a "
2316 "normal terminal but will match the location of the folder view "
2317 "so you can navigate using either.</para><para>The terminal panel "
2318 "is not needed for basic computer usage but can be useful for "
2319 "advanced tasks. To learn more about terminals use the help features in a "
2320 "standalone terminal application like Konsole.</para>")
2323 QAction
*focusTerminalPanel
= actionCollection()->addAction(QStringLiteral("focus_terminal_panel"));
2324 focusTerminalPanel
->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2325 focusTerminalPanel
->setToolTip(i18nc("@info:tooltip", "Move keyboard focus to and from the Terminal panel."));
2326 focusTerminalPanel
->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
2327 actionCollection()->setDefaultShortcut(focusTerminalPanel
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F4
);
2328 connect(focusTerminalPanel
, &QAction::triggered
, this, &DolphinMainWindow::toggleTerminalPanelFocus
);
2329 } // endif "shell_access" allowed
2330 #endif // HAVE_TERMINAL
2332 if (GeneralSettings::version() < 200) {
2334 foldersDock
->hide();
2338 DolphinDockWidget
*placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
2339 placesDock
->setLocked(lock
);
2340 placesDock
->setObjectName(QStringLiteral("placesDock"));
2341 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2343 m_placesPanel
= new PlacesPanel(placesDock
);
2344 m_placesPanel
->setCustomContextMenuActions({lockLayoutAction
});
2345 placesDock
->setWidget(m_placesPanel
);
2347 createPanelAction(QIcon::fromTheme(QStringLiteral("compass")), Qt::Key_F9
, placesDock
, QStringLiteral("show_places_panel"));
2349 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
2350 connect(m_placesPanel
, &PlacesPanel::placeActivated
, this, &DolphinMainWindow::slotPlaceActivated
);
2351 connect(m_placesPanel
, &PlacesPanel::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2352 connect(m_placesPanel
, &PlacesPanel::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2353 connect(m_placesPanel
, &PlacesPanel::newWindowRequested
, this, [this](const QUrl
&url
) {
2354 Dolphin::openNewWindow({url
}, this);
2356 connect(m_placesPanel
, &PlacesPanel::openInSplitViewRequested
, this, &DolphinMainWindow::openInSplitView
);
2357 connect(m_placesPanel
, &PlacesPanel::errorMessage
, this, &DolphinMainWindow::showErrorMessage
);
2358 connect(this, &DolphinMainWindow::urlChanged
, m_placesPanel
, &PlacesPanel::setUrl
);
2359 connect(placesDock
, &DolphinDockWidget::visibilityChanged
, &DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged
);
2360 connect(placesDock
, &DolphinDockWidget::visibilityChanged
, this, &DolphinMainWindow::slotPlacesPanelVisibilityChanged
);
2361 connect(this, &DolphinMainWindow::settingsChanged
, m_placesPanel
, &PlacesPanel::readSettings
);
2362 connect(m_placesPanel
, &PlacesPanel::storageTearDownRequested
, this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested
);
2363 connect(m_placesPanel
, &PlacesPanel::storageTearDownExternallyRequested
, this, &DolphinMainWindow::slotStorageTearDownExternallyRequested
);
2364 DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged(m_placesPanel
->isVisible());
2366 auto actionShowAllPlaces
= new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this);
2367 actionShowAllPlaces
->setCheckable(true);
2368 actionShowAllPlaces
->setDisabled(true);
2369 actionShowAllPlaces
->setWhatsThis(i18nc("@info:whatsthis",
2371 "all places in the places panel that have been hidden. They will "
2372 "appear semi-transparent and allow you to uncheck their \"Hide\" property."));
2374 connect(actionShowAllPlaces
, &QAction::triggered
, this, [this](bool checked
) {
2375 m_placesPanel
->setShowAll(checked
);
2377 connect(m_placesPanel
, &PlacesPanel::allPlacesShownChanged
, actionShowAllPlaces
, &QAction::setChecked
);
2380 ->action(QStringLiteral("show_places_panel"))
2381 ->setWhatsThis(xi18nc("@info:whatsthis",
2382 "<para>This toggles the "
2383 "<emphasis>places</emphasis> panel at the left side of the window."
2384 "</para><para>It allows you to go to locations you have "
2385 "bookmarked and to access disk or media attached to the computer "
2386 "or to the network. It also contains sections to find recently "
2387 "saved files or files of a certain type.</para>"));
2388 placesDock
->setWhatsThis(xi18nc("@info:whatsthis",
2389 "<para>This is the "
2390 "<emphasis>Places</emphasis> panel. It allows you to go to locations "
2391 "you have bookmarked and to access disk or media attached to the "
2392 "computer or to the network. It also contains sections to find "
2393 "recently saved files or files of a certain type.</para><para>"
2394 "Click on an entry to go there. Click with the right mouse button "
2395 "instead to open any entry in a new tab or new window.</para>"
2396 "<para>New entries can be added by dragging folders onto this panel. "
2397 "Right-click any section or entry to hide it. Right-click an empty "
2398 "space on this panel and select <interface>Show Hidden Places"
2399 "</interface> to display it again.</para>")
2402 QAction
*focusPlacesPanel
= actionCollection()->addAction(QStringLiteral("focus_places_panel"));
2403 focusPlacesPanel
->setText(i18nc("@action:inmenu View", "Focus Places Panel"));
2404 focusPlacesPanel
->setToolTip(i18nc("@info:tooltip", "Move keyboard focus to and from the Places panel."));
2405 focusPlacesPanel
->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
2406 actionCollection()->setDefaultShortcut(focusPlacesPanel
, Qt::CTRL
| Qt::Key_P
);
2407 connect(focusPlacesPanel
, &QAction::triggered
, this, &DolphinMainWindow::togglePlacesPanelFocus
);
2409 // Add actions into the "Panels" menu
2410 KActionMenu
*panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Show Panels"), this);
2411 actionCollection()->addAction(QStringLiteral("panels"), panelsMenu
);
2412 panelsMenu
->setIcon(QIcon::fromTheme(QStringLiteral("view-sidetree")));
2413 panelsMenu
->setPopupMode(QToolButton::InstantPopup
);
2414 const KActionCollection
*ac
= actionCollection();
2415 panelsMenu
->addAction(ac
->action(QStringLiteral("show_places_panel")));
2417 panelsMenu
->addAction(ac
->action(QStringLiteral("show_information_panel")));
2419 panelsMenu
->addAction(ac
->action(QStringLiteral("show_folders_panel")));
2420 panelsMenu
->addAction(ac
->action(QStringLiteral("show_terminal_panel")));
2421 panelsMenu
->addSeparator();
2422 panelsMenu
->addAction(lockLayoutAction
);
2423 panelsMenu
->addSeparator();
2424 panelsMenu
->addAction(actionShowAllPlaces
);
2425 panelsMenu
->addAction(focusPlacesPanel
);
2426 panelsMenu
->addAction(ac
->action(QStringLiteral("focus_terminal_panel")));
2428 connect(panelsMenu
->menu(), &QMenu::aboutToShow
, this, [actionShowAllPlaces
] {
2429 actionShowAllPlaces
->setEnabled(DolphinPlacesModelSingleton::instance().placesModel()->hiddenCount());
2433 void DolphinMainWindow::updateFileAndEditActions()
2435 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
2436 const KActionCollection
*col
= actionCollection();
2437 KFileItemListProperties
capabilitiesSource(list
);
2439 QAction
*renameAction
= col
->action(KStandardAction::name(KStandardAction::RenameFile
));
2440 QAction
*moveToTrashAction
= col
->action(KStandardAction::name(KStandardAction::MoveToTrash
));
2441 QAction
*deleteAction
= col
->action(KStandardAction::name(KStandardAction::DeleteFile
));
2442 QAction
*cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
2443 QAction
*duplicateAction
= col
->action(QStringLiteral("duplicate")); // see DolphinViewActionHandler
2444 QAction
*addToPlacesAction
= col
->action(QStringLiteral("add_to_places"));
2445 QAction
*copyToOtherViewAction
= col
->action(QStringLiteral("copy_to_inactive_split_view"));
2446 QAction
*moveToOtherViewAction
= col
->action(QStringLiteral("move_to_inactive_split_view"));
2447 QAction
*copyLocation
= col
->action(QString("copy_location"));
2449 if (list
.isEmpty()) {
2450 stateChanged(QStringLiteral("has_no_selection"));
2452 // All actions that need a selection to function can be enabled because they should trigger selection mode.
2453 renameAction
->setEnabled(true);
2454 moveToTrashAction
->setEnabled(true);
2455 deleteAction
->setEnabled(true);
2456 cutAction
->setEnabled(true);
2457 duplicateAction
->setEnabled(true);
2458 addToPlacesAction
->setEnabled(true);
2459 copyLocation
->setEnabled(true);
2460 // Them triggering selection mode and not directly acting on selected items is signified by adding "…" to their text.
2461 m_actionTextHelper
->textsWhenNothingIsSelectedEnabled(true);
2464 m_actionTextHelper
->textsWhenNothingIsSelectedEnabled(false);
2465 stateChanged(QStringLiteral("has_selection"));
2467 QAction
*deleteWithTrashShortcut
= col
->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
2468 QAction
*showTarget
= col
->action(QStringLiteral("show_target"));
2470 if (list
.length() == 1 && list
.first().isDir()) {
2471 addToPlacesAction
->setEnabled(true);
2473 addToPlacesAction
->setEnabled(false);
2476 const bool enableMoveToTrash
= capabilitiesSource
.isLocal() && capabilitiesSource
.supportsMoving();
2478 renameAction
->setEnabled(capabilitiesSource
.supportsMoving());
2479 m_disabledActionNotifier
->setDisabledReason(renameAction
, i18nc("@info", "Cannot rename: You do not have permission to rename items in this folder."));
2480 deleteAction
->setEnabled(capabilitiesSource
.supportsDeleting());
2481 m_disabledActionNotifier
->setDisabledReason(deleteAction
,
2482 i18nc("@info", "Cannot delete: You do not have permission to remove items from this folder."));
2483 cutAction
->setEnabled(capabilitiesSource
.supportsMoving());
2484 m_disabledActionNotifier
->setDisabledReason(cutAction
, i18nc("@info", "Cannot cut: You do not have permission to move items from this folder."));
2485 copyLocation
->setEnabled(list
.length() == 1);
2486 showTarget
->setEnabled(list
.length() == 1 && list
.at(0).isLink());
2487 duplicateAction
->setEnabled(capabilitiesSource
.supportsWriting());
2488 m_disabledActionNotifier
->setDisabledReason(duplicateAction
,
2489 i18nc("@info", "Cannot duplicate here: You do not have permission to create items in this folder."));
2491 if (enableMoveToTrash
) {
2492 moveToTrashAction
->setEnabled(true);
2493 deleteWithTrashShortcut
->setEnabled(false);
2494 m_disabledActionNotifier
->clearDisabledReason(deleteWithTrashShortcut
);
2496 moveToTrashAction
->setEnabled(false);
2497 deleteWithTrashShortcut
->setEnabled(capabilitiesSource
.supportsDeleting());
2498 m_disabledActionNotifier
->setDisabledReason(deleteWithTrashShortcut
,
2499 i18nc("@info", "Cannot delete: You do not have permission to remove items from this folder."));
2503 if (!m_tabWidget
->currentTabPage()->splitViewEnabled()) {
2504 // No need to set the disabled reason here, as it's obvious to the user that the reason is the split view being disabled.
2505 copyToOtherViewAction
->setEnabled(false);
2506 m_disabledActionNotifier
->clearDisabledReason(copyToOtherViewAction
);
2507 moveToOtherViewAction
->setEnabled(false);
2508 m_disabledActionNotifier
->clearDisabledReason(moveToOtherViewAction
);
2509 } else if (list
.isEmpty()) {
2510 copyToOtherViewAction
->setEnabled(false);
2511 m_disabledActionNotifier
->setDisabledReason(copyToOtherViewAction
, i18nc("@info", "Cannot copy to other view: No files selected."));
2512 moveToOtherViewAction
->setEnabled(false);
2513 m_disabledActionNotifier
->setDisabledReason(moveToOtherViewAction
, i18nc("@info", "Cannot move to other view: No files selected."));
2515 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
2516 KFileItem capabilitiesDestination
;
2518 if (tabPage
->primaryViewActive()) {
2519 capabilitiesDestination
= tabPage
->secondaryViewContainer()->rootItem();
2521 capabilitiesDestination
= tabPage
->primaryViewContainer()->rootItem();
2524 const auto destUrl
= capabilitiesDestination
.url();
2525 const bool allNotTargetOrigin
= std::all_of(list
.cbegin(), list
.cend(), [destUrl
](const KFileItem
&item
) {
2526 return item
.url().adjusted(QUrl::RemoveFilename
| QUrl::StripTrailingSlash
) != destUrl
;
2529 if (!allNotTargetOrigin
) {
2530 copyToOtherViewAction
->setEnabled(false);
2531 m_disabledActionNotifier
->setDisabledReason(copyToOtherViewAction
,
2532 i18nc("@info", "Cannot copy to other view: The other view already contains these items."));
2533 moveToOtherViewAction
->setEnabled(false);
2534 m_disabledActionNotifier
->setDisabledReason(moveToOtherViewAction
,
2535 i18nc("@info", "Cannot move to other view: The other view already contains these items."));
2536 } else if (!capabilitiesDestination
.isWritable()) {
2537 copyToOtherViewAction
->setEnabled(false);
2538 m_disabledActionNotifier
->setDisabledReason(
2539 copyToOtherViewAction
,
2540 i18nc("@info", "Cannot copy to other view: You do not have permission to write into the destination folder."));
2541 moveToOtherViewAction
->setEnabled(false);
2542 m_disabledActionNotifier
->setDisabledReason(
2543 moveToOtherViewAction
,
2544 i18nc("@info", "Cannot move to other view: You do not have permission to write into the destination folder."));
2546 copyToOtherViewAction
->setEnabled(true);
2547 moveToOtherViewAction
->setEnabled(capabilitiesSource
.supportsMoving());
2548 m_disabledActionNotifier
->setDisabledReason(
2549 moveToOtherViewAction
,
2550 i18nc("@info", "Cannot move to other view: You do not have permission to move items from this folder."));
2555 void DolphinMainWindow::updateViewActions()
2557 m_actionHandler
->updateViewActions();
2559 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
2560 toggleFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
2562 updateSplitActions();
2565 void DolphinMainWindow::updateGoActions()
2567 QAction
*goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
2568 const QUrl currentUrl
= m_activeViewContainer
->url();
2569 // I think this is one of the best places to firstly be confronted
2570 // with a file system and its hierarchy. Talking about the root
2571 // directory might seem too much here but it is the question that
2572 // naturally arises in this context.
2573 goUpAction
->setWhatsThis(xi18nc("@info:whatsthis",
2575 "the folder that contains the currently viewed one.</para>"
2576 "<para>All files and folders are organized in a hierarchical "
2577 "<emphasis>file system</emphasis>. At the top of this hierarchy is "
2578 "a directory that contains all data connected to this computer"
2579 "—the <emphasis>root directory</emphasis>.</para>"));
2580 goUpAction
->setEnabled(KIO::upUrl(currentUrl
) != currentUrl
);
2583 void DolphinMainWindow::refreshViews()
2585 m_tabWidget
->refreshViews();
2587 if (GeneralSettings::modifiedStartupSettings()) {
2588 updateWindowTitle();
2591 updateSplitActions();
2593 Q_EMIT
settingsChanged();
2596 void DolphinMainWindow::clearStatusBar()
2598 m_activeViewContainer
->statusBar()->resetToDefaultText();
2601 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
*container
)
2603 connect(container
, &DolphinViewContainer::showFilterBarChanged
, this, &DolphinMainWindow::updateFilterBarAction
);
2604 connect(container
, &DolphinViewContainer::writeStateChanged
, this, &DolphinMainWindow::slotWriteStateChanged
);
2605 slotWriteStateChanged(container
->view()->isFolderWritable());
2606 connect(container
, &DolphinViewContainer::searchModeEnabledChanged
, this, &DolphinMainWindow::updateSearchAction
);
2607 connect(container
, &DolphinViewContainer::captionChanged
, this, &DolphinMainWindow::updateWindowTitle
);
2608 connect(container
, &DolphinViewContainer::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2609 connect(container
, &DolphinViewContainer::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2611 const QAction
*toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
2612 connect(toggleSearchAction
, &QAction::triggered
, container
, &DolphinViewContainer::setSearchModeEnabled
);
2614 // Make the toggled state of the selection mode actions visually follow the selection mode state of the view.
2615 auto toggleSelectionModeAction
= actionCollection()->action(QStringLiteral("toggle_selection_mode"));
2616 toggleSelectionModeAction
->setChecked(m_activeViewContainer
->isSelectionModeEnabled());
2617 connect(m_activeViewContainer
, &DolphinViewContainer::selectionModeChanged
, toggleSelectionModeAction
, &QAction::setChecked
);
2619 const DolphinView
*view
= container
->view();
2620 connect(view
, &DolphinView::selectionChanged
, this, &DolphinMainWindow::slotSelectionChanged
);
2621 connect(view
, &DolphinView::requestItemInfo
, this, &DolphinMainWindow::requestItemInfo
);
2622 connect(view
, &DolphinView::fileItemsChanged
, this, &DolphinMainWindow::fileItemsChanged
);
2623 connect(view
, &DolphinView::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2624 connect(view
, &DolphinView::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2625 connect(view
, &DolphinView::windowRequested
, this, &DolphinMainWindow::openNewWindow
);
2626 connect(view
, &DolphinView::requestContextMenu
, this, &DolphinMainWindow::openContextMenu
);
2627 connect(view
, &DolphinView::directoryLoadingStarted
, this, &DolphinMainWindow::enableStopAction
);
2628 connect(view
, &DolphinView::directoryLoadingCompleted
, this, &DolphinMainWindow::disableStopAction
);
2629 connect(view
, &DolphinView::directoryLoadingCompleted
, this, &DolphinMainWindow::slotDirectoryLoadingCompleted
);
2630 connect(view
, &DolphinView::goBackRequested
, this, &DolphinMainWindow::goBack
);
2631 connect(view
, &DolphinView::goForwardRequested
, this, &DolphinMainWindow::goForward
);
2632 connect(view
, &DolphinView::urlActivated
, this, &DolphinMainWindow::handleUrl
);
2633 connect(view
, &DolphinView::goUpRequested
, this, &DolphinMainWindow::goUp
);
2634 connect(view
, &DolphinView::doubleClickViewBackground
, this, &DolphinMainWindow::slotDoubleClickViewBackground
);
2636 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::urlChanged
, this, &DolphinMainWindow::changeUrl
);
2637 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::historyChanged
, this, &DolphinMainWindow::updateHistory
);
2639 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2640 const KUrlNavigator
*navigator
=
2641 m_tabWidget
->currentTabPage()->primaryViewActive() ? navigators
->primaryUrlNavigator() : navigators
->secondaryUrlNavigator();
2643 QAction
*editableLocactionAction
= actionCollection()->action(QStringLiteral("editable_location"));
2644 editableLocactionAction
->setChecked(navigator
->isUrlEditable());
2645 connect(navigator
, &KUrlNavigator::editableStateChanged
, this, &DolphinMainWindow::slotEditableStateChanged
);
2646 connect(navigator
, &KUrlNavigator::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2647 connect(navigator
, &KUrlNavigator::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2648 connect(navigator
, &KUrlNavigator::newWindowRequested
, this, &DolphinMainWindow::openNewWindow
);
2651 void DolphinMainWindow::updateSplitActions()
2653 QAction
*popoutSplitAction
= actionCollection()->action(QStringLiteral("popout_split_view"));
2655 auto setActionPopupMode
= [this](KActionMenu
*action
, QToolButton::ToolButtonPopupMode popupMode
) {
2656 action
->setPopupMode(popupMode
);
2657 if (auto *buttonForAction
= qobject_cast
<QToolButton
*>(toolBar()->widgetForAction(action
))) {
2658 buttonForAction
->setPopupMode(popupMode
);
2662 const DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
2663 if (tabPage
->splitViewEnabled()) {
2664 if (GeneralSettings::closeActiveSplitView() ? tabPage
->primaryViewActive() : !tabPage
->primaryViewActive()) {
2665 m_splitViewAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2666 m_splitViewAction
->setToolTip(i18nc("@info", "Close left view"));
2667 m_splitViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close")));
2668 popoutSplitAction
->setText(i18nc("@action:intoolbar Move left view to a new window", "Pop out Left View"));
2669 popoutSplitAction
->setToolTip(i18nc("@info", "Move left view to a new window"));
2671 m_splitViewAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2672 m_splitViewAction
->setToolTip(i18nc("@info", "Close right view"));
2673 m_splitViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close")));
2674 popoutSplitAction
->setText(i18nc("@action:intoolbar Move right view to a new window", "Pop out Right View"));
2675 popoutSplitAction
->setToolTip(i18nc("@info", "Move right view to a new window"));
2677 popoutSplitAction
->setEnabled(true);
2678 if (!m_splitViewAction
->menu()) {
2679 setActionPopupMode(m_splitViewAction
, QToolButton::MenuButtonPopup
);
2680 m_splitViewAction
->setMenu(new QMenu
);
2681 m_splitViewAction
->addAction(popoutSplitAction
);
2684 m_splitViewAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2685 m_splitViewAction
->setToolTip(i18nc("@info", "Split view"));
2686 m_splitViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
2687 popoutSplitAction
->setText(i18nc("@action:intoolbar Move view in focus to a new window", "Pop out"));
2688 popoutSplitAction
->setEnabled(false);
2689 if (m_splitViewAction
->menu()) {
2690 m_splitViewAction
->removeAction(popoutSplitAction
);
2691 m_splitViewAction
->menu()->deleteLater();
2692 m_splitViewAction
->setMenu(nullptr);
2693 setActionPopupMode(m_splitViewAction
, QToolButton::DelayedPopup
);
2697 // Update state from toolbar action
2698 m_splitViewMenuAction
->setText(m_splitViewAction
->text());
2699 m_splitViewMenuAction
->setToolTip(m_splitViewAction
->toolTip());
2700 m_splitViewMenuAction
->setIcon(m_splitViewAction
->icon());
2703 void DolphinMainWindow::updateAllowedToolbarAreas()
2705 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2706 if (toolBar()->actions().contains(navigators
)) {
2707 toolBar()->setAllowedAreas(Qt::TopToolBarArea
| Qt::BottomToolBarArea
);
2708 if (toolBarArea(toolBar()) == Qt::LeftToolBarArea
|| toolBarArea(toolBar()) == Qt::RightToolBarArea
) {
2709 addToolBar(Qt::TopToolBarArea
, toolBar());
2712 toolBar()->setAllowedAreas(Qt::AllToolBarAreas
);
2716 bool DolphinMainWindow::isKompareInstalled() const
2718 static bool initialized
= false;
2719 static bool installed
= false;
2721 // TODO: maybe replace this approach later by using a menu
2722 // plugin like kdiff3plugin.cpp
2723 installed
= !QStandardPaths::findExecutable(QStringLiteral("kompare")).isEmpty();
2729 void DolphinMainWindow::createPanelAction(const QIcon
&icon
, const QKeySequence
&shortcut
, QDockWidget
*dockWidget
, const QString
&actionName
)
2731 auto dockAction
= dockWidget
->toggleViewAction();
2732 dockAction
->setIcon(icon
);
2733 dockAction
->setEnabled(true);
2735 QAction
*panelAction
= actionCollection()->addAction(actionName
, dockAction
);
2736 actionCollection()->setDefaultShortcut(panelAction
, shortcut
);
2739 void DolphinMainWindow::setupWhatsThis()
2742 menuBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2743 "<emphasis>Menubar</emphasis>. It provides access to commands and "
2744 "configuration options. Left-click on any of the menus on this "
2745 "bar to see its contents.</para><para>The Menubar can be hidden "
2746 "by unchecking <interface>Settings|Show Menubar</interface>. Then "
2747 "most of its contents become available through a <interface>Menu"
2748 "</interface> button on the <emphasis>Toolbar</emphasis>.</para>"));
2749 toolBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2750 "<emphasis>Toolbar</emphasis>. It allows quick access to "
2751 "frequently used actions.</para><para>It is highly customizable. "
2752 "All items you see in the <interface>Menu</interface> or "
2753 "in the <interface>Menubar</interface> can be placed on the "
2754 "Toolbar. Just right-click on it and select <interface>Configure "
2755 "Toolbars…</interface> or find this action within the <interface>"
2757 "</para><para>The location of the bar and the style of its "
2758 "buttons can also be changed in the right-click menu. Right-click "
2759 "a button if you want to show or hide its text.</para>"));
2760 m_tabWidget
->setWhatsThis(xi18nc("@info:whatsthis main view",
2761 "<para>Here you can see the <emphasis>folders</emphasis> and "
2762 "<emphasis>files</emphasis> that are at the location described in "
2763 "the <interface>Location Bar</interface> above. This area is the "
2764 "central part of this application where you navigate to the files "
2765 "you want to use.</para><para>For an elaborate and general "
2766 "introduction to this application <link "
2767 "url='https://userbase.kde.org/Dolphin/File_Management#Introduction_to_Dolphin'>"
2768 "click here</link>. This will open an introductory article from "
2769 "the <emphasis>KDE UserBase Wiki</emphasis>.</para><para>For brief "
2770 "explanations of all the features of this <emphasis>view</emphasis> "
2771 "<link url='help:/dolphin/dolphin-view.html'>click here</link> "
2772 "instead. This will open a page from the <emphasis>Handbook"
2773 "</emphasis> that covers the basics.</para>"));
2776 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings
))
2777 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window "
2778 "that lists the <emphasis>keyboard shortcuts</emphasis>.<nl/>"
2779 "There you can set up key combinations to trigger an action when "
2780 "they are pressed simultaneously. All commands in this application can "
2781 "be triggered this way.</para>"));
2782 actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars
))
2783 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window in which "
2784 "you can change which buttons appear on the <emphasis>Toolbar</emphasis>.</para>"
2785 "<para>All items you see in the <interface>Menu</interface> can also be placed on the Toolbar.</para>"));
2786 actionCollection()->action(KStandardAction::name(KStandardAction::Preferences
))
2787 ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window where you can "
2788 "change a multitude of settings for this application. For an explanation "
2789 "of the various settings go to the chapter <emphasis>Configuring Dolphin"
2790 "</emphasis> in <interface>Help|Dolphin Handbook</interface>."));
2794 auto setStandardActionWhatsThis
= [this](KStandardAction::StandardAction actionId
,
2795 const QString
&whatsThis
) {
2796 // Check for the existence of an action since it can be restricted through the Kiosk system
2797 if (auto *action
= actionCollection()->action(KStandardAction::name(actionId
))) {
2798 action
->setWhatsThis(whatsThis
);
2802 // i18n: If the external link isn't available in your language it might make
2803 // sense to state the external link's language in brackets to not
2804 // frustrate the user. If there are multiple languages that the user might
2805 // know with a reasonable chance you might want to have 2 external links.
2806 // The same might be true for any external link you translate.
2807 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>"));
2808 // (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 )
2810 setStandardActionWhatsThis(KStandardAction::WhatsThis
,
2811 xi18nc("@info:whatsthis whatsthis button",
2812 "<para>This is the button that invokes the help feature you are "
2813 "using right now! Click it, then click any component of this "
2814 "application to ask \"What's this?\" about it. The mouse cursor "
2815 "will change appearance if no help is available for a spot.</para>"
2816 "<para>There are two other ways to get help: "
2817 "The <link url='help:/dolphin/index.html'>Dolphin Handbook</link> and "
2818 "the <link url='https://userbase.kde.org/Dolphin/File_Management'>KDE "
2819 "UserBase Wiki</link>.</para><para>The \"What's this?\" help is "
2820 "missing in most other windows so don't get too used to this.</para>"));
2822 setStandardActionWhatsThis(KStandardAction::ReportBug
,
2823 xi18nc("@info:whatsthis","<para>This opens a "
2824 "window that will guide you through reporting errors or flaws "
2825 "in this application or in other KDE software.</para>"
2826 "<para>High-quality bug reports are much appreciated. To learn "
2827 "how to make your bug report as effective as possible "
2828 "<link url='https://community.kde.org/Get_Involved/Bug_Reporting'>"
2829 "click here</link>.</para>"));
2831 setStandardActionWhatsThis(KStandardAction::Donate
,
2832 xi18nc("@info:whatsthis", "<para>This opens a "
2833 "<emphasis>web page</emphasis> where you can donate to "
2834 "support the continued work on this application and many "
2835 "other projects by the <emphasis>KDE</emphasis> community.</para>"
2836 "<para>Donating is the easiest and fastest way to efficiently "
2837 "support KDE and its projects. KDE projects are available for "
2838 "free therefore your donation is needed to cover things that "
2839 "require money like servers, contributor meetings, etc.</para>"
2840 "<para><emphasis>KDE e.V.</emphasis> is the non-profit "
2841 "organization behind the KDE community.</para>"));
2843 setStandardActionWhatsThis(KStandardAction::SwitchApplicationLanguage
,
2844 xi18nc("@info:whatsthis",
2845 "With this you can change the language this application uses."
2846 "<nl/>You can even set secondary languages which will be used "
2847 "if texts are not available in your preferred language."));
2849 setStandardActionWhatsThis(KStandardAction::AboutApp
,
2850 xi18nc("@info:whatsthis","This opens a "
2851 "window that informs you about the version, license, "
2852 "used libraries and maintainers of this application."));
2854 setStandardActionWhatsThis(KStandardAction::AboutKDE
,
2855 xi18nc("@info:whatsthis","This opens a "
2856 "window with information about <emphasis>KDE</emphasis>. "
2857 "The KDE community are the people behind this free software."
2858 "<nl/>If you like using this application but don't know "
2859 "about KDE or want to see a cute dragon have a look!"));
2863 bool DolphinMainWindow::addHamburgerMenuToToolbar()
2865 QDomDocument domDocument
= KXMLGUIClient::domDocument();
2866 if (domDocument
.isNull()) {
2869 QDomNode toolbar
= domDocument
.elementsByTagName(QStringLiteral("ToolBar")).at(0);
2870 if (toolbar
.isNull()) {
2874 QDomElement hamburgerMenuElement
= domDocument
.createElement(QStringLiteral("Action"));
2875 hamburgerMenuElement
.setAttribute(QStringLiteral("name"), QStringLiteral("hamburger_menu"));
2876 toolbar
.appendChild(hamburgerMenuElement
);
2878 KXMLGUIFactory::saveConfigFile(domDocument
, xmlFile());
2882 // Make sure to also remove the <KXMLGUIFactory> and <QDomDocument> include
2883 // whenever this method is removed (maybe in the year ~2026).
2886 // Set a sane initial window size
2887 QSize
DolphinMainWindow::sizeHint() const
2889 return KXmlGuiWindow::sizeHint().expandedTo(QSize(760, 550));
2892 void DolphinMainWindow::saveNewToolbarConfig()
2894 KXmlGuiWindow::saveNewToolbarConfig(); // Applies the new config. This has to be called first
2895 // because the rest of this method decides things
2896 // based on the new config.
2897 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2898 if (!toolBar()->actions().contains(navigators
)) {
2899 m_tabWidget
->currentTabPage()->insertNavigatorsWidget(navigators
);
2901 updateAllowedToolbarAreas();
2902 (static_cast<KHamburgerMenu
*>(actionCollection()->action(KStandardAction::name(KStandardAction::HamburgerMenu
))))->hideActionsOf(toolBar());
2905 void DolphinMainWindow::toggleTerminalPanelFocus()
2907 if (!m_terminalPanel
->isVisible()) {
2908 actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger(); // Also moves focus to the panel.
2909 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2913 if (m_terminalPanel
->terminalHasFocus()) {
2914 m_activeViewContainer
->view()->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2915 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2919 m_terminalPanel
->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2920 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2923 void DolphinMainWindow::togglePlacesPanelFocus()
2925 if (!m_placesPanel
->isVisible()) {
2926 actionCollection()->action(QStringLiteral("show_places_panel"))->trigger(); // Also moves focus to the panel.
2927 actionCollection()->action(QStringLiteral("focus_places_panel"))->setText(i18nc("@action:inmenu View", "Defocus Terminal Panel"));
2931 if (m_placesPanel
->hasFocus()) {
2932 m_activeViewContainer
->view()->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2933 actionCollection()->action(QStringLiteral("focus_places_panel"))->setText(i18nc("@action:inmenu View", "Focus Places Panel"));
2937 m_placesPanel
->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2938 actionCollection()->action(QStringLiteral("focus_places_panel"))->setText(i18nc("@action:inmenu View", "Defocus Places Panel"));
2941 DolphinMainWindow::UndoUiInterface::UndoUiInterface()
2942 : KIO::FileUndoManager::UiInterface()
2946 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2950 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
*job
)
2952 DolphinMainWindow
*mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2954 DolphinViewContainer
*container
= mainWin
->activeViewContainer();
2955 container
->showMessage(job
->errorString(), KMessageWidget::Error
);
2957 KIO::FileUndoManager::UiInterface::jobError(job
);
2961 bool DolphinMainWindow::isUrlOpen(const QString
&url
)
2963 return m_tabWidget
->isUrlOpen(QUrl::fromUserInput(url
));
2966 bool DolphinMainWindow::isItemVisibleInAnyView(const QString
&urlOfItem
)
2968 return m_tabWidget
->isItemVisibleInAnyView(QUrl::fromUserInput(urlOfItem
));
2971 void DolphinMainWindow::slotDoubleClickViewBackground(Qt::MouseButton button
)
2973 if (button
== Qt::MouseButton::LeftButton
) {
2974 // only handle left mouse button for now
2978 GeneralSettings
*settings
= GeneralSettings::self();
2979 QString clickAction
= settings
->doubleClickViewAction();
2981 DolphinView
*view
= activeViewContainer()->view();
2982 if (view
== nullptr || clickAction
== "none") {
2986 if (clickAction
== customCommand
) {
2987 // run custom command set by the user
2988 QString path
= view
->url().toLocalFile();
2989 QString clickCustomAction
= settings
->doubleClickViewCustomAction();
2990 clickCustomAction
.replace("{path}", path
.prepend('"').append('"'));
2992 m_job
= new KIO::CommandLauncherJob(clickCustomAction
);
2993 m_job
->setUiDelegate(new KDialogJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
2997 // get the action set by the user and trigger it
2998 const KActionCollection
*actions
= actionCollection();
2999 QAction
*action
= actions
->action(clickAction
);
3000 if (action
== nullptr) {
3001 qCWarning(DolphinDebug
) << QStringLiteral("Double-click view: action `%1` was not found").arg(clickAction
);
3008 #include "moc_dolphinmainwindow.cpp"