2 * SPDX-FileCopyrightText: 2006 Peter Penz <peter.penz19@gmail.com>
3 * SPDX-FileCopyrightText: 2006 Stefan Monov <logixoul@gmail.com>
4 * SPDX-FileCopyrightText: 2006 Cvetoslav Ludmiloff <ludmiloff@gmail.com>
6 * SPDX-License-Identifier: GPL-2.0-or-later
9 #include "dolphinmainwindow.h"
11 #include "dolphin_generalsettings.h"
12 #include "dolphinbookmarkhandler.h"
13 #include "dolphincontextmenu.h"
14 #include "dolphindockwidget.h"
15 #include "dolphinmainwindowadaptor.h"
16 #include "dolphinnavigatorswidgetaction.h"
17 #include "dolphinnewfilemenu.h"
18 #include "dolphinplacesmodelsingleton.h"
19 #include "dolphinrecenttabsmenu.h"
20 #include "dolphintabpage.h"
21 #include "dolphinurlnavigatorscontroller.h"
22 #include "dolphinviewcontainer.h"
24 #include "middleclickactioneventfilter.h"
25 #include "panels/folders/folderspanel.h"
26 #include "panels/places/placespanel.h"
27 #include "panels/terminal/terminalpanel.h"
28 #include "selectionmode/actiontexthelper.h"
29 #include "settings/dolphinsettingsdialog.h"
30 #include "statusbar/dolphinstatusbar.h"
31 #include "views/dolphinnewfilemenuobserver.h"
32 #include "views/dolphinremoteencoding.h"
33 #include "views/dolphinviewactionhandler.h"
34 #include "views/draganddrophelper.h"
35 #include "views/viewproperties.h"
37 #include <KActionCollection>
38 #include <KActionMenu>
39 #include <KAuthorized>
42 #include <KDualAction>
43 #include <KFileItemListProperties>
44 #include <KIO/CommandLauncherJob>
45 #include <kio_version.h>
46 #if KIO_VERSION >= QT_VERSION_CHECK(5, 98, 0)
47 #include <KIO/JobUiDelegateFactory>
49 #include <KIO/JobUiDelegate>
51 #include <KIO/OpenFileManagerWindowJob>
52 #include <KIO/OpenUrlJob>
53 #include <KJobWidgets>
54 #include <KLocalizedString>
55 #include <KMessageBox>
56 #include <KMoreToolsMenuFactory>
57 #include <KProtocolInfo>
58 #include <KProtocolManager>
60 #include <KShortcutsDialog>
61 #include <KStandardAction>
62 #include <KStartupInfo>
64 #include <KTerminalLauncherJob>
65 #include <KToggleAction>
67 #include <KToolBarPopupAction>
68 #include <KUrlComboBox>
69 #include <KUrlNavigator>
70 #include <KWindowSystem>
71 #include <KXMLGUIFactory>
73 #include <kio_version.h>
74 #include <kwidgetsaddons_version.h>
76 #include <QApplication>
78 #include <QCloseEvent>
79 #include <QDesktopServices>
81 #include <QDomDocument>
85 #include <QPushButton>
87 #include <QStandardPaths>
89 #include <QToolButton>
93 // Used for GeneralSettings::version() to determine whether
94 // an updated version of Dolphin is running, so as to migrate
95 // removed/renamed ...etc config entries; increment it in such
97 const int CurrentDolphinVersion
= 202;
98 // The maximum number of entries in the back/forward popup menu
99 const int MaxNumberOfNavigationentries
= 12;
100 // The maximum number of "Activate Tab" shortcuts
101 const int MaxActivateTabShortcuts
= 9;
104 DolphinMainWindow::DolphinMainWindow()
105 : KXmlGuiWindow(nullptr)
106 , m_newFileMenu(nullptr)
107 , m_tabWidget(nullptr)
108 , m_activeViewContainer(nullptr)
109 , m_actionHandler(nullptr)
110 , m_remoteEncoding(nullptr)
112 , m_bookmarkHandler(nullptr)
113 , m_lastHandleUrlOpenJob(nullptr)
114 , m_terminalPanel(nullptr)
115 , m_placesPanel(nullptr)
116 , m_tearDownFromPlacesRequested(false)
117 , m_backAction(nullptr)
118 , m_forwardAction(nullptr)
120 Q_INIT_RESOURCE(dolphin
);
122 new MainWindowAdaptor(this);
125 setWindowFlags(Qt::WindowContextHelpButtonHint
);
127 setComponentName(QStringLiteral("dolphin"), QGuiApplication::applicationDisplayName());
128 setObjectName(QStringLiteral("Dolphin#"));
130 setStateConfigGroup("State");
132 connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::errorMessage
, this, &DolphinMainWindow::showErrorMessage
);
134 KIO::FileUndoManager
*undoManager
= KIO::FileUndoManager::self();
135 undoManager
->setUiInterface(new UndoUiInterface());
137 connect(undoManager
, &KIO::FileUndoManager::undoAvailable
, this, &DolphinMainWindow::slotUndoAvailable
);
138 connect(undoManager
, &KIO::FileUndoManager::undoTextChanged
, this, &DolphinMainWindow::slotUndoTextChanged
);
139 connect(undoManager
, &KIO::FileUndoManager::jobRecordingStarted
, this, &DolphinMainWindow::clearStatusBar
);
140 connect(undoManager
, &KIO::FileUndoManager::jobRecordingFinished
, this, &DolphinMainWindow::showCommand
);
142 const bool firstRun
= (GeneralSettings::version() < 200);
144 GeneralSettings::setViewPropsTimestamp(QDateTime::currentDateTime());
147 setAcceptDrops(true);
149 auto *navigatorsWidgetAction
= new DolphinNavigatorsWidgetAction(this);
150 actionCollection()->addAction(QStringLiteral("url_navigators"), navigatorsWidgetAction
);
151 m_tabWidget
= new DolphinTabWidget(navigatorsWidgetAction
, this);
152 m_tabWidget
->setObjectName("tabWidget");
153 connect(m_tabWidget
, &DolphinTabWidget::activeViewChanged
, this, &DolphinMainWindow::activeViewChanged
);
154 connect(m_tabWidget
, &DolphinTabWidget::tabCountChanged
, this, &DolphinMainWindow::tabCountChanged
);
155 connect(m_tabWidget
, &DolphinTabWidget::currentUrlChanged
, this, &DolphinMainWindow::updateWindowTitle
);
156 setCentralWidget(m_tabWidget
);
158 m_actionTextHelper
= new SelectionMode::ActionTextHelper(this);
161 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), m_actionTextHelper
, this);
162 connect(m_actionHandler
, &DolphinViewActionHandler::actionBeingHandled
, this, &DolphinMainWindow::clearStatusBar
);
163 connect(m_actionHandler
, &DolphinViewActionHandler::createDirectoryTriggered
, this, &DolphinMainWindow::createDirectory
);
164 connect(m_actionHandler
, &DolphinViewActionHandler::selectionModeChangeTriggered
, this, &DolphinMainWindow::slotSetSelectionMode
);
166 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
167 connect(this, &DolphinMainWindow::urlChanged
, m_remoteEncoding
, &DolphinRemoteEncoding::slotAboutToOpenUrl
);
171 setupGUI(Save
| Create
| ToolBar
);
172 stateChanged(QStringLiteral("new_file"));
174 QClipboard
*clipboard
= QApplication::clipboard();
175 connect(clipboard
, &QClipboard::dataChanged
, this, &DolphinMainWindow::updatePasteAction
);
177 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
178 toggleFilterBarAction
->setChecked(GeneralSettings::filterBar());
181 menuBar()->setVisible(false);
184 const bool showMenu
= !menuBar()->isHidden();
185 QAction
*showMenuBarAction
= actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar
));
186 showMenuBarAction
->setChecked(showMenu
); // workaround for bug #171080
188 auto hamburgerMenu
= static_cast<KHamburgerMenu
*>(actionCollection()->action(KStandardAction::name(KStandardAction::HamburgerMenu
)));
189 hamburgerMenu
->setMenuBar(menuBar());
190 hamburgerMenu
->setShowMenuBarAction(showMenuBarAction
);
191 connect(hamburgerMenu
, &KHamburgerMenu::aboutToShowMenu
, this, &DolphinMainWindow::updateHamburgerMenu
);
192 hamburgerMenu
->hideActionsOf(toolBar());
193 if (GeneralSettings::version() < 201 && !toolBar()->actions().contains(hamburgerMenu
)) {
194 addHamburgerMenuToToolbar();
197 updateAllowedToolbarAreas();
199 // enable middle-click on back/forward/up to open in a new tab
200 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
201 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotToolBarActionMiddleClicked
);
202 toolBar()->installEventFilter(middleClickEventFilter
);
206 connect(KSycoca::self(), &KSycoca::databaseChanged
, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
208 QTimer::singleShot(0, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
210 m_fileItemActions
.setParentWidget(this);
211 connect(&m_fileItemActions
, &KFileItemActions::error
, this, [this](const QString
&errorMessage
) {
212 showErrorMessage(errorMessage
);
215 connect(GeneralSettings::self(), &GeneralSettings::splitViewChanged
, this, &DolphinMainWindow::slotSplitViewChanged
);
218 DolphinMainWindow::~DolphinMainWindow()
220 // This fixes a crash on Wayland when closing the mainwindow while another dialog is open.
221 disconnect(QGuiApplication::clipboard(), &QClipboard::dataChanged
, this, &DolphinMainWindow::updatePasteAction
);
224 QVector
<DolphinViewContainer
*> DolphinMainWindow::viewContainers() const
226 QVector
<DolphinViewContainer
*> viewContainers
;
228 for (int i
= 0; i
< m_tabWidget
->count(); ++i
) {
229 DolphinTabPage
*tabPage
= m_tabWidget
->tabPageAt(i
);
231 viewContainers
<< tabPage
->primaryViewContainer();
232 if (tabPage
->splitViewEnabled()) {
233 viewContainers
<< tabPage
->secondaryViewContainer();
236 return viewContainers
;
239 void DolphinMainWindow::openDirectories(const QList
<QUrl
> &dirs
, bool splitView
)
241 m_tabWidget
->openDirectories(dirs
, splitView
);
244 void DolphinMainWindow::openDirectories(const QStringList
&dirs
, bool splitView
)
246 openDirectories(QUrl::fromStringList(dirs
), splitView
);
249 void DolphinMainWindow::openFiles(const QList
<QUrl
> &files
, bool splitView
)
251 m_tabWidget
->openFiles(files
, splitView
);
254 bool DolphinMainWindow::isFoldersPanelEnabled() const
256 return actionCollection()->action(QStringLiteral("show_folders_panel"))->isChecked();
259 bool DolphinMainWindow::isInformationPanelEnabled() const
262 return actionCollection()->action(QStringLiteral("show_information_panel"))->isChecked();
268 void DolphinMainWindow::openFiles(const QStringList
&files
, bool splitView
)
270 openFiles(QUrl::fromStringList(files
), splitView
);
273 void DolphinMainWindow::activateWindow(const QString
&activationToken
)
275 window()->setAttribute(Qt::WA_NativeWindow
, true);
277 if (KWindowSystem::isPlatformWayland()) {
278 KWindowSystem::setCurrentXdgActivationToken(activationToken
);
280 KStartupInfo::setNewStartupId(window()->windowHandle(), activationToken
.toUtf8());
283 KWindowSystem::activateWindow(window()->windowHandle());
286 bool DolphinMainWindow::isActiveWindow()
288 return window()->isActiveWindow();
291 void DolphinMainWindow::showCommand(CommandType command
)
293 DolphinStatusBar
*statusBar
= m_activeViewContainer
->statusBar();
295 case KIO::FileUndoManager::Copy
:
296 statusBar
->setText(i18nc("@info:status", "Successfully copied."));
298 case KIO::FileUndoManager::Move
:
299 statusBar
->setText(i18nc("@info:status", "Successfully moved."));
301 case KIO::FileUndoManager::Link
:
302 statusBar
->setText(i18nc("@info:status", "Successfully linked."));
304 case KIO::FileUndoManager::Trash
:
305 statusBar
->setText(i18nc("@info:status", "Successfully moved to trash."));
307 case KIO::FileUndoManager::Rename
:
308 statusBar
->setText(i18nc("@info:status", "Successfully renamed."));
311 case KIO::FileUndoManager::Mkdir
:
312 statusBar
->setText(i18nc("@info:status", "Created folder."));
320 void DolphinMainWindow::pasteIntoFolder()
322 m_activeViewContainer
->view()->pasteIntoFolder();
325 void DolphinMainWindow::changeUrl(const QUrl
&url
)
327 if (!KProtocolManager::supportsListing(url
)) {
328 // The URL navigator only checks for validity, not
329 // if the URL can be listed. An error message is
330 // shown due to DolphinViewContainer::restoreView().
334 m_activeViewContainer
->setUrl(url
);
335 updateFileAndEditActions();
340 Q_EMIT
urlChanged(url
);
343 void DolphinMainWindow::slotTerminalDirectoryChanged(const QUrl
&url
)
345 if (m_tearDownFromPlacesRequested
&& url
== QUrl::fromLocalFile(QDir::homePath())) {
346 m_placesPanel
->proceedWithTearDown();
347 m_tearDownFromPlacesRequested
= false;
350 m_activeViewContainer
->setAutoGrabFocus(false);
352 m_activeViewContainer
->setAutoGrabFocus(true);
355 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
357 KToggleAction
*editableLocationAction
= static_cast<KToggleAction
*>(actionCollection()->action(QStringLiteral("editable_location")));
358 editableLocationAction
->setChecked(editable
);
361 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
&selection
)
363 updateFileAndEditActions();
365 const int selectedUrlsCount
= m_tabWidget
->currentTabPage()->selectedItemsCount();
367 QAction
*compareFilesAction
= actionCollection()->action(QStringLiteral("compare_files"));
368 if (selectedUrlsCount
== 2) {
369 compareFilesAction
->setEnabled(isKompareInstalled());
371 compareFilesAction
->setEnabled(false);
374 Q_EMIT
selectionChanged(selection
);
377 void DolphinMainWindow::updateHistory()
379 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
380 const int index
= urlNavigator
->historyIndex();
382 QAction
*backAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Back
));
384 backAction
->setToolTip(i18nc("@info", "Go back"));
385 backAction
->setWhatsThis(i18nc("@info:whatsthis go back", "Return to the previously viewed folder."));
386 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
389 QAction
*forwardAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Forward
));
391 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
392 forwardAction
->setWhatsThis(xi18nc("@info:whatsthis go forward", "This undoes a <interface>Go|Back</interface> action."));
393 forwardAction
->setEnabled(index
> 0);
397 void DolphinMainWindow::updateFilterBarAction(bool show
)
399 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
400 toggleFilterBarAction
->setChecked(show
);
403 void DolphinMainWindow::openNewMainWindow()
405 Dolphin::openNewWindow({m_activeViewContainer
->url()}, this);
408 void DolphinMainWindow::openNewActivatedTab()
410 // keep browsers compatibility, new tab is always after last one
411 auto openNewTabAfterLastTabConfigured
= GeneralSettings::openNewTabAfterLastTab();
412 GeneralSettings::setOpenNewTabAfterLastTab(true);
413 m_tabWidget
->openNewActivatedTab();
414 GeneralSettings::setOpenNewTabAfterLastTab(openNewTabAfterLastTabConfigured
);
417 void DolphinMainWindow::addToPlaces()
422 // If nothing is selected, act on the current dir
423 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
424 url
= m_activeViewContainer
->url();
425 name
= m_activeViewContainer
->placesText();
427 const auto dirToAdd
= m_activeViewContainer
->view()->selectedItems().first();
428 url
= dirToAdd
.url();
429 name
= dirToAdd
.name();
433 if (m_activeViewContainer
->isSearchModeEnabled()) {
434 icon
= QStringLiteral("folder-saved-search-symbolic");
436 icon
= KIO::iconNameForUrl(url
);
438 DolphinPlacesModelSingleton::instance().placesModel()->addPlace(name
, url
, icon
);
442 void DolphinMainWindow::openNewTab(const QUrl
&url
)
444 m_tabWidget
->openNewTab(url
, QUrl());
447 void DolphinMainWindow::openNewTabAndActivate(const QUrl
&url
)
449 m_tabWidget
->openNewActivatedTab(url
, QUrl());
452 void DolphinMainWindow::openNewWindow(const QUrl
&url
)
454 Dolphin::openNewWindow({url
}, this);
457 void DolphinMainWindow::slotSplitViewChanged()
459 m_tabWidget
->currentTabPage()->setSplitViewEnabled(GeneralSettings::splitView(), WithAnimation
);
463 void DolphinMainWindow::openInNewTab()
465 const KFileItemList
&list
= m_activeViewContainer
->view()->selectedItems();
466 bool tabCreated
= false;
468 for (const KFileItem
&item
: list
) {
469 const QUrl
&url
= DolphinView::openItemAsFolderUrl(item
);
470 if (!url
.isEmpty()) {
476 // if no new tab has been created from the selection
477 // open the current directory in a new tab
479 openNewTab(m_activeViewContainer
->url());
483 void DolphinMainWindow::openInNewWindow()
487 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
488 if (list
.isEmpty()) {
489 newWindowUrl
= m_activeViewContainer
->url();
490 } else if (list
.count() == 1) {
491 const KFileItem
&item
= list
.first();
492 newWindowUrl
= DolphinView::openItemAsFolderUrl(item
);
495 if (!newWindowUrl
.isEmpty()) {
496 Dolphin::openNewWindow({newWindowUrl
}, this);
500 void DolphinMainWindow::showTarget()
502 const KFileItem link
= m_activeViewContainer
->view()->selectedItems().at(0);
503 const QUrl destinationUrl
= link
.url().resolved(QUrl(link
.linkDest()));
505 auto job
= KIO::statDetails(destinationUrl
, KIO::StatJob::SourceSide
, KIO::StatNoDetails
);
507 connect(job
, &KJob::finished
, this, [this, destinationUrl
](KJob
*job
) {
508 KIO::StatJob
*statJob
= static_cast<KIO::StatJob
*>(job
);
510 if (statJob
->error()) {
511 m_activeViewContainer
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
513 KIO::highlightInFileManager({destinationUrl
});
518 void DolphinMainWindow::showEvent(QShowEvent
*event
)
520 KXmlGuiWindow::showEvent(event
);
522 if (!event
->spontaneous()) {
523 m_activeViewContainer
->view()->setFocus();
527 void DolphinMainWindow::closeEvent(QCloseEvent
*event
)
529 // Find out if Dolphin is closed directly by the user or
530 // by the session manager because the session is closed
531 bool closedByUser
= true;
532 if (qApp
->isSavingSession()) {
533 closedByUser
= false;
536 if (m_tabWidget
->count() > 1 && GeneralSettings::confirmClosingMultipleTabs() && !GeneralSettings::rememberOpenedTabs() && closedByUser
) {
537 // Ask the user if he really wants to quit and close all tabs.
538 // Open a confirmation dialog with 3 buttons:
539 // QDialogButtonBox::Yes -> Quit
540 // QDialogButtonBox::No -> Close only the current tab
541 // QDialogButtonBox::Cancel -> do nothing
542 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
543 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
544 dialog
->setModal(true);
545 QDialogButtonBox
*buttons
= new QDialogButtonBox(QDialogButtonBox::Yes
| QDialogButtonBox::No
| QDialogButtonBox::Cancel
);
546 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
),
547 KGuiItem(i18nc("@action:button 'Quit Dolphin' button", "&Quit %1", QGuiApplication::applicationDisplayName()),
548 QIcon::fromTheme(QStringLiteral("application-exit"))));
549 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("C&lose Current Tab"), QIcon::fromTheme(QStringLiteral("tab-close"))));
550 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
551 buttons
->button(QDialogButtonBox::Yes
)->setDefault(true);
553 bool doNotAskAgainCheckboxResult
= false;
555 const auto result
= KMessageBox::createKMessageBox(dialog
,
557 QMessageBox::Warning
,
558 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
560 i18n("Do not ask again"),
561 &doNotAskAgainCheckboxResult
,
562 KMessageBox::Notify
);
564 if (doNotAskAgainCheckboxResult
) {
565 GeneralSettings::setConfirmClosingMultipleTabs(false);
569 case QDialogButtonBox::Yes
:
572 case QDialogButtonBox::No
:
573 // Close only the current tab
574 m_tabWidget
->closeTab();
582 if (m_terminalPanel
&& m_terminalPanel
->hasProgramRunning() && GeneralSettings::confirmClosingTerminalRunningProgram() && closedByUser
) {
583 // Ask if the user really wants to quit Dolphin with a program that is still running in the Terminal panel
584 // Open a confirmation dialog with 3 buttons:
585 // QDialogButtonBox::Yes -> Quit
586 // QDialogButtonBox::No -> Show Terminal Panel
587 // QDialogButtonBox::Cancel -> do nothing
588 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
589 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
590 dialog
->setModal(true);
591 auto standardButtons
= QDialogButtonBox::Yes
| QDialogButtonBox::Cancel
;
592 if (!m_terminalPanel
->isVisible()) {
593 standardButtons
|= QDialogButtonBox::No
;
595 QDialogButtonBox
*buttons
= new QDialogButtonBox(standardButtons
);
596 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KStandardGuiItem::quit());
597 if (!m_terminalPanel
->isVisible()) {
598 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("Show &Terminal Panel"), QIcon::fromTheme(QStringLiteral("dialog-scripts"))));
600 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
602 bool doNotAskAgainCheckboxResult
= false;
604 const auto result
= KMessageBox::createKMessageBox(
607 QMessageBox::Warning
,
608 i18n("The program '%1' is still running in the Terminal panel. Are you sure you want to quit?", m_terminalPanel
->runningProgramName()),
610 i18n("Do not ask again"),
611 &doNotAskAgainCheckboxResult
,
612 KMessageBox::Dangerous
);
614 if (doNotAskAgainCheckboxResult
) {
615 GeneralSettings::setConfirmClosingTerminalRunningProgram(false);
619 case QDialogButtonBox::Yes
:
622 case QDialogButtonBox::No
:
623 actionCollection()->action("show_terminal_panel")->trigger();
624 // Do not quit, ignore quit event
632 if (GeneralSettings::rememberOpenedTabs()) {
633 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
634 KConfig
*config
= KConfigGui::sessionConfig();
635 saveGlobalProperties(config
);
636 savePropertiesInternal(config
, 1);
640 GeneralSettings::setVersion(CurrentDolphinVersion
);
641 GeneralSettings::self()->save();
643 KXmlGuiWindow::closeEvent(event
);
646 void DolphinMainWindow::saveProperties(KConfigGroup
&group
)
648 m_tabWidget
->saveProperties(group
);
651 void DolphinMainWindow::readProperties(const KConfigGroup
&group
)
653 m_tabWidget
->readProperties(group
);
656 void DolphinMainWindow::updateNewMenu()
658 m_newFileMenu
->checkUpToDate();
659 #if KIO_VERSION >= QT_VERSION_CHECK(5, 97, 0)
660 m_newFileMenu
->setWorkingDirectory(activeViewContainer()->url());
662 m_newFileMenu
->setPopupFiles(QList
<QUrl
>() << activeViewContainer()->url());
666 void DolphinMainWindow::createDirectory()
668 #if KIO_VERSION >= QT_VERSION_CHECK(5, 97, 0)
669 m_newFileMenu
->setWorkingDirectory(activeViewContainer()->url());
671 m_newFileMenu
->setPopupFiles(QList
<QUrl
>() << activeViewContainer()->url());
673 m_newFileMenu
->createDirectory();
676 void DolphinMainWindow::quit()
681 void DolphinMainWindow::showErrorMessage(const QString
&message
)
683 m_activeViewContainer
->showMessage(message
, DolphinViewContainer::Error
);
686 void DolphinMainWindow::slotUndoAvailable(bool available
)
688 QAction
*undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
690 undoAction
->setEnabled(available
);
694 void DolphinMainWindow::slotUndoTextChanged(const QString
&text
)
696 QAction
*undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
698 undoAction
->setText(text
);
702 void DolphinMainWindow::undo()
705 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
706 KIO::FileUndoManager::self()->undo();
709 void DolphinMainWindow::cut()
711 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
712 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CutContents
);
714 m_activeViewContainer
->view()->cutSelectedItemsToClipboard();
715 m_activeViewContainer
->setSelectionModeEnabled(false);
719 void DolphinMainWindow::copy()
721 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
722 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CopyContents
);
724 m_activeViewContainer
->view()->copySelectedItemsToClipboard();
725 m_activeViewContainer
->setSelectionModeEnabled(false);
729 void DolphinMainWindow::paste()
731 m_activeViewContainer
->view()->paste();
734 void DolphinMainWindow::find()
736 m_activeViewContainer
->setSearchModeEnabled(true);
739 void DolphinMainWindow::updateSearchAction()
741 QAction
*toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
742 toggleSearchAction
->setChecked(m_activeViewContainer
->isSearchModeEnabled());
745 void DolphinMainWindow::updatePasteAction()
747 QAction
*pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
748 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
749 pasteAction
->setEnabled(pasteInfo
.first
);
750 pasteAction
->setText(pasteInfo
.second
);
753 void DolphinMainWindow::slotDirectoryLoadingCompleted()
758 void DolphinMainWindow::slotToolBarActionMiddleClicked(QAction
*action
)
760 if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Back
))) {
762 } else if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Forward
))) {
764 } else if (action
== actionCollection()->action(QStringLiteral("go_up"))) {
766 } else if (action
== actionCollection()->action(QStringLiteral("go_home"))) {
771 QAction
*DolphinMainWindow::urlNavigatorHistoryAction(const KUrlNavigator
*urlNavigator
, int historyIndex
, QObject
*parent
)
773 const QUrl url
= urlNavigator
->locationUrl(historyIndex
);
775 QString text
= url
.toDisplayString(QUrl::PreferLocalFile
);
777 if (!urlNavigator
->showFullPath()) {
778 const KFilePlacesModel
*placesModel
= DolphinPlacesModelSingleton::instance().placesModel();
780 const QModelIndex closestIdx
= placesModel
->closestItem(url
);
781 if (closestIdx
.isValid()) {
782 const QUrl placeUrl
= placesModel
->url(closestIdx
);
784 text
= placesModel
->text(closestIdx
);
786 QString pathInsidePlace
= url
.path().mid(placeUrl
.path().length());
788 if (!pathInsidePlace
.isEmpty() && !pathInsidePlace
.startsWith(QLatin1Char('/'))) {
789 pathInsidePlace
.prepend(QLatin1Char('/'));
792 if (pathInsidePlace
!= QLatin1Char('/')) {
793 text
.append(pathInsidePlace
);
798 QAction
*action
= new QAction(QIcon::fromTheme(KIO::iconNameForUrl(url
)), text
, parent
);
799 action
->setData(historyIndex
);
803 void DolphinMainWindow::slotAboutToShowBackPopupMenu()
805 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
807 m_backAction
->menu()->clear();
808 for (int i
= urlNavigator
->historyIndex() + 1; i
< urlNavigator
->historySize() && entries
< MaxNumberOfNavigationentries
; ++i
, ++entries
) {
809 QAction
*action
= urlNavigatorHistoryAction(urlNavigator
, i
, m_backAction
->menu());
810 m_backAction
->menu()->addAction(action
);
814 void DolphinMainWindow::slotGoBack(QAction
*action
)
816 int gotoIndex
= action
->data().value
<int>();
817 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
818 for (int i
= gotoIndex
- urlNavigator
->historyIndex(); i
> 0; --i
) {
823 void DolphinMainWindow::slotBackForwardActionMiddleClicked(QAction
*action
)
826 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
827 openNewTab(urlNavigator
->locationUrl(action
->data().value
<int>()));
831 void DolphinMainWindow::slotAboutToShowForwardPopupMenu()
833 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
835 m_forwardAction
->menu()->clear();
836 for (int i
= urlNavigator
->historyIndex() - 1; i
>= 0 && entries
< MaxNumberOfNavigationentries
; --i
, ++entries
) {
837 QAction
*action
= urlNavigatorHistoryAction(urlNavigator
, i
, m_forwardAction
->menu());
838 m_forwardAction
->menu()->addAction(action
);
842 void DolphinMainWindow::slotGoForward(QAction
*action
)
844 int gotoIndex
= action
->data().value
<int>();
845 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
846 for (int i
= urlNavigator
->historyIndex() - gotoIndex
; i
> 0; --i
) {
851 void DolphinMainWindow::slotSetSelectionMode(bool enabled
, SelectionMode::BottomBar::Contents bottomBarContents
)
853 m_activeViewContainer
->setSelectionModeEnabled(enabled
, actionCollection(), bottomBarContents
);
856 void DolphinMainWindow::selectAll()
860 // if the URL navigator is editable and focused, select the whole
861 // URL instead of all items of the view
863 KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigator();
864 QLineEdit
*lineEdit
= urlNavigator
->editor()->lineEdit();
865 const bool selectUrl
= urlNavigator
->isUrlEditable() && lineEdit
->hasFocus();
867 lineEdit
->selectAll();
869 m_activeViewContainer
->view()->selectAll();
873 void DolphinMainWindow::invertSelection()
876 m_activeViewContainer
->view()->invertSelection();
879 void DolphinMainWindow::toggleSplitView()
881 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
882 tabPage
->setSplitViewEnabled(!tabPage
->splitViewEnabled(), WithAnimation
);
887 void DolphinMainWindow::toggleSplitStash()
889 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
890 tabPage
->setSplitViewEnabled(false, WithAnimation
);
891 tabPage
->setSplitViewEnabled(true, WithAnimation
, QUrl("stash:/"));
894 void DolphinMainWindow::copyToInactiveSplitView()
896 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
897 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CopyToOtherViewContents
);
899 m_tabWidget
->copyToInactiveSplitView();
900 m_activeViewContainer
->setSelectionModeEnabled(false);
904 void DolphinMainWindow::moveToInactiveSplitView()
906 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
907 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::MoveToOtherViewContents
);
909 m_tabWidget
->moveToInactiveSplitView();
910 m_activeViewContainer
->setSelectionModeEnabled(false);
914 void DolphinMainWindow::reloadView()
917 m_activeViewContainer
->reload();
918 m_activeViewContainer
->statusBar()->updateSpaceInfo();
921 void DolphinMainWindow::stopLoading()
923 m_activeViewContainer
->view()->stopLoading();
926 void DolphinMainWindow::enableStopAction()
928 actionCollection()->action(QStringLiteral("stop"))->setEnabled(true);
931 void DolphinMainWindow::disableStopAction()
933 actionCollection()->action(QStringLiteral("stop"))->setEnabled(false);
936 void DolphinMainWindow::toggleSelectionMode()
938 const bool checked
= !m_activeViewContainer
->isSelectionModeEnabled();
940 m_activeViewContainer
->setSelectionModeEnabled(checked
, actionCollection(), SelectionMode::BottomBar::Contents::GeneralContents
);
941 actionCollection()->action(QStringLiteral("toggle_selection_mode"))->setChecked(checked
);
944 void DolphinMainWindow::showFilterBar()
946 m_activeViewContainer
->setFilterBarVisible(true);
949 void DolphinMainWindow::toggleFilterBar()
951 const bool checked
= !m_activeViewContainer
->isFilterBarVisible();
952 m_activeViewContainer
->setFilterBarVisible(checked
);
954 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
955 toggleFilterBarAction
->setChecked(checked
);
958 void DolphinMainWindow::toggleEditLocation()
962 QAction
*action
= actionCollection()->action(QStringLiteral("editable_location"));
963 KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigator();
964 urlNavigator
->setUrlEditable(action
->isChecked());
967 void DolphinMainWindow::replaceLocation()
969 KUrlNavigator
*navigator
= m_activeViewContainer
->urlNavigator();
970 QLineEdit
*lineEdit
= navigator
->editor()->lineEdit();
972 // If the text field currently has focus and everything is selected,
973 // pressing the keyboard shortcut returns the whole thing to breadcrumb mode
974 if (navigator
->isUrlEditable() && lineEdit
->hasFocus() && lineEdit
->selectedText() == lineEdit
->text()) {
975 navigator
->setUrlEditable(false);
977 navigator
->setUrlEditable(true);
978 navigator
->setFocus();
979 lineEdit
->selectAll();
983 void DolphinMainWindow::togglePanelLockState()
985 const bool newLockState
= !GeneralSettings::lockPanels();
986 const auto childrenObjects
= children();
987 for (QObject
*child
: childrenObjects
) {
988 DolphinDockWidget
*dock
= qobject_cast
<DolphinDockWidget
*>(child
);
990 dock
->setLocked(newLockState
);
994 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(newLockState
);
996 GeneralSettings::setLockPanels(newLockState
);
999 void DolphinMainWindow::slotTerminalPanelVisibilityChanged()
1001 if (m_terminalPanel
->isHiddenInVisibleWindow() && m_activeViewContainer
) {
1002 m_activeViewContainer
->view()->setFocus();
1006 void DolphinMainWindow::goBack()
1008 DolphinUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
1009 urlNavigator
->goBack();
1011 if (urlNavigator
->locationState().isEmpty()) {
1012 // An empty location state indicates a redirection URL,
1013 // which must be skipped too
1014 urlNavigator
->goBack();
1018 void DolphinMainWindow::goForward()
1020 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goForward();
1023 void DolphinMainWindow::goUp()
1025 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goUp();
1028 void DolphinMainWindow::goHome()
1030 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goHome();
1033 void DolphinMainWindow::goBackInNewTab()
1035 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
1036 const int index
= urlNavigator
->historyIndex() + 1;
1037 openNewTab(urlNavigator
->locationUrl(index
));
1040 void DolphinMainWindow::goForwardInNewTab()
1042 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
1043 const int index
= urlNavigator
->historyIndex() - 1;
1044 openNewTab(urlNavigator
->locationUrl(index
));
1047 void DolphinMainWindow::goUpInNewTab()
1049 const QUrl currentUrl
= activeViewContainer()->urlNavigator()->locationUrl();
1050 openNewTab(KIO::upUrl(currentUrl
));
1053 void DolphinMainWindow::goHomeInNewTab()
1055 openNewTab(Dolphin::homeUrl());
1058 void DolphinMainWindow::compareFiles()
1060 const KFileItemList items
= m_tabWidget
->currentTabPage()->selectedItems();
1061 if (items
.count() != 2) {
1062 // The action is disabled in this case, but it could have been triggered
1063 // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
1067 QUrl urlA
= items
.at(0).url();
1068 QUrl urlB
= items
.at(1).url();
1070 QString
command(QStringLiteral("kompare -c \""));
1071 command
.append(urlA
.toDisplayString(QUrl::PreferLocalFile
));
1072 command
.append("\" \"");
1073 command
.append(urlB
.toDisplayString(QUrl::PreferLocalFile
));
1074 command
.append('\"');
1076 KIO::CommandLauncherJob
*job
= new KIO::CommandLauncherJob(command
, this);
1077 job
->setDesktopName(QStringLiteral("org.kde.kompare"));
1081 void DolphinMainWindow::toggleShowMenuBar()
1083 const bool visible
= menuBar()->isVisible();
1084 menuBar()->setVisible(!visible
);
1087 QPointer
<QAction
> DolphinMainWindow::preferredSearchTool()
1089 m_searchTools
.clear();
1090 KMoreToolsMenuFactory("dolphin/search-tools").fillMenuFromGroupingNames(&m_searchTools
, {"files-find"}, m_activeViewContainer
->url());
1091 QList
<QAction
*> actions
= m_searchTools
.actions();
1092 if (actions
.isEmpty()) {
1095 QAction
*action
= actions
.first();
1096 if (action
->isSeparator()) {
1102 void DolphinMainWindow::updateOpenPreferredSearchToolAction()
1104 QAction
*openPreferredSearchTool
= actionCollection()->action(QStringLiteral("open_preferred_search_tool"));
1105 if (!openPreferredSearchTool
) {
1108 QPointer
<QAction
> tool
= preferredSearchTool();
1110 openPreferredSearchTool
->setVisible(true);
1111 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open %1", tool
->text()));
1112 // Only override with the app icon if it is the default, i.e. the user hasn't configured one manually
1113 // https://bugs.kde.org/show_bug.cgi?id=442815
1114 if (openPreferredSearchTool
->icon().name() == QLatin1String("search")) {
1115 openPreferredSearchTool
->setIcon(tool
->icon());
1118 openPreferredSearchTool
->setVisible(false);
1119 // still visible in Shortcuts configuration window
1120 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1121 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1125 void DolphinMainWindow::openPreferredSearchTool()
1127 QPointer
<QAction
> tool
= preferredSearchTool();
1133 void DolphinMainWindow::openTerminal()
1135 openTerminalJob(m_activeViewContainer
->url());
1138 void DolphinMainWindow::openTerminalHere()
1140 QList
<QUrl
> urls
= {};
1142 for (const KFileItem
&item
: m_activeViewContainer
->view()->selectedItems()) {
1143 QUrl url
= item
.targetUrl();
1144 if (item
.isFile()) {
1145 url
.setPath(QFileInfo(url
.path()).absolutePath());
1147 if (!urls
.contains(url
)) {
1152 // No items are selected. Open a terminal window for the current location.
1153 if (urls
.count() == 0) {
1158 if (urls
.count() > 5) {
1159 QString question
= i18np("Are you sure you want to open 1 terminal window?", "Are you sure you want to open %1 terminal windows?", urls
.count());
1160 #if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
1161 const int answer
= KMessageBox::warningTwoActions(
1166 const int answer
= KMessageBox::warningYesNo(
1171 KGuiItem(i18ncp("@action:button", "Open %1 Terminal", "Open %1 Terminals", urls
.count()), QStringLiteral("utilities-terminal")),
1172 KStandardGuiItem::cancel());
1173 #if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
1174 if (answer
!= KMessageBox::PrimaryAction
) {
1176 if (answer
!= KMessageBox::Yes
) {
1182 for (const QUrl
&url
: urls
) {
1183 openTerminalJob(url
);
1187 void DolphinMainWindow::openTerminalJob(const QUrl
&url
)
1189 if (url
.isLocalFile()) {
1190 auto job
= new KTerminalLauncherJob(QString());
1191 job
->setWorkingDirectory(url
.toLocalFile());
1196 // Not a local file, with protocol Class ":local", try stat'ing
1197 if (KProtocolInfo::protocolClass(url
.scheme()) == QLatin1String(":local")) {
1198 KIO::StatJob
*job
= KIO::mostLocalUrl(url
);
1199 KJobWidgets::setWindow(job
, this);
1200 connect(job
, &KJob::result
, this, [job
]() {
1202 if (!job
->error()) {
1203 statUrl
= job
->mostLocalUrl();
1206 auto job
= new KTerminalLauncherJob(QString());
1207 job
->setWorkingDirectory(statUrl
.isLocalFile() ? statUrl
.toLocalFile() : QDir::homePath());
1214 // Nothing worked, just use $HOME
1215 auto job
= new KTerminalLauncherJob(QString());
1216 job
->setWorkingDirectory(QDir::homePath());
1220 void DolphinMainWindow::editSettings()
1222 if (!m_settingsDialog
) {
1223 DolphinViewContainer
*container
= activeViewContainer();
1224 container
->view()->writeSettings();
1226 const QUrl url
= container
->url();
1227 DolphinSettingsDialog
*settingsDialog
= new DolphinSettingsDialog(url
, this, actionCollection());
1228 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, this, &DolphinMainWindow::refreshViews
);
1229 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, &DolphinUrlNavigatorsController::slotReadSettings
);
1230 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1231 settingsDialog
->show();
1232 m_settingsDialog
= settingsDialog
;
1234 m_settingsDialog
.data()->raise();
1238 void DolphinMainWindow::handleUrl(const QUrl
&url
)
1240 delete m_lastHandleUrlOpenJob
;
1241 m_lastHandleUrlOpenJob
= nullptr;
1243 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1244 activeViewContainer()->setUrl(url
);
1246 m_lastHandleUrlOpenJob
= new KIO::OpenUrlJob(url
);
1247 #if KIO_VERSION >= QT_VERSION_CHECK(5, 98, 0)
1248 m_lastHandleUrlOpenJob
->setUiDelegate(KIO::createDefaultJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
1250 m_lastHandleUrlOpenJob
->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
1252 m_lastHandleUrlOpenJob
->setShowOpenOrExecuteDialog(true);
1254 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::mimeTypeFound
, this, [this, url
](const QString
&mimetype
) {
1255 if (mimetype
== QLatin1String("inode/directory")) {
1256 // If it's a dir, we'll take it from here
1257 m_lastHandleUrlOpenJob
->kill();
1258 m_lastHandleUrlOpenJob
= nullptr;
1259 activeViewContainer()->setUrl(url
);
1263 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::result
, this, [this]() {
1264 m_lastHandleUrlOpenJob
= nullptr;
1267 m_lastHandleUrlOpenJob
->start();
1271 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1273 // trash:/ is writable but we don't want to create new items in it.
1274 // TODO: remove the trash check once https://phabricator.kde.org/T8234 is implemented
1275 newFileMenu()->setEnabled(isFolderWritable
&& m_activeViewContainer
->url().scheme() != QLatin1String("trash"));
1278 void DolphinMainWindow::openContextMenu(const QPoint
&pos
, const KFileItem
&item
, const KFileItemList
&selectedItems
, const QUrl
&url
)
1280 QPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, item
, selectedItems
, url
, &m_fileItemActions
);
1281 contextMenu
.data()->exec(pos
);
1283 // Delete the menu, unless it has been deleted in its own nested event loop already.
1285 contextMenu
->deleteLater();
1289 QMenu
*DolphinMainWindow::createPopupMenu()
1291 QMenu
*menu
= KXmlGuiWindow::createPopupMenu();
1293 menu
->addSeparator();
1294 menu
->addAction(actionCollection()->action(QStringLiteral("lock_panels")));
1299 void DolphinMainWindow::updateHamburgerMenu()
1301 KActionCollection
*ac
= actionCollection();
1302 auto hamburgerMenu
= static_cast<KHamburgerMenu
*>(ac
->action(KStandardAction::name(KStandardAction::HamburgerMenu
)));
1303 auto menu
= hamburgerMenu
->menu();
1305 menu
= new QMenu(this);
1306 hamburgerMenu
->setMenu(menu
);
1307 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("basic_actions"))->menu());
1308 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("zoom"))->menu());
1312 const QList
<QAction
*> toolbarActions
= toolBar()->actions();
1314 if (!toolBar()->isVisible()) {
1315 // If neither the menu bar nor the toolbar are visible, these actions should be available.
1316 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)));
1317 menu
->addAction(toolBarMenuAction());
1318 menu
->addSeparator();
1321 // This group of actions (until the next separator) contains all the most basic actions
1322 // necessary to use Dolphin effectively.
1323 menu
->addAction(ac
->action(QStringLiteral("go_back")));
1324 menu
->addAction(ac
->action(QStringLiteral("go_forward")));
1326 menu
->addMenu(m_newFileMenu
->menu());
1327 if (!toolBar()->isVisible() || !toolbarActions
.contains(ac
->action(QStringLiteral("toggle_selection_mode_tool_bar")))) {
1328 menu
->addAction(ac
->action(QStringLiteral("toggle_selection_mode")));
1330 menu
->addAction(ac
->action(QStringLiteral("basic_actions")));
1331 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Undo
)));
1332 if (!toolBar()->isVisible()
1333 || (!toolbarActions
.contains(ac
->action(QStringLiteral("toggle_search")))
1334 && !toolbarActions
.contains(ac
->action(QStringLiteral("open_preferred_search_tool"))))) {
1335 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Find
)));
1336 // This way a search action will only be added if none of the three available
1337 // search actions is present on the toolbar.
1339 if (!toolBar()->isVisible() || !toolbarActions
.contains(ac
->action(QStringLiteral("toggle_filter")))) {
1340 menu
->addAction(ac
->action(QStringLiteral("show_filter_bar")));
1341 // This way a filter action will only be added if none of the two available
1342 // filter actions is present on the toolbar.
1344 menu
->addSeparator();
1346 // The second group of actions (up until the next separator) contains actions for opening
1347 // additional views to interact with the file system.
1348 menu
->addAction(ac
->action(QStringLiteral("file_new")));
1349 menu
->addAction(ac
->action(QStringLiteral("new_tab")));
1350 if (ac
->action(QStringLiteral("undo_close_tab"))->isEnabled()) {
1351 menu
->addAction(ac
->action(QStringLiteral("closed_tabs")));
1353 menu
->addAction(ac
->action(QStringLiteral("open_terminal")));
1354 menu
->addSeparator();
1356 // The third group contains actions to change what one sees in the view
1357 // and to change the more general UI.
1358 if (!toolBar()->isVisible()
1359 || (!toolbarActions
.contains(ac
->action(QStringLiteral("icons"))) && !toolbarActions
.contains(ac
->action(QStringLiteral("compact")))
1360 && !toolbarActions
.contains(ac
->action(QStringLiteral("details"))) && !toolbarActions
.contains(ac
->action(QStringLiteral("view_mode"))))) {
1361 menu
->addAction(ac
->action(QStringLiteral("view_mode")));
1363 menu
->addAction(ac
->action(QStringLiteral("show_hidden_files")));
1364 menu
->addAction(ac
->action(QStringLiteral("sort")));
1365 menu
->addAction(ac
->action(QStringLiteral("additional_info")));
1366 if (!GeneralSettings::showStatusBar() || !GeneralSettings::showZoomSlider()) {
1367 menu
->addAction(ac
->action(QStringLiteral("zoom")));
1369 menu
->addAction(ac
->action(QStringLiteral("panels")));
1371 // The "Configure" menu is not added to the actionCollection() because there is hardly
1372 // a good reason for users to put it on their toolbar.
1373 auto configureMenu
= menu
->addMenu(QIcon::fromTheme(QStringLiteral("configure")), i18nc("@action:inmenu menu for configure actions", "Configure"));
1374 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
)));
1375 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)));
1376 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)));
1377 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Preferences
)));
1378 hamburgerMenu
->hideActionsOf(configureMenu
);
1381 void DolphinMainWindow::slotPlaceActivated(const QUrl
&url
)
1383 DolphinViewContainer
*view
= activeViewContainer();
1385 if (view
->url() == url
) {
1386 view
->clearFilterBar(); // Fixes bug 259382.
1388 // We can end up here if the user clicked a device in the Places Panel
1389 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
1392 view
->disableUrlNavigatorSelectionRequests();
1394 view
->enableUrlNavigatorSelectionRequests();
1398 void DolphinMainWindow::closedTabsCountChanged(unsigned int count
)
1400 actionCollection()->action(QStringLiteral("undo_close_tab"))->setEnabled(count
> 0);
1403 void DolphinMainWindow::activeViewChanged(DolphinViewContainer
*viewContainer
)
1405 DolphinViewContainer
*oldViewContainer
= m_activeViewContainer
;
1406 Q_ASSERT(viewContainer
);
1408 m_activeViewContainer
= viewContainer
;
1410 if (oldViewContainer
) {
1411 const QAction
*toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
1412 toggleSearchAction
->disconnect(oldViewContainer
);
1414 // Disconnect all signals between the old view container (container,
1415 // view and url navigator) and main window.
1416 oldViewContainer
->disconnect(this);
1417 oldViewContainer
->view()->disconnect(this);
1418 oldViewContainer
->urlNavigatorInternalWithHistory()->disconnect(this);
1419 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
1420 navigators
->primaryUrlNavigator()->disconnect(this);
1421 if (auto secondaryUrlNavigator
= navigators
->secondaryUrlNavigator()) {
1422 secondaryUrlNavigator
->disconnect(this);
1425 // except the requestItemInfo so that on hover the information panel can still be updated
1426 connect(oldViewContainer
->view(), &DolphinView::requestItemInfo
, this, &DolphinMainWindow::requestItemInfo
);
1428 // Disconnect other slots.
1430 &DolphinViewContainer::selectionModeChanged
,
1431 actionCollection()->action(QStringLiteral("toggle_selection_mode")),
1432 &QAction::setChecked
);
1435 connectViewSignals(viewContainer
);
1437 m_actionHandler
->setCurrentView(viewContainer
->view());
1440 updateFileAndEditActions();
1441 updatePasteAction();
1442 updateViewActions();
1444 updateSearchAction();
1446 const QUrl url
= viewContainer
->url();
1447 Q_EMIT
urlChanged(url
);
1450 void DolphinMainWindow::tabCountChanged(int count
)
1452 const bool enableTabActions
= (count
> 1);
1453 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1454 actionCollection()->action(QStringLiteral("activate_tab_%1").arg(i
))->setEnabled(enableTabActions
);
1456 actionCollection()->action(QStringLiteral("activate_last_tab"))->setEnabled(enableTabActions
);
1457 actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions
);
1458 actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions
);
1461 void DolphinMainWindow::updateWindowTitle()
1463 const QString newTitle
= m_activeViewContainer
->captionWindowTitle();
1464 if (windowTitle() != newTitle
) {
1465 setWindowTitle(newTitle
);
1469 void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString
&mountPath
)
1471 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1472 setViewsToHomeIfMountPathOpen(mountPath
);
1475 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectory().startsWith(mountPath
)) {
1476 m_tearDownFromPlacesRequested
= true;
1477 m_terminalPanel
->goHome();
1478 // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged
1480 m_placesPanel
->proceedWithTearDown();
1484 void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString
&mountPath
)
1486 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1487 setViewsToHomeIfMountPathOpen(mountPath
);
1490 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectory().startsWith(mountPath
)) {
1491 m_tearDownFromPlacesRequested
= false;
1492 m_terminalPanel
->goHome();
1496 void DolphinMainWindow::slotKeyBindings()
1498 KShortcutsDialog
dialog(KShortcutsEditor::AllActions
, KShortcutsEditor::LetterShortcutsAllowed
, this);
1499 dialog
.addCollection(actionCollection());
1500 if (m_terminalPanel
) {
1501 KActionCollection
*konsolePartActionCollection
= m_terminalPanel
->actionCollection();
1502 if (konsolePartActionCollection
) {
1503 dialog
.addCollection(konsolePartActionCollection
, QStringLiteral("KonsolePart"));
1509 void DolphinMainWindow::setViewsToHomeIfMountPathOpen(const QString
&mountPath
)
1511 const QVector
<DolphinViewContainer
*> theViewContainers
= viewContainers();
1512 for (DolphinViewContainer
*viewContainer
: theViewContainers
) {
1513 if (viewContainer
&& viewContainer
->url().toLocalFile().startsWith(mountPath
)) {
1514 viewContainer
->setUrl(QUrl::fromLocalFile(QDir::homePath()));
1517 disconnect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, nullptr, nullptr);
1520 void DolphinMainWindow::setupActions()
1522 auto hamburgerMenuAction
= KStandardAction::hamburgerMenu(nullptr, nullptr, actionCollection());
1524 // setup 'File' menu
1525 m_newFileMenu
= new DolphinNewFileMenu(actionCollection(), this);
1526 QMenu
*menu
= m_newFileMenu
->menu();
1527 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1528 menu
->setIcon(QIcon::fromTheme(QStringLiteral("list-add")));
1529 m_newFileMenu
->setPopupMode(QToolButton::InstantPopup
);
1530 connect(menu
, &QMenu::aboutToShow
, this, &DolphinMainWindow::updateNewMenu
);
1532 QAction
*newWindow
= KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow
, actionCollection());
1533 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1534 newWindow
->setToolTip(i18nc("@info", "Open a new Dolphin window"));
1535 newWindow
->setWhatsThis(xi18nc("@info:whatsthis",
1537 "window just like this one with the current location and view."
1538 "<nl/>You can drag and drop items between windows."));
1539 newWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1541 QAction
*newTab
= actionCollection()->addAction(QStringLiteral("new_tab"));
1542 newTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1543 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1544 newTab
->setWhatsThis(xi18nc("@info:whatsthis",
1546 "<emphasis>Tab</emphasis> with the current location and view.<nl/>"
1547 "A tab is an additional view within this window. "
1548 "You can drag and drop items between tabs."));
1549 actionCollection()->setDefaultShortcuts(newTab
, {Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
});
1550 connect(newTab
, &QAction::triggered
, this, &DolphinMainWindow::openNewActivatedTab
);
1552 QAction
*addToPlaces
= actionCollection()->addAction(QStringLiteral("add_to_places"));
1553 addToPlaces
->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new")));
1554 addToPlaces
->setText(i18nc("@action:inmenu Add current folder to places", "Add to Places"));
1555 addToPlaces
->setWhatsThis(xi18nc("@info:whatsthis",
1556 "This adds the selected folder "
1557 "to the Places panel."));
1558 connect(addToPlaces
, &QAction::triggered
, this, &DolphinMainWindow::addToPlaces
);
1560 QAction
*closeTab
= KStandardAction::close(m_tabWidget
, QOverload
<>::of(&DolphinTabWidget::closeTab
), actionCollection());
1561 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1562 closeTab
->setWhatsThis(i18nc("@info:whatsthis",
1564 "currently viewed tab. If no more tabs are left this window "
1565 "will close instead."));
1567 QAction
*quitAction
= KStandardAction::quit(this, &DolphinMainWindow::quit
, actionCollection());
1568 quitAction
->setWhatsThis(i18nc("@info:whatsthis quit", "This closes this window."));
1570 // setup 'Edit' menu
1571 KStandardAction::undo(this, &DolphinMainWindow::undo
, actionCollection());
1573 // i18n: This will be the last paragraph for the whatsthis for all three:
1574 // Cut, Copy and Paste
1575 const QString cutCopyPastePara
= xi18nc("@info:whatsthis",
1576 "<para><emphasis>Cut, "
1577 "Copy</emphasis> and <emphasis>Paste</emphasis> work between many "
1578 "applications and are among the most used commands. That's why their "
1579 "<emphasis>keyboard shortcuts</emphasis> are prominently placed right "
1580 "next to each other on the keyboard: <shortcut>Ctrl+X</shortcut>, "
1581 "<shortcut>Ctrl+C</shortcut> and <shortcut>Ctrl+V</shortcut>.</para>");
1582 QAction
*cutAction
= KStandardAction::cut(this, &DolphinMainWindow::cut
, actionCollection());
1583 m_actionTextHelper
->registerTextWhenNothingIsSelected(cutAction
, i18nc("@action", "Cut…"));
1584 cutAction
->setWhatsThis(xi18nc("@info:whatsthis cut",
1585 "This copies the items "
1586 "in your current selection to the <emphasis>clipboard</emphasis>.<nl/>"
1587 "Use the <emphasis>Paste</emphasis> action afterwards to copy them from "
1588 "the clipboard to a new location. The items will be removed from their "
1589 "initial location.")
1590 + cutCopyPastePara
);
1591 QAction
*copyAction
= KStandardAction::copy(this, &DolphinMainWindow::copy
, actionCollection());
1592 m_actionTextHelper
->registerTextWhenNothingIsSelected(copyAction
, i18nc("@action", "Copy…"));
1593 copyAction
->setWhatsThis(xi18nc("@info:whatsthis copy",
1595 "items in your current selection to the <emphasis>clipboard</emphasis>."
1596 "<nl/>Use the <emphasis>Paste</emphasis> action afterwards to copy them "
1597 "from the clipboard to a new location.")
1598 + cutCopyPastePara
);
1599 QAction
*paste
= KStandardAction::paste(this, &DolphinMainWindow::paste
, actionCollection());
1600 // The text of the paste-action is modified dynamically by Dolphin
1601 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1602 // due to the long text, the text "Paste" is used:
1603 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1604 paste
->setWhatsThis(xi18nc("@info:whatsthis paste",
1605 "This copies the items from "
1606 "your <emphasis>clipboard</emphasis> to the currently viewed folder.<nl/>"
1607 "If the items were added to the clipboard by the <emphasis>Cut</emphasis> "
1608 "action they are removed from their old location.")
1609 + cutCopyPastePara
);
1611 QAction
*copyToOtherViewAction
= actionCollection()->addAction(QStringLiteral("copy_to_inactive_split_view"));
1612 copyToOtherViewAction
->setText(i18nc("@action:inmenu", "Copy to Inactive Split View"));
1613 m_actionTextHelper
->registerTextWhenNothingIsSelected(copyToOtherViewAction
, i18nc("@action:inmenu", "Copy to Inactive Split View…"));
1614 copyToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Copy",
1615 "This copies the selected items from "
1616 "the <emphasis>active</emphasis> view to the inactive split view."));
1617 copyToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
1618 copyToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Copy to Inactive Split View"));
1619 actionCollection()->setDefaultShortcut(copyToOtherViewAction
, Qt::SHIFT
| Qt::Key_F5
);
1620 connect(copyToOtherViewAction
, &QAction::triggered
, this, &DolphinMainWindow::copyToInactiveSplitView
);
1622 QAction
*moveToOtherViewAction
= actionCollection()->addAction(QStringLiteral("move_to_inactive_split_view"));
1623 moveToOtherViewAction
->setText(i18nc("@action:inmenu", "Move to Inactive Split View"));
1624 m_actionTextHelper
->registerTextWhenNothingIsSelected(moveToOtherViewAction
, i18nc("@action:inmenu", "Move to Inactive Split View…"));
1625 moveToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Move",
1626 "This moves the selected items from "
1627 "the <emphasis>active</emphasis> view to the inactive split view."));
1628 moveToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-cut")));
1629 moveToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Move to Inactive Split View"));
1630 actionCollection()->setDefaultShortcut(moveToOtherViewAction
, Qt::SHIFT
| Qt::Key_F6
);
1631 connect(moveToOtherViewAction
, &QAction::triggered
, this, &DolphinMainWindow::moveToInactiveSplitView
);
1633 QAction
*showFilterBar
= actionCollection()->addAction(QStringLiteral("show_filter_bar"));
1634 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Filter..."));
1635 showFilterBar
->setToolTip(i18nc("@info:tooltip", "Show Filter Bar"));
1636 showFilterBar
->setWhatsThis(xi18nc("@info:whatsthis",
1638 "<emphasis>Filter Bar</emphasis> at the bottom of the window.<nl/> "
1639 "There you can enter a text to filter the files and folders currently displayed. "
1640 "Only those that contain the text in their name will be kept in view."));
1641 showFilterBar
->setIcon(QIcon::fromTheme(QStringLiteral("view-filter")));
1642 actionCollection()->setDefaultShortcuts(showFilterBar
, {Qt::CTRL
| Qt::Key_I
, Qt::Key_Slash
});
1643 connect(showFilterBar
, &QAction::triggered
, this, &DolphinMainWindow::showFilterBar
);
1645 // toggle_filter acts as a copy of the main showFilterBar to be used mainly
1646 // in the toolbar, with no default shortcut attached, to avoid messing with
1647 // existing workflows (filter bar always open and Ctrl-I to focus)
1648 QAction
*toggleFilter
= actionCollection()->addAction(QStringLiteral("toggle_filter"));
1649 toggleFilter
->setText(i18nc("@action:inmenu", "Toggle Filter Bar"));
1650 toggleFilter
->setIconText(i18nc("@action:intoolbar", "Filter"));
1651 toggleFilter
->setIcon(showFilterBar
->icon());
1652 toggleFilter
->setToolTip(showFilterBar
->toolTip());
1653 toggleFilter
->setWhatsThis(showFilterBar
->whatsThis());
1654 toggleFilter
->setCheckable(true);
1655 connect(toggleFilter
, &QAction::triggered
, this, &DolphinMainWindow::toggleFilterBar
);
1657 QAction
*searchAction
= KStandardAction::find(this, &DolphinMainWindow::find
, actionCollection());
1658 searchAction
->setText(i18n("Search..."));
1659 searchAction
->setToolTip(i18nc("@info:tooltip", "Search for files and folders"));
1660 searchAction
->setWhatsThis(xi18nc("@info:whatsthis find",
1661 "<para>This helps you "
1662 "find files and folders by opening a <emphasis>find bar</emphasis>. "
1663 "There you can enter search terms and specify settings to find the "
1664 "objects you are looking for.</para><para>Use this help again on "
1665 "the find bar so we can have a look at it while the settings are "
1666 "explained.</para>"));
1668 // toggle_search acts as a copy of the main searchAction to be used mainly
1669 // in the toolbar, with no default shortcut attached, to avoid messing with
1670 // existing workflows (search bar always open and Ctrl-F to focus)
1671 QAction
*toggleSearchAction
= actionCollection()->addAction(QStringLiteral("toggle_search"));
1672 toggleSearchAction
->setText(i18nc("@action:inmenu", "Toggle Search Bar"));
1673 toggleSearchAction
->setIconText(i18nc("@action:intoolbar", "Search"));
1674 toggleSearchAction
->setIcon(searchAction
->icon());
1675 toggleSearchAction
->setToolTip(searchAction
->toolTip());
1676 toggleSearchAction
->setWhatsThis(searchAction
->whatsThis());
1677 toggleSearchAction
->setCheckable(true);
1679 QAction
*toggleSelectionModeAction
= actionCollection()->addAction(QStringLiteral("toggle_selection_mode"));
1680 // i18n: This action toggles a selection mode.
1681 toggleSelectionModeAction
->setText(i18nc("@action:inmenu", "Select Files and Folders"));
1682 // i18n: Opens a selection mode for selecting files/folders.
1683 // The text is kept so unspecific because it will be shown on the toolbar where space is at a premium.
1684 toggleSelectionModeAction
->setIconText(i18nc("@action:intoolbar", "Select"));
1685 toggleSelectionModeAction
->setWhatsThis(xi18nc(
1687 "<para>This application only knows which files or folders should be acted on if they are"
1688 " <emphasis>selected</emphasis> first. Press this to toggle a <emphasis>Selection Mode</emphasis> which makes selecting and deselecting as easy as "
1689 "pressing an item once.</para><para>While in this mode, a quick access bar at the bottom shows available actions for the currently selected items."
1691 toggleSelectionModeAction
->setIcon(QIcon::fromTheme(QStringLiteral("quickwizard")));
1692 toggleSelectionModeAction
->setCheckable(true);
1693 connect(toggleSelectionModeAction
, &QAction::triggered
, this, &DolphinMainWindow::toggleSelectionMode
);
1695 // A special version of the toggleSelectionModeAction for the toolbar that also contains a menu
1696 // with the selectAllAction and invertSelectionAction.
1697 auto *toggleSelectionModeToolBarAction
=
1698 new KToolBarPopupAction(toggleSelectionModeAction
->icon(), toggleSelectionModeAction
->iconText(), actionCollection());
1699 toggleSelectionModeToolBarAction
->setToolTip(toggleSelectionModeAction
->text());
1700 toggleSelectionModeToolBarAction
->setWhatsThis(toggleSelectionModeAction
->whatsThis());
1701 actionCollection()->addAction(QStringLiteral("toggle_selection_mode_tool_bar"), toggleSelectionModeToolBarAction
);
1702 toggleSelectionModeToolBarAction
->setCheckable(true);
1703 toggleSelectionModeToolBarAction
->setPopupMode(QToolButton::DelayedPopup
);
1704 connect(toggleSelectionModeToolBarAction
, &QAction::triggered
, toggleSelectionModeAction
, &QAction::trigger
);
1705 connect(toggleSelectionModeAction
, &QAction::toggled
, toggleSelectionModeToolBarAction
, &QAction::setChecked
);
1707 QAction
*selectAllAction
= KStandardAction::selectAll(this, &DolphinMainWindow::selectAll
, actionCollection());
1708 selectAllAction
->setWhatsThis(xi18nc("@info:whatsthis",
1710 "files and folders in the current location."));
1712 QAction
*invertSelection
= actionCollection()->addAction(QStringLiteral("invert_selection"));
1713 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1714 invertSelection
->setWhatsThis(xi18nc("@info:whatsthis invert",
1716 "objects that you have currently <emphasis>not</emphasis> selected instead."));
1717 invertSelection
->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-invert")));
1718 actionCollection()->setDefaultShortcut(invertSelection
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1719 connect(invertSelection
, &QAction::triggered
, this, &DolphinMainWindow::invertSelection
);
1721 QMenu
*toggleSelectionModeActionMenu
= new QMenu(this);
1722 toggleSelectionModeActionMenu
->addAction(selectAllAction
);
1723 toggleSelectionModeActionMenu
->addAction(invertSelection
);
1724 toggleSelectionModeToolBarAction
->setMenu(toggleSelectionModeActionMenu
);
1726 // setup 'View' menu
1727 // (note that most of it is set up in DolphinViewActionHandler)
1729 QAction
*split
= actionCollection()->addAction(QStringLiteral("split_view"));
1730 split
->setWhatsThis(xi18nc("@info:whatsthis find",
1731 "<para>This splits "
1732 "the folder view below into two autonomous views.</para><para>This "
1733 "way you can see two locations at once and move items between them "
1734 "quickly.</para>Click this again afterwards to recombine the views."));
1735 actionCollection()->setDefaultShortcut(split
, Qt::Key_F3
);
1736 connect(split
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitView
);
1738 QAction
*stashSplit
= actionCollection()->addAction(QStringLiteral("split_stash"));
1739 actionCollection()->setDefaultShortcut(stashSplit
, Qt::CTRL
| Qt::Key_S
);
1740 stashSplit
->setText(i18nc("@action:intoolbar Stash", "Stash"));
1741 stashSplit
->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
1742 stashSplit
->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
1743 stashSplit
->setCheckable(false);
1744 QDBusConnectionInterface
*sessionInterface
= QDBusConnection::sessionBus().interface();
1745 stashSplit
->setVisible(sessionInterface
&& sessionInterface
->isServiceRegistered(QStringLiteral("org.kde.kio.StashNotifier")));
1746 connect(stashSplit
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitStash
);
1748 KStandardAction::redisplay(this, &DolphinMainWindow::reloadView
, actionCollection());
1750 QAction
*stop
= actionCollection()->addAction(QStringLiteral("stop"));
1751 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1752 stop
->setToolTip(i18nc("@info", "Stop loading"));
1753 stop
->setWhatsThis(i18nc("@info", "This stops the loading of the contents of the current folder."));
1754 stop
->setIcon(QIcon::fromTheme(QStringLiteral("process-stop")));
1755 connect(stop
, &QAction::triggered
, this, &DolphinMainWindow::stopLoading
);
1757 KToggleAction
*editableLocation
= actionCollection()->add
<KToggleAction
>(QStringLiteral("editable_location"));
1758 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1759 editableLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1760 "This toggles the <emphasis>Location Bar</emphasis> to be "
1761 "editable so you can directly enter a location you want to go to.<nl/>"
1762 "You can also switch to editing by clicking to the right of the "
1763 "location and switch back by confirming the edited location."));
1764 actionCollection()->setDefaultShortcut(editableLocation
, Qt::Key_F6
);
1765 connect(editableLocation
, &KToggleAction::triggered
, this, &DolphinMainWindow::toggleEditLocation
);
1767 QAction
*replaceLocation
= actionCollection()->addAction(QStringLiteral("replace_location"));
1768 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1769 // i18n: "enter" is used both in the meaning of "writing" and "going to" a new location here.
1770 // Both meanings are useful but not necessary to understand the use of "Replace Location".
1771 // So you might want to be more verbose in your language to convey the meaning but it's up to you.
1772 replaceLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1773 "This switches to editing the location and selects it "
1774 "so you can quickly enter a different location."));
1775 actionCollection()->setDefaultShortcut(replaceLocation
, Qt::CTRL
| Qt::Key_L
);
1776 connect(replaceLocation
, &QAction::triggered
, this, &DolphinMainWindow::replaceLocation
);
1780 QScopedPointer
<QAction
> backAction(KStandardAction::back(nullptr, nullptr, nullptr));
1781 m_backAction
= new KToolBarPopupAction(backAction
->icon(), backAction
->text(), actionCollection());
1782 m_backAction
->setObjectName(backAction
->objectName());
1783 m_backAction
->setShortcuts(backAction
->shortcuts());
1785 m_backAction
->setPopupMode(QToolButton::DelayedPopup
);
1786 connect(m_backAction
, &QAction::triggered
, this, &DolphinMainWindow::goBack
);
1787 connect(m_backAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowBackPopupMenu
);
1788 connect(m_backAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoBack
);
1789 actionCollection()->addAction(m_backAction
->objectName(), m_backAction
);
1791 auto backShortcuts
= m_backAction
->shortcuts();
1792 // Prepend this shortcut, to avoid being hidden by the two-slot UI (#371130)
1793 backShortcuts
.prepend(QKeySequence(Qt::Key_Backspace
));
1794 actionCollection()->setDefaultShortcuts(m_backAction
, backShortcuts
);
1796 DolphinRecentTabsMenu
*recentTabsMenu
= new DolphinRecentTabsMenu(this);
1797 actionCollection()->addAction(QStringLiteral("closed_tabs"), recentTabsMenu
);
1798 connect(m_tabWidget
, &DolphinTabWidget::rememberClosedTab
, recentTabsMenu
, &DolphinRecentTabsMenu::rememberClosedTab
);
1799 connect(recentTabsMenu
, &DolphinRecentTabsMenu::restoreClosedTab
, m_tabWidget
, &DolphinTabWidget::restoreClosedTab
);
1800 connect(recentTabsMenu
, &DolphinRecentTabsMenu::closedTabsCountChanged
, this, &DolphinMainWindow::closedTabsCountChanged
);
1802 QAction
*undoCloseTab
= actionCollection()->addAction(QStringLiteral("undo_close_tab"));
1803 undoCloseTab
->setText(i18nc("@action:inmenu File", "Undo close tab"));
1804 undoCloseTab
->setWhatsThis(i18nc("@info:whatsthis undo close tab", "This returns you to the previously closed tab."));
1805 actionCollection()->setDefaultShortcut(undoCloseTab
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_T
);
1806 undoCloseTab
->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo")));
1807 undoCloseTab
->setEnabled(false);
1808 connect(undoCloseTab
, &QAction::triggered
, recentTabsMenu
, &DolphinRecentTabsMenu::undoCloseTab
);
1810 auto undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
1811 undoAction
->setWhatsThis(xi18nc("@info:whatsthis",
1813 "the last change you made to files or folders.<nl/>"
1814 "Such changes include <interface>creating, renaming</interface> "
1815 "and <interface>moving</interface> them to a different location "
1816 "or to the <filename>Trash</filename>. <nl/>Changes that can't "
1817 "be undone will ask for your confirmation."));
1818 undoAction
->setEnabled(false); // undo should be disabled by default
1821 QScopedPointer
<QAction
> forwardAction(KStandardAction::forward(nullptr, nullptr, nullptr));
1822 m_forwardAction
= new KToolBarPopupAction(forwardAction
->icon(), forwardAction
->text(), actionCollection());
1823 m_forwardAction
->setObjectName(forwardAction
->objectName());
1824 m_forwardAction
->setShortcuts(forwardAction
->shortcuts());
1826 m_forwardAction
->setPopupMode(QToolButton::DelayedPopup
);
1827 connect(m_forwardAction
, &QAction::triggered
, this, &DolphinMainWindow::goForward
);
1828 connect(m_forwardAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowForwardPopupMenu
);
1829 connect(m_forwardAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoForward
);
1830 actionCollection()->addAction(m_forwardAction
->objectName(), m_forwardAction
);
1831 actionCollection()->setDefaultShortcuts(m_forwardAction
, m_forwardAction
->shortcuts());
1833 // enable middle-click to open in a new tab
1834 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
1835 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotBackForwardActionMiddleClicked
);
1836 m_backAction
->menu()->installEventFilter(middleClickEventFilter
);
1837 m_forwardAction
->menu()->installEventFilter(middleClickEventFilter
);
1838 KStandardAction::up(this, &DolphinMainWindow::goUp
, actionCollection());
1839 QAction
*homeAction
= KStandardAction::home(this, &DolphinMainWindow::goHome
, actionCollection());
1840 homeAction
->setWhatsThis(xi18nc("@info:whatsthis",
1842 "<filename>Home</filename> folder.<nl/>Every user account "
1843 "has their own <filename>Home</filename> that contains their data "
1844 "including folders that contain personal application data."));
1846 // setup 'Tools' menu
1847 QAction
*compareFiles
= actionCollection()->addAction(QStringLiteral("compare_files"));
1848 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1849 compareFiles
->setIcon(QIcon::fromTheme(QStringLiteral("kompare")));
1850 compareFiles
->setEnabled(false);
1851 connect(compareFiles
, &QAction::triggered
, this, &DolphinMainWindow::compareFiles
);
1853 QAction
*openPreferredSearchTool
= actionCollection()->addAction(QStringLiteral("open_preferred_search_tool"));
1854 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1855 openPreferredSearchTool
->setWhatsThis(xi18nc("@info:whatsthis",
1856 "<para>This opens a preferred search tool for the viewed location.</para>"
1857 "<para>Use <emphasis>More Search Tools</emphasis> menu to configure it.</para>"));
1858 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1859 actionCollection()->setDefaultShortcut(openPreferredSearchTool
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F
);
1860 connect(openPreferredSearchTool
, &QAction::triggered
, this, &DolphinMainWindow::openPreferredSearchTool
);
1862 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1863 QAction
*openTerminal
= actionCollection()->addAction(QStringLiteral("open_terminal"));
1864 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1865 openTerminal
->setWhatsThis(xi18nc("@info:whatsthis",
1866 "<para>This opens a <emphasis>terminal</emphasis> application for the viewed location.</para>"
1867 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1868 openTerminal
->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
1869 actionCollection()->setDefaultShortcut(openTerminal
, Qt::SHIFT
| Qt::Key_F4
);
1870 connect(openTerminal
, &QAction::triggered
, this, &DolphinMainWindow::openTerminal
);
1872 QAction
*openTerminalHere
= actionCollection()->addAction(QStringLiteral("open_terminal_here"));
1873 // i18n: "Here" refers to the location(s) of the currently selected item(s) or the currently viewed location if nothing is selected.
1874 openTerminalHere
->setText(i18nc("@action:inmenu Tools", "Open Terminal Here"));
1875 openTerminalHere
->setWhatsThis(xi18nc("@info:whatsthis",
1876 "<para>This opens <emphasis>terminal</emphasis> applications for the selected items' locations.</para>"
1877 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1878 openTerminalHere
->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
1879 actionCollection()->setDefaultShortcut(openTerminalHere
, Qt::SHIFT
| Qt::ALT
| Qt::Key_F4
);
1880 connect(openTerminalHere
, &QAction::triggered
, this, &DolphinMainWindow::openTerminalHere
);
1883 QAction
*focusTerminalPanel
= actionCollection()->addAction(QStringLiteral("focus_terminal_panel"));
1884 focusTerminalPanel
->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
1885 focusTerminalPanel
->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
1886 actionCollection()->setDefaultShortcut(focusTerminalPanel
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F4
);
1887 connect(focusTerminalPanel
, &QAction::triggered
, this, &DolphinMainWindow::focusTerminalPanel
);
1891 // setup 'Bookmarks' menu
1892 KActionMenu
*bookmarkMenu
= new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this);
1893 bookmarkMenu
->setIcon(QIcon::fromTheme(QStringLiteral("bookmarks")));
1894 // Make the toolbar button version work properly on click
1895 bookmarkMenu
->setPopupMode(QToolButton::InstantPopup
);
1896 m_bookmarkHandler
= new DolphinBookmarkHandler(this, actionCollection(), bookmarkMenu
->menu(), this);
1897 actionCollection()->addAction(QStringLiteral("bookmarks"), bookmarkMenu
);
1899 // setup 'Settings' menu
1900 KToggleAction
*showMenuBar
= KStandardAction::showMenubar(nullptr, nullptr, actionCollection());
1901 showMenuBar
->setWhatsThis(xi18nc("@info:whatsthis",
1902 "<para>This switches between having a <emphasis>Menubar</emphasis> "
1903 "and having a <interface>%1</interface> button. Both "
1904 "contain mostly the same actions and configuration options.</para>"
1905 "<para>The Menubar takes up more space but allows for fast and organised access to all "
1906 "actions an application has to offer.</para><para>The <interface>%1</interface> button "
1907 "is simpler and small which makes triggering advanced actions more time consuming.</para>",
1908 hamburgerMenuAction
->text().replace('&', "")));
1909 connect(showMenuBar
,
1910 &KToggleAction::triggered
, // Fixes #286822
1912 &DolphinMainWindow::toggleShowMenuBar
,
1913 Qt::QueuedConnection
);
1915 KToggleAction
*showStatusBar
= KStandardAction::showStatusbar(nullptr, nullptr, actionCollection());
1916 showStatusBar
->setChecked(GeneralSettings::showStatusBar());
1917 connect(GeneralSettings::self(), &GeneralSettings::showStatusBarChanged
, showStatusBar
, &KToggleAction::setChecked
);
1918 connect(showStatusBar
, &KToggleAction::triggered
, this, [this](bool checked
) {
1919 GeneralSettings::setShowStatusBar(checked
);
1923 KStandardAction::keyBindings(this, &DolphinMainWindow::slotKeyBindings
, actionCollection());
1924 KStandardAction::preferences(this, &DolphinMainWindow::editSettings
, actionCollection());
1926 // not in menu actions
1927 QList
<QKeySequence
> nextTabKeys
= KStandardShortcut::tabNext();
1928 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
1930 QList
<QKeySequence
> prevTabKeys
= KStandardShortcut::tabPrev();
1931 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
1933 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1934 QAction
*activateTab
= actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i
));
1935 activateTab
->setText(i18nc("@action:inmenu", "Activate Tab %1", i
+ 1));
1936 activateTab
->setEnabled(false);
1937 connect(activateTab
, &QAction::triggered
, this, [this, i
]() {
1938 m_tabWidget
->activateTab(i
);
1941 // only add default shortcuts for the first 9 tabs regardless of MaxActivateTabShortcuts
1943 actionCollection()->setDefaultShortcut(activateTab
, QStringLiteral("Alt+%1").arg(i
+ 1));
1947 QAction
*activateLastTab
= actionCollection()->addAction(QStringLiteral("activate_last_tab"));
1948 activateLastTab
->setText(i18nc("@action:inmenu", "Activate Last Tab"));
1949 activateLastTab
->setEnabled(false);
1950 connect(activateLastTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateLastTab
);
1951 actionCollection()->setDefaultShortcut(activateLastTab
, Qt::ALT
| Qt::Key_0
);
1953 QAction
*activateNextTab
= actionCollection()->addAction(QStringLiteral("activate_next_tab"));
1954 activateNextTab
->setIconText(i18nc("@action:inmenu", "Next Tab"));
1955 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1956 activateNextTab
->setEnabled(false);
1957 connect(activateNextTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateNextTab
);
1958 actionCollection()->setDefaultShortcuts(activateNextTab
, nextTabKeys
);
1960 QAction
*activatePrevTab
= actionCollection()->addAction(QStringLiteral("activate_prev_tab"));
1961 activatePrevTab
->setIconText(i18nc("@action:inmenu", "Previous Tab"));
1962 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1963 activatePrevTab
->setEnabled(false);
1964 connect(activatePrevTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activatePrevTab
);
1965 actionCollection()->setDefaultShortcuts(activatePrevTab
, prevTabKeys
);
1968 QAction
*showTarget
= actionCollection()->addAction(QStringLiteral("show_target"));
1969 showTarget
->setText(i18nc("@action:inmenu", "Show Target"));
1970 showTarget
->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
1971 showTarget
->setEnabled(false);
1972 connect(showTarget
, &QAction::triggered
, this, &DolphinMainWindow::showTarget
);
1974 QAction
*openInNewTab
= actionCollection()->addAction(QStringLiteral("open_in_new_tab"));
1975 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1976 openInNewTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1977 connect(openInNewTab
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
1979 QAction
*openInNewTabs
= actionCollection()->addAction(QStringLiteral("open_in_new_tabs"));
1980 openInNewTabs
->setText(i18nc("@action:inmenu", "Open in New Tabs"));
1981 openInNewTabs
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1982 connect(openInNewTabs
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
1984 QAction
*openInNewWindow
= actionCollection()->addAction(QStringLiteral("open_in_new_window"));
1985 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1986 openInNewWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1987 connect(openInNewWindow
, &QAction::triggered
, this, &DolphinMainWindow::openInNewWindow
);
1990 void DolphinMainWindow::setupDockWidgets()
1992 const bool lock
= GeneralSettings::lockPanels();
1994 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(lock
);
1996 KDualAction
*lockLayoutAction
= actionCollection()->add
<KDualAction
>(QStringLiteral("lock_panels"));
1997 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1998 lockLayoutAction
->setActiveIcon(QIcon::fromTheme(QStringLiteral("object-unlocked")));
1999 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
2000 lockLayoutAction
->setInactiveIcon(QIcon::fromTheme(QStringLiteral("object-locked")));
2001 lockLayoutAction
->setWhatsThis(xi18nc("@info:whatsthis",
2003 "switches between having panels <emphasis>locked</emphasis> or "
2004 "<emphasis>unlocked</emphasis>.<nl/>Unlocked panels can be "
2005 "dragged to the other side of the window and have a close "
2006 "button.<nl/>Locked panels are embedded more cleanly."));
2007 lockLayoutAction
->setActive(lock
);
2008 connect(lockLayoutAction
, &KDualAction::triggered
, this, &DolphinMainWindow::togglePanelLockState
);
2010 // Setup "Information"
2011 DolphinDockWidget
*infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
2012 infoDock
->setLocked(lock
);
2013 infoDock
->setObjectName(QStringLiteral("infoDock"));
2014 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2017 InformationPanel
*infoPanel
= new InformationPanel(infoDock
);
2018 infoPanel
->setCustomContextMenuActions({lockLayoutAction
});
2019 connect(infoPanel
, &InformationPanel::urlActivated
, this, &DolphinMainWindow::handleUrl
);
2020 infoDock
->setWidget(infoPanel
);
2022 QAction
*infoAction
= infoDock
->toggleViewAction();
2023 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-information")), Qt::Key_F11
, infoAction
, QStringLiteral("show_information_panel"));
2025 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
2026 connect(this, &DolphinMainWindow::urlChanged
, infoPanel
, &InformationPanel::setUrl
);
2027 connect(this, &DolphinMainWindow::selectionChanged
, infoPanel
, &InformationPanel::setSelection
);
2028 connect(this, &DolphinMainWindow::requestItemInfo
, infoPanel
, &InformationPanel::requestDelayedItemInfo
);
2029 connect(this, &DolphinMainWindow::fileItemsChanged
, infoPanel
, &InformationPanel::slotFilesItemChanged
);
2032 // i18n: This is the last paragraph for the "What's This"-texts of all four panels.
2033 const QString panelWhatsThis
= xi18nc("@info:whatsthis",
2035 "hide panels like this go to <interface>Menu|Panels</interface> "
2036 "or <interface>View|Panels</interface>.</para>");
2039 ->action(QStringLiteral("show_information_panel"))
2040 ->setWhatsThis(xi18nc("@info:whatsthis",
2041 "<para> This toggles the "
2042 "<emphasis>information</emphasis> panel at the right side of the "
2043 "window.</para><para>The panel provides in-depth information "
2044 "about the items your mouse is hovering over or about the selected "
2045 "items. Otherwise it informs you about the currently viewed folder.<nl/>"
2046 "For single items a preview of their contents is provided.</para>"));
2048 infoDock
->setWhatsThis(xi18nc("@info:whatsthis",
2050 "provides in-depth information about the items your mouse is "
2051 "hovering over or about the selected items. Otherwise it informs "
2052 "you about the currently viewed folder.<nl/>For single items a "
2053 "preview of their contents is provided.</para><para>You can configure "
2054 "which and how details are given here by right-clicking.</para>")
2058 DolphinDockWidget
*foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
2059 foldersDock
->setLocked(lock
);
2060 foldersDock
->setObjectName(QStringLiteral("foldersDock"));
2061 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2062 FoldersPanel
*foldersPanel
= new FoldersPanel(foldersDock
);
2063 foldersPanel
->setCustomContextMenuActions({lockLayoutAction
});
2064 foldersDock
->setWidget(foldersPanel
);
2066 QAction
*foldersAction
= foldersDock
->toggleViewAction();
2067 createPanelAction(QIcon::fromTheme(QStringLiteral("folder")), Qt::Key_F7
, foldersAction
, QStringLiteral("show_folders_panel"));
2069 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
2070 connect(this, &DolphinMainWindow::urlChanged
, foldersPanel
, &FoldersPanel::setUrl
);
2071 connect(foldersPanel
, &FoldersPanel::folderActivated
, this, &DolphinMainWindow::changeUrl
);
2072 connect(foldersPanel
, &FoldersPanel::folderInNewTab
, this, &DolphinMainWindow::openNewTab
);
2073 connect(foldersPanel
, &FoldersPanel::folderInNewActiveTab
, this, &DolphinMainWindow::openNewTabAndActivate
);
2074 connect(foldersPanel
, &FoldersPanel::errorMessage
, this, &DolphinMainWindow::showErrorMessage
);
2077 ->action(QStringLiteral("show_folders_panel"))
2078 ->setWhatsThis(xi18nc("@info:whatsthis",
2080 "<emphasis>folders</emphasis> panel at the left side of the window."
2081 "<nl/><nl/>It shows the folders of the <emphasis>file system"
2082 "</emphasis> in a <emphasis>tree view</emphasis>."));
2083 foldersDock
->setWhatsThis(xi18nc("@info:whatsthis",
2085 "shows the folders of the <emphasis>file system</emphasis> in a "
2086 "<emphasis>tree view</emphasis>.</para><para>Click a folder to go "
2087 "there. Click the arrow to the left of a folder to see its subfolders. "
2088 "This allows quick switching between any folders.</para>")
2093 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
2094 DolphinDockWidget
*terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
2095 terminalDock
->setLocked(lock
);
2096 terminalDock
->setObjectName(QStringLiteral("terminalDock"));
2097 m_terminalPanel
= new TerminalPanel(terminalDock
);
2098 m_terminalPanel
->setCustomContextMenuActions({lockLayoutAction
});
2099 terminalDock
->setWidget(m_terminalPanel
);
2101 connect(m_terminalPanel
, &TerminalPanel::hideTerminalPanel
, terminalDock
, &DolphinDockWidget::hide
);
2102 connect(m_terminalPanel
, &TerminalPanel::changeUrl
, this, &DolphinMainWindow::slotTerminalDirectoryChanged
);
2103 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
, m_terminalPanel
, &TerminalPanel::dockVisibilityChanged
);
2104 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
, this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged
);
2106 QAction
*terminalAction
= terminalDock
->toggleViewAction();
2107 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-scripts")), Qt::Key_F4
, terminalAction
, QStringLiteral("show_terminal_panel"));
2109 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
2110 connect(this, &DolphinMainWindow::urlChanged
, m_terminalPanel
, &TerminalPanel::setUrl
);
2112 if (GeneralSettings::version() < 200) {
2113 terminalDock
->hide();
2117 ->action(QStringLiteral("show_terminal_panel"))
2118 ->setWhatsThis(xi18nc("@info:whatsthis",
2119 "<para>This toggles the "
2120 "<emphasis>terminal</emphasis> panel at the bottom of the window."
2121 "<nl/>The location in the terminal will always match the folder "
2122 "view so you can navigate using either.</para><para>The terminal "
2123 "panel is not needed for basic computer usage but can be useful "
2124 "for advanced tasks. To learn more about terminals use the help "
2125 "in a standalone terminal application like Konsole.</para>"));
2126 terminalDock
->setWhatsThis(xi18nc("@info:whatsthis",
2128 "the <emphasis>terminal</emphasis> panel. It behaves like a "
2129 "normal terminal but will match the location of the folder view "
2130 "so you can navigate using either.</para><para>The terminal panel "
2131 "is not needed for basic computer usage but can be useful for "
2132 "advanced tasks. To learn more about terminals use the help in a "
2133 "standalone terminal application like Konsole.</para>")
2138 if (GeneralSettings::version() < 200) {
2140 foldersDock
->hide();
2144 DolphinDockWidget
*placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
2145 placesDock
->setLocked(lock
);
2146 placesDock
->setObjectName(QStringLiteral("placesDock"));
2147 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2149 m_placesPanel
= new PlacesPanel(placesDock
);
2150 m_placesPanel
->setCustomContextMenuActions({lockLayoutAction
});
2151 placesDock
->setWidget(m_placesPanel
);
2153 QAction
*placesAction
= placesDock
->toggleViewAction();
2154 createPanelAction(QIcon::fromTheme(QStringLiteral("compass")), Qt::Key_F9
, placesAction
, QStringLiteral("show_places_panel"));
2156 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
2157 connect(m_placesPanel
, &PlacesPanel::placeActivated
, this, &DolphinMainWindow::slotPlaceActivated
);
2158 connect(m_placesPanel
, &PlacesPanel::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2159 connect(m_placesPanel
, &PlacesPanel::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2160 connect(m_placesPanel
, &PlacesPanel::newWindowRequested
, this, [this](const QUrl
&url
) {
2161 Dolphin::openNewWindow({url
}, this);
2163 connect(m_placesPanel
, &PlacesPanel::errorMessage
, this, &DolphinMainWindow::showErrorMessage
);
2164 connect(this, &DolphinMainWindow::urlChanged
, m_placesPanel
, &PlacesPanel::setUrl
);
2165 connect(placesDock
, &DolphinDockWidget::visibilityChanged
, &DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged
);
2166 connect(this, &DolphinMainWindow::settingsChanged
, m_placesPanel
, &PlacesPanel::readSettings
);
2167 connect(m_placesPanel
, &PlacesPanel::storageTearDownRequested
, this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested
);
2168 connect(m_placesPanel
, &PlacesPanel::storageTearDownExternallyRequested
, this, &DolphinMainWindow::slotStorageTearDownExternallyRequested
);
2169 DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged(m_placesPanel
->isVisible());
2171 auto actionShowAllPlaces
= new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this);
2172 actionShowAllPlaces
->setCheckable(true);
2173 actionShowAllPlaces
->setDisabled(true);
2174 actionShowAllPlaces
->setWhatsThis(i18nc("@info:whatsthis",
2176 "all places in the places panel that have been hidden. They will "
2177 "appear semi-transparent unless you uncheck their hide property."));
2179 connect(actionShowAllPlaces
, &QAction::triggered
, this, [actionShowAllPlaces
, this](bool checked
) {
2180 m_placesPanel
->setShowAll(checked
);
2182 connect(m_placesPanel
, &PlacesPanel::allPlacesShownChanged
, actionShowAllPlaces
, &QAction::setChecked
);
2185 ->action(QStringLiteral("show_places_panel"))
2186 ->setWhatsThis(xi18nc("@info:whatsthis",
2187 "<para>This toggles the "
2188 "<emphasis>places</emphasis> panel at the left side of the window."
2189 "</para><para>It allows you to go to locations you have "
2190 "bookmarked and to access disk or media attached to the computer "
2191 "or to the network. It also contains sections to find recently "
2192 "saved files or files of a certain type.</para>"));
2193 placesDock
->setWhatsThis(xi18nc("@info:whatsthis",
2194 "<para>This is the "
2195 "<emphasis>Places</emphasis> panel. It allows you to go to locations "
2196 "you have bookmarked and to access disk or media attached to the "
2197 "computer or to the network. It also contains sections to find "
2198 "recently saved files or files of a certain type.</para><para>"
2199 "Click on an entry to go there. Click with the right mouse button "
2200 "instead to open any entry in a new tab or new window.</para>"
2201 "<para>New entries can be added by dragging folders onto this panel. "
2202 "Right-click any section or entry to hide it. Right-click an empty "
2203 "space on this panel and select <interface>Show Hidden Places"
2204 "</interface> to display it again.</para>")
2207 // Add actions into the "Panels" menu
2208 KActionMenu
*panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Show Panels"), this);
2209 actionCollection()->addAction(QStringLiteral("panels"), panelsMenu
);
2210 panelsMenu
->setIcon(QIcon::fromTheme(QStringLiteral("view-sidetree")));
2211 panelsMenu
->setPopupMode(QToolButton::InstantPopup
);
2212 const KActionCollection
*ac
= actionCollection();
2213 panelsMenu
->addAction(ac
->action(QStringLiteral("show_places_panel")));
2215 panelsMenu
->addAction(ac
->action(QStringLiteral("show_information_panel")));
2217 panelsMenu
->addAction(ac
->action(QStringLiteral("show_folders_panel")));
2218 panelsMenu
->addAction(ac
->action(QStringLiteral("show_terminal_panel")));
2219 panelsMenu
->addSeparator();
2220 panelsMenu
->addAction(actionShowAllPlaces
);
2221 panelsMenu
->addAction(lockLayoutAction
);
2223 connect(panelsMenu
->menu(), &QMenu::aboutToShow
, this, [actionShowAllPlaces
, this] {
2224 actionShowAllPlaces
->setEnabled(DolphinPlacesModelSingleton::instance().placesModel()->hiddenCount());
2228 void DolphinMainWindow::updateFileAndEditActions()
2230 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
2231 const KActionCollection
*col
= actionCollection();
2232 KFileItemListProperties
capabilitiesSource(list
);
2234 QAction
*renameAction
= col
->action(KStandardAction::name(KStandardAction::RenameFile
));
2235 QAction
*moveToTrashAction
= col
->action(KStandardAction::name(KStandardAction::MoveToTrash
));
2236 QAction
*deleteAction
= col
->action(KStandardAction::name(KStandardAction::DeleteFile
));
2237 QAction
*cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
2238 QAction
*duplicateAction
= col
->action(QStringLiteral("duplicate")); // see DolphinViewActionHandler
2239 QAction
*addToPlacesAction
= col
->action(QStringLiteral("add_to_places"));
2240 QAction
*copyToOtherViewAction
= col
->action(QStringLiteral("copy_to_inactive_split_view"));
2241 QAction
*moveToOtherViewAction
= col
->action(QStringLiteral("move_to_inactive_split_view"));
2242 QAction
*copyLocation
= col
->action(QString("copy_location"));
2244 if (list
.isEmpty()) {
2245 stateChanged(QStringLiteral("has_no_selection"));
2247 // All actions that need a selection to function can be enabled because they should trigger selection mode.
2248 renameAction
->setEnabled(true);
2249 moveToTrashAction
->setEnabled(true);
2250 deleteAction
->setEnabled(true);
2251 cutAction
->setEnabled(true);
2252 duplicateAction
->setEnabled(true);
2253 addToPlacesAction
->setEnabled(true);
2254 copyLocation
->setEnabled(true);
2255 // Them triggering selection mode and not directly acting on selected items is signified by adding "…" to their text.
2256 m_actionTextHelper
->textsWhenNothingIsSelectedEnabled(true);
2259 m_actionTextHelper
->textsWhenNothingIsSelectedEnabled(false);
2260 stateChanged(QStringLiteral("has_selection"));
2262 QAction
*deleteWithTrashShortcut
= col
->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
2263 QAction
*showTarget
= col
->action(QStringLiteral("show_target"));
2265 if (list
.length() == 1 && list
.first().isDir()) {
2266 addToPlacesAction
->setEnabled(true);
2268 addToPlacesAction
->setEnabled(false);
2271 const bool enableMoveToTrash
= capabilitiesSource
.isLocal() && capabilitiesSource
.supportsMoving();
2273 renameAction
->setEnabled(capabilitiesSource
.supportsMoving());
2274 moveToTrashAction
->setEnabled(enableMoveToTrash
);
2275 deleteAction
->setEnabled(capabilitiesSource
.supportsDeleting());
2276 deleteWithTrashShortcut
->setEnabled(capabilitiesSource
.supportsDeleting() && !enableMoveToTrash
);
2277 cutAction
->setEnabled(capabilitiesSource
.supportsMoving());
2278 copyLocation
->setEnabled(list
.length() == 1);
2279 showTarget
->setEnabled(list
.length() == 1 && list
.at(0).isLink());
2280 duplicateAction
->setEnabled(capabilitiesSource
.supportsWriting());
2283 if (m_tabWidget
->currentTabPage()->splitViewEnabled()) {
2284 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
2285 KFileItem capabilitiesDestination
;
2287 if (tabPage
->primaryViewActive()) {
2288 capabilitiesDestination
= tabPage
->secondaryViewContainer()->url();
2290 capabilitiesDestination
= tabPage
->primaryViewContainer()->url();
2293 copyToOtherViewAction
->setEnabled(capabilitiesDestination
.isWritable());
2294 moveToOtherViewAction
->setEnabled((list
.isEmpty() || capabilitiesSource
.supportsMoving()) && capabilitiesDestination
.isWritable());
2296 copyToOtherViewAction
->setEnabled(false);
2297 moveToOtherViewAction
->setEnabled(false);
2301 void DolphinMainWindow::updateViewActions()
2303 m_actionHandler
->updateViewActions();
2305 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
2306 toggleFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
2308 updateSplitAction();
2311 void DolphinMainWindow::updateGoActions()
2313 QAction
*goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
2314 const QUrl currentUrl
= m_activeViewContainer
->url();
2315 // I think this is one of the best places to firstly be confronted
2316 // with a file system and its hierarchy. Talking about the root
2317 // directory might seem too much here but it is the question that
2318 // naturally arises in this context.
2319 goUpAction
->setWhatsThis(xi18nc("@info:whatsthis",
2321 "the folder that contains the currently viewed one.</para>"
2322 "<para>All files and folders are organized in a hierarchical "
2323 "<emphasis>file system</emphasis>. At the top of this hierarchy is "
2324 "a directory that contains all data connected to this computer"
2325 "—the <emphasis>root directory</emphasis>.</para>"));
2326 goUpAction
->setEnabled(KIO::upUrl(currentUrl
) != currentUrl
);
2329 void DolphinMainWindow::refreshViews()
2331 m_tabWidget
->refreshViews();
2333 if (GeneralSettings::modifiedStartupSettings()) {
2334 updateWindowTitle();
2337 updateSplitAction();
2339 Q_EMIT
settingsChanged();
2342 void DolphinMainWindow::clearStatusBar()
2344 m_activeViewContainer
->statusBar()->resetToDefaultText();
2347 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
*container
)
2349 connect(container
, &DolphinViewContainer::showFilterBarChanged
, this, &DolphinMainWindow::updateFilterBarAction
);
2350 connect(container
, &DolphinViewContainer::writeStateChanged
, this, &DolphinMainWindow::slotWriteStateChanged
);
2351 connect(container
, &DolphinViewContainer::searchModeEnabledChanged
, this, &DolphinMainWindow::updateSearchAction
);
2352 connect(container
, &DolphinViewContainer::captionChanged
, this, &DolphinMainWindow::updateWindowTitle
);
2353 connect(container
, &DolphinViewContainer::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2354 connect(container
, &DolphinViewContainer::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2356 const QAction
*toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
2357 connect(toggleSearchAction
, &QAction::triggered
, container
, &DolphinViewContainer::setSearchModeEnabled
);
2359 // Make the toggled state of the selection mode actions visually follow the selection mode state of the view.
2360 auto toggleSelectionModeAction
= actionCollection()->action(QStringLiteral("toggle_selection_mode"));
2361 toggleSelectionModeAction
->setChecked(m_activeViewContainer
->isSelectionModeEnabled());
2362 connect(m_activeViewContainer
, &DolphinViewContainer::selectionModeChanged
, toggleSelectionModeAction
, &QAction::setChecked
);
2364 const DolphinView
*view
= container
->view();
2365 connect(view
, &DolphinView::selectionChanged
, this, &DolphinMainWindow::slotSelectionChanged
);
2366 connect(view
, &DolphinView::requestItemInfo
, this, &DolphinMainWindow::requestItemInfo
);
2367 connect(view
, &DolphinView::fileItemsChanged
, this, &DolphinMainWindow::fileItemsChanged
);
2368 connect(view
, &DolphinView::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2369 connect(view
, &DolphinView::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2370 connect(view
, &DolphinView::windowRequested
, this, &DolphinMainWindow::openNewWindow
);
2371 connect(view
, &DolphinView::requestContextMenu
, this, &DolphinMainWindow::openContextMenu
);
2372 connect(view
, &DolphinView::directoryLoadingStarted
, this, &DolphinMainWindow::enableStopAction
);
2373 connect(view
, &DolphinView::directoryLoadingCompleted
, this, &DolphinMainWindow::disableStopAction
);
2374 connect(view
, &DolphinView::directoryLoadingCompleted
, this, &DolphinMainWindow::slotDirectoryLoadingCompleted
);
2375 connect(view
, &DolphinView::goBackRequested
, this, &DolphinMainWindow::goBack
);
2376 connect(view
, &DolphinView::goForwardRequested
, this, &DolphinMainWindow::goForward
);
2377 connect(view
, &DolphinView::urlActivated
, this, &DolphinMainWindow::handleUrl
);
2378 connect(view
, &DolphinView::goUpRequested
, this, &DolphinMainWindow::goUp
);
2380 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::urlChanged
, this, &DolphinMainWindow::changeUrl
);
2381 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::historyChanged
, this, &DolphinMainWindow::updateHistory
);
2383 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2384 const KUrlNavigator
*navigator
=
2385 m_tabWidget
->currentTabPage()->primaryViewActive() ? navigators
->primaryUrlNavigator() : navigators
->secondaryUrlNavigator();
2387 QAction
*editableLocactionAction
= actionCollection()->action(QStringLiteral("editable_location"));
2388 editableLocactionAction
->setChecked(navigator
->isUrlEditable());
2389 connect(navigator
, &KUrlNavigator::editableStateChanged
, this, &DolphinMainWindow::slotEditableStateChanged
);
2390 connect(navigator
, &KUrlNavigator::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2391 connect(navigator
, &KUrlNavigator::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2392 connect(navigator
, &KUrlNavigator::newWindowRequested
, this, &DolphinMainWindow::openNewWindow
);
2395 void DolphinMainWindow::updateSplitAction()
2397 QAction
*splitAction
= actionCollection()->action(QStringLiteral("split_view"));
2398 const DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
2399 if (tabPage
->splitViewEnabled()) {
2400 if (GeneralSettings::closeActiveSplitView() ? tabPage
->primaryViewActive() : !tabPage
->primaryViewActive()) {
2401 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2402 splitAction
->setToolTip(i18nc("@info", "Close left view"));
2403 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close")));
2405 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2406 splitAction
->setToolTip(i18nc("@info", "Close right view"));
2407 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close")));
2410 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2411 splitAction
->setToolTip(i18nc("@info", "Split view"));
2412 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
2416 void DolphinMainWindow::updateAllowedToolbarAreas()
2418 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2419 if (toolBar()->actions().contains(navigators
)) {
2420 toolBar()->setAllowedAreas(Qt::TopToolBarArea
| Qt::BottomToolBarArea
);
2421 if (toolBarArea(toolBar()) == Qt::LeftToolBarArea
|| toolBarArea(toolBar()) == Qt::RightToolBarArea
) {
2422 addToolBar(Qt::TopToolBarArea
, toolBar());
2425 toolBar()->setAllowedAreas(Qt::AllToolBarAreas
);
2429 bool DolphinMainWindow::isKompareInstalled() const
2431 static bool initialized
= false;
2432 static bool installed
= false;
2434 // TODO: maybe replace this approach later by using a menu
2435 // plugin like kdiff3plugin.cpp
2436 installed
= !QStandardPaths::findExecutable(QStringLiteral("kompare")).isEmpty();
2442 void DolphinMainWindow::createPanelAction(const QIcon
&icon
, const QKeySequence
&shortcut
, QAction
*dockAction
, const QString
&actionName
)
2444 QAction
*panelAction
= actionCollection()->addAction(actionName
);
2445 panelAction
->setCheckable(true);
2446 panelAction
->setChecked(dockAction
->isChecked());
2447 panelAction
->setText(dockAction
->text());
2448 panelAction
->setIcon(icon
);
2449 dockAction
->setIcon(icon
);
2450 actionCollection()->setDefaultShortcut(panelAction
, shortcut
);
2452 connect(panelAction
, &QAction::triggered
, dockAction
, &QAction::trigger
);
2453 connect(dockAction
, &QAction::toggled
, panelAction
, &QAction::setChecked
);
2456 void DolphinMainWindow::setupWhatsThis()
2459 menuBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2460 "<emphasis>Menubar</emphasis>. It provides access to commands and "
2461 "configuration options. Left-click on any of the menus on this "
2462 "bar to see its contents.</para><para>The Menubar can be hidden "
2463 "by unchecking <interface>Settings|Show Menubar</interface>. Then "
2464 "most of its contents become available through a <interface>Menu"
2465 "</interface> button on the <emphasis>Toolbar</emphasis>.</para>"));
2466 toolBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2467 "<emphasis>Toolbar</emphasis>. It allows quick access to "
2468 "frequently used actions.</para><para>It is highly customizable. "
2469 "All items you see in the <interface>Menu</interface> or "
2470 "in the <interface>Menubar</interface> can be placed on the "
2471 "Toolbar. Just right-click on it and select <interface>Configure "
2472 "Toolbars…</interface> or find this action within the <interface>"
2474 "</para><para>The location of the bar and the style of its "
2475 "buttons can also be changed in the right-click menu. Right-click "
2476 "a button if you want to show or hide its text.</para>"));
2477 m_tabWidget
->setWhatsThis(xi18nc("@info:whatsthis main view",
2478 "<para>Here you can see the <emphasis>folders</emphasis> and "
2479 "<emphasis>files</emphasis> that are at the location described in "
2480 "the <interface>Location Bar</interface> above. This area is the "
2481 "central part of this application where you navigate to the files "
2482 "you want to use.</para><para>For an elaborate and general "
2483 "introduction to this application <link "
2484 "url='https://userbase.kde.org/Dolphin/File_Management#Introduction_to_Dolphin'>"
2485 "click here</link>. This will open an introductory article from "
2486 "the <emphasis>KDE UserBase Wiki</emphasis>.</para><para>For brief "
2487 "explanations of all the features of this <emphasis>view</emphasis> "
2488 "<link url='help:/dolphin/dolphin-view.html'>click here</link> "
2489 "instead. This will open a page from the <emphasis>Handbook"
2490 "</emphasis> that covers the basics.</para>"));
2493 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings
))
2494 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window "
2495 "that lists the <emphasis>keyboard shortcuts</emphasis>.<nl/>"
2496 "There you can set up key combinations to trigger an action when "
2497 "they are pressed simultaneously. All commands in this application can "
2498 "be triggered this way.</para>"));
2499 actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars
))
2500 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window in which "
2501 "you can change which buttons appear on the <emphasis>Toolbar</emphasis>.</para>"
2502 "<para>All items you see in the <interface>Menu</interface> can also be placed on the Toolbar.</para>"));
2503 actionCollection()->action(KStandardAction::name(KStandardAction::Preferences
))
2504 ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window where you can "
2505 "change a multitude of settings for this application. For an explanation "
2506 "of the various settings go to the chapter <emphasis>Configuring Dolphin"
2507 "</emphasis> in <interface>Help|Dolphin Handbook</interface>."));
2511 auto setStandardActionWhatsThis
= [this](KStandardAction::StandardAction actionId
,
2512 const QString
&whatsThis
) {
2513 // Check for the existence of an action since it can be restricted through the Kiosk system
2514 if (auto *action
= actionCollection()->action(KStandardAction::name(actionId
))) {
2515 action
->setWhatsThis(whatsThis
);
2519 // i18n: If the external link isn't available in your language it might make
2520 // sense to state the external link's language in brackets to not
2521 // frustrate the user. If there are multiple languages that the user might
2522 // know with a reasonable chance you might want to have 2 external links.
2523 // The same might be true for any external link you translate.
2524 setStandardActionWhatsThis(KStandardAction::HelpContents
, xi18nc("@info:whatsthis handbook", "<para>This opens the Handbook for this application. It provides explanations for every part of <emphasis>Dolphin</emphasis>.</para><para>If you want more elaborate introductions to the different features of <emphasis>Dolphin</emphasis> <link url='https://userbase.kde.org/Dolphin/File_Management'>click here</link>. It will open the dedicated page in the KDE UserBase Wiki.</para>"));
2525 // (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 )
2527 setStandardActionWhatsThis(KStandardAction::WhatsThis
,
2528 xi18nc("@info:whatsthis whatsthis button",
2529 "<para>This is the button that invokes the help feature you are "
2530 "using right now! Click it, then click any component of this "
2531 "application to ask \"What's this?\" about it. The mouse cursor "
2532 "will change appearance if no help is available for a spot.</para>"
2533 "<para>There are two other ways to get help: "
2534 "The <link url='help:/dolphin/index.html'>Dolphin Handbook</link> and "
2535 "the <link url='https://userbase.kde.org/Dolphin/File_Management'>KDE "
2536 "UserBase Wiki</link>.</para><para>The \"What's this?\" help is "
2537 "missing in most other windows so don't get too used to this.</para>"));
2539 setStandardActionWhatsThis(KStandardAction::ReportBug
,
2540 xi18nc("@info:whatsthis","<para>This opens a "
2541 "window that will guide you through reporting errors or flaws "
2542 "in this application or in other KDE software.</para>"
2543 "<para>High-quality bug reports are much appreciated. To learn "
2544 "how to make your bug report as effective as possible "
2545 "<link url='https://community.kde.org/Get_Involved/Bug_Reporting'>"
2546 "click here</link>.</para>"));
2548 setStandardActionWhatsThis(KStandardAction::Donate
,
2549 xi18nc("@info:whatsthis", "<para>This opens a "
2550 "<emphasis>web page</emphasis> where you can donate to "
2551 "support the continued work on this application and many "
2552 "other projects by the <emphasis>KDE</emphasis> community.</para>"
2553 "<para>Donating is the easiest and fastest way to efficiently "
2554 "support KDE and its projects. KDE projects are available for "
2555 "free therefore your donation is needed to cover things that "
2556 "require money like servers, contributor meetings, etc.</para>"
2557 "<para><emphasis>KDE e.V.</emphasis> is the non-profit "
2558 "organization behind the KDE community.</para>"));
2560 setStandardActionWhatsThis(KStandardAction::SwitchApplicationLanguage
,
2561 xi18nc("@info:whatsthis",
2562 "With this you can change the language this application uses."
2563 "<nl/>You can even set secondary languages which will be used "
2564 "if texts are not available in your preferred language."));
2566 setStandardActionWhatsThis(KStandardAction::AboutApp
,
2567 xi18nc("@info:whatsthis","This opens a "
2568 "window that informs you about the version, license, "
2569 "used libraries and maintainers of this application."));
2571 setStandardActionWhatsThis(KStandardAction::AboutKDE
,
2572 xi18nc("@info:whatsthis","This opens a "
2573 "window with information about <emphasis>KDE</emphasis>. "
2574 "The KDE community are the people behind this free software."
2575 "<nl/>If you like using this application but don't know "
2576 "about KDE or want to see a cute dragon have a look!"));
2580 bool DolphinMainWindow::addHamburgerMenuToToolbar()
2582 QDomDocument domDocument
= KXMLGUIClient::domDocument();
2583 if (domDocument
.isNull()) {
2586 QDomNode toolbar
= domDocument
.elementsByTagName(QStringLiteral("ToolBar")).at(0);
2587 if (toolbar
.isNull()) {
2591 QDomElement hamburgerMenuElement
= domDocument
.createElement(QStringLiteral("Action"));
2592 hamburgerMenuElement
.setAttribute(QStringLiteral("name"), QStringLiteral("hamburger_menu"));
2593 toolbar
.appendChild(hamburgerMenuElement
);
2595 KXMLGUIFactory::saveConfigFile(domDocument
, xmlFile());
2599 // Make sure to also remove the <KXMLGUIFactory> and <QDomDocument> include
2600 // whenever this method is removed (maybe in the year ~2026).
2603 // Set a sane initial window size
2604 QSize
DolphinMainWindow::sizeHint() const
2606 return KXmlGuiWindow::sizeHint().expandedTo(QSize(760, 550));
2609 void DolphinMainWindow::saveNewToolbarConfig()
2611 KXmlGuiWindow::saveNewToolbarConfig(); // Applies the new config. This has to be called first
2612 // because the rest of this method decides things
2613 // based on the new config.
2614 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2615 if (!toolBar()->actions().contains(navigators
)) {
2616 m_tabWidget
->currentTabPage()->insertNavigatorsWidget(navigators
);
2618 updateAllowedToolbarAreas();
2619 (static_cast<KHamburgerMenu
*>(actionCollection()->action(KStandardAction::name(KStandardAction::HamburgerMenu
))))->hideActionsOf(toolBar());
2622 void DolphinMainWindow::focusTerminalPanel()
2624 if (m_terminalPanel
->isVisible()) {
2625 if (m_terminalPanel
->terminalHasFocus()) {
2626 m_activeViewContainer
->view()->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2627 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2629 m_terminalPanel
->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2630 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2633 actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger();
2634 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2638 DolphinMainWindow::UndoUiInterface::UndoUiInterface()
2639 : KIO::FileUndoManager::UiInterface()
2643 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2647 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
*job
)
2649 DolphinMainWindow
*mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2651 DolphinViewContainer
*container
= mainWin
->activeViewContainer();
2652 container
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
2654 KIO::FileUndoManager::UiInterface::jobError(job
);
2658 bool DolphinMainWindow::isUrlOpen(const QString
&url
)
2660 return m_tabWidget
->isUrlOpen(QUrl::fromUserInput(url
));
2663 bool DolphinMainWindow::isItemVisibleInAnyView(const QString
&urlOfItem
)
2665 return m_tabWidget
->isItemVisibleInAnyView(QUrl::fromUserInput(urlOfItem
));