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 <KMoreToolsMenuFactory>
52 #include <KProtocolInfo>
53 #include <KProtocolManager>
55 #include <KShortcutsDialog>
56 #include <KStandardAction>
57 #include <KStartupInfo>
59 #include <KTerminalLauncherJob>
60 #include <KToggleAction>
62 #include <KToolBarPopupAction>
63 #include <KUrlComboBox>
64 #include <KUrlNavigator>
65 #include <KWindowSystem>
66 #include <KXMLGUIFactory>
67 #include <kio_version.h>
69 #include <QApplication>
71 #include <QCloseEvent>
72 #include <QDesktopServices>
74 #include <QDomDocument>
78 #include <QPushButton>
80 #include <QStandardPaths>
82 #include <QToolButton>
88 // Used for GeneralSettings::version() to determine whether
89 // an updated version of Dolphin is running, so as to migrate
90 // removed/renamed ...etc config entries; increment it in such
92 const int CurrentDolphinVersion
= 202;
93 // The maximum number of entries in the back/forward popup menu
94 const int MaxNumberOfNavigationentries
= 12;
95 // The maximum number of "Activate Tab" shortcuts
96 const int MaxActivateTabShortcuts
= 9;
99 DolphinMainWindow::DolphinMainWindow()
100 : KXmlGuiWindow(nullptr)
101 , m_newFileMenu(nullptr)
102 , m_tabWidget(nullptr)
103 , m_activeViewContainer(nullptr)
104 , m_actionHandler(nullptr)
105 , m_remoteEncoding(nullptr)
107 , m_bookmarkHandler(nullptr)
108 , m_lastHandleUrlOpenJob(nullptr)
109 , m_terminalPanel(nullptr)
110 , m_placesPanel(nullptr)
111 , m_tearDownFromPlacesRequested(false)
112 , m_backAction(nullptr)
113 , m_forwardAction(nullptr)
115 Q_INIT_RESOURCE(dolphin
);
117 new MainWindowAdaptor(this);
120 setWindowFlags(Qt::WindowContextHelpButtonHint
);
122 setComponentName(QStringLiteral("dolphin"), QGuiApplication::applicationDisplayName());
123 setObjectName(QStringLiteral("Dolphin#"));
125 setStateConfigGroup("State");
127 connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::errorMessage
, this, &DolphinMainWindow::showErrorMessage
);
129 KIO::FileUndoManager
*undoManager
= KIO::FileUndoManager::self();
130 undoManager
->setUiInterface(new UndoUiInterface());
132 connect(undoManager
, &KIO::FileUndoManager::undoAvailable
, this, &DolphinMainWindow::slotUndoAvailable
);
133 connect(undoManager
, &KIO::FileUndoManager::undoTextChanged
, this, &DolphinMainWindow::slotUndoTextChanged
);
134 connect(undoManager
, &KIO::FileUndoManager::jobRecordingStarted
, this, &DolphinMainWindow::clearStatusBar
);
135 connect(undoManager
, &KIO::FileUndoManager::jobRecordingFinished
, this, &DolphinMainWindow::showCommand
);
137 const bool firstRun
= (GeneralSettings::version() < 200);
139 GeneralSettings::setViewPropsTimestamp(QDateTime::currentDateTime());
142 setAcceptDrops(true);
144 auto *navigatorsWidgetAction
= new DolphinNavigatorsWidgetAction(this);
145 actionCollection()->addAction(QStringLiteral("url_navigators"), navigatorsWidgetAction
);
146 m_tabWidget
= new DolphinTabWidget(navigatorsWidgetAction
, this);
147 m_tabWidget
->setObjectName("tabWidget");
148 connect(m_tabWidget
, &DolphinTabWidget::activeViewChanged
, this, &DolphinMainWindow::activeViewChanged
);
149 connect(m_tabWidget
, &DolphinTabWidget::tabCountChanged
, this, &DolphinMainWindow::tabCountChanged
);
150 connect(m_tabWidget
, &DolphinTabWidget::currentUrlChanged
, this, &DolphinMainWindow::updateWindowTitle
);
151 setCentralWidget(m_tabWidget
);
153 m_actionTextHelper
= new SelectionMode::ActionTextHelper(this);
156 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), m_actionTextHelper
, this);
157 connect(m_actionHandler
, &DolphinViewActionHandler::actionBeingHandled
, this, &DolphinMainWindow::clearStatusBar
);
158 connect(m_actionHandler
, &DolphinViewActionHandler::createDirectoryTriggered
, this, &DolphinMainWindow::createDirectory
);
159 connect(m_actionHandler
, &DolphinViewActionHandler::selectionModeChangeTriggered
, this, &DolphinMainWindow::slotSetSelectionMode
);
161 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
162 connect(this, &DolphinMainWindow::urlChanged
, m_remoteEncoding
, &DolphinRemoteEncoding::slotAboutToOpenUrl
);
166 setupGUI(Save
| Create
| ToolBar
);
167 stateChanged(QStringLiteral("new_file"));
169 QClipboard
*clipboard
= QApplication::clipboard();
170 connect(clipboard
, &QClipboard::dataChanged
, this, &DolphinMainWindow::updatePasteAction
);
172 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
173 toggleFilterBarAction
->setChecked(GeneralSettings::filterBar());
176 menuBar()->setVisible(false);
179 const bool showMenu
= !menuBar()->isHidden();
180 QAction
*showMenuBarAction
= actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar
));
181 showMenuBarAction
->setChecked(showMenu
); // workaround for bug #171080
183 auto hamburgerMenu
= static_cast<KHamburgerMenu
*>(actionCollection()->action(KStandardAction::name(KStandardAction::HamburgerMenu
)));
184 hamburgerMenu
->setMenuBar(menuBar());
185 hamburgerMenu
->setShowMenuBarAction(showMenuBarAction
);
186 connect(hamburgerMenu
, &KHamburgerMenu::aboutToShowMenu
, this, &DolphinMainWindow::updateHamburgerMenu
);
187 hamburgerMenu
->hideActionsOf(toolBar());
188 if (GeneralSettings::version() < 201 && !toolBar()->actions().contains(hamburgerMenu
)) {
189 addHamburgerMenuToToolbar();
192 updateAllowedToolbarAreas();
194 // enable middle-click on back/forward/up to open in a new tab
195 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
196 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotToolBarActionMiddleClicked
);
197 toolBar()->installEventFilter(middleClickEventFilter
);
201 connect(KSycoca::self(), &KSycoca::databaseChanged
, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
203 QTimer::singleShot(0, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
205 m_fileItemActions
.setParentWidget(this);
206 connect(&m_fileItemActions
, &KFileItemActions::error
, this, [this](const QString
&errorMessage
) {
207 showErrorMessage(errorMessage
);
210 connect(GeneralSettings::self(), &GeneralSettings::splitViewChanged
, this, &DolphinMainWindow::slotSplitViewChanged
);
213 DolphinMainWindow::~DolphinMainWindow()
215 // This fixes a crash on Wayland when closing the mainwindow while another dialog is open.
216 disconnect(QGuiApplication::clipboard(), &QClipboard::dataChanged
, this, &DolphinMainWindow::updatePasteAction
);
219 QVector
<DolphinViewContainer
*> DolphinMainWindow::viewContainers() const
221 QVector
<DolphinViewContainer
*> viewContainers
;
223 for (int i
= 0; i
< m_tabWidget
->count(); ++i
) {
224 DolphinTabPage
*tabPage
= m_tabWidget
->tabPageAt(i
);
226 viewContainers
<< tabPage
->primaryViewContainer();
227 if (tabPage
->splitViewEnabled()) {
228 viewContainers
<< tabPage
->secondaryViewContainer();
231 return viewContainers
;
234 void DolphinMainWindow::openDirectories(const QList
<QUrl
> &dirs
, bool splitView
)
236 m_tabWidget
->openDirectories(dirs
, splitView
);
239 void DolphinMainWindow::openDirectories(const QStringList
&dirs
, bool splitView
)
241 openDirectories(QUrl::fromStringList(dirs
), splitView
);
244 void DolphinMainWindow::openFiles(const QList
<QUrl
> &files
, bool splitView
)
246 m_tabWidget
->openFiles(files
, splitView
);
249 bool DolphinMainWindow::isFoldersPanelEnabled() const
251 return actionCollection()->action(QStringLiteral("show_folders_panel"))->isChecked();
254 bool DolphinMainWindow::isInformationPanelEnabled() const
257 return actionCollection()->action(QStringLiteral("show_information_panel"))->isChecked();
263 bool DolphinMainWindow::isSplitViewEnabledInCurrentTab() const
265 return m_tabWidget
->currentTabPage()->splitViewEnabled();
268 void DolphinMainWindow::openFiles(const QStringList
&files
, bool splitView
)
270 openFiles(QUrl::fromStringList(files
), splitView
);
273 void DolphinMainWindow::activateWindow(const QString
&activationToken
)
275 window()->setAttribute(Qt::WA_NativeWindow
, true);
277 if (KWindowSystem::isPlatformWayland()) {
278 KWindowSystem::setCurrentXdgActivationToken(activationToken
);
280 KStartupInfo::setNewStartupId(window()->windowHandle(), activationToken
.toUtf8());
283 KWindowSystem::activateWindow(window()->windowHandle());
286 bool DolphinMainWindow::isActiveWindow()
288 return window()->isActiveWindow();
291 void DolphinMainWindow::showCommand(CommandType command
)
293 DolphinStatusBar
*statusBar
= m_activeViewContainer
->statusBar();
295 case KIO::FileUndoManager::Copy
:
296 statusBar
->setText(i18nc("@info:status", "Successfully copied."));
298 case KIO::FileUndoManager::Move
:
299 statusBar
->setText(i18nc("@info:status", "Successfully moved."));
301 case KIO::FileUndoManager::Link
:
302 statusBar
->setText(i18nc("@info:status", "Successfully linked."));
304 case KIO::FileUndoManager::Trash
:
305 statusBar
->setText(i18nc("@info:status", "Successfully moved to trash."));
307 case KIO::FileUndoManager::Rename
:
308 statusBar
->setText(i18nc("@info:status", "Successfully renamed."));
311 case KIO::FileUndoManager::Mkdir
:
312 statusBar
->setText(i18nc("@info:status", "Created folder."));
320 void DolphinMainWindow::pasteIntoFolder()
322 m_activeViewContainer
->view()->pasteIntoFolder();
325 void DolphinMainWindow::changeUrl(const QUrl
&url
)
327 if (!KProtocolManager::supportsListing(url
)) {
328 // The URL navigator only checks for validity, not
329 // if the URL can be listed. An error message is
330 // shown due to DolphinViewContainer::restoreView().
334 m_activeViewContainer
->setUrl(url
);
335 updateFileAndEditActions();
340 Q_EMIT
urlChanged(url
);
343 void DolphinMainWindow::slotTerminalDirectoryChanged(const QUrl
&url
)
345 if (m_tearDownFromPlacesRequested
&& url
== QUrl::fromLocalFile(QDir::homePath())) {
346 m_placesPanel
->proceedWithTearDown();
347 m_tearDownFromPlacesRequested
= false;
350 m_activeViewContainer
->setAutoGrabFocus(false);
352 m_activeViewContainer
->setAutoGrabFocus(true);
355 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
357 KToggleAction
*editableLocationAction
= static_cast<KToggleAction
*>(actionCollection()->action(QStringLiteral("editable_location")));
358 editableLocationAction
->setChecked(editable
);
361 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
&selection
)
363 updateFileAndEditActions();
365 const int selectedUrlsCount
= m_tabWidget
->currentTabPage()->selectedItemsCount();
367 QAction
*compareFilesAction
= actionCollection()->action(QStringLiteral("compare_files"));
368 if (selectedUrlsCount
== 2) {
369 compareFilesAction
->setEnabled(isKompareInstalled());
371 compareFilesAction
->setEnabled(false);
374 Q_EMIT
selectionChanged(selection
);
377 void DolphinMainWindow::updateHistory()
379 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
380 const int index
= urlNavigator
->historyIndex();
382 QAction
*backAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Back
));
384 backAction
->setToolTip(i18nc("@info", "Go back"));
385 backAction
->setWhatsThis(i18nc("@info:whatsthis go back", "Return to the previously viewed folder."));
386 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
389 QAction
*forwardAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Forward
));
391 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
392 forwardAction
->setWhatsThis(xi18nc("@info:whatsthis go forward", "This undoes a <interface>Go|Back</interface> action."));
393 forwardAction
->setEnabled(index
> 0);
397 void DolphinMainWindow::updateFilterBarAction(bool show
)
399 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
400 toggleFilterBarAction
->setChecked(show
);
403 void DolphinMainWindow::openNewMainWindow()
405 Dolphin::openNewWindow({m_activeViewContainer
->url()}, this);
408 void DolphinMainWindow::openNewActivatedTab()
410 // keep browsers compatibility, new tab is always after last one
411 auto openNewTabAfterLastTabConfigured
= GeneralSettings::openNewTabAfterLastTab();
412 GeneralSettings::setOpenNewTabAfterLastTab(true);
413 m_tabWidget
->openNewActivatedTab();
414 GeneralSettings::setOpenNewTabAfterLastTab(openNewTabAfterLastTabConfigured
);
417 void DolphinMainWindow::addToPlaces()
422 // If nothing is selected, act on the current dir
423 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
424 url
= m_activeViewContainer
->url();
425 name
= m_activeViewContainer
->placesText();
427 const auto dirToAdd
= m_activeViewContainer
->view()->selectedItems().first();
428 url
= dirToAdd
.url();
429 name
= dirToAdd
.name();
433 if (m_activeViewContainer
->isSearchModeEnabled()) {
434 icon
= QStringLiteral("folder-saved-search-symbolic");
436 icon
= KIO::iconNameForUrl(url
);
438 DolphinPlacesModelSingleton::instance().placesModel()->addPlace(name
, url
, icon
);
442 void DolphinMainWindow::openNewTab(const QUrl
&url
)
444 m_tabWidget
->openNewTab(url
, QUrl());
447 void DolphinMainWindow::openNewTabAndActivate(const QUrl
&url
)
449 m_tabWidget
->openNewActivatedTab(url
, QUrl());
452 void DolphinMainWindow::openNewWindow(const QUrl
&url
)
454 Dolphin::openNewWindow({url
}, this);
457 void DolphinMainWindow::slotSplitViewChanged()
459 m_tabWidget
->currentTabPage()->setSplitViewEnabled(GeneralSettings::splitView(), WithAnimation
);
463 void DolphinMainWindow::openInNewTab()
465 const KFileItemList
&list
= m_activeViewContainer
->view()->selectedItems();
466 bool tabCreated
= false;
468 for (const KFileItem
&item
: list
) {
469 const QUrl
&url
= DolphinView::openItemAsFolderUrl(item
);
470 if (!url
.isEmpty()) {
476 // if no new tab has been created from the selection
477 // open the current directory in a new tab
479 openNewTab(m_activeViewContainer
->url());
483 void DolphinMainWindow::openInNewWindow()
487 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
488 if (list
.isEmpty()) {
489 newWindowUrl
= m_activeViewContainer
->url();
490 } else if (list
.count() == 1) {
491 const KFileItem
&item
= list
.first();
492 newWindowUrl
= DolphinView::openItemAsFolderUrl(item
);
495 if (!newWindowUrl
.isEmpty()) {
496 Dolphin::openNewWindow({newWindowUrl
}, this);
500 void DolphinMainWindow::openInSplitView(const QUrl
&url
)
502 QUrl newSplitViewUrl
= url
;
504 if (newSplitViewUrl
.isEmpty()) {
505 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
506 if (list
.count() == 1) {
507 const KFileItem
&item
= list
.first();
508 newSplitViewUrl
= DolphinView::openItemAsFolderUrl(item
);
512 if (newSplitViewUrl
.isEmpty()) {
516 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
517 if (tabPage
->splitViewEnabled()) {
518 tabPage
->switchActiveView();
519 tabPage
->activeViewContainer()->setUrl(newSplitViewUrl
);
521 tabPage
->setSplitViewEnabled(true, WithAnimation
, newSplitViewUrl
);
526 void DolphinMainWindow::showTarget()
528 const KFileItem link
= m_activeViewContainer
->view()->selectedItems().at(0);
529 const QUrl destinationUrl
= link
.url().resolved(QUrl(link
.linkDest()));
531 auto job
= KIO::statDetails(destinationUrl
, KIO::StatJob::SourceSide
, KIO::StatNoDetails
);
533 connect(job
, &KJob::finished
, this, [this, destinationUrl
](KJob
*job
) {
534 KIO::StatJob
*statJob
= static_cast<KIO::StatJob
*>(job
);
536 if (statJob
->error()) {
537 m_activeViewContainer
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
539 KIO::highlightInFileManager({destinationUrl
});
544 bool DolphinMainWindow::event(QEvent
*event
)
546 if (event
->type() == QEvent::ShortcutOverride
) {
547 const QKeyEvent
*keyEvent
= static_cast<QKeyEvent
*>(event
);
548 if (keyEvent
->key() == Qt::Key_Space
&& m_activeViewContainer
->view()->handleSpaceAsNormalKey()) {
554 return KXmlGuiWindow::event(event
);
557 void DolphinMainWindow::showEvent(QShowEvent
*event
)
559 KXmlGuiWindow::showEvent(event
);
561 if (!event
->spontaneous()) {
562 m_activeViewContainer
->view()->setFocus();
566 void DolphinMainWindow::closeEvent(QCloseEvent
*event
)
568 // Find out if Dolphin is closed directly by the user or
569 // by the session manager because the session is closed
570 bool closedByUser
= true;
571 if (qApp
->isSavingSession()) {
572 closedByUser
= false;
575 if (m_tabWidget
->count() > 1 && GeneralSettings::confirmClosingMultipleTabs() && !GeneralSettings::rememberOpenedTabs() && closedByUser
) {
576 // Ask the user if he really wants to quit and close all tabs.
577 // Open a confirmation dialog with 3 buttons:
578 // QDialogButtonBox::Yes -> Quit
579 // QDialogButtonBox::No -> Close only the current tab
580 // QDialogButtonBox::Cancel -> do nothing
581 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
582 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
583 dialog
->setModal(true);
584 QDialogButtonBox
*buttons
= new QDialogButtonBox(QDialogButtonBox::Yes
| QDialogButtonBox::No
| QDialogButtonBox::Cancel
);
585 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
),
586 KGuiItem(i18nc("@action:button 'Quit Dolphin' button", "&Quit %1", QGuiApplication::applicationDisplayName()),
587 QIcon::fromTheme(QStringLiteral("application-exit"))));
588 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("C&lose Current Tab"), QIcon::fromTheme(QStringLiteral("tab-close"))));
589 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
590 buttons
->button(QDialogButtonBox::Yes
)->setDefault(true);
592 bool doNotAskAgainCheckboxResult
= false;
594 const auto result
= KMessageBox::createKMessageBox(dialog
,
596 QMessageBox::Warning
,
597 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
599 i18n("Do not ask again"),
600 &doNotAskAgainCheckboxResult
,
601 KMessageBox::Notify
);
603 if (doNotAskAgainCheckboxResult
) {
604 GeneralSettings::setConfirmClosingMultipleTabs(false);
608 case QDialogButtonBox::Yes
:
611 case QDialogButtonBox::No
:
612 // Close only the current tab
613 m_tabWidget
->closeTab();
621 if (m_terminalPanel
&& m_terminalPanel
->hasProgramRunning() && GeneralSettings::confirmClosingTerminalRunningProgram() && closedByUser
) {
622 // Ask if the user really wants to quit Dolphin with a program that is still running in the Terminal panel
623 // Open a confirmation dialog with 3 buttons:
624 // QDialogButtonBox::Yes -> Quit
625 // QDialogButtonBox::No -> Show Terminal Panel
626 // QDialogButtonBox::Cancel -> do nothing
627 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
628 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
629 dialog
->setModal(true);
630 auto standardButtons
= QDialogButtonBox::Yes
| QDialogButtonBox::Cancel
;
631 if (!m_terminalPanel
->isVisible()) {
632 standardButtons
|= QDialogButtonBox::No
;
634 QDialogButtonBox
*buttons
= new QDialogButtonBox(standardButtons
);
635 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KStandardGuiItem::quit());
636 if (!m_terminalPanel
->isVisible()) {
637 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("Show &Terminal Panel"), QIcon::fromTheme(QStringLiteral("dialog-scripts"))));
639 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
641 bool doNotAskAgainCheckboxResult
= false;
643 const auto result
= KMessageBox::createKMessageBox(
646 QMessageBox::Warning
,
647 i18n("The program '%1' is still running in the Terminal panel. Are you sure you want to quit?", m_terminalPanel
->runningProgramName()),
649 i18n("Do not ask again"),
650 &doNotAskAgainCheckboxResult
,
651 KMessageBox::Notify
| KMessageBox::Dangerous
);
653 if (doNotAskAgainCheckboxResult
) {
654 GeneralSettings::setConfirmClosingTerminalRunningProgram(false);
658 case QDialogButtonBox::Yes
:
661 case QDialogButtonBox::No
:
662 actionCollection()->action("show_terminal_panel")->trigger();
663 // Do not quit, ignore quit event
671 if (GeneralSettings::rememberOpenedTabs()) {
672 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
673 KConfig
*config
= KConfigGui::sessionConfig();
674 saveGlobalProperties(config
);
675 savePropertiesInternal(config
, 1);
679 GeneralSettings::setVersion(CurrentDolphinVersion
);
680 GeneralSettings::self()->save();
682 KXmlGuiWindow::closeEvent(event
);
685 void DolphinMainWindow::saveProperties(KConfigGroup
&group
)
687 m_tabWidget
->saveProperties(group
);
690 void DolphinMainWindow::readProperties(const KConfigGroup
&group
)
692 m_tabWidget
->readProperties(group
);
695 void DolphinMainWindow::updateNewMenu()
697 m_newFileMenu
->checkUpToDate();
698 m_newFileMenu
->setWorkingDirectory(activeViewContainer()->url());
701 void DolphinMainWindow::createDirectory()
703 m_newFileMenu
->setWorkingDirectory(activeViewContainer()->url());
704 m_newFileMenu
->createDirectory();
707 void DolphinMainWindow::quit()
712 void DolphinMainWindow::showErrorMessage(const QString
&message
)
714 m_activeViewContainer
->showMessage(message
, DolphinViewContainer::Error
);
717 void DolphinMainWindow::slotUndoAvailable(bool available
)
719 QAction
*undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
721 undoAction
->setEnabled(available
);
725 void DolphinMainWindow::slotUndoTextChanged(const QString
&text
)
727 QAction
*undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
729 undoAction
->setText(text
);
733 void DolphinMainWindow::undo()
736 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
737 KIO::FileUndoManager::self()->undo();
740 void DolphinMainWindow::cut()
742 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
743 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CutContents
);
745 m_activeViewContainer
->view()->cutSelectedItemsToClipboard();
746 m_activeViewContainer
->setSelectionModeEnabled(false);
750 void DolphinMainWindow::copy()
752 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
753 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CopyContents
);
755 m_activeViewContainer
->view()->copySelectedItemsToClipboard();
756 m_activeViewContainer
->setSelectionModeEnabled(false);
760 void DolphinMainWindow::paste()
762 m_activeViewContainer
->view()->paste();
765 void DolphinMainWindow::find()
767 m_activeViewContainer
->setSearchModeEnabled(true);
770 void DolphinMainWindow::updateSearchAction()
772 QAction
*toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
773 toggleSearchAction
->setChecked(m_activeViewContainer
->isSearchModeEnabled());
776 void DolphinMainWindow::updatePasteAction()
778 QAction
*pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
779 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
780 pasteAction
->setEnabled(pasteInfo
.first
);
781 pasteAction
->setText(pasteInfo
.second
);
784 void DolphinMainWindow::slotDirectoryLoadingCompleted()
789 void DolphinMainWindow::slotToolBarActionMiddleClicked(QAction
*action
)
791 if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Back
))) {
793 } else if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Forward
))) {
795 } else if (action
== actionCollection()->action(QStringLiteral("go_up"))) {
797 } else if (action
== actionCollection()->action(QStringLiteral("go_home"))) {
802 QAction
*DolphinMainWindow::urlNavigatorHistoryAction(const KUrlNavigator
*urlNavigator
, int historyIndex
, QObject
*parent
)
804 const QUrl url
= urlNavigator
->locationUrl(historyIndex
);
806 QString text
= url
.toDisplayString(QUrl::PreferLocalFile
);
808 if (!urlNavigator
->showFullPath()) {
809 const KFilePlacesModel
*placesModel
= DolphinPlacesModelSingleton::instance().placesModel();
811 const QModelIndex closestIdx
= placesModel
->closestItem(url
);
812 if (closestIdx
.isValid()) {
813 const QUrl placeUrl
= placesModel
->url(closestIdx
);
815 text
= placesModel
->text(closestIdx
);
817 QString pathInsidePlace
= url
.path().mid(placeUrl
.path().length());
819 if (!pathInsidePlace
.isEmpty() && !pathInsidePlace
.startsWith(QLatin1Char('/'))) {
820 pathInsidePlace
.prepend(QLatin1Char('/'));
823 if (pathInsidePlace
!= QLatin1Char('/')) {
824 text
.append(pathInsidePlace
);
829 QAction
*action
= new QAction(QIcon::fromTheme(KIO::iconNameForUrl(url
)), text
, parent
);
830 action
->setData(historyIndex
);
834 void DolphinMainWindow::slotAboutToShowBackPopupMenu()
836 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
838 m_backAction
->menu()->clear();
839 for (int i
= urlNavigator
->historyIndex() + 1; i
< urlNavigator
->historySize() && entries
< MaxNumberOfNavigationentries
; ++i
, ++entries
) {
840 QAction
*action
= urlNavigatorHistoryAction(urlNavigator
, i
, m_backAction
->menu());
841 m_backAction
->menu()->addAction(action
);
845 void DolphinMainWindow::slotGoBack(QAction
*action
)
847 int gotoIndex
= action
->data().value
<int>();
848 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
849 for (int i
= gotoIndex
- urlNavigator
->historyIndex(); i
> 0; --i
) {
854 void DolphinMainWindow::slotBackForwardActionMiddleClicked(QAction
*action
)
857 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
858 openNewTab(urlNavigator
->locationUrl(action
->data().value
<int>()));
862 void DolphinMainWindow::slotAboutToShowForwardPopupMenu()
864 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
866 m_forwardAction
->menu()->clear();
867 for (int i
= urlNavigator
->historyIndex() - 1; i
>= 0 && entries
< MaxNumberOfNavigationentries
; --i
, ++entries
) {
868 QAction
*action
= urlNavigatorHistoryAction(urlNavigator
, i
, m_forwardAction
->menu());
869 m_forwardAction
->menu()->addAction(action
);
873 void DolphinMainWindow::slotGoForward(QAction
*action
)
875 int gotoIndex
= action
->data().value
<int>();
876 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
877 for (int i
= urlNavigator
->historyIndex() - gotoIndex
; i
> 0; --i
) {
882 void DolphinMainWindow::slotSetSelectionMode(bool enabled
, SelectionMode::BottomBar::Contents bottomBarContents
)
884 m_activeViewContainer
->setSelectionModeEnabled(enabled
, actionCollection(), bottomBarContents
);
887 void DolphinMainWindow::selectAll()
891 // if the URL navigator is editable and focused, select the whole
892 // URL instead of all items of the view
894 KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigator();
895 QLineEdit
*lineEdit
= urlNavigator
->editor()->lineEdit();
896 const bool selectUrl
= urlNavigator
->isUrlEditable() && lineEdit
->hasFocus();
898 lineEdit
->selectAll();
900 m_activeViewContainer
->view()->selectAll();
904 void DolphinMainWindow::invertSelection()
907 m_activeViewContainer
->view()->invertSelection();
910 void DolphinMainWindow::toggleSplitView()
912 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
913 tabPage
->setSplitViewEnabled(!tabPage
->splitViewEnabled(), WithAnimation
);
917 void DolphinMainWindow::toggleSplitStash()
919 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
920 tabPage
->setSplitViewEnabled(false, WithAnimation
);
921 tabPage
->setSplitViewEnabled(true, WithAnimation
, QUrl("stash:/"));
924 void DolphinMainWindow::copyToInactiveSplitView()
926 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
927 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CopyToOtherViewContents
);
929 m_tabWidget
->copyToInactiveSplitView();
930 m_activeViewContainer
->setSelectionModeEnabled(false);
934 void DolphinMainWindow::moveToInactiveSplitView()
936 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
937 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::MoveToOtherViewContents
);
939 m_tabWidget
->moveToInactiveSplitView();
940 m_activeViewContainer
->setSelectionModeEnabled(false);
944 void DolphinMainWindow::reloadView()
947 m_activeViewContainer
->reload();
948 m_activeViewContainer
->statusBar()->updateSpaceInfo();
951 void DolphinMainWindow::stopLoading()
953 m_activeViewContainer
->view()->stopLoading();
956 void DolphinMainWindow::enableStopAction()
958 actionCollection()->action(QStringLiteral("stop"))->setEnabled(true);
961 void DolphinMainWindow::disableStopAction()
963 actionCollection()->action(QStringLiteral("stop"))->setEnabled(false);
966 void DolphinMainWindow::toggleSelectionMode()
968 const bool checked
= !m_activeViewContainer
->isSelectionModeEnabled();
970 m_activeViewContainer
->setSelectionModeEnabled(checked
, actionCollection(), SelectionMode::BottomBar::Contents::GeneralContents
);
971 actionCollection()->action(QStringLiteral("toggle_selection_mode"))->setChecked(checked
);
974 void DolphinMainWindow::showFilterBar()
976 m_activeViewContainer
->setFilterBarVisible(true);
979 void DolphinMainWindow::toggleFilterBar()
981 const bool checked
= !m_activeViewContainer
->isFilterBarVisible();
982 m_activeViewContainer
->setFilterBarVisible(checked
);
984 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
985 toggleFilterBarAction
->setChecked(checked
);
988 void DolphinMainWindow::toggleEditLocation()
992 QAction
*action
= actionCollection()->action(QStringLiteral("editable_location"));
993 KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigator();
994 urlNavigator
->setUrlEditable(action
->isChecked());
997 void DolphinMainWindow::replaceLocation()
999 KUrlNavigator
*navigator
= m_activeViewContainer
->urlNavigator();
1000 QLineEdit
*lineEdit
= navigator
->editor()->lineEdit();
1002 // If the text field currently has focus and everything is selected,
1003 // pressing the keyboard shortcut returns the whole thing to breadcrumb mode
1004 if (navigator
->isUrlEditable() && lineEdit
->hasFocus() && lineEdit
->selectedText() == lineEdit
->text()) {
1005 navigator
->setUrlEditable(false);
1007 navigator
->setUrlEditable(true);
1008 navigator
->setFocus();
1009 lineEdit
->selectAll();
1013 void DolphinMainWindow::togglePanelLockState()
1015 const bool newLockState
= !GeneralSettings::lockPanels();
1016 const auto childrenObjects
= children();
1017 for (QObject
*child
: childrenObjects
) {
1018 DolphinDockWidget
*dock
= qobject_cast
<DolphinDockWidget
*>(child
);
1020 dock
->setLocked(newLockState
);
1024 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(newLockState
);
1026 GeneralSettings::setLockPanels(newLockState
);
1029 void DolphinMainWindow::slotTerminalPanelVisibilityChanged()
1031 if (m_terminalPanel
->isHiddenInVisibleWindow() && m_activeViewContainer
) {
1032 m_activeViewContainer
->view()->setFocus();
1036 void DolphinMainWindow::goBack()
1038 DolphinUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
1039 urlNavigator
->goBack();
1041 if (urlNavigator
->locationState().isEmpty()) {
1042 // An empty location state indicates a redirection URL,
1043 // which must be skipped too
1044 urlNavigator
->goBack();
1048 void DolphinMainWindow::goForward()
1050 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goForward();
1053 void DolphinMainWindow::goUp()
1055 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goUp();
1058 void DolphinMainWindow::goHome()
1060 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goHome();
1063 void DolphinMainWindow::goBackInNewTab()
1065 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
1066 const int index
= urlNavigator
->historyIndex() + 1;
1067 openNewTab(urlNavigator
->locationUrl(index
));
1070 void DolphinMainWindow::goForwardInNewTab()
1072 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
1073 const int index
= urlNavigator
->historyIndex() - 1;
1074 openNewTab(urlNavigator
->locationUrl(index
));
1077 void DolphinMainWindow::goUpInNewTab()
1079 const QUrl currentUrl
= activeViewContainer()->urlNavigator()->locationUrl();
1080 openNewTab(KIO::upUrl(currentUrl
));
1083 void DolphinMainWindow::goHomeInNewTab()
1085 openNewTab(Dolphin::homeUrl());
1088 void DolphinMainWindow::compareFiles()
1090 const KFileItemList items
= m_tabWidget
->currentTabPage()->selectedItems();
1091 if (items
.count() != 2) {
1092 // The action is disabled in this case, but it could have been triggered
1093 // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
1097 QUrl urlA
= items
.at(0).url();
1098 QUrl urlB
= items
.at(1).url();
1100 QString
command(QStringLiteral("kompare -c \""));
1101 command
.append(urlA
.toDisplayString(QUrl::PreferLocalFile
));
1102 command
.append("\" \"");
1103 command
.append(urlB
.toDisplayString(QUrl::PreferLocalFile
));
1104 command
.append('\"');
1106 KIO::CommandLauncherJob
*job
= new KIO::CommandLauncherJob(command
, this);
1107 job
->setDesktopName(QStringLiteral("org.kde.kompare"));
1111 void DolphinMainWindow::toggleShowMenuBar()
1113 const bool visible
= menuBar()->isVisible();
1114 menuBar()->setVisible(!visible
);
1117 QPointer
<QAction
> DolphinMainWindow::preferredSearchTool()
1119 m_searchTools
.clear();
1120 KMoreToolsMenuFactory("dolphin/search-tools").fillMenuFromGroupingNames(&m_searchTools
, {"files-find"}, m_activeViewContainer
->url());
1121 QList
<QAction
*> actions
= m_searchTools
.actions();
1122 if (actions
.isEmpty()) {
1125 QAction
*action
= actions
.first();
1126 if (action
->isSeparator()) {
1132 void DolphinMainWindow::updateOpenPreferredSearchToolAction()
1134 QAction
*openPreferredSearchTool
= actionCollection()->action(QStringLiteral("open_preferred_search_tool"));
1135 if (!openPreferredSearchTool
) {
1138 QPointer
<QAction
> tool
= preferredSearchTool();
1140 openPreferredSearchTool
->setVisible(true);
1141 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open %1", tool
->text()));
1142 // Only override with the app icon if it is the default, i.e. the user hasn't configured one manually
1143 // https://bugs.kde.org/show_bug.cgi?id=442815
1144 if (openPreferredSearchTool
->icon().name() == QLatin1String("search")) {
1145 openPreferredSearchTool
->setIcon(tool
->icon());
1148 openPreferredSearchTool
->setVisible(false);
1149 // still visible in Shortcuts configuration window
1150 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1151 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1155 void DolphinMainWindow::openPreferredSearchTool()
1157 QPointer
<QAction
> tool
= preferredSearchTool();
1163 void DolphinMainWindow::openTerminal()
1165 openTerminalJob(m_activeViewContainer
->url());
1168 void DolphinMainWindow::openTerminalHere()
1170 QList
<QUrl
> urls
= {};
1172 const auto selectedItems
= m_activeViewContainer
->view()->selectedItems();
1173 for (const KFileItem
&item
: selectedItems
) {
1174 QUrl url
= item
.targetUrl();
1175 if (item
.isFile()) {
1176 url
.setPath(QFileInfo(url
.path()).absolutePath());
1178 if (!urls
.contains(url
)) {
1183 // No items are selected. Open a terminal window for the current location.
1184 if (urls
.count() == 0) {
1189 if (urls
.count() > 5) {
1190 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());
1191 const int answer
= KMessageBox::warningContinueCancel(
1195 KGuiItem(i18ncp("@action:button", "Open %1 Terminal", "Open %1 Terminals", urls
.count()), QStringLiteral("utilities-terminal")),
1196 KStandardGuiItem::cancel(),
1197 QStringLiteral("ConfirmOpenManyTerminals"));
1198 if (answer
!= KMessageBox::PrimaryAction
&& answer
!= KMessageBox::Continue
) {
1203 for (const QUrl
&url
: std::as_const(urls
)) {
1204 openTerminalJob(url
);
1208 void DolphinMainWindow::openTerminalJob(const QUrl
&url
)
1210 if (url
.isLocalFile()) {
1211 auto job
= new KTerminalLauncherJob(QString());
1212 job
->setWorkingDirectory(url
.toLocalFile());
1217 // Not a local file, with protocol Class ":local", try stat'ing
1218 if (KProtocolInfo::protocolClass(url
.scheme()) == QLatin1String(":local")) {
1219 KIO::StatJob
*job
= KIO::mostLocalUrl(url
);
1220 KJobWidgets::setWindow(job
, this);
1221 connect(job
, &KJob::result
, this, [job
]() {
1223 if (!job
->error()) {
1224 statUrl
= job
->mostLocalUrl();
1227 auto job
= new KTerminalLauncherJob(QString());
1228 job
->setWorkingDirectory(statUrl
.isLocalFile() ? statUrl
.toLocalFile() : QDir::homePath());
1235 // Nothing worked, just use $HOME
1236 auto job
= new KTerminalLauncherJob(QString());
1237 job
->setWorkingDirectory(QDir::homePath());
1241 void DolphinMainWindow::editSettings()
1243 if (!m_settingsDialog
) {
1244 DolphinViewContainer
*container
= activeViewContainer();
1245 container
->view()->writeSettings();
1247 const QUrl url
= container
->url();
1248 DolphinSettingsDialog
*settingsDialog
= new DolphinSettingsDialog(url
, this, actionCollection());
1249 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, this, &DolphinMainWindow::refreshViews
);
1250 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, &DolphinUrlNavigatorsController::slotReadSettings
);
1251 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1252 settingsDialog
->show();
1253 m_settingsDialog
= settingsDialog
;
1255 m_settingsDialog
.data()->raise();
1259 void DolphinMainWindow::handleUrl(const QUrl
&url
)
1261 delete m_lastHandleUrlOpenJob
;
1262 m_lastHandleUrlOpenJob
= nullptr;
1264 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1265 activeViewContainer()->setUrl(url
);
1267 m_lastHandleUrlOpenJob
= new KIO::OpenUrlJob(url
);
1268 m_lastHandleUrlOpenJob
->setUiDelegate(KIO::createDefaultJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
1269 m_lastHandleUrlOpenJob
->setShowOpenOrExecuteDialog(true);
1271 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::mimeTypeFound
, this, [this, url
](const QString
&mimetype
) {
1272 if (mimetype
== QLatin1String("inode/directory")) {
1273 // If it's a dir, we'll take it from here
1274 m_lastHandleUrlOpenJob
->kill();
1275 m_lastHandleUrlOpenJob
= nullptr;
1276 activeViewContainer()->setUrl(url
);
1280 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::result
, this, [this]() {
1281 m_lastHandleUrlOpenJob
= nullptr;
1284 m_lastHandleUrlOpenJob
->start();
1288 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1290 // trash:/ is writable but we don't want to create new items in it.
1291 // TODO: remove the trash check once https://phabricator.kde.org/T8234 is implemented
1292 newFileMenu()->setEnabled(isFolderWritable
&& m_activeViewContainer
->url().scheme() != QLatin1String("trash"));
1295 void DolphinMainWindow::openContextMenu(const QPoint
&pos
, const KFileItem
&item
, const KFileItemList
&selectedItems
, const QUrl
&url
)
1297 QPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, item
, selectedItems
, url
, &m_fileItemActions
);
1298 contextMenu
.data()->exec(pos
);
1300 // Delete the menu, unless it has been deleted in its own nested event loop already.
1302 contextMenu
->deleteLater();
1306 QMenu
*DolphinMainWindow::createPopupMenu()
1308 QMenu
*menu
= KXmlGuiWindow::createPopupMenu();
1310 menu
->addSeparator();
1311 menu
->addAction(actionCollection()->action(QStringLiteral("lock_panels")));
1316 void DolphinMainWindow::updateHamburgerMenu()
1318 KActionCollection
*ac
= actionCollection();
1319 auto hamburgerMenu
= static_cast<KHamburgerMenu
*>(ac
->action(KStandardAction::name(KStandardAction::HamburgerMenu
)));
1320 auto menu
= hamburgerMenu
->menu();
1322 menu
= new QMenu(this);
1323 hamburgerMenu
->setMenu(menu
);
1324 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("basic_actions"))->menu());
1325 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("zoom"))->menu());
1329 const QList
<QAction
*> toolbarActions
= toolBar()->actions();
1331 if (!toolBar()->isVisible()) {
1332 // If neither the menu bar nor the toolbar are visible, these actions should be available.
1333 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)));
1334 menu
->addAction(toolBarMenuAction());
1335 menu
->addSeparator();
1338 // This group of actions (until the next separator) contains all the most basic actions
1339 // necessary to use Dolphin effectively.
1340 menu
->addAction(ac
->action(QStringLiteral("go_back")));
1341 menu
->addAction(ac
->action(QStringLiteral("go_forward")));
1343 menu
->addMenu(m_newFileMenu
->menu());
1344 if (!toolBar()->isVisible() || !toolbarActions
.contains(ac
->action(QStringLiteral("toggle_selection_mode_tool_bar")))) {
1345 menu
->addAction(ac
->action(QStringLiteral("toggle_selection_mode")));
1347 menu
->addAction(ac
->action(QStringLiteral("basic_actions")));
1348 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Undo
)));
1349 if (!toolBar()->isVisible()
1350 || (!toolbarActions
.contains(ac
->action(QStringLiteral("toggle_search")))
1351 && !toolbarActions
.contains(ac
->action(QStringLiteral("open_preferred_search_tool"))))) {
1352 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Find
)));
1353 // This way a search action will only be added if none of the three available
1354 // search actions is present on the toolbar.
1356 if (!toolBar()->isVisible() || !toolbarActions
.contains(ac
->action(QStringLiteral("toggle_filter")))) {
1357 menu
->addAction(ac
->action(QStringLiteral("show_filter_bar")));
1358 // This way a filter action will only be added if none of the two available
1359 // filter actions is present on the toolbar.
1361 menu
->addSeparator();
1363 // The second group of actions (up until the next separator) contains actions for opening
1364 // additional views to interact with the file system.
1365 menu
->addAction(ac
->action(QStringLiteral("file_new")));
1366 menu
->addAction(ac
->action(QStringLiteral("new_tab")));
1367 if (ac
->action(QStringLiteral("undo_close_tab"))->isEnabled()) {
1368 menu
->addAction(ac
->action(QStringLiteral("closed_tabs")));
1370 menu
->addAction(ac
->action(QStringLiteral("open_terminal")));
1371 menu
->addSeparator();
1373 // The third group contains actions to change what one sees in the view
1374 // and to change the more general UI.
1375 if (!toolBar()->isVisible()
1376 || (!toolbarActions
.contains(ac
->action(QStringLiteral("icons"))) && !toolbarActions
.contains(ac
->action(QStringLiteral("compact")))
1377 && !toolbarActions
.contains(ac
->action(QStringLiteral("details"))) && !toolbarActions
.contains(ac
->action(QStringLiteral("view_mode"))))) {
1378 menu
->addAction(ac
->action(QStringLiteral("view_mode")));
1380 menu
->addAction(ac
->action(QStringLiteral("show_hidden_files")));
1381 menu
->addAction(ac
->action(QStringLiteral("sort")));
1382 menu
->addAction(ac
->action(QStringLiteral("additional_info")));
1383 if (!GeneralSettings::showStatusBar() || !GeneralSettings::showZoomSlider()) {
1384 menu
->addAction(ac
->action(QStringLiteral("zoom")));
1386 menu
->addAction(ac
->action(QStringLiteral("panels")));
1388 // The "Configure" menu is not added to the actionCollection() because there is hardly
1389 // a good reason for users to put it on their toolbar.
1390 auto configureMenu
= menu
->addMenu(QIcon::fromTheme(QStringLiteral("configure")), i18nc("@action:inmenu menu for configure actions", "Configure"));
1391 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
)));
1392 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)));
1393 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)));
1394 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Preferences
)));
1395 hamburgerMenu
->hideActionsOf(configureMenu
);
1398 void DolphinMainWindow::slotPlaceActivated(const QUrl
&url
)
1400 DolphinViewContainer
*view
= activeViewContainer();
1402 if (view
->url() == url
) {
1403 view
->clearFilterBar(); // Fixes bug 259382.
1405 // We can end up here if the user clicked a device in the Places Panel
1406 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
1409 view
->disableUrlNavigatorSelectionRequests();
1411 view
->enableUrlNavigatorSelectionRequests();
1415 void DolphinMainWindow::closedTabsCountChanged(unsigned int count
)
1417 actionCollection()->action(QStringLiteral("undo_close_tab"))->setEnabled(count
> 0);
1420 void DolphinMainWindow::activeViewChanged(DolphinViewContainer
*viewContainer
)
1422 DolphinViewContainer
*oldViewContainer
= m_activeViewContainer
;
1423 Q_ASSERT(viewContainer
);
1425 m_activeViewContainer
= viewContainer
;
1427 if (oldViewContainer
) {
1428 const QAction
*toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
1429 toggleSearchAction
->disconnect(oldViewContainer
);
1431 // Disconnect all signals between the old view container (container,
1432 // view and url navigator) and main window.
1433 oldViewContainer
->disconnect(this);
1434 oldViewContainer
->view()->disconnect(this);
1435 oldViewContainer
->urlNavigatorInternalWithHistory()->disconnect(this);
1436 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
1437 navigators
->primaryUrlNavigator()->disconnect(this);
1438 if (auto secondaryUrlNavigator
= navigators
->secondaryUrlNavigator()) {
1439 secondaryUrlNavigator
->disconnect(this);
1442 // except the requestItemInfo so that on hover the information panel can still be updated
1443 connect(oldViewContainer
->view(), &DolphinView::requestItemInfo
, this, &DolphinMainWindow::requestItemInfo
);
1445 // Disconnect other slots.
1446 disconnect(oldViewContainer
,
1447 &DolphinViewContainer::selectionModeChanged
,
1448 actionCollection()->action(QStringLiteral("toggle_selection_mode")),
1449 &QAction::setChecked
);
1452 connectViewSignals(viewContainer
);
1454 m_actionHandler
->setCurrentView(viewContainer
->view());
1457 updateFileAndEditActions();
1458 updatePasteAction();
1459 updateViewActions();
1461 updateSearchAction();
1463 const QUrl url
= viewContainer
->url();
1464 Q_EMIT
urlChanged(url
);
1467 void DolphinMainWindow::tabCountChanged(int count
)
1469 const bool enableTabActions
= (count
> 1);
1470 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1471 actionCollection()->action(QStringLiteral("activate_tab_%1").arg(i
))->setEnabled(enableTabActions
);
1473 actionCollection()->action(QStringLiteral("activate_last_tab"))->setEnabled(enableTabActions
);
1474 actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions
);
1475 actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions
);
1478 void DolphinMainWindow::updateWindowTitle()
1480 const QString newTitle
= m_activeViewContainer
->captionWindowTitle();
1481 if (windowTitle() != newTitle
) {
1482 setWindowTitle(newTitle
);
1486 void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString
&mountPath
)
1488 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1489 setViewsToHomeIfMountPathOpen(mountPath
);
1492 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectoryIsChildOf(mountPath
)) {
1493 m_tearDownFromPlacesRequested
= true;
1494 m_terminalPanel
->goHome();
1495 // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged
1497 m_placesPanel
->proceedWithTearDown();
1501 void DolphinMainWindow::slotStorageTearDownExternallyRequested(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
= false;
1509 m_terminalPanel
->goHome();
1513 void DolphinMainWindow::slotKeyBindings()
1515 KShortcutsDialog
dialog(KShortcutsEditor::AllActions
, KShortcutsEditor::LetterShortcutsAllowed
, this);
1516 dialog
.addCollection(actionCollection());
1517 if (m_terminalPanel
) {
1518 KActionCollection
*konsolePartActionCollection
= m_terminalPanel
->actionCollection();
1519 if (konsolePartActionCollection
) {
1520 dialog
.addCollection(konsolePartActionCollection
, QStringLiteral("KonsolePart"));
1526 void DolphinMainWindow::setViewsToHomeIfMountPathOpen(const QString
&mountPath
)
1528 const QVector
<DolphinViewContainer
*> theViewContainers
= viewContainers();
1529 for (DolphinViewContainer
*viewContainer
: theViewContainers
) {
1530 if (viewContainer
&& viewContainer
->url().toLocalFile().startsWith(mountPath
)) {
1531 viewContainer
->setUrl(QUrl::fromLocalFile(QDir::homePath()));
1534 disconnect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, nullptr, nullptr);
1537 void DolphinMainWindow::setupActions()
1539 auto hamburgerMenuAction
= KStandardAction::hamburgerMenu(nullptr, nullptr, actionCollection());
1541 // setup 'File' menu
1542 m_newFileMenu
= new DolphinNewFileMenu(actionCollection(), this);
1543 QMenu
*menu
= m_newFileMenu
->menu();
1544 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1545 menu
->setIcon(QIcon::fromTheme(QStringLiteral("list-add")));
1546 m_newFileMenu
->setPopupMode(QToolButton::InstantPopup
);
1547 connect(menu
, &QMenu::aboutToShow
, this, &DolphinMainWindow::updateNewMenu
);
1549 QAction
*newWindow
= KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow
, actionCollection());
1550 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1551 newWindow
->setToolTip(i18nc("@info", "Open a new Dolphin window"));
1552 newWindow
->setWhatsThis(xi18nc("@info:whatsthis",
1554 "window just like this one with the current location and view."
1555 "<nl/>You can drag and drop items between windows."));
1556 newWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1558 QAction
*newTab
= actionCollection()->addAction(QStringLiteral("new_tab"));
1559 newTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1560 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1561 newTab
->setWhatsThis(xi18nc("@info:whatsthis",
1563 "<emphasis>Tab</emphasis> with the current location and view.<nl/>"
1564 "A tab is an additional view within this window. "
1565 "You can drag and drop items between tabs."));
1566 actionCollection()->setDefaultShortcuts(newTab
, {Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
});
1567 connect(newTab
, &QAction::triggered
, this, &DolphinMainWindow::openNewActivatedTab
);
1569 QAction
*addToPlaces
= actionCollection()->addAction(QStringLiteral("add_to_places"));
1570 addToPlaces
->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new")));
1571 addToPlaces
->setText(i18nc("@action:inmenu Add current folder to places", "Add to Places"));
1572 addToPlaces
->setWhatsThis(xi18nc("@info:whatsthis",
1573 "This adds the selected folder "
1574 "to the Places panel."));
1575 connect(addToPlaces
, &QAction::triggered
, this, &DolphinMainWindow::addToPlaces
);
1577 QAction
*closeTab
= KStandardAction::close(m_tabWidget
, QOverload
<>::of(&DolphinTabWidget::closeTab
), actionCollection());
1578 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1579 closeTab
->setWhatsThis(i18nc("@info:whatsthis",
1581 "currently viewed tab. If no more tabs are left this window "
1582 "will close instead."));
1584 QAction
*quitAction
= KStandardAction::quit(this, &DolphinMainWindow::quit
, actionCollection());
1585 quitAction
->setWhatsThis(i18nc("@info:whatsthis quit", "This closes this window."));
1587 // setup 'Edit' menu
1588 KStandardAction::undo(this, &DolphinMainWindow::undo
, actionCollection());
1590 // i18n: This will be the last paragraph for the whatsthis for all three:
1591 // Cut, Copy and Paste
1592 const QString cutCopyPastePara
= xi18nc("@info:whatsthis",
1593 "<para><emphasis>Cut, "
1594 "Copy</emphasis> and <emphasis>Paste</emphasis> work between many "
1595 "applications and are among the most used commands. That's why their "
1596 "<emphasis>keyboard shortcuts</emphasis> are prominently placed right "
1597 "next to each other on the keyboard: <shortcut>Ctrl+X</shortcut>, "
1598 "<shortcut>Ctrl+C</shortcut> and <shortcut>Ctrl+V</shortcut>.</para>");
1599 QAction
*cutAction
= KStandardAction::cut(this, &DolphinMainWindow::cut
, actionCollection());
1600 m_actionTextHelper
->registerTextWhenNothingIsSelected(cutAction
, i18nc("@action", "Cut…"));
1601 cutAction
->setWhatsThis(xi18nc("@info:whatsthis cut",
1602 "This copies the items "
1603 "in your current selection to the <emphasis>clipboard</emphasis>.<nl/>"
1604 "Use the <emphasis>Paste</emphasis> action afterwards to copy them from "
1605 "the clipboard to a new location. The items will be removed from their "
1606 "initial location.")
1607 + cutCopyPastePara
);
1608 QAction
*copyAction
= KStandardAction::copy(this, &DolphinMainWindow::copy
, actionCollection());
1609 m_actionTextHelper
->registerTextWhenNothingIsSelected(copyAction
, i18nc("@action", "Copy…"));
1610 copyAction
->setWhatsThis(xi18nc("@info:whatsthis copy",
1612 "items in your current selection to the <emphasis>clipboard</emphasis>."
1613 "<nl/>Use the <emphasis>Paste</emphasis> action afterwards to copy them "
1614 "from the clipboard to a new location.")
1615 + cutCopyPastePara
);
1616 QAction
*paste
= KStandardAction::paste(this, &DolphinMainWindow::paste
, actionCollection());
1617 // The text of the paste-action is modified dynamically by Dolphin
1618 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1619 // due to the long text, the text "Paste" is used:
1620 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1621 paste
->setWhatsThis(xi18nc("@info:whatsthis paste",
1622 "This copies the items from "
1623 "your <emphasis>clipboard</emphasis> to the currently viewed folder.<nl/>"
1624 "If the items were added to the clipboard by the <emphasis>Cut</emphasis> "
1625 "action they are removed from their old location.")
1626 + cutCopyPastePara
);
1628 QAction
*copyToOtherViewAction
= actionCollection()->addAction(QStringLiteral("copy_to_inactive_split_view"));
1629 copyToOtherViewAction
->setText(i18nc("@action:inmenu", "Copy to Other View"));
1630 m_actionTextHelper
->registerTextWhenNothingIsSelected(copyToOtherViewAction
, i18nc("@action:inmenu", "Copy to Other View…"));
1631 copyToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Copy",
1632 "This copies the selected items from "
1633 "the <emphasis>active</emphasis> view to the inactive split view."));
1634 copyToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
1635 copyToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Copy to Inactive Split View"));
1636 actionCollection()->setDefaultShortcut(copyToOtherViewAction
, Qt::SHIFT
| Qt::Key_F5
);
1637 connect(copyToOtherViewAction
, &QAction::triggered
, this, &DolphinMainWindow::copyToInactiveSplitView
);
1639 QAction
*moveToOtherViewAction
= actionCollection()->addAction(QStringLiteral("move_to_inactive_split_view"));
1640 moveToOtherViewAction
->setText(i18nc("@action:inmenu", "Move to Other View"));
1641 m_actionTextHelper
->registerTextWhenNothingIsSelected(moveToOtherViewAction
, i18nc("@action:inmenu", "Move to Other View…"));
1642 moveToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Move",
1643 "This moves the selected items from "
1644 "the <emphasis>active</emphasis> view to the inactive split view."));
1645 moveToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-cut")));
1646 moveToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Move to Inactive Split View"));
1647 actionCollection()->setDefaultShortcut(moveToOtherViewAction
, Qt::SHIFT
| Qt::Key_F6
);
1648 connect(moveToOtherViewAction
, &QAction::triggered
, this, &DolphinMainWindow::moveToInactiveSplitView
);
1650 QAction
*showFilterBar
= actionCollection()->addAction(QStringLiteral("show_filter_bar"));
1651 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Filter…"));
1652 showFilterBar
->setToolTip(i18nc("@info:tooltip", "Show Filter Bar"));
1653 showFilterBar
->setWhatsThis(xi18nc("@info:whatsthis",
1655 "<emphasis>Filter Bar</emphasis> at the bottom of the window.<nl/> "
1656 "There you can enter a text to filter the files and folders currently displayed. "
1657 "Only those that contain the text in their name will be kept in view."));
1658 showFilterBar
->setIcon(QIcon::fromTheme(QStringLiteral("view-filter")));
1659 actionCollection()->setDefaultShortcuts(showFilterBar
, {Qt::CTRL
| Qt::Key_I
, Qt::Key_Slash
});
1660 connect(showFilterBar
, &QAction::triggered
, this, &DolphinMainWindow::showFilterBar
);
1662 // toggle_filter acts as a copy of the main showFilterBar to be used mainly
1663 // in the toolbar, with no default shortcut attached, to avoid messing with
1664 // existing workflows (filter bar always open and Ctrl-I to focus)
1665 QAction
*toggleFilter
= actionCollection()->addAction(QStringLiteral("toggle_filter"));
1666 toggleFilter
->setText(i18nc("@action:inmenu", "Toggle Filter Bar"));
1667 toggleFilter
->setIconText(i18nc("@action:intoolbar", "Filter"));
1668 toggleFilter
->setIcon(showFilterBar
->icon());
1669 toggleFilter
->setToolTip(showFilterBar
->toolTip());
1670 toggleFilter
->setWhatsThis(showFilterBar
->whatsThis());
1671 toggleFilter
->setCheckable(true);
1672 connect(toggleFilter
, &QAction::triggered
, this, &DolphinMainWindow::toggleFilterBar
);
1674 QAction
*searchAction
= KStandardAction::find(this, &DolphinMainWindow::find
, actionCollection());
1675 searchAction
->setText(i18n("Search…"));
1676 searchAction
->setToolTip(i18nc("@info:tooltip", "Search for files and folders"));
1677 searchAction
->setWhatsThis(xi18nc("@info:whatsthis find",
1678 "<para>This helps you "
1679 "find files and folders by opening a <emphasis>find bar</emphasis>. "
1680 "There you can enter search terms and specify settings to find the "
1681 "objects you are looking for.</para><para>Use this help again on "
1682 "the find bar so we can have a look at it while the settings are "
1683 "explained.</para>"));
1685 // toggle_search acts as a copy of the main searchAction to be used mainly
1686 // in the toolbar, with no default shortcut attached, to avoid messing with
1687 // existing workflows (search bar always open and Ctrl-F to focus)
1688 QAction
*toggleSearchAction
= actionCollection()->addAction(QStringLiteral("toggle_search"));
1689 toggleSearchAction
->setText(i18nc("@action:inmenu", "Toggle Search Bar"));
1690 toggleSearchAction
->setIconText(i18nc("@action:intoolbar", "Search"));
1691 toggleSearchAction
->setIcon(searchAction
->icon());
1692 toggleSearchAction
->setToolTip(searchAction
->toolTip());
1693 toggleSearchAction
->setWhatsThis(searchAction
->whatsThis());
1694 toggleSearchAction
->setCheckable(true);
1696 QAction
*toggleSelectionModeAction
= actionCollection()->addAction(QStringLiteral("toggle_selection_mode"));
1697 // i18n: This action toggles a selection mode.
1698 toggleSelectionModeAction
->setText(i18nc("@action:inmenu", "Select Files and Folders"));
1699 // i18n: Opens a selection mode for selecting files/folders.
1700 // The text is kept so unspecific because it will be shown on the toolbar where space is at a premium.
1701 toggleSelectionModeAction
->setIconText(i18nc("@action:intoolbar", "Select"));
1702 toggleSelectionModeAction
->setWhatsThis(xi18nc(
1704 "<para>This application only knows which files or folders should be acted on if they are"
1705 " <emphasis>selected</emphasis> first. Press this to toggle a <emphasis>Selection Mode</emphasis> which makes selecting and deselecting as easy as "
1706 "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."
1708 toggleSelectionModeAction
->setIcon(QIcon::fromTheme(QStringLiteral("quickwizard")));
1709 toggleSelectionModeAction
->setCheckable(true);
1710 actionCollection()->setDefaultShortcut(toggleSelectionModeAction
, Qt::Key_Space
);
1711 connect(toggleSelectionModeAction
, &QAction::triggered
, this, &DolphinMainWindow::toggleSelectionMode
);
1713 // A special version of the toggleSelectionModeAction for the toolbar that also contains a menu
1714 // with the selectAllAction and invertSelectionAction.
1715 auto *toggleSelectionModeToolBarAction
=
1716 new KToolBarPopupAction(toggleSelectionModeAction
->icon(), toggleSelectionModeAction
->iconText(), actionCollection());
1717 toggleSelectionModeToolBarAction
->setToolTip(toggleSelectionModeAction
->text());
1718 toggleSelectionModeToolBarAction
->setWhatsThis(toggleSelectionModeAction
->whatsThis());
1719 actionCollection()->addAction(QStringLiteral("toggle_selection_mode_tool_bar"), toggleSelectionModeToolBarAction
);
1720 toggleSelectionModeToolBarAction
->setCheckable(true);
1721 toggleSelectionModeToolBarAction
->setPopupMode(QToolButton::DelayedPopup
);
1722 connect(toggleSelectionModeToolBarAction
, &QAction::triggered
, toggleSelectionModeAction
, &QAction::trigger
);
1723 connect(toggleSelectionModeAction
, &QAction::toggled
, toggleSelectionModeToolBarAction
, &QAction::setChecked
);
1725 QAction
*selectAllAction
= KStandardAction::selectAll(this, &DolphinMainWindow::selectAll
, actionCollection());
1726 selectAllAction
->setWhatsThis(xi18nc("@info:whatsthis",
1728 "files and folders in the current location."));
1730 QAction
*invertSelection
= actionCollection()->addAction(QStringLiteral("invert_selection"));
1731 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1732 invertSelection
->setWhatsThis(xi18nc("@info:whatsthis invert",
1734 "objects that you have currently <emphasis>not</emphasis> selected instead."));
1735 invertSelection
->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-invert")));
1736 actionCollection()->setDefaultShortcut(invertSelection
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1737 connect(invertSelection
, &QAction::triggered
, this, &DolphinMainWindow::invertSelection
);
1739 QMenu
*toggleSelectionModeActionMenu
= new QMenu(this);
1740 toggleSelectionModeActionMenu
->addAction(selectAllAction
);
1741 toggleSelectionModeActionMenu
->addAction(invertSelection
);
1742 toggleSelectionModeToolBarAction
->setMenu(toggleSelectionModeActionMenu
);
1744 // setup 'View' menu
1745 // (note that most of it is set up in DolphinViewActionHandler)
1747 QAction
*split
= actionCollection()->addAction(QStringLiteral("split_view"));
1748 split
->setWhatsThis(xi18nc("@info:whatsthis find",
1749 "<para>This splits "
1750 "the folder view below into two autonomous views.</para><para>This "
1751 "way you can see two locations at once and move items between them "
1752 "quickly.</para>Click this again afterwards to recombine the views."));
1753 actionCollection()->setDefaultShortcut(split
, Qt::Key_F3
);
1754 connect(split
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitView
);
1756 QAction
*stashSplit
= actionCollection()->addAction(QStringLiteral("split_stash"));
1757 actionCollection()->setDefaultShortcut(stashSplit
, Qt::CTRL
| Qt::Key_S
);
1758 stashSplit
->setText(i18nc("@action:intoolbar Stash", "Stash"));
1759 stashSplit
->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
1760 stashSplit
->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
1761 stashSplit
->setCheckable(false);
1762 QDBusConnectionInterface
*sessionInterface
= QDBusConnection::sessionBus().interface();
1763 stashSplit
->setVisible(sessionInterface
&& sessionInterface
->isServiceRegistered(QStringLiteral("org.kde.kio.StashNotifier")));
1764 connect(stashSplit
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitStash
);
1766 QAction
*redisplay
= KStandardAction::redisplay(this, &DolphinMainWindow::reloadView
, actionCollection());
1767 redisplay
->setToolTip(i18nc("@info:tooltip", "Refresh view"));
1768 redisplay
->setWhatsThis(xi18nc("@info:whatsthis refresh",
1769 "<para>This refreshes "
1770 "the folder view.</para>"
1771 "<para>If the contents of this folder have changed, refreshing will re-scan this folder "
1772 "and show you a newly-updated view of the files and folders contained here.</para>"
1773 "<para>If the view is split, this refreshes the one that is currently in focus.</para>"));
1775 QAction
*stop
= actionCollection()->addAction(QStringLiteral("stop"));
1776 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1777 stop
->setToolTip(i18nc("@info", "Stop loading"));
1778 stop
->setWhatsThis(i18nc("@info", "This stops the loading of the contents of the current folder."));
1779 stop
->setIcon(QIcon::fromTheme(QStringLiteral("process-stop")));
1780 connect(stop
, &QAction::triggered
, this, &DolphinMainWindow::stopLoading
);
1782 KToggleAction
*editableLocation
= actionCollection()->add
<KToggleAction
>(QStringLiteral("editable_location"));
1783 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1784 editableLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1785 "This toggles the <emphasis>Location Bar</emphasis> to be "
1786 "editable so you can directly enter a location you want to go to.<nl/>"
1787 "You can also switch to editing by clicking to the right of the "
1788 "location and switch back by confirming the edited location."));
1789 actionCollection()->setDefaultShortcut(editableLocation
, Qt::Key_F6
);
1790 connect(editableLocation
, &KToggleAction::triggered
, this, &DolphinMainWindow::toggleEditLocation
);
1792 QAction
*replaceLocation
= actionCollection()->addAction(QStringLiteral("replace_location"));
1793 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1794 // i18n: "enter" is used both in the meaning of "writing" and "going to" a new location here.
1795 // Both meanings are useful but not necessary to understand the use of "Replace Location".
1796 // So you might want to be more verbose in your language to convey the meaning but it's up to you.
1797 replaceLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1798 "This switches to editing the location and selects it "
1799 "so you can quickly enter a different location."));
1800 actionCollection()->setDefaultShortcuts(replaceLocation
, {Qt::CTRL
| Qt::Key_L
, Qt::ALT
| Qt::Key_D
});
1801 connect(replaceLocation
, &QAction::triggered
, this, &DolphinMainWindow::replaceLocation
);
1805 QScopedPointer
<QAction
> backAction(KStandardAction::back(nullptr, nullptr, nullptr));
1806 m_backAction
= new KToolBarPopupAction(backAction
->icon(), backAction
->text(), actionCollection());
1807 m_backAction
->setObjectName(backAction
->objectName());
1808 m_backAction
->setShortcuts(backAction
->shortcuts());
1810 m_backAction
->setPopupMode(QToolButton::DelayedPopup
);
1811 connect(m_backAction
, &QAction::triggered
, this, &DolphinMainWindow::goBack
);
1812 connect(m_backAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowBackPopupMenu
);
1813 connect(m_backAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoBack
);
1814 actionCollection()->addAction(m_backAction
->objectName(), m_backAction
);
1816 auto backShortcuts
= m_backAction
->shortcuts();
1817 // Prepend this shortcut, to avoid being hidden by the two-slot UI (#371130)
1818 backShortcuts
.prepend(QKeySequence(Qt::Key_Backspace
));
1819 actionCollection()->setDefaultShortcuts(m_backAction
, backShortcuts
);
1821 DolphinRecentTabsMenu
*recentTabsMenu
= new DolphinRecentTabsMenu(this);
1822 actionCollection()->addAction(QStringLiteral("closed_tabs"), recentTabsMenu
);
1823 connect(m_tabWidget
, &DolphinTabWidget::rememberClosedTab
, recentTabsMenu
, &DolphinRecentTabsMenu::rememberClosedTab
);
1824 connect(recentTabsMenu
, &DolphinRecentTabsMenu::restoreClosedTab
, m_tabWidget
, &DolphinTabWidget::restoreClosedTab
);
1825 connect(recentTabsMenu
, &DolphinRecentTabsMenu::closedTabsCountChanged
, this, &DolphinMainWindow::closedTabsCountChanged
);
1827 QAction
*undoCloseTab
= actionCollection()->addAction(QStringLiteral("undo_close_tab"));
1828 undoCloseTab
->setText(i18nc("@action:inmenu File", "Undo close tab"));
1829 undoCloseTab
->setWhatsThis(i18nc("@info:whatsthis undo close tab", "This returns you to the previously closed tab."));
1830 actionCollection()->setDefaultShortcut(undoCloseTab
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_T
);
1831 undoCloseTab
->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo")));
1832 undoCloseTab
->setEnabled(false);
1833 connect(undoCloseTab
, &QAction::triggered
, recentTabsMenu
, &DolphinRecentTabsMenu::undoCloseTab
);
1835 auto undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
1836 undoAction
->setWhatsThis(xi18nc("@info:whatsthis",
1838 "the last change you made to files or folders.<nl/>"
1839 "Such changes include <interface>creating, renaming</interface> "
1840 "and <interface>moving</interface> them to a different location "
1841 "or to the <filename>Trash</filename>. <nl/>Changes that can't "
1842 "be undone will ask for your confirmation."));
1843 undoAction
->setEnabled(false); // undo should be disabled by default
1846 QScopedPointer
<QAction
> forwardAction(KStandardAction::forward(nullptr, nullptr, nullptr));
1847 m_forwardAction
= new KToolBarPopupAction(forwardAction
->icon(), forwardAction
->text(), actionCollection());
1848 m_forwardAction
->setObjectName(forwardAction
->objectName());
1849 m_forwardAction
->setShortcuts(forwardAction
->shortcuts());
1851 m_forwardAction
->setPopupMode(QToolButton::DelayedPopup
);
1852 connect(m_forwardAction
, &QAction::triggered
, this, &DolphinMainWindow::goForward
);
1853 connect(m_forwardAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowForwardPopupMenu
);
1854 connect(m_forwardAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoForward
);
1855 actionCollection()->addAction(m_forwardAction
->objectName(), m_forwardAction
);
1856 actionCollection()->setDefaultShortcuts(m_forwardAction
, m_forwardAction
->shortcuts());
1858 // enable middle-click to open in a new tab
1859 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
1860 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotBackForwardActionMiddleClicked
);
1861 m_backAction
->menu()->installEventFilter(middleClickEventFilter
);
1862 m_forwardAction
->menu()->installEventFilter(middleClickEventFilter
);
1863 KStandardAction::up(this, &DolphinMainWindow::goUp
, actionCollection());
1864 QAction
*homeAction
= KStandardAction::home(this, &DolphinMainWindow::goHome
, actionCollection());
1865 homeAction
->setWhatsThis(xi18nc("@info:whatsthis",
1867 "<filename>Home</filename> folder.<nl/>Every user account "
1868 "has their own <filename>Home</filename> that contains their data "
1869 "including folders that contain personal application data."));
1871 // setup 'Tools' menu
1872 QAction
*compareFiles
= actionCollection()->addAction(QStringLiteral("compare_files"));
1873 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1874 compareFiles
->setIcon(QIcon::fromTheme(QStringLiteral("kompare")));
1875 compareFiles
->setEnabled(false);
1876 connect(compareFiles
, &QAction::triggered
, this, &DolphinMainWindow::compareFiles
);
1878 QAction
*openPreferredSearchTool
= actionCollection()->addAction(QStringLiteral("open_preferred_search_tool"));
1879 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1880 openPreferredSearchTool
->setWhatsThis(xi18nc("@info:whatsthis",
1881 "<para>This opens a preferred search tool for the viewed location.</para>"
1882 "<para>Use <emphasis>More Search Tools</emphasis> menu to configure it.</para>"));
1883 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1884 actionCollection()->setDefaultShortcut(openPreferredSearchTool
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F
);
1885 connect(openPreferredSearchTool
, &QAction::triggered
, this, &DolphinMainWindow::openPreferredSearchTool
);
1887 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1888 QAction
*openTerminal
= actionCollection()->addAction(QStringLiteral("open_terminal"));
1889 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1890 openTerminal
->setWhatsThis(xi18nc("@info:whatsthis",
1891 "<para>This opens a <emphasis>terminal</emphasis> application for the viewed location.</para>"
1892 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1893 openTerminal
->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
1894 actionCollection()->setDefaultShortcut(openTerminal
, Qt::SHIFT
| Qt::Key_F4
);
1895 connect(openTerminal
, &QAction::triggered
, this, &DolphinMainWindow::openTerminal
);
1897 QAction
*openTerminalHere
= actionCollection()->addAction(QStringLiteral("open_terminal_here"));
1898 // i18n: "Here" refers to the location(s) of the currently selected item(s) or the currently viewed location if nothing is selected.
1899 openTerminalHere
->setText(i18nc("@action:inmenu Tools", "Open Terminal Here"));
1900 openTerminalHere
->setWhatsThis(xi18nc("@info:whatsthis",
1901 "<para>This opens <emphasis>terminal</emphasis> applications for the selected items' locations.</para>"
1902 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1903 openTerminalHere
->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
1904 actionCollection()->setDefaultShortcut(openTerminalHere
, Qt::SHIFT
| Qt::ALT
| Qt::Key_F4
);
1905 connect(openTerminalHere
, &QAction::triggered
, this, &DolphinMainWindow::openTerminalHere
);
1908 QAction
*focusTerminalPanel
= actionCollection()->addAction(QStringLiteral("focus_terminal_panel"));
1909 focusTerminalPanel
->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
1910 focusTerminalPanel
->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
1911 actionCollection()->setDefaultShortcut(focusTerminalPanel
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F4
);
1912 connect(focusTerminalPanel
, &QAction::triggered
, this, &DolphinMainWindow::focusTerminalPanel
);
1916 // setup 'Bookmarks' menu
1917 KActionMenu
*bookmarkMenu
= new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this);
1918 bookmarkMenu
->setIcon(QIcon::fromTheme(QStringLiteral("bookmarks")));
1919 // Make the toolbar button version work properly on click
1920 bookmarkMenu
->setPopupMode(QToolButton::InstantPopup
);
1921 m_bookmarkHandler
= new DolphinBookmarkHandler(this, actionCollection(), bookmarkMenu
->menu(), this);
1922 actionCollection()->addAction(QStringLiteral("bookmarks"), bookmarkMenu
);
1924 // setup 'Settings' menu
1925 KToggleAction
*showMenuBar
= KStandardAction::showMenubar(nullptr, nullptr, actionCollection());
1926 showMenuBar
->setWhatsThis(xi18nc("@info:whatsthis",
1927 "<para>This switches between having a <emphasis>Menubar</emphasis> "
1928 "and having a <interface>%1</interface> button. Both "
1929 "contain mostly the same actions and configuration options.</para>"
1930 "<para>The Menubar takes up more space but allows for fast and organised access to all "
1931 "actions an application has to offer.</para><para>The <interface>%1</interface> button "
1932 "is simpler and small which makes triggering advanced actions more time consuming.</para>",
1933 hamburgerMenuAction
->text().replace('&', "")));
1934 connect(showMenuBar
,
1935 &KToggleAction::triggered
, // Fixes #286822
1937 &DolphinMainWindow::toggleShowMenuBar
,
1938 Qt::QueuedConnection
);
1940 KToggleAction
*showStatusBar
= KStandardAction::showStatusbar(nullptr, nullptr, actionCollection());
1941 showStatusBar
->setChecked(GeneralSettings::showStatusBar());
1942 connect(GeneralSettings::self(), &GeneralSettings::showStatusBarChanged
, showStatusBar
, &KToggleAction::setChecked
);
1943 connect(showStatusBar
, &KToggleAction::triggered
, this, [this](bool checked
) {
1944 GeneralSettings::setShowStatusBar(checked
);
1948 KStandardAction::keyBindings(this, &DolphinMainWindow::slotKeyBindings
, actionCollection());
1949 KStandardAction::preferences(this, &DolphinMainWindow::editSettings
, actionCollection());
1951 // not in menu actions
1952 QList
<QKeySequence
> nextTabKeys
= KStandardShortcut::tabNext();
1953 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
1955 QList
<QKeySequence
> prevTabKeys
= KStandardShortcut::tabPrev();
1956 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
1958 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1959 QAction
*activateTab
= actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i
));
1960 activateTab
->setText(i18nc("@action:inmenu", "Activate Tab %1", i
+ 1));
1961 activateTab
->setEnabled(false);
1962 connect(activateTab
, &QAction::triggered
, this, [this, i
]() {
1963 m_tabWidget
->activateTab(i
);
1966 // only add default shortcuts for the first 9 tabs regardless of MaxActivateTabShortcuts
1968 actionCollection()->setDefaultShortcut(activateTab
, QStringLiteral("Alt+%1").arg(i
+ 1));
1972 QAction
*activateLastTab
= actionCollection()->addAction(QStringLiteral("activate_last_tab"));
1973 activateLastTab
->setText(i18nc("@action:inmenu", "Activate Last Tab"));
1974 activateLastTab
->setEnabled(false);
1975 connect(activateLastTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateLastTab
);
1976 actionCollection()->setDefaultShortcut(activateLastTab
, Qt::ALT
| Qt::Key_0
);
1978 QAction
*activateNextTab
= actionCollection()->addAction(QStringLiteral("activate_next_tab"));
1979 activateNextTab
->setIconText(i18nc("@action:inmenu", "Next Tab"));
1980 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1981 activateNextTab
->setEnabled(false);
1982 connect(activateNextTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateNextTab
);
1983 actionCollection()->setDefaultShortcuts(activateNextTab
, nextTabKeys
);
1985 QAction
*activatePrevTab
= actionCollection()->addAction(QStringLiteral("activate_prev_tab"));
1986 activatePrevTab
->setIconText(i18nc("@action:inmenu", "Previous Tab"));
1987 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1988 activatePrevTab
->setEnabled(false);
1989 connect(activatePrevTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activatePrevTab
);
1990 actionCollection()->setDefaultShortcuts(activatePrevTab
, prevTabKeys
);
1993 QAction
*showTarget
= actionCollection()->addAction(QStringLiteral("show_target"));
1994 showTarget
->setText(i18nc("@action:inmenu", "Show Target"));
1995 showTarget
->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
1996 showTarget
->setEnabled(false);
1997 connect(showTarget
, &QAction::triggered
, this, &DolphinMainWindow::showTarget
);
1999 QAction
*openInNewTab
= actionCollection()->addAction(QStringLiteral("open_in_new_tab"));
2000 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
2001 openInNewTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
2002 connect(openInNewTab
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
2004 QAction
*openInNewTabs
= actionCollection()->addAction(QStringLiteral("open_in_new_tabs"));
2005 openInNewTabs
->setText(i18nc("@action:inmenu", "Open in New Tabs"));
2006 openInNewTabs
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
2007 connect(openInNewTabs
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
2009 QAction
*openInNewWindow
= actionCollection()->addAction(QStringLiteral("open_in_new_window"));
2010 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
2011 openInNewWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
2012 connect(openInNewWindow
, &QAction::triggered
, this, &DolphinMainWindow::openInNewWindow
);
2014 QAction
*openInSplitViewAction
= actionCollection()->addAction(QStringLiteral("open_in_split_view"));
2015 openInSplitViewAction
->setText(i18nc("@action:inmenu", "Open in Split View"));
2016 openInSplitViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
2017 connect(openInSplitViewAction
, &QAction::triggered
, this, [this]() {
2018 openInSplitView(QUrl());
2022 void DolphinMainWindow::setupDockWidgets()
2024 const bool lock
= GeneralSettings::lockPanels();
2026 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(lock
);
2028 KDualAction
*lockLayoutAction
= actionCollection()->add
<KDualAction
>(QStringLiteral("lock_panels"));
2029 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
2030 lockLayoutAction
->setActiveIcon(QIcon::fromTheme(QStringLiteral("object-unlocked")));
2031 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
2032 lockLayoutAction
->setInactiveIcon(QIcon::fromTheme(QStringLiteral("object-locked")));
2033 lockLayoutAction
->setWhatsThis(xi18nc("@info:whatsthis",
2035 "switches between having panels <emphasis>locked</emphasis> or "
2036 "<emphasis>unlocked</emphasis>.<nl/>Unlocked panels can be "
2037 "dragged to the other side of the window and have a close "
2038 "button.<nl/>Locked panels are embedded more cleanly."));
2039 lockLayoutAction
->setActive(lock
);
2040 connect(lockLayoutAction
, &KDualAction::triggered
, this, &DolphinMainWindow::togglePanelLockState
);
2042 // Setup "Information"
2043 DolphinDockWidget
*infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
2044 infoDock
->setLocked(lock
);
2045 infoDock
->setObjectName(QStringLiteral("infoDock"));
2046 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2049 InformationPanel
*infoPanel
= new InformationPanel(infoDock
);
2050 infoPanel
->setCustomContextMenuActions({lockLayoutAction
});
2051 connect(infoPanel
, &InformationPanel::urlActivated
, this, &DolphinMainWindow::handleUrl
);
2052 infoDock
->setWidget(infoPanel
);
2054 QAction
*infoAction
= infoDock
->toggleViewAction();
2055 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-information")), Qt::Key_F11
, infoAction
, QStringLiteral("show_information_panel"));
2057 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
2058 connect(this, &DolphinMainWindow::urlChanged
, infoPanel
, &InformationPanel::setUrl
);
2059 connect(this, &DolphinMainWindow::selectionChanged
, infoPanel
, &InformationPanel::setSelection
);
2060 connect(this, &DolphinMainWindow::requestItemInfo
, infoPanel
, &InformationPanel::requestDelayedItemInfo
);
2061 connect(this, &DolphinMainWindow::fileItemsChanged
, infoPanel
, &InformationPanel::slotFilesItemChanged
);
2064 // i18n: This is the last paragraph for the "What's This"-texts of all four panels.
2065 const QString panelWhatsThis
= xi18nc("@info:whatsthis",
2067 "hide panels like this go to <interface>Menu|Panels</interface> "
2068 "or <interface>View|Panels</interface>.</para>");
2071 ->action(QStringLiteral("show_information_panel"))
2072 ->setWhatsThis(xi18nc("@info:whatsthis",
2073 "<para> This toggles the "
2074 "<emphasis>information</emphasis> panel at the right side of the "
2075 "window.</para><para>The panel provides in-depth information "
2076 "about the items your mouse is hovering over or about the selected "
2077 "items. Otherwise it informs you about the currently viewed folder.<nl/>"
2078 "For single items a preview of their contents is provided.</para>"));
2080 infoDock
->setWhatsThis(xi18nc("@info:whatsthis",
2082 "provides in-depth information about the items your mouse is "
2083 "hovering over or about the selected items. Otherwise it informs "
2084 "you about the currently viewed folder.<nl/>For single items a "
2085 "preview of their contents is provided.</para><para>You can configure "
2086 "which and how details are given here by right-clicking.</para>")
2090 DolphinDockWidget
*foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
2091 foldersDock
->setLocked(lock
);
2092 foldersDock
->setObjectName(QStringLiteral("foldersDock"));
2093 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2094 FoldersPanel
*foldersPanel
= new FoldersPanel(foldersDock
);
2095 foldersPanel
->setCustomContextMenuActions({lockLayoutAction
});
2096 foldersDock
->setWidget(foldersPanel
);
2098 QAction
*foldersAction
= foldersDock
->toggleViewAction();
2099 createPanelAction(QIcon::fromTheme(QStringLiteral("folder")), Qt::Key_F7
, foldersAction
, QStringLiteral("show_folders_panel"));
2101 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
2102 connect(this, &DolphinMainWindow::urlChanged
, foldersPanel
, &FoldersPanel::setUrl
);
2103 connect(foldersPanel
, &FoldersPanel::folderActivated
, this, &DolphinMainWindow::changeUrl
);
2104 connect(foldersPanel
, &FoldersPanel::folderInNewTab
, this, &DolphinMainWindow::openNewTab
);
2105 connect(foldersPanel
, &FoldersPanel::folderInNewActiveTab
, this, &DolphinMainWindow::openNewTabAndActivate
);
2106 connect(foldersPanel
, &FoldersPanel::errorMessage
, this, &DolphinMainWindow::showErrorMessage
);
2109 ->action(QStringLiteral("show_folders_panel"))
2110 ->setWhatsThis(xi18nc("@info:whatsthis",
2112 "<emphasis>folders</emphasis> panel at the left side of the window."
2113 "<nl/><nl/>It shows the folders of the <emphasis>file system"
2114 "</emphasis> in a <emphasis>tree view</emphasis>."));
2115 foldersDock
->setWhatsThis(xi18nc("@info:whatsthis",
2117 "shows the folders of the <emphasis>file system</emphasis> in a "
2118 "<emphasis>tree view</emphasis>.</para><para>Click a folder to go "
2119 "there. Click the arrow to the left of a folder to see its subfolders. "
2120 "This allows quick switching between any folders.</para>")
2125 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
2126 DolphinDockWidget
*terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
2127 terminalDock
->setLocked(lock
);
2128 terminalDock
->setObjectName(QStringLiteral("terminalDock"));
2129 m_terminalPanel
= new TerminalPanel(terminalDock
);
2130 m_terminalPanel
->setCustomContextMenuActions({lockLayoutAction
});
2131 terminalDock
->setWidget(m_terminalPanel
);
2133 connect(m_terminalPanel
, &TerminalPanel::hideTerminalPanel
, terminalDock
, &DolphinDockWidget::hide
);
2134 connect(m_terminalPanel
, &TerminalPanel::changeUrl
, this, &DolphinMainWindow::slotTerminalDirectoryChanged
);
2135 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
, m_terminalPanel
, &TerminalPanel::dockVisibilityChanged
);
2136 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
, this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged
);
2138 QAction
*terminalAction
= terminalDock
->toggleViewAction();
2139 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-scripts")), Qt::Key_F4
, terminalAction
, QStringLiteral("show_terminal_panel"));
2141 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
2142 connect(this, &DolphinMainWindow::urlChanged
, m_terminalPanel
, &TerminalPanel::setUrl
);
2144 if (GeneralSettings::version() < 200) {
2145 terminalDock
->hide();
2149 ->action(QStringLiteral("show_terminal_panel"))
2150 ->setWhatsThis(xi18nc("@info:whatsthis",
2151 "<para>This toggles the "
2152 "<emphasis>terminal</emphasis> panel at the bottom of the window."
2153 "<nl/>The location in the terminal will always match the folder "
2154 "view so you can navigate using either.</para><para>The terminal "
2155 "panel is not needed for basic computer usage but can be useful "
2156 "for advanced tasks. To learn more about terminals use the help "
2157 "in a standalone terminal application like Konsole.</para>"));
2158 terminalDock
->setWhatsThis(xi18nc("@info:whatsthis",
2160 "the <emphasis>terminal</emphasis> panel. It behaves like a "
2161 "normal terminal but will match the location of the folder view "
2162 "so you can navigate using either.</para><para>The terminal panel "
2163 "is not needed for basic computer usage but can be useful for "
2164 "advanced tasks. To learn more about terminals use the help in a "
2165 "standalone terminal application like Konsole.</para>")
2170 if (GeneralSettings::version() < 200) {
2172 foldersDock
->hide();
2176 DolphinDockWidget
*placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
2177 placesDock
->setLocked(lock
);
2178 placesDock
->setObjectName(QStringLiteral("placesDock"));
2179 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2181 m_placesPanel
= new PlacesPanel(placesDock
);
2182 m_placesPanel
->setCustomContextMenuActions({lockLayoutAction
});
2183 placesDock
->setWidget(m_placesPanel
);
2185 QAction
*placesAction
= placesDock
->toggleViewAction();
2186 createPanelAction(QIcon::fromTheme(QStringLiteral("compass")), Qt::Key_F9
, placesAction
, QStringLiteral("show_places_panel"));
2188 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
2189 connect(m_placesPanel
, &PlacesPanel::placeActivated
, this, &DolphinMainWindow::slotPlaceActivated
);
2190 connect(m_placesPanel
, &PlacesPanel::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2191 connect(m_placesPanel
, &PlacesPanel::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2192 connect(m_placesPanel
, &PlacesPanel::newWindowRequested
, this, [this](const QUrl
&url
) {
2193 Dolphin::openNewWindow({url
}, this);
2195 connect(m_placesPanel
, &PlacesPanel::openInSplitViewRequested
, this, &DolphinMainWindow::openInSplitView
);
2196 connect(m_placesPanel
, &PlacesPanel::errorMessage
, this, &DolphinMainWindow::showErrorMessage
);
2197 connect(this, &DolphinMainWindow::urlChanged
, m_placesPanel
, &PlacesPanel::setUrl
);
2198 connect(placesDock
, &DolphinDockWidget::visibilityChanged
, &DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged
);
2199 connect(this, &DolphinMainWindow::settingsChanged
, m_placesPanel
, &PlacesPanel::readSettings
);
2200 connect(m_placesPanel
, &PlacesPanel::storageTearDownRequested
, this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested
);
2201 connect(m_placesPanel
, &PlacesPanel::storageTearDownExternallyRequested
, this, &DolphinMainWindow::slotStorageTearDownExternallyRequested
);
2202 DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged(m_placesPanel
->isVisible());
2204 auto actionShowAllPlaces
= new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this);
2205 actionShowAllPlaces
->setCheckable(true);
2206 actionShowAllPlaces
->setDisabled(true);
2207 actionShowAllPlaces
->setWhatsThis(i18nc("@info:whatsthis",
2209 "all places in the places panel that have been hidden. They will "
2210 "appear semi-transparent unless you uncheck their hide property."));
2212 connect(actionShowAllPlaces
, &QAction::triggered
, this, [actionShowAllPlaces
, this](bool checked
) {
2213 m_placesPanel
->setShowAll(checked
);
2215 connect(m_placesPanel
, &PlacesPanel::allPlacesShownChanged
, actionShowAllPlaces
, &QAction::setChecked
);
2218 ->action(QStringLiteral("show_places_panel"))
2219 ->setWhatsThis(xi18nc("@info:whatsthis",
2220 "<para>This toggles the "
2221 "<emphasis>places</emphasis> panel at the left side of the window."
2222 "</para><para>It allows you to go to locations you have "
2223 "bookmarked and to access disk or media attached to the computer "
2224 "or to the network. It also contains sections to find recently "
2225 "saved files or files of a certain type.</para>"));
2226 placesDock
->setWhatsThis(xi18nc("@info:whatsthis",
2227 "<para>This is the "
2228 "<emphasis>Places</emphasis> panel. It allows you to go to locations "
2229 "you have bookmarked and to access disk or media attached to the "
2230 "computer or to the network. It also contains sections to find "
2231 "recently saved files or files of a certain type.</para><para>"
2232 "Click on an entry to go there. Click with the right mouse button "
2233 "instead to open any entry in a new tab or new window.</para>"
2234 "<para>New entries can be added by dragging folders onto this panel. "
2235 "Right-click any section or entry to hide it. Right-click an empty "
2236 "space on this panel and select <interface>Show Hidden Places"
2237 "</interface> to display it again.</para>")
2240 // Add actions into the "Panels" menu
2241 KActionMenu
*panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Show Panels"), this);
2242 actionCollection()->addAction(QStringLiteral("panels"), panelsMenu
);
2243 panelsMenu
->setIcon(QIcon::fromTheme(QStringLiteral("view-sidetree")));
2244 panelsMenu
->setPopupMode(QToolButton::InstantPopup
);
2245 const KActionCollection
*ac
= actionCollection();
2246 panelsMenu
->addAction(ac
->action(QStringLiteral("show_places_panel")));
2248 panelsMenu
->addAction(ac
->action(QStringLiteral("show_information_panel")));
2250 panelsMenu
->addAction(ac
->action(QStringLiteral("show_folders_panel")));
2251 panelsMenu
->addAction(ac
->action(QStringLiteral("show_terminal_panel")));
2252 panelsMenu
->addSeparator();
2253 panelsMenu
->addAction(actionShowAllPlaces
);
2254 panelsMenu
->addAction(lockLayoutAction
);
2256 connect(panelsMenu
->menu(), &QMenu::aboutToShow
, this, [actionShowAllPlaces
, this] {
2257 actionShowAllPlaces
->setEnabled(DolphinPlacesModelSingleton::instance().placesModel()->hiddenCount());
2261 void DolphinMainWindow::updateFileAndEditActions()
2263 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
2264 const KActionCollection
*col
= actionCollection();
2265 KFileItemListProperties
capabilitiesSource(list
);
2267 QAction
*renameAction
= col
->action(KStandardAction::name(KStandardAction::RenameFile
));
2268 QAction
*moveToTrashAction
= col
->action(KStandardAction::name(KStandardAction::MoveToTrash
));
2269 QAction
*deleteAction
= col
->action(KStandardAction::name(KStandardAction::DeleteFile
));
2270 QAction
*cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
2271 QAction
*duplicateAction
= col
->action(QStringLiteral("duplicate")); // see DolphinViewActionHandler
2272 QAction
*addToPlacesAction
= col
->action(QStringLiteral("add_to_places"));
2273 QAction
*copyToOtherViewAction
= col
->action(QStringLiteral("copy_to_inactive_split_view"));
2274 QAction
*moveToOtherViewAction
= col
->action(QStringLiteral("move_to_inactive_split_view"));
2275 QAction
*copyLocation
= col
->action(QString("copy_location"));
2277 if (list
.isEmpty()) {
2278 stateChanged(QStringLiteral("has_no_selection"));
2280 // All actions that need a selection to function can be enabled because they should trigger selection mode.
2281 renameAction
->setEnabled(true);
2282 moveToTrashAction
->setEnabled(true);
2283 deleteAction
->setEnabled(true);
2284 cutAction
->setEnabled(true);
2285 duplicateAction
->setEnabled(true);
2286 addToPlacesAction
->setEnabled(true);
2287 copyLocation
->setEnabled(true);
2288 // Them triggering selection mode and not directly acting on selected items is signified by adding "…" to their text.
2289 m_actionTextHelper
->textsWhenNothingIsSelectedEnabled(true);
2292 m_actionTextHelper
->textsWhenNothingIsSelectedEnabled(false);
2293 stateChanged(QStringLiteral("has_selection"));
2295 QAction
*deleteWithTrashShortcut
= col
->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
2296 QAction
*showTarget
= col
->action(QStringLiteral("show_target"));
2298 if (list
.length() == 1 && list
.first().isDir()) {
2299 addToPlacesAction
->setEnabled(true);
2301 addToPlacesAction
->setEnabled(false);
2304 const bool enableMoveToTrash
= capabilitiesSource
.isLocal() && capabilitiesSource
.supportsMoving();
2306 renameAction
->setEnabled(capabilitiesSource
.supportsMoving());
2307 moveToTrashAction
->setEnabled(enableMoveToTrash
);
2308 deleteAction
->setEnabled(capabilitiesSource
.supportsDeleting());
2309 deleteWithTrashShortcut
->setEnabled(capabilitiesSource
.supportsDeleting() && !enableMoveToTrash
);
2310 cutAction
->setEnabled(capabilitiesSource
.supportsMoving());
2311 copyLocation
->setEnabled(list
.length() == 1);
2312 showTarget
->setEnabled(list
.length() == 1 && list
.at(0).isLink());
2313 duplicateAction
->setEnabled(capabilitiesSource
.supportsWriting());
2316 if (m_tabWidget
->currentTabPage()->splitViewEnabled() && !list
.isEmpty()) {
2317 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
2318 KFileItem capabilitiesDestination
;
2320 if (tabPage
->primaryViewActive()) {
2321 capabilitiesDestination
= tabPage
->secondaryViewContainer()->rootItem();
2323 capabilitiesDestination
= tabPage
->primaryViewContainer()->rootItem();
2326 const auto destUrl
= capabilitiesDestination
.url();
2327 const bool allNotTargetOrigin
= std::all_of(list
.cbegin(), list
.cend(), [destUrl
](const KFileItem
&item
) {
2328 return item
.url().adjusted(QUrl::RemoveFilename
| QUrl::StripTrailingSlash
) != destUrl
;
2331 copyToOtherViewAction
->setEnabled(capabilitiesDestination
.isWritable() && allNotTargetOrigin
);
2332 moveToOtherViewAction
->setEnabled((list
.isEmpty() || capabilitiesSource
.supportsMoving()) && capabilitiesDestination
.isWritable()
2333 && allNotTargetOrigin
);
2335 copyToOtherViewAction
->setEnabled(false);
2336 moveToOtherViewAction
->setEnabled(false);
2340 void DolphinMainWindow::updateViewActions()
2342 m_actionHandler
->updateViewActions();
2344 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
2345 toggleFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
2347 updateSplitAction();
2350 void DolphinMainWindow::updateGoActions()
2352 QAction
*goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
2353 const QUrl currentUrl
= m_activeViewContainer
->url();
2354 // I think this is one of the best places to firstly be confronted
2355 // with a file system and its hierarchy. Talking about the root
2356 // directory might seem too much here but it is the question that
2357 // naturally arises in this context.
2358 goUpAction
->setWhatsThis(xi18nc("@info:whatsthis",
2360 "the folder that contains the currently viewed one.</para>"
2361 "<para>All files and folders are organized in a hierarchical "
2362 "<emphasis>file system</emphasis>. At the top of this hierarchy is "
2363 "a directory that contains all data connected to this computer"
2364 "—the <emphasis>root directory</emphasis>.</para>"));
2365 goUpAction
->setEnabled(KIO::upUrl(currentUrl
) != currentUrl
);
2368 void DolphinMainWindow::refreshViews()
2370 m_tabWidget
->refreshViews();
2372 if (GeneralSettings::modifiedStartupSettings()) {
2373 updateWindowTitle();
2376 updateSplitAction();
2378 Q_EMIT
settingsChanged();
2381 void DolphinMainWindow::clearStatusBar()
2383 m_activeViewContainer
->statusBar()->resetToDefaultText();
2386 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
*container
)
2388 connect(container
, &DolphinViewContainer::showFilterBarChanged
, this, &DolphinMainWindow::updateFilterBarAction
);
2389 connect(container
, &DolphinViewContainer::writeStateChanged
, this, &DolphinMainWindow::slotWriteStateChanged
);
2390 connect(container
, &DolphinViewContainer::searchModeEnabledChanged
, this, &DolphinMainWindow::updateSearchAction
);
2391 connect(container
, &DolphinViewContainer::captionChanged
, this, &DolphinMainWindow::updateWindowTitle
);
2392 connect(container
, &DolphinViewContainer::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2393 connect(container
, &DolphinViewContainer::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2395 const QAction
*toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
2396 connect(toggleSearchAction
, &QAction::triggered
, container
, &DolphinViewContainer::setSearchModeEnabled
);
2398 // Make the toggled state of the selection mode actions visually follow the selection mode state of the view.
2399 auto toggleSelectionModeAction
= actionCollection()->action(QStringLiteral("toggle_selection_mode"));
2400 toggleSelectionModeAction
->setChecked(m_activeViewContainer
->isSelectionModeEnabled());
2401 connect(m_activeViewContainer
, &DolphinViewContainer::selectionModeChanged
, toggleSelectionModeAction
, &QAction::setChecked
);
2403 const DolphinView
*view
= container
->view();
2404 connect(view
, &DolphinView::selectionChanged
, this, &DolphinMainWindow::slotSelectionChanged
);
2405 connect(view
, &DolphinView::requestItemInfo
, this, &DolphinMainWindow::requestItemInfo
);
2406 connect(view
, &DolphinView::fileItemsChanged
, this, &DolphinMainWindow::fileItemsChanged
);
2407 connect(view
, &DolphinView::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2408 connect(view
, &DolphinView::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2409 connect(view
, &DolphinView::windowRequested
, this, &DolphinMainWindow::openNewWindow
);
2410 connect(view
, &DolphinView::requestContextMenu
, this, &DolphinMainWindow::openContextMenu
);
2411 connect(view
, &DolphinView::directoryLoadingStarted
, this, &DolphinMainWindow::enableStopAction
);
2412 connect(view
, &DolphinView::directoryLoadingCompleted
, this, &DolphinMainWindow::disableStopAction
);
2413 connect(view
, &DolphinView::directoryLoadingCompleted
, this, &DolphinMainWindow::slotDirectoryLoadingCompleted
);
2414 connect(view
, &DolphinView::goBackRequested
, this, &DolphinMainWindow::goBack
);
2415 connect(view
, &DolphinView::goForwardRequested
, this, &DolphinMainWindow::goForward
);
2416 connect(view
, &DolphinView::urlActivated
, this, &DolphinMainWindow::handleUrl
);
2417 connect(view
, &DolphinView::goUpRequested
, this, &DolphinMainWindow::goUp
);
2419 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::urlChanged
, this, &DolphinMainWindow::changeUrl
);
2420 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::historyChanged
, this, &DolphinMainWindow::updateHistory
);
2422 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2423 const KUrlNavigator
*navigator
=
2424 m_tabWidget
->currentTabPage()->primaryViewActive() ? navigators
->primaryUrlNavigator() : navigators
->secondaryUrlNavigator();
2426 QAction
*editableLocactionAction
= actionCollection()->action(QStringLiteral("editable_location"));
2427 editableLocactionAction
->setChecked(navigator
->isUrlEditable());
2428 connect(navigator
, &KUrlNavigator::editableStateChanged
, this, &DolphinMainWindow::slotEditableStateChanged
);
2429 connect(navigator
, &KUrlNavigator::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2430 connect(navigator
, &KUrlNavigator::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2431 connect(navigator
, &KUrlNavigator::newWindowRequested
, this, &DolphinMainWindow::openNewWindow
);
2434 void DolphinMainWindow::updateSplitAction()
2436 QAction
*splitAction
= actionCollection()->action(QStringLiteral("split_view"));
2437 const DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
2438 if (tabPage
->splitViewEnabled()) {
2439 if (GeneralSettings::closeActiveSplitView() ? tabPage
->primaryViewActive() : !tabPage
->primaryViewActive()) {
2440 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2441 splitAction
->setToolTip(i18nc("@info", "Close left view"));
2442 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close")));
2444 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2445 splitAction
->setToolTip(i18nc("@info", "Close right view"));
2446 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close")));
2449 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2450 splitAction
->setToolTip(i18nc("@info", "Split view"));
2451 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
2455 void DolphinMainWindow::updateAllowedToolbarAreas()
2457 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2458 if (toolBar()->actions().contains(navigators
)) {
2459 toolBar()->setAllowedAreas(Qt::TopToolBarArea
| Qt::BottomToolBarArea
);
2460 if (toolBarArea(toolBar()) == Qt::LeftToolBarArea
|| toolBarArea(toolBar()) == Qt::RightToolBarArea
) {
2461 addToolBar(Qt::TopToolBarArea
, toolBar());
2464 toolBar()->setAllowedAreas(Qt::AllToolBarAreas
);
2468 bool DolphinMainWindow::isKompareInstalled() const
2470 static bool initialized
= false;
2471 static bool installed
= false;
2473 // TODO: maybe replace this approach later by using a menu
2474 // plugin like kdiff3plugin.cpp
2475 installed
= !QStandardPaths::findExecutable(QStringLiteral("kompare")).isEmpty();
2481 void DolphinMainWindow::createPanelAction(const QIcon
&icon
, const QKeySequence
&shortcut
, QAction
*dockAction
, const QString
&actionName
)
2483 QAction
*panelAction
= actionCollection()->addAction(actionName
);
2484 panelAction
->setCheckable(true);
2485 panelAction
->setChecked(dockAction
->isChecked());
2486 panelAction
->setText(dockAction
->text());
2487 panelAction
->setIcon(icon
);
2488 dockAction
->setIcon(icon
);
2489 actionCollection()->setDefaultShortcut(panelAction
, shortcut
);
2491 connect(panelAction
, &QAction::triggered
, dockAction
, &QAction::trigger
);
2492 connect(dockAction
, &QAction::toggled
, panelAction
, &QAction::setChecked
);
2495 void DolphinMainWindow::setupWhatsThis()
2498 menuBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2499 "<emphasis>Menubar</emphasis>. It provides access to commands and "
2500 "configuration options. Left-click on any of the menus on this "
2501 "bar to see its contents.</para><para>The Menubar can be hidden "
2502 "by unchecking <interface>Settings|Show Menubar</interface>. Then "
2503 "most of its contents become available through a <interface>Menu"
2504 "</interface> button on the <emphasis>Toolbar</emphasis>.</para>"));
2505 toolBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2506 "<emphasis>Toolbar</emphasis>. It allows quick access to "
2507 "frequently used actions.</para><para>It is highly customizable. "
2508 "All items you see in the <interface>Menu</interface> or "
2509 "in the <interface>Menubar</interface> can be placed on the "
2510 "Toolbar. Just right-click on it and select <interface>Configure "
2511 "Toolbars…</interface> or find this action within the <interface>"
2513 "</para><para>The location of the bar and the style of its "
2514 "buttons can also be changed in the right-click menu. Right-click "
2515 "a button if you want to show or hide its text.</para>"));
2516 m_tabWidget
->setWhatsThis(xi18nc("@info:whatsthis main view",
2517 "<para>Here you can see the <emphasis>folders</emphasis> and "
2518 "<emphasis>files</emphasis> that are at the location described in "
2519 "the <interface>Location Bar</interface> above. This area is the "
2520 "central part of this application where you navigate to the files "
2521 "you want to use.</para><para>For an elaborate and general "
2522 "introduction to this application <link "
2523 "url='https://userbase.kde.org/Dolphin/File_Management#Introduction_to_Dolphin'>"
2524 "click here</link>. This will open an introductory article from "
2525 "the <emphasis>KDE UserBase Wiki</emphasis>.</para><para>For brief "
2526 "explanations of all the features of this <emphasis>view</emphasis> "
2527 "<link url='help:/dolphin/dolphin-view.html'>click here</link> "
2528 "instead. This will open a page from the <emphasis>Handbook"
2529 "</emphasis> that covers the basics.</para>"));
2532 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings
))
2533 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window "
2534 "that lists the <emphasis>keyboard shortcuts</emphasis>.<nl/>"
2535 "There you can set up key combinations to trigger an action when "
2536 "they are pressed simultaneously. All commands in this application can "
2537 "be triggered this way.</para>"));
2538 actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars
))
2539 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window in which "
2540 "you can change which buttons appear on the <emphasis>Toolbar</emphasis>.</para>"
2541 "<para>All items you see in the <interface>Menu</interface> can also be placed on the Toolbar.</para>"));
2542 actionCollection()->action(KStandardAction::name(KStandardAction::Preferences
))
2543 ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window where you can "
2544 "change a multitude of settings for this application. For an explanation "
2545 "of the various settings go to the chapter <emphasis>Configuring Dolphin"
2546 "</emphasis> in <interface>Help|Dolphin Handbook</interface>."));
2550 auto setStandardActionWhatsThis
= [this](KStandardAction::StandardAction actionId
,
2551 const QString
&whatsThis
) {
2552 // Check for the existence of an action since it can be restricted through the Kiosk system
2553 if (auto *action
= actionCollection()->action(KStandardAction::name(actionId
))) {
2554 action
->setWhatsThis(whatsThis
);
2558 // i18n: If the external link isn't available in your language it might make
2559 // sense to state the external link's language in brackets to not
2560 // frustrate the user. If there are multiple languages that the user might
2561 // know with a reasonable chance you might want to have 2 external links.
2562 // The same might be true for any external link you translate.
2563 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>"));
2564 // (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 )
2566 setStandardActionWhatsThis(KStandardAction::WhatsThis
,
2567 xi18nc("@info:whatsthis whatsthis button",
2568 "<para>This is the button that invokes the help feature you are "
2569 "using right now! Click it, then click any component of this "
2570 "application to ask \"What's this?\" about it. The mouse cursor "
2571 "will change appearance if no help is available for a spot.</para>"
2572 "<para>There are two other ways to get help: "
2573 "The <link url='help:/dolphin/index.html'>Dolphin Handbook</link> and "
2574 "the <link url='https://userbase.kde.org/Dolphin/File_Management'>KDE "
2575 "UserBase Wiki</link>.</para><para>The \"What's this?\" help is "
2576 "missing in most other windows so don't get too used to this.</para>"));
2578 setStandardActionWhatsThis(KStandardAction::ReportBug
,
2579 xi18nc("@info:whatsthis","<para>This opens a "
2580 "window that will guide you through reporting errors or flaws "
2581 "in this application or in other KDE software.</para>"
2582 "<para>High-quality bug reports are much appreciated. To learn "
2583 "how to make your bug report as effective as possible "
2584 "<link url='https://community.kde.org/Get_Involved/Bug_Reporting'>"
2585 "click here</link>.</para>"));
2587 setStandardActionWhatsThis(KStandardAction::Donate
,
2588 xi18nc("@info:whatsthis", "<para>This opens a "
2589 "<emphasis>web page</emphasis> where you can donate to "
2590 "support the continued work on this application and many "
2591 "other projects by the <emphasis>KDE</emphasis> community.</para>"
2592 "<para>Donating is the easiest and fastest way to efficiently "
2593 "support KDE and its projects. KDE projects are available for "
2594 "free therefore your donation is needed to cover things that "
2595 "require money like servers, contributor meetings, etc.</para>"
2596 "<para><emphasis>KDE e.V.</emphasis> is the non-profit "
2597 "organization behind the KDE community.</para>"));
2599 setStandardActionWhatsThis(KStandardAction::SwitchApplicationLanguage
,
2600 xi18nc("@info:whatsthis",
2601 "With this you can change the language this application uses."
2602 "<nl/>You can even set secondary languages which will be used "
2603 "if texts are not available in your preferred language."));
2605 setStandardActionWhatsThis(KStandardAction::AboutApp
,
2606 xi18nc("@info:whatsthis","This opens a "
2607 "window that informs you about the version, license, "
2608 "used libraries and maintainers of this application."));
2610 setStandardActionWhatsThis(KStandardAction::AboutKDE
,
2611 xi18nc("@info:whatsthis","This opens a "
2612 "window with information about <emphasis>KDE</emphasis>. "
2613 "The KDE community are the people behind this free software."
2614 "<nl/>If you like using this application but don't know "
2615 "about KDE or want to see a cute dragon have a look!"));
2619 bool DolphinMainWindow::addHamburgerMenuToToolbar()
2621 QDomDocument domDocument
= KXMLGUIClient::domDocument();
2622 if (domDocument
.isNull()) {
2625 QDomNode toolbar
= domDocument
.elementsByTagName(QStringLiteral("ToolBar")).at(0);
2626 if (toolbar
.isNull()) {
2630 QDomElement hamburgerMenuElement
= domDocument
.createElement(QStringLiteral("Action"));
2631 hamburgerMenuElement
.setAttribute(QStringLiteral("name"), QStringLiteral("hamburger_menu"));
2632 toolbar
.appendChild(hamburgerMenuElement
);
2634 KXMLGUIFactory::saveConfigFile(domDocument
, xmlFile());
2638 // Make sure to also remove the <KXMLGUIFactory> and <QDomDocument> include
2639 // whenever this method is removed (maybe in the year ~2026).
2642 // Set a sane initial window size
2643 QSize
DolphinMainWindow::sizeHint() const
2645 return KXmlGuiWindow::sizeHint().expandedTo(QSize(760, 550));
2648 void DolphinMainWindow::saveNewToolbarConfig()
2650 KXmlGuiWindow::saveNewToolbarConfig(); // Applies the new config. This has to be called first
2651 // because the rest of this method decides things
2652 // based on the new config.
2653 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2654 if (!toolBar()->actions().contains(navigators
)) {
2655 m_tabWidget
->currentTabPage()->insertNavigatorsWidget(navigators
);
2657 updateAllowedToolbarAreas();
2658 (static_cast<KHamburgerMenu
*>(actionCollection()->action(KStandardAction::name(KStandardAction::HamburgerMenu
))))->hideActionsOf(toolBar());
2661 void DolphinMainWindow::focusTerminalPanel()
2663 if (m_terminalPanel
->isVisible()) {
2664 if (m_terminalPanel
->terminalHasFocus()) {
2665 m_activeViewContainer
->view()->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2666 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2668 m_terminalPanel
->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2669 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2672 actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger();
2673 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2677 DolphinMainWindow::UndoUiInterface::UndoUiInterface()
2678 : KIO::FileUndoManager::UiInterface()
2682 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2686 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
*job
)
2688 DolphinMainWindow
*mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2690 DolphinViewContainer
*container
= mainWin
->activeViewContainer();
2691 container
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
2693 KIO::FileUndoManager::UiInterface::jobError(job
);
2697 bool DolphinMainWindow::isUrlOpen(const QString
&url
)
2699 return m_tabWidget
->isUrlOpen(QUrl::fromUserInput(url
));
2702 bool DolphinMainWindow::isItemVisibleInAnyView(const QString
&urlOfItem
)
2704 return m_tabWidget
->isItemVisibleInAnyView(QUrl::fromUserInput(urlOfItem
));
2707 #include "moc_dolphinmainwindow.cpp"