2 * SPDX-FileCopyrightText: 2006 Peter Penz <peter.penz19@gmail.com>
3 * SPDX-FileCopyrightText: 2006 Stefan Monov <logixoul@gmail.com>
4 * SPDX-FileCopyrightText: 2006 Cvetoslav Ludmiloff <ludmiloff@gmail.com>
6 * SPDX-License-Identifier: GPL-2.0-or-later
9 #include "dolphinmainwindow.h"
11 #include "dolphin_generalsettings.h"
12 #include "dolphinbookmarkhandler.h"
13 #include "dolphincontextmenu.h"
14 #include "dolphindockwidget.h"
15 #include "dolphinmainwindowadaptor.h"
16 #include "dolphinnavigatorswidgetaction.h"
17 #include "dolphinnewfilemenu.h"
18 #include "dolphinplacesmodelsingleton.h"
19 #include "dolphinrecenttabsmenu.h"
20 #include "dolphintabpage.h"
21 #include "dolphinurlnavigatorscontroller.h"
22 #include "dolphinviewcontainer.h"
24 #include "middleclickactioneventfilter.h"
25 #include "panels/folders/folderspanel.h"
26 #include "panels/places/placespanel.h"
27 #include "panels/terminal/terminalpanel.h"
28 #include "selectionmode/actiontexthelper.h"
29 #include "settings/dolphinsettingsdialog.h"
30 #include "statusbar/dolphinstatusbar.h"
31 #include "views/dolphinnewfilemenuobserver.h"
32 #include "views/dolphinremoteencoding.h"
33 #include "views/dolphinviewactionhandler.h"
34 #include "views/draganddrophelper.h"
35 #include "views/viewproperties.h"
37 #include <KActionCollection>
38 #include <KActionMenu>
39 #include <KAuthorized>
42 #include <KDualAction>
43 #include <KFileItemListProperties>
44 #include <KIO/CommandLauncherJob>
45 #include <kio_version.h>
46 #if KIO_VERSION >= QT_VERSION_CHECK(5, 98, 0)
47 #include <KIO/JobUiDelegateFactory>
49 #include <KIO/JobUiDelegate>
51 #include <KIO/OpenFileManagerWindowJob>
52 #include <KIO/OpenUrlJob>
53 #include <KJobWidgets>
54 #include <KLocalizedString>
55 #include <KMessageBox>
56 #include <KMoreToolsMenuFactory>
57 #include <KProtocolInfo>
58 #include <KProtocolManager>
60 #include <KShortcutsDialog>
61 #include <KStandardAction>
62 #include <KStartupInfo>
64 #include <KTerminalLauncherJob>
65 #include <KToggleAction>
67 #include <KToolBarPopupAction>
68 #include <KUrlComboBox>
69 #include <KUrlNavigator>
70 #include <KWindowSystem>
71 #include <KXMLGUIFactory>
73 #include <kio_version.h>
74 #include <kwidgetsaddons_version.h>
76 #include <QApplication>
78 #include <QCloseEvent>
79 #include <QDesktopServices>
81 #include <QDomDocument>
85 #include <QPushButton>
87 #include <QStandardPaths>
89 #include <QToolButton>
93 // Used for GeneralSettings::version() to determine whether
94 // an updated version of Dolphin is running, so as to migrate
95 // removed/renamed ...etc config entries; increment it in such
97 const int CurrentDolphinVersion
= 202;
98 // The maximum number of entries in the back/forward popup menu
99 const int MaxNumberOfNavigationentries
= 12;
100 // The maximum number of "Activate Tab" shortcuts
101 const int MaxActivateTabShortcuts
= 9;
104 DolphinMainWindow::DolphinMainWindow()
105 : KXmlGuiWindow(nullptr)
106 , m_newFileMenu(nullptr)
107 , m_tabWidget(nullptr)
108 , m_activeViewContainer(nullptr)
109 , m_actionHandler(nullptr)
110 , m_remoteEncoding(nullptr)
112 , m_bookmarkHandler(nullptr)
113 , m_lastHandleUrlOpenJob(nullptr)
114 , m_terminalPanel(nullptr)
115 , m_placesPanel(nullptr)
116 , m_tearDownFromPlacesRequested(false)
117 , m_backAction(nullptr)
118 , m_forwardAction(nullptr)
120 Q_INIT_RESOURCE(dolphin
);
122 new MainWindowAdaptor(this);
125 setWindowFlags(Qt::WindowContextHelpButtonHint
);
127 setComponentName(QStringLiteral("dolphin"), QGuiApplication::applicationDisplayName());
128 setObjectName(QStringLiteral("Dolphin#"));
130 setStateConfigGroup("State");
132 connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::errorMessage
, this, &DolphinMainWindow::showErrorMessage
);
134 KIO::FileUndoManager
*undoManager
= KIO::FileUndoManager::self();
135 undoManager
->setUiInterface(new UndoUiInterface());
137 connect(undoManager
, &KIO::FileUndoManager::undoAvailable
, this, &DolphinMainWindow::slotUndoAvailable
);
138 connect(undoManager
, &KIO::FileUndoManager::undoTextChanged
, this, &DolphinMainWindow::slotUndoTextChanged
);
139 connect(undoManager
, &KIO::FileUndoManager::jobRecordingStarted
, this, &DolphinMainWindow::clearStatusBar
);
140 connect(undoManager
, &KIO::FileUndoManager::jobRecordingFinished
, this, &DolphinMainWindow::showCommand
);
142 const bool firstRun
= (GeneralSettings::version() < 200);
144 GeneralSettings::setViewPropsTimestamp(QDateTime::currentDateTime());
147 setAcceptDrops(true);
149 auto *navigatorsWidgetAction
= new DolphinNavigatorsWidgetAction(this);
150 actionCollection()->addAction(QStringLiteral("url_navigators"), navigatorsWidgetAction
);
151 m_tabWidget
= new DolphinTabWidget(navigatorsWidgetAction
, this);
152 m_tabWidget
->setObjectName("tabWidget");
153 connect(m_tabWidget
, &DolphinTabWidget::activeViewChanged
, this, &DolphinMainWindow::activeViewChanged
);
154 connect(m_tabWidget
, &DolphinTabWidget::tabCountChanged
, this, &DolphinMainWindow::tabCountChanged
);
155 connect(m_tabWidget
, &DolphinTabWidget::currentUrlChanged
, this, &DolphinMainWindow::updateWindowTitle
);
156 setCentralWidget(m_tabWidget
);
158 m_actionTextHelper
= new SelectionMode::ActionTextHelper(this);
161 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), m_actionTextHelper
, this);
162 connect(m_actionHandler
, &DolphinViewActionHandler::actionBeingHandled
, this, &DolphinMainWindow::clearStatusBar
);
163 connect(m_actionHandler
, &DolphinViewActionHandler::createDirectoryTriggered
, this, &DolphinMainWindow::createDirectory
);
164 connect(m_actionHandler
, &DolphinViewActionHandler::selectionModeChangeTriggered
, this, &DolphinMainWindow::slotSetSelectionMode
);
166 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
167 connect(this, &DolphinMainWindow::urlChanged
, m_remoteEncoding
, &DolphinRemoteEncoding::slotAboutToOpenUrl
);
171 setupGUI(Save
| Create
| ToolBar
);
172 stateChanged(QStringLiteral("new_file"));
174 QClipboard
*clipboard
= QApplication::clipboard();
175 connect(clipboard
, &QClipboard::dataChanged
, this, &DolphinMainWindow::updatePasteAction
);
177 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
178 toggleFilterBarAction
->setChecked(GeneralSettings::filterBar());
181 menuBar()->setVisible(false);
184 const bool showMenu
= !menuBar()->isHidden();
185 QAction
*showMenuBarAction
= actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar
));
186 showMenuBarAction
->setChecked(showMenu
); // workaround for bug #171080
188 auto hamburgerMenu
= static_cast<KHamburgerMenu
*>(actionCollection()->action(KStandardAction::name(KStandardAction::HamburgerMenu
)));
189 hamburgerMenu
->setMenuBar(menuBar());
190 hamburgerMenu
->setShowMenuBarAction(showMenuBarAction
);
191 connect(hamburgerMenu
, &KHamburgerMenu::aboutToShowMenu
, this, &DolphinMainWindow::updateHamburgerMenu
);
192 hamburgerMenu
->hideActionsOf(toolBar());
193 if (GeneralSettings::version() < 201 && !toolBar()->actions().contains(hamburgerMenu
)) {
194 addHamburgerMenuToToolbar();
197 updateAllowedToolbarAreas();
199 // enable middle-click on back/forward/up to open in a new tab
200 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
201 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotToolBarActionMiddleClicked
);
202 toolBar()->installEventFilter(middleClickEventFilter
);
206 connect(KSycoca::self(), &KSycoca::databaseChanged
, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
208 QTimer::singleShot(0, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
210 m_fileItemActions
.setParentWidget(this);
211 connect(&m_fileItemActions
, &KFileItemActions::error
, this, [this](const QString
&errorMessage
) {
212 showErrorMessage(errorMessage
);
215 connect(GeneralSettings::self(), &GeneralSettings::splitViewChanged
, this, &DolphinMainWindow::slotSplitViewChanged
);
218 DolphinMainWindow::~DolphinMainWindow()
220 // This fixes a crash on Wayland when closing the mainwindow while another dialog is open.
221 disconnect(QGuiApplication::clipboard(), &QClipboard::dataChanged
, this, &DolphinMainWindow::updatePasteAction
);
224 QVector
<DolphinViewContainer
*> DolphinMainWindow::viewContainers() const
226 QVector
<DolphinViewContainer
*> viewContainers
;
228 for (int i
= 0; i
< m_tabWidget
->count(); ++i
) {
229 DolphinTabPage
*tabPage
= m_tabWidget
->tabPageAt(i
);
231 viewContainers
<< tabPage
->primaryViewContainer();
232 if (tabPage
->splitViewEnabled()) {
233 viewContainers
<< tabPage
->secondaryViewContainer();
236 return viewContainers
;
239 void DolphinMainWindow::openDirectories(const QList
<QUrl
> &dirs
, bool splitView
)
241 m_tabWidget
->openDirectories(dirs
, splitView
);
244 void DolphinMainWindow::openDirectories(const QStringList
&dirs
, bool splitView
)
246 openDirectories(QUrl::fromStringList(dirs
), splitView
);
249 void DolphinMainWindow::openFiles(const QList
<QUrl
> &files
, bool splitView
)
251 m_tabWidget
->openFiles(files
, splitView
);
254 bool DolphinMainWindow::isFoldersPanelEnabled() const
256 return actionCollection()->action(QStringLiteral("show_folders_panel"))->isChecked();
259 bool DolphinMainWindow::isInformationPanelEnabled() const
262 return actionCollection()->action(QStringLiteral("show_information_panel"))->isChecked();
268 void DolphinMainWindow::openFiles(const QStringList
&files
, bool splitView
)
270 openFiles(QUrl::fromStringList(files
), splitView
);
273 void DolphinMainWindow::activateWindow(const QString
&activationToken
)
275 window()->setAttribute(Qt::WA_NativeWindow
, true);
277 if (KWindowSystem::isPlatformWayland()) {
278 KWindowSystem::setCurrentXdgActivationToken(activationToken
);
280 KStartupInfo::setNewStartupId(window()->windowHandle(), activationToken
.toUtf8());
283 KWindowSystem::activateWindow(window()->windowHandle());
286 bool DolphinMainWindow::isActiveWindow()
288 return window()->isActiveWindow();
291 void DolphinMainWindow::showCommand(CommandType command
)
293 DolphinStatusBar
*statusBar
= m_activeViewContainer
->statusBar();
295 case KIO::FileUndoManager::Copy
:
296 statusBar
->setText(i18nc("@info:status", "Successfully copied."));
298 case KIO::FileUndoManager::Move
:
299 statusBar
->setText(i18nc("@info:status", "Successfully moved."));
301 case KIO::FileUndoManager::Link
:
302 statusBar
->setText(i18nc("@info:status", "Successfully linked."));
304 case KIO::FileUndoManager::Trash
:
305 statusBar
->setText(i18nc("@info:status", "Successfully moved to trash."));
307 case KIO::FileUndoManager::Rename
:
308 statusBar
->setText(i18nc("@info:status", "Successfully renamed."));
311 case KIO::FileUndoManager::Mkdir
:
312 statusBar
->setText(i18nc("@info:status", "Created folder."));
320 void DolphinMainWindow::pasteIntoFolder()
322 m_activeViewContainer
->view()->pasteIntoFolder();
325 void DolphinMainWindow::changeUrl(const QUrl
&url
)
327 if (!KProtocolManager::supportsListing(url
)) {
328 // The URL navigator only checks for validity, not
329 // if the URL can be listed. An error message is
330 // shown due to DolphinViewContainer::restoreView().
334 m_activeViewContainer
->setUrl(url
);
335 updateFileAndEditActions();
340 Q_EMIT
urlChanged(url
);
343 void DolphinMainWindow::slotTerminalDirectoryChanged(const QUrl
&url
)
345 if (m_tearDownFromPlacesRequested
&& url
== QUrl::fromLocalFile(QDir::homePath())) {
346 m_placesPanel
->proceedWithTearDown();
347 m_tearDownFromPlacesRequested
= false;
350 m_activeViewContainer
->setAutoGrabFocus(false);
352 m_activeViewContainer
->setAutoGrabFocus(true);
355 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
357 KToggleAction
*editableLocationAction
= static_cast<KToggleAction
*>(actionCollection()->action(QStringLiteral("editable_location")));
358 editableLocationAction
->setChecked(editable
);
361 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
&selection
)
363 updateFileAndEditActions();
365 const int selectedUrlsCount
= m_tabWidget
->currentTabPage()->selectedItemsCount();
367 QAction
*compareFilesAction
= actionCollection()->action(QStringLiteral("compare_files"));
368 if (selectedUrlsCount
== 2) {
369 compareFilesAction
->setEnabled(isKompareInstalled());
371 compareFilesAction
->setEnabled(false);
374 Q_EMIT
selectionChanged(selection
);
377 void DolphinMainWindow::updateHistory()
379 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
380 const int index
= urlNavigator
->historyIndex();
382 QAction
*backAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Back
));
384 backAction
->setToolTip(i18nc("@info", "Go back"));
385 backAction
->setWhatsThis(i18nc("@info:whatsthis go back", "Return to the previously viewed folder."));
386 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
389 QAction
*forwardAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Forward
));
391 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
392 forwardAction
->setWhatsThis(xi18nc("@info:whatsthis go forward", "This undoes a <interface>Go|Back</interface> action."));
393 forwardAction
->setEnabled(index
> 0);
397 void DolphinMainWindow::updateFilterBarAction(bool show
)
399 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
400 toggleFilterBarAction
->setChecked(show
);
403 void DolphinMainWindow::openNewMainWindow()
405 Dolphin::openNewWindow({m_activeViewContainer
->url()}, this);
408 void DolphinMainWindow::openNewActivatedTab()
410 // keep browsers compatibility, new tab is always after last one
411 auto openNewTabAfterLastTabConfigured
= GeneralSettings::openNewTabAfterLastTab();
412 GeneralSettings::setOpenNewTabAfterLastTab(true);
413 m_tabWidget
->openNewActivatedTab();
414 GeneralSettings::setOpenNewTabAfterLastTab(openNewTabAfterLastTabConfigured
);
417 void DolphinMainWindow::addToPlaces()
422 // If nothing is selected, act on the current dir
423 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
424 url
= m_activeViewContainer
->url();
425 name
= m_activeViewContainer
->placesText();
427 const auto dirToAdd
= m_activeViewContainer
->view()->selectedItems().first();
428 url
= dirToAdd
.url();
429 name
= dirToAdd
.name();
433 if (m_activeViewContainer
->isSearchModeEnabled()) {
434 icon
= QStringLiteral("folder-saved-search-symbolic");
436 icon
= KIO::iconNameForUrl(url
);
438 DolphinPlacesModelSingleton::instance().placesModel()->addPlace(name
, url
, icon
);
442 void DolphinMainWindow::openNewTab(const QUrl
&url
)
444 m_tabWidget
->openNewTab(url
, QUrl());
447 void DolphinMainWindow::openNewTabAndActivate(const QUrl
&url
)
449 m_tabWidget
->openNewActivatedTab(url
, QUrl());
452 void DolphinMainWindow::openNewWindow(const QUrl
&url
)
454 Dolphin::openNewWindow({url
}, this);
457 void DolphinMainWindow::slotSplitViewChanged()
459 m_tabWidget
->currentTabPage()->setSplitViewEnabled(GeneralSettings::splitView(), WithAnimation
);
463 void DolphinMainWindow::openInNewTab()
465 const KFileItemList
&list
= m_activeViewContainer
->view()->selectedItems();
466 bool tabCreated
= false;
468 for (const KFileItem
&item
: list
) {
469 const QUrl
&url
= DolphinView::openItemAsFolderUrl(item
);
470 if (!url
.isEmpty()) {
476 // if no new tab has been created from the selection
477 // open the current directory in a new tab
479 openNewTab(m_activeViewContainer
->url());
483 void DolphinMainWindow::openInNewWindow()
487 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
488 if (list
.isEmpty()) {
489 newWindowUrl
= m_activeViewContainer
->url();
490 } else if (list
.count() == 1) {
491 const KFileItem
&item
= list
.first();
492 newWindowUrl
= DolphinView::openItemAsFolderUrl(item
);
495 if (!newWindowUrl
.isEmpty()) {
496 Dolphin::openNewWindow({newWindowUrl
}, this);
500 void DolphinMainWindow::showTarget()
502 const auto link
= m_activeViewContainer
->view()->selectedItems().at(0);
503 const auto linkLocationDir
= QFileInfo(link
.localPath()).absoluteDir();
504 auto linkDestination
= link
.linkDest();
505 if (QFileInfo(linkDestination
).isRelative()) {
506 linkDestination
= linkLocationDir
.filePath(linkDestination
);
508 if (QFileInfo::exists(linkDestination
)) {
509 KIO::highlightInFileManager({QUrl::fromLocalFile(linkDestination
).adjusted(QUrl::StripTrailingSlash
)});
511 m_activeViewContainer
->showMessage(xi18nc("@info", "Could not access <filename>%1</filename>.", linkDestination
), DolphinViewContainer::Warning
);
515 void DolphinMainWindow::showEvent(QShowEvent
*event
)
517 KXmlGuiWindow::showEvent(event
);
519 if (!event
->spontaneous()) {
520 m_activeViewContainer
->view()->setFocus();
524 void DolphinMainWindow::closeEvent(QCloseEvent
*event
)
526 // Find out if Dolphin is closed directly by the user or
527 // by the session manager because the session is closed
528 bool closedByUser
= true;
529 if (qApp
->isSavingSession()) {
530 closedByUser
= false;
533 if (m_tabWidget
->count() > 1 && GeneralSettings::confirmClosingMultipleTabs() && !GeneralSettings::rememberOpenedTabs() && closedByUser
) {
534 // Ask the user if he really wants to quit and close all tabs.
535 // Open a confirmation dialog with 3 buttons:
536 // QDialogButtonBox::Yes -> Quit
537 // QDialogButtonBox::No -> Close only the current tab
538 // QDialogButtonBox::Cancel -> do nothing
539 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
540 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
541 dialog
->setModal(true);
542 QDialogButtonBox
*buttons
= new QDialogButtonBox(QDialogButtonBox::Yes
| QDialogButtonBox::No
| QDialogButtonBox::Cancel
);
543 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
),
544 KGuiItem(i18nc("@action:button 'Quit Dolphin' button", "&Quit %1", QGuiApplication::applicationDisplayName()),
545 QIcon::fromTheme(QStringLiteral("application-exit"))));
546 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("C&lose Current Tab"), QIcon::fromTheme(QStringLiteral("tab-close"))));
547 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
548 buttons
->button(QDialogButtonBox::Yes
)->setDefault(true);
550 bool doNotAskAgainCheckboxResult
= false;
552 const auto result
= KMessageBox::createKMessageBox(dialog
,
554 QMessageBox::Warning
,
555 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
557 i18n("Do not ask again"),
558 &doNotAskAgainCheckboxResult
,
559 KMessageBox::Notify
);
561 if (doNotAskAgainCheckboxResult
) {
562 GeneralSettings::setConfirmClosingMultipleTabs(false);
566 case QDialogButtonBox::Yes
:
569 case QDialogButtonBox::No
:
570 // Close only the current tab
571 m_tabWidget
->closeTab();
579 if (m_terminalPanel
&& m_terminalPanel
->hasProgramRunning() && GeneralSettings::confirmClosingTerminalRunningProgram() && closedByUser
) {
580 // Ask if the user really wants to quit Dolphin with a program that is still running in the Terminal panel
581 // Open a confirmation dialog with 3 buttons:
582 // QDialogButtonBox::Yes -> Quit
583 // QDialogButtonBox::No -> Show Terminal Panel
584 // QDialogButtonBox::Cancel -> do nothing
585 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
586 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
587 dialog
->setModal(true);
588 auto standardButtons
= QDialogButtonBox::Yes
| QDialogButtonBox::Cancel
;
589 if (!m_terminalPanel
->isVisible()) {
590 standardButtons
|= QDialogButtonBox::No
;
592 QDialogButtonBox
*buttons
= new QDialogButtonBox(standardButtons
);
593 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KStandardGuiItem::quit());
594 if (!m_terminalPanel
->isVisible()) {
595 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("Show &Terminal Panel"), QIcon::fromTheme(QStringLiteral("dialog-scripts"))));
597 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
599 bool doNotAskAgainCheckboxResult
= false;
601 const auto result
= KMessageBox::createKMessageBox(
604 QMessageBox::Warning
,
605 i18n("The program '%1' is still running in the Terminal panel. Are you sure you want to quit?", m_terminalPanel
->runningProgramName()),
607 i18n("Do not ask again"),
608 &doNotAskAgainCheckboxResult
,
609 KMessageBox::Dangerous
);
611 if (doNotAskAgainCheckboxResult
) {
612 GeneralSettings::setConfirmClosingTerminalRunningProgram(false);
616 case QDialogButtonBox::Yes
:
619 case QDialogButtonBox::No
:
620 actionCollection()->action("show_terminal_panel")->trigger();
621 // Do not quit, ignore quit event
629 if (GeneralSettings::rememberOpenedTabs()) {
630 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
631 KConfig
*config
= KConfigGui::sessionConfig();
632 saveGlobalProperties(config
);
633 savePropertiesInternal(config
, 1);
637 GeneralSettings::setVersion(CurrentDolphinVersion
);
638 GeneralSettings::self()->save();
640 KXmlGuiWindow::closeEvent(event
);
643 void DolphinMainWindow::saveProperties(KConfigGroup
&group
)
645 m_tabWidget
->saveProperties(group
);
648 void DolphinMainWindow::readProperties(const KConfigGroup
&group
)
650 m_tabWidget
->readProperties(group
);
653 void DolphinMainWindow::updateNewMenu()
655 m_newFileMenu
->checkUpToDate();
656 #if KIO_VERSION >= QT_VERSION_CHECK(5, 97, 0)
657 m_newFileMenu
->setWorkingDirectory(activeViewContainer()->url());
659 m_newFileMenu
->setPopupFiles(QList
<QUrl
>() << activeViewContainer()->url());
663 void DolphinMainWindow::createDirectory()
665 #if KIO_VERSION >= QT_VERSION_CHECK(5, 97, 0)
666 m_newFileMenu
->setWorkingDirectory(activeViewContainer()->url());
668 m_newFileMenu
->setPopupFiles(QList
<QUrl
>() << activeViewContainer()->url());
670 m_newFileMenu
->createDirectory();
673 void DolphinMainWindow::quit()
678 void DolphinMainWindow::showErrorMessage(const QString
&message
)
680 m_activeViewContainer
->showMessage(message
, DolphinViewContainer::Error
);
683 void DolphinMainWindow::slotUndoAvailable(bool available
)
685 QAction
*undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
687 undoAction
->setEnabled(available
);
691 void DolphinMainWindow::slotUndoTextChanged(const QString
&text
)
693 QAction
*undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
695 undoAction
->setText(text
);
699 void DolphinMainWindow::undo()
702 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
703 KIO::FileUndoManager::self()->undo();
706 void DolphinMainWindow::cut()
708 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
709 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CutContents
);
711 m_activeViewContainer
->view()->cutSelectedItemsToClipboard();
712 m_activeViewContainer
->setSelectionModeEnabled(false);
716 void DolphinMainWindow::copy()
718 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
719 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CopyContents
);
721 m_activeViewContainer
->view()->copySelectedItemsToClipboard();
722 m_activeViewContainer
->setSelectionModeEnabled(false);
726 void DolphinMainWindow::paste()
728 m_activeViewContainer
->view()->paste();
731 void DolphinMainWindow::find()
733 m_activeViewContainer
->setSearchModeEnabled(true);
736 void DolphinMainWindow::updateSearchAction()
738 QAction
*toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
739 toggleSearchAction
->setChecked(m_activeViewContainer
->isSearchModeEnabled());
742 void DolphinMainWindow::updatePasteAction()
744 QAction
*pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
745 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
746 pasteAction
->setEnabled(pasteInfo
.first
);
747 pasteAction
->setText(pasteInfo
.second
);
750 void DolphinMainWindow::slotDirectoryLoadingCompleted()
755 void DolphinMainWindow::slotToolBarActionMiddleClicked(QAction
*action
)
757 if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Back
))) {
759 } else if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Forward
))) {
761 } else if (action
== actionCollection()->action(QStringLiteral("go_up"))) {
763 } else if (action
== actionCollection()->action(QStringLiteral("go_home"))) {
768 QAction
*DolphinMainWindow::urlNavigatorHistoryAction(const KUrlNavigator
*urlNavigator
, int historyIndex
, QObject
*parent
)
770 const QUrl url
= urlNavigator
->locationUrl(historyIndex
);
772 QString text
= url
.toDisplayString(QUrl::PreferLocalFile
);
774 if (!urlNavigator
->showFullPath()) {
775 const KFilePlacesModel
*placesModel
= DolphinPlacesModelSingleton::instance().placesModel();
777 const QModelIndex closestIdx
= placesModel
->closestItem(url
);
778 if (closestIdx
.isValid()) {
779 const QUrl placeUrl
= placesModel
->url(closestIdx
);
781 text
= placesModel
->text(closestIdx
);
783 QString pathInsidePlace
= url
.path().mid(placeUrl
.path().length());
785 if (!pathInsidePlace
.isEmpty() && !pathInsidePlace
.startsWith(QLatin1Char('/'))) {
786 pathInsidePlace
.prepend(QLatin1Char('/'));
789 if (pathInsidePlace
!= QLatin1Char('/')) {
790 text
.append(pathInsidePlace
);
795 QAction
*action
= new QAction(QIcon::fromTheme(KIO::iconNameForUrl(url
)), text
, parent
);
796 action
->setData(historyIndex
);
800 void DolphinMainWindow::slotAboutToShowBackPopupMenu()
802 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
804 m_backAction
->menu()->clear();
805 for (int i
= urlNavigator
->historyIndex() + 1; i
< urlNavigator
->historySize() && entries
< MaxNumberOfNavigationentries
; ++i
, ++entries
) {
806 QAction
*action
= urlNavigatorHistoryAction(urlNavigator
, i
, m_backAction
->menu());
807 m_backAction
->menu()->addAction(action
);
811 void DolphinMainWindow::slotGoBack(QAction
*action
)
813 int gotoIndex
= action
->data().value
<int>();
814 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
815 for (int i
= gotoIndex
- urlNavigator
->historyIndex(); i
> 0; --i
) {
820 void DolphinMainWindow::slotBackForwardActionMiddleClicked(QAction
*action
)
823 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
824 openNewTab(urlNavigator
->locationUrl(action
->data().value
<int>()));
828 void DolphinMainWindow::slotAboutToShowForwardPopupMenu()
830 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
832 m_forwardAction
->menu()->clear();
833 for (int i
= urlNavigator
->historyIndex() - 1; i
>= 0 && entries
< MaxNumberOfNavigationentries
; --i
, ++entries
) {
834 QAction
*action
= urlNavigatorHistoryAction(urlNavigator
, i
, m_forwardAction
->menu());
835 m_forwardAction
->menu()->addAction(action
);
839 void DolphinMainWindow::slotGoForward(QAction
*action
)
841 int gotoIndex
= action
->data().value
<int>();
842 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
843 for (int i
= urlNavigator
->historyIndex() - gotoIndex
; i
> 0; --i
) {
848 void DolphinMainWindow::slotSetSelectionMode(bool enabled
, SelectionMode::BottomBar::Contents bottomBarContents
)
850 m_activeViewContainer
->setSelectionModeEnabled(enabled
, actionCollection(), bottomBarContents
);
853 void DolphinMainWindow::selectAll()
857 // if the URL navigator is editable and focused, select the whole
858 // URL instead of all items of the view
860 KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigator();
861 QLineEdit
*lineEdit
= urlNavigator
->editor()->lineEdit();
862 const bool selectUrl
= urlNavigator
->isUrlEditable() && lineEdit
->hasFocus();
864 lineEdit
->selectAll();
866 m_activeViewContainer
->view()->selectAll();
870 void DolphinMainWindow::invertSelection()
873 m_activeViewContainer
->view()->invertSelection();
876 void DolphinMainWindow::toggleSplitView()
878 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
879 tabPage
->setSplitViewEnabled(!tabPage
->splitViewEnabled(), WithAnimation
);
884 void DolphinMainWindow::toggleSplitStash()
886 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
887 tabPage
->setSplitViewEnabled(false, WithAnimation
);
888 tabPage
->setSplitViewEnabled(true, WithAnimation
, QUrl("stash:/"));
891 void DolphinMainWindow::copyToInactiveSplitView()
893 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
894 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CopyToOtherViewContents
);
896 m_tabWidget
->copyToInactiveSplitView();
897 m_activeViewContainer
->setSelectionModeEnabled(false);
901 void DolphinMainWindow::moveToInactiveSplitView()
903 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
904 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::MoveToOtherViewContents
);
906 m_tabWidget
->moveToInactiveSplitView();
907 m_activeViewContainer
->setSelectionModeEnabled(false);
911 void DolphinMainWindow::reloadView()
914 m_activeViewContainer
->reload();
915 m_activeViewContainer
->statusBar()->updateSpaceInfo();
918 void DolphinMainWindow::stopLoading()
920 m_activeViewContainer
->view()->stopLoading();
923 void DolphinMainWindow::enableStopAction()
925 actionCollection()->action(QStringLiteral("stop"))->setEnabled(true);
928 void DolphinMainWindow::disableStopAction()
930 actionCollection()->action(QStringLiteral("stop"))->setEnabled(false);
933 void DolphinMainWindow::toggleSelectionMode()
935 const bool checked
= !m_activeViewContainer
->isSelectionModeEnabled();
937 m_activeViewContainer
->setSelectionModeEnabled(checked
, actionCollection(), SelectionMode::BottomBar::Contents::GeneralContents
);
938 actionCollection()->action(QStringLiteral("toggle_selection_mode"))->setChecked(checked
);
941 void DolphinMainWindow::showFilterBar()
943 m_activeViewContainer
->setFilterBarVisible(true);
946 void DolphinMainWindow::toggleFilterBar()
948 const bool checked
= !m_activeViewContainer
->isFilterBarVisible();
949 m_activeViewContainer
->setFilterBarVisible(checked
);
951 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
952 toggleFilterBarAction
->setChecked(checked
);
955 void DolphinMainWindow::toggleEditLocation()
959 QAction
*action
= actionCollection()->action(QStringLiteral("editable_location"));
960 KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigator();
961 urlNavigator
->setUrlEditable(action
->isChecked());
964 void DolphinMainWindow::replaceLocation()
966 KUrlNavigator
*navigator
= m_activeViewContainer
->urlNavigator();
967 QLineEdit
*lineEdit
= navigator
->editor()->lineEdit();
969 // If the text field currently has focus and everything is selected,
970 // pressing the keyboard shortcut returns the whole thing to breadcrumb mode
971 if (navigator
->isUrlEditable() && lineEdit
->hasFocus() && lineEdit
->selectedText() == lineEdit
->text()) {
972 navigator
->setUrlEditable(false);
974 navigator
->setUrlEditable(true);
975 navigator
->setFocus();
976 lineEdit
->selectAll();
980 void DolphinMainWindow::togglePanelLockState()
982 const bool newLockState
= !GeneralSettings::lockPanels();
983 const auto childrenObjects
= children();
984 for (QObject
*child
: childrenObjects
) {
985 DolphinDockWidget
*dock
= qobject_cast
<DolphinDockWidget
*>(child
);
987 dock
->setLocked(newLockState
);
991 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(newLockState
);
993 GeneralSettings::setLockPanels(newLockState
);
996 void DolphinMainWindow::slotTerminalPanelVisibilityChanged()
998 if (m_terminalPanel
->isHiddenInVisibleWindow() && m_activeViewContainer
) {
999 m_activeViewContainer
->view()->setFocus();
1003 void DolphinMainWindow::goBack()
1005 DolphinUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
1006 urlNavigator
->goBack();
1008 if (urlNavigator
->locationState().isEmpty()) {
1009 // An empty location state indicates a redirection URL,
1010 // which must be skipped too
1011 urlNavigator
->goBack();
1015 void DolphinMainWindow::goForward()
1017 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goForward();
1020 void DolphinMainWindow::goUp()
1022 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goUp();
1025 void DolphinMainWindow::goHome()
1027 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goHome();
1030 void DolphinMainWindow::goBackInNewTab()
1032 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
1033 const int index
= urlNavigator
->historyIndex() + 1;
1034 openNewTab(urlNavigator
->locationUrl(index
));
1037 void DolphinMainWindow::goForwardInNewTab()
1039 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
1040 const int index
= urlNavigator
->historyIndex() - 1;
1041 openNewTab(urlNavigator
->locationUrl(index
));
1044 void DolphinMainWindow::goUpInNewTab()
1046 const QUrl currentUrl
= activeViewContainer()->urlNavigator()->locationUrl();
1047 openNewTab(KIO::upUrl(currentUrl
));
1050 void DolphinMainWindow::goHomeInNewTab()
1052 openNewTab(Dolphin::homeUrl());
1055 void DolphinMainWindow::compareFiles()
1057 const KFileItemList items
= m_tabWidget
->currentTabPage()->selectedItems();
1058 if (items
.count() != 2) {
1059 // The action is disabled in this case, but it could have been triggered
1060 // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
1064 QUrl urlA
= items
.at(0).url();
1065 QUrl urlB
= items
.at(1).url();
1067 QString
command(QStringLiteral("kompare -c \""));
1068 command
.append(urlA
.toDisplayString(QUrl::PreferLocalFile
));
1069 command
.append("\" \"");
1070 command
.append(urlB
.toDisplayString(QUrl::PreferLocalFile
));
1071 command
.append('\"');
1073 KIO::CommandLauncherJob
*job
= new KIO::CommandLauncherJob(command
, this);
1074 job
->setDesktopName(QStringLiteral("org.kde.kompare"));
1078 void DolphinMainWindow::toggleShowMenuBar()
1080 const bool visible
= menuBar()->isVisible();
1081 menuBar()->setVisible(!visible
);
1084 QPointer
<QAction
> DolphinMainWindow::preferredSearchTool()
1086 m_searchTools
.clear();
1087 KMoreToolsMenuFactory("dolphin/search-tools").fillMenuFromGroupingNames(&m_searchTools
, {"files-find"}, m_activeViewContainer
->url());
1088 QList
<QAction
*> actions
= m_searchTools
.actions();
1089 if (actions
.isEmpty()) {
1092 QAction
*action
= actions
.first();
1093 if (action
->isSeparator()) {
1099 void DolphinMainWindow::updateOpenPreferredSearchToolAction()
1101 QAction
*openPreferredSearchTool
= actionCollection()->action(QStringLiteral("open_preferred_search_tool"));
1102 if (!openPreferredSearchTool
) {
1105 QPointer
<QAction
> tool
= preferredSearchTool();
1107 openPreferredSearchTool
->setVisible(true);
1108 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open %1", tool
->text()));
1109 // Only override with the app icon if it is the default, i.e. the user hasn't configured one manually
1110 // https://bugs.kde.org/show_bug.cgi?id=442815
1111 if (openPreferredSearchTool
->icon().name() == QLatin1String("search")) {
1112 openPreferredSearchTool
->setIcon(tool
->icon());
1115 openPreferredSearchTool
->setVisible(false);
1116 // still visible in Shortcuts configuration window
1117 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1118 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1122 void DolphinMainWindow::openPreferredSearchTool()
1124 QPointer
<QAction
> tool
= preferredSearchTool();
1130 void DolphinMainWindow::openTerminal()
1132 openTerminalJob(m_activeViewContainer
->url());
1135 void DolphinMainWindow::openTerminalHere()
1137 QList
<QUrl
> urls
= {};
1139 for (const KFileItem
&item
: m_activeViewContainer
->view()->selectedItems()) {
1140 QUrl url
= item
.targetUrl();
1141 if (item
.isFile()) {
1142 url
.setPath(QFileInfo(url
.path()).absolutePath());
1144 if (!urls
.contains(url
)) {
1149 // No items are selected. Open a terminal window for the current location.
1150 if (urls
.count() == 0) {
1155 if (urls
.count() > 5) {
1156 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());
1157 #if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
1158 const int answer
= KMessageBox::warningTwoActions(
1163 const int answer
= KMessageBox::warningYesNo(
1168 KGuiItem(i18ncp("@action:button", "Open %1 Terminal", "Open %1 Terminals", urls
.count()), QStringLiteral("utilities-terminal")),
1169 KStandardGuiItem::cancel());
1170 #if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
1171 if (answer
!= KMessageBox::PrimaryAction
) {
1173 if (answer
!= KMessageBox::Yes
) {
1179 for (const QUrl
&url
: urls
) {
1180 openTerminalJob(url
);
1184 void DolphinMainWindow::openTerminalJob(const QUrl
&url
)
1186 if (url
.isLocalFile()) {
1187 auto job
= new KTerminalLauncherJob(QString());
1188 job
->setWorkingDirectory(url
.toLocalFile());
1193 // Not a local file, with protocol Class ":local", try stat'ing
1194 if (KProtocolInfo::protocolClass(url
.scheme()) == QLatin1String(":local")) {
1195 KIO::StatJob
*job
= KIO::mostLocalUrl(url
);
1196 KJobWidgets::setWindow(job
, this);
1197 connect(job
, &KJob::result
, this, [job
]() {
1199 if (!job
->error()) {
1200 statUrl
= job
->mostLocalUrl();
1203 auto job
= new KTerminalLauncherJob(QString());
1204 job
->setWorkingDirectory(statUrl
.isLocalFile() ? statUrl
.toLocalFile() : QDir::homePath());
1211 // Nothing worked, just use $HOME
1212 auto job
= new KTerminalLauncherJob(QString());
1213 job
->setWorkingDirectory(QDir::homePath());
1217 void DolphinMainWindow::editSettings()
1219 if (!m_settingsDialog
) {
1220 DolphinViewContainer
*container
= activeViewContainer();
1221 container
->view()->writeSettings();
1223 const QUrl url
= container
->url();
1224 DolphinSettingsDialog
*settingsDialog
= new DolphinSettingsDialog(url
, this, actionCollection());
1225 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, this, &DolphinMainWindow::refreshViews
);
1226 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, &DolphinUrlNavigatorsController::slotReadSettings
);
1227 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1228 settingsDialog
->show();
1229 m_settingsDialog
= settingsDialog
;
1231 m_settingsDialog
.data()->raise();
1235 void DolphinMainWindow::handleUrl(const QUrl
&url
)
1237 delete m_lastHandleUrlOpenJob
;
1238 m_lastHandleUrlOpenJob
= nullptr;
1240 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1241 activeViewContainer()->setUrl(url
);
1243 m_lastHandleUrlOpenJob
= new KIO::OpenUrlJob(url
);
1244 #if KIO_VERSION >= QT_VERSION_CHECK(5, 98, 0)
1245 m_lastHandleUrlOpenJob
->setUiDelegate(KIO::createDefaultJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
1247 m_lastHandleUrlOpenJob
->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
1249 m_lastHandleUrlOpenJob
->setShowOpenOrExecuteDialog(true);
1251 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::mimeTypeFound
, this, [this, url
](const QString
&mimetype
) {
1252 if (mimetype
== QLatin1String("inode/directory")) {
1253 // If it's a dir, we'll take it from here
1254 m_lastHandleUrlOpenJob
->kill();
1255 m_lastHandleUrlOpenJob
= nullptr;
1256 activeViewContainer()->setUrl(url
);
1260 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::result
, this, [this]() {
1261 m_lastHandleUrlOpenJob
= nullptr;
1264 m_lastHandleUrlOpenJob
->start();
1268 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1270 // trash:/ is writable but we don't want to create new items in it.
1271 // TODO: remove the trash check once https://phabricator.kde.org/T8234 is implemented
1272 newFileMenu()->setEnabled(isFolderWritable
&& m_activeViewContainer
->url().scheme() != QLatin1String("trash"));
1275 void DolphinMainWindow::openContextMenu(const QPoint
&pos
, const KFileItem
&item
, const KFileItemList
&selectedItems
, const QUrl
&url
)
1277 QPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, item
, selectedItems
, url
, &m_fileItemActions
);
1278 contextMenu
.data()->exec(pos
);
1280 // Delete the menu, unless it has been deleted in its own nested event loop already.
1282 contextMenu
->deleteLater();
1286 QMenu
*DolphinMainWindow::createPopupMenu()
1288 QMenu
*menu
= KXmlGuiWindow::createPopupMenu();
1290 menu
->addSeparator();
1291 menu
->addAction(actionCollection()->action(QStringLiteral("lock_panels")));
1296 void DolphinMainWindow::updateHamburgerMenu()
1298 KActionCollection
*ac
= actionCollection();
1299 auto hamburgerMenu
= static_cast<KHamburgerMenu
*>(ac
->action(KStandardAction::name(KStandardAction::HamburgerMenu
)));
1300 auto menu
= hamburgerMenu
->menu();
1302 menu
= new QMenu(this);
1303 hamburgerMenu
->setMenu(menu
);
1304 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("basic_actions"))->menu());
1305 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("zoom"))->menu());
1309 const QList
<QAction
*> toolbarActions
= toolBar()->actions();
1311 if (!toolBar()->isVisible()) {
1312 // If neither the menu bar nor the toolbar are visible, these actions should be available.
1313 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)));
1314 menu
->addAction(toolBarMenuAction());
1315 menu
->addSeparator();
1318 // This group of actions (until the next separator) contains all the most basic actions
1319 // necessary to use Dolphin effectively.
1320 menu
->addAction(ac
->action(QStringLiteral("go_back")));
1321 menu
->addAction(ac
->action(QStringLiteral("go_forward")));
1323 menu
->addMenu(m_newFileMenu
->menu());
1324 if (!toolBar()->isVisible() || !toolbarActions
.contains(ac
->action(QStringLiteral("toggle_selection_mode_tool_bar")))) {
1325 menu
->addAction(ac
->action(QStringLiteral("toggle_selection_mode")));
1327 menu
->addAction(ac
->action(QStringLiteral("basic_actions")));
1328 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Undo
)));
1329 if (!toolBar()->isVisible()
1330 || (!toolbarActions
.contains(ac
->action(QStringLiteral("toggle_search")))
1331 && !toolbarActions
.contains(ac
->action(QStringLiteral("open_preferred_search_tool"))))) {
1332 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Find
)));
1333 // This way a search action will only be added if none of the three available
1334 // search actions is present on the toolbar.
1336 if (!toolBar()->isVisible() || !toolbarActions
.contains(ac
->action(QStringLiteral("toggle_filter")))) {
1337 menu
->addAction(ac
->action(QStringLiteral("show_filter_bar")));
1338 // This way a filter action will only be added if none of the two available
1339 // filter actions is present on the toolbar.
1341 menu
->addSeparator();
1343 // The second group of actions (up until the next separator) contains actions for opening
1344 // additional views to interact with the file system.
1345 menu
->addAction(ac
->action(QStringLiteral("file_new")));
1346 menu
->addAction(ac
->action(QStringLiteral("new_tab")));
1347 if (ac
->action(QStringLiteral("undo_close_tab"))->isEnabled()) {
1348 menu
->addAction(ac
->action(QStringLiteral("closed_tabs")));
1350 menu
->addAction(ac
->action(QStringLiteral("open_terminal")));
1351 menu
->addSeparator();
1353 // The third group contains actions to change what one sees in the view
1354 // and to change the more general UI.
1355 if (!toolBar()->isVisible()
1356 || (!toolbarActions
.contains(ac
->action(QStringLiteral("icons"))) && !toolbarActions
.contains(ac
->action(QStringLiteral("compact")))
1357 && !toolbarActions
.contains(ac
->action(QStringLiteral("details"))) && !toolbarActions
.contains(ac
->action(QStringLiteral("view_mode"))))) {
1358 menu
->addAction(ac
->action(QStringLiteral("view_mode")));
1360 menu
->addAction(ac
->action(QStringLiteral("show_hidden_files")));
1361 menu
->addAction(ac
->action(QStringLiteral("sort")));
1362 menu
->addAction(ac
->action(QStringLiteral("additional_info")));
1363 if (!GeneralSettings::showStatusBar() || !GeneralSettings::showZoomSlider()) {
1364 menu
->addAction(ac
->action(QStringLiteral("zoom")));
1366 menu
->addAction(ac
->action(QStringLiteral("panels")));
1368 // The "Configure" menu is not added to the actionCollection() because there is hardly
1369 // a good reason for users to put it on their toolbar.
1370 auto configureMenu
= menu
->addMenu(QIcon::fromTheme(QStringLiteral("configure")), i18nc("@action:inmenu menu for configure actions", "Configure"));
1371 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
)));
1372 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)));
1373 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)));
1374 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Preferences
)));
1375 hamburgerMenu
->hideActionsOf(configureMenu
);
1378 void DolphinMainWindow::slotPlaceActivated(const QUrl
&url
)
1380 DolphinViewContainer
*view
= activeViewContainer();
1382 if (view
->url() == url
) {
1383 view
->clearFilterBar(); // Fixes bug 259382.
1385 // We can end up here if the user clicked a device in the Places Panel
1386 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
1389 view
->disableUrlNavigatorSelectionRequests();
1391 view
->enableUrlNavigatorSelectionRequests();
1395 void DolphinMainWindow::closedTabsCountChanged(unsigned int count
)
1397 actionCollection()->action(QStringLiteral("undo_close_tab"))->setEnabled(count
> 0);
1400 void DolphinMainWindow::activeViewChanged(DolphinViewContainer
*viewContainer
)
1402 DolphinViewContainer
*oldViewContainer
= m_activeViewContainer
;
1403 Q_ASSERT(viewContainer
);
1405 m_activeViewContainer
= viewContainer
;
1407 if (oldViewContainer
) {
1408 const QAction
*toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
1409 toggleSearchAction
->disconnect(oldViewContainer
);
1411 // Disconnect all signals between the old view container (container,
1412 // view and url navigator) and main window.
1413 oldViewContainer
->disconnect(this);
1414 oldViewContainer
->view()->disconnect(this);
1415 oldViewContainer
->urlNavigatorInternalWithHistory()->disconnect(this);
1416 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
1417 navigators
->primaryUrlNavigator()->disconnect(this);
1418 if (auto secondaryUrlNavigator
= navigators
->secondaryUrlNavigator()) {
1419 secondaryUrlNavigator
->disconnect(this);
1422 // except the requestItemInfo so that on hover the information panel can still be updated
1423 connect(oldViewContainer
->view(), &DolphinView::requestItemInfo
, this, &DolphinMainWindow::requestItemInfo
);
1425 // Disconnect other slots.
1427 &DolphinViewContainer::selectionModeChanged
,
1428 actionCollection()->action(QStringLiteral("toggle_selection_mode")),
1429 &QAction::setChecked
);
1432 connectViewSignals(viewContainer
);
1434 m_actionHandler
->setCurrentView(viewContainer
->view());
1437 updateFileAndEditActions();
1438 updatePasteAction();
1439 updateViewActions();
1441 updateSearchAction();
1443 const QUrl url
= viewContainer
->url();
1444 Q_EMIT
urlChanged(url
);
1447 void DolphinMainWindow::tabCountChanged(int count
)
1449 const bool enableTabActions
= (count
> 1);
1450 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1451 actionCollection()->action(QStringLiteral("activate_tab_%1").arg(i
))->setEnabled(enableTabActions
);
1453 actionCollection()->action(QStringLiteral("activate_last_tab"))->setEnabled(enableTabActions
);
1454 actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions
);
1455 actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions
);
1458 void DolphinMainWindow::updateWindowTitle()
1460 const QString newTitle
= m_activeViewContainer
->captionWindowTitle();
1461 if (windowTitle() != newTitle
) {
1462 setWindowTitle(newTitle
);
1466 void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString
&mountPath
)
1468 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1469 setViewsToHomeIfMountPathOpen(mountPath
);
1472 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectory().startsWith(mountPath
)) {
1473 m_tearDownFromPlacesRequested
= true;
1474 m_terminalPanel
->goHome();
1475 // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged
1477 m_placesPanel
->proceedWithTearDown();
1481 void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString
&mountPath
)
1483 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1484 setViewsToHomeIfMountPathOpen(mountPath
);
1487 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectory().startsWith(mountPath
)) {
1488 m_tearDownFromPlacesRequested
= false;
1489 m_terminalPanel
->goHome();
1493 void DolphinMainWindow::slotKeyBindings()
1495 KShortcutsDialog
dialog(KShortcutsEditor::AllActions
, KShortcutsEditor::LetterShortcutsAllowed
, this);
1496 dialog
.addCollection(actionCollection());
1497 if (m_terminalPanel
) {
1498 KActionCollection
*konsolePartActionCollection
= m_terminalPanel
->actionCollection();
1499 if (konsolePartActionCollection
) {
1500 dialog
.addCollection(konsolePartActionCollection
, QStringLiteral("KonsolePart"));
1506 void DolphinMainWindow::setViewsToHomeIfMountPathOpen(const QString
&mountPath
)
1508 const QVector
<DolphinViewContainer
*> theViewContainers
= viewContainers();
1509 for (DolphinViewContainer
*viewContainer
: theViewContainers
) {
1510 if (viewContainer
&& viewContainer
->url().toLocalFile().startsWith(mountPath
)) {
1511 viewContainer
->setUrl(QUrl::fromLocalFile(QDir::homePath()));
1514 disconnect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, nullptr, nullptr);
1517 void DolphinMainWindow::setupActions()
1519 auto hamburgerMenuAction
= KStandardAction::hamburgerMenu(nullptr, nullptr, actionCollection());
1521 // setup 'File' menu
1522 m_newFileMenu
= new DolphinNewFileMenu(actionCollection(), this);
1523 QMenu
*menu
= m_newFileMenu
->menu();
1524 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1525 menu
->setIcon(QIcon::fromTheme(QStringLiteral("list-add")));
1526 m_newFileMenu
->setPopupMode(QToolButton::InstantPopup
);
1527 connect(menu
, &QMenu::aboutToShow
, this, &DolphinMainWindow::updateNewMenu
);
1529 QAction
*newWindow
= KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow
, actionCollection());
1530 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1531 newWindow
->setToolTip(i18nc("@info", "Open a new Dolphin window"));
1532 newWindow
->setWhatsThis(xi18nc("@info:whatsthis",
1534 "window just like this one with the current location and view."
1535 "<nl/>You can drag and drop items between windows."));
1536 newWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1538 QAction
*newTab
= actionCollection()->addAction(QStringLiteral("new_tab"));
1539 newTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1540 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1541 newTab
->setWhatsThis(xi18nc("@info:whatsthis",
1543 "<emphasis>Tab</emphasis> with the current location and view.<nl/>"
1544 "A tab is an additional view within this window. "
1545 "You can drag and drop items between tabs."));
1546 actionCollection()->setDefaultShortcuts(newTab
, {Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
});
1547 connect(newTab
, &QAction::triggered
, this, &DolphinMainWindow::openNewActivatedTab
);
1549 QAction
*addToPlaces
= actionCollection()->addAction(QStringLiteral("add_to_places"));
1550 addToPlaces
->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new")));
1551 addToPlaces
->setText(i18nc("@action:inmenu Add current folder to places", "Add to Places"));
1552 addToPlaces
->setWhatsThis(xi18nc("@info:whatsthis",
1553 "This adds the selected folder "
1554 "to the Places panel."));
1555 connect(addToPlaces
, &QAction::triggered
, this, &DolphinMainWindow::addToPlaces
);
1557 QAction
*closeTab
= KStandardAction::close(m_tabWidget
, QOverload
<>::of(&DolphinTabWidget::closeTab
), actionCollection());
1558 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1559 closeTab
->setWhatsThis(i18nc("@info:whatsthis",
1561 "currently viewed tab. If no more tabs are left this window "
1562 "will close instead."));
1564 QAction
*quitAction
= KStandardAction::quit(this, &DolphinMainWindow::quit
, actionCollection());
1565 quitAction
->setWhatsThis(i18nc("@info:whatsthis quit", "This closes this window."));
1567 // setup 'Edit' menu
1568 KStandardAction::undo(this, &DolphinMainWindow::undo
, actionCollection());
1570 // i18n: This will be the last paragraph for the whatsthis for all three:
1571 // Cut, Copy and Paste
1572 const QString cutCopyPastePara
= xi18nc("@info:whatsthis",
1573 "<para><emphasis>Cut, "
1574 "Copy</emphasis> and <emphasis>Paste</emphasis> work between many "
1575 "applications and are among the most used commands. That's why their "
1576 "<emphasis>keyboard shortcuts</emphasis> are prominently placed right "
1577 "next to each other on the keyboard: <shortcut>Ctrl+X</shortcut>, "
1578 "<shortcut>Ctrl+C</shortcut> and <shortcut>Ctrl+V</shortcut>.</para>");
1579 QAction
*cutAction
= KStandardAction::cut(this, &DolphinMainWindow::cut
, actionCollection());
1580 m_actionTextHelper
->registerTextWhenNothingIsSelected(cutAction
, i18nc("@action", "Cut…"));
1581 cutAction
->setWhatsThis(xi18nc("@info:whatsthis cut",
1582 "This copies the items "
1583 "in your current selection to the <emphasis>clipboard</emphasis>.<nl/>"
1584 "Use the <emphasis>Paste</emphasis> action afterwards to copy them from "
1585 "the clipboard to a new location. The items will be removed from their "
1586 "initial location.")
1587 + cutCopyPastePara
);
1588 QAction
*copyAction
= KStandardAction::copy(this, &DolphinMainWindow::copy
, actionCollection());
1589 m_actionTextHelper
->registerTextWhenNothingIsSelected(copyAction
, i18nc("@action", "Copy…"));
1590 copyAction
->setWhatsThis(xi18nc("@info:whatsthis copy",
1592 "items in your current selection to the <emphasis>clipboard</emphasis>."
1593 "<nl/>Use the <emphasis>Paste</emphasis> action afterwards to copy them "
1594 "from the clipboard to a new location.")
1595 + cutCopyPastePara
);
1596 QAction
*paste
= KStandardAction::paste(this, &DolphinMainWindow::paste
, actionCollection());
1597 // The text of the paste-action is modified dynamically by Dolphin
1598 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1599 // due to the long text, the text "Paste" is used:
1600 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1601 paste
->setWhatsThis(xi18nc("@info:whatsthis paste",
1602 "This copies the items from "
1603 "your <emphasis>clipboard</emphasis> to the currently viewed folder.<nl/>"
1604 "If the items were added to the clipboard by the <emphasis>Cut</emphasis> "
1605 "action they are removed from their old location.")
1606 + cutCopyPastePara
);
1608 QAction
*copyToOtherViewAction
= actionCollection()->addAction(QStringLiteral("copy_to_inactive_split_view"));
1609 copyToOtherViewAction
->setText(i18nc("@action:inmenu", "Copy to Inactive Split View"));
1610 m_actionTextHelper
->registerTextWhenNothingIsSelected(copyToOtherViewAction
, i18nc("@action:inmenu", "Copy to Inactive Split View…"));
1611 copyToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Copy",
1612 "This copies the selected items from "
1613 "the <emphasis>active</emphasis> view to the inactive split view."));
1614 copyToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
1615 copyToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Copy to Inactive Split View"));
1616 actionCollection()->setDefaultShortcut(copyToOtherViewAction
, Qt::SHIFT
| Qt::Key_F5
);
1617 connect(copyToOtherViewAction
, &QAction::triggered
, this, &DolphinMainWindow::copyToInactiveSplitView
);
1619 QAction
*moveToOtherViewAction
= actionCollection()->addAction(QStringLiteral("move_to_inactive_split_view"));
1620 moveToOtherViewAction
->setText(i18nc("@action:inmenu", "Move to Inactive Split View"));
1621 m_actionTextHelper
->registerTextWhenNothingIsSelected(moveToOtherViewAction
, i18nc("@action:inmenu", "Move to Inactive Split View…"));
1622 moveToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Move",
1623 "This moves the selected items from "
1624 "the <emphasis>active</emphasis> view to the inactive split view."));
1625 moveToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-cut")));
1626 moveToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Move to Inactive Split View"));
1627 actionCollection()->setDefaultShortcut(moveToOtherViewAction
, Qt::SHIFT
| Qt::Key_F6
);
1628 connect(moveToOtherViewAction
, &QAction::triggered
, this, &DolphinMainWindow::moveToInactiveSplitView
);
1630 QAction
*showFilterBar
= actionCollection()->addAction(QStringLiteral("show_filter_bar"));
1631 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Filter..."));
1632 showFilterBar
->setToolTip(i18nc("@info:tooltip", "Show Filter Bar"));
1633 showFilterBar
->setWhatsThis(xi18nc("@info:whatsthis",
1635 "<emphasis>Filter Bar</emphasis> at the bottom of the window.<nl/> "
1636 "There you can enter a text to filter the files and folders currently displayed. "
1637 "Only those that contain the text in their name will be kept in view."));
1638 showFilterBar
->setIcon(QIcon::fromTheme(QStringLiteral("view-filter")));
1639 actionCollection()->setDefaultShortcuts(showFilterBar
, {Qt::CTRL
| Qt::Key_I
, Qt::Key_Slash
});
1640 connect(showFilterBar
, &QAction::triggered
, this, &DolphinMainWindow::showFilterBar
);
1642 // toggle_filter acts as a copy of the main showFilterBar to be used mainly
1643 // in the toolbar, with no default shortcut attached, to avoid messing with
1644 // existing workflows (filter bar always open and Ctrl-I to focus)
1645 QAction
*toggleFilter
= actionCollection()->addAction(QStringLiteral("toggle_filter"));
1646 toggleFilter
->setText(i18nc("@action:inmenu", "Toggle Filter Bar"));
1647 toggleFilter
->setIconText(i18nc("@action:intoolbar", "Filter"));
1648 toggleFilter
->setIcon(showFilterBar
->icon());
1649 toggleFilter
->setToolTip(showFilterBar
->toolTip());
1650 toggleFilter
->setWhatsThis(showFilterBar
->whatsThis());
1651 toggleFilter
->setCheckable(true);
1652 connect(toggleFilter
, &QAction::triggered
, this, &DolphinMainWindow::toggleFilterBar
);
1654 QAction
*searchAction
= KStandardAction::find(this, &DolphinMainWindow::find
, actionCollection());
1655 searchAction
->setText(i18n("Search..."));
1656 searchAction
->setToolTip(i18nc("@info:tooltip", "Search for files and folders"));
1657 searchAction
->setWhatsThis(xi18nc("@info:whatsthis find",
1658 "<para>This helps you "
1659 "find files and folders by opening a <emphasis>find bar</emphasis>. "
1660 "There you can enter search terms and specify settings to find the "
1661 "objects you are looking for.</para><para>Use this help again on "
1662 "the find bar so we can have a look at it while the settings are "
1663 "explained.</para>"));
1665 // toggle_search acts as a copy of the main searchAction to be used mainly
1666 // in the toolbar, with no default shortcut attached, to avoid messing with
1667 // existing workflows (search bar always open and Ctrl-F to focus)
1668 QAction
*toggleSearchAction
= actionCollection()->addAction(QStringLiteral("toggle_search"));
1669 toggleSearchAction
->setText(i18nc("@action:inmenu", "Toggle Search Bar"));
1670 toggleSearchAction
->setIconText(i18nc("@action:intoolbar", "Search"));
1671 toggleSearchAction
->setIcon(searchAction
->icon());
1672 toggleSearchAction
->setToolTip(searchAction
->toolTip());
1673 toggleSearchAction
->setWhatsThis(searchAction
->whatsThis());
1674 toggleSearchAction
->setCheckable(true);
1676 QAction
*toggleSelectionModeAction
= actionCollection()->addAction(QStringLiteral("toggle_selection_mode"));
1677 // i18n: This action toggles a selection mode.
1678 toggleSelectionModeAction
->setText(i18nc("@action:inmenu", "Select Files and Folders"));
1679 // i18n: Opens a selection mode for selecting files/folders.
1680 // The text is kept so unspecific because it will be shown on the toolbar where space is at a premium.
1681 toggleSelectionModeAction
->setIconText(i18nc("@action:intoolbar", "Select"));
1682 toggleSelectionModeAction
->setWhatsThis(xi18nc(
1684 "<para>This application only knows which files or folders should be acted on if they are"
1685 " <emphasis>selected</emphasis> first. Press this to toggle a <emphasis>Selection Mode</emphasis> which makes selecting and deselecting as easy as "
1686 "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."
1688 toggleSelectionModeAction
->setIcon(QIcon::fromTheme(QStringLiteral("quickwizard")));
1689 toggleSelectionModeAction
->setCheckable(true);
1690 connect(toggleSelectionModeAction
, &QAction::triggered
, this, &DolphinMainWindow::toggleSelectionMode
);
1692 // A special version of the toggleSelectionModeAction for the toolbar that also contains a menu
1693 // with the selectAllAction and invertSelectionAction.
1694 auto *toggleSelectionModeToolBarAction
=
1695 new KToolBarPopupAction(toggleSelectionModeAction
->icon(), toggleSelectionModeAction
->iconText(), actionCollection());
1696 toggleSelectionModeToolBarAction
->setToolTip(toggleSelectionModeAction
->text());
1697 toggleSelectionModeToolBarAction
->setWhatsThis(toggleSelectionModeAction
->whatsThis());
1698 actionCollection()->addAction(QStringLiteral("toggle_selection_mode_tool_bar"), toggleSelectionModeToolBarAction
);
1699 toggleSelectionModeToolBarAction
->setCheckable(true);
1700 toggleSelectionModeToolBarAction
->setPopupMode(QToolButton::DelayedPopup
);
1701 connect(toggleSelectionModeToolBarAction
, &QAction::triggered
, toggleSelectionModeAction
, &QAction::trigger
);
1702 connect(toggleSelectionModeAction
, &QAction::toggled
, toggleSelectionModeToolBarAction
, &QAction::setChecked
);
1704 QAction
*selectAllAction
= KStandardAction::selectAll(this, &DolphinMainWindow::selectAll
, actionCollection());
1705 selectAllAction
->setWhatsThis(xi18nc("@info:whatsthis",
1707 "files and folders in the current location."));
1709 QAction
*invertSelection
= actionCollection()->addAction(QStringLiteral("invert_selection"));
1710 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1711 invertSelection
->setWhatsThis(xi18nc("@info:whatsthis invert",
1713 "objects that you have currently <emphasis>not</emphasis> selected instead."));
1714 invertSelection
->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-invert")));
1715 actionCollection()->setDefaultShortcut(invertSelection
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1716 connect(invertSelection
, &QAction::triggered
, this, &DolphinMainWindow::invertSelection
);
1718 QMenu
*toggleSelectionModeActionMenu
= new QMenu(this);
1719 toggleSelectionModeActionMenu
->addAction(selectAllAction
);
1720 toggleSelectionModeActionMenu
->addAction(invertSelection
);
1721 toggleSelectionModeToolBarAction
->setMenu(toggleSelectionModeActionMenu
);
1723 // setup 'View' menu
1724 // (note that most of it is set up in DolphinViewActionHandler)
1726 QAction
*split
= actionCollection()->addAction(QStringLiteral("split_view"));
1727 split
->setWhatsThis(xi18nc("@info:whatsthis find",
1728 "<para>This splits "
1729 "the folder view below into two autonomous views.</para><para>This "
1730 "way you can see two locations at once and move items between them "
1731 "quickly.</para>Click this again afterwards to recombine the views."));
1732 actionCollection()->setDefaultShortcut(split
, Qt::Key_F3
);
1733 connect(split
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitView
);
1735 QAction
*stashSplit
= actionCollection()->addAction(QStringLiteral("split_stash"));
1736 actionCollection()->setDefaultShortcut(stashSplit
, Qt::CTRL
| Qt::Key_S
);
1737 stashSplit
->setText(i18nc("@action:intoolbar Stash", "Stash"));
1738 stashSplit
->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
1739 stashSplit
->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
1740 stashSplit
->setCheckable(false);
1741 QDBusConnectionInterface
*sessionInterface
= QDBusConnection::sessionBus().interface();
1742 stashSplit
->setVisible(sessionInterface
&& sessionInterface
->isServiceRegistered(QStringLiteral("org.kde.kio.StashNotifier")));
1743 connect(stashSplit
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitStash
);
1745 KStandardAction::redisplay(this, &DolphinMainWindow::reloadView
, actionCollection());
1747 QAction
*stop
= actionCollection()->addAction(QStringLiteral("stop"));
1748 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1749 stop
->setToolTip(i18nc("@info", "Stop loading"));
1750 stop
->setWhatsThis(i18nc("@info", "This stops the loading of the contents of the current folder."));
1751 stop
->setIcon(QIcon::fromTheme(QStringLiteral("process-stop")));
1752 connect(stop
, &QAction::triggered
, this, &DolphinMainWindow::stopLoading
);
1754 KToggleAction
*editableLocation
= actionCollection()->add
<KToggleAction
>(QStringLiteral("editable_location"));
1755 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1756 editableLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1757 "This toggles the <emphasis>Location Bar</emphasis> to be "
1758 "editable so you can directly enter a location you want to go to.<nl/>"
1759 "You can also switch to editing by clicking to the right of the "
1760 "location and switch back by confirming the edited location."));
1761 actionCollection()->setDefaultShortcut(editableLocation
, Qt::Key_F6
);
1762 connect(editableLocation
, &KToggleAction::triggered
, this, &DolphinMainWindow::toggleEditLocation
);
1764 QAction
*replaceLocation
= actionCollection()->addAction(QStringLiteral("replace_location"));
1765 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1766 // i18n: "enter" is used both in the meaning of "writing" and "going to" a new location here.
1767 // Both meanings are useful but not necessary to understand the use of "Replace Location".
1768 // So you might want to be more verbose in your language to convey the meaning but it's up to you.
1769 replaceLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1770 "This switches to editing the location and selects it "
1771 "so you can quickly enter a different location."));
1772 actionCollection()->setDefaultShortcut(replaceLocation
, Qt::CTRL
| Qt::Key_L
);
1773 connect(replaceLocation
, &QAction::triggered
, this, &DolphinMainWindow::replaceLocation
);
1777 QScopedPointer
<QAction
> backAction(KStandardAction::back(nullptr, nullptr, nullptr));
1778 m_backAction
= new KToolBarPopupAction(backAction
->icon(), backAction
->text(), actionCollection());
1779 m_backAction
->setObjectName(backAction
->objectName());
1780 m_backAction
->setShortcuts(backAction
->shortcuts());
1782 m_backAction
->setPopupMode(QToolButton::DelayedPopup
);
1783 connect(m_backAction
, &QAction::triggered
, this, &DolphinMainWindow::goBack
);
1784 connect(m_backAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowBackPopupMenu
);
1785 connect(m_backAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoBack
);
1786 actionCollection()->addAction(m_backAction
->objectName(), m_backAction
);
1788 auto backShortcuts
= m_backAction
->shortcuts();
1789 // Prepend this shortcut, to avoid being hidden by the two-slot UI (#371130)
1790 backShortcuts
.prepend(QKeySequence(Qt::Key_Backspace
));
1791 actionCollection()->setDefaultShortcuts(m_backAction
, backShortcuts
);
1793 DolphinRecentTabsMenu
*recentTabsMenu
= new DolphinRecentTabsMenu(this);
1794 actionCollection()->addAction(QStringLiteral("closed_tabs"), recentTabsMenu
);
1795 connect(m_tabWidget
, &DolphinTabWidget::rememberClosedTab
, recentTabsMenu
, &DolphinRecentTabsMenu::rememberClosedTab
);
1796 connect(recentTabsMenu
, &DolphinRecentTabsMenu::restoreClosedTab
, m_tabWidget
, &DolphinTabWidget::restoreClosedTab
);
1797 connect(recentTabsMenu
, &DolphinRecentTabsMenu::closedTabsCountChanged
, this, &DolphinMainWindow::closedTabsCountChanged
);
1799 QAction
*undoCloseTab
= actionCollection()->addAction(QStringLiteral("undo_close_tab"));
1800 undoCloseTab
->setText(i18nc("@action:inmenu File", "Undo close tab"));
1801 undoCloseTab
->setWhatsThis(i18nc("@info:whatsthis undo close tab", "This returns you to the previously closed tab."));
1802 actionCollection()->setDefaultShortcut(undoCloseTab
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_T
);
1803 undoCloseTab
->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo")));
1804 undoCloseTab
->setEnabled(false);
1805 connect(undoCloseTab
, &QAction::triggered
, recentTabsMenu
, &DolphinRecentTabsMenu::undoCloseTab
);
1807 auto undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
1808 undoAction
->setWhatsThis(xi18nc("@info:whatsthis",
1810 "the last change you made to files or folders.<nl/>"
1811 "Such changes include <interface>creating, renaming</interface> "
1812 "and <interface>moving</interface> them to a different location "
1813 "or to the <filename>Trash</filename>. <nl/>Changes that can't "
1814 "be undone will ask for your confirmation."));
1815 undoAction
->setEnabled(false); // undo should be disabled by default
1818 QScopedPointer
<QAction
> forwardAction(KStandardAction::forward(nullptr, nullptr, nullptr));
1819 m_forwardAction
= new KToolBarPopupAction(forwardAction
->icon(), forwardAction
->text(), actionCollection());
1820 m_forwardAction
->setObjectName(forwardAction
->objectName());
1821 m_forwardAction
->setShortcuts(forwardAction
->shortcuts());
1823 m_forwardAction
->setPopupMode(QToolButton::DelayedPopup
);
1824 connect(m_forwardAction
, &QAction::triggered
, this, &DolphinMainWindow::goForward
);
1825 connect(m_forwardAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowForwardPopupMenu
);
1826 connect(m_forwardAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoForward
);
1827 actionCollection()->addAction(m_forwardAction
->objectName(), m_forwardAction
);
1828 actionCollection()->setDefaultShortcuts(m_forwardAction
, m_forwardAction
->shortcuts());
1830 // enable middle-click to open in a new tab
1831 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
1832 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotBackForwardActionMiddleClicked
);
1833 m_backAction
->menu()->installEventFilter(middleClickEventFilter
);
1834 m_forwardAction
->menu()->installEventFilter(middleClickEventFilter
);
1835 KStandardAction::up(this, &DolphinMainWindow::goUp
, actionCollection());
1836 QAction
*homeAction
= KStandardAction::home(this, &DolphinMainWindow::goHome
, actionCollection());
1837 homeAction
->setWhatsThis(xi18nc("@info:whatsthis",
1839 "<filename>Home</filename> folder.<nl/>Every user account "
1840 "has their own <filename>Home</filename> that contains their data "
1841 "including folders that contain personal application data."));
1843 // setup 'Tools' menu
1844 QAction
*compareFiles
= actionCollection()->addAction(QStringLiteral("compare_files"));
1845 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1846 compareFiles
->setIcon(QIcon::fromTheme(QStringLiteral("kompare")));
1847 compareFiles
->setEnabled(false);
1848 connect(compareFiles
, &QAction::triggered
, this, &DolphinMainWindow::compareFiles
);
1850 QAction
*openPreferredSearchTool
= actionCollection()->addAction(QStringLiteral("open_preferred_search_tool"));
1851 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1852 openPreferredSearchTool
->setWhatsThis(xi18nc("@info:whatsthis",
1853 "<para>This opens a preferred search tool for the viewed location.</para>"
1854 "<para>Use <emphasis>More Search Tools</emphasis> menu to configure it.</para>"));
1855 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1856 actionCollection()->setDefaultShortcut(openPreferredSearchTool
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F
);
1857 connect(openPreferredSearchTool
, &QAction::triggered
, this, &DolphinMainWindow::openPreferredSearchTool
);
1859 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1860 QAction
*openTerminal
= actionCollection()->addAction(QStringLiteral("open_terminal"));
1861 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1862 openTerminal
->setWhatsThis(xi18nc("@info:whatsthis",
1863 "<para>This opens a <emphasis>terminal</emphasis> application for the viewed location.</para>"
1864 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1865 openTerminal
->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
1866 actionCollection()->setDefaultShortcut(openTerminal
, Qt::SHIFT
| Qt::Key_F4
);
1867 connect(openTerminal
, &QAction::triggered
, this, &DolphinMainWindow::openTerminal
);
1869 QAction
*openTerminalHere
= actionCollection()->addAction(QStringLiteral("open_terminal_here"));
1870 // i18n: "Here" refers to the location(s) of the currently selected item(s) or the currently viewed location if nothing is selected.
1871 openTerminalHere
->setText(i18nc("@action:inmenu Tools", "Open Terminal Here"));
1872 openTerminalHere
->setWhatsThis(xi18nc("@info:whatsthis",
1873 "<para>This opens <emphasis>terminal</emphasis> applications for the selected items' locations.</para>"
1874 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1875 openTerminalHere
->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
1876 actionCollection()->setDefaultShortcut(openTerminalHere
, Qt::SHIFT
| Qt::ALT
| Qt::Key_F4
);
1877 connect(openTerminalHere
, &QAction::triggered
, this, &DolphinMainWindow::openTerminalHere
);
1880 QAction
*focusTerminalPanel
= actionCollection()->addAction(QStringLiteral("focus_terminal_panel"));
1881 focusTerminalPanel
->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
1882 focusTerminalPanel
->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
1883 actionCollection()->setDefaultShortcut(focusTerminalPanel
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F4
);
1884 connect(focusTerminalPanel
, &QAction::triggered
, this, &DolphinMainWindow::focusTerminalPanel
);
1888 // setup 'Bookmarks' menu
1889 KActionMenu
*bookmarkMenu
= new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this);
1890 bookmarkMenu
->setIcon(QIcon::fromTheme(QStringLiteral("bookmarks")));
1891 // Make the toolbar button version work properly on click
1892 bookmarkMenu
->setPopupMode(QToolButton::InstantPopup
);
1893 m_bookmarkHandler
= new DolphinBookmarkHandler(this, actionCollection(), bookmarkMenu
->menu(), this);
1894 actionCollection()->addAction(QStringLiteral("bookmarks"), bookmarkMenu
);
1896 // setup 'Settings' menu
1897 KToggleAction
*showMenuBar
= KStandardAction::showMenubar(nullptr, nullptr, actionCollection());
1898 showMenuBar
->setWhatsThis(xi18nc("@info:whatsthis",
1899 "<para>This switches between having a <emphasis>Menubar</emphasis> "
1900 "and having a <interface>%1</interface> button. Both "
1901 "contain mostly the same actions and configuration options.</para>"
1902 "<para>The Menubar takes up more space but allows for fast and organised access to all "
1903 "actions an application has to offer.</para><para>The <interface>%1</interface> button "
1904 "is simpler and small which makes triggering advanced actions more time consuming.</para>",
1905 hamburgerMenuAction
->text().replace('&', "")));
1906 connect(showMenuBar
,
1907 &KToggleAction::triggered
, // Fixes #286822
1909 &DolphinMainWindow::toggleShowMenuBar
,
1910 Qt::QueuedConnection
);
1912 KToggleAction
*showStatusBar
= KStandardAction::showStatusbar(nullptr, nullptr, actionCollection());
1913 showStatusBar
->setChecked(GeneralSettings::showStatusBar());
1914 connect(GeneralSettings::self(), &GeneralSettings::showStatusBarChanged
, showStatusBar
, &KToggleAction::setChecked
);
1915 connect(showStatusBar
, &KToggleAction::triggered
, this, [this](bool checked
) {
1916 GeneralSettings::setShowStatusBar(checked
);
1920 KStandardAction::keyBindings(this, &DolphinMainWindow::slotKeyBindings
, actionCollection());
1921 KStandardAction::preferences(this, &DolphinMainWindow::editSettings
, actionCollection());
1923 // not in menu actions
1924 QList
<QKeySequence
> nextTabKeys
= KStandardShortcut::tabNext();
1925 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
1927 QList
<QKeySequence
> prevTabKeys
= KStandardShortcut::tabPrev();
1928 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
1930 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1931 QAction
*activateTab
= actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i
));
1932 activateTab
->setText(i18nc("@action:inmenu", "Activate Tab %1", i
+ 1));
1933 activateTab
->setEnabled(false);
1934 connect(activateTab
, &QAction::triggered
, this, [this, i
]() {
1935 m_tabWidget
->activateTab(i
);
1938 // only add default shortcuts for the first 9 tabs regardless of MaxActivateTabShortcuts
1940 actionCollection()->setDefaultShortcut(activateTab
, QStringLiteral("Alt+%1").arg(i
+ 1));
1944 QAction
*activateLastTab
= actionCollection()->addAction(QStringLiteral("activate_last_tab"));
1945 activateLastTab
->setText(i18nc("@action:inmenu", "Activate Last Tab"));
1946 activateLastTab
->setEnabled(false);
1947 connect(activateLastTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateLastTab
);
1948 actionCollection()->setDefaultShortcut(activateLastTab
, Qt::ALT
| Qt::Key_0
);
1950 QAction
*activateNextTab
= actionCollection()->addAction(QStringLiteral("activate_next_tab"));
1951 activateNextTab
->setIconText(i18nc("@action:inmenu", "Next Tab"));
1952 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1953 activateNextTab
->setEnabled(false);
1954 connect(activateNextTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateNextTab
);
1955 actionCollection()->setDefaultShortcuts(activateNextTab
, nextTabKeys
);
1957 QAction
*activatePrevTab
= actionCollection()->addAction(QStringLiteral("activate_prev_tab"));
1958 activatePrevTab
->setIconText(i18nc("@action:inmenu", "Previous Tab"));
1959 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1960 activatePrevTab
->setEnabled(false);
1961 connect(activatePrevTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activatePrevTab
);
1962 actionCollection()->setDefaultShortcuts(activatePrevTab
, prevTabKeys
);
1965 QAction
*showTarget
= actionCollection()->addAction(QStringLiteral("show_target"));
1966 showTarget
->setText(i18nc("@action:inmenu", "Show Target"));
1967 showTarget
->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
1968 showTarget
->setEnabled(false);
1969 connect(showTarget
, &QAction::triggered
, this, &DolphinMainWindow::showTarget
);
1971 QAction
*openInNewTab
= actionCollection()->addAction(QStringLiteral("open_in_new_tab"));
1972 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1973 openInNewTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1974 connect(openInNewTab
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
1976 QAction
*openInNewTabs
= actionCollection()->addAction(QStringLiteral("open_in_new_tabs"));
1977 openInNewTabs
->setText(i18nc("@action:inmenu", "Open in New Tabs"));
1978 openInNewTabs
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1979 connect(openInNewTabs
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
1981 QAction
*openInNewWindow
= actionCollection()->addAction(QStringLiteral("open_in_new_window"));
1982 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1983 openInNewWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1984 connect(openInNewWindow
, &QAction::triggered
, this, &DolphinMainWindow::openInNewWindow
);
1987 void DolphinMainWindow::setupDockWidgets()
1989 const bool lock
= GeneralSettings::lockPanels();
1991 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(lock
);
1993 KDualAction
*lockLayoutAction
= actionCollection()->add
<KDualAction
>(QStringLiteral("lock_panels"));
1994 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1995 lockLayoutAction
->setActiveIcon(QIcon::fromTheme(QStringLiteral("object-unlocked")));
1996 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1997 lockLayoutAction
->setInactiveIcon(QIcon::fromTheme(QStringLiteral("object-locked")));
1998 lockLayoutAction
->setWhatsThis(xi18nc("@info:whatsthis",
2000 "switches between having panels <emphasis>locked</emphasis> or "
2001 "<emphasis>unlocked</emphasis>.<nl/>Unlocked panels can be "
2002 "dragged to the other side of the window and have a close "
2003 "button.<nl/>Locked panels are embedded more cleanly."));
2004 lockLayoutAction
->setActive(lock
);
2005 connect(lockLayoutAction
, &KDualAction::triggered
, this, &DolphinMainWindow::togglePanelLockState
);
2007 // Setup "Information"
2008 DolphinDockWidget
*infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
2009 infoDock
->setLocked(lock
);
2010 infoDock
->setObjectName(QStringLiteral("infoDock"));
2011 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2014 InformationPanel
*infoPanel
= new InformationPanel(infoDock
);
2015 infoPanel
->setCustomContextMenuActions({lockLayoutAction
});
2016 connect(infoPanel
, &InformationPanel::urlActivated
, this, &DolphinMainWindow::handleUrl
);
2017 infoDock
->setWidget(infoPanel
);
2019 QAction
*infoAction
= infoDock
->toggleViewAction();
2020 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-information")), Qt::Key_F11
, infoAction
, QStringLiteral("show_information_panel"));
2022 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
2023 connect(this, &DolphinMainWindow::urlChanged
, infoPanel
, &InformationPanel::setUrl
);
2024 connect(this, &DolphinMainWindow::selectionChanged
, infoPanel
, &InformationPanel::setSelection
);
2025 connect(this, &DolphinMainWindow::requestItemInfo
, infoPanel
, &InformationPanel::requestDelayedItemInfo
);
2026 connect(this, &DolphinMainWindow::fileItemsChanged
, infoPanel
, &InformationPanel::slotFilesItemChanged
);
2029 // i18n: This is the last paragraph for the "What's This"-texts of all four panels.
2030 const QString panelWhatsThis
= xi18nc("@info:whatsthis",
2032 "hide panels like this go to <interface>Menu|Panels</interface> "
2033 "or <interface>View|Panels</interface>.</para>");
2036 ->action(QStringLiteral("show_information_panel"))
2037 ->setWhatsThis(xi18nc("@info:whatsthis",
2038 "<para> This toggles the "
2039 "<emphasis>information</emphasis> panel at the right side of the "
2040 "window.</para><para>The panel provides in-depth information "
2041 "about the items your mouse is hovering over or about the selected "
2042 "items. Otherwise it informs you about the currently viewed folder.<nl/>"
2043 "For single items a preview of their contents is provided.</para>"));
2045 infoDock
->setWhatsThis(xi18nc("@info:whatsthis",
2047 "provides in-depth information about the items your mouse is "
2048 "hovering over or about the selected items. Otherwise it informs "
2049 "you about the currently viewed folder.<nl/>For single items a "
2050 "preview of their contents is provided.</para><para>You can configure "
2051 "which and how details are given here by right-clicking.</para>")
2055 DolphinDockWidget
*foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
2056 foldersDock
->setLocked(lock
);
2057 foldersDock
->setObjectName(QStringLiteral("foldersDock"));
2058 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2059 FoldersPanel
*foldersPanel
= new FoldersPanel(foldersDock
);
2060 foldersPanel
->setCustomContextMenuActions({lockLayoutAction
});
2061 foldersDock
->setWidget(foldersPanel
);
2063 QAction
*foldersAction
= foldersDock
->toggleViewAction();
2064 createPanelAction(QIcon::fromTheme(QStringLiteral("folder")), Qt::Key_F7
, foldersAction
, QStringLiteral("show_folders_panel"));
2066 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
2067 connect(this, &DolphinMainWindow::urlChanged
, foldersPanel
, &FoldersPanel::setUrl
);
2068 connect(foldersPanel
, &FoldersPanel::folderActivated
, this, &DolphinMainWindow::changeUrl
);
2069 connect(foldersPanel
, &FoldersPanel::folderInNewTab
, this, &DolphinMainWindow::openNewTab
);
2070 connect(foldersPanel
, &FoldersPanel::folderInNewActiveTab
, this, &DolphinMainWindow::openNewTabAndActivate
);
2071 connect(foldersPanel
, &FoldersPanel::errorMessage
, this, &DolphinMainWindow::showErrorMessage
);
2074 ->action(QStringLiteral("show_folders_panel"))
2075 ->setWhatsThis(xi18nc("@info:whatsthis",
2077 "<emphasis>folders</emphasis> panel at the left side of the window."
2078 "<nl/><nl/>It shows the folders of the <emphasis>file system"
2079 "</emphasis> in a <emphasis>tree view</emphasis>."));
2080 foldersDock
->setWhatsThis(xi18nc("@info:whatsthis",
2082 "shows the folders of the <emphasis>file system</emphasis> in a "
2083 "<emphasis>tree view</emphasis>.</para><para>Click a folder to go "
2084 "there. Click the arrow to the left of a folder to see its subfolders. "
2085 "This allows quick switching between any folders.</para>")
2090 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
2091 DolphinDockWidget
*terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
2092 terminalDock
->setLocked(lock
);
2093 terminalDock
->setObjectName(QStringLiteral("terminalDock"));
2094 m_terminalPanel
= new TerminalPanel(terminalDock
);
2095 m_terminalPanel
->setCustomContextMenuActions({lockLayoutAction
});
2096 terminalDock
->setWidget(m_terminalPanel
);
2098 connect(m_terminalPanel
, &TerminalPanel::hideTerminalPanel
, terminalDock
, &DolphinDockWidget::hide
);
2099 connect(m_terminalPanel
, &TerminalPanel::changeUrl
, this, &DolphinMainWindow::slotTerminalDirectoryChanged
);
2100 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
, m_terminalPanel
, &TerminalPanel::dockVisibilityChanged
);
2101 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
, this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged
);
2103 QAction
*terminalAction
= terminalDock
->toggleViewAction();
2104 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-scripts")), Qt::Key_F4
, terminalAction
, QStringLiteral("show_terminal_panel"));
2106 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
2107 connect(this, &DolphinMainWindow::urlChanged
, m_terminalPanel
, &TerminalPanel::setUrl
);
2109 if (GeneralSettings::version() < 200) {
2110 terminalDock
->hide();
2114 ->action(QStringLiteral("show_terminal_panel"))
2115 ->setWhatsThis(xi18nc("@info:whatsthis",
2116 "<para>This toggles the "
2117 "<emphasis>terminal</emphasis> panel at the bottom of the window."
2118 "<nl/>The location in the terminal will always match the folder "
2119 "view so you can navigate using either.</para><para>The terminal "
2120 "panel is not needed for basic computer usage but can be useful "
2121 "for advanced tasks. To learn more about terminals use the help "
2122 "in a standalone terminal application like Konsole.</para>"));
2123 terminalDock
->setWhatsThis(xi18nc("@info:whatsthis",
2125 "the <emphasis>terminal</emphasis> panel. It behaves like a "
2126 "normal terminal but will match the location of the folder view "
2127 "so you can navigate using either.</para><para>The terminal panel "
2128 "is not needed for basic computer usage but can be useful for "
2129 "advanced tasks. To learn more about terminals use the help in a "
2130 "standalone terminal application like Konsole.</para>")
2135 if (GeneralSettings::version() < 200) {
2137 foldersDock
->hide();
2141 DolphinDockWidget
*placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
2142 placesDock
->setLocked(lock
);
2143 placesDock
->setObjectName(QStringLiteral("placesDock"));
2144 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2146 m_placesPanel
= new PlacesPanel(placesDock
);
2147 m_placesPanel
->setCustomContextMenuActions({lockLayoutAction
});
2148 placesDock
->setWidget(m_placesPanel
);
2150 QAction
*placesAction
= placesDock
->toggleViewAction();
2151 createPanelAction(QIcon::fromTheme(QStringLiteral("compass")), Qt::Key_F9
, placesAction
, QStringLiteral("show_places_panel"));
2153 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
2154 connect(m_placesPanel
, &PlacesPanel::placeActivated
, this, &DolphinMainWindow::slotPlaceActivated
);
2155 connect(m_placesPanel
, &PlacesPanel::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2156 connect(m_placesPanel
, &PlacesPanel::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2157 connect(m_placesPanel
, &PlacesPanel::newWindowRequested
, this, [this](const QUrl
&url
) {
2158 Dolphin::openNewWindow({url
}, this);
2160 connect(m_placesPanel
, &PlacesPanel::errorMessage
, this, &DolphinMainWindow::showErrorMessage
);
2161 connect(this, &DolphinMainWindow::urlChanged
, m_placesPanel
, &PlacesPanel::setUrl
);
2162 connect(placesDock
, &DolphinDockWidget::visibilityChanged
, &DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged
);
2163 connect(this, &DolphinMainWindow::settingsChanged
, m_placesPanel
, &PlacesPanel::readSettings
);
2164 connect(m_placesPanel
, &PlacesPanel::storageTearDownRequested
, this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested
);
2165 connect(m_placesPanel
, &PlacesPanel::storageTearDownExternallyRequested
, this, &DolphinMainWindow::slotStorageTearDownExternallyRequested
);
2166 DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged(m_placesPanel
->isVisible());
2168 auto actionShowAllPlaces
= new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this);
2169 actionShowAllPlaces
->setCheckable(true);
2170 actionShowAllPlaces
->setDisabled(true);
2171 actionShowAllPlaces
->setWhatsThis(i18nc("@info:whatsthis",
2173 "all places in the places panel that have been hidden. They will "
2174 "appear semi-transparent unless you uncheck their hide property."));
2176 connect(actionShowAllPlaces
, &QAction::triggered
, this, [actionShowAllPlaces
, this](bool checked
) {
2177 m_placesPanel
->setShowAll(checked
);
2179 connect(m_placesPanel
, &PlacesPanel::allPlacesShownChanged
, actionShowAllPlaces
, &QAction::setChecked
);
2182 ->action(QStringLiteral("show_places_panel"))
2183 ->setWhatsThis(xi18nc("@info:whatsthis",
2184 "<para>This toggles the "
2185 "<emphasis>places</emphasis> panel at the left side of the window."
2186 "</para><para>It allows you to go to locations you have "
2187 "bookmarked and to access disk or media attached to the computer "
2188 "or to the network. It also contains sections to find recently "
2189 "saved files or files of a certain type.</para>"));
2190 placesDock
->setWhatsThis(xi18nc("@info:whatsthis",
2191 "<para>This is the "
2192 "<emphasis>Places</emphasis> panel. It allows you to go to locations "
2193 "you have bookmarked and to access disk or media attached to the "
2194 "computer or to the network. It also contains sections to find "
2195 "recently saved files or files of a certain type.</para><para>"
2196 "Click on an entry to go there. Click with the right mouse button "
2197 "instead to open any entry in a new tab or new window.</para>"
2198 "<para>New entries can be added by dragging folders onto this panel. "
2199 "Right-click any section or entry to hide it. Right-click an empty "
2200 "space on this panel and select <interface>Show Hidden Places"
2201 "</interface> to display it again.</para>")
2204 // Add actions into the "Panels" menu
2205 KActionMenu
*panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Show Panels"), this);
2206 actionCollection()->addAction(QStringLiteral("panels"), panelsMenu
);
2207 panelsMenu
->setIcon(QIcon::fromTheme(QStringLiteral("view-sidetree")));
2208 panelsMenu
->setPopupMode(QToolButton::InstantPopup
);
2209 const KActionCollection
*ac
= actionCollection();
2210 panelsMenu
->addAction(ac
->action(QStringLiteral("show_places_panel")));
2212 panelsMenu
->addAction(ac
->action(QStringLiteral("show_information_panel")));
2214 panelsMenu
->addAction(ac
->action(QStringLiteral("show_folders_panel")));
2215 panelsMenu
->addAction(ac
->action(QStringLiteral("show_terminal_panel")));
2216 panelsMenu
->addSeparator();
2217 panelsMenu
->addAction(actionShowAllPlaces
);
2218 panelsMenu
->addAction(lockLayoutAction
);
2220 connect(panelsMenu
->menu(), &QMenu::aboutToShow
, this, [actionShowAllPlaces
, this] {
2221 actionShowAllPlaces
->setEnabled(DolphinPlacesModelSingleton::instance().placesModel()->hiddenCount());
2225 void DolphinMainWindow::updateFileAndEditActions()
2227 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
2228 const KActionCollection
*col
= actionCollection();
2229 KFileItemListProperties
capabilitiesSource(list
);
2231 QAction
*renameAction
= col
->action(KStandardAction::name(KStandardAction::RenameFile
));
2232 QAction
*moveToTrashAction
= col
->action(KStandardAction::name(KStandardAction::MoveToTrash
));
2233 QAction
*deleteAction
= col
->action(KStandardAction::name(KStandardAction::DeleteFile
));
2234 QAction
*cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
2235 QAction
*duplicateAction
= col
->action(QStringLiteral("duplicate")); // see DolphinViewActionHandler
2236 QAction
*addToPlacesAction
= col
->action(QStringLiteral("add_to_places"));
2237 QAction
*copyToOtherViewAction
= col
->action(QStringLiteral("copy_to_inactive_split_view"));
2238 QAction
*moveToOtherViewAction
= col
->action(QStringLiteral("move_to_inactive_split_view"));
2239 QAction
*copyLocation
= col
->action(QString("copy_location"));
2241 if (list
.isEmpty()) {
2242 stateChanged(QStringLiteral("has_no_selection"));
2244 // All actions that need a selection to function can be enabled because they should trigger selection mode.
2245 renameAction
->setEnabled(true);
2246 moveToTrashAction
->setEnabled(true);
2247 deleteAction
->setEnabled(true);
2248 cutAction
->setEnabled(true);
2249 duplicateAction
->setEnabled(true);
2250 addToPlacesAction
->setEnabled(true);
2251 copyLocation
->setEnabled(true);
2252 // Them triggering selection mode and not directly acting on selected items is signified by adding "…" to their text.
2253 m_actionTextHelper
->textsWhenNothingIsSelectedEnabled(true);
2256 m_actionTextHelper
->textsWhenNothingIsSelectedEnabled(false);
2257 stateChanged(QStringLiteral("has_selection"));
2259 QAction
*deleteWithTrashShortcut
= col
->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
2260 QAction
*showTarget
= col
->action(QStringLiteral("show_target"));
2262 if (list
.length() == 1 && list
.first().isDir()) {
2263 addToPlacesAction
->setEnabled(true);
2265 addToPlacesAction
->setEnabled(false);
2268 const bool enableMoveToTrash
= capabilitiesSource
.isLocal() && capabilitiesSource
.supportsMoving();
2270 renameAction
->setEnabled(capabilitiesSource
.supportsMoving());
2271 moveToTrashAction
->setEnabled(enableMoveToTrash
);
2272 deleteAction
->setEnabled(capabilitiesSource
.supportsDeleting());
2273 deleteWithTrashShortcut
->setEnabled(capabilitiesSource
.supportsDeleting() && !enableMoveToTrash
);
2274 cutAction
->setEnabled(capabilitiesSource
.supportsMoving());
2275 copyLocation
->setEnabled(list
.length() == 1);
2276 showTarget
->setEnabled(list
.length() == 1 && list
.at(0).isLink());
2277 duplicateAction
->setEnabled(capabilitiesSource
.supportsWriting());
2280 if (m_tabWidget
->currentTabPage()->splitViewEnabled()) {
2281 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
2282 KFileItem capabilitiesDestination
;
2284 if (tabPage
->primaryViewActive()) {
2285 capabilitiesDestination
= tabPage
->secondaryViewContainer()->url();
2287 capabilitiesDestination
= tabPage
->primaryViewContainer()->url();
2290 copyToOtherViewAction
->setEnabled(capabilitiesDestination
.isWritable());
2291 moveToOtherViewAction
->setEnabled((list
.isEmpty() || capabilitiesSource
.supportsMoving()) && capabilitiesDestination
.isWritable());
2293 copyToOtherViewAction
->setEnabled(false);
2294 moveToOtherViewAction
->setEnabled(false);
2298 void DolphinMainWindow::updateViewActions()
2300 m_actionHandler
->updateViewActions();
2302 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
2303 toggleFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
2305 updateSplitAction();
2308 void DolphinMainWindow::updateGoActions()
2310 QAction
*goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
2311 const QUrl currentUrl
= m_activeViewContainer
->url();
2312 // I think this is one of the best places to firstly be confronted
2313 // with a file system and its hierarchy. Talking about the root
2314 // directory might seem too much here but it is the question that
2315 // naturally arises in this context.
2316 goUpAction
->setWhatsThis(xi18nc("@info:whatsthis",
2318 "the folder that contains the currently viewed one.</para>"
2319 "<para>All files and folders are organized in a hierarchical "
2320 "<emphasis>file system</emphasis>. At the top of this hierarchy is "
2321 "a directory that contains all data connected to this computer"
2322 "—the <emphasis>root directory</emphasis>.</para>"));
2323 goUpAction
->setEnabled(KIO::upUrl(currentUrl
) != currentUrl
);
2326 void DolphinMainWindow::refreshViews()
2328 m_tabWidget
->refreshViews();
2330 if (GeneralSettings::modifiedStartupSettings()) {
2331 updateWindowTitle();
2334 updateSplitAction();
2336 Q_EMIT
settingsChanged();
2339 void DolphinMainWindow::clearStatusBar()
2341 m_activeViewContainer
->statusBar()->resetToDefaultText();
2344 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
*container
)
2346 connect(container
, &DolphinViewContainer::showFilterBarChanged
, this, &DolphinMainWindow::updateFilterBarAction
);
2347 connect(container
, &DolphinViewContainer::writeStateChanged
, this, &DolphinMainWindow::slotWriteStateChanged
);
2348 connect(container
, &DolphinViewContainer::searchModeEnabledChanged
, this, &DolphinMainWindow::updateSearchAction
);
2349 connect(container
, &DolphinViewContainer::captionChanged
, this, &DolphinMainWindow::updateWindowTitle
);
2350 connect(container
, &DolphinViewContainer::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2351 connect(container
, &DolphinViewContainer::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2353 const QAction
*toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
2354 connect(toggleSearchAction
, &QAction::triggered
, container
, &DolphinViewContainer::setSearchModeEnabled
);
2356 // Make the toggled state of the selection mode actions visually follow the selection mode state of the view.
2357 auto toggleSelectionModeAction
= actionCollection()->action(QStringLiteral("toggle_selection_mode"));
2358 toggleSelectionModeAction
->setChecked(m_activeViewContainer
->isSelectionModeEnabled());
2359 connect(m_activeViewContainer
, &DolphinViewContainer::selectionModeChanged
, toggleSelectionModeAction
, &QAction::setChecked
);
2361 const DolphinView
*view
= container
->view();
2362 connect(view
, &DolphinView::selectionChanged
, this, &DolphinMainWindow::slotSelectionChanged
);
2363 connect(view
, &DolphinView::requestItemInfo
, this, &DolphinMainWindow::requestItemInfo
);
2364 connect(view
, &DolphinView::fileItemsChanged
, this, &DolphinMainWindow::fileItemsChanged
);
2365 connect(view
, &DolphinView::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2366 connect(view
, &DolphinView::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2367 connect(view
, &DolphinView::windowRequested
, this, &DolphinMainWindow::openNewWindow
);
2368 connect(view
, &DolphinView::requestContextMenu
, this, &DolphinMainWindow::openContextMenu
);
2369 connect(view
, &DolphinView::directoryLoadingStarted
, this, &DolphinMainWindow::enableStopAction
);
2370 connect(view
, &DolphinView::directoryLoadingCompleted
, this, &DolphinMainWindow::disableStopAction
);
2371 connect(view
, &DolphinView::directoryLoadingCompleted
, this, &DolphinMainWindow::slotDirectoryLoadingCompleted
);
2372 connect(view
, &DolphinView::goBackRequested
, this, &DolphinMainWindow::goBack
);
2373 connect(view
, &DolphinView::goForwardRequested
, this, &DolphinMainWindow::goForward
);
2374 connect(view
, &DolphinView::urlActivated
, this, &DolphinMainWindow::handleUrl
);
2375 connect(view
, &DolphinView::goUpRequested
, this, &DolphinMainWindow::goUp
);
2377 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::urlChanged
, this, &DolphinMainWindow::changeUrl
);
2378 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::historyChanged
, this, &DolphinMainWindow::updateHistory
);
2380 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2381 const KUrlNavigator
*navigator
=
2382 m_tabWidget
->currentTabPage()->primaryViewActive() ? navigators
->primaryUrlNavigator() : navigators
->secondaryUrlNavigator();
2384 QAction
*editableLocactionAction
= actionCollection()->action(QStringLiteral("editable_location"));
2385 editableLocactionAction
->setChecked(navigator
->isUrlEditable());
2386 connect(navigator
, &KUrlNavigator::editableStateChanged
, this, &DolphinMainWindow::slotEditableStateChanged
);
2387 connect(navigator
, &KUrlNavigator::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2388 connect(navigator
, &KUrlNavigator::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2389 connect(navigator
, &KUrlNavigator::newWindowRequested
, this, &DolphinMainWindow::openNewWindow
);
2392 void DolphinMainWindow::updateSplitAction()
2394 QAction
*splitAction
= actionCollection()->action(QStringLiteral("split_view"));
2395 const DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
2396 if (tabPage
->splitViewEnabled()) {
2397 if (GeneralSettings::closeActiveSplitView() ? tabPage
->primaryViewActive() : !tabPage
->primaryViewActive()) {
2398 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2399 splitAction
->setToolTip(i18nc("@info", "Close left view"));
2400 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close")));
2402 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2403 splitAction
->setToolTip(i18nc("@info", "Close right view"));
2404 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close")));
2407 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2408 splitAction
->setToolTip(i18nc("@info", "Split view"));
2409 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
2413 void DolphinMainWindow::updateAllowedToolbarAreas()
2415 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2416 if (toolBar()->actions().contains(navigators
)) {
2417 toolBar()->setAllowedAreas(Qt::TopToolBarArea
| Qt::BottomToolBarArea
);
2418 if (toolBarArea(toolBar()) == Qt::LeftToolBarArea
|| toolBarArea(toolBar()) == Qt::RightToolBarArea
) {
2419 addToolBar(Qt::TopToolBarArea
, toolBar());
2422 toolBar()->setAllowedAreas(Qt::AllToolBarAreas
);
2426 bool DolphinMainWindow::isKompareInstalled() const
2428 static bool initialized
= false;
2429 static bool installed
= false;
2431 // TODO: maybe replace this approach later by using a menu
2432 // plugin like kdiff3plugin.cpp
2433 installed
= !QStandardPaths::findExecutable(QStringLiteral("kompare")).isEmpty();
2439 void DolphinMainWindow::createPanelAction(const QIcon
&icon
, const QKeySequence
&shortcut
, QAction
*dockAction
, const QString
&actionName
)
2441 QAction
*panelAction
= actionCollection()->addAction(actionName
);
2442 panelAction
->setCheckable(true);
2443 panelAction
->setChecked(dockAction
->isChecked());
2444 panelAction
->setText(dockAction
->text());
2445 panelAction
->setIcon(icon
);
2446 dockAction
->setIcon(icon
);
2447 actionCollection()->setDefaultShortcut(panelAction
, shortcut
);
2449 connect(panelAction
, &QAction::triggered
, dockAction
, &QAction::trigger
);
2450 connect(dockAction
, &QAction::toggled
, panelAction
, &QAction::setChecked
);
2453 void DolphinMainWindow::setupWhatsThis()
2456 menuBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2457 "<emphasis>Menubar</emphasis>. It provides access to commands and "
2458 "configuration options. Left-click on any of the menus on this "
2459 "bar to see its contents.</para><para>The Menubar can be hidden "
2460 "by unchecking <interface>Settings|Show Menubar</interface>. Then "
2461 "most of its contents become available through a <interface>Menu"
2462 "</interface> button on the <emphasis>Toolbar</emphasis>.</para>"));
2463 toolBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2464 "<emphasis>Toolbar</emphasis>. It allows quick access to "
2465 "frequently used actions.</para><para>It is highly customizable. "
2466 "All items you see in the <interface>Menu</interface> or "
2467 "in the <interface>Menubar</interface> can be placed on the "
2468 "Toolbar. Just right-click on it and select <interface>Configure "
2469 "Toolbars…</interface> or find this action within the <interface>"
2471 "</para><para>The location of the bar and the style of its "
2472 "buttons can also be changed in the right-click menu. Right-click "
2473 "a button if you want to show or hide its text.</para>"));
2474 m_tabWidget
->setWhatsThis(xi18nc("@info:whatsthis main view",
2475 "<para>Here you can see the <emphasis>folders</emphasis> and "
2476 "<emphasis>files</emphasis> that are at the location described in "
2477 "the <interface>Location Bar</interface> above. This area is the "
2478 "central part of this application where you navigate to the files "
2479 "you want to use.</para><para>For an elaborate and general "
2480 "introduction to this application <link "
2481 "url='https://userbase.kde.org/Dolphin/File_Management#Introduction_to_Dolphin'>"
2482 "click here</link>. This will open an introductory article from "
2483 "the <emphasis>KDE UserBase Wiki</emphasis>.</para><para>For brief "
2484 "explanations of all the features of this <emphasis>view</emphasis> "
2485 "<link url='help:/dolphin/dolphin-view.html'>click here</link> "
2486 "instead. This will open a page from the <emphasis>Handbook"
2487 "</emphasis> that covers the basics.</para>"));
2490 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings
))
2491 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window "
2492 "that lists the <emphasis>keyboard shortcuts</emphasis>.<nl/>"
2493 "There you can set up key combinations to trigger an action when "
2494 "they are pressed simultaneously. All commands in this application can "
2495 "be triggered this way.</para>"));
2496 actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars
))
2497 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window in which "
2498 "you can change which buttons appear on the <emphasis>Toolbar</emphasis>.</para>"
2499 "<para>All items you see in the <interface>Menu</interface> can also be placed on the Toolbar.</para>"));
2500 actionCollection()->action(KStandardAction::name(KStandardAction::Preferences
))
2501 ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window where you can "
2502 "change a multitude of settings for this application. For an explanation "
2503 "of the various settings go to the chapter <emphasis>Configuring Dolphin"
2504 "</emphasis> in <interface>Help|Dolphin Handbook</interface>."));
2508 auto setStandardActionWhatsThis
= [this](KStandardAction::StandardAction actionId
,
2509 const QString
&whatsThis
) {
2510 // Check for the existence of an action since it can be restricted through the Kiosk system
2511 if (auto *action
= actionCollection()->action(KStandardAction::name(actionId
))) {
2512 action
->setWhatsThis(whatsThis
);
2516 // i18n: If the external link isn't available in your language it might make
2517 // sense to state the external link's language in brackets to not
2518 // frustrate the user. If there are multiple languages that the user might
2519 // know with a reasonable chance you might want to have 2 external links.
2520 // The same might be true for any external link you translate.
2521 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>"));
2522 // (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 )
2524 setStandardActionWhatsThis(KStandardAction::WhatsThis
,
2525 xi18nc("@info:whatsthis whatsthis button",
2526 "<para>This is the button that invokes the help feature you are "
2527 "using right now! Click it, then click any component of this "
2528 "application to ask \"What's this?\" about it. The mouse cursor "
2529 "will change appearance if no help is available for a spot.</para>"
2530 "<para>There are two other ways to get help: "
2531 "The <link url='help:/dolphin/index.html'>Dolphin Handbook</link> and "
2532 "the <link url='https://userbase.kde.org/Dolphin/File_Management'>KDE "
2533 "UserBase Wiki</link>.</para><para>The \"What's this?\" help is "
2534 "missing in most other windows so don't get too used to this.</para>"));
2536 setStandardActionWhatsThis(KStandardAction::ReportBug
,
2537 xi18nc("@info:whatsthis","<para>This opens a "
2538 "window that will guide you through reporting errors or flaws "
2539 "in this application or in other KDE software.</para>"
2540 "<para>High-quality bug reports are much appreciated. To learn "
2541 "how to make your bug report as effective as possible "
2542 "<link url='https://community.kde.org/Get_Involved/Bug_Reporting'>"
2543 "click here</link>.</para>"));
2545 setStandardActionWhatsThis(KStandardAction::Donate
,
2546 xi18nc("@info:whatsthis", "<para>This opens a "
2547 "<emphasis>web page</emphasis> where you can donate to "
2548 "support the continued work on this application and many "
2549 "other projects by the <emphasis>KDE</emphasis> community.</para>"
2550 "<para>Donating is the easiest and fastest way to efficiently "
2551 "support KDE and its projects. KDE projects are available for "
2552 "free therefore your donation is needed to cover things that "
2553 "require money like servers, contributor meetings, etc.</para>"
2554 "<para><emphasis>KDE e.V.</emphasis> is the non-profit "
2555 "organization behind the KDE community.</para>"));
2557 setStandardActionWhatsThis(KStandardAction::SwitchApplicationLanguage
,
2558 xi18nc("@info:whatsthis",
2559 "With this you can change the language this application uses."
2560 "<nl/>You can even set secondary languages which will be used "
2561 "if texts are not available in your preferred language."));
2563 setStandardActionWhatsThis(KStandardAction::AboutApp
,
2564 xi18nc("@info:whatsthis","This opens a "
2565 "window that informs you about the version, license, "
2566 "used libraries and maintainers of this application."));
2568 setStandardActionWhatsThis(KStandardAction::AboutKDE
,
2569 xi18nc("@info:whatsthis","This opens a "
2570 "window with information about <emphasis>KDE</emphasis>. "
2571 "The KDE community are the people behind this free software."
2572 "<nl/>If you like using this application but don't know "
2573 "about KDE or want to see a cute dragon have a look!"));
2577 bool DolphinMainWindow::addHamburgerMenuToToolbar()
2579 QDomDocument domDocument
= KXMLGUIClient::domDocument();
2580 if (domDocument
.isNull()) {
2583 QDomNode toolbar
= domDocument
.elementsByTagName(QStringLiteral("ToolBar")).at(0);
2584 if (toolbar
.isNull()) {
2588 QDomElement hamburgerMenuElement
= domDocument
.createElement(QStringLiteral("Action"));
2589 hamburgerMenuElement
.setAttribute(QStringLiteral("name"), QStringLiteral("hamburger_menu"));
2590 toolbar
.appendChild(hamburgerMenuElement
);
2592 KXMLGUIFactory::saveConfigFile(domDocument
, xmlFile());
2596 // Make sure to also remove the <KXMLGUIFactory> and <QDomDocument> include
2597 // whenever this method is removed (maybe in the year ~2026).
2600 // Set a sane initial window size
2601 QSize
DolphinMainWindow::sizeHint() const
2603 return KXmlGuiWindow::sizeHint().expandedTo(QSize(760, 550));
2606 void DolphinMainWindow::saveNewToolbarConfig()
2608 KXmlGuiWindow::saveNewToolbarConfig(); // Applies the new config. This has to be called first
2609 // because the rest of this method decides things
2610 // based on the new config.
2611 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2612 if (!toolBar()->actions().contains(navigators
)) {
2613 m_tabWidget
->currentTabPage()->insertNavigatorsWidget(navigators
);
2615 updateAllowedToolbarAreas();
2616 (static_cast<KHamburgerMenu
*>(actionCollection()->action(KStandardAction::name(KStandardAction::HamburgerMenu
))))->hideActionsOf(toolBar());
2619 void DolphinMainWindow::focusTerminalPanel()
2621 if (m_terminalPanel
->isVisible()) {
2622 if (m_terminalPanel
->terminalHasFocus()) {
2623 m_activeViewContainer
->view()->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2624 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2626 m_terminalPanel
->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2627 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2630 actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger();
2631 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2635 DolphinMainWindow::UndoUiInterface::UndoUiInterface()
2636 : KIO::FileUndoManager::UiInterface()
2640 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2644 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
*job
)
2646 DolphinMainWindow
*mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2648 DolphinViewContainer
*container
= mainWin
->activeViewContainer();
2649 container
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
2651 KIO::FileUndoManager::UiInterface::jobError(job
);
2655 bool DolphinMainWindow::isUrlOpen(const QString
&url
)
2657 return m_tabWidget
->isUrlOpen(QUrl::fromUserInput(url
));
2660 bool DolphinMainWindow::isItemVisibleInAnyView(const QString
&urlOfItem
)
2662 return m_tabWidget
->isItemVisibleInAnyView(QUrl::fromUserInput(urlOfItem
));