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>
68 #include <kwidgetsaddons_version.h>
70 #include <QApplication>
72 #include <QCloseEvent>
73 #include <QDesktopServices>
75 #include <QDomDocument>
79 #include <QPushButton>
81 #include <QStandardPaths>
83 #include <QToolButton>
89 // Used for GeneralSettings::version() to determine whether
90 // an updated version of Dolphin is running, so as to migrate
91 // removed/renamed ...etc config entries; increment it in such
93 const int CurrentDolphinVersion
= 202;
94 // The maximum number of entries in the back/forward popup menu
95 const int MaxNumberOfNavigationentries
= 12;
96 // The maximum number of "Activate Tab" shortcuts
97 const int MaxActivateTabShortcuts
= 9;
100 DolphinMainWindow::DolphinMainWindow()
101 : KXmlGuiWindow(nullptr)
102 , m_newFileMenu(nullptr)
103 , m_tabWidget(nullptr)
104 , m_activeViewContainer(nullptr)
105 , m_actionHandler(nullptr)
106 , m_remoteEncoding(nullptr)
108 , m_bookmarkHandler(nullptr)
109 , m_lastHandleUrlOpenJob(nullptr)
110 , m_terminalPanel(nullptr)
111 , m_placesPanel(nullptr)
112 , m_tearDownFromPlacesRequested(false)
113 , m_backAction(nullptr)
114 , m_forwardAction(nullptr)
116 Q_INIT_RESOURCE(dolphin
);
118 new MainWindowAdaptor(this);
121 setWindowFlags(Qt::WindowContextHelpButtonHint
);
123 setComponentName(QStringLiteral("dolphin"), QGuiApplication::applicationDisplayName());
124 setObjectName(QStringLiteral("Dolphin#"));
126 setStateConfigGroup("State");
128 connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::errorMessage
, this, &DolphinMainWindow::showErrorMessage
);
130 KIO::FileUndoManager
*undoManager
= KIO::FileUndoManager::self();
131 undoManager
->setUiInterface(new UndoUiInterface());
133 connect(undoManager
, &KIO::FileUndoManager::undoAvailable
, this, &DolphinMainWindow::slotUndoAvailable
);
134 connect(undoManager
, &KIO::FileUndoManager::undoTextChanged
, this, &DolphinMainWindow::slotUndoTextChanged
);
135 connect(undoManager
, &KIO::FileUndoManager::jobRecordingStarted
, this, &DolphinMainWindow::clearStatusBar
);
136 connect(undoManager
, &KIO::FileUndoManager::jobRecordingFinished
, this, &DolphinMainWindow::showCommand
);
138 const bool firstRun
= (GeneralSettings::version() < 200);
140 GeneralSettings::setViewPropsTimestamp(QDateTime::currentDateTime());
143 setAcceptDrops(true);
145 auto *navigatorsWidgetAction
= new DolphinNavigatorsWidgetAction(this);
146 actionCollection()->addAction(QStringLiteral("url_navigators"), navigatorsWidgetAction
);
147 m_tabWidget
= new DolphinTabWidget(navigatorsWidgetAction
, this);
148 m_tabWidget
->setObjectName("tabWidget");
149 connect(m_tabWidget
, &DolphinTabWidget::activeViewChanged
, this, &DolphinMainWindow::activeViewChanged
);
150 connect(m_tabWidget
, &DolphinTabWidget::tabCountChanged
, this, &DolphinMainWindow::tabCountChanged
);
151 connect(m_tabWidget
, &DolphinTabWidget::currentUrlChanged
, this, &DolphinMainWindow::updateWindowTitle
);
152 setCentralWidget(m_tabWidget
);
154 m_actionTextHelper
= new SelectionMode::ActionTextHelper(this);
157 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), m_actionTextHelper
, this);
158 connect(m_actionHandler
, &DolphinViewActionHandler::actionBeingHandled
, this, &DolphinMainWindow::clearStatusBar
);
159 connect(m_actionHandler
, &DolphinViewActionHandler::createDirectoryTriggered
, this, &DolphinMainWindow::createDirectory
);
160 connect(m_actionHandler
, &DolphinViewActionHandler::selectionModeChangeTriggered
, this, &DolphinMainWindow::slotSetSelectionMode
);
162 Q_CHECK_PTR(actionCollection()->action(QStringLiteral("create_dir")));
163 m_newFileMenu
->setNewFolderShortcutAction(actionCollection()->action(QStringLiteral("create_dir")));
165 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
166 connect(this, &DolphinMainWindow::urlChanged
, m_remoteEncoding
, &DolphinRemoteEncoding::slotAboutToOpenUrl
);
170 setupGUI(Save
| Create
| ToolBar
);
171 stateChanged(QStringLiteral("new_file"));
173 QClipboard
*clipboard
= QApplication::clipboard();
174 connect(clipboard
, &QClipboard::dataChanged
, this, &DolphinMainWindow::updatePasteAction
);
176 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
177 toggleFilterBarAction
->setChecked(GeneralSettings::filterBar());
180 menuBar()->setVisible(false);
183 const bool showMenu
= !menuBar()->isHidden();
184 QAction
*showMenuBarAction
= actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar
));
185 showMenuBarAction
->setChecked(showMenu
); // workaround for bug #171080
187 auto hamburgerMenu
= static_cast<KHamburgerMenu
*>(actionCollection()->action(KStandardAction::name(KStandardAction::HamburgerMenu
)));
188 hamburgerMenu
->setMenuBar(menuBar());
189 hamburgerMenu
->setShowMenuBarAction(showMenuBarAction
);
190 connect(hamburgerMenu
, &KHamburgerMenu::aboutToShowMenu
, this, &DolphinMainWindow::updateHamburgerMenu
);
191 hamburgerMenu
->hideActionsOf(toolBar());
192 if (GeneralSettings::version() < 201 && !toolBar()->actions().contains(hamburgerMenu
)) {
193 addHamburgerMenuToToolbar();
196 updateAllowedToolbarAreas();
198 // enable middle-click on back/forward/up to open in a new tab
199 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
200 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotToolBarActionMiddleClicked
);
201 toolBar()->installEventFilter(middleClickEventFilter
);
205 connect(KSycoca::self(), &KSycoca::databaseChanged
, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
207 QTimer::singleShot(0, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
209 m_fileItemActions
.setParentWidget(this);
210 connect(&m_fileItemActions
, &KFileItemActions::error
, this, [this](const QString
&errorMessage
) {
211 showErrorMessage(errorMessage
);
214 connect(GeneralSettings::self(), &GeneralSettings::splitViewChanged
, this, &DolphinMainWindow::slotSplitViewChanged
);
217 DolphinMainWindow::~DolphinMainWindow()
219 // This fixes a crash on Wayland when closing the mainwindow while another dialog is open.
220 disconnect(QGuiApplication::clipboard(), &QClipboard::dataChanged
, this, &DolphinMainWindow::updatePasteAction
);
223 QVector
<DolphinViewContainer
*> DolphinMainWindow::viewContainers() const
225 QVector
<DolphinViewContainer
*> viewContainers
;
227 for (int i
= 0; i
< m_tabWidget
->count(); ++i
) {
228 DolphinTabPage
*tabPage
= m_tabWidget
->tabPageAt(i
);
230 viewContainers
<< tabPage
->primaryViewContainer();
231 if (tabPage
->splitViewEnabled()) {
232 viewContainers
<< tabPage
->secondaryViewContainer();
235 return viewContainers
;
238 void DolphinMainWindow::openDirectories(const QList
<QUrl
> &dirs
, bool splitView
)
240 m_tabWidget
->openDirectories(dirs
, splitView
);
243 void DolphinMainWindow::openDirectories(const QStringList
&dirs
, bool splitView
)
245 openDirectories(QUrl::fromStringList(dirs
), splitView
);
248 void DolphinMainWindow::openFiles(const QList
<QUrl
> &files
, bool splitView
)
250 m_tabWidget
->openFiles(files
, splitView
);
253 bool DolphinMainWindow::isFoldersPanelEnabled() const
255 return actionCollection()->action(QStringLiteral("show_folders_panel"))->isChecked();
258 bool DolphinMainWindow::isInformationPanelEnabled() const
261 return actionCollection()->action(QStringLiteral("show_information_panel"))->isChecked();
267 bool DolphinMainWindow::isSplitViewEnabledInCurrentTab() const
269 return m_tabWidget
->currentTabPage()->splitViewEnabled();
272 void DolphinMainWindow::openFiles(const QStringList
&files
, bool splitView
)
274 openFiles(QUrl::fromStringList(files
), splitView
);
277 bool DolphinMainWindow::isOnCurrentDesktop() const
280 if (KWindowSystem::isPlatformX11()) {
281 const NET::Properties properties
= NET::WMDesktop
;
282 KWindowInfo
info(this->winId(), properties
);
283 return info
.isOnCurrentDesktop();
289 bool DolphinMainWindow::isOnActivity(const QString
&activityId
) const
291 #if HAVE_X11 && HAVE_KACTIVITIES
292 if (KWindowSystem::isPlatformX11()) {
293 const NET::Properties properties
= NET::Supported
;
294 const NET::Properties2 properties2
= NET::WM2Activities
;
295 KWindowInfo
info(this->winId(), properties
, properties2
);
296 return info
.activities().contains(activityId
);
302 void DolphinMainWindow::activateWindow(const QString
&activationToken
)
304 window()->setAttribute(Qt::WA_NativeWindow
, true);
306 if (KWindowSystem::isPlatformWayland()) {
307 KWindowSystem::setCurrentXdgActivationToken(activationToken
);
309 KStartupInfo::setNewStartupId(window()->windowHandle(), activationToken
.toUtf8());
312 KWindowSystem::activateWindow(window()->windowHandle());
315 bool DolphinMainWindow::isActiveWindow()
317 return window()->isActiveWindow();
320 void DolphinMainWindow::showCommand(CommandType command
)
322 DolphinStatusBar
*statusBar
= m_activeViewContainer
->statusBar();
324 case KIO::FileUndoManager::Copy
:
325 statusBar
->setText(i18nc("@info:status", "Successfully copied."));
327 case KIO::FileUndoManager::Move
:
328 statusBar
->setText(i18nc("@info:status", "Successfully moved."));
330 case KIO::FileUndoManager::Link
:
331 statusBar
->setText(i18nc("@info:status", "Successfully linked."));
333 case KIO::FileUndoManager::Trash
:
334 statusBar
->setText(i18nc("@info:status", "Successfully moved to trash."));
336 case KIO::FileUndoManager::Rename
:
337 statusBar
->setText(i18nc("@info:status", "Successfully renamed."));
340 case KIO::FileUndoManager::Mkdir
:
341 statusBar
->setText(i18nc("@info:status", "Created folder."));
349 void DolphinMainWindow::pasteIntoFolder()
351 m_activeViewContainer
->view()->pasteIntoFolder();
354 void DolphinMainWindow::changeUrl(const QUrl
&url
)
356 if (!KProtocolManager::supportsListing(url
)) {
357 // The URL navigator only checks for validity, not
358 // if the URL can be listed. An error message is
359 // shown due to DolphinViewContainer::restoreView().
363 m_activeViewContainer
->setUrl(url
);
364 updateFileAndEditActions();
369 Q_EMIT
urlChanged(url
);
372 void DolphinMainWindow::slotTerminalDirectoryChanged(const QUrl
&url
)
374 if (m_tearDownFromPlacesRequested
&& url
== QUrl::fromLocalFile(QDir::homePath())) {
375 m_placesPanel
->proceedWithTearDown();
376 m_tearDownFromPlacesRequested
= false;
379 m_activeViewContainer
->setAutoGrabFocus(false);
381 m_activeViewContainer
->setAutoGrabFocus(true);
384 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
386 KToggleAction
*editableLocationAction
= static_cast<KToggleAction
*>(actionCollection()->action(QStringLiteral("editable_location")));
387 editableLocationAction
->setChecked(editable
);
390 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
&selection
)
392 updateFileAndEditActions();
394 const int selectedUrlsCount
= m_tabWidget
->currentTabPage()->selectedItemsCount();
396 QAction
*compareFilesAction
= actionCollection()->action(QStringLiteral("compare_files"));
397 if (selectedUrlsCount
== 2) {
398 compareFilesAction
->setEnabled(isKompareInstalled());
400 compareFilesAction
->setEnabled(false);
403 Q_EMIT
selectionChanged(selection
);
406 void DolphinMainWindow::updateHistory()
408 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
409 const int index
= urlNavigator
->historyIndex();
411 QAction
*backAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Back
));
413 backAction
->setToolTip(i18nc("@info", "Go back"));
414 backAction
->setWhatsThis(i18nc("@info:whatsthis go back", "Return to the previously viewed folder."));
415 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
418 QAction
*forwardAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Forward
));
420 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
421 forwardAction
->setWhatsThis(xi18nc("@info:whatsthis go forward", "This undoes a <interface>Go|Back</interface> action."));
422 forwardAction
->setEnabled(index
> 0);
426 void DolphinMainWindow::updateFilterBarAction(bool show
)
428 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
429 toggleFilterBarAction
->setChecked(show
);
432 void DolphinMainWindow::openNewMainWindow()
434 Dolphin::openNewWindow({m_activeViewContainer
->url()}, this);
437 void DolphinMainWindow::openNewActivatedTab()
439 // keep browsers compatibility, new tab is always after last one
440 auto openNewTabAfterLastTabConfigured
= GeneralSettings::openNewTabAfterLastTab();
441 GeneralSettings::setOpenNewTabAfterLastTab(true);
442 m_tabWidget
->openNewActivatedTab();
443 GeneralSettings::setOpenNewTabAfterLastTab(openNewTabAfterLastTabConfigured
);
446 void DolphinMainWindow::addToPlaces()
451 // If nothing is selected, act on the current dir
452 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
453 url
= m_activeViewContainer
->url();
454 name
= m_activeViewContainer
->placesText();
456 const auto dirToAdd
= m_activeViewContainer
->view()->selectedItems().first();
457 url
= dirToAdd
.url();
458 name
= dirToAdd
.name();
462 if (m_activeViewContainer
->isSearchModeEnabled()) {
463 icon
= QStringLiteral("folder-saved-search-symbolic");
465 icon
= KIO::iconNameForUrl(url
);
467 DolphinPlacesModelSingleton::instance().placesModel()->addPlace(name
, url
, icon
);
471 void DolphinMainWindow::openNewTab(const QUrl
&url
)
473 m_tabWidget
->openNewTab(url
, QUrl());
476 void DolphinMainWindow::openNewTabAndActivate(const QUrl
&url
)
478 m_tabWidget
->openNewActivatedTab(url
, QUrl());
481 void DolphinMainWindow::openNewWindow(const QUrl
&url
)
483 Dolphin::openNewWindow({url
}, this);
486 void DolphinMainWindow::slotSplitViewChanged()
488 m_tabWidget
->currentTabPage()->setSplitViewEnabled(GeneralSettings::splitView(), WithAnimation
);
492 void DolphinMainWindow::openInNewTab()
494 const KFileItemList
&list
= m_activeViewContainer
->view()->selectedItems();
495 bool tabCreated
= false;
497 for (const KFileItem
&item
: list
) {
498 const QUrl
&url
= DolphinView::openItemAsFolderUrl(item
);
499 if (!url
.isEmpty()) {
505 // if no new tab has been created from the selection
506 // open the current directory in a new tab
508 openNewTab(m_activeViewContainer
->url());
512 void DolphinMainWindow::openInNewWindow()
516 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
517 if (list
.isEmpty()) {
518 newWindowUrl
= m_activeViewContainer
->url();
519 } else if (list
.count() == 1) {
520 const KFileItem
&item
= list
.first();
521 newWindowUrl
= DolphinView::openItemAsFolderUrl(item
);
524 if (!newWindowUrl
.isEmpty()) {
525 Dolphin::openNewWindow({newWindowUrl
}, this);
529 void DolphinMainWindow::showTarget()
531 const KFileItem link
= m_activeViewContainer
->view()->selectedItems().at(0);
532 const QUrl destinationUrl
= link
.url().resolved(QUrl(link
.linkDest()));
534 auto job
= KIO::stat(destinationUrl
, KIO::StatJob::SourceSide
, KIO::StatNoDetails
);
536 connect(job
, &KJob::finished
, this, [this, destinationUrl
](KJob
*job
) {
537 KIO::StatJob
*statJob
= static_cast<KIO::StatJob
*>(job
);
539 if (statJob
->error()) {
540 m_activeViewContainer
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
542 KIO::highlightInFileManager({destinationUrl
});
547 bool DolphinMainWindow::event(QEvent
*event
)
549 if (event
->type() == QEvent::ShortcutOverride
) {
550 const QKeyEvent
*keyEvent
= static_cast<QKeyEvent
*>(event
);
551 if (keyEvent
->key() == Qt::Key_Space
&& m_activeViewContainer
->view()->handleSpaceAsNormalKey()) {
557 return KXmlGuiWindow::event(event
);
560 void DolphinMainWindow::showEvent(QShowEvent
*event
)
562 KXmlGuiWindow::showEvent(event
);
564 if (!event
->spontaneous()) {
565 m_activeViewContainer
->view()->setFocus();
569 void DolphinMainWindow::closeEvent(QCloseEvent
*event
)
571 // Find out if Dolphin is closed directly by the user or
572 // by the session manager because the session is closed
573 bool closedByUser
= true;
574 if (qApp
->isSavingSession()) {
575 closedByUser
= false;
578 if (m_tabWidget
->count() > 1 && GeneralSettings::confirmClosingMultipleTabs() && !GeneralSettings::rememberOpenedTabs() && closedByUser
) {
579 // Ask the user if he really wants to quit and close all tabs.
580 // Open a confirmation dialog with 3 buttons:
581 // QDialogButtonBox::Yes -> Quit
582 // QDialogButtonBox::No -> Close only the current tab
583 // QDialogButtonBox::Cancel -> do nothing
584 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
585 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
586 dialog
->setModal(true);
587 QDialogButtonBox
*buttons
= new QDialogButtonBox(QDialogButtonBox::Yes
| QDialogButtonBox::No
| QDialogButtonBox::Cancel
);
588 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
),
589 KGuiItem(i18nc("@action:button 'Quit Dolphin' button", "&Quit %1", QGuiApplication::applicationDisplayName()),
590 QIcon::fromTheme(QStringLiteral("application-exit"))));
591 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("C&lose Current Tab"), QIcon::fromTheme(QStringLiteral("tab-close"))));
592 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
593 buttons
->button(QDialogButtonBox::Yes
)->setDefault(true);
595 bool doNotAskAgainCheckboxResult
= false;
597 const auto result
= KMessageBox::createKMessageBox(dialog
,
599 QMessageBox::Warning
,
600 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
602 i18n("Do not ask again"),
603 &doNotAskAgainCheckboxResult
,
604 KMessageBox::Notify
);
606 if (doNotAskAgainCheckboxResult
) {
607 GeneralSettings::setConfirmClosingMultipleTabs(false);
611 case QDialogButtonBox::Yes
:
614 case QDialogButtonBox::No
:
615 // Close only the current tab
616 m_tabWidget
->closeTab();
624 if (m_terminalPanel
&& m_terminalPanel
->hasProgramRunning() && GeneralSettings::confirmClosingTerminalRunningProgram() && closedByUser
) {
625 // Ask if the user really wants to quit Dolphin with a program that is still running in the Terminal panel
626 // Open a confirmation dialog with 3 buttons:
627 // QDialogButtonBox::Yes -> Quit
628 // QDialogButtonBox::No -> Show Terminal Panel
629 // QDialogButtonBox::Cancel -> do nothing
630 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
631 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
632 dialog
->setModal(true);
633 auto standardButtons
= QDialogButtonBox::Yes
| QDialogButtonBox::Cancel
;
634 if (!m_terminalPanel
->isVisible()) {
635 standardButtons
|= QDialogButtonBox::No
;
637 QDialogButtonBox
*buttons
= new QDialogButtonBox(standardButtons
);
638 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KStandardGuiItem::quit());
639 if (!m_terminalPanel
->isVisible()) {
640 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("Show &Terminal Panel"), QIcon::fromTheme(QStringLiteral("dialog-scripts"))));
642 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
644 bool doNotAskAgainCheckboxResult
= false;
646 const auto result
= KMessageBox::createKMessageBox(
649 QMessageBox::Warning
,
650 i18n("The program '%1' is still running in the Terminal panel. Are you sure you want to quit?", m_terminalPanel
->runningProgramName()),
652 i18n("Do not ask again"),
653 &doNotAskAgainCheckboxResult
,
654 KMessageBox::Dangerous
);
656 if (doNotAskAgainCheckboxResult
) {
657 GeneralSettings::setConfirmClosingTerminalRunningProgram(false);
661 case QDialogButtonBox::Yes
:
664 case QDialogButtonBox::No
:
665 actionCollection()->action("show_terminal_panel")->trigger();
666 // Do not quit, ignore quit event
674 if (GeneralSettings::rememberOpenedTabs()) {
675 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
676 KConfig
*config
= KConfigGui::sessionConfig();
677 saveGlobalProperties(config
);
678 savePropertiesInternal(config
, 1);
682 GeneralSettings::setVersion(CurrentDolphinVersion
);
683 GeneralSettings::self()->save();
685 KXmlGuiWindow::closeEvent(event
);
688 void DolphinMainWindow::saveProperties(KConfigGroup
&group
)
690 m_tabWidget
->saveProperties(group
);
693 void DolphinMainWindow::readProperties(const KConfigGroup
&group
)
695 m_tabWidget
->readProperties(group
);
698 void DolphinMainWindow::updateNewMenu()
700 m_newFileMenu
->checkUpToDate();
701 m_newFileMenu
->setWorkingDirectory(activeViewContainer()->url());
704 void DolphinMainWindow::createDirectory()
706 m_newFileMenu
->setWorkingDirectory(activeViewContainer()->url());
707 m_newFileMenu
->createDirectory();
710 void DolphinMainWindow::quit()
715 void DolphinMainWindow::showErrorMessage(const QString
&message
)
717 m_activeViewContainer
->showMessage(message
, DolphinViewContainer::Error
);
720 void DolphinMainWindow::slotUndoAvailable(bool available
)
722 QAction
*undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
724 undoAction
->setEnabled(available
);
728 void DolphinMainWindow::slotUndoTextChanged(const QString
&text
)
730 QAction
*undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
732 undoAction
->setText(text
);
736 void DolphinMainWindow::undo()
739 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
740 KIO::FileUndoManager::self()->undo();
743 void DolphinMainWindow::cut()
745 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
746 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CutContents
);
748 m_activeViewContainer
->view()->cutSelectedItemsToClipboard();
749 m_activeViewContainer
->setSelectionModeEnabled(false);
753 void DolphinMainWindow::copy()
755 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
756 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CopyContents
);
758 m_activeViewContainer
->view()->copySelectedItemsToClipboard();
759 m_activeViewContainer
->setSelectionModeEnabled(false);
763 void DolphinMainWindow::paste()
765 m_activeViewContainer
->view()->paste();
768 void DolphinMainWindow::find()
770 m_activeViewContainer
->setSearchModeEnabled(true);
773 void DolphinMainWindow::updateSearchAction()
775 QAction
*toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
776 toggleSearchAction
->setChecked(m_activeViewContainer
->isSearchModeEnabled());
779 void DolphinMainWindow::updatePasteAction()
781 QAction
*pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
782 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
783 pasteAction
->setEnabled(pasteInfo
.first
);
784 pasteAction
->setText(pasteInfo
.second
);
787 void DolphinMainWindow::slotDirectoryLoadingCompleted()
792 void DolphinMainWindow::slotToolBarActionMiddleClicked(QAction
*action
)
794 if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Back
))) {
796 } else if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Forward
))) {
798 } else if (action
== actionCollection()->action(QStringLiteral("go_up"))) {
800 } else if (action
== actionCollection()->action(QStringLiteral("go_home"))) {
805 QAction
*DolphinMainWindow::urlNavigatorHistoryAction(const KUrlNavigator
*urlNavigator
, int historyIndex
, QObject
*parent
)
807 const QUrl url
= urlNavigator
->locationUrl(historyIndex
);
809 QString text
= url
.toDisplayString(QUrl::PreferLocalFile
);
811 if (!urlNavigator
->showFullPath()) {
812 const KFilePlacesModel
*placesModel
= DolphinPlacesModelSingleton::instance().placesModel();
814 const QModelIndex closestIdx
= placesModel
->closestItem(url
);
815 if (closestIdx
.isValid()) {
816 const QUrl placeUrl
= placesModel
->url(closestIdx
);
818 text
= placesModel
->text(closestIdx
);
820 QString pathInsidePlace
= url
.path().mid(placeUrl
.path().length());
822 if (!pathInsidePlace
.isEmpty() && !pathInsidePlace
.startsWith(QLatin1Char('/'))) {
823 pathInsidePlace
.prepend(QLatin1Char('/'));
826 if (pathInsidePlace
!= QLatin1Char('/')) {
827 text
.append(pathInsidePlace
);
832 QAction
*action
= new QAction(QIcon::fromTheme(KIO::iconNameForUrl(url
)), text
, parent
);
833 action
->setData(historyIndex
);
837 void DolphinMainWindow::slotAboutToShowBackPopupMenu()
839 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
841 m_backAction
->menu()->clear();
842 for (int i
= urlNavigator
->historyIndex() + 1; i
< urlNavigator
->historySize() && entries
< MaxNumberOfNavigationentries
; ++i
, ++entries
) {
843 QAction
*action
= urlNavigatorHistoryAction(urlNavigator
, i
, m_backAction
->menu());
844 m_backAction
->menu()->addAction(action
);
848 void DolphinMainWindow::slotGoBack(QAction
*action
)
850 int gotoIndex
= action
->data().value
<int>();
851 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
852 for (int i
= gotoIndex
- urlNavigator
->historyIndex(); i
> 0; --i
) {
857 void DolphinMainWindow::slotBackForwardActionMiddleClicked(QAction
*action
)
860 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
861 openNewTab(urlNavigator
->locationUrl(action
->data().value
<int>()));
865 void DolphinMainWindow::slotAboutToShowForwardPopupMenu()
867 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
869 m_forwardAction
->menu()->clear();
870 for (int i
= urlNavigator
->historyIndex() - 1; i
>= 0 && entries
< MaxNumberOfNavigationentries
; --i
, ++entries
) {
871 QAction
*action
= urlNavigatorHistoryAction(urlNavigator
, i
, m_forwardAction
->menu());
872 m_forwardAction
->menu()->addAction(action
);
876 void DolphinMainWindow::slotGoForward(QAction
*action
)
878 int gotoIndex
= action
->data().value
<int>();
879 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
880 for (int i
= urlNavigator
->historyIndex() - gotoIndex
; i
> 0; --i
) {
885 void DolphinMainWindow::slotSetSelectionMode(bool enabled
, SelectionMode::BottomBar::Contents bottomBarContents
)
887 m_activeViewContainer
->setSelectionModeEnabled(enabled
, actionCollection(), bottomBarContents
);
890 void DolphinMainWindow::selectAll()
894 // if the URL navigator is editable and focused, select the whole
895 // URL instead of all items of the view
897 KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigator();
898 QLineEdit
*lineEdit
= urlNavigator
->editor()->lineEdit();
899 const bool selectUrl
= urlNavigator
->isUrlEditable() && lineEdit
->hasFocus();
901 lineEdit
->selectAll();
903 m_activeViewContainer
->view()->selectAll();
907 void DolphinMainWindow::invertSelection()
910 m_activeViewContainer
->view()->invertSelection();
913 void DolphinMainWindow::toggleSplitView()
915 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
916 tabPage
->setSplitViewEnabled(!tabPage
->splitViewEnabled(), WithAnimation
);
921 void DolphinMainWindow::toggleSplitStash()
923 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
924 tabPage
->setSplitViewEnabled(false, WithAnimation
);
925 tabPage
->setSplitViewEnabled(true, WithAnimation
, QUrl("stash:/"));
928 void DolphinMainWindow::copyToInactiveSplitView()
930 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
931 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CopyToOtherViewContents
);
933 m_tabWidget
->copyToInactiveSplitView();
934 m_activeViewContainer
->setSelectionModeEnabled(false);
938 void DolphinMainWindow::moveToInactiveSplitView()
940 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
941 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::MoveToOtherViewContents
);
943 m_tabWidget
->moveToInactiveSplitView();
944 m_activeViewContainer
->setSelectionModeEnabled(false);
948 void DolphinMainWindow::reloadView()
951 m_activeViewContainer
->reload();
952 m_activeViewContainer
->statusBar()->updateSpaceInfo();
955 void DolphinMainWindow::stopLoading()
957 m_activeViewContainer
->view()->stopLoading();
960 void DolphinMainWindow::enableStopAction()
962 actionCollection()->action(QStringLiteral("stop"))->setEnabled(true);
965 void DolphinMainWindow::disableStopAction()
967 actionCollection()->action(QStringLiteral("stop"))->setEnabled(false);
970 void DolphinMainWindow::toggleSelectionMode()
972 const bool checked
= !m_activeViewContainer
->isSelectionModeEnabled();
974 m_activeViewContainer
->setSelectionModeEnabled(checked
, actionCollection(), SelectionMode::BottomBar::Contents::GeneralContents
);
975 actionCollection()->action(QStringLiteral("toggle_selection_mode"))->setChecked(checked
);
978 void DolphinMainWindow::showFilterBar()
980 m_activeViewContainer
->setFilterBarVisible(true);
983 void DolphinMainWindow::toggleFilterBar()
985 const bool checked
= !m_activeViewContainer
->isFilterBarVisible();
986 m_activeViewContainer
->setFilterBarVisible(checked
);
988 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
989 toggleFilterBarAction
->setChecked(checked
);
992 void DolphinMainWindow::toggleEditLocation()
996 QAction
*action
= actionCollection()->action(QStringLiteral("editable_location"));
997 KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigator();
998 urlNavigator
->setUrlEditable(action
->isChecked());
1001 void DolphinMainWindow::replaceLocation()
1003 KUrlNavigator
*navigator
= m_activeViewContainer
->urlNavigator();
1004 QLineEdit
*lineEdit
= navigator
->editor()->lineEdit();
1006 // If the text field currently has focus and everything is selected,
1007 // pressing the keyboard shortcut returns the whole thing to breadcrumb mode
1008 if (navigator
->isUrlEditable() && lineEdit
->hasFocus() && lineEdit
->selectedText() == lineEdit
->text()) {
1009 navigator
->setUrlEditable(false);
1011 navigator
->setUrlEditable(true);
1012 navigator
->setFocus();
1013 lineEdit
->selectAll();
1017 void DolphinMainWindow::togglePanelLockState()
1019 const bool newLockState
= !GeneralSettings::lockPanels();
1020 const auto childrenObjects
= children();
1021 for (QObject
*child
: childrenObjects
) {
1022 DolphinDockWidget
*dock
= qobject_cast
<DolphinDockWidget
*>(child
);
1024 dock
->setLocked(newLockState
);
1028 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(newLockState
);
1030 GeneralSettings::setLockPanels(newLockState
);
1033 void DolphinMainWindow::slotTerminalPanelVisibilityChanged()
1035 if (m_terminalPanel
->isHiddenInVisibleWindow() && m_activeViewContainer
) {
1036 m_activeViewContainer
->view()->setFocus();
1040 void DolphinMainWindow::goBack()
1042 DolphinUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
1043 urlNavigator
->goBack();
1045 if (urlNavigator
->locationState().isEmpty()) {
1046 // An empty location state indicates a redirection URL,
1047 // which must be skipped too
1048 urlNavigator
->goBack();
1052 void DolphinMainWindow::goForward()
1054 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goForward();
1057 void DolphinMainWindow::goUp()
1059 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goUp();
1062 void DolphinMainWindow::goHome()
1064 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goHome();
1067 void DolphinMainWindow::goBackInNewTab()
1069 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
1070 const int index
= urlNavigator
->historyIndex() + 1;
1071 openNewTab(urlNavigator
->locationUrl(index
));
1074 void DolphinMainWindow::goForwardInNewTab()
1076 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
1077 const int index
= urlNavigator
->historyIndex() - 1;
1078 openNewTab(urlNavigator
->locationUrl(index
));
1081 void DolphinMainWindow::goUpInNewTab()
1083 const QUrl currentUrl
= activeViewContainer()->urlNavigator()->locationUrl();
1084 openNewTab(KIO::upUrl(currentUrl
));
1087 void DolphinMainWindow::goHomeInNewTab()
1089 openNewTab(Dolphin::homeUrl());
1092 void DolphinMainWindow::compareFiles()
1094 const KFileItemList items
= m_tabWidget
->currentTabPage()->selectedItems();
1095 if (items
.count() != 2) {
1096 // The action is disabled in this case, but it could have been triggered
1097 // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
1101 QUrl urlA
= items
.at(0).url();
1102 QUrl urlB
= items
.at(1).url();
1104 QString
command(QStringLiteral("kompare -c \""));
1105 command
.append(urlA
.toDisplayString(QUrl::PreferLocalFile
));
1106 command
.append("\" \"");
1107 command
.append(urlB
.toDisplayString(QUrl::PreferLocalFile
));
1108 command
.append('\"');
1110 KIO::CommandLauncherJob
*job
= new KIO::CommandLauncherJob(command
, this);
1111 job
->setDesktopName(QStringLiteral("org.kde.kompare"));
1115 void DolphinMainWindow::toggleShowMenuBar()
1117 const bool visible
= menuBar()->isVisible();
1118 menuBar()->setVisible(!visible
);
1121 QPointer
<QAction
> DolphinMainWindow::preferredSearchTool()
1123 m_searchTools
.clear();
1124 KMoreToolsMenuFactory("dolphin/search-tools").fillMenuFromGroupingNames(&m_searchTools
, {"files-find"}, m_activeViewContainer
->url());
1125 QList
<QAction
*> actions
= m_searchTools
.actions();
1126 if (actions
.isEmpty()) {
1129 QAction
*action
= actions
.first();
1130 if (action
->isSeparator()) {
1136 void DolphinMainWindow::updateOpenPreferredSearchToolAction()
1138 QAction
*openPreferredSearchTool
= actionCollection()->action(QStringLiteral("open_preferred_search_tool"));
1139 if (!openPreferredSearchTool
) {
1142 QPointer
<QAction
> tool
= preferredSearchTool();
1144 openPreferredSearchTool
->setVisible(true);
1145 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open %1", tool
->text()));
1146 // Only override with the app icon if it is the default, i.e. the user hasn't configured one manually
1147 // https://bugs.kde.org/show_bug.cgi?id=442815
1148 if (openPreferredSearchTool
->icon().name() == QLatin1String("search")) {
1149 openPreferredSearchTool
->setIcon(tool
->icon());
1152 openPreferredSearchTool
->setVisible(false);
1153 // still visible in Shortcuts configuration window
1154 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1155 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1159 void DolphinMainWindow::openPreferredSearchTool()
1161 QPointer
<QAction
> tool
= preferredSearchTool();
1167 void DolphinMainWindow::openTerminal()
1169 openTerminalJob(m_activeViewContainer
->url());
1172 void DolphinMainWindow::openTerminalHere()
1174 QList
<QUrl
> urls
= {};
1176 for (const KFileItem
&item
: m_activeViewContainer
->view()->selectedItems()) {
1177 QUrl url
= item
.targetUrl();
1178 if (item
.isFile()) {
1179 url
.setPath(QFileInfo(url
.path()).absolutePath());
1181 if (!urls
.contains(url
)) {
1186 // No items are selected. Open a terminal window for the current location.
1187 if (urls
.count() == 0) {
1192 if (urls
.count() > 5) {
1193 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());
1194 #if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
1195 const int answer
= KMessageBox::warningTwoActions(
1200 const int answer
= KMessageBox::warningYesNo(
1205 KGuiItem(i18ncp("@action:button", "Open %1 Terminal", "Open %1 Terminals", urls
.count()), QStringLiteral("utilities-terminal")),
1206 KStandardGuiItem::cancel());
1207 #if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
1208 if (answer
!= KMessageBox::PrimaryAction
) {
1210 if (answer
!= KMessageBox::Yes
) {
1216 for (const QUrl
&url
: urls
) {
1217 openTerminalJob(url
);
1221 void DolphinMainWindow::openTerminalJob(const QUrl
&url
)
1223 if (url
.isLocalFile()) {
1224 auto job
= new KTerminalLauncherJob(QString());
1225 job
->setWorkingDirectory(url
.toLocalFile());
1230 // Not a local file, with protocol Class ":local", try stat'ing
1231 if (KProtocolInfo::protocolClass(url
.scheme()) == QLatin1String(":local")) {
1232 KIO::StatJob
*job
= KIO::mostLocalUrl(url
);
1233 KJobWidgets::setWindow(job
, this);
1234 connect(job
, &KJob::result
, this, [job
]() {
1236 if (!job
->error()) {
1237 statUrl
= job
->mostLocalUrl();
1240 auto job
= new KTerminalLauncherJob(QString());
1241 job
->setWorkingDirectory(statUrl
.isLocalFile() ? statUrl
.toLocalFile() : QDir::homePath());
1248 // Nothing worked, just use $HOME
1249 auto job
= new KTerminalLauncherJob(QString());
1250 job
->setWorkingDirectory(QDir::homePath());
1254 void DolphinMainWindow::editSettings()
1256 if (!m_settingsDialog
) {
1257 DolphinViewContainer
*container
= activeViewContainer();
1258 container
->view()->writeSettings();
1260 const QUrl url
= container
->url();
1261 DolphinSettingsDialog
*settingsDialog
= new DolphinSettingsDialog(url
, this, actionCollection());
1262 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, this, &DolphinMainWindow::refreshViews
);
1263 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, &DolphinUrlNavigatorsController::slotReadSettings
);
1264 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1265 settingsDialog
->show();
1266 m_settingsDialog
= settingsDialog
;
1268 m_settingsDialog
.data()->raise();
1272 void DolphinMainWindow::handleUrl(const QUrl
&url
)
1274 delete m_lastHandleUrlOpenJob
;
1275 m_lastHandleUrlOpenJob
= nullptr;
1277 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1278 activeViewContainer()->setUrl(url
);
1280 m_lastHandleUrlOpenJob
= new KIO::OpenUrlJob(url
);
1281 m_lastHandleUrlOpenJob
->setUiDelegate(KIO::createDefaultJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
1282 m_lastHandleUrlOpenJob
->setShowOpenOrExecuteDialog(true);
1284 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::mimeTypeFound
, this, [this, url
](const QString
&mimetype
) {
1285 if (mimetype
== QLatin1String("inode/directory")) {
1286 // If it's a dir, we'll take it from here
1287 m_lastHandleUrlOpenJob
->kill();
1288 m_lastHandleUrlOpenJob
= nullptr;
1289 activeViewContainer()->setUrl(url
);
1293 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::result
, this, [this]() {
1294 m_lastHandleUrlOpenJob
= nullptr;
1297 m_lastHandleUrlOpenJob
->start();
1301 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1303 // trash:/ is writable but we don't want to create new items in it.
1304 // TODO: remove the trash check once https://phabricator.kde.org/T8234 is implemented
1305 newFileMenu()->setEnabled(isFolderWritable
&& m_activeViewContainer
->url().scheme() != QLatin1String("trash"));
1308 void DolphinMainWindow::openContextMenu(const QPoint
&pos
, const KFileItem
&item
, const KFileItemList
&selectedItems
, const QUrl
&url
)
1310 QPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, item
, selectedItems
, url
, &m_fileItemActions
);
1311 contextMenu
.data()->exec(pos
);
1313 // Delete the menu, unless it has been deleted in its own nested event loop already.
1315 contextMenu
->deleteLater();
1319 QMenu
*DolphinMainWindow::createPopupMenu()
1321 QMenu
*menu
= KXmlGuiWindow::createPopupMenu();
1323 menu
->addSeparator();
1324 menu
->addAction(actionCollection()->action(QStringLiteral("lock_panels")));
1329 void DolphinMainWindow::updateHamburgerMenu()
1331 KActionCollection
*ac
= actionCollection();
1332 auto hamburgerMenu
= static_cast<KHamburgerMenu
*>(ac
->action(KStandardAction::name(KStandardAction::HamburgerMenu
)));
1333 auto menu
= hamburgerMenu
->menu();
1335 menu
= new QMenu(this);
1336 hamburgerMenu
->setMenu(menu
);
1337 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("basic_actions"))->menu());
1338 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("zoom"))->menu());
1342 const QList
<QAction
*> toolbarActions
= toolBar()->actions();
1344 if (!toolBar()->isVisible()) {
1345 // If neither the menu bar nor the toolbar are visible, these actions should be available.
1346 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)));
1347 menu
->addAction(toolBarMenuAction());
1348 menu
->addSeparator();
1351 // This group of actions (until the next separator) contains all the most basic actions
1352 // necessary to use Dolphin effectively.
1353 menu
->addAction(ac
->action(QStringLiteral("go_back")));
1354 menu
->addAction(ac
->action(QStringLiteral("go_forward")));
1356 menu
->addMenu(m_newFileMenu
->menu());
1357 if (!toolBar()->isVisible() || !toolbarActions
.contains(ac
->action(QStringLiteral("toggle_selection_mode_tool_bar")))) {
1358 menu
->addAction(ac
->action(QStringLiteral("toggle_selection_mode")));
1360 menu
->addAction(ac
->action(QStringLiteral("basic_actions")));
1361 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Undo
)));
1362 if (!toolBar()->isVisible()
1363 || (!toolbarActions
.contains(ac
->action(QStringLiteral("toggle_search")))
1364 && !toolbarActions
.contains(ac
->action(QStringLiteral("open_preferred_search_tool"))))) {
1365 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Find
)));
1366 // This way a search action will only be added if none of the three available
1367 // search actions is present on the toolbar.
1369 if (!toolBar()->isVisible() || !toolbarActions
.contains(ac
->action(QStringLiteral("toggle_filter")))) {
1370 menu
->addAction(ac
->action(QStringLiteral("show_filter_bar")));
1371 // This way a filter action will only be added if none of the two available
1372 // filter actions is present on the toolbar.
1374 menu
->addSeparator();
1376 // The second group of actions (up until the next separator) contains actions for opening
1377 // additional views to interact with the file system.
1378 menu
->addAction(ac
->action(QStringLiteral("file_new")));
1379 menu
->addAction(ac
->action(QStringLiteral("new_tab")));
1380 if (ac
->action(QStringLiteral("undo_close_tab"))->isEnabled()) {
1381 menu
->addAction(ac
->action(QStringLiteral("closed_tabs")));
1383 menu
->addAction(ac
->action(QStringLiteral("open_terminal")));
1384 menu
->addSeparator();
1386 // The third group contains actions to change what one sees in the view
1387 // and to change the more general UI.
1388 if (!toolBar()->isVisible()
1389 || (!toolbarActions
.contains(ac
->action(QStringLiteral("icons"))) && !toolbarActions
.contains(ac
->action(QStringLiteral("compact")))
1390 && !toolbarActions
.contains(ac
->action(QStringLiteral("details"))) && !toolbarActions
.contains(ac
->action(QStringLiteral("view_mode"))))) {
1391 menu
->addAction(ac
->action(QStringLiteral("view_mode")));
1393 menu
->addAction(ac
->action(QStringLiteral("show_hidden_files")));
1394 menu
->addAction(ac
->action(QStringLiteral("sort")));
1395 menu
->addAction(ac
->action(QStringLiteral("additional_info")));
1396 if (!GeneralSettings::showStatusBar() || !GeneralSettings::showZoomSlider()) {
1397 menu
->addAction(ac
->action(QStringLiteral("zoom")));
1399 menu
->addAction(ac
->action(QStringLiteral("panels")));
1401 // The "Configure" menu is not added to the actionCollection() because there is hardly
1402 // a good reason for users to put it on their toolbar.
1403 auto configureMenu
= menu
->addMenu(QIcon::fromTheme(QStringLiteral("configure")), i18nc("@action:inmenu menu for configure actions", "Configure"));
1404 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
)));
1405 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)));
1406 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)));
1407 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Preferences
)));
1408 hamburgerMenu
->hideActionsOf(configureMenu
);
1411 void DolphinMainWindow::slotPlaceActivated(const QUrl
&url
)
1413 DolphinViewContainer
*view
= activeViewContainer();
1415 if (view
->url() == url
) {
1416 view
->clearFilterBar(); // Fixes bug 259382.
1418 // We can end up here if the user clicked a device in the Places Panel
1419 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
1422 view
->disableUrlNavigatorSelectionRequests();
1424 view
->enableUrlNavigatorSelectionRequests();
1428 void DolphinMainWindow::closedTabsCountChanged(unsigned int count
)
1430 actionCollection()->action(QStringLiteral("undo_close_tab"))->setEnabled(count
> 0);
1433 void DolphinMainWindow::activeViewChanged(DolphinViewContainer
*viewContainer
)
1435 DolphinViewContainer
*oldViewContainer
= m_activeViewContainer
;
1436 Q_ASSERT(viewContainer
);
1438 m_activeViewContainer
= viewContainer
;
1440 if (oldViewContainer
) {
1441 const QAction
*toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
1442 toggleSearchAction
->disconnect(oldViewContainer
);
1444 // Disconnect all signals between the old view container (container,
1445 // view and url navigator) and main window.
1446 oldViewContainer
->disconnect(this);
1447 oldViewContainer
->view()->disconnect(this);
1448 oldViewContainer
->urlNavigatorInternalWithHistory()->disconnect(this);
1449 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
1450 navigators
->primaryUrlNavigator()->disconnect(this);
1451 if (auto secondaryUrlNavigator
= navigators
->secondaryUrlNavigator()) {
1452 secondaryUrlNavigator
->disconnect(this);
1455 // except the requestItemInfo so that on hover the information panel can still be updated
1456 connect(oldViewContainer
->view(), &DolphinView::requestItemInfo
, this, &DolphinMainWindow::requestItemInfo
);
1458 // Disconnect other slots.
1459 disconnect(oldViewContainer
,
1460 &DolphinViewContainer::selectionModeChanged
,
1461 actionCollection()->action(QStringLiteral("toggle_selection_mode")),
1462 &QAction::setChecked
);
1465 connectViewSignals(viewContainer
);
1467 m_actionHandler
->setCurrentView(viewContainer
->view());
1470 updateFileAndEditActions();
1471 updatePasteAction();
1472 updateViewActions();
1474 updateSearchAction();
1476 const QUrl url
= viewContainer
->url();
1477 Q_EMIT
urlChanged(url
);
1480 void DolphinMainWindow::tabCountChanged(int count
)
1482 const bool enableTabActions
= (count
> 1);
1483 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1484 actionCollection()->action(QStringLiteral("activate_tab_%1").arg(i
))->setEnabled(enableTabActions
);
1486 actionCollection()->action(QStringLiteral("activate_last_tab"))->setEnabled(enableTabActions
);
1487 actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions
);
1488 actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions
);
1491 void DolphinMainWindow::updateWindowTitle()
1493 const QString newTitle
= m_activeViewContainer
->captionWindowTitle();
1494 if (windowTitle() != newTitle
) {
1495 setWindowTitle(newTitle
);
1499 void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString
&mountPath
)
1501 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1502 setViewsToHomeIfMountPathOpen(mountPath
);
1505 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectoryIsChildOf(mountPath
)) {
1506 m_tearDownFromPlacesRequested
= true;
1507 m_terminalPanel
->goHome();
1508 // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged
1510 m_placesPanel
->proceedWithTearDown();
1514 void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString
&mountPath
)
1516 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1517 setViewsToHomeIfMountPathOpen(mountPath
);
1520 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectoryIsChildOf(mountPath
)) {
1521 m_tearDownFromPlacesRequested
= false;
1522 m_terminalPanel
->goHome();
1526 void DolphinMainWindow::slotKeyBindings()
1528 KShortcutsDialog
dialog(KShortcutsEditor::AllActions
, KShortcutsEditor::LetterShortcutsAllowed
, this);
1529 dialog
.addCollection(actionCollection());
1530 if (m_terminalPanel
) {
1531 KActionCollection
*konsolePartActionCollection
= m_terminalPanel
->actionCollection();
1532 if (konsolePartActionCollection
) {
1533 dialog
.addCollection(konsolePartActionCollection
, QStringLiteral("KonsolePart"));
1539 void DolphinMainWindow::setViewsToHomeIfMountPathOpen(const QString
&mountPath
)
1541 const QVector
<DolphinViewContainer
*> theViewContainers
= viewContainers();
1542 for (DolphinViewContainer
*viewContainer
: theViewContainers
) {
1543 if (viewContainer
&& viewContainer
->url().toLocalFile().startsWith(mountPath
)) {
1544 viewContainer
->setUrl(QUrl::fromLocalFile(QDir::homePath()));
1547 disconnect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, nullptr, nullptr);
1550 void DolphinMainWindow::setupActions()
1552 auto hamburgerMenuAction
= KStandardAction::hamburgerMenu(nullptr, nullptr, actionCollection());
1554 // setup 'File' menu
1555 m_newFileMenu
= new DolphinNewFileMenu(nullptr, this);
1556 actionCollection()->addAction(QStringLiteral("new_menu"), m_newFileMenu
);
1557 QMenu
*menu
= m_newFileMenu
->menu();
1558 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1559 menu
->setIcon(QIcon::fromTheme(QStringLiteral("list-add")));
1560 m_newFileMenu
->setPopupMode(QToolButton::InstantPopup
);
1561 connect(menu
, &QMenu::aboutToShow
, this, &DolphinMainWindow::updateNewMenu
);
1563 QAction
*newWindow
= KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow
, actionCollection());
1564 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1565 newWindow
->setToolTip(i18nc("@info", "Open a new Dolphin window"));
1566 newWindow
->setWhatsThis(xi18nc("@info:whatsthis",
1568 "window just like this one with the current location and view."
1569 "<nl/>You can drag and drop items between windows."));
1570 newWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1572 QAction
*newTab
= actionCollection()->addAction(QStringLiteral("new_tab"));
1573 newTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1574 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1575 newTab
->setWhatsThis(xi18nc("@info:whatsthis",
1577 "<emphasis>Tab</emphasis> with the current location and view.<nl/>"
1578 "A tab is an additional view within this window. "
1579 "You can drag and drop items between tabs."));
1580 actionCollection()->setDefaultShortcuts(newTab
, {Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
});
1581 connect(newTab
, &QAction::triggered
, this, &DolphinMainWindow::openNewActivatedTab
);
1583 QAction
*addToPlaces
= actionCollection()->addAction(QStringLiteral("add_to_places"));
1584 addToPlaces
->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new")));
1585 addToPlaces
->setText(i18nc("@action:inmenu Add current folder to places", "Add to Places"));
1586 addToPlaces
->setWhatsThis(xi18nc("@info:whatsthis",
1587 "This adds the selected folder "
1588 "to the Places panel."));
1589 connect(addToPlaces
, &QAction::triggered
, this, &DolphinMainWindow::addToPlaces
);
1591 QAction
*closeTab
= KStandardAction::close(m_tabWidget
, QOverload
<>::of(&DolphinTabWidget::closeTab
), actionCollection());
1592 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1593 closeTab
->setWhatsThis(i18nc("@info:whatsthis",
1595 "currently viewed tab. If no more tabs are left this window "
1596 "will close instead."));
1598 QAction
*quitAction
= KStandardAction::quit(this, &DolphinMainWindow::quit
, actionCollection());
1599 quitAction
->setWhatsThis(i18nc("@info:whatsthis quit", "This closes this window."));
1601 // setup 'Edit' menu
1602 KStandardAction::undo(this, &DolphinMainWindow::undo
, actionCollection());
1604 // i18n: This will be the last paragraph for the whatsthis for all three:
1605 // Cut, Copy and Paste
1606 const QString cutCopyPastePara
= xi18nc("@info:whatsthis",
1607 "<para><emphasis>Cut, "
1608 "Copy</emphasis> and <emphasis>Paste</emphasis> work between many "
1609 "applications and are among the most used commands. That's why their "
1610 "<emphasis>keyboard shortcuts</emphasis> are prominently placed right "
1611 "next to each other on the keyboard: <shortcut>Ctrl+X</shortcut>, "
1612 "<shortcut>Ctrl+C</shortcut> and <shortcut>Ctrl+V</shortcut>.</para>");
1613 QAction
*cutAction
= KStandardAction::cut(this, &DolphinMainWindow::cut
, actionCollection());
1614 m_actionTextHelper
->registerTextWhenNothingIsSelected(cutAction
, i18nc("@action", "Cut…"));
1615 cutAction
->setWhatsThis(xi18nc("@info:whatsthis cut",
1616 "This copies the items "
1617 "in your current selection to the <emphasis>clipboard</emphasis>.<nl/>"
1618 "Use the <emphasis>Paste</emphasis> action afterwards to copy them from "
1619 "the clipboard to a new location. The items will be removed from their "
1620 "initial location.")
1621 + cutCopyPastePara
);
1622 QAction
*copyAction
= KStandardAction::copy(this, &DolphinMainWindow::copy
, actionCollection());
1623 m_actionTextHelper
->registerTextWhenNothingIsSelected(copyAction
, i18nc("@action", "Copy…"));
1624 copyAction
->setWhatsThis(xi18nc("@info:whatsthis copy",
1626 "items in your current selection to the <emphasis>clipboard</emphasis>."
1627 "<nl/>Use the <emphasis>Paste</emphasis> action afterwards to copy them "
1628 "from the clipboard to a new location.")
1629 + cutCopyPastePara
);
1630 QAction
*paste
= KStandardAction::paste(this, &DolphinMainWindow::paste
, actionCollection());
1631 // The text of the paste-action is modified dynamically by Dolphin
1632 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1633 // due to the long text, the text "Paste" is used:
1634 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1635 paste
->setWhatsThis(xi18nc("@info:whatsthis paste",
1636 "This copies the items from "
1637 "your <emphasis>clipboard</emphasis> to the currently viewed folder.<nl/>"
1638 "If the items were added to the clipboard by the <emphasis>Cut</emphasis> "
1639 "action they are removed from their old location.")
1640 + cutCopyPastePara
);
1642 QAction
*copyToOtherViewAction
= actionCollection()->addAction(QStringLiteral("copy_to_inactive_split_view"));
1643 copyToOtherViewAction
->setText(i18nc("@action:inmenu", "Copy to Other View"));
1644 m_actionTextHelper
->registerTextWhenNothingIsSelected(copyToOtherViewAction
, i18nc("@action:inmenu", "Copy to Other View…"));
1645 copyToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Copy",
1646 "This copies the selected items from "
1647 "the <emphasis>active</emphasis> view to the inactive split view."));
1648 copyToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
1649 copyToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Copy to Inactive Split View"));
1650 actionCollection()->setDefaultShortcut(copyToOtherViewAction
, Qt::SHIFT
| Qt::Key_F5
);
1651 connect(copyToOtherViewAction
, &QAction::triggered
, this, &DolphinMainWindow::copyToInactiveSplitView
);
1653 QAction
*moveToOtherViewAction
= actionCollection()->addAction(QStringLiteral("move_to_inactive_split_view"));
1654 moveToOtherViewAction
->setText(i18nc("@action:inmenu", "Move to Other View"));
1655 m_actionTextHelper
->registerTextWhenNothingIsSelected(moveToOtherViewAction
, i18nc("@action:inmenu", "Move to Other View…"));
1656 moveToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Move",
1657 "This moves the selected items from "
1658 "the <emphasis>active</emphasis> view to the inactive split view."));
1659 moveToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-cut")));
1660 moveToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Move to Inactive Split View"));
1661 actionCollection()->setDefaultShortcut(moveToOtherViewAction
, Qt::SHIFT
| Qt::Key_F6
);
1662 connect(moveToOtherViewAction
, &QAction::triggered
, this, &DolphinMainWindow::moveToInactiveSplitView
);
1664 QAction
*showFilterBar
= actionCollection()->addAction(QStringLiteral("show_filter_bar"));
1665 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Filter..."));
1666 showFilterBar
->setToolTip(i18nc("@info:tooltip", "Show Filter Bar"));
1667 showFilterBar
->setWhatsThis(xi18nc("@info:whatsthis",
1669 "<emphasis>Filter Bar</emphasis> at the bottom of the window.<nl/> "
1670 "There you can enter a text to filter the files and folders currently displayed. "
1671 "Only those that contain the text in their name will be kept in view."));
1672 showFilterBar
->setIcon(QIcon::fromTheme(QStringLiteral("view-filter")));
1673 actionCollection()->setDefaultShortcuts(showFilterBar
, {Qt::CTRL
| Qt::Key_I
, Qt::Key_Slash
});
1674 connect(showFilterBar
, &QAction::triggered
, this, &DolphinMainWindow::showFilterBar
);
1676 // toggle_filter acts as a copy of the main showFilterBar to be used mainly
1677 // in the toolbar, with no default shortcut attached, to avoid messing with
1678 // existing workflows (filter bar always open and Ctrl-I to focus)
1679 QAction
*toggleFilter
= actionCollection()->addAction(QStringLiteral("toggle_filter"));
1680 toggleFilter
->setText(i18nc("@action:inmenu", "Toggle Filter Bar"));
1681 toggleFilter
->setIconText(i18nc("@action:intoolbar", "Filter"));
1682 toggleFilter
->setIcon(showFilterBar
->icon());
1683 toggleFilter
->setToolTip(showFilterBar
->toolTip());
1684 toggleFilter
->setWhatsThis(showFilterBar
->whatsThis());
1685 toggleFilter
->setCheckable(true);
1686 connect(toggleFilter
, &QAction::triggered
, this, &DolphinMainWindow::toggleFilterBar
);
1688 QAction
*searchAction
= KStandardAction::find(this, &DolphinMainWindow::find
, actionCollection());
1689 searchAction
->setText(i18n("Search..."));
1690 searchAction
->setToolTip(i18nc("@info:tooltip", "Search for files and folders"));
1691 searchAction
->setWhatsThis(xi18nc("@info:whatsthis find",
1692 "<para>This helps you "
1693 "find files and folders by opening a <emphasis>find bar</emphasis>. "
1694 "There you can enter search terms and specify settings to find the "
1695 "objects you are looking for.</para><para>Use this help again on "
1696 "the find bar so we can have a look at it while the settings are "
1697 "explained.</para>"));
1699 // toggle_search acts as a copy of the main searchAction to be used mainly
1700 // in the toolbar, with no default shortcut attached, to avoid messing with
1701 // existing workflows (search bar always open and Ctrl-F to focus)
1702 QAction
*toggleSearchAction
= actionCollection()->addAction(QStringLiteral("toggle_search"));
1703 toggleSearchAction
->setText(i18nc("@action:inmenu", "Toggle Search Bar"));
1704 toggleSearchAction
->setIconText(i18nc("@action:intoolbar", "Search"));
1705 toggleSearchAction
->setIcon(searchAction
->icon());
1706 toggleSearchAction
->setToolTip(searchAction
->toolTip());
1707 toggleSearchAction
->setWhatsThis(searchAction
->whatsThis());
1708 toggleSearchAction
->setCheckable(true);
1710 QAction
*toggleSelectionModeAction
= actionCollection()->addAction(QStringLiteral("toggle_selection_mode"));
1711 // i18n: This action toggles a selection mode.
1712 toggleSelectionModeAction
->setText(i18nc("@action:inmenu", "Select Files and Folders"));
1713 // i18n: Opens a selection mode for selecting files/folders.
1714 // The text is kept so unspecific because it will be shown on the toolbar where space is at a premium.
1715 toggleSelectionModeAction
->setIconText(i18nc("@action:intoolbar", "Select"));
1716 toggleSelectionModeAction
->setWhatsThis(xi18nc(
1718 "<para>This application only knows which files or folders should be acted on if they are"
1719 " <emphasis>selected</emphasis> first. Press this to toggle a <emphasis>Selection Mode</emphasis> which makes selecting and deselecting as easy as "
1720 "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."
1722 toggleSelectionModeAction
->setIcon(QIcon::fromTheme(QStringLiteral("quickwizard")));
1723 toggleSelectionModeAction
->setCheckable(true);
1724 actionCollection()->setDefaultShortcut(toggleSelectionModeAction
, Qt::Key_Space
);
1725 connect(toggleSelectionModeAction
, &QAction::triggered
, this, &DolphinMainWindow::toggleSelectionMode
);
1727 // A special version of the toggleSelectionModeAction for the toolbar that also contains a menu
1728 // with the selectAllAction and invertSelectionAction.
1729 auto *toggleSelectionModeToolBarAction
=
1730 new KToolBarPopupAction(toggleSelectionModeAction
->icon(), toggleSelectionModeAction
->iconText(), actionCollection());
1731 toggleSelectionModeToolBarAction
->setToolTip(toggleSelectionModeAction
->text());
1732 toggleSelectionModeToolBarAction
->setWhatsThis(toggleSelectionModeAction
->whatsThis());
1733 actionCollection()->addAction(QStringLiteral("toggle_selection_mode_tool_bar"), toggleSelectionModeToolBarAction
);
1734 toggleSelectionModeToolBarAction
->setCheckable(true);
1735 toggleSelectionModeToolBarAction
->setPopupMode(QToolButton::DelayedPopup
);
1736 connect(toggleSelectionModeToolBarAction
, &QAction::triggered
, toggleSelectionModeAction
, &QAction::trigger
);
1737 connect(toggleSelectionModeAction
, &QAction::toggled
, toggleSelectionModeToolBarAction
, &QAction::setChecked
);
1739 QAction
*selectAllAction
= KStandardAction::selectAll(this, &DolphinMainWindow::selectAll
, actionCollection());
1740 selectAllAction
->setWhatsThis(xi18nc("@info:whatsthis",
1742 "files and folders in the current location."));
1744 QAction
*invertSelection
= actionCollection()->addAction(QStringLiteral("invert_selection"));
1745 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1746 invertSelection
->setWhatsThis(xi18nc("@info:whatsthis invert",
1748 "objects that you have currently <emphasis>not</emphasis> selected instead."));
1749 invertSelection
->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-invert")));
1750 actionCollection()->setDefaultShortcut(invertSelection
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1751 connect(invertSelection
, &QAction::triggered
, this, &DolphinMainWindow::invertSelection
);
1753 QMenu
*toggleSelectionModeActionMenu
= new QMenu(this);
1754 toggleSelectionModeActionMenu
->addAction(selectAllAction
);
1755 toggleSelectionModeActionMenu
->addAction(invertSelection
);
1756 toggleSelectionModeToolBarAction
->setMenu(toggleSelectionModeActionMenu
);
1758 // setup 'View' menu
1759 // (note that most of it is set up in DolphinViewActionHandler)
1761 QAction
*split
= actionCollection()->addAction(QStringLiteral("split_view"));
1762 split
->setWhatsThis(xi18nc("@info:whatsthis find",
1763 "<para>This splits "
1764 "the folder view below into two autonomous views.</para><para>This "
1765 "way you can see two locations at once and move items between them "
1766 "quickly.</para>Click this again afterwards to recombine the views."));
1767 actionCollection()->setDefaultShortcut(split
, Qt::Key_F3
);
1768 connect(split
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitView
);
1770 QAction
*stashSplit
= actionCollection()->addAction(QStringLiteral("split_stash"));
1771 actionCollection()->setDefaultShortcut(stashSplit
, Qt::CTRL
| Qt::Key_S
);
1772 stashSplit
->setText(i18nc("@action:intoolbar Stash", "Stash"));
1773 stashSplit
->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
1774 stashSplit
->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
1775 stashSplit
->setCheckable(false);
1776 QDBusConnectionInterface
*sessionInterface
= QDBusConnection::sessionBus().interface();
1777 stashSplit
->setVisible(sessionInterface
&& sessionInterface
->isServiceRegistered(QStringLiteral("org.kde.kio.StashNotifier")));
1778 connect(stashSplit
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitStash
);
1780 KStandardAction::redisplay(this, &DolphinMainWindow::reloadView
, actionCollection());
1782 QAction
*stop
= actionCollection()->addAction(QStringLiteral("stop"));
1783 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1784 stop
->setToolTip(i18nc("@info", "Stop loading"));
1785 stop
->setWhatsThis(i18nc("@info", "This stops the loading of the contents of the current folder."));
1786 stop
->setIcon(QIcon::fromTheme(QStringLiteral("process-stop")));
1787 connect(stop
, &QAction::triggered
, this, &DolphinMainWindow::stopLoading
);
1789 KToggleAction
*editableLocation
= actionCollection()->add
<KToggleAction
>(QStringLiteral("editable_location"));
1790 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1791 editableLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1792 "This toggles the <emphasis>Location Bar</emphasis> to be "
1793 "editable so you can directly enter a location you want to go to.<nl/>"
1794 "You can also switch to editing by clicking to the right of the "
1795 "location and switch back by confirming the edited location."));
1796 actionCollection()->setDefaultShortcut(editableLocation
, Qt::Key_F6
);
1797 connect(editableLocation
, &KToggleAction::triggered
, this, &DolphinMainWindow::toggleEditLocation
);
1799 QAction
*replaceLocation
= actionCollection()->addAction(QStringLiteral("replace_location"));
1800 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1801 // i18n: "enter" is used both in the meaning of "writing" and "going to" a new location here.
1802 // Both meanings are useful but not necessary to understand the use of "Replace Location".
1803 // So you might want to be more verbose in your language to convey the meaning but it's up to you.
1804 replaceLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1805 "This switches to editing the location and selects it "
1806 "so you can quickly enter a different location."));
1807 actionCollection()->setDefaultShortcut(replaceLocation
, Qt::CTRL
| Qt::Key_L
);
1808 connect(replaceLocation
, &QAction::triggered
, this, &DolphinMainWindow::replaceLocation
);
1812 QScopedPointer
<QAction
> backAction(KStandardAction::back(nullptr, nullptr, nullptr));
1813 m_backAction
= new KToolBarPopupAction(backAction
->icon(), backAction
->text(), actionCollection());
1814 m_backAction
->setObjectName(backAction
->objectName());
1815 m_backAction
->setShortcuts(backAction
->shortcuts());
1817 m_backAction
->setPopupMode(QToolButton::DelayedPopup
);
1818 connect(m_backAction
, &QAction::triggered
, this, &DolphinMainWindow::goBack
);
1819 connect(m_backAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowBackPopupMenu
);
1820 connect(m_backAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoBack
);
1821 actionCollection()->addAction(m_backAction
->objectName(), m_backAction
);
1823 auto backShortcuts
= m_backAction
->shortcuts();
1824 // Prepend this shortcut, to avoid being hidden by the two-slot UI (#371130)
1825 backShortcuts
.prepend(QKeySequence(Qt::Key_Backspace
));
1826 actionCollection()->setDefaultShortcuts(m_backAction
, backShortcuts
);
1828 DolphinRecentTabsMenu
*recentTabsMenu
= new DolphinRecentTabsMenu(this);
1829 actionCollection()->addAction(QStringLiteral("closed_tabs"), recentTabsMenu
);
1830 connect(m_tabWidget
, &DolphinTabWidget::rememberClosedTab
, recentTabsMenu
, &DolphinRecentTabsMenu::rememberClosedTab
);
1831 connect(recentTabsMenu
, &DolphinRecentTabsMenu::restoreClosedTab
, m_tabWidget
, &DolphinTabWidget::restoreClosedTab
);
1832 connect(recentTabsMenu
, &DolphinRecentTabsMenu::closedTabsCountChanged
, this, &DolphinMainWindow::closedTabsCountChanged
);
1834 QAction
*undoCloseTab
= actionCollection()->addAction(QStringLiteral("undo_close_tab"));
1835 undoCloseTab
->setText(i18nc("@action:inmenu File", "Undo close tab"));
1836 undoCloseTab
->setWhatsThis(i18nc("@info:whatsthis undo close tab", "This returns you to the previously closed tab."));
1837 actionCollection()->setDefaultShortcut(undoCloseTab
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_T
);
1838 undoCloseTab
->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo")));
1839 undoCloseTab
->setEnabled(false);
1840 connect(undoCloseTab
, &QAction::triggered
, recentTabsMenu
, &DolphinRecentTabsMenu::undoCloseTab
);
1842 auto undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
1843 undoAction
->setWhatsThis(xi18nc("@info:whatsthis",
1845 "the last change you made to files or folders.<nl/>"
1846 "Such changes include <interface>creating, renaming</interface> "
1847 "and <interface>moving</interface> them to a different location "
1848 "or to the <filename>Trash</filename>. <nl/>Changes that can't "
1849 "be undone will ask for your confirmation."));
1850 undoAction
->setEnabled(false); // undo should be disabled by default
1853 QScopedPointer
<QAction
> forwardAction(KStandardAction::forward(nullptr, nullptr, nullptr));
1854 m_forwardAction
= new KToolBarPopupAction(forwardAction
->icon(), forwardAction
->text(), actionCollection());
1855 m_forwardAction
->setObjectName(forwardAction
->objectName());
1856 m_forwardAction
->setShortcuts(forwardAction
->shortcuts());
1858 m_forwardAction
->setPopupMode(QToolButton::DelayedPopup
);
1859 connect(m_forwardAction
, &QAction::triggered
, this, &DolphinMainWindow::goForward
);
1860 connect(m_forwardAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowForwardPopupMenu
);
1861 connect(m_forwardAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoForward
);
1862 actionCollection()->addAction(m_forwardAction
->objectName(), m_forwardAction
);
1863 actionCollection()->setDefaultShortcuts(m_forwardAction
, m_forwardAction
->shortcuts());
1865 // enable middle-click to open in a new tab
1866 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
1867 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotBackForwardActionMiddleClicked
);
1868 m_backAction
->menu()->installEventFilter(middleClickEventFilter
);
1869 m_forwardAction
->menu()->installEventFilter(middleClickEventFilter
);
1870 KStandardAction::up(this, &DolphinMainWindow::goUp
, actionCollection());
1871 QAction
*homeAction
= KStandardAction::home(this, &DolphinMainWindow::goHome
, actionCollection());
1872 homeAction
->setWhatsThis(xi18nc("@info:whatsthis",
1874 "<filename>Home</filename> folder.<nl/>Every user account "
1875 "has their own <filename>Home</filename> that contains their data "
1876 "including folders that contain personal application data."));
1878 // setup 'Tools' menu
1879 QAction
*compareFiles
= actionCollection()->addAction(QStringLiteral("compare_files"));
1880 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1881 compareFiles
->setIcon(QIcon::fromTheme(QStringLiteral("kompare")));
1882 compareFiles
->setEnabled(false);
1883 connect(compareFiles
, &QAction::triggered
, this, &DolphinMainWindow::compareFiles
);
1885 QAction
*openPreferredSearchTool
= actionCollection()->addAction(QStringLiteral("open_preferred_search_tool"));
1886 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1887 openPreferredSearchTool
->setWhatsThis(xi18nc("@info:whatsthis",
1888 "<para>This opens a preferred search tool for the viewed location.</para>"
1889 "<para>Use <emphasis>More Search Tools</emphasis> menu to configure it.</para>"));
1890 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1891 actionCollection()->setDefaultShortcut(openPreferredSearchTool
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F
);
1892 connect(openPreferredSearchTool
, &QAction::triggered
, this, &DolphinMainWindow::openPreferredSearchTool
);
1894 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1895 QAction
*openTerminal
= actionCollection()->addAction(QStringLiteral("open_terminal"));
1896 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1897 openTerminal
->setWhatsThis(xi18nc("@info:whatsthis",
1898 "<para>This opens a <emphasis>terminal</emphasis> application for the viewed location.</para>"
1899 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1900 openTerminal
->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
1901 actionCollection()->setDefaultShortcut(openTerminal
, Qt::SHIFT
| Qt::Key_F4
);
1902 connect(openTerminal
, &QAction::triggered
, this, &DolphinMainWindow::openTerminal
);
1904 QAction
*openTerminalHere
= actionCollection()->addAction(QStringLiteral("open_terminal_here"));
1905 // i18n: "Here" refers to the location(s) of the currently selected item(s) or the currently viewed location if nothing is selected.
1906 openTerminalHere
->setText(i18nc("@action:inmenu Tools", "Open Terminal Here"));
1907 openTerminalHere
->setWhatsThis(xi18nc("@info:whatsthis",
1908 "<para>This opens <emphasis>terminal</emphasis> applications for the selected items' locations.</para>"
1909 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1910 openTerminalHere
->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
1911 actionCollection()->setDefaultShortcut(openTerminalHere
, Qt::SHIFT
| Qt::ALT
| Qt::Key_F4
);
1912 connect(openTerminalHere
, &QAction::triggered
, this, &DolphinMainWindow::openTerminalHere
);
1915 QAction
*focusTerminalPanel
= actionCollection()->addAction(QStringLiteral("focus_terminal_panel"));
1916 focusTerminalPanel
->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
1917 focusTerminalPanel
->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
1918 actionCollection()->setDefaultShortcut(focusTerminalPanel
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F4
);
1919 connect(focusTerminalPanel
, &QAction::triggered
, this, &DolphinMainWindow::focusTerminalPanel
);
1923 // setup 'Bookmarks' menu
1924 KActionMenu
*bookmarkMenu
= new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this);
1925 bookmarkMenu
->setIcon(QIcon::fromTheme(QStringLiteral("bookmarks")));
1926 // Make the toolbar button version work properly on click
1927 bookmarkMenu
->setPopupMode(QToolButton::InstantPopup
);
1928 m_bookmarkHandler
= new DolphinBookmarkHandler(this, actionCollection(), bookmarkMenu
->menu(), this);
1929 actionCollection()->addAction(QStringLiteral("bookmarks"), bookmarkMenu
);
1931 // setup 'Settings' menu
1932 KToggleAction
*showMenuBar
= KStandardAction::showMenubar(nullptr, nullptr, actionCollection());
1933 showMenuBar
->setWhatsThis(xi18nc("@info:whatsthis",
1934 "<para>This switches between having a <emphasis>Menubar</emphasis> "
1935 "and having a <interface>%1</interface> button. Both "
1936 "contain mostly the same actions and configuration options.</para>"
1937 "<para>The Menubar takes up more space but allows for fast and organised access to all "
1938 "actions an application has to offer.</para><para>The <interface>%1</interface> button "
1939 "is simpler and small which makes triggering advanced actions more time consuming.</para>",
1940 hamburgerMenuAction
->text().replace('&', "")));
1941 connect(showMenuBar
,
1942 &KToggleAction::triggered
, // Fixes #286822
1944 &DolphinMainWindow::toggleShowMenuBar
,
1945 Qt::QueuedConnection
);
1947 KToggleAction
*showStatusBar
= KStandardAction::showStatusbar(nullptr, nullptr, actionCollection());
1948 showStatusBar
->setChecked(GeneralSettings::showStatusBar());
1949 connect(GeneralSettings::self(), &GeneralSettings::showStatusBarChanged
, showStatusBar
, &KToggleAction::setChecked
);
1950 connect(showStatusBar
, &KToggleAction::triggered
, this, [this](bool checked
) {
1951 GeneralSettings::setShowStatusBar(checked
);
1955 KStandardAction::keyBindings(this, &DolphinMainWindow::slotKeyBindings
, actionCollection());
1956 KStandardAction::preferences(this, &DolphinMainWindow::editSettings
, actionCollection());
1958 // not in menu actions
1959 QList
<QKeySequence
> nextTabKeys
= KStandardShortcut::tabNext();
1960 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
1962 QList
<QKeySequence
> prevTabKeys
= KStandardShortcut::tabPrev();
1963 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
1965 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1966 QAction
*activateTab
= actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i
));
1967 activateTab
->setText(i18nc("@action:inmenu", "Activate Tab %1", i
+ 1));
1968 activateTab
->setEnabled(false);
1969 connect(activateTab
, &QAction::triggered
, this, [this, i
]() {
1970 m_tabWidget
->activateTab(i
);
1973 // only add default shortcuts for the first 9 tabs regardless of MaxActivateTabShortcuts
1975 actionCollection()->setDefaultShortcut(activateTab
, QStringLiteral("Alt+%1").arg(i
+ 1));
1979 QAction
*activateLastTab
= actionCollection()->addAction(QStringLiteral("activate_last_tab"));
1980 activateLastTab
->setText(i18nc("@action:inmenu", "Activate Last Tab"));
1981 activateLastTab
->setEnabled(false);
1982 connect(activateLastTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateLastTab
);
1983 actionCollection()->setDefaultShortcut(activateLastTab
, Qt::ALT
| Qt::Key_0
);
1985 QAction
*activateNextTab
= actionCollection()->addAction(QStringLiteral("activate_next_tab"));
1986 activateNextTab
->setIconText(i18nc("@action:inmenu", "Next Tab"));
1987 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1988 activateNextTab
->setEnabled(false);
1989 connect(activateNextTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateNextTab
);
1990 actionCollection()->setDefaultShortcuts(activateNextTab
, nextTabKeys
);
1992 QAction
*activatePrevTab
= actionCollection()->addAction(QStringLiteral("activate_prev_tab"));
1993 activatePrevTab
->setIconText(i18nc("@action:inmenu", "Previous Tab"));
1994 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1995 activatePrevTab
->setEnabled(false);
1996 connect(activatePrevTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activatePrevTab
);
1997 actionCollection()->setDefaultShortcuts(activatePrevTab
, prevTabKeys
);
2000 QAction
*showTarget
= actionCollection()->addAction(QStringLiteral("show_target"));
2001 showTarget
->setText(i18nc("@action:inmenu", "Show Target"));
2002 showTarget
->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
2003 showTarget
->setEnabled(false);
2004 connect(showTarget
, &QAction::triggered
, this, &DolphinMainWindow::showTarget
);
2006 QAction
*openInNewTab
= actionCollection()->addAction(QStringLiteral("open_in_new_tab"));
2007 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
2008 openInNewTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
2009 connect(openInNewTab
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
2011 QAction
*openInNewTabs
= actionCollection()->addAction(QStringLiteral("open_in_new_tabs"));
2012 openInNewTabs
->setText(i18nc("@action:inmenu", "Open in New Tabs"));
2013 openInNewTabs
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
2014 connect(openInNewTabs
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
2016 QAction
*openInNewWindow
= actionCollection()->addAction(QStringLiteral("open_in_new_window"));
2017 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
2018 openInNewWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
2019 connect(openInNewWindow
, &QAction::triggered
, this, &DolphinMainWindow::openInNewWindow
);
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::errorMessage
, this, &DolphinMainWindow::showErrorMessage
);
2196 connect(this, &DolphinMainWindow::urlChanged
, m_placesPanel
, &PlacesPanel::setUrl
);
2197 connect(placesDock
, &DolphinDockWidget::visibilityChanged
, &DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged
);
2198 connect(this, &DolphinMainWindow::settingsChanged
, m_placesPanel
, &PlacesPanel::readSettings
);
2199 connect(m_placesPanel
, &PlacesPanel::storageTearDownRequested
, this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested
);
2200 connect(m_placesPanel
, &PlacesPanel::storageTearDownExternallyRequested
, this, &DolphinMainWindow::slotStorageTearDownExternallyRequested
);
2201 DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged(m_placesPanel
->isVisible());
2203 auto actionShowAllPlaces
= new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this);
2204 actionShowAllPlaces
->setCheckable(true);
2205 actionShowAllPlaces
->setDisabled(true);
2206 actionShowAllPlaces
->setWhatsThis(i18nc("@info:whatsthis",
2208 "all places in the places panel that have been hidden. They will "
2209 "appear semi-transparent unless you uncheck their hide property."));
2211 connect(actionShowAllPlaces
, &QAction::triggered
, this, [actionShowAllPlaces
, this](bool checked
) {
2212 m_placesPanel
->setShowAll(checked
);
2214 connect(m_placesPanel
, &PlacesPanel::allPlacesShownChanged
, actionShowAllPlaces
, &QAction::setChecked
);
2217 ->action(QStringLiteral("show_places_panel"))
2218 ->setWhatsThis(xi18nc("@info:whatsthis",
2219 "<para>This toggles the "
2220 "<emphasis>places</emphasis> panel at the left side of the window."
2221 "</para><para>It allows you to go to locations you have "
2222 "bookmarked and to access disk or media attached to the computer "
2223 "or to the network. It also contains sections to find recently "
2224 "saved files or files of a certain type.</para>"));
2225 placesDock
->setWhatsThis(xi18nc("@info:whatsthis",
2226 "<para>This is the "
2227 "<emphasis>Places</emphasis> panel. It allows you to go to locations "
2228 "you have bookmarked and to access disk or media attached to the "
2229 "computer or to the network. It also contains sections to find "
2230 "recently saved files or files of a certain type.</para><para>"
2231 "Click on an entry to go there. Click with the right mouse button "
2232 "instead to open any entry in a new tab or new window.</para>"
2233 "<para>New entries can be added by dragging folders onto this panel. "
2234 "Right-click any section or entry to hide it. Right-click an empty "
2235 "space on this panel and select <interface>Show Hidden Places"
2236 "</interface> to display it again.</para>")
2239 // Add actions into the "Panels" menu
2240 KActionMenu
*panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Show Panels"), this);
2241 actionCollection()->addAction(QStringLiteral("panels"), panelsMenu
);
2242 panelsMenu
->setIcon(QIcon::fromTheme(QStringLiteral("view-sidetree")));
2243 panelsMenu
->setPopupMode(QToolButton::InstantPopup
);
2244 const KActionCollection
*ac
= actionCollection();
2245 panelsMenu
->addAction(ac
->action(QStringLiteral("show_places_panel")));
2247 panelsMenu
->addAction(ac
->action(QStringLiteral("show_information_panel")));
2249 panelsMenu
->addAction(ac
->action(QStringLiteral("show_folders_panel")));
2250 panelsMenu
->addAction(ac
->action(QStringLiteral("show_terminal_panel")));
2251 panelsMenu
->addSeparator();
2252 panelsMenu
->addAction(actionShowAllPlaces
);
2253 panelsMenu
->addAction(lockLayoutAction
);
2255 connect(panelsMenu
->menu(), &QMenu::aboutToShow
, this, [actionShowAllPlaces
, this] {
2256 actionShowAllPlaces
->setEnabled(DolphinPlacesModelSingleton::instance().placesModel()->hiddenCount());
2260 void DolphinMainWindow::updateFileAndEditActions()
2262 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
2263 const KActionCollection
*col
= actionCollection();
2264 KFileItemListProperties
capabilitiesSource(list
);
2266 QAction
*renameAction
= col
->action(KStandardAction::name(KStandardAction::RenameFile
));
2267 QAction
*moveToTrashAction
= col
->action(KStandardAction::name(KStandardAction::MoveToTrash
));
2268 QAction
*deleteAction
= col
->action(KStandardAction::name(KStandardAction::DeleteFile
));
2269 QAction
*cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
2270 QAction
*duplicateAction
= col
->action(QStringLiteral("duplicate")); // see DolphinViewActionHandler
2271 QAction
*addToPlacesAction
= col
->action(QStringLiteral("add_to_places"));
2272 QAction
*copyToOtherViewAction
= col
->action(QStringLiteral("copy_to_inactive_split_view"));
2273 QAction
*moveToOtherViewAction
= col
->action(QStringLiteral("move_to_inactive_split_view"));
2274 QAction
*copyLocation
= col
->action(QString("copy_location"));
2276 if (list
.isEmpty()) {
2277 stateChanged(QStringLiteral("has_no_selection"));
2279 // All actions that need a selection to function can be enabled because they should trigger selection mode.
2280 renameAction
->setEnabled(true);
2281 moveToTrashAction
->setEnabled(true);
2282 deleteAction
->setEnabled(true);
2283 cutAction
->setEnabled(true);
2284 duplicateAction
->setEnabled(true);
2285 addToPlacesAction
->setEnabled(true);
2286 copyLocation
->setEnabled(true);
2287 // Them triggering selection mode and not directly acting on selected items is signified by adding "…" to their text.
2288 m_actionTextHelper
->textsWhenNothingIsSelectedEnabled(true);
2291 m_actionTextHelper
->textsWhenNothingIsSelectedEnabled(false);
2292 stateChanged(QStringLiteral("has_selection"));
2294 QAction
*deleteWithTrashShortcut
= col
->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
2295 QAction
*showTarget
= col
->action(QStringLiteral("show_target"));
2297 if (list
.length() == 1 && list
.first().isDir()) {
2298 addToPlacesAction
->setEnabled(true);
2300 addToPlacesAction
->setEnabled(false);
2303 const bool enableMoveToTrash
= capabilitiesSource
.isLocal() && capabilitiesSource
.supportsMoving();
2305 renameAction
->setEnabled(capabilitiesSource
.supportsMoving());
2306 moveToTrashAction
->setEnabled(enableMoveToTrash
);
2307 deleteAction
->setEnabled(capabilitiesSource
.supportsDeleting());
2308 deleteWithTrashShortcut
->setEnabled(capabilitiesSource
.supportsDeleting() && !enableMoveToTrash
);
2309 cutAction
->setEnabled(capabilitiesSource
.supportsMoving());
2310 copyLocation
->setEnabled(list
.length() == 1);
2311 showTarget
->setEnabled(list
.length() == 1 && list
.at(0).isLink());
2312 duplicateAction
->setEnabled(capabilitiesSource
.supportsWriting());
2315 if (m_tabWidget
->currentTabPage()->splitViewEnabled() && !list
.isEmpty()) {
2316 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
2317 KFileItem capabilitiesDestination
;
2319 if (tabPage
->primaryViewActive()) {
2320 capabilitiesDestination
= tabPage
->secondaryViewContainer()->rootItem();
2322 capabilitiesDestination
= tabPage
->primaryViewContainer()->rootItem();
2325 const auto destUrl
= capabilitiesDestination
.url();
2326 const bool allNotTargetOrigin
= std::all_of(list
.cbegin(), list
.cend(), [destUrl
](const KFileItem
&item
) {
2327 return item
.url().adjusted(QUrl::RemoveFilename
| QUrl::StripTrailingSlash
) != destUrl
;
2330 copyToOtherViewAction
->setEnabled(capabilitiesDestination
.isWritable() && allNotTargetOrigin
);
2331 moveToOtherViewAction
->setEnabled((list
.isEmpty() || capabilitiesSource
.supportsMoving()) && capabilitiesDestination
.isWritable()
2332 && allNotTargetOrigin
);
2334 copyToOtherViewAction
->setEnabled(false);
2335 moveToOtherViewAction
->setEnabled(false);
2339 void DolphinMainWindow::updateViewActions()
2341 m_actionHandler
->updateViewActions();
2343 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
2344 toggleFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
2346 updateSplitAction();
2349 void DolphinMainWindow::updateGoActions()
2351 QAction
*goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
2352 const QUrl currentUrl
= m_activeViewContainer
->url();
2353 // I think this is one of the best places to firstly be confronted
2354 // with a file system and its hierarchy. Talking about the root
2355 // directory might seem too much here but it is the question that
2356 // naturally arises in this context.
2357 goUpAction
->setWhatsThis(xi18nc("@info:whatsthis",
2359 "the folder that contains the currently viewed one.</para>"
2360 "<para>All files and folders are organized in a hierarchical "
2361 "<emphasis>file system</emphasis>. At the top of this hierarchy is "
2362 "a directory that contains all data connected to this computer"
2363 "—the <emphasis>root directory</emphasis>.</para>"));
2364 goUpAction
->setEnabled(KIO::upUrl(currentUrl
) != currentUrl
);
2367 void DolphinMainWindow::refreshViews()
2369 m_tabWidget
->refreshViews();
2371 if (GeneralSettings::modifiedStartupSettings()) {
2372 updateWindowTitle();
2375 updateSplitAction();
2377 Q_EMIT
settingsChanged();
2380 void DolphinMainWindow::clearStatusBar()
2382 m_activeViewContainer
->statusBar()->resetToDefaultText();
2385 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
*container
)
2387 connect(container
, &DolphinViewContainer::showFilterBarChanged
, this, &DolphinMainWindow::updateFilterBarAction
);
2388 connect(container
, &DolphinViewContainer::writeStateChanged
, this, &DolphinMainWindow::slotWriteStateChanged
);
2389 connect(container
, &DolphinViewContainer::searchModeEnabledChanged
, this, &DolphinMainWindow::updateSearchAction
);
2390 connect(container
, &DolphinViewContainer::captionChanged
, this, &DolphinMainWindow::updateWindowTitle
);
2391 connect(container
, &DolphinViewContainer::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2392 connect(container
, &DolphinViewContainer::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2394 const QAction
*toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
2395 connect(toggleSearchAction
, &QAction::triggered
, container
, &DolphinViewContainer::setSearchModeEnabled
);
2397 // Make the toggled state of the selection mode actions visually follow the selection mode state of the view.
2398 auto toggleSelectionModeAction
= actionCollection()->action(QStringLiteral("toggle_selection_mode"));
2399 toggleSelectionModeAction
->setChecked(m_activeViewContainer
->isSelectionModeEnabled());
2400 connect(m_activeViewContainer
, &DolphinViewContainer::selectionModeChanged
, toggleSelectionModeAction
, &QAction::setChecked
);
2402 const DolphinView
*view
= container
->view();
2403 connect(view
, &DolphinView::selectionChanged
, this, &DolphinMainWindow::slotSelectionChanged
);
2404 connect(view
, &DolphinView::requestItemInfo
, this, &DolphinMainWindow::requestItemInfo
);
2405 connect(view
, &DolphinView::fileItemsChanged
, this, &DolphinMainWindow::fileItemsChanged
);
2406 connect(view
, &DolphinView::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2407 connect(view
, &DolphinView::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2408 connect(view
, &DolphinView::windowRequested
, this, &DolphinMainWindow::openNewWindow
);
2409 connect(view
, &DolphinView::requestContextMenu
, this, &DolphinMainWindow::openContextMenu
);
2410 connect(view
, &DolphinView::directoryLoadingStarted
, this, &DolphinMainWindow::enableStopAction
);
2411 connect(view
, &DolphinView::directoryLoadingCompleted
, this, &DolphinMainWindow::disableStopAction
);
2412 connect(view
, &DolphinView::directoryLoadingCompleted
, this, &DolphinMainWindow::slotDirectoryLoadingCompleted
);
2413 connect(view
, &DolphinView::goBackRequested
, this, &DolphinMainWindow::goBack
);
2414 connect(view
, &DolphinView::goForwardRequested
, this, &DolphinMainWindow::goForward
);
2415 connect(view
, &DolphinView::urlActivated
, this, &DolphinMainWindow::handleUrl
);
2416 connect(view
, &DolphinView::goUpRequested
, this, &DolphinMainWindow::goUp
);
2418 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::urlChanged
, this, &DolphinMainWindow::changeUrl
);
2419 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::historyChanged
, this, &DolphinMainWindow::updateHistory
);
2421 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2422 const KUrlNavigator
*navigator
=
2423 m_tabWidget
->currentTabPage()->primaryViewActive() ? navigators
->primaryUrlNavigator() : navigators
->secondaryUrlNavigator();
2425 QAction
*editableLocactionAction
= actionCollection()->action(QStringLiteral("editable_location"));
2426 editableLocactionAction
->setChecked(navigator
->isUrlEditable());
2427 connect(navigator
, &KUrlNavigator::editableStateChanged
, this, &DolphinMainWindow::slotEditableStateChanged
);
2428 connect(navigator
, &KUrlNavigator::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2429 connect(navigator
, &KUrlNavigator::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2430 connect(navigator
, &KUrlNavigator::newWindowRequested
, this, &DolphinMainWindow::openNewWindow
);
2433 void DolphinMainWindow::updateSplitAction()
2435 QAction
*splitAction
= actionCollection()->action(QStringLiteral("split_view"));
2436 const DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
2437 if (tabPage
->splitViewEnabled()) {
2438 if (GeneralSettings::closeActiveSplitView() ? tabPage
->primaryViewActive() : !tabPage
->primaryViewActive()) {
2439 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2440 splitAction
->setToolTip(i18nc("@info", "Close left view"));
2441 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close")));
2443 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2444 splitAction
->setToolTip(i18nc("@info", "Close right view"));
2445 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close")));
2448 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2449 splitAction
->setToolTip(i18nc("@info", "Split view"));
2450 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
2454 void DolphinMainWindow::updateAllowedToolbarAreas()
2456 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2457 if (toolBar()->actions().contains(navigators
)) {
2458 toolBar()->setAllowedAreas(Qt::TopToolBarArea
| Qt::BottomToolBarArea
);
2459 if (toolBarArea(toolBar()) == Qt::LeftToolBarArea
|| toolBarArea(toolBar()) == Qt::RightToolBarArea
) {
2460 addToolBar(Qt::TopToolBarArea
, toolBar());
2463 toolBar()->setAllowedAreas(Qt::AllToolBarAreas
);
2467 bool DolphinMainWindow::isKompareInstalled() const
2469 static bool initialized
= false;
2470 static bool installed
= false;
2472 // TODO: maybe replace this approach later by using a menu
2473 // plugin like kdiff3plugin.cpp
2474 installed
= !QStandardPaths::findExecutable(QStringLiteral("kompare")).isEmpty();
2480 void DolphinMainWindow::createPanelAction(const QIcon
&icon
, const QKeySequence
&shortcut
, QAction
*dockAction
, const QString
&actionName
)
2482 QAction
*panelAction
= actionCollection()->addAction(actionName
);
2483 panelAction
->setCheckable(true);
2484 panelAction
->setChecked(dockAction
->isChecked());
2485 panelAction
->setText(dockAction
->text());
2486 panelAction
->setIcon(icon
);
2487 dockAction
->setIcon(icon
);
2488 actionCollection()->setDefaultShortcut(panelAction
, shortcut
);
2490 connect(panelAction
, &QAction::triggered
, dockAction
, &QAction::trigger
);
2491 connect(dockAction
, &QAction::toggled
, panelAction
, &QAction::setChecked
);
2494 void DolphinMainWindow::setupWhatsThis()
2497 menuBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2498 "<emphasis>Menubar</emphasis>. It provides access to commands and "
2499 "configuration options. Left-click on any of the menus on this "
2500 "bar to see its contents.</para><para>The Menubar can be hidden "
2501 "by unchecking <interface>Settings|Show Menubar</interface>. Then "
2502 "most of its contents become available through a <interface>Menu"
2503 "</interface> button on the <emphasis>Toolbar</emphasis>.</para>"));
2504 toolBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2505 "<emphasis>Toolbar</emphasis>. It allows quick access to "
2506 "frequently used actions.</para><para>It is highly customizable. "
2507 "All items you see in the <interface>Menu</interface> or "
2508 "in the <interface>Menubar</interface> can be placed on the "
2509 "Toolbar. Just right-click on it and select <interface>Configure "
2510 "Toolbars…</interface> or find this action within the <interface>"
2512 "</para><para>The location of the bar and the style of its "
2513 "buttons can also be changed in the right-click menu. Right-click "
2514 "a button if you want to show or hide its text.</para>"));
2515 m_tabWidget
->setWhatsThis(xi18nc("@info:whatsthis main view",
2516 "<para>Here you can see the <emphasis>folders</emphasis> and "
2517 "<emphasis>files</emphasis> that are at the location described in "
2518 "the <interface>Location Bar</interface> above. This area is the "
2519 "central part of this application where you navigate to the files "
2520 "you want to use.</para><para>For an elaborate and general "
2521 "introduction to this application <link "
2522 "url='https://userbase.kde.org/Dolphin/File_Management#Introduction_to_Dolphin'>"
2523 "click here</link>. This will open an introductory article from "
2524 "the <emphasis>KDE UserBase Wiki</emphasis>.</para><para>For brief "
2525 "explanations of all the features of this <emphasis>view</emphasis> "
2526 "<link url='help:/dolphin/dolphin-view.html'>click here</link> "
2527 "instead. This will open a page from the <emphasis>Handbook"
2528 "</emphasis> that covers the basics.</para>"));
2531 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings
))
2532 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window "
2533 "that lists the <emphasis>keyboard shortcuts</emphasis>.<nl/>"
2534 "There you can set up key combinations to trigger an action when "
2535 "they are pressed simultaneously. All commands in this application can "
2536 "be triggered this way.</para>"));
2537 actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars
))
2538 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window in which "
2539 "you can change which buttons appear on the <emphasis>Toolbar</emphasis>.</para>"
2540 "<para>All items you see in the <interface>Menu</interface> can also be placed on the Toolbar.</para>"));
2541 actionCollection()->action(KStandardAction::name(KStandardAction::Preferences
))
2542 ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window where you can "
2543 "change a multitude of settings for this application. For an explanation "
2544 "of the various settings go to the chapter <emphasis>Configuring Dolphin"
2545 "</emphasis> in <interface>Help|Dolphin Handbook</interface>."));
2549 auto setStandardActionWhatsThis
= [this](KStandardAction::StandardAction actionId
,
2550 const QString
&whatsThis
) {
2551 // Check for the existence of an action since it can be restricted through the Kiosk system
2552 if (auto *action
= actionCollection()->action(KStandardAction::name(actionId
))) {
2553 action
->setWhatsThis(whatsThis
);
2557 // i18n: If the external link isn't available in your language it might make
2558 // sense to state the external link's language in brackets to not
2559 // frustrate the user. If there are multiple languages that the user might
2560 // know with a reasonable chance you might want to have 2 external links.
2561 // The same might be true for any external link you translate.
2562 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>"));
2563 // (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 )
2565 setStandardActionWhatsThis(KStandardAction::WhatsThis
,
2566 xi18nc("@info:whatsthis whatsthis button",
2567 "<para>This is the button that invokes the help feature you are "
2568 "using right now! Click it, then click any component of this "
2569 "application to ask \"What's this?\" about it. The mouse cursor "
2570 "will change appearance if no help is available for a spot.</para>"
2571 "<para>There are two other ways to get help: "
2572 "The <link url='help:/dolphin/index.html'>Dolphin Handbook</link> and "
2573 "the <link url='https://userbase.kde.org/Dolphin/File_Management'>KDE "
2574 "UserBase Wiki</link>.</para><para>The \"What's this?\" help is "
2575 "missing in most other windows so don't get too used to this.</para>"));
2577 setStandardActionWhatsThis(KStandardAction::ReportBug
,
2578 xi18nc("@info:whatsthis","<para>This opens a "
2579 "window that will guide you through reporting errors or flaws "
2580 "in this application or in other KDE software.</para>"
2581 "<para>High-quality bug reports are much appreciated. To learn "
2582 "how to make your bug report as effective as possible "
2583 "<link url='https://community.kde.org/Get_Involved/Bug_Reporting'>"
2584 "click here</link>.</para>"));
2586 setStandardActionWhatsThis(KStandardAction::Donate
,
2587 xi18nc("@info:whatsthis", "<para>This opens a "
2588 "<emphasis>web page</emphasis> where you can donate to "
2589 "support the continued work on this application and many "
2590 "other projects by the <emphasis>KDE</emphasis> community.</para>"
2591 "<para>Donating is the easiest and fastest way to efficiently "
2592 "support KDE and its projects. KDE projects are available for "
2593 "free therefore your donation is needed to cover things that "
2594 "require money like servers, contributor meetings, etc.</para>"
2595 "<para><emphasis>KDE e.V.</emphasis> is the non-profit "
2596 "organization behind the KDE community.</para>"));
2598 setStandardActionWhatsThis(KStandardAction::SwitchApplicationLanguage
,
2599 xi18nc("@info:whatsthis",
2600 "With this you can change the language this application uses."
2601 "<nl/>You can even set secondary languages which will be used "
2602 "if texts are not available in your preferred language."));
2604 setStandardActionWhatsThis(KStandardAction::AboutApp
,
2605 xi18nc("@info:whatsthis","This opens a "
2606 "window that informs you about the version, license, "
2607 "used libraries and maintainers of this application."));
2609 setStandardActionWhatsThis(KStandardAction::AboutKDE
,
2610 xi18nc("@info:whatsthis","This opens a "
2611 "window with information about <emphasis>KDE</emphasis>. "
2612 "The KDE community are the people behind this free software."
2613 "<nl/>If you like using this application but don't know "
2614 "about KDE or want to see a cute dragon have a look!"));
2618 bool DolphinMainWindow::addHamburgerMenuToToolbar()
2620 QDomDocument domDocument
= KXMLGUIClient::domDocument();
2621 if (domDocument
.isNull()) {
2624 QDomNode toolbar
= domDocument
.elementsByTagName(QStringLiteral("ToolBar")).at(0);
2625 if (toolbar
.isNull()) {
2629 QDomElement hamburgerMenuElement
= domDocument
.createElement(QStringLiteral("Action"));
2630 hamburgerMenuElement
.setAttribute(QStringLiteral("name"), QStringLiteral("hamburger_menu"));
2631 toolbar
.appendChild(hamburgerMenuElement
);
2633 KXMLGUIFactory::saveConfigFile(domDocument
, xmlFile());
2637 // Make sure to also remove the <KXMLGUIFactory> and <QDomDocument> include
2638 // whenever this method is removed (maybe in the year ~2026).
2641 // Set a sane initial window size
2642 QSize
DolphinMainWindow::sizeHint() const
2644 return KXmlGuiWindow::sizeHint().expandedTo(QSize(760, 550));
2647 void DolphinMainWindow::saveNewToolbarConfig()
2649 KXmlGuiWindow::saveNewToolbarConfig(); // Applies the new config. This has to be called first
2650 // because the rest of this method decides things
2651 // based on the new config.
2652 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2653 if (!toolBar()->actions().contains(navigators
)) {
2654 m_tabWidget
->currentTabPage()->insertNavigatorsWidget(navigators
);
2656 updateAllowedToolbarAreas();
2657 (static_cast<KHamburgerMenu
*>(actionCollection()->action(KStandardAction::name(KStandardAction::HamburgerMenu
))))->hideActionsOf(toolBar());
2660 void DolphinMainWindow::focusTerminalPanel()
2662 if (m_terminalPanel
->isVisible()) {
2663 if (m_terminalPanel
->terminalHasFocus()) {
2664 m_activeViewContainer
->view()->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2665 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2667 m_terminalPanel
->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2668 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2671 actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger();
2672 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2676 DolphinMainWindow::UndoUiInterface::UndoUiInterface()
2677 : KIO::FileUndoManager::UiInterface()
2681 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2685 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
*job
)
2687 DolphinMainWindow
*mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2689 DolphinViewContainer
*container
= mainWin
->activeViewContainer();
2690 container
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
2692 KIO::FileUndoManager::UiInterface::jobError(job
);
2696 bool DolphinMainWindow::isUrlOpen(const QString
&url
)
2698 return m_tabWidget
->isUrlOpen(QUrl::fromUserInput(url
));
2701 bool DolphinMainWindow::isItemVisibleInAnyView(const QString
&urlOfItem
)
2703 return m_tabWidget
->isItemVisibleInAnyView(QUrl::fromUserInput(urlOfItem
));