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 <kwidgetsaddons_version.h>
74 #include <kio_version.h>
76 #include <QApplication>
78 #include <QCloseEvent>
79 #include <QDesktopServices>
81 #include <QDomDocument>
85 #include <QPushButton>
87 #include <QStandardPaths>
89 #include <QToolButton>
92 // Used for GeneralSettings::version() to determine whether
93 // an updated version of Dolphin is running, so as to migrate
94 // removed/renamed ...etc config entries; increment it in such
96 const int CurrentDolphinVersion
= 202;
97 // The maximum number of entries in the back/forward popup menu
98 const int MaxNumberOfNavigationentries
= 12;
99 // The maximum number of "Activate Tab" shortcuts
100 const int MaxActivateTabShortcuts
= 9;
103 DolphinMainWindow::DolphinMainWindow() :
104 KXmlGuiWindow(nullptr),
105 m_newFileMenu(nullptr),
106 m_tabWidget(nullptr),
107 m_activeViewContainer(nullptr),
108 m_actionHandler(nullptr),
109 m_remoteEncoding(nullptr),
111 m_bookmarkHandler(nullptr),
112 m_lastHandleUrlOpenJob(nullptr),
113 m_terminalPanel(nullptr),
114 m_placesPanel(nullptr),
115 m_tearDownFromPlacesRequested(false),
116 m_backAction(nullptr),
117 m_forwardAction(nullptr)
119 Q_INIT_RESOURCE(dolphin
);
121 new MainWindowAdaptor(this);
124 setWindowFlags(Qt::WindowContextHelpButtonHint
);
126 setComponentName(QStringLiteral("dolphin"), QGuiApplication::applicationDisplayName());
127 setObjectName(QStringLiteral("Dolphin#"));
129 setStateConfigGroup("State");
131 connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::errorMessage
,
132 this, &DolphinMainWindow::showErrorMessage
);
134 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
135 undoManager
->setUiInterface(new UndoUiInterface());
137 connect(undoManager
, &KIO::FileUndoManager::undoAvailable
,
138 this, &DolphinMainWindow::slotUndoAvailable
);
139 connect(undoManager
, &KIO::FileUndoManager::undoTextChanged
,
140 this, &DolphinMainWindow::slotUndoTextChanged
);
141 connect(undoManager
, &KIO::FileUndoManager::jobRecordingStarted
,
142 this, &DolphinMainWindow::clearStatusBar
);
143 connect(undoManager
, &KIO::FileUndoManager::jobRecordingFinished
,
144 this, &DolphinMainWindow::showCommand
);
146 const bool firstRun
= (GeneralSettings::version() < 200);
148 GeneralSettings::setViewPropsTimestamp(QDateTime::currentDateTime());
151 setAcceptDrops(true);
153 auto *navigatorsWidgetAction
= new DolphinNavigatorsWidgetAction(this);
154 actionCollection()->addAction(QStringLiteral("url_navigators"), navigatorsWidgetAction
);
155 m_tabWidget
= new DolphinTabWidget(navigatorsWidgetAction
, this);
156 m_tabWidget
->setObjectName("tabWidget");
157 connect(m_tabWidget
, &DolphinTabWidget::activeViewChanged
,
158 this, &DolphinMainWindow::activeViewChanged
);
159 connect(m_tabWidget
, &DolphinTabWidget::tabCountChanged
,
160 this, &DolphinMainWindow::tabCountChanged
);
161 connect(m_tabWidget
, &DolphinTabWidget::currentUrlChanged
,
162 this, &DolphinMainWindow::updateWindowTitle
);
163 setCentralWidget(m_tabWidget
);
165 m_actionTextHelper
= new SelectionMode::ActionTextHelper(this);
168 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), m_actionTextHelper
, this);
169 connect(m_actionHandler
, &DolphinViewActionHandler::actionBeingHandled
, this, &DolphinMainWindow::clearStatusBar
);
170 connect(m_actionHandler
, &DolphinViewActionHandler::createDirectoryTriggered
, this, &DolphinMainWindow::createDirectory
);
171 connect(m_actionHandler
, &DolphinViewActionHandler::selectionModeChangeTriggered
, this, &DolphinMainWindow::slotSetSelectionMode
);
173 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
174 connect(this, &DolphinMainWindow::urlChanged
,
175 m_remoteEncoding
, &DolphinRemoteEncoding::slotAboutToOpenUrl
);
179 setupGUI(Save
| Create
| ToolBar
);
180 stateChanged(QStringLiteral("new_file"));
182 QClipboard
* clipboard
= QApplication::clipboard();
183 connect(clipboard
, &QClipboard::dataChanged
,
184 this, &DolphinMainWindow::updatePasteAction
);
186 QAction
* toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
187 toggleFilterBarAction
->setChecked(GeneralSettings::filterBar());
190 menuBar()->setVisible(false);
193 const bool showMenu
= !menuBar()->isHidden();
194 QAction
* showMenuBarAction
= actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar
));
195 showMenuBarAction
->setChecked(showMenu
); // workaround for bug #171080
197 auto hamburgerMenu
= static_cast<KHamburgerMenu
*>(actionCollection()->action(
198 KStandardAction::name(KStandardAction::HamburgerMenu
)));
199 hamburgerMenu
->setMenuBar(menuBar());
200 hamburgerMenu
->setShowMenuBarAction(showMenuBarAction
);
201 connect(hamburgerMenu
, &KHamburgerMenu::aboutToShowMenu
,
202 this, &DolphinMainWindow::updateHamburgerMenu
);
203 hamburgerMenu
->hideActionsOf(toolBar());
204 if (GeneralSettings::version() < 201 && !toolBar()->actions().contains(hamburgerMenu
)) {
205 addHamburgerMenuToToolbar();
208 updateAllowedToolbarAreas();
210 // enable middle-click on back/forward/up to open in a new tab
211 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
212 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotToolBarActionMiddleClicked
);
213 toolBar()->installEventFilter(middleClickEventFilter
);
217 connect(KSycoca::self(), &KSycoca::databaseChanged
, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
219 QTimer::singleShot(0, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
221 m_fileItemActions
.setParentWidget(this);
222 connect(&m_fileItemActions
, &KFileItemActions::error
, this, [this](const QString
&errorMessage
) {
223 showErrorMessage(errorMessage
);
226 connect(GeneralSettings::self(), &GeneralSettings::splitViewChanged
,
227 this, &DolphinMainWindow::slotSplitViewChanged
);
230 DolphinMainWindow::~DolphinMainWindow()
232 // This fixes a crash on Wayland when closing the mainwindow while another dialog is open.
233 disconnect(QGuiApplication::clipboard(), &QClipboard::dataChanged
, this, &DolphinMainWindow::updatePasteAction
);
236 QVector
<DolphinViewContainer
*> DolphinMainWindow::viewContainers() const
238 QVector
<DolphinViewContainer
*> viewContainers
;
240 for (int i
= 0; i
< m_tabWidget
->count(); ++i
) {
241 DolphinTabPage
*tabPage
= m_tabWidget
->tabPageAt(i
);
243 viewContainers
<< tabPage
->primaryViewContainer();
244 if (tabPage
->splitViewEnabled()) {
245 viewContainers
<< tabPage
->secondaryViewContainer();
248 return viewContainers
;
251 void DolphinMainWindow::openDirectories(const QList
<QUrl
>& dirs
, bool splitView
)
253 m_tabWidget
->openDirectories(dirs
, splitView
);
256 void DolphinMainWindow::openDirectories(const QStringList
& dirs
, bool splitView
)
258 openDirectories(QUrl::fromStringList(dirs
), splitView
);
261 void DolphinMainWindow::openFiles(const QList
<QUrl
>& files
, bool splitView
)
263 m_tabWidget
->openFiles(files
, splitView
);
266 bool DolphinMainWindow::isFoldersPanelEnabled() const
268 return actionCollection()->action(QStringLiteral("show_folders_panel"))->isChecked();
271 bool DolphinMainWindow::isInformationPanelEnabled() const
274 return actionCollection()->action(QStringLiteral("show_information_panel"))->isChecked();
280 void DolphinMainWindow::openFiles(const QStringList
& files
, bool splitView
)
282 openFiles(QUrl::fromStringList(files
), splitView
);
285 void DolphinMainWindow::activateWindow(const QString
&activationToken
)
287 window()->setAttribute(Qt::WA_NativeWindow
, true);
289 if (KWindowSystem::isPlatformWayland()) {
290 KWindowSystem::setCurrentXdgActivationToken(activationToken
);
292 KStartupInfo::setNewStartupId(window()->windowHandle(), KStartupInfo::startupId());
295 KWindowSystem::activateWindow(window()->windowHandle());
298 bool DolphinMainWindow::isActiveWindow()
300 return window()->isActiveWindow();
303 void DolphinMainWindow::showCommand(CommandType command
)
305 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
307 case KIO::FileUndoManager::Copy
:
308 statusBar
->setText(i18nc("@info:status", "Successfully copied."));
310 case KIO::FileUndoManager::Move
:
311 statusBar
->setText(i18nc("@info:status", "Successfully moved."));
313 case KIO::FileUndoManager::Link
:
314 statusBar
->setText(i18nc("@info:status", "Successfully linked."));
316 case KIO::FileUndoManager::Trash
:
317 statusBar
->setText(i18nc("@info:status", "Successfully moved to trash."));
319 case KIO::FileUndoManager::Rename
:
320 statusBar
->setText(i18nc("@info:status", "Successfully renamed."));
323 case KIO::FileUndoManager::Mkdir
:
324 statusBar
->setText(i18nc("@info:status", "Created folder."));
332 void DolphinMainWindow::pasteIntoFolder()
334 m_activeViewContainer
->view()->pasteIntoFolder();
337 void DolphinMainWindow::changeUrl(const QUrl
&url
)
339 if (!KProtocolManager::supportsListing(url
)) {
340 // The URL navigator only checks for validity, not
341 // if the URL can be listed. An error message is
342 // shown due to DolphinViewContainer::restoreView().
346 m_activeViewContainer
->setUrl(url
);
347 updateFileAndEditActions();
352 Q_EMIT
urlChanged(url
);
355 void DolphinMainWindow::slotTerminalDirectoryChanged(const QUrl
& url
)
357 if (m_tearDownFromPlacesRequested
&& url
== QUrl::fromLocalFile(QDir::homePath())) {
358 m_placesPanel
->proceedWithTearDown();
359 m_tearDownFromPlacesRequested
= false;
362 m_activeViewContainer
->setAutoGrabFocus(false);
364 m_activeViewContainer
->setAutoGrabFocus(true);
367 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
369 KToggleAction
* editableLocationAction
=
370 static_cast<KToggleAction
*>(actionCollection()->action(QStringLiteral("editable_location")));
371 editableLocationAction
->setChecked(editable
);
374 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
376 updateFileAndEditActions();
378 const int selectedUrlsCount
= m_tabWidget
->currentTabPage()->selectedItemsCount();
380 QAction
* compareFilesAction
= actionCollection()->action(QStringLiteral("compare_files"));
381 if (selectedUrlsCount
== 2) {
382 compareFilesAction
->setEnabled(isKompareInstalled());
384 compareFilesAction
->setEnabled(false);
387 Q_EMIT
selectionChanged(selection
);
390 void DolphinMainWindow::updateHistory()
392 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
393 const int index
= urlNavigator
->historyIndex();
395 QAction
* backAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Back
));
397 backAction
->setToolTip(i18nc("@info", "Go back"));
398 backAction
->setWhatsThis(i18nc("@info:whatsthis go back", "Return to the previously viewed folder."));
399 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
402 QAction
* forwardAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Forward
));
404 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
405 forwardAction
->setWhatsThis(xi18nc("@info:whatsthis go forward",
406 "This undoes a <interface>Go|Back</interface> action."));
407 forwardAction
->setEnabled(index
> 0);
411 void DolphinMainWindow::updateFilterBarAction(bool show
)
413 QAction
* toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
414 toggleFilterBarAction
->setChecked(show
);
417 void DolphinMainWindow::openNewMainWindow()
419 Dolphin::openNewWindow({m_activeViewContainer
->url()}, this);
422 void DolphinMainWindow::openNewActivatedTab()
424 // keep browsers compatibility, new tab is always after last one
425 auto openNewTabAfterLastTabConfigured
= GeneralSettings::openNewTabAfterLastTab();
426 GeneralSettings::setOpenNewTabAfterLastTab(true);
427 m_tabWidget
->openNewActivatedTab();
428 GeneralSettings::setOpenNewTabAfterLastTab(openNewTabAfterLastTabConfigured
);
431 void DolphinMainWindow::addToPlaces()
436 // If nothing is selected, act on the current dir
437 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
438 url
= m_activeViewContainer
->url();
439 name
= m_activeViewContainer
->placesText();
441 const auto dirToAdd
= m_activeViewContainer
->view()->selectedItems().first();
442 url
= dirToAdd
.url();
443 name
= dirToAdd
.name();
447 if (m_activeViewContainer
->isSearchModeEnabled()) {
448 icon
= QStringLiteral("folder-saved-search-symbolic");
450 icon
= KIO::iconNameForUrl(url
);
452 DolphinPlacesModelSingleton::instance().placesModel()->addPlace(name
, url
, icon
);
456 void DolphinMainWindow::openNewTab(const QUrl
& url
)
458 m_tabWidget
->openNewTab(url
, QUrl());
461 void DolphinMainWindow::openNewTabAndActivate(const QUrl
&url
)
463 m_tabWidget
->openNewActivatedTab(url
, QUrl());
466 void DolphinMainWindow::openNewWindow(const QUrl
&url
)
468 Dolphin::openNewWindow({url
}, this);
471 void DolphinMainWindow::slotSplitViewChanged()
473 m_tabWidget
->currentTabPage()->setSplitViewEnabled(GeneralSettings::splitView(), WithAnimation
);
477 void DolphinMainWindow::openInNewTab()
479 const KFileItemList
& list
= m_activeViewContainer
->view()->selectedItems();
480 bool tabCreated
= false;
482 for (const KFileItem
& item
: list
) {
483 const QUrl
& url
= DolphinView::openItemAsFolderUrl(item
);
484 if (!url
.isEmpty()) {
490 // if no new tab has been created from the selection
491 // open the current directory in a new tab
493 openNewTab(m_activeViewContainer
->url());
497 void DolphinMainWindow::openInNewWindow()
501 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
502 if (list
.isEmpty()) {
503 newWindowUrl
= m_activeViewContainer
->url();
504 } else if (list
.count() == 1) {
505 const KFileItem
& item
= list
.first();
506 newWindowUrl
= DolphinView::openItemAsFolderUrl(item
);
509 if (!newWindowUrl
.isEmpty()) {
510 Dolphin::openNewWindow({newWindowUrl
}, this);
514 void DolphinMainWindow::showTarget()
516 const auto link
= m_activeViewContainer
->view()->selectedItems().at(0);
517 const auto linkLocationDir
= QFileInfo(link
.localPath()).absoluteDir();
518 auto linkDestination
= link
.linkDest();
519 if (QFileInfo(linkDestination
).isRelative()) {
520 linkDestination
= linkLocationDir
.filePath(linkDestination
);
522 if (QFileInfo::exists(linkDestination
)) {
523 KIO::highlightInFileManager({QUrl::fromLocalFile(linkDestination
).adjusted(QUrl::StripTrailingSlash
)});
525 m_activeViewContainer
->showMessage(xi18nc("@info", "Could not access <filename>%1</filename>.", linkDestination
),
526 DolphinViewContainer::Warning
);
530 void DolphinMainWindow::showEvent(QShowEvent
* event
)
532 KXmlGuiWindow::showEvent(event
);
534 if (!event
->spontaneous()) {
535 m_activeViewContainer
->view()->setFocus();
539 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
541 // Find out if Dolphin is closed directly by the user or
542 // by the session manager because the session is closed
543 bool closedByUser
= true;
544 if (qApp
->isSavingSession()) {
545 closedByUser
= false;
548 if (m_tabWidget
->count() > 1
549 && GeneralSettings::confirmClosingMultipleTabs()
550 && !GeneralSettings::rememberOpenedTabs()
552 // Ask the user if he really wants to quit and close all tabs.
553 // Open a confirmation dialog with 3 buttons:
554 // QDialogButtonBox::Yes -> Quit
555 // QDialogButtonBox::No -> Close only the current tab
556 // QDialogButtonBox::Cancel -> do nothing
557 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
558 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
559 dialog
->setModal(true);
560 QDialogButtonBox
* buttons
= new QDialogButtonBox(QDialogButtonBox::Yes
| QDialogButtonBox::No
| QDialogButtonBox::Cancel
);
561 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KGuiItem(i18nc("@action:button 'Quit Dolphin' button", "&Quit %1", QGuiApplication::applicationDisplayName()), QIcon::fromTheme(QStringLiteral("application-exit"))));
562 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("C&lose Current Tab"), QIcon::fromTheme(QStringLiteral("tab-close"))));
563 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
564 buttons
->button(QDialogButtonBox::Yes
)->setDefault(true);
566 bool doNotAskAgainCheckboxResult
= false;
568 const auto result
= KMessageBox::createKMessageBox(dialog
,
570 QMessageBox::Warning
,
571 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
573 i18n("Do not ask again"),
574 &doNotAskAgainCheckboxResult
,
575 KMessageBox::Notify
);
577 if (doNotAskAgainCheckboxResult
) {
578 GeneralSettings::setConfirmClosingMultipleTabs(false);
582 case QDialogButtonBox::Yes
:
585 case QDialogButtonBox::No
:
586 // Close only the current tab
587 m_tabWidget
->closeTab();
595 if (m_terminalPanel
&& m_terminalPanel
->hasProgramRunning() && GeneralSettings::confirmClosingTerminalRunningProgram() && closedByUser
) {
596 // Ask if the user really wants to quit Dolphin with a program that is still running in the Terminal panel
597 // Open a confirmation dialog with 3 buttons:
598 // QDialogButtonBox::Yes -> Quit
599 // QDialogButtonBox::No -> Show Terminal Panel
600 // QDialogButtonBox::Cancel -> do nothing
601 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
602 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
603 dialog
->setModal(true);
604 auto standardButtons
= QDialogButtonBox::Yes
| QDialogButtonBox::Cancel
;
605 if (!m_terminalPanel
->isVisible()) {
606 standardButtons
|= QDialogButtonBox::No
;
608 QDialogButtonBox
*buttons
= new QDialogButtonBox(standardButtons
);
609 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KStandardGuiItem::quit());
610 if (!m_terminalPanel
->isVisible()) {
612 buttons
->button(QDialogButtonBox::No
),
613 KGuiItem(i18n("Show &Terminal Panel"), QIcon::fromTheme(QStringLiteral("dialog-scripts"))));
615 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
617 bool doNotAskAgainCheckboxResult
= false;
619 const auto result
= KMessageBox::createKMessageBox(
622 QMessageBox::Warning
,
623 i18n("The program '%1' is still running in the Terminal panel. Are you sure you want to quit?", m_terminalPanel
->runningProgramName()),
625 i18n("Do not ask again"),
626 &doNotAskAgainCheckboxResult
,
627 KMessageBox::Dangerous
);
629 if (doNotAskAgainCheckboxResult
) {
630 GeneralSettings::setConfirmClosingTerminalRunningProgram(false);
634 case QDialogButtonBox::Yes
:
637 case QDialogButtonBox::No
:
638 actionCollection()->action("show_terminal_panel")->trigger();
639 // Do not quit, ignore quit event
647 if (GeneralSettings::rememberOpenedTabs()) {
648 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
649 KConfig
*config
= KConfigGui::sessionConfig();
650 saveGlobalProperties(config
);
651 savePropertiesInternal(config
, 1);
655 GeneralSettings::setVersion(CurrentDolphinVersion
);
656 GeneralSettings::self()->save();
658 KXmlGuiWindow::closeEvent(event
);
661 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
663 m_tabWidget
->saveProperties(group
);
666 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
668 m_tabWidget
->readProperties(group
);
671 void DolphinMainWindow::updateNewMenu()
673 m_newFileMenu
->checkUpToDate();
674 #if KIO_VERSION >= QT_VERSION_CHECK(5, 97, 0)
675 m_newFileMenu
->setWorkingDirectory(activeViewContainer()->url());
677 m_newFileMenu
->setPopupFiles(QList
<QUrl
>() << activeViewContainer()->url());
681 void DolphinMainWindow::createDirectory()
683 #if KIO_VERSION >= QT_VERSION_CHECK(5, 97, 0)
684 m_newFileMenu
->setWorkingDirectory(activeViewContainer()->url());
686 m_newFileMenu
->setPopupFiles(QList
<QUrl
>() << activeViewContainer()->url());
688 m_newFileMenu
->createDirectory();
691 void DolphinMainWindow::quit()
696 void DolphinMainWindow::showErrorMessage(const QString
& message
)
698 m_activeViewContainer
->showMessage(message
, DolphinViewContainer::Error
);
701 void DolphinMainWindow::slotUndoAvailable(bool available
)
703 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
705 undoAction
->setEnabled(available
);
709 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
711 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
713 undoAction
->setText(text
);
717 void DolphinMainWindow::undo()
720 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
721 KIO::FileUndoManager::self()->undo();
724 void DolphinMainWindow::cut()
726 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
727 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CutContents
);
729 m_activeViewContainer
->view()->cutSelectedItemsToClipboard();
730 m_activeViewContainer
->setSelectionModeEnabled(false);
734 void DolphinMainWindow::copy()
736 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
737 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CopyContents
);
739 m_activeViewContainer
->view()->copySelectedItemsToClipboard();
740 m_activeViewContainer
->setSelectionModeEnabled(false);
744 void DolphinMainWindow::paste()
746 m_activeViewContainer
->view()->paste();
749 void DolphinMainWindow::find()
751 m_activeViewContainer
->setSearchModeEnabled(true);
754 void DolphinMainWindow::updateSearchAction()
756 QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
757 toggleSearchAction
->setChecked(m_activeViewContainer
->isSearchModeEnabled());
760 void DolphinMainWindow::updatePasteAction()
762 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
763 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
764 pasteAction
->setEnabled(pasteInfo
.first
);
765 pasteAction
->setText(pasteInfo
.second
);
768 void DolphinMainWindow::slotDirectoryLoadingCompleted()
773 void DolphinMainWindow::slotToolBarActionMiddleClicked(QAction
*action
)
775 if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Back
))) {
777 } else if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Forward
))) {
779 } else if (action
== actionCollection()->action(QStringLiteral("go_up"))) {
781 } else if (action
== actionCollection()->action(QStringLiteral("go_home"))) {
786 QAction
*DolphinMainWindow::urlNavigatorHistoryAction(const KUrlNavigator
*urlNavigator
, int historyIndex
, QObject
*parent
)
788 const QUrl url
= urlNavigator
->locationUrl(historyIndex
);
790 QString text
= url
.toDisplayString(QUrl::PreferLocalFile
);
792 if (!urlNavigator
->showFullPath()) {
793 const KFilePlacesModel
*placesModel
= DolphinPlacesModelSingleton::instance().placesModel();
795 const QModelIndex closestIdx
= placesModel
->closestItem(url
);
796 if (closestIdx
.isValid()) {
797 const QUrl placeUrl
= placesModel
->url(closestIdx
);
799 text
= placesModel
->text(closestIdx
);
801 QString pathInsidePlace
= url
.path().mid(placeUrl
.path().length());
803 if (!pathInsidePlace
.isEmpty() && !pathInsidePlace
.startsWith(QLatin1Char('/'))) {
804 pathInsidePlace
.prepend(QLatin1Char('/'));
807 if (pathInsidePlace
!= QLatin1Char('/')) {
808 text
.append(pathInsidePlace
);
813 QAction
*action
= new QAction(QIcon::fromTheme(KIO::iconNameForUrl(url
)), text
, parent
);
814 action
->setData(historyIndex
);
818 void DolphinMainWindow::slotAboutToShowBackPopupMenu()
820 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
822 m_backAction
->menu()->clear();
823 for (int i
= urlNavigator
->historyIndex() + 1; i
< urlNavigator
->historySize() && entries
< MaxNumberOfNavigationentries
; ++i
, ++entries
) {
824 QAction
*action
= urlNavigatorHistoryAction(urlNavigator
, i
, m_backAction
->menu());
825 m_backAction
->menu()->addAction(action
);
829 void DolphinMainWindow::slotGoBack(QAction
* action
)
831 int gotoIndex
= action
->data().value
<int>();
832 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
833 for (int i
= gotoIndex
- urlNavigator
->historyIndex(); i
> 0; --i
) {
838 void DolphinMainWindow::slotBackForwardActionMiddleClicked(QAction
* action
)
841 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
842 openNewTab(urlNavigator
->locationUrl(action
->data().value
<int>()));
846 void DolphinMainWindow::slotAboutToShowForwardPopupMenu()
848 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
850 m_forwardAction
->menu()->clear();
851 for (int i
= urlNavigator
->historyIndex() - 1; i
>= 0 && entries
< MaxNumberOfNavigationentries
; --i
, ++entries
) {
852 QAction
*action
= urlNavigatorHistoryAction(urlNavigator
, i
, m_forwardAction
->menu());
853 m_forwardAction
->menu()->addAction(action
);
857 void DolphinMainWindow::slotGoForward(QAction
* action
)
859 int gotoIndex
= action
->data().value
<int>();
860 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
861 for (int i
= urlNavigator
->historyIndex() - gotoIndex
; i
> 0; --i
) {
866 void DolphinMainWindow::slotSetSelectionMode(bool enabled
, SelectionMode::BottomBar::Contents bottomBarContents
)
868 m_activeViewContainer
->setSelectionModeEnabled(enabled
, actionCollection(), bottomBarContents
);
871 void DolphinMainWindow::selectAll()
875 // if the URL navigator is editable and focused, select the whole
876 // URL instead of all items of the view
878 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
879 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit();
880 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
881 lineEdit
->hasFocus();
883 lineEdit
->selectAll();
885 m_activeViewContainer
->view()->selectAll();
889 void DolphinMainWindow::invertSelection()
892 m_activeViewContainer
->view()->invertSelection();
895 void DolphinMainWindow::toggleSplitView()
897 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
898 tabPage
->setSplitViewEnabled(!tabPage
->splitViewEnabled(), WithAnimation
);
903 void DolphinMainWindow::toggleSplitStash()
905 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
906 tabPage
->setSplitViewEnabled(false, WithAnimation
);
907 tabPage
->setSplitViewEnabled(true, WithAnimation
, QUrl("stash:/"));
910 void DolphinMainWindow::copyToInactiveSplitView()
912 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
913 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CopyToOtherViewContents
);
915 m_tabWidget
->copyToInactiveSplitView();
916 m_activeViewContainer
->setSelectionModeEnabled(false);
920 void DolphinMainWindow::moveToInactiveSplitView()
922 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
923 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::MoveToOtherViewContents
);
925 m_tabWidget
->moveToInactiveSplitView();
926 m_activeViewContainer
->setSelectionModeEnabled(false);
930 void DolphinMainWindow::reloadView()
933 m_activeViewContainer
->reload();
934 m_activeViewContainer
->statusBar()->updateSpaceInfo();
937 void DolphinMainWindow::stopLoading()
939 m_activeViewContainer
->view()->stopLoading();
942 void DolphinMainWindow::enableStopAction()
944 actionCollection()->action(QStringLiteral("stop"))->setEnabled(true);
947 void DolphinMainWindow::disableStopAction()
949 actionCollection()->action(QStringLiteral("stop"))->setEnabled(false);
952 void DolphinMainWindow::toggleSelectionMode()
954 const bool checked
= !m_activeViewContainer
->isSelectionModeEnabled();
956 m_activeViewContainer
->setSelectionModeEnabled(checked
, actionCollection(), SelectionMode::BottomBar::Contents::GeneralContents
);
957 actionCollection()->action(QStringLiteral("toggle_selection_mode"))->setChecked(checked
);
960 void DolphinMainWindow::showFilterBar()
962 m_activeViewContainer
->setFilterBarVisible(true);
965 void DolphinMainWindow::toggleFilterBar()
967 const bool checked
= !m_activeViewContainer
->isFilterBarVisible();
968 m_activeViewContainer
->setFilterBarVisible(checked
);
970 QAction
* toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
971 toggleFilterBarAction
->setChecked(checked
);
974 void DolphinMainWindow::toggleEditLocation()
978 QAction
* action
= actionCollection()->action(QStringLiteral("editable_location"));
979 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
980 urlNavigator
->setUrlEditable(action
->isChecked());
983 void DolphinMainWindow::replaceLocation()
985 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
986 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit();
988 // If the text field currently has focus and everything is selected,
989 // pressing the keyboard shortcut returns the whole thing to breadcrumb mode
990 if (navigator
->isUrlEditable()
991 && lineEdit
->hasFocus()
992 && lineEdit
->selectedText() == lineEdit
->text() ) {
993 navigator
->setUrlEditable(false);
995 navigator
->setUrlEditable(true);
996 navigator
->setFocus();
997 lineEdit
->selectAll();
1001 void DolphinMainWindow::togglePanelLockState()
1003 const bool newLockState
= !GeneralSettings::lockPanels();
1004 const auto childrenObjects
= children();
1005 for (QObject
* child
: childrenObjects
) {
1006 DolphinDockWidget
* dock
= qobject_cast
<DolphinDockWidget
*>(child
);
1008 dock
->setLocked(newLockState
);
1012 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(newLockState
);
1014 GeneralSettings::setLockPanels(newLockState
);
1017 void DolphinMainWindow::slotTerminalPanelVisibilityChanged()
1019 if (m_terminalPanel
->isHiddenInVisibleWindow() && m_activeViewContainer
) {
1020 m_activeViewContainer
->view()->setFocus();
1024 void DolphinMainWindow::goBack()
1026 DolphinUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
1027 urlNavigator
->goBack();
1029 if (urlNavigator
->locationState().isEmpty()) {
1030 // An empty location state indicates a redirection URL,
1031 // which must be skipped too
1032 urlNavigator
->goBack();
1036 void DolphinMainWindow::goForward()
1038 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goForward();
1041 void DolphinMainWindow::goUp()
1043 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goUp();
1046 void DolphinMainWindow::goHome()
1048 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goHome();
1051 void DolphinMainWindow::goBackInNewTab()
1053 const KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
1054 const int index
= urlNavigator
->historyIndex() + 1;
1055 openNewTab(urlNavigator
->locationUrl(index
));
1058 void DolphinMainWindow::goForwardInNewTab()
1060 const KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
1061 const int index
= urlNavigator
->historyIndex() - 1;
1062 openNewTab(urlNavigator
->locationUrl(index
));
1065 void DolphinMainWindow::goUpInNewTab()
1067 const QUrl currentUrl
= activeViewContainer()->urlNavigator()->locationUrl();
1068 openNewTab(KIO::upUrl(currentUrl
));
1071 void DolphinMainWindow::goHomeInNewTab()
1073 openNewTab(Dolphin::homeUrl());
1076 void DolphinMainWindow::compareFiles()
1078 const KFileItemList items
= m_tabWidget
->currentTabPage()->selectedItems();
1079 if (items
.count() != 2) {
1080 // The action is disabled in this case, but it could have been triggered
1081 // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
1085 QUrl urlA
= items
.at(0).url();
1086 QUrl urlB
= items
.at(1).url();
1088 QString
command(QStringLiteral("kompare -c \""));
1089 command
.append(urlA
.toDisplayString(QUrl::PreferLocalFile
));
1090 command
.append("\" \"");
1091 command
.append(urlB
.toDisplayString(QUrl::PreferLocalFile
));
1092 command
.append('\"');
1094 KIO::CommandLauncherJob
*job
= new KIO::CommandLauncherJob(command
, this);
1095 job
->setDesktopName(QStringLiteral("org.kde.kompare"));
1099 void DolphinMainWindow::toggleShowMenuBar()
1101 const bool visible
= menuBar()->isVisible();
1102 menuBar()->setVisible(!visible
);
1105 QPointer
<QAction
> DolphinMainWindow::preferredSearchTool()
1107 m_searchTools
.clear();
1108 KMoreToolsMenuFactory("dolphin/search-tools").fillMenuFromGroupingNames(
1109 &m_searchTools
, { "files-find" }, m_activeViewContainer
->url()
1111 QList
<QAction
*> actions
= m_searchTools
.actions();
1112 if (actions
.isEmpty()) {
1115 QAction
* action
= actions
.first();
1116 if (action
->isSeparator()) {
1122 void DolphinMainWindow::updateOpenPreferredSearchToolAction()
1124 QAction
* openPreferredSearchTool
= actionCollection()->action(QStringLiteral("open_preferred_search_tool"));
1125 if (!openPreferredSearchTool
) {
1128 QPointer
<QAction
> tool
= preferredSearchTool();
1130 openPreferredSearchTool
->setVisible(true);
1131 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open %1", tool
->text()));
1132 // Only override with the app icon if it is the default, i.e. the user hasn't configured one manually
1133 // https://bugs.kde.org/show_bug.cgi?id=442815
1134 if (openPreferredSearchTool
->icon().name() == QLatin1String("search")) {
1135 openPreferredSearchTool
->setIcon(tool
->icon());
1138 openPreferredSearchTool
->setVisible(false);
1139 // still visible in Shortcuts configuration window
1140 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1141 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1145 void DolphinMainWindow::openPreferredSearchTool()
1147 QPointer
<QAction
> tool
= preferredSearchTool();
1153 void DolphinMainWindow::openTerminal()
1155 openTerminalJob(m_activeViewContainer
->url());
1158 void DolphinMainWindow::openTerminalHere()
1160 QList
<QUrl
> urls
= {};
1162 for (const KFileItem
& item
: m_activeViewContainer
->view()->selectedItems()) {
1163 QUrl url
= item
.targetUrl();
1164 if (item
.isFile()) {
1165 url
.setPath(QFileInfo(url
.path()).absolutePath());
1167 if (!urls
.contains(url
)) {
1172 // No items are selected. Open a terminal window for the current location.
1173 if (urls
.count() == 0) {
1178 if (urls
.count() > 5) {
1179 QString question
= i18np("Are you sure you want to open 1 terminal window?",
1180 "Are you sure you want to open %1 terminal windows?", urls
.count());
1181 #if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
1182 const int answer
= KMessageBox::warningTwoActions(this, question
, {},
1184 const int answer
= KMessageBox::warningYesNo(this, question
, {},
1186 KGuiItem(i18ncp("@action:button", "Open %1 Terminal", "Open %1 Terminals", urls
.count()),
1187 QStringLiteral("utilities-terminal")),
1188 KStandardGuiItem::cancel());
1189 #if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
1190 if (answer
!= KMessageBox::PrimaryAction
) {
1192 if (answer
!= KMessageBox::Yes
) {
1198 for (const QUrl
& url
: urls
) {
1199 openTerminalJob(url
);
1203 void DolphinMainWindow::openTerminalJob(const QUrl
& url
)
1205 if (url
.isLocalFile()) {
1206 auto job
= new KTerminalLauncherJob(QString());
1207 job
->setWorkingDirectory(url
.toLocalFile());
1212 // Not a local file, with protocol Class ":local", try stat'ing
1213 if (KProtocolInfo::protocolClass(url
.scheme()) == QLatin1String(":local")) {
1214 KIO::StatJob
*job
= KIO::mostLocalUrl(url
);
1215 KJobWidgets::setWindow(job
, this);
1216 connect(job
, &KJob::result
, this, [job
]() {
1218 if (!job
->error()) {
1219 statUrl
= job
->mostLocalUrl();
1222 auto job
= new KTerminalLauncherJob(QString());
1223 job
->setWorkingDirectory(statUrl
.isLocalFile() ? statUrl
.toLocalFile() : QDir::homePath());
1230 // Nothing worked, just use $HOME
1231 auto job
= new KTerminalLauncherJob(QString());
1232 job
->setWorkingDirectory(QDir::homePath());
1236 void DolphinMainWindow::editSettings()
1238 if (!m_settingsDialog
) {
1239 DolphinViewContainer
* container
= activeViewContainer();
1240 container
->view()->writeSettings();
1242 const QUrl url
= container
->url();
1243 DolphinSettingsDialog
* settingsDialog
= new DolphinSettingsDialog(url
, this, actionCollection());
1244 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, this, &DolphinMainWindow::refreshViews
);
1245 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
,
1246 &DolphinUrlNavigatorsController::slotReadSettings
);
1247 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1248 settingsDialog
->show();
1249 m_settingsDialog
= settingsDialog
;
1251 m_settingsDialog
.data()->raise();
1255 void DolphinMainWindow::handleUrl(const QUrl
& url
)
1257 delete m_lastHandleUrlOpenJob
;
1258 m_lastHandleUrlOpenJob
= nullptr;
1260 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1261 activeViewContainer()->setUrl(url
);
1263 m_lastHandleUrlOpenJob
= new KIO::OpenUrlJob(url
);
1264 #if KIO_VERSION >= QT_VERSION_CHECK(5, 98, 0)
1265 m_lastHandleUrlOpenJob
->setUiDelegate(KIO::createDefaultJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
1267 m_lastHandleUrlOpenJob
->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
1269 m_lastHandleUrlOpenJob
->setShowOpenOrExecuteDialog(true);
1271 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::mimeTypeFound
, this,
1272 [this, url
](const QString
&mimetype
) {
1273 if (mimetype
== QLatin1String("inode/directory")) {
1274 // If it's a dir, we'll take it from here
1275 m_lastHandleUrlOpenJob
->kill();
1276 m_lastHandleUrlOpenJob
= nullptr;
1277 activeViewContainer()->setUrl(url
);
1281 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::result
, this, [this]() {
1282 m_lastHandleUrlOpenJob
= nullptr;
1285 m_lastHandleUrlOpenJob
->start();
1289 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1291 // trash:/ is writable but we don't want to create new items in it.
1292 // TODO: remove the trash check once https://phabricator.kde.org/T8234 is implemented
1293 newFileMenu()->setEnabled(isFolderWritable
&& m_activeViewContainer
->url().scheme() != QLatin1String("trash"));
1296 void DolphinMainWindow::openContextMenu(const QPoint
& pos
,
1297 const KFileItem
& item
,
1298 const KFileItemList
&selectedItems
,
1301 QPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, item
, selectedItems
, url
, &m_fileItemActions
);
1302 contextMenu
.data()->exec(pos
);
1304 // Delete the menu, unless it has been deleted in its own nested event loop already.
1306 contextMenu
->deleteLater();
1310 QMenu
*DolphinMainWindow::createPopupMenu()
1312 QMenu
*menu
= KXmlGuiWindow::createPopupMenu();
1314 menu
->addSeparator();
1315 menu
->addAction(actionCollection()->action(QStringLiteral("lock_panels")));
1320 void DolphinMainWindow::updateHamburgerMenu()
1322 KActionCollection
* ac
= actionCollection();
1323 auto hamburgerMenu
= static_cast<KHamburgerMenu
*>(
1324 ac
->action(KStandardAction::name(KStandardAction::HamburgerMenu
)));
1325 auto menu
= hamburgerMenu
->menu();
1327 menu
= new QMenu(this);
1328 hamburgerMenu
->setMenu(menu
);
1329 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("basic_actions"))->menu());
1330 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("zoom"))->menu());
1334 const QList
<QAction
*> toolbarActions
= toolBar()->actions();
1336 if (!toolBar()->isVisible()) {
1337 // If neither the menu bar nor the toolbar are visible, these actions should be available.
1338 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)));
1339 menu
->addAction(toolBarMenuAction());
1340 menu
->addSeparator();
1343 // This group of actions (until the next separator) contains all the most basic actions
1344 // necessary to use Dolphin effectively.
1345 menu
->addAction(ac
->action(QStringLiteral("go_back")));
1346 menu
->addAction(ac
->action(QStringLiteral("go_forward")));
1348 menu
->addMenu(m_newFileMenu
->menu());
1349 if (!toolBar()->isVisible()
1350 || !toolbarActions
.contains(ac
->action(QStringLiteral("toggle_selection_mode_tool_bar")))
1352 menu
->addAction(ac
->action(QStringLiteral("toggle_selection_mode")));
1354 menu
->addAction(ac
->action(QStringLiteral("basic_actions")));
1355 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Undo
)));
1356 if (!toolBar()->isVisible()
1357 || (!toolbarActions
.contains(ac
->action(QStringLiteral("toggle_search")))
1358 && !toolbarActions
.contains(ac
->action(QStringLiteral("open_preferred_search_tool"))))
1360 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Find
)));
1361 // This way a search action will only be added if none of the three available
1362 // search actions is present on the toolbar.
1364 if (!toolBar()->isVisible()
1365 || !toolbarActions
.contains(ac
->action(QStringLiteral("toggle_filter")))
1367 menu
->addAction(ac
->action(QStringLiteral("show_filter_bar")));
1368 // This way a filter action will only be added if none of the two available
1369 // filter actions is present on the toolbar.
1371 menu
->addSeparator();
1373 // The second group of actions (up until the next separator) contains actions for opening
1374 // additional views to interact with the file system.
1375 menu
->addAction(ac
->action(QStringLiteral("file_new")));
1376 menu
->addAction(ac
->action(QStringLiteral("new_tab")));
1377 if (ac
->action(QStringLiteral("undo_close_tab"))->isEnabled()) {
1378 menu
->addAction(ac
->action(QStringLiteral("closed_tabs")));
1380 menu
->addAction(ac
->action(QStringLiteral("open_terminal")));
1381 menu
->addSeparator();
1383 // The third group contains actions to change what one sees in the view
1384 // and to change the more general UI.
1385 if (!toolBar()->isVisible()
1386 || (!toolbarActions
.contains(ac
->action(QStringLiteral("icons")))
1387 && !toolbarActions
.contains(ac
->action(QStringLiteral("compact")))
1388 && !toolbarActions
.contains(ac
->action(QStringLiteral("details")))
1389 && !toolbarActions
.contains(ac
->action(QStringLiteral("view_mode"))))
1391 menu
->addAction(ac
->action(QStringLiteral("view_mode")));
1393 menu
->addAction(ac
->action(QStringLiteral("show_hidden_files")));
1394 menu
->addAction(ac
->action(QStringLiteral("sort")));
1395 menu
->addAction(ac
->action(QStringLiteral("additional_info")));
1396 if (!GeneralSettings::showStatusBar() || !GeneralSettings::showZoomSlider()) {
1397 menu
->addAction(ac
->action(QStringLiteral("zoom")));
1399 menu
->addAction(ac
->action(QStringLiteral("panels")));
1401 // The "Configure" menu is not added to the actionCollection() because there is hardly
1402 // a good reason for users to put it on their toolbar.
1403 auto configureMenu
= menu
->addMenu(QIcon::fromTheme(QStringLiteral("configure")),
1404 i18nc("@action:inmenu menu for configure actions", "Configure"));
1405 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
)));
1406 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)));
1407 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)));
1408 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Preferences
)));
1409 hamburgerMenu
->hideActionsOf(configureMenu
);
1412 void DolphinMainWindow::slotPlaceActivated(const QUrl
& url
)
1414 DolphinViewContainer
* view
= activeViewContainer();
1416 if (view
->url() == url
) {
1417 // We can end up here if the user clicked a device in the Places Panel
1418 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
1421 view
->disableUrlNavigatorSelectionRequests();
1423 view
->enableUrlNavigatorSelectionRequests();
1427 void DolphinMainWindow::closedTabsCountChanged(unsigned int count
)
1429 actionCollection()->action(QStringLiteral("undo_close_tab"))->setEnabled(count
> 0);
1432 void DolphinMainWindow::activeViewChanged(DolphinViewContainer
* viewContainer
)
1434 DolphinViewContainer
* oldViewContainer
= m_activeViewContainer
;
1435 Q_ASSERT(viewContainer
);
1437 m_activeViewContainer
= viewContainer
;
1439 if (oldViewContainer
) {
1440 const QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
1441 toggleSearchAction
->disconnect(oldViewContainer
);
1443 // Disconnect all signals between the old view container (container,
1444 // view and url navigator) and main window.
1445 oldViewContainer
->disconnect(this);
1446 oldViewContainer
->view()->disconnect(this);
1447 oldViewContainer
->urlNavigatorInternalWithHistory()->disconnect(this);
1448 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
1449 (actionCollection()->action(QStringLiteral("url_navigators")));
1450 navigators
->primaryUrlNavigator()->disconnect(this);
1451 if (auto secondaryUrlNavigator
= navigators
->secondaryUrlNavigator()) {
1452 secondaryUrlNavigator
->disconnect(this);
1455 // except the requestItemInfo so that on hover the information panel can still be updated
1456 connect(oldViewContainer
->view(), &DolphinView::requestItemInfo
,
1457 this, &DolphinMainWindow::requestItemInfo
);
1459 // Disconnect other slots.
1460 disconnect(nullptr, &DolphinViewContainer::selectionModeChanged
,
1461 actionCollection()->action(QStringLiteral("toggle_selection_mode")), &QAction::setChecked
);
1464 connectViewSignals(viewContainer
);
1466 m_actionHandler
->setCurrentView(viewContainer
->view());
1469 updateFileAndEditActions();
1470 updatePasteAction();
1471 updateViewActions();
1473 updateSearchAction();
1475 const QUrl url
= viewContainer
->url();
1476 Q_EMIT
urlChanged(url
);
1479 void DolphinMainWindow::tabCountChanged(int count
)
1481 const bool enableTabActions
= (count
> 1);
1482 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1483 actionCollection()->action(QStringLiteral("activate_tab_%1").arg(i
))->setEnabled(enableTabActions
);
1485 actionCollection()->action(QStringLiteral("activate_last_tab"))->setEnabled(enableTabActions
);
1486 actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions
);
1487 actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions
);
1490 void DolphinMainWindow::updateWindowTitle()
1492 const QString newTitle
= m_activeViewContainer
->captionWindowTitle();
1493 if (windowTitle() != newTitle
) {
1494 setWindowTitle(newTitle
);
1498 void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(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
= true;
1506 m_terminalPanel
->goHome();
1507 // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged
1509 m_placesPanel
->proceedWithTearDown();
1513 void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString
& mountPath
)
1515 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1516 setViewsToHomeIfMountPathOpen(mountPath
);
1519 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectory().startsWith(mountPath
)) {
1520 m_tearDownFromPlacesRequested
= false;
1521 m_terminalPanel
->goHome();
1525 void DolphinMainWindow::slotKeyBindings()
1527 KShortcutsDialog
dialog(KShortcutsEditor::AllActions
, KShortcutsEditor::LetterShortcutsAllowed
, this);
1528 dialog
.addCollection(actionCollection());
1529 if (m_terminalPanel
) {
1530 KActionCollection
*konsolePartActionCollection
= m_terminalPanel
->actionCollection();
1531 if (konsolePartActionCollection
) {
1532 dialog
.addCollection(konsolePartActionCollection
, QStringLiteral("KonsolePart"));
1538 void DolphinMainWindow::setViewsToHomeIfMountPathOpen(const QString
& mountPath
)
1540 const QVector
<DolphinViewContainer
*> theViewContainers
= viewContainers();
1541 for (DolphinViewContainer
*viewContainer
: theViewContainers
) {
1542 if (viewContainer
&& viewContainer
->url().toLocalFile().startsWith(mountPath
)) {
1543 viewContainer
->setUrl(QUrl::fromLocalFile(QDir::homePath()));
1546 disconnect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, nullptr, nullptr);
1549 void DolphinMainWindow::setupActions()
1551 auto hamburgerMenuAction
= KStandardAction::hamburgerMenu(nullptr, nullptr, actionCollection());
1553 // setup 'File' menu
1554 m_newFileMenu
= new DolphinNewFileMenu(actionCollection(), this);
1555 QMenu
* menu
= m_newFileMenu
->menu();
1556 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1557 menu
->setIcon(QIcon::fromTheme(QStringLiteral("list-add")));
1558 m_newFileMenu
->setPopupMode(QToolButton::InstantPopup
);
1559 connect(menu
, &QMenu::aboutToShow
,
1560 this, &DolphinMainWindow::updateNewMenu
);
1562 QAction
* newWindow
= KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow
, actionCollection());
1563 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1564 newWindow
->setToolTip(i18nc("@info", "Open a new Dolphin window"));
1565 newWindow
->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1566 "window just like this one with the current location and view."
1567 "<nl/>You can drag and drop items between windows."));
1568 newWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1570 QAction
* newTab
= actionCollection()->addAction(QStringLiteral("new_tab"));
1571 newTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1572 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1573 newTab
->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1574 "<emphasis>Tab</emphasis> with the current location and view.<nl/>"
1575 "A tab is an additional view within this window. "
1576 "You can drag and drop items between tabs."));
1577 actionCollection()->setDefaultShortcuts(newTab
, {Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
});
1578 connect(newTab
, &QAction::triggered
, this, &DolphinMainWindow::openNewActivatedTab
);
1580 QAction
* addToPlaces
= actionCollection()->addAction(QStringLiteral("add_to_places"));
1581 addToPlaces
->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new")));
1582 addToPlaces
->setText(i18nc("@action:inmenu Add current folder to places", "Add to Places"));
1583 addToPlaces
->setWhatsThis(xi18nc("@info:whatsthis", "This adds the selected folder "
1584 "to the Places panel."));
1585 connect(addToPlaces
, &QAction::triggered
, this, &DolphinMainWindow::addToPlaces
);
1587 QAction
* closeTab
= KStandardAction::close(m_tabWidget
, QOverload
<>::of(&DolphinTabWidget::closeTab
), actionCollection());
1588 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1589 closeTab
->setWhatsThis(i18nc("@info:whatsthis", "This closes the "
1590 "currently viewed tab. If no more tabs are left this window "
1591 "will close instead."));
1593 QAction
* quitAction
= KStandardAction::quit(this, &DolphinMainWindow::quit
, actionCollection());
1594 quitAction
->setWhatsThis(i18nc("@info:whatsthis quit", "This closes this window."));
1596 // setup 'Edit' menu
1597 KStandardAction::undo(this,
1598 &DolphinMainWindow::undo
,
1599 actionCollection());
1601 // i18n: This will be the last paragraph for the whatsthis for all three:
1602 // Cut, Copy and Paste
1603 const QString cutCopyPastePara
= xi18nc("@info:whatsthis", "<para><emphasis>Cut, "
1604 "Copy</emphasis> and <emphasis>Paste</emphasis> work between many "
1605 "applications and are among the most used commands. That's why their "
1606 "<emphasis>keyboard shortcuts</emphasis> are prominently placed right "
1607 "next to each other on the keyboard: <shortcut>Ctrl+X</shortcut>, "
1608 "<shortcut>Ctrl+C</shortcut> and <shortcut>Ctrl+V</shortcut>.</para>");
1609 QAction
* cutAction
= KStandardAction::cut(this, &DolphinMainWindow::cut
, actionCollection());
1610 m_actionTextHelper
->registerTextWhenNothingIsSelected(cutAction
, i18nc("@action", "Cut…"));
1611 cutAction
->setWhatsThis(xi18nc("@info:whatsthis cut", "This copies the items "
1612 "in your current selection to the <emphasis>clipboard</emphasis>.<nl/>"
1613 "Use the <emphasis>Paste</emphasis> action afterwards to copy them from "
1614 "the clipboard to a new location. The items will be removed from their "
1615 "initial location.") + cutCopyPastePara
);
1616 QAction
* copyAction
= KStandardAction::copy(this, &DolphinMainWindow::copy
, actionCollection());
1617 m_actionTextHelper
->registerTextWhenNothingIsSelected(copyAction
, i18nc("@action", "Copy…"));
1618 copyAction
->setWhatsThis(xi18nc("@info:whatsthis copy", "This copies the "
1619 "items in your current selection to the <emphasis>clipboard</emphasis>."
1620 "<nl/>Use the <emphasis>Paste</emphasis> action afterwards to copy them "
1621 "from the clipboard to a new location.") + cutCopyPastePara
);
1622 QAction
* paste
= KStandardAction::paste(this, &DolphinMainWindow::paste
, actionCollection());
1623 // The text of the paste-action is modified dynamically by Dolphin
1624 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1625 // due to the long text, the text "Paste" is used:
1626 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1627 paste
->setWhatsThis(xi18nc("@info:whatsthis paste", "This copies the items from "
1628 "your <emphasis>clipboard</emphasis> to the currently viewed folder.<nl/>"
1629 "If the items were added to the clipboard by the <emphasis>Cut</emphasis> "
1630 "action they are removed from their old location.") + cutCopyPastePara
);
1632 QAction
* copyToOtherViewAction
= actionCollection()->addAction(QStringLiteral("copy_to_inactive_split_view"));
1633 copyToOtherViewAction
->setText(i18nc("@action:inmenu", "Copy to Inactive Split View"));
1634 m_actionTextHelper
->registerTextWhenNothingIsSelected(copyToOtherViewAction
, i18nc("@action:inmenu", "Copy to Inactive Split View…"));
1635 copyToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Copy", "This copies the selected items from "
1636 "the <emphasis>active</emphasis> view to the inactive split view."));
1637 copyToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
1638 copyToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Copy to Inactive Split View"));
1639 actionCollection()->setDefaultShortcut(copyToOtherViewAction
, Qt::SHIFT
| Qt::Key_F5
);
1640 connect(copyToOtherViewAction
, &QAction::triggered
, this, &DolphinMainWindow::copyToInactiveSplitView
);
1642 QAction
* moveToOtherViewAction
= actionCollection()->addAction(QStringLiteral("move_to_inactive_split_view"));
1643 moveToOtherViewAction
->setText(i18nc("@action:inmenu", "Move to Inactive Split View"));
1644 m_actionTextHelper
->registerTextWhenNothingIsSelected(moveToOtherViewAction
, i18nc("@action:inmenu", "Move to Inactive Split View…"));
1645 moveToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Move", "This moves the selected items from "
1646 "the <emphasis>active</emphasis> view to the inactive split view."));
1647 moveToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-cut")));
1648 moveToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Move to Inactive Split View"));
1649 actionCollection()->setDefaultShortcut(moveToOtherViewAction
, Qt::SHIFT
| Qt::Key_F6
);
1650 connect(moveToOtherViewAction
, &QAction::triggered
, this, &DolphinMainWindow::moveToInactiveSplitView
);
1652 QAction
* showFilterBar
= actionCollection()->addAction(QStringLiteral("show_filter_bar"));
1653 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Filter..."));
1654 showFilterBar
->setToolTip(i18nc("@info:tooltip", "Show Filter Bar"));
1655 showFilterBar
->setWhatsThis(xi18nc("@info:whatsthis", "This opens the "
1656 "<emphasis>Filter Bar</emphasis> at the bottom of the window.<nl/> "
1657 "There you can enter a text to filter the files and folders currently displayed. "
1658 "Only those that contain the text in their name will be kept in view."));
1659 showFilterBar
->setIcon(QIcon::fromTheme(QStringLiteral("view-filter")));
1660 actionCollection()->setDefaultShortcuts(showFilterBar
, {Qt::CTRL
| Qt::Key_I
, Qt::Key_Slash
});
1661 connect(showFilterBar
, &QAction::triggered
, this, &DolphinMainWindow::showFilterBar
);
1663 // toggle_filter acts as a copy of the main showFilterBar to be used mainly
1664 // in the toolbar, with no default shortcut attached, to avoid messing with
1665 // existing workflows (filter bar always open and Ctrl-I to focus)
1666 QAction
*toggleFilter
= actionCollection()->addAction(QStringLiteral("toggle_filter"));
1667 toggleFilter
->setText(i18nc("@action:inmenu", "Toggle Filter Bar"));
1668 toggleFilter
->setIconText(i18nc("@action:intoolbar", "Filter"));
1669 toggleFilter
->setIcon(showFilterBar
->icon());
1670 toggleFilter
->setToolTip(showFilterBar
->toolTip());
1671 toggleFilter
->setWhatsThis(showFilterBar
->whatsThis());
1672 toggleFilter
->setCheckable(true);
1673 connect(toggleFilter
, &QAction::triggered
, this, &DolphinMainWindow::toggleFilterBar
);
1675 QAction
*searchAction
= KStandardAction::find(this, &DolphinMainWindow::find
, actionCollection());
1676 searchAction
->setText(i18n("Search..."));
1677 searchAction
->setToolTip(i18nc("@info:tooltip", "Search for files and folders"));
1678 searchAction
->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This helps you "
1679 "find files and folders by opening a <emphasis>find bar</emphasis>. "
1680 "There you can enter search terms and specify settings to find the "
1681 "objects you are looking for.</para><para>Use this help again on "
1682 "the find bar so we can have a look at it while the settings are "
1683 "explained.</para>"));
1685 // toggle_search acts as a copy of the main searchAction to be used mainly
1686 // in the toolbar, with no default shortcut attached, to avoid messing with
1687 // existing workflows (search bar always open and Ctrl-F to focus)
1688 QAction
*toggleSearchAction
= actionCollection()->addAction(QStringLiteral("toggle_search"));
1689 toggleSearchAction
->setText(i18nc("@action:inmenu", "Toggle Search Bar"));
1690 toggleSearchAction
->setIconText(i18nc("@action:intoolbar", "Search"));
1691 toggleSearchAction
->setIcon(searchAction
->icon());
1692 toggleSearchAction
->setToolTip(searchAction
->toolTip());
1693 toggleSearchAction
->setWhatsThis(searchAction
->whatsThis());
1694 toggleSearchAction
->setCheckable(true);
1696 QAction
*toggleSelectionModeAction
= actionCollection()->addAction(QStringLiteral("toggle_selection_mode"));
1697 // i18n: This action toggles a selection mode.
1698 toggleSelectionModeAction
->setText(i18nc("@action:inmenu", "Select Files and Folders"));
1699 // i18n: Opens a selection mode for selecting files/folders.
1700 // The text is kept so unspecific because it will be shown on the toolbar where space is at a premium.
1701 toggleSelectionModeAction
->setIconText(i18nc("@action:intoolbar", "Select"));
1702 toggleSelectionModeAction
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This application only knows which files or folders should be acted on if they are"
1703 " <emphasis>selected</emphasis> first. Press this to toggle a <emphasis>Selection Mode</emphasis> which makes selecting and deselecting as easy as "
1704 "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."
1706 toggleSelectionModeAction
->setIcon(QIcon::fromTheme(QStringLiteral("quickwizard")));
1707 toggleSelectionModeAction
->setCheckable(true);
1708 actionCollection()->setDefaultShortcut(toggleSelectionModeAction
, Qt::Key_Space
);
1709 connect(toggleSelectionModeAction
, &QAction::triggered
, this, &DolphinMainWindow::toggleSelectionMode
);
1711 // A special version of the toggleSelectionModeAction for the toolbar that also contains a menu
1712 // with the selectAllAction and invertSelectionAction.
1713 auto *toggleSelectionModeToolBarAction
= new KToolBarPopupAction(toggleSelectionModeAction
->icon(), toggleSelectionModeAction
->iconText(), actionCollection());
1714 toggleSelectionModeToolBarAction
->setToolTip(toggleSelectionModeAction
->text());
1715 toggleSelectionModeToolBarAction
->setWhatsThis(toggleSelectionModeAction
->whatsThis());
1716 actionCollection()->addAction(QStringLiteral("toggle_selection_mode_tool_bar"), toggleSelectionModeToolBarAction
);
1717 toggleSelectionModeToolBarAction
->setCheckable(true);
1718 toggleSelectionModeToolBarAction
->setPopupMode(QToolButton::DelayedPopup
);
1719 connect(toggleSelectionModeToolBarAction
, &QAction::triggered
, toggleSelectionModeAction
, &QAction::trigger
);
1720 connect(toggleSelectionModeAction
, &QAction::toggled
, toggleSelectionModeToolBarAction
, &QAction::setChecked
);
1722 QAction
* selectAllAction
= KStandardAction::selectAll(this, &DolphinMainWindow::selectAll
, actionCollection());
1723 selectAllAction
->setWhatsThis(xi18nc("@info:whatsthis", "This selects all "
1724 "files and folders in the current location."));
1726 QAction
* invertSelection
= actionCollection()->addAction(QStringLiteral("invert_selection"));
1727 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1728 invertSelection
->setWhatsThis(xi18nc("@info:whatsthis invert", "This selects all "
1729 "objects that you have currently <emphasis>not</emphasis> selected instead."));
1730 invertSelection
->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-invert")));
1731 actionCollection()->setDefaultShortcut(invertSelection
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1732 connect(invertSelection
, &QAction::triggered
, this, &DolphinMainWindow::invertSelection
);
1734 QMenu
*toggleSelectionModeActionMenu
= new QMenu(this);
1735 toggleSelectionModeActionMenu
->addAction(selectAllAction
);
1736 toggleSelectionModeActionMenu
->addAction(invertSelection
);
1737 toggleSelectionModeToolBarAction
->setMenu(toggleSelectionModeActionMenu
);
1739 // setup 'View' menu
1740 // (note that most of it is set up in DolphinViewActionHandler)
1742 QAction
* split
= actionCollection()->addAction(QStringLiteral("split_view"));
1743 split
->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This splits "
1744 "the folder view below into two autonomous views.</para><para>This "
1745 "way you can see two locations at once and move items between them "
1746 "quickly.</para>Click this again afterwards to recombine the views."));
1747 actionCollection()->setDefaultShortcut(split
, Qt::Key_F3
);
1748 connect(split
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitView
);
1750 QAction
* stashSplit
= actionCollection()->addAction(QStringLiteral("split_stash"));
1751 actionCollection()->setDefaultShortcut(stashSplit
, Qt::CTRL
| Qt::Key_S
);
1752 stashSplit
->setText(i18nc("@action:intoolbar Stash", "Stash"));
1753 stashSplit
->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
1754 stashSplit
->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
1755 stashSplit
->setCheckable(false);
1756 QDBusConnectionInterface
*sessionInterface
= QDBusConnection::sessionBus().interface();
1757 stashSplit
->setVisible(sessionInterface
&& sessionInterface
->isServiceRegistered(QStringLiteral("org.kde.kio.StashNotifier")));
1758 connect(stashSplit
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitStash
);
1760 KStandardAction::redisplay(this, &DolphinMainWindow::reloadView
, actionCollection());
1762 QAction
* stop
= actionCollection()->addAction(QStringLiteral("stop"));
1763 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1764 stop
->setToolTip(i18nc("@info", "Stop loading"));
1765 stop
->setWhatsThis(i18nc("@info", "This stops the loading of the contents of the current folder."));
1766 stop
->setIcon(QIcon::fromTheme(QStringLiteral("process-stop")));
1767 connect(stop
, &QAction::triggered
, this, &DolphinMainWindow::stopLoading
);
1769 KToggleAction
* editableLocation
= actionCollection()->add
<KToggleAction
>(QStringLiteral("editable_location"));
1770 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1771 editableLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1772 "This toggles the <emphasis>Location Bar</emphasis> to be "
1773 "editable so you can directly enter a location you want to go to.<nl/>"
1774 "You can also switch to editing by clicking to the right of the "
1775 "location and switch back by confirming the edited location."));
1776 actionCollection()->setDefaultShortcut(editableLocation
, Qt::Key_F6
);
1777 connect(editableLocation
, &KToggleAction::triggered
, this, &DolphinMainWindow::toggleEditLocation
);
1779 QAction
* replaceLocation
= actionCollection()->addAction(QStringLiteral("replace_location"));
1780 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1781 // i18n: "enter" is used both in the meaning of "writing" and "going to" a new location here.
1782 // Both meanings are useful but not necessary to understand the use of "Replace Location".
1783 // So you might want to be more verbose in your language to convey the meaning but it's up to you.
1784 replaceLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1785 "This switches to editing the location and selects it "
1786 "so you can quickly enter a different location."));
1787 actionCollection()->setDefaultShortcut(replaceLocation
, Qt::CTRL
| Qt::Key_L
);
1788 connect(replaceLocation
, &QAction::triggered
, this, &DolphinMainWindow::replaceLocation
);
1792 QScopedPointer
<QAction
> backAction(KStandardAction::back(nullptr, nullptr, nullptr));
1793 m_backAction
= new KToolBarPopupAction(backAction
->icon(), backAction
->text(), actionCollection());
1794 m_backAction
->setObjectName(backAction
->objectName());
1795 m_backAction
->setShortcuts(backAction
->shortcuts());
1797 m_backAction
->setPopupMode(QToolButton::DelayedPopup
);
1798 connect(m_backAction
, &QAction::triggered
, this, &DolphinMainWindow::goBack
);
1799 connect(m_backAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowBackPopupMenu
);
1800 connect(m_backAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoBack
);
1801 actionCollection()->addAction(m_backAction
->objectName(), m_backAction
);
1803 auto backShortcuts
= m_backAction
->shortcuts();
1804 backShortcuts
.append(QKeySequence(Qt::Key_Backspace
));
1805 actionCollection()->setDefaultShortcuts(m_backAction
, backShortcuts
);
1807 DolphinRecentTabsMenu
* recentTabsMenu
= new DolphinRecentTabsMenu(this);
1808 actionCollection()->addAction(QStringLiteral("closed_tabs"), recentTabsMenu
);
1809 connect(m_tabWidget
, &DolphinTabWidget::rememberClosedTab
,
1810 recentTabsMenu
, &DolphinRecentTabsMenu::rememberClosedTab
);
1811 connect(recentTabsMenu
, &DolphinRecentTabsMenu::restoreClosedTab
,
1812 m_tabWidget
, &DolphinTabWidget::restoreClosedTab
);
1813 connect(recentTabsMenu
, &DolphinRecentTabsMenu::closedTabsCountChanged
,
1814 this, &DolphinMainWindow::closedTabsCountChanged
);
1816 QAction
* undoCloseTab
= actionCollection()->addAction(QStringLiteral("undo_close_tab"));
1817 undoCloseTab
->setText(i18nc("@action:inmenu File", "Undo close tab"));
1818 undoCloseTab
->setWhatsThis(i18nc("@info:whatsthis undo close tab",
1819 "This returns you to the previously closed tab."));
1820 actionCollection()->setDefaultShortcut(undoCloseTab
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_T
);
1821 undoCloseTab
->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo")));
1822 undoCloseTab
->setEnabled(false);
1823 connect(undoCloseTab
, &QAction::triggered
, recentTabsMenu
, &DolphinRecentTabsMenu::undoCloseTab
);
1825 auto undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
1826 undoAction
->setWhatsThis(xi18nc("@info:whatsthis", "This undoes "
1827 "the last change you made to files or folders.<nl/>"
1828 "Such changes include <interface>creating, renaming</interface> "
1829 "and <interface>moving</interface> them to a different location "
1830 "or to the <filename>Trash</filename>. <nl/>Changes that can't "
1831 "be undone will ask for your confirmation."));
1832 undoAction
->setEnabled(false); // undo should be disabled by default
1835 QScopedPointer
<QAction
> forwardAction(KStandardAction::forward(nullptr, nullptr, nullptr));
1836 m_forwardAction
= new KToolBarPopupAction(forwardAction
->icon(), forwardAction
->text(), actionCollection());
1837 m_forwardAction
->setObjectName(forwardAction
->objectName());
1838 m_forwardAction
->setShortcuts(forwardAction
->shortcuts());
1840 m_forwardAction
->setPopupMode(QToolButton::DelayedPopup
);
1841 connect(m_forwardAction
, &QAction::triggered
, this, &DolphinMainWindow::goForward
);
1842 connect(m_forwardAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowForwardPopupMenu
);
1843 connect(m_forwardAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoForward
);
1844 actionCollection()->addAction(m_forwardAction
->objectName(), m_forwardAction
);
1845 actionCollection()->setDefaultShortcuts(m_forwardAction
, m_forwardAction
->shortcuts());
1847 // enable middle-click to open in a new tab
1848 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
1849 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotBackForwardActionMiddleClicked
);
1850 m_backAction
->menu()->installEventFilter(middleClickEventFilter
);
1851 m_forwardAction
->menu()->installEventFilter(middleClickEventFilter
);
1852 KStandardAction::up(this, &DolphinMainWindow::goUp
, actionCollection());
1853 QAction
* homeAction
= KStandardAction::home(this, &DolphinMainWindow::goHome
, actionCollection());
1854 homeAction
->setWhatsThis(xi18nc("@info:whatsthis", "Go to your "
1855 "<filename>Home</filename> folder.<nl/>Every user account "
1856 "has their own <filename>Home</filename> that contains their data "
1857 "including folders that contain personal application data."));
1859 // setup 'Tools' menu
1860 QAction
* compareFiles
= actionCollection()->addAction(QStringLiteral("compare_files"));
1861 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1862 compareFiles
->setIcon(QIcon::fromTheme(QStringLiteral("kompare")));
1863 compareFiles
->setEnabled(false);
1864 connect(compareFiles
, &QAction::triggered
, this, &DolphinMainWindow::compareFiles
);
1866 QAction
* openPreferredSearchTool
= actionCollection()->addAction(QStringLiteral("open_preferred_search_tool"));
1867 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1868 openPreferredSearchTool
->setWhatsThis(xi18nc("@info:whatsthis",
1869 "<para>This opens a preferred search tool for the viewed location.</para>"
1870 "<para>Use <emphasis>More Search Tools</emphasis> menu to configure it.</para>"));
1871 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1872 actionCollection()->setDefaultShortcut(openPreferredSearchTool
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F
);
1873 connect(openPreferredSearchTool
, &QAction::triggered
, this, &DolphinMainWindow::openPreferredSearchTool
);
1875 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1876 QAction
* openTerminal
= actionCollection()->addAction(QStringLiteral("open_terminal"));
1877 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1878 openTerminal
->setWhatsThis(xi18nc("@info:whatsthis",
1879 "<para>This opens a <emphasis>terminal</emphasis> application for the viewed location.</para>"
1880 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1881 openTerminal
->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
1882 actionCollection()->setDefaultShortcut(openTerminal
, Qt::SHIFT
| Qt::Key_F4
);
1883 connect(openTerminal
, &QAction::triggered
, this, &DolphinMainWindow::openTerminal
);
1885 QAction
* openTerminalHere
= actionCollection()->addAction(QStringLiteral("open_terminal_here"));
1886 // i18n: "Here" refers to the location(s) of the currently selected item(s) or the currently viewed location if nothing is selected.
1887 openTerminalHere
->setText(i18nc("@action:inmenu Tools", "Open Terminal Here"));
1888 openTerminalHere
->setWhatsThis(xi18nc("@info:whatsthis",
1889 "<para>This opens <emphasis>terminal</emphasis> applications for the selected items' locations.</para>"
1890 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1891 openTerminalHere
->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
1892 actionCollection()->setDefaultShortcut(openTerminalHere
, Qt::SHIFT
| Qt::ALT
| Qt::Key_F4
);
1893 connect(openTerminalHere
, &QAction::triggered
, this, &DolphinMainWindow::openTerminalHere
);
1896 QAction
* focusTerminalPanel
= actionCollection()->addAction(QStringLiteral("focus_terminal_panel"));
1897 focusTerminalPanel
->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
1898 focusTerminalPanel
->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
1899 actionCollection()->setDefaultShortcut(focusTerminalPanel
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F4
);
1900 connect(focusTerminalPanel
, &QAction::triggered
, this, &DolphinMainWindow::focusTerminalPanel
);
1904 // setup 'Bookmarks' menu
1905 KActionMenu
*bookmarkMenu
= new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this);
1906 bookmarkMenu
->setIcon(QIcon::fromTheme(QStringLiteral("bookmarks")));
1907 // Make the toolbar button version work properly on click
1908 bookmarkMenu
->setPopupMode(QToolButton::InstantPopup
);
1909 m_bookmarkHandler
= new DolphinBookmarkHandler(this, actionCollection(), bookmarkMenu
->menu(), this);
1910 actionCollection()->addAction(QStringLiteral("bookmarks"), bookmarkMenu
);
1912 // setup 'Settings' menu
1913 KToggleAction
* showMenuBar
= KStandardAction::showMenubar(nullptr, nullptr, actionCollection());
1914 showMenuBar
->setWhatsThis(xi18nc("@info:whatsthis",
1915 "<para>This switches between having a <emphasis>Menubar</emphasis> "
1916 "and having a <interface>%1</interface> button. Both "
1917 "contain mostly the same actions and configuration options.</para>"
1918 "<para>The Menubar takes up more space but allows for fast and organised access to all "
1919 "actions an application has to offer.</para><para>The <interface>%1</interface> button "
1920 "is simpler and small which makes triggering advanced actions more time consuming.</para>", hamburgerMenuAction
->text().replace('&', "")));
1921 connect(showMenuBar
, &KToggleAction::triggered
, // Fixes #286822
1922 this, &DolphinMainWindow::toggleShowMenuBar
, Qt::QueuedConnection
);
1924 KToggleAction
* showStatusBar
= KStandardAction::showStatusbar(nullptr, nullptr, actionCollection());
1925 showStatusBar
->setChecked(GeneralSettings::showStatusBar());
1926 connect(GeneralSettings::self(), &GeneralSettings::showStatusBarChanged
, showStatusBar
, &KToggleAction::setChecked
);
1927 connect(showStatusBar
, &KToggleAction::triggered
, this, [this](bool checked
) {
1928 GeneralSettings::setShowStatusBar(checked
);
1932 KStandardAction::keyBindings(this, &DolphinMainWindow::slotKeyBindings
, actionCollection());
1933 KStandardAction::preferences(this, &DolphinMainWindow::editSettings
, actionCollection());
1935 // not in menu actions
1936 QList
<QKeySequence
> nextTabKeys
= KStandardShortcut::tabNext();
1937 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
1939 QList
<QKeySequence
> prevTabKeys
= KStandardShortcut::tabPrev();
1940 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
1942 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1943 QAction
* activateTab
= actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i
));
1944 activateTab
->setText(i18nc("@action:inmenu", "Activate Tab %1", i
+ 1));
1945 activateTab
->setEnabled(false);
1946 connect(activateTab
, &QAction::triggered
, this, [this, i
]() { m_tabWidget
->activateTab(i
); });
1948 // only add default shortcuts for the first 9 tabs regardless of MaxActivateTabShortcuts
1950 actionCollection()->setDefaultShortcut(activateTab
, QStringLiteral("Alt+%1").arg(i
+ 1));
1954 QAction
* activateLastTab
= actionCollection()->addAction(QStringLiteral("activate_last_tab"));
1955 activateLastTab
->setText(i18nc("@action:inmenu", "Activate Last Tab"));
1956 activateLastTab
->setEnabled(false);
1957 connect(activateLastTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateLastTab
);
1958 actionCollection()->setDefaultShortcut(activateLastTab
, Qt::ALT
| Qt::Key_0
);
1960 QAction
* activateNextTab
= actionCollection()->addAction(QStringLiteral("activate_next_tab"));
1961 activateNextTab
->setIconText(i18nc("@action:inmenu", "Next Tab"));
1962 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1963 activateNextTab
->setEnabled(false);
1964 connect(activateNextTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateNextTab
);
1965 actionCollection()->setDefaultShortcuts(activateNextTab
, nextTabKeys
);
1967 QAction
* activatePrevTab
= actionCollection()->addAction(QStringLiteral("activate_prev_tab"));
1968 activatePrevTab
->setIconText(i18nc("@action:inmenu", "Previous Tab"));
1969 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1970 activatePrevTab
->setEnabled(false);
1971 connect(activatePrevTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activatePrevTab
);
1972 actionCollection()->setDefaultShortcuts(activatePrevTab
, prevTabKeys
);
1975 QAction
* showTarget
= actionCollection()->addAction(QStringLiteral("show_target"));
1976 showTarget
->setText(i18nc("@action:inmenu", "Show Target"));
1977 showTarget
->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
1978 showTarget
->setEnabled(false);
1979 connect(showTarget
, &QAction::triggered
, this, &DolphinMainWindow::showTarget
);
1981 QAction
* openInNewTab
= actionCollection()->addAction(QStringLiteral("open_in_new_tab"));
1982 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1983 openInNewTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1984 connect(openInNewTab
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
1986 QAction
* openInNewTabs
= actionCollection()->addAction(QStringLiteral("open_in_new_tabs"));
1987 openInNewTabs
->setText(i18nc("@action:inmenu", "Open in New Tabs"));
1988 openInNewTabs
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1989 connect(openInNewTabs
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
1991 QAction
* openInNewWindow
= actionCollection()->addAction(QStringLiteral("open_in_new_window"));
1992 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1993 openInNewWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1994 connect(openInNewWindow
, &QAction::triggered
, this, &DolphinMainWindow::openInNewWindow
);
1997 void DolphinMainWindow::setupDockWidgets()
1999 const bool lock
= GeneralSettings::lockPanels();
2001 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(lock
);
2003 KDualAction
* lockLayoutAction
= actionCollection()->add
<KDualAction
>(QStringLiteral("lock_panels"));
2004 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
2005 lockLayoutAction
->setActiveIcon(QIcon::fromTheme(QStringLiteral("object-unlocked")));
2006 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
2007 lockLayoutAction
->setInactiveIcon(QIcon::fromTheme(QStringLiteral("object-locked")));
2008 lockLayoutAction
->setWhatsThis(xi18nc("@info:whatsthis", "This "
2009 "switches between having panels <emphasis>locked</emphasis> or "
2010 "<emphasis>unlocked</emphasis>.<nl/>Unlocked panels can be "
2011 "dragged to the other side of the window and have a close "
2012 "button.<nl/>Locked panels are embedded more cleanly."));
2013 lockLayoutAction
->setActive(lock
);
2014 connect(lockLayoutAction
, &KDualAction::triggered
, this, &DolphinMainWindow::togglePanelLockState
);
2016 // Setup "Information"
2017 DolphinDockWidget
* infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
2018 infoDock
->setLocked(lock
);
2019 infoDock
->setObjectName(QStringLiteral("infoDock"));
2020 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2023 InformationPanel
* infoPanel
= new InformationPanel(infoDock
);
2024 infoPanel
->setCustomContextMenuActions({lockLayoutAction
});
2025 connect(infoPanel
, &InformationPanel::urlActivated
, this, &DolphinMainWindow::handleUrl
);
2026 infoDock
->setWidget(infoPanel
);
2028 QAction
* infoAction
= infoDock
->toggleViewAction();
2029 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-information")), Qt::Key_F11
, infoAction
, QStringLiteral("show_information_panel"));
2031 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
2032 connect(this, &DolphinMainWindow::urlChanged
,
2033 infoPanel
, &InformationPanel::setUrl
);
2034 connect(this, &DolphinMainWindow::selectionChanged
,
2035 infoPanel
, &InformationPanel::setSelection
);
2036 connect(this, &DolphinMainWindow::requestItemInfo
,
2037 infoPanel
, &InformationPanel::requestDelayedItemInfo
);
2038 connect(this, &DolphinMainWindow::fileItemsChanged
,
2039 infoPanel
, &InformationPanel::slotFilesItemChanged
);
2042 // i18n: This is the last paragraph for the "What's This"-texts of all four panels.
2043 const QString panelWhatsThis
= xi18nc("@info:whatsthis", "<para>To show or "
2044 "hide panels like this go to <interface>Menu|Panels</interface> "
2045 "or <interface>View|Panels</interface>.</para>");
2047 actionCollection()->action(QStringLiteral("show_information_panel"))
2048 ->setWhatsThis(xi18nc("@info:whatsthis", "<para> This toggles the "
2049 "<emphasis>information</emphasis> panel at the right side of the "
2050 "window.</para><para>The panel provides in-depth information "
2051 "about the items your mouse is hovering over or about the selected "
2052 "items. Otherwise it informs you about the currently viewed folder.<nl/>"
2053 "For single items a preview of their contents is provided.</para>"));
2055 infoDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
2056 "provides in-depth information about the items your mouse is "
2057 "hovering over or about the selected items. Otherwise it informs "
2058 "you about the currently viewed folder.<nl/>For single items a "
2059 "preview of their contents is provided.</para><para>You can configure "
2060 "which and how details are given here by right-clicking.</para>") + panelWhatsThis
);
2063 DolphinDockWidget
* foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
2064 foldersDock
->setLocked(lock
);
2065 foldersDock
->setObjectName(QStringLiteral("foldersDock"));
2066 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2067 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
2068 foldersPanel
->setCustomContextMenuActions({lockLayoutAction
});
2069 foldersDock
->setWidget(foldersPanel
);
2071 QAction
* foldersAction
= foldersDock
->toggleViewAction();
2072 createPanelAction(QIcon::fromTheme(QStringLiteral("folder")), Qt::Key_F7
, foldersAction
, QStringLiteral("show_folders_panel"));
2074 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
2075 connect(this, &DolphinMainWindow::urlChanged
,
2076 foldersPanel
, &FoldersPanel::setUrl
);
2077 connect(foldersPanel
, &FoldersPanel::folderActivated
,
2078 this, &DolphinMainWindow::changeUrl
);
2079 connect(foldersPanel
, &FoldersPanel::folderInNewTab
,
2080 this, &DolphinMainWindow::openNewTab
);
2081 connect(foldersPanel
, &FoldersPanel::folderInNewActiveTab
,
2082 this, &DolphinMainWindow::openNewTabAndActivate
);
2083 connect(foldersPanel
, &FoldersPanel::errorMessage
,
2084 this, &DolphinMainWindow::showErrorMessage
);
2086 actionCollection()->action(QStringLiteral("show_folders_panel"))
2087 ->setWhatsThis(xi18nc("@info:whatsthis", "This toggles the "
2088 "<emphasis>folders</emphasis> panel at the left side of the window."
2089 "<nl/><nl/>It shows the folders of the <emphasis>file system"
2090 "</emphasis> in a <emphasis>tree view</emphasis>."));
2091 foldersDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
2092 "shows the folders of the <emphasis>file system</emphasis> in a "
2093 "<emphasis>tree view</emphasis>.</para><para>Click a folder to go "
2094 "there. Click the arrow to the left of a folder to see its subfolders. "
2095 "This allows quick switching between any folders.</para>") + panelWhatsThis
);
2099 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
2100 DolphinDockWidget
* terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
2101 terminalDock
->setLocked(lock
);
2102 terminalDock
->setObjectName(QStringLiteral("terminalDock"));
2103 m_terminalPanel
= new TerminalPanel(terminalDock
);
2104 m_terminalPanel
->setCustomContextMenuActions({lockLayoutAction
});
2105 terminalDock
->setWidget(m_terminalPanel
);
2107 connect(m_terminalPanel
, &TerminalPanel::hideTerminalPanel
, terminalDock
, &DolphinDockWidget::hide
);
2108 connect(m_terminalPanel
, &TerminalPanel::changeUrl
, this, &DolphinMainWindow::slotTerminalDirectoryChanged
);
2109 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
,
2110 m_terminalPanel
, &TerminalPanel::dockVisibilityChanged
);
2111 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
,
2112 this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged
);
2114 QAction
* terminalAction
= terminalDock
->toggleViewAction();
2115 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-scripts")), Qt::Key_F4
, terminalAction
, QStringLiteral("show_terminal_panel"));
2117 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
2118 connect(this, &DolphinMainWindow::urlChanged
,
2119 m_terminalPanel
, &TerminalPanel::setUrl
);
2121 if (GeneralSettings::version() < 200) {
2122 terminalDock
->hide();
2125 actionCollection()->action(QStringLiteral("show_terminal_panel"))
2126 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
2127 "<emphasis>terminal</emphasis> panel at the bottom of the window."
2128 "<nl/>The location in the terminal will always match the folder "
2129 "view so you can navigate using either.</para><para>The terminal "
2130 "panel is not needed for basic computer usage but can be useful "
2131 "for advanced tasks. To learn more about terminals use the help "
2132 "in a standalone terminal application like Konsole.</para>"));
2133 terminalDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is "
2134 "the <emphasis>terminal</emphasis> panel. It behaves like a "
2135 "normal terminal but will match the location of the folder view "
2136 "so you can navigate using either.</para><para>The terminal panel "
2137 "is not needed for basic computer usage but can be useful for "
2138 "advanced tasks. To learn more about terminals use the help in a "
2139 "standalone terminal application like Konsole.</para>") + panelWhatsThis
);
2143 if (GeneralSettings::version() < 200) {
2145 foldersDock
->hide();
2149 DolphinDockWidget
* placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
2150 placesDock
->setLocked(lock
);
2151 placesDock
->setObjectName(QStringLiteral("placesDock"));
2152 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2154 m_placesPanel
= new PlacesPanel(placesDock
);
2155 m_placesPanel
->setCustomContextMenuActions({lockLayoutAction
});
2156 placesDock
->setWidget(m_placesPanel
);
2158 QAction
*placesAction
= placesDock
->toggleViewAction();
2159 createPanelAction(QIcon::fromTheme(QStringLiteral("compass")), Qt::Key_F9
, placesAction
, QStringLiteral("show_places_panel"));
2161 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
2162 connect(m_placesPanel
, &PlacesPanel::placeActivated
,
2163 this, &DolphinMainWindow::slotPlaceActivated
);
2164 connect(m_placesPanel
, &PlacesPanel::tabRequested
,
2165 this, &DolphinMainWindow::openNewTab
);
2166 connect(m_placesPanel
, &PlacesPanel::activeTabRequested
,
2167 this, &DolphinMainWindow::openNewTabAndActivate
);
2168 connect(m_placesPanel
, &PlacesPanel::newWindowRequested
, this, [this](const QUrl
&url
) {
2169 Dolphin::openNewWindow({url
}, this);
2171 connect(m_placesPanel
, &PlacesPanel::errorMessage
,
2172 this, &DolphinMainWindow::showErrorMessage
);
2173 connect(this, &DolphinMainWindow::urlChanged
,
2174 m_placesPanel
, &PlacesPanel::setUrl
);
2175 connect(placesDock
, &DolphinDockWidget::visibilityChanged
,
2176 &DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged
);
2177 connect(this, &DolphinMainWindow::settingsChanged
,
2178 m_placesPanel
, &PlacesPanel::readSettings
);
2179 connect(m_placesPanel
, &PlacesPanel::storageTearDownRequested
,
2180 this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested
);
2181 connect(m_placesPanel
, &PlacesPanel::storageTearDownExternallyRequested
,
2182 this, &DolphinMainWindow::slotStorageTearDownExternallyRequested
);
2183 DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged(m_placesPanel
->isVisible());
2185 auto actionShowAllPlaces
= new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this);
2186 actionShowAllPlaces
->setCheckable(true);
2187 actionShowAllPlaces
->setDisabled(true);
2188 actionShowAllPlaces
->setWhatsThis(i18nc("@info:whatsthis", "This displays "
2189 "all places in the places panel that have been hidden. They will "
2190 "appear semi-transparent unless you uncheck their hide property."));
2192 connect(actionShowAllPlaces
, &QAction::triggered
, this, [actionShowAllPlaces
, this](bool checked
){
2193 m_placesPanel
->setShowAll(checked
);
2195 connect(m_placesPanel
, &PlacesPanel::allPlacesShownChanged
, actionShowAllPlaces
, &QAction::setChecked
);
2197 actionCollection()->action(QStringLiteral("show_places_panel"))
2198 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
2199 "<emphasis>places</emphasis> panel at the left side of the window."
2200 "</para><para>It allows you to go to locations you have "
2201 "bookmarked and to access disk or media attached to the computer "
2202 "or to the network. It also contains sections to find recently "
2203 "saved files or files of a certain type.</para>"));
2204 placesDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2205 "<emphasis>Places</emphasis> panel. It allows you to go to locations "
2206 "you have bookmarked and to access disk or media attached to the "
2207 "computer or to the network. It also contains sections to find "
2208 "recently saved files or files of a certain type.</para><para>"
2209 "Click on an entry to go there. Click with the right mouse button "
2210 "instead to open any entry in a new tab or new window.</para>"
2211 "<para>New entries can be added by dragging folders onto this panel. "
2212 "Right-click any section or entry to hide it. Right-click an empty "
2213 "space on this panel and select <interface>Show Hidden Places"
2214 "</interface> to display it again.</para>") + panelWhatsThis
);
2216 // Add actions into the "Panels" menu
2217 KActionMenu
* panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Show Panels"), this);
2218 actionCollection()->addAction(QStringLiteral("panels"), panelsMenu
);
2219 panelsMenu
->setIcon(QIcon::fromTheme(QStringLiteral("view-sidetree")));
2220 panelsMenu
->setPopupMode(QToolButton::InstantPopup
);
2221 const KActionCollection
* ac
= actionCollection();
2222 panelsMenu
->addAction(ac
->action(QStringLiteral("show_places_panel")));
2224 panelsMenu
->addAction(ac
->action(QStringLiteral("show_information_panel")));
2226 panelsMenu
->addAction(ac
->action(QStringLiteral("show_folders_panel")));
2227 panelsMenu
->addAction(ac
->action(QStringLiteral("show_terminal_panel")));
2228 panelsMenu
->addSeparator();
2229 panelsMenu
->addAction(actionShowAllPlaces
);
2230 panelsMenu
->addAction(lockLayoutAction
);
2232 connect(panelsMenu
->menu(), &QMenu::aboutToShow
, this, [actionShowAllPlaces
, this]{
2233 actionShowAllPlaces
->setEnabled(DolphinPlacesModelSingleton::instance().placesModel()->hiddenCount());
2238 void DolphinMainWindow::updateFileAndEditActions()
2240 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
2241 const KActionCollection
* col
= actionCollection();
2242 KFileItemListProperties
capabilitiesSource(list
);
2244 QAction
* renameAction
= col
->action(KStandardAction::name(KStandardAction::RenameFile
));
2245 QAction
* moveToTrashAction
= col
->action(KStandardAction::name(KStandardAction::MoveToTrash
));
2246 QAction
* deleteAction
= col
->action(KStandardAction::name(KStandardAction::DeleteFile
));
2247 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
2248 QAction
* duplicateAction
= col
->action(QStringLiteral("duplicate")); // see DolphinViewActionHandler
2249 QAction
* addToPlacesAction
= col
->action(QStringLiteral("add_to_places"));
2250 QAction
* copyToOtherViewAction
= col
->action(QStringLiteral("copy_to_inactive_split_view"));
2251 QAction
* moveToOtherViewAction
= col
->action(QStringLiteral("move_to_inactive_split_view"));
2252 QAction
* copyLocation
= col
->action(QString("copy_location"));
2254 if (list
.isEmpty()) {
2255 stateChanged(QStringLiteral("has_no_selection"));
2257 // All actions that need a selection to function can be enabled because they should trigger selection mode.
2258 renameAction
->setEnabled(true);
2259 moveToTrashAction
->setEnabled(true);
2260 deleteAction
->setEnabled(true);
2261 cutAction
->setEnabled(true);
2262 duplicateAction
->setEnabled(true);
2263 addToPlacesAction
->setEnabled(true);
2264 copyLocation
->setEnabled(true);
2265 // Them triggering selection mode and not directly acting on selected items is signified by adding "…" to their text.
2266 m_actionTextHelper
->textsWhenNothingIsSelectedEnabled(true);
2269 m_actionTextHelper
->textsWhenNothingIsSelectedEnabled(false);
2270 stateChanged(QStringLiteral("has_selection"));
2272 QAction
* deleteWithTrashShortcut
= col
->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
2273 QAction
* showTarget
= col
->action(QStringLiteral("show_target"));
2275 if (list
.length() == 1 && list
.first().isDir()) {
2276 addToPlacesAction
->setEnabled(true);
2278 addToPlacesAction
->setEnabled(false);
2281 const bool enableMoveToTrash
= capabilitiesSource
.isLocal() && capabilitiesSource
.supportsMoving();
2283 renameAction
->setEnabled(capabilitiesSource
.supportsMoving());
2284 moveToTrashAction
->setEnabled(enableMoveToTrash
);
2285 deleteAction
->setEnabled(capabilitiesSource
.supportsDeleting());
2286 deleteWithTrashShortcut
->setEnabled(capabilitiesSource
.supportsDeleting() && !enableMoveToTrash
);
2287 cutAction
->setEnabled(capabilitiesSource
.supportsMoving());
2288 copyLocation
->setEnabled(list
.length() == 1);
2289 showTarget
->setEnabled(list
.length() == 1 && list
.at(0).isLink());
2290 duplicateAction
->setEnabled(capabilitiesSource
.supportsWriting());
2293 if (m_tabWidget
->currentTabPage()->splitViewEnabled()) {
2294 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
2295 KFileItem capabilitiesDestination
;
2297 if (tabPage
->primaryViewActive()) {
2298 capabilitiesDestination
= tabPage
->secondaryViewContainer()->url();
2300 capabilitiesDestination
= tabPage
->primaryViewContainer()->url();
2303 copyToOtherViewAction
->setEnabled(capabilitiesDestination
.isWritable());
2304 moveToOtherViewAction
->setEnabled((list
.isEmpty() || capabilitiesSource
.supportsMoving()) && capabilitiesDestination
.isWritable());
2306 copyToOtherViewAction
->setEnabled(false);
2307 moveToOtherViewAction
->setEnabled(false);
2311 void DolphinMainWindow::updateViewActions()
2313 m_actionHandler
->updateViewActions();
2315 QAction
* toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
2316 toggleFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
2318 updateSplitAction();
2321 void DolphinMainWindow::updateGoActions()
2323 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
2324 const QUrl currentUrl
= m_activeViewContainer
->url();
2325 // I think this is one of the best places to firstly be confronted
2326 // with a file system and its hierarchy. Talking about the root
2327 // directory might seem too much here but it is the question that
2328 // naturally arises in this context.
2329 goUpAction
->setWhatsThis(xi18nc("@info:whatsthis", "<para>Go to "
2330 "the folder that contains the currently viewed one.</para>"
2331 "<para>All files and folders are organized in a hierarchical "
2332 "<emphasis>file system</emphasis>. At the top of this hierarchy is "
2333 "a directory that contains all data connected to this computer"
2334 "—the <emphasis>root directory</emphasis>.</para>"));
2335 goUpAction
->setEnabled(KIO::upUrl(currentUrl
) != currentUrl
);
2338 void DolphinMainWindow::refreshViews()
2340 m_tabWidget
->refreshViews();
2342 if (GeneralSettings::modifiedStartupSettings()) {
2343 updateWindowTitle();
2346 Q_EMIT
settingsChanged();
2349 void DolphinMainWindow::clearStatusBar()
2351 m_activeViewContainer
->statusBar()->resetToDefaultText();
2354 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
2356 connect(container
, &DolphinViewContainer::showFilterBarChanged
,
2357 this, &DolphinMainWindow::updateFilterBarAction
);
2358 connect(container
, &DolphinViewContainer::writeStateChanged
,
2359 this, &DolphinMainWindow::slotWriteStateChanged
);
2360 connect(container
, &DolphinViewContainer::searchModeEnabledChanged
,
2361 this, &DolphinMainWindow::updateSearchAction
);
2362 connect(container
, &DolphinViewContainer::captionChanged
,
2363 this, &DolphinMainWindow::updateWindowTitle
);
2364 connect(container
, &DolphinViewContainer::tabRequested
,
2365 this, &DolphinMainWindow::openNewTab
);
2366 connect(container
, &DolphinViewContainer::activeTabRequested
,
2367 this, &DolphinMainWindow::openNewTabAndActivate
);
2369 const QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
2370 connect(toggleSearchAction
, &QAction::triggered
, container
, &DolphinViewContainer::setSearchModeEnabled
);
2372 // Make the toggled state of the selection mode actions visually follow the selection mode state of the view.
2373 auto toggleSelectionModeAction
= actionCollection()->action(QStringLiteral("toggle_selection_mode"));
2374 toggleSelectionModeAction
->setChecked(m_activeViewContainer
->isSelectionModeEnabled());
2375 connect(m_activeViewContainer
, &DolphinViewContainer::selectionModeChanged
,
2376 toggleSelectionModeAction
, &QAction::setChecked
);
2378 const DolphinView
* view
= container
->view();
2379 connect(view
, &DolphinView::selectionChanged
,
2380 this, &DolphinMainWindow::slotSelectionChanged
);
2381 connect(view
, &DolphinView::requestItemInfo
,
2382 this, &DolphinMainWindow::requestItemInfo
);
2383 connect(view
, &DolphinView::fileItemsChanged
,
2384 this, &DolphinMainWindow::fileItemsChanged
);
2385 connect(view
, &DolphinView::tabRequested
,
2386 this, &DolphinMainWindow::openNewTab
);
2387 connect(view
, &DolphinView::activeTabRequested
,
2388 this, &DolphinMainWindow::openNewTabAndActivate
);
2389 connect(view
, &DolphinView::windowRequested
,
2390 this, &DolphinMainWindow::openNewWindow
);
2391 connect(view
, &DolphinView::requestContextMenu
,
2392 this, &DolphinMainWindow::openContextMenu
);
2393 connect(view
, &DolphinView::directoryLoadingStarted
,
2394 this, &DolphinMainWindow::enableStopAction
);
2395 connect(view
, &DolphinView::directoryLoadingCompleted
,
2396 this, &DolphinMainWindow::disableStopAction
);
2397 connect(view
, &DolphinView::directoryLoadingCompleted
,
2398 this, &DolphinMainWindow::slotDirectoryLoadingCompleted
);
2399 connect(view
, &DolphinView::goBackRequested
,
2400 this, &DolphinMainWindow::goBack
);
2401 connect(view
, &DolphinView::goForwardRequested
,
2402 this, &DolphinMainWindow::goForward
);
2403 connect(view
, &DolphinView::urlActivated
,
2404 this, &DolphinMainWindow::handleUrl
);
2405 connect(view
, &DolphinView::goUpRequested
,
2406 this, &DolphinMainWindow::goUp
);
2408 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::urlChanged
,
2409 this, &DolphinMainWindow::changeUrl
);
2410 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::historyChanged
,
2411 this, &DolphinMainWindow::updateHistory
);
2413 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
2414 (actionCollection()->action(QStringLiteral("url_navigators")));
2415 const KUrlNavigator
*navigator
= m_tabWidget
->currentTabPage()->primaryViewActive() ?
2416 navigators
->primaryUrlNavigator() :
2417 navigators
->secondaryUrlNavigator();
2419 QAction
*editableLocactionAction
= actionCollection()->action(QStringLiteral("editable_location"));
2420 editableLocactionAction
->setChecked(navigator
->isUrlEditable());
2421 connect(navigator
, &KUrlNavigator::editableStateChanged
,
2422 this, &DolphinMainWindow::slotEditableStateChanged
);
2423 connect(navigator
, &KUrlNavigator::tabRequested
,
2424 this, &DolphinMainWindow::openNewTab
);
2425 connect(navigator
, &KUrlNavigator::activeTabRequested
,
2426 this, &DolphinMainWindow::openNewTabAndActivate
);
2427 connect(navigator
, &KUrlNavigator::newWindowRequested
,
2428 this, &DolphinMainWindow::openNewWindow
);
2432 void DolphinMainWindow::updateSplitAction()
2434 QAction
* splitAction
= actionCollection()->action(QStringLiteral("split_view"));
2435 const DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
2436 if (tabPage
->splitViewEnabled()) {
2437 if (GeneralSettings::closeActiveSplitView() ? tabPage
->primaryViewActive() : !tabPage
->primaryViewActive()) {
2438 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2439 splitAction
->setToolTip(i18nc("@info", "Close left view"));
2440 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close")));
2442 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2443 splitAction
->setToolTip(i18nc("@info", "Close right view"));
2444 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close")));
2447 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2448 splitAction
->setToolTip(i18nc("@info", "Split view"));
2449 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
2453 void DolphinMainWindow::updateAllowedToolbarAreas()
2455 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
2456 (actionCollection()->action(QStringLiteral("url_navigators")));
2457 if (toolBar()->actions().contains(navigators
)) {
2458 toolBar()->setAllowedAreas(Qt::TopToolBarArea
| Qt::BottomToolBarArea
);
2459 if (toolBarArea(toolBar()) == Qt::LeftToolBarArea
||
2460 toolBarArea(toolBar()) == Qt::RightToolBarArea
) {
2461 addToolBar(Qt::TopToolBarArea
, toolBar());
2464 toolBar()->setAllowedAreas(Qt::AllToolBarAreas
);
2468 bool DolphinMainWindow::isKompareInstalled() const
2470 static bool initialized
= false;
2471 static bool installed
= false;
2473 // TODO: maybe replace this approach later by using a menu
2474 // plugin like kdiff3plugin.cpp
2475 installed
= !QStandardPaths::findExecutable(QStringLiteral("kompare")).isEmpty();
2481 void DolphinMainWindow::createPanelAction(const QIcon
& icon
,
2482 const QKeySequence
& shortcut
,
2483 QAction
* dockAction
,
2484 const QString
& actionName
)
2486 QAction
* panelAction
= actionCollection()->addAction(actionName
);
2487 panelAction
->setCheckable(true);
2488 panelAction
->setChecked(dockAction
->isChecked());
2489 panelAction
->setText(dockAction
->text());
2490 panelAction
->setIcon(icon
);
2491 dockAction
->setIcon(icon
);
2492 actionCollection()->setDefaultShortcut(panelAction
, shortcut
);
2494 connect(panelAction
, &QAction::triggered
, dockAction
, &QAction::trigger
);
2495 connect(dockAction
, &QAction::toggled
, panelAction
, &QAction::setChecked
);
2498 void DolphinMainWindow::setupWhatsThis()
2501 menuBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2502 "<emphasis>Menubar</emphasis>. It provides access to commands and "
2503 "configuration options. Left-click on any of the menus on this "
2504 "bar to see its contents.</para><para>The Menubar can be hidden "
2505 "by unchecking <interface>Settings|Show Menubar</interface>. Then "
2506 "most of its contents become available through a <interface>Menu"
2507 "</interface> button on the <emphasis>Toolbar</emphasis>.</para>"));
2508 toolBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2509 "<emphasis>Toolbar</emphasis>. It allows quick access to "
2510 "frequently used actions.</para><para>It is highly customizable. "
2511 "All items you see in the <interface>Menu</interface> or "
2512 "in the <interface>Menubar</interface> can be placed on the "
2513 "Toolbar. Just right-click on it and select <interface>Configure "
2514 "Toolbars…</interface> or find this action within the <interface>"
2516 "</para><para>The location of the bar and the style of its "
2517 "buttons can also be changed in the right-click menu. Right-click "
2518 "a button if you want to show or hide its text.</para>"));
2519 m_tabWidget
->setWhatsThis(xi18nc("@info:whatsthis main view",
2520 "<para>Here you can see the <emphasis>folders</emphasis> and "
2521 "<emphasis>files</emphasis> that are at the location described in "
2522 "the <interface>Location Bar</interface> above. This area is the "
2523 "central part of this application where you navigate to the files "
2524 "you want to use.</para><para>For an elaborate and general "
2525 "introduction to this application <link "
2526 "url='https://userbase.kde.org/Dolphin/File_Management#Introduction_to_Dolphin'>"
2527 "click here</link>. This will open an introductory article from "
2528 "the <emphasis>KDE UserBase Wiki</emphasis>.</para><para>For brief "
2529 "explanations of all the features of this <emphasis>view</emphasis> "
2530 "<link url='help:/dolphin/dolphin-view.html'>click here</link> "
2531 "instead. This will open a page from the <emphasis>Handbook"
2532 "</emphasis> that covers the basics.</para>"));
2535 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings
))
2536 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window "
2537 "that lists the <emphasis>keyboard shortcuts</emphasis>.<nl/>"
2538 "There you can set up key combinations to trigger an action when "
2539 "they are pressed simultaneously. All commands in this application can "
2540 "be triggered this way.</para>"));
2541 actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars
))
2542 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window in which "
2543 "you can change which buttons appear on the <emphasis>Toolbar</emphasis>.</para>"
2544 "<para>All items you see in the <interface>Menu</interface> can also be placed on the Toolbar.</para>"));
2545 actionCollection()->action(KStandardAction::name(KStandardAction::Preferences
))
2546 ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window where you can "
2547 "change a multitude of settings for this application. For an explanation "
2548 "of the various settings go to the chapter <emphasis>Configuring Dolphin"
2549 "</emphasis> in <interface>Help|Dolphin Handbook</interface>."));
2553 // i18n: If the external link isn't available in your language it might make
2554 // sense to state the external link's language in brackets to not
2555 // frustrate the user. If there are multiple languages that the user might
2556 // know with a reasonable chance you might want to have 2 external links.
2557 // The same might be true for any external link you translate.
2558 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>"));
2559 // (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 )
2561 actionCollection()->action(KStandardAction::name(KStandardAction::WhatsThis
))->setWhatsThis(
2562 xi18nc("@info:whatsthis whatsthis button",
2563 "<para>This is the button that invokes the help feature you are "
2564 "using right now! Click it, then click any component of this "
2565 "application to ask \"What's this?\" about it. The mouse cursor "
2566 "will change appearance if no help is available for a spot.</para>"
2567 "<para>There are two other ways to get help: "
2568 "The <link url='help:/dolphin/index.html'>Dolphin Handbook</link> and "
2569 "the <link url='https://userbase.kde.org/Dolphin/File_Management'>KDE "
2570 "UserBase Wiki</link>.</para><para>The \"What's this?\" help is "
2571 "missing in most other windows so don't get too used to this.</para>"));
2573 actionCollection()->action(KStandardAction::name(KStandardAction::ReportBug
))->setWhatsThis(
2574 xi18nc("@info:whatsthis","<para>This opens a "
2575 "window that will guide you through reporting errors or flaws "
2576 "in this application or in other KDE software.</para>"
2577 "<para>High-quality bug reports are much appreciated. To learn "
2578 "how to make your bug report as effective as possible "
2579 "<link url='https://community.kde.org/Get_Involved/Bug_Reporting'>"
2580 "click here</link>.</para>"));
2582 actionCollection()->action(KStandardAction::name(KStandardAction::Donate
))->setWhatsThis(
2583 xi18nc("@info:whatsthis", "<para>This opens a "
2584 "<emphasis>web page</emphasis> where you can donate to "
2585 "support the continued work on this application and many "
2586 "other projects by the <emphasis>KDE</emphasis> community.</para>"
2587 "<para>Donating is the easiest and fastest way to efficiently "
2588 "support KDE and its projects. KDE projects are available for "
2589 "free therefore your donation is needed to cover things that "
2590 "require money like servers, contributor meetings, etc.</para>"
2591 "<para><emphasis>KDE e.V.</emphasis> is the non-profit "
2592 "organization behind the KDE community.</para>"));
2594 actionCollection()->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
))->setWhatsThis(
2595 xi18nc("@info:whatsthis",
2596 "With this you can change the language this application uses."
2597 "<nl/>You can even set secondary languages which will be used "
2598 "if texts are not available in your preferred language."));
2600 actionCollection()->action(KStandardAction::name(KStandardAction::AboutApp
))->setWhatsThis(
2601 xi18nc("@info:whatsthis","This opens a "
2602 "window that informs you about the version, license, "
2603 "used libraries and maintainers of this application."));
2605 actionCollection()->action(KStandardAction::name(KStandardAction::AboutKDE
))->setWhatsThis(
2606 xi18nc("@info:whatsthis","This opens a "
2607 "window with information about <emphasis>KDE</emphasis>. "
2608 "The KDE community are the people behind this free software."
2609 "<nl/>If you like using this application but don't know "
2610 "about KDE or want to see a cute dragon have a look!"));
2613 bool DolphinMainWindow::addHamburgerMenuToToolbar()
2615 QDomDocument domDocument
= KXMLGUIClient::domDocument();
2616 if (domDocument
.isNull()) {
2619 QDomNode toolbar
= domDocument
.elementsByTagName(QStringLiteral("ToolBar")).at(0);
2620 if (toolbar
.isNull()) {
2624 QDomElement hamburgerMenuElement
= domDocument
.createElement(QStringLiteral("Action"));
2625 hamburgerMenuElement
.setAttribute(QStringLiteral("name"), QStringLiteral("hamburger_menu"));
2626 toolbar
.appendChild(hamburgerMenuElement
);
2628 KXMLGUIFactory::saveConfigFile(domDocument
, xmlFile());
2632 // Make sure to also remove the <KXMLGUIFactory> and <QDomDocument> include
2633 // whenever this method is removed (maybe in the year ~2026).
2636 // Set a sane initial window size
2637 QSize
DolphinMainWindow::sizeHint() const
2639 return KXmlGuiWindow::sizeHint().expandedTo(QSize(760, 550));
2642 void DolphinMainWindow::saveNewToolbarConfig()
2644 KXmlGuiWindow::saveNewToolbarConfig(); // Applies the new config. This has to be called first
2645 // because the rest of this method decides things
2646 // based on the new config.
2647 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
2648 (actionCollection()->action(QStringLiteral("url_navigators")));
2649 if (!toolBar()->actions().contains(navigators
)) {
2650 m_tabWidget
->currentTabPage()->insertNavigatorsWidget(navigators
);
2652 updateAllowedToolbarAreas();
2653 (static_cast<KHamburgerMenu
*>(actionCollection()->action(KStandardAction::name(
2654 KStandardAction::HamburgerMenu
))))->hideActionsOf(toolBar());
2657 void DolphinMainWindow::focusTerminalPanel()
2659 if (m_terminalPanel
->isVisible()) {
2660 if (m_terminalPanel
->terminalHasFocus()) {
2661 m_activeViewContainer
->view()->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2662 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2664 m_terminalPanel
->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2665 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2668 actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger();
2669 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2673 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
2674 KIO::FileUndoManager::UiInterface()
2678 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2682 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
2684 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2686 DolphinViewContainer
* container
= mainWin
->activeViewContainer();
2687 container
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
2689 KIO::FileUndoManager::UiInterface::jobError(job
);
2693 bool DolphinMainWindow::isUrlOpen(const QString
&url
)
2695 return m_tabWidget
->isUrlOpen(QUrl::fromUserInput(url
));
2698 bool DolphinMainWindow::isItemVisibleInAnyView(const QString
&urlOfItem
)
2700 return m_tabWidget
->isItemVisibleInAnyView(QUrl::fromUserInput(urlOfItem
));