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/JobUiDelegateFactory>
46 #include <KIO/OpenFileManagerWindowJob>
47 #include <KIO/OpenUrlJob>
48 #include <KJobWidgets>
49 #include <KLocalizedString>
50 #include <KMessageBox>
51 #include <KProtocolInfo>
52 #include <KProtocolManager>
54 #include <KShortcutsDialog>
55 #include <KStandardAction>
57 #include <KTerminalLauncherJob>
58 #include <KToggleAction>
60 #include <KToolBarPopupAction>
61 #include <KUrlComboBox>
62 #include <KUrlNavigator>
63 #include <KWindowSystem>
64 #include <KXMLGUIFactory>
66 #include <kwidgetsaddons_version.h>
68 #include <QApplication>
70 #include <QCloseEvent>
71 #include <QDesktopServices>
73 #include <QDomDocument>
77 #include <QPushButton>
79 #include <QStandardPaths>
81 #include <QToolButton>
86 #include <KStartupInfo>
91 // Used for GeneralSettings::version() to determine whether
92 // an updated version of Dolphin is running, so as to migrate
93 // removed/renamed ...etc config entries; increment it in such
95 const int CurrentDolphinVersion
= 202;
96 // The maximum number of entries in the back/forward popup menu
97 const int MaxNumberOfNavigationentries
= 12;
98 // The maximum number of "Activate Tab" shortcuts
99 const int MaxActivateTabShortcuts
= 9;
102 DolphinMainWindow::DolphinMainWindow()
103 : KXmlGuiWindow(nullptr)
104 , m_newFileMenu(nullptr)
105 , m_tabWidget(nullptr)
106 , m_activeViewContainer(nullptr)
107 , m_actionHandler(nullptr)
108 , m_remoteEncoding(nullptr)
110 , m_bookmarkHandler(nullptr)
111 , m_lastHandleUrlOpenJob(nullptr)
112 , m_terminalPanel(nullptr)
113 , m_placesPanel(nullptr)
114 , m_tearDownFromPlacesRequested(false)
115 , m_backAction(nullptr)
116 , m_forwardAction(nullptr)
118 Q_INIT_RESOURCE(dolphin
);
120 new MainWindowAdaptor(this);
123 setWindowFlags(Qt::WindowContextHelpButtonHint
);
125 setComponentName(QStringLiteral("dolphin"), QGuiApplication::applicationDisplayName());
126 setObjectName(QStringLiteral("Dolphin#"));
128 setStateConfigGroup("State");
130 connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::errorMessage
, this, &DolphinMainWindow::showErrorMessage
);
132 KIO::FileUndoManager
*undoManager
= KIO::FileUndoManager::self();
133 undoManager
->setUiInterface(new UndoUiInterface());
135 connect(undoManager
, &KIO::FileUndoManager::undoAvailable
, this, &DolphinMainWindow::slotUndoAvailable
);
136 connect(undoManager
, &KIO::FileUndoManager::undoTextChanged
, this, &DolphinMainWindow::slotUndoTextChanged
);
137 connect(undoManager
, &KIO::FileUndoManager::jobRecordingStarted
, this, &DolphinMainWindow::clearStatusBar
);
138 connect(undoManager
, &KIO::FileUndoManager::jobRecordingFinished
, this, &DolphinMainWindow::showCommand
);
140 const bool firstRun
= (GeneralSettings::version() < 200);
142 GeneralSettings::setViewPropsTimestamp(QDateTime::currentDateTime());
145 setAcceptDrops(true);
147 auto *navigatorsWidgetAction
= new DolphinNavigatorsWidgetAction(this);
148 actionCollection()->addAction(QStringLiteral("url_navigators"), navigatorsWidgetAction
);
149 m_tabWidget
= new DolphinTabWidget(navigatorsWidgetAction
, this);
150 m_tabWidget
->setObjectName("tabWidget");
151 connect(m_tabWidget
, &DolphinTabWidget::activeViewChanged
, this, &DolphinMainWindow::activeViewChanged
);
152 connect(m_tabWidget
, &DolphinTabWidget::tabCountChanged
, this, &DolphinMainWindow::tabCountChanged
);
153 connect(m_tabWidget
, &DolphinTabWidget::currentUrlChanged
, this, &DolphinMainWindow::updateWindowTitle
);
154 setCentralWidget(m_tabWidget
);
156 m_actionTextHelper
= new SelectionMode::ActionTextHelper(this);
159 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), m_actionTextHelper
, this);
160 connect(m_actionHandler
, &DolphinViewActionHandler::actionBeingHandled
, this, &DolphinMainWindow::clearStatusBar
);
161 connect(m_actionHandler
, &DolphinViewActionHandler::createDirectoryTriggered
, this, &DolphinMainWindow::createDirectory
);
162 connect(m_actionHandler
, &DolphinViewActionHandler::selectionModeChangeTriggered
, this, &DolphinMainWindow::slotSetSelectionMode
);
164 Q_CHECK_PTR(actionCollection()->action(QStringLiteral("create_dir")));
165 m_newFileMenu
->setNewFolderShortcutAction(actionCollection()->action(QStringLiteral("create_dir")));
167 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
168 connect(this, &DolphinMainWindow::urlChanged
, m_remoteEncoding
, &DolphinRemoteEncoding::slotAboutToOpenUrl
);
172 setupGUI(Save
| Create
| ToolBar
);
173 stateChanged(QStringLiteral("new_file"));
175 QClipboard
*clipboard
= QApplication::clipboard();
176 connect(clipboard
, &QClipboard::dataChanged
, this, &DolphinMainWindow::updatePasteAction
);
178 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
179 toggleFilterBarAction
->setChecked(GeneralSettings::filterBar());
182 menuBar()->setVisible(false);
185 const bool showMenu
= !menuBar()->isHidden();
186 QAction
*showMenuBarAction
= actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar
));
187 showMenuBarAction
->setChecked(showMenu
); // workaround for bug #171080
189 auto hamburgerMenu
= static_cast<KHamburgerMenu
*>(actionCollection()->action(KStandardAction::name(KStandardAction::HamburgerMenu
)));
190 hamburgerMenu
->setMenuBar(menuBar());
191 hamburgerMenu
->setShowMenuBarAction(showMenuBarAction
);
192 connect(hamburgerMenu
, &KHamburgerMenu::aboutToShowMenu
, this, &DolphinMainWindow::updateHamburgerMenu
);
193 hamburgerMenu
->hideActionsOf(toolBar());
194 if (GeneralSettings::version() < 201 && !toolBar()->actions().contains(hamburgerMenu
)) {
195 addHamburgerMenuToToolbar();
198 updateAllowedToolbarAreas();
200 // enable middle-click on back/forward/up to open in a new tab
201 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
202 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotToolBarActionMiddleClicked
);
203 toolBar()->installEventFilter(middleClickEventFilter
);
207 connect(KSycoca::self(), &KSycoca::databaseChanged
, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
209 QTimer::singleShot(0, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
211 m_fileItemActions
.setParentWidget(this);
212 connect(&m_fileItemActions
, &KFileItemActions::error
, this, [this](const QString
&errorMessage
) {
213 showErrorMessage(errorMessage
);
216 connect(GeneralSettings::self(), &GeneralSettings::splitViewChanged
, this, &DolphinMainWindow::slotSplitViewChanged
);
219 DolphinMainWindow::~DolphinMainWindow()
221 // This fixes a crash on Wayland when closing the mainwindow while another dialog is open.
222 disconnect(QGuiApplication::clipboard(), &QClipboard::dataChanged
, this, &DolphinMainWindow::updatePasteAction
);
225 QVector
<DolphinViewContainer
*> DolphinMainWindow::viewContainers() const
227 QVector
<DolphinViewContainer
*> viewContainers
;
229 for (int i
= 0; i
< m_tabWidget
->count(); ++i
) {
230 DolphinTabPage
*tabPage
= m_tabWidget
->tabPageAt(i
);
232 viewContainers
<< tabPage
->primaryViewContainer();
233 if (tabPage
->splitViewEnabled()) {
234 viewContainers
<< tabPage
->secondaryViewContainer();
237 return viewContainers
;
240 void DolphinMainWindow::openDirectories(const QList
<QUrl
> &dirs
, bool splitView
)
242 m_tabWidget
->openDirectories(dirs
, splitView
);
245 void DolphinMainWindow::openDirectories(const QStringList
&dirs
, bool splitView
)
247 openDirectories(QUrl::fromStringList(dirs
), splitView
);
250 void DolphinMainWindow::openFiles(const QList
<QUrl
> &files
, bool splitView
)
252 m_tabWidget
->openFiles(files
, splitView
);
255 bool DolphinMainWindow::isFoldersPanelEnabled() const
257 return actionCollection()->action(QStringLiteral("show_folders_panel"))->isChecked();
260 bool DolphinMainWindow::isInformationPanelEnabled() const
263 return actionCollection()->action(QStringLiteral("show_information_panel"))->isChecked();
269 bool DolphinMainWindow::isSplitViewEnabledInCurrentTab() const
271 return m_tabWidget
->currentTabPage()->splitViewEnabled();
274 void DolphinMainWindow::openFiles(const QStringList
&files
, bool splitView
)
276 openFiles(QUrl::fromStringList(files
), splitView
);
279 void DolphinMainWindow::activateWindow(const QString
&activationToken
)
281 window()->setAttribute(Qt::WA_NativeWindow
, true);
283 if (KWindowSystem::isPlatformWayland()) {
284 KWindowSystem::setCurrentXdgActivationToken(activationToken
);
285 } else if (KWindowSystem::isPlatformX11()) {
287 KStartupInfo::setNewStartupId(window()->windowHandle(), activationToken
.toUtf8());
291 KWindowSystem::activateWindow(window()->windowHandle());
294 bool DolphinMainWindow::isActiveWindow()
296 return window()->isActiveWindow();
299 void DolphinMainWindow::showCommand(CommandType command
)
301 DolphinStatusBar
*statusBar
= m_activeViewContainer
->statusBar();
303 case KIO::FileUndoManager::Copy
:
304 statusBar
->setText(i18nc("@info:status", "Successfully copied."));
306 case KIO::FileUndoManager::Move
:
307 statusBar
->setText(i18nc("@info:status", "Successfully moved."));
309 case KIO::FileUndoManager::Link
:
310 statusBar
->setText(i18nc("@info:status", "Successfully linked."));
312 case KIO::FileUndoManager::Trash
:
313 statusBar
->setText(i18nc("@info:status", "Successfully moved to trash."));
315 case KIO::FileUndoManager::Rename
:
316 statusBar
->setText(i18nc("@info:status", "Successfully renamed."));
319 case KIO::FileUndoManager::Mkdir
:
320 statusBar
->setText(i18nc("@info:status", "Created folder."));
328 void DolphinMainWindow::pasteIntoFolder()
330 m_activeViewContainer
->view()->pasteIntoFolder();
333 void DolphinMainWindow::changeUrl(const QUrl
&url
)
335 if (!KProtocolManager::supportsListing(url
)) {
336 // The URL navigator only checks for validity, not
337 // if the URL can be listed. An error message is
338 // shown due to DolphinViewContainer::restoreView().
342 m_activeViewContainer
->setUrl(url
);
343 updateFileAndEditActions();
348 Q_EMIT
urlChanged(url
);
351 void DolphinMainWindow::slotTerminalDirectoryChanged(const QUrl
&url
)
353 if (m_tearDownFromPlacesRequested
&& url
== QUrl::fromLocalFile(QDir::homePath())) {
354 m_placesPanel
->proceedWithTearDown();
355 m_tearDownFromPlacesRequested
= false;
358 m_activeViewContainer
->setAutoGrabFocus(false);
360 m_activeViewContainer
->setAutoGrabFocus(true);
363 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
365 KToggleAction
*editableLocationAction
= static_cast<KToggleAction
*>(actionCollection()->action(QStringLiteral("editable_location")));
366 editableLocationAction
->setChecked(editable
);
369 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
&selection
)
371 updateFileAndEditActions();
373 const int selectedUrlsCount
= m_tabWidget
->currentTabPage()->selectedItemsCount();
375 QAction
*compareFilesAction
= actionCollection()->action(QStringLiteral("compare_files"));
376 if (selectedUrlsCount
== 2) {
377 compareFilesAction
->setEnabled(isKompareInstalled());
379 compareFilesAction
->setEnabled(false);
382 Q_EMIT
selectionChanged(selection
);
385 void DolphinMainWindow::updateHistory()
387 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
388 const int index
= urlNavigator
->historyIndex();
390 QAction
*backAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Back
));
392 backAction
->setToolTip(i18nc("@info", "Go back"));
393 backAction
->setWhatsThis(i18nc("@info:whatsthis go back", "Return to the previously viewed folder."));
394 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
397 QAction
*forwardAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Forward
));
399 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
400 forwardAction
->setWhatsThis(xi18nc("@info:whatsthis go forward", "This undoes a <interface>Go|Back</interface> action."));
401 forwardAction
->setEnabled(index
> 0);
405 void DolphinMainWindow::updateFilterBarAction(bool show
)
407 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
408 toggleFilterBarAction
->setChecked(show
);
411 void DolphinMainWindow::openNewMainWindow()
413 Dolphin::openNewWindow({m_activeViewContainer
->url()}, this);
416 void DolphinMainWindow::openNewActivatedTab()
418 // keep browsers compatibility, new tab is always after last one
419 auto openNewTabAfterLastTabConfigured
= GeneralSettings::openNewTabAfterLastTab();
420 GeneralSettings::setOpenNewTabAfterLastTab(true);
421 m_tabWidget
->openNewActivatedTab();
422 GeneralSettings::setOpenNewTabAfterLastTab(openNewTabAfterLastTabConfigured
);
425 void DolphinMainWindow::addToPlaces()
430 // If nothing is selected, act on the current dir
431 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
432 url
= m_activeViewContainer
->url();
433 name
= m_activeViewContainer
->placesText();
435 const auto dirToAdd
= m_activeViewContainer
->view()->selectedItems().first();
436 url
= dirToAdd
.url();
437 name
= dirToAdd
.name();
441 if (m_activeViewContainer
->isSearchModeEnabled()) {
442 icon
= QStringLiteral("folder-saved-search-symbolic");
444 icon
= KIO::iconNameForUrl(url
);
446 DolphinPlacesModelSingleton::instance().placesModel()->addPlace(name
, url
, icon
);
450 void DolphinMainWindow::openNewTab(const QUrl
&url
)
452 m_tabWidget
->openNewTab(url
, QUrl());
455 void DolphinMainWindow::openNewTabAndActivate(const QUrl
&url
)
457 m_tabWidget
->openNewActivatedTab(url
, QUrl());
460 void DolphinMainWindow::openNewWindow(const QUrl
&url
)
462 Dolphin::openNewWindow({url
}, this);
465 void DolphinMainWindow::slotSplitViewChanged()
467 m_tabWidget
->currentTabPage()->setSplitViewEnabled(GeneralSettings::splitView(), WithAnimation
);
471 void DolphinMainWindow::openInNewTab()
473 const KFileItemList
&list
= m_activeViewContainer
->view()->selectedItems();
474 bool tabCreated
= false;
476 for (const KFileItem
&item
: list
) {
477 const QUrl
&url
= DolphinView::openItemAsFolderUrl(item
);
478 if (!url
.isEmpty()) {
484 // if no new tab has been created from the selection
485 // open the current directory in a new tab
487 openNewTab(m_activeViewContainer
->url());
491 void DolphinMainWindow::openInNewWindow()
495 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
496 if (list
.isEmpty()) {
497 newWindowUrl
= m_activeViewContainer
->url();
498 } else if (list
.count() == 1) {
499 const KFileItem
&item
= list
.first();
500 newWindowUrl
= DolphinView::openItemAsFolderUrl(item
);
503 if (!newWindowUrl
.isEmpty()) {
504 Dolphin::openNewWindow({newWindowUrl
}, this);
508 void DolphinMainWindow::openInSplitView(const QUrl
&url
)
510 QUrl newSplitViewUrl
= url
;
512 if (newSplitViewUrl
.isEmpty()) {
513 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
514 if (list
.count() == 1) {
515 const KFileItem
&item
= list
.first();
516 newSplitViewUrl
= DolphinView::openItemAsFolderUrl(item
);
520 if (newSplitViewUrl
.isEmpty()) {
524 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
525 if (tabPage
->splitViewEnabled()) {
526 tabPage
->switchActiveView();
527 tabPage
->activeViewContainer()->setUrl(newSplitViewUrl
);
529 tabPage
->setSplitViewEnabled(true, WithAnimation
, newSplitViewUrl
);
534 void DolphinMainWindow::showTarget()
536 const KFileItem link
= m_activeViewContainer
->view()->selectedItems().at(0);
537 const QUrl destinationUrl
= link
.url().resolved(QUrl(link
.linkDest()));
539 auto job
= KIO::stat(destinationUrl
, KIO::StatJob::SourceSide
, KIO::StatNoDetails
);
541 connect(job
, &KJob::finished
, this, [this, destinationUrl
](KJob
*job
) {
542 KIO::StatJob
*statJob
= static_cast<KIO::StatJob
*>(job
);
544 if (statJob
->error()) {
545 m_activeViewContainer
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
547 KIO::highlightInFileManager({destinationUrl
});
552 bool DolphinMainWindow::event(QEvent
*event
)
554 if (event
->type() == QEvent::ShortcutOverride
) {
555 const QKeyEvent
*keyEvent
= static_cast<QKeyEvent
*>(event
);
556 if (keyEvent
->key() == Qt::Key_Space
&& m_activeViewContainer
->view()->handleSpaceAsNormalKey()) {
562 return KXmlGuiWindow::event(event
);
565 void DolphinMainWindow::showEvent(QShowEvent
*event
)
567 KXmlGuiWindow::showEvent(event
);
569 if (!event
->spontaneous()) {
570 m_activeViewContainer
->view()->setFocus();
574 void DolphinMainWindow::closeEvent(QCloseEvent
*event
)
576 // Find out if Dolphin is closed directly by the user or
577 // by the session manager because the session is closed
578 bool closedByUser
= true;
579 if (qApp
->isSavingSession()) {
580 closedByUser
= false;
583 if (m_tabWidget
->count() > 1 && GeneralSettings::confirmClosingMultipleTabs() && !GeneralSettings::rememberOpenedTabs() && closedByUser
) {
584 // Ask the user if he really wants to quit and close all tabs.
585 // Open a confirmation dialog with 3 buttons:
586 // QDialogButtonBox::Yes -> Quit
587 // QDialogButtonBox::No -> Close only the current tab
588 // QDialogButtonBox::Cancel -> do nothing
589 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
590 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
591 dialog
->setModal(true);
592 QDialogButtonBox
*buttons
= new QDialogButtonBox(QDialogButtonBox::Yes
| QDialogButtonBox::No
| QDialogButtonBox::Cancel
);
593 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
),
594 KGuiItem(i18nc("@action:button 'Quit Dolphin' button", "&Quit %1", QGuiApplication::applicationDisplayName()),
595 QIcon::fromTheme(QStringLiteral("application-exit"))));
596 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("C&lose Current Tab"), QIcon::fromTheme(QStringLiteral("tab-close"))));
597 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
598 buttons
->button(QDialogButtonBox::Yes
)->setDefault(true);
600 bool doNotAskAgainCheckboxResult
= false;
602 const auto result
= KMessageBox::createKMessageBox(dialog
,
604 QMessageBox::Warning
,
605 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
607 i18n("Do not ask again"),
608 &doNotAskAgainCheckboxResult
,
609 KMessageBox::Notify
);
611 if (doNotAskAgainCheckboxResult
) {
612 GeneralSettings::setConfirmClosingMultipleTabs(false);
616 case QDialogButtonBox::Yes
:
619 case QDialogButtonBox::No
:
620 // Close only the current tab
621 m_tabWidget
->closeTab();
629 if (m_terminalPanel
&& m_terminalPanel
->hasProgramRunning() && GeneralSettings::confirmClosingTerminalRunningProgram() && closedByUser
) {
630 // Ask if the user really wants to quit Dolphin with a program that is still running in the Terminal panel
631 // Open a confirmation dialog with 3 buttons:
632 // QDialogButtonBox::Yes -> Quit
633 // QDialogButtonBox::No -> Show Terminal Panel
634 // QDialogButtonBox::Cancel -> do nothing
635 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
636 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
637 dialog
->setModal(true);
638 auto standardButtons
= QDialogButtonBox::Yes
| QDialogButtonBox::Cancel
;
639 if (!m_terminalPanel
->isVisible()) {
640 standardButtons
|= QDialogButtonBox::No
;
642 QDialogButtonBox
*buttons
= new QDialogButtonBox(standardButtons
);
643 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KStandardGuiItem::quit());
644 if (!m_terminalPanel
->isVisible()) {
645 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("Show &Terminal Panel"), QIcon::fromTheme(QStringLiteral("dialog-scripts"))));
647 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
649 bool doNotAskAgainCheckboxResult
= false;
651 const auto result
= KMessageBox::createKMessageBox(
654 QMessageBox::Warning
,
655 i18n("The program '%1' is still running in the Terminal panel. Are you sure you want to quit?", m_terminalPanel
->runningProgramName()),
657 i18n("Do not ask again"),
658 &doNotAskAgainCheckboxResult
,
659 KMessageBox::Notify
| KMessageBox::Dangerous
);
661 if (doNotAskAgainCheckboxResult
) {
662 GeneralSettings::setConfirmClosingTerminalRunningProgram(false);
666 case QDialogButtonBox::Yes
:
669 case QDialogButtonBox::No
:
670 actionCollection()->action("show_terminal_panel")->trigger();
671 // Do not quit, ignore quit event
679 if (GeneralSettings::rememberOpenedTabs()) {
680 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
681 KConfig
*config
= KConfigGui::sessionConfig();
682 saveGlobalProperties(config
);
683 savePropertiesInternal(config
, 1);
687 GeneralSettings::setVersion(CurrentDolphinVersion
);
688 GeneralSettings::self()->save();
690 KXmlGuiWindow::closeEvent(event
);
693 void DolphinMainWindow::saveProperties(KConfigGroup
&group
)
695 m_tabWidget
->saveProperties(group
);
698 void DolphinMainWindow::readProperties(const KConfigGroup
&group
)
700 m_tabWidget
->readProperties(group
);
703 void DolphinMainWindow::updateNewMenu()
705 m_newFileMenu
->checkUpToDate();
706 m_newFileMenu
->setWorkingDirectory(activeViewContainer()->url());
709 void DolphinMainWindow::createDirectory()
711 m_newFileMenu
->setWorkingDirectory(activeViewContainer()->url());
712 m_newFileMenu
->createDirectory();
715 void DolphinMainWindow::quit()
720 void DolphinMainWindow::showErrorMessage(const QString
&message
)
722 m_activeViewContainer
->showMessage(message
, DolphinViewContainer::Error
);
725 void DolphinMainWindow::slotUndoAvailable(bool available
)
727 QAction
*undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
729 undoAction
->setEnabled(available
);
733 void DolphinMainWindow::slotUndoTextChanged(const QString
&text
)
735 QAction
*undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
737 undoAction
->setText(text
);
741 void DolphinMainWindow::undo()
744 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
745 KIO::FileUndoManager::self()->undo();
748 void DolphinMainWindow::cut()
750 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
751 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CutContents
);
753 m_activeViewContainer
->view()->cutSelectedItemsToClipboard();
754 m_activeViewContainer
->setSelectionModeEnabled(false);
758 void DolphinMainWindow::copy()
760 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
761 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CopyContents
);
763 m_activeViewContainer
->view()->copySelectedItemsToClipboard();
764 m_activeViewContainer
->setSelectionModeEnabled(false);
768 void DolphinMainWindow::paste()
770 m_activeViewContainer
->view()->paste();
773 void DolphinMainWindow::find()
775 m_activeViewContainer
->setSearchModeEnabled(true);
778 void DolphinMainWindow::updateSearchAction()
780 QAction
*toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
781 toggleSearchAction
->setChecked(m_activeViewContainer
->isSearchModeEnabled());
784 void DolphinMainWindow::updatePasteAction()
786 QAction
*pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
787 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
788 pasteAction
->setEnabled(pasteInfo
.first
);
789 pasteAction
->setText(pasteInfo
.second
);
792 void DolphinMainWindow::slotDirectoryLoadingCompleted()
797 void DolphinMainWindow::slotToolBarActionMiddleClicked(QAction
*action
)
799 if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Back
))) {
801 } else if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Forward
))) {
803 } else if (action
== actionCollection()->action(QStringLiteral("go_up"))) {
805 } else if (action
== actionCollection()->action(QStringLiteral("go_home"))) {
810 QAction
*DolphinMainWindow::urlNavigatorHistoryAction(const KUrlNavigator
*urlNavigator
, int historyIndex
, QObject
*parent
)
812 const QUrl url
= urlNavigator
->locationUrl(historyIndex
);
814 QString text
= url
.toDisplayString(QUrl::PreferLocalFile
);
816 if (!urlNavigator
->showFullPath()) {
817 const KFilePlacesModel
*placesModel
= DolphinPlacesModelSingleton::instance().placesModel();
819 const QModelIndex closestIdx
= placesModel
->closestItem(url
);
820 if (closestIdx
.isValid()) {
821 const QUrl placeUrl
= placesModel
->url(closestIdx
);
823 text
= placesModel
->text(closestIdx
);
825 QString pathInsidePlace
= url
.path().mid(placeUrl
.path().length());
827 if (!pathInsidePlace
.isEmpty() && !pathInsidePlace
.startsWith(QLatin1Char('/'))) {
828 pathInsidePlace
.prepend(QLatin1Char('/'));
831 if (pathInsidePlace
!= QLatin1Char('/')) {
832 text
.append(pathInsidePlace
);
837 QAction
*action
= new QAction(QIcon::fromTheme(KIO::iconNameForUrl(url
)), text
, parent
);
838 action
->setData(historyIndex
);
842 void DolphinMainWindow::slotAboutToShowBackPopupMenu()
844 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
846 QMenu
*menu
= m_backAction
->popupMenu();
848 for (int i
= urlNavigator
->historyIndex() + 1; i
< urlNavigator
->historySize() && entries
< MaxNumberOfNavigationentries
; ++i
, ++entries
) {
849 QAction
*action
= urlNavigatorHistoryAction(urlNavigator
, i
, menu
);
850 menu
->addAction(action
);
854 void DolphinMainWindow::slotGoBack(QAction
*action
)
856 int gotoIndex
= action
->data().value
<int>();
857 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
858 for (int i
= gotoIndex
- urlNavigator
->historyIndex(); i
> 0; --i
) {
863 void DolphinMainWindow::slotBackForwardActionMiddleClicked(QAction
*action
)
866 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
867 openNewTab(urlNavigator
->locationUrl(action
->data().value
<int>()));
871 void DolphinMainWindow::slotAboutToShowForwardPopupMenu()
873 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
875 QMenu
*menu
= m_forwardAction
->popupMenu();
876 for (int i
= urlNavigator
->historyIndex() - 1; i
>= 0 && entries
< MaxNumberOfNavigationentries
; --i
, ++entries
) {
877 QAction
*action
= urlNavigatorHistoryAction(urlNavigator
, i
, menu
);
878 menu
->addAction(action
);
882 void DolphinMainWindow::slotGoForward(QAction
*action
)
884 int gotoIndex
= action
->data().value
<int>();
885 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
886 for (int i
= urlNavigator
->historyIndex() - gotoIndex
; i
> 0; --i
) {
891 void DolphinMainWindow::slotSetSelectionMode(bool enabled
, SelectionMode::BottomBar::Contents bottomBarContents
)
893 m_activeViewContainer
->setSelectionModeEnabled(enabled
, actionCollection(), bottomBarContents
);
896 void DolphinMainWindow::selectAll()
900 // if the URL navigator is editable and focused, select the whole
901 // URL instead of all items of the view
903 KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigator();
904 QLineEdit
*lineEdit
= urlNavigator
->editor()->lineEdit();
905 const bool selectUrl
= urlNavigator
->isUrlEditable() && lineEdit
->hasFocus();
907 lineEdit
->selectAll();
909 m_activeViewContainer
->view()->selectAll();
913 void DolphinMainWindow::invertSelection()
916 m_activeViewContainer
->view()->invertSelection();
919 void DolphinMainWindow::toggleSplitView()
921 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
922 tabPage
->setSplitViewEnabled(!tabPage
->splitViewEnabled(), WithAnimation
);
923 m_tabWidget
->updateTabName(m_tabWidget
->indexOf(tabPage
));
927 void DolphinMainWindow::toggleSplitStash()
929 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
930 tabPage
->setSplitViewEnabled(false, WithAnimation
);
931 tabPage
->setSplitViewEnabled(true, WithAnimation
, QUrl("stash:/"));
934 void DolphinMainWindow::copyToInactiveSplitView()
936 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
937 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CopyToOtherViewContents
);
939 m_tabWidget
->copyToInactiveSplitView();
940 m_activeViewContainer
->setSelectionModeEnabled(false);
944 void DolphinMainWindow::moveToInactiveSplitView()
946 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
947 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::MoveToOtherViewContents
);
949 m_tabWidget
->moveToInactiveSplitView();
950 m_activeViewContainer
->setSelectionModeEnabled(false);
954 void DolphinMainWindow::reloadView()
957 m_activeViewContainer
->reload();
958 m_activeViewContainer
->statusBar()->updateSpaceInfo();
961 void DolphinMainWindow::stopLoading()
963 m_activeViewContainer
->view()->stopLoading();
966 void DolphinMainWindow::enableStopAction()
968 actionCollection()->action(QStringLiteral("stop"))->setEnabled(true);
971 void DolphinMainWindow::disableStopAction()
973 actionCollection()->action(QStringLiteral("stop"))->setEnabled(false);
976 void DolphinMainWindow::toggleSelectionMode()
978 const bool checked
= !m_activeViewContainer
->isSelectionModeEnabled();
980 m_activeViewContainer
->setSelectionModeEnabled(checked
, actionCollection(), SelectionMode::BottomBar::Contents::GeneralContents
);
981 actionCollection()->action(QStringLiteral("toggle_selection_mode"))->setChecked(checked
);
984 void DolphinMainWindow::showFilterBar()
986 m_activeViewContainer
->setFilterBarVisible(true);
989 void DolphinMainWindow::toggleFilterBar()
991 const bool checked
= !m_activeViewContainer
->isFilterBarVisible();
992 m_activeViewContainer
->setFilterBarVisible(checked
);
994 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
995 toggleFilterBarAction
->setChecked(checked
);
998 void DolphinMainWindow::toggleEditLocation()
1002 QAction
*action
= actionCollection()->action(QStringLiteral("editable_location"));
1003 KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigator();
1004 urlNavigator
->setUrlEditable(action
->isChecked());
1007 void DolphinMainWindow::replaceLocation()
1009 KUrlNavigator
*navigator
= m_activeViewContainer
->urlNavigator();
1010 QLineEdit
*lineEdit
= navigator
->editor()->lineEdit();
1012 // If the text field currently has focus and everything is selected,
1013 // pressing the keyboard shortcut returns the whole thing to breadcrumb mode
1014 if (navigator
->isUrlEditable() && lineEdit
->hasFocus() && lineEdit
->selectedText() == lineEdit
->text()) {
1015 navigator
->setUrlEditable(false);
1017 navigator
->setUrlEditable(true);
1018 navigator
->setFocus();
1019 lineEdit
->selectAll();
1023 void DolphinMainWindow::togglePanelLockState()
1025 const bool newLockState
= !GeneralSettings::lockPanels();
1026 const auto childrenObjects
= children();
1027 for (QObject
*child
: childrenObjects
) {
1028 DolphinDockWidget
*dock
= qobject_cast
<DolphinDockWidget
*>(child
);
1030 dock
->setLocked(newLockState
);
1034 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(newLockState
);
1036 GeneralSettings::setLockPanels(newLockState
);
1039 void DolphinMainWindow::slotTerminalPanelVisibilityChanged()
1041 if (m_terminalPanel
->isHiddenInVisibleWindow() && m_activeViewContainer
) {
1042 m_activeViewContainer
->view()->setFocus();
1046 void DolphinMainWindow::goBack()
1048 DolphinUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
1049 urlNavigator
->goBack();
1051 if (urlNavigator
->locationState().isEmpty()) {
1052 // An empty location state indicates a redirection URL,
1053 // which must be skipped too
1054 urlNavigator
->goBack();
1058 void DolphinMainWindow::goForward()
1060 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goForward();
1063 void DolphinMainWindow::goUp()
1065 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goUp();
1068 void DolphinMainWindow::goHome()
1070 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goHome();
1073 void DolphinMainWindow::goBackInNewTab()
1075 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
1076 const int index
= urlNavigator
->historyIndex() + 1;
1077 openNewTab(urlNavigator
->locationUrl(index
));
1080 void DolphinMainWindow::goForwardInNewTab()
1082 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
1083 const int index
= urlNavigator
->historyIndex() - 1;
1084 openNewTab(urlNavigator
->locationUrl(index
));
1087 void DolphinMainWindow::goUpInNewTab()
1089 const QUrl currentUrl
= activeViewContainer()->urlNavigator()->locationUrl();
1090 openNewTab(KIO::upUrl(currentUrl
));
1093 void DolphinMainWindow::goHomeInNewTab()
1095 openNewTab(Dolphin::homeUrl());
1098 void DolphinMainWindow::compareFiles()
1100 const KFileItemList items
= m_tabWidget
->currentTabPage()->selectedItems();
1101 if (items
.count() != 2) {
1102 // The action is disabled in this case, but it could have been triggered
1103 // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
1107 QUrl urlA
= items
.at(0).url();
1108 QUrl urlB
= items
.at(1).url();
1110 QString
command(QStringLiteral("kompare -c \""));
1111 command
.append(urlA
.toDisplayString(QUrl::PreferLocalFile
));
1112 command
.append("\" \"");
1113 command
.append(urlB
.toDisplayString(QUrl::PreferLocalFile
));
1114 command
.append('\"');
1116 KIO::CommandLauncherJob
*job
= new KIO::CommandLauncherJob(command
, this);
1117 job
->setDesktopName(QStringLiteral("org.kde.kompare"));
1121 void DolphinMainWindow::toggleShowMenuBar()
1123 const bool visible
= menuBar()->isVisible();
1124 menuBar()->setVisible(!visible
);
1127 QPointer
<QAction
> DolphinMainWindow::preferredSearchTool()
1129 m_searchTools
.clear();
1131 KService::Ptr kfind
= KService::serviceByDesktopName(QStringLiteral("org.kde.kfind"));
1137 auto *action
= new QAction(QIcon::fromTheme(kfind
->icon()), kfind
->name(), this);
1139 connect(action
, &QAction::triggered
, this, [kfind
] {
1140 auto *job
= new KIO::ApplicationLauncherJob(kfind
);
1147 void DolphinMainWindow::updateOpenPreferredSearchToolAction()
1149 QAction
*openPreferredSearchTool
= actionCollection()->action(QStringLiteral("open_preferred_search_tool"));
1150 if (!openPreferredSearchTool
) {
1153 QPointer
<QAction
> tool
= preferredSearchTool();
1155 openPreferredSearchTool
->setVisible(true);
1156 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open %1", tool
->text()));
1157 // Only override with the app icon if it is the default, i.e. the user hasn't configured one manually
1158 // https://bugs.kde.org/show_bug.cgi?id=442815
1159 if (openPreferredSearchTool
->icon().name() == QLatin1String("search")) {
1160 openPreferredSearchTool
->setIcon(tool
->icon());
1163 openPreferredSearchTool
->setVisible(false);
1164 // still visible in Shortcuts configuration window
1165 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1166 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1170 void DolphinMainWindow::openPreferredSearchTool()
1172 QPointer
<QAction
> tool
= preferredSearchTool();
1178 void DolphinMainWindow::openTerminal()
1180 openTerminalJob(m_activeViewContainer
->url());
1183 void DolphinMainWindow::openTerminalHere()
1185 QList
<QUrl
> urls
= {};
1187 const auto selectedItems
= m_activeViewContainer
->view()->selectedItems();
1188 for (const KFileItem
&item
: selectedItems
) {
1189 QUrl url
= item
.targetUrl();
1190 if (item
.isFile()) {
1191 url
.setPath(QFileInfo(url
.path()).absolutePath());
1193 if (!urls
.contains(url
)) {
1198 // No items are selected. Open a terminal window for the current location.
1199 if (urls
.count() == 0) {
1204 if (urls
.count() > 5) {
1205 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());
1206 const int answer
= KMessageBox::warningContinueCancel(
1210 KGuiItem(i18ncp("@action:button", "Open %1 Terminal", "Open %1 Terminals", urls
.count()), QStringLiteral("utilities-terminal")),
1211 KStandardGuiItem::cancel(),
1212 QStringLiteral("ConfirmOpenManyTerminals"));
1213 if (answer
!= KMessageBox::PrimaryAction
&& answer
!= KMessageBox::Continue
) {
1218 for (const QUrl
&url
: std::as_const(urls
)) {
1219 openTerminalJob(url
);
1223 void DolphinMainWindow::openTerminalJob(const QUrl
&url
)
1225 if (url
.isLocalFile()) {
1226 auto job
= new KTerminalLauncherJob(QString());
1227 job
->setWorkingDirectory(url
.toLocalFile());
1232 // Not a local file, with protocol Class ":local", try stat'ing
1233 if (KProtocolInfo::protocolClass(url
.scheme()) == QLatin1String(":local")) {
1234 KIO::StatJob
*job
= KIO::mostLocalUrl(url
);
1235 KJobWidgets::setWindow(job
, this);
1236 connect(job
, &KJob::result
, this, [job
]() {
1238 if (!job
->error()) {
1239 statUrl
= job
->mostLocalUrl();
1242 auto job
= new KTerminalLauncherJob(QString());
1243 job
->setWorkingDirectory(statUrl
.isLocalFile() ? statUrl
.toLocalFile() : QDir::homePath());
1250 // Nothing worked, just use $HOME
1251 auto job
= new KTerminalLauncherJob(QString());
1252 job
->setWorkingDirectory(QDir::homePath());
1256 void DolphinMainWindow::editSettings()
1258 if (!m_settingsDialog
) {
1259 DolphinViewContainer
*container
= activeViewContainer();
1260 container
->view()->writeSettings();
1262 const QUrl url
= container
->url();
1263 DolphinSettingsDialog
*settingsDialog
= new DolphinSettingsDialog(url
, this, actionCollection());
1264 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, this, &DolphinMainWindow::refreshViews
);
1265 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, &DolphinUrlNavigatorsController::slotReadSettings
);
1266 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1267 settingsDialog
->show();
1268 m_settingsDialog
= settingsDialog
;
1270 m_settingsDialog
.data()->raise();
1274 void DolphinMainWindow::handleUrl(const QUrl
&url
)
1276 delete m_lastHandleUrlOpenJob
;
1277 m_lastHandleUrlOpenJob
= nullptr;
1279 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1280 activeViewContainer()->setUrl(url
);
1282 m_lastHandleUrlOpenJob
= new KIO::OpenUrlJob(url
);
1283 m_lastHandleUrlOpenJob
->setUiDelegate(KIO::createDefaultJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
1284 m_lastHandleUrlOpenJob
->setShowOpenOrExecuteDialog(true);
1286 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::mimeTypeFound
, this, [this, url
](const QString
&mimetype
) {
1287 if (mimetype
== QLatin1String("inode/directory")) {
1288 // If it's a dir, we'll take it from here
1289 m_lastHandleUrlOpenJob
->kill();
1290 m_lastHandleUrlOpenJob
= nullptr;
1291 activeViewContainer()->setUrl(url
);
1295 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::result
, this, [this]() {
1296 m_lastHandleUrlOpenJob
= nullptr;
1299 m_lastHandleUrlOpenJob
->start();
1303 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1305 // trash:/ is writable but we don't want to create new items in it.
1306 // TODO: remove the trash check once https://phabricator.kde.org/T8234 is implemented
1307 newFileMenu()->setEnabled(isFolderWritable
&& m_activeViewContainer
->url().scheme() != QLatin1String("trash"));
1310 void DolphinMainWindow::openContextMenu(const QPoint
&pos
, const KFileItem
&item
, const KFileItemList
&selectedItems
, const QUrl
&url
)
1312 QPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, item
, selectedItems
, url
, &m_fileItemActions
);
1313 contextMenu
->exec(pos
);
1315 // Delete the menu, unless it has been deleted in its own nested event loop already.
1317 contextMenu
->deleteLater();
1321 QMenu
*DolphinMainWindow::createPopupMenu()
1323 QMenu
*menu
= KXmlGuiWindow::createPopupMenu();
1325 menu
->addSeparator();
1326 menu
->addAction(actionCollection()->action(QStringLiteral("lock_panels")));
1331 void DolphinMainWindow::updateHamburgerMenu()
1333 KActionCollection
*ac
= actionCollection();
1334 auto hamburgerMenu
= static_cast<KHamburgerMenu
*>(ac
->action(KStandardAction::name(KStandardAction::HamburgerMenu
)));
1335 auto menu
= hamburgerMenu
->menu();
1337 menu
= new QMenu(this);
1338 hamburgerMenu
->setMenu(menu
);
1339 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("basic_actions"))->menu());
1340 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("zoom"))->menu());
1344 const QList
<QAction
*> toolbarActions
= toolBar()->actions();
1346 if (!toolBar()->isVisible()) {
1347 // If neither the menu bar nor the toolbar are visible, these actions should be available.
1348 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)));
1349 menu
->addAction(toolBarMenuAction());
1350 menu
->addSeparator();
1353 // This group of actions (until the next separator) contains all the most basic actions
1354 // necessary to use Dolphin effectively.
1355 menu
->addAction(ac
->action(QStringLiteral("go_back")));
1356 menu
->addAction(ac
->action(QStringLiteral("go_forward")));
1358 menu
->addMenu(m_newFileMenu
->menu());
1359 if (!toolBar()->isVisible() || !toolbarActions
.contains(ac
->action(QStringLiteral("toggle_selection_mode_tool_bar")))) {
1360 menu
->addAction(ac
->action(QStringLiteral("toggle_selection_mode")));
1362 menu
->addAction(ac
->action(QStringLiteral("basic_actions")));
1363 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Undo
)));
1364 if (!toolBar()->isVisible()
1365 || (!toolbarActions
.contains(ac
->action(QStringLiteral("toggle_search")))
1366 && !toolbarActions
.contains(ac
->action(QStringLiteral("open_preferred_search_tool"))))) {
1367 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Find
)));
1368 // This way a search action will only be added if none of the three available
1369 // search actions is present on the toolbar.
1371 if (!toolBar()->isVisible() || !toolbarActions
.contains(ac
->action(QStringLiteral("toggle_filter")))) {
1372 menu
->addAction(ac
->action(QStringLiteral("show_filter_bar")));
1373 // This way a filter action will only be added if none of the two available
1374 // filter actions is present on the toolbar.
1376 menu
->addSeparator();
1378 // The second group of actions (up until the next separator) contains actions for opening
1379 // additional views to interact with the file system.
1380 menu
->addAction(ac
->action(QStringLiteral("file_new")));
1381 menu
->addAction(ac
->action(QStringLiteral("new_tab")));
1382 if (ac
->action(QStringLiteral("undo_close_tab"))->isEnabled()) {
1383 menu
->addAction(ac
->action(QStringLiteral("closed_tabs")));
1385 menu
->addAction(ac
->action(QStringLiteral("open_terminal")));
1386 menu
->addSeparator();
1388 // The third group contains actions to change what one sees in the view
1389 // and to change the more general UI.
1390 if (!toolBar()->isVisible()
1391 || (!toolbarActions
.contains(ac
->action(QStringLiteral("icons"))) && !toolbarActions
.contains(ac
->action(QStringLiteral("compact")))
1392 && !toolbarActions
.contains(ac
->action(QStringLiteral("details"))) && !toolbarActions
.contains(ac
->action(QStringLiteral("view_mode"))))) {
1393 menu
->addAction(ac
->action(QStringLiteral("view_mode")));
1395 menu
->addAction(ac
->action(QStringLiteral("show_hidden_files")));
1396 menu
->addAction(ac
->action(QStringLiteral("sort")));
1397 menu
->addAction(ac
->action(QStringLiteral("additional_info")));
1398 if (!GeneralSettings::showStatusBar() || !GeneralSettings::showZoomSlider()) {
1399 menu
->addAction(ac
->action(QStringLiteral("zoom")));
1401 menu
->addAction(ac
->action(QStringLiteral("panels")));
1403 // The "Configure" menu is not added to the actionCollection() because there is hardly
1404 // a good reason for users to put it on their toolbar.
1405 auto configureMenu
= menu
->addMenu(QIcon::fromTheme(QStringLiteral("configure")), i18nc("@action:inmenu menu for configure actions", "Configure"));
1406 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
)));
1407 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)));
1408 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)));
1409 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Preferences
)));
1410 hamburgerMenu
->hideActionsOf(configureMenu
);
1413 void DolphinMainWindow::slotPlaceActivated(const QUrl
&url
)
1415 DolphinViewContainer
*view
= activeViewContainer();
1417 if (view
->url() == url
) {
1418 view
->clearFilterBar(); // Fixes bug 259382.
1420 // We can end up here if the user clicked a device in the Places Panel
1421 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
1424 view
->disableUrlNavigatorSelectionRequests();
1426 view
->enableUrlNavigatorSelectionRequests();
1430 void DolphinMainWindow::closedTabsCountChanged(unsigned int count
)
1432 actionCollection()->action(QStringLiteral("undo_close_tab"))->setEnabled(count
> 0);
1435 void DolphinMainWindow::activeViewChanged(DolphinViewContainer
*viewContainer
)
1437 DolphinViewContainer
*oldViewContainer
= m_activeViewContainer
;
1438 Q_ASSERT(viewContainer
);
1440 m_activeViewContainer
= viewContainer
;
1442 if (oldViewContainer
) {
1443 const QAction
*toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
1444 toggleSearchAction
->disconnect(oldViewContainer
);
1446 // Disconnect all signals between the old view container (container,
1447 // view and url navigator) and main window.
1448 oldViewContainer
->disconnect(this);
1449 oldViewContainer
->view()->disconnect(this);
1450 oldViewContainer
->urlNavigatorInternalWithHistory()->disconnect(this);
1451 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
1452 navigators
->primaryUrlNavigator()->disconnect(this);
1453 if (auto secondaryUrlNavigator
= navigators
->secondaryUrlNavigator()) {
1454 secondaryUrlNavigator
->disconnect(this);
1457 // except the requestItemInfo so that on hover the information panel can still be updated
1458 connect(oldViewContainer
->view(), &DolphinView::requestItemInfo
, this, &DolphinMainWindow::requestItemInfo
);
1460 // Disconnect other slots.
1461 disconnect(oldViewContainer
,
1462 &DolphinViewContainer::selectionModeChanged
,
1463 actionCollection()->action(QStringLiteral("toggle_selection_mode")),
1464 &QAction::setChecked
);
1467 connectViewSignals(viewContainer
);
1469 m_actionHandler
->setCurrentView(viewContainer
->view());
1472 updateFileAndEditActions();
1473 updatePasteAction();
1474 updateViewActions();
1476 updateSearchAction();
1478 const QUrl url
= viewContainer
->url();
1479 Q_EMIT
urlChanged(url
);
1482 void DolphinMainWindow::tabCountChanged(int count
)
1484 const bool enableTabActions
= (count
> 1);
1485 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1486 actionCollection()->action(QStringLiteral("activate_tab_%1").arg(i
))->setEnabled(enableTabActions
);
1488 actionCollection()->action(QStringLiteral("activate_last_tab"))->setEnabled(enableTabActions
);
1489 actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions
);
1490 actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions
);
1493 void DolphinMainWindow::updateWindowTitle()
1495 const QString newTitle
= m_activeViewContainer
->captionWindowTitle();
1496 if (windowTitle() != newTitle
) {
1497 setWindowTitle(newTitle
);
1501 void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString
&mountPath
)
1503 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1504 setViewsToHomeIfMountPathOpen(mountPath
);
1507 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectoryIsChildOf(mountPath
)) {
1508 m_tearDownFromPlacesRequested
= true;
1509 m_terminalPanel
->goHome();
1510 // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged
1512 m_placesPanel
->proceedWithTearDown();
1516 void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString
&mountPath
)
1518 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1519 setViewsToHomeIfMountPathOpen(mountPath
);
1522 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectoryIsChildOf(mountPath
)) {
1523 m_tearDownFromPlacesRequested
= false;
1524 m_terminalPanel
->goHome();
1528 void DolphinMainWindow::slotKeyBindings()
1530 KShortcutsDialog
dialog(KShortcutsEditor::AllActions
, KShortcutsEditor::LetterShortcutsAllowed
, this);
1531 dialog
.addCollection(actionCollection());
1532 if (m_terminalPanel
) {
1533 KActionCollection
*konsolePartActionCollection
= m_terminalPanel
->actionCollection();
1534 if (konsolePartActionCollection
) {
1535 dialog
.addCollection(konsolePartActionCollection
, QStringLiteral("KonsolePart"));
1541 void DolphinMainWindow::setViewsToHomeIfMountPathOpen(const QString
&mountPath
)
1543 const QVector
<DolphinViewContainer
*> theViewContainers
= viewContainers();
1544 for (DolphinViewContainer
*viewContainer
: theViewContainers
) {
1545 if (viewContainer
&& viewContainer
->url().toLocalFile().startsWith(mountPath
)) {
1546 viewContainer
->setUrl(QUrl::fromLocalFile(QDir::homePath()));
1549 disconnect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, nullptr, nullptr);
1552 void DolphinMainWindow::setupActions()
1554 auto hamburgerMenuAction
= KStandardAction::hamburgerMenu(nullptr, nullptr, actionCollection());
1556 // setup 'File' menu
1557 m_newFileMenu
= new DolphinNewFileMenu(nullptr, this);
1558 actionCollection()->addAction(QStringLiteral("new_menu"), m_newFileMenu
);
1559 QMenu
*menu
= m_newFileMenu
->menu();
1560 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1561 menu
->setIcon(QIcon::fromTheme(QStringLiteral("list-add")));
1562 m_newFileMenu
->setPopupMode(QToolButton::InstantPopup
);
1563 connect(menu
, &QMenu::aboutToShow
, this, &DolphinMainWindow::updateNewMenu
);
1565 QAction
*newWindow
= KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow
, actionCollection());
1566 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1567 newWindow
->setToolTip(i18nc("@info", "Open a new Dolphin window"));
1568 newWindow
->setWhatsThis(xi18nc("@info:whatsthis",
1570 "window just like this one with the current location and view."
1571 "<nl/>You can drag and drop items between windows."));
1572 newWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1574 QAction
*newTab
= actionCollection()->addAction(QStringLiteral("new_tab"));
1575 newTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1576 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1577 newTab
->setWhatsThis(xi18nc("@info:whatsthis",
1579 "<emphasis>Tab</emphasis> with the current location and view.<nl/>"
1580 "A tab is an additional view within this window. "
1581 "You can drag and drop items between tabs."));
1582 actionCollection()->setDefaultShortcut(newTab
, Qt::CTRL
| Qt::Key_T
);
1583 connect(newTab
, &QAction::triggered
, this, &DolphinMainWindow::openNewActivatedTab
);
1585 QAction
*addToPlaces
= actionCollection()->addAction(QStringLiteral("add_to_places"));
1586 addToPlaces
->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new")));
1587 addToPlaces
->setText(i18nc("@action:inmenu Add current folder to places", "Add to Places"));
1588 addToPlaces
->setWhatsThis(xi18nc("@info:whatsthis",
1589 "This adds the selected folder "
1590 "to the Places panel."));
1591 connect(addToPlaces
, &QAction::triggered
, this, &DolphinMainWindow::addToPlaces
);
1593 QAction
*closeTab
= KStandardAction::close(m_tabWidget
, QOverload
<>::of(&DolphinTabWidget::closeTab
), actionCollection());
1594 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1595 closeTab
->setWhatsThis(i18nc("@info:whatsthis",
1597 "currently viewed tab. If no more tabs are left this window "
1598 "will close instead."));
1600 QAction
*quitAction
= KStandardAction::quit(this, &DolphinMainWindow::quit
, actionCollection());
1601 quitAction
->setWhatsThis(i18nc("@info:whatsthis quit", "This closes this window."));
1603 // setup 'Edit' menu
1604 KStandardAction::undo(this, &DolphinMainWindow::undo
, actionCollection());
1606 // i18n: This will be the last paragraph for the whatsthis for all three:
1607 // Cut, Copy and Paste
1608 const QString cutCopyPastePara
= xi18nc("@info:whatsthis",
1609 "<para><emphasis>Cut, "
1610 "Copy</emphasis> and <emphasis>Paste</emphasis> work between many "
1611 "applications and are among the most used commands. That's why their "
1612 "<emphasis>keyboard shortcuts</emphasis> are prominently placed right "
1613 "next to each other on the keyboard: <shortcut>Ctrl+X</shortcut>, "
1614 "<shortcut>Ctrl+C</shortcut> and <shortcut>Ctrl+V</shortcut>.</para>");
1615 QAction
*cutAction
= KStandardAction::cut(this, &DolphinMainWindow::cut
, actionCollection());
1616 m_actionTextHelper
->registerTextWhenNothingIsSelected(cutAction
, i18nc("@action", "Cut…"));
1617 cutAction
->setWhatsThis(xi18nc("@info:whatsthis cut",
1618 "This copies the items "
1619 "in your current selection to the <emphasis>clipboard</emphasis>.<nl/>"
1620 "Use the <emphasis>Paste</emphasis> action afterwards to copy them from "
1621 "the clipboard to a new location. The items will be removed from their "
1622 "initial location.")
1623 + cutCopyPastePara
);
1624 QAction
*copyAction
= KStandardAction::copy(this, &DolphinMainWindow::copy
, actionCollection());
1625 m_actionTextHelper
->registerTextWhenNothingIsSelected(copyAction
, i18nc("@action", "Copy…"));
1626 copyAction
->setWhatsThis(xi18nc("@info:whatsthis copy",
1628 "items in your current selection to the <emphasis>clipboard</emphasis>."
1629 "<nl/>Use the <emphasis>Paste</emphasis> action afterwards to copy them "
1630 "from the clipboard to a new location.")
1631 + cutCopyPastePara
);
1632 QAction
*paste
= KStandardAction::paste(this, &DolphinMainWindow::paste
, actionCollection());
1633 // The text of the paste-action is modified dynamically by Dolphin
1634 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1635 // due to the long text, the text "Paste" is used:
1636 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1637 paste
->setWhatsThis(xi18nc("@info:whatsthis paste",
1638 "This copies the items from "
1639 "your <emphasis>clipboard</emphasis> to the currently viewed folder.<nl/>"
1640 "If the items were added to the clipboard by the <emphasis>Cut</emphasis> "
1641 "action they are removed from their old location.")
1642 + cutCopyPastePara
);
1644 QAction
*copyToOtherViewAction
= actionCollection()->addAction(QStringLiteral("copy_to_inactive_split_view"));
1645 copyToOtherViewAction
->setText(i18nc("@action:inmenu", "Copy to Other View"));
1646 m_actionTextHelper
->registerTextWhenNothingIsSelected(copyToOtherViewAction
, i18nc("@action:inmenu", "Copy to Other View…"));
1647 copyToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Copy",
1648 "This copies the selected items from "
1649 "the <emphasis>active</emphasis> view to the inactive split view."));
1650 copyToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
1651 copyToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Copy to Inactive Split View"));
1652 actionCollection()->setDefaultShortcut(copyToOtherViewAction
, Qt::SHIFT
| Qt::Key_F5
);
1653 connect(copyToOtherViewAction
, &QAction::triggered
, this, &DolphinMainWindow::copyToInactiveSplitView
);
1655 QAction
*moveToOtherViewAction
= actionCollection()->addAction(QStringLiteral("move_to_inactive_split_view"));
1656 moveToOtherViewAction
->setText(i18nc("@action:inmenu", "Move to Other View"));
1657 m_actionTextHelper
->registerTextWhenNothingIsSelected(moveToOtherViewAction
, i18nc("@action:inmenu", "Move to Other View…"));
1658 moveToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Move",
1659 "This moves the selected items from "
1660 "the <emphasis>active</emphasis> view to the inactive split view."));
1661 moveToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-cut")));
1662 moveToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Move to Inactive Split View"));
1663 actionCollection()->setDefaultShortcut(moveToOtherViewAction
, Qt::SHIFT
| Qt::Key_F6
);
1664 connect(moveToOtherViewAction
, &QAction::triggered
, this, &DolphinMainWindow::moveToInactiveSplitView
);
1666 QAction
*showFilterBar
= actionCollection()->addAction(QStringLiteral("show_filter_bar"));
1667 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Filter…"));
1668 showFilterBar
->setToolTip(i18nc("@info:tooltip", "Show Filter Bar"));
1669 showFilterBar
->setWhatsThis(xi18nc("@info:whatsthis",
1671 "<emphasis>Filter Bar</emphasis> at the bottom of the window.<nl/> "
1672 "There you can enter a text to filter the files and folders currently displayed. "
1673 "Only those that contain the text in their name will be kept in view."));
1674 showFilterBar
->setIcon(QIcon::fromTheme(QStringLiteral("view-filter")));
1675 actionCollection()->setDefaultShortcuts(showFilterBar
, {Qt::CTRL
| Qt::Key_I
, Qt::Key_Slash
});
1676 connect(showFilterBar
, &QAction::triggered
, this, &DolphinMainWindow::showFilterBar
);
1678 // toggle_filter acts as a copy of the main showFilterBar to be used mainly
1679 // in the toolbar, with no default shortcut attached, to avoid messing with
1680 // existing workflows (filter bar always open and Ctrl-I to focus)
1681 QAction
*toggleFilter
= actionCollection()->addAction(QStringLiteral("toggle_filter"));
1682 toggleFilter
->setText(i18nc("@action:inmenu", "Toggle Filter Bar"));
1683 toggleFilter
->setIconText(i18nc("@action:intoolbar", "Filter"));
1684 toggleFilter
->setIcon(showFilterBar
->icon());
1685 toggleFilter
->setToolTip(showFilterBar
->toolTip());
1686 toggleFilter
->setWhatsThis(showFilterBar
->whatsThis());
1687 toggleFilter
->setCheckable(true);
1688 connect(toggleFilter
, &QAction::triggered
, this, &DolphinMainWindow::toggleFilterBar
);
1690 QAction
*searchAction
= KStandardAction::find(this, &DolphinMainWindow::find
, actionCollection());
1691 searchAction
->setText(i18n("Search…"));
1692 searchAction
->setToolTip(i18nc("@info:tooltip", "Search for files and folders"));
1693 searchAction
->setWhatsThis(xi18nc("@info:whatsthis find",
1694 "<para>This helps you "
1695 "find files and folders by opening a <emphasis>find bar</emphasis>. "
1696 "There you can enter search terms and specify settings to find the "
1697 "objects you are looking for.</para><para>Use this help again on "
1698 "the find bar so we can have a look at it while the settings are "
1699 "explained.</para>"));
1701 // toggle_search acts as a copy of the main searchAction to be used mainly
1702 // in the toolbar, with no default shortcut attached, to avoid messing with
1703 // existing workflows (search bar always open and Ctrl-F to focus)
1704 QAction
*toggleSearchAction
= actionCollection()->addAction(QStringLiteral("toggle_search"));
1705 toggleSearchAction
->setText(i18nc("@action:inmenu", "Toggle Search Bar"));
1706 toggleSearchAction
->setIconText(i18nc("@action:intoolbar", "Search"));
1707 toggleSearchAction
->setIcon(searchAction
->icon());
1708 toggleSearchAction
->setToolTip(searchAction
->toolTip());
1709 toggleSearchAction
->setWhatsThis(searchAction
->whatsThis());
1710 toggleSearchAction
->setCheckable(true);
1712 QAction
*toggleSelectionModeAction
= actionCollection()->addAction(QStringLiteral("toggle_selection_mode"));
1713 // i18n: This action toggles a selection mode.
1714 toggleSelectionModeAction
->setText(i18nc("@action:inmenu", "Select Files and Folders"));
1715 // i18n: Opens a selection mode for selecting files/folders.
1716 // The text is kept so unspecific because it will be shown on the toolbar where space is at a premium.
1717 toggleSelectionModeAction
->setIconText(i18nc("@action:intoolbar", "Select"));
1718 toggleSelectionModeAction
->setWhatsThis(xi18nc(
1720 "<para>This application only knows which files or folders should be acted on if they are"
1721 " <emphasis>selected</emphasis> first. Press this to toggle a <emphasis>Selection Mode</emphasis> which makes selecting and deselecting as easy as "
1722 "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."
1724 toggleSelectionModeAction
->setIcon(QIcon::fromTheme(QStringLiteral("quickwizard")));
1725 toggleSelectionModeAction
->setCheckable(true);
1726 actionCollection()->setDefaultShortcut(toggleSelectionModeAction
, Qt::Key_Space
);
1727 connect(toggleSelectionModeAction
, &QAction::triggered
, this, &DolphinMainWindow::toggleSelectionMode
);
1729 // A special version of the toggleSelectionModeAction for the toolbar that also contains a menu
1730 // with the selectAllAction and invertSelectionAction.
1731 auto *toggleSelectionModeToolBarAction
=
1732 new KToolBarPopupAction(toggleSelectionModeAction
->icon(), toggleSelectionModeAction
->iconText(), actionCollection());
1733 toggleSelectionModeToolBarAction
->setToolTip(toggleSelectionModeAction
->text());
1734 toggleSelectionModeToolBarAction
->setWhatsThis(toggleSelectionModeAction
->whatsThis());
1735 actionCollection()->addAction(QStringLiteral("toggle_selection_mode_tool_bar"), toggleSelectionModeToolBarAction
);
1736 toggleSelectionModeToolBarAction
->setCheckable(true);
1737 toggleSelectionModeToolBarAction
->setPopupMode(KToolBarPopupAction::DelayedPopup
);
1738 connect(toggleSelectionModeToolBarAction
, &QAction::triggered
, toggleSelectionModeAction
, &QAction::trigger
);
1739 connect(toggleSelectionModeAction
, &QAction::toggled
, toggleSelectionModeToolBarAction
, &QAction::setChecked
);
1741 QAction
*selectAllAction
= KStandardAction::selectAll(this, &DolphinMainWindow::selectAll
, actionCollection());
1742 selectAllAction
->setWhatsThis(xi18nc("@info:whatsthis",
1744 "files and folders in the current location."));
1746 QAction
*invertSelection
= actionCollection()->addAction(QStringLiteral("invert_selection"));
1747 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1748 invertSelection
->setWhatsThis(xi18nc("@info:whatsthis invert",
1750 "objects that you have currently <emphasis>not</emphasis> selected instead."));
1751 invertSelection
->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-invert")));
1752 actionCollection()->setDefaultShortcut(invertSelection
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1753 connect(invertSelection
, &QAction::triggered
, this, &DolphinMainWindow::invertSelection
);
1755 QMenu
*toggleSelectionModeActionMenu
= new QMenu(this);
1756 toggleSelectionModeActionMenu
->addAction(selectAllAction
);
1757 toggleSelectionModeActionMenu
->addAction(invertSelection
);
1758 toggleSelectionModeToolBarAction
->setMenu(toggleSelectionModeActionMenu
);
1760 // setup 'View' menu
1761 // (note that most of it is set up in DolphinViewActionHandler)
1763 QAction
*split
= actionCollection()->addAction(QStringLiteral("split_view"));
1764 split
->setWhatsThis(xi18nc("@info:whatsthis find",
1765 "<para>This splits "
1766 "the folder view below into two autonomous views.</para><para>This "
1767 "way you can see two locations at once and move items between them "
1768 "quickly.</para>Click this again afterwards to recombine the views."));
1769 actionCollection()->setDefaultShortcut(split
, Qt::Key_F3
);
1770 connect(split
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitView
);
1772 QAction
*stashSplit
= actionCollection()->addAction(QStringLiteral("split_stash"));
1773 actionCollection()->setDefaultShortcut(stashSplit
, Qt::CTRL
| Qt::Key_S
);
1774 stashSplit
->setText(i18nc("@action:intoolbar Stash", "Stash"));
1775 stashSplit
->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
1776 stashSplit
->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
1777 stashSplit
->setCheckable(false);
1778 QDBusConnectionInterface
*sessionInterface
= QDBusConnection::sessionBus().interface();
1779 stashSplit
->setVisible(sessionInterface
&& sessionInterface
->isServiceRegistered(QStringLiteral("org.kde.kio.StashNotifier")));
1780 connect(stashSplit
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitStash
);
1782 QAction
*redisplay
= KStandardAction::redisplay(this, &DolphinMainWindow::reloadView
, actionCollection());
1783 redisplay
->setToolTip(i18nc("@info:tooltip", "Refresh view"));
1784 redisplay
->setWhatsThis(xi18nc("@info:whatsthis refresh",
1785 "<para>This refreshes "
1786 "the folder view.</para>"
1787 "<para>If the contents of this folder have changed, refreshing will re-scan this folder "
1788 "and show you a newly-updated view of the files and folders contained here.</para>"
1789 "<para>If the view is split, this refreshes the one that is currently in focus.</para>"));
1791 QAction
*stop
= actionCollection()->addAction(QStringLiteral("stop"));
1792 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1793 stop
->setToolTip(i18nc("@info", "Stop loading"));
1794 stop
->setWhatsThis(i18nc("@info", "This stops the loading of the contents of the current folder."));
1795 stop
->setIcon(QIcon::fromTheme(QStringLiteral("process-stop")));
1796 connect(stop
, &QAction::triggered
, this, &DolphinMainWindow::stopLoading
);
1798 KToggleAction
*editableLocation
= actionCollection()->add
<KToggleAction
>(QStringLiteral("editable_location"));
1799 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1800 editableLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1801 "This toggles the <emphasis>Location Bar</emphasis> to be "
1802 "editable so you can directly enter a location you want to go to.<nl/>"
1803 "You can also switch to editing by clicking to the right of the "
1804 "location and switch back by confirming the edited location."));
1805 actionCollection()->setDefaultShortcut(editableLocation
, Qt::Key_F6
);
1806 connect(editableLocation
, &KToggleAction::triggered
, this, &DolphinMainWindow::toggleEditLocation
);
1808 QAction
*replaceLocation
= actionCollection()->addAction(QStringLiteral("replace_location"));
1809 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1810 // i18n: "enter" is used both in the meaning of "writing" and "going to" a new location here.
1811 // Both meanings are useful but not necessary to understand the use of "Replace Location".
1812 // So you might want to be more verbose in your language to convey the meaning but it's up to you.
1813 replaceLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1814 "This switches to editing the location and selects it "
1815 "so you can quickly enter a different location."));
1816 actionCollection()->setDefaultShortcuts(replaceLocation
, {Qt::CTRL
| Qt::Key_L
, Qt::ALT
| Qt::Key_D
});
1817 connect(replaceLocation
, &QAction::triggered
, this, &DolphinMainWindow::replaceLocation
);
1821 QScopedPointer
<QAction
> backAction(KStandardAction::back(nullptr, nullptr, nullptr));
1822 m_backAction
= new KToolBarPopupAction(backAction
->icon(), backAction
->text(), actionCollection());
1823 m_backAction
->setObjectName(backAction
->objectName());
1824 m_backAction
->setShortcuts(backAction
->shortcuts());
1826 m_backAction
->setPopupMode(KToolBarPopupAction::DelayedPopup
);
1827 connect(m_backAction
, &QAction::triggered
, this, &DolphinMainWindow::goBack
);
1828 connect(m_backAction
->popupMenu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowBackPopupMenu
);
1829 connect(m_backAction
->popupMenu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoBack
);
1830 actionCollection()->addAction(m_backAction
->objectName(), m_backAction
);
1832 auto backShortcuts
= m_backAction
->shortcuts();
1833 // Prepend this shortcut, to avoid being hidden by the two-slot UI (#371130)
1834 backShortcuts
.prepend(QKeySequence(Qt::Key_Backspace
));
1835 actionCollection()->setDefaultShortcuts(m_backAction
, backShortcuts
);
1837 DolphinRecentTabsMenu
*recentTabsMenu
= new DolphinRecentTabsMenu(this);
1838 actionCollection()->addAction(QStringLiteral("closed_tabs"), recentTabsMenu
);
1839 connect(m_tabWidget
, &DolphinTabWidget::rememberClosedTab
, recentTabsMenu
, &DolphinRecentTabsMenu::rememberClosedTab
);
1840 connect(recentTabsMenu
, &DolphinRecentTabsMenu::restoreClosedTab
, m_tabWidget
, &DolphinTabWidget::restoreClosedTab
);
1841 connect(recentTabsMenu
, &DolphinRecentTabsMenu::closedTabsCountChanged
, this, &DolphinMainWindow::closedTabsCountChanged
);
1843 QAction
*undoCloseTab
= actionCollection()->addAction(QStringLiteral("undo_close_tab"));
1844 undoCloseTab
->setText(i18nc("@action:inmenu File", "Undo close tab"));
1845 undoCloseTab
->setWhatsThis(i18nc("@info:whatsthis undo close tab", "This returns you to the previously closed tab."));
1846 actionCollection()->setDefaultShortcut(undoCloseTab
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_T
);
1847 undoCloseTab
->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo")));
1848 undoCloseTab
->setEnabled(false);
1849 connect(undoCloseTab
, &QAction::triggered
, recentTabsMenu
, &DolphinRecentTabsMenu::undoCloseTab
);
1851 auto undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
1852 undoAction
->setWhatsThis(xi18nc("@info:whatsthis",
1854 "the last change you made to files or folders.<nl/>"
1855 "Such changes include <interface>creating, renaming</interface> "
1856 "and <interface>moving</interface> them to a different location "
1857 "or to the <filename>Trash</filename>. <nl/>Changes that can't "
1858 "be undone will ask for your confirmation."));
1859 undoAction
->setEnabled(false); // undo should be disabled by default
1862 QScopedPointer
<QAction
> forwardAction(KStandardAction::forward(nullptr, nullptr, nullptr));
1863 m_forwardAction
= new KToolBarPopupAction(forwardAction
->icon(), forwardAction
->text(), actionCollection());
1864 m_forwardAction
->setObjectName(forwardAction
->objectName());
1865 m_forwardAction
->setShortcuts(forwardAction
->shortcuts());
1867 m_forwardAction
->setPopupMode(KToolBarPopupAction::DelayedPopup
);
1868 connect(m_forwardAction
, &QAction::triggered
, this, &DolphinMainWindow::goForward
);
1869 connect(m_forwardAction
->popupMenu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowForwardPopupMenu
);
1870 connect(m_forwardAction
->popupMenu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoForward
);
1871 actionCollection()->addAction(m_forwardAction
->objectName(), m_forwardAction
);
1872 actionCollection()->setDefaultShortcuts(m_forwardAction
, m_forwardAction
->shortcuts());
1874 // enable middle-click to open in a new tab
1875 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
1876 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotBackForwardActionMiddleClicked
);
1877 m_backAction
->popupMenu()->installEventFilter(middleClickEventFilter
);
1878 m_forwardAction
->popupMenu()->installEventFilter(middleClickEventFilter
);
1879 KStandardAction::up(this, &DolphinMainWindow::goUp
, actionCollection());
1880 QAction
*homeAction
= KStandardAction::home(this, &DolphinMainWindow::goHome
, actionCollection());
1881 homeAction
->setWhatsThis(xi18nc("@info:whatsthis",
1883 "<filename>Home</filename> folder.<nl/>Every user account "
1884 "has their own <filename>Home</filename> that contains their data "
1885 "including folders that contain personal application data."));
1887 // setup 'Tools' menu
1888 QAction
*compareFiles
= actionCollection()->addAction(QStringLiteral("compare_files"));
1889 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1890 compareFiles
->setIcon(QIcon::fromTheme(QStringLiteral("kompare")));
1891 compareFiles
->setEnabled(false);
1892 connect(compareFiles
, &QAction::triggered
, this, &DolphinMainWindow::compareFiles
);
1894 QAction
*openPreferredSearchTool
= actionCollection()->addAction(QStringLiteral("open_preferred_search_tool"));
1895 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1896 openPreferredSearchTool
->setWhatsThis(xi18nc("@info:whatsthis",
1897 "<para>This opens a preferred search tool for the viewed location.</para>"
1898 "<para>Use <emphasis>More Search Tools</emphasis> menu to configure it.</para>"));
1899 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1900 actionCollection()->setDefaultShortcut(openPreferredSearchTool
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F
);
1901 connect(openPreferredSearchTool
, &QAction::triggered
, this, &DolphinMainWindow::openPreferredSearchTool
);
1903 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1904 QAction
*openTerminal
= actionCollection()->addAction(QStringLiteral("open_terminal"));
1905 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1906 openTerminal
->setWhatsThis(xi18nc("@info:whatsthis",
1907 "<para>This opens a <emphasis>terminal</emphasis> application for the viewed location.</para>"
1908 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1909 openTerminal
->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
1910 actionCollection()->setDefaultShortcut(openTerminal
, Qt::SHIFT
| Qt::Key_F4
);
1911 connect(openTerminal
, &QAction::triggered
, this, &DolphinMainWindow::openTerminal
);
1913 QAction
*openTerminalHere
= actionCollection()->addAction(QStringLiteral("open_terminal_here"));
1914 // i18n: "Here" refers to the location(s) of the currently selected item(s) or the currently viewed location if nothing is selected.
1915 openTerminalHere
->setText(i18nc("@action:inmenu Tools", "Open Terminal Here"));
1916 openTerminalHere
->setWhatsThis(xi18nc("@info:whatsthis",
1917 "<para>This opens <emphasis>terminal</emphasis> applications for the selected items' locations.</para>"
1918 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1919 openTerminalHere
->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
1920 actionCollection()->setDefaultShortcut(openTerminalHere
, Qt::SHIFT
| Qt::ALT
| Qt::Key_F4
);
1921 connect(openTerminalHere
, &QAction::triggered
, this, &DolphinMainWindow::openTerminalHere
);
1924 QAction
*focusTerminalPanel
= actionCollection()->addAction(QStringLiteral("focus_terminal_panel"));
1925 focusTerminalPanel
->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
1926 focusTerminalPanel
->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
1927 actionCollection()->setDefaultShortcut(focusTerminalPanel
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F4
);
1928 connect(focusTerminalPanel
, &QAction::triggered
, this, &DolphinMainWindow::focusTerminalPanel
);
1932 // setup 'Bookmarks' menu
1933 KActionMenu
*bookmarkMenu
= new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this);
1934 bookmarkMenu
->setIcon(QIcon::fromTheme(QStringLiteral("bookmarks")));
1935 // Make the toolbar button version work properly on click
1936 bookmarkMenu
->setPopupMode(QToolButton::InstantPopup
);
1937 m_bookmarkHandler
= new DolphinBookmarkHandler(this, actionCollection(), bookmarkMenu
->menu(), this);
1938 actionCollection()->addAction(QStringLiteral("bookmarks"), bookmarkMenu
);
1940 // setup 'Settings' menu
1941 KToggleAction
*showMenuBar
= KStandardAction::showMenubar(nullptr, nullptr, actionCollection());
1942 showMenuBar
->setWhatsThis(xi18nc("@info:whatsthis",
1943 "<para>This switches between having a <emphasis>Menubar</emphasis> "
1944 "and having a <interface>%1</interface> button. Both "
1945 "contain mostly the same actions and configuration options.</para>"
1946 "<para>The Menubar takes up more space but allows for fast and organised access to all "
1947 "actions an application has to offer.</para><para>The <interface>%1</interface> button "
1948 "is simpler and small which makes triggering advanced actions more time consuming.</para>",
1949 hamburgerMenuAction
->text().replace('&', "")));
1950 connect(showMenuBar
,
1951 &KToggleAction::triggered
, // Fixes #286822
1953 &DolphinMainWindow::toggleShowMenuBar
,
1954 Qt::QueuedConnection
);
1956 KToggleAction
*showStatusBar
= KStandardAction::showStatusbar(nullptr, nullptr, actionCollection());
1957 showStatusBar
->setChecked(GeneralSettings::showStatusBar());
1958 connect(GeneralSettings::self(), &GeneralSettings::showStatusBarChanged
, showStatusBar
, &KToggleAction::setChecked
);
1959 connect(showStatusBar
, &KToggleAction::triggered
, this, [this](bool checked
) {
1960 GeneralSettings::setShowStatusBar(checked
);
1964 KStandardAction::keyBindings(this, &DolphinMainWindow::slotKeyBindings
, actionCollection());
1965 KStandardAction::preferences(this, &DolphinMainWindow::editSettings
, actionCollection());
1967 // not in menu actions
1968 QList
<QKeySequence
> nextTabKeys
= KStandardShortcut::tabNext();
1969 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
1971 QList
<QKeySequence
> prevTabKeys
= KStandardShortcut::tabPrev();
1972 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
1974 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1975 QAction
*activateTab
= actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i
));
1976 activateTab
->setText(i18nc("@action:inmenu", "Activate Tab %1", i
+ 1));
1977 activateTab
->setEnabled(false);
1978 connect(activateTab
, &QAction::triggered
, this, [this, i
]() {
1979 m_tabWidget
->activateTab(i
);
1982 // only add default shortcuts for the first 9 tabs regardless of MaxActivateTabShortcuts
1984 actionCollection()->setDefaultShortcut(activateTab
, QStringLiteral("Alt+%1").arg(i
+ 1));
1988 QAction
*activateLastTab
= actionCollection()->addAction(QStringLiteral("activate_last_tab"));
1989 activateLastTab
->setText(i18nc("@action:inmenu", "Activate Last Tab"));
1990 activateLastTab
->setEnabled(false);
1991 connect(activateLastTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateLastTab
);
1992 actionCollection()->setDefaultShortcut(activateLastTab
, Qt::ALT
| Qt::Key_0
);
1994 QAction
*activateNextTab
= actionCollection()->addAction(QStringLiteral("activate_next_tab"));
1995 activateNextTab
->setIconText(i18nc("@action:inmenu", "Next Tab"));
1996 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1997 activateNextTab
->setEnabled(false);
1998 connect(activateNextTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateNextTab
);
1999 actionCollection()->setDefaultShortcuts(activateNextTab
, nextTabKeys
);
2001 QAction
*activatePrevTab
= actionCollection()->addAction(QStringLiteral("activate_prev_tab"));
2002 activatePrevTab
->setIconText(i18nc("@action:inmenu", "Previous Tab"));
2003 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
2004 activatePrevTab
->setEnabled(false);
2005 connect(activatePrevTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activatePrevTab
);
2006 actionCollection()->setDefaultShortcuts(activatePrevTab
, prevTabKeys
);
2009 QAction
*showTarget
= actionCollection()->addAction(QStringLiteral("show_target"));
2010 showTarget
->setText(i18nc("@action:inmenu", "Show Target"));
2011 showTarget
->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
2012 showTarget
->setEnabled(false);
2013 connect(showTarget
, &QAction::triggered
, this, &DolphinMainWindow::showTarget
);
2015 QAction
*openInNewTab
= actionCollection()->addAction(QStringLiteral("open_in_new_tab"));
2016 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
2017 openInNewTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
2018 connect(openInNewTab
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
2020 QAction
*openInNewTabs
= actionCollection()->addAction(QStringLiteral("open_in_new_tabs"));
2021 openInNewTabs
->setText(i18nc("@action:inmenu", "Open in New Tabs"));
2022 openInNewTabs
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
2023 connect(openInNewTabs
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
2025 QAction
*openInNewWindow
= actionCollection()->addAction(QStringLiteral("open_in_new_window"));
2026 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
2027 openInNewWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
2028 connect(openInNewWindow
, &QAction::triggered
, this, &DolphinMainWindow::openInNewWindow
);
2030 QAction
*openInSplitViewAction
= actionCollection()->addAction(QStringLiteral("open_in_split_view"));
2031 openInSplitViewAction
->setText(i18nc("@action:inmenu", "Open in Split View"));
2032 openInSplitViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
2033 connect(openInSplitViewAction
, &QAction::triggered
, this, [this]() {
2034 openInSplitView(QUrl());
2038 void DolphinMainWindow::setupDockWidgets()
2040 const bool lock
= GeneralSettings::lockPanels();
2042 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(lock
);
2044 KDualAction
*lockLayoutAction
= actionCollection()->add
<KDualAction
>(QStringLiteral("lock_panels"));
2045 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
2046 lockLayoutAction
->setActiveIcon(QIcon::fromTheme(QStringLiteral("object-unlocked")));
2047 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
2048 lockLayoutAction
->setInactiveIcon(QIcon::fromTheme(QStringLiteral("object-locked")));
2049 lockLayoutAction
->setWhatsThis(xi18nc("@info:whatsthis",
2051 "switches between having panels <emphasis>locked</emphasis> or "
2052 "<emphasis>unlocked</emphasis>.<nl/>Unlocked panels can be "
2053 "dragged to the other side of the window and have a close "
2054 "button.<nl/>Locked panels are embedded more cleanly."));
2055 lockLayoutAction
->setActive(lock
);
2056 connect(lockLayoutAction
, &KDualAction::triggered
, this, &DolphinMainWindow::togglePanelLockState
);
2058 // Setup "Information"
2059 DolphinDockWidget
*infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
2060 infoDock
->setLocked(lock
);
2061 infoDock
->setObjectName(QStringLiteral("infoDock"));
2062 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2065 InformationPanel
*infoPanel
= new InformationPanel(infoDock
);
2066 infoPanel
->setCustomContextMenuActions({lockLayoutAction
});
2067 connect(infoPanel
, &InformationPanel::urlActivated
, this, &DolphinMainWindow::handleUrl
);
2068 infoDock
->setWidget(infoPanel
);
2070 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-information")), Qt::Key_F11
, infoDock
, QStringLiteral("show_information_panel"));
2072 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
2073 connect(this, &DolphinMainWindow::urlChanged
, infoPanel
, &InformationPanel::setUrl
);
2074 connect(this, &DolphinMainWindow::selectionChanged
, infoPanel
, &InformationPanel::setSelection
);
2075 connect(this, &DolphinMainWindow::requestItemInfo
, infoPanel
, &InformationPanel::requestDelayedItemInfo
);
2076 connect(this, &DolphinMainWindow::fileItemsChanged
, infoPanel
, &InformationPanel::slotFilesItemChanged
);
2079 // i18n: This is the last paragraph for the "What's This"-texts of all four panels.
2080 const QString panelWhatsThis
= xi18nc("@info:whatsthis",
2082 "hide panels like this go to <interface>Menu|Panels</interface> "
2083 "or <interface>View|Panels</interface>.</para>");
2086 ->action(QStringLiteral("show_information_panel"))
2087 ->setWhatsThis(xi18nc("@info:whatsthis",
2088 "<para> This toggles the "
2089 "<emphasis>information</emphasis> panel at the right side of the "
2090 "window.</para><para>The panel provides in-depth information "
2091 "about the items your mouse is hovering over or about the selected "
2092 "items. Otherwise it informs you about the currently viewed folder.<nl/>"
2093 "For single items a preview of their contents is provided.</para>"));
2095 infoDock
->setWhatsThis(xi18nc("@info:whatsthis",
2097 "provides in-depth information about the items your mouse is "
2098 "hovering over or about the selected items. Otherwise it informs "
2099 "you about the currently viewed folder.<nl/>For single items a "
2100 "preview of their contents is provided.</para><para>You can configure "
2101 "which and how details are given here by right-clicking.</para>")
2105 DolphinDockWidget
*foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
2106 foldersDock
->setLocked(lock
);
2107 foldersDock
->setObjectName(QStringLiteral("foldersDock"));
2108 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2109 FoldersPanel
*foldersPanel
= new FoldersPanel(foldersDock
);
2110 foldersPanel
->setCustomContextMenuActions({lockLayoutAction
});
2111 foldersDock
->setWidget(foldersPanel
);
2113 createPanelAction(QIcon::fromTheme(QStringLiteral("folder")), Qt::Key_F7
, foldersDock
, QStringLiteral("show_folders_panel"));
2115 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
2116 connect(this, &DolphinMainWindow::urlChanged
, foldersPanel
, &FoldersPanel::setUrl
);
2117 connect(foldersPanel
, &FoldersPanel::folderActivated
, this, &DolphinMainWindow::changeUrl
);
2118 connect(foldersPanel
, &FoldersPanel::folderInNewTab
, this, &DolphinMainWindow::openNewTab
);
2119 connect(foldersPanel
, &FoldersPanel::folderInNewActiveTab
, this, &DolphinMainWindow::openNewTabAndActivate
);
2120 connect(foldersPanel
, &FoldersPanel::errorMessage
, this, &DolphinMainWindow::showErrorMessage
);
2123 ->action(QStringLiteral("show_folders_panel"))
2124 ->setWhatsThis(xi18nc("@info:whatsthis",
2126 "<emphasis>folders</emphasis> panel at the left side of the window."
2127 "<nl/><nl/>It shows the folders of the <emphasis>file system"
2128 "</emphasis> in a <emphasis>tree view</emphasis>."));
2129 foldersDock
->setWhatsThis(xi18nc("@info:whatsthis",
2131 "shows the folders of the <emphasis>file system</emphasis> in a "
2132 "<emphasis>tree view</emphasis>.</para><para>Click a folder to go "
2133 "there. Click the arrow to the left of a folder to see its subfolders. "
2134 "This allows quick switching between any folders.</para>")
2139 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
2140 DolphinDockWidget
*terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
2141 terminalDock
->setLocked(lock
);
2142 terminalDock
->setObjectName(QStringLiteral("terminalDock"));
2143 terminalDock
->setContentsMargins(0, 0, 0, 0);
2144 m_terminalPanel
= new TerminalPanel(terminalDock
);
2145 m_terminalPanel
->setCustomContextMenuActions({lockLayoutAction
});
2146 terminalDock
->setWidget(m_terminalPanel
);
2148 connect(m_terminalPanel
, &TerminalPanel::hideTerminalPanel
, terminalDock
, &DolphinDockWidget::hide
);
2149 connect(m_terminalPanel
, &TerminalPanel::changeUrl
, this, &DolphinMainWindow::slotTerminalDirectoryChanged
);
2150 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
, m_terminalPanel
, &TerminalPanel::dockVisibilityChanged
);
2151 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
, this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged
);
2153 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-scripts")), Qt::Key_F4
, terminalDock
, QStringLiteral("show_terminal_panel"));
2155 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
2156 connect(this, &DolphinMainWindow::urlChanged
, m_terminalPanel
, &TerminalPanel::setUrl
);
2158 if (GeneralSettings::version() < 200) {
2159 terminalDock
->hide();
2163 ->action(QStringLiteral("show_terminal_panel"))
2164 ->setWhatsThis(xi18nc("@info:whatsthis",
2165 "<para>This toggles the "
2166 "<emphasis>terminal</emphasis> panel at the bottom of the window."
2167 "<nl/>The location in the terminal will always match the folder "
2168 "view so you can navigate using either.</para><para>The terminal "
2169 "panel is not needed for basic computer usage but can be useful "
2170 "for advanced tasks. To learn more about terminals use the help "
2171 "in a standalone terminal application like Konsole.</para>"));
2172 terminalDock
->setWhatsThis(xi18nc("@info:whatsthis",
2174 "the <emphasis>terminal</emphasis> panel. It behaves like a "
2175 "normal terminal but will match the location of the folder view "
2176 "so you can navigate using either.</para><para>The terminal panel "
2177 "is not needed for basic computer usage but can be useful for "
2178 "advanced tasks. To learn more about terminals use the help in a "
2179 "standalone terminal application like Konsole.</para>")
2184 if (GeneralSettings::version() < 200) {
2186 foldersDock
->hide();
2190 DolphinDockWidget
*placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
2191 placesDock
->setLocked(lock
);
2192 placesDock
->setObjectName(QStringLiteral("placesDock"));
2193 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2195 m_placesPanel
= new PlacesPanel(placesDock
);
2196 m_placesPanel
->setCustomContextMenuActions({lockLayoutAction
});
2197 placesDock
->setWidget(m_placesPanel
);
2199 createPanelAction(QIcon::fromTheme(QStringLiteral("compass")), Qt::Key_F9
, placesDock
, QStringLiteral("show_places_panel"));
2201 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
2202 connect(m_placesPanel
, &PlacesPanel::placeActivated
, this, &DolphinMainWindow::slotPlaceActivated
);
2203 connect(m_placesPanel
, &PlacesPanel::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2204 connect(m_placesPanel
, &PlacesPanel::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2205 connect(m_placesPanel
, &PlacesPanel::newWindowRequested
, this, [this](const QUrl
&url
) {
2206 Dolphin::openNewWindow({url
}, this);
2208 connect(m_placesPanel
, &PlacesPanel::openInSplitViewRequested
, this, &DolphinMainWindow::openInSplitView
);
2209 connect(m_placesPanel
, &PlacesPanel::errorMessage
, this, &DolphinMainWindow::showErrorMessage
);
2210 connect(this, &DolphinMainWindow::urlChanged
, m_placesPanel
, &PlacesPanel::setUrl
);
2211 connect(placesDock
, &DolphinDockWidget::visibilityChanged
, &DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged
);
2212 connect(this, &DolphinMainWindow::settingsChanged
, m_placesPanel
, &PlacesPanel::readSettings
);
2213 connect(m_placesPanel
, &PlacesPanel::storageTearDownRequested
, this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested
);
2214 connect(m_placesPanel
, &PlacesPanel::storageTearDownExternallyRequested
, this, &DolphinMainWindow::slotStorageTearDownExternallyRequested
);
2215 DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged(m_placesPanel
->isVisible());
2217 auto actionShowAllPlaces
= new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this);
2218 actionShowAllPlaces
->setCheckable(true);
2219 actionShowAllPlaces
->setDisabled(true);
2220 actionShowAllPlaces
->setWhatsThis(i18nc("@info:whatsthis",
2222 "all places in the places panel that have been hidden. They will "
2223 "appear semi-transparent unless you uncheck their hide property."));
2225 connect(actionShowAllPlaces
, &QAction::triggered
, this, [this](bool checked
) {
2226 m_placesPanel
->setShowAll(checked
);
2228 connect(m_placesPanel
, &PlacesPanel::allPlacesShownChanged
, actionShowAllPlaces
, &QAction::setChecked
);
2231 ->action(QStringLiteral("show_places_panel"))
2232 ->setWhatsThis(xi18nc("@info:whatsthis",
2233 "<para>This toggles the "
2234 "<emphasis>places</emphasis> panel at the left side of the window."
2235 "</para><para>It allows you to go to locations you have "
2236 "bookmarked and to access disk or media attached to the computer "
2237 "or to the network. It also contains sections to find recently "
2238 "saved files or files of a certain type.</para>"));
2239 placesDock
->setWhatsThis(xi18nc("@info:whatsthis",
2240 "<para>This is the "
2241 "<emphasis>Places</emphasis> panel. It allows you to go to locations "
2242 "you have bookmarked and to access disk or media attached to the "
2243 "computer or to the network. It also contains sections to find "
2244 "recently saved files or files of a certain type.</para><para>"
2245 "Click on an entry to go there. Click with the right mouse button "
2246 "instead to open any entry in a new tab or new window.</para>"
2247 "<para>New entries can be added by dragging folders onto this panel. "
2248 "Right-click any section or entry to hide it. Right-click an empty "
2249 "space on this panel and select <interface>Show Hidden Places"
2250 "</interface> to display it again.</para>")
2253 // Add actions into the "Panels" menu
2254 KActionMenu
*panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Show Panels"), this);
2255 actionCollection()->addAction(QStringLiteral("panels"), panelsMenu
);
2256 panelsMenu
->setIcon(QIcon::fromTheme(QStringLiteral("view-sidetree")));
2257 panelsMenu
->setPopupMode(QToolButton::InstantPopup
);
2258 const KActionCollection
*ac
= actionCollection();
2259 panelsMenu
->addAction(ac
->action(QStringLiteral("show_places_panel")));
2261 panelsMenu
->addAction(ac
->action(QStringLiteral("show_information_panel")));
2263 panelsMenu
->addAction(ac
->action(QStringLiteral("show_folders_panel")));
2264 panelsMenu
->addAction(ac
->action(QStringLiteral("show_terminal_panel")));
2265 panelsMenu
->addSeparator();
2266 panelsMenu
->addAction(actionShowAllPlaces
);
2267 panelsMenu
->addAction(lockLayoutAction
);
2269 connect(panelsMenu
->menu(), &QMenu::aboutToShow
, this, [actionShowAllPlaces
] {
2270 actionShowAllPlaces
->setEnabled(DolphinPlacesModelSingleton::instance().placesModel()->hiddenCount());
2274 void DolphinMainWindow::updateFileAndEditActions()
2276 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
2277 const KActionCollection
*col
= actionCollection();
2278 KFileItemListProperties
capabilitiesSource(list
);
2280 QAction
*renameAction
= col
->action(KStandardAction::name(KStandardAction::RenameFile
));
2281 QAction
*moveToTrashAction
= col
->action(KStandardAction::name(KStandardAction::MoveToTrash
));
2282 QAction
*deleteAction
= col
->action(KStandardAction::name(KStandardAction::DeleteFile
));
2283 QAction
*cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
2284 QAction
*duplicateAction
= col
->action(QStringLiteral("duplicate")); // see DolphinViewActionHandler
2285 QAction
*addToPlacesAction
= col
->action(QStringLiteral("add_to_places"));
2286 QAction
*copyToOtherViewAction
= col
->action(QStringLiteral("copy_to_inactive_split_view"));
2287 QAction
*moveToOtherViewAction
= col
->action(QStringLiteral("move_to_inactive_split_view"));
2288 QAction
*copyLocation
= col
->action(QString("copy_location"));
2290 if (list
.isEmpty()) {
2291 stateChanged(QStringLiteral("has_no_selection"));
2293 // All actions that need a selection to function can be enabled because they should trigger selection mode.
2294 renameAction
->setEnabled(true);
2295 moveToTrashAction
->setEnabled(true);
2296 deleteAction
->setEnabled(true);
2297 cutAction
->setEnabled(true);
2298 duplicateAction
->setEnabled(true);
2299 addToPlacesAction
->setEnabled(true);
2300 copyLocation
->setEnabled(true);
2301 // Them triggering selection mode and not directly acting on selected items is signified by adding "…" to their text.
2302 m_actionTextHelper
->textsWhenNothingIsSelectedEnabled(true);
2305 m_actionTextHelper
->textsWhenNothingIsSelectedEnabled(false);
2306 stateChanged(QStringLiteral("has_selection"));
2308 QAction
*deleteWithTrashShortcut
= col
->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
2309 QAction
*showTarget
= col
->action(QStringLiteral("show_target"));
2311 if (list
.length() == 1 && list
.first().isDir()) {
2312 addToPlacesAction
->setEnabled(true);
2314 addToPlacesAction
->setEnabled(false);
2317 const bool enableMoveToTrash
= capabilitiesSource
.isLocal() && capabilitiesSource
.supportsMoving();
2319 renameAction
->setEnabled(capabilitiesSource
.supportsMoving());
2320 moveToTrashAction
->setEnabled(enableMoveToTrash
);
2321 deleteAction
->setEnabled(capabilitiesSource
.supportsDeleting());
2322 deleteWithTrashShortcut
->setEnabled(capabilitiesSource
.supportsDeleting() && !enableMoveToTrash
);
2323 cutAction
->setEnabled(capabilitiesSource
.supportsMoving());
2324 copyLocation
->setEnabled(list
.length() == 1);
2325 showTarget
->setEnabled(list
.length() == 1 && list
.at(0).isLink());
2326 duplicateAction
->setEnabled(capabilitiesSource
.supportsWriting());
2329 if (m_tabWidget
->currentTabPage()->splitViewEnabled() && !list
.isEmpty()) {
2330 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
2331 KFileItem capabilitiesDestination
;
2333 if (tabPage
->primaryViewActive()) {
2334 capabilitiesDestination
= tabPage
->secondaryViewContainer()->rootItem();
2336 capabilitiesDestination
= tabPage
->primaryViewContainer()->rootItem();
2339 const auto destUrl
= capabilitiesDestination
.url();
2340 const bool allNotTargetOrigin
= std::all_of(list
.cbegin(), list
.cend(), [destUrl
](const KFileItem
&item
) {
2341 return item
.url().adjusted(QUrl::RemoveFilename
| QUrl::StripTrailingSlash
) != destUrl
;
2344 copyToOtherViewAction
->setEnabled(capabilitiesDestination
.isWritable() && allNotTargetOrigin
);
2345 moveToOtherViewAction
->setEnabled((list
.isEmpty() || capabilitiesSource
.supportsMoving()) && capabilitiesDestination
.isWritable()
2346 && allNotTargetOrigin
);
2348 copyToOtherViewAction
->setEnabled(false);
2349 moveToOtherViewAction
->setEnabled(false);
2353 void DolphinMainWindow::updateViewActions()
2355 m_actionHandler
->updateViewActions();
2357 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
2358 toggleFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
2360 updateSplitAction();
2363 void DolphinMainWindow::updateGoActions()
2365 QAction
*goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
2366 const QUrl currentUrl
= m_activeViewContainer
->url();
2367 // I think this is one of the best places to firstly be confronted
2368 // with a file system and its hierarchy. Talking about the root
2369 // directory might seem too much here but it is the question that
2370 // naturally arises in this context.
2371 goUpAction
->setWhatsThis(xi18nc("@info:whatsthis",
2373 "the folder that contains the currently viewed one.</para>"
2374 "<para>All files and folders are organized in a hierarchical "
2375 "<emphasis>file system</emphasis>. At the top of this hierarchy is "
2376 "a directory that contains all data connected to this computer"
2377 "—the <emphasis>root directory</emphasis>.</para>"));
2378 goUpAction
->setEnabled(KIO::upUrl(currentUrl
) != currentUrl
);
2381 void DolphinMainWindow::refreshViews()
2383 m_tabWidget
->refreshViews();
2385 if (GeneralSettings::modifiedStartupSettings()) {
2386 updateWindowTitle();
2389 updateSplitAction();
2391 Q_EMIT
settingsChanged();
2394 void DolphinMainWindow::clearStatusBar()
2396 m_activeViewContainer
->statusBar()->resetToDefaultText();
2399 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
*container
)
2401 connect(container
, &DolphinViewContainer::showFilterBarChanged
, this, &DolphinMainWindow::updateFilterBarAction
);
2402 connect(container
, &DolphinViewContainer::writeStateChanged
, this, &DolphinMainWindow::slotWriteStateChanged
);
2403 slotWriteStateChanged(container
->view()->isFolderWritable());
2404 connect(container
, &DolphinViewContainer::searchModeEnabledChanged
, this, &DolphinMainWindow::updateSearchAction
);
2405 connect(container
, &DolphinViewContainer::captionChanged
, this, &DolphinMainWindow::updateWindowTitle
);
2406 connect(container
, &DolphinViewContainer::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2407 connect(container
, &DolphinViewContainer::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2409 const QAction
*toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
2410 connect(toggleSearchAction
, &QAction::triggered
, container
, &DolphinViewContainer::setSearchModeEnabled
);
2412 // Make the toggled state of the selection mode actions visually follow the selection mode state of the view.
2413 auto toggleSelectionModeAction
= actionCollection()->action(QStringLiteral("toggle_selection_mode"));
2414 toggleSelectionModeAction
->setChecked(m_activeViewContainer
->isSelectionModeEnabled());
2415 connect(m_activeViewContainer
, &DolphinViewContainer::selectionModeChanged
, toggleSelectionModeAction
, &QAction::setChecked
);
2417 const DolphinView
*view
= container
->view();
2418 connect(view
, &DolphinView::selectionChanged
, this, &DolphinMainWindow::slotSelectionChanged
);
2419 connect(view
, &DolphinView::requestItemInfo
, this, &DolphinMainWindow::requestItemInfo
);
2420 connect(view
, &DolphinView::fileItemsChanged
, this, &DolphinMainWindow::fileItemsChanged
);
2421 connect(view
, &DolphinView::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2422 connect(view
, &DolphinView::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2423 connect(view
, &DolphinView::windowRequested
, this, &DolphinMainWindow::openNewWindow
);
2424 connect(view
, &DolphinView::requestContextMenu
, this, &DolphinMainWindow::openContextMenu
);
2425 connect(view
, &DolphinView::directoryLoadingStarted
, this, &DolphinMainWindow::enableStopAction
);
2426 connect(view
, &DolphinView::directoryLoadingCompleted
, this, &DolphinMainWindow::disableStopAction
);
2427 connect(view
, &DolphinView::directoryLoadingCompleted
, this, &DolphinMainWindow::slotDirectoryLoadingCompleted
);
2428 connect(view
, &DolphinView::goBackRequested
, this, &DolphinMainWindow::goBack
);
2429 connect(view
, &DolphinView::goForwardRequested
, this, &DolphinMainWindow::goForward
);
2430 connect(view
, &DolphinView::urlActivated
, this, &DolphinMainWindow::handleUrl
);
2431 connect(view
, &DolphinView::goUpRequested
, this, &DolphinMainWindow::goUp
);
2433 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::urlChanged
, this, &DolphinMainWindow::changeUrl
);
2434 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::historyChanged
, this, &DolphinMainWindow::updateHistory
);
2436 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2437 const KUrlNavigator
*navigator
=
2438 m_tabWidget
->currentTabPage()->primaryViewActive() ? navigators
->primaryUrlNavigator() : navigators
->secondaryUrlNavigator();
2440 QAction
*editableLocactionAction
= actionCollection()->action(QStringLiteral("editable_location"));
2441 editableLocactionAction
->setChecked(navigator
->isUrlEditable());
2442 connect(navigator
, &KUrlNavigator::editableStateChanged
, this, &DolphinMainWindow::slotEditableStateChanged
);
2443 connect(navigator
, &KUrlNavigator::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2444 connect(navigator
, &KUrlNavigator::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2445 connect(navigator
, &KUrlNavigator::newWindowRequested
, this, &DolphinMainWindow::openNewWindow
);
2448 void DolphinMainWindow::updateSplitAction()
2450 QAction
*splitAction
= actionCollection()->action(QStringLiteral("split_view"));
2451 const DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
2452 if (tabPage
->splitViewEnabled()) {
2453 if (GeneralSettings::closeActiveSplitView() ? tabPage
->primaryViewActive() : !tabPage
->primaryViewActive()) {
2454 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2455 splitAction
->setToolTip(i18nc("@info", "Close left view"));
2456 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close")));
2458 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2459 splitAction
->setToolTip(i18nc("@info", "Close right view"));
2460 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close")));
2463 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2464 splitAction
->setToolTip(i18nc("@info", "Split view"));
2465 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
2469 void DolphinMainWindow::updateAllowedToolbarAreas()
2471 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2472 if (toolBar()->actions().contains(navigators
)) {
2473 toolBar()->setAllowedAreas(Qt::TopToolBarArea
| Qt::BottomToolBarArea
);
2474 if (toolBarArea(toolBar()) == Qt::LeftToolBarArea
|| toolBarArea(toolBar()) == Qt::RightToolBarArea
) {
2475 addToolBar(Qt::TopToolBarArea
, toolBar());
2478 toolBar()->setAllowedAreas(Qt::AllToolBarAreas
);
2482 bool DolphinMainWindow::isKompareInstalled() const
2484 static bool initialized
= false;
2485 static bool installed
= false;
2487 // TODO: maybe replace this approach later by using a menu
2488 // plugin like kdiff3plugin.cpp
2489 installed
= !QStandardPaths::findExecutable(QStringLiteral("kompare")).isEmpty();
2495 void DolphinMainWindow::createPanelAction(const QIcon
&icon
, const QKeySequence
&shortcut
, QDockWidget
*dockWidget
, const QString
&actionName
)
2497 auto dockAction
= dockWidget
->toggleViewAction();
2498 dockAction
->setIcon(icon
);
2499 dockAction
->setEnabled(true);
2501 QAction
*panelAction
= actionCollection()->addAction(actionName
, dockAction
);
2502 actionCollection()->setDefaultShortcut(panelAction
, shortcut
);
2504 connect(panelAction
, &QAction::toggled
, dockWidget
, &QWidget::setVisible
);
2507 void DolphinMainWindow::setupWhatsThis()
2510 menuBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2511 "<emphasis>Menubar</emphasis>. It provides access to commands and "
2512 "configuration options. Left-click on any of the menus on this "
2513 "bar to see its contents.</para><para>The Menubar can be hidden "
2514 "by unchecking <interface>Settings|Show Menubar</interface>. Then "
2515 "most of its contents become available through a <interface>Menu"
2516 "</interface> button on the <emphasis>Toolbar</emphasis>.</para>"));
2517 toolBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2518 "<emphasis>Toolbar</emphasis>. It allows quick access to "
2519 "frequently used actions.</para><para>It is highly customizable. "
2520 "All items you see in the <interface>Menu</interface> or "
2521 "in the <interface>Menubar</interface> can be placed on the "
2522 "Toolbar. Just right-click on it and select <interface>Configure "
2523 "Toolbars…</interface> or find this action within the <interface>"
2525 "</para><para>The location of the bar and the style of its "
2526 "buttons can also be changed in the right-click menu. Right-click "
2527 "a button if you want to show or hide its text.</para>"));
2528 m_tabWidget
->setWhatsThis(xi18nc("@info:whatsthis main view",
2529 "<para>Here you can see the <emphasis>folders</emphasis> and "
2530 "<emphasis>files</emphasis> that are at the location described in "
2531 "the <interface>Location Bar</interface> above. This area is the "
2532 "central part of this application where you navigate to the files "
2533 "you want to use.</para><para>For an elaborate and general "
2534 "introduction to this application <link "
2535 "url='https://userbase.kde.org/Dolphin/File_Management#Introduction_to_Dolphin'>"
2536 "click here</link>. This will open an introductory article from "
2537 "the <emphasis>KDE UserBase Wiki</emphasis>.</para><para>For brief "
2538 "explanations of all the features of this <emphasis>view</emphasis> "
2539 "<link url='help:/dolphin/dolphin-view.html'>click here</link> "
2540 "instead. This will open a page from the <emphasis>Handbook"
2541 "</emphasis> that covers the basics.</para>"));
2544 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings
))
2545 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window "
2546 "that lists the <emphasis>keyboard shortcuts</emphasis>.<nl/>"
2547 "There you can set up key combinations to trigger an action when "
2548 "they are pressed simultaneously. All commands in this application can "
2549 "be triggered this way.</para>"));
2550 actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars
))
2551 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window in which "
2552 "you can change which buttons appear on the <emphasis>Toolbar</emphasis>.</para>"
2553 "<para>All items you see in the <interface>Menu</interface> can also be placed on the Toolbar.</para>"));
2554 actionCollection()->action(KStandardAction::name(KStandardAction::Preferences
))
2555 ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window where you can "
2556 "change a multitude of settings for this application. For an explanation "
2557 "of the various settings go to the chapter <emphasis>Configuring Dolphin"
2558 "</emphasis> in <interface>Help|Dolphin Handbook</interface>."));
2562 auto setStandardActionWhatsThis
= [this](KStandardAction::StandardAction actionId
,
2563 const QString
&whatsThis
) {
2564 // Check for the existence of an action since it can be restricted through the Kiosk system
2565 if (auto *action
= actionCollection()->action(KStandardAction::name(actionId
))) {
2566 action
->setWhatsThis(whatsThis
);
2570 // i18n: If the external link isn't available in your language it might make
2571 // sense to state the external link's language in brackets to not
2572 // frustrate the user. If there are multiple languages that the user might
2573 // know with a reasonable chance you might want to have 2 external links.
2574 // The same might be true for any external link you translate.
2575 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>"));
2576 // (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 )
2578 setStandardActionWhatsThis(KStandardAction::WhatsThis
,
2579 xi18nc("@info:whatsthis whatsthis button",
2580 "<para>This is the button that invokes the help feature you are "
2581 "using right now! Click it, then click any component of this "
2582 "application to ask \"What's this?\" about it. The mouse cursor "
2583 "will change appearance if no help is available for a spot.</para>"
2584 "<para>There are two other ways to get help: "
2585 "The <link url='help:/dolphin/index.html'>Dolphin Handbook</link> and "
2586 "the <link url='https://userbase.kde.org/Dolphin/File_Management'>KDE "
2587 "UserBase Wiki</link>.</para><para>The \"What's this?\" help is "
2588 "missing in most other windows so don't get too used to this.</para>"));
2590 setStandardActionWhatsThis(KStandardAction::ReportBug
,
2591 xi18nc("@info:whatsthis","<para>This opens a "
2592 "window that will guide you through reporting errors or flaws "
2593 "in this application or in other KDE software.</para>"
2594 "<para>High-quality bug reports are much appreciated. To learn "
2595 "how to make your bug report as effective as possible "
2596 "<link url='https://community.kde.org/Get_Involved/Bug_Reporting'>"
2597 "click here</link>.</para>"));
2599 setStandardActionWhatsThis(KStandardAction::Donate
,
2600 xi18nc("@info:whatsthis", "<para>This opens a "
2601 "<emphasis>web page</emphasis> where you can donate to "
2602 "support the continued work on this application and many "
2603 "other projects by the <emphasis>KDE</emphasis> community.</para>"
2604 "<para>Donating is the easiest and fastest way to efficiently "
2605 "support KDE and its projects. KDE projects are available for "
2606 "free therefore your donation is needed to cover things that "
2607 "require money like servers, contributor meetings, etc.</para>"
2608 "<para><emphasis>KDE e.V.</emphasis> is the non-profit "
2609 "organization behind the KDE community.</para>"));
2611 setStandardActionWhatsThis(KStandardAction::SwitchApplicationLanguage
,
2612 xi18nc("@info:whatsthis",
2613 "With this you can change the language this application uses."
2614 "<nl/>You can even set secondary languages which will be used "
2615 "if texts are not available in your preferred language."));
2617 setStandardActionWhatsThis(KStandardAction::AboutApp
,
2618 xi18nc("@info:whatsthis","This opens a "
2619 "window that informs you about the version, license, "
2620 "used libraries and maintainers of this application."));
2622 setStandardActionWhatsThis(KStandardAction::AboutKDE
,
2623 xi18nc("@info:whatsthis","This opens a "
2624 "window with information about <emphasis>KDE</emphasis>. "
2625 "The KDE community are the people behind this free software."
2626 "<nl/>If you like using this application but don't know "
2627 "about KDE or want to see a cute dragon have a look!"));
2631 bool DolphinMainWindow::addHamburgerMenuToToolbar()
2633 QDomDocument domDocument
= KXMLGUIClient::domDocument();
2634 if (domDocument
.isNull()) {
2637 QDomNode toolbar
= domDocument
.elementsByTagName(QStringLiteral("ToolBar")).at(0);
2638 if (toolbar
.isNull()) {
2642 QDomElement hamburgerMenuElement
= domDocument
.createElement(QStringLiteral("Action"));
2643 hamburgerMenuElement
.setAttribute(QStringLiteral("name"), QStringLiteral("hamburger_menu"));
2644 toolbar
.appendChild(hamburgerMenuElement
);
2646 KXMLGUIFactory::saveConfigFile(domDocument
, xmlFile());
2650 // Make sure to also remove the <KXMLGUIFactory> and <QDomDocument> include
2651 // whenever this method is removed (maybe in the year ~2026).
2654 // Set a sane initial window size
2655 QSize
DolphinMainWindow::sizeHint() const
2657 return KXmlGuiWindow::sizeHint().expandedTo(QSize(760, 550));
2660 void DolphinMainWindow::saveNewToolbarConfig()
2662 KXmlGuiWindow::saveNewToolbarConfig(); // Applies the new config. This has to be called first
2663 // because the rest of this method decides things
2664 // based on the new config.
2665 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2666 if (!toolBar()->actions().contains(navigators
)) {
2667 m_tabWidget
->currentTabPage()->insertNavigatorsWidget(navigators
);
2669 updateAllowedToolbarAreas();
2670 (static_cast<KHamburgerMenu
*>(actionCollection()->action(KStandardAction::name(KStandardAction::HamburgerMenu
))))->hideActionsOf(toolBar());
2673 void DolphinMainWindow::focusTerminalPanel()
2675 if (m_terminalPanel
->isVisible()) {
2676 if (m_terminalPanel
->terminalHasFocus()) {
2677 m_activeViewContainer
->view()->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2678 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2680 m_terminalPanel
->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2681 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2684 actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger();
2685 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2689 DolphinMainWindow::UndoUiInterface::UndoUiInterface()
2690 : KIO::FileUndoManager::UiInterface()
2694 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2698 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
*job
)
2700 DolphinMainWindow
*mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2702 DolphinViewContainer
*container
= mainWin
->activeViewContainer();
2703 container
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
2705 KIO::FileUndoManager::UiInterface::jobError(job
);
2709 bool DolphinMainWindow::isUrlOpen(const QString
&url
)
2711 return m_tabWidget
->isUrlOpen(QUrl::fromUserInput(url
));
2714 bool DolphinMainWindow::isItemVisibleInAnyView(const QString
&urlOfItem
)
2716 return m_tabWidget
->isItemVisibleInAnyView(QUrl::fromUserInput(urlOfItem
));
2719 #include "moc_dolphinmainwindow.cpp"