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 "dolphin_generalsettings.h"
12 #include "dolphinbookmarkhandler.h"
13 #include "dolphincontextmenu.h"
14 #include "dolphindockwidget.h"
15 #include "dolphinmainwindowadaptor.h"
16 #include "dolphinnavigatorswidgetaction.h"
17 #include "dolphinnewfilemenu.h"
18 #include "dolphinplacesmodelsingleton.h"
19 #include "dolphinrecenttabsmenu.h"
20 #include "dolphintabpage.h"
21 #include "dolphinurlnavigatorscontroller.h"
22 #include "dolphinviewcontainer.h"
24 #include "middleclickactioneventfilter.h"
25 #include "panels/folders/folderspanel.h"
26 #include "panels/places/placespanel.h"
27 #include "panels/terminal/terminalpanel.h"
28 #include "selectionmode/actiontexthelper.h"
29 #include "settings/dolphinsettingsdialog.h"
30 #include "statusbar/dolphinstatusbar.h"
31 #include "views/dolphinnewfilemenuobserver.h"
32 #include "views/dolphinremoteencoding.h"
33 #include "views/dolphinviewactionhandler.h"
34 #include "views/draganddrophelper.h"
35 #include "views/viewproperties.h"
37 #include <KActionCollection>
38 #include <KActionMenu>
39 #include <KAuthorized>
42 #include <KDualAction>
43 #include <KFileItemListProperties>
44 #include <KIO/CommandLauncherJob>
45 #include <kio_version.h>
46 #if KIO_VERSION >= QT_VERSION_CHECK(5, 98, 0)
47 #include <KIO/JobUiDelegateFactory>
49 #include <KIO/JobUiDelegate>
51 #include <KIO/OpenFileManagerWindowJob>
52 #include <KIO/OpenUrlJob>
53 #include <KJobWidgets>
54 #include <KLocalizedString>
55 #include <KMessageBox>
56 #include <KMoreToolsMenuFactory>
57 #include <KProtocolInfo>
58 #include <KProtocolManager>
60 #include <KShortcutsDialog>
61 #include <KStandardAction>
62 #include <KStartupInfo>
64 #include <KTerminalLauncherJob>
65 #include <KToggleAction>
67 #include <KToolBarPopupAction>
68 #include <KUrlComboBox>
69 #include <KUrlNavigator>
70 #include <KWindowSystem>
71 #include <KXMLGUIFactory>
73 #include <kio_version.h>
74 #include <kwidgetsaddons_version.h>
76 #include <QApplication>
78 #include <QCloseEvent>
79 #include <QDesktopServices>
81 #include <QDomDocument>
85 #include <QPushButton>
87 #include <QStandardPaths>
89 #include <QToolButton>
95 // Used for GeneralSettings::version() to determine whether
96 // an updated version of Dolphin is running, so as to migrate
97 // removed/renamed ...etc config entries; increment it in such
99 const int CurrentDolphinVersion
= 202;
100 // The maximum number of entries in the back/forward popup menu
101 const int MaxNumberOfNavigationentries
= 12;
102 // The maximum number of "Activate Tab" shortcuts
103 const int MaxActivateTabShortcuts
= 9;
106 DolphinMainWindow::DolphinMainWindow()
107 : KXmlGuiWindow(nullptr)
108 , m_newFileMenu(nullptr)
109 , m_tabWidget(nullptr)
110 , m_activeViewContainer(nullptr)
111 , m_actionHandler(nullptr)
112 , m_remoteEncoding(nullptr)
114 , m_bookmarkHandler(nullptr)
115 , m_lastHandleUrlOpenJob(nullptr)
116 , m_terminalPanel(nullptr)
117 , m_placesPanel(nullptr)
118 , m_tearDownFromPlacesRequested(false)
119 , m_backAction(nullptr)
120 , m_forwardAction(nullptr)
122 Q_INIT_RESOURCE(dolphin
);
124 new MainWindowAdaptor(this);
127 setWindowFlags(Qt::WindowContextHelpButtonHint
);
129 setComponentName(QStringLiteral("dolphin"), QGuiApplication::applicationDisplayName());
130 setObjectName(QStringLiteral("Dolphin#"));
132 setStateConfigGroup("State");
134 connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::errorMessage
, this, &DolphinMainWindow::showErrorMessage
);
136 KIO::FileUndoManager
*undoManager
= KIO::FileUndoManager::self();
137 undoManager
->setUiInterface(new UndoUiInterface());
139 connect(undoManager
, &KIO::FileUndoManager::undoAvailable
, this, &DolphinMainWindow::slotUndoAvailable
);
140 connect(undoManager
, &KIO::FileUndoManager::undoTextChanged
, this, &DolphinMainWindow::slotUndoTextChanged
);
141 connect(undoManager
, &KIO::FileUndoManager::jobRecordingStarted
, this, &DolphinMainWindow::clearStatusBar
);
142 connect(undoManager
, &KIO::FileUndoManager::jobRecordingFinished
, this, &DolphinMainWindow::showCommand
);
144 const bool firstRun
= (GeneralSettings::version() < 200);
146 GeneralSettings::setViewPropsTimestamp(QDateTime::currentDateTime());
149 setAcceptDrops(true);
151 auto *navigatorsWidgetAction
= new DolphinNavigatorsWidgetAction(this);
152 actionCollection()->addAction(QStringLiteral("url_navigators"), navigatorsWidgetAction
);
153 m_tabWidget
= new DolphinTabWidget(navigatorsWidgetAction
, this);
154 m_tabWidget
->setObjectName("tabWidget");
155 connect(m_tabWidget
, &DolphinTabWidget::activeViewChanged
, this, &DolphinMainWindow::activeViewChanged
);
156 connect(m_tabWidget
, &DolphinTabWidget::tabCountChanged
, this, &DolphinMainWindow::tabCountChanged
);
157 connect(m_tabWidget
, &DolphinTabWidget::currentUrlChanged
, this, &DolphinMainWindow::updateWindowTitle
);
158 setCentralWidget(m_tabWidget
);
160 m_actionTextHelper
= new SelectionMode::ActionTextHelper(this);
163 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), m_actionTextHelper
, this);
164 connect(m_actionHandler
, &DolphinViewActionHandler::actionBeingHandled
, this, &DolphinMainWindow::clearStatusBar
);
165 connect(m_actionHandler
, &DolphinViewActionHandler::createDirectoryTriggered
, this, &DolphinMainWindow::createDirectory
);
166 connect(m_actionHandler
, &DolphinViewActionHandler::selectionModeChangeTriggered
, this, &DolphinMainWindow::slotSetSelectionMode
);
168 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
169 connect(this, &DolphinMainWindow::urlChanged
, m_remoteEncoding
, &DolphinRemoteEncoding::slotAboutToOpenUrl
);
173 setupGUI(Save
| Create
| ToolBar
);
174 stateChanged(QStringLiteral("new_file"));
176 QClipboard
*clipboard
= QApplication::clipboard();
177 connect(clipboard
, &QClipboard::dataChanged
, this, &DolphinMainWindow::updatePasteAction
);
179 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
180 toggleFilterBarAction
->setChecked(GeneralSettings::filterBar());
183 menuBar()->setVisible(false);
186 const bool showMenu
= !menuBar()->isHidden();
187 QAction
*showMenuBarAction
= actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar
));
188 showMenuBarAction
->setChecked(showMenu
); // workaround for bug #171080
190 auto hamburgerMenu
= static_cast<KHamburgerMenu
*>(actionCollection()->action(KStandardAction::name(KStandardAction::HamburgerMenu
)));
191 hamburgerMenu
->setMenuBar(menuBar());
192 hamburgerMenu
->setShowMenuBarAction(showMenuBarAction
);
193 connect(hamburgerMenu
, &KHamburgerMenu::aboutToShowMenu
, this, &DolphinMainWindow::updateHamburgerMenu
);
194 hamburgerMenu
->hideActionsOf(toolBar());
195 if (GeneralSettings::version() < 201 && !toolBar()->actions().contains(hamburgerMenu
)) {
196 addHamburgerMenuToToolbar();
199 updateAllowedToolbarAreas();
201 // enable middle-click on back/forward/up to open in a new tab
202 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
203 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotToolBarActionMiddleClicked
);
204 toolBar()->installEventFilter(middleClickEventFilter
);
208 connect(KSycoca::self(), &KSycoca::databaseChanged
, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
210 QTimer::singleShot(0, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
212 m_fileItemActions
.setParentWidget(this);
213 connect(&m_fileItemActions
, &KFileItemActions::error
, this, [this](const QString
&errorMessage
) {
214 showErrorMessage(errorMessage
);
217 connect(GeneralSettings::self(), &GeneralSettings::splitViewChanged
, this, &DolphinMainWindow::slotSplitViewChanged
);
220 DolphinMainWindow::~DolphinMainWindow()
222 // This fixes a crash on Wayland when closing the mainwindow while another dialog is open.
223 disconnect(QGuiApplication::clipboard(), &QClipboard::dataChanged
, this, &DolphinMainWindow::updatePasteAction
);
226 QVector
<DolphinViewContainer
*> DolphinMainWindow::viewContainers() const
228 QVector
<DolphinViewContainer
*> viewContainers
;
230 for (int i
= 0; i
< m_tabWidget
->count(); ++i
) {
231 DolphinTabPage
*tabPage
= m_tabWidget
->tabPageAt(i
);
233 viewContainers
<< tabPage
->primaryViewContainer();
234 if (tabPage
->splitViewEnabled()) {
235 viewContainers
<< tabPage
->secondaryViewContainer();
238 return viewContainers
;
241 void DolphinMainWindow::openDirectories(const QList
<QUrl
> &dirs
, bool splitView
)
243 m_tabWidget
->openDirectories(dirs
, splitView
);
246 void DolphinMainWindow::openDirectories(const QStringList
&dirs
, bool splitView
)
248 openDirectories(QUrl::fromStringList(dirs
), splitView
);
251 void DolphinMainWindow::openFiles(const QList
<QUrl
> &files
, bool splitView
)
253 m_tabWidget
->openFiles(files
, splitView
);
256 bool DolphinMainWindow::isFoldersPanelEnabled() const
258 return actionCollection()->action(QStringLiteral("show_folders_panel"))->isChecked();
261 bool DolphinMainWindow::isInformationPanelEnabled() const
264 return actionCollection()->action(QStringLiteral("show_information_panel"))->isChecked();
270 bool DolphinMainWindow::isSplitViewEnabledInCurrentTab() const
272 return m_tabWidget
->currentTabPage()->splitViewEnabled();
275 void DolphinMainWindow::openFiles(const QStringList
&files
, bool splitView
)
277 openFiles(QUrl::fromStringList(files
), splitView
);
280 void DolphinMainWindow::activateWindow(const QString
&activationToken
)
282 window()->setAttribute(Qt::WA_NativeWindow
, true);
284 if (KWindowSystem::isPlatformWayland()) {
285 KWindowSystem::setCurrentXdgActivationToken(activationToken
);
287 KStartupInfo::setNewStartupId(window()->windowHandle(), activationToken
.toUtf8());
290 KWindowSystem::activateWindow(window()->windowHandle());
293 bool DolphinMainWindow::isActiveWindow()
295 return window()->isActiveWindow();
298 void DolphinMainWindow::showCommand(CommandType command
)
300 DolphinStatusBar
*statusBar
= m_activeViewContainer
->statusBar();
302 case KIO::FileUndoManager::Copy
:
303 statusBar
->setText(i18nc("@info:status", "Successfully copied."));
305 case KIO::FileUndoManager::Move
:
306 statusBar
->setText(i18nc("@info:status", "Successfully moved."));
308 case KIO::FileUndoManager::Link
:
309 statusBar
->setText(i18nc("@info:status", "Successfully linked."));
311 case KIO::FileUndoManager::Trash
:
312 statusBar
->setText(i18nc("@info:status", "Successfully moved to trash."));
314 case KIO::FileUndoManager::Rename
:
315 statusBar
->setText(i18nc("@info:status", "Successfully renamed."));
318 case KIO::FileUndoManager::Mkdir
:
319 statusBar
->setText(i18nc("@info:status", "Created folder."));
327 void DolphinMainWindow::pasteIntoFolder()
329 m_activeViewContainer
->view()->pasteIntoFolder();
332 void DolphinMainWindow::changeUrl(const QUrl
&url
)
334 if (!KProtocolManager::supportsListing(url
)) {
335 // The URL navigator only checks for validity, not
336 // if the URL can be listed. An error message is
337 // shown due to DolphinViewContainer::restoreView().
341 m_activeViewContainer
->setUrl(url
);
342 updateFileAndEditActions();
347 Q_EMIT
urlChanged(url
);
350 void DolphinMainWindow::slotTerminalDirectoryChanged(const QUrl
&url
)
352 if (m_tearDownFromPlacesRequested
&& url
== QUrl::fromLocalFile(QDir::homePath())) {
353 m_placesPanel
->proceedWithTearDown();
354 m_tearDownFromPlacesRequested
= false;
357 m_activeViewContainer
->setAutoGrabFocus(false);
359 m_activeViewContainer
->setAutoGrabFocus(true);
362 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
364 KToggleAction
*editableLocationAction
= static_cast<KToggleAction
*>(actionCollection()->action(QStringLiteral("editable_location")));
365 editableLocationAction
->setChecked(editable
);
368 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
&selection
)
370 updateFileAndEditActions();
372 const int selectedUrlsCount
= m_tabWidget
->currentTabPage()->selectedItemsCount();
374 QAction
*compareFilesAction
= actionCollection()->action(QStringLiteral("compare_files"));
375 if (selectedUrlsCount
== 2) {
376 compareFilesAction
->setEnabled(isKompareInstalled());
378 compareFilesAction
->setEnabled(false);
381 Q_EMIT
selectionChanged(selection
);
384 void DolphinMainWindow::updateHistory()
386 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
387 const int index
= urlNavigator
->historyIndex();
389 QAction
*backAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Back
));
391 backAction
->setToolTip(i18nc("@info", "Go back"));
392 backAction
->setWhatsThis(i18nc("@info:whatsthis go back", "Return to the previously viewed folder."));
393 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
396 QAction
*forwardAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Forward
));
398 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
399 forwardAction
->setWhatsThis(xi18nc("@info:whatsthis go forward", "This undoes a <interface>Go|Back</interface> action."));
400 forwardAction
->setEnabled(index
> 0);
404 void DolphinMainWindow::updateFilterBarAction(bool show
)
406 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
407 toggleFilterBarAction
->setChecked(show
);
410 void DolphinMainWindow::openNewMainWindow()
412 Dolphin::openNewWindow({m_activeViewContainer
->url()}, this);
415 void DolphinMainWindow::openNewActivatedTab()
417 // keep browsers compatibility, new tab is always after last one
418 auto openNewTabAfterLastTabConfigured
= GeneralSettings::openNewTabAfterLastTab();
419 GeneralSettings::setOpenNewTabAfterLastTab(true);
420 m_tabWidget
->openNewActivatedTab();
421 GeneralSettings::setOpenNewTabAfterLastTab(openNewTabAfterLastTabConfigured
);
424 void DolphinMainWindow::addToPlaces()
429 // If nothing is selected, act on the current dir
430 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
431 url
= m_activeViewContainer
->url();
432 name
= m_activeViewContainer
->placesText();
434 const auto dirToAdd
= m_activeViewContainer
->view()->selectedItems().first();
435 url
= dirToAdd
.url();
436 name
= dirToAdd
.name();
440 if (m_activeViewContainer
->isSearchModeEnabled()) {
441 icon
= QStringLiteral("folder-saved-search-symbolic");
443 icon
= KIO::iconNameForUrl(url
);
445 DolphinPlacesModelSingleton::instance().placesModel()->addPlace(name
, url
, icon
);
449 void DolphinMainWindow::openNewTab(const QUrl
&url
)
451 m_tabWidget
->openNewTab(url
, QUrl());
454 void DolphinMainWindow::openNewTabAndActivate(const QUrl
&url
)
456 m_tabWidget
->openNewActivatedTab(url
, QUrl());
459 void DolphinMainWindow::openNewWindow(const QUrl
&url
)
461 Dolphin::openNewWindow({url
}, this);
464 void DolphinMainWindow::slotSplitViewChanged()
466 m_tabWidget
->currentTabPage()->setSplitViewEnabled(GeneralSettings::splitView(), WithAnimation
);
470 void DolphinMainWindow::openInNewTab()
472 const KFileItemList
&list
= m_activeViewContainer
->view()->selectedItems();
473 bool tabCreated
= false;
475 for (const KFileItem
&item
: list
) {
476 const QUrl
&url
= DolphinView::openItemAsFolderUrl(item
);
477 if (!url
.isEmpty()) {
483 // if no new tab has been created from the selection
484 // open the current directory in a new tab
486 openNewTab(m_activeViewContainer
->url());
490 void DolphinMainWindow::openInNewWindow()
494 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
495 if (list
.isEmpty()) {
496 newWindowUrl
= m_activeViewContainer
->url();
497 } else if (list
.count() == 1) {
498 const KFileItem
&item
= list
.first();
499 newWindowUrl
= DolphinView::openItemAsFolderUrl(item
);
502 if (!newWindowUrl
.isEmpty()) {
503 Dolphin::openNewWindow({newWindowUrl
}, this);
507 void DolphinMainWindow::showTarget()
509 const KFileItem link
= m_activeViewContainer
->view()->selectedItems().at(0);
510 const QUrl destinationUrl
= link
.url().resolved(QUrl(link
.linkDest()));
512 auto job
= KIO::statDetails(destinationUrl
, KIO::StatJob::SourceSide
, KIO::StatNoDetails
);
514 connect(job
, &KJob::finished
, this, [this, destinationUrl
](KJob
*job
) {
515 KIO::StatJob
*statJob
= static_cast<KIO::StatJob
*>(job
);
517 if (statJob
->error()) {
518 m_activeViewContainer
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
520 KIO::highlightInFileManager({destinationUrl
});
525 bool DolphinMainWindow::event(QEvent
*event
)
527 if (event
->type() == QEvent::ShortcutOverride
) {
528 const QKeyEvent
*keyEvent
= static_cast<QKeyEvent
*>(event
);
529 if (keyEvent
->key() == Qt::Key_Space
&& m_activeViewContainer
->view()->handleSpaceAsNormalKey()) {
535 return KXmlGuiWindow::event(event
);
538 void DolphinMainWindow::showEvent(QShowEvent
*event
)
540 KXmlGuiWindow::showEvent(event
);
542 if (!event
->spontaneous()) {
543 m_activeViewContainer
->view()->setFocus();
547 void DolphinMainWindow::closeEvent(QCloseEvent
*event
)
549 // Find out if Dolphin is closed directly by the user or
550 // by the session manager because the session is closed
551 bool closedByUser
= true;
552 if (qApp
->isSavingSession()) {
553 closedByUser
= false;
556 if (m_tabWidget
->count() > 1 && GeneralSettings::confirmClosingMultipleTabs() && !GeneralSettings::rememberOpenedTabs() && closedByUser
) {
557 // Ask the user if he really wants to quit and close all tabs.
558 // Open a confirmation dialog with 3 buttons:
559 // QDialogButtonBox::Yes -> Quit
560 // QDialogButtonBox::No -> Close only the current tab
561 // QDialogButtonBox::Cancel -> do nothing
562 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
563 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
564 dialog
->setModal(true);
565 QDialogButtonBox
*buttons
= new QDialogButtonBox(QDialogButtonBox::Yes
| QDialogButtonBox::No
| QDialogButtonBox::Cancel
);
566 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
),
567 KGuiItem(i18nc("@action:button 'Quit Dolphin' button", "&Quit %1", QGuiApplication::applicationDisplayName()),
568 QIcon::fromTheme(QStringLiteral("application-exit"))));
569 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("C&lose Current Tab"), QIcon::fromTheme(QStringLiteral("tab-close"))));
570 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
571 buttons
->button(QDialogButtonBox::Yes
)->setDefault(true);
573 bool doNotAskAgainCheckboxResult
= false;
575 const auto result
= KMessageBox::createKMessageBox(dialog
,
577 QMessageBox::Warning
,
578 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
580 i18n("Do not ask again"),
581 &doNotAskAgainCheckboxResult
,
582 KMessageBox::Notify
);
584 if (doNotAskAgainCheckboxResult
) {
585 GeneralSettings::setConfirmClosingMultipleTabs(false);
589 case QDialogButtonBox::Yes
:
592 case QDialogButtonBox::No
:
593 // Close only the current tab
594 m_tabWidget
->closeTab();
602 if (m_terminalPanel
&& m_terminalPanel
->hasProgramRunning() && GeneralSettings::confirmClosingTerminalRunningProgram() && closedByUser
) {
603 // Ask if the user really wants to quit Dolphin with a program that is still running in the Terminal panel
604 // Open a confirmation dialog with 3 buttons:
605 // QDialogButtonBox::Yes -> Quit
606 // QDialogButtonBox::No -> Show Terminal Panel
607 // QDialogButtonBox::Cancel -> do nothing
608 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
609 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
610 dialog
->setModal(true);
611 auto standardButtons
= QDialogButtonBox::Yes
| QDialogButtonBox::Cancel
;
612 if (!m_terminalPanel
->isVisible()) {
613 standardButtons
|= QDialogButtonBox::No
;
615 QDialogButtonBox
*buttons
= new QDialogButtonBox(standardButtons
);
616 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KStandardGuiItem::quit());
617 if (!m_terminalPanel
->isVisible()) {
618 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("Show &Terminal Panel"), QIcon::fromTheme(QStringLiteral("dialog-scripts"))));
620 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
622 bool doNotAskAgainCheckboxResult
= false;
624 const auto result
= KMessageBox::createKMessageBox(
627 QMessageBox::Warning
,
628 i18n("The program '%1' is still running in the Terminal panel. Are you sure you want to quit?", m_terminalPanel
->runningProgramName()),
630 i18n("Do not ask again"),
631 &doNotAskAgainCheckboxResult
,
632 KMessageBox::Dangerous
);
634 if (doNotAskAgainCheckboxResult
) {
635 GeneralSettings::setConfirmClosingTerminalRunningProgram(false);
639 case QDialogButtonBox::Yes
:
642 case QDialogButtonBox::No
:
643 actionCollection()->action("show_terminal_panel")->trigger();
644 // Do not quit, ignore quit event
652 if (GeneralSettings::rememberOpenedTabs()) {
653 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
654 KConfig
*config
= KConfigGui::sessionConfig();
655 saveGlobalProperties(config
);
656 savePropertiesInternal(config
, 1);
660 GeneralSettings::setVersion(CurrentDolphinVersion
);
661 GeneralSettings::self()->save();
663 KXmlGuiWindow::closeEvent(event
);
666 void DolphinMainWindow::saveProperties(KConfigGroup
&group
)
668 m_tabWidget
->saveProperties(group
);
671 void DolphinMainWindow::readProperties(const KConfigGroup
&group
)
673 m_tabWidget
->readProperties(group
);
676 void DolphinMainWindow::updateNewMenu()
678 m_newFileMenu
->checkUpToDate();
679 #if KIO_VERSION >= QT_VERSION_CHECK(5, 97, 0)
680 m_newFileMenu
->setWorkingDirectory(activeViewContainer()->url());
682 m_newFileMenu
->setPopupFiles(QList
<QUrl
>() << activeViewContainer()->url());
686 void DolphinMainWindow::createDirectory()
688 #if KIO_VERSION >= QT_VERSION_CHECK(5, 97, 0)
689 m_newFileMenu
->setWorkingDirectory(activeViewContainer()->url());
691 m_newFileMenu
->setPopupFiles(QList
<QUrl
>() << activeViewContainer()->url());
693 m_newFileMenu
->createDirectory();
696 void DolphinMainWindow::quit()
701 void DolphinMainWindow::showErrorMessage(const QString
&message
)
703 m_activeViewContainer
->showMessage(message
, DolphinViewContainer::Error
);
706 void DolphinMainWindow::slotUndoAvailable(bool available
)
708 QAction
*undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
710 undoAction
->setEnabled(available
);
714 void DolphinMainWindow::slotUndoTextChanged(const QString
&text
)
716 QAction
*undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
718 undoAction
->setText(text
);
722 void DolphinMainWindow::undo()
725 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
726 KIO::FileUndoManager::self()->undo();
729 void DolphinMainWindow::cut()
731 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
732 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CutContents
);
734 m_activeViewContainer
->view()->cutSelectedItemsToClipboard();
735 m_activeViewContainer
->setSelectionModeEnabled(false);
739 void DolphinMainWindow::copy()
741 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
742 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CopyContents
);
744 m_activeViewContainer
->view()->copySelectedItemsToClipboard();
745 m_activeViewContainer
->setSelectionModeEnabled(false);
749 void DolphinMainWindow::paste()
751 m_activeViewContainer
->view()->paste();
754 void DolphinMainWindow::find()
756 m_activeViewContainer
->setSearchModeEnabled(true);
759 void DolphinMainWindow::updateSearchAction()
761 QAction
*toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
762 toggleSearchAction
->setChecked(m_activeViewContainer
->isSearchModeEnabled());
765 void DolphinMainWindow::updatePasteAction()
767 QAction
*pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
768 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
769 pasteAction
->setEnabled(pasteInfo
.first
);
770 pasteAction
->setText(pasteInfo
.second
);
773 void DolphinMainWindow::slotDirectoryLoadingCompleted()
778 void DolphinMainWindow::slotToolBarActionMiddleClicked(QAction
*action
)
780 if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Back
))) {
782 } else if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Forward
))) {
784 } else if (action
== actionCollection()->action(QStringLiteral("go_up"))) {
786 } else if (action
== actionCollection()->action(QStringLiteral("go_home"))) {
791 QAction
*DolphinMainWindow::urlNavigatorHistoryAction(const KUrlNavigator
*urlNavigator
, int historyIndex
, QObject
*parent
)
793 const QUrl url
= urlNavigator
->locationUrl(historyIndex
);
795 QString text
= url
.toDisplayString(QUrl::PreferLocalFile
);
797 if (!urlNavigator
->showFullPath()) {
798 const KFilePlacesModel
*placesModel
= DolphinPlacesModelSingleton::instance().placesModel();
800 const QModelIndex closestIdx
= placesModel
->closestItem(url
);
801 if (closestIdx
.isValid()) {
802 const QUrl placeUrl
= placesModel
->url(closestIdx
);
804 text
= placesModel
->text(closestIdx
);
806 QString pathInsidePlace
= url
.path().mid(placeUrl
.path().length());
808 if (!pathInsidePlace
.isEmpty() && !pathInsidePlace
.startsWith(QLatin1Char('/'))) {
809 pathInsidePlace
.prepend(QLatin1Char('/'));
812 if (pathInsidePlace
!= QLatin1Char('/')) {
813 text
.append(pathInsidePlace
);
818 QAction
*action
= new QAction(QIcon::fromTheme(KIO::iconNameForUrl(url
)), text
, parent
);
819 action
->setData(historyIndex
);
823 void DolphinMainWindow::slotAboutToShowBackPopupMenu()
825 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
827 m_backAction
->menu()->clear();
828 for (int i
= urlNavigator
->historyIndex() + 1; i
< urlNavigator
->historySize() && entries
< MaxNumberOfNavigationentries
; ++i
, ++entries
) {
829 QAction
*action
= urlNavigatorHistoryAction(urlNavigator
, i
, m_backAction
->menu());
830 m_backAction
->menu()->addAction(action
);
834 void DolphinMainWindow::slotGoBack(QAction
*action
)
836 int gotoIndex
= action
->data().value
<int>();
837 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
838 for (int i
= gotoIndex
- urlNavigator
->historyIndex(); i
> 0; --i
) {
843 void DolphinMainWindow::slotBackForwardActionMiddleClicked(QAction
*action
)
846 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
847 openNewTab(urlNavigator
->locationUrl(action
->data().value
<int>()));
851 void DolphinMainWindow::slotAboutToShowForwardPopupMenu()
853 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
855 m_forwardAction
->menu()->clear();
856 for (int i
= urlNavigator
->historyIndex() - 1; i
>= 0 && entries
< MaxNumberOfNavigationentries
; --i
, ++entries
) {
857 QAction
*action
= urlNavigatorHistoryAction(urlNavigator
, i
, m_forwardAction
->menu());
858 m_forwardAction
->menu()->addAction(action
);
862 void DolphinMainWindow::slotGoForward(QAction
*action
)
864 int gotoIndex
= action
->data().value
<int>();
865 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
866 for (int i
= urlNavigator
->historyIndex() - gotoIndex
; i
> 0; --i
) {
871 void DolphinMainWindow::slotSetSelectionMode(bool enabled
, SelectionMode::BottomBar::Contents bottomBarContents
)
873 m_activeViewContainer
->setSelectionModeEnabled(enabled
, actionCollection(), bottomBarContents
);
876 void DolphinMainWindow::selectAll()
880 // if the URL navigator is editable and focused, select the whole
881 // URL instead of all items of the view
883 KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigator();
884 QLineEdit
*lineEdit
= urlNavigator
->editor()->lineEdit();
885 const bool selectUrl
= urlNavigator
->isUrlEditable() && lineEdit
->hasFocus();
887 lineEdit
->selectAll();
889 m_activeViewContainer
->view()->selectAll();
893 void DolphinMainWindow::invertSelection()
896 m_activeViewContainer
->view()->invertSelection();
899 void DolphinMainWindow::toggleSplitView()
901 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
902 tabPage
->setSplitViewEnabled(!tabPage
->splitViewEnabled(), WithAnimation
);
907 void DolphinMainWindow::toggleSplitStash()
909 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
910 tabPage
->setSplitViewEnabled(false, WithAnimation
);
911 tabPage
->setSplitViewEnabled(true, WithAnimation
, QUrl("stash:/"));
914 void DolphinMainWindow::copyToInactiveSplitView()
916 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
917 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CopyToOtherViewContents
);
919 m_tabWidget
->copyToInactiveSplitView();
920 m_activeViewContainer
->setSelectionModeEnabled(false);
924 void DolphinMainWindow::moveToInactiveSplitView()
926 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
927 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::MoveToOtherViewContents
);
929 m_tabWidget
->moveToInactiveSplitView();
930 m_activeViewContainer
->setSelectionModeEnabled(false);
934 void DolphinMainWindow::reloadView()
937 m_activeViewContainer
->reload();
938 m_activeViewContainer
->statusBar()->updateSpaceInfo();
941 void DolphinMainWindow::stopLoading()
943 m_activeViewContainer
->view()->stopLoading();
946 void DolphinMainWindow::enableStopAction()
948 actionCollection()->action(QStringLiteral("stop"))->setEnabled(true);
951 void DolphinMainWindow::disableStopAction()
953 actionCollection()->action(QStringLiteral("stop"))->setEnabled(false);
956 void DolphinMainWindow::toggleSelectionMode()
958 const bool checked
= !m_activeViewContainer
->isSelectionModeEnabled();
960 m_activeViewContainer
->setSelectionModeEnabled(checked
, actionCollection(), SelectionMode::BottomBar::Contents::GeneralContents
);
961 actionCollection()->action(QStringLiteral("toggle_selection_mode"))->setChecked(checked
);
964 void DolphinMainWindow::showFilterBar()
966 m_activeViewContainer
->setFilterBarVisible(true);
969 void DolphinMainWindow::toggleFilterBar()
971 const bool checked
= !m_activeViewContainer
->isFilterBarVisible();
972 m_activeViewContainer
->setFilterBarVisible(checked
);
974 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
975 toggleFilterBarAction
->setChecked(checked
);
978 void DolphinMainWindow::toggleEditLocation()
982 QAction
*action
= actionCollection()->action(QStringLiteral("editable_location"));
983 KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigator();
984 urlNavigator
->setUrlEditable(action
->isChecked());
987 void DolphinMainWindow::replaceLocation()
989 KUrlNavigator
*navigator
= m_activeViewContainer
->urlNavigator();
990 QLineEdit
*lineEdit
= navigator
->editor()->lineEdit();
992 // If the text field currently has focus and everything is selected,
993 // pressing the keyboard shortcut returns the whole thing to breadcrumb mode
994 if (navigator
->isUrlEditable() && lineEdit
->hasFocus() && lineEdit
->selectedText() == lineEdit
->text()) {
995 navigator
->setUrlEditable(false);
997 navigator
->setUrlEditable(true);
998 navigator
->setFocus();
999 lineEdit
->selectAll();
1003 void DolphinMainWindow::togglePanelLockState()
1005 const bool newLockState
= !GeneralSettings::lockPanels();
1006 const auto childrenObjects
= children();
1007 for (QObject
*child
: childrenObjects
) {
1008 DolphinDockWidget
*dock
= qobject_cast
<DolphinDockWidget
*>(child
);
1010 dock
->setLocked(newLockState
);
1014 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(newLockState
);
1016 GeneralSettings::setLockPanels(newLockState
);
1019 void DolphinMainWindow::slotTerminalPanelVisibilityChanged()
1021 if (m_terminalPanel
->isHiddenInVisibleWindow() && m_activeViewContainer
) {
1022 m_activeViewContainer
->view()->setFocus();
1026 void DolphinMainWindow::goBack()
1028 DolphinUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
1029 urlNavigator
->goBack();
1031 if (urlNavigator
->locationState().isEmpty()) {
1032 // An empty location state indicates a redirection URL,
1033 // which must be skipped too
1034 urlNavigator
->goBack();
1038 void DolphinMainWindow::goForward()
1040 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goForward();
1043 void DolphinMainWindow::goUp()
1045 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goUp();
1048 void DolphinMainWindow::goHome()
1050 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goHome();
1053 void DolphinMainWindow::goBackInNewTab()
1055 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
1056 const int index
= urlNavigator
->historyIndex() + 1;
1057 openNewTab(urlNavigator
->locationUrl(index
));
1060 void DolphinMainWindow::goForwardInNewTab()
1062 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
1063 const int index
= urlNavigator
->historyIndex() - 1;
1064 openNewTab(urlNavigator
->locationUrl(index
));
1067 void DolphinMainWindow::goUpInNewTab()
1069 const QUrl currentUrl
= activeViewContainer()->urlNavigator()->locationUrl();
1070 openNewTab(KIO::upUrl(currentUrl
));
1073 void DolphinMainWindow::goHomeInNewTab()
1075 openNewTab(Dolphin::homeUrl());
1078 void DolphinMainWindow::compareFiles()
1080 const KFileItemList items
= m_tabWidget
->currentTabPage()->selectedItems();
1081 if (items
.count() != 2) {
1082 // The action is disabled in this case, but it could have been triggered
1083 // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
1087 QUrl urlA
= items
.at(0).url();
1088 QUrl urlB
= items
.at(1).url();
1090 QString
command(QStringLiteral("kompare -c \""));
1091 command
.append(urlA
.toDisplayString(QUrl::PreferLocalFile
));
1092 command
.append("\" \"");
1093 command
.append(urlB
.toDisplayString(QUrl::PreferLocalFile
));
1094 command
.append('\"');
1096 KIO::CommandLauncherJob
*job
= new KIO::CommandLauncherJob(command
, this);
1097 job
->setDesktopName(QStringLiteral("org.kde.kompare"));
1101 void DolphinMainWindow::toggleShowMenuBar()
1103 const bool visible
= menuBar()->isVisible();
1104 menuBar()->setVisible(!visible
);
1107 QPointer
<QAction
> DolphinMainWindow::preferredSearchTool()
1109 m_searchTools
.clear();
1110 KMoreToolsMenuFactory("dolphin/search-tools").fillMenuFromGroupingNames(&m_searchTools
, {"files-find"}, m_activeViewContainer
->url());
1111 QList
<QAction
*> actions
= m_searchTools
.actions();
1112 if (actions
.isEmpty()) {
1115 QAction
*action
= actions
.first();
1116 if (action
->isSeparator()) {
1122 void DolphinMainWindow::updateOpenPreferredSearchToolAction()
1124 QAction
*openPreferredSearchTool
= actionCollection()->action(QStringLiteral("open_preferred_search_tool"));
1125 if (!openPreferredSearchTool
) {
1128 QPointer
<QAction
> tool
= preferredSearchTool();
1130 openPreferredSearchTool
->setVisible(true);
1131 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open %1", tool
->text()));
1132 // Only override with the app icon if it is the default, i.e. the user hasn't configured one manually
1133 // https://bugs.kde.org/show_bug.cgi?id=442815
1134 if (openPreferredSearchTool
->icon().name() == QLatin1String("search")) {
1135 openPreferredSearchTool
->setIcon(tool
->icon());
1138 openPreferredSearchTool
->setVisible(false);
1139 // still visible in Shortcuts configuration window
1140 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1141 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1145 void DolphinMainWindow::openPreferredSearchTool()
1147 QPointer
<QAction
> tool
= preferredSearchTool();
1153 void DolphinMainWindow::openTerminal()
1155 openTerminalJob(m_activeViewContainer
->url());
1158 void DolphinMainWindow::openTerminalHere()
1160 QList
<QUrl
> urls
= {};
1162 for (const KFileItem
&item
: m_activeViewContainer
->view()->selectedItems()) {
1163 QUrl url
= item
.targetUrl();
1164 if (item
.isFile()) {
1165 url
.setPath(QFileInfo(url
.path()).absolutePath());
1167 if (!urls
.contains(url
)) {
1172 // No items are selected. Open a terminal window for the current location.
1173 if (urls
.count() == 0) {
1178 if (urls
.count() > 5) {
1179 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());
1180 #if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
1181 const int answer
= KMessageBox::warningTwoActions(
1186 const int answer
= KMessageBox::warningYesNo(
1191 KGuiItem(i18ncp("@action:button", "Open %1 Terminal", "Open %1 Terminals", urls
.count()), QStringLiteral("utilities-terminal")),
1192 KStandardGuiItem::cancel());
1193 #if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
1194 if (answer
!= KMessageBox::PrimaryAction
) {
1196 if (answer
!= KMessageBox::Yes
) {
1202 for (const QUrl
&url
: urls
) {
1203 openTerminalJob(url
);
1207 void DolphinMainWindow::openTerminalJob(const QUrl
&url
)
1209 if (url
.isLocalFile()) {
1210 auto job
= new KTerminalLauncherJob(QString());
1211 job
->setWorkingDirectory(url
.toLocalFile());
1216 // Not a local file, with protocol Class ":local", try stat'ing
1217 if (KProtocolInfo::protocolClass(url
.scheme()) == QLatin1String(":local")) {
1218 KIO::StatJob
*job
= KIO::mostLocalUrl(url
);
1219 KJobWidgets::setWindow(job
, this);
1220 connect(job
, &KJob::result
, this, [job
]() {
1222 if (!job
->error()) {
1223 statUrl
= job
->mostLocalUrl();
1226 auto job
= new KTerminalLauncherJob(QString());
1227 job
->setWorkingDirectory(statUrl
.isLocalFile() ? statUrl
.toLocalFile() : QDir::homePath());
1234 // Nothing worked, just use $HOME
1235 auto job
= new KTerminalLauncherJob(QString());
1236 job
->setWorkingDirectory(QDir::homePath());
1240 void DolphinMainWindow::editSettings()
1242 if (!m_settingsDialog
) {
1243 DolphinViewContainer
*container
= activeViewContainer();
1244 container
->view()->writeSettings();
1246 const QUrl url
= container
->url();
1247 DolphinSettingsDialog
*settingsDialog
= new DolphinSettingsDialog(url
, this, actionCollection());
1248 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, this, &DolphinMainWindow::refreshViews
);
1249 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, &DolphinUrlNavigatorsController::slotReadSettings
);
1250 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1251 settingsDialog
->show();
1252 m_settingsDialog
= settingsDialog
;
1254 m_settingsDialog
.data()->raise();
1258 void DolphinMainWindow::handleUrl(const QUrl
&url
)
1260 delete m_lastHandleUrlOpenJob
;
1261 m_lastHandleUrlOpenJob
= nullptr;
1263 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1264 activeViewContainer()->setUrl(url
);
1266 m_lastHandleUrlOpenJob
= new KIO::OpenUrlJob(url
);
1267 #if KIO_VERSION >= QT_VERSION_CHECK(5, 98, 0)
1268 m_lastHandleUrlOpenJob
->setUiDelegate(KIO::createDefaultJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
1270 m_lastHandleUrlOpenJob
->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
1272 m_lastHandleUrlOpenJob
->setShowOpenOrExecuteDialog(true);
1274 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::mimeTypeFound
, this, [this, url
](const QString
&mimetype
) {
1275 if (mimetype
== QLatin1String("inode/directory")) {
1276 // If it's a dir, we'll take it from here
1277 m_lastHandleUrlOpenJob
->kill();
1278 m_lastHandleUrlOpenJob
= nullptr;
1279 activeViewContainer()->setUrl(url
);
1283 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::result
, this, [this]() {
1284 m_lastHandleUrlOpenJob
= nullptr;
1287 m_lastHandleUrlOpenJob
->start();
1291 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1293 // trash:/ is writable but we don't want to create new items in it.
1294 // TODO: remove the trash check once https://phabricator.kde.org/T8234 is implemented
1295 newFileMenu()->setEnabled(isFolderWritable
&& m_activeViewContainer
->url().scheme() != QLatin1String("trash"));
1298 void DolphinMainWindow::openContextMenu(const QPoint
&pos
, const KFileItem
&item
, const KFileItemList
&selectedItems
, const QUrl
&url
)
1300 QPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, item
, selectedItems
, url
, &m_fileItemActions
);
1301 contextMenu
.data()->exec(pos
);
1303 // Delete the menu, unless it has been deleted in its own nested event loop already.
1305 contextMenu
->deleteLater();
1309 QMenu
*DolphinMainWindow::createPopupMenu()
1311 QMenu
*menu
= KXmlGuiWindow::createPopupMenu();
1313 menu
->addSeparator();
1314 menu
->addAction(actionCollection()->action(QStringLiteral("lock_panels")));
1319 void DolphinMainWindow::updateHamburgerMenu()
1321 KActionCollection
*ac
= actionCollection();
1322 auto hamburgerMenu
= static_cast<KHamburgerMenu
*>(ac
->action(KStandardAction::name(KStandardAction::HamburgerMenu
)));
1323 auto menu
= hamburgerMenu
->menu();
1325 menu
= new QMenu(this);
1326 hamburgerMenu
->setMenu(menu
);
1327 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("basic_actions"))->menu());
1328 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("zoom"))->menu());
1332 const QList
<QAction
*> toolbarActions
= toolBar()->actions();
1334 if (!toolBar()->isVisible()) {
1335 // If neither the menu bar nor the toolbar are visible, these actions should be available.
1336 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)));
1337 menu
->addAction(toolBarMenuAction());
1338 menu
->addSeparator();
1341 // This group of actions (until the next separator) contains all the most basic actions
1342 // necessary to use Dolphin effectively.
1343 menu
->addAction(ac
->action(QStringLiteral("go_back")));
1344 menu
->addAction(ac
->action(QStringLiteral("go_forward")));
1346 menu
->addMenu(m_newFileMenu
->menu());
1347 if (!toolBar()->isVisible() || !toolbarActions
.contains(ac
->action(QStringLiteral("toggle_selection_mode_tool_bar")))) {
1348 menu
->addAction(ac
->action(QStringLiteral("toggle_selection_mode")));
1350 menu
->addAction(ac
->action(QStringLiteral("basic_actions")));
1351 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Undo
)));
1352 if (!toolBar()->isVisible()
1353 || (!toolbarActions
.contains(ac
->action(QStringLiteral("toggle_search")))
1354 && !toolbarActions
.contains(ac
->action(QStringLiteral("open_preferred_search_tool"))))) {
1355 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Find
)));
1356 // This way a search action will only be added if none of the three available
1357 // search actions is present on the toolbar.
1359 if (!toolBar()->isVisible() || !toolbarActions
.contains(ac
->action(QStringLiteral("toggle_filter")))) {
1360 menu
->addAction(ac
->action(QStringLiteral("show_filter_bar")));
1361 // This way a filter action will only be added if none of the two available
1362 // filter actions is present on the toolbar.
1364 menu
->addSeparator();
1366 // The second group of actions (up until the next separator) contains actions for opening
1367 // additional views to interact with the file system.
1368 menu
->addAction(ac
->action(QStringLiteral("file_new")));
1369 menu
->addAction(ac
->action(QStringLiteral("new_tab")));
1370 if (ac
->action(QStringLiteral("undo_close_tab"))->isEnabled()) {
1371 menu
->addAction(ac
->action(QStringLiteral("closed_tabs")));
1373 menu
->addAction(ac
->action(QStringLiteral("open_terminal")));
1374 menu
->addSeparator();
1376 // The third group contains actions to change what one sees in the view
1377 // and to change the more general UI.
1378 if (!toolBar()->isVisible()
1379 || (!toolbarActions
.contains(ac
->action(QStringLiteral("icons"))) && !toolbarActions
.contains(ac
->action(QStringLiteral("compact")))
1380 && !toolbarActions
.contains(ac
->action(QStringLiteral("details"))) && !toolbarActions
.contains(ac
->action(QStringLiteral("view_mode"))))) {
1381 menu
->addAction(ac
->action(QStringLiteral("view_mode")));
1383 menu
->addAction(ac
->action(QStringLiteral("show_hidden_files")));
1384 menu
->addAction(ac
->action(QStringLiteral("sort")));
1385 menu
->addAction(ac
->action(QStringLiteral("additional_info")));
1386 if (!GeneralSettings::showStatusBar() || !GeneralSettings::showZoomSlider()) {
1387 menu
->addAction(ac
->action(QStringLiteral("zoom")));
1389 menu
->addAction(ac
->action(QStringLiteral("panels")));
1391 // The "Configure" menu is not added to the actionCollection() because there is hardly
1392 // a good reason for users to put it on their toolbar.
1393 auto configureMenu
= menu
->addMenu(QIcon::fromTheme(QStringLiteral("configure")), i18nc("@action:inmenu menu for configure actions", "Configure"));
1394 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
)));
1395 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)));
1396 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)));
1397 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Preferences
)));
1398 hamburgerMenu
->hideActionsOf(configureMenu
);
1401 void DolphinMainWindow::slotPlaceActivated(const QUrl
&url
)
1403 DolphinViewContainer
*view
= activeViewContainer();
1405 if (view
->url() == url
) {
1406 view
->clearFilterBar(); // Fixes bug 259382.
1408 // We can end up here if the user clicked a device in the Places Panel
1409 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
1412 view
->disableUrlNavigatorSelectionRequests();
1414 view
->enableUrlNavigatorSelectionRequests();
1418 void DolphinMainWindow::closedTabsCountChanged(unsigned int count
)
1420 actionCollection()->action(QStringLiteral("undo_close_tab"))->setEnabled(count
> 0);
1423 void DolphinMainWindow::activeViewChanged(DolphinViewContainer
*viewContainer
)
1425 DolphinViewContainer
*oldViewContainer
= m_activeViewContainer
;
1426 Q_ASSERT(viewContainer
);
1428 m_activeViewContainer
= viewContainer
;
1430 if (oldViewContainer
) {
1431 const QAction
*toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
1432 toggleSearchAction
->disconnect(oldViewContainer
);
1434 // Disconnect all signals between the old view container (container,
1435 // view and url navigator) and main window.
1436 oldViewContainer
->disconnect(this);
1437 oldViewContainer
->view()->disconnect(this);
1438 oldViewContainer
->urlNavigatorInternalWithHistory()->disconnect(this);
1439 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
1440 navigators
->primaryUrlNavigator()->disconnect(this);
1441 if (auto secondaryUrlNavigator
= navigators
->secondaryUrlNavigator()) {
1442 secondaryUrlNavigator
->disconnect(this);
1445 // except the requestItemInfo so that on hover the information panel can still be updated
1446 connect(oldViewContainer
->view(), &DolphinView::requestItemInfo
, this, &DolphinMainWindow::requestItemInfo
);
1448 // Disconnect other slots.
1449 disconnect(oldViewContainer
,
1450 &DolphinViewContainer::selectionModeChanged
,
1451 actionCollection()->action(QStringLiteral("toggle_selection_mode")),
1452 &QAction::setChecked
);
1455 connectViewSignals(viewContainer
);
1457 m_actionHandler
->setCurrentView(viewContainer
->view());
1460 updateFileAndEditActions();
1461 updatePasteAction();
1462 updateViewActions();
1464 updateSearchAction();
1466 const QUrl url
= viewContainer
->url();
1467 Q_EMIT
urlChanged(url
);
1470 void DolphinMainWindow::tabCountChanged(int count
)
1472 const bool enableTabActions
= (count
> 1);
1473 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1474 actionCollection()->action(QStringLiteral("activate_tab_%1").arg(i
))->setEnabled(enableTabActions
);
1476 actionCollection()->action(QStringLiteral("activate_last_tab"))->setEnabled(enableTabActions
);
1477 actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions
);
1478 actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions
);
1481 void DolphinMainWindow::updateWindowTitle()
1483 const QString newTitle
= m_activeViewContainer
->captionWindowTitle();
1484 if (windowTitle() != newTitle
) {
1485 setWindowTitle(newTitle
);
1489 void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString
&mountPath
)
1491 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1492 setViewsToHomeIfMountPathOpen(mountPath
);
1495 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectoryIsChildOf(mountPath
)) {
1496 m_tearDownFromPlacesRequested
= true;
1497 m_terminalPanel
->goHome();
1498 // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged
1500 m_placesPanel
->proceedWithTearDown();
1504 void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString
&mountPath
)
1506 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1507 setViewsToHomeIfMountPathOpen(mountPath
);
1510 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectoryIsChildOf(mountPath
)) {
1511 m_tearDownFromPlacesRequested
= false;
1512 m_terminalPanel
->goHome();
1516 void DolphinMainWindow::slotKeyBindings()
1518 KShortcutsDialog
dialog(KShortcutsEditor::AllActions
, KShortcutsEditor::LetterShortcutsAllowed
, this);
1519 dialog
.addCollection(actionCollection());
1520 if (m_terminalPanel
) {
1521 KActionCollection
*konsolePartActionCollection
= m_terminalPanel
->actionCollection();
1522 if (konsolePartActionCollection
) {
1523 dialog
.addCollection(konsolePartActionCollection
, QStringLiteral("KonsolePart"));
1529 void DolphinMainWindow::setViewsToHomeIfMountPathOpen(const QString
&mountPath
)
1531 const QVector
<DolphinViewContainer
*> theViewContainers
= viewContainers();
1532 for (DolphinViewContainer
*viewContainer
: theViewContainers
) {
1533 if (viewContainer
&& viewContainer
->url().toLocalFile().startsWith(mountPath
)) {
1534 viewContainer
->setUrl(QUrl::fromLocalFile(QDir::homePath()));
1537 disconnect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, nullptr, nullptr);
1540 void DolphinMainWindow::setupActions()
1542 auto hamburgerMenuAction
= KStandardAction::hamburgerMenu(nullptr, nullptr, actionCollection());
1544 // setup 'File' menu
1545 m_newFileMenu
= new DolphinNewFileMenu(actionCollection(), this);
1546 QMenu
*menu
= m_newFileMenu
->menu();
1547 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1548 menu
->setIcon(QIcon::fromTheme(QStringLiteral("list-add")));
1549 m_newFileMenu
->setPopupMode(QToolButton::InstantPopup
);
1550 connect(menu
, &QMenu::aboutToShow
, this, &DolphinMainWindow::updateNewMenu
);
1552 QAction
*newWindow
= KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow
, actionCollection());
1553 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1554 newWindow
->setToolTip(i18nc("@info", "Open a new Dolphin window"));
1555 newWindow
->setWhatsThis(xi18nc("@info:whatsthis",
1557 "window just like this one with the current location and view."
1558 "<nl/>You can drag and drop items between windows."));
1559 newWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1561 QAction
*newTab
= actionCollection()->addAction(QStringLiteral("new_tab"));
1562 newTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1563 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1564 newTab
->setWhatsThis(xi18nc("@info:whatsthis",
1566 "<emphasis>Tab</emphasis> with the current location and view.<nl/>"
1567 "A tab is an additional view within this window. "
1568 "You can drag and drop items between tabs."));
1569 actionCollection()->setDefaultShortcuts(newTab
, {Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
});
1570 connect(newTab
, &QAction::triggered
, this, &DolphinMainWindow::openNewActivatedTab
);
1572 QAction
*addToPlaces
= actionCollection()->addAction(QStringLiteral("add_to_places"));
1573 addToPlaces
->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new")));
1574 addToPlaces
->setText(i18nc("@action:inmenu Add current folder to places", "Add to Places"));
1575 addToPlaces
->setWhatsThis(xi18nc("@info:whatsthis",
1576 "This adds the selected folder "
1577 "to the Places panel."));
1578 connect(addToPlaces
, &QAction::triggered
, this, &DolphinMainWindow::addToPlaces
);
1580 QAction
*closeTab
= KStandardAction::close(m_tabWidget
, QOverload
<>::of(&DolphinTabWidget::closeTab
), actionCollection());
1581 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1582 closeTab
->setWhatsThis(i18nc("@info:whatsthis",
1584 "currently viewed tab. If no more tabs are left this window "
1585 "will close instead."));
1587 QAction
*quitAction
= KStandardAction::quit(this, &DolphinMainWindow::quit
, actionCollection());
1588 quitAction
->setWhatsThis(i18nc("@info:whatsthis quit", "This closes this window."));
1590 // setup 'Edit' menu
1591 KStandardAction::undo(this, &DolphinMainWindow::undo
, actionCollection());
1593 // i18n: This will be the last paragraph for the whatsthis for all three:
1594 // Cut, Copy and Paste
1595 const QString cutCopyPastePara
= xi18nc("@info:whatsthis",
1596 "<para><emphasis>Cut, "
1597 "Copy</emphasis> and <emphasis>Paste</emphasis> work between many "
1598 "applications and are among the most used commands. That's why their "
1599 "<emphasis>keyboard shortcuts</emphasis> are prominently placed right "
1600 "next to each other on the keyboard: <shortcut>Ctrl+X</shortcut>, "
1601 "<shortcut>Ctrl+C</shortcut> and <shortcut>Ctrl+V</shortcut>.</para>");
1602 QAction
*cutAction
= KStandardAction::cut(this, &DolphinMainWindow::cut
, actionCollection());
1603 m_actionTextHelper
->registerTextWhenNothingIsSelected(cutAction
, i18nc("@action", "Cut…"));
1604 cutAction
->setWhatsThis(xi18nc("@info:whatsthis cut",
1605 "This copies the items "
1606 "in your current selection to the <emphasis>clipboard</emphasis>.<nl/>"
1607 "Use the <emphasis>Paste</emphasis> action afterwards to copy them from "
1608 "the clipboard to a new location. The items will be removed from their "
1609 "initial location.")
1610 + cutCopyPastePara
);
1611 QAction
*copyAction
= KStandardAction::copy(this, &DolphinMainWindow::copy
, actionCollection());
1612 m_actionTextHelper
->registerTextWhenNothingIsSelected(copyAction
, i18nc("@action", "Copy…"));
1613 copyAction
->setWhatsThis(xi18nc("@info:whatsthis copy",
1615 "items in your current selection to the <emphasis>clipboard</emphasis>."
1616 "<nl/>Use the <emphasis>Paste</emphasis> action afterwards to copy them "
1617 "from the clipboard to a new location.")
1618 + cutCopyPastePara
);
1619 QAction
*paste
= KStandardAction::paste(this, &DolphinMainWindow::paste
, actionCollection());
1620 // The text of the paste-action is modified dynamically by Dolphin
1621 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1622 // due to the long text, the text "Paste" is used:
1623 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1624 paste
->setWhatsThis(xi18nc("@info:whatsthis paste",
1625 "This copies the items from "
1626 "your <emphasis>clipboard</emphasis> to the currently viewed folder.<nl/>"
1627 "If the items were added to the clipboard by the <emphasis>Cut</emphasis> "
1628 "action they are removed from their old location.")
1629 + cutCopyPastePara
);
1631 QAction
*copyToOtherViewAction
= actionCollection()->addAction(QStringLiteral("copy_to_inactive_split_view"));
1632 copyToOtherViewAction
->setText(i18nc("@action:inmenu", "Copy to Other View"));
1633 m_actionTextHelper
->registerTextWhenNothingIsSelected(copyToOtherViewAction
, i18nc("@action:inmenu", "Copy to Other View…"));
1634 copyToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Copy",
1635 "This copies the selected items from "
1636 "the <emphasis>active</emphasis> view to the inactive split view."));
1637 copyToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
1638 copyToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Copy to Inactive Split View"));
1639 actionCollection()->setDefaultShortcut(copyToOtherViewAction
, Qt::SHIFT
| Qt::Key_F5
);
1640 connect(copyToOtherViewAction
, &QAction::triggered
, this, &DolphinMainWindow::copyToInactiveSplitView
);
1642 QAction
*moveToOtherViewAction
= actionCollection()->addAction(QStringLiteral("move_to_inactive_split_view"));
1643 moveToOtherViewAction
->setText(i18nc("@action:inmenu", "Move to Other View"));
1644 m_actionTextHelper
->registerTextWhenNothingIsSelected(moveToOtherViewAction
, i18nc("@action:inmenu", "Move to Other View…"));
1645 moveToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Move",
1646 "This moves the selected items from "
1647 "the <emphasis>active</emphasis> view to the inactive split view."));
1648 moveToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-cut")));
1649 moveToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Move to Inactive Split View"));
1650 actionCollection()->setDefaultShortcut(moveToOtherViewAction
, Qt::SHIFT
| Qt::Key_F6
);
1651 connect(moveToOtherViewAction
, &QAction::triggered
, this, &DolphinMainWindow::moveToInactiveSplitView
);
1653 QAction
*showFilterBar
= actionCollection()->addAction(QStringLiteral("show_filter_bar"));
1654 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Filter…"));
1655 showFilterBar
->setToolTip(i18nc("@info:tooltip", "Show Filter Bar"));
1656 showFilterBar
->setWhatsThis(xi18nc("@info:whatsthis",
1658 "<emphasis>Filter Bar</emphasis> at the bottom of the window.<nl/> "
1659 "There you can enter a text to filter the files and folders currently displayed. "
1660 "Only those that contain the text in their name will be kept in view."));
1661 showFilterBar
->setIcon(QIcon::fromTheme(QStringLiteral("view-filter")));
1662 actionCollection()->setDefaultShortcuts(showFilterBar
, {Qt::CTRL
| Qt::Key_I
, Qt::Key_Slash
});
1663 connect(showFilterBar
, &QAction::triggered
, this, &DolphinMainWindow::showFilterBar
);
1665 // toggle_filter acts as a copy of the main showFilterBar to be used mainly
1666 // in the toolbar, with no default shortcut attached, to avoid messing with
1667 // existing workflows (filter bar always open and Ctrl-I to focus)
1668 QAction
*toggleFilter
= actionCollection()->addAction(QStringLiteral("toggle_filter"));
1669 toggleFilter
->setText(i18nc("@action:inmenu", "Toggle Filter Bar"));
1670 toggleFilter
->setIconText(i18nc("@action:intoolbar", "Filter"));
1671 toggleFilter
->setIcon(showFilterBar
->icon());
1672 toggleFilter
->setToolTip(showFilterBar
->toolTip());
1673 toggleFilter
->setWhatsThis(showFilterBar
->whatsThis());
1674 toggleFilter
->setCheckable(true);
1675 connect(toggleFilter
, &QAction::triggered
, this, &DolphinMainWindow::toggleFilterBar
);
1677 QAction
*searchAction
= KStandardAction::find(this, &DolphinMainWindow::find
, actionCollection());
1678 searchAction
->setText(i18n("Search…"));
1679 searchAction
->setToolTip(i18nc("@info:tooltip", "Search for files and folders"));
1680 searchAction
->setWhatsThis(xi18nc("@info:whatsthis find",
1681 "<para>This helps you "
1682 "find files and folders by opening a <emphasis>find bar</emphasis>. "
1683 "There you can enter search terms and specify settings to find the "
1684 "objects you are looking for.</para><para>Use this help again on "
1685 "the find bar so we can have a look at it while the settings are "
1686 "explained.</para>"));
1688 // toggle_search acts as a copy of the main searchAction to be used mainly
1689 // in the toolbar, with no default shortcut attached, to avoid messing with
1690 // existing workflows (search bar always open and Ctrl-F to focus)
1691 QAction
*toggleSearchAction
= actionCollection()->addAction(QStringLiteral("toggle_search"));
1692 toggleSearchAction
->setText(i18nc("@action:inmenu", "Toggle Search Bar"));
1693 toggleSearchAction
->setIconText(i18nc("@action:intoolbar", "Search"));
1694 toggleSearchAction
->setIcon(searchAction
->icon());
1695 toggleSearchAction
->setToolTip(searchAction
->toolTip());
1696 toggleSearchAction
->setWhatsThis(searchAction
->whatsThis());
1697 toggleSearchAction
->setCheckable(true);
1699 QAction
*toggleSelectionModeAction
= actionCollection()->addAction(QStringLiteral("toggle_selection_mode"));
1700 // i18n: This action toggles a selection mode.
1701 toggleSelectionModeAction
->setText(i18nc("@action:inmenu", "Select Files and Folders"));
1702 // i18n: Opens a selection mode for selecting files/folders.
1703 // The text is kept so unspecific because it will be shown on the toolbar where space is at a premium.
1704 toggleSelectionModeAction
->setIconText(i18nc("@action:intoolbar", "Select"));
1705 toggleSelectionModeAction
->setWhatsThis(xi18nc(
1707 "<para>This application only knows which files or folders should be acted on if they are"
1708 " <emphasis>selected</emphasis> first. Press this to toggle a <emphasis>Selection Mode</emphasis> which makes selecting and deselecting as easy as "
1709 "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."
1711 toggleSelectionModeAction
->setIcon(QIcon::fromTheme(QStringLiteral("quickwizard")));
1712 toggleSelectionModeAction
->setCheckable(true);
1713 actionCollection()->setDefaultShortcut(toggleSelectionModeAction
, Qt::Key_Space
);
1714 connect(toggleSelectionModeAction
, &QAction::triggered
, this, &DolphinMainWindow::toggleSelectionMode
);
1716 // A special version of the toggleSelectionModeAction for the toolbar that also contains a menu
1717 // with the selectAllAction and invertSelectionAction.
1718 auto *toggleSelectionModeToolBarAction
=
1719 new KToolBarPopupAction(toggleSelectionModeAction
->icon(), toggleSelectionModeAction
->iconText(), actionCollection());
1720 toggleSelectionModeToolBarAction
->setToolTip(toggleSelectionModeAction
->text());
1721 toggleSelectionModeToolBarAction
->setWhatsThis(toggleSelectionModeAction
->whatsThis());
1722 actionCollection()->addAction(QStringLiteral("toggle_selection_mode_tool_bar"), toggleSelectionModeToolBarAction
);
1723 toggleSelectionModeToolBarAction
->setCheckable(true);
1724 toggleSelectionModeToolBarAction
->setPopupMode(QToolButton::DelayedPopup
);
1725 connect(toggleSelectionModeToolBarAction
, &QAction::triggered
, toggleSelectionModeAction
, &QAction::trigger
);
1726 connect(toggleSelectionModeAction
, &QAction::toggled
, toggleSelectionModeToolBarAction
, &QAction::setChecked
);
1728 QAction
*selectAllAction
= KStandardAction::selectAll(this, &DolphinMainWindow::selectAll
, actionCollection());
1729 selectAllAction
->setWhatsThis(xi18nc("@info:whatsthis",
1731 "files and folders in the current location."));
1733 QAction
*invertSelection
= actionCollection()->addAction(QStringLiteral("invert_selection"));
1734 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1735 invertSelection
->setWhatsThis(xi18nc("@info:whatsthis invert",
1737 "objects that you have currently <emphasis>not</emphasis> selected instead."));
1738 invertSelection
->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-invert")));
1739 actionCollection()->setDefaultShortcut(invertSelection
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1740 connect(invertSelection
, &QAction::triggered
, this, &DolphinMainWindow::invertSelection
);
1742 QMenu
*toggleSelectionModeActionMenu
= new QMenu(this);
1743 toggleSelectionModeActionMenu
->addAction(selectAllAction
);
1744 toggleSelectionModeActionMenu
->addAction(invertSelection
);
1745 toggleSelectionModeToolBarAction
->setMenu(toggleSelectionModeActionMenu
);
1747 // setup 'View' menu
1748 // (note that most of it is set up in DolphinViewActionHandler)
1750 QAction
*split
= actionCollection()->addAction(QStringLiteral("split_view"));
1751 split
->setWhatsThis(xi18nc("@info:whatsthis find",
1752 "<para>This splits "
1753 "the folder view below into two autonomous views.</para><para>This "
1754 "way you can see two locations at once and move items between them "
1755 "quickly.</para>Click this again afterwards to recombine the views."));
1756 actionCollection()->setDefaultShortcut(split
, Qt::Key_F3
);
1757 connect(split
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitView
);
1759 QAction
*stashSplit
= actionCollection()->addAction(QStringLiteral("split_stash"));
1760 actionCollection()->setDefaultShortcut(stashSplit
, Qt::CTRL
| Qt::Key_S
);
1761 stashSplit
->setText(i18nc("@action:intoolbar Stash", "Stash"));
1762 stashSplit
->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
1763 stashSplit
->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
1764 stashSplit
->setCheckable(false);
1765 QDBusConnectionInterface
*sessionInterface
= QDBusConnection::sessionBus().interface();
1766 stashSplit
->setVisible(sessionInterface
&& sessionInterface
->isServiceRegistered(QStringLiteral("org.kde.kio.StashNotifier")));
1767 connect(stashSplit
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitStash
);
1769 QAction
*redisplay
= KStandardAction::redisplay(this, &DolphinMainWindow::reloadView
, actionCollection());
1770 redisplay
->setToolTip(i18nc("@info:tooltip", "Refresh view"));
1771 redisplay
->setWhatsThis(xi18nc("@info:whatsthis refresh",
1772 "<para>This refreshes "
1773 "the folder view.</para>"
1774 "<para>If the contents of this folder have changed, refreshing will re-scan this folder "
1775 "and show you a newly-updated view of the files and folders contained here.</para>"
1776 "<para>If the view is split, this refreshes the one that is currently in focus.</para>"));
1778 QAction
*stop
= actionCollection()->addAction(QStringLiteral("stop"));
1779 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1780 stop
->setToolTip(i18nc("@info", "Stop loading"));
1781 stop
->setWhatsThis(i18nc("@info", "This stops the loading of the contents of the current folder."));
1782 stop
->setIcon(QIcon::fromTheme(QStringLiteral("process-stop")));
1783 connect(stop
, &QAction::triggered
, this, &DolphinMainWindow::stopLoading
);
1785 KToggleAction
*editableLocation
= actionCollection()->add
<KToggleAction
>(QStringLiteral("editable_location"));
1786 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1787 editableLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1788 "This toggles the <emphasis>Location Bar</emphasis> to be "
1789 "editable so you can directly enter a location you want to go to.<nl/>"
1790 "You can also switch to editing by clicking to the right of the "
1791 "location and switch back by confirming the edited location."));
1792 actionCollection()->setDefaultShortcut(editableLocation
, Qt::Key_F6
);
1793 connect(editableLocation
, &KToggleAction::triggered
, this, &DolphinMainWindow::toggleEditLocation
);
1795 QAction
*replaceLocation
= actionCollection()->addAction(QStringLiteral("replace_location"));
1796 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1797 // i18n: "enter" is used both in the meaning of "writing" and "going to" a new location here.
1798 // Both meanings are useful but not necessary to understand the use of "Replace Location".
1799 // So you might want to be more verbose in your language to convey the meaning but it's up to you.
1800 replaceLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1801 "This switches to editing the location and selects it "
1802 "so you can quickly enter a different location."));
1803 actionCollection()->setDefaultShortcut(replaceLocation
, Qt::CTRL
| Qt::Key_L
);
1804 connect(replaceLocation
, &QAction::triggered
, this, &DolphinMainWindow::replaceLocation
);
1808 QScopedPointer
<QAction
> backAction(KStandardAction::back(nullptr, nullptr, nullptr));
1809 m_backAction
= new KToolBarPopupAction(backAction
->icon(), backAction
->text(), actionCollection());
1810 m_backAction
->setObjectName(backAction
->objectName());
1811 m_backAction
->setShortcuts(backAction
->shortcuts());
1813 m_backAction
->setPopupMode(QToolButton::DelayedPopup
);
1814 connect(m_backAction
, &QAction::triggered
, this, &DolphinMainWindow::goBack
);
1815 connect(m_backAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowBackPopupMenu
);
1816 connect(m_backAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoBack
);
1817 actionCollection()->addAction(m_backAction
->objectName(), m_backAction
);
1819 auto backShortcuts
= m_backAction
->shortcuts();
1820 // Prepend this shortcut, to avoid being hidden by the two-slot UI (#371130)
1821 backShortcuts
.prepend(QKeySequence(Qt::Key_Backspace
));
1822 actionCollection()->setDefaultShortcuts(m_backAction
, backShortcuts
);
1824 DolphinRecentTabsMenu
*recentTabsMenu
= new DolphinRecentTabsMenu(this);
1825 actionCollection()->addAction(QStringLiteral("closed_tabs"), recentTabsMenu
);
1826 connect(m_tabWidget
, &DolphinTabWidget::rememberClosedTab
, recentTabsMenu
, &DolphinRecentTabsMenu::rememberClosedTab
);
1827 connect(recentTabsMenu
, &DolphinRecentTabsMenu::restoreClosedTab
, m_tabWidget
, &DolphinTabWidget::restoreClosedTab
);
1828 connect(recentTabsMenu
, &DolphinRecentTabsMenu::closedTabsCountChanged
, this, &DolphinMainWindow::closedTabsCountChanged
);
1830 QAction
*undoCloseTab
= actionCollection()->addAction(QStringLiteral("undo_close_tab"));
1831 undoCloseTab
->setText(i18nc("@action:inmenu File", "Undo close tab"));
1832 undoCloseTab
->setWhatsThis(i18nc("@info:whatsthis undo close tab", "This returns you to the previously closed tab."));
1833 actionCollection()->setDefaultShortcut(undoCloseTab
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_T
);
1834 undoCloseTab
->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo")));
1835 undoCloseTab
->setEnabled(false);
1836 connect(undoCloseTab
, &QAction::triggered
, recentTabsMenu
, &DolphinRecentTabsMenu::undoCloseTab
);
1838 auto undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
1839 undoAction
->setWhatsThis(xi18nc("@info:whatsthis",
1841 "the last change you made to files or folders.<nl/>"
1842 "Such changes include <interface>creating, renaming</interface> "
1843 "and <interface>moving</interface> them to a different location "
1844 "or to the <filename>Trash</filename>. <nl/>Changes that can't "
1845 "be undone will ask for your confirmation."));
1846 undoAction
->setEnabled(false); // undo should be disabled by default
1849 QScopedPointer
<QAction
> forwardAction(KStandardAction::forward(nullptr, nullptr, nullptr));
1850 m_forwardAction
= new KToolBarPopupAction(forwardAction
->icon(), forwardAction
->text(), actionCollection());
1851 m_forwardAction
->setObjectName(forwardAction
->objectName());
1852 m_forwardAction
->setShortcuts(forwardAction
->shortcuts());
1854 m_forwardAction
->setPopupMode(QToolButton::DelayedPopup
);
1855 connect(m_forwardAction
, &QAction::triggered
, this, &DolphinMainWindow::goForward
);
1856 connect(m_forwardAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowForwardPopupMenu
);
1857 connect(m_forwardAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoForward
);
1858 actionCollection()->addAction(m_forwardAction
->objectName(), m_forwardAction
);
1859 actionCollection()->setDefaultShortcuts(m_forwardAction
, m_forwardAction
->shortcuts());
1861 // enable middle-click to open in a new tab
1862 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
1863 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotBackForwardActionMiddleClicked
);
1864 m_backAction
->menu()->installEventFilter(middleClickEventFilter
);
1865 m_forwardAction
->menu()->installEventFilter(middleClickEventFilter
);
1866 KStandardAction::up(this, &DolphinMainWindow::goUp
, actionCollection());
1867 QAction
*homeAction
= KStandardAction::home(this, &DolphinMainWindow::goHome
, actionCollection());
1868 homeAction
->setWhatsThis(xi18nc("@info:whatsthis",
1870 "<filename>Home</filename> folder.<nl/>Every user account "
1871 "has their own <filename>Home</filename> that contains their data "
1872 "including folders that contain personal application data."));
1874 // setup 'Tools' menu
1875 QAction
*compareFiles
= actionCollection()->addAction(QStringLiteral("compare_files"));
1876 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1877 compareFiles
->setIcon(QIcon::fromTheme(QStringLiteral("kompare")));
1878 compareFiles
->setEnabled(false);
1879 connect(compareFiles
, &QAction::triggered
, this, &DolphinMainWindow::compareFiles
);
1881 QAction
*openPreferredSearchTool
= actionCollection()->addAction(QStringLiteral("open_preferred_search_tool"));
1882 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1883 openPreferredSearchTool
->setWhatsThis(xi18nc("@info:whatsthis",
1884 "<para>This opens a preferred search tool for the viewed location.</para>"
1885 "<para>Use <emphasis>More Search Tools</emphasis> menu to configure it.</para>"));
1886 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1887 actionCollection()->setDefaultShortcut(openPreferredSearchTool
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F
);
1888 connect(openPreferredSearchTool
, &QAction::triggered
, this, &DolphinMainWindow::openPreferredSearchTool
);
1890 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1891 QAction
*openTerminal
= actionCollection()->addAction(QStringLiteral("open_terminal"));
1892 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1893 openTerminal
->setWhatsThis(xi18nc("@info:whatsthis",
1894 "<para>This opens a <emphasis>terminal</emphasis> application for the viewed location.</para>"
1895 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1896 openTerminal
->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
1897 actionCollection()->setDefaultShortcut(openTerminal
, Qt::SHIFT
| Qt::Key_F4
);
1898 connect(openTerminal
, &QAction::triggered
, this, &DolphinMainWindow::openTerminal
);
1900 QAction
*openTerminalHere
= actionCollection()->addAction(QStringLiteral("open_terminal_here"));
1901 // i18n: "Here" refers to the location(s) of the currently selected item(s) or the currently viewed location if nothing is selected.
1902 openTerminalHere
->setText(i18nc("@action:inmenu Tools", "Open Terminal Here"));
1903 openTerminalHere
->setWhatsThis(xi18nc("@info:whatsthis",
1904 "<para>This opens <emphasis>terminal</emphasis> applications for the selected items' locations.</para>"
1905 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1906 openTerminalHere
->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
1907 actionCollection()->setDefaultShortcut(openTerminalHere
, Qt::SHIFT
| Qt::ALT
| Qt::Key_F4
);
1908 connect(openTerminalHere
, &QAction::triggered
, this, &DolphinMainWindow::openTerminalHere
);
1911 QAction
*focusTerminalPanel
= actionCollection()->addAction(QStringLiteral("focus_terminal_panel"));
1912 focusTerminalPanel
->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
1913 focusTerminalPanel
->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
1914 actionCollection()->setDefaultShortcut(focusTerminalPanel
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F4
);
1915 connect(focusTerminalPanel
, &QAction::triggered
, this, &DolphinMainWindow::focusTerminalPanel
);
1919 // setup 'Bookmarks' menu
1920 KActionMenu
*bookmarkMenu
= new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this);
1921 bookmarkMenu
->setIcon(QIcon::fromTheme(QStringLiteral("bookmarks")));
1922 // Make the toolbar button version work properly on click
1923 bookmarkMenu
->setPopupMode(QToolButton::InstantPopup
);
1924 m_bookmarkHandler
= new DolphinBookmarkHandler(this, actionCollection(), bookmarkMenu
->menu(), this);
1925 actionCollection()->addAction(QStringLiteral("bookmarks"), bookmarkMenu
);
1927 // setup 'Settings' menu
1928 KToggleAction
*showMenuBar
= KStandardAction::showMenubar(nullptr, nullptr, actionCollection());
1929 showMenuBar
->setWhatsThis(xi18nc("@info:whatsthis",
1930 "<para>This switches between having a <emphasis>Menubar</emphasis> "
1931 "and having a <interface>%1</interface> button. Both "
1932 "contain mostly the same actions and configuration options.</para>"
1933 "<para>The Menubar takes up more space but allows for fast and organised access to all "
1934 "actions an application has to offer.</para><para>The <interface>%1</interface> button "
1935 "is simpler and small which makes triggering advanced actions more time consuming.</para>",
1936 hamburgerMenuAction
->text().replace('&', "")));
1937 connect(showMenuBar
,
1938 &KToggleAction::triggered
, // Fixes #286822
1940 &DolphinMainWindow::toggleShowMenuBar
,
1941 Qt::QueuedConnection
);
1943 KToggleAction
*showStatusBar
= KStandardAction::showStatusbar(nullptr, nullptr, actionCollection());
1944 showStatusBar
->setChecked(GeneralSettings::showStatusBar());
1945 connect(GeneralSettings::self(), &GeneralSettings::showStatusBarChanged
, showStatusBar
, &KToggleAction::setChecked
);
1946 connect(showStatusBar
, &KToggleAction::triggered
, this, [this](bool checked
) {
1947 GeneralSettings::setShowStatusBar(checked
);
1951 KStandardAction::keyBindings(this, &DolphinMainWindow::slotKeyBindings
, actionCollection());
1952 KStandardAction::preferences(this, &DolphinMainWindow::editSettings
, actionCollection());
1954 // not in menu actions
1955 QList
<QKeySequence
> nextTabKeys
= KStandardShortcut::tabNext();
1956 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
1958 QList
<QKeySequence
> prevTabKeys
= KStandardShortcut::tabPrev();
1959 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
1961 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1962 QAction
*activateTab
= actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i
));
1963 activateTab
->setText(i18nc("@action:inmenu", "Activate Tab %1", i
+ 1));
1964 activateTab
->setEnabled(false);
1965 connect(activateTab
, &QAction::triggered
, this, [this, i
]() {
1966 m_tabWidget
->activateTab(i
);
1969 // only add default shortcuts for the first 9 tabs regardless of MaxActivateTabShortcuts
1971 actionCollection()->setDefaultShortcut(activateTab
, QStringLiteral("Alt+%1").arg(i
+ 1));
1975 QAction
*activateLastTab
= actionCollection()->addAction(QStringLiteral("activate_last_tab"));
1976 activateLastTab
->setText(i18nc("@action:inmenu", "Activate Last Tab"));
1977 activateLastTab
->setEnabled(false);
1978 connect(activateLastTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateLastTab
);
1979 actionCollection()->setDefaultShortcut(activateLastTab
, Qt::ALT
| Qt::Key_0
);
1981 QAction
*activateNextTab
= actionCollection()->addAction(QStringLiteral("activate_next_tab"));
1982 activateNextTab
->setIconText(i18nc("@action:inmenu", "Next Tab"));
1983 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1984 activateNextTab
->setEnabled(false);
1985 connect(activateNextTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateNextTab
);
1986 actionCollection()->setDefaultShortcuts(activateNextTab
, nextTabKeys
);
1988 QAction
*activatePrevTab
= actionCollection()->addAction(QStringLiteral("activate_prev_tab"));
1989 activatePrevTab
->setIconText(i18nc("@action:inmenu", "Previous Tab"));
1990 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1991 activatePrevTab
->setEnabled(false);
1992 connect(activatePrevTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activatePrevTab
);
1993 actionCollection()->setDefaultShortcuts(activatePrevTab
, prevTabKeys
);
1996 QAction
*showTarget
= actionCollection()->addAction(QStringLiteral("show_target"));
1997 showTarget
->setText(i18nc("@action:inmenu", "Show Target"));
1998 showTarget
->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
1999 showTarget
->setEnabled(false);
2000 connect(showTarget
, &QAction::triggered
, this, &DolphinMainWindow::showTarget
);
2002 QAction
*openInNewTab
= actionCollection()->addAction(QStringLiteral("open_in_new_tab"));
2003 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
2004 openInNewTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
2005 connect(openInNewTab
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
2007 QAction
*openInNewTabs
= actionCollection()->addAction(QStringLiteral("open_in_new_tabs"));
2008 openInNewTabs
->setText(i18nc("@action:inmenu", "Open in New Tabs"));
2009 openInNewTabs
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
2010 connect(openInNewTabs
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
2012 QAction
*openInNewWindow
= actionCollection()->addAction(QStringLiteral("open_in_new_window"));
2013 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
2014 openInNewWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
2015 connect(openInNewWindow
, &QAction::triggered
, this, &DolphinMainWindow::openInNewWindow
);
2018 void DolphinMainWindow::setupDockWidgets()
2020 const bool lock
= GeneralSettings::lockPanels();
2022 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(lock
);
2024 KDualAction
*lockLayoutAction
= actionCollection()->add
<KDualAction
>(QStringLiteral("lock_panels"));
2025 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
2026 lockLayoutAction
->setActiveIcon(QIcon::fromTheme(QStringLiteral("object-unlocked")));
2027 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
2028 lockLayoutAction
->setInactiveIcon(QIcon::fromTheme(QStringLiteral("object-locked")));
2029 lockLayoutAction
->setWhatsThis(xi18nc("@info:whatsthis",
2031 "switches between having panels <emphasis>locked</emphasis> or "
2032 "<emphasis>unlocked</emphasis>.<nl/>Unlocked panels can be "
2033 "dragged to the other side of the window and have a close "
2034 "button.<nl/>Locked panels are embedded more cleanly."));
2035 lockLayoutAction
->setActive(lock
);
2036 connect(lockLayoutAction
, &KDualAction::triggered
, this, &DolphinMainWindow::togglePanelLockState
);
2038 // Setup "Information"
2039 DolphinDockWidget
*infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
2040 infoDock
->setLocked(lock
);
2041 infoDock
->setObjectName(QStringLiteral("infoDock"));
2042 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2045 InformationPanel
*infoPanel
= new InformationPanel(infoDock
);
2046 infoPanel
->setCustomContextMenuActions({lockLayoutAction
});
2047 connect(infoPanel
, &InformationPanel::urlActivated
, this, &DolphinMainWindow::handleUrl
);
2048 infoDock
->setWidget(infoPanel
);
2050 QAction
*infoAction
= infoDock
->toggleViewAction();
2051 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-information")), Qt::Key_F11
, infoAction
, QStringLiteral("show_information_panel"));
2053 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
2054 connect(this, &DolphinMainWindow::urlChanged
, infoPanel
, &InformationPanel::setUrl
);
2055 connect(this, &DolphinMainWindow::selectionChanged
, infoPanel
, &InformationPanel::setSelection
);
2056 connect(this, &DolphinMainWindow::requestItemInfo
, infoPanel
, &InformationPanel::requestDelayedItemInfo
);
2057 connect(this, &DolphinMainWindow::fileItemsChanged
, infoPanel
, &InformationPanel::slotFilesItemChanged
);
2060 // i18n: This is the last paragraph for the "What's This"-texts of all four panels.
2061 const QString panelWhatsThis
= xi18nc("@info:whatsthis",
2063 "hide panels like this go to <interface>Menu|Panels</interface> "
2064 "or <interface>View|Panels</interface>.</para>");
2067 ->action(QStringLiteral("show_information_panel"))
2068 ->setWhatsThis(xi18nc("@info:whatsthis",
2069 "<para> This toggles the "
2070 "<emphasis>information</emphasis> panel at the right side of the "
2071 "window.</para><para>The panel provides in-depth information "
2072 "about the items your mouse is hovering over or about the selected "
2073 "items. Otherwise it informs you about the currently viewed folder.<nl/>"
2074 "For single items a preview of their contents is provided.</para>"));
2076 infoDock
->setWhatsThis(xi18nc("@info:whatsthis",
2078 "provides in-depth information about the items your mouse is "
2079 "hovering over or about the selected items. Otherwise it informs "
2080 "you about the currently viewed folder.<nl/>For single items a "
2081 "preview of their contents is provided.</para><para>You can configure "
2082 "which and how details are given here by right-clicking.</para>")
2086 DolphinDockWidget
*foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
2087 foldersDock
->setLocked(lock
);
2088 foldersDock
->setObjectName(QStringLiteral("foldersDock"));
2089 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2090 FoldersPanel
*foldersPanel
= new FoldersPanel(foldersDock
);
2091 foldersPanel
->setCustomContextMenuActions({lockLayoutAction
});
2092 foldersDock
->setWidget(foldersPanel
);
2094 QAction
*foldersAction
= foldersDock
->toggleViewAction();
2095 createPanelAction(QIcon::fromTheme(QStringLiteral("folder")), Qt::Key_F7
, foldersAction
, QStringLiteral("show_folders_panel"));
2097 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
2098 connect(this, &DolphinMainWindow::urlChanged
, foldersPanel
, &FoldersPanel::setUrl
);
2099 connect(foldersPanel
, &FoldersPanel::folderActivated
, this, &DolphinMainWindow::changeUrl
);
2100 connect(foldersPanel
, &FoldersPanel::folderInNewTab
, this, &DolphinMainWindow::openNewTab
);
2101 connect(foldersPanel
, &FoldersPanel::folderInNewActiveTab
, this, &DolphinMainWindow::openNewTabAndActivate
);
2102 connect(foldersPanel
, &FoldersPanel::errorMessage
, this, &DolphinMainWindow::showErrorMessage
);
2105 ->action(QStringLiteral("show_folders_panel"))
2106 ->setWhatsThis(xi18nc("@info:whatsthis",
2108 "<emphasis>folders</emphasis> panel at the left side of the window."
2109 "<nl/><nl/>It shows the folders of the <emphasis>file system"
2110 "</emphasis> in a <emphasis>tree view</emphasis>."));
2111 foldersDock
->setWhatsThis(xi18nc("@info:whatsthis",
2113 "shows the folders of the <emphasis>file system</emphasis> in a "
2114 "<emphasis>tree view</emphasis>.</para><para>Click a folder to go "
2115 "there. Click the arrow to the left of a folder to see its subfolders. "
2116 "This allows quick switching between any folders.</para>")
2121 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
2122 DolphinDockWidget
*terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
2123 terminalDock
->setLocked(lock
);
2124 terminalDock
->setObjectName(QStringLiteral("terminalDock"));
2125 m_terminalPanel
= new TerminalPanel(terminalDock
);
2126 m_terminalPanel
->setCustomContextMenuActions({lockLayoutAction
});
2127 terminalDock
->setWidget(m_terminalPanel
);
2129 connect(m_terminalPanel
, &TerminalPanel::hideTerminalPanel
, terminalDock
, &DolphinDockWidget::hide
);
2130 connect(m_terminalPanel
, &TerminalPanel::changeUrl
, this, &DolphinMainWindow::slotTerminalDirectoryChanged
);
2131 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
, m_terminalPanel
, &TerminalPanel::dockVisibilityChanged
);
2132 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
, this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged
);
2134 QAction
*terminalAction
= terminalDock
->toggleViewAction();
2135 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-scripts")), Qt::Key_F4
, terminalAction
, QStringLiteral("show_terminal_panel"));
2137 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
2138 connect(this, &DolphinMainWindow::urlChanged
, m_terminalPanel
, &TerminalPanel::setUrl
);
2140 if (GeneralSettings::version() < 200) {
2141 terminalDock
->hide();
2145 ->action(QStringLiteral("show_terminal_panel"))
2146 ->setWhatsThis(xi18nc("@info:whatsthis",
2147 "<para>This toggles the "
2148 "<emphasis>terminal</emphasis> panel at the bottom of the window."
2149 "<nl/>The location in the terminal will always match the folder "
2150 "view so you can navigate using either.</para><para>The terminal "
2151 "panel is not needed for basic computer usage but can be useful "
2152 "for advanced tasks. To learn more about terminals use the help "
2153 "in a standalone terminal application like Konsole.</para>"));
2154 terminalDock
->setWhatsThis(xi18nc("@info:whatsthis",
2156 "the <emphasis>terminal</emphasis> panel. It behaves like a "
2157 "normal terminal but will match the location of the folder view "
2158 "so you can navigate using either.</para><para>The terminal panel "
2159 "is not needed for basic computer usage but can be useful for "
2160 "advanced tasks. To learn more about terminals use the help in a "
2161 "standalone terminal application like Konsole.</para>")
2166 if (GeneralSettings::version() < 200) {
2168 foldersDock
->hide();
2172 DolphinDockWidget
*placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
2173 placesDock
->setLocked(lock
);
2174 placesDock
->setObjectName(QStringLiteral("placesDock"));
2175 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2177 m_placesPanel
= new PlacesPanel(placesDock
);
2178 m_placesPanel
->setCustomContextMenuActions({lockLayoutAction
});
2179 placesDock
->setWidget(m_placesPanel
);
2181 QAction
*placesAction
= placesDock
->toggleViewAction();
2182 createPanelAction(QIcon::fromTheme(QStringLiteral("compass")), Qt::Key_F9
, placesAction
, QStringLiteral("show_places_panel"));
2184 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
2185 connect(m_placesPanel
, &PlacesPanel::placeActivated
, this, &DolphinMainWindow::slotPlaceActivated
);
2186 connect(m_placesPanel
, &PlacesPanel::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2187 connect(m_placesPanel
, &PlacesPanel::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2188 connect(m_placesPanel
, &PlacesPanel::newWindowRequested
, this, [this](const QUrl
&url
) {
2189 Dolphin::openNewWindow({url
}, this);
2191 connect(m_placesPanel
, &PlacesPanel::errorMessage
, this, &DolphinMainWindow::showErrorMessage
);
2192 connect(this, &DolphinMainWindow::urlChanged
, m_placesPanel
, &PlacesPanel::setUrl
);
2193 connect(placesDock
, &DolphinDockWidget::visibilityChanged
, &DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged
);
2194 connect(this, &DolphinMainWindow::settingsChanged
, m_placesPanel
, &PlacesPanel::readSettings
);
2195 connect(m_placesPanel
, &PlacesPanel::storageTearDownRequested
, this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested
);
2196 connect(m_placesPanel
, &PlacesPanel::storageTearDownExternallyRequested
, this, &DolphinMainWindow::slotStorageTearDownExternallyRequested
);
2197 DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged(m_placesPanel
->isVisible());
2199 auto actionShowAllPlaces
= new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this);
2200 actionShowAllPlaces
->setCheckable(true);
2201 actionShowAllPlaces
->setDisabled(true);
2202 actionShowAllPlaces
->setWhatsThis(i18nc("@info:whatsthis",
2204 "all places in the places panel that have been hidden. They will "
2205 "appear semi-transparent unless you uncheck their hide property."));
2207 connect(actionShowAllPlaces
, &QAction::triggered
, this, [actionShowAllPlaces
, this](bool checked
) {
2208 m_placesPanel
->setShowAll(checked
);
2210 connect(m_placesPanel
, &PlacesPanel::allPlacesShownChanged
, actionShowAllPlaces
, &QAction::setChecked
);
2213 ->action(QStringLiteral("show_places_panel"))
2214 ->setWhatsThis(xi18nc("@info:whatsthis",
2215 "<para>This toggles the "
2216 "<emphasis>places</emphasis> panel at the left side of the window."
2217 "</para><para>It allows you to go to locations you have "
2218 "bookmarked and to access disk or media attached to the computer "
2219 "or to the network. It also contains sections to find recently "
2220 "saved files or files of a certain type.</para>"));
2221 placesDock
->setWhatsThis(xi18nc("@info:whatsthis",
2222 "<para>This is the "
2223 "<emphasis>Places</emphasis> panel. It allows you to go to locations "
2224 "you have bookmarked and to access disk or media attached to the "
2225 "computer or to the network. It also contains sections to find "
2226 "recently saved files or files of a certain type.</para><para>"
2227 "Click on an entry to go there. Click with the right mouse button "
2228 "instead to open any entry in a new tab or new window.</para>"
2229 "<para>New entries can be added by dragging folders onto this panel. "
2230 "Right-click any section or entry to hide it. Right-click an empty "
2231 "space on this panel and select <interface>Show Hidden Places"
2232 "</interface> to display it again.</para>")
2235 // Add actions into the "Panels" menu
2236 KActionMenu
*panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Show Panels"), this);
2237 actionCollection()->addAction(QStringLiteral("panels"), panelsMenu
);
2238 panelsMenu
->setIcon(QIcon::fromTheme(QStringLiteral("view-sidetree")));
2239 panelsMenu
->setPopupMode(QToolButton::InstantPopup
);
2240 const KActionCollection
*ac
= actionCollection();
2241 panelsMenu
->addAction(ac
->action(QStringLiteral("show_places_panel")));
2243 panelsMenu
->addAction(ac
->action(QStringLiteral("show_information_panel")));
2245 panelsMenu
->addAction(ac
->action(QStringLiteral("show_folders_panel")));
2246 panelsMenu
->addAction(ac
->action(QStringLiteral("show_terminal_panel")));
2247 panelsMenu
->addSeparator();
2248 panelsMenu
->addAction(actionShowAllPlaces
);
2249 panelsMenu
->addAction(lockLayoutAction
);
2251 connect(panelsMenu
->menu(), &QMenu::aboutToShow
, this, [actionShowAllPlaces
, this] {
2252 actionShowAllPlaces
->setEnabled(DolphinPlacesModelSingleton::instance().placesModel()->hiddenCount());
2256 void DolphinMainWindow::updateFileAndEditActions()
2258 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
2259 const KActionCollection
*col
= actionCollection();
2260 KFileItemListProperties
capabilitiesSource(list
);
2262 QAction
*renameAction
= col
->action(KStandardAction::name(KStandardAction::RenameFile
));
2263 QAction
*moveToTrashAction
= col
->action(KStandardAction::name(KStandardAction::MoveToTrash
));
2264 QAction
*deleteAction
= col
->action(KStandardAction::name(KStandardAction::DeleteFile
));
2265 QAction
*cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
2266 QAction
*duplicateAction
= col
->action(QStringLiteral("duplicate")); // see DolphinViewActionHandler
2267 QAction
*addToPlacesAction
= col
->action(QStringLiteral("add_to_places"));
2268 QAction
*copyToOtherViewAction
= col
->action(QStringLiteral("copy_to_inactive_split_view"));
2269 QAction
*moveToOtherViewAction
= col
->action(QStringLiteral("move_to_inactive_split_view"));
2270 QAction
*copyLocation
= col
->action(QString("copy_location"));
2272 if (list
.isEmpty()) {
2273 stateChanged(QStringLiteral("has_no_selection"));
2275 // All actions that need a selection to function can be enabled because they should trigger selection mode.
2276 renameAction
->setEnabled(true);
2277 moveToTrashAction
->setEnabled(true);
2278 deleteAction
->setEnabled(true);
2279 cutAction
->setEnabled(true);
2280 duplicateAction
->setEnabled(true);
2281 addToPlacesAction
->setEnabled(true);
2282 copyLocation
->setEnabled(true);
2283 // Them triggering selection mode and not directly acting on selected items is signified by adding "…" to their text.
2284 m_actionTextHelper
->textsWhenNothingIsSelectedEnabled(true);
2287 m_actionTextHelper
->textsWhenNothingIsSelectedEnabled(false);
2288 stateChanged(QStringLiteral("has_selection"));
2290 QAction
*deleteWithTrashShortcut
= col
->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
2291 QAction
*showTarget
= col
->action(QStringLiteral("show_target"));
2293 if (list
.length() == 1 && list
.first().isDir()) {
2294 addToPlacesAction
->setEnabled(true);
2296 addToPlacesAction
->setEnabled(false);
2299 const bool enableMoveToTrash
= capabilitiesSource
.isLocal() && capabilitiesSource
.supportsMoving();
2301 renameAction
->setEnabled(capabilitiesSource
.supportsMoving());
2302 moveToTrashAction
->setEnabled(enableMoveToTrash
);
2303 deleteAction
->setEnabled(capabilitiesSource
.supportsDeleting());
2304 deleteWithTrashShortcut
->setEnabled(capabilitiesSource
.supportsDeleting() && !enableMoveToTrash
);
2305 cutAction
->setEnabled(capabilitiesSource
.supportsMoving());
2306 copyLocation
->setEnabled(list
.length() == 1);
2307 showTarget
->setEnabled(list
.length() == 1 && list
.at(0).isLink());
2308 duplicateAction
->setEnabled(capabilitiesSource
.supportsWriting());
2311 if (m_tabWidget
->currentTabPage()->splitViewEnabled() && !list
.isEmpty()) {
2312 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
2313 KFileItem capabilitiesDestination
;
2315 if (tabPage
->primaryViewActive()) {
2316 capabilitiesDestination
= tabPage
->secondaryViewContainer()->rootItem();
2318 capabilitiesDestination
= tabPage
->primaryViewContainer()->rootItem();
2321 const auto destUrl
= capabilitiesDestination
.url();
2322 const bool allNotTargetOrigin
= std::all_of(list
.cbegin(), list
.cend(), [destUrl
](const KFileItem
&item
) {
2323 return item
.url().adjusted(QUrl::RemoveFilename
| QUrl::StripTrailingSlash
) != destUrl
;
2326 copyToOtherViewAction
->setEnabled(capabilitiesDestination
.isWritable() && allNotTargetOrigin
);
2327 moveToOtherViewAction
->setEnabled((list
.isEmpty() || capabilitiesSource
.supportsMoving()) && capabilitiesDestination
.isWritable()
2328 && allNotTargetOrigin
);
2330 copyToOtherViewAction
->setEnabled(false);
2331 moveToOtherViewAction
->setEnabled(false);
2335 void DolphinMainWindow::updateViewActions()
2337 m_actionHandler
->updateViewActions();
2339 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
2340 toggleFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
2342 updateSplitAction();
2345 void DolphinMainWindow::updateGoActions()
2347 QAction
*goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
2348 const QUrl currentUrl
= m_activeViewContainer
->url();
2349 // I think this is one of the best places to firstly be confronted
2350 // with a file system and its hierarchy. Talking about the root
2351 // directory might seem too much here but it is the question that
2352 // naturally arises in this context.
2353 goUpAction
->setWhatsThis(xi18nc("@info:whatsthis",
2355 "the folder that contains the currently viewed one.</para>"
2356 "<para>All files and folders are organized in a hierarchical "
2357 "<emphasis>file system</emphasis>. At the top of this hierarchy is "
2358 "a directory that contains all data connected to this computer"
2359 "—the <emphasis>root directory</emphasis>.</para>"));
2360 goUpAction
->setEnabled(KIO::upUrl(currentUrl
) != currentUrl
);
2363 void DolphinMainWindow::refreshViews()
2365 m_tabWidget
->refreshViews();
2367 if (GeneralSettings::modifiedStartupSettings()) {
2368 updateWindowTitle();
2371 updateSplitAction();
2373 Q_EMIT
settingsChanged();
2376 void DolphinMainWindow::clearStatusBar()
2378 m_activeViewContainer
->statusBar()->resetToDefaultText();
2381 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
*container
)
2383 connect(container
, &DolphinViewContainer::showFilterBarChanged
, this, &DolphinMainWindow::updateFilterBarAction
);
2384 connect(container
, &DolphinViewContainer::writeStateChanged
, this, &DolphinMainWindow::slotWriteStateChanged
);
2385 connect(container
, &DolphinViewContainer::searchModeEnabledChanged
, this, &DolphinMainWindow::updateSearchAction
);
2386 connect(container
, &DolphinViewContainer::captionChanged
, this, &DolphinMainWindow::updateWindowTitle
);
2387 connect(container
, &DolphinViewContainer::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2388 connect(container
, &DolphinViewContainer::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2390 const QAction
*toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
2391 connect(toggleSearchAction
, &QAction::triggered
, container
, &DolphinViewContainer::setSearchModeEnabled
);
2393 // Make the toggled state of the selection mode actions visually follow the selection mode state of the view.
2394 auto toggleSelectionModeAction
= actionCollection()->action(QStringLiteral("toggle_selection_mode"));
2395 toggleSelectionModeAction
->setChecked(m_activeViewContainer
->isSelectionModeEnabled());
2396 connect(m_activeViewContainer
, &DolphinViewContainer::selectionModeChanged
, toggleSelectionModeAction
, &QAction::setChecked
);
2398 const DolphinView
*view
= container
->view();
2399 connect(view
, &DolphinView::selectionChanged
, this, &DolphinMainWindow::slotSelectionChanged
);
2400 connect(view
, &DolphinView::requestItemInfo
, this, &DolphinMainWindow::requestItemInfo
);
2401 connect(view
, &DolphinView::fileItemsChanged
, this, &DolphinMainWindow::fileItemsChanged
);
2402 connect(view
, &DolphinView::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2403 connect(view
, &DolphinView::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2404 connect(view
, &DolphinView::windowRequested
, this, &DolphinMainWindow::openNewWindow
);
2405 connect(view
, &DolphinView::requestContextMenu
, this, &DolphinMainWindow::openContextMenu
);
2406 connect(view
, &DolphinView::directoryLoadingStarted
, this, &DolphinMainWindow::enableStopAction
);
2407 connect(view
, &DolphinView::directoryLoadingCompleted
, this, &DolphinMainWindow::disableStopAction
);
2408 connect(view
, &DolphinView::directoryLoadingCompleted
, this, &DolphinMainWindow::slotDirectoryLoadingCompleted
);
2409 connect(view
, &DolphinView::goBackRequested
, this, &DolphinMainWindow::goBack
);
2410 connect(view
, &DolphinView::goForwardRequested
, this, &DolphinMainWindow::goForward
);
2411 connect(view
, &DolphinView::urlActivated
, this, &DolphinMainWindow::handleUrl
);
2412 connect(view
, &DolphinView::goUpRequested
, this, &DolphinMainWindow::goUp
);
2414 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::urlChanged
, this, &DolphinMainWindow::changeUrl
);
2415 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::historyChanged
, this, &DolphinMainWindow::updateHistory
);
2417 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2418 const KUrlNavigator
*navigator
=
2419 m_tabWidget
->currentTabPage()->primaryViewActive() ? navigators
->primaryUrlNavigator() : navigators
->secondaryUrlNavigator();
2421 QAction
*editableLocactionAction
= actionCollection()->action(QStringLiteral("editable_location"));
2422 editableLocactionAction
->setChecked(navigator
->isUrlEditable());
2423 connect(navigator
, &KUrlNavigator::editableStateChanged
, this, &DolphinMainWindow::slotEditableStateChanged
);
2424 connect(navigator
, &KUrlNavigator::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2425 connect(navigator
, &KUrlNavigator::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2426 connect(navigator
, &KUrlNavigator::newWindowRequested
, this, &DolphinMainWindow::openNewWindow
);
2429 void DolphinMainWindow::updateSplitAction()
2431 QAction
*splitAction
= actionCollection()->action(QStringLiteral("split_view"));
2432 const DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
2433 if (tabPage
->splitViewEnabled()) {
2434 if (GeneralSettings::closeActiveSplitView() ? tabPage
->primaryViewActive() : !tabPage
->primaryViewActive()) {
2435 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2436 splitAction
->setToolTip(i18nc("@info", "Close left view"));
2437 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close")));
2439 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2440 splitAction
->setToolTip(i18nc("@info", "Close right view"));
2441 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close")));
2444 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2445 splitAction
->setToolTip(i18nc("@info", "Split view"));
2446 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
2450 void DolphinMainWindow::updateAllowedToolbarAreas()
2452 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2453 if (toolBar()->actions().contains(navigators
)) {
2454 toolBar()->setAllowedAreas(Qt::TopToolBarArea
| Qt::BottomToolBarArea
);
2455 if (toolBarArea(toolBar()) == Qt::LeftToolBarArea
|| toolBarArea(toolBar()) == Qt::RightToolBarArea
) {
2456 addToolBar(Qt::TopToolBarArea
, toolBar());
2459 toolBar()->setAllowedAreas(Qt::AllToolBarAreas
);
2463 bool DolphinMainWindow::isKompareInstalled() const
2465 static bool initialized
= false;
2466 static bool installed
= false;
2468 // TODO: maybe replace this approach later by using a menu
2469 // plugin like kdiff3plugin.cpp
2470 installed
= !QStandardPaths::findExecutable(QStringLiteral("kompare")).isEmpty();
2476 void DolphinMainWindow::createPanelAction(const QIcon
&icon
, const QKeySequence
&shortcut
, QAction
*dockAction
, const QString
&actionName
)
2478 QAction
*panelAction
= actionCollection()->addAction(actionName
);
2479 panelAction
->setCheckable(true);
2480 panelAction
->setChecked(dockAction
->isChecked());
2481 panelAction
->setText(dockAction
->text());
2482 panelAction
->setIcon(icon
);
2483 dockAction
->setIcon(icon
);
2484 actionCollection()->setDefaultShortcut(panelAction
, shortcut
);
2486 connect(panelAction
, &QAction::triggered
, dockAction
, &QAction::trigger
);
2487 connect(dockAction
, &QAction::toggled
, panelAction
, &QAction::setChecked
);
2490 void DolphinMainWindow::setupWhatsThis()
2493 menuBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2494 "<emphasis>Menubar</emphasis>. It provides access to commands and "
2495 "configuration options. Left-click on any of the menus on this "
2496 "bar to see its contents.</para><para>The Menubar can be hidden "
2497 "by unchecking <interface>Settings|Show Menubar</interface>. Then "
2498 "most of its contents become available through a <interface>Menu"
2499 "</interface> button on the <emphasis>Toolbar</emphasis>.</para>"));
2500 toolBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2501 "<emphasis>Toolbar</emphasis>. It allows quick access to "
2502 "frequently used actions.</para><para>It is highly customizable. "
2503 "All items you see in the <interface>Menu</interface> or "
2504 "in the <interface>Menubar</interface> can be placed on the "
2505 "Toolbar. Just right-click on it and select <interface>Configure "
2506 "Toolbars…</interface> or find this action within the <interface>"
2508 "</para><para>The location of the bar and the style of its "
2509 "buttons can also be changed in the right-click menu. Right-click "
2510 "a button if you want to show or hide its text.</para>"));
2511 m_tabWidget
->setWhatsThis(xi18nc("@info:whatsthis main view",
2512 "<para>Here you can see the <emphasis>folders</emphasis> and "
2513 "<emphasis>files</emphasis> that are at the location described in "
2514 "the <interface>Location Bar</interface> above. This area is the "
2515 "central part of this application where you navigate to the files "
2516 "you want to use.</para><para>For an elaborate and general "
2517 "introduction to this application <link "
2518 "url='https://userbase.kde.org/Dolphin/File_Management#Introduction_to_Dolphin'>"
2519 "click here</link>. This will open an introductory article from "
2520 "the <emphasis>KDE UserBase Wiki</emphasis>.</para><para>For brief "
2521 "explanations of all the features of this <emphasis>view</emphasis> "
2522 "<link url='help:/dolphin/dolphin-view.html'>click here</link> "
2523 "instead. This will open a page from the <emphasis>Handbook"
2524 "</emphasis> that covers the basics.</para>"));
2527 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings
))
2528 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window "
2529 "that lists the <emphasis>keyboard shortcuts</emphasis>.<nl/>"
2530 "There you can set up key combinations to trigger an action when "
2531 "they are pressed simultaneously. All commands in this application can "
2532 "be triggered this way.</para>"));
2533 actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars
))
2534 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window in which "
2535 "you can change which buttons appear on the <emphasis>Toolbar</emphasis>.</para>"
2536 "<para>All items you see in the <interface>Menu</interface> can also be placed on the Toolbar.</para>"));
2537 actionCollection()->action(KStandardAction::name(KStandardAction::Preferences
))
2538 ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window where you can "
2539 "change a multitude of settings for this application. For an explanation "
2540 "of the various settings go to the chapter <emphasis>Configuring Dolphin"
2541 "</emphasis> in <interface>Help|Dolphin Handbook</interface>."));
2545 auto setStandardActionWhatsThis
= [this](KStandardAction::StandardAction actionId
,
2546 const QString
&whatsThis
) {
2547 // Check for the existence of an action since it can be restricted through the Kiosk system
2548 if (auto *action
= actionCollection()->action(KStandardAction::name(actionId
))) {
2549 action
->setWhatsThis(whatsThis
);
2553 // i18n: If the external link isn't available in your language it might make
2554 // sense to state the external link's language in brackets to not
2555 // frustrate the user. If there are multiple languages that the user might
2556 // know with a reasonable chance you might want to have 2 external links.
2557 // The same might be true for any external link you translate.
2558 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>"));
2559 // (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 )
2561 setStandardActionWhatsThis(KStandardAction::WhatsThis
,
2562 xi18nc("@info:whatsthis whatsthis button",
2563 "<para>This is the button that invokes the help feature you are "
2564 "using right now! Click it, then click any component of this "
2565 "application to ask \"What's this?\" about it. The mouse cursor "
2566 "will change appearance if no help is available for a spot.</para>"
2567 "<para>There are two other ways to get help: "
2568 "The <link url='help:/dolphin/index.html'>Dolphin Handbook</link> and "
2569 "the <link url='https://userbase.kde.org/Dolphin/File_Management'>KDE "
2570 "UserBase Wiki</link>.</para><para>The \"What's this?\" help is "
2571 "missing in most other windows so don't get too used to this.</para>"));
2573 setStandardActionWhatsThis(KStandardAction::ReportBug
,
2574 xi18nc("@info:whatsthis","<para>This opens a "
2575 "window that will guide you through reporting errors or flaws "
2576 "in this application or in other KDE software.</para>"
2577 "<para>High-quality bug reports are much appreciated. To learn "
2578 "how to make your bug report as effective as possible "
2579 "<link url='https://community.kde.org/Get_Involved/Bug_Reporting'>"
2580 "click here</link>.</para>"));
2582 setStandardActionWhatsThis(KStandardAction::Donate
,
2583 xi18nc("@info:whatsthis", "<para>This opens a "
2584 "<emphasis>web page</emphasis> where you can donate to "
2585 "support the continued work on this application and many "
2586 "other projects by the <emphasis>KDE</emphasis> community.</para>"
2587 "<para>Donating is the easiest and fastest way to efficiently "
2588 "support KDE and its projects. KDE projects are available for "
2589 "free therefore your donation is needed to cover things that "
2590 "require money like servers, contributor meetings, etc.</para>"
2591 "<para><emphasis>KDE e.V.</emphasis> is the non-profit "
2592 "organization behind the KDE community.</para>"));
2594 setStandardActionWhatsThis(KStandardAction::SwitchApplicationLanguage
,
2595 xi18nc("@info:whatsthis",
2596 "With this you can change the language this application uses."
2597 "<nl/>You can even set secondary languages which will be used "
2598 "if texts are not available in your preferred language."));
2600 setStandardActionWhatsThis(KStandardAction::AboutApp
,
2601 xi18nc("@info:whatsthis","This opens a "
2602 "window that informs you about the version, license, "
2603 "used libraries and maintainers of this application."));
2605 setStandardActionWhatsThis(KStandardAction::AboutKDE
,
2606 xi18nc("@info:whatsthis","This opens a "
2607 "window with information about <emphasis>KDE</emphasis>. "
2608 "The KDE community are the people behind this free software."
2609 "<nl/>If you like using this application but don't know "
2610 "about KDE or want to see a cute dragon have a look!"));
2614 bool DolphinMainWindow::addHamburgerMenuToToolbar()
2616 QDomDocument domDocument
= KXMLGUIClient::domDocument();
2617 if (domDocument
.isNull()) {
2620 QDomNode toolbar
= domDocument
.elementsByTagName(QStringLiteral("ToolBar")).at(0);
2621 if (toolbar
.isNull()) {
2625 QDomElement hamburgerMenuElement
= domDocument
.createElement(QStringLiteral("Action"));
2626 hamburgerMenuElement
.setAttribute(QStringLiteral("name"), QStringLiteral("hamburger_menu"));
2627 toolbar
.appendChild(hamburgerMenuElement
);
2629 KXMLGUIFactory::saveConfigFile(domDocument
, xmlFile());
2633 // Make sure to also remove the <KXMLGUIFactory> and <QDomDocument> include
2634 // whenever this method is removed (maybe in the year ~2026).
2637 // Set a sane initial window size
2638 QSize
DolphinMainWindow::sizeHint() const
2640 return KXmlGuiWindow::sizeHint().expandedTo(QSize(760, 550));
2643 void DolphinMainWindow::saveNewToolbarConfig()
2645 KXmlGuiWindow::saveNewToolbarConfig(); // Applies the new config. This has to be called first
2646 // because the rest of this method decides things
2647 // based on the new config.
2648 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2649 if (!toolBar()->actions().contains(navigators
)) {
2650 m_tabWidget
->currentTabPage()->insertNavigatorsWidget(navigators
);
2652 updateAllowedToolbarAreas();
2653 (static_cast<KHamburgerMenu
*>(actionCollection()->action(KStandardAction::name(KStandardAction::HamburgerMenu
))))->hideActionsOf(toolBar());
2656 void DolphinMainWindow::focusTerminalPanel()
2658 if (m_terminalPanel
->isVisible()) {
2659 if (m_terminalPanel
->terminalHasFocus()) {
2660 m_activeViewContainer
->view()->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2661 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2663 m_terminalPanel
->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2664 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2667 actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger();
2668 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2672 DolphinMainWindow::UndoUiInterface::UndoUiInterface()
2673 : KIO::FileUndoManager::UiInterface()
2677 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2681 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
*job
)
2683 DolphinMainWindow
*mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2685 DolphinViewContainer
*container
= mainWin
->activeViewContainer();
2686 container
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
2688 KIO::FileUndoManager::UiInterface::jobError(job
);
2692 bool DolphinMainWindow::isUrlOpen(const QString
&url
)
2694 return m_tabWidget
->isUrlOpen(QUrl::fromUserInput(url
));
2697 bool DolphinMainWindow::isItemVisibleInAnyView(const QString
&urlOfItem
)
2699 return m_tabWidget
->isItemVisibleInAnyView(QUrl::fromUserInput(urlOfItem
));
2702 #include "moc_dolphinmainwindow.cpp"