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>
57 #include <KRuntimePlatform>
59 #include <KShortcutsDialog>
60 #include <KStandardAction>
62 #include <KTerminalLauncherJob>
63 #include <KToggleAction>
65 #include <KToolBarPopupAction>
66 #include <KUrlComboBox>
67 #include <KUrlNavigator>
68 #include <KWindowSystem>
69 #include <KXMLGUIFactory>
71 #include <kwidgetsaddons_version.h>
73 #include <QApplication>
75 #include <QCloseEvent>
76 #include <QDesktopServices>
78 #include <QDomDocument>
82 #include <QPushButton>
84 #include <QStandardPaths>
86 #include <QToolButton>
87 #include <QtConcurrentRun>
88 #include <dolphindebug.h>
93 #include <KStartupInfo>
98 // Used for GeneralSettings::version() to determine whether
99 // an updated version of Dolphin is running, so as to migrate
100 // removed/renamed ...etc config entries; increment it in such
102 const int CurrentDolphinVersion
= 202;
103 // The maximum number of entries in the back/forward popup menu
104 const int MaxNumberOfNavigationentries
= 12;
105 // The maximum number of "Go to Tab" shortcuts
106 const int MaxActivateTabShortcuts
= 9;
109 DolphinMainWindow::DolphinMainWindow()
110 : KXmlGuiWindow(nullptr)
111 , m_newFileMenu(nullptr)
112 , m_tabWidget(nullptr)
113 , m_activeViewContainer(nullptr)
114 , m_actionHandler(nullptr)
115 , m_remoteEncoding(nullptr)
117 , m_bookmarkHandler(nullptr)
118 , m_disabledActionNotifier(nullptr)
119 , m_lastHandleUrlOpenJob(nullptr)
120 , m_terminalPanel(nullptr)
121 , m_placesPanel(nullptr)
122 , m_tearDownFromPlacesRequested(false)
123 , m_backAction(nullptr)
124 , m_forwardAction(nullptr)
125 , m_splitViewAction(nullptr)
126 , m_splitViewMenuAction(nullptr)
127 , m_sessionSaveTimer(nullptr)
128 , m_sessionSaveWatcher(nullptr)
129 , m_sessionSaveScheduled(false)
131 Q_INIT_RESOURCE(dolphin
);
133 new MainWindowAdaptor(this);
136 setWindowFlags(Qt::WindowContextHelpButtonHint
);
138 setComponentName(QStringLiteral("dolphin"), QGuiApplication::applicationDisplayName());
139 setObjectName(QStringLiteral("Dolphin#"));
141 setStateConfigGroup("State");
143 #if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
144 new KColorSchemeManager(this); // Sets a sensible color scheme which fixes unreadable icons and text on Windows.
147 connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::errorMessage
, this, &DolphinMainWindow::showErrorMessage
);
149 KIO::FileUndoManager
*undoManager
= KIO::FileUndoManager::self();
150 undoManager
->setUiInterface(new UndoUiInterface());
152 connect(undoManager
, &KIO::FileUndoManager::undoAvailable
, this, &DolphinMainWindow::slotUndoAvailable
);
153 connect(undoManager
, &KIO::FileUndoManager::undoTextChanged
, this, &DolphinMainWindow::slotUndoTextChanged
);
154 connect(undoManager
, &KIO::FileUndoManager::jobRecordingStarted
, this, &DolphinMainWindow::clearStatusBar
);
155 connect(undoManager
, &KIO::FileUndoManager::jobRecordingFinished
, this, &DolphinMainWindow::showCommand
);
157 const bool firstRun
= (GeneralSettings::version() < 200);
159 GeneralSettings::setViewPropsTimestamp(QDateTime::currentDateTime());
162 setAcceptDrops(true);
164 auto *navigatorsWidgetAction
= new DolphinNavigatorsWidgetAction(this);
165 actionCollection()->addAction(QStringLiteral("url_navigators"), navigatorsWidgetAction
);
166 m_tabWidget
= new DolphinTabWidget(navigatorsWidgetAction
, this);
167 m_tabWidget
->setObjectName("tabWidget");
168 connect(m_tabWidget
, &DolphinTabWidget::activeViewChanged
, this, &DolphinMainWindow::activeViewChanged
);
169 connect(m_tabWidget
, &DolphinTabWidget::tabCountChanged
, this, &DolphinMainWindow::tabCountChanged
);
170 connect(m_tabWidget
, &DolphinTabWidget::currentUrlChanged
, this, &DolphinMainWindow::updateWindowTitle
);
171 setCentralWidget(m_tabWidget
);
173 m_actionTextHelper
= new SelectionMode::ActionTextHelper(this);
176 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), m_actionTextHelper
, this);
177 connect(m_actionHandler
, &DolphinViewActionHandler::actionBeingHandled
, this, &DolphinMainWindow::clearStatusBar
);
178 connect(m_actionHandler
, &DolphinViewActionHandler::createDirectoryTriggered
, this, &DolphinMainWindow::createDirectory
);
179 connect(m_actionHandler
, &DolphinViewActionHandler::selectionModeChangeTriggered
, this, &DolphinMainWindow::slotSetSelectionMode
);
181 Q_CHECK_PTR(actionCollection()->action(QStringLiteral("create_dir")));
182 m_newFileMenu
->setNewFolderShortcutAction(actionCollection()->action(QStringLiteral("create_dir")));
184 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
185 connect(this, &DolphinMainWindow::urlChanged
, m_remoteEncoding
, &DolphinRemoteEncoding::slotAboutToOpenUrl
);
187 m_disabledActionNotifier
= new DisabledActionNotifier(this);
188 connect(m_disabledActionNotifier
, &DisabledActionNotifier::disabledActionTriggered
, this, [this](const QAction
*, QString reason
) {
189 m_activeViewContainer
->showMessage(reason
, KMessageWidget::Warning
);
194 const bool usePhoneUi
{KRuntimePlatform::runtimePlatform().contains(QLatin1String("phone"))};
195 setupGUI(Save
| Create
| ToolBar
, usePhoneUi
? QStringLiteral("dolphinuiforphones.rc") : QString() /* load the default dolphinui.rc file */);
196 stateChanged(QStringLiteral("new_file"));
198 QClipboard
*clipboard
= QApplication::clipboard();
199 connect(clipboard
, &QClipboard::dataChanged
, this, &DolphinMainWindow::updatePasteAction
);
201 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
202 toggleFilterBarAction
->setChecked(GeneralSettings::filterBar());
205 menuBar()->setVisible(false);
208 Q_ASSERT(qobject_cast
<QDockWidget
*>(m_placesPanel
->parent()));
209 m_placesPanel
->parentWidget()->hide();
210 auto settings
= GeneralSettings::self();
211 settings
->setShowZoomSlider(false); // Zooming can be done with pinch gestures instead and we are short on horizontal space.
212 settings
->setRenameInline(false); // This works around inline renaming currently not working well with virtual keyboards.
213 settings
->save(); // Otherwise the RenameInline setting is not picked up for the first time Dolphin is used.
217 const bool showMenu
= !menuBar()->isHidden();
218 QAction
*showMenuBarAction
= actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar
));
219 showMenuBarAction
->setChecked(showMenu
); // workaround for bug #171080
221 auto hamburgerMenu
= static_cast<KHamburgerMenu
*>(actionCollection()->action(KStandardAction::name(KStandardAction::HamburgerMenu
)));
222 hamburgerMenu
->setMenuBar(menuBar());
223 hamburgerMenu
->setShowMenuBarAction(showMenuBarAction
);
224 connect(hamburgerMenu
, &KHamburgerMenu::aboutToShowMenu
, this, &DolphinMainWindow::updateHamburgerMenu
);
225 hamburgerMenu
->hideActionsOf(toolBar());
226 if (GeneralSettings::version() < 201 && !toolBar()->actions().contains(hamburgerMenu
)) {
227 addHamburgerMenuToToolbar();
230 updateAllowedToolbarAreas();
232 // enable middle-click on back/forward/up to open in a new tab
233 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
234 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotToolBarActionMiddleClicked
);
235 toolBar()->installEventFilter(middleClickEventFilter
);
239 connect(KSycoca::self(), &KSycoca::databaseChanged
, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
241 QTimer::singleShot(0, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
243 m_fileItemActions
.setParentWidget(this);
244 connect(&m_fileItemActions
, &KFileItemActions::error
, this, [this](const QString
&errorMessage
) {
245 showErrorMessage(errorMessage
);
248 connect(GeneralSettings::self(), &GeneralSettings::splitViewChanged
, this, &DolphinMainWindow::slotSplitViewChanged
);
251 DolphinMainWindow::~DolphinMainWindow()
253 // This fixes a crash on Wayland when closing the mainwindow while another dialog is open.
254 disconnect(QGuiApplication::clipboard(), &QClipboard::dataChanged
, this, &DolphinMainWindow::updatePasteAction
);
256 // This fixes a crash in dolphinmainwindowtest where the connection below fires even though the KMainWindow destructor of this object is already running.
257 Q_CHECK_PTR(qobject_cast
<DolphinDockWidget
*>(m_placesPanel
->parent()));
258 disconnect(static_cast<DolphinDockWidget
*>(m_placesPanel
->parent()),
259 &DolphinDockWidget::visibilityChanged
,
261 &DolphinMainWindow::slotPlacesPanelVisibilityChanged
);
264 QVector
<DolphinViewContainer
*> DolphinMainWindow::viewContainers() const
266 QVector
<DolphinViewContainer
*> viewContainers
;
268 for (int i
= 0; i
< m_tabWidget
->count(); ++i
) {
269 DolphinTabPage
*tabPage
= m_tabWidget
->tabPageAt(i
);
271 viewContainers
<< tabPage
->primaryViewContainer();
272 if (tabPage
->splitViewEnabled()) {
273 viewContainers
<< tabPage
->secondaryViewContainer();
276 return viewContainers
;
279 void DolphinMainWindow::openDirectories(const QList
<QUrl
> &dirs
, bool splitView
)
281 m_tabWidget
->openDirectories(dirs
, splitView
);
284 void DolphinMainWindow::openDirectories(const QStringList
&dirs
, bool splitView
)
286 openDirectories(QUrl::fromStringList(dirs
), splitView
);
289 void DolphinMainWindow::openFiles(const QList
<QUrl
> &files
, bool splitView
)
291 m_tabWidget
->openFiles(files
, splitView
);
294 bool DolphinMainWindow::isFoldersPanelEnabled() const
296 return actionCollection()->action(QStringLiteral("show_folders_panel"))->isChecked();
299 bool DolphinMainWindow::isInformationPanelEnabled() const
302 return actionCollection()->action(QStringLiteral("show_information_panel"))->isChecked();
308 bool DolphinMainWindow::isSplitViewEnabledInCurrentTab() const
310 return m_tabWidget
->currentTabPage()->splitViewEnabled();
313 void DolphinMainWindow::openFiles(const QStringList
&files
, bool splitView
)
315 openFiles(QUrl::fromStringList(files
), splitView
);
318 void DolphinMainWindow::activateWindow(const QString
&activationToken
)
320 window()->setAttribute(Qt::WA_NativeWindow
, true);
322 if (KWindowSystem::isPlatformWayland()) {
323 KWindowSystem::setCurrentXdgActivationToken(activationToken
);
324 } else if (KWindowSystem::isPlatformX11()) {
326 KStartupInfo::setNewStartupId(window()->windowHandle(), activationToken
.toUtf8());
330 KWindowSystem::activateWindow(window()->windowHandle());
333 bool DolphinMainWindow::isActiveWindow()
335 return window()->isActiveWindow();
338 void DolphinMainWindow::showCommand(CommandType command
)
340 DolphinStatusBar
*statusBar
= m_activeViewContainer
->statusBar();
342 case KIO::FileUndoManager::Copy
:
343 statusBar
->setText(i18nc("@info:status", "Successfully copied."));
345 case KIO::FileUndoManager::Move
:
346 statusBar
->setText(i18nc("@info:status", "Successfully moved."));
348 case KIO::FileUndoManager::Link
:
349 statusBar
->setText(i18nc("@info:status", "Successfully linked."));
351 case KIO::FileUndoManager::Trash
:
352 statusBar
->setText(i18nc("@info:status", "Successfully moved to trash."));
354 case KIO::FileUndoManager::Rename
:
355 statusBar
->setText(i18nc("@info:status", "Successfully renamed."));
358 case KIO::FileUndoManager::Mkdir
:
359 statusBar
->setText(i18nc("@info:status", "Created folder."));
367 void DolphinMainWindow::pasteIntoFolder()
369 m_activeViewContainer
->view()->pasteIntoFolder();
372 void DolphinMainWindow::changeUrl(const QUrl
&url
)
374 if (!KProtocolManager::supportsListing(url
)) {
375 // The URL navigator only checks for validity, not
376 // if the URL can be listed. An error message is
377 // shown due to DolphinViewContainer::restoreView().
381 m_activeViewContainer
->setUrl(url
);
382 updateFileAndEditActions();
387 // will signal used urls to activities manager, too
388 m_recentFiles
->addUrl(url
, QString(), "inode/directory");
390 Q_EMIT
urlChanged(url
);
393 void DolphinMainWindow::slotTerminalDirectoryChanged(const QUrl
&url
)
395 if (m_tearDownFromPlacesRequested
&& url
== QUrl::fromLocalFile(QDir::homePath())) {
396 m_placesPanel
->proceedWithTearDown();
397 m_tearDownFromPlacesRequested
= false;
400 m_activeViewContainer
->setAutoGrabFocus(false);
402 m_activeViewContainer
->setAutoGrabFocus(true);
405 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
407 KToggleAction
*editableLocationAction
= static_cast<KToggleAction
*>(actionCollection()->action(QStringLiteral("editable_location")));
408 editableLocationAction
->setChecked(editable
);
411 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
&selection
)
413 updateFileAndEditActions();
415 const int selectedUrlsCount
= m_tabWidget
->currentTabPage()->selectedItemsCount();
417 QAction
*compareFilesAction
= actionCollection()->action(QStringLiteral("compare_files"));
418 if (selectedUrlsCount
== 2) {
419 compareFilesAction
->setEnabled(isKompareInstalled());
421 compareFilesAction
->setEnabled(false);
424 Q_EMIT
selectionChanged(selection
);
427 void DolphinMainWindow::updateHistory()
429 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
430 const int index
= urlNavigator
->historyIndex();
432 QAction
*backAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Back
));
434 backAction
->setToolTip(i18nc("@info", "Go back"));
435 backAction
->setWhatsThis(i18nc("@info:whatsthis go back", "Return to the previously viewed folder."));
436 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
439 QAction
*forwardAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Forward
));
441 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
442 forwardAction
->setWhatsThis(xi18nc("@info:whatsthis go forward", "This undoes a <interface>Go|Back</interface> action."));
443 forwardAction
->setEnabled(index
> 0);
447 void DolphinMainWindow::updateFilterBarAction(bool show
)
449 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
450 toggleFilterBarAction
->setChecked(show
);
453 void DolphinMainWindow::openNewMainWindow()
455 Dolphin::openNewWindow({m_activeViewContainer
->url()}, this);
458 void DolphinMainWindow::openNewActivatedTab()
460 // keep browsers compatibility, new tab is always after last one
461 auto openNewTabAfterLastTabConfigured
= GeneralSettings::openNewTabAfterLastTab();
462 GeneralSettings::setOpenNewTabAfterLastTab(true);
463 m_tabWidget
->openNewActivatedTab();
464 GeneralSettings::setOpenNewTabAfterLastTab(openNewTabAfterLastTabConfigured
);
467 void DolphinMainWindow::addToPlaces()
472 // If nothing is selected, act on the current dir
473 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
474 url
= m_activeViewContainer
->url();
475 name
= m_activeViewContainer
->placesText();
477 const auto dirToAdd
= m_activeViewContainer
->view()->selectedItems().first();
478 url
= dirToAdd
.url();
479 name
= dirToAdd
.name();
483 if (m_activeViewContainer
->isSearchModeEnabled()) {
484 icon
= QStringLiteral("folder-saved-search-symbolic");
486 icon
= KIO::iconNameForUrl(url
);
488 DolphinPlacesModelSingleton::instance().placesModel()->addPlace(name
, url
, icon
);
492 DolphinTabPage
*DolphinMainWindow::openNewTab(const QUrl
&url
)
494 return m_tabWidget
->openNewTab(url
, QUrl());
497 void DolphinMainWindow::openNewTabAndActivate(const QUrl
&url
)
499 m_tabWidget
->openNewActivatedTab(url
, QUrl());
502 void DolphinMainWindow::openNewWindow(const QUrl
&url
)
504 Dolphin::openNewWindow({url
}, this);
507 void DolphinMainWindow::slotSplitViewChanged()
509 m_tabWidget
->currentTabPage()->setSplitViewEnabled(GeneralSettings::splitView(), WithAnimation
);
510 updateSplitActions();
513 void DolphinMainWindow::openInNewTab()
515 const KFileItemList
&list
= m_activeViewContainer
->view()->selectedItems();
516 bool tabCreated
= false;
518 for (const KFileItem
&item
: list
) {
519 const QUrl
&url
= DolphinView::openItemAsFolderUrl(item
);
520 if (!url
.isEmpty()) {
526 // if no new tab has been created from the selection
527 // open the current directory in a new tab
529 openNewTab(m_activeViewContainer
->url());
533 void DolphinMainWindow::openInNewWindow()
537 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
538 if (list
.isEmpty()) {
539 newWindowUrl
= m_activeViewContainer
->url();
540 } else if (list
.count() == 1) {
541 const KFileItem
&item
= list
.first();
542 newWindowUrl
= DolphinView::openItemAsFolderUrl(item
);
545 if (!newWindowUrl
.isEmpty()) {
546 Dolphin::openNewWindow({newWindowUrl
}, this);
550 void DolphinMainWindow::openInSplitView(const QUrl
&url
)
552 QUrl newSplitViewUrl
= url
;
554 if (newSplitViewUrl
.isEmpty()) {
555 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
556 if (list
.count() == 1) {
557 const KFileItem
&item
= list
.first();
558 newSplitViewUrl
= DolphinView::openItemAsFolderUrl(item
);
562 if (newSplitViewUrl
.isEmpty()) {
566 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
567 if (tabPage
->splitViewEnabled()) {
568 tabPage
->switchActiveView();
569 tabPage
->activeViewContainer()->setUrl(newSplitViewUrl
);
571 tabPage
->setSplitViewEnabled(true, WithAnimation
, newSplitViewUrl
);
576 void DolphinMainWindow::showTarget()
578 const KFileItem link
= m_activeViewContainer
->view()->selectedItems().at(0);
579 const QUrl destinationUrl
= link
.url().resolved(QUrl(link
.linkDest()));
581 auto job
= KIO::stat(destinationUrl
, KIO::StatJob::SourceSide
, KIO::StatNoDetails
);
583 connect(job
, &KJob::finished
, this, [this, destinationUrl
](KJob
*job
) {
584 KIO::StatJob
*statJob
= static_cast<KIO::StatJob
*>(job
);
586 if (statJob
->error()) {
587 m_activeViewContainer
->showMessage(job
->errorString(), KMessageWidget::Error
);
589 KIO::highlightInFileManager({destinationUrl
});
594 bool DolphinMainWindow::event(QEvent
*event
)
596 if (event
->type() == QEvent::ShortcutOverride
) {
597 const QKeyEvent
*keyEvent
= static_cast<QKeyEvent
*>(event
);
598 if (keyEvent
->key() == Qt::Key_Space
&& m_activeViewContainer
->view()->handleSpaceAsNormalKey()) {
604 return KXmlGuiWindow::event(event
);
607 void DolphinMainWindow::showEvent(QShowEvent
*event
)
609 KXmlGuiWindow::showEvent(event
);
611 if (!event
->spontaneous() && m_activeViewContainer
) {
612 m_activeViewContainer
->view()->setFocus();
616 void DolphinMainWindow::closeEvent(QCloseEvent
*event
)
618 // Find out if Dolphin is closed directly by the user or
619 // by the session manager because the session is closed
620 bool closedByUser
= true;
621 if (qApp
->isSavingSession()) {
622 closedByUser
= false;
625 if (m_tabWidget
->count() > 1 && GeneralSettings::confirmClosingMultipleTabs() && !GeneralSettings::rememberOpenedTabs() && closedByUser
) {
626 // Ask the user if he really wants to quit and close all tabs.
627 // Open a confirmation dialog with 3 buttons:
628 // QDialogButtonBox::Yes -> Quit
629 // QDialogButtonBox::No -> Close only the current tab
630 // QDialogButtonBox::Cancel -> do nothing
631 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
632 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
633 dialog
->setModal(true);
634 QDialogButtonBox
*buttons
= new QDialogButtonBox(QDialogButtonBox::Yes
| QDialogButtonBox::No
| QDialogButtonBox::Cancel
);
635 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
),
636 KGuiItem(i18nc("@action:button 'Quit Dolphin' button", "&Quit %1", QGuiApplication::applicationDisplayName()),
637 QIcon::fromTheme(QStringLiteral("application-exit"))));
638 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("C&lose Current Tab"), QIcon::fromTheme(QStringLiteral("tab-close"))));
639 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
640 buttons
->button(QDialogButtonBox::Yes
)->setDefault(true);
642 bool doNotAskAgainCheckboxResult
= false;
644 const auto result
= KMessageBox::createKMessageBox(dialog
,
646 QMessageBox::Warning
,
647 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
649 i18n("Do not ask again"),
650 &doNotAskAgainCheckboxResult
,
651 KMessageBox::Notify
);
653 if (doNotAskAgainCheckboxResult
) {
654 GeneralSettings::setConfirmClosingMultipleTabs(false);
658 case QDialogButtonBox::Yes
:
661 case QDialogButtonBox::No
:
662 // Close only the current tab
663 m_tabWidget
->closeTab();
671 if (m_terminalPanel
&& m_terminalPanel
->hasProgramRunning() && GeneralSettings::confirmClosingTerminalRunningProgram() && closedByUser
) {
672 // Ask if the user really wants to quit Dolphin with a program that is still running in the Terminal panel
673 // Open a confirmation dialog with 3 buttons:
674 // QDialogButtonBox::Yes -> Quit
675 // QDialogButtonBox::No -> Show Terminal Panel
676 // QDialogButtonBox::Cancel -> do nothing
677 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
678 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
679 dialog
->setModal(true);
680 auto standardButtons
= QDialogButtonBox::Yes
| QDialogButtonBox::Cancel
;
681 if (!m_terminalPanel
->isVisible()) {
682 standardButtons
|= QDialogButtonBox::No
;
684 QDialogButtonBox
*buttons
= new QDialogButtonBox(standardButtons
);
685 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KStandardGuiItem::quit());
686 if (!m_terminalPanel
->isVisible()) {
687 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("Show &Terminal Panel"), QIcon::fromTheme(QStringLiteral("dialog-scripts"))));
689 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
691 bool doNotAskAgainCheckboxResult
= false;
693 const auto result
= KMessageBox::createKMessageBox(
696 QMessageBox::Warning
,
697 i18n("The program '%1' is still running in the Terminal panel. Are you sure you want to quit?", m_terminalPanel
->runningProgramName()),
699 i18n("Do not ask again"),
700 &doNotAskAgainCheckboxResult
,
701 KMessageBox::Notify
| KMessageBox::Dangerous
);
703 if (doNotAskAgainCheckboxResult
) {
704 GeneralSettings::setConfirmClosingTerminalRunningProgram(false);
708 case QDialogButtonBox::Yes
:
711 case QDialogButtonBox::No
:
712 actionCollection()->action("show_terminal_panel")->trigger();
713 // Do not quit, ignore quit event
721 if (m_sessionSaveTimer
&& (m_sessionSaveTimer
->isActive() || m_sessionSaveWatcher
->isRunning())) {
722 const bool sessionSaveTimerActive
= m_sessionSaveTimer
->isActive();
724 m_sessionSaveTimer
->stop();
725 m_sessionSaveWatcher
->disconnect();
726 m_sessionSaveWatcher
->waitForFinished();
728 if (sessionSaveTimerActive
|| m_sessionSaveScheduled
) {
733 GeneralSettings::setVersion(CurrentDolphinVersion
);
734 GeneralSettings::self()->save();
736 KXmlGuiWindow::closeEvent(event
);
739 void DolphinMainWindow::slotSaveSession()
741 m_sessionSaveScheduled
= false;
743 if (m_sessionSaveWatcher
->isRunning()) {
744 // The previous session is still being saved - schedule another save.
745 m_sessionSaveWatcher
->disconnect();
746 connect(m_sessionSaveWatcher
, &QFutureWatcher
<void>::finished
, this, &DolphinMainWindow::slotSaveSession
, Qt::SingleShotConnection
);
747 m_sessionSaveScheduled
= true;
748 } else if (!m_sessionSaveTimer
->isActive()) {
749 // No point in saving the session if the timer is running (since it will save the session again when it times out).
750 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
751 KConfig
*config
= KConfigGui::sessionConfig();
752 saveGlobalProperties(config
);
753 savePropertiesInternal(config
, 1);
755 auto future
= QtConcurrent::run([config
]() {
758 m_sessionSaveWatcher
->setFuture(future
);
762 void DolphinMainWindow::setSessionAutoSaveEnabled(bool enable
)
765 if (!m_sessionSaveTimer
) {
766 m_sessionSaveTimer
= new QTimer(this);
767 m_sessionSaveWatcher
= new QFutureWatcher
<void>(this);
768 m_sessionSaveTimer
->setSingleShot(true);
769 m_sessionSaveTimer
->setInterval(22000);
771 connect(m_sessionSaveTimer
, &QTimer::timeout
, this, &DolphinMainWindow::slotSaveSession
);
774 connect(m_tabWidget
, &DolphinTabWidget::urlChanged
, m_sessionSaveTimer
, qOverload
<>(&QTimer::start
), Qt::UniqueConnection
);
775 connect(m_tabWidget
, &DolphinTabWidget::tabCountChanged
, m_sessionSaveTimer
, qOverload
<>(&QTimer::start
), Qt::UniqueConnection
);
776 connect(m_tabWidget
, &DolphinTabWidget::activeViewChanged
, m_sessionSaveTimer
, qOverload
<>(&QTimer::start
), Qt::UniqueConnection
);
777 } else if (m_sessionSaveTimer
) {
778 m_sessionSaveTimer
->stop();
779 m_sessionSaveWatcher
->disconnect();
780 m_sessionSaveScheduled
= false;
782 m_sessionSaveWatcher
->waitForFinished();
784 m_sessionSaveTimer
->deleteLater();
785 m_sessionSaveWatcher
->deleteLater();
786 m_sessionSaveTimer
= nullptr;
787 m_sessionSaveWatcher
= nullptr;
791 void DolphinMainWindow::saveProperties(KConfigGroup
&group
)
793 m_tabWidget
->saveProperties(group
);
796 void DolphinMainWindow::readProperties(const KConfigGroup
&group
)
798 m_tabWidget
->readProperties(group
);
801 void DolphinMainWindow::updateNewMenu()
803 m_newFileMenu
->checkUpToDate();
804 m_newFileMenu
->setWorkingDirectory(activeViewContainer()->url());
807 void DolphinMainWindow::createDirectory()
809 // When creating directory, namejob is being run. In network folders,
810 // this job can take long time, so instead of starting multiple namejobs,
811 // just check if we are already running one. This prevents opening multiple
812 // dialogs. BUG:481401
813 if (!m_newFileMenu
->isCreateDirectoryRunning()) {
814 m_newFileMenu
->setWorkingDirectory(activeViewContainer()->url());
815 m_newFileMenu
->createDirectory();
819 void DolphinMainWindow::quit()
824 void DolphinMainWindow::showErrorMessage(const QString
&message
)
826 m_activeViewContainer
->showMessage(message
, KMessageWidget::Error
);
829 void DolphinMainWindow::slotUndoAvailable(bool available
)
831 QAction
*undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
833 undoAction
->setEnabled(available
);
837 void DolphinMainWindow::slotUndoTextChanged(const QString
&text
)
839 QAction
*undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
841 undoAction
->setText(text
);
845 void DolphinMainWindow::undo()
848 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
849 KIO::FileUndoManager::self()->undo();
852 void DolphinMainWindow::cut()
854 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
855 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CutContents
);
857 m_activeViewContainer
->view()->cutSelectedItemsToClipboard();
858 m_activeViewContainer
->setSelectionModeEnabled(false);
862 void DolphinMainWindow::copy()
864 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
865 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CopyContents
);
867 m_activeViewContainer
->view()->copySelectedItemsToClipboard();
868 m_activeViewContainer
->setSelectionModeEnabled(false);
872 void DolphinMainWindow::paste()
874 m_activeViewContainer
->view()->paste();
877 void DolphinMainWindow::find()
879 m_activeViewContainer
->setSearchModeEnabled(true);
882 void DolphinMainWindow::updateSearchAction()
884 QAction
*toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
885 toggleSearchAction
->setChecked(m_activeViewContainer
->isSearchModeEnabled());
888 void DolphinMainWindow::updatePasteAction()
890 QAction
*pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
891 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
892 pasteAction
->setEnabled(pasteInfo
.first
);
893 m_disabledActionNotifier
->setDisabledReason(pasteAction
,
894 m_activeViewContainer
->rootItem().isWritable()
895 ? i18nc("@info", "Cannot paste: The clipboard is empty.")
896 : i18nc("@info", "Cannot paste: You do not have permission to write into this folder."));
897 pasteAction
->setText(pasteInfo
.second
);
900 void DolphinMainWindow::slotDirectoryLoadingCompleted()
905 void DolphinMainWindow::slotToolBarActionMiddleClicked(QAction
*action
)
907 if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Back
))) {
909 } else if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Forward
))) {
911 } else if (action
== actionCollection()->action(QStringLiteral("go_up"))) {
913 } else if (action
== actionCollection()->action(QStringLiteral("go_home"))) {
918 QAction
*DolphinMainWindow::urlNavigatorHistoryAction(const KUrlNavigator
*urlNavigator
, int historyIndex
, QObject
*parent
)
920 const QUrl url
= urlNavigator
->locationUrl(historyIndex
);
922 QString text
= url
.toDisplayString(QUrl::PreferLocalFile
);
924 if (!urlNavigator
->showFullPath()) {
925 const KFilePlacesModel
*placesModel
= DolphinPlacesModelSingleton::instance().placesModel();
927 const QModelIndex closestIdx
= placesModel
->closestItem(url
);
928 if (closestIdx
.isValid()) {
929 const QUrl placeUrl
= placesModel
->url(closestIdx
);
931 text
= placesModel
->text(closestIdx
);
933 QString pathInsidePlace
= url
.path().mid(placeUrl
.path().length());
935 if (!pathInsidePlace
.isEmpty() && !pathInsidePlace
.startsWith(QLatin1Char('/'))) {
936 pathInsidePlace
.prepend(QLatin1Char('/'));
939 if (pathInsidePlace
!= QLatin1Char('/')) {
940 text
.append(pathInsidePlace
);
945 QAction
*action
= new QAction(QIcon::fromTheme(KIO::iconNameForUrl(url
)), text
, parent
);
946 action
->setData(historyIndex
);
950 void DolphinMainWindow::slotAboutToShowBackPopupMenu()
952 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
954 QMenu
*menu
= m_backAction
->popupMenu();
956 for (int i
= urlNavigator
->historyIndex() + 1; i
< urlNavigator
->historySize() && entries
< MaxNumberOfNavigationentries
; ++i
, ++entries
) {
957 QAction
*action
= urlNavigatorHistoryAction(urlNavigator
, i
, menu
);
958 menu
->addAction(action
);
962 void DolphinMainWindow::slotGoBack(QAction
*action
)
964 int gotoIndex
= action
->data().value
<int>();
965 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
966 for (int i
= gotoIndex
- urlNavigator
->historyIndex(); i
> 0; --i
) {
971 void DolphinMainWindow::slotBackForwardActionMiddleClicked(QAction
*action
)
974 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
975 openNewTab(urlNavigator
->locationUrl(action
->data().value
<int>()));
979 void DolphinMainWindow::slotAboutToShowForwardPopupMenu()
981 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
983 QMenu
*menu
= m_forwardAction
->popupMenu();
985 for (int i
= urlNavigator
->historyIndex() - 1; i
>= 0 && entries
< MaxNumberOfNavigationentries
; --i
, ++entries
) {
986 QAction
*action
= urlNavigatorHistoryAction(urlNavigator
, i
, menu
);
987 menu
->addAction(action
);
991 void DolphinMainWindow::slotGoForward(QAction
*action
)
993 int gotoIndex
= action
->data().value
<int>();
994 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
995 for (int i
= urlNavigator
->historyIndex() - gotoIndex
; i
> 0; --i
) {
1000 void DolphinMainWindow::slotSetSelectionMode(bool enabled
, SelectionMode::BottomBar::Contents bottomBarContents
)
1002 m_activeViewContainer
->setSelectionModeEnabled(enabled
, actionCollection(), bottomBarContents
);
1005 void DolphinMainWindow::selectAll()
1009 // if the URL navigator is editable and focused, select the whole
1010 // URL instead of all items of the view
1012 KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigator();
1013 QLineEdit
*lineEdit
= urlNavigator
->editor()->lineEdit();
1014 const bool selectUrl
= urlNavigator
->isUrlEditable() && lineEdit
->hasFocus();
1016 lineEdit
->selectAll();
1018 m_activeViewContainer
->view()->selectAll();
1022 void DolphinMainWindow::invertSelection()
1025 m_activeViewContainer
->view()->invertSelection();
1028 void DolphinMainWindow::toggleSplitView()
1030 QUrl newSplitViewUrl
;
1031 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1032 if (list
.count() == 1) {
1033 const KFileItem
&item
= list
.first();
1034 newSplitViewUrl
= DolphinView::openItemAsFolderUrl(item
);
1037 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
1038 tabPage
->setSplitViewEnabled(!tabPage
->splitViewEnabled(), WithAnimation
, newSplitViewUrl
);
1039 m_tabWidget
->updateTabName(m_tabWidget
->indexOf(tabPage
));
1040 updateViewActions();
1043 void DolphinMainWindow::popoutSplitView()
1045 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
1046 if (!tabPage
->splitViewEnabled())
1048 openNewWindow((GeneralSettings::closeActiveSplitView() ? tabPage
->activeViewContainer() : tabPage
->inactiveViewContainer())->url());
1049 tabPage
->setSplitViewEnabled(false, WithAnimation
);
1050 updateSplitActions();
1053 void DolphinMainWindow::toggleSplitStash()
1055 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
1056 tabPage
->setSplitViewEnabled(false, WithAnimation
);
1057 tabPage
->setSplitViewEnabled(true, WithAnimation
, QUrl("stash:/"));
1060 void DolphinMainWindow::copyToInactiveSplitView()
1062 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
1063 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CopyToOtherViewContents
);
1065 m_tabWidget
->copyToInactiveSplitView();
1066 m_activeViewContainer
->setSelectionModeEnabled(false);
1070 void DolphinMainWindow::moveToInactiveSplitView()
1072 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
1073 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::MoveToOtherViewContents
);
1075 m_tabWidget
->moveToInactiveSplitView();
1076 m_activeViewContainer
->setSelectionModeEnabled(false);
1080 void DolphinMainWindow::reloadView()
1083 m_activeViewContainer
->reload();
1084 m_activeViewContainer
->statusBar()->updateSpaceInfo();
1087 void DolphinMainWindow::stopLoading()
1089 m_activeViewContainer
->view()->stopLoading();
1092 void DolphinMainWindow::enableStopAction()
1094 actionCollection()->action(QStringLiteral("stop"))->setEnabled(true);
1097 void DolphinMainWindow::disableStopAction()
1099 actionCollection()->action(QStringLiteral("stop"))->setEnabled(false);
1102 void DolphinMainWindow::toggleSelectionMode()
1104 const bool checked
= !m_activeViewContainer
->isSelectionModeEnabled();
1106 m_activeViewContainer
->setSelectionModeEnabled(checked
, actionCollection(), SelectionMode::BottomBar::Contents::GeneralContents
);
1107 actionCollection()->action(QStringLiteral("toggle_selection_mode"))->setChecked(checked
);
1110 void DolphinMainWindow::showFilterBar()
1112 m_activeViewContainer
->setFilterBarVisible(true);
1115 void DolphinMainWindow::toggleFilterBar()
1117 const bool checked
= !m_activeViewContainer
->isFilterBarVisible();
1118 m_activeViewContainer
->setFilterBarVisible(checked
);
1120 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
1121 toggleFilterBarAction
->setChecked(checked
);
1124 void DolphinMainWindow::toggleEditLocation()
1128 QAction
*action
= actionCollection()->action(QStringLiteral("editable_location"));
1129 KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigator();
1130 urlNavigator
->setUrlEditable(action
->isChecked());
1133 void DolphinMainWindow::replaceLocation()
1135 KUrlNavigator
*navigator
= m_activeViewContainer
->urlNavigator();
1136 QLineEdit
*lineEdit
= navigator
->editor()->lineEdit();
1138 // If the text field currently has focus and everything is selected,
1139 // pressing the keyboard shortcut returns the whole thing to breadcrumb mode
1140 // and goes back to the view, just like how it was before this action was triggered the first time.
1141 if (navigator
->isUrlEditable() && lineEdit
->hasFocus() && lineEdit
->selectedText() == lineEdit
->text()) {
1142 navigator
->setUrlEditable(false);
1143 m_activeViewContainer
->view()->setFocus();
1145 navigator
->setUrlEditable(true);
1146 navigator
->setFocus();
1147 lineEdit
->selectAll();
1151 void DolphinMainWindow::togglePanelLockState()
1153 const bool newLockState
= !GeneralSettings::lockPanels();
1154 const auto childrenObjects
= children();
1155 for (QObject
*child
: childrenObjects
) {
1156 DolphinDockWidget
*dock
= qobject_cast
<DolphinDockWidget
*>(child
);
1158 dock
->setLocked(newLockState
);
1162 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(newLockState
);
1164 GeneralSettings::setLockPanels(newLockState
);
1167 void DolphinMainWindow::slotTerminalPanelVisibilityChanged(bool visible
)
1169 if (!visible
&& m_activeViewContainer
) {
1170 m_activeViewContainer
->view()->setFocus();
1172 // Putting focus to the Terminal is not handled here but in TerminalPanel::showEvent().
1175 void DolphinMainWindow::slotPlacesPanelVisibilityChanged(bool visible
)
1177 if (!visible
&& m_activeViewContainer
) {
1178 m_activeViewContainer
->view()->setFocus();
1181 m_placesPanel
->setFocus();
1184 void DolphinMainWindow::goBack()
1186 DolphinUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
1187 urlNavigator
->goBack();
1189 if (urlNavigator
->locationState().isEmpty()) {
1190 // An empty location state indicates a redirection URL,
1191 // which must be skipped too
1192 urlNavigator
->goBack();
1196 void DolphinMainWindow::goForward()
1198 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goForward();
1201 void DolphinMainWindow::goUp()
1203 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goUp();
1206 void DolphinMainWindow::goHome()
1208 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goHome();
1211 void DolphinMainWindow::goBackInNewTab()
1213 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
1214 const int index
= urlNavigator
->historyIndex() + 1;
1215 openNewTab(urlNavigator
->locationUrl(index
));
1218 void DolphinMainWindow::goForwardInNewTab()
1220 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
1221 const int index
= urlNavigator
->historyIndex() - 1;
1222 openNewTab(urlNavigator
->locationUrl(index
));
1225 void DolphinMainWindow::goUpInNewTab()
1227 const QUrl currentUrl
= activeViewContainer()->urlNavigator()->locationUrl();
1228 openNewTab(KIO::upUrl(currentUrl
));
1231 void DolphinMainWindow::goHomeInNewTab()
1233 openNewTab(Dolphin::homeUrl());
1236 void DolphinMainWindow::compareFiles()
1238 const KFileItemList items
= m_tabWidget
->currentTabPage()->selectedItems();
1239 if (items
.count() != 2) {
1240 // The action is disabled in this case, but it could have been triggered
1241 // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
1245 QUrl urlA
= items
.at(0).url();
1246 QUrl urlB
= items
.at(1).url();
1248 QString
command(QStringLiteral("kompare -c \""));
1249 command
.append(urlA
.toDisplayString(QUrl::PreferLocalFile
));
1250 command
.append("\" \"");
1251 command
.append(urlB
.toDisplayString(QUrl::PreferLocalFile
));
1252 command
.append('\"');
1254 KIO::CommandLauncherJob
*job
= new KIO::CommandLauncherJob(command
, this);
1255 job
->setDesktopName(QStringLiteral("org.kde.kompare"));
1259 void DolphinMainWindow::toggleShowMenuBar()
1261 const bool visible
= menuBar()->isVisible();
1262 menuBar()->setVisible(!visible
);
1265 QPointer
<QAction
> DolphinMainWindow::preferredSearchTool()
1267 m_searchTools
.clear();
1269 KService::Ptr kfind
= KService::serviceByDesktopName(QStringLiteral("org.kde.kfind"));
1275 auto *action
= new QAction(QIcon::fromTheme(kfind
->icon()), kfind
->name(), this);
1277 connect(action
, &QAction::triggered
, this, [this, kfind
] {
1278 auto *job
= new KIO::ApplicationLauncherJob(kfind
);
1279 job
->setUrls({m_activeViewContainer
->url()});
1286 void DolphinMainWindow::updateOpenPreferredSearchToolAction()
1288 QAction
*openPreferredSearchTool
= actionCollection()->action(QStringLiteral("open_preferred_search_tool"));
1289 if (!openPreferredSearchTool
) {
1292 QPointer
<QAction
> tool
= preferredSearchTool();
1294 openPreferredSearchTool
->setVisible(true);
1295 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open %1", tool
->text()));
1296 // Only override with the app icon if it is the default, i.e. the user hasn't configured one manually
1297 // https://bugs.kde.org/show_bug.cgi?id=442815
1298 if (openPreferredSearchTool
->icon().name() == QLatin1String("search")) {
1299 openPreferredSearchTool
->setIcon(tool
->icon());
1302 openPreferredSearchTool
->setVisible(false);
1303 // still visible in Shortcuts configuration window
1304 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1305 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1309 void DolphinMainWindow::openPreferredSearchTool()
1311 QPointer
<QAction
> tool
= preferredSearchTool();
1317 void DolphinMainWindow::openTerminal()
1319 openTerminalJob(m_activeViewContainer
->url());
1322 void DolphinMainWindow::openTerminalHere()
1324 QList
<QUrl
> urls
= {};
1326 const auto selectedItems
= m_activeViewContainer
->view()->selectedItems();
1327 for (const KFileItem
&item
: selectedItems
) {
1328 QUrl url
= item
.targetUrl();
1329 if (item
.isFile()) {
1330 url
.setPath(QFileInfo(url
.path()).absolutePath());
1332 if (!urls
.contains(url
)) {
1337 // No items are selected. Open a terminal window for the current location.
1338 if (urls
.count() == 0) {
1343 if (urls
.count() > 5) {
1344 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());
1345 const int answer
= KMessageBox::warningContinueCancel(
1349 KGuiItem(i18ncp("@action:button", "Open %1 Terminal", "Open %1 Terminals", urls
.count()), QStringLiteral("utilities-terminal")),
1350 KStandardGuiItem::cancel(),
1351 QStringLiteral("ConfirmOpenManyTerminals"));
1352 if (answer
!= KMessageBox::PrimaryAction
&& answer
!= KMessageBox::Continue
) {
1357 for (const QUrl
&url
: std::as_const(urls
)) {
1358 openTerminalJob(url
);
1362 void DolphinMainWindow::openTerminalJob(const QUrl
&url
)
1364 if (url
.isLocalFile()) {
1365 auto job
= new KTerminalLauncherJob(QString());
1366 job
->setWorkingDirectory(url
.toLocalFile());
1371 // Not a local file, with protocol Class ":local", try stat'ing
1372 if (KProtocolInfo::protocolClass(url
.scheme()) == QLatin1String(":local")) {
1373 KIO::StatJob
*job
= KIO::mostLocalUrl(url
);
1374 KJobWidgets::setWindow(job
, this);
1375 connect(job
, &KJob::result
, this, [job
]() {
1377 if (!job
->error()) {
1378 statUrl
= job
->mostLocalUrl();
1381 auto job
= new KTerminalLauncherJob(QString());
1382 job
->setWorkingDirectory(statUrl
.isLocalFile() ? statUrl
.toLocalFile() : QDir::homePath());
1389 // Nothing worked, just use $HOME
1390 auto job
= new KTerminalLauncherJob(QString());
1391 job
->setWorkingDirectory(QDir::homePath());
1395 void DolphinMainWindow::editSettings()
1397 if (!m_settingsDialog
) {
1398 DolphinViewContainer
*container
= activeViewContainer();
1399 container
->view()->writeSettings();
1401 const QUrl url
= container
->url();
1402 DolphinSettingsDialog
*settingsDialog
= new DolphinSettingsDialog(url
, this, actionCollection());
1403 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, this, &DolphinMainWindow::refreshViews
);
1404 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, &DolphinUrlNavigatorsController::slotReadSettings
);
1405 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1406 settingsDialog
->show();
1407 m_settingsDialog
= settingsDialog
;
1409 m_settingsDialog
.data()->raise();
1413 void DolphinMainWindow::handleUrl(const QUrl
&url
)
1415 delete m_lastHandleUrlOpenJob
;
1416 m_lastHandleUrlOpenJob
= nullptr;
1418 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1419 activeViewContainer()->setUrl(url
);
1421 m_lastHandleUrlOpenJob
= new KIO::OpenUrlJob(url
);
1422 m_lastHandleUrlOpenJob
->setUiDelegate(KIO::createDefaultJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
1423 m_lastHandleUrlOpenJob
->setShowOpenOrExecuteDialog(true);
1425 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::mimeTypeFound
, this, [this, url
](const QString
&mimetype
) {
1426 if (mimetype
== QLatin1String("inode/directory")) {
1427 // If it's a dir, we'll take it from here
1428 m_lastHandleUrlOpenJob
->kill();
1429 m_lastHandleUrlOpenJob
= nullptr;
1430 activeViewContainer()->setUrl(url
);
1434 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::result
, this, [this]() {
1435 m_lastHandleUrlOpenJob
= nullptr;
1438 m_lastHandleUrlOpenJob
->start();
1442 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1444 // trash:/ is writable but we don't want to create new items in it.
1445 // TODO: remove the trash check once https://phabricator.kde.org/T8234 is implemented
1446 newFileMenu()->setEnabled(isFolderWritable
&& m_activeViewContainer
->url().scheme() != QLatin1String("trash"));
1447 // 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.
1448 QTimer::singleShot(0, this, [this]() {
1449 m_disabledActionNotifier
->setDisabledReason(actionCollection()->action(QStringLiteral("create_dir")),
1450 i18nc("@info", "Cannot create new folder: You do not have permission to create items in this folder."));
1454 void DolphinMainWindow::openContextMenu(const QPoint
&pos
, const KFileItem
&item
, const KFileItemList
&selectedItems
, const QUrl
&url
)
1456 QPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, item
, selectedItems
, url
, &m_fileItemActions
);
1457 contextMenu
->exec(pos
);
1459 // Delete the menu, unless it has been deleted in its own nested event loop already.
1461 contextMenu
->deleteLater();
1465 QMenu
*DolphinMainWindow::createPopupMenu()
1467 QMenu
*menu
= KXmlGuiWindow::createPopupMenu();
1469 menu
->addSeparator();
1470 menu
->addAction(actionCollection()->action(QStringLiteral("lock_panels")));
1475 void DolphinMainWindow::updateHamburgerMenu()
1477 KActionCollection
*ac
= actionCollection();
1478 auto hamburgerMenu
= static_cast<KHamburgerMenu
*>(ac
->action(KStandardAction::name(KStandardAction::HamburgerMenu
)));
1479 auto menu
= hamburgerMenu
->menu();
1481 menu
= new QMenu(this);
1482 hamburgerMenu
->setMenu(menu
);
1483 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("basic_actions"))->menu());
1484 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("zoom"))->menu());
1488 const QList
<QAction
*> toolbarActions
= toolBar()->actions();
1490 if (!toolBar()->isVisible()) {
1491 // If neither the menu bar nor the toolbar are visible, these actions should be available.
1492 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)));
1493 menu
->addAction(toolBarMenuAction());
1494 menu
->addSeparator();
1497 // This group of actions (until the next separator) contains all the most basic actions
1498 // necessary to use Dolphin effectively.
1499 menu
->addAction(ac
->action(QStringLiteral("go_back")));
1500 menu
->addAction(ac
->action(QStringLiteral("go_forward")));
1502 menu
->addMenu(m_newFileMenu
->menu());
1503 if (!toolBar()->isVisible() || !toolbarActions
.contains(ac
->action(QStringLiteral("toggle_selection_mode_tool_bar")))) {
1504 menu
->addAction(ac
->action(QStringLiteral("toggle_selection_mode")));
1506 menu
->addAction(ac
->action(QStringLiteral("basic_actions")));
1507 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Undo
)));
1508 if (!toolBar()->isVisible()
1509 || (!toolbarActions
.contains(ac
->action(QStringLiteral("toggle_search")))
1510 && !toolbarActions
.contains(ac
->action(QStringLiteral("open_preferred_search_tool"))))) {
1511 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Find
)));
1512 // This way a search action will only be added if none of the three available
1513 // search actions is present on the toolbar.
1515 if (!toolBar()->isVisible() || !toolbarActions
.contains(ac
->action(QStringLiteral("toggle_filter")))) {
1516 menu
->addAction(ac
->action(QStringLiteral("show_filter_bar")));
1517 // This way a filter action will only be added if none of the two available
1518 // filter actions is present on the toolbar.
1520 menu
->addSeparator();
1522 // The second group of actions (up until the next separator) contains actions for opening
1523 // additional views to interact with the file system.
1524 menu
->addAction(ac
->action(QStringLiteral("file_new")));
1525 menu
->addAction(ac
->action(QStringLiteral("new_tab")));
1526 if (ac
->action(QStringLiteral("undo_close_tab"))->isEnabled()) {
1527 menu
->addAction(ac
->action(QStringLiteral("closed_tabs")));
1529 menu
->addAction(ac
->action(QStringLiteral("open_terminal")));
1530 menu
->addSeparator();
1532 // The third group contains actions to change what one sees in the view
1533 // and to change the more general UI.
1534 if (!toolBar()->isVisible()
1535 || (!toolbarActions
.contains(ac
->action(QStringLiteral("icons"))) && !toolbarActions
.contains(ac
->action(QStringLiteral("compact")))
1536 && !toolbarActions
.contains(ac
->action(QStringLiteral("details"))) && !toolbarActions
.contains(ac
->action(QStringLiteral("view_mode"))))) {
1537 menu
->addAction(ac
->action(QStringLiteral("view_mode")));
1539 menu
->addAction(ac
->action(QStringLiteral("show_hidden_files")));
1540 menu
->addAction(ac
->action(QStringLiteral("sort")));
1541 menu
->addAction(ac
->action(QStringLiteral("additional_info")));
1542 if (!GeneralSettings::showStatusBar() || !GeneralSettings::showZoomSlider()) {
1543 menu
->addAction(ac
->action(QStringLiteral("zoom")));
1545 menu
->addAction(ac
->action(QStringLiteral("panels")));
1547 // The "Configure" menu is not added to the actionCollection() because there is hardly
1548 // a good reason for users to put it on their toolbar.
1549 auto configureMenu
= menu
->addMenu(QIcon::fromTheme(QStringLiteral("configure")), i18nc("@action:inmenu menu for configure actions", "Configure"));
1550 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
)));
1551 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)));
1552 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)));
1553 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Preferences
)));
1554 hamburgerMenu
->hideActionsOf(configureMenu
);
1557 void DolphinMainWindow::slotPlaceActivated(const QUrl
&url
)
1559 DolphinViewContainer
*view
= activeViewContainer();
1561 if (view
->url() == url
) {
1562 view
->clearFilterBar(); // Fixes bug 259382.
1564 // We can end up here if the user clicked a device in the Places Panel
1565 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
1568 m_activeViewContainer
->view()->setFocus(); // We always want the focus on the view after activating a place.
1570 view
->disableUrlNavigatorSelectionRequests();
1572 view
->enableUrlNavigatorSelectionRequests();
1576 void DolphinMainWindow::closedTabsCountChanged(unsigned int count
)
1578 actionCollection()->action(QStringLiteral("undo_close_tab"))->setEnabled(count
> 0);
1581 void DolphinMainWindow::activeViewChanged(DolphinViewContainer
*viewContainer
)
1583 DolphinViewContainer
*oldViewContainer
= m_activeViewContainer
;
1584 Q_ASSERT(viewContainer
);
1586 m_activeViewContainer
= viewContainer
;
1588 if (oldViewContainer
) {
1589 const QAction
*toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
1590 toggleSearchAction
->disconnect(oldViewContainer
);
1592 // Disconnect all signals between the old view container (container,
1593 // view and url navigator) and main window.
1594 oldViewContainer
->disconnect(this);
1595 oldViewContainer
->view()->disconnect(this);
1596 oldViewContainer
->urlNavigatorInternalWithHistory()->disconnect(this);
1597 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
1598 navigators
->primaryUrlNavigator()->disconnect(this);
1599 if (auto secondaryUrlNavigator
= navigators
->secondaryUrlNavigator()) {
1600 secondaryUrlNavigator
->disconnect(this);
1603 // except the requestItemInfo so that on hover the information panel can still be updated
1604 connect(oldViewContainer
->view(), &DolphinView::requestItemInfo
, this, &DolphinMainWindow::requestItemInfo
);
1606 // Disconnect other slots.
1607 disconnect(oldViewContainer
,
1608 &DolphinViewContainer::selectionModeChanged
,
1609 actionCollection()->action(QStringLiteral("toggle_selection_mode")),
1610 &QAction::setChecked
);
1613 connectViewSignals(viewContainer
);
1615 m_actionHandler
->setCurrentView(viewContainer
->view());
1618 updateFileAndEditActions();
1619 updatePasteAction();
1620 updateViewActions();
1622 updateSearchAction();
1624 const QUrl url
= viewContainer
->url();
1625 Q_EMIT
urlChanged(url
);
1628 void DolphinMainWindow::tabCountChanged(int count
)
1630 const bool enableTabActions
= (count
> 1);
1631 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1632 actionCollection()->action(QStringLiteral("activate_tab_%1").arg(i
))->setEnabled(enableTabActions
);
1634 actionCollection()->action(QStringLiteral("activate_last_tab"))->setEnabled(enableTabActions
);
1635 actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions
);
1636 actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions
);
1639 void DolphinMainWindow::updateWindowTitle()
1641 const QString newTitle
= m_activeViewContainer
->captionWindowTitle();
1642 if (windowTitle() != newTitle
) {
1643 setWindowTitle(newTitle
);
1647 void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString
&mountPath
)
1649 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1650 setViewsToHomeIfMountPathOpen(mountPath
);
1653 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectoryIsChildOf(mountPath
)) {
1654 m_tearDownFromPlacesRequested
= true;
1655 m_terminalPanel
->goHome();
1656 // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged
1658 m_placesPanel
->proceedWithTearDown();
1662 void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString
&mountPath
)
1664 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1665 setViewsToHomeIfMountPathOpen(mountPath
);
1668 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectoryIsChildOf(mountPath
)) {
1669 m_tearDownFromPlacesRequested
= false;
1670 m_terminalPanel
->goHome();
1674 void DolphinMainWindow::slotKeyBindings()
1676 KShortcutsDialog
dialog(KShortcutsEditor::AllActions
, KShortcutsEditor::LetterShortcutsAllowed
, this);
1677 dialog
.addCollection(actionCollection());
1678 if (m_terminalPanel
) {
1679 KActionCollection
*konsolePartActionCollection
= m_terminalPanel
->actionCollection();
1680 if (konsolePartActionCollection
) {
1681 dialog
.addCollection(konsolePartActionCollection
, QStringLiteral("KonsolePart"));
1687 void DolphinMainWindow::setViewsToHomeIfMountPathOpen(const QString
&mountPath
)
1689 const QVector
<DolphinViewContainer
*> theViewContainers
= viewContainers();
1690 for (DolphinViewContainer
*viewContainer
: theViewContainers
) {
1691 if (viewContainer
&& viewContainer
->url().toLocalFile().startsWith(mountPath
)) {
1692 viewContainer
->setUrl(QUrl::fromLocalFile(QDir::homePath()));
1695 disconnect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, nullptr, nullptr);
1698 void DolphinMainWindow::setupActions()
1700 auto hamburgerMenuAction
= KStandardAction::hamburgerMenu(nullptr, nullptr, actionCollection());
1702 // setup 'File' menu
1703 m_newFileMenu
= new DolphinNewFileMenu(nullptr, this);
1704 actionCollection()->addAction(QStringLiteral("new_menu"), m_newFileMenu
);
1705 QMenu
*menu
= m_newFileMenu
->menu();
1706 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1707 menu
->setIcon(QIcon::fromTheme(QStringLiteral("list-add")));
1708 m_newFileMenu
->setPopupMode(QToolButton::InstantPopup
);
1709 connect(menu
, &QMenu::aboutToShow
, this, &DolphinMainWindow::updateNewMenu
);
1711 QAction
*newWindow
= KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow
, actionCollection());
1712 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1713 newWindow
->setToolTip(i18nc("@info", "Open a new Dolphin window"));
1714 newWindow
->setWhatsThis(xi18nc("@info:whatsthis",
1716 "window just like this one with the current location."
1717 "<nl/>You can drag and drop items between windows."));
1718 newWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1720 QAction
*newTab
= actionCollection()->addAction(QStringLiteral("new_tab"));
1721 newTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1722 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1723 newTab
->setWhatsThis(xi18nc("@info:whatsthis",
1725 "<emphasis>Tab</emphasis> with the current location."
1726 "<nl/>Tabs allow you to quickly switch between multiple locations and views within this window. "
1727 "You can drag and drop items between tabs."));
1728 actionCollection()->setDefaultShortcut(newTab
, Qt::CTRL
| Qt::Key_T
);
1729 connect(newTab
, &QAction::triggered
, this, &DolphinMainWindow::openNewActivatedTab
);
1731 QAction
*addToPlaces
= actionCollection()->addAction(QStringLiteral("add_to_places"));
1732 addToPlaces
->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new")));
1733 addToPlaces
->setText(i18nc("@action:inmenu Add current folder to places", "Add to Places"));
1734 addToPlaces
->setWhatsThis(xi18nc("@info:whatsthis",
1735 "This adds the selected folder "
1736 "to the Places panel."));
1737 connect(addToPlaces
, &QAction::triggered
, this, &DolphinMainWindow::addToPlaces
);
1739 QAction
*closeTab
= KStandardAction::close(m_tabWidget
, QOverload
<>::of(&DolphinTabWidget::closeTab
), actionCollection());
1740 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1741 closeTab
->setToolTip(i18nc("@info", "Close Tab"));
1742 closeTab
->setWhatsThis(i18nc("@info:whatsthis",
1744 "currently viewed tab. If no more tabs are left, this closes "
1745 "the whole window instead."));
1747 QAction
*quitAction
= KStandardAction::quit(this, &DolphinMainWindow::quit
, actionCollection());
1748 quitAction
->setWhatsThis(i18nc("@info:whatsthis quit", "This closes this window."));
1750 // setup 'Edit' menu
1751 KStandardAction::undo(this, &DolphinMainWindow::undo
, actionCollection());
1753 // i18n: This will be the last paragraph for the whatsthis for all three:
1754 // Cut, Copy and Paste
1755 const QString cutCopyPastePara
= xi18nc("@info:whatsthis",
1756 "<para><emphasis>Cut, "
1757 "Copy</emphasis> and <emphasis>Paste</emphasis> work between many "
1758 "applications and are among the most used commands. That's why their "
1759 "<emphasis>keyboard shortcuts</emphasis> are prominently placed right "
1760 "next to each other on the keyboard: <shortcut>Ctrl+X</shortcut>, "
1761 "<shortcut>Ctrl+C</shortcut> and <shortcut>Ctrl+V</shortcut>.</para>");
1762 QAction
*cutAction
= KStandardAction::cut(this, &DolphinMainWindow::cut
, actionCollection());
1763 m_actionTextHelper
->registerTextWhenNothingIsSelected(cutAction
, i18nc("@action", "Cut…"));
1764 cutAction
->setWhatsThis(xi18nc("@info:whatsthis cut",
1765 "This copies the items "
1766 "in your current selection to the <emphasis>clipboard</emphasis>.<nl/>"
1767 "Use the <emphasis>Paste</emphasis> action afterwards to copy them from "
1768 "the clipboard to a new location. The items will be removed from their "
1769 "initial location.")
1770 + cutCopyPastePara
);
1771 QAction
*copyAction
= KStandardAction::copy(this, &DolphinMainWindow::copy
, actionCollection());
1772 m_actionTextHelper
->registerTextWhenNothingIsSelected(copyAction
, i18nc("@action", "Copy…"));
1773 copyAction
->setWhatsThis(xi18nc("@info:whatsthis copy",
1775 "items in your current selection to the <emphasis>clipboard</emphasis>."
1776 "<nl/>Use the <emphasis>Paste</emphasis> action afterwards to copy them "
1777 "from the clipboard to a new location.")
1778 + cutCopyPastePara
);
1779 QAction
*paste
= KStandardAction::paste(this, &DolphinMainWindow::paste
, actionCollection());
1780 // The text of the paste-action is modified dynamically by Dolphin
1781 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1782 // due to the long text, the text "Paste" is used:
1783 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1784 paste
->setWhatsThis(xi18nc("@info:whatsthis paste",
1785 "This copies the items from "
1786 "your <emphasis>clipboard</emphasis> to the currently viewed folder.<nl/>"
1787 "If the items were added to the clipboard by the <emphasis>Cut</emphasis> "
1788 "action they are removed from their old location.")
1789 + cutCopyPastePara
);
1791 QAction
*copyToOtherViewAction
= actionCollection()->addAction(QStringLiteral("copy_to_inactive_split_view"));
1792 copyToOtherViewAction
->setText(i18nc("@action:inmenu", "Copy to Other View"));
1793 m_actionTextHelper
->registerTextWhenNothingIsSelected(copyToOtherViewAction
, i18nc("@action:inmenu", "Copy to Other View…"));
1794 copyToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Copy",
1795 "This copies the selected items from "
1796 "the view in focus to the other view. "
1797 "(Only available while in Split View mode.)"));
1798 copyToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
1799 copyToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Copy to Other View"));
1800 actionCollection()->setDefaultShortcut(copyToOtherViewAction
, Qt::SHIFT
| Qt::Key_F5
);
1801 connect(copyToOtherViewAction
, &QAction::triggered
, this, &DolphinMainWindow::copyToInactiveSplitView
);
1803 QAction
*moveToOtherViewAction
= actionCollection()->addAction(QStringLiteral("move_to_inactive_split_view"));
1804 moveToOtherViewAction
->setText(i18nc("@action:inmenu", "Move to Other View"));
1805 m_actionTextHelper
->registerTextWhenNothingIsSelected(moveToOtherViewAction
, i18nc("@action:inmenu", "Move to Other View…"));
1806 moveToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Move",
1807 "This moves the selected items from "
1808 "the view in focus to the other view. "
1809 "(Only available while in Split View mode.)"));
1810 moveToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-cut")));
1811 moveToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Move to Other View"));
1812 actionCollection()->setDefaultShortcut(moveToOtherViewAction
, Qt::SHIFT
| Qt::Key_F6
);
1813 connect(moveToOtherViewAction
, &QAction::triggered
, this, &DolphinMainWindow::moveToInactiveSplitView
);
1815 QAction
*showFilterBar
= actionCollection()->addAction(QStringLiteral("show_filter_bar"));
1816 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Filter…"));
1817 showFilterBar
->setToolTip(i18nc("@info:tooltip", "Show Filter Bar"));
1818 showFilterBar
->setWhatsThis(xi18nc("@info:whatsthis",
1820 "<emphasis>Filter Bar</emphasis> at the bottom of the window.<nl/> "
1821 "There you can enter text to filter the files and folders currently displayed. "
1822 "Only those that contain the text in their name will be kept in view."));
1823 showFilterBar
->setIcon(QIcon::fromTheme(QStringLiteral("view-filter")));
1824 actionCollection()->setDefaultShortcuts(showFilterBar
, {Qt::CTRL
| Qt::Key_I
, Qt::Key_Slash
});
1825 connect(showFilterBar
, &QAction::triggered
, this, &DolphinMainWindow::showFilterBar
);
1827 // toggle_filter acts as a copy of the main showFilterBar to be used mainly
1828 // in the toolbar, with no default shortcut attached, to avoid messing with
1829 // existing workflows (filter bar always open and Ctrl-I to focus)
1830 QAction
*toggleFilter
= actionCollection()->addAction(QStringLiteral("toggle_filter"));
1831 toggleFilter
->setText(i18nc("@action:inmenu", "Toggle Filter Bar"));
1832 toggleFilter
->setIconText(i18nc("@action:intoolbar", "Filter"));
1833 toggleFilter
->setIcon(showFilterBar
->icon());
1834 toggleFilter
->setToolTip(showFilterBar
->toolTip());
1835 toggleFilter
->setWhatsThis(showFilterBar
->whatsThis());
1836 toggleFilter
->setCheckable(true);
1837 connect(toggleFilter
, &QAction::triggered
, this, &DolphinMainWindow::toggleFilterBar
);
1839 QAction
*searchAction
= KStandardAction::find(this, &DolphinMainWindow::find
, actionCollection());
1840 searchAction
->setText(i18n("Search…"));
1841 searchAction
->setToolTip(i18nc("@info:tooltip", "Search for files and folders"));
1842 searchAction
->setWhatsThis(xi18nc("@info:whatsthis find",
1843 "<para>This helps you "
1844 "find files and folders by opening a <emphasis>search bar</emphasis>. "
1845 "There you can enter search terms and specify settings to find the "
1846 "items you are looking for.</para><para>Use this help again on "
1847 "the search bar so we can have a look at it while the settings are "
1848 "explained.</para>"));
1850 // toggle_search acts as a copy of the main searchAction to be used mainly
1851 // in the toolbar, with no default shortcut attached, to avoid messing with
1852 // existing workflows (search bar always open and Ctrl-F to focus)
1853 QAction
*toggleSearchAction
= actionCollection()->addAction(QStringLiteral("toggle_search"));
1854 toggleSearchAction
->setText(i18nc("@action:inmenu", "Toggle Search Bar"));
1855 toggleSearchAction
->setIconText(i18nc("@action:intoolbar", "Search"));
1856 toggleSearchAction
->setIcon(searchAction
->icon());
1857 toggleSearchAction
->setToolTip(searchAction
->toolTip());
1858 toggleSearchAction
->setWhatsThis(searchAction
->whatsThis());
1859 toggleSearchAction
->setCheckable(true);
1861 QAction
*toggleSelectionModeAction
= actionCollection()->addAction(QStringLiteral("toggle_selection_mode"));
1862 // i18n: This action toggles a selection mode.
1863 toggleSelectionModeAction
->setText(i18nc("@action:inmenu", "Select Files and Folders"));
1864 // i18n: Opens a selection mode for selecting files/folders.
1865 // The text is kept so unspecific because it will be shown on the toolbar where space is at a premium.
1866 toggleSelectionModeAction
->setIconText(i18nc("@action:intoolbar", "Select"));
1867 toggleSelectionModeAction
->setWhatsThis(xi18nc(
1869 "<para>This application only knows which files or folders should be acted on if they are"
1870 " <emphasis>selected</emphasis> first. Press this to toggle a <emphasis>Selection Mode</emphasis> which makes selecting and deselecting as easy as "
1871 "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."
1873 toggleSelectionModeAction
->setIcon(QIcon::fromTheme(QStringLiteral("quickwizard")));
1874 toggleSelectionModeAction
->setCheckable(true);
1875 actionCollection()->setDefaultShortcut(toggleSelectionModeAction
, Qt::Key_Space
);
1876 connect(toggleSelectionModeAction
, &QAction::triggered
, this, &DolphinMainWindow::toggleSelectionMode
);
1878 // A special version of the toggleSelectionModeAction for the toolbar that also contains a menu
1879 // with the selectAllAction and invertSelectionAction.
1880 auto *toggleSelectionModeToolBarAction
=
1881 new KToolBarPopupAction(toggleSelectionModeAction
->icon(), toggleSelectionModeAction
->iconText(), actionCollection());
1882 toggleSelectionModeToolBarAction
->setToolTip(toggleSelectionModeAction
->text());
1883 toggleSelectionModeToolBarAction
->setWhatsThis(toggleSelectionModeAction
->whatsThis());
1884 actionCollection()->addAction(QStringLiteral("toggle_selection_mode_tool_bar"), toggleSelectionModeToolBarAction
);
1885 toggleSelectionModeToolBarAction
->setCheckable(true);
1886 toggleSelectionModeToolBarAction
->setPopupMode(KToolBarPopupAction::DelayedPopup
);
1887 connect(toggleSelectionModeToolBarAction
, &QAction::triggered
, toggleSelectionModeAction
, &QAction::trigger
);
1888 connect(toggleSelectionModeAction
, &QAction::toggled
, toggleSelectionModeToolBarAction
, &QAction::setChecked
);
1890 QAction
*selectAllAction
= KStandardAction::selectAll(this, &DolphinMainWindow::selectAll
, actionCollection());
1891 selectAllAction
->setWhatsThis(xi18nc("@info:whatsthis",
1893 "files and folders in the current location."));
1895 QAction
*invertSelection
= actionCollection()->addAction(QStringLiteral("invert_selection"));
1896 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1897 invertSelection
->setWhatsThis(xi18nc("@info:whatsthis invert",
1899 "items that you have currently <emphasis>not</emphasis> selected instead."));
1900 invertSelection
->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-invert")));
1901 actionCollection()->setDefaultShortcut(invertSelection
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1902 connect(invertSelection
, &QAction::triggered
, this, &DolphinMainWindow::invertSelection
);
1904 QMenu
*toggleSelectionModeActionMenu
= new QMenu(this);
1905 toggleSelectionModeActionMenu
->addAction(selectAllAction
);
1906 toggleSelectionModeActionMenu
->addAction(invertSelection
);
1907 toggleSelectionModeToolBarAction
->setMenu(toggleSelectionModeActionMenu
);
1909 // setup 'View' menu
1910 // (note that most of it is set up in DolphinViewActionHandler)
1912 Admin::WorkerIntegration::createActAsAdminAction(actionCollection(), this);
1914 m_splitViewAction
= actionCollection()->add
<KActionMenu
>(QStringLiteral("split_view"));
1915 m_splitViewMenuAction
= actionCollection()->addAction(QStringLiteral("split_view_menu"));
1917 m_splitViewAction
->setWhatsThis(xi18nc("@info:whatsthis split",
1918 "<para>This presents "
1919 "a second view side-by-side with the current view, so you can see "
1920 "the contents of two folders at once and easily move items between "
1921 "them.</para><para>The view that is not \"in focus\" will be dimmed. "
1922 "</para>Click this button again to close one of the views."));
1923 m_splitViewMenuAction
->setWhatsThis(m_splitViewAction
->whatsThis());
1925 // only set it for the menu version
1926 actionCollection()->setDefaultShortcut(m_splitViewMenuAction
, Qt::Key_F3
);
1928 connect(m_splitViewAction
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitView
);
1929 connect(m_splitViewMenuAction
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitView
);
1931 QAction
*popoutSplit
= actionCollection()->addAction(QStringLiteral("popout_split_view"));
1932 popoutSplit
->setWhatsThis(xi18nc("@info:whatsthis",
1933 "If the view has been split, this will pop the view in focus "
1934 "out into a new window."));
1935 popoutSplit
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1936 actionCollection()->setDefaultShortcut(popoutSplit
, Qt::SHIFT
| Qt::Key_F3
);
1937 connect(popoutSplit
, &QAction::triggered
, this, &DolphinMainWindow::popoutSplitView
);
1939 QAction
*stashSplit
= actionCollection()->addAction(QStringLiteral("split_stash"));
1940 actionCollection()->setDefaultShortcut(stashSplit
, Qt::CTRL
| Qt::Key_S
);
1941 stashSplit
->setText(i18nc("@action:intoolbar Stash", "Stash"));
1942 stashSplit
->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
1943 stashSplit
->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
1944 stashSplit
->setCheckable(false);
1945 QDBusConnectionInterface
*sessionInterface
= QDBusConnection::sessionBus().interface();
1946 stashSplit
->setVisible(sessionInterface
&& sessionInterface
->isServiceRegistered(QStringLiteral("org.kde.kio.StashNotifier")));
1947 connect(stashSplit
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitStash
);
1949 QAction
*redisplay
= KStandardAction::redisplay(this, &DolphinMainWindow::reloadView
, actionCollection());
1950 redisplay
->setToolTip(i18nc("@info:tooltip", "Refresh view"));
1951 redisplay
->setWhatsThis(xi18nc("@info:whatsthis refresh",
1952 "<para>This refreshes "
1953 "the folder view.</para>"
1954 "<para>If the contents of this folder have changed, refreshing will re-scan this folder "
1955 "and show you a newly-updated view of the files and folders contained here.</para>"
1956 "<para>If the view is split, this refreshes the one that is currently in focus.</para>"));
1958 QAction
*stop
= actionCollection()->addAction(QStringLiteral("stop"));
1959 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1960 stop
->setToolTip(i18nc("@info", "Stop loading"));
1961 stop
->setWhatsThis(i18nc("@info", "This stops the loading of the contents of the current folder."));
1962 stop
->setIcon(QIcon::fromTheme(QStringLiteral("process-stop")));
1963 connect(stop
, &QAction::triggered
, this, &DolphinMainWindow::stopLoading
);
1965 KToggleAction
*editableLocation
= actionCollection()->add
<KToggleAction
>(QStringLiteral("editable_location"));
1966 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1967 editableLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1968 "This toggles the <emphasis>Location Bar</emphasis> to be "
1969 "editable so you can directly enter a location you want to go to.<nl/>"
1970 "You can also switch to editing by clicking to the right of the "
1971 "location and switch back by confirming the edited location."));
1972 actionCollection()->setDefaultShortcut(editableLocation
, Qt::Key_F6
);
1973 connect(editableLocation
, &KToggleAction::triggered
, this, &DolphinMainWindow::toggleEditLocation
);
1975 QAction
*replaceLocation
= actionCollection()->addAction(QStringLiteral("replace_location"));
1976 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1977 // i18n: "enter" is used both in the meaning of "writing" and "going to" a new location here.
1978 // Both meanings are useful but not necessary to understand the use of "Replace Location".
1979 // So you might want to be more verbose in your language to convey the meaning but it's up to you.
1980 replaceLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1981 "This switches to editing the location and selects it "
1982 "so you can quickly enter a different location."));
1983 actionCollection()->setDefaultShortcuts(replaceLocation
, {Qt::CTRL
| Qt::Key_L
, Qt::ALT
| Qt::Key_D
});
1984 connect(replaceLocation
, &QAction::triggered
, this, &DolphinMainWindow::replaceLocation
);
1988 QScopedPointer
<QAction
> backAction(KStandardAction::back(nullptr, nullptr, nullptr));
1989 m_backAction
= new KToolBarPopupAction(backAction
->icon(), backAction
->text(), actionCollection());
1990 m_backAction
->setObjectName(backAction
->objectName());
1991 m_backAction
->setShortcuts(backAction
->shortcuts());
1993 m_backAction
->setPopupMode(KToolBarPopupAction::DelayedPopup
);
1994 connect(m_backAction
, &QAction::triggered
, this, &DolphinMainWindow::goBack
);
1995 connect(m_backAction
->popupMenu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowBackPopupMenu
);
1996 connect(m_backAction
->popupMenu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoBack
);
1997 actionCollection()->addAction(m_backAction
->objectName(), m_backAction
);
1999 auto backShortcuts
= m_backAction
->shortcuts();
2000 // Prepend this shortcut, to avoid being hidden by the two-slot UI (#371130)
2001 backShortcuts
.prepend(QKeySequence(Qt::Key_Backspace
));
2002 actionCollection()->setDefaultShortcuts(m_backAction
, backShortcuts
);
2004 DolphinRecentTabsMenu
*recentTabsMenu
= new DolphinRecentTabsMenu(this);
2005 actionCollection()->addAction(QStringLiteral("closed_tabs"), recentTabsMenu
);
2006 connect(m_tabWidget
, &DolphinTabWidget::rememberClosedTab
, recentTabsMenu
, &DolphinRecentTabsMenu::rememberClosedTab
);
2007 connect(recentTabsMenu
, &DolphinRecentTabsMenu::restoreClosedTab
, m_tabWidget
, &DolphinTabWidget::restoreClosedTab
);
2008 connect(recentTabsMenu
, &DolphinRecentTabsMenu::closedTabsCountChanged
, this, &DolphinMainWindow::closedTabsCountChanged
);
2010 QAction
*undoCloseTab
= actionCollection()->addAction(QStringLiteral("undo_close_tab"));
2011 undoCloseTab
->setText(i18nc("@action:inmenu File", "Undo close tab"));
2012 undoCloseTab
->setWhatsThis(i18nc("@info:whatsthis undo close tab", "This returns you to the previously closed tab."));
2013 actionCollection()->setDefaultShortcut(undoCloseTab
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_T
);
2014 undoCloseTab
->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo")));
2015 undoCloseTab
->setEnabled(false);
2016 connect(undoCloseTab
, &QAction::triggered
, recentTabsMenu
, &DolphinRecentTabsMenu::undoCloseTab
);
2018 auto undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
2019 undoAction
->setWhatsThis(xi18nc("@info:whatsthis",
2021 "the last change you made to files or folders.<nl/>"
2022 "Such changes include <interface>creating</interface>, <interface>renaming</interface> "
2023 "and <interface>moving</interface> them to a different location "
2024 "or to the <filename>Trash</filename>. <nl/>Any changes that cannot be undone "
2025 "will ask for your confirmation beforehand."));
2026 undoAction
->setEnabled(false); // undo should be disabled by default
2029 QScopedPointer
<QAction
> forwardAction(KStandardAction::forward(nullptr, nullptr, nullptr));
2030 m_forwardAction
= new KToolBarPopupAction(forwardAction
->icon(), forwardAction
->text(), actionCollection());
2031 m_forwardAction
->setObjectName(forwardAction
->objectName());
2032 m_forwardAction
->setShortcuts(forwardAction
->shortcuts());
2034 m_forwardAction
->setPopupMode(KToolBarPopupAction::DelayedPopup
);
2035 connect(m_forwardAction
, &QAction::triggered
, this, &DolphinMainWindow::goForward
);
2036 connect(m_forwardAction
->popupMenu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowForwardPopupMenu
);
2037 connect(m_forwardAction
->popupMenu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoForward
);
2038 actionCollection()->addAction(m_forwardAction
->objectName(), m_forwardAction
);
2039 actionCollection()->setDefaultShortcuts(m_forwardAction
, m_forwardAction
->shortcuts());
2041 // enable middle-click to open in a new tab
2042 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
2043 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotBackForwardActionMiddleClicked
);
2044 m_backAction
->popupMenu()->installEventFilter(middleClickEventFilter
);
2045 m_forwardAction
->popupMenu()->installEventFilter(middleClickEventFilter
);
2046 KStandardAction::up(this, &DolphinMainWindow::goUp
, actionCollection());
2047 QAction
*homeAction
= KStandardAction::home(this, &DolphinMainWindow::goHome
, actionCollection());
2048 homeAction
->setWhatsThis(xi18nc("@info:whatsthis",
2050 "<filename>Home</filename> folder.<nl/>Every user account "
2051 "has their own <filename>Home</filename> that contains their personal files, "
2052 "as well as hidden folders for their applications' data and configuration files."));
2054 // setup 'Tools' menu
2055 QAction
*compareFiles
= actionCollection()->addAction(QStringLiteral("compare_files"));
2056 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
2057 compareFiles
->setIcon(QIcon::fromTheme(QStringLiteral("kompare")));
2058 compareFiles
->setEnabled(false);
2059 connect(compareFiles
, &QAction::triggered
, this, &DolphinMainWindow::compareFiles
);
2061 QAction
*openPreferredSearchTool
= actionCollection()->addAction(QStringLiteral("open_preferred_search_tool"));
2062 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
2063 openPreferredSearchTool
->setWhatsThis(xi18nc("@info:whatsthis",
2064 "<para>This opens a preferred search tool for the viewed location.</para>"
2065 "<para>Use <emphasis>More Search Tools</emphasis> menu to configure it.</para>"));
2066 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
2067 actionCollection()->setDefaultShortcut(openPreferredSearchTool
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F
);
2068 connect(openPreferredSearchTool
, &QAction::triggered
, this, &DolphinMainWindow::openPreferredSearchTool
);
2070 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
2071 QAction
*openTerminal
= actionCollection()->addAction(QStringLiteral("open_terminal"));
2072 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
2073 openTerminal
->setWhatsThis(xi18nc("@info:whatsthis",
2074 "<para>This opens a <emphasis>terminal</emphasis> application for the viewed location.</para>"
2075 "<para>To learn more about terminals use the help features in the terminal application.</para>"));
2076 openTerminal
->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
2077 actionCollection()->setDefaultShortcut(openTerminal
, Qt::SHIFT
| Qt::Key_F4
);
2078 connect(openTerminal
, &QAction::triggered
, this, &DolphinMainWindow::openTerminal
);
2080 QAction
*openTerminalHere
= actionCollection()->addAction(QStringLiteral("open_terminal_here"));
2081 // i18n: "Here" refers to the location(s) of the currently selected item(s) or the currently viewed location if nothing is selected.
2082 openTerminalHere
->setText(i18nc("@action:inmenu Tools", "Open Terminal Here"));
2083 openTerminalHere
->setWhatsThis(xi18nc("@info:whatsthis",
2084 "<para>This opens <emphasis>terminal</emphasis> applications for the selected items' locations.</para>"
2085 "<para>To learn more about terminals use the help features in the terminal application.</para>"));
2086 openTerminalHere
->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
2087 actionCollection()->setDefaultShortcut(openTerminalHere
, Qt::SHIFT
| Qt::ALT
| Qt::Key_F4
);
2088 connect(openTerminalHere
, &QAction::triggered
, this, &DolphinMainWindow::openTerminalHere
);
2091 // setup 'Bookmarks' menu
2092 KActionMenu
*bookmarkMenu
= new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this);
2093 bookmarkMenu
->setIcon(QIcon::fromTheme(QStringLiteral("bookmarks")));
2094 // Make the toolbar button version work properly on click
2095 bookmarkMenu
->setPopupMode(QToolButton::InstantPopup
);
2096 m_bookmarkHandler
= new DolphinBookmarkHandler(this, actionCollection(), bookmarkMenu
->menu(), this);
2097 actionCollection()->addAction(QStringLiteral("bookmarks"), bookmarkMenu
);
2099 // setup 'Settings' menu
2100 KToggleAction
*showMenuBar
= KStandardAction::showMenubar(nullptr, nullptr, actionCollection());
2101 showMenuBar
->setWhatsThis(xi18nc("@info:whatsthis",
2102 "<para>This switches between having a <emphasis>Menubar</emphasis> "
2103 "and having an <interface>%1</interface> button. Both "
2104 "contain mostly the same actions and configuration options.</para>"
2105 "<para>The Menubar takes up more space but allows for fast and organized access to all "
2106 "actions an application has to offer.</para><para>The %1 button "
2107 "is simpler and small which makes triggering advanced actions more time consuming.</para>",
2108 hamburgerMenuAction
->text().replace('&', "")));
2109 connect(showMenuBar
,
2110 &KToggleAction::triggered
, // Fixes #286822
2112 &DolphinMainWindow::toggleShowMenuBar
,
2113 Qt::QueuedConnection
);
2115 KToggleAction
*showStatusBar
= KStandardAction::showStatusbar(nullptr, nullptr, actionCollection());
2116 showStatusBar
->setChecked(GeneralSettings::showStatusBar());
2117 connect(GeneralSettings::self(), &GeneralSettings::showStatusBarChanged
, showStatusBar
, &KToggleAction::setChecked
);
2118 connect(showStatusBar
, &KToggleAction::triggered
, this, [this](bool checked
) {
2119 GeneralSettings::setShowStatusBar(checked
);
2123 KStandardAction::keyBindings(this, &DolphinMainWindow::slotKeyBindings
, actionCollection());
2124 KStandardAction::preferences(this, &DolphinMainWindow::editSettings
, actionCollection());
2126 // not in menu actions
2127 QList
<QKeySequence
> nextTabKeys
= KStandardShortcut::tabNext();
2128 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
2130 QList
<QKeySequence
> prevTabKeys
= KStandardShortcut::tabPrev();
2131 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
2133 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
2134 QAction
*activateTab
= actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i
));
2135 activateTab
->setText(i18nc("@action:inmenu", "Go to Tab %1", i
+ 1));
2136 activateTab
->setEnabled(false);
2137 connect(activateTab
, &QAction::triggered
, this, [this, i
]() {
2138 m_tabWidget
->activateTab(i
);
2141 // only add default shortcuts for the first 9 tabs regardless of MaxActivateTabShortcuts
2143 actionCollection()->setDefaultShortcut(activateTab
, QStringLiteral("Alt+%1").arg(i
+ 1));
2147 QAction
*activateLastTab
= actionCollection()->addAction(QStringLiteral("activate_last_tab"));
2148 activateLastTab
->setIconText(i18nc("@action:inmenu", "Last Tab"));
2149 activateLastTab
->setText(i18nc("@action:inmenu", "Go to Last Tab"));
2150 activateLastTab
->setEnabled(false);
2151 connect(activateLastTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateLastTab
);
2152 actionCollection()->setDefaultShortcut(activateLastTab
, Qt::ALT
| Qt::Key_0
);
2154 QAction
*activateNextTab
= actionCollection()->addAction(QStringLiteral("activate_next_tab"));
2155 activateNextTab
->setIconText(i18nc("@action:inmenu", "Next Tab"));
2156 activateNextTab
->setText(i18nc("@action:inmenu", "Go to Next Tab"));
2157 activateNextTab
->setEnabled(false);
2158 connect(activateNextTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateNextTab
);
2159 actionCollection()->setDefaultShortcuts(activateNextTab
, nextTabKeys
);
2161 QAction
*activatePrevTab
= actionCollection()->addAction(QStringLiteral("activate_prev_tab"));
2162 activatePrevTab
->setIconText(i18nc("@action:inmenu", "Previous Tab"));
2163 activatePrevTab
->setText(i18nc("@action:inmenu", "Go to Previous Tab"));
2164 activatePrevTab
->setEnabled(false);
2165 connect(activatePrevTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activatePrevTab
);
2166 actionCollection()->setDefaultShortcuts(activatePrevTab
, prevTabKeys
);
2169 QAction
*showTarget
= actionCollection()->addAction(QStringLiteral("show_target"));
2170 showTarget
->setText(i18nc("@action:inmenu", "Show Target"));
2171 showTarget
->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
2172 showTarget
->setEnabled(false);
2173 connect(showTarget
, &QAction::triggered
, this, &DolphinMainWindow::showTarget
);
2175 QAction
*openInNewTab
= actionCollection()->addAction(QStringLiteral("open_in_new_tab"));
2176 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
2177 openInNewTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
2178 connect(openInNewTab
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
2180 QAction
*openInNewTabs
= actionCollection()->addAction(QStringLiteral("open_in_new_tabs"));
2181 openInNewTabs
->setText(i18nc("@action:inmenu", "Open in New Tabs"));
2182 openInNewTabs
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
2183 connect(openInNewTabs
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
2185 QAction
*openInNewWindow
= actionCollection()->addAction(QStringLiteral("open_in_new_window"));
2186 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
2187 openInNewWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
2188 connect(openInNewWindow
, &QAction::triggered
, this, &DolphinMainWindow::openInNewWindow
);
2190 QAction
*openInSplitViewAction
= actionCollection()->addAction(QStringLiteral("open_in_split_view"));
2191 openInSplitViewAction
->setText(i18nc("@action:inmenu", "Open in Split View"));
2192 openInSplitViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
2193 connect(openInSplitViewAction
, &QAction::triggered
, this, [this]() {
2194 openInSplitView(QUrl());
2197 m_recentFiles
= new KRecentFilesAction(this);
2200 void DolphinMainWindow::setupDockWidgets()
2202 const bool lock
= GeneralSettings::lockPanels();
2204 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(lock
);
2206 KDualAction
*lockLayoutAction
= actionCollection()->add
<KDualAction
>(QStringLiteral("lock_panels"));
2207 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
2208 lockLayoutAction
->setActiveIcon(QIcon::fromTheme(QStringLiteral("object-unlocked")));
2209 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
2210 lockLayoutAction
->setInactiveIcon(QIcon::fromTheme(QStringLiteral("object-locked")));
2211 lockLayoutAction
->setWhatsThis(xi18nc("@info:whatsthis",
2213 "switches between having panels <emphasis>locked</emphasis> or "
2214 "<emphasis>unlocked</emphasis>.<nl/>Unlocked panels can be "
2215 "dragged to the other side of the window and have a close "
2216 "button.<nl/>Locked panels are embedded more cleanly."));
2217 lockLayoutAction
->setActive(lock
);
2218 connect(lockLayoutAction
, &KDualAction::triggered
, this, &DolphinMainWindow::togglePanelLockState
);
2220 // Setup "Information"
2221 DolphinDockWidget
*infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
2222 infoDock
->setLocked(lock
);
2223 infoDock
->setObjectName(QStringLiteral("infoDock"));
2224 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2227 InformationPanel
*infoPanel
= new InformationPanel(infoDock
);
2228 infoPanel
->setCustomContextMenuActions({lockLayoutAction
});
2229 connect(infoPanel
, &InformationPanel::urlActivated
, this, &DolphinMainWindow::handleUrl
);
2230 infoDock
->setWidget(infoPanel
);
2232 createPanelAction(QIcon::fromTheme(QStringLiteral("documentinfo")), Qt::Key_F11
, infoDock
, QStringLiteral("show_information_panel"));
2234 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
2235 connect(this, &DolphinMainWindow::urlChanged
, infoPanel
, &InformationPanel::setUrl
);
2236 connect(this, &DolphinMainWindow::selectionChanged
, infoPanel
, &InformationPanel::setSelection
);
2237 connect(this, &DolphinMainWindow::requestItemInfo
, infoPanel
, &InformationPanel::requestDelayedItemInfo
);
2238 connect(this, &DolphinMainWindow::fileItemsChanged
, infoPanel
, &InformationPanel::slotFilesItemChanged
);
2239 connect(this, &DolphinMainWindow::settingsChanged
, infoPanel
, &InformationPanel::readSettings
);
2242 // i18n: This is the last paragraph for the "What's This"-texts of all four panels.
2243 const QString panelWhatsThis
= xi18nc("@info:whatsthis",
2245 "hide panels like this go to <interface>Menu|Panels</interface> "
2246 "or <interface>View|Panels</interface>.</para>");
2249 ->action(QStringLiteral("show_information_panel"))
2250 ->setWhatsThis(xi18nc("@info:whatsthis",
2251 "<para> This toggles the "
2252 "<emphasis>information</emphasis> panel at the right side of the "
2253 "window.</para><para>The panel provides in-depth information "
2254 "about the items your mouse is hovering over or about the selected "
2255 "items. Otherwise it informs you about the currently viewed folder.<nl/>"
2256 "For single items a preview of their contents is provided.</para>"));
2258 infoDock
->setWhatsThis(xi18nc("@info:whatsthis",
2260 "provides in-depth information about the items your mouse is "
2261 "hovering over or about the selected items. Otherwise it informs "
2262 "you about the currently viewed folder.<nl/>For single items a "
2263 "preview of their contents is provided.</para><para>You can configure "
2264 "which and how details are given here by right-clicking.</para>")
2268 DolphinDockWidget
*foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
2269 foldersDock
->setLocked(lock
);
2270 foldersDock
->setObjectName(QStringLiteral("foldersDock"));
2271 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2272 FoldersPanel
*foldersPanel
= new FoldersPanel(foldersDock
);
2273 foldersPanel
->setCustomContextMenuActions({lockLayoutAction
});
2274 foldersDock
->setWidget(foldersPanel
);
2276 createPanelAction(QIcon::fromTheme(QStringLiteral("folder")), Qt::Key_F7
, foldersDock
, QStringLiteral("show_folders_panel"));
2278 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
2279 connect(this, &DolphinMainWindow::urlChanged
, foldersPanel
, &FoldersPanel::setUrl
);
2280 connect(foldersPanel
, &FoldersPanel::folderActivated
, this, &DolphinMainWindow::changeUrl
);
2281 connect(foldersPanel
, &FoldersPanel::folderInNewTab
, this, &DolphinMainWindow::openNewTab
);
2282 connect(foldersPanel
, &FoldersPanel::folderInNewActiveTab
, this, &DolphinMainWindow::openNewTabAndActivate
);
2283 connect(foldersPanel
, &FoldersPanel::errorMessage
, this, &DolphinMainWindow::showErrorMessage
);
2286 ->action(QStringLiteral("show_folders_panel"))
2287 ->setWhatsThis(xi18nc("@info:whatsthis",
2289 "<emphasis>folders</emphasis> panel at the left side of the window."
2290 "<nl/><nl/>It shows the folders of the <emphasis>file system"
2291 "</emphasis> in a <emphasis>tree view</emphasis>."));
2292 foldersDock
->setWhatsThis(xi18nc("@info:whatsthis",
2294 "shows the folders of the <emphasis>file system</emphasis> in a "
2295 "<emphasis>tree view</emphasis>.</para><para>Click a folder to go "
2296 "there. Click the arrow to the left of a folder to see its subfolders. "
2297 "This allows quick switching between any folders.</para>")
2302 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
2303 DolphinDockWidget
*terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
2304 terminalDock
->setLocked(lock
);
2305 terminalDock
->setObjectName(QStringLiteral("terminalDock"));
2306 terminalDock
->setContentsMargins(0, 0, 0, 0);
2307 m_terminalPanel
= new TerminalPanel(terminalDock
);
2308 m_terminalPanel
->setCustomContextMenuActions({lockLayoutAction
});
2309 terminalDock
->setWidget(m_terminalPanel
);
2311 connect(m_terminalPanel
, &TerminalPanel::hideTerminalPanel
, terminalDock
, &DolphinDockWidget::hide
);
2312 connect(m_terminalPanel
, &TerminalPanel::changeUrl
, this, &DolphinMainWindow::slotTerminalDirectoryChanged
);
2313 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
, m_terminalPanel
, &TerminalPanel::dockVisibilityChanged
);
2314 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
, this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged
);
2316 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-scripts")), Qt::Key_F4
, terminalDock
, QStringLiteral("show_terminal_panel"));
2318 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
2319 connect(this, &DolphinMainWindow::urlChanged
, m_terminalPanel
, &TerminalPanel::setUrl
);
2321 if (GeneralSettings::version() < 200) {
2322 terminalDock
->hide();
2326 ->action(QStringLiteral("show_terminal_panel"))
2327 ->setWhatsThis(xi18nc("@info:whatsthis",
2328 "<para>This toggles the "
2329 "<emphasis>terminal</emphasis> panel at the bottom of the window."
2330 "<nl/>The location in the terminal will always match the folder "
2331 "view so you can navigate using either.</para><para>The terminal "
2332 "panel is not needed for basic computer usage but can be useful "
2333 "for advanced tasks. To learn more about terminals use the help features "
2334 "in a standalone terminal application like Konsole.</para>"));
2335 terminalDock
->setWhatsThis(xi18nc("@info:whatsthis",
2337 "the <emphasis>terminal</emphasis> panel. It behaves like a "
2338 "normal terminal but will match the location of the folder view "
2339 "so you can navigate using either.</para><para>The terminal panel "
2340 "is not needed for basic computer usage but can be useful for "
2341 "advanced tasks. To learn more about terminals use the help features in a "
2342 "standalone terminal application like Konsole.</para>")
2345 QAction
*focusTerminalPanel
= actionCollection()->addAction(QStringLiteral("focus_terminal_panel"));
2346 focusTerminalPanel
->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2347 focusTerminalPanel
->setToolTip(i18nc("@info:tooltip", "Move keyboard focus to and from the Terminal panel."));
2348 focusTerminalPanel
->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
2349 actionCollection()->setDefaultShortcut(focusTerminalPanel
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F4
);
2350 connect(focusTerminalPanel
, &QAction::triggered
, this, &DolphinMainWindow::toggleTerminalPanelFocus
);
2351 } // endif "shell_access" allowed
2352 #endif // HAVE_TERMINAL
2354 if (GeneralSettings::version() < 200) {
2356 foldersDock
->hide();
2360 DolphinDockWidget
*placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
2361 placesDock
->setLocked(lock
);
2362 placesDock
->setObjectName(QStringLiteral("placesDock"));
2363 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2365 m_placesPanel
= new PlacesPanel(placesDock
);
2366 m_placesPanel
->setCustomContextMenuActions({lockLayoutAction
});
2367 placesDock
->setWidget(m_placesPanel
);
2369 createPanelAction(QIcon::fromTheme(QStringLiteral("compass")), Qt::Key_F9
, placesDock
, QStringLiteral("show_places_panel"));
2371 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
2372 connect(m_placesPanel
, &PlacesPanel::placeActivated
, this, &DolphinMainWindow::slotPlaceActivated
);
2373 connect(m_placesPanel
, &PlacesPanel::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2374 connect(m_placesPanel
, &PlacesPanel::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2375 connect(m_placesPanel
, &PlacesPanel::newWindowRequested
, this, [this](const QUrl
&url
) {
2376 Dolphin::openNewWindow({url
}, this);
2378 connect(m_placesPanel
, &PlacesPanel::openInSplitViewRequested
, this, &DolphinMainWindow::openInSplitView
);
2379 connect(m_placesPanel
, &PlacesPanel::errorMessage
, this, &DolphinMainWindow::showErrorMessage
);
2380 connect(this, &DolphinMainWindow::urlChanged
, m_placesPanel
, &PlacesPanel::setUrl
);
2381 connect(placesDock
, &DolphinDockWidget::visibilityChanged
, &DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged
);
2382 connect(placesDock
, &DolphinDockWidget::visibilityChanged
, this, &DolphinMainWindow::slotPlacesPanelVisibilityChanged
);
2383 connect(this, &DolphinMainWindow::settingsChanged
, m_placesPanel
, &PlacesPanel::readSettings
);
2384 connect(m_placesPanel
, &PlacesPanel::storageTearDownRequested
, this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested
);
2385 connect(m_placesPanel
, &PlacesPanel::storageTearDownExternallyRequested
, this, &DolphinMainWindow::slotStorageTearDownExternallyRequested
);
2386 DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged(m_placesPanel
->isVisible());
2388 auto actionShowAllPlaces
= new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this);
2389 actionShowAllPlaces
->setCheckable(true);
2390 actionShowAllPlaces
->setDisabled(true);
2391 actionShowAllPlaces
->setWhatsThis(i18nc("@info:whatsthis",
2393 "all places in the places panel that have been hidden. They will "
2394 "appear semi-transparent and allow you to uncheck their \"Hide\" property."));
2396 connect(actionShowAllPlaces
, &QAction::triggered
, this, [this](bool checked
) {
2397 m_placesPanel
->setShowAll(checked
);
2399 connect(m_placesPanel
, &PlacesPanel::allPlacesShownChanged
, actionShowAllPlaces
, &QAction::setChecked
);
2402 ->action(QStringLiteral("show_places_panel"))
2403 ->setWhatsThis(xi18nc("@info:whatsthis",
2404 "<para>This toggles the "
2405 "<emphasis>places</emphasis> panel at the left side of the window."
2406 "</para><para>It allows you to go to locations you have "
2407 "bookmarked and to access disk or media attached to the computer "
2408 "or to the network. It also contains sections to find recently "
2409 "saved files or files of a certain type.</para>"));
2410 placesDock
->setWhatsThis(xi18nc("@info:whatsthis",
2411 "<para>This is the "
2412 "<emphasis>Places</emphasis> panel. It allows you to go to locations "
2413 "you have bookmarked and to access disk or media attached to the "
2414 "computer or to the network. It also contains sections to find "
2415 "recently saved files or files of a certain type.</para><para>"
2416 "Click on an entry to go there. Click with the right mouse button "
2417 "instead to open any entry in a new tab or new window.</para>"
2418 "<para>New entries can be added by dragging folders onto this panel. "
2419 "Right-click any section or entry to hide it. Right-click an empty "
2420 "space on this panel and select <interface>Show Hidden Places"
2421 "</interface> to display it again.</para>")
2424 QAction
*focusPlacesPanel
= actionCollection()->addAction(QStringLiteral("focus_places_panel"));
2425 focusPlacesPanel
->setText(i18nc("@action:inmenu View", "Focus Places Panel"));
2426 focusPlacesPanel
->setToolTip(i18nc("@info:tooltip", "Move keyboard focus to and from the Places panel."));
2427 focusPlacesPanel
->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
2428 actionCollection()->setDefaultShortcut(focusPlacesPanel
, Qt::CTRL
| Qt::Key_P
);
2429 connect(focusPlacesPanel
, &QAction::triggered
, this, &DolphinMainWindow::togglePlacesPanelFocus
);
2431 // Add actions into the "Panels" menu
2432 KActionMenu
*panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Show Panels"), this);
2433 actionCollection()->addAction(QStringLiteral("panels"), panelsMenu
);
2434 panelsMenu
->setIcon(QIcon::fromTheme(QStringLiteral("view-sidetree")));
2435 panelsMenu
->setPopupMode(QToolButton::InstantPopup
);
2436 const KActionCollection
*ac
= actionCollection();
2437 panelsMenu
->addAction(ac
->action(QStringLiteral("show_places_panel")));
2439 panelsMenu
->addAction(ac
->action(QStringLiteral("show_information_panel")));
2441 panelsMenu
->addAction(ac
->action(QStringLiteral("show_folders_panel")));
2442 panelsMenu
->addAction(ac
->action(QStringLiteral("show_terminal_panel")));
2443 panelsMenu
->addSeparator();
2444 panelsMenu
->addAction(lockLayoutAction
);
2445 panelsMenu
->addSeparator();
2446 panelsMenu
->addAction(actionShowAllPlaces
);
2447 panelsMenu
->addAction(focusPlacesPanel
);
2448 panelsMenu
->addAction(ac
->action(QStringLiteral("focus_terminal_panel")));
2450 connect(panelsMenu
->menu(), &QMenu::aboutToShow
, this, [actionShowAllPlaces
] {
2451 actionShowAllPlaces
->setEnabled(DolphinPlacesModelSingleton::instance().placesModel()->hiddenCount());
2455 void DolphinMainWindow::updateFileAndEditActions()
2457 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
2458 const KActionCollection
*col
= actionCollection();
2459 KFileItemListProperties
capabilitiesSource(list
);
2461 QAction
*renameAction
= col
->action(KStandardAction::name(KStandardAction::RenameFile
));
2462 QAction
*moveToTrashAction
= col
->action(KStandardAction::name(KStandardAction::MoveToTrash
));
2463 QAction
*deleteAction
= col
->action(KStandardAction::name(KStandardAction::DeleteFile
));
2464 QAction
*cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
2465 QAction
*duplicateAction
= col
->action(QStringLiteral("duplicate")); // see DolphinViewActionHandler
2466 QAction
*addToPlacesAction
= col
->action(QStringLiteral("add_to_places"));
2467 QAction
*copyToOtherViewAction
= col
->action(QStringLiteral("copy_to_inactive_split_view"));
2468 QAction
*moveToOtherViewAction
= col
->action(QStringLiteral("move_to_inactive_split_view"));
2469 QAction
*copyLocation
= col
->action(QStringLiteral("copy_location"));
2471 if (list
.isEmpty()) {
2472 stateChanged(QStringLiteral("has_no_selection"));
2474 // All actions that need a selection to function can be enabled because they should trigger selection mode.
2475 renameAction
->setEnabled(true);
2476 moveToTrashAction
->setEnabled(true);
2477 deleteAction
->setEnabled(true);
2478 cutAction
->setEnabled(true);
2479 duplicateAction
->setEnabled(true);
2480 addToPlacesAction
->setEnabled(true);
2481 copyLocation
->setEnabled(true);
2482 // Them triggering selection mode and not directly acting on selected items is signified by adding "…" to their text.
2483 m_actionTextHelper
->textsWhenNothingIsSelectedEnabled(true);
2486 m_actionTextHelper
->textsWhenNothingIsSelectedEnabled(false);
2487 stateChanged(QStringLiteral("has_selection"));
2489 QAction
*deleteWithTrashShortcut
= col
->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
2490 QAction
*showTarget
= col
->action(QStringLiteral("show_target"));
2492 if (list
.length() == 1 && list
.first().isDir()) {
2493 addToPlacesAction
->setEnabled(true);
2495 addToPlacesAction
->setEnabled(false);
2498 const bool enableMoveToTrash
= capabilitiesSource
.isLocal() && capabilitiesSource
.supportsMoving();
2500 renameAction
->setEnabled(capabilitiesSource
.supportsMoving());
2501 m_disabledActionNotifier
->setDisabledReason(renameAction
, i18nc("@info", "Cannot rename: You do not have permission to rename items in this folder."));
2502 deleteAction
->setEnabled(capabilitiesSource
.supportsDeleting());
2503 m_disabledActionNotifier
->setDisabledReason(deleteAction
,
2504 i18nc("@info", "Cannot delete: You do not have permission to remove items from this folder."));
2505 cutAction
->setEnabled(capabilitiesSource
.supportsMoving());
2506 m_disabledActionNotifier
->setDisabledReason(cutAction
, i18nc("@info", "Cannot cut: You do not have permission to move items from this folder."));
2507 copyLocation
->setEnabled(list
.length() == 1);
2508 showTarget
->setEnabled(list
.length() == 1 && list
.at(0).isLink());
2509 duplicateAction
->setEnabled(capabilitiesSource
.supportsWriting());
2510 m_disabledActionNotifier
->setDisabledReason(duplicateAction
,
2511 i18nc("@info", "Cannot duplicate here: You do not have permission to create items in this folder."));
2513 if (enableMoveToTrash
) {
2514 moveToTrashAction
->setEnabled(true);
2515 deleteWithTrashShortcut
->setEnabled(false);
2516 m_disabledActionNotifier
->clearDisabledReason(deleteWithTrashShortcut
);
2518 moveToTrashAction
->setEnabled(false);
2519 deleteWithTrashShortcut
->setEnabled(capabilitiesSource
.supportsDeleting());
2520 m_disabledActionNotifier
->setDisabledReason(deleteWithTrashShortcut
,
2521 i18nc("@info", "Cannot delete: You do not have permission to remove items from this folder."));
2525 if (!m_tabWidget
->currentTabPage()->splitViewEnabled()) {
2526 // No need to set the disabled reason here, as it's obvious to the user that the reason is the split view being disabled.
2527 copyToOtherViewAction
->setEnabled(false);
2528 m_disabledActionNotifier
->clearDisabledReason(copyToOtherViewAction
);
2529 moveToOtherViewAction
->setEnabled(false);
2530 m_disabledActionNotifier
->clearDisabledReason(moveToOtherViewAction
);
2531 } else if (list
.isEmpty()) {
2532 copyToOtherViewAction
->setEnabled(false);
2533 m_disabledActionNotifier
->setDisabledReason(copyToOtherViewAction
, i18nc("@info", "Cannot copy to other view: No files selected."));
2534 moveToOtherViewAction
->setEnabled(false);
2535 m_disabledActionNotifier
->setDisabledReason(moveToOtherViewAction
, i18nc("@info", "Cannot move to other view: No files selected."));
2537 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
2538 KFileItem capabilitiesDestination
;
2540 if (tabPage
->primaryViewActive()) {
2541 capabilitiesDestination
= tabPage
->secondaryViewContainer()->rootItem();
2543 capabilitiesDestination
= tabPage
->primaryViewContainer()->rootItem();
2546 const auto destUrl
= capabilitiesDestination
.url();
2547 const bool allNotTargetOrigin
= std::all_of(list
.cbegin(), list
.cend(), [destUrl
](const KFileItem
&item
) {
2548 return item
.url().adjusted(QUrl::RemoveFilename
| QUrl::StripTrailingSlash
) != destUrl
;
2551 if (!allNotTargetOrigin
) {
2552 copyToOtherViewAction
->setEnabled(false);
2553 m_disabledActionNotifier
->setDisabledReason(copyToOtherViewAction
,
2554 i18nc("@info", "Cannot copy to other view: The other view already contains these items."));
2555 moveToOtherViewAction
->setEnabled(false);
2556 m_disabledActionNotifier
->setDisabledReason(moveToOtherViewAction
,
2557 i18nc("@info", "Cannot move to other view: The other view already contains these items."));
2558 } else if (!capabilitiesDestination
.isWritable()) {
2559 copyToOtherViewAction
->setEnabled(false);
2560 m_disabledActionNotifier
->setDisabledReason(
2561 copyToOtherViewAction
,
2562 i18nc("@info", "Cannot copy to other view: You do not have permission to write into the destination folder."));
2563 moveToOtherViewAction
->setEnabled(false);
2564 m_disabledActionNotifier
->setDisabledReason(
2565 moveToOtherViewAction
,
2566 i18nc("@info", "Cannot move to other view: You do not have permission to write into the destination folder."));
2568 copyToOtherViewAction
->setEnabled(true);
2569 moveToOtherViewAction
->setEnabled(capabilitiesSource
.supportsMoving());
2570 m_disabledActionNotifier
->setDisabledReason(
2571 moveToOtherViewAction
,
2572 i18nc("@info", "Cannot move to other view: You do not have permission to move items from this folder."));
2577 void DolphinMainWindow::updateViewActions()
2579 m_actionHandler
->updateViewActions();
2581 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
2582 toggleFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
2584 updateSplitActions();
2587 void DolphinMainWindow::updateGoActions()
2589 QAction
*goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
2590 const QUrl currentUrl
= m_activeViewContainer
->url();
2591 // I think this is one of the best places to firstly be confronted
2592 // with a file system and its hierarchy. Talking about the root
2593 // directory might seem too much here but it is the question that
2594 // naturally arises in this context.
2595 goUpAction
->setWhatsThis(xi18nc("@info:whatsthis",
2597 "the folder that contains the currently viewed one.</para>"
2598 "<para>All files and folders are organized in a hierarchical "
2599 "<emphasis>file system</emphasis>. At the top of this hierarchy is "
2600 "a directory that contains all data connected to this computer"
2601 "—the <emphasis>root directory</emphasis>.</para>"));
2602 goUpAction
->setEnabled(KIO::upUrl(currentUrl
) != currentUrl
);
2605 void DolphinMainWindow::refreshViews()
2607 m_tabWidget
->refreshViews();
2609 if (GeneralSettings::modifiedStartupSettings()) {
2610 updateWindowTitle();
2613 updateSplitActions();
2615 Q_EMIT
settingsChanged();
2618 void DolphinMainWindow::clearStatusBar()
2620 m_activeViewContainer
->statusBar()->resetToDefaultText();
2623 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
*container
)
2625 connect(container
, &DolphinViewContainer::showFilterBarChanged
, this, &DolphinMainWindow::updateFilterBarAction
);
2626 connect(container
, &DolphinViewContainer::writeStateChanged
, this, &DolphinMainWindow::slotWriteStateChanged
);
2627 slotWriteStateChanged(container
->view()->isFolderWritable());
2628 connect(container
, &DolphinViewContainer::searchModeEnabledChanged
, this, &DolphinMainWindow::updateSearchAction
);
2629 connect(container
, &DolphinViewContainer::captionChanged
, this, &DolphinMainWindow::updateWindowTitle
);
2630 connect(container
, &DolphinViewContainer::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2631 connect(container
, &DolphinViewContainer::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2633 const QAction
*toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
2634 connect(toggleSearchAction
, &QAction::triggered
, container
, &DolphinViewContainer::setSearchModeEnabled
);
2636 // Make the toggled state of the selection mode actions visually follow the selection mode state of the view.
2637 auto toggleSelectionModeAction
= actionCollection()->action(QStringLiteral("toggle_selection_mode"));
2638 toggleSelectionModeAction
->setChecked(m_activeViewContainer
->isSelectionModeEnabled());
2639 connect(m_activeViewContainer
, &DolphinViewContainer::selectionModeChanged
, toggleSelectionModeAction
, &QAction::setChecked
);
2641 const DolphinView
*view
= container
->view();
2642 connect(view
, &DolphinView::selectionChanged
, this, &DolphinMainWindow::slotSelectionChanged
);
2643 connect(view
, &DolphinView::requestItemInfo
, this, &DolphinMainWindow::requestItemInfo
);
2644 connect(view
, &DolphinView::fileItemsChanged
, this, &DolphinMainWindow::fileItemsChanged
);
2645 connect(view
, &DolphinView::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2646 connect(view
, &DolphinView::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2647 connect(view
, &DolphinView::windowRequested
, this, &DolphinMainWindow::openNewWindow
);
2648 connect(view
, &DolphinView::requestContextMenu
, this, &DolphinMainWindow::openContextMenu
);
2649 connect(view
, &DolphinView::directoryLoadingStarted
, this, &DolphinMainWindow::enableStopAction
);
2650 connect(view
, &DolphinView::directoryLoadingCompleted
, this, &DolphinMainWindow::disableStopAction
);
2651 connect(view
, &DolphinView::directoryLoadingCompleted
, this, &DolphinMainWindow::slotDirectoryLoadingCompleted
);
2652 connect(view
, &DolphinView::goBackRequested
, this, &DolphinMainWindow::goBack
);
2653 connect(view
, &DolphinView::goForwardRequested
, this, &DolphinMainWindow::goForward
);
2654 connect(view
, &DolphinView::urlActivated
, this, &DolphinMainWindow::handleUrl
);
2655 connect(view
, &DolphinView::goUpRequested
, this, &DolphinMainWindow::goUp
);
2656 connect(view
, &DolphinView::doubleClickViewBackground
, this, &DolphinMainWindow::slotDoubleClickViewBackground
);
2658 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::urlChanged
, this, &DolphinMainWindow::changeUrl
);
2659 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::historyChanged
, this, &DolphinMainWindow::updateHistory
);
2661 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2662 const KUrlNavigator
*navigator
=
2663 m_tabWidget
->currentTabPage()->primaryViewActive() ? navigators
->primaryUrlNavigator() : navigators
->secondaryUrlNavigator();
2665 QAction
*editableLocactionAction
= actionCollection()->action(QStringLiteral("editable_location"));
2666 editableLocactionAction
->setChecked(navigator
->isUrlEditable());
2667 connect(navigator
, &KUrlNavigator::editableStateChanged
, this, &DolphinMainWindow::slotEditableStateChanged
);
2668 connect(navigator
, &KUrlNavigator::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2669 connect(navigator
, &KUrlNavigator::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2670 connect(navigator
, &KUrlNavigator::newWindowRequested
, this, &DolphinMainWindow::openNewWindow
);
2673 void DolphinMainWindow::updateSplitActions()
2675 QAction
*popoutSplitAction
= actionCollection()->action(QStringLiteral("popout_split_view"));
2677 auto setActionPopupMode
= [this](KActionMenu
*action
, QToolButton::ToolButtonPopupMode popupMode
) {
2678 action
->setPopupMode(popupMode
);
2679 if (auto *buttonForAction
= qobject_cast
<QToolButton
*>(toolBar()->widgetForAction(action
))) {
2680 buttonForAction
->setPopupMode(popupMode
);
2684 const DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
2685 if (tabPage
->splitViewEnabled()) {
2686 if (GeneralSettings::closeActiveSplitView() ? tabPage
->primaryViewActive() : !tabPage
->primaryViewActive()) {
2687 m_splitViewAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2688 m_splitViewAction
->setToolTip(i18nc("@info", "Close left view"));
2689 m_splitViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close")));
2690 popoutSplitAction
->setText(i18nc("@action:intoolbar Move left view to a new window", "Pop out Left View"));
2691 popoutSplitAction
->setToolTip(i18nc("@info", "Move left view to a new window"));
2693 m_splitViewAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2694 m_splitViewAction
->setToolTip(i18nc("@info", "Close right view"));
2695 m_splitViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close")));
2696 popoutSplitAction
->setText(i18nc("@action:intoolbar Move right view to a new window", "Pop out Right View"));
2697 popoutSplitAction
->setToolTip(i18nc("@info", "Move right view to a new window"));
2699 popoutSplitAction
->setEnabled(true);
2700 if (!m_splitViewAction
->menu()) {
2701 setActionPopupMode(m_splitViewAction
, QToolButton::MenuButtonPopup
);
2702 m_splitViewAction
->setMenu(new QMenu
);
2703 m_splitViewAction
->addAction(popoutSplitAction
);
2706 m_splitViewAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2707 m_splitViewAction
->setToolTip(i18nc("@info", "Split view"));
2708 m_splitViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
2709 popoutSplitAction
->setText(i18nc("@action:intoolbar Move view in focus to a new window", "Pop out"));
2710 popoutSplitAction
->setEnabled(false);
2711 if (m_splitViewAction
->menu()) {
2712 m_splitViewAction
->removeAction(popoutSplitAction
);
2713 m_splitViewAction
->menu()->deleteLater();
2714 m_splitViewAction
->setMenu(nullptr);
2715 setActionPopupMode(m_splitViewAction
, QToolButton::DelayedPopup
);
2719 // Update state from toolbar action
2720 m_splitViewMenuAction
->setText(m_splitViewAction
->text());
2721 m_splitViewMenuAction
->setToolTip(m_splitViewAction
->toolTip());
2722 m_splitViewMenuAction
->setIcon(m_splitViewAction
->icon());
2725 void DolphinMainWindow::updateAllowedToolbarAreas()
2727 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2728 if (toolBar()->actions().contains(navigators
)) {
2729 toolBar()->setAllowedAreas(Qt::TopToolBarArea
| Qt::BottomToolBarArea
);
2730 if (toolBarArea(toolBar()) == Qt::LeftToolBarArea
|| toolBarArea(toolBar()) == Qt::RightToolBarArea
) {
2731 addToolBar(Qt::TopToolBarArea
, toolBar());
2734 toolBar()->setAllowedAreas(Qt::AllToolBarAreas
);
2738 bool DolphinMainWindow::isKompareInstalled() const
2740 static bool initialized
= false;
2741 static bool installed
= false;
2743 // TODO: maybe replace this approach later by using a menu
2744 // plugin like kdiff3plugin.cpp
2745 installed
= !QStandardPaths::findExecutable(QStringLiteral("kompare")).isEmpty();
2751 void DolphinMainWindow::createPanelAction(const QIcon
&icon
, const QKeySequence
&shortcut
, QDockWidget
*dockWidget
, const QString
&actionName
)
2753 auto dockAction
= dockWidget
->toggleViewAction();
2754 dockAction
->setIcon(icon
);
2755 dockAction
->setEnabled(true);
2757 QAction
*panelAction
= actionCollection()->addAction(actionName
, dockAction
);
2758 actionCollection()->setDefaultShortcut(panelAction
, shortcut
);
2761 void DolphinMainWindow::setupWhatsThis()
2764 menuBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2765 "<emphasis>Menubar</emphasis>. It provides access to commands and "
2766 "configuration options. Left-click on any of the menus on this "
2767 "bar to see its contents.</para><para>The Menubar can be hidden "
2768 "by unchecking <interface>Settings|Show Menubar</interface>. Then "
2769 "most of its contents become available through a <interface>Menu"
2770 "</interface> button on the <emphasis>Toolbar</emphasis>.</para>"));
2771 toolBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2772 "<emphasis>Toolbar</emphasis>. It allows quick access to "
2773 "frequently used actions.</para><para>It is highly customizable. "
2774 "All items you see in the <interface>Menu</interface> or "
2775 "in the <interface>Menubar</interface> can be placed on the "
2776 "Toolbar. Just right-click on it and select <interface>Configure "
2777 "Toolbars…</interface> or find this action within the <interface>"
2779 "</para><para>The location of the bar and the style of its "
2780 "buttons can also be changed in the right-click menu. Right-click "
2781 "a button if you want to show or hide its text.</para>"));
2782 m_tabWidget
->setWhatsThis(xi18nc("@info:whatsthis main view",
2783 "<para>Here you can see the <emphasis>folders</emphasis> and "
2784 "<emphasis>files</emphasis> that are at the location described in "
2785 "the <interface>Location Bar</interface> above. This area is the "
2786 "central part of this application where you navigate to the files "
2787 "you want to use.</para><para>For an elaborate and general "
2788 "introduction to this application <link "
2789 "url='https://userbase.kde.org/Dolphin/File_Management#Introduction_to_Dolphin'>"
2790 "click here</link>. This will open an introductory article from "
2791 "the <emphasis>KDE UserBase Wiki</emphasis>.</para><para>For brief "
2792 "explanations of all the features of this <emphasis>view</emphasis> "
2793 "<link url='help:/dolphin/dolphin-view.html'>click here</link> "
2794 "instead. This will open a page from the <emphasis>Handbook"
2795 "</emphasis> that covers the basics.</para>"));
2798 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings
))
2799 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window "
2800 "that lists the <emphasis>keyboard shortcuts</emphasis>.<nl/>"
2801 "There you can set up key combinations to trigger an action when "
2802 "they are pressed simultaneously. All commands in this application can "
2803 "be triggered this way.</para>"));
2804 actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars
))
2805 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window in which "
2806 "you can change which buttons appear on the <emphasis>Toolbar</emphasis>.</para>"
2807 "<para>All items you see in the <interface>Menu</interface> can also be placed on the Toolbar.</para>"));
2808 actionCollection()->action(KStandardAction::name(KStandardAction::Preferences
))
2809 ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window where you can "
2810 "change a multitude of settings for this application. For an explanation "
2811 "of the various settings go to the chapter <emphasis>Configuring Dolphin"
2812 "</emphasis> in <interface>Help|Dolphin Handbook</interface>."));
2816 auto setStandardActionWhatsThis
= [this](KStandardAction::StandardAction actionId
,
2817 const QString
&whatsThis
) {
2818 // Check for the existence of an action since it can be restricted through the Kiosk system
2819 if (auto *action
= actionCollection()->action(KStandardAction::name(actionId
))) {
2820 action
->setWhatsThis(whatsThis
);
2824 // i18n: If the external link isn't available in your language it might make
2825 // sense to state the external link's language in brackets to not
2826 // frustrate the user. If there are multiple languages that the user might
2827 // know with a reasonable chance you might want to have 2 external links.
2828 // The same might be true for any external link you translate.
2829 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>"));
2830 // (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 )
2832 setStandardActionWhatsThis(KStandardAction::WhatsThis
,
2833 xi18nc("@info:whatsthis whatsthis button",
2834 "<para>This is the button that invokes the help feature you are "
2835 "using right now! Click it, then click any component of this "
2836 "application to ask \"What's this?\" about it. The mouse cursor "
2837 "will change appearance if no help is available for a spot.</para>"
2838 "<para>There are two other ways to get help: "
2839 "The <link url='help:/dolphin/index.html'>Dolphin Handbook</link> and "
2840 "the <link url='https://userbase.kde.org/Dolphin/File_Management'>KDE "
2841 "UserBase Wiki</link>.</para><para>The \"What's this?\" help is "
2842 "missing in most other windows so don't get too used to this.</para>"));
2844 setStandardActionWhatsThis(KStandardAction::ReportBug
,
2845 xi18nc("@info:whatsthis","<para>This opens a "
2846 "window that will guide you through reporting errors or flaws "
2847 "in this application or in other KDE software.</para>"
2848 "<para>High-quality bug reports are much appreciated. To learn "
2849 "how to make your bug report as effective as possible "
2850 "<link url='https://community.kde.org/Get_Involved/Bug_Reporting'>"
2851 "click here</link>.</para>"));
2853 setStandardActionWhatsThis(KStandardAction::Donate
,
2854 xi18nc("@info:whatsthis", "<para>This opens a "
2855 "<emphasis>web page</emphasis> where you can donate to "
2856 "support the continued work on this application and many "
2857 "other projects by the <emphasis>KDE</emphasis> community.</para>"
2858 "<para>Donating is the easiest and fastest way to efficiently "
2859 "support KDE and its projects. KDE projects are available for "
2860 "free therefore your donation is needed to cover things that "
2861 "require money like servers, contributor meetings, etc.</para>"
2862 "<para><emphasis>KDE e.V.</emphasis> is the non-profit "
2863 "organization behind the KDE community.</para>"));
2865 setStandardActionWhatsThis(KStandardAction::SwitchApplicationLanguage
,
2866 xi18nc("@info:whatsthis",
2867 "With this you can change the language this application uses."
2868 "<nl/>You can even set secondary languages which will be used "
2869 "if texts are not available in your preferred language."));
2871 setStandardActionWhatsThis(KStandardAction::AboutApp
,
2872 xi18nc("@info:whatsthis","This opens a "
2873 "window that informs you about the version, license, "
2874 "used libraries and maintainers of this application."));
2876 setStandardActionWhatsThis(KStandardAction::AboutKDE
,
2877 xi18nc("@info:whatsthis","This opens a "
2878 "window with information about <emphasis>KDE</emphasis>. "
2879 "The KDE community are the people behind this free software."
2880 "<nl/>If you like using this application but don't know "
2881 "about KDE or want to see a cute dragon have a look!"));
2885 bool DolphinMainWindow::addHamburgerMenuToToolbar()
2887 QDomDocument domDocument
= KXMLGUIClient::domDocument();
2888 if (domDocument
.isNull()) {
2891 QDomNode toolbar
= domDocument
.elementsByTagName(QStringLiteral("ToolBar")).at(0);
2892 if (toolbar
.isNull()) {
2896 QDomElement hamburgerMenuElement
= domDocument
.createElement(QStringLiteral("Action"));
2897 hamburgerMenuElement
.setAttribute(QStringLiteral("name"), QStringLiteral("hamburger_menu"));
2898 toolbar
.appendChild(hamburgerMenuElement
);
2900 KXMLGUIFactory::saveConfigFile(domDocument
, xmlFile());
2904 // Make sure to also remove the <KXMLGUIFactory> and <QDomDocument> include
2905 // whenever this method is removed (maybe in the year ~2026).
2908 // Set a sane initial window size
2909 QSize
DolphinMainWindow::sizeHint() const
2911 return KXmlGuiWindow::sizeHint().expandedTo(QSize(760, 550));
2914 void DolphinMainWindow::saveNewToolbarConfig()
2916 KXmlGuiWindow::saveNewToolbarConfig(); // Applies the new config. This has to be called first
2917 // because the rest of this method decides things
2918 // based on the new config.
2919 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2920 if (!toolBar()->actions().contains(navigators
)) {
2921 m_tabWidget
->currentTabPage()->insertNavigatorsWidget(navigators
);
2923 updateAllowedToolbarAreas();
2924 (static_cast<KHamburgerMenu
*>(actionCollection()->action(KStandardAction::name(KStandardAction::HamburgerMenu
))))->hideActionsOf(toolBar());
2927 void DolphinMainWindow::toggleTerminalPanelFocus()
2929 if (!m_terminalPanel
->isVisible()) {
2930 actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger(); // Also moves focus to the panel.
2931 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2935 if (m_terminalPanel
->terminalHasFocus()) {
2936 m_activeViewContainer
->view()->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2937 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2941 m_terminalPanel
->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2942 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2945 void DolphinMainWindow::togglePlacesPanelFocus()
2947 if (!m_placesPanel
->isVisible()) {
2948 actionCollection()->action(QStringLiteral("show_places_panel"))->trigger(); // Also moves focus to the panel.
2949 actionCollection()->action(QStringLiteral("focus_places_panel"))->setText(i18nc("@action:inmenu View", "Defocus Terminal Panel"));
2953 if (m_placesPanel
->hasFocus()) {
2954 m_activeViewContainer
->view()->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2955 actionCollection()->action(QStringLiteral("focus_places_panel"))->setText(i18nc("@action:inmenu View", "Focus Places Panel"));
2959 m_placesPanel
->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2960 actionCollection()->action(QStringLiteral("focus_places_panel"))->setText(i18nc("@action:inmenu View", "Defocus Places Panel"));
2963 DolphinMainWindow::UndoUiInterface::UndoUiInterface()
2964 : KIO::FileUndoManager::UiInterface()
2968 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2972 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
*job
)
2974 DolphinMainWindow
*mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2976 DolphinViewContainer
*container
= mainWin
->activeViewContainer();
2977 container
->showMessage(job
->errorString(), KMessageWidget::Error
);
2979 KIO::FileUndoManager::UiInterface::jobError(job
);
2983 bool DolphinMainWindow::isUrlOpen(const QString
&url
)
2985 return m_tabWidget
->isUrlOpen(QUrl::fromUserInput(url
));
2988 bool DolphinMainWindow::isItemVisibleInAnyView(const QString
&urlOfItem
)
2990 return m_tabWidget
->isItemVisibleInAnyView(QUrl::fromUserInput(urlOfItem
));
2993 void DolphinMainWindow::slotDoubleClickViewBackground(Qt::MouseButton button
)
2995 if (button
!= Qt::MouseButton::LeftButton
) {
2996 // only handle left mouse button for now
3000 GeneralSettings
*settings
= GeneralSettings::self();
3001 QString clickAction
= settings
->doubleClickViewAction();
3003 DolphinView
*view
= activeViewContainer()->view();
3004 if (view
== nullptr || clickAction
== "none") {
3008 if (clickAction
== customCommand
) {
3009 // run custom command set by the user
3010 QString path
= view
->url().toLocalFile();
3011 QString clickCustomAction
= settings
->doubleClickViewCustomAction();
3012 clickCustomAction
.replace("{path}", path
.prepend('"').append('"'));
3014 m_job
= new KIO::CommandLauncherJob(clickCustomAction
);
3015 m_job
->setUiDelegate(new KDialogJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
3019 // get the action set by the user and trigger it
3020 const KActionCollection
*actions
= actionCollection();
3021 QAction
*action
= actions
->action(clickAction
);
3022 if (action
== nullptr) {
3023 qCWarning(DolphinDebug
) << QStringLiteral("Double-click view: action `%1` was not found").arg(clickAction
);
3030 #include "moc_dolphinmainwindow.cpp"