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 "dolphinmainwindowadaptor.h"
13 #include "dolphinbookmarkhandler.h"
14 #include "dolphindockwidget.h"
15 #include "dolphincontextmenu.h"
16 #include "dolphinnavigatorswidgetaction.h"
17 #include "dolphinnewfilemenu.h"
18 #include "dolphinrecenttabsmenu.h"
19 #include "dolphinplacesmodelsingleton.h"
20 #include "dolphinurlnavigatorscontroller.h"
21 #include "dolphinviewcontainer.h"
22 #include "dolphintabpage.h"
23 #include "middleclickactioneventfilter.h"
24 #include "panels/folders/folderspanel.h"
25 #include "panels/places/placespanel.h"
26 #include "panels/terminal/terminalpanel.h"
27 #include "selectionmode/actiontexthelper.h"
28 #include "settings/dolphinsettingsdialog.h"
29 #include "statusbar/dolphinstatusbar.h"
30 #include "views/dolphinviewactionhandler.h"
31 #include "views/dolphinremoteencoding.h"
32 #include "views/draganddrophelper.h"
33 #include "views/viewproperties.h"
34 #include "views/dolphinnewfilemenuobserver.h"
35 #include "dolphin_generalsettings.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>
75 #include <QApplication>
77 #include <QCloseEvent>
78 #include <QDesktopServices>
80 #include <QDomDocument>
84 #include <QPushButton>
86 #include <QStandardPaths>
88 #include <QToolButton>
91 // Used for GeneralSettings::version() to determine whether
92 // an updated version of Dolphin is running, so as to migrate
93 // removed/renamed ...etc config entries; increment it in such
95 const int CurrentDolphinVersion
= 202;
96 // The maximum number of entries in the back/forward popup menu
97 const int MaxNumberOfNavigationentries
= 12;
98 // The maximum number of "Activate Tab" shortcuts
99 const int MaxActivateTabShortcuts
= 9;
102 DolphinMainWindow::DolphinMainWindow() :
103 KXmlGuiWindow(nullptr),
104 m_newFileMenu(nullptr),
105 m_tabWidget(nullptr),
106 m_activeViewContainer(nullptr),
107 m_actionHandler(nullptr),
108 m_remoteEncoding(nullptr),
110 m_bookmarkHandler(nullptr),
111 m_lastHandleUrlOpenJob(nullptr),
112 m_terminalPanel(nullptr),
113 m_placesPanel(nullptr),
114 m_tearDownFromPlacesRequested(false),
115 m_backAction(nullptr),
116 m_forwardAction(nullptr)
118 Q_INIT_RESOURCE(dolphin
);
120 new MainWindowAdaptor(this);
123 setWindowFlags(Qt::WindowContextHelpButtonHint
);
125 setComponentName(QStringLiteral("dolphin"), QGuiApplication::applicationDisplayName());
126 setObjectName(QStringLiteral("Dolphin#"));
128 setStateConfigGroup("State");
130 connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::errorMessage
,
131 this, &DolphinMainWindow::showErrorMessage
);
133 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
134 undoManager
->setUiInterface(new UndoUiInterface());
136 connect(undoManager
, &KIO::FileUndoManager::undoAvailable
,
137 this, &DolphinMainWindow::slotUndoAvailable
);
138 connect(undoManager
, &KIO::FileUndoManager::undoTextChanged
,
139 this, &DolphinMainWindow::slotUndoTextChanged
);
140 connect(undoManager
, &KIO::FileUndoManager::jobRecordingStarted
,
141 this, &DolphinMainWindow::clearStatusBar
);
142 connect(undoManager
, &KIO::FileUndoManager::jobRecordingFinished
,
143 this, &DolphinMainWindow::showCommand
);
145 const bool firstRun
= (GeneralSettings::version() < 200);
147 GeneralSettings::setViewPropsTimestamp(QDateTime::currentDateTime());
150 setAcceptDrops(true);
152 auto *navigatorsWidgetAction
= new DolphinNavigatorsWidgetAction(this);
153 actionCollection()->addAction(QStringLiteral("url_navigators"), navigatorsWidgetAction
);
154 m_tabWidget
= new DolphinTabWidget(navigatorsWidgetAction
, this);
155 m_tabWidget
->setObjectName("tabWidget");
156 connect(m_tabWidget
, &DolphinTabWidget::activeViewChanged
,
157 this, &DolphinMainWindow::activeViewChanged
);
158 connect(m_tabWidget
, &DolphinTabWidget::tabCountChanged
,
159 this, &DolphinMainWindow::tabCountChanged
);
160 connect(m_tabWidget
, &DolphinTabWidget::currentUrlChanged
,
161 this, &DolphinMainWindow::updateWindowTitle
);
162 setCentralWidget(m_tabWidget
);
164 m_actionTextHelper
= new SelectionMode::ActionTextHelper(this);
167 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), m_actionTextHelper
, this);
168 connect(m_actionHandler
, &DolphinViewActionHandler::actionBeingHandled
, this, &DolphinMainWindow::clearStatusBar
);
169 connect(m_actionHandler
, &DolphinViewActionHandler::createDirectoryTriggered
, this, &DolphinMainWindow::createDirectory
);
170 connect(m_actionHandler
, &DolphinViewActionHandler::selectionModeChangeTriggered
, this, &DolphinMainWindow::slotSetSelectionMode
);
172 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
173 connect(this, &DolphinMainWindow::urlChanged
,
174 m_remoteEncoding
, &DolphinRemoteEncoding::slotAboutToOpenUrl
);
178 setupGUI(Save
| Create
| ToolBar
);
179 stateChanged(QStringLiteral("new_file"));
181 QClipboard
* clipboard
= QApplication::clipboard();
182 connect(clipboard
, &QClipboard::dataChanged
,
183 this, &DolphinMainWindow::updatePasteAction
);
185 QAction
* toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
186 toggleFilterBarAction
->setChecked(GeneralSettings::filterBar());
189 menuBar()->setVisible(false);
192 const bool showMenu
= !menuBar()->isHidden();
193 QAction
* showMenuBarAction
= actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar
));
194 showMenuBarAction
->setChecked(showMenu
); // workaround for bug #171080
196 auto hamburgerMenu
= static_cast<KHamburgerMenu
*>(actionCollection()->action(
197 KStandardAction::name(KStandardAction::HamburgerMenu
)));
198 hamburgerMenu
->setMenuBar(menuBar());
199 hamburgerMenu
->setShowMenuBarAction(showMenuBarAction
);
200 connect(hamburgerMenu
, &KHamburgerMenu::aboutToShowMenu
,
201 this, &DolphinMainWindow::updateHamburgerMenu
);
202 hamburgerMenu
->hideActionsOf(toolBar());
203 if (GeneralSettings::version() < 201 && !toolBar()->actions().contains(hamburgerMenu
)) {
204 addHamburgerMenuToToolbar();
207 updateAllowedToolbarAreas();
209 // enable middle-click on back/forward/up to open in a new tab
210 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
211 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotToolBarActionMiddleClicked
);
212 toolBar()->installEventFilter(middleClickEventFilter
);
216 connect(KSycoca::self(), &KSycoca::databaseChanged
, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
218 QTimer::singleShot(0, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
220 m_fileItemActions
.setParentWidget(this);
221 connect(&m_fileItemActions
, &KFileItemActions::error
, this, [this](const QString
&errorMessage
) {
222 showErrorMessage(errorMessage
);
225 connect(GeneralSettings::self(), &GeneralSettings::splitViewChanged
,
226 this, &DolphinMainWindow::slotSplitViewChanged
);
229 DolphinMainWindow::~DolphinMainWindow()
231 // This fixes a crash on Wayland when closing the mainwindow while another dialog is open.
232 disconnect(QGuiApplication::clipboard(), &QClipboard::dataChanged
, this, &DolphinMainWindow::updatePasteAction
);
235 QVector
<DolphinViewContainer
*> DolphinMainWindow::viewContainers() const
237 QVector
<DolphinViewContainer
*> viewContainers
;
239 for (int i
= 0; i
< m_tabWidget
->count(); ++i
) {
240 DolphinTabPage
*tabPage
= m_tabWidget
->tabPageAt(i
);
242 viewContainers
<< tabPage
->primaryViewContainer();
243 if (tabPage
->splitViewEnabled()) {
244 viewContainers
<< tabPage
->secondaryViewContainer();
247 return viewContainers
;
250 void DolphinMainWindow::openDirectories(const QList
<QUrl
>& dirs
, bool splitView
)
252 m_tabWidget
->openDirectories(dirs
, splitView
);
255 void DolphinMainWindow::openDirectories(const QStringList
& dirs
, bool splitView
)
257 openDirectories(QUrl::fromStringList(dirs
), splitView
);
260 void DolphinMainWindow::openFiles(const QList
<QUrl
>& files
, bool splitView
)
262 m_tabWidget
->openFiles(files
, splitView
);
265 bool DolphinMainWindow::isFoldersPanelEnabled() const
267 return actionCollection()->action(QStringLiteral("show_folders_panel"))->isChecked();
270 bool DolphinMainWindow::isInformationPanelEnabled() const
273 return actionCollection()->action(QStringLiteral("show_information_panel"))->isChecked();
279 void DolphinMainWindow::openFiles(const QStringList
& files
, bool splitView
)
281 openFiles(QUrl::fromStringList(files
), splitView
);
284 void DolphinMainWindow::activateWindow()
286 window()->setAttribute(Qt::WA_NativeWindow
, true);
287 KStartupInfo::setNewStartupId(window()->windowHandle(), KStartupInfo::startupId());
288 KWindowSystem::activateWindow(window()->effectiveWinId());
291 bool DolphinMainWindow::isActiveWindow()
293 return window()->isActiveWindow();
296 void DolphinMainWindow::showCommand(CommandType command
)
298 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
300 case KIO::FileUndoManager::Copy
:
301 statusBar
->setText(i18nc("@info:status", "Successfully copied."));
303 case KIO::FileUndoManager::Move
:
304 statusBar
->setText(i18nc("@info:status", "Successfully moved."));
306 case KIO::FileUndoManager::Link
:
307 statusBar
->setText(i18nc("@info:status", "Successfully linked."));
309 case KIO::FileUndoManager::Trash
:
310 statusBar
->setText(i18nc("@info:status", "Successfully moved to trash."));
312 case KIO::FileUndoManager::Rename
:
313 statusBar
->setText(i18nc("@info:status", "Successfully renamed."));
316 case KIO::FileUndoManager::Mkdir
:
317 statusBar
->setText(i18nc("@info:status", "Created folder."));
325 void DolphinMainWindow::pasteIntoFolder()
327 m_activeViewContainer
->view()->pasteIntoFolder();
330 void DolphinMainWindow::changeUrl(const QUrl
&url
)
332 if (!KProtocolManager::supportsListing(url
)) {
333 // The URL navigator only checks for validity, not
334 // if the URL can be listed. An error message is
335 // shown due to DolphinViewContainer::restoreView().
339 m_activeViewContainer
->setUrl(url
);
340 updateFileAndEditActions();
345 Q_EMIT
urlChanged(url
);
348 void DolphinMainWindow::slotTerminalDirectoryChanged(const QUrl
& url
)
350 if (m_tearDownFromPlacesRequested
&& url
== QUrl::fromLocalFile(QDir::homePath())) {
351 m_placesPanel
->proceedWithTearDown();
352 m_tearDownFromPlacesRequested
= false;
355 m_activeViewContainer
->setAutoGrabFocus(false);
357 m_activeViewContainer
->setAutoGrabFocus(true);
360 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
362 KToggleAction
* editableLocationAction
=
363 static_cast<KToggleAction
*>(actionCollection()->action(QStringLiteral("editable_location")));
364 editableLocationAction
->setChecked(editable
);
367 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
369 updateFileAndEditActions();
371 const int selectedUrlsCount
= m_tabWidget
->currentTabPage()->selectedItemsCount();
373 QAction
* compareFilesAction
= actionCollection()->action(QStringLiteral("compare_files"));
374 if (selectedUrlsCount
== 2) {
375 compareFilesAction
->setEnabled(isKompareInstalled());
377 compareFilesAction
->setEnabled(false);
380 Q_EMIT
selectionChanged(selection
);
383 void DolphinMainWindow::updateHistory()
385 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
386 const int index
= urlNavigator
->historyIndex();
388 QAction
* backAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Back
));
390 backAction
->setToolTip(i18nc("@info", "Go back"));
391 backAction
->setWhatsThis(i18nc("@info:whatsthis go back", "Return to the previously viewed folder."));
392 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
395 QAction
* forwardAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Forward
));
397 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
398 forwardAction
->setWhatsThis(xi18nc("@info:whatsthis go forward",
399 "This undoes a <interface>Go|Back</interface> action."));
400 forwardAction
->setEnabled(index
> 0);
404 void DolphinMainWindow::updateFilterBarAction(bool show
)
406 QAction
* toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
407 toggleFilterBarAction
->setChecked(show
);
410 void DolphinMainWindow::openNewMainWindow()
412 Dolphin::openNewWindow({m_activeViewContainer
->url()}, this);
415 void DolphinMainWindow::openNewActivatedTab()
417 // keep browsers compatibility, new tab is always after last one
418 auto openNewTabAfterLastTabConfigured
= GeneralSettings::openNewTabAfterLastTab();
419 GeneralSettings::setOpenNewTabAfterLastTab(true);
420 m_tabWidget
->openNewActivatedTab();
421 GeneralSettings::setOpenNewTabAfterLastTab(openNewTabAfterLastTabConfigured
);
424 void DolphinMainWindow::addToPlaces()
429 // If nothing is selected, act on the current dir
430 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
431 url
= m_activeViewContainer
->url();
432 name
= m_activeViewContainer
->placesText();
434 const auto dirToAdd
= m_activeViewContainer
->view()->selectedItems().first();
435 url
= dirToAdd
.url();
436 name
= dirToAdd
.name();
440 if (m_activeViewContainer
->isSearchModeEnabled()) {
441 icon
= QStringLiteral("folder-saved-search-symbolic");
443 icon
= KIO::iconNameForUrl(url
);
445 DolphinPlacesModelSingleton::instance().placesModel()->addPlace(name
, url
, icon
);
449 void DolphinMainWindow::openNewTab(const QUrl
& url
)
451 m_tabWidget
->openNewTab(url
, QUrl());
454 void DolphinMainWindow::openNewTabAndActivate(const QUrl
&url
)
456 m_tabWidget
->openNewActivatedTab(url
, QUrl());
459 void DolphinMainWindow::openNewWindow(const QUrl
&url
)
461 Dolphin::openNewWindow({url
}, this);
464 void DolphinMainWindow::slotSplitViewChanged()
466 m_tabWidget
->currentTabPage()->setSplitViewEnabled(GeneralSettings::splitView(), WithAnimation
);
470 void DolphinMainWindow::openInNewTab()
472 const KFileItemList
& list
= m_activeViewContainer
->view()->selectedItems();
473 bool tabCreated
= false;
475 for (const KFileItem
& item
: list
) {
476 const QUrl
& url
= DolphinView::openItemAsFolderUrl(item
);
477 if (!url
.isEmpty()) {
483 // if no new tab has been created from the selection
484 // open the current directory in a new tab
486 openNewTab(m_activeViewContainer
->url());
490 void DolphinMainWindow::openInNewWindow()
494 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
495 if (list
.isEmpty()) {
496 newWindowUrl
= m_activeViewContainer
->url();
497 } else if (list
.count() == 1) {
498 const KFileItem
& item
= list
.first();
499 newWindowUrl
= DolphinView::openItemAsFolderUrl(item
);
502 if (!newWindowUrl
.isEmpty()) {
503 Dolphin::openNewWindow({newWindowUrl
}, this);
507 void DolphinMainWindow::showTarget()
509 const auto link
= m_activeViewContainer
->view()->selectedItems().at(0);
510 const auto linkLocationDir
= QFileInfo(link
.localPath()).absoluteDir();
511 auto linkDestination
= link
.linkDest();
512 if (QFileInfo(linkDestination
).isRelative()) {
513 linkDestination
= linkLocationDir
.filePath(linkDestination
);
515 if (QFileInfo::exists(linkDestination
)) {
516 KIO::highlightInFileManager({QUrl::fromLocalFile(linkDestination
).adjusted(QUrl::StripTrailingSlash
)});
518 m_activeViewContainer
->showMessage(xi18nc("@info", "Could not access <filename>%1</filename>.", linkDestination
),
519 DolphinViewContainer::Warning
);
523 void DolphinMainWindow::showEvent(QShowEvent
* event
)
525 KXmlGuiWindow::showEvent(event
);
527 if (!event
->spontaneous()) {
528 m_activeViewContainer
->view()->setFocus();
532 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
534 // Find out if Dolphin is closed directly by the user or
535 // by the session manager because the session is closed
536 bool closedByUser
= true;
537 if (qApp
->isSavingSession()) {
538 closedByUser
= false;
541 if (m_tabWidget
->count() > 1
542 && GeneralSettings::confirmClosingMultipleTabs()
543 && !GeneralSettings::rememberOpenedTabs()
545 // Ask the user if he really wants to quit and close all tabs.
546 // Open a confirmation dialog with 3 buttons:
547 // QDialogButtonBox::Yes -> Quit
548 // QDialogButtonBox::No -> Close only the current tab
549 // QDialogButtonBox::Cancel -> do nothing
550 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
551 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
552 dialog
->setModal(true);
553 QDialogButtonBox
* buttons
= new QDialogButtonBox(QDialogButtonBox::Yes
| QDialogButtonBox::No
| QDialogButtonBox::Cancel
);
554 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KGuiItem(i18nc("@action:button 'Quit Dolphin' button", "&Quit %1", QGuiApplication::applicationDisplayName()), QIcon::fromTheme(QStringLiteral("application-exit"))));
555 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("C&lose Current Tab"), QIcon::fromTheme(QStringLiteral("tab-close"))));
556 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
557 buttons
->button(QDialogButtonBox::Yes
)->setDefault(true);
559 bool doNotAskAgainCheckboxResult
= false;
561 const auto result
= KMessageBox::createKMessageBox(dialog
,
563 QMessageBox::Warning
,
564 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
566 i18n("Do not ask again"),
567 &doNotAskAgainCheckboxResult
,
568 KMessageBox::Notify
);
570 if (doNotAskAgainCheckboxResult
) {
571 GeneralSettings::setConfirmClosingMultipleTabs(false);
575 case QDialogButtonBox::Yes
:
578 case QDialogButtonBox::No
:
579 // Close only the current tab
580 m_tabWidget
->closeTab();
588 if (m_terminalPanel
&& m_terminalPanel
->hasProgramRunning() && GeneralSettings::confirmClosingTerminalRunningProgram() && closedByUser
) {
589 // Ask if the user really wants to quit Dolphin with a program that is still running in the Terminal panel
590 // Open a confirmation dialog with 3 buttons:
591 // QDialogButtonBox::Yes -> Quit
592 // QDialogButtonBox::No -> Show Terminal Panel
593 // QDialogButtonBox::Cancel -> do nothing
594 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
595 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
596 dialog
->setModal(true);
597 auto standardButtons
= QDialogButtonBox::Yes
| QDialogButtonBox::Cancel
;
598 if (!m_terminalPanel
->isVisible()) {
599 standardButtons
|= QDialogButtonBox::No
;
601 QDialogButtonBox
*buttons
= new QDialogButtonBox(standardButtons
);
602 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KStandardGuiItem::quit());
603 if (!m_terminalPanel
->isVisible()) {
605 buttons
->button(QDialogButtonBox::No
),
606 KGuiItem(i18n("Show &Terminal Panel"), QIcon::fromTheme(QStringLiteral("dialog-scripts"))));
608 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
610 bool doNotAskAgainCheckboxResult
= false;
612 const auto result
= KMessageBox::createKMessageBox(
615 QMessageBox::Warning
,
616 i18n("The program '%1' is still running in the Terminal panel. Are you sure you want to quit?", m_terminalPanel
->runningProgramName()),
618 i18n("Do not ask again"),
619 &doNotAskAgainCheckboxResult
,
620 KMessageBox::Dangerous
);
622 if (doNotAskAgainCheckboxResult
) {
623 GeneralSettings::setConfirmClosingTerminalRunningProgram(false);
627 case QDialogButtonBox::Yes
:
630 case QDialogButtonBox::No
:
631 actionCollection()->action("show_terminal_panel")->trigger();
632 // Do not quit, ignore quit event
640 if (GeneralSettings::rememberOpenedTabs()) {
641 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
642 KConfig
*config
= KConfigGui::sessionConfig();
643 saveGlobalProperties(config
);
644 savePropertiesInternal(config
, 1);
648 GeneralSettings::setVersion(CurrentDolphinVersion
);
649 GeneralSettings::self()->save();
651 KXmlGuiWindow::closeEvent(event
);
654 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
656 m_tabWidget
->saveProperties(group
);
659 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
661 m_tabWidget
->readProperties(group
);
664 void DolphinMainWindow::updateNewMenu()
666 m_newFileMenu
->checkUpToDate();
667 #if KIO_VERSION >= QT_VERSION_CHECK(5, 97, 0)
668 m_newFileMenu
->setWorkingDirectory(activeViewContainer()->url());
670 m_newFileMenu
->setPopupFiles(QList
<QUrl
>() << activeViewContainer()->url());
674 void DolphinMainWindow::createDirectory()
676 #if KIO_VERSION >= QT_VERSION_CHECK(5, 97, 0)
677 m_newFileMenu
->setWorkingDirectory(activeViewContainer()->url());
679 m_newFileMenu
->setPopupFiles(QList
<QUrl
>() << activeViewContainer()->url());
681 m_newFileMenu
->createDirectory();
684 void DolphinMainWindow::quit()
689 void DolphinMainWindow::showErrorMessage(const QString
& message
)
691 m_activeViewContainer
->showMessage(message
, DolphinViewContainer::Error
);
694 void DolphinMainWindow::slotUndoAvailable(bool available
)
696 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
698 undoAction
->setEnabled(available
);
702 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
704 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
706 undoAction
->setText(text
);
710 void DolphinMainWindow::undo()
713 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
714 KIO::FileUndoManager::self()->undo();
717 void DolphinMainWindow::cut()
719 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
720 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CutContents
);
722 m_activeViewContainer
->view()->cutSelectedItemsToClipboard();
723 m_activeViewContainer
->setSelectionModeEnabled(false);
727 void DolphinMainWindow::copy()
729 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
730 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CopyContents
);
732 m_activeViewContainer
->view()->copySelectedItemsToClipboard();
733 m_activeViewContainer
->setSelectionModeEnabled(false);
737 void DolphinMainWindow::paste()
739 m_activeViewContainer
->view()->paste();
742 void DolphinMainWindow::find()
744 m_activeViewContainer
->setSearchModeEnabled(true);
747 void DolphinMainWindow::updateSearchAction()
749 QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
750 toggleSearchAction
->setChecked(m_activeViewContainer
->isSearchModeEnabled());
753 void DolphinMainWindow::updatePasteAction()
755 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
756 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
757 pasteAction
->setEnabled(pasteInfo
.first
);
758 pasteAction
->setText(pasteInfo
.second
);
761 void DolphinMainWindow::slotDirectoryLoadingCompleted()
766 void DolphinMainWindow::slotToolBarActionMiddleClicked(QAction
*action
)
768 if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Back
))) {
770 } else if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Forward
))) {
772 } else if (action
== actionCollection()->action(QStringLiteral("go_up"))) {
774 } else if (action
== actionCollection()->action(QStringLiteral("go_home"))) {
779 QAction
*DolphinMainWindow::urlNavigatorHistoryAction(const KUrlNavigator
*urlNavigator
, int historyIndex
, QObject
*parent
)
781 const QUrl url
= urlNavigator
->locationUrl(historyIndex
);
783 QString text
= url
.toDisplayString(QUrl::PreferLocalFile
);
785 if (!urlNavigator
->showFullPath()) {
786 const KFilePlacesModel
*placesModel
= DolphinPlacesModelSingleton::instance().placesModel();
788 const QModelIndex closestIdx
= placesModel
->closestItem(url
);
789 if (closestIdx
.isValid()) {
790 const QUrl placeUrl
= placesModel
->url(closestIdx
);
792 text
= placesModel
->text(closestIdx
);
794 QString pathInsidePlace
= url
.path().mid(placeUrl
.path().length());
796 if (!pathInsidePlace
.isEmpty() && !pathInsidePlace
.startsWith(QLatin1Char('/'))) {
797 pathInsidePlace
.prepend(QLatin1Char('/'));
800 if (pathInsidePlace
!= QLatin1Char('/')) {
801 text
.append(pathInsidePlace
);
806 QAction
*action
= new QAction(QIcon::fromTheme(KIO::iconNameForUrl(url
)), text
, parent
);
807 action
->setData(historyIndex
);
811 void DolphinMainWindow::slotAboutToShowBackPopupMenu()
813 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
815 m_backAction
->menu()->clear();
816 for (int i
= urlNavigator
->historyIndex() + 1; i
< urlNavigator
->historySize() && entries
< MaxNumberOfNavigationentries
; ++i
, ++entries
) {
817 QAction
*action
= urlNavigatorHistoryAction(urlNavigator
, i
, m_backAction
->menu());
818 m_backAction
->menu()->addAction(action
);
822 void DolphinMainWindow::slotGoBack(QAction
* action
)
824 int gotoIndex
= action
->data().value
<int>();
825 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
826 for (int i
= gotoIndex
- urlNavigator
->historyIndex(); i
> 0; --i
) {
831 void DolphinMainWindow::slotBackForwardActionMiddleClicked(QAction
* action
)
834 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
835 openNewTab(urlNavigator
->locationUrl(action
->data().value
<int>()));
839 void DolphinMainWindow::slotAboutToShowForwardPopupMenu()
841 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
843 m_forwardAction
->menu()->clear();
844 for (int i
= urlNavigator
->historyIndex() - 1; i
>= 0 && entries
< MaxNumberOfNavigationentries
; --i
, ++entries
) {
845 QAction
*action
= urlNavigatorHistoryAction(urlNavigator
, i
, m_forwardAction
->menu());
846 m_forwardAction
->menu()->addAction(action
);
850 void DolphinMainWindow::slotGoForward(QAction
* action
)
852 int gotoIndex
= action
->data().value
<int>();
853 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
854 for (int i
= urlNavigator
->historyIndex() - gotoIndex
; i
> 0; --i
) {
859 void DolphinMainWindow::slotSetSelectionMode(bool enabled
, SelectionMode::BottomBar::Contents bottomBarContents
)
861 m_activeViewContainer
->setSelectionModeEnabled(enabled
, actionCollection(), bottomBarContents
);
864 void DolphinMainWindow::selectAll()
868 // if the URL navigator is editable and focused, select the whole
869 // URL instead of all items of the view
871 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
872 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit();
873 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
874 lineEdit
->hasFocus();
876 lineEdit
->selectAll();
878 m_activeViewContainer
->view()->selectAll();
882 void DolphinMainWindow::invertSelection()
885 m_activeViewContainer
->view()->invertSelection();
888 void DolphinMainWindow::toggleSplitView()
890 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
891 tabPage
->setSplitViewEnabled(!tabPage
->splitViewEnabled(), WithAnimation
);
896 void DolphinMainWindow::toggleSplitStash()
898 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
899 tabPage
->setSplitViewEnabled(false, WithAnimation
);
900 tabPage
->setSplitViewEnabled(true, WithAnimation
, QUrl("stash:/"));
903 void DolphinMainWindow::copyToInactiveSplitView()
905 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
906 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CopyToOtherViewContents
);
908 m_tabWidget
->copyToInactiveSplitView();
909 m_activeViewContainer
->setSelectionModeEnabled(false);
913 void DolphinMainWindow::moveToInactiveSplitView()
915 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
916 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::MoveToOtherViewContents
);
918 m_tabWidget
->moveToInactiveSplitView();
919 m_activeViewContainer
->setSelectionModeEnabled(false);
923 void DolphinMainWindow::reloadView()
926 m_activeViewContainer
->reload();
927 m_activeViewContainer
->statusBar()->updateSpaceInfo();
930 void DolphinMainWindow::stopLoading()
932 m_activeViewContainer
->view()->stopLoading();
935 void DolphinMainWindow::enableStopAction()
937 actionCollection()->action(QStringLiteral("stop"))->setEnabled(true);
940 void DolphinMainWindow::disableStopAction()
942 actionCollection()->action(QStringLiteral("stop"))->setEnabled(false);
945 void DolphinMainWindow::toggleSelectionMode()
947 const bool checked
= !m_activeViewContainer
->isSelectionModeEnabled();
949 m_activeViewContainer
->setSelectionModeEnabled(checked
, actionCollection(), SelectionMode::BottomBar::Contents::GeneralContents
);
950 actionCollection()->action(QStringLiteral("toggle_selection_mode"))->setChecked(checked
);
953 void DolphinMainWindow::showFilterBar()
955 m_activeViewContainer
->setFilterBarVisible(true);
958 void DolphinMainWindow::toggleFilterBar()
960 const bool checked
= !m_activeViewContainer
->isFilterBarVisible();
961 m_activeViewContainer
->setFilterBarVisible(checked
);
963 QAction
* toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
964 toggleFilterBarAction
->setChecked(checked
);
967 void DolphinMainWindow::toggleEditLocation()
971 QAction
* action
= actionCollection()->action(QStringLiteral("editable_location"));
972 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
973 urlNavigator
->setUrlEditable(action
->isChecked());
976 void DolphinMainWindow::replaceLocation()
978 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
979 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit();
981 // If the text field currently has focus and everything is selected,
982 // pressing the keyboard shortcut returns the whole thing to breadcrumb mode
983 if (navigator
->isUrlEditable()
984 && lineEdit
->hasFocus()
985 && lineEdit
->selectedText() == lineEdit
->text() ) {
986 navigator
->setUrlEditable(false);
988 navigator
->setUrlEditable(true);
989 navigator
->setFocus();
990 lineEdit
->selectAll();
994 void DolphinMainWindow::togglePanelLockState()
996 const bool newLockState
= !GeneralSettings::lockPanels();
997 const auto childrenObjects
= children();
998 for (QObject
* child
: childrenObjects
) {
999 DolphinDockWidget
* dock
= qobject_cast
<DolphinDockWidget
*>(child
);
1001 dock
->setLocked(newLockState
);
1005 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(newLockState
);
1007 GeneralSettings::setLockPanels(newLockState
);
1010 void DolphinMainWindow::slotTerminalPanelVisibilityChanged()
1012 if (m_terminalPanel
->isHiddenInVisibleWindow() && m_activeViewContainer
) {
1013 m_activeViewContainer
->view()->setFocus();
1017 void DolphinMainWindow::goBack()
1019 DolphinUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
1020 urlNavigator
->goBack();
1022 if (urlNavigator
->locationState().isEmpty()) {
1023 // An empty location state indicates a redirection URL,
1024 // which must be skipped too
1025 urlNavigator
->goBack();
1029 void DolphinMainWindow::goForward()
1031 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goForward();
1034 void DolphinMainWindow::goUp()
1036 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goUp();
1039 void DolphinMainWindow::goHome()
1041 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goHome();
1044 void DolphinMainWindow::goBackInNewTab()
1046 const KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
1047 const int index
= urlNavigator
->historyIndex() + 1;
1048 openNewTab(urlNavigator
->locationUrl(index
));
1051 void DolphinMainWindow::goForwardInNewTab()
1053 const KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
1054 const int index
= urlNavigator
->historyIndex() - 1;
1055 openNewTab(urlNavigator
->locationUrl(index
));
1058 void DolphinMainWindow::goUpInNewTab()
1060 const QUrl currentUrl
= activeViewContainer()->urlNavigator()->locationUrl();
1061 openNewTab(KIO::upUrl(currentUrl
));
1064 void DolphinMainWindow::goHomeInNewTab()
1066 openNewTab(Dolphin::homeUrl());
1069 void DolphinMainWindow::compareFiles()
1071 const KFileItemList items
= m_tabWidget
->currentTabPage()->selectedItems();
1072 if (items
.count() != 2) {
1073 // The action is disabled in this case, but it could have been triggered
1074 // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
1078 QUrl urlA
= items
.at(0).url();
1079 QUrl urlB
= items
.at(1).url();
1081 QString
command(QStringLiteral("kompare -c \""));
1082 command
.append(urlA
.toDisplayString(QUrl::PreferLocalFile
));
1083 command
.append("\" \"");
1084 command
.append(urlB
.toDisplayString(QUrl::PreferLocalFile
));
1085 command
.append('\"');
1087 KIO::CommandLauncherJob
*job
= new KIO::CommandLauncherJob(command
, this);
1088 job
->setDesktopName(QStringLiteral("org.kde.kompare"));
1092 void DolphinMainWindow::toggleShowMenuBar()
1094 const bool visible
= menuBar()->isVisible();
1095 menuBar()->setVisible(!visible
);
1098 QPointer
<QAction
> DolphinMainWindow::preferredSearchTool()
1100 m_searchTools
.clear();
1101 KMoreToolsMenuFactory("dolphin/search-tools").fillMenuFromGroupingNames(
1102 &m_searchTools
, { "files-find" }, m_activeViewContainer
->url()
1104 QList
<QAction
*> actions
= m_searchTools
.actions();
1105 if (actions
.isEmpty()) {
1108 QAction
* action
= actions
.first();
1109 if (action
->isSeparator()) {
1115 void DolphinMainWindow::updateOpenPreferredSearchToolAction()
1117 QAction
* openPreferredSearchTool
= actionCollection()->action(QStringLiteral("open_preferred_search_tool"));
1118 if (!openPreferredSearchTool
) {
1121 QPointer
<QAction
> tool
= preferredSearchTool();
1123 openPreferredSearchTool
->setVisible(true);
1124 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open %1", tool
->text()));
1125 // Only override with the app icon if it is the default, i.e. the user hasn't configured one manually
1126 // https://bugs.kde.org/show_bug.cgi?id=442815
1127 if (openPreferredSearchTool
->icon().name() == QLatin1String("search")) {
1128 openPreferredSearchTool
->setIcon(tool
->icon());
1131 openPreferredSearchTool
->setVisible(false);
1132 // still visible in Shortcuts configuration window
1133 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1134 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1138 void DolphinMainWindow::openPreferredSearchTool()
1140 QPointer
<QAction
> tool
= preferredSearchTool();
1146 void DolphinMainWindow::openTerminal()
1148 openTerminalJob(m_activeViewContainer
->url());
1151 void DolphinMainWindow::openTerminalHere()
1153 QList
<QUrl
> urls
= {};
1155 for (const KFileItem
& item
: m_activeViewContainer
->view()->selectedItems()) {
1156 QUrl url
= item
.targetUrl();
1157 if (item
.isFile()) {
1158 url
.setPath(QFileInfo(url
.path()).absolutePath());
1160 if (!urls
.contains(url
)) {
1165 // No items are selected. Open a terminal window for the current location.
1166 if (urls
.count() == 0) {
1171 if (urls
.count() > 5) {
1172 QString question
= i18np("Are you sure you want to open 1 terminal window?",
1173 "Are you sure you want to open %1 terminal windows?", urls
.count());
1174 const int answer
= KMessageBox::warningYesNo(this, question
, {},
1175 KGuiItem(i18ncp("@action:button", "Open %1 Terminal", "Open %1 Terminals", urls
.count()),
1176 QStringLiteral("utilities-terminal")),
1177 KStandardGuiItem::cancel());
1178 if (answer
!= KMessageBox::Yes
) {
1183 for (const QUrl
& url
: urls
) {
1184 openTerminalJob(url
);
1188 void DolphinMainWindow::openTerminalJob(const QUrl
& url
)
1190 if (url
.isLocalFile()) {
1191 auto job
= new KTerminalLauncherJob(QString());
1192 job
->setWorkingDirectory(url
.toLocalFile());
1197 // Not a local file, with protocol Class ":local", try stat'ing
1198 if (KProtocolInfo::protocolClass(url
.scheme()) == QLatin1String(":local")) {
1199 KIO::StatJob
*job
= KIO::mostLocalUrl(url
);
1200 KJobWidgets::setWindow(job
, this);
1201 connect(job
, &KJob::result
, this, [job
]() {
1203 if (!job
->error()) {
1204 statUrl
= job
->mostLocalUrl();
1207 auto job
= new KTerminalLauncherJob(QString());
1208 job
->setWorkingDirectory(statUrl
.isLocalFile() ? statUrl
.toLocalFile() : QDir::homePath());
1215 // Nothing worked, just use $HOME
1216 auto job
= new KTerminalLauncherJob(QString());
1217 job
->setWorkingDirectory(QDir::homePath());
1221 void DolphinMainWindow::editSettings()
1223 if (!m_settingsDialog
) {
1224 DolphinViewContainer
* container
= activeViewContainer();
1225 container
->view()->writeSettings();
1227 const QUrl url
= container
->url();
1228 DolphinSettingsDialog
* settingsDialog
= new DolphinSettingsDialog(url
, this, actionCollection());
1229 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, this, &DolphinMainWindow::refreshViews
);
1230 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
,
1231 &DolphinUrlNavigatorsController::slotReadSettings
);
1232 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1233 settingsDialog
->show();
1234 m_settingsDialog
= settingsDialog
;
1236 m_settingsDialog
.data()->raise();
1240 void DolphinMainWindow::handleUrl(const QUrl
& url
)
1242 delete m_lastHandleUrlOpenJob
;
1243 m_lastHandleUrlOpenJob
= nullptr;
1245 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1246 activeViewContainer()->setUrl(url
);
1248 m_lastHandleUrlOpenJob
= new KIO::OpenUrlJob(url
);
1249 #if KIO_VERSION >= QT_VERSION_CHECK(5, 98, 0)
1250 m_lastHandleUrlOpenJob
->setUiDelegate(KIO::createDefaultJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
1252 m_lastHandleUrlOpenJob
->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
1254 m_lastHandleUrlOpenJob
->setShowOpenOrExecuteDialog(true);
1256 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::mimeTypeFound
, this,
1257 [this, url
](const QString
&mimetype
) {
1258 if (mimetype
== QLatin1String("inode/directory")) {
1259 // If it's a dir, we'll take it from here
1260 m_lastHandleUrlOpenJob
->kill();
1261 m_lastHandleUrlOpenJob
= nullptr;
1262 activeViewContainer()->setUrl(url
);
1266 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::result
, this, [this]() {
1267 m_lastHandleUrlOpenJob
= nullptr;
1270 m_lastHandleUrlOpenJob
->start();
1274 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1276 // trash:/ is writable but we don't want to create new items in it.
1277 // TODO: remove the trash check once https://phabricator.kde.org/T8234 is implemented
1278 newFileMenu()->setEnabled(isFolderWritable
&& m_activeViewContainer
->url().scheme() != QLatin1String("trash"));
1281 void DolphinMainWindow::openContextMenu(const QPoint
& pos
,
1282 const KFileItem
& item
,
1283 const KFileItemList
&selectedItems
,
1286 QPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, item
, selectedItems
, url
, &m_fileItemActions
);
1287 contextMenu
.data()->exec(pos
);
1289 // Delete the menu, unless it has been deleted in its own nested event loop already.
1291 contextMenu
->deleteLater();
1295 QMenu
*DolphinMainWindow::createPopupMenu()
1297 QMenu
*menu
= KXmlGuiWindow::createPopupMenu();
1299 menu
->addSeparator();
1300 menu
->addAction(actionCollection()->action(QStringLiteral("lock_panels")));
1305 void DolphinMainWindow::updateHamburgerMenu()
1307 KActionCollection
* ac
= actionCollection();
1308 auto hamburgerMenu
= static_cast<KHamburgerMenu
*>(
1309 ac
->action(KStandardAction::name(KStandardAction::HamburgerMenu
)));
1310 auto menu
= hamburgerMenu
->menu();
1312 menu
= new QMenu(this);
1313 hamburgerMenu
->setMenu(menu
);
1314 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("basic_actions"))->menu());
1315 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("zoom"))->menu());
1319 const QList
<QAction
*> toolbarActions
= toolBar()->actions();
1321 if (!toolBar()->isVisible()) {
1322 // If neither the menu bar nor the toolbar are visible, these actions should be available.
1323 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)));
1324 menu
->addAction(toolBarMenuAction());
1325 menu
->addSeparator();
1328 // This group of actions (until the next separator) contains all the most basic actions
1329 // necessary to use Dolphin effectively.
1330 menu
->addAction(ac
->action(QStringLiteral("go_back")));
1331 menu
->addAction(ac
->action(QStringLiteral("go_forward")));
1333 menu
->addMenu(m_newFileMenu
->menu());
1334 if (!toolBar()->isVisible()
1335 || !toolbarActions
.contains(ac
->action(QStringLiteral("toggle_selection_mode_tool_bar")))
1337 menu
->addAction(ac
->action(QStringLiteral("toggle_selection_mode")));
1339 menu
->addAction(ac
->action(QStringLiteral("basic_actions")));
1340 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Undo
)));
1341 if (!toolBar()->isVisible()
1342 || (!toolbarActions
.contains(ac
->action(QStringLiteral("toggle_search")))
1343 && !toolbarActions
.contains(ac
->action(QStringLiteral("open_preferred_search_tool"))))
1345 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Find
)));
1346 // This way a search action will only be added if none of the three available
1347 // search actions is present on the toolbar.
1349 if (!toolBar()->isVisible()
1350 || !toolbarActions
.contains(ac
->action(QStringLiteral("toggle_filter")))
1352 menu
->addAction(ac
->action(QStringLiteral("show_filter_bar")));
1353 // This way a filter action will only be added if none of the two available
1354 // filter actions is present on the toolbar.
1356 menu
->addSeparator();
1358 // The second group of actions (up until the next separator) contains actions for opening
1359 // additional views to interact with the file system.
1360 menu
->addAction(ac
->action(QStringLiteral("file_new")));
1361 menu
->addAction(ac
->action(QStringLiteral("new_tab")));
1362 if (ac
->action(QStringLiteral("undo_close_tab"))->isEnabled()) {
1363 menu
->addAction(ac
->action(QStringLiteral("closed_tabs")));
1365 menu
->addAction(ac
->action(QStringLiteral("open_terminal")));
1366 menu
->addSeparator();
1368 // The third group contains actions to change what one sees in the view
1369 // and to change the more general UI.
1370 if (!toolBar()->isVisible()
1371 || (!toolbarActions
.contains(ac
->action(QStringLiteral("icons")))
1372 && !toolbarActions
.contains(ac
->action(QStringLiteral("compact")))
1373 && !toolbarActions
.contains(ac
->action(QStringLiteral("details")))
1374 && !toolbarActions
.contains(ac
->action(QStringLiteral("view_mode"))))
1376 menu
->addAction(ac
->action(QStringLiteral("view_mode")));
1378 menu
->addAction(ac
->action(QStringLiteral("show_hidden_files")));
1379 menu
->addAction(ac
->action(QStringLiteral("sort")));
1380 menu
->addAction(ac
->action(QStringLiteral("additional_info")));
1381 if (!GeneralSettings::showStatusBar() || !GeneralSettings::showZoomSlider()) {
1382 menu
->addAction(ac
->action(QStringLiteral("zoom")));
1384 menu
->addAction(ac
->action(QStringLiteral("panels")));
1386 // The "Configure" menu is not added to the actionCollection() because there is hardly
1387 // a good reason for users to put it on their toolbar.
1388 auto configureMenu
= menu
->addMenu(QIcon::fromTheme(QStringLiteral("configure")),
1389 i18nc("@action:inmenu menu for configure actions", "Configure"));
1390 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
)));
1391 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)));
1392 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)));
1393 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Preferences
)));
1394 hamburgerMenu
->hideActionsOf(configureMenu
);
1397 void DolphinMainWindow::slotPlaceActivated(const QUrl
& url
)
1399 DolphinViewContainer
* view
= activeViewContainer();
1401 if (view
->url() == url
) {
1402 // We can end up here if the user clicked a device in the Places Panel
1403 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
1406 view
->disableUrlNavigatorSelectionRequests();
1408 view
->enableUrlNavigatorSelectionRequests();
1412 void DolphinMainWindow::closedTabsCountChanged(unsigned int count
)
1414 actionCollection()->action(QStringLiteral("undo_close_tab"))->setEnabled(count
> 0);
1417 void DolphinMainWindow::activeViewChanged(DolphinViewContainer
* viewContainer
)
1419 DolphinViewContainer
* oldViewContainer
= m_activeViewContainer
;
1420 Q_ASSERT(viewContainer
);
1422 m_activeViewContainer
= viewContainer
;
1424 if (oldViewContainer
) {
1425 const QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
1426 toggleSearchAction
->disconnect(oldViewContainer
);
1428 // Disconnect all signals between the old view container (container,
1429 // view and url navigator) and main window.
1430 oldViewContainer
->disconnect(this);
1431 oldViewContainer
->view()->disconnect(this);
1432 oldViewContainer
->urlNavigatorInternalWithHistory()->disconnect(this);
1433 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
1434 (actionCollection()->action(QStringLiteral("url_navigators")));
1435 navigators
->primaryUrlNavigator()->disconnect(this);
1436 if (auto secondaryUrlNavigator
= navigators
->secondaryUrlNavigator()) {
1437 secondaryUrlNavigator
->disconnect(this);
1440 // except the requestItemInfo so that on hover the information panel can still be updated
1441 connect(oldViewContainer
->view(), &DolphinView::requestItemInfo
,
1442 this, &DolphinMainWindow::requestItemInfo
);
1444 // Disconnect other slots.
1445 disconnect(nullptr, &DolphinViewContainer::selectionModeChanged
,
1446 actionCollection()->action(QStringLiteral("toggle_selection_mode")), &QAction::setChecked
);
1449 connectViewSignals(viewContainer
);
1451 m_actionHandler
->setCurrentView(viewContainer
->view());
1454 updateFileAndEditActions();
1455 updatePasteAction();
1456 updateViewActions();
1458 updateSearchAction();
1460 const QUrl url
= viewContainer
->url();
1461 Q_EMIT
urlChanged(url
);
1464 void DolphinMainWindow::tabCountChanged(int count
)
1466 const bool enableTabActions
= (count
> 1);
1467 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1468 actionCollection()->action(QStringLiteral("activate_tab_%1").arg(i
))->setEnabled(enableTabActions
);
1470 actionCollection()->action(QStringLiteral("activate_last_tab"))->setEnabled(enableTabActions
);
1471 actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions
);
1472 actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions
);
1475 void DolphinMainWindow::updateWindowTitle()
1477 const QString newTitle
= m_activeViewContainer
->captionWindowTitle();
1478 if (windowTitle() != newTitle
) {
1479 setWindowTitle(newTitle
);
1483 void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString
& mountPath
)
1485 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1486 setViewsToHomeIfMountPathOpen(mountPath
);
1489 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectory().startsWith(mountPath
)) {
1490 m_tearDownFromPlacesRequested
= true;
1491 m_terminalPanel
->goHome();
1492 // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged
1494 m_placesPanel
->proceedWithTearDown();
1498 void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString
& mountPath
)
1500 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1501 setViewsToHomeIfMountPathOpen(mountPath
);
1504 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectory().startsWith(mountPath
)) {
1505 m_tearDownFromPlacesRequested
= false;
1506 m_terminalPanel
->goHome();
1510 void DolphinMainWindow::slotKeyBindings()
1512 KShortcutsDialog
dialog(KShortcutsEditor::AllActions
, KShortcutsEditor::LetterShortcutsAllowed
, this);
1513 dialog
.addCollection(actionCollection());
1514 if (m_terminalPanel
) {
1515 KActionCollection
*konsolePartActionCollection
= m_terminalPanel
->actionCollection();
1516 if (konsolePartActionCollection
) {
1517 dialog
.addCollection(konsolePartActionCollection
, QStringLiteral("KonsolePart"));
1523 void DolphinMainWindow::setViewsToHomeIfMountPathOpen(const QString
& mountPath
)
1525 const QVector
<DolphinViewContainer
*> theViewContainers
= viewContainers();
1526 for (DolphinViewContainer
*viewContainer
: theViewContainers
) {
1527 if (viewContainer
&& viewContainer
->url().toLocalFile().startsWith(mountPath
)) {
1528 viewContainer
->setUrl(QUrl::fromLocalFile(QDir::homePath()));
1531 disconnect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, nullptr, nullptr);
1534 void DolphinMainWindow::setupActions()
1536 auto hamburgerMenuAction
= KStandardAction::hamburgerMenu(nullptr, nullptr, actionCollection());
1538 // setup 'File' menu
1539 m_newFileMenu
= new DolphinNewFileMenu(actionCollection(), this);
1540 QMenu
* menu
= m_newFileMenu
->menu();
1541 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1542 menu
->setIcon(QIcon::fromTheme(QStringLiteral("list-add")));
1543 m_newFileMenu
->setPopupMode(QToolButton::InstantPopup
);
1544 connect(menu
, &QMenu::aboutToShow
,
1545 this, &DolphinMainWindow::updateNewMenu
);
1547 QAction
* newWindow
= KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow
, actionCollection());
1548 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1549 newWindow
->setToolTip(i18nc("@info", "Open a new Dolphin window"));
1550 newWindow
->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1551 "window just like this one with the current location and view."
1552 "<nl/>You can drag and drop items between windows."));
1553 newWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1555 QAction
* newTab
= actionCollection()->addAction(QStringLiteral("new_tab"));
1556 newTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1557 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1558 newTab
->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1559 "<emphasis>Tab</emphasis> with the current location and view.<nl/>"
1560 "A tab is an additional view within this window. "
1561 "You can drag and drop items between tabs."));
1562 actionCollection()->setDefaultShortcuts(newTab
, {Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
});
1563 connect(newTab
, &QAction::triggered
, this, &DolphinMainWindow::openNewActivatedTab
);
1565 QAction
* addToPlaces
= actionCollection()->addAction(QStringLiteral("add_to_places"));
1566 addToPlaces
->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new")));
1567 addToPlaces
->setText(i18nc("@action:inmenu Add current folder to places", "Add to Places"));
1568 addToPlaces
->setWhatsThis(xi18nc("@info:whatsthis", "This adds the selected folder "
1569 "to the Places panel."));
1570 connect(addToPlaces
, &QAction::triggered
, this, &DolphinMainWindow::addToPlaces
);
1572 QAction
* closeTab
= KStandardAction::close(m_tabWidget
, QOverload
<>::of(&DolphinTabWidget::closeTab
), actionCollection());
1573 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1574 closeTab
->setWhatsThis(i18nc("@info:whatsthis", "This closes the "
1575 "currently viewed tab. If no more tabs are left this window "
1576 "will close instead."));
1578 QAction
* quitAction
= KStandardAction::quit(this, &DolphinMainWindow::quit
, actionCollection());
1579 quitAction
->setWhatsThis(i18nc("@info:whatsthis quit", "This closes this window."));
1581 // setup 'Edit' menu
1582 KStandardAction::undo(this,
1583 &DolphinMainWindow::undo
,
1584 actionCollection());
1586 // i18n: This will be the last paragraph for the whatsthis for all three:
1587 // Cut, Copy and Paste
1588 const QString cutCopyPastePara
= xi18nc("@info:whatsthis", "<para><emphasis>Cut, "
1589 "Copy</emphasis> and <emphasis>Paste</emphasis> work between many "
1590 "applications and are among the most used commands. That's why their "
1591 "<emphasis>keyboard shortcuts</emphasis> are prominently placed right "
1592 "next to each other on the keyboard: <shortcut>Ctrl+X</shortcut>, "
1593 "<shortcut>Ctrl+C</shortcut> and <shortcut>Ctrl+V</shortcut>.</para>");
1594 QAction
* cutAction
= KStandardAction::cut(this, &DolphinMainWindow::cut
, actionCollection());
1595 m_actionTextHelper
->registerTextWhenNothingIsSelected(cutAction
, i18nc("@action", "Cut…"));
1596 cutAction
->setWhatsThis(xi18nc("@info:whatsthis cut", "This copies the items "
1597 "in your current selection to the <emphasis>clipboard</emphasis>.<nl/>"
1598 "Use the <emphasis>Paste</emphasis> action afterwards to copy them from "
1599 "the clipboard to a new location. The items will be removed from their "
1600 "initial location.") + cutCopyPastePara
);
1601 QAction
* copyAction
= KStandardAction::copy(this, &DolphinMainWindow::copy
, actionCollection());
1602 m_actionTextHelper
->registerTextWhenNothingIsSelected(copyAction
, i18nc("@action", "Copy…"));
1603 copyAction
->setWhatsThis(xi18nc("@info:whatsthis copy", "This copies the "
1604 "items in your current selection to the <emphasis>clipboard</emphasis>."
1605 "<nl/>Use the <emphasis>Paste</emphasis> action afterwards to copy them "
1606 "from the clipboard to a new location.") + cutCopyPastePara
);
1607 QAction
* paste
= KStandardAction::paste(this, &DolphinMainWindow::paste
, actionCollection());
1608 // The text of the paste-action is modified dynamically by Dolphin
1609 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1610 // due to the long text, the text "Paste" is used:
1611 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1612 paste
->setWhatsThis(xi18nc("@info:whatsthis paste", "This copies the items from "
1613 "your <emphasis>clipboard</emphasis> to the currently viewed folder.<nl/>"
1614 "If the items were added to the clipboard by the <emphasis>Cut</emphasis> "
1615 "action they are removed from their old location.") + cutCopyPastePara
);
1617 QAction
* copyToOtherViewAction
= actionCollection()->addAction(QStringLiteral("copy_to_inactive_split_view"));
1618 copyToOtherViewAction
->setText(i18nc("@action:inmenu", "Copy to Inactive Split View"));
1619 m_actionTextHelper
->registerTextWhenNothingIsSelected(copyToOtherViewAction
, i18nc("@action:inmenu", "Copy to Inactive Split View…"));
1620 copyToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Copy", "This copies the selected items from "
1621 "the <emphasis>active</emphasis> view to the inactive split view."));
1622 copyToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
1623 copyToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Copy to Inactive Split View"));
1624 actionCollection()->setDefaultShortcut(copyToOtherViewAction
, Qt::SHIFT
| Qt::Key_F5
);
1625 connect(copyToOtherViewAction
, &QAction::triggered
, this, &DolphinMainWindow::copyToInactiveSplitView
);
1627 QAction
* moveToOtherViewAction
= actionCollection()->addAction(QStringLiteral("move_to_inactive_split_view"));
1628 moveToOtherViewAction
->setText(i18nc("@action:inmenu", "Move to Inactive Split View"));
1629 m_actionTextHelper
->registerTextWhenNothingIsSelected(moveToOtherViewAction
, i18nc("@action:inmenu", "Move to Inactive Split View…"));
1630 moveToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Move", "This moves the selected items from "
1631 "the <emphasis>active</emphasis> view to the inactive split view."));
1632 moveToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-cut")));
1633 moveToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Move to Inactive Split View"));
1634 actionCollection()->setDefaultShortcut(moveToOtherViewAction
, Qt::SHIFT
| Qt::Key_F6
);
1635 connect(moveToOtherViewAction
, &QAction::triggered
, this, &DolphinMainWindow::moveToInactiveSplitView
);
1637 QAction
* showFilterBar
= actionCollection()->addAction(QStringLiteral("show_filter_bar"));
1638 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Filter..."));
1639 showFilterBar
->setToolTip(i18nc("@info:tooltip", "Show Filter Bar"));
1640 showFilterBar
->setWhatsThis(xi18nc("@info:whatsthis", "This opens the "
1641 "<emphasis>Filter Bar</emphasis> at the bottom of the window.<nl/> "
1642 "There you can enter a text to filter the files and folders currently displayed. "
1643 "Only those that contain the text in their name will be kept in view."));
1644 showFilterBar
->setIcon(QIcon::fromTheme(QStringLiteral("view-filter")));
1645 actionCollection()->setDefaultShortcuts(showFilterBar
, {Qt::CTRL
| Qt::Key_I
, Qt::Key_Slash
});
1646 connect(showFilterBar
, &QAction::triggered
, this, &DolphinMainWindow::showFilterBar
);
1648 // toggle_filter acts as a copy of the main showFilterBar to be used mainly
1649 // in the toolbar, with no default shortcut attached, to avoid messing with
1650 // existing workflows (filter bar always open and Ctrl-I to focus)
1651 QAction
*toggleFilter
= actionCollection()->addAction(QStringLiteral("toggle_filter"));
1652 toggleFilter
->setText(i18nc("@action:inmenu", "Toggle Filter Bar"));
1653 toggleFilter
->setIconText(i18nc("@action:intoolbar", "Filter"));
1654 toggleFilter
->setIcon(showFilterBar
->icon());
1655 toggleFilter
->setToolTip(showFilterBar
->toolTip());
1656 toggleFilter
->setWhatsThis(showFilterBar
->whatsThis());
1657 toggleFilter
->setCheckable(true);
1658 connect(toggleFilter
, &QAction::triggered
, this, &DolphinMainWindow::toggleFilterBar
);
1660 QAction
*searchAction
= KStandardAction::find(this, &DolphinMainWindow::find
, actionCollection());
1661 searchAction
->setText(i18n("Search..."));
1662 searchAction
->setToolTip(i18nc("@info:tooltip", "Search for files and folders"));
1663 searchAction
->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This helps you "
1664 "find files and folders by opening a <emphasis>find bar</emphasis>. "
1665 "There you can enter search terms and specify settings to find the "
1666 "objects you are looking for.</para><para>Use this help again on "
1667 "the find bar so we can have a look at it while the settings are "
1668 "explained.</para>"));
1670 // toggle_search acts as a copy of the main searchAction to be used mainly
1671 // in the toolbar, with no default shortcut attached, to avoid messing with
1672 // existing workflows (search bar always open and Ctrl-F to focus)
1673 QAction
*toggleSearchAction
= actionCollection()->addAction(QStringLiteral("toggle_search"));
1674 toggleSearchAction
->setText(i18nc("@action:inmenu", "Toggle Search Bar"));
1675 toggleSearchAction
->setIconText(i18nc("@action:intoolbar", "Search"));
1676 toggleSearchAction
->setIcon(searchAction
->icon());
1677 toggleSearchAction
->setToolTip(searchAction
->toolTip());
1678 toggleSearchAction
->setWhatsThis(searchAction
->whatsThis());
1679 toggleSearchAction
->setCheckable(true);
1681 QAction
*toggleSelectionModeAction
= actionCollection()->addAction(QStringLiteral("toggle_selection_mode"));
1682 // i18n: This action toggles a selection mode.
1683 toggleSelectionModeAction
->setText(i18nc("@action:inmenu", "Select Files and Folders"));
1684 // i18n: Opens a selection mode for selecting files/folders.
1685 // The text is kept so unspecific because it will be shown on the toolbar where space is at a premium.
1686 toggleSelectionModeAction
->setIconText(i18nc("@action:intoolbar", "Select"));
1687 toggleSelectionModeAction
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This application only knows which files or folders should be acted on if they are"
1688 " <emphasis>selected</emphasis> first. Press this to toggle a <emphasis>Selection Mode</emphasis> which makes selecting and deselecting as easy as "
1689 "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."
1691 toggleSelectionModeAction
->setIcon(QIcon::fromTheme(QStringLiteral("quickwizard")));
1692 toggleSelectionModeAction
->setCheckable(true);
1693 actionCollection()->setDefaultShortcut(toggleSelectionModeAction
, Qt::Key_Space
);
1694 connect(toggleSelectionModeAction
, &QAction::triggered
, this, &DolphinMainWindow::toggleSelectionMode
);
1696 // A special version of the toggleSelectionModeAction for the toolbar that also contains a menu
1697 // with the selectAllAction and invertSelectionAction.
1698 auto *toggleSelectionModeToolBarAction
= new KToolBarPopupAction(toggleSelectionModeAction
->icon(), toggleSelectionModeAction
->iconText(), actionCollection());
1699 toggleSelectionModeToolBarAction
->setToolTip(toggleSelectionModeAction
->text());
1700 toggleSelectionModeToolBarAction
->setWhatsThis(toggleSelectionModeAction
->whatsThis());
1701 actionCollection()->addAction(QStringLiteral("toggle_selection_mode_tool_bar"), toggleSelectionModeToolBarAction
);
1702 toggleSelectionModeToolBarAction
->setCheckable(true);
1703 toggleSelectionModeToolBarAction
->setPopupMode(QToolButton::DelayedPopup
);
1704 connect(toggleSelectionModeToolBarAction
, &QAction::triggered
, toggleSelectionModeAction
, &QAction::trigger
);
1705 connect(toggleSelectionModeAction
, &QAction::toggled
, toggleSelectionModeToolBarAction
, &QAction::setChecked
);
1707 QAction
* selectAllAction
= KStandardAction::selectAll(this, &DolphinMainWindow::selectAll
, actionCollection());
1708 selectAllAction
->setWhatsThis(xi18nc("@info:whatsthis", "This selects all "
1709 "files and folders in the current location."));
1711 QAction
* invertSelection
= actionCollection()->addAction(QStringLiteral("invert_selection"));
1712 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1713 invertSelection
->setWhatsThis(xi18nc("@info:whatsthis invert", "This selects all "
1714 "objects that you have currently <emphasis>not</emphasis> selected instead."));
1715 invertSelection
->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-invert")));
1716 actionCollection()->setDefaultShortcut(invertSelection
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1717 connect(invertSelection
, &QAction::triggered
, this, &DolphinMainWindow::invertSelection
);
1719 QMenu
*toggleSelectionModeActionMenu
= new QMenu(this);
1720 toggleSelectionModeActionMenu
->addAction(selectAllAction
);
1721 toggleSelectionModeActionMenu
->addAction(invertSelection
);
1722 toggleSelectionModeToolBarAction
->setMenu(toggleSelectionModeActionMenu
);
1724 // setup 'View' menu
1725 // (note that most of it is set up in DolphinViewActionHandler)
1727 QAction
* split
= actionCollection()->addAction(QStringLiteral("split_view"));
1728 split
->setWhatsThis(xi18nc("@info:whatsthis find", "<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 backShortcuts
.append(QKeySequence(Qt::Key_Backspace
));
1790 actionCollection()->setDefaultShortcuts(m_backAction
, backShortcuts
);
1792 DolphinRecentTabsMenu
* recentTabsMenu
= new DolphinRecentTabsMenu(this);
1793 actionCollection()->addAction(QStringLiteral("closed_tabs"), recentTabsMenu
);
1794 connect(m_tabWidget
, &DolphinTabWidget::rememberClosedTab
,
1795 recentTabsMenu
, &DolphinRecentTabsMenu::rememberClosedTab
);
1796 connect(recentTabsMenu
, &DolphinRecentTabsMenu::restoreClosedTab
,
1797 m_tabWidget
, &DolphinTabWidget::restoreClosedTab
);
1798 connect(recentTabsMenu
, &DolphinRecentTabsMenu::closedTabsCountChanged
,
1799 this, &DolphinMainWindow::closedTabsCountChanged
);
1801 QAction
* undoCloseTab
= actionCollection()->addAction(QStringLiteral("undo_close_tab"));
1802 undoCloseTab
->setText(i18nc("@action:inmenu File", "Undo close tab"));
1803 undoCloseTab
->setWhatsThis(i18nc("@info:whatsthis undo close tab",
1804 "This returns you to the previously closed tab."));
1805 actionCollection()->setDefaultShortcut(undoCloseTab
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_T
);
1806 undoCloseTab
->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo")));
1807 undoCloseTab
->setEnabled(false);
1808 connect(undoCloseTab
, &QAction::triggered
, recentTabsMenu
, &DolphinRecentTabsMenu::undoCloseTab
);
1810 auto undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
1811 undoAction
->setWhatsThis(xi18nc("@info:whatsthis", "This undoes "
1812 "the last change you made to files or folders.<nl/>"
1813 "Such changes include <interface>creating, renaming</interface> "
1814 "and <interface>moving</interface> them to a different location "
1815 "or to the <filename>Trash</filename>. <nl/>Changes that can't "
1816 "be undone will ask for your confirmation."));
1817 undoAction
->setEnabled(false); // undo should be disabled by default
1820 QScopedPointer
<QAction
> forwardAction(KStandardAction::forward(nullptr, nullptr, nullptr));
1821 m_forwardAction
= new KToolBarPopupAction(forwardAction
->icon(), forwardAction
->text(), actionCollection());
1822 m_forwardAction
->setObjectName(forwardAction
->objectName());
1823 m_forwardAction
->setShortcuts(forwardAction
->shortcuts());
1825 m_forwardAction
->setPopupMode(QToolButton::DelayedPopup
);
1826 connect(m_forwardAction
, &QAction::triggered
, this, &DolphinMainWindow::goForward
);
1827 connect(m_forwardAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowForwardPopupMenu
);
1828 connect(m_forwardAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoForward
);
1829 actionCollection()->addAction(m_forwardAction
->objectName(), m_forwardAction
);
1830 actionCollection()->setDefaultShortcuts(m_forwardAction
, m_forwardAction
->shortcuts());
1832 // enable middle-click to open in a new tab
1833 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
1834 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotBackForwardActionMiddleClicked
);
1835 m_backAction
->menu()->installEventFilter(middleClickEventFilter
);
1836 m_forwardAction
->menu()->installEventFilter(middleClickEventFilter
);
1837 KStandardAction::up(this, &DolphinMainWindow::goUp
, actionCollection());
1838 QAction
* homeAction
= KStandardAction::home(this, &DolphinMainWindow::goHome
, actionCollection());
1839 homeAction
->setWhatsThis(xi18nc("@info:whatsthis", "Go to your "
1840 "<filename>Home</filename> folder.<nl/>Every user account "
1841 "has their own <filename>Home</filename> that contains their data "
1842 "including folders that contain personal application data."));
1844 // setup 'Tools' menu
1845 QAction
* compareFiles
= actionCollection()->addAction(QStringLiteral("compare_files"));
1846 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1847 compareFiles
->setIcon(QIcon::fromTheme(QStringLiteral("kompare")));
1848 compareFiles
->setEnabled(false);
1849 connect(compareFiles
, &QAction::triggered
, this, &DolphinMainWindow::compareFiles
);
1851 QAction
* openPreferredSearchTool
= actionCollection()->addAction(QStringLiteral("open_preferred_search_tool"));
1852 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1853 openPreferredSearchTool
->setWhatsThis(xi18nc("@info:whatsthis",
1854 "<para>This opens a preferred search tool for the viewed location.</para>"
1855 "<para>Use <emphasis>More Search Tools</emphasis> menu to configure it.</para>"));
1856 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1857 actionCollection()->setDefaultShortcut(openPreferredSearchTool
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F
);
1858 connect(openPreferredSearchTool
, &QAction::triggered
, this, &DolphinMainWindow::openPreferredSearchTool
);
1860 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1861 QAction
* openTerminal
= actionCollection()->addAction(QStringLiteral("open_terminal"));
1862 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1863 openTerminal
->setWhatsThis(xi18nc("@info:whatsthis",
1864 "<para>This opens a <emphasis>terminal</emphasis> application for the viewed location.</para>"
1865 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1866 openTerminal
->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
1867 actionCollection()->setDefaultShortcut(openTerminal
, Qt::SHIFT
| Qt::Key_F4
);
1868 connect(openTerminal
, &QAction::triggered
, this, &DolphinMainWindow::openTerminal
);
1870 QAction
* openTerminalHere
= actionCollection()->addAction(QStringLiteral("open_terminal_here"));
1871 // i18n: "Here" refers to the location(s) of the currently selected item(s) or the currently viewed location if nothing is selected.
1872 openTerminalHere
->setText(i18nc("@action:inmenu Tools", "Open Terminal Here"));
1873 openTerminalHere
->setWhatsThis(xi18nc("@info:whatsthis",
1874 "<para>This opens <emphasis>terminal</emphasis> applications for the selected items' locations.</para>"
1875 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1876 openTerminalHere
->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
1877 actionCollection()->setDefaultShortcut(openTerminalHere
, Qt::SHIFT
| Qt::ALT
| Qt::Key_F4
);
1878 connect(openTerminalHere
, &QAction::triggered
, this, &DolphinMainWindow::openTerminalHere
);
1881 QAction
* focusTerminalPanel
= actionCollection()->addAction(QStringLiteral("focus_terminal_panel"));
1882 focusTerminalPanel
->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
1883 focusTerminalPanel
->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
1884 actionCollection()->setDefaultShortcut(focusTerminalPanel
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F4
);
1885 connect(focusTerminalPanel
, &QAction::triggered
, this, &DolphinMainWindow::focusTerminalPanel
);
1889 // setup 'Bookmarks' menu
1890 KActionMenu
*bookmarkMenu
= new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this);
1891 bookmarkMenu
->setIcon(QIcon::fromTheme(QStringLiteral("bookmarks")));
1892 // Make the toolbar button version work properly on click
1893 bookmarkMenu
->setPopupMode(QToolButton::InstantPopup
);
1894 m_bookmarkHandler
= new DolphinBookmarkHandler(this, actionCollection(), bookmarkMenu
->menu(), this);
1895 actionCollection()->addAction(QStringLiteral("bookmarks"), bookmarkMenu
);
1897 // setup 'Settings' menu
1898 KToggleAction
* showMenuBar
= KStandardAction::showMenubar(nullptr, nullptr, actionCollection());
1899 showMenuBar
->setWhatsThis(xi18nc("@info:whatsthis",
1900 "<para>This switches between having a <emphasis>Menubar</emphasis> "
1901 "and having a <interface>%1</interface> button. Both "
1902 "contain mostly the same actions and configuration options.</para>"
1903 "<para>The Menubar takes up more space but allows for fast and organised access to all "
1904 "actions an application has to offer.</para><para>The <interface>%1</interface> button "
1905 "is simpler and small which makes triggering advanced actions more time consuming.</para>", hamburgerMenuAction
->text().replace('&', "")));
1906 connect(showMenuBar
, &KToggleAction::triggered
, // Fixes #286822
1907 this, &DolphinMainWindow::toggleShowMenuBar
, Qt::QueuedConnection
);
1909 KToggleAction
* showStatusBar
= KStandardAction::showStatusbar(nullptr, nullptr, actionCollection());
1910 showStatusBar
->setChecked(GeneralSettings::showStatusBar());
1911 connect(GeneralSettings::self(), &GeneralSettings::showStatusBarChanged
, showStatusBar
, &KToggleAction::setChecked
);
1912 connect(showStatusBar
, &KToggleAction::triggered
, this, [this](bool checked
) {
1913 GeneralSettings::setShowStatusBar(checked
);
1917 KStandardAction::keyBindings(this, &DolphinMainWindow::slotKeyBindings
, actionCollection());
1918 KStandardAction::preferences(this, &DolphinMainWindow::editSettings
, actionCollection());
1920 // not in menu actions
1921 QList
<QKeySequence
> nextTabKeys
= KStandardShortcut::tabNext();
1922 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
1924 QList
<QKeySequence
> prevTabKeys
= KStandardShortcut::tabPrev();
1925 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
1927 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1928 QAction
* activateTab
= actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i
));
1929 activateTab
->setText(i18nc("@action:inmenu", "Activate Tab %1", i
+ 1));
1930 activateTab
->setEnabled(false);
1931 connect(activateTab
, &QAction::triggered
, this, [this, i
]() { m_tabWidget
->activateTab(i
); });
1933 // only add default shortcuts for the first 9 tabs regardless of MaxActivateTabShortcuts
1935 actionCollection()->setDefaultShortcut(activateTab
, QStringLiteral("Alt+%1").arg(i
+ 1));
1939 QAction
* activateLastTab
= actionCollection()->addAction(QStringLiteral("activate_last_tab"));
1940 activateLastTab
->setText(i18nc("@action:inmenu", "Activate Last Tab"));
1941 activateLastTab
->setEnabled(false);
1942 connect(activateLastTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateLastTab
);
1943 actionCollection()->setDefaultShortcut(activateLastTab
, Qt::ALT
| Qt::Key_0
);
1945 QAction
* activateNextTab
= actionCollection()->addAction(QStringLiteral("activate_next_tab"));
1946 activateNextTab
->setIconText(i18nc("@action:inmenu", "Next Tab"));
1947 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1948 activateNextTab
->setEnabled(false);
1949 connect(activateNextTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateNextTab
);
1950 actionCollection()->setDefaultShortcuts(activateNextTab
, nextTabKeys
);
1952 QAction
* activatePrevTab
= actionCollection()->addAction(QStringLiteral("activate_prev_tab"));
1953 activatePrevTab
->setIconText(i18nc("@action:inmenu", "Previous Tab"));
1954 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1955 activatePrevTab
->setEnabled(false);
1956 connect(activatePrevTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activatePrevTab
);
1957 actionCollection()->setDefaultShortcuts(activatePrevTab
, prevTabKeys
);
1960 QAction
* showTarget
= actionCollection()->addAction(QStringLiteral("show_target"));
1961 showTarget
->setText(i18nc("@action:inmenu", "Show Target"));
1962 showTarget
->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
1963 showTarget
->setEnabled(false);
1964 connect(showTarget
, &QAction::triggered
, this, &DolphinMainWindow::showTarget
);
1966 QAction
* openInNewTab
= actionCollection()->addAction(QStringLiteral("open_in_new_tab"));
1967 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1968 openInNewTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1969 connect(openInNewTab
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
1971 QAction
* openInNewTabs
= actionCollection()->addAction(QStringLiteral("open_in_new_tabs"));
1972 openInNewTabs
->setText(i18nc("@action:inmenu", "Open in New Tabs"));
1973 openInNewTabs
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1974 connect(openInNewTabs
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
1976 QAction
* openInNewWindow
= actionCollection()->addAction(QStringLiteral("open_in_new_window"));
1977 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1978 openInNewWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1979 connect(openInNewWindow
, &QAction::triggered
, this, &DolphinMainWindow::openInNewWindow
);
1982 void DolphinMainWindow::setupDockWidgets()
1984 const bool lock
= GeneralSettings::lockPanels();
1986 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(lock
);
1988 KDualAction
* lockLayoutAction
= actionCollection()->add
<KDualAction
>(QStringLiteral("lock_panels"));
1989 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1990 lockLayoutAction
->setActiveIcon(QIcon::fromTheme(QStringLiteral("object-unlocked")));
1991 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1992 lockLayoutAction
->setInactiveIcon(QIcon::fromTheme(QStringLiteral("object-locked")));
1993 lockLayoutAction
->setWhatsThis(xi18nc("@info:whatsthis", "This "
1994 "switches between having panels <emphasis>locked</emphasis> or "
1995 "<emphasis>unlocked</emphasis>.<nl/>Unlocked panels can be "
1996 "dragged to the other side of the window and have a close "
1997 "button.<nl/>Locked panels are embedded more cleanly."));
1998 lockLayoutAction
->setActive(lock
);
1999 connect(lockLayoutAction
, &KDualAction::triggered
, this, &DolphinMainWindow::togglePanelLockState
);
2001 // Setup "Information"
2002 DolphinDockWidget
* infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
2003 infoDock
->setLocked(lock
);
2004 infoDock
->setObjectName(QStringLiteral("infoDock"));
2005 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2008 InformationPanel
* infoPanel
= new InformationPanel(infoDock
);
2009 infoPanel
->setCustomContextMenuActions({lockLayoutAction
});
2010 connect(infoPanel
, &InformationPanel::urlActivated
, this, &DolphinMainWindow::handleUrl
);
2011 infoDock
->setWidget(infoPanel
);
2013 QAction
* infoAction
= infoDock
->toggleViewAction();
2014 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-information")), Qt::Key_F11
, infoAction
, QStringLiteral("show_information_panel"));
2016 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
2017 connect(this, &DolphinMainWindow::urlChanged
,
2018 infoPanel
, &InformationPanel::setUrl
);
2019 connect(this, &DolphinMainWindow::selectionChanged
,
2020 infoPanel
, &InformationPanel::setSelection
);
2021 connect(this, &DolphinMainWindow::requestItemInfo
,
2022 infoPanel
, &InformationPanel::requestDelayedItemInfo
);
2023 connect(this, &DolphinMainWindow::fileItemsChanged
,
2024 infoPanel
, &InformationPanel::slotFilesItemChanged
);
2027 // i18n: This is the last paragraph for the "What's This"-texts of all four panels.
2028 const QString panelWhatsThis
= xi18nc("@info:whatsthis", "<para>To show or "
2029 "hide panels like this go to <interface>Menu|Panels</interface> "
2030 "or <interface>View|Panels</interface>.</para>");
2032 actionCollection()->action(QStringLiteral("show_information_panel"))
2033 ->setWhatsThis(xi18nc("@info:whatsthis", "<para> This toggles the "
2034 "<emphasis>information</emphasis> panel at the right side of the "
2035 "window.</para><para>The panel provides in-depth information "
2036 "about the items your mouse is hovering over or about the selected "
2037 "items. Otherwise it informs you about the currently viewed folder.<nl/>"
2038 "For single items a preview of their contents is provided.</para>"));
2040 infoDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
2041 "provides in-depth information about the items your mouse is "
2042 "hovering over or about the selected items. Otherwise it informs "
2043 "you about the currently viewed folder.<nl/>For single items a "
2044 "preview of their contents is provided.</para><para>You can configure "
2045 "which and how details are given here by right-clicking.</para>") + panelWhatsThis
);
2048 DolphinDockWidget
* foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
2049 foldersDock
->setLocked(lock
);
2050 foldersDock
->setObjectName(QStringLiteral("foldersDock"));
2051 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2052 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
2053 foldersPanel
->setCustomContextMenuActions({lockLayoutAction
});
2054 foldersDock
->setWidget(foldersPanel
);
2056 QAction
* foldersAction
= foldersDock
->toggleViewAction();
2057 createPanelAction(QIcon::fromTheme(QStringLiteral("folder")), Qt::Key_F7
, foldersAction
, QStringLiteral("show_folders_panel"));
2059 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
2060 connect(this, &DolphinMainWindow::urlChanged
,
2061 foldersPanel
, &FoldersPanel::setUrl
);
2062 connect(foldersPanel
, &FoldersPanel::folderActivated
,
2063 this, &DolphinMainWindow::changeUrl
);
2064 connect(foldersPanel
, &FoldersPanel::folderInNewTab
,
2065 this, &DolphinMainWindow::openNewTab
);
2066 connect(foldersPanel
, &FoldersPanel::folderInNewActiveTab
,
2067 this, &DolphinMainWindow::openNewTabAndActivate
);
2068 connect(foldersPanel
, &FoldersPanel::errorMessage
,
2069 this, &DolphinMainWindow::showErrorMessage
);
2071 actionCollection()->action(QStringLiteral("show_folders_panel"))
2072 ->setWhatsThis(xi18nc("@info:whatsthis", "This toggles the "
2073 "<emphasis>folders</emphasis> panel at the left side of the window."
2074 "<nl/><nl/>It shows the folders of the <emphasis>file system"
2075 "</emphasis> in a <emphasis>tree view</emphasis>."));
2076 foldersDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
2077 "shows the folders of the <emphasis>file system</emphasis> in a "
2078 "<emphasis>tree view</emphasis>.</para><para>Click a folder to go "
2079 "there. Click the arrow to the left of a folder to see its subfolders. "
2080 "This allows quick switching between any folders.</para>") + panelWhatsThis
);
2084 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
2085 DolphinDockWidget
* terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
2086 terminalDock
->setLocked(lock
);
2087 terminalDock
->setObjectName(QStringLiteral("terminalDock"));
2088 m_terminalPanel
= new TerminalPanel(terminalDock
);
2089 m_terminalPanel
->setCustomContextMenuActions({lockLayoutAction
});
2090 terminalDock
->setWidget(m_terminalPanel
);
2092 connect(m_terminalPanel
, &TerminalPanel::hideTerminalPanel
, terminalDock
, &DolphinDockWidget::hide
);
2093 connect(m_terminalPanel
, &TerminalPanel::changeUrl
, this, &DolphinMainWindow::slotTerminalDirectoryChanged
);
2094 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
,
2095 m_terminalPanel
, &TerminalPanel::dockVisibilityChanged
);
2096 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
,
2097 this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged
);
2099 QAction
* terminalAction
= terminalDock
->toggleViewAction();
2100 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-scripts")), Qt::Key_F4
, terminalAction
, QStringLiteral("show_terminal_panel"));
2102 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
2103 connect(this, &DolphinMainWindow::urlChanged
,
2104 m_terminalPanel
, &TerminalPanel::setUrl
);
2106 if (GeneralSettings::version() < 200) {
2107 terminalDock
->hide();
2110 actionCollection()->action(QStringLiteral("show_terminal_panel"))
2111 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
2112 "<emphasis>terminal</emphasis> panel at the bottom of the window."
2113 "<nl/>The location in the terminal will always match the folder "
2114 "view so you can navigate using either.</para><para>The terminal "
2115 "panel is not needed for basic computer usage but can be useful "
2116 "for advanced tasks. To learn more about terminals use the help "
2117 "in a standalone terminal application like Konsole.</para>"));
2118 terminalDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is "
2119 "the <emphasis>terminal</emphasis> panel. It behaves like a "
2120 "normal terminal but will match the location of the folder view "
2121 "so you can navigate using either.</para><para>The terminal panel "
2122 "is not needed for basic computer usage but can be useful for "
2123 "advanced tasks. To learn more about terminals use the help in a "
2124 "standalone terminal application like Konsole.</para>") + panelWhatsThis
);
2128 if (GeneralSettings::version() < 200) {
2130 foldersDock
->hide();
2134 DolphinDockWidget
* placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
2135 placesDock
->setLocked(lock
);
2136 placesDock
->setObjectName(QStringLiteral("placesDock"));
2137 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2139 m_placesPanel
= new PlacesPanel(placesDock
);
2140 m_placesPanel
->setCustomContextMenuActions({lockLayoutAction
});
2141 placesDock
->setWidget(m_placesPanel
);
2143 QAction
*placesAction
= placesDock
->toggleViewAction();
2144 createPanelAction(QIcon::fromTheme(QStringLiteral("compass")), Qt::Key_F9
, placesAction
, QStringLiteral("show_places_panel"));
2146 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
2147 connect(m_placesPanel
, &PlacesPanel::placeActivated
,
2148 this, &DolphinMainWindow::slotPlaceActivated
);
2149 connect(m_placesPanel
, &PlacesPanel::tabRequested
,
2150 this, &DolphinMainWindow::openNewTab
);
2151 connect(m_placesPanel
, &PlacesPanel::activeTabRequested
,
2152 this, &DolphinMainWindow::openNewTabAndActivate
);
2153 connect(m_placesPanel
, &PlacesPanel::newWindowRequested
, this, [this](const QUrl
&url
) {
2154 Dolphin::openNewWindow({url
}, this);
2156 connect(m_placesPanel
, &PlacesPanel::errorMessage
,
2157 this, &DolphinMainWindow::showErrorMessage
);
2158 connect(this, &DolphinMainWindow::urlChanged
,
2159 m_placesPanel
, &PlacesPanel::setUrl
);
2160 connect(placesDock
, &DolphinDockWidget::visibilityChanged
,
2161 &DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged
);
2162 connect(this, &DolphinMainWindow::settingsChanged
,
2163 m_placesPanel
, &PlacesPanel::readSettings
);
2164 connect(m_placesPanel
, &PlacesPanel::storageTearDownRequested
,
2165 this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested
);
2166 connect(m_placesPanel
, &PlacesPanel::storageTearDownExternallyRequested
,
2167 this, &DolphinMainWindow::slotStorageTearDownExternallyRequested
);
2168 DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged(m_placesPanel
->isVisible());
2170 auto actionShowAllPlaces
= new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this);
2171 actionShowAllPlaces
->setCheckable(true);
2172 actionShowAllPlaces
->setDisabled(true);
2173 actionShowAllPlaces
->setWhatsThis(i18nc("@info:whatsthis", "This displays "
2174 "all places in the places panel that have been hidden. They will "
2175 "appear semi-transparent unless you uncheck their hide property."));
2177 connect(actionShowAllPlaces
, &QAction::triggered
, this, [actionShowAllPlaces
, this](bool checked
){
2178 m_placesPanel
->setShowAll(checked
);
2180 connect(m_placesPanel
, &PlacesPanel::allPlacesShownChanged
, actionShowAllPlaces
, &QAction::setChecked
);
2182 actionCollection()->action(QStringLiteral("show_places_panel"))
2183 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
2184 "<emphasis>places</emphasis> panel at the left side of the window."
2185 "</para><para>It allows you to go to locations you have "
2186 "bookmarked and to access disk or media attached to the computer "
2187 "or to the network. It also contains sections to find recently "
2188 "saved files or files of a certain type.</para>"));
2189 placesDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2190 "<emphasis>Places</emphasis> panel. It allows you to go to locations "
2191 "you have bookmarked and to access disk or media attached to the "
2192 "computer or to the network. It also contains sections to find "
2193 "recently saved files or files of a certain type.</para><para>"
2194 "Click on an entry to go there. Click with the right mouse button "
2195 "instead to open any entry in a new tab or new window.</para>"
2196 "<para>New entries can be added by dragging folders onto this panel. "
2197 "Right-click any section or entry to hide it. Right-click an empty "
2198 "space on this panel and select <interface>Show Hidden Places"
2199 "</interface> to display it again.</para>") + panelWhatsThis
);
2201 // Add actions into the "Panels" menu
2202 KActionMenu
* panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Show Panels"), this);
2203 actionCollection()->addAction(QStringLiteral("panels"), panelsMenu
);
2204 panelsMenu
->setIcon(QIcon::fromTheme(QStringLiteral("view-sidetree")));
2205 panelsMenu
->setPopupMode(QToolButton::InstantPopup
);
2206 const KActionCollection
* ac
= actionCollection();
2207 panelsMenu
->addAction(ac
->action(QStringLiteral("show_places_panel")));
2209 panelsMenu
->addAction(ac
->action(QStringLiteral("show_information_panel")));
2211 panelsMenu
->addAction(ac
->action(QStringLiteral("show_folders_panel")));
2212 panelsMenu
->addAction(ac
->action(QStringLiteral("show_terminal_panel")));
2213 panelsMenu
->addSeparator();
2214 panelsMenu
->addAction(actionShowAllPlaces
);
2215 panelsMenu
->addAction(lockLayoutAction
);
2217 connect(panelsMenu
->menu(), &QMenu::aboutToShow
, this, [actionShowAllPlaces
, this]{
2218 actionShowAllPlaces
->setEnabled(DolphinPlacesModelSingleton::instance().placesModel()->hiddenCount());
2223 void DolphinMainWindow::updateFileAndEditActions()
2225 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
2226 const KActionCollection
* col
= actionCollection();
2227 KFileItemListProperties
capabilitiesSource(list
);
2229 QAction
* renameAction
= col
->action(KStandardAction::name(KStandardAction::RenameFile
));
2230 QAction
* moveToTrashAction
= col
->action(KStandardAction::name(KStandardAction::MoveToTrash
));
2231 QAction
* deleteAction
= col
->action(KStandardAction::name(KStandardAction::DeleteFile
));
2232 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
2233 QAction
* duplicateAction
= col
->action(QStringLiteral("duplicate")); // see DolphinViewActionHandler
2234 QAction
* addToPlacesAction
= col
->action(QStringLiteral("add_to_places"));
2235 QAction
* copyToOtherViewAction
= col
->action(QStringLiteral("copy_to_inactive_split_view"));
2236 QAction
* moveToOtherViewAction
= col
->action(QStringLiteral("move_to_inactive_split_view"));
2237 QAction
* copyLocation
= col
->action(QString("copy_location"));
2239 if (list
.isEmpty()) {
2240 stateChanged(QStringLiteral("has_no_selection"));
2242 // All actions that need a selection to function can be enabled because they should trigger selection mode.
2243 renameAction
->setEnabled(true);
2244 moveToTrashAction
->setEnabled(true);
2245 deleteAction
->setEnabled(true);
2246 cutAction
->setEnabled(true);
2247 duplicateAction
->setEnabled(true);
2248 addToPlacesAction
->setEnabled(true);
2249 copyLocation
->setEnabled(true);
2250 // Them triggering selection mode and not directly acting on selected items is signified by adding "…" to their text.
2251 m_actionTextHelper
->textsWhenNothingIsSelectedEnabled(true);
2254 m_actionTextHelper
->textsWhenNothingIsSelectedEnabled(false);
2255 stateChanged(QStringLiteral("has_selection"));
2257 QAction
* deleteWithTrashShortcut
= col
->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
2258 QAction
* showTarget
= col
->action(QStringLiteral("show_target"));
2260 if (list
.length() == 1 && list
.first().isDir()) {
2261 addToPlacesAction
->setEnabled(true);
2263 addToPlacesAction
->setEnabled(false);
2266 const bool enableMoveToTrash
= capabilitiesSource
.isLocal() && capabilitiesSource
.supportsMoving();
2268 renameAction
->setEnabled(capabilitiesSource
.supportsMoving());
2269 moveToTrashAction
->setEnabled(enableMoveToTrash
);
2270 deleteAction
->setEnabled(capabilitiesSource
.supportsDeleting());
2271 deleteWithTrashShortcut
->setEnabled(capabilitiesSource
.supportsDeleting() && !enableMoveToTrash
);
2272 cutAction
->setEnabled(capabilitiesSource
.supportsMoving());
2273 copyLocation
->setEnabled(list
.length() == 1);
2274 showTarget
->setEnabled(list
.length() == 1 && list
.at(0).isLink());
2275 duplicateAction
->setEnabled(capabilitiesSource
.supportsWriting());
2278 if (m_tabWidget
->currentTabPage()->splitViewEnabled()) {
2279 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
2280 KFileItem capabilitiesDestination
;
2282 if (tabPage
->primaryViewActive()) {
2283 capabilitiesDestination
= tabPage
->secondaryViewContainer()->url();
2285 capabilitiesDestination
= tabPage
->primaryViewContainer()->url();
2288 copyToOtherViewAction
->setEnabled(capabilitiesDestination
.isWritable());
2289 moveToOtherViewAction
->setEnabled((list
.isEmpty() || capabilitiesSource
.supportsMoving()) && capabilitiesDestination
.isWritable());
2291 copyToOtherViewAction
->setEnabled(false);
2292 moveToOtherViewAction
->setEnabled(false);
2296 void DolphinMainWindow::updateViewActions()
2298 m_actionHandler
->updateViewActions();
2300 QAction
* toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
2301 toggleFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
2303 updateSplitAction();
2306 void DolphinMainWindow::updateGoActions()
2308 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
2309 const QUrl currentUrl
= m_activeViewContainer
->url();
2310 // I think this is one of the best places to firstly be confronted
2311 // with a file system and its hierarchy. Talking about the root
2312 // directory might seem too much here but it is the question that
2313 // naturally arises in this context.
2314 goUpAction
->setWhatsThis(xi18nc("@info:whatsthis", "<para>Go to "
2315 "the folder that contains the currently viewed one.</para>"
2316 "<para>All files and folders are organized in a hierarchical "
2317 "<emphasis>file system</emphasis>. At the top of this hierarchy is "
2318 "a directory that contains all data connected to this computer"
2319 "—the <emphasis>root directory</emphasis>.</para>"));
2320 goUpAction
->setEnabled(KIO::upUrl(currentUrl
) != currentUrl
);
2323 void DolphinMainWindow::refreshViews()
2325 m_tabWidget
->refreshViews();
2327 if (GeneralSettings::modifiedStartupSettings()) {
2328 updateWindowTitle();
2331 Q_EMIT
settingsChanged();
2334 void DolphinMainWindow::clearStatusBar()
2336 m_activeViewContainer
->statusBar()->resetToDefaultText();
2339 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
2341 connect(container
, &DolphinViewContainer::showFilterBarChanged
,
2342 this, &DolphinMainWindow::updateFilterBarAction
);
2343 connect(container
, &DolphinViewContainer::writeStateChanged
,
2344 this, &DolphinMainWindow::slotWriteStateChanged
);
2345 connect(container
, &DolphinViewContainer::searchModeEnabledChanged
,
2346 this, &DolphinMainWindow::updateSearchAction
);
2347 connect(container
, &DolphinViewContainer::captionChanged
,
2348 this, &DolphinMainWindow::updateWindowTitle
);
2349 connect(container
, &DolphinViewContainer::tabRequested
,
2350 this, &DolphinMainWindow::openNewTab
);
2351 connect(container
, &DolphinViewContainer::activeTabRequested
,
2352 this, &DolphinMainWindow::openNewTabAndActivate
);
2354 const QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
2355 connect(toggleSearchAction
, &QAction::triggered
, container
, &DolphinViewContainer::setSearchModeEnabled
);
2357 // Make the toggled state of the selection mode actions visually follow the selection mode state of the view.
2358 auto toggleSelectionModeAction
= actionCollection()->action(QStringLiteral("toggle_selection_mode"));
2359 toggleSelectionModeAction
->setChecked(m_activeViewContainer
->isSelectionModeEnabled());
2360 connect(m_activeViewContainer
, &DolphinViewContainer::selectionModeChanged
,
2361 toggleSelectionModeAction
, &QAction::setChecked
);
2363 const DolphinView
* view
= container
->view();
2364 connect(view
, &DolphinView::selectionChanged
,
2365 this, &DolphinMainWindow::slotSelectionChanged
);
2366 connect(view
, &DolphinView::requestItemInfo
,
2367 this, &DolphinMainWindow::requestItemInfo
);
2368 connect(view
, &DolphinView::fileItemsChanged
,
2369 this, &DolphinMainWindow::fileItemsChanged
);
2370 connect(view
, &DolphinView::tabRequested
,
2371 this, &DolphinMainWindow::openNewTab
);
2372 connect(view
, &DolphinView::activeTabRequested
,
2373 this, &DolphinMainWindow::openNewTabAndActivate
);
2374 connect(view
, &DolphinView::windowRequested
,
2375 this, &DolphinMainWindow::openNewWindow
);
2376 connect(view
, &DolphinView::requestContextMenu
,
2377 this, &DolphinMainWindow::openContextMenu
);
2378 connect(view
, &DolphinView::directoryLoadingStarted
,
2379 this, &DolphinMainWindow::enableStopAction
);
2380 connect(view
, &DolphinView::directoryLoadingCompleted
,
2381 this, &DolphinMainWindow::disableStopAction
);
2382 connect(view
, &DolphinView::directoryLoadingCompleted
,
2383 this, &DolphinMainWindow::slotDirectoryLoadingCompleted
);
2384 connect(view
, &DolphinView::goBackRequested
,
2385 this, &DolphinMainWindow::goBack
);
2386 connect(view
, &DolphinView::goForwardRequested
,
2387 this, &DolphinMainWindow::goForward
);
2388 connect(view
, &DolphinView::urlActivated
,
2389 this, &DolphinMainWindow::handleUrl
);
2390 connect(view
, &DolphinView::goUpRequested
,
2391 this, &DolphinMainWindow::goUp
);
2393 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::urlChanged
,
2394 this, &DolphinMainWindow::changeUrl
);
2395 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::historyChanged
,
2396 this, &DolphinMainWindow::updateHistory
);
2398 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
2399 (actionCollection()->action(QStringLiteral("url_navigators")));
2400 const KUrlNavigator
*navigator
= m_tabWidget
->currentTabPage()->primaryViewActive() ?
2401 navigators
->primaryUrlNavigator() :
2402 navigators
->secondaryUrlNavigator();
2404 QAction
*editableLocactionAction
= actionCollection()->action(QStringLiteral("editable_location"));
2405 editableLocactionAction
->setChecked(navigator
->isUrlEditable());
2406 connect(navigator
, &KUrlNavigator::editableStateChanged
,
2407 this, &DolphinMainWindow::slotEditableStateChanged
);
2408 connect(navigator
, &KUrlNavigator::tabRequested
,
2409 this, &DolphinMainWindow::openNewTab
);
2410 connect(navigator
, &KUrlNavigator::activeTabRequested
,
2411 this, &DolphinMainWindow::openNewTabAndActivate
);
2412 connect(navigator
, &KUrlNavigator::newWindowRequested
,
2413 this, &DolphinMainWindow::openNewWindow
);
2417 void DolphinMainWindow::updateSplitAction()
2419 QAction
* splitAction
= actionCollection()->action(QStringLiteral("split_view"));
2420 const DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
2421 if (tabPage
->splitViewEnabled()) {
2422 if (GeneralSettings::closeActiveSplitView() ? tabPage
->primaryViewActive() : !tabPage
->primaryViewActive()) {
2423 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2424 splitAction
->setToolTip(i18nc("@info", "Close left view"));
2425 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close")));
2427 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2428 splitAction
->setToolTip(i18nc("@info", "Close right view"));
2429 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close")));
2432 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2433 splitAction
->setToolTip(i18nc("@info", "Split view"));
2434 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
2438 void DolphinMainWindow::updateAllowedToolbarAreas()
2440 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
2441 (actionCollection()->action(QStringLiteral("url_navigators")));
2442 if (toolBar()->actions().contains(navigators
)) {
2443 toolBar()->setAllowedAreas(Qt::TopToolBarArea
| Qt::BottomToolBarArea
);
2444 if (toolBarArea(toolBar()) == Qt::LeftToolBarArea
||
2445 toolBarArea(toolBar()) == Qt::RightToolBarArea
) {
2446 addToolBar(Qt::TopToolBarArea
, toolBar());
2449 toolBar()->setAllowedAreas(Qt::AllToolBarAreas
);
2453 bool DolphinMainWindow::isKompareInstalled() const
2455 static bool initialized
= false;
2456 static bool installed
= false;
2458 // TODO: maybe replace this approach later by using a menu
2459 // plugin like kdiff3plugin.cpp
2460 installed
= !QStandardPaths::findExecutable(QStringLiteral("kompare")).isEmpty();
2466 void DolphinMainWindow::createPanelAction(const QIcon
& icon
,
2467 const QKeySequence
& shortcut
,
2468 QAction
* dockAction
,
2469 const QString
& actionName
)
2471 QAction
* panelAction
= actionCollection()->addAction(actionName
);
2472 panelAction
->setCheckable(true);
2473 panelAction
->setChecked(dockAction
->isChecked());
2474 panelAction
->setText(dockAction
->text());
2475 panelAction
->setIcon(icon
);
2476 dockAction
->setIcon(icon
);
2477 actionCollection()->setDefaultShortcut(panelAction
, shortcut
);
2479 connect(panelAction
, &QAction::triggered
, dockAction
, &QAction::trigger
);
2480 connect(dockAction
, &QAction::toggled
, panelAction
, &QAction::setChecked
);
2483 void DolphinMainWindow::setupWhatsThis()
2486 menuBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2487 "<emphasis>Menubar</emphasis>. It provides access to commands and "
2488 "configuration options. Left-click on any of the menus on this "
2489 "bar to see its contents.</para><para>The Menubar can be hidden "
2490 "by unchecking <interface>Settings|Show Menubar</interface>. Then "
2491 "most of its contents become available through a <interface>Menu"
2492 "</interface> button on the <emphasis>Toolbar</emphasis>.</para>"));
2493 toolBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2494 "<emphasis>Toolbar</emphasis>. It allows quick access to "
2495 "frequently used actions.</para><para>It is highly customizable. "
2496 "All items you see in the <interface>Menu</interface> or "
2497 "in the <interface>Menubar</interface> can be placed on the "
2498 "Toolbar. Just right-click on it and select <interface>Configure "
2499 "Toolbars…</interface> or find this action within the <interface>"
2501 "</para><para>The location of the bar and the style of its "
2502 "buttons can also be changed in the right-click menu. Right-click "
2503 "a button if you want to show or hide its text.</para>"));
2504 m_tabWidget
->setWhatsThis(xi18nc("@info:whatsthis main view",
2505 "<para>Here you can see the <emphasis>folders</emphasis> and "
2506 "<emphasis>files</emphasis> that are at the location described in "
2507 "the <interface>Location Bar</interface> above. This area is the "
2508 "central part of this application where you navigate to the files "
2509 "you want to use.</para><para>For an elaborate and general "
2510 "introduction to this application <link "
2511 "url='https://userbase.kde.org/Dolphin/File_Management#Introduction_to_Dolphin'>"
2512 "click here</link>. This will open an introductory article from "
2513 "the <emphasis>KDE UserBase Wiki</emphasis>.</para><para>For brief "
2514 "explanations of all the features of this <emphasis>view</emphasis> "
2515 "<link url='help:/dolphin/dolphin-view.html'>click here</link> "
2516 "instead. This will open a page from the <emphasis>Handbook"
2517 "</emphasis> that covers the basics.</para>"));
2520 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings
))
2521 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window "
2522 "that lists the <emphasis>keyboard shortcuts</emphasis>.<nl/>"
2523 "There you can set up key combinations to trigger an action when "
2524 "they are pressed simultaneously. All commands in this application can "
2525 "be triggered this way.</para>"));
2526 actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars
))
2527 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window in which "
2528 "you can change which buttons appear on the <emphasis>Toolbar</emphasis>.</para>"
2529 "<para>All items you see in the <interface>Menu</interface> can also be placed on the Toolbar.</para>"));
2530 actionCollection()->action(KStandardAction::name(KStandardAction::Preferences
))
2531 ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window where you can "
2532 "change a multitude of settings for this application. For an explanation "
2533 "of the various settings go to the chapter <emphasis>Configuring Dolphin"
2534 "</emphasis> in <interface>Help|Dolphin Handbook</interface>."));
2538 // i18n: If the external link isn't available in your language it might make
2539 // sense to state the external link's language in brackets to not
2540 // frustrate the user. If there are multiple languages that the user might
2541 // know with a reasonable chance you might want to have 2 external links.
2542 // The same might be true for any external link you translate.
2543 actionCollection()->action(KStandardAction::name(KStandardAction::HelpContents
))->setWhatsThis(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>"));
2544 // (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 )
2546 actionCollection()->action(KStandardAction::name(KStandardAction::WhatsThis
))->setWhatsThis(
2547 xi18nc("@info:whatsthis whatsthis button",
2548 "<para>This is the button that invokes the help feature you are "
2549 "using right now! Click it, then click any component of this "
2550 "application to ask \"What's this?\" about it. The mouse cursor "
2551 "will change appearance if no help is available for a spot.</para>"
2552 "<para>There are two other ways to get help: "
2553 "The <link url='help:/dolphin/index.html'>Dolphin Handbook</link> and "
2554 "the <link url='https://userbase.kde.org/Dolphin/File_Management'>KDE "
2555 "UserBase Wiki</link>.</para><para>The \"What's this?\" help is "
2556 "missing in most other windows so don't get too used to this.</para>"));
2558 actionCollection()->action(KStandardAction::name(KStandardAction::ReportBug
))->setWhatsThis(
2559 xi18nc("@info:whatsthis","<para>This opens a "
2560 "window that will guide you through reporting errors or flaws "
2561 "in this application or in other KDE software.</para>"
2562 "<para>High-quality bug reports are much appreciated. To learn "
2563 "how to make your bug report as effective as possible "
2564 "<link url='https://community.kde.org/Get_Involved/Bug_Reporting'>"
2565 "click here</link>.</para>"));
2567 actionCollection()->action(KStandardAction::name(KStandardAction::Donate
))->setWhatsThis(
2568 xi18nc("@info:whatsthis", "<para>This opens a "
2569 "<emphasis>web page</emphasis> where you can donate to "
2570 "support the continued work on this application and many "
2571 "other projects by the <emphasis>KDE</emphasis> community.</para>"
2572 "<para>Donating is the easiest and fastest way to efficiently "
2573 "support KDE and its projects. KDE projects are available for "
2574 "free therefore your donation is needed to cover things that "
2575 "require money like servers, contributor meetings, etc.</para>"
2576 "<para><emphasis>KDE e.V.</emphasis> is the non-profit "
2577 "organization behind the KDE community.</para>"));
2579 actionCollection()->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
))->setWhatsThis(
2580 xi18nc("@info:whatsthis",
2581 "With this you can change the language this application uses."
2582 "<nl/>You can even set secondary languages which will be used "
2583 "if texts are not available in your preferred language."));
2585 actionCollection()->action(KStandardAction::name(KStandardAction::AboutApp
))->setWhatsThis(
2586 xi18nc("@info:whatsthis","This opens a "
2587 "window that informs you about the version, license, "
2588 "used libraries and maintainers of this application."));
2590 actionCollection()->action(KStandardAction::name(KStandardAction::AboutKDE
))->setWhatsThis(
2591 xi18nc("@info:whatsthis","This opens a "
2592 "window with information about <emphasis>KDE</emphasis>. "
2593 "The KDE community are the people behind this free software."
2594 "<nl/>If you like using this application but don't know "
2595 "about KDE or want to see a cute dragon have a look!"));
2598 bool DolphinMainWindow::addHamburgerMenuToToolbar()
2600 QDomDocument domDocument
= KXMLGUIClient::domDocument();
2601 if (domDocument
.isNull()) {
2604 QDomNode toolbar
= domDocument
.elementsByTagName(QStringLiteral("ToolBar")).at(0);
2605 if (toolbar
.isNull()) {
2609 QDomElement hamburgerMenuElement
= domDocument
.createElement(QStringLiteral("Action"));
2610 hamburgerMenuElement
.setAttribute(QStringLiteral("name"), QStringLiteral("hamburger_menu"));
2611 toolbar
.appendChild(hamburgerMenuElement
);
2613 KXMLGUIFactory::saveConfigFile(domDocument
, xmlFile());
2617 // Make sure to also remove the <KXMLGUIFactory> and <QDomDocument> include
2618 // whenever this method is removed (maybe in the year ~2026).
2621 // Set a sane initial window size
2622 QSize
DolphinMainWindow::sizeHint() const
2624 return KXmlGuiWindow::sizeHint().expandedTo(QSize(760, 550));
2627 void DolphinMainWindow::saveNewToolbarConfig()
2629 KXmlGuiWindow::saveNewToolbarConfig(); // Applies the new config. This has to be called first
2630 // because the rest of this method decides things
2631 // based on the new config.
2632 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
2633 (actionCollection()->action(QStringLiteral("url_navigators")));
2634 if (!toolBar()->actions().contains(navigators
)) {
2635 m_tabWidget
->currentTabPage()->insertNavigatorsWidget(navigators
);
2637 updateAllowedToolbarAreas();
2638 (static_cast<KHamburgerMenu
*>(actionCollection()->action(KStandardAction::name(
2639 KStandardAction::HamburgerMenu
))))->hideActionsOf(toolBar());
2642 void DolphinMainWindow::focusTerminalPanel()
2644 if (m_terminalPanel
->isVisible()) {
2645 if (m_terminalPanel
->terminalHasFocus()) {
2646 m_activeViewContainer
->view()->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2647 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2649 m_terminalPanel
->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2650 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2653 actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger();
2654 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2658 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
2659 KIO::FileUndoManager::UiInterface()
2663 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2667 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
2669 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2671 DolphinViewContainer
* container
= mainWin
->activeViewContainer();
2672 container
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
2674 KIO::FileUndoManager::UiInterface::jobError(job
);
2678 bool DolphinMainWindow::isUrlOpen(const QString
&url
)
2680 return m_tabWidget
->isUrlOpen(QUrl::fromUserInput(url
));
2683 bool DolphinMainWindow::isUrlOrParentOpen(const QString
&url
)
2685 return m_tabWidget
->isUrlOrParentOpen(QUrl::fromUserInput(url
));