2 * SPDX-FileCopyrightText: 2006 Peter Penz <peter.penz19@gmail.com>
3 * SPDX-FileCopyrightText: 2006 Stefan Monov <logixoul@gmail.com>
4 * SPDX-FileCopyrightText: 2006 Cvetoslav Ludmiloff <ludmiloff@gmail.com>
6 * SPDX-License-Identifier: GPL-2.0-or-later
9 #include "dolphinmainwindow.h"
11 #include "dolphin_generalsettings.h"
12 #include "dolphinbookmarkhandler.h"
13 #include "dolphincontextmenu.h"
14 #include "dolphindockwidget.h"
15 #include "dolphinmainwindowadaptor.h"
16 #include "dolphinnavigatorswidgetaction.h"
17 #include "dolphinnewfilemenu.h"
18 #include "dolphinplacesmodelsingleton.h"
19 #include "dolphinrecenttabsmenu.h"
20 #include "dolphintabpage.h"
21 #include "dolphinurlnavigatorscontroller.h"
22 #include "dolphinviewcontainer.h"
24 #include "middleclickactioneventfilter.h"
25 #include "panels/folders/folderspanel.h"
26 #include "panels/places/placespanel.h"
27 #include "panels/terminal/terminalpanel.h"
28 #include "selectionmode/actiontexthelper.h"
29 #include "settings/dolphinsettingsdialog.h"
30 #include "statusbar/dolphinstatusbar.h"
31 #include "views/dolphinnewfilemenuobserver.h"
32 #include "views/dolphinremoteencoding.h"
33 #include "views/dolphinviewactionhandler.h"
34 #include "views/draganddrophelper.h"
35 #include "views/viewproperties.h"
37 #include <KActionCollection>
38 #include <KActionMenu>
39 #include <KAuthorized>
42 #include <KDualAction>
43 #include <KFileItemListProperties>
44 #include <KIO/CommandLauncherJob>
45 #include <KIO/JobUiDelegateFactory>
46 #include <KIO/OpenFileManagerWindowJob>
47 #include <KIO/OpenUrlJob>
48 #include <KJobWidgets>
49 #include <KLocalizedString>
50 #include <KMessageBox>
51 #include <KMoreToolsMenuFactory>
52 #include <KProtocolInfo>
53 #include <KProtocolManager>
55 #include <KShortcutsDialog>
56 #include <KStandardAction>
57 #include <KStartupInfo>
59 #include <KTerminalLauncherJob>
60 #include <KToggleAction>
62 #include <KToolBarPopupAction>
63 #include <KUrlComboBox>
64 #include <KUrlNavigator>
65 #include <KWindowSystem>
66 #include <KXMLGUIFactory>
68 #include <kwidgetsaddons_version.h>
70 #include <QApplication>
72 #include <QCloseEvent>
73 #include <QDesktopServices>
75 #include <QDomDocument>
79 #include <QPushButton>
81 #include <QStandardPaths>
83 #include <QToolButton>
89 // Used for GeneralSettings::version() to determine whether
90 // an updated version of Dolphin is running, so as to migrate
91 // removed/renamed ...etc config entries; increment it in such
93 const int CurrentDolphinVersion
= 202;
94 // The maximum number of entries in the back/forward popup menu
95 const int MaxNumberOfNavigationentries
= 12;
96 // The maximum number of "Activate Tab" shortcuts
97 const int MaxActivateTabShortcuts
= 9;
100 DolphinMainWindow::DolphinMainWindow()
101 : KXmlGuiWindow(nullptr)
102 , m_newFileMenu(nullptr)
103 , m_tabWidget(nullptr)
104 , m_activeViewContainer(nullptr)
105 , m_actionHandler(nullptr)
106 , m_remoteEncoding(nullptr)
108 , m_bookmarkHandler(nullptr)
109 , m_lastHandleUrlOpenJob(nullptr)
110 , m_terminalPanel(nullptr)
111 , m_placesPanel(nullptr)
112 , m_tearDownFromPlacesRequested(false)
113 , m_backAction(nullptr)
114 , m_forwardAction(nullptr)
116 Q_INIT_RESOURCE(dolphin
);
118 new MainWindowAdaptor(this);
121 setWindowFlags(Qt::WindowContextHelpButtonHint
);
123 setComponentName(QStringLiteral("dolphin"), QGuiApplication::applicationDisplayName());
124 setObjectName(QStringLiteral("Dolphin#"));
126 setStateConfigGroup("State");
128 connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::errorMessage
, this, &DolphinMainWindow::showErrorMessage
);
130 KIO::FileUndoManager
*undoManager
= KIO::FileUndoManager::self();
131 undoManager
->setUiInterface(new UndoUiInterface());
133 connect(undoManager
, &KIO::FileUndoManager::undoAvailable
, this, &DolphinMainWindow::slotUndoAvailable
);
134 connect(undoManager
, &KIO::FileUndoManager::undoTextChanged
, this, &DolphinMainWindow::slotUndoTextChanged
);
135 connect(undoManager
, &KIO::FileUndoManager::jobRecordingStarted
, this, &DolphinMainWindow::clearStatusBar
);
136 connect(undoManager
, &KIO::FileUndoManager::jobRecordingFinished
, this, &DolphinMainWindow::showCommand
);
138 const bool firstRun
= (GeneralSettings::version() < 200);
140 GeneralSettings::setViewPropsTimestamp(QDateTime::currentDateTime());
143 setAcceptDrops(true);
145 auto *navigatorsWidgetAction
= new DolphinNavigatorsWidgetAction(this);
146 actionCollection()->addAction(QStringLiteral("url_navigators"), navigatorsWidgetAction
);
147 m_tabWidget
= new DolphinTabWidget(navigatorsWidgetAction
, this);
148 m_tabWidget
->setObjectName("tabWidget");
149 connect(m_tabWidget
, &DolphinTabWidget::activeViewChanged
, this, &DolphinMainWindow::activeViewChanged
);
150 connect(m_tabWidget
, &DolphinTabWidget::tabCountChanged
, this, &DolphinMainWindow::tabCountChanged
);
151 connect(m_tabWidget
, &DolphinTabWidget::currentUrlChanged
, this, &DolphinMainWindow::updateWindowTitle
);
152 setCentralWidget(m_tabWidget
);
154 m_actionTextHelper
= new SelectionMode::ActionTextHelper(this);
157 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), m_actionTextHelper
, this);
158 connect(m_actionHandler
, &DolphinViewActionHandler::actionBeingHandled
, this, &DolphinMainWindow::clearStatusBar
);
159 connect(m_actionHandler
, &DolphinViewActionHandler::createDirectoryTriggered
, this, &DolphinMainWindow::createDirectory
);
160 connect(m_actionHandler
, &DolphinViewActionHandler::selectionModeChangeTriggered
, this, &DolphinMainWindow::slotSetSelectionMode
);
162 m_newFileMenu
->setNewFolderShortcutAction(actionCollection()->action("create_dir"));
164 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
165 connect(this, &DolphinMainWindow::urlChanged
, m_remoteEncoding
, &DolphinRemoteEncoding::slotAboutToOpenUrl
);
169 setupGUI(Save
| Create
| ToolBar
);
170 stateChanged(QStringLiteral("new_file"));
172 QClipboard
*clipboard
= QApplication::clipboard();
173 connect(clipboard
, &QClipboard::dataChanged
, this, &DolphinMainWindow::updatePasteAction
);
175 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
176 toggleFilterBarAction
->setChecked(GeneralSettings::filterBar());
179 menuBar()->setVisible(false);
182 const bool showMenu
= !menuBar()->isHidden();
183 QAction
*showMenuBarAction
= actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar
));
184 showMenuBarAction
->setChecked(showMenu
); // workaround for bug #171080
186 auto hamburgerMenu
= static_cast<KHamburgerMenu
*>(actionCollection()->action(KStandardAction::name(KStandardAction::HamburgerMenu
)));
187 hamburgerMenu
->setMenuBar(menuBar());
188 hamburgerMenu
->setShowMenuBarAction(showMenuBarAction
);
189 connect(hamburgerMenu
, &KHamburgerMenu::aboutToShowMenu
, this, &DolphinMainWindow::updateHamburgerMenu
);
190 hamburgerMenu
->hideActionsOf(toolBar());
191 if (GeneralSettings::version() < 201 && !toolBar()->actions().contains(hamburgerMenu
)) {
192 addHamburgerMenuToToolbar();
195 updateAllowedToolbarAreas();
197 // enable middle-click on back/forward/up to open in a new tab
198 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
199 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotToolBarActionMiddleClicked
);
200 toolBar()->installEventFilter(middleClickEventFilter
);
204 connect(KSycoca::self(), &KSycoca::databaseChanged
, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
206 QTimer::singleShot(0, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
208 m_fileItemActions
.setParentWidget(this);
209 connect(&m_fileItemActions
, &KFileItemActions::error
, this, [this](const QString
&errorMessage
) {
210 showErrorMessage(errorMessage
);
213 connect(GeneralSettings::self(), &GeneralSettings::splitViewChanged
, this, &DolphinMainWindow::slotSplitViewChanged
);
216 DolphinMainWindow::~DolphinMainWindow()
218 // This fixes a crash on Wayland when closing the mainwindow while another dialog is open.
219 disconnect(QGuiApplication::clipboard(), &QClipboard::dataChanged
, this, &DolphinMainWindow::updatePasteAction
);
222 QVector
<DolphinViewContainer
*> DolphinMainWindow::viewContainers() const
224 QVector
<DolphinViewContainer
*> viewContainers
;
226 for (int i
= 0; i
< m_tabWidget
->count(); ++i
) {
227 DolphinTabPage
*tabPage
= m_tabWidget
->tabPageAt(i
);
229 viewContainers
<< tabPage
->primaryViewContainer();
230 if (tabPage
->splitViewEnabled()) {
231 viewContainers
<< tabPage
->secondaryViewContainer();
234 return viewContainers
;
237 void DolphinMainWindow::openDirectories(const QList
<QUrl
> &dirs
, bool splitView
)
239 m_tabWidget
->openDirectories(dirs
, splitView
);
242 void DolphinMainWindow::openDirectories(const QStringList
&dirs
, bool splitView
)
244 openDirectories(QUrl::fromStringList(dirs
), splitView
);
247 void DolphinMainWindow::openFiles(const QList
<QUrl
> &files
, bool splitView
)
249 m_tabWidget
->openFiles(files
, splitView
);
252 bool DolphinMainWindow::isFoldersPanelEnabled() const
254 return actionCollection()->action(QStringLiteral("show_folders_panel"))->isChecked();
257 bool DolphinMainWindow::isInformationPanelEnabled() const
260 return actionCollection()->action(QStringLiteral("show_information_panel"))->isChecked();
266 bool DolphinMainWindow::isSplitViewEnabledInCurrentTab() const
268 return m_tabWidget
->currentTabPage()->splitViewEnabled();
271 void DolphinMainWindow::openFiles(const QStringList
&files
, bool splitView
)
273 openFiles(QUrl::fromStringList(files
), splitView
);
276 bool DolphinMainWindow::isOnCurrentDesktop() const
279 if (KWindowSystem::isPlatformX11()) {
280 const NET::Properties properties
= NET::WMDesktop
;
281 KWindowInfo
info(this->winId(), properties
);
282 return info
.isOnCurrentDesktop();
288 bool DolphinMainWindow::isOnActivity(const QString
&activityId
) const
290 #if HAVE_X11 && HAVE_KACTIVITIES
291 if (KWindowSystem::isPlatformX11()) {
292 const NET::Properties properties
= NET::Supported
;
293 const NET::Properties2 properties2
= NET::WM2Activities
;
294 KWindowInfo
info(this->winId(), properties
, properties2
);
295 return info
.activities().contains(activityId
);
301 void DolphinMainWindow::activateWindow(const QString
&activationToken
)
303 window()->setAttribute(Qt::WA_NativeWindow
, true);
305 if (KWindowSystem::isPlatformWayland()) {
306 KWindowSystem::setCurrentXdgActivationToken(activationToken
);
308 KStartupInfo::setNewStartupId(window()->windowHandle(), activationToken
.toUtf8());
311 KWindowSystem::activateWindow(window()->windowHandle());
314 bool DolphinMainWindow::isActiveWindow()
316 return window()->isActiveWindow();
319 void DolphinMainWindow::showCommand(CommandType command
)
321 DolphinStatusBar
*statusBar
= m_activeViewContainer
->statusBar();
323 case KIO::FileUndoManager::Copy
:
324 statusBar
->setText(i18nc("@info:status", "Successfully copied."));
326 case KIO::FileUndoManager::Move
:
327 statusBar
->setText(i18nc("@info:status", "Successfully moved."));
329 case KIO::FileUndoManager::Link
:
330 statusBar
->setText(i18nc("@info:status", "Successfully linked."));
332 case KIO::FileUndoManager::Trash
:
333 statusBar
->setText(i18nc("@info:status", "Successfully moved to trash."));
335 case KIO::FileUndoManager::Rename
:
336 statusBar
->setText(i18nc("@info:status", "Successfully renamed."));
339 case KIO::FileUndoManager::Mkdir
:
340 statusBar
->setText(i18nc("@info:status", "Created folder."));
348 void DolphinMainWindow::pasteIntoFolder()
350 m_activeViewContainer
->view()->pasteIntoFolder();
353 void DolphinMainWindow::changeUrl(const QUrl
&url
)
355 if (!KProtocolManager::supportsListing(url
)) {
356 // The URL navigator only checks for validity, not
357 // if the URL can be listed. An error message is
358 // shown due to DolphinViewContainer::restoreView().
362 m_activeViewContainer
->setUrl(url
);
363 updateFileAndEditActions();
368 Q_EMIT
urlChanged(url
);
371 void DolphinMainWindow::slotTerminalDirectoryChanged(const QUrl
&url
)
373 if (m_tearDownFromPlacesRequested
&& url
== QUrl::fromLocalFile(QDir::homePath())) {
374 m_placesPanel
->proceedWithTearDown();
375 m_tearDownFromPlacesRequested
= false;
378 m_activeViewContainer
->setAutoGrabFocus(false);
380 m_activeViewContainer
->setAutoGrabFocus(true);
383 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
385 KToggleAction
*editableLocationAction
= static_cast<KToggleAction
*>(actionCollection()->action(QStringLiteral("editable_location")));
386 editableLocationAction
->setChecked(editable
);
389 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
&selection
)
391 updateFileAndEditActions();
393 const int selectedUrlsCount
= m_tabWidget
->currentTabPage()->selectedItemsCount();
395 QAction
*compareFilesAction
= actionCollection()->action(QStringLiteral("compare_files"));
396 if (selectedUrlsCount
== 2) {
397 compareFilesAction
->setEnabled(isKompareInstalled());
399 compareFilesAction
->setEnabled(false);
402 Q_EMIT
selectionChanged(selection
);
405 void DolphinMainWindow::updateHistory()
407 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
408 const int index
= urlNavigator
->historyIndex();
410 QAction
*backAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Back
));
412 backAction
->setToolTip(i18nc("@info", "Go back"));
413 backAction
->setWhatsThis(i18nc("@info:whatsthis go back", "Return to the previously viewed folder."));
414 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
417 QAction
*forwardAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Forward
));
419 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
420 forwardAction
->setWhatsThis(xi18nc("@info:whatsthis go forward", "This undoes a <interface>Go|Back</interface> action."));
421 forwardAction
->setEnabled(index
> 0);
425 void DolphinMainWindow::updateFilterBarAction(bool show
)
427 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
428 toggleFilterBarAction
->setChecked(show
);
431 void DolphinMainWindow::openNewMainWindow()
433 Dolphin::openNewWindow({m_activeViewContainer
->url()}, this);
436 void DolphinMainWindow::openNewActivatedTab()
438 // keep browsers compatibility, new tab is always after last one
439 auto openNewTabAfterLastTabConfigured
= GeneralSettings::openNewTabAfterLastTab();
440 GeneralSettings::setOpenNewTabAfterLastTab(true);
441 m_tabWidget
->openNewActivatedTab();
442 GeneralSettings::setOpenNewTabAfterLastTab(openNewTabAfterLastTabConfigured
);
445 void DolphinMainWindow::addToPlaces()
450 // If nothing is selected, act on the current dir
451 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
452 url
= m_activeViewContainer
->url();
453 name
= m_activeViewContainer
->placesText();
455 const auto dirToAdd
= m_activeViewContainer
->view()->selectedItems().first();
456 url
= dirToAdd
.url();
457 name
= dirToAdd
.name();
461 if (m_activeViewContainer
->isSearchModeEnabled()) {
462 icon
= QStringLiteral("folder-saved-search-symbolic");
464 icon
= KIO::iconNameForUrl(url
);
466 DolphinPlacesModelSingleton::instance().placesModel()->addPlace(name
, url
, icon
);
470 void DolphinMainWindow::openNewTab(const QUrl
&url
)
472 m_tabWidget
->openNewTab(url
, QUrl());
475 void DolphinMainWindow::openNewTabAndActivate(const QUrl
&url
)
477 m_tabWidget
->openNewActivatedTab(url
, QUrl());
480 void DolphinMainWindow::openNewWindow(const QUrl
&url
)
482 Dolphin::openNewWindow({url
}, this);
485 void DolphinMainWindow::slotSplitViewChanged()
487 m_tabWidget
->currentTabPage()->setSplitViewEnabled(GeneralSettings::splitView(), WithAnimation
);
491 void DolphinMainWindow::openInNewTab()
493 const KFileItemList
&list
= m_activeViewContainer
->view()->selectedItems();
494 bool tabCreated
= false;
496 for (const KFileItem
&item
: list
) {
497 const QUrl
&url
= DolphinView::openItemAsFolderUrl(item
);
498 if (!url
.isEmpty()) {
504 // if no new tab has been created from the selection
505 // open the current directory in a new tab
507 openNewTab(m_activeViewContainer
->url());
511 void DolphinMainWindow::openInNewWindow()
515 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
516 if (list
.isEmpty()) {
517 newWindowUrl
= m_activeViewContainer
->url();
518 } else if (list
.count() == 1) {
519 const KFileItem
&item
= list
.first();
520 newWindowUrl
= DolphinView::openItemAsFolderUrl(item
);
523 if (!newWindowUrl
.isEmpty()) {
524 Dolphin::openNewWindow({newWindowUrl
}, this);
528 void DolphinMainWindow::showTarget()
530 const KFileItem link
= m_activeViewContainer
->view()->selectedItems().at(0);
531 const QUrl destinationUrl
= link
.url().resolved(QUrl(link
.linkDest()));
533 auto job
= KIO::stat(destinationUrl
, KIO::StatJob::SourceSide
, KIO::StatNoDetails
);
535 connect(job
, &KJob::finished
, this, [this, destinationUrl
](KJob
*job
) {
536 KIO::StatJob
*statJob
= static_cast<KIO::StatJob
*>(job
);
538 if (statJob
->error()) {
539 m_activeViewContainer
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
541 KIO::highlightInFileManager({destinationUrl
});
546 bool DolphinMainWindow::event(QEvent
*event
)
548 if (event
->type() == QEvent::ShortcutOverride
) {
549 const QKeyEvent
*keyEvent
= static_cast<QKeyEvent
*>(event
);
550 if (keyEvent
->key() == Qt::Key_Space
&& m_activeViewContainer
->view()->handleSpaceAsNormalKey()) {
556 return KXmlGuiWindow::event(event
);
559 void DolphinMainWindow::showEvent(QShowEvent
*event
)
561 KXmlGuiWindow::showEvent(event
);
563 if (!event
->spontaneous()) {
564 m_activeViewContainer
->view()->setFocus();
568 void DolphinMainWindow::closeEvent(QCloseEvent
*event
)
570 // Find out if Dolphin is closed directly by the user or
571 // by the session manager because the session is closed
572 bool closedByUser
= true;
573 if (qApp
->isSavingSession()) {
574 closedByUser
= false;
577 if (m_tabWidget
->count() > 1 && GeneralSettings::confirmClosingMultipleTabs() && !GeneralSettings::rememberOpenedTabs() && closedByUser
) {
578 // Ask the user if he really wants to quit and close all tabs.
579 // Open a confirmation dialog with 3 buttons:
580 // QDialogButtonBox::Yes -> Quit
581 // QDialogButtonBox::No -> Close only the current tab
582 // QDialogButtonBox::Cancel -> do nothing
583 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
584 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
585 dialog
->setModal(true);
586 QDialogButtonBox
*buttons
= new QDialogButtonBox(QDialogButtonBox::Yes
| QDialogButtonBox::No
| QDialogButtonBox::Cancel
);
587 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
),
588 KGuiItem(i18nc("@action:button 'Quit Dolphin' button", "&Quit %1", QGuiApplication::applicationDisplayName()),
589 QIcon::fromTheme(QStringLiteral("application-exit"))));
590 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("C&lose Current Tab"), QIcon::fromTheme(QStringLiteral("tab-close"))));
591 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
592 buttons
->button(QDialogButtonBox::Yes
)->setDefault(true);
594 bool doNotAskAgainCheckboxResult
= false;
596 const auto result
= KMessageBox::createKMessageBox(dialog
,
598 QMessageBox::Warning
,
599 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
601 i18n("Do not ask again"),
602 &doNotAskAgainCheckboxResult
,
603 KMessageBox::Notify
);
605 if (doNotAskAgainCheckboxResult
) {
606 GeneralSettings::setConfirmClosingMultipleTabs(false);
610 case QDialogButtonBox::Yes
:
613 case QDialogButtonBox::No
:
614 // Close only the current tab
615 m_tabWidget
->closeTab();
623 if (m_terminalPanel
&& m_terminalPanel
->hasProgramRunning() && GeneralSettings::confirmClosingTerminalRunningProgram() && closedByUser
) {
624 // Ask if the user really wants to quit Dolphin with a program that is still running in the Terminal panel
625 // Open a confirmation dialog with 3 buttons:
626 // QDialogButtonBox::Yes -> Quit
627 // QDialogButtonBox::No -> Show Terminal Panel
628 // QDialogButtonBox::Cancel -> do nothing
629 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
630 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
631 dialog
->setModal(true);
632 auto standardButtons
= QDialogButtonBox::Yes
| QDialogButtonBox::Cancel
;
633 if (!m_terminalPanel
->isVisible()) {
634 standardButtons
|= QDialogButtonBox::No
;
636 QDialogButtonBox
*buttons
= new QDialogButtonBox(standardButtons
);
637 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KStandardGuiItem::quit());
638 if (!m_terminalPanel
->isVisible()) {
639 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("Show &Terminal Panel"), QIcon::fromTheme(QStringLiteral("dialog-scripts"))));
641 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
643 bool doNotAskAgainCheckboxResult
= false;
645 const auto result
= KMessageBox::createKMessageBox(
648 QMessageBox::Warning
,
649 i18n("The program '%1' is still running in the Terminal panel. Are you sure you want to quit?", m_terminalPanel
->runningProgramName()),
651 i18n("Do not ask again"),
652 &doNotAskAgainCheckboxResult
,
653 KMessageBox::Dangerous
);
655 if (doNotAskAgainCheckboxResult
) {
656 GeneralSettings::setConfirmClosingTerminalRunningProgram(false);
660 case QDialogButtonBox::Yes
:
663 case QDialogButtonBox::No
:
664 actionCollection()->action("show_terminal_panel")->trigger();
665 // Do not quit, ignore quit event
673 if (GeneralSettings::rememberOpenedTabs()) {
674 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
675 KConfig
*config
= KConfigGui::sessionConfig();
676 saveGlobalProperties(config
);
677 savePropertiesInternal(config
, 1);
681 GeneralSettings::setVersion(CurrentDolphinVersion
);
682 GeneralSettings::self()->save();
684 KXmlGuiWindow::closeEvent(event
);
687 void DolphinMainWindow::saveProperties(KConfigGroup
&group
)
689 m_tabWidget
->saveProperties(group
);
692 void DolphinMainWindow::readProperties(const KConfigGroup
&group
)
694 m_tabWidget
->readProperties(group
);
697 void DolphinMainWindow::updateNewMenu()
699 m_newFileMenu
->checkUpToDate();
700 m_newFileMenu
->setWorkingDirectory(activeViewContainer()->url());
703 void DolphinMainWindow::createDirectory()
705 m_newFileMenu
->setWorkingDirectory(activeViewContainer()->url());
706 m_newFileMenu
->createDirectory();
709 void DolphinMainWindow::quit()
714 void DolphinMainWindow::showErrorMessage(const QString
&message
)
716 m_activeViewContainer
->showMessage(message
, DolphinViewContainer::Error
);
719 void DolphinMainWindow::slotUndoAvailable(bool available
)
721 QAction
*undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
723 undoAction
->setEnabled(available
);
727 void DolphinMainWindow::slotUndoTextChanged(const QString
&text
)
729 QAction
*undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
731 undoAction
->setText(text
);
735 void DolphinMainWindow::undo()
738 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
739 KIO::FileUndoManager::self()->undo();
742 void DolphinMainWindow::cut()
744 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
745 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CutContents
);
747 m_activeViewContainer
->view()->cutSelectedItemsToClipboard();
748 m_activeViewContainer
->setSelectionModeEnabled(false);
752 void DolphinMainWindow::copy()
754 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
755 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CopyContents
);
757 m_activeViewContainer
->view()->copySelectedItemsToClipboard();
758 m_activeViewContainer
->setSelectionModeEnabled(false);
762 void DolphinMainWindow::paste()
764 m_activeViewContainer
->view()->paste();
767 void DolphinMainWindow::find()
769 m_activeViewContainer
->setSearchModeEnabled(true);
772 void DolphinMainWindow::updateSearchAction()
774 QAction
*toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
775 toggleSearchAction
->setChecked(m_activeViewContainer
->isSearchModeEnabled());
778 void DolphinMainWindow::updatePasteAction()
780 QAction
*pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
781 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
782 pasteAction
->setEnabled(pasteInfo
.first
);
783 pasteAction
->setText(pasteInfo
.second
);
786 void DolphinMainWindow::slotDirectoryLoadingCompleted()
791 void DolphinMainWindow::slotToolBarActionMiddleClicked(QAction
*action
)
793 if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Back
))) {
795 } else if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Forward
))) {
797 } else if (action
== actionCollection()->action(QStringLiteral("go_up"))) {
799 } else if (action
== actionCollection()->action(QStringLiteral("go_home"))) {
804 QAction
*DolphinMainWindow::urlNavigatorHistoryAction(const KUrlNavigator
*urlNavigator
, int historyIndex
, QObject
*parent
)
806 const QUrl url
= urlNavigator
->locationUrl(historyIndex
);
808 QString text
= url
.toDisplayString(QUrl::PreferLocalFile
);
810 if (!urlNavigator
->showFullPath()) {
811 const KFilePlacesModel
*placesModel
= DolphinPlacesModelSingleton::instance().placesModel();
813 const QModelIndex closestIdx
= placesModel
->closestItem(url
);
814 if (closestIdx
.isValid()) {
815 const QUrl placeUrl
= placesModel
->url(closestIdx
);
817 text
= placesModel
->text(closestIdx
);
819 QString pathInsidePlace
= url
.path().mid(placeUrl
.path().length());
821 if (!pathInsidePlace
.isEmpty() && !pathInsidePlace
.startsWith(QLatin1Char('/'))) {
822 pathInsidePlace
.prepend(QLatin1Char('/'));
825 if (pathInsidePlace
!= QLatin1Char('/')) {
826 text
.append(pathInsidePlace
);
831 QAction
*action
= new QAction(QIcon::fromTheme(KIO::iconNameForUrl(url
)), text
, parent
);
832 action
->setData(historyIndex
);
836 void DolphinMainWindow::slotAboutToShowBackPopupMenu()
838 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
840 m_backAction
->menu()->clear();
841 for (int i
= urlNavigator
->historyIndex() + 1; i
< urlNavigator
->historySize() && entries
< MaxNumberOfNavigationentries
; ++i
, ++entries
) {
842 QAction
*action
= urlNavigatorHistoryAction(urlNavigator
, i
, m_backAction
->menu());
843 m_backAction
->menu()->addAction(action
);
847 void DolphinMainWindow::slotGoBack(QAction
*action
)
849 int gotoIndex
= action
->data().value
<int>();
850 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
851 for (int i
= gotoIndex
- urlNavigator
->historyIndex(); i
> 0; --i
) {
856 void DolphinMainWindow::slotBackForwardActionMiddleClicked(QAction
*action
)
859 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
860 openNewTab(urlNavigator
->locationUrl(action
->data().value
<int>()));
864 void DolphinMainWindow::slotAboutToShowForwardPopupMenu()
866 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
868 m_forwardAction
->menu()->clear();
869 for (int i
= urlNavigator
->historyIndex() - 1; i
>= 0 && entries
< MaxNumberOfNavigationentries
; --i
, ++entries
) {
870 QAction
*action
= urlNavigatorHistoryAction(urlNavigator
, i
, m_forwardAction
->menu());
871 m_forwardAction
->menu()->addAction(action
);
875 void DolphinMainWindow::slotGoForward(QAction
*action
)
877 int gotoIndex
= action
->data().value
<int>();
878 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
879 for (int i
= urlNavigator
->historyIndex() - gotoIndex
; i
> 0; --i
) {
884 void DolphinMainWindow::slotSetSelectionMode(bool enabled
, SelectionMode::BottomBar::Contents bottomBarContents
)
886 m_activeViewContainer
->setSelectionModeEnabled(enabled
, actionCollection(), bottomBarContents
);
889 void DolphinMainWindow::selectAll()
893 // if the URL navigator is editable and focused, select the whole
894 // URL instead of all items of the view
896 KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigator();
897 QLineEdit
*lineEdit
= urlNavigator
->editor()->lineEdit();
898 const bool selectUrl
= urlNavigator
->isUrlEditable() && lineEdit
->hasFocus();
900 lineEdit
->selectAll();
902 m_activeViewContainer
->view()->selectAll();
906 void DolphinMainWindow::invertSelection()
909 m_activeViewContainer
->view()->invertSelection();
912 void DolphinMainWindow::toggleSplitView()
914 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
915 tabPage
->setSplitViewEnabled(!tabPage
->splitViewEnabled(), WithAnimation
);
920 void DolphinMainWindow::toggleSplitStash()
922 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
923 tabPage
->setSplitViewEnabled(false, WithAnimation
);
924 tabPage
->setSplitViewEnabled(true, WithAnimation
, QUrl("stash:/"));
927 void DolphinMainWindow::copyToInactiveSplitView()
929 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
930 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CopyToOtherViewContents
);
932 m_tabWidget
->copyToInactiveSplitView();
933 m_activeViewContainer
->setSelectionModeEnabled(false);
937 void DolphinMainWindow::moveToInactiveSplitView()
939 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
940 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::MoveToOtherViewContents
);
942 m_tabWidget
->moveToInactiveSplitView();
943 m_activeViewContainer
->setSelectionModeEnabled(false);
947 void DolphinMainWindow::reloadView()
950 m_activeViewContainer
->reload();
951 m_activeViewContainer
->statusBar()->updateSpaceInfo();
954 void DolphinMainWindow::stopLoading()
956 m_activeViewContainer
->view()->stopLoading();
959 void DolphinMainWindow::enableStopAction()
961 actionCollection()->action(QStringLiteral("stop"))->setEnabled(true);
964 void DolphinMainWindow::disableStopAction()
966 actionCollection()->action(QStringLiteral("stop"))->setEnabled(false);
969 void DolphinMainWindow::toggleSelectionMode()
971 const bool checked
= !m_activeViewContainer
->isSelectionModeEnabled();
973 m_activeViewContainer
->setSelectionModeEnabled(checked
, actionCollection(), SelectionMode::BottomBar::Contents::GeneralContents
);
974 actionCollection()->action(QStringLiteral("toggle_selection_mode"))->setChecked(checked
);
977 void DolphinMainWindow::showFilterBar()
979 m_activeViewContainer
->setFilterBarVisible(true);
982 void DolphinMainWindow::toggleFilterBar()
984 const bool checked
= !m_activeViewContainer
->isFilterBarVisible();
985 m_activeViewContainer
->setFilterBarVisible(checked
);
987 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
988 toggleFilterBarAction
->setChecked(checked
);
991 void DolphinMainWindow::toggleEditLocation()
995 QAction
*action
= actionCollection()->action(QStringLiteral("editable_location"));
996 KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigator();
997 urlNavigator
->setUrlEditable(action
->isChecked());
1000 void DolphinMainWindow::replaceLocation()
1002 KUrlNavigator
*navigator
= m_activeViewContainer
->urlNavigator();
1003 QLineEdit
*lineEdit
= navigator
->editor()->lineEdit();
1005 // If the text field currently has focus and everything is selected,
1006 // pressing the keyboard shortcut returns the whole thing to breadcrumb mode
1007 if (navigator
->isUrlEditable() && lineEdit
->hasFocus() && lineEdit
->selectedText() == lineEdit
->text()) {
1008 navigator
->setUrlEditable(false);
1010 navigator
->setUrlEditable(true);
1011 navigator
->setFocus();
1012 lineEdit
->selectAll();
1016 void DolphinMainWindow::togglePanelLockState()
1018 const bool newLockState
= !GeneralSettings::lockPanels();
1019 const auto childrenObjects
= children();
1020 for (QObject
*child
: childrenObjects
) {
1021 DolphinDockWidget
*dock
= qobject_cast
<DolphinDockWidget
*>(child
);
1023 dock
->setLocked(newLockState
);
1027 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(newLockState
);
1029 GeneralSettings::setLockPanels(newLockState
);
1032 void DolphinMainWindow::slotTerminalPanelVisibilityChanged()
1034 if (m_terminalPanel
->isHiddenInVisibleWindow() && m_activeViewContainer
) {
1035 m_activeViewContainer
->view()->setFocus();
1039 void DolphinMainWindow::goBack()
1041 DolphinUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
1042 urlNavigator
->goBack();
1044 if (urlNavigator
->locationState().isEmpty()) {
1045 // An empty location state indicates a redirection URL,
1046 // which must be skipped too
1047 urlNavigator
->goBack();
1051 void DolphinMainWindow::goForward()
1053 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goForward();
1056 void DolphinMainWindow::goUp()
1058 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goUp();
1061 void DolphinMainWindow::goHome()
1063 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goHome();
1066 void DolphinMainWindow::goBackInNewTab()
1068 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
1069 const int index
= urlNavigator
->historyIndex() + 1;
1070 openNewTab(urlNavigator
->locationUrl(index
));
1073 void DolphinMainWindow::goForwardInNewTab()
1075 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
1076 const int index
= urlNavigator
->historyIndex() - 1;
1077 openNewTab(urlNavigator
->locationUrl(index
));
1080 void DolphinMainWindow::goUpInNewTab()
1082 const QUrl currentUrl
= activeViewContainer()->urlNavigator()->locationUrl();
1083 openNewTab(KIO::upUrl(currentUrl
));
1086 void DolphinMainWindow::goHomeInNewTab()
1088 openNewTab(Dolphin::homeUrl());
1091 void DolphinMainWindow::compareFiles()
1093 const KFileItemList items
= m_tabWidget
->currentTabPage()->selectedItems();
1094 if (items
.count() != 2) {
1095 // The action is disabled in this case, but it could have been triggered
1096 // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
1100 QUrl urlA
= items
.at(0).url();
1101 QUrl urlB
= items
.at(1).url();
1103 QString
command(QStringLiteral("kompare -c \""));
1104 command
.append(urlA
.toDisplayString(QUrl::PreferLocalFile
));
1105 command
.append("\" \"");
1106 command
.append(urlB
.toDisplayString(QUrl::PreferLocalFile
));
1107 command
.append('\"');
1109 KIO::CommandLauncherJob
*job
= new KIO::CommandLauncherJob(command
, this);
1110 job
->setDesktopName(QStringLiteral("org.kde.kompare"));
1114 void DolphinMainWindow::toggleShowMenuBar()
1116 const bool visible
= menuBar()->isVisible();
1117 menuBar()->setVisible(!visible
);
1120 QPointer
<QAction
> DolphinMainWindow::preferredSearchTool()
1122 m_searchTools
.clear();
1123 KMoreToolsMenuFactory("dolphin/search-tools").fillMenuFromGroupingNames(&m_searchTools
, {"files-find"}, m_activeViewContainer
->url());
1124 QList
<QAction
*> actions
= m_searchTools
.actions();
1125 if (actions
.isEmpty()) {
1128 QAction
*action
= actions
.first();
1129 if (action
->isSeparator()) {
1135 void DolphinMainWindow::updateOpenPreferredSearchToolAction()
1137 QAction
*openPreferredSearchTool
= actionCollection()->action(QStringLiteral("open_preferred_search_tool"));
1138 if (!openPreferredSearchTool
) {
1141 QPointer
<QAction
> tool
= preferredSearchTool();
1143 openPreferredSearchTool
->setVisible(true);
1144 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open %1", tool
->text()));
1145 // Only override with the app icon if it is the default, i.e. the user hasn't configured one manually
1146 // https://bugs.kde.org/show_bug.cgi?id=442815
1147 if (openPreferredSearchTool
->icon().name() == QLatin1String("search")) {
1148 openPreferredSearchTool
->setIcon(tool
->icon());
1151 openPreferredSearchTool
->setVisible(false);
1152 // still visible in Shortcuts configuration window
1153 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1154 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1158 void DolphinMainWindow::openPreferredSearchTool()
1160 QPointer
<QAction
> tool
= preferredSearchTool();
1166 void DolphinMainWindow::openTerminal()
1168 openTerminalJob(m_activeViewContainer
->url());
1171 void DolphinMainWindow::openTerminalHere()
1173 QList
<QUrl
> urls
= {};
1175 for (const KFileItem
&item
: m_activeViewContainer
->view()->selectedItems()) {
1176 QUrl url
= item
.targetUrl();
1177 if (item
.isFile()) {
1178 url
.setPath(QFileInfo(url
.path()).absolutePath());
1180 if (!urls
.contains(url
)) {
1185 // No items are selected. Open a terminal window for the current location.
1186 if (urls
.count() == 0) {
1191 if (urls
.count() > 5) {
1192 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());
1193 #if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
1194 const int answer
= KMessageBox::warningTwoActions(
1199 const int answer
= KMessageBox::warningYesNo(
1204 KGuiItem(i18ncp("@action:button", "Open %1 Terminal", "Open %1 Terminals", urls
.count()), QStringLiteral("utilities-terminal")),
1205 KStandardGuiItem::cancel());
1206 #if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
1207 if (answer
!= KMessageBox::PrimaryAction
) {
1209 if (answer
!= KMessageBox::Yes
) {
1215 for (const QUrl
&url
: urls
) {
1216 openTerminalJob(url
);
1220 void DolphinMainWindow::openTerminalJob(const QUrl
&url
)
1222 if (url
.isLocalFile()) {
1223 auto job
= new KTerminalLauncherJob(QString());
1224 job
->setWorkingDirectory(url
.toLocalFile());
1229 // Not a local file, with protocol Class ":local", try stat'ing
1230 if (KProtocolInfo::protocolClass(url
.scheme()) == QLatin1String(":local")) {
1231 KIO::StatJob
*job
= KIO::mostLocalUrl(url
);
1232 KJobWidgets::setWindow(job
, this);
1233 connect(job
, &KJob::result
, this, [job
]() {
1235 if (!job
->error()) {
1236 statUrl
= job
->mostLocalUrl();
1239 auto job
= new KTerminalLauncherJob(QString());
1240 job
->setWorkingDirectory(statUrl
.isLocalFile() ? statUrl
.toLocalFile() : QDir::homePath());
1247 // Nothing worked, just use $HOME
1248 auto job
= new KTerminalLauncherJob(QString());
1249 job
->setWorkingDirectory(QDir::homePath());
1253 void DolphinMainWindow::editSettings()
1255 if (!m_settingsDialog
) {
1256 DolphinViewContainer
*container
= activeViewContainer();
1257 container
->view()->writeSettings();
1259 const QUrl url
= container
->url();
1260 DolphinSettingsDialog
*settingsDialog
= new DolphinSettingsDialog(url
, this, actionCollection());
1261 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, this, &DolphinMainWindow::refreshViews
);
1262 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, &DolphinUrlNavigatorsController::slotReadSettings
);
1263 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1264 settingsDialog
->show();
1265 m_settingsDialog
= settingsDialog
;
1267 m_settingsDialog
.data()->raise();
1271 void DolphinMainWindow::handleUrl(const QUrl
&url
)
1273 delete m_lastHandleUrlOpenJob
;
1274 m_lastHandleUrlOpenJob
= nullptr;
1276 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1277 activeViewContainer()->setUrl(url
);
1279 m_lastHandleUrlOpenJob
= new KIO::OpenUrlJob(url
);
1280 m_lastHandleUrlOpenJob
->setUiDelegate(KIO::createDefaultJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
1281 m_lastHandleUrlOpenJob
->setShowOpenOrExecuteDialog(true);
1283 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::mimeTypeFound
, this, [this, url
](const QString
&mimetype
) {
1284 if (mimetype
== QLatin1String("inode/directory")) {
1285 // If it's a dir, we'll take it from here
1286 m_lastHandleUrlOpenJob
->kill();
1287 m_lastHandleUrlOpenJob
= nullptr;
1288 activeViewContainer()->setUrl(url
);
1292 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::result
, this, [this]() {
1293 m_lastHandleUrlOpenJob
= nullptr;
1296 m_lastHandleUrlOpenJob
->start();
1300 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1302 // trash:/ is writable but we don't want to create new items in it.
1303 // TODO: remove the trash check once https://phabricator.kde.org/T8234 is implemented
1304 newFileMenu()->setEnabled(isFolderWritable
&& m_activeViewContainer
->url().scheme() != QLatin1String("trash"));
1307 void DolphinMainWindow::openContextMenu(const QPoint
&pos
, const KFileItem
&item
, const KFileItemList
&selectedItems
, const QUrl
&url
)
1309 QPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, item
, selectedItems
, url
, &m_fileItemActions
);
1310 contextMenu
.data()->exec(pos
);
1312 // Delete the menu, unless it has been deleted in its own nested event loop already.
1314 contextMenu
->deleteLater();
1318 QMenu
*DolphinMainWindow::createPopupMenu()
1320 QMenu
*menu
= KXmlGuiWindow::createPopupMenu();
1322 menu
->addSeparator();
1323 menu
->addAction(actionCollection()->action(QStringLiteral("lock_panels")));
1328 void DolphinMainWindow::updateHamburgerMenu()
1330 KActionCollection
*ac
= actionCollection();
1331 auto hamburgerMenu
= static_cast<KHamburgerMenu
*>(ac
->action(KStandardAction::name(KStandardAction::HamburgerMenu
)));
1332 auto menu
= hamburgerMenu
->menu();
1334 menu
= new QMenu(this);
1335 hamburgerMenu
->setMenu(menu
);
1336 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("basic_actions"))->menu());
1337 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("zoom"))->menu());
1341 const QList
<QAction
*> toolbarActions
= toolBar()->actions();
1343 if (!toolBar()->isVisible()) {
1344 // If neither the menu bar nor the toolbar are visible, these actions should be available.
1345 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)));
1346 menu
->addAction(toolBarMenuAction());
1347 menu
->addSeparator();
1350 // This group of actions (until the next separator) contains all the most basic actions
1351 // necessary to use Dolphin effectively.
1352 menu
->addAction(ac
->action(QStringLiteral("go_back")));
1353 menu
->addAction(ac
->action(QStringLiteral("go_forward")));
1355 menu
->addMenu(m_newFileMenu
->menu());
1356 if (!toolBar()->isVisible() || !toolbarActions
.contains(ac
->action(QStringLiteral("toggle_selection_mode_tool_bar")))) {
1357 menu
->addAction(ac
->action(QStringLiteral("toggle_selection_mode")));
1359 menu
->addAction(ac
->action(QStringLiteral("basic_actions")));
1360 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Undo
)));
1361 if (!toolBar()->isVisible()
1362 || (!toolbarActions
.contains(ac
->action(QStringLiteral("toggle_search")))
1363 && !toolbarActions
.contains(ac
->action(QStringLiteral("open_preferred_search_tool"))))) {
1364 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Find
)));
1365 // This way a search action will only be added if none of the three available
1366 // search actions is present on the toolbar.
1368 if (!toolBar()->isVisible() || !toolbarActions
.contains(ac
->action(QStringLiteral("toggle_filter")))) {
1369 menu
->addAction(ac
->action(QStringLiteral("show_filter_bar")));
1370 // This way a filter action will only be added if none of the two available
1371 // filter actions is present on the toolbar.
1373 menu
->addSeparator();
1375 // The second group of actions (up until the next separator) contains actions for opening
1376 // additional views to interact with the file system.
1377 menu
->addAction(ac
->action(QStringLiteral("file_new")));
1378 menu
->addAction(ac
->action(QStringLiteral("new_tab")));
1379 if (ac
->action(QStringLiteral("undo_close_tab"))->isEnabled()) {
1380 menu
->addAction(ac
->action(QStringLiteral("closed_tabs")));
1382 menu
->addAction(ac
->action(QStringLiteral("open_terminal")));
1383 menu
->addSeparator();
1385 // The third group contains actions to change what one sees in the view
1386 // and to change the more general UI.
1387 if (!toolBar()->isVisible()
1388 || (!toolbarActions
.contains(ac
->action(QStringLiteral("icons"))) && !toolbarActions
.contains(ac
->action(QStringLiteral("compact")))
1389 && !toolbarActions
.contains(ac
->action(QStringLiteral("details"))) && !toolbarActions
.contains(ac
->action(QStringLiteral("view_mode"))))) {
1390 menu
->addAction(ac
->action(QStringLiteral("view_mode")));
1392 menu
->addAction(ac
->action(QStringLiteral("show_hidden_files")));
1393 menu
->addAction(ac
->action(QStringLiteral("sort")));
1394 menu
->addAction(ac
->action(QStringLiteral("additional_info")));
1395 if (!GeneralSettings::showStatusBar() || !GeneralSettings::showZoomSlider()) {
1396 menu
->addAction(ac
->action(QStringLiteral("zoom")));
1398 menu
->addAction(ac
->action(QStringLiteral("panels")));
1400 // The "Configure" menu is not added to the actionCollection() because there is hardly
1401 // a good reason for users to put it on their toolbar.
1402 auto configureMenu
= menu
->addMenu(QIcon::fromTheme(QStringLiteral("configure")), i18nc("@action:inmenu menu for configure actions", "Configure"));
1403 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
)));
1404 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)));
1405 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)));
1406 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Preferences
)));
1407 hamburgerMenu
->hideActionsOf(configureMenu
);
1410 void DolphinMainWindow::slotPlaceActivated(const QUrl
&url
)
1412 DolphinViewContainer
*view
= activeViewContainer();
1414 if (view
->url() == url
) {
1415 view
->clearFilterBar(); // Fixes bug 259382.
1417 // We can end up here if the user clicked a device in the Places Panel
1418 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
1421 view
->disableUrlNavigatorSelectionRequests();
1423 view
->enableUrlNavigatorSelectionRequests();
1427 void DolphinMainWindow::closedTabsCountChanged(unsigned int count
)
1429 actionCollection()->action(QStringLiteral("undo_close_tab"))->setEnabled(count
> 0);
1432 void DolphinMainWindow::activeViewChanged(DolphinViewContainer
*viewContainer
)
1434 DolphinViewContainer
*oldViewContainer
= m_activeViewContainer
;
1435 Q_ASSERT(viewContainer
);
1437 m_activeViewContainer
= viewContainer
;
1439 if (oldViewContainer
) {
1440 const QAction
*toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
1441 toggleSearchAction
->disconnect(oldViewContainer
);
1443 // Disconnect all signals between the old view container (container,
1444 // view and url navigator) and main window.
1445 oldViewContainer
->disconnect(this);
1446 oldViewContainer
->view()->disconnect(this);
1447 oldViewContainer
->urlNavigatorInternalWithHistory()->disconnect(this);
1448 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
1449 navigators
->primaryUrlNavigator()->disconnect(this);
1450 if (auto secondaryUrlNavigator
= navigators
->secondaryUrlNavigator()) {
1451 secondaryUrlNavigator
->disconnect(this);
1454 // except the requestItemInfo so that on hover the information panel can still be updated
1455 connect(oldViewContainer
->view(), &DolphinView::requestItemInfo
, this, &DolphinMainWindow::requestItemInfo
);
1457 // Disconnect other slots.
1458 disconnect(oldViewContainer
,
1459 &DolphinViewContainer::selectionModeChanged
,
1460 actionCollection()->action(QStringLiteral("toggle_selection_mode")),
1461 &QAction::setChecked
);
1464 connectViewSignals(viewContainer
);
1466 m_actionHandler
->setCurrentView(viewContainer
->view());
1469 updateFileAndEditActions();
1470 updatePasteAction();
1471 updateViewActions();
1473 updateSearchAction();
1475 const QUrl url
= viewContainer
->url();
1476 Q_EMIT
urlChanged(url
);
1479 void DolphinMainWindow::tabCountChanged(int count
)
1481 const bool enableTabActions
= (count
> 1);
1482 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1483 actionCollection()->action(QStringLiteral("activate_tab_%1").arg(i
))->setEnabled(enableTabActions
);
1485 actionCollection()->action(QStringLiteral("activate_last_tab"))->setEnabled(enableTabActions
);
1486 actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions
);
1487 actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions
);
1490 void DolphinMainWindow::updateWindowTitle()
1492 const QString newTitle
= m_activeViewContainer
->captionWindowTitle();
1493 if (windowTitle() != newTitle
) {
1494 setWindowTitle(newTitle
);
1498 void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString
&mountPath
)
1500 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1501 setViewsToHomeIfMountPathOpen(mountPath
);
1504 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectoryIsChildOf(mountPath
)) {
1505 m_tearDownFromPlacesRequested
= true;
1506 m_terminalPanel
->goHome();
1507 // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged
1509 m_placesPanel
->proceedWithTearDown();
1513 void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString
&mountPath
)
1515 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1516 setViewsToHomeIfMountPathOpen(mountPath
);
1519 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectoryIsChildOf(mountPath
)) {
1520 m_tearDownFromPlacesRequested
= false;
1521 m_terminalPanel
->goHome();
1525 void DolphinMainWindow::slotKeyBindings()
1527 KShortcutsDialog
dialog(KShortcutsEditor::AllActions
, KShortcutsEditor::LetterShortcutsAllowed
, this);
1528 dialog
.addCollection(actionCollection());
1529 if (m_terminalPanel
) {
1530 KActionCollection
*konsolePartActionCollection
= m_terminalPanel
->actionCollection();
1531 if (konsolePartActionCollection
) {
1532 dialog
.addCollection(konsolePartActionCollection
, QStringLiteral("KonsolePart"));
1538 void DolphinMainWindow::setViewsToHomeIfMountPathOpen(const QString
&mountPath
)
1540 const QVector
<DolphinViewContainer
*> theViewContainers
= viewContainers();
1541 for (DolphinViewContainer
*viewContainer
: theViewContainers
) {
1542 if (viewContainer
&& viewContainer
->url().toLocalFile().startsWith(mountPath
)) {
1543 viewContainer
->setUrl(QUrl::fromLocalFile(QDir::homePath()));
1546 disconnect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, nullptr, nullptr);
1549 void DolphinMainWindow::setupActions()
1551 auto hamburgerMenuAction
= KStandardAction::hamburgerMenu(nullptr, nullptr, actionCollection());
1553 // setup 'File' menu
1554 m_newFileMenu
= new DolphinNewFileMenu(actionCollection(), this);
1555 QMenu
*menu
= m_newFileMenu
->menu();
1556 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1557 menu
->setIcon(QIcon::fromTheme(QStringLiteral("list-add")));
1558 m_newFileMenu
->setPopupMode(QToolButton::InstantPopup
);
1559 connect(menu
, &QMenu::aboutToShow
, this, &DolphinMainWindow::updateNewMenu
);
1561 QAction
*newWindow
= KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow
, actionCollection());
1562 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1563 newWindow
->setToolTip(i18nc("@info", "Open a new Dolphin window"));
1564 newWindow
->setWhatsThis(xi18nc("@info:whatsthis",
1566 "window just like this one with the current location and view."
1567 "<nl/>You can drag and drop items between windows."));
1568 newWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1570 QAction
*newTab
= actionCollection()->addAction(QStringLiteral("new_tab"));
1571 newTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1572 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1573 newTab
->setWhatsThis(xi18nc("@info:whatsthis",
1575 "<emphasis>Tab</emphasis> with the current location and view.<nl/>"
1576 "A tab is an additional view within this window. "
1577 "You can drag and drop items between tabs."));
1578 actionCollection()->setDefaultShortcuts(newTab
, {Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
});
1579 connect(newTab
, &QAction::triggered
, this, &DolphinMainWindow::openNewActivatedTab
);
1581 QAction
*addToPlaces
= actionCollection()->addAction(QStringLiteral("add_to_places"));
1582 addToPlaces
->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new")));
1583 addToPlaces
->setText(i18nc("@action:inmenu Add current folder to places", "Add to Places"));
1584 addToPlaces
->setWhatsThis(xi18nc("@info:whatsthis",
1585 "This adds the selected folder "
1586 "to the Places panel."));
1587 connect(addToPlaces
, &QAction::triggered
, this, &DolphinMainWindow::addToPlaces
);
1589 QAction
*closeTab
= KStandardAction::close(m_tabWidget
, QOverload
<>::of(&DolphinTabWidget::closeTab
), actionCollection());
1590 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1591 closeTab
->setWhatsThis(i18nc("@info:whatsthis",
1593 "currently viewed tab. If no more tabs are left this window "
1594 "will close instead."));
1596 QAction
*quitAction
= KStandardAction::quit(this, &DolphinMainWindow::quit
, actionCollection());
1597 quitAction
->setWhatsThis(i18nc("@info:whatsthis quit", "This closes this window."));
1599 // setup 'Edit' menu
1600 KStandardAction::undo(this, &DolphinMainWindow::undo
, actionCollection());
1602 // i18n: This will be the last paragraph for the whatsthis for all three:
1603 // Cut, Copy and Paste
1604 const QString cutCopyPastePara
= xi18nc("@info:whatsthis",
1605 "<para><emphasis>Cut, "
1606 "Copy</emphasis> and <emphasis>Paste</emphasis> work between many "
1607 "applications and are among the most used commands. That's why their "
1608 "<emphasis>keyboard shortcuts</emphasis> are prominently placed right "
1609 "next to each other on the keyboard: <shortcut>Ctrl+X</shortcut>, "
1610 "<shortcut>Ctrl+C</shortcut> and <shortcut>Ctrl+V</shortcut>.</para>");
1611 QAction
*cutAction
= KStandardAction::cut(this, &DolphinMainWindow::cut
, actionCollection());
1612 m_actionTextHelper
->registerTextWhenNothingIsSelected(cutAction
, i18nc("@action", "Cut…"));
1613 cutAction
->setWhatsThis(xi18nc("@info:whatsthis cut",
1614 "This copies the items "
1615 "in your current selection to the <emphasis>clipboard</emphasis>.<nl/>"
1616 "Use the <emphasis>Paste</emphasis> action afterwards to copy them from "
1617 "the clipboard to a new location. The items will be removed from their "
1618 "initial location.")
1619 + cutCopyPastePara
);
1620 QAction
*copyAction
= KStandardAction::copy(this, &DolphinMainWindow::copy
, actionCollection());
1621 m_actionTextHelper
->registerTextWhenNothingIsSelected(copyAction
, i18nc("@action", "Copy…"));
1622 copyAction
->setWhatsThis(xi18nc("@info:whatsthis copy",
1624 "items in your current selection to the <emphasis>clipboard</emphasis>."
1625 "<nl/>Use the <emphasis>Paste</emphasis> action afterwards to copy them "
1626 "from the clipboard to a new location.")
1627 + cutCopyPastePara
);
1628 QAction
*paste
= KStandardAction::paste(this, &DolphinMainWindow::paste
, actionCollection());
1629 // The text of the paste-action is modified dynamically by Dolphin
1630 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1631 // due to the long text, the text "Paste" is used:
1632 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1633 paste
->setWhatsThis(xi18nc("@info:whatsthis paste",
1634 "This copies the items from "
1635 "your <emphasis>clipboard</emphasis> to the currently viewed folder.<nl/>"
1636 "If the items were added to the clipboard by the <emphasis>Cut</emphasis> "
1637 "action they are removed from their old location.")
1638 + cutCopyPastePara
);
1640 QAction
*copyToOtherViewAction
= actionCollection()->addAction(QStringLiteral("copy_to_inactive_split_view"));
1641 copyToOtherViewAction
->setText(i18nc("@action:inmenu", "Copy to Other View"));
1642 m_actionTextHelper
->registerTextWhenNothingIsSelected(copyToOtherViewAction
, i18nc("@action:inmenu", "Copy to Other View…"));
1643 copyToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Copy",
1644 "This copies the selected items from "
1645 "the <emphasis>active</emphasis> view to the inactive split view."));
1646 copyToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
1647 copyToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Copy to Inactive Split View"));
1648 actionCollection()->setDefaultShortcut(copyToOtherViewAction
, Qt::SHIFT
| Qt::Key_F5
);
1649 connect(copyToOtherViewAction
, &QAction::triggered
, this, &DolphinMainWindow::copyToInactiveSplitView
);
1651 QAction
*moveToOtherViewAction
= actionCollection()->addAction(QStringLiteral("move_to_inactive_split_view"));
1652 moveToOtherViewAction
->setText(i18nc("@action:inmenu", "Move to Other View"));
1653 m_actionTextHelper
->registerTextWhenNothingIsSelected(moveToOtherViewAction
, i18nc("@action:inmenu", "Move to Other View…"));
1654 moveToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Move",
1655 "This moves the selected items from "
1656 "the <emphasis>active</emphasis> view to the inactive split view."));
1657 moveToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-cut")));
1658 moveToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Move to Inactive Split View"));
1659 actionCollection()->setDefaultShortcut(moveToOtherViewAction
, Qt::SHIFT
| Qt::Key_F6
);
1660 connect(moveToOtherViewAction
, &QAction::triggered
, this, &DolphinMainWindow::moveToInactiveSplitView
);
1662 QAction
*showFilterBar
= actionCollection()->addAction(QStringLiteral("show_filter_bar"));
1663 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Filter..."));
1664 showFilterBar
->setToolTip(i18nc("@info:tooltip", "Show Filter Bar"));
1665 showFilterBar
->setWhatsThis(xi18nc("@info:whatsthis",
1667 "<emphasis>Filter Bar</emphasis> at the bottom of the window.<nl/> "
1668 "There you can enter a text to filter the files and folders currently displayed. "
1669 "Only those that contain the text in their name will be kept in view."));
1670 showFilterBar
->setIcon(QIcon::fromTheme(QStringLiteral("view-filter")));
1671 actionCollection()->setDefaultShortcuts(showFilterBar
, {Qt::CTRL
| Qt::Key_I
, Qt::Key_Slash
});
1672 connect(showFilterBar
, &QAction::triggered
, this, &DolphinMainWindow::showFilterBar
);
1674 // toggle_filter acts as a copy of the main showFilterBar to be used mainly
1675 // in the toolbar, with no default shortcut attached, to avoid messing with
1676 // existing workflows (filter bar always open and Ctrl-I to focus)
1677 QAction
*toggleFilter
= actionCollection()->addAction(QStringLiteral("toggle_filter"));
1678 toggleFilter
->setText(i18nc("@action:inmenu", "Toggle Filter Bar"));
1679 toggleFilter
->setIconText(i18nc("@action:intoolbar", "Filter"));
1680 toggleFilter
->setIcon(showFilterBar
->icon());
1681 toggleFilter
->setToolTip(showFilterBar
->toolTip());
1682 toggleFilter
->setWhatsThis(showFilterBar
->whatsThis());
1683 toggleFilter
->setCheckable(true);
1684 connect(toggleFilter
, &QAction::triggered
, this, &DolphinMainWindow::toggleFilterBar
);
1686 QAction
*searchAction
= KStandardAction::find(this, &DolphinMainWindow::find
, actionCollection());
1687 searchAction
->setText(i18n("Search..."));
1688 searchAction
->setToolTip(i18nc("@info:tooltip", "Search for files and folders"));
1689 searchAction
->setWhatsThis(xi18nc("@info:whatsthis find",
1690 "<para>This helps you "
1691 "find files and folders by opening a <emphasis>find bar</emphasis>. "
1692 "There you can enter search terms and specify settings to find the "
1693 "objects you are looking for.</para><para>Use this help again on "
1694 "the find bar so we can have a look at it while the settings are "
1695 "explained.</para>"));
1697 // toggle_search acts as a copy of the main searchAction to be used mainly
1698 // in the toolbar, with no default shortcut attached, to avoid messing with
1699 // existing workflows (search bar always open and Ctrl-F to focus)
1700 QAction
*toggleSearchAction
= actionCollection()->addAction(QStringLiteral("toggle_search"));
1701 toggleSearchAction
->setText(i18nc("@action:inmenu", "Toggle Search Bar"));
1702 toggleSearchAction
->setIconText(i18nc("@action:intoolbar", "Search"));
1703 toggleSearchAction
->setIcon(searchAction
->icon());
1704 toggleSearchAction
->setToolTip(searchAction
->toolTip());
1705 toggleSearchAction
->setWhatsThis(searchAction
->whatsThis());
1706 toggleSearchAction
->setCheckable(true);
1708 QAction
*toggleSelectionModeAction
= actionCollection()->addAction(QStringLiteral("toggle_selection_mode"));
1709 // i18n: This action toggles a selection mode.
1710 toggleSelectionModeAction
->setText(i18nc("@action:inmenu", "Select Files and Folders"));
1711 // i18n: Opens a selection mode for selecting files/folders.
1712 // The text is kept so unspecific because it will be shown on the toolbar where space is at a premium.
1713 toggleSelectionModeAction
->setIconText(i18nc("@action:intoolbar", "Select"));
1714 toggleSelectionModeAction
->setWhatsThis(xi18nc(
1716 "<para>This application only knows which files or folders should be acted on if they are"
1717 " <emphasis>selected</emphasis> first. Press this to toggle a <emphasis>Selection Mode</emphasis> which makes selecting and deselecting as easy as "
1718 "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."
1720 toggleSelectionModeAction
->setIcon(QIcon::fromTheme(QStringLiteral("quickwizard")));
1721 toggleSelectionModeAction
->setCheckable(true);
1722 actionCollection()->setDefaultShortcut(toggleSelectionModeAction
, Qt::Key_Space
);
1723 connect(toggleSelectionModeAction
, &QAction::triggered
, this, &DolphinMainWindow::toggleSelectionMode
);
1725 // A special version of the toggleSelectionModeAction for the toolbar that also contains a menu
1726 // with the selectAllAction and invertSelectionAction.
1727 auto *toggleSelectionModeToolBarAction
=
1728 new KToolBarPopupAction(toggleSelectionModeAction
->icon(), toggleSelectionModeAction
->iconText(), actionCollection());
1729 toggleSelectionModeToolBarAction
->setToolTip(toggleSelectionModeAction
->text());
1730 toggleSelectionModeToolBarAction
->setWhatsThis(toggleSelectionModeAction
->whatsThis());
1731 actionCollection()->addAction(QStringLiteral("toggle_selection_mode_tool_bar"), toggleSelectionModeToolBarAction
);
1732 toggleSelectionModeToolBarAction
->setCheckable(true);
1733 toggleSelectionModeToolBarAction
->setPopupMode(QToolButton::DelayedPopup
);
1734 connect(toggleSelectionModeToolBarAction
, &QAction::triggered
, toggleSelectionModeAction
, &QAction::trigger
);
1735 connect(toggleSelectionModeAction
, &QAction::toggled
, toggleSelectionModeToolBarAction
, &QAction::setChecked
);
1737 QAction
*selectAllAction
= KStandardAction::selectAll(this, &DolphinMainWindow::selectAll
, actionCollection());
1738 selectAllAction
->setWhatsThis(xi18nc("@info:whatsthis",
1740 "files and folders in the current location."));
1742 QAction
*invertSelection
= actionCollection()->addAction(QStringLiteral("invert_selection"));
1743 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1744 invertSelection
->setWhatsThis(xi18nc("@info:whatsthis invert",
1746 "objects that you have currently <emphasis>not</emphasis> selected instead."));
1747 invertSelection
->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-invert")));
1748 actionCollection()->setDefaultShortcut(invertSelection
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1749 connect(invertSelection
, &QAction::triggered
, this, &DolphinMainWindow::invertSelection
);
1751 QMenu
*toggleSelectionModeActionMenu
= new QMenu(this);
1752 toggleSelectionModeActionMenu
->addAction(selectAllAction
);
1753 toggleSelectionModeActionMenu
->addAction(invertSelection
);
1754 toggleSelectionModeToolBarAction
->setMenu(toggleSelectionModeActionMenu
);
1756 // setup 'View' menu
1757 // (note that most of it is set up in DolphinViewActionHandler)
1759 QAction
*split
= actionCollection()->addAction(QStringLiteral("split_view"));
1760 split
->setWhatsThis(xi18nc("@info:whatsthis find",
1761 "<para>This splits "
1762 "the folder view below into two autonomous views.</para><para>This "
1763 "way you can see two locations at once and move items between them "
1764 "quickly.</para>Click this again afterwards to recombine the views."));
1765 actionCollection()->setDefaultShortcut(split
, Qt::Key_F3
);
1766 connect(split
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitView
);
1768 QAction
*stashSplit
= actionCollection()->addAction(QStringLiteral("split_stash"));
1769 actionCollection()->setDefaultShortcut(stashSplit
, Qt::CTRL
| Qt::Key_S
);
1770 stashSplit
->setText(i18nc("@action:intoolbar Stash", "Stash"));
1771 stashSplit
->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
1772 stashSplit
->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
1773 stashSplit
->setCheckable(false);
1774 QDBusConnectionInterface
*sessionInterface
= QDBusConnection::sessionBus().interface();
1775 stashSplit
->setVisible(sessionInterface
&& sessionInterface
->isServiceRegistered(QStringLiteral("org.kde.kio.StashNotifier")));
1776 connect(stashSplit
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitStash
);
1778 KStandardAction::redisplay(this, &DolphinMainWindow::reloadView
, actionCollection());
1780 QAction
*stop
= actionCollection()->addAction(QStringLiteral("stop"));
1781 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1782 stop
->setToolTip(i18nc("@info", "Stop loading"));
1783 stop
->setWhatsThis(i18nc("@info", "This stops the loading of the contents of the current folder."));
1784 stop
->setIcon(QIcon::fromTheme(QStringLiteral("process-stop")));
1785 connect(stop
, &QAction::triggered
, this, &DolphinMainWindow::stopLoading
);
1787 KToggleAction
*editableLocation
= actionCollection()->add
<KToggleAction
>(QStringLiteral("editable_location"));
1788 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1789 editableLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1790 "This toggles the <emphasis>Location Bar</emphasis> to be "
1791 "editable so you can directly enter a location you want to go to.<nl/>"
1792 "You can also switch to editing by clicking to the right of the "
1793 "location and switch back by confirming the edited location."));
1794 actionCollection()->setDefaultShortcut(editableLocation
, Qt::Key_F6
);
1795 connect(editableLocation
, &KToggleAction::triggered
, this, &DolphinMainWindow::toggleEditLocation
);
1797 QAction
*replaceLocation
= actionCollection()->addAction(QStringLiteral("replace_location"));
1798 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1799 // i18n: "enter" is used both in the meaning of "writing" and "going to" a new location here.
1800 // Both meanings are useful but not necessary to understand the use of "Replace Location".
1801 // So you might want to be more verbose in your language to convey the meaning but it's up to you.
1802 replaceLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1803 "This switches to editing the location and selects it "
1804 "so you can quickly enter a different location."));
1805 actionCollection()->setDefaultShortcut(replaceLocation
, Qt::CTRL
| Qt::Key_L
);
1806 connect(replaceLocation
, &QAction::triggered
, this, &DolphinMainWindow::replaceLocation
);
1810 QScopedPointer
<QAction
> backAction(KStandardAction::back(nullptr, nullptr, nullptr));
1811 m_backAction
= new KToolBarPopupAction(backAction
->icon(), backAction
->text(), actionCollection());
1812 m_backAction
->setObjectName(backAction
->objectName());
1813 m_backAction
->setShortcuts(backAction
->shortcuts());
1815 m_backAction
->setPopupMode(QToolButton::DelayedPopup
);
1816 connect(m_backAction
, &QAction::triggered
, this, &DolphinMainWindow::goBack
);
1817 connect(m_backAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowBackPopupMenu
);
1818 connect(m_backAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoBack
);
1819 actionCollection()->addAction(m_backAction
->objectName(), m_backAction
);
1821 auto backShortcuts
= m_backAction
->shortcuts();
1822 // Prepend this shortcut, to avoid being hidden by the two-slot UI (#371130)
1823 backShortcuts
.prepend(QKeySequence(Qt::Key_Backspace
));
1824 actionCollection()->setDefaultShortcuts(m_backAction
, backShortcuts
);
1826 DolphinRecentTabsMenu
*recentTabsMenu
= new DolphinRecentTabsMenu(this);
1827 actionCollection()->addAction(QStringLiteral("closed_tabs"), recentTabsMenu
);
1828 connect(m_tabWidget
, &DolphinTabWidget::rememberClosedTab
, recentTabsMenu
, &DolphinRecentTabsMenu::rememberClosedTab
);
1829 connect(recentTabsMenu
, &DolphinRecentTabsMenu::restoreClosedTab
, m_tabWidget
, &DolphinTabWidget::restoreClosedTab
);
1830 connect(recentTabsMenu
, &DolphinRecentTabsMenu::closedTabsCountChanged
, this, &DolphinMainWindow::closedTabsCountChanged
);
1832 QAction
*undoCloseTab
= actionCollection()->addAction(QStringLiteral("undo_close_tab"));
1833 undoCloseTab
->setText(i18nc("@action:inmenu File", "Undo close tab"));
1834 undoCloseTab
->setWhatsThis(i18nc("@info:whatsthis undo close tab", "This returns you to the previously closed tab."));
1835 actionCollection()->setDefaultShortcut(undoCloseTab
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_T
);
1836 undoCloseTab
->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo")));
1837 undoCloseTab
->setEnabled(false);
1838 connect(undoCloseTab
, &QAction::triggered
, recentTabsMenu
, &DolphinRecentTabsMenu::undoCloseTab
);
1840 auto undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
1841 undoAction
->setWhatsThis(xi18nc("@info:whatsthis",
1843 "the last change you made to files or folders.<nl/>"
1844 "Such changes include <interface>creating, renaming</interface> "
1845 "and <interface>moving</interface> them to a different location "
1846 "or to the <filename>Trash</filename>. <nl/>Changes that can't "
1847 "be undone will ask for your confirmation."));
1848 undoAction
->setEnabled(false); // undo should be disabled by default
1851 QScopedPointer
<QAction
> forwardAction(KStandardAction::forward(nullptr, nullptr, nullptr));
1852 m_forwardAction
= new KToolBarPopupAction(forwardAction
->icon(), forwardAction
->text(), actionCollection());
1853 m_forwardAction
->setObjectName(forwardAction
->objectName());
1854 m_forwardAction
->setShortcuts(forwardAction
->shortcuts());
1856 m_forwardAction
->setPopupMode(QToolButton::DelayedPopup
);
1857 connect(m_forwardAction
, &QAction::triggered
, this, &DolphinMainWindow::goForward
);
1858 connect(m_forwardAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowForwardPopupMenu
);
1859 connect(m_forwardAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoForward
);
1860 actionCollection()->addAction(m_forwardAction
->objectName(), m_forwardAction
);
1861 actionCollection()->setDefaultShortcuts(m_forwardAction
, m_forwardAction
->shortcuts());
1863 // enable middle-click to open in a new tab
1864 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
1865 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotBackForwardActionMiddleClicked
);
1866 m_backAction
->menu()->installEventFilter(middleClickEventFilter
);
1867 m_forwardAction
->menu()->installEventFilter(middleClickEventFilter
);
1868 KStandardAction::up(this, &DolphinMainWindow::goUp
, actionCollection());
1869 QAction
*homeAction
= KStandardAction::home(this, &DolphinMainWindow::goHome
, actionCollection());
1870 homeAction
->setWhatsThis(xi18nc("@info:whatsthis",
1872 "<filename>Home</filename> folder.<nl/>Every user account "
1873 "has their own <filename>Home</filename> that contains their data "
1874 "including folders that contain personal application data."));
1876 // setup 'Tools' menu
1877 QAction
*compareFiles
= actionCollection()->addAction(QStringLiteral("compare_files"));
1878 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1879 compareFiles
->setIcon(QIcon::fromTheme(QStringLiteral("kompare")));
1880 compareFiles
->setEnabled(false);
1881 connect(compareFiles
, &QAction::triggered
, this, &DolphinMainWindow::compareFiles
);
1883 QAction
*openPreferredSearchTool
= actionCollection()->addAction(QStringLiteral("open_preferred_search_tool"));
1884 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1885 openPreferredSearchTool
->setWhatsThis(xi18nc("@info:whatsthis",
1886 "<para>This opens a preferred search tool for the viewed location.</para>"
1887 "<para>Use <emphasis>More Search Tools</emphasis> menu to configure it.</para>"));
1888 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1889 actionCollection()->setDefaultShortcut(openPreferredSearchTool
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F
);
1890 connect(openPreferredSearchTool
, &QAction::triggered
, this, &DolphinMainWindow::openPreferredSearchTool
);
1892 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1893 QAction
*openTerminal
= actionCollection()->addAction(QStringLiteral("open_terminal"));
1894 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1895 openTerminal
->setWhatsThis(xi18nc("@info:whatsthis",
1896 "<para>This opens a <emphasis>terminal</emphasis> application for the viewed location.</para>"
1897 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1898 openTerminal
->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
1899 actionCollection()->setDefaultShortcut(openTerminal
, Qt::SHIFT
| Qt::Key_F4
);
1900 connect(openTerminal
, &QAction::triggered
, this, &DolphinMainWindow::openTerminal
);
1902 QAction
*openTerminalHere
= actionCollection()->addAction(QStringLiteral("open_terminal_here"));
1903 // i18n: "Here" refers to the location(s) of the currently selected item(s) or the currently viewed location if nothing is selected.
1904 openTerminalHere
->setText(i18nc("@action:inmenu Tools", "Open Terminal Here"));
1905 openTerminalHere
->setWhatsThis(xi18nc("@info:whatsthis",
1906 "<para>This opens <emphasis>terminal</emphasis> applications for the selected items' locations.</para>"
1907 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1908 openTerminalHere
->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
1909 actionCollection()->setDefaultShortcut(openTerminalHere
, Qt::SHIFT
| Qt::ALT
| Qt::Key_F4
);
1910 connect(openTerminalHere
, &QAction::triggered
, this, &DolphinMainWindow::openTerminalHere
);
1913 QAction
*focusTerminalPanel
= actionCollection()->addAction(QStringLiteral("focus_terminal_panel"));
1914 focusTerminalPanel
->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
1915 focusTerminalPanel
->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
1916 actionCollection()->setDefaultShortcut(focusTerminalPanel
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F4
);
1917 connect(focusTerminalPanel
, &QAction::triggered
, this, &DolphinMainWindow::focusTerminalPanel
);
1921 // setup 'Bookmarks' menu
1922 KActionMenu
*bookmarkMenu
= new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this);
1923 bookmarkMenu
->setIcon(QIcon::fromTheme(QStringLiteral("bookmarks")));
1924 // Make the toolbar button version work properly on click
1925 bookmarkMenu
->setPopupMode(QToolButton::InstantPopup
);
1926 m_bookmarkHandler
= new DolphinBookmarkHandler(this, actionCollection(), bookmarkMenu
->menu(), this);
1927 actionCollection()->addAction(QStringLiteral("bookmarks"), bookmarkMenu
);
1929 // setup 'Settings' menu
1930 KToggleAction
*showMenuBar
= KStandardAction::showMenubar(nullptr, nullptr, actionCollection());
1931 showMenuBar
->setWhatsThis(xi18nc("@info:whatsthis",
1932 "<para>This switches between having a <emphasis>Menubar</emphasis> "
1933 "and having a <interface>%1</interface> button. Both "
1934 "contain mostly the same actions and configuration options.</para>"
1935 "<para>The Menubar takes up more space but allows for fast and organised access to all "
1936 "actions an application has to offer.</para><para>The <interface>%1</interface> button "
1937 "is simpler and small which makes triggering advanced actions more time consuming.</para>",
1938 hamburgerMenuAction
->text().replace('&', "")));
1939 connect(showMenuBar
,
1940 &KToggleAction::triggered
, // Fixes #286822
1942 &DolphinMainWindow::toggleShowMenuBar
,
1943 Qt::QueuedConnection
);
1945 KToggleAction
*showStatusBar
= KStandardAction::showStatusbar(nullptr, nullptr, actionCollection());
1946 showStatusBar
->setChecked(GeneralSettings::showStatusBar());
1947 connect(GeneralSettings::self(), &GeneralSettings::showStatusBarChanged
, showStatusBar
, &KToggleAction::setChecked
);
1948 connect(showStatusBar
, &KToggleAction::triggered
, this, [this](bool checked
) {
1949 GeneralSettings::setShowStatusBar(checked
);
1953 KStandardAction::keyBindings(this, &DolphinMainWindow::slotKeyBindings
, actionCollection());
1954 KStandardAction::preferences(this, &DolphinMainWindow::editSettings
, actionCollection());
1956 // not in menu actions
1957 QList
<QKeySequence
> nextTabKeys
= KStandardShortcut::tabNext();
1958 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
1960 QList
<QKeySequence
> prevTabKeys
= KStandardShortcut::tabPrev();
1961 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
1963 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1964 QAction
*activateTab
= actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i
));
1965 activateTab
->setText(i18nc("@action:inmenu", "Activate Tab %1", i
+ 1));
1966 activateTab
->setEnabled(false);
1967 connect(activateTab
, &QAction::triggered
, this, [this, i
]() {
1968 m_tabWidget
->activateTab(i
);
1971 // only add default shortcuts for the first 9 tabs regardless of MaxActivateTabShortcuts
1973 actionCollection()->setDefaultShortcut(activateTab
, QStringLiteral("Alt+%1").arg(i
+ 1));
1977 QAction
*activateLastTab
= actionCollection()->addAction(QStringLiteral("activate_last_tab"));
1978 activateLastTab
->setText(i18nc("@action:inmenu", "Activate Last Tab"));
1979 activateLastTab
->setEnabled(false);
1980 connect(activateLastTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateLastTab
);
1981 actionCollection()->setDefaultShortcut(activateLastTab
, Qt::ALT
| Qt::Key_0
);
1983 QAction
*activateNextTab
= actionCollection()->addAction(QStringLiteral("activate_next_tab"));
1984 activateNextTab
->setIconText(i18nc("@action:inmenu", "Next Tab"));
1985 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1986 activateNextTab
->setEnabled(false);
1987 connect(activateNextTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateNextTab
);
1988 actionCollection()->setDefaultShortcuts(activateNextTab
, nextTabKeys
);
1990 QAction
*activatePrevTab
= actionCollection()->addAction(QStringLiteral("activate_prev_tab"));
1991 activatePrevTab
->setIconText(i18nc("@action:inmenu", "Previous Tab"));
1992 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1993 activatePrevTab
->setEnabled(false);
1994 connect(activatePrevTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activatePrevTab
);
1995 actionCollection()->setDefaultShortcuts(activatePrevTab
, prevTabKeys
);
1998 QAction
*showTarget
= actionCollection()->addAction(QStringLiteral("show_target"));
1999 showTarget
->setText(i18nc("@action:inmenu", "Show Target"));
2000 showTarget
->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
2001 showTarget
->setEnabled(false);
2002 connect(showTarget
, &QAction::triggered
, this, &DolphinMainWindow::showTarget
);
2004 QAction
*openInNewTab
= actionCollection()->addAction(QStringLiteral("open_in_new_tab"));
2005 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
2006 openInNewTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
2007 connect(openInNewTab
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
2009 QAction
*openInNewTabs
= actionCollection()->addAction(QStringLiteral("open_in_new_tabs"));
2010 openInNewTabs
->setText(i18nc("@action:inmenu", "Open in New Tabs"));
2011 openInNewTabs
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
2012 connect(openInNewTabs
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
2014 QAction
*openInNewWindow
= actionCollection()->addAction(QStringLiteral("open_in_new_window"));
2015 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
2016 openInNewWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
2017 connect(openInNewWindow
, &QAction::triggered
, this, &DolphinMainWindow::openInNewWindow
);
2020 void DolphinMainWindow::setupDockWidgets()
2022 const bool lock
= GeneralSettings::lockPanels();
2024 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(lock
);
2026 KDualAction
*lockLayoutAction
= actionCollection()->add
<KDualAction
>(QStringLiteral("lock_panels"));
2027 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
2028 lockLayoutAction
->setActiveIcon(QIcon::fromTheme(QStringLiteral("object-unlocked")));
2029 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
2030 lockLayoutAction
->setInactiveIcon(QIcon::fromTheme(QStringLiteral("object-locked")));
2031 lockLayoutAction
->setWhatsThis(xi18nc("@info:whatsthis",
2033 "switches between having panels <emphasis>locked</emphasis> or "
2034 "<emphasis>unlocked</emphasis>.<nl/>Unlocked panels can be "
2035 "dragged to the other side of the window and have a close "
2036 "button.<nl/>Locked panels are embedded more cleanly."));
2037 lockLayoutAction
->setActive(lock
);
2038 connect(lockLayoutAction
, &KDualAction::triggered
, this, &DolphinMainWindow::togglePanelLockState
);
2040 // Setup "Information"
2041 DolphinDockWidget
*infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
2042 infoDock
->setLocked(lock
);
2043 infoDock
->setObjectName(QStringLiteral("infoDock"));
2044 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2047 InformationPanel
*infoPanel
= new InformationPanel(infoDock
);
2048 infoPanel
->setCustomContextMenuActions({lockLayoutAction
});
2049 connect(infoPanel
, &InformationPanel::urlActivated
, this, &DolphinMainWindow::handleUrl
);
2050 infoDock
->setWidget(infoPanel
);
2052 QAction
*infoAction
= infoDock
->toggleViewAction();
2053 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-information")), Qt::Key_F11
, infoAction
, QStringLiteral("show_information_panel"));
2055 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
2056 connect(this, &DolphinMainWindow::urlChanged
, infoPanel
, &InformationPanel::setUrl
);
2057 connect(this, &DolphinMainWindow::selectionChanged
, infoPanel
, &InformationPanel::setSelection
);
2058 connect(this, &DolphinMainWindow::requestItemInfo
, infoPanel
, &InformationPanel::requestDelayedItemInfo
);
2059 connect(this, &DolphinMainWindow::fileItemsChanged
, infoPanel
, &InformationPanel::slotFilesItemChanged
);
2062 // i18n: This is the last paragraph for the "What's This"-texts of all four panels.
2063 const QString panelWhatsThis
= xi18nc("@info:whatsthis",
2065 "hide panels like this go to <interface>Menu|Panels</interface> "
2066 "or <interface>View|Panels</interface>.</para>");
2069 ->action(QStringLiteral("show_information_panel"))
2070 ->setWhatsThis(xi18nc("@info:whatsthis",
2071 "<para> This toggles the "
2072 "<emphasis>information</emphasis> panel at the right side of the "
2073 "window.</para><para>The panel provides in-depth information "
2074 "about the items your mouse is hovering over or about the selected "
2075 "items. Otherwise it informs you about the currently viewed folder.<nl/>"
2076 "For single items a preview of their contents is provided.</para>"));
2078 infoDock
->setWhatsThis(xi18nc("@info:whatsthis",
2080 "provides in-depth information about the items your mouse is "
2081 "hovering over or about the selected items. Otherwise it informs "
2082 "you about the currently viewed folder.<nl/>For single items a "
2083 "preview of their contents is provided.</para><para>You can configure "
2084 "which and how details are given here by right-clicking.</para>")
2088 DolphinDockWidget
*foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
2089 foldersDock
->setLocked(lock
);
2090 foldersDock
->setObjectName(QStringLiteral("foldersDock"));
2091 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2092 FoldersPanel
*foldersPanel
= new FoldersPanel(foldersDock
);
2093 foldersPanel
->setCustomContextMenuActions({lockLayoutAction
});
2094 foldersDock
->setWidget(foldersPanel
);
2096 QAction
*foldersAction
= foldersDock
->toggleViewAction();
2097 createPanelAction(QIcon::fromTheme(QStringLiteral("folder")), Qt::Key_F7
, foldersAction
, QStringLiteral("show_folders_panel"));
2099 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
2100 connect(this, &DolphinMainWindow::urlChanged
, foldersPanel
, &FoldersPanel::setUrl
);
2101 connect(foldersPanel
, &FoldersPanel::folderActivated
, this, &DolphinMainWindow::changeUrl
);
2102 connect(foldersPanel
, &FoldersPanel::folderInNewTab
, this, &DolphinMainWindow::openNewTab
);
2103 connect(foldersPanel
, &FoldersPanel::folderInNewActiveTab
, this, &DolphinMainWindow::openNewTabAndActivate
);
2104 connect(foldersPanel
, &FoldersPanel::errorMessage
, this, &DolphinMainWindow::showErrorMessage
);
2107 ->action(QStringLiteral("show_folders_panel"))
2108 ->setWhatsThis(xi18nc("@info:whatsthis",
2110 "<emphasis>folders</emphasis> panel at the left side of the window."
2111 "<nl/><nl/>It shows the folders of the <emphasis>file system"
2112 "</emphasis> in a <emphasis>tree view</emphasis>."));
2113 foldersDock
->setWhatsThis(xi18nc("@info:whatsthis",
2115 "shows the folders of the <emphasis>file system</emphasis> in a "
2116 "<emphasis>tree view</emphasis>.</para><para>Click a folder to go "
2117 "there. Click the arrow to the left of a folder to see its subfolders. "
2118 "This allows quick switching between any folders.</para>")
2123 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
2124 DolphinDockWidget
*terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
2125 terminalDock
->setLocked(lock
);
2126 terminalDock
->setObjectName(QStringLiteral("terminalDock"));
2127 m_terminalPanel
= new TerminalPanel(terminalDock
);
2128 m_terminalPanel
->setCustomContextMenuActions({lockLayoutAction
});
2129 terminalDock
->setWidget(m_terminalPanel
);
2131 connect(m_terminalPanel
, &TerminalPanel::hideTerminalPanel
, terminalDock
, &DolphinDockWidget::hide
);
2132 connect(m_terminalPanel
, &TerminalPanel::changeUrl
, this, &DolphinMainWindow::slotTerminalDirectoryChanged
);
2133 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
, m_terminalPanel
, &TerminalPanel::dockVisibilityChanged
);
2134 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
, this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged
);
2136 QAction
*terminalAction
= terminalDock
->toggleViewAction();
2137 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-scripts")), Qt::Key_F4
, terminalAction
, QStringLiteral("show_terminal_panel"));
2139 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
2140 connect(this, &DolphinMainWindow::urlChanged
, m_terminalPanel
, &TerminalPanel::setUrl
);
2142 if (GeneralSettings::version() < 200) {
2143 terminalDock
->hide();
2147 ->action(QStringLiteral("show_terminal_panel"))
2148 ->setWhatsThis(xi18nc("@info:whatsthis",
2149 "<para>This toggles the "
2150 "<emphasis>terminal</emphasis> panel at the bottom of the window."
2151 "<nl/>The location in the terminal will always match the folder "
2152 "view so you can navigate using either.</para><para>The terminal "
2153 "panel is not needed for basic computer usage but can be useful "
2154 "for advanced tasks. To learn more about terminals use the help "
2155 "in a standalone terminal application like Konsole.</para>"));
2156 terminalDock
->setWhatsThis(xi18nc("@info:whatsthis",
2158 "the <emphasis>terminal</emphasis> panel. It behaves like a "
2159 "normal terminal but will match the location of the folder view "
2160 "so you can navigate using either.</para><para>The terminal panel "
2161 "is not needed for basic computer usage but can be useful for "
2162 "advanced tasks. To learn more about terminals use the help in a "
2163 "standalone terminal application like Konsole.</para>")
2168 if (GeneralSettings::version() < 200) {
2170 foldersDock
->hide();
2174 DolphinDockWidget
*placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
2175 placesDock
->setLocked(lock
);
2176 placesDock
->setObjectName(QStringLiteral("placesDock"));
2177 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2179 m_placesPanel
= new PlacesPanel(placesDock
);
2180 m_placesPanel
->setCustomContextMenuActions({lockLayoutAction
});
2181 placesDock
->setWidget(m_placesPanel
);
2183 QAction
*placesAction
= placesDock
->toggleViewAction();
2184 createPanelAction(QIcon::fromTheme(QStringLiteral("compass")), Qt::Key_F9
, placesAction
, QStringLiteral("show_places_panel"));
2186 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
2187 connect(m_placesPanel
, &PlacesPanel::placeActivated
, this, &DolphinMainWindow::slotPlaceActivated
);
2188 connect(m_placesPanel
, &PlacesPanel::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2189 connect(m_placesPanel
, &PlacesPanel::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2190 connect(m_placesPanel
, &PlacesPanel::newWindowRequested
, this, [this](const QUrl
&url
) {
2191 Dolphin::openNewWindow({url
}, this);
2193 connect(m_placesPanel
, &PlacesPanel::errorMessage
, this, &DolphinMainWindow::showErrorMessage
);
2194 connect(this, &DolphinMainWindow::urlChanged
, m_placesPanel
, &PlacesPanel::setUrl
);
2195 connect(placesDock
, &DolphinDockWidget::visibilityChanged
, &DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged
);
2196 connect(this, &DolphinMainWindow::settingsChanged
, m_placesPanel
, &PlacesPanel::readSettings
);
2197 connect(m_placesPanel
, &PlacesPanel::storageTearDownRequested
, this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested
);
2198 connect(m_placesPanel
, &PlacesPanel::storageTearDownExternallyRequested
, this, &DolphinMainWindow::slotStorageTearDownExternallyRequested
);
2199 DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged(m_placesPanel
->isVisible());
2201 auto actionShowAllPlaces
= new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this);
2202 actionShowAllPlaces
->setCheckable(true);
2203 actionShowAllPlaces
->setDisabled(true);
2204 actionShowAllPlaces
->setWhatsThis(i18nc("@info:whatsthis",
2206 "all places in the places panel that have been hidden. They will "
2207 "appear semi-transparent unless you uncheck their hide property."));
2209 connect(actionShowAllPlaces
, &QAction::triggered
, this, [actionShowAllPlaces
, this](bool checked
) {
2210 m_placesPanel
->setShowAll(checked
);
2212 connect(m_placesPanel
, &PlacesPanel::allPlacesShownChanged
, actionShowAllPlaces
, &QAction::setChecked
);
2215 ->action(QStringLiteral("show_places_panel"))
2216 ->setWhatsThis(xi18nc("@info:whatsthis",
2217 "<para>This toggles the "
2218 "<emphasis>places</emphasis> panel at the left side of the window."
2219 "</para><para>It allows you to go to locations you have "
2220 "bookmarked and to access disk or media attached to the computer "
2221 "or to the network. It also contains sections to find recently "
2222 "saved files or files of a certain type.</para>"));
2223 placesDock
->setWhatsThis(xi18nc("@info:whatsthis",
2224 "<para>This is the "
2225 "<emphasis>Places</emphasis> panel. It allows you to go to locations "
2226 "you have bookmarked and to access disk or media attached to the "
2227 "computer or to the network. It also contains sections to find "
2228 "recently saved files or files of a certain type.</para><para>"
2229 "Click on an entry to go there. Click with the right mouse button "
2230 "instead to open any entry in a new tab or new window.</para>"
2231 "<para>New entries can be added by dragging folders onto this panel. "
2232 "Right-click any section or entry to hide it. Right-click an empty "
2233 "space on this panel and select <interface>Show Hidden Places"
2234 "</interface> to display it again.</para>")
2237 // Add actions into the "Panels" menu
2238 KActionMenu
*panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Show Panels"), this);
2239 actionCollection()->addAction(QStringLiteral("panels"), panelsMenu
);
2240 panelsMenu
->setIcon(QIcon::fromTheme(QStringLiteral("view-sidetree")));
2241 panelsMenu
->setPopupMode(QToolButton::InstantPopup
);
2242 const KActionCollection
*ac
= actionCollection();
2243 panelsMenu
->addAction(ac
->action(QStringLiteral("show_places_panel")));
2245 panelsMenu
->addAction(ac
->action(QStringLiteral("show_information_panel")));
2247 panelsMenu
->addAction(ac
->action(QStringLiteral("show_folders_panel")));
2248 panelsMenu
->addAction(ac
->action(QStringLiteral("show_terminal_panel")));
2249 panelsMenu
->addSeparator();
2250 panelsMenu
->addAction(actionShowAllPlaces
);
2251 panelsMenu
->addAction(lockLayoutAction
);
2253 connect(panelsMenu
->menu(), &QMenu::aboutToShow
, this, [actionShowAllPlaces
, this] {
2254 actionShowAllPlaces
->setEnabled(DolphinPlacesModelSingleton::instance().placesModel()->hiddenCount());
2258 void DolphinMainWindow::updateFileAndEditActions()
2260 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
2261 const KActionCollection
*col
= actionCollection();
2262 KFileItemListProperties
capabilitiesSource(list
);
2264 QAction
*renameAction
= col
->action(KStandardAction::name(KStandardAction::RenameFile
));
2265 QAction
*moveToTrashAction
= col
->action(KStandardAction::name(KStandardAction::MoveToTrash
));
2266 QAction
*deleteAction
= col
->action(KStandardAction::name(KStandardAction::DeleteFile
));
2267 QAction
*cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
2268 QAction
*duplicateAction
= col
->action(QStringLiteral("duplicate")); // see DolphinViewActionHandler
2269 QAction
*addToPlacesAction
= col
->action(QStringLiteral("add_to_places"));
2270 QAction
*copyToOtherViewAction
= col
->action(QStringLiteral("copy_to_inactive_split_view"));
2271 QAction
*moveToOtherViewAction
= col
->action(QStringLiteral("move_to_inactive_split_view"));
2272 QAction
*copyLocation
= col
->action(QString("copy_location"));
2274 if (list
.isEmpty()) {
2275 stateChanged(QStringLiteral("has_no_selection"));
2277 // All actions that need a selection to function can be enabled because they should trigger selection mode.
2278 renameAction
->setEnabled(true);
2279 moveToTrashAction
->setEnabled(true);
2280 deleteAction
->setEnabled(true);
2281 cutAction
->setEnabled(true);
2282 duplicateAction
->setEnabled(true);
2283 addToPlacesAction
->setEnabled(true);
2284 copyLocation
->setEnabled(true);
2285 // Them triggering selection mode and not directly acting on selected items is signified by adding "…" to their text.
2286 m_actionTextHelper
->textsWhenNothingIsSelectedEnabled(true);
2289 m_actionTextHelper
->textsWhenNothingIsSelectedEnabled(false);
2290 stateChanged(QStringLiteral("has_selection"));
2292 QAction
*deleteWithTrashShortcut
= col
->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
2293 QAction
*showTarget
= col
->action(QStringLiteral("show_target"));
2295 if (list
.length() == 1 && list
.first().isDir()) {
2296 addToPlacesAction
->setEnabled(true);
2298 addToPlacesAction
->setEnabled(false);
2301 const bool enableMoveToTrash
= capabilitiesSource
.isLocal() && capabilitiesSource
.supportsMoving();
2303 renameAction
->setEnabled(capabilitiesSource
.supportsMoving());
2304 moveToTrashAction
->setEnabled(enableMoveToTrash
);
2305 deleteAction
->setEnabled(capabilitiesSource
.supportsDeleting());
2306 deleteWithTrashShortcut
->setEnabled(capabilitiesSource
.supportsDeleting() && !enableMoveToTrash
);
2307 cutAction
->setEnabled(capabilitiesSource
.supportsMoving());
2308 copyLocation
->setEnabled(list
.length() == 1);
2309 showTarget
->setEnabled(list
.length() == 1 && list
.at(0).isLink());
2310 duplicateAction
->setEnabled(capabilitiesSource
.supportsWriting());
2313 if (m_tabWidget
->currentTabPage()->splitViewEnabled() && !list
.isEmpty()) {
2314 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
2315 KFileItem capabilitiesDestination
;
2317 if (tabPage
->primaryViewActive()) {
2318 capabilitiesDestination
= tabPage
->secondaryViewContainer()->rootItem();
2320 capabilitiesDestination
= tabPage
->primaryViewContainer()->rootItem();
2323 const auto destUrl
= capabilitiesDestination
.url();
2324 const bool allNotTargetOrigin
= std::all_of(list
.cbegin(), list
.cend(), [destUrl
](const KFileItem
&item
) {
2325 return item
.url().adjusted(QUrl::RemoveFilename
| QUrl::StripTrailingSlash
) != destUrl
;
2328 copyToOtherViewAction
->setEnabled(capabilitiesDestination
.isWritable() && allNotTargetOrigin
);
2329 moveToOtherViewAction
->setEnabled((list
.isEmpty() || capabilitiesSource
.supportsMoving()) && capabilitiesDestination
.isWritable()
2330 && allNotTargetOrigin
);
2332 copyToOtherViewAction
->setEnabled(false);
2333 moveToOtherViewAction
->setEnabled(false);
2337 void DolphinMainWindow::updateViewActions()
2339 m_actionHandler
->updateViewActions();
2341 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
2342 toggleFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
2344 updateSplitAction();
2347 void DolphinMainWindow::updateGoActions()
2349 QAction
*goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
2350 const QUrl currentUrl
= m_activeViewContainer
->url();
2351 // I think this is one of the best places to firstly be confronted
2352 // with a file system and its hierarchy. Talking about the root
2353 // directory might seem too much here but it is the question that
2354 // naturally arises in this context.
2355 goUpAction
->setWhatsThis(xi18nc("@info:whatsthis",
2357 "the folder that contains the currently viewed one.</para>"
2358 "<para>All files and folders are organized in a hierarchical "
2359 "<emphasis>file system</emphasis>. At the top of this hierarchy is "
2360 "a directory that contains all data connected to this computer"
2361 "—the <emphasis>root directory</emphasis>.</para>"));
2362 goUpAction
->setEnabled(KIO::upUrl(currentUrl
) != currentUrl
);
2365 void DolphinMainWindow::refreshViews()
2367 m_tabWidget
->refreshViews();
2369 if (GeneralSettings::modifiedStartupSettings()) {
2370 updateWindowTitle();
2373 updateSplitAction();
2375 Q_EMIT
settingsChanged();
2378 void DolphinMainWindow::clearStatusBar()
2380 m_activeViewContainer
->statusBar()->resetToDefaultText();
2383 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
*container
)
2385 connect(container
, &DolphinViewContainer::showFilterBarChanged
, this, &DolphinMainWindow::updateFilterBarAction
);
2386 connect(container
, &DolphinViewContainer::writeStateChanged
, this, &DolphinMainWindow::slotWriteStateChanged
);
2387 connect(container
, &DolphinViewContainer::searchModeEnabledChanged
, this, &DolphinMainWindow::updateSearchAction
);
2388 connect(container
, &DolphinViewContainer::captionChanged
, this, &DolphinMainWindow::updateWindowTitle
);
2389 connect(container
, &DolphinViewContainer::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2390 connect(container
, &DolphinViewContainer::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2392 const QAction
*toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
2393 connect(toggleSearchAction
, &QAction::triggered
, container
, &DolphinViewContainer::setSearchModeEnabled
);
2395 // Make the toggled state of the selection mode actions visually follow the selection mode state of the view.
2396 auto toggleSelectionModeAction
= actionCollection()->action(QStringLiteral("toggle_selection_mode"));
2397 toggleSelectionModeAction
->setChecked(m_activeViewContainer
->isSelectionModeEnabled());
2398 connect(m_activeViewContainer
, &DolphinViewContainer::selectionModeChanged
, toggleSelectionModeAction
, &QAction::setChecked
);
2400 const DolphinView
*view
= container
->view();
2401 connect(view
, &DolphinView::selectionChanged
, this, &DolphinMainWindow::slotSelectionChanged
);
2402 connect(view
, &DolphinView::requestItemInfo
, this, &DolphinMainWindow::requestItemInfo
);
2403 connect(view
, &DolphinView::fileItemsChanged
, this, &DolphinMainWindow::fileItemsChanged
);
2404 connect(view
, &DolphinView::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2405 connect(view
, &DolphinView::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2406 connect(view
, &DolphinView::windowRequested
, this, &DolphinMainWindow::openNewWindow
);
2407 connect(view
, &DolphinView::requestContextMenu
, this, &DolphinMainWindow::openContextMenu
);
2408 connect(view
, &DolphinView::directoryLoadingStarted
, this, &DolphinMainWindow::enableStopAction
);
2409 connect(view
, &DolphinView::directoryLoadingCompleted
, this, &DolphinMainWindow::disableStopAction
);
2410 connect(view
, &DolphinView::directoryLoadingCompleted
, this, &DolphinMainWindow::slotDirectoryLoadingCompleted
);
2411 connect(view
, &DolphinView::goBackRequested
, this, &DolphinMainWindow::goBack
);
2412 connect(view
, &DolphinView::goForwardRequested
, this, &DolphinMainWindow::goForward
);
2413 connect(view
, &DolphinView::urlActivated
, this, &DolphinMainWindow::handleUrl
);
2414 connect(view
, &DolphinView::goUpRequested
, this, &DolphinMainWindow::goUp
);
2416 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::urlChanged
, this, &DolphinMainWindow::changeUrl
);
2417 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::historyChanged
, this, &DolphinMainWindow::updateHistory
);
2419 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2420 const KUrlNavigator
*navigator
=
2421 m_tabWidget
->currentTabPage()->primaryViewActive() ? navigators
->primaryUrlNavigator() : navigators
->secondaryUrlNavigator();
2423 QAction
*editableLocactionAction
= actionCollection()->action(QStringLiteral("editable_location"));
2424 editableLocactionAction
->setChecked(navigator
->isUrlEditable());
2425 connect(navigator
, &KUrlNavigator::editableStateChanged
, this, &DolphinMainWindow::slotEditableStateChanged
);
2426 connect(navigator
, &KUrlNavigator::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2427 connect(navigator
, &KUrlNavigator::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2428 connect(navigator
, &KUrlNavigator::newWindowRequested
, this, &DolphinMainWindow::openNewWindow
);
2431 void DolphinMainWindow::updateSplitAction()
2433 QAction
*splitAction
= actionCollection()->action(QStringLiteral("split_view"));
2434 const DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
2435 if (tabPage
->splitViewEnabled()) {
2436 if (GeneralSettings::closeActiveSplitView() ? tabPage
->primaryViewActive() : !tabPage
->primaryViewActive()) {
2437 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2438 splitAction
->setToolTip(i18nc("@info", "Close left view"));
2439 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close")));
2441 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2442 splitAction
->setToolTip(i18nc("@info", "Close right view"));
2443 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close")));
2446 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2447 splitAction
->setToolTip(i18nc("@info", "Split view"));
2448 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
2452 void DolphinMainWindow::updateAllowedToolbarAreas()
2454 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2455 if (toolBar()->actions().contains(navigators
)) {
2456 toolBar()->setAllowedAreas(Qt::TopToolBarArea
| Qt::BottomToolBarArea
);
2457 if (toolBarArea(toolBar()) == Qt::LeftToolBarArea
|| toolBarArea(toolBar()) == Qt::RightToolBarArea
) {
2458 addToolBar(Qt::TopToolBarArea
, toolBar());
2461 toolBar()->setAllowedAreas(Qt::AllToolBarAreas
);
2465 bool DolphinMainWindow::isKompareInstalled() const
2467 static bool initialized
= false;
2468 static bool installed
= false;
2470 // TODO: maybe replace this approach later by using a menu
2471 // plugin like kdiff3plugin.cpp
2472 installed
= !QStandardPaths::findExecutable(QStringLiteral("kompare")).isEmpty();
2478 void DolphinMainWindow::createPanelAction(const QIcon
&icon
, const QKeySequence
&shortcut
, QAction
*dockAction
, const QString
&actionName
)
2480 QAction
*panelAction
= actionCollection()->addAction(actionName
);
2481 panelAction
->setCheckable(true);
2482 panelAction
->setChecked(dockAction
->isChecked());
2483 panelAction
->setText(dockAction
->text());
2484 panelAction
->setIcon(icon
);
2485 dockAction
->setIcon(icon
);
2486 actionCollection()->setDefaultShortcut(panelAction
, shortcut
);
2488 connect(panelAction
, &QAction::triggered
, dockAction
, &QAction::trigger
);
2489 connect(dockAction
, &QAction::toggled
, panelAction
, &QAction::setChecked
);
2492 void DolphinMainWindow::setupWhatsThis()
2495 menuBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2496 "<emphasis>Menubar</emphasis>. It provides access to commands and "
2497 "configuration options. Left-click on any of the menus on this "
2498 "bar to see its contents.</para><para>The Menubar can be hidden "
2499 "by unchecking <interface>Settings|Show Menubar</interface>. Then "
2500 "most of its contents become available through a <interface>Menu"
2501 "</interface> button on the <emphasis>Toolbar</emphasis>.</para>"));
2502 toolBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2503 "<emphasis>Toolbar</emphasis>. It allows quick access to "
2504 "frequently used actions.</para><para>It is highly customizable. "
2505 "All items you see in the <interface>Menu</interface> or "
2506 "in the <interface>Menubar</interface> can be placed on the "
2507 "Toolbar. Just right-click on it and select <interface>Configure "
2508 "Toolbars…</interface> or find this action within the <interface>"
2510 "</para><para>The location of the bar and the style of its "
2511 "buttons can also be changed in the right-click menu. Right-click "
2512 "a button if you want to show or hide its text.</para>"));
2513 m_tabWidget
->setWhatsThis(xi18nc("@info:whatsthis main view",
2514 "<para>Here you can see the <emphasis>folders</emphasis> and "
2515 "<emphasis>files</emphasis> that are at the location described in "
2516 "the <interface>Location Bar</interface> above. This area is the "
2517 "central part of this application where you navigate to the files "
2518 "you want to use.</para><para>For an elaborate and general "
2519 "introduction to this application <link "
2520 "url='https://userbase.kde.org/Dolphin/File_Management#Introduction_to_Dolphin'>"
2521 "click here</link>. This will open an introductory article from "
2522 "the <emphasis>KDE UserBase Wiki</emphasis>.</para><para>For brief "
2523 "explanations of all the features of this <emphasis>view</emphasis> "
2524 "<link url='help:/dolphin/dolphin-view.html'>click here</link> "
2525 "instead. This will open a page from the <emphasis>Handbook"
2526 "</emphasis> that covers the basics.</para>"));
2529 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings
))
2530 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window "
2531 "that lists the <emphasis>keyboard shortcuts</emphasis>.<nl/>"
2532 "There you can set up key combinations to trigger an action when "
2533 "they are pressed simultaneously. All commands in this application can "
2534 "be triggered this way.</para>"));
2535 actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars
))
2536 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window in which "
2537 "you can change which buttons appear on the <emphasis>Toolbar</emphasis>.</para>"
2538 "<para>All items you see in the <interface>Menu</interface> can also be placed on the Toolbar.</para>"));
2539 actionCollection()->action(KStandardAction::name(KStandardAction::Preferences
))
2540 ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window where you can "
2541 "change a multitude of settings for this application. For an explanation "
2542 "of the various settings go to the chapter <emphasis>Configuring Dolphin"
2543 "</emphasis> in <interface>Help|Dolphin Handbook</interface>."));
2547 auto setStandardActionWhatsThis
= [this](KStandardAction::StandardAction actionId
,
2548 const QString
&whatsThis
) {
2549 // Check for the existence of an action since it can be restricted through the Kiosk system
2550 if (auto *action
= actionCollection()->action(KStandardAction::name(actionId
))) {
2551 action
->setWhatsThis(whatsThis
);
2555 // i18n: If the external link isn't available in your language it might make
2556 // sense to state the external link's language in brackets to not
2557 // frustrate the user. If there are multiple languages that the user might
2558 // know with a reasonable chance you might want to have 2 external links.
2559 // The same might be true for any external link you translate.
2560 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>"));
2561 // (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 )
2563 setStandardActionWhatsThis(KStandardAction::WhatsThis
,
2564 xi18nc("@info:whatsthis whatsthis button",
2565 "<para>This is the button that invokes the help feature you are "
2566 "using right now! Click it, then click any component of this "
2567 "application to ask \"What's this?\" about it. The mouse cursor "
2568 "will change appearance if no help is available for a spot.</para>"
2569 "<para>There are two other ways to get help: "
2570 "The <link url='help:/dolphin/index.html'>Dolphin Handbook</link> and "
2571 "the <link url='https://userbase.kde.org/Dolphin/File_Management'>KDE "
2572 "UserBase Wiki</link>.</para><para>The \"What's this?\" help is "
2573 "missing in most other windows so don't get too used to this.</para>"));
2575 setStandardActionWhatsThis(KStandardAction::ReportBug
,
2576 xi18nc("@info:whatsthis","<para>This opens a "
2577 "window that will guide you through reporting errors or flaws "
2578 "in this application or in other KDE software.</para>"
2579 "<para>High-quality bug reports are much appreciated. To learn "
2580 "how to make your bug report as effective as possible "
2581 "<link url='https://community.kde.org/Get_Involved/Bug_Reporting'>"
2582 "click here</link>.</para>"));
2584 setStandardActionWhatsThis(KStandardAction::Donate
,
2585 xi18nc("@info:whatsthis", "<para>This opens a "
2586 "<emphasis>web page</emphasis> where you can donate to "
2587 "support the continued work on this application and many "
2588 "other projects by the <emphasis>KDE</emphasis> community.</para>"
2589 "<para>Donating is the easiest and fastest way to efficiently "
2590 "support KDE and its projects. KDE projects are available for "
2591 "free therefore your donation is needed to cover things that "
2592 "require money like servers, contributor meetings, etc.</para>"
2593 "<para><emphasis>KDE e.V.</emphasis> is the non-profit "
2594 "organization behind the KDE community.</para>"));
2596 setStandardActionWhatsThis(KStandardAction::SwitchApplicationLanguage
,
2597 xi18nc("@info:whatsthis",
2598 "With this you can change the language this application uses."
2599 "<nl/>You can even set secondary languages which will be used "
2600 "if texts are not available in your preferred language."));
2602 setStandardActionWhatsThis(KStandardAction::AboutApp
,
2603 xi18nc("@info:whatsthis","This opens a "
2604 "window that informs you about the version, license, "
2605 "used libraries and maintainers of this application."));
2607 setStandardActionWhatsThis(KStandardAction::AboutKDE
,
2608 xi18nc("@info:whatsthis","This opens a "
2609 "window with information about <emphasis>KDE</emphasis>. "
2610 "The KDE community are the people behind this free software."
2611 "<nl/>If you like using this application but don't know "
2612 "about KDE or want to see a cute dragon have a look!"));
2616 bool DolphinMainWindow::addHamburgerMenuToToolbar()
2618 QDomDocument domDocument
= KXMLGUIClient::domDocument();
2619 if (domDocument
.isNull()) {
2622 QDomNode toolbar
= domDocument
.elementsByTagName(QStringLiteral("ToolBar")).at(0);
2623 if (toolbar
.isNull()) {
2627 QDomElement hamburgerMenuElement
= domDocument
.createElement(QStringLiteral("Action"));
2628 hamburgerMenuElement
.setAttribute(QStringLiteral("name"), QStringLiteral("hamburger_menu"));
2629 toolbar
.appendChild(hamburgerMenuElement
);
2631 KXMLGUIFactory::saveConfigFile(domDocument
, xmlFile());
2635 // Make sure to also remove the <KXMLGUIFactory> and <QDomDocument> include
2636 // whenever this method is removed (maybe in the year ~2026).
2639 // Set a sane initial window size
2640 QSize
DolphinMainWindow::sizeHint() const
2642 return KXmlGuiWindow::sizeHint().expandedTo(QSize(760, 550));
2645 void DolphinMainWindow::saveNewToolbarConfig()
2647 KXmlGuiWindow::saveNewToolbarConfig(); // Applies the new config. This has to be called first
2648 // because the rest of this method decides things
2649 // based on the new config.
2650 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2651 if (!toolBar()->actions().contains(navigators
)) {
2652 m_tabWidget
->currentTabPage()->insertNavigatorsWidget(navigators
);
2654 updateAllowedToolbarAreas();
2655 (static_cast<KHamburgerMenu
*>(actionCollection()->action(KStandardAction::name(KStandardAction::HamburgerMenu
))))->hideActionsOf(toolBar());
2658 void DolphinMainWindow::focusTerminalPanel()
2660 if (m_terminalPanel
->isVisible()) {
2661 if (m_terminalPanel
->terminalHasFocus()) {
2662 m_activeViewContainer
->view()->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2663 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2665 m_terminalPanel
->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2666 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2669 actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger();
2670 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2674 DolphinMainWindow::UndoUiInterface::UndoUiInterface()
2675 : KIO::FileUndoManager::UiInterface()
2679 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2683 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
*job
)
2685 DolphinMainWindow
*mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2687 DolphinViewContainer
*container
= mainWin
->activeViewContainer();
2688 container
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
2690 KIO::FileUndoManager::UiInterface::jobError(job
);
2694 bool DolphinMainWindow::isUrlOpen(const QString
&url
)
2696 return m_tabWidget
->isUrlOpen(QUrl::fromUserInput(url
));
2699 bool DolphinMainWindow::isItemVisibleInAnyView(const QString
&urlOfItem
)
2701 return m_tabWidget
->isItemVisibleInAnyView(QUrl::fromUserInput(urlOfItem
));