2 * SPDX-FileCopyrightText: 2006 Peter Penz <peter.penz19@gmail.com>
3 * SPDX-FileCopyrightText: 2006 Stefan Monov <logixoul@gmail.com>
4 * SPDX-FileCopyrightText: 2006 Cvetoslav Ludmiloff <ludmiloff@gmail.com>
6 * SPDX-License-Identifier: GPL-2.0-or-later
9 #include "dolphinmainwindow.h"
11 #include "dolphinmainwindowadaptor.h"
13 #include "dolphinbookmarkhandler.h"
14 #include "dolphindockwidget.h"
15 #include "dolphincontextmenu.h"
16 #include "dolphinnavigatorswidgetaction.h"
17 #include "dolphinnewfilemenu.h"
18 #include "dolphinrecenttabsmenu.h"
19 #include "dolphinplacesmodelsingleton.h"
20 #include "dolphinurlnavigatorscontroller.h"
21 #include "dolphinviewcontainer.h"
22 #include "dolphintabpage.h"
23 #include "middleclickactioneventfilter.h"
24 #include "panels/folders/folderspanel.h"
25 #include "panels/places/placespanel.h"
26 #include "panels/terminal/terminalpanel.h"
27 #include "selectionmode/actiontexthelper.h"
28 #include "settings/dolphinsettingsdialog.h"
29 #include "statusbar/dolphinstatusbar.h"
30 #include "views/dolphinviewactionhandler.h"
31 #include "views/dolphinremoteencoding.h"
32 #include "views/draganddrophelper.h"
33 #include "views/viewproperties.h"
34 #include "views/dolphinnewfilemenuobserver.h"
35 #include "dolphin_generalsettings.h"
37 #include <KActionCollection>
38 #include <KActionMenu>
39 #include <KAuthorized>
42 #include <KDualAction>
43 #include <KFileItemListProperties>
44 #include <KIO/CommandLauncherJob>
45 #include <KIO/JobUiDelegate>
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 <kio_version.h>
70 #include <QApplication>
72 #include <QCloseEvent>
73 #include <QDesktopServices>
75 #include <QDomDocument>
79 #include <QPushButton>
81 #include <QStandardPaths>
83 #include <QToolButton>
86 // Used for GeneralSettings::version() to determine whether
87 // an updated version of Dolphin is running, so as to migrate
88 // removed/renamed ...etc config entries; increment it in such
90 const int CurrentDolphinVersion
= 202;
91 // The maximum number of entries in the back/forward popup menu
92 const int MaxNumberOfNavigationentries
= 12;
93 // The maximum number of "Activate Tab" shortcuts
94 const int MaxActivateTabShortcuts
= 9;
97 DolphinMainWindow::DolphinMainWindow() :
98 KXmlGuiWindow(nullptr),
99 m_newFileMenu(nullptr),
100 m_tabWidget(nullptr),
101 m_activeViewContainer(nullptr),
102 m_actionHandler(nullptr),
103 m_remoteEncoding(nullptr),
105 m_bookmarkHandler(nullptr),
106 m_lastHandleUrlOpenJob(nullptr),
107 m_terminalPanel(nullptr),
108 m_placesPanel(nullptr),
109 m_tearDownFromPlacesRequested(false),
110 m_backAction(nullptr),
111 m_forwardAction(nullptr)
113 Q_INIT_RESOURCE(dolphin
);
115 new MainWindowAdaptor(this);
118 setWindowFlags(Qt::WindowContextHelpButtonHint
);
120 setComponentName(QStringLiteral("dolphin"), QGuiApplication::applicationDisplayName());
121 setObjectName(QStringLiteral("Dolphin#"));
123 setStateConfigGroup("State");
125 connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::errorMessage
,
126 this, &DolphinMainWindow::showErrorMessage
);
128 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
129 undoManager
->setUiInterface(new UndoUiInterface());
131 connect(undoManager
, &KIO::FileUndoManager::undoAvailable
,
132 this, &DolphinMainWindow::slotUndoAvailable
);
133 connect(undoManager
, &KIO::FileUndoManager::undoTextChanged
,
134 this, &DolphinMainWindow::slotUndoTextChanged
);
135 connect(undoManager
, &KIO::FileUndoManager::jobRecordingStarted
,
136 this, &DolphinMainWindow::clearStatusBar
);
137 connect(undoManager
, &KIO::FileUndoManager::jobRecordingFinished
,
138 this, &DolphinMainWindow::showCommand
);
140 const bool firstRun
= (GeneralSettings::version() < 200);
142 GeneralSettings::setViewPropsTimestamp(QDateTime::currentDateTime());
145 setAcceptDrops(true);
147 auto *navigatorsWidgetAction
= new DolphinNavigatorsWidgetAction(this);
148 actionCollection()->addAction(QStringLiteral("url_navigators"), navigatorsWidgetAction
);
149 m_tabWidget
= new DolphinTabWidget(navigatorsWidgetAction
, this);
150 m_tabWidget
->setObjectName("tabWidget");
151 connect(m_tabWidget
, &DolphinTabWidget::activeViewChanged
,
152 this, &DolphinMainWindow::activeViewChanged
);
153 connect(m_tabWidget
, &DolphinTabWidget::tabCountChanged
,
154 this, &DolphinMainWindow::tabCountChanged
);
155 connect(m_tabWidget
, &DolphinTabWidget::currentUrlChanged
,
156 this, &DolphinMainWindow::updateWindowTitle
);
157 setCentralWidget(m_tabWidget
);
159 m_actionTextHelper
= new SelectionMode::ActionTextHelper(this);
162 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), m_actionTextHelper
, this);
163 connect(m_actionHandler
, &DolphinViewActionHandler::actionBeingHandled
, this, &DolphinMainWindow::clearStatusBar
);
164 connect(m_actionHandler
, &DolphinViewActionHandler::createDirectoryTriggered
, this, &DolphinMainWindow::createDirectory
);
165 connect(m_actionHandler
, &DolphinViewActionHandler::selectionModeChangeTriggered
, this, &DolphinMainWindow::slotSetSelectionMode
);
167 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
168 connect(this, &DolphinMainWindow::urlChanged
,
169 m_remoteEncoding
, &DolphinRemoteEncoding::slotAboutToOpenUrl
);
173 setupGUI(Save
| Create
| ToolBar
);
174 stateChanged(QStringLiteral("new_file"));
176 QClipboard
* clipboard
= QApplication::clipboard();
177 connect(clipboard
, &QClipboard::dataChanged
,
178 this, &DolphinMainWindow::updatePasteAction
);
180 QAction
* toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
181 toggleFilterBarAction
->setChecked(GeneralSettings::filterBar());
184 menuBar()->setVisible(false);
187 const bool showMenu
= !menuBar()->isHidden();
188 QAction
* showMenuBarAction
= actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar
));
189 showMenuBarAction
->setChecked(showMenu
); // workaround for bug #171080
191 auto hamburgerMenu
= static_cast<KHamburgerMenu
*>(actionCollection()->action(
192 KStandardAction::name(KStandardAction::HamburgerMenu
)));
193 hamburgerMenu
->setMenuBar(menuBar());
194 hamburgerMenu
->setShowMenuBarAction(showMenuBarAction
);
195 connect(hamburgerMenu
, &KHamburgerMenu::aboutToShowMenu
,
196 this, &DolphinMainWindow::updateHamburgerMenu
);
197 hamburgerMenu
->hideActionsOf(toolBar());
198 if (GeneralSettings::version() < 201 && !toolBar()->actions().contains(hamburgerMenu
)) {
199 addHamburgerMenuToToolbar();
202 updateAllowedToolbarAreas();
204 // enable middle-click on back/forward/up to open in a new tab
205 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
206 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotToolBarActionMiddleClicked
);
207 toolBar()->installEventFilter(middleClickEventFilter
);
211 connect(KSycoca::self(), &KSycoca::databaseChanged
, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
213 QTimer::singleShot(0, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
215 m_fileItemActions
.setParentWidget(this);
216 connect(&m_fileItemActions
, &KFileItemActions::error
, this, [this](const QString
&errorMessage
) {
217 showErrorMessage(errorMessage
);
220 connect(GeneralSettings::self(), &GeneralSettings::splitViewChanged
,
221 this, &DolphinMainWindow::slotSplitViewChanged
);
224 DolphinMainWindow::~DolphinMainWindow()
226 // This fixes a crash on Wayland when closing the mainwindow while another dialog is open.
227 disconnect(QGuiApplication::clipboard(), &QClipboard::dataChanged
, this, &DolphinMainWindow::updatePasteAction
);
230 QVector
<DolphinViewContainer
*> DolphinMainWindow::viewContainers() const
232 QVector
<DolphinViewContainer
*> viewContainers
;
234 for (int i
= 0; i
< m_tabWidget
->count(); ++i
) {
235 DolphinTabPage
*tabPage
= m_tabWidget
->tabPageAt(i
);
237 viewContainers
<< tabPage
->primaryViewContainer();
238 if (tabPage
->splitViewEnabled()) {
239 viewContainers
<< tabPage
->secondaryViewContainer();
242 return viewContainers
;
245 void DolphinMainWindow::openDirectories(const QList
<QUrl
>& dirs
, bool splitView
)
247 m_tabWidget
->openDirectories(dirs
, splitView
);
250 void DolphinMainWindow::openDirectories(const QStringList
& dirs
, bool splitView
)
252 openDirectories(QUrl::fromStringList(dirs
), splitView
);
255 void DolphinMainWindow::openFiles(const QList
<QUrl
>& files
, bool splitView
)
257 m_tabWidget
->openFiles(files
, splitView
);
260 bool DolphinMainWindow::isFoldersPanelEnabled() const
262 return actionCollection()->action(QStringLiteral("show_folders_panel"))->isChecked();
265 bool DolphinMainWindow::isInformationPanelEnabled() const
268 return actionCollection()->action(QStringLiteral("show_information_panel"))->isChecked();
274 void DolphinMainWindow::openFiles(const QStringList
& files
, bool splitView
)
276 openFiles(QUrl::fromStringList(files
), splitView
);
279 void DolphinMainWindow::activateWindow()
281 window()->setAttribute(Qt::WA_NativeWindow
, true);
282 KStartupInfo::setNewStartupId(window()->windowHandle(), KStartupInfo::startupId());
283 KWindowSystem::activateWindow(window()->effectiveWinId());
286 bool DolphinMainWindow::isActiveWindow()
288 return window()->isActiveWindow();
291 void DolphinMainWindow::showCommand(CommandType command
)
293 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
295 case KIO::FileUndoManager::Copy
:
296 statusBar
->setText(i18nc("@info:status", "Successfully copied."));
298 case KIO::FileUndoManager::Move
:
299 statusBar
->setText(i18nc("@info:status", "Successfully moved."));
301 case KIO::FileUndoManager::Link
:
302 statusBar
->setText(i18nc("@info:status", "Successfully linked."));
304 case KIO::FileUndoManager::Trash
:
305 statusBar
->setText(i18nc("@info:status", "Successfully moved to trash."));
307 case KIO::FileUndoManager::Rename
:
308 statusBar
->setText(i18nc("@info:status", "Successfully renamed."));
311 case KIO::FileUndoManager::Mkdir
:
312 statusBar
->setText(i18nc("@info:status", "Created folder."));
320 void DolphinMainWindow::pasteIntoFolder()
322 m_activeViewContainer
->view()->pasteIntoFolder();
325 void DolphinMainWindow::changeUrl(const QUrl
&url
)
327 if (!KProtocolManager::supportsListing(url
)) {
328 // The URL navigator only checks for validity, not
329 // if the URL can be listed. An error message is
330 // shown due to DolphinViewContainer::restoreView().
334 m_activeViewContainer
->setUrl(url
);
335 updateFileAndEditActions();
340 Q_EMIT
urlChanged(url
);
343 void DolphinMainWindow::slotTerminalDirectoryChanged(const QUrl
& url
)
345 if (m_tearDownFromPlacesRequested
&& url
== QUrl::fromLocalFile(QDir::homePath())) {
346 m_placesPanel
->proceedWithTearDown();
347 m_tearDownFromPlacesRequested
= false;
350 m_activeViewContainer
->setAutoGrabFocus(false);
352 m_activeViewContainer
->setAutoGrabFocus(true);
355 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
357 KToggleAction
* editableLocationAction
=
358 static_cast<KToggleAction
*>(actionCollection()->action(QStringLiteral("editable_location")));
359 editableLocationAction
->setChecked(editable
);
362 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
364 updateFileAndEditActions();
366 const int selectedUrlsCount
= m_tabWidget
->currentTabPage()->selectedItemsCount();
368 QAction
* compareFilesAction
= actionCollection()->action(QStringLiteral("compare_files"));
369 if (selectedUrlsCount
== 2) {
370 compareFilesAction
->setEnabled(isKompareInstalled());
372 compareFilesAction
->setEnabled(false);
375 Q_EMIT
selectionChanged(selection
);
378 void DolphinMainWindow::updateHistory()
380 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
381 const int index
= urlNavigator
->historyIndex();
383 QAction
* backAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Back
));
385 backAction
->setToolTip(i18nc("@info", "Go back"));
386 backAction
->setWhatsThis(i18nc("@info:whatsthis go back", "Return to the previously viewed folder."));
387 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
390 QAction
* forwardAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Forward
));
392 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
393 forwardAction
->setWhatsThis(xi18nc("@info:whatsthis go forward",
394 "This undoes a <interface>Go|Back</interface> action."));
395 forwardAction
->setEnabled(index
> 0);
399 void DolphinMainWindow::updateFilterBarAction(bool show
)
401 QAction
* toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
402 toggleFilterBarAction
->setChecked(show
);
405 void DolphinMainWindow::openNewMainWindow()
407 Dolphin::openNewWindow({m_activeViewContainer
->url()}, this);
410 void DolphinMainWindow::openNewActivatedTab()
412 // keep browsers compatibility, new tab is always after last one
413 auto openNewTabAfterLastTabConfigured
= GeneralSettings::openNewTabAfterLastTab();
414 GeneralSettings::setOpenNewTabAfterLastTab(true);
415 m_tabWidget
->openNewActivatedTab();
416 GeneralSettings::setOpenNewTabAfterLastTab(openNewTabAfterLastTabConfigured
);
419 void DolphinMainWindow::addToPlaces()
424 // If nothing is selected, act on the current dir
425 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
426 url
= m_activeViewContainer
->url();
427 name
= m_activeViewContainer
->placesText();
429 const auto dirToAdd
= m_activeViewContainer
->view()->selectedItems().first();
430 url
= dirToAdd
.url();
431 name
= dirToAdd
.name();
435 if (m_activeViewContainer
->isSearchModeEnabled()) {
436 icon
= QStringLiteral("folder-saved-search-symbolic");
438 icon
= KIO::iconNameForUrl(url
);
440 DolphinPlacesModelSingleton::instance().placesModel()->addPlace(name
, url
, icon
);
444 void DolphinMainWindow::openNewTab(const QUrl
& url
)
446 m_tabWidget
->openNewTab(url
, QUrl());
449 void DolphinMainWindow::openNewTabAndActivate(const QUrl
&url
)
451 m_tabWidget
->openNewActivatedTab(url
, QUrl());
454 void DolphinMainWindow::openNewWindow(const QUrl
&url
)
456 Dolphin::openNewWindow({url
}, this);
459 void DolphinMainWindow::slotSplitViewChanged()
461 m_tabWidget
->currentTabPage()->setSplitViewEnabled(GeneralSettings::splitView(), WithAnimation
);
465 void DolphinMainWindow::openInNewTab()
467 const KFileItemList
& list
= m_activeViewContainer
->view()->selectedItems();
468 bool tabCreated
= false;
470 for (const KFileItem
& item
: list
) {
471 const QUrl
& url
= DolphinView::openItemAsFolderUrl(item
);
472 if (!url
.isEmpty()) {
478 // if no new tab has been created from the selection
479 // open the current directory in a new tab
481 openNewTab(m_activeViewContainer
->url());
485 void DolphinMainWindow::openInNewWindow()
489 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
490 if (list
.isEmpty()) {
491 newWindowUrl
= m_activeViewContainer
->url();
492 } else if (list
.count() == 1) {
493 const KFileItem
& item
= list
.first();
494 newWindowUrl
= DolphinView::openItemAsFolderUrl(item
);
497 if (!newWindowUrl
.isEmpty()) {
498 Dolphin::openNewWindow({newWindowUrl
}, this);
502 void DolphinMainWindow::showTarget()
504 const auto link
= m_activeViewContainer
->view()->selectedItems().at(0);
505 const auto linkLocationDir
= QFileInfo(link
.localPath()).absoluteDir();
506 auto linkDestination
= link
.linkDest();
507 if (QFileInfo(linkDestination
).isRelative()) {
508 linkDestination
= linkLocationDir
.filePath(linkDestination
);
510 if (QFileInfo::exists(linkDestination
)) {
511 KIO::highlightInFileManager({QUrl::fromLocalFile(linkDestination
).adjusted(QUrl::StripTrailingSlash
)});
513 m_activeViewContainer
->showMessage(xi18nc("@info", "Could not access <filename>%1</filename>.", linkDestination
),
514 DolphinViewContainer::Warning
);
518 void DolphinMainWindow::showEvent(QShowEvent
* event
)
520 KXmlGuiWindow::showEvent(event
);
522 if (!event
->spontaneous()) {
523 m_activeViewContainer
->view()->setFocus();
527 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
529 // Find out if Dolphin is closed directly by the user or
530 // by the session manager because the session is closed
531 bool closedByUser
= true;
532 if (qApp
->isSavingSession()) {
533 closedByUser
= false;
536 if (m_tabWidget
->count() > 1
537 && GeneralSettings::confirmClosingMultipleTabs()
538 && !GeneralSettings::rememberOpenedTabs()
540 // Ask the user if he really wants to quit and close all tabs.
541 // Open a confirmation dialog with 3 buttons:
542 // QDialogButtonBox::Yes -> Quit
543 // QDialogButtonBox::No -> Close only the current tab
544 // QDialogButtonBox::Cancel -> do nothing
545 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
546 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
547 dialog
->setModal(true);
548 QDialogButtonBox
* buttons
= new QDialogButtonBox(QDialogButtonBox::Yes
| QDialogButtonBox::No
| QDialogButtonBox::Cancel
);
549 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KGuiItem(i18nc("@action:button 'Quit Dolphin' button", "&Quit %1", QGuiApplication::applicationDisplayName()), QIcon::fromTheme(QStringLiteral("application-exit"))));
550 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("C&lose Current Tab"), QIcon::fromTheme(QStringLiteral("tab-close"))));
551 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
552 buttons
->button(QDialogButtonBox::Yes
)->setDefault(true);
554 bool doNotAskAgainCheckboxResult
= false;
556 const auto result
= KMessageBox::createKMessageBox(dialog
,
558 QMessageBox::Warning
,
559 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
561 i18n("Do not ask again"),
562 &doNotAskAgainCheckboxResult
,
563 KMessageBox::Notify
);
565 if (doNotAskAgainCheckboxResult
) {
566 GeneralSettings::setConfirmClosingMultipleTabs(false);
570 case QDialogButtonBox::Yes
:
573 case QDialogButtonBox::No
:
574 // Close only the current tab
575 m_tabWidget
->closeTab();
583 if (m_terminalPanel
&& m_terminalPanel
->hasProgramRunning() && GeneralSettings::confirmClosingTerminalRunningProgram() && closedByUser
) {
584 // Ask if the user really wants to quit Dolphin with a program that is still running in the Terminal panel
585 // Open a confirmation dialog with 3 buttons:
586 // QDialogButtonBox::Yes -> Quit
587 // QDialogButtonBox::No -> Show Terminal Panel
588 // QDialogButtonBox::Cancel -> do nothing
589 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
590 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
591 dialog
->setModal(true);
592 auto standardButtons
= QDialogButtonBox::Yes
| QDialogButtonBox::Cancel
;
593 if (!m_terminalPanel
->isVisible()) {
594 standardButtons
|= QDialogButtonBox::No
;
596 QDialogButtonBox
*buttons
= new QDialogButtonBox(standardButtons
);
597 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KStandardGuiItem::quit());
598 if (!m_terminalPanel
->isVisible()) {
600 buttons
->button(QDialogButtonBox::No
),
601 KGuiItem(i18n("Show &Terminal Panel"), QIcon::fromTheme(QStringLiteral("dialog-scripts"))));
603 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
605 bool doNotAskAgainCheckboxResult
= false;
607 const auto result
= KMessageBox::createKMessageBox(
610 QMessageBox::Warning
,
611 i18n("The program '%1' is still running in the Terminal panel. Are you sure you want to quit?", m_terminalPanel
->runningProgramName()),
613 i18n("Do not ask again"),
614 &doNotAskAgainCheckboxResult
,
615 KMessageBox::Dangerous
);
617 if (doNotAskAgainCheckboxResult
) {
618 GeneralSettings::setConfirmClosingTerminalRunningProgram(false);
622 case QDialogButtonBox::Yes
:
625 case QDialogButtonBox::No
:
626 actionCollection()->action("show_terminal_panel")->trigger();
627 // Do not quit, ignore quit event
635 if (GeneralSettings::rememberOpenedTabs()) {
636 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
637 KConfig
*config
= KConfigGui::sessionConfig();
638 saveGlobalProperties(config
);
639 savePropertiesInternal(config
, 1);
643 GeneralSettings::setVersion(CurrentDolphinVersion
);
644 GeneralSettings::self()->save();
646 KXmlGuiWindow::closeEvent(event
);
649 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
651 m_tabWidget
->saveProperties(group
);
654 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
656 m_tabWidget
->readProperties(group
);
659 void DolphinMainWindow::updateNewMenu()
661 m_newFileMenu
->checkUpToDate();
662 #if KIO_VERSION >= QT_VERSION_CHECK(5, 97, 0)
663 m_newFileMenu
->setWorkingDirectory(activeViewContainer()->url());
665 m_newFileMenu
->setPopupFiles(QList
<QUrl
>() << activeViewContainer()->url());
669 void DolphinMainWindow::createDirectory()
671 #if KIO_VERSION >= QT_VERSION_CHECK(5, 97, 0)
672 m_newFileMenu
->setWorkingDirectory(activeViewContainer()->url());
674 m_newFileMenu
->setPopupFiles(QList
<QUrl
>() << activeViewContainer()->url());
676 m_newFileMenu
->createDirectory();
679 void DolphinMainWindow::quit()
684 void DolphinMainWindow::showErrorMessage(const QString
& message
)
686 m_activeViewContainer
->showMessage(message
, DolphinViewContainer::Error
);
689 void DolphinMainWindow::slotUndoAvailable(bool available
)
691 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
693 undoAction
->setEnabled(available
);
697 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
699 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
701 undoAction
->setText(text
);
705 void DolphinMainWindow::undo()
708 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
709 KIO::FileUndoManager::self()->undo();
712 void DolphinMainWindow::cut()
714 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
715 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CutContents
);
717 m_activeViewContainer
->view()->cutSelectedItemsToClipboard();
718 m_activeViewContainer
->setSelectionModeEnabled(false);
722 void DolphinMainWindow::copy()
724 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
725 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CopyContents
);
727 m_activeViewContainer
->view()->copySelectedItemsToClipboard();
728 m_activeViewContainer
->setSelectionModeEnabled(false);
732 void DolphinMainWindow::paste()
734 m_activeViewContainer
->view()->paste();
737 void DolphinMainWindow::find()
739 m_activeViewContainer
->setSearchModeEnabled(true);
742 void DolphinMainWindow::updateSearchAction()
744 QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
745 toggleSearchAction
->setChecked(m_activeViewContainer
->isSearchModeEnabled());
748 void DolphinMainWindow::updatePasteAction()
750 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
751 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
752 pasteAction
->setEnabled(pasteInfo
.first
);
753 pasteAction
->setText(pasteInfo
.second
);
756 void DolphinMainWindow::slotDirectoryLoadingCompleted()
761 void DolphinMainWindow::slotToolBarActionMiddleClicked(QAction
*action
)
763 if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Back
))) {
765 } else if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Forward
))) {
767 } else if (action
== actionCollection()->action(QStringLiteral("go_up"))) {
769 } else if (action
== actionCollection()->action(QStringLiteral("go_home"))) {
774 QAction
*DolphinMainWindow::urlNavigatorHistoryAction(const KUrlNavigator
*urlNavigator
, int historyIndex
, QObject
*parent
)
776 const QUrl url
= urlNavigator
->locationUrl(historyIndex
);
778 QString text
= url
.toDisplayString(QUrl::PreferLocalFile
);
780 if (!urlNavigator
->showFullPath()) {
781 const KFilePlacesModel
*placesModel
= DolphinPlacesModelSingleton::instance().placesModel();
783 const QModelIndex closestIdx
= placesModel
->closestItem(url
);
784 if (closestIdx
.isValid()) {
785 const QUrl placeUrl
= placesModel
->url(closestIdx
);
787 text
= placesModel
->text(closestIdx
);
789 QString pathInsidePlace
= url
.path().mid(placeUrl
.path().length());
791 if (!pathInsidePlace
.isEmpty() && !pathInsidePlace
.startsWith(QLatin1Char('/'))) {
792 pathInsidePlace
.prepend(QLatin1Char('/'));
795 if (pathInsidePlace
!= QLatin1Char('/')) {
796 text
.append(pathInsidePlace
);
801 QAction
*action
= new QAction(QIcon::fromTheme(KIO::iconNameForUrl(url
)), text
, parent
);
802 action
->setData(historyIndex
);
806 void DolphinMainWindow::slotAboutToShowBackPopupMenu()
808 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
810 m_backAction
->menu()->clear();
811 for (int i
= urlNavigator
->historyIndex() + 1; i
< urlNavigator
->historySize() && entries
< MaxNumberOfNavigationentries
; ++i
, ++entries
) {
812 QAction
*action
= urlNavigatorHistoryAction(urlNavigator
, i
, m_backAction
->menu());
814 m_backAction
->menu()->addAction(action
);
818 void DolphinMainWindow::slotGoBack(QAction
* action
)
820 int gotoIndex
= action
->data().value
<int>();
821 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
822 for (int i
= gotoIndex
- urlNavigator
->historyIndex(); i
> 0; --i
) {
827 void DolphinMainWindow::slotBackForwardActionMiddleClicked(QAction
* action
)
830 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
831 openNewTab(urlNavigator
->locationUrl(action
->data().value
<int>()));
835 void DolphinMainWindow::slotAboutToShowForwardPopupMenu()
837 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
839 m_forwardAction
->menu()->clear();
840 for (int i
= urlNavigator
->historyIndex() - 1; i
>= 0 && entries
< MaxNumberOfNavigationentries
; --i
, ++entries
) {
841 QAction
*action
= urlNavigatorHistoryAction(urlNavigator
, i
, m_forwardAction
->menu());
843 m_forwardAction
->menu()->addAction(action
);
847 void DolphinMainWindow::slotGoForward(QAction
* action
)
849 int gotoIndex
= action
->data().value
<int>();
850 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
851 for (int i
= urlNavigator
->historyIndex() - gotoIndex
; i
> 0; --i
) {
856 void DolphinMainWindow::slotSetSelectionMode(bool enabled
, SelectionMode::BottomBar::Contents bottomBarContents
)
858 m_activeViewContainer
->setSelectionModeEnabled(enabled
, actionCollection(), bottomBarContents
);
861 void DolphinMainWindow::selectAll()
865 // if the URL navigator is editable and focused, select the whole
866 // URL instead of all items of the view
868 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
869 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit();
870 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
871 lineEdit
->hasFocus();
873 lineEdit
->selectAll();
875 m_activeViewContainer
->view()->selectAll();
879 void DolphinMainWindow::invertSelection()
882 m_activeViewContainer
->view()->invertSelection();
885 void DolphinMainWindow::toggleSplitView()
887 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
888 tabPage
->setSplitViewEnabled(!tabPage
->splitViewEnabled(), WithAnimation
);
893 void DolphinMainWindow::toggleSplitStash()
895 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
896 tabPage
->setSplitViewEnabled(false, WithAnimation
);
897 tabPage
->setSplitViewEnabled(true, WithAnimation
, QUrl("stash:/"));
900 void DolphinMainWindow::copyToInactiveSplitView()
902 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
903 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CopyToOtherViewContents
);
905 m_tabWidget
->copyToInactiveSplitView();
906 m_activeViewContainer
->setSelectionModeEnabled(false);
910 void DolphinMainWindow::moveToInactiveSplitView()
912 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
913 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::MoveToOtherViewContents
);
915 m_tabWidget
->moveToInactiveSplitView();
916 m_activeViewContainer
->setSelectionModeEnabled(false);
920 void DolphinMainWindow::reloadView()
923 m_activeViewContainer
->reload();
924 m_activeViewContainer
->statusBar()->updateSpaceInfo();
927 void DolphinMainWindow::stopLoading()
929 m_activeViewContainer
->view()->stopLoading();
932 void DolphinMainWindow::enableStopAction()
934 actionCollection()->action(QStringLiteral("stop"))->setEnabled(true);
937 void DolphinMainWindow::disableStopAction()
939 actionCollection()->action(QStringLiteral("stop"))->setEnabled(false);
942 void DolphinMainWindow::toggleSelectionMode()
944 const bool checked
= !m_activeViewContainer
->isSelectionModeEnabled();
946 m_activeViewContainer
->setSelectionModeEnabled(checked
, actionCollection(), SelectionMode::BottomBar::Contents::GeneralContents
);
947 actionCollection()->action(QStringLiteral("toggle_selection_mode"))->setChecked(checked
);
950 void DolphinMainWindow::showFilterBar()
952 m_activeViewContainer
->setFilterBarVisible(true);
955 void DolphinMainWindow::toggleFilterBar()
957 const bool checked
= !m_activeViewContainer
->isFilterBarVisible();
958 m_activeViewContainer
->setFilterBarVisible(checked
);
960 QAction
* toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
961 toggleFilterBarAction
->setChecked(checked
);
964 void DolphinMainWindow::toggleEditLocation()
968 QAction
* action
= actionCollection()->action(QStringLiteral("editable_location"));
969 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
970 urlNavigator
->setUrlEditable(action
->isChecked());
973 void DolphinMainWindow::replaceLocation()
975 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
976 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit();
978 // If the text field currently has focus and everything is selected,
979 // pressing the keyboard shortcut returns the whole thing to breadcrumb mode
980 if (navigator
->isUrlEditable()
981 && lineEdit
->hasFocus()
982 && lineEdit
->selectedText() == lineEdit
->text() ) {
983 navigator
->setUrlEditable(false);
985 navigator
->setUrlEditable(true);
986 navigator
->setFocus();
987 lineEdit
->selectAll();
991 void DolphinMainWindow::togglePanelLockState()
993 const bool newLockState
= !GeneralSettings::lockPanels();
994 const auto childrenObjects
= children();
995 for (QObject
* child
: childrenObjects
) {
996 DolphinDockWidget
* dock
= qobject_cast
<DolphinDockWidget
*>(child
);
998 dock
->setLocked(newLockState
);
1002 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(newLockState
);
1004 GeneralSettings::setLockPanels(newLockState
);
1007 void DolphinMainWindow::slotTerminalPanelVisibilityChanged()
1009 if (m_terminalPanel
->isHiddenInVisibleWindow() && m_activeViewContainer
) {
1010 m_activeViewContainer
->view()->setFocus();
1014 void DolphinMainWindow::goBack()
1016 DolphinUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
1017 urlNavigator
->goBack();
1019 if (urlNavigator
->locationState().isEmpty()) {
1020 // An empty location state indicates a redirection URL,
1021 // which must be skipped too
1022 urlNavigator
->goBack();
1026 void DolphinMainWindow::goForward()
1028 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goForward();
1031 void DolphinMainWindow::goUp()
1033 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goUp();
1036 void DolphinMainWindow::goHome()
1038 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goHome();
1041 void DolphinMainWindow::goBackInNewTab()
1043 const KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
1044 const int index
= urlNavigator
->historyIndex() + 1;
1045 openNewTab(urlNavigator
->locationUrl(index
));
1048 void DolphinMainWindow::goForwardInNewTab()
1050 const KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
1051 const int index
= urlNavigator
->historyIndex() - 1;
1052 openNewTab(urlNavigator
->locationUrl(index
));
1055 void DolphinMainWindow::goUpInNewTab()
1057 const QUrl currentUrl
= activeViewContainer()->urlNavigator()->locationUrl();
1058 openNewTab(KIO::upUrl(currentUrl
));
1061 void DolphinMainWindow::goHomeInNewTab()
1063 openNewTab(Dolphin::homeUrl());
1066 void DolphinMainWindow::compareFiles()
1068 const KFileItemList items
= m_tabWidget
->currentTabPage()->selectedItems();
1069 if (items
.count() != 2) {
1070 // The action is disabled in this case, but it could have been triggered
1071 // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
1075 QUrl urlA
= items
.at(0).url();
1076 QUrl urlB
= items
.at(1).url();
1078 QString
command(QStringLiteral("kompare -c \""));
1079 command
.append(urlA
.toDisplayString(QUrl::PreferLocalFile
));
1080 command
.append("\" \"");
1081 command
.append(urlB
.toDisplayString(QUrl::PreferLocalFile
));
1082 command
.append('\"');
1084 KIO::CommandLauncherJob
*job
= new KIO::CommandLauncherJob(command
, this);
1085 job
->setDesktopName(QStringLiteral("org.kde.kompare"));
1089 void DolphinMainWindow::toggleShowMenuBar()
1091 const bool visible
= menuBar()->isVisible();
1092 menuBar()->setVisible(!visible
);
1095 QPointer
<QAction
> DolphinMainWindow::preferredSearchTool()
1097 m_searchTools
.clear();
1098 KMoreToolsMenuFactory("dolphin/search-tools").fillMenuFromGroupingNames(
1099 &m_searchTools
, { "files-find" }, m_activeViewContainer
->url()
1101 QList
<QAction
*> actions
= m_searchTools
.actions();
1102 if (actions
.isEmpty()) {
1105 QAction
* action
= actions
.first();
1106 if (action
->isSeparator()) {
1112 void DolphinMainWindow::updateOpenPreferredSearchToolAction()
1114 QAction
* openPreferredSearchTool
= actionCollection()->action(QStringLiteral("open_preferred_search_tool"));
1115 if (!openPreferredSearchTool
) {
1118 QPointer
<QAction
> tool
= preferredSearchTool();
1120 openPreferredSearchTool
->setVisible(true);
1121 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open %1", tool
->text()));
1122 // Only override with the app icon if it is the default, i.e. the user hasn't configured one manually
1123 // https://bugs.kde.org/show_bug.cgi?id=442815
1124 if (openPreferredSearchTool
->icon().name() == QLatin1String("search")) {
1125 openPreferredSearchTool
->setIcon(tool
->icon());
1128 openPreferredSearchTool
->setVisible(false);
1129 // still visible in Shortcuts configuration window
1130 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1131 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1135 void DolphinMainWindow::openPreferredSearchTool()
1137 QPointer
<QAction
> tool
= preferredSearchTool();
1143 void DolphinMainWindow::openTerminal()
1145 openTerminalJob(m_activeViewContainer
->url());
1148 void DolphinMainWindow::openTerminalHere()
1150 QList
<QUrl
> urls
= {};
1152 for (const KFileItem
& item
: m_activeViewContainer
->view()->selectedItems()) {
1153 QUrl url
= item
.targetUrl();
1154 if (item
.isFile()) {
1155 url
.setPath(QFileInfo(url
.path()).absolutePath());
1157 if (!urls
.contains(url
)) {
1162 // No items are selected. Open a terminal window for the current location.
1163 if (urls
.count() == 0) {
1168 if (urls
.count() > 5) {
1169 QString question
= i18np("Are you sure you want to open 1 terminal window?",
1170 "Are you sure you want to open %1 terminal windows?", urls
.count());
1171 const int answer
= KMessageBox::warningYesNo(this, question
, {},
1172 KGuiItem(i18ncp("@action:button", "Open %1 Terminal", "Open %1 Terminals", urls
.count()),
1173 QStringLiteral("utilities-terminal")),
1174 KStandardGuiItem::cancel());
1175 if (answer
!= KMessageBox::Yes
) {
1180 for (const QUrl
& url
: urls
) {
1181 openTerminalJob(url
);
1185 void DolphinMainWindow::openTerminalJob(const QUrl
& url
)
1187 if (url
.isLocalFile()) {
1188 auto job
= new KTerminalLauncherJob(QString());
1189 job
->setWorkingDirectory(url
.toLocalFile());
1194 // Not a local file, with protocol Class ":local", try stat'ing
1195 if (KProtocolInfo::protocolClass(url
.scheme()) == QLatin1String(":local")) {
1196 KIO::StatJob
*job
= KIO::mostLocalUrl(url
);
1197 KJobWidgets::setWindow(job
, this);
1198 connect(job
, &KJob::result
, this, [job
]() {
1200 if (!job
->error()) {
1201 statUrl
= job
->mostLocalUrl();
1204 auto job
= new KTerminalLauncherJob(QString());
1205 job
->setWorkingDirectory(statUrl
.isLocalFile() ? statUrl
.toLocalFile() : QDir::homePath());
1212 // Nothing worked, just use $HOME
1213 auto job
= new KTerminalLauncherJob(QString());
1214 job
->setWorkingDirectory(QDir::homePath());
1218 void DolphinMainWindow::editSettings()
1220 if (!m_settingsDialog
) {
1221 DolphinViewContainer
* container
= activeViewContainer();
1222 container
->view()->writeSettings();
1224 const QUrl url
= container
->url();
1225 DolphinSettingsDialog
* settingsDialog
= new DolphinSettingsDialog(url
, this, actionCollection());
1226 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, this, &DolphinMainWindow::refreshViews
);
1227 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
,
1228 &DolphinUrlNavigatorsController::slotReadSettings
);
1229 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1230 settingsDialog
->show();
1231 m_settingsDialog
= settingsDialog
;
1233 m_settingsDialog
.data()->raise();
1237 void DolphinMainWindow::handleUrl(const QUrl
& url
)
1239 delete m_lastHandleUrlOpenJob
;
1240 m_lastHandleUrlOpenJob
= nullptr;
1242 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1243 activeViewContainer()->setUrl(url
);
1245 m_lastHandleUrlOpenJob
= new KIO::OpenUrlJob(url
);
1246 m_lastHandleUrlOpenJob
->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
1247 m_lastHandleUrlOpenJob
->setShowOpenOrExecuteDialog(true);
1249 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::mimeTypeFound
, this,
1250 [this, url
](const QString
&mimetype
) {
1251 if (mimetype
== QLatin1String("inode/directory")) {
1252 // If it's a dir, we'll take it from here
1253 m_lastHandleUrlOpenJob
->kill();
1254 m_lastHandleUrlOpenJob
= nullptr;
1255 activeViewContainer()->setUrl(url
);
1259 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::result
, this, [this]() {
1260 m_lastHandleUrlOpenJob
= nullptr;
1263 m_lastHandleUrlOpenJob
->start();
1267 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1269 // trash:/ is writable but we don't want to create new items in it.
1270 // TODO: remove the trash check once https://phabricator.kde.org/T8234 is implemented
1271 newFileMenu()->setEnabled(isFolderWritable
&& m_activeViewContainer
->url().scheme() != QLatin1String("trash"));
1274 void DolphinMainWindow::openContextMenu(const QPoint
& pos
,
1275 const KFileItem
& item
,
1276 const KFileItemList
&selectedItems
,
1279 QPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, item
, selectedItems
, url
, &m_fileItemActions
);
1280 contextMenu
.data()->exec(pos
);
1282 // Delete the menu, unless it has been deleted in its own nested event loop already.
1284 contextMenu
->deleteLater();
1288 QMenu
*DolphinMainWindow::createPopupMenu()
1290 QMenu
*menu
= KXmlGuiWindow::createPopupMenu();
1292 menu
->addSeparator();
1293 menu
->addAction(actionCollection()->action(QStringLiteral("lock_panels")));
1298 void DolphinMainWindow::updateHamburgerMenu()
1300 KActionCollection
* ac
= actionCollection();
1301 auto hamburgerMenu
= static_cast<KHamburgerMenu
*>(
1302 ac
->action(KStandardAction::name(KStandardAction::HamburgerMenu
)));
1303 auto menu
= hamburgerMenu
->menu();
1305 menu
= new QMenu(this);
1306 hamburgerMenu
->setMenu(menu
);
1307 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("basic_actions"))->menu());
1308 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("zoom"))->menu());
1312 const QList
<QAction
*> toolbarActions
= toolBar()->actions();
1314 if (!toolBar()->isVisible()) {
1315 // If neither the menu bar nor the toolbar are visible, these actions should be available.
1316 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)));
1317 menu
->addAction(toolBarMenuAction());
1318 menu
->addSeparator();
1321 // This group of actions (until the next separator) contains all the most basic actions
1322 // necessary to use Dolphin effectively.
1323 menu
->addAction(ac
->action(QStringLiteral("go_back")));
1324 menu
->addAction(ac
->action(QStringLiteral("go_forward")));
1326 menu
->addMenu(m_newFileMenu
->menu());
1327 if (!toolBar()->isVisible()
1328 || !toolbarActions
.contains(ac
->action(QStringLiteral("toggle_selection_mode_tool_bar")))
1330 menu
->addAction(ac
->action(QStringLiteral("toggle_selection_mode")));
1332 menu
->addAction(ac
->action(QStringLiteral("basic_actions")));
1333 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Undo
)));
1334 if (!toolBar()->isVisible()
1335 || (!toolbarActions
.contains(ac
->action(QStringLiteral("toggle_search")))
1336 && !toolbarActions
.contains(ac
->action(QStringLiteral("open_preferred_search_tool"))))
1338 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Find
)));
1339 // This way a search action will only be added if none of the three available
1340 // search actions is present on the toolbar.
1342 if (!toolBar()->isVisible()
1343 || !toolbarActions
.contains(ac
->action(QStringLiteral("toggle_filter")))
1345 menu
->addAction(ac
->action(QStringLiteral("show_filter_bar")));
1346 // This way a filter action will only be added if none of the two available
1347 // filter actions is present on the toolbar.
1349 menu
->addSeparator();
1351 // The second group of actions (up until the next separator) contains actions for opening
1352 // additional views to interact with the file system.
1353 menu
->addAction(ac
->action(QStringLiteral("file_new")));
1354 menu
->addAction(ac
->action(QStringLiteral("new_tab")));
1355 if (ac
->action(QStringLiteral("undo_close_tab"))->isEnabled()) {
1356 menu
->addAction(ac
->action(QStringLiteral("closed_tabs")));
1358 menu
->addAction(ac
->action(QStringLiteral("open_terminal")));
1359 menu
->addSeparator();
1361 // The third group contains actions to change what one sees in the view
1362 // and to change the more general UI.
1363 if (!toolBar()->isVisible()
1364 || (!toolbarActions
.contains(ac
->action(QStringLiteral("icons")))
1365 && !toolbarActions
.contains(ac
->action(QStringLiteral("compact")))
1366 && !toolbarActions
.contains(ac
->action(QStringLiteral("details")))
1367 && !toolbarActions
.contains(ac
->action(QStringLiteral("view_mode"))))
1369 menu
->addAction(ac
->action(QStringLiteral("view_mode")));
1371 menu
->addAction(ac
->action(QStringLiteral("show_hidden_files")));
1372 menu
->addAction(ac
->action(QStringLiteral("sort")));
1373 menu
->addAction(ac
->action(QStringLiteral("additional_info")));
1374 if (!GeneralSettings::showStatusBar() || !GeneralSettings::showZoomSlider()) {
1375 menu
->addAction(ac
->action(QStringLiteral("zoom")));
1377 menu
->addAction(ac
->action(QStringLiteral("panels")));
1379 // The "Configure" menu is not added to the actionCollection() because there is hardly
1380 // a good reason for users to put it on their toolbar.
1381 auto configureMenu
= menu
->addMenu(QIcon::fromTheme(QStringLiteral("configure")),
1382 i18nc("@action:inmenu menu for configure actions", "Configure"));
1383 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
)));
1384 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)));
1385 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)));
1386 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Preferences
)));
1387 hamburgerMenu
->hideActionsOf(configureMenu
);
1390 void DolphinMainWindow::slotPlaceActivated(const QUrl
& url
)
1392 DolphinViewContainer
* view
= activeViewContainer();
1394 if (view
->url() == url
) {
1395 // We can end up here if the user clicked a device in the Places Panel
1396 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
1399 view
->disableUrlNavigatorSelectionRequests();
1401 view
->enableUrlNavigatorSelectionRequests();
1405 void DolphinMainWindow::closedTabsCountChanged(unsigned int count
)
1407 actionCollection()->action(QStringLiteral("undo_close_tab"))->setEnabled(count
> 0);
1410 void DolphinMainWindow::activeViewChanged(DolphinViewContainer
* viewContainer
)
1412 DolphinViewContainer
* oldViewContainer
= m_activeViewContainer
;
1413 Q_ASSERT(viewContainer
);
1415 m_activeViewContainer
= viewContainer
;
1417 if (oldViewContainer
) {
1418 const QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
1419 toggleSearchAction
->disconnect(oldViewContainer
);
1421 // Disconnect all signals between the old view container (container,
1422 // view and url navigator) and main window.
1423 oldViewContainer
->disconnect(this);
1424 oldViewContainer
->view()->disconnect(this);
1425 oldViewContainer
->urlNavigatorInternalWithHistory()->disconnect(this);
1426 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
1427 (actionCollection()->action(QStringLiteral("url_navigators")));
1428 navigators
->primaryUrlNavigator()->disconnect(this);
1429 if (auto secondaryUrlNavigator
= navigators
->secondaryUrlNavigator()) {
1430 secondaryUrlNavigator
->disconnect(this);
1433 // except the requestItemInfo so that on hover the information panel can still be updated
1434 connect(oldViewContainer
->view(), &DolphinView::requestItemInfo
,
1435 this, &DolphinMainWindow::requestItemInfo
);
1437 // Disconnect other slots.
1438 disconnect(nullptr, &DolphinViewContainer::selectionModeChanged
,
1439 actionCollection()->action(QStringLiteral("toggle_selection_mode")), &QAction::setChecked
);
1442 connectViewSignals(viewContainer
);
1444 m_actionHandler
->setCurrentView(viewContainer
->view());
1447 updateFileAndEditActions();
1448 updatePasteAction();
1449 updateViewActions();
1451 updateSearchAction();
1453 const QUrl url
= viewContainer
->url();
1454 Q_EMIT
urlChanged(url
);
1457 void DolphinMainWindow::tabCountChanged(int count
)
1459 const bool enableTabActions
= (count
> 1);
1460 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1461 actionCollection()->action(QStringLiteral("activate_tab_%1").arg(i
))->setEnabled(enableTabActions
);
1463 actionCollection()->action(QStringLiteral("activate_last_tab"))->setEnabled(enableTabActions
);
1464 actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions
);
1465 actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions
);
1468 void DolphinMainWindow::updateWindowTitle()
1470 const QString newTitle
= m_activeViewContainer
->captionWindowTitle();
1471 if (windowTitle() != newTitle
) {
1472 setWindowTitle(newTitle
);
1476 void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString
& mountPath
)
1478 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1479 setViewsToHomeIfMountPathOpen(mountPath
);
1482 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectory().startsWith(mountPath
)) {
1483 m_tearDownFromPlacesRequested
= true;
1484 m_terminalPanel
->goHome();
1485 // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged
1487 m_placesPanel
->proceedWithTearDown();
1491 void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString
& mountPath
)
1493 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1494 setViewsToHomeIfMountPathOpen(mountPath
);
1497 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectory().startsWith(mountPath
)) {
1498 m_tearDownFromPlacesRequested
= false;
1499 m_terminalPanel
->goHome();
1503 void DolphinMainWindow::slotKeyBindings()
1505 KShortcutsDialog
dialog(KShortcutsEditor::AllActions
, KShortcutsEditor::LetterShortcutsAllowed
, this);
1506 dialog
.addCollection(actionCollection());
1507 if (m_terminalPanel
) {
1508 KActionCollection
*konsolePartActionCollection
= m_terminalPanel
->actionCollection();
1509 if (konsolePartActionCollection
) {
1510 dialog
.addCollection(konsolePartActionCollection
, QStringLiteral("KonsolePart"));
1516 void DolphinMainWindow::setViewsToHomeIfMountPathOpen(const QString
& mountPath
)
1518 const QVector
<DolphinViewContainer
*> theViewContainers
= viewContainers();
1519 for (DolphinViewContainer
*viewContainer
: theViewContainers
) {
1520 if (viewContainer
&& viewContainer
->url().toLocalFile().startsWith(mountPath
)) {
1521 viewContainer
->setUrl(QUrl::fromLocalFile(QDir::homePath()));
1524 disconnect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, nullptr, nullptr);
1527 void DolphinMainWindow::setupActions()
1529 auto hamburgerMenuAction
= KStandardAction::hamburgerMenu(nullptr, nullptr, actionCollection());
1531 // setup 'File' menu
1532 m_newFileMenu
= new DolphinNewFileMenu(actionCollection(), this);
1533 QMenu
* menu
= m_newFileMenu
->menu();
1534 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1535 menu
->setIcon(QIcon::fromTheme(QStringLiteral("list-add")));
1536 m_newFileMenu
->setPopupMode(QToolButton::InstantPopup
);
1537 connect(menu
, &QMenu::aboutToShow
,
1538 this, &DolphinMainWindow::updateNewMenu
);
1540 QAction
* newWindow
= KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow
, actionCollection());
1541 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1542 newWindow
->setToolTip(i18nc("@info", "Open a new Dolphin window"));
1543 newWindow
->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1544 "window just like this one with the current location and view."
1545 "<nl/>You can drag and drop items between windows."));
1546 newWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1548 QAction
* newTab
= actionCollection()->addAction(QStringLiteral("new_tab"));
1549 newTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1550 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1551 newTab
->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1552 "<emphasis>Tab</emphasis> with the current location and view.<nl/>"
1553 "A tab is an additional view within this window. "
1554 "You can drag and drop items between tabs."));
1555 actionCollection()->setDefaultShortcuts(newTab
, {Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
});
1556 connect(newTab
, &QAction::triggered
, this, &DolphinMainWindow::openNewActivatedTab
);
1558 QAction
* addToPlaces
= actionCollection()->addAction(QStringLiteral("add_to_places"));
1559 addToPlaces
->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new")));
1560 addToPlaces
->setText(i18nc("@action:inmenu Add current folder to places", "Add to Places"));
1561 addToPlaces
->setWhatsThis(xi18nc("@info:whatsthis", "This adds the selected folder "
1562 "to the Places panel."));
1563 connect(addToPlaces
, &QAction::triggered
, this, &DolphinMainWindow::addToPlaces
);
1565 QAction
* closeTab
= KStandardAction::close(m_tabWidget
, QOverload
<>::of(&DolphinTabWidget::closeTab
), actionCollection());
1566 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1567 closeTab
->setWhatsThis(i18nc("@info:whatsthis", "This closes the "
1568 "currently viewed tab. If no more tabs are left this window "
1569 "will close instead."));
1571 QAction
* quitAction
= KStandardAction::quit(this, &DolphinMainWindow::quit
, actionCollection());
1572 quitAction
->setWhatsThis(i18nc("@info:whatsthis quit", "This closes this window."));
1574 // setup 'Edit' menu
1575 KStandardAction::undo(this,
1576 &DolphinMainWindow::undo
,
1577 actionCollection());
1579 // i18n: This will be the last paragraph for the whatsthis for all three:
1580 // Cut, Copy and Paste
1581 const QString cutCopyPastePara
= xi18nc("@info:whatsthis", "<para><emphasis>Cut, "
1582 "Copy</emphasis> and <emphasis>Paste</emphasis> work between many "
1583 "applications and are among the most used commands. That's why their "
1584 "<emphasis>keyboard shortcuts</emphasis> are prominently placed right "
1585 "next to each other on the keyboard: <shortcut>Ctrl+X</shortcut>, "
1586 "<shortcut>Ctrl+C</shortcut> and <shortcut>Ctrl+V</shortcut>.</para>");
1587 QAction
* cutAction
= KStandardAction::cut(this, &DolphinMainWindow::cut
, actionCollection());
1588 m_actionTextHelper
->registerTextWhenNothingIsSelected(cutAction
, i18nc("@action", "Cut…"));
1589 cutAction
->setWhatsThis(xi18nc("@info:whatsthis cut", "This copies the items "
1590 "in your current selection to the <emphasis>clipboard</emphasis>.<nl/>"
1591 "Use the <emphasis>Paste</emphasis> action afterwards to copy them from "
1592 "the clipboard to a new location. The items will be removed from their "
1593 "initial location.") + cutCopyPastePara
);
1594 QAction
* copyAction
= KStandardAction::copy(this, &DolphinMainWindow::copy
, actionCollection());
1595 m_actionTextHelper
->registerTextWhenNothingIsSelected(copyAction
, i18nc("@action", "Copy…"));
1596 copyAction
->setWhatsThis(xi18nc("@info:whatsthis copy", "This copies the "
1597 "items in your current selection to the <emphasis>clipboard</emphasis>."
1598 "<nl/>Use the <emphasis>Paste</emphasis> action afterwards to copy them "
1599 "from the clipboard to a new location.") + cutCopyPastePara
);
1600 QAction
* paste
= KStandardAction::paste(this, &DolphinMainWindow::paste
, actionCollection());
1601 // The text of the paste-action is modified dynamically by Dolphin
1602 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1603 // due to the long text, the text "Paste" is used:
1604 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1605 paste
->setWhatsThis(xi18nc("@info:whatsthis paste", "This copies the items from "
1606 "your <emphasis>clipboard</emphasis> to the currently viewed folder.<nl/>"
1607 "If the items were added to the clipboard by the <emphasis>Cut</emphasis> "
1608 "action they are removed from their old location.") + cutCopyPastePara
);
1610 QAction
* copyToOtherViewAction
= actionCollection()->addAction(QStringLiteral("copy_to_inactive_split_view"));
1611 copyToOtherViewAction
->setText(i18nc("@action:inmenu", "Copy to Inactive Split View"));
1612 m_actionTextHelper
->registerTextWhenNothingIsSelected(copyToOtherViewAction
, i18nc("@action:inmenu", "Copy to Inactive Split View…"));
1613 copyToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Copy", "This copies the selected items from "
1614 "the <emphasis>active</emphasis> view to the inactive split view."));
1615 copyToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
1616 copyToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Copy to Inactive Split View"));
1617 actionCollection()->setDefaultShortcut(copyToOtherViewAction
, Qt::SHIFT
| Qt::Key_F5
);
1618 connect(copyToOtherViewAction
, &QAction::triggered
, this, &DolphinMainWindow::copyToInactiveSplitView
);
1620 QAction
* moveToOtherViewAction
= actionCollection()->addAction(QStringLiteral("move_to_inactive_split_view"));
1621 moveToOtherViewAction
->setText(i18nc("@action:inmenu", "Move to Inactive Split View"));
1622 m_actionTextHelper
->registerTextWhenNothingIsSelected(moveToOtherViewAction
, i18nc("@action:inmenu", "Move to Inactive Split View…"));
1623 moveToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Move", "This moves the selected items from "
1624 "the <emphasis>active</emphasis> view to the inactive split view."));
1625 moveToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-cut")));
1626 moveToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Move to Inactive Split View"));
1627 actionCollection()->setDefaultShortcut(moveToOtherViewAction
, Qt::SHIFT
| Qt::Key_F6
);
1628 connect(moveToOtherViewAction
, &QAction::triggered
, this, &DolphinMainWindow::moveToInactiveSplitView
);
1630 QAction
* showFilterBar
= actionCollection()->addAction(QStringLiteral("show_filter_bar"));
1631 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Filter..."));
1632 showFilterBar
->setToolTip(i18nc("@info:tooltip", "Show Filter Bar"));
1633 showFilterBar
->setWhatsThis(xi18nc("@info:whatsthis", "This opens the "
1634 "<emphasis>Filter Bar</emphasis> at the bottom of the window.<nl/> "
1635 "There you can enter a text to filter the files and folders currently displayed. "
1636 "Only those that contain the text in their name will be kept in view."));
1637 showFilterBar
->setIcon(QIcon::fromTheme(QStringLiteral("view-filter")));
1638 actionCollection()->setDefaultShortcuts(showFilterBar
, {Qt::CTRL
| Qt::Key_I
, Qt::Key_Slash
});
1639 connect(showFilterBar
, &QAction::triggered
, this, &DolphinMainWindow::showFilterBar
);
1641 // toggle_filter acts as a copy of the main showFilterBar to be used mainly
1642 // in the toolbar, with no default shortcut attached, to avoid messing with
1643 // existing workflows (filter bar always open and Ctrl-I to focus)
1644 QAction
*toggleFilter
= actionCollection()->addAction(QStringLiteral("toggle_filter"));
1645 toggleFilter
->setText(i18nc("@action:inmenu", "Toggle Filter Bar"));
1646 toggleFilter
->setIconText(i18nc("@action:intoolbar", "Filter"));
1647 toggleFilter
->setIcon(showFilterBar
->icon());
1648 toggleFilter
->setToolTip(showFilterBar
->toolTip());
1649 toggleFilter
->setWhatsThis(showFilterBar
->whatsThis());
1650 toggleFilter
->setCheckable(true);
1651 connect(toggleFilter
, &QAction::triggered
, this, &DolphinMainWindow::toggleFilterBar
);
1653 QAction
*searchAction
= KStandardAction::find(this, &DolphinMainWindow::find
, actionCollection());
1654 searchAction
->setText(i18n("Search..."));
1655 searchAction
->setToolTip(i18nc("@info:tooltip", "Search for files and folders"));
1656 searchAction
->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This helps you "
1657 "find files and folders by opening a <emphasis>find bar</emphasis>. "
1658 "There you can enter search terms and specify settings to find the "
1659 "objects you are looking for.</para><para>Use this help again on "
1660 "the find bar so we can have a look at it while the settings are "
1661 "explained.</para>"));
1663 // toggle_search acts as a copy of the main searchAction to be used mainly
1664 // in the toolbar, with no default shortcut attached, to avoid messing with
1665 // existing workflows (search bar always open and Ctrl-F to focus)
1666 QAction
*toggleSearchAction
= actionCollection()->addAction(QStringLiteral("toggle_search"));
1667 toggleSearchAction
->setText(i18nc("@action:inmenu", "Toggle Search Bar"));
1668 toggleSearchAction
->setIconText(i18nc("@action:intoolbar", "Search"));
1669 toggleSearchAction
->setIcon(searchAction
->icon());
1670 toggleSearchAction
->setToolTip(searchAction
->toolTip());
1671 toggleSearchAction
->setWhatsThis(searchAction
->whatsThis());
1672 toggleSearchAction
->setCheckable(true);
1674 QAction
*toggleSelectionModeAction
= actionCollection()->addAction(QStringLiteral("toggle_selection_mode"));
1675 // i18n: This action toggles a selection mode.
1676 toggleSelectionModeAction
->setText(i18nc("@action:inmenu", "Select Files and Folders"));
1677 // i18n: Opens a selection mode for selecting files/folders.
1678 // The text is kept so unspecific because it will be shown on the toolbar where space is at a premium.
1679 toggleSelectionModeAction
->setIconText(i18nc("@action:intoolbar", "Select"));
1680 toggleSelectionModeAction
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This application only knows which files or folders should be acted on if they are"
1681 " <emphasis>selected</emphasis> first. Press this to toggle a <emphasis>Selection Mode</emphasis> which makes selecting and deselecting as easy as "
1682 "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."
1684 toggleSelectionModeAction
->setIcon(QIcon::fromTheme(QStringLiteral("quickwizard")));
1685 toggleSelectionModeAction
->setCheckable(true);
1686 actionCollection()->setDefaultShortcut(toggleSelectionModeAction
, Qt::Key_Space
);
1687 connect(toggleSelectionModeAction
, &QAction::triggered
, this, &DolphinMainWindow::toggleSelectionMode
);
1689 // A special version of the toggleSelectionModeAction for the toolbar that also contains a menu
1690 // with the selectAllAction and invertSelectionAction.
1691 auto *toggleSelectionModeToolBarAction
= new KToolBarPopupAction(toggleSelectionModeAction
->icon(), toggleSelectionModeAction
->iconText(), actionCollection());
1692 toggleSelectionModeToolBarAction
->setToolTip(toggleSelectionModeAction
->text());
1693 toggleSelectionModeToolBarAction
->setWhatsThis(toggleSelectionModeAction
->whatsThis());
1694 actionCollection()->addAction(QStringLiteral("toggle_selection_mode_tool_bar"), toggleSelectionModeToolBarAction
);
1695 toggleSelectionModeToolBarAction
->setCheckable(true);
1696 toggleSelectionModeToolBarAction
->setPopupMode(QToolButton::DelayedPopup
);
1697 connect(toggleSelectionModeToolBarAction
, &QAction::triggered
, toggleSelectionModeAction
, &QAction::trigger
);
1698 connect(toggleSelectionModeAction
, &QAction::toggled
, toggleSelectionModeToolBarAction
, &QAction::setChecked
);
1700 QAction
* selectAllAction
= KStandardAction::selectAll(this, &DolphinMainWindow::selectAll
, actionCollection());
1701 selectAllAction
->setWhatsThis(xi18nc("@info:whatsthis", "This selects all "
1702 "files and folders in the current location."));
1704 QAction
* invertSelection
= actionCollection()->addAction(QStringLiteral("invert_selection"));
1705 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1706 invertSelection
->setWhatsThis(xi18nc("@info:whatsthis invert", "This selects all "
1707 "objects that you have currently <emphasis>not</emphasis> selected instead."));
1708 invertSelection
->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-invert")));
1709 actionCollection()->setDefaultShortcut(invertSelection
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1710 connect(invertSelection
, &QAction::triggered
, this, &DolphinMainWindow::invertSelection
);
1712 QMenu
*toggleSelectionModeActionMenu
= new QMenu(this);
1713 toggleSelectionModeActionMenu
->addAction(selectAllAction
);
1714 toggleSelectionModeActionMenu
->addAction(invertSelection
);
1715 toggleSelectionModeToolBarAction
->setMenu(toggleSelectionModeActionMenu
);
1717 // setup 'View' menu
1718 // (note that most of it is set up in DolphinViewActionHandler)
1720 QAction
* split
= actionCollection()->addAction(QStringLiteral("split_view"));
1721 split
->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This splits "
1722 "the folder view below into two autonomous views.</para><para>This "
1723 "way you can see two locations at once and move items between them "
1724 "quickly.</para>Click this again afterwards to recombine the views."));
1725 actionCollection()->setDefaultShortcut(split
, Qt::Key_F3
);
1726 connect(split
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitView
);
1728 QAction
* stashSplit
= actionCollection()->addAction(QStringLiteral("split_stash"));
1729 actionCollection()->setDefaultShortcut(stashSplit
, Qt::CTRL
| Qt::Key_S
);
1730 stashSplit
->setText(i18nc("@action:intoolbar Stash", "Stash"));
1731 stashSplit
->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
1732 stashSplit
->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
1733 stashSplit
->setCheckable(false);
1734 QDBusConnectionInterface
*sessionInterface
= QDBusConnection::sessionBus().interface();
1735 stashSplit
->setVisible(sessionInterface
&& sessionInterface
->isServiceRegistered(QStringLiteral("org.kde.kio.StashNotifier")));
1736 connect(stashSplit
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitStash
);
1738 KStandardAction::redisplay(this, &DolphinMainWindow::reloadView
, actionCollection());
1740 QAction
* stop
= actionCollection()->addAction(QStringLiteral("stop"));
1741 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1742 stop
->setToolTip(i18nc("@info", "Stop loading"));
1743 stop
->setWhatsThis(i18nc("@info", "This stops the loading of the contents of the current folder."));
1744 stop
->setIcon(QIcon::fromTheme(QStringLiteral("process-stop")));
1745 connect(stop
, &QAction::triggered
, this, &DolphinMainWindow::stopLoading
);
1747 KToggleAction
* editableLocation
= actionCollection()->add
<KToggleAction
>(QStringLiteral("editable_location"));
1748 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1749 editableLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1750 "This toggles the <emphasis>Location Bar</emphasis> to be "
1751 "editable so you can directly enter a location you want to go to.<nl/>"
1752 "You can also switch to editing by clicking to the right of the "
1753 "location and switch back by confirming the edited location."));
1754 actionCollection()->setDefaultShortcut(editableLocation
, Qt::Key_F6
);
1755 connect(editableLocation
, &KToggleAction::triggered
, this, &DolphinMainWindow::toggleEditLocation
);
1757 QAction
* replaceLocation
= actionCollection()->addAction(QStringLiteral("replace_location"));
1758 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1759 // i18n: "enter" is used both in the meaning of "writing" and "going to" a new location here.
1760 // Both meanings are useful but not necessary to understand the use of "Replace Location".
1761 // So you might want to be more verbose in your language to convey the meaning but it's up to you.
1762 replaceLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1763 "This switches to editing the location and selects it "
1764 "so you can quickly enter a different location."));
1765 actionCollection()->setDefaultShortcut(replaceLocation
, Qt::CTRL
| Qt::Key_L
);
1766 connect(replaceLocation
, &QAction::triggered
, this, &DolphinMainWindow::replaceLocation
);
1770 QScopedPointer
<QAction
> backAction(KStandardAction::back(nullptr, nullptr, nullptr));
1771 m_backAction
= new KToolBarPopupAction(backAction
->icon(), backAction
->text(), actionCollection());
1772 m_backAction
->setObjectName(backAction
->objectName());
1773 m_backAction
->setShortcuts(backAction
->shortcuts());
1775 m_backAction
->setPopupMode(QToolButton::DelayedPopup
);
1776 connect(m_backAction
, &QAction::triggered
, this, &DolphinMainWindow::goBack
);
1777 connect(m_backAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowBackPopupMenu
);
1778 connect(m_backAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoBack
);
1779 actionCollection()->addAction(m_backAction
->objectName(), m_backAction
);
1781 auto backShortcuts
= m_backAction
->shortcuts();
1782 backShortcuts
.append(QKeySequence(Qt::Key_Backspace
));
1783 actionCollection()->setDefaultShortcuts(m_backAction
, backShortcuts
);
1785 DolphinRecentTabsMenu
* recentTabsMenu
= new DolphinRecentTabsMenu(this);
1786 actionCollection()->addAction(QStringLiteral("closed_tabs"), recentTabsMenu
);
1787 connect(m_tabWidget
, &DolphinTabWidget::rememberClosedTab
,
1788 recentTabsMenu
, &DolphinRecentTabsMenu::rememberClosedTab
);
1789 connect(recentTabsMenu
, &DolphinRecentTabsMenu::restoreClosedTab
,
1790 m_tabWidget
, &DolphinTabWidget::restoreClosedTab
);
1791 connect(recentTabsMenu
, &DolphinRecentTabsMenu::closedTabsCountChanged
,
1792 this, &DolphinMainWindow::closedTabsCountChanged
);
1794 QAction
* undoCloseTab
= actionCollection()->addAction(QStringLiteral("undo_close_tab"));
1795 undoCloseTab
->setText(i18nc("@action:inmenu File", "Undo close tab"));
1796 undoCloseTab
->setWhatsThis(i18nc("@info:whatsthis undo close tab",
1797 "This returns you to the previously closed tab."));
1798 actionCollection()->setDefaultShortcut(undoCloseTab
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_T
);
1799 undoCloseTab
->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo")));
1800 undoCloseTab
->setEnabled(false);
1801 connect(undoCloseTab
, &QAction::triggered
, recentTabsMenu
, &DolphinRecentTabsMenu::undoCloseTab
);
1803 auto undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
1804 undoAction
->setWhatsThis(xi18nc("@info:whatsthis", "This undoes "
1805 "the last change you made to files or folders.<nl/>"
1806 "Such changes include <interface>creating, renaming</interface> "
1807 "and <interface>moving</interface> them to a different location "
1808 "or to the <filename>Trash</filename>. <nl/>Changes that can't "
1809 "be undone will ask for your confirmation."));
1810 undoAction
->setEnabled(false); // undo should be disabled by default
1813 QScopedPointer
<QAction
> forwardAction(KStandardAction::forward(nullptr, nullptr, nullptr));
1814 m_forwardAction
= new KToolBarPopupAction(forwardAction
->icon(), forwardAction
->text(), actionCollection());
1815 m_forwardAction
->setObjectName(forwardAction
->objectName());
1816 m_forwardAction
->setShortcuts(forwardAction
->shortcuts());
1818 m_forwardAction
->setPopupMode(QToolButton::DelayedPopup
);
1819 connect(m_forwardAction
, &QAction::triggered
, this, &DolphinMainWindow::goForward
);
1820 connect(m_forwardAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowForwardPopupMenu
);
1821 connect(m_forwardAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoForward
);
1822 actionCollection()->addAction(m_forwardAction
->objectName(), m_forwardAction
);
1823 actionCollection()->setDefaultShortcuts(m_forwardAction
, m_forwardAction
->shortcuts());
1825 // enable middle-click to open in a new tab
1826 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
1827 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotBackForwardActionMiddleClicked
);
1828 m_backAction
->menu()->installEventFilter(middleClickEventFilter
);
1829 m_forwardAction
->menu()->installEventFilter(middleClickEventFilter
);
1830 KStandardAction::up(this, &DolphinMainWindow::goUp
, actionCollection());
1831 QAction
* homeAction
= KStandardAction::home(this, &DolphinMainWindow::goHome
, actionCollection());
1832 homeAction
->setWhatsThis(xi18nc("@info:whatsthis", "Go to your "
1833 "<filename>Home</filename> folder.<nl/>Every user account "
1834 "has their own <filename>Home</filename> that contains their data "
1835 "including folders that contain personal application data."));
1837 // setup 'Tools' menu
1838 QAction
* compareFiles
= actionCollection()->addAction(QStringLiteral("compare_files"));
1839 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1840 compareFiles
->setIcon(QIcon::fromTheme(QStringLiteral("kompare")));
1841 compareFiles
->setEnabled(false);
1842 connect(compareFiles
, &QAction::triggered
, this, &DolphinMainWindow::compareFiles
);
1844 QAction
* openPreferredSearchTool
= actionCollection()->addAction(QStringLiteral("open_preferred_search_tool"));
1845 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1846 openPreferredSearchTool
->setWhatsThis(xi18nc("@info:whatsthis",
1847 "<para>This opens a preferred search tool for the viewed location.</para>"
1848 "<para>Use <emphasis>More Search Tools</emphasis> menu to configure it.</para>"));
1849 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1850 actionCollection()->setDefaultShortcut(openPreferredSearchTool
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F
);
1851 connect(openPreferredSearchTool
, &QAction::triggered
, this, &DolphinMainWindow::openPreferredSearchTool
);
1853 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1854 QAction
* openTerminal
= actionCollection()->addAction(QStringLiteral("open_terminal"));
1855 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1856 openTerminal
->setWhatsThis(xi18nc("@info:whatsthis",
1857 "<para>This opens a <emphasis>terminal</emphasis> application for the viewed location.</para>"
1858 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1859 openTerminal
->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
1860 actionCollection()->setDefaultShortcut(openTerminal
, Qt::SHIFT
| Qt::Key_F4
);
1861 connect(openTerminal
, &QAction::triggered
, this, &DolphinMainWindow::openTerminal
);
1863 QAction
* openTerminalHere
= actionCollection()->addAction(QStringLiteral("open_terminal_here"));
1864 // i18n: "Here" refers to the location(s) of the currently selected item(s) or the currently viewed location if nothing is selected.
1865 openTerminalHere
->setText(i18nc("@action:inmenu Tools", "Open Terminal Here"));
1866 openTerminalHere
->setWhatsThis(xi18nc("@info:whatsthis",
1867 "<para>This opens <emphasis>terminal</emphasis> applications for the selected items' locations.</para>"
1868 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1869 openTerminalHere
->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
1870 actionCollection()->setDefaultShortcut(openTerminalHere
, Qt::SHIFT
| Qt::ALT
| Qt::Key_F4
);
1871 connect(openTerminalHere
, &QAction::triggered
, this, &DolphinMainWindow::openTerminalHere
);
1874 QAction
* focusTerminalPanel
= actionCollection()->addAction(QStringLiteral("focus_terminal_panel"));
1875 focusTerminalPanel
->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
1876 focusTerminalPanel
->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
1877 actionCollection()->setDefaultShortcut(focusTerminalPanel
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F4
);
1878 connect(focusTerminalPanel
, &QAction::triggered
, this, &DolphinMainWindow::focusTerminalPanel
);
1882 // setup 'Bookmarks' menu
1883 KActionMenu
*bookmarkMenu
= new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this);
1884 bookmarkMenu
->setIcon(QIcon::fromTheme(QStringLiteral("bookmarks")));
1885 // Make the toolbar button version work properly on click
1886 bookmarkMenu
->setPopupMode(QToolButton::InstantPopup
);
1887 m_bookmarkHandler
= new DolphinBookmarkHandler(this, actionCollection(), bookmarkMenu
->menu(), this);
1888 actionCollection()->addAction(QStringLiteral("bookmarks"), bookmarkMenu
);
1890 // setup 'Settings' menu
1891 KToggleAction
* showMenuBar
= KStandardAction::showMenubar(nullptr, nullptr, actionCollection());
1892 showMenuBar
->setWhatsThis(xi18nc("@info:whatsthis",
1893 "<para>This switches between having a <emphasis>Menubar</emphasis> "
1894 "and having a <interface>%1</interface> button. Both "
1895 "contain mostly the same actions and configuration options.</para>"
1896 "<para>The Menubar takes up more space but allows for fast and organised access to all "
1897 "actions an application has to offer.</para><para>The <interface>%1</interface> button "
1898 "is simpler and small which makes triggering advanced actions more time consuming.</para>", hamburgerMenuAction
->text().replace('&', "")));
1899 connect(showMenuBar
, &KToggleAction::triggered
, // Fixes #286822
1900 this, &DolphinMainWindow::toggleShowMenuBar
, Qt::QueuedConnection
);
1902 KToggleAction
* showStatusBar
= KStandardAction::showStatusbar(nullptr, nullptr, actionCollection());
1903 showStatusBar
->setChecked(GeneralSettings::showStatusBar());
1904 connect(GeneralSettings::self(), &GeneralSettings::showStatusBarChanged
, showStatusBar
, &KToggleAction::setChecked
);
1905 connect(showStatusBar
, &KToggleAction::triggered
, this, [this](bool checked
) {
1906 GeneralSettings::setShowStatusBar(checked
);
1910 KStandardAction::keyBindings(this, &DolphinMainWindow::slotKeyBindings
, actionCollection());
1911 KStandardAction::preferences(this, &DolphinMainWindow::editSettings
, actionCollection());
1913 // not in menu actions
1914 QList
<QKeySequence
> nextTabKeys
= KStandardShortcut::tabNext();
1915 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
1917 QList
<QKeySequence
> prevTabKeys
= KStandardShortcut::tabPrev();
1918 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
1920 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1921 QAction
* activateTab
= actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i
));
1922 activateTab
->setText(i18nc("@action:inmenu", "Activate Tab %1", i
+ 1));
1923 activateTab
->setEnabled(false);
1924 connect(activateTab
, &QAction::triggered
, this, [this, i
]() { m_tabWidget
->activateTab(i
); });
1926 // only add default shortcuts for the first 9 tabs regardless of MaxActivateTabShortcuts
1928 actionCollection()->setDefaultShortcut(activateTab
, QStringLiteral("Alt+%1").arg(i
+ 1));
1932 QAction
* activateLastTab
= actionCollection()->addAction(QStringLiteral("activate_last_tab"));
1933 activateLastTab
->setText(i18nc("@action:inmenu", "Activate Last Tab"));
1934 activateLastTab
->setEnabled(false);
1935 connect(activateLastTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateLastTab
);
1936 actionCollection()->setDefaultShortcut(activateLastTab
, Qt::ALT
| Qt::Key_0
);
1938 QAction
* activateNextTab
= actionCollection()->addAction(QStringLiteral("activate_next_tab"));
1939 activateNextTab
->setIconText(i18nc("@action:inmenu", "Next Tab"));
1940 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1941 activateNextTab
->setEnabled(false);
1942 connect(activateNextTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateNextTab
);
1943 actionCollection()->setDefaultShortcuts(activateNextTab
, nextTabKeys
);
1945 QAction
* activatePrevTab
= actionCollection()->addAction(QStringLiteral("activate_prev_tab"));
1946 activatePrevTab
->setIconText(i18nc("@action:inmenu", "Previous Tab"));
1947 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1948 activatePrevTab
->setEnabled(false);
1949 connect(activatePrevTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activatePrevTab
);
1950 actionCollection()->setDefaultShortcuts(activatePrevTab
, prevTabKeys
);
1953 QAction
* showTarget
= actionCollection()->addAction(QStringLiteral("show_target"));
1954 showTarget
->setText(i18nc("@action:inmenu", "Show Target"));
1955 showTarget
->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
1956 showTarget
->setEnabled(false);
1957 connect(showTarget
, &QAction::triggered
, this, &DolphinMainWindow::showTarget
);
1959 QAction
* openInNewTab
= actionCollection()->addAction(QStringLiteral("open_in_new_tab"));
1960 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1961 openInNewTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1962 connect(openInNewTab
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
1964 QAction
* openInNewTabs
= actionCollection()->addAction(QStringLiteral("open_in_new_tabs"));
1965 openInNewTabs
->setText(i18nc("@action:inmenu", "Open in New Tabs"));
1966 openInNewTabs
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1967 connect(openInNewTabs
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
1969 QAction
* openInNewWindow
= actionCollection()->addAction(QStringLiteral("open_in_new_window"));
1970 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1971 openInNewWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1972 connect(openInNewWindow
, &QAction::triggered
, this, &DolphinMainWindow::openInNewWindow
);
1975 void DolphinMainWindow::setupDockWidgets()
1977 const bool lock
= GeneralSettings::lockPanels();
1979 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(lock
);
1981 KDualAction
* lockLayoutAction
= actionCollection()->add
<KDualAction
>(QStringLiteral("lock_panels"));
1982 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1983 lockLayoutAction
->setActiveIcon(QIcon::fromTheme(QStringLiteral("object-unlocked")));
1984 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1985 lockLayoutAction
->setInactiveIcon(QIcon::fromTheme(QStringLiteral("object-locked")));
1986 lockLayoutAction
->setWhatsThis(xi18nc("@info:whatsthis", "This "
1987 "switches between having panels <emphasis>locked</emphasis> or "
1988 "<emphasis>unlocked</emphasis>.<nl/>Unlocked panels can be "
1989 "dragged to the other side of the window and have a close "
1990 "button.<nl/>Locked panels are embedded more cleanly."));
1991 lockLayoutAction
->setActive(lock
);
1992 connect(lockLayoutAction
, &KDualAction::triggered
, this, &DolphinMainWindow::togglePanelLockState
);
1994 // Setup "Information"
1995 DolphinDockWidget
* infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
1996 infoDock
->setLocked(lock
);
1997 infoDock
->setObjectName(QStringLiteral("infoDock"));
1998 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2001 InformationPanel
* infoPanel
= new InformationPanel(infoDock
);
2002 infoPanel
->setCustomContextMenuActions({lockLayoutAction
});
2003 connect(infoPanel
, &InformationPanel::urlActivated
, this, &DolphinMainWindow::handleUrl
);
2004 infoDock
->setWidget(infoPanel
);
2006 QAction
* infoAction
= infoDock
->toggleViewAction();
2007 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-information")), Qt::Key_F11
, infoAction
, QStringLiteral("show_information_panel"));
2009 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
2010 connect(this, &DolphinMainWindow::urlChanged
,
2011 infoPanel
, &InformationPanel::setUrl
);
2012 connect(this, &DolphinMainWindow::selectionChanged
,
2013 infoPanel
, &InformationPanel::setSelection
);
2014 connect(this, &DolphinMainWindow::requestItemInfo
,
2015 infoPanel
, &InformationPanel::requestDelayedItemInfo
);
2016 connect(this, &DolphinMainWindow::fileItemsChanged
,
2017 infoPanel
, &InformationPanel::slotFilesItemChanged
);
2020 // i18n: This is the last paragraph for the "What's This"-texts of all four panels.
2021 const QString panelWhatsThis
= xi18nc("@info:whatsthis", "<para>To show or "
2022 "hide panels like this go to <interface>Menu|Panels</interface> "
2023 "or <interface>View|Panels</interface>.</para>");
2025 actionCollection()->action(QStringLiteral("show_information_panel"))
2026 ->setWhatsThis(xi18nc("@info:whatsthis", "<para> This toggles the "
2027 "<emphasis>information</emphasis> panel at the right side of the "
2028 "window.</para><para>The panel provides in-depth information "
2029 "about the items your mouse is hovering over or about the selected "
2030 "items. Otherwise it informs you about the currently viewed folder.<nl/>"
2031 "For single items a preview of their contents is provided.</para>"));
2033 infoDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
2034 "provides in-depth information about the items your mouse is "
2035 "hovering over or about the selected items. Otherwise it informs "
2036 "you about the currently viewed folder.<nl/>For single items a "
2037 "preview of their contents is provided.</para><para>You can configure "
2038 "which and how details are given here by right-clicking.</para>") + panelWhatsThis
);
2041 DolphinDockWidget
* foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
2042 foldersDock
->setLocked(lock
);
2043 foldersDock
->setObjectName(QStringLiteral("foldersDock"));
2044 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2045 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
2046 foldersPanel
->setCustomContextMenuActions({lockLayoutAction
});
2047 foldersDock
->setWidget(foldersPanel
);
2049 QAction
* foldersAction
= foldersDock
->toggleViewAction();
2050 createPanelAction(QIcon::fromTheme(QStringLiteral("folder")), Qt::Key_F7
, foldersAction
, QStringLiteral("show_folders_panel"));
2052 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
2053 connect(this, &DolphinMainWindow::urlChanged
,
2054 foldersPanel
, &FoldersPanel::setUrl
);
2055 connect(foldersPanel
, &FoldersPanel::folderActivated
,
2056 this, &DolphinMainWindow::changeUrl
);
2057 connect(foldersPanel
, &FoldersPanel::folderInNewTab
,
2058 this, &DolphinMainWindow::openNewTab
);
2059 connect(foldersPanel
, &FoldersPanel::folderInNewActiveTab
,
2060 this, &DolphinMainWindow::openNewTabAndActivate
);
2061 connect(foldersPanel
, &FoldersPanel::errorMessage
,
2062 this, &DolphinMainWindow::showErrorMessage
);
2064 actionCollection()->action(QStringLiteral("show_folders_panel"))
2065 ->setWhatsThis(xi18nc("@info:whatsthis", "This toggles the "
2066 "<emphasis>folders</emphasis> panel at the left side of the window."
2067 "<nl/><nl/>It shows the folders of the <emphasis>file system"
2068 "</emphasis> in a <emphasis>tree view</emphasis>."));
2069 foldersDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
2070 "shows the folders of the <emphasis>file system</emphasis> in a "
2071 "<emphasis>tree view</emphasis>.</para><para>Click a folder to go "
2072 "there. Click the arrow to the left of a folder to see its subfolders. "
2073 "This allows quick switching between any folders.</para>") + panelWhatsThis
);
2077 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
2078 DolphinDockWidget
* terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
2079 terminalDock
->setLocked(lock
);
2080 terminalDock
->setObjectName(QStringLiteral("terminalDock"));
2081 m_terminalPanel
= new TerminalPanel(terminalDock
);
2082 m_terminalPanel
->setCustomContextMenuActions({lockLayoutAction
});
2083 terminalDock
->setWidget(m_terminalPanel
);
2085 connect(m_terminalPanel
, &TerminalPanel::hideTerminalPanel
, terminalDock
, &DolphinDockWidget::hide
);
2086 connect(m_terminalPanel
, &TerminalPanel::changeUrl
, this, &DolphinMainWindow::slotTerminalDirectoryChanged
);
2087 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
,
2088 m_terminalPanel
, &TerminalPanel::dockVisibilityChanged
);
2089 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
,
2090 this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged
);
2092 QAction
* terminalAction
= terminalDock
->toggleViewAction();
2093 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-scripts")), Qt::Key_F4
, terminalAction
, QStringLiteral("show_terminal_panel"));
2095 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
2096 connect(this, &DolphinMainWindow::urlChanged
,
2097 m_terminalPanel
, &TerminalPanel::setUrl
);
2099 if (GeneralSettings::version() < 200) {
2100 terminalDock
->hide();
2103 actionCollection()->action(QStringLiteral("show_terminal_panel"))
2104 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
2105 "<emphasis>terminal</emphasis> panel at the bottom of the window."
2106 "<nl/>The location in the terminal will always match the folder "
2107 "view so you can navigate using either.</para><para>The terminal "
2108 "panel is not needed for basic computer usage but can be useful "
2109 "for advanced tasks. To learn more about terminals use the help "
2110 "in a standalone terminal application like Konsole.</para>"));
2111 terminalDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is "
2112 "the <emphasis>terminal</emphasis> panel. It behaves like a "
2113 "normal terminal but will match the location of the folder view "
2114 "so you can navigate using either.</para><para>The terminal panel "
2115 "is not needed for basic computer usage but can be useful for "
2116 "advanced tasks. To learn more about terminals use the help in a "
2117 "standalone terminal application like Konsole.</para>") + panelWhatsThis
);
2121 if (GeneralSettings::version() < 200) {
2123 foldersDock
->hide();
2127 DolphinDockWidget
* placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
2128 placesDock
->setLocked(lock
);
2129 placesDock
->setObjectName(QStringLiteral("placesDock"));
2130 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2132 m_placesPanel
= new PlacesPanel(placesDock
);
2133 m_placesPanel
->setCustomContextMenuActions({lockLayoutAction
});
2134 placesDock
->setWidget(m_placesPanel
);
2136 QAction
*placesAction
= placesDock
->toggleViewAction();
2137 createPanelAction(QIcon::fromTheme(QStringLiteral("compass")), Qt::Key_F9
, placesAction
, QStringLiteral("show_places_panel"));
2139 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
2140 connect(m_placesPanel
, &PlacesPanel::placeActivated
,
2141 this, &DolphinMainWindow::slotPlaceActivated
);
2142 connect(m_placesPanel
, &PlacesPanel::tabRequested
,
2143 this, &DolphinMainWindow::openNewTab
);
2144 connect(m_placesPanel
, &PlacesPanel::activeTabRequested
,
2145 this, &DolphinMainWindow::openNewTabAndActivate
);
2146 connect(m_placesPanel
, &PlacesPanel::newWindowRequested
, this, [this](const QUrl
&url
) {
2147 Dolphin::openNewWindow({url
}, this);
2149 connect(m_placesPanel
, &PlacesPanel::errorMessage
,
2150 this, &DolphinMainWindow::showErrorMessage
);
2151 connect(this, &DolphinMainWindow::urlChanged
,
2152 m_placesPanel
, &PlacesPanel::setUrl
);
2153 connect(placesDock
, &DolphinDockWidget::visibilityChanged
,
2154 &DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged
);
2155 connect(this, &DolphinMainWindow::settingsChanged
,
2156 m_placesPanel
, &PlacesPanel::readSettings
);
2157 connect(m_placesPanel
, &PlacesPanel::storageTearDownRequested
,
2158 this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested
);
2159 connect(m_placesPanel
, &PlacesPanel::storageTearDownExternallyRequested
,
2160 this, &DolphinMainWindow::slotStorageTearDownExternallyRequested
);
2161 DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged(m_placesPanel
->isVisible());
2163 auto actionShowAllPlaces
= new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this);
2164 actionShowAllPlaces
->setCheckable(true);
2165 actionShowAllPlaces
->setDisabled(true);
2166 actionShowAllPlaces
->setWhatsThis(i18nc("@info:whatsthis", "This displays "
2167 "all places in the places panel that have been hidden. They will "
2168 "appear semi-transparent unless you uncheck their hide property."));
2170 connect(actionShowAllPlaces
, &QAction::triggered
, this, [actionShowAllPlaces
, this](bool checked
){
2171 m_placesPanel
->setShowAll(checked
);
2173 connect(m_placesPanel
, &PlacesPanel::allPlacesShownChanged
, actionShowAllPlaces
, &QAction::setChecked
);
2175 actionCollection()->action(QStringLiteral("show_places_panel"))
2176 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
2177 "<emphasis>places</emphasis> panel at the left side of the window."
2178 "</para><para>It allows you to go to locations you have "
2179 "bookmarked and to access disk or media attached to the computer "
2180 "or to the network. It also contains sections to find recently "
2181 "saved files or files of a certain type.</para>"));
2182 placesDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2183 "<emphasis>Places</emphasis> panel. It allows you to go to locations "
2184 "you have bookmarked and to access disk or media attached to the "
2185 "computer or to the network. It also contains sections to find "
2186 "recently saved files or files of a certain type.</para><para>"
2187 "Click on an entry to go there. Click with the right mouse button "
2188 "instead to open any entry in a new tab or new window.</para>"
2189 "<para>New entries can be added by dragging folders onto this panel. "
2190 "Right-click any section or entry to hide it. Right-click an empty "
2191 "space on this panel and select <interface>Show Hidden Places"
2192 "</interface> to display it again.</para>") + panelWhatsThis
);
2194 // Add actions into the "Panels" menu
2195 KActionMenu
* panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Show Panels"), this);
2196 actionCollection()->addAction(QStringLiteral("panels"), panelsMenu
);
2197 panelsMenu
->setIcon(QIcon::fromTheme(QStringLiteral("view-sidetree")));
2198 panelsMenu
->setPopupMode(QToolButton::InstantPopup
);
2199 const KActionCollection
* ac
= actionCollection();
2200 panelsMenu
->addAction(ac
->action(QStringLiteral("show_places_panel")));
2202 panelsMenu
->addAction(ac
->action(QStringLiteral("show_information_panel")));
2204 panelsMenu
->addAction(ac
->action(QStringLiteral("show_folders_panel")));
2205 panelsMenu
->addAction(ac
->action(QStringLiteral("show_terminal_panel")));
2206 panelsMenu
->addSeparator();
2207 panelsMenu
->addAction(actionShowAllPlaces
);
2208 panelsMenu
->addAction(lockLayoutAction
);
2210 connect(panelsMenu
->menu(), &QMenu::aboutToShow
, this, [actionShowAllPlaces
, this]{
2211 actionShowAllPlaces
->setEnabled(DolphinPlacesModelSingleton::instance().placesModel()->hiddenCount());
2216 void DolphinMainWindow::updateFileAndEditActions()
2218 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
2219 const KActionCollection
* col
= actionCollection();
2220 KFileItemListProperties
capabilitiesSource(list
);
2222 QAction
* renameAction
= col
->action(KStandardAction::name(KStandardAction::RenameFile
));
2223 QAction
* moveToTrashAction
= col
->action(KStandardAction::name(KStandardAction::MoveToTrash
));
2224 QAction
* deleteAction
= col
->action(KStandardAction::name(KStandardAction::DeleteFile
));
2225 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
2226 QAction
* duplicateAction
= col
->action(QStringLiteral("duplicate")); // see DolphinViewActionHandler
2227 QAction
* addToPlacesAction
= col
->action(QStringLiteral("add_to_places"));
2228 QAction
* copyToOtherViewAction
= col
->action(QStringLiteral("copy_to_inactive_split_view"));
2229 QAction
* moveToOtherViewAction
= col
->action(QStringLiteral("move_to_inactive_split_view"));
2230 QAction
* copyLocation
= col
->action(QString("copy_location"));
2232 if (list
.isEmpty()) {
2233 stateChanged(QStringLiteral("has_no_selection"));
2235 // All actions that need a selection to function can be enabled because they should trigger selection mode.
2236 renameAction
->setEnabled(true);
2237 moveToTrashAction
->setEnabled(true);
2238 deleteAction
->setEnabled(true);
2239 cutAction
->setEnabled(true);
2240 duplicateAction
->setEnabled(true);
2241 addToPlacesAction
->setEnabled(true);
2242 copyLocation
->setEnabled(true);
2243 // Them triggering selection mode and not directly acting on selected items is signified by adding "…" to their text.
2244 m_actionTextHelper
->textsWhenNothingIsSelectedEnabled(true);
2247 m_actionTextHelper
->textsWhenNothingIsSelectedEnabled(false);
2248 stateChanged(QStringLiteral("has_selection"));
2250 QAction
* deleteWithTrashShortcut
= col
->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
2251 QAction
* showTarget
= col
->action(QStringLiteral("show_target"));
2253 if (list
.length() == 1 && list
.first().isDir()) {
2254 addToPlacesAction
->setEnabled(true);
2256 addToPlacesAction
->setEnabled(false);
2259 const bool enableMoveToTrash
= capabilitiesSource
.isLocal() && capabilitiesSource
.supportsMoving();
2261 renameAction
->setEnabled(capabilitiesSource
.supportsMoving());
2262 moveToTrashAction
->setEnabled(enableMoveToTrash
);
2263 deleteAction
->setEnabled(capabilitiesSource
.supportsDeleting());
2264 deleteWithTrashShortcut
->setEnabled(capabilitiesSource
.supportsDeleting() && !enableMoveToTrash
);
2265 cutAction
->setEnabled(capabilitiesSource
.supportsMoving());
2266 copyLocation
->setEnabled(list
.length() == 1);
2267 showTarget
->setEnabled(list
.length() == 1 && list
.at(0).isLink());
2268 duplicateAction
->setEnabled(capabilitiesSource
.supportsWriting());
2271 if (m_tabWidget
->currentTabPage()->splitViewEnabled()) {
2272 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
2273 KFileItem capabilitiesDestination
;
2275 if (tabPage
->primaryViewActive()) {
2276 capabilitiesDestination
= tabPage
->secondaryViewContainer()->url();
2278 capabilitiesDestination
= tabPage
->primaryViewContainer()->url();
2281 copyToOtherViewAction
->setEnabled(capabilitiesDestination
.isWritable());
2282 moveToOtherViewAction
->setEnabled((list
.isEmpty() || capabilitiesSource
.supportsMoving()) && capabilitiesDestination
.isWritable());
2284 copyToOtherViewAction
->setEnabled(false);
2285 moveToOtherViewAction
->setEnabled(false);
2289 void DolphinMainWindow::updateViewActions()
2291 m_actionHandler
->updateViewActions();
2293 QAction
* toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
2294 toggleFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
2296 updateSplitAction();
2299 void DolphinMainWindow::updateGoActions()
2301 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
2302 const QUrl currentUrl
= m_activeViewContainer
->url();
2303 // I think this is one of the best places to firstly be confronted
2304 // with a file system and its hierarchy. Talking about the root
2305 // directory might seem too much here but it is the question that
2306 // naturally arises in this context.
2307 goUpAction
->setWhatsThis(xi18nc("@info:whatsthis", "<para>Go to "
2308 "the folder that contains the currently viewed one.</para>"
2309 "<para>All files and folders are organized in a hierarchical "
2310 "<emphasis>file system</emphasis>. At the top of this hierarchy is "
2311 "a directory that contains all data connected to this computer"
2312 "—the <emphasis>root directory</emphasis>.</para>"));
2313 goUpAction
->setEnabled(KIO::upUrl(currentUrl
) != currentUrl
);
2316 void DolphinMainWindow::refreshViews()
2318 m_tabWidget
->refreshViews();
2320 if (GeneralSettings::modifiedStartupSettings()) {
2321 updateWindowTitle();
2324 Q_EMIT
settingsChanged();
2327 void DolphinMainWindow::clearStatusBar()
2329 m_activeViewContainer
->statusBar()->resetToDefaultText();
2332 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
2334 connect(container
, &DolphinViewContainer::showFilterBarChanged
,
2335 this, &DolphinMainWindow::updateFilterBarAction
);
2336 connect(container
, &DolphinViewContainer::writeStateChanged
,
2337 this, &DolphinMainWindow::slotWriteStateChanged
);
2338 connect(container
, &DolphinViewContainer::searchModeEnabledChanged
,
2339 this, &DolphinMainWindow::updateSearchAction
);
2340 connect(container
, &DolphinViewContainer::captionChanged
,
2341 this, &DolphinMainWindow::updateWindowTitle
);
2342 connect(container
, &DolphinViewContainer::tabRequested
,
2343 this, &DolphinMainWindow::openNewTab
);
2344 connect(container
, &DolphinViewContainer::activeTabRequested
,
2345 this, &DolphinMainWindow::openNewTabAndActivate
);
2347 const QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
2348 connect(toggleSearchAction
, &QAction::triggered
, container
, &DolphinViewContainer::setSearchModeEnabled
);
2350 // Make the toggled state of the selection mode actions visually follow the selection mode state of the view.
2351 auto toggleSelectionModeAction
= actionCollection()->action(QStringLiteral("toggle_selection_mode"));
2352 toggleSelectionModeAction
->setChecked(m_activeViewContainer
->isSelectionModeEnabled());
2353 connect(m_activeViewContainer
, &DolphinViewContainer::selectionModeChanged
,
2354 toggleSelectionModeAction
, &QAction::setChecked
);
2356 const DolphinView
* view
= container
->view();
2357 connect(view
, &DolphinView::selectionChanged
,
2358 this, &DolphinMainWindow::slotSelectionChanged
);
2359 connect(view
, &DolphinView::requestItemInfo
,
2360 this, &DolphinMainWindow::requestItemInfo
);
2361 connect(view
, &DolphinView::fileItemsChanged
,
2362 this, &DolphinMainWindow::fileItemsChanged
);
2363 connect(view
, &DolphinView::tabRequested
,
2364 this, &DolphinMainWindow::openNewTab
);
2365 connect(view
, &DolphinView::activeTabRequested
,
2366 this, &DolphinMainWindow::openNewTabAndActivate
);
2367 connect(view
, &DolphinView::windowRequested
,
2368 this, &DolphinMainWindow::openNewWindow
);
2369 connect(view
, &DolphinView::requestContextMenu
,
2370 this, &DolphinMainWindow::openContextMenu
);
2371 connect(view
, &DolphinView::directoryLoadingStarted
,
2372 this, &DolphinMainWindow::enableStopAction
);
2373 connect(view
, &DolphinView::directoryLoadingCompleted
,
2374 this, &DolphinMainWindow::disableStopAction
);
2375 connect(view
, &DolphinView::directoryLoadingCompleted
,
2376 this, &DolphinMainWindow::slotDirectoryLoadingCompleted
);
2377 connect(view
, &DolphinView::goBackRequested
,
2378 this, &DolphinMainWindow::goBack
);
2379 connect(view
, &DolphinView::goForwardRequested
,
2380 this, &DolphinMainWindow::goForward
);
2381 connect(view
, &DolphinView::urlActivated
,
2382 this, &DolphinMainWindow::handleUrl
);
2383 connect(view
, &DolphinView::goUpRequested
,
2384 this, &DolphinMainWindow::goUp
);
2386 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::urlChanged
,
2387 this, &DolphinMainWindow::changeUrl
);
2388 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::historyChanged
,
2389 this, &DolphinMainWindow::updateHistory
);
2391 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
2392 (actionCollection()->action(QStringLiteral("url_navigators")));
2393 const KUrlNavigator
*navigator
= m_tabWidget
->currentTabPage()->primaryViewActive() ?
2394 navigators
->primaryUrlNavigator() :
2395 navigators
->secondaryUrlNavigator();
2397 QAction
*editableLocactionAction
= actionCollection()->action(QStringLiteral("editable_location"));
2398 editableLocactionAction
->setChecked(navigator
->isUrlEditable());
2399 connect(navigator
, &KUrlNavigator::editableStateChanged
,
2400 this, &DolphinMainWindow::slotEditableStateChanged
);
2401 connect(navigator
, &KUrlNavigator::tabRequested
,
2402 this, &DolphinMainWindow::openNewTab
);
2403 connect(navigator
, &KUrlNavigator::activeTabRequested
,
2404 this, &DolphinMainWindow::openNewTabAndActivate
);
2405 connect(navigator
, &KUrlNavigator::newWindowRequested
,
2406 this, &DolphinMainWindow::openNewWindow
);
2410 void DolphinMainWindow::updateSplitAction()
2412 QAction
* splitAction
= actionCollection()->action(QStringLiteral("split_view"));
2413 const DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
2414 if (tabPage
->splitViewEnabled()) {
2415 if (GeneralSettings::closeActiveSplitView() ? tabPage
->primaryViewActive() : !tabPage
->primaryViewActive()) {
2416 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2417 splitAction
->setToolTip(i18nc("@info", "Close left view"));
2418 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close")));
2420 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2421 splitAction
->setToolTip(i18nc("@info", "Close right view"));
2422 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close")));
2425 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2426 splitAction
->setToolTip(i18nc("@info", "Split view"));
2427 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
2431 void DolphinMainWindow::updateAllowedToolbarAreas()
2433 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
2434 (actionCollection()->action(QStringLiteral("url_navigators")));
2435 if (toolBar()->actions().contains(navigators
)) {
2436 toolBar()->setAllowedAreas(Qt::TopToolBarArea
| Qt::BottomToolBarArea
);
2437 if (toolBarArea(toolBar()) == Qt::LeftToolBarArea
||
2438 toolBarArea(toolBar()) == Qt::RightToolBarArea
) {
2439 addToolBar(Qt::TopToolBarArea
, toolBar());
2442 toolBar()->setAllowedAreas(Qt::AllToolBarAreas
);
2446 bool DolphinMainWindow::isKompareInstalled() const
2448 static bool initialized
= false;
2449 static bool installed
= false;
2451 // TODO: maybe replace this approach later by using a menu
2452 // plugin like kdiff3plugin.cpp
2453 installed
= !QStandardPaths::findExecutable(QStringLiteral("kompare")).isEmpty();
2459 void DolphinMainWindow::createPanelAction(const QIcon
& icon
,
2460 const QKeySequence
& shortcut
,
2461 QAction
* dockAction
,
2462 const QString
& actionName
)
2464 QAction
* panelAction
= actionCollection()->addAction(actionName
);
2465 panelAction
->setCheckable(true);
2466 panelAction
->setChecked(dockAction
->isChecked());
2467 panelAction
->setText(dockAction
->text());
2468 panelAction
->setIcon(icon
);
2469 dockAction
->setIcon(icon
);
2470 actionCollection()->setDefaultShortcut(panelAction
, shortcut
);
2472 connect(panelAction
, &QAction::triggered
, dockAction
, &QAction::trigger
);
2473 connect(dockAction
, &QAction::toggled
, panelAction
, &QAction::setChecked
);
2476 void DolphinMainWindow::setupWhatsThis()
2479 menuBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2480 "<emphasis>Menubar</emphasis>. It provides access to commands and "
2481 "configuration options. Left-click on any of the menus on this "
2482 "bar to see its contents.</para><para>The Menubar can be hidden "
2483 "by unchecking <interface>Settings|Show Menubar</interface>. Then "
2484 "most of its contents become available through a <interface>Menu"
2485 "</interface> button on the <emphasis>Toolbar</emphasis>.</para>"));
2486 toolBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2487 "<emphasis>Toolbar</emphasis>. It allows quick access to "
2488 "frequently used actions.</para><para>It is highly customizable. "
2489 "All items you see in the <interface>Menu</interface> or "
2490 "in the <interface>Menubar</interface> can be placed on the "
2491 "Toolbar. Just right-click on it and select <interface>Configure "
2492 "Toolbars…</interface> or find this action within the <interface>"
2494 "</para><para>The location of the bar and the style of its "
2495 "buttons can also be changed in the right-click menu. Right-click "
2496 "a button if you want to show or hide its text.</para>"));
2497 m_tabWidget
->setWhatsThis(xi18nc("@info:whatsthis main view",
2498 "<para>Here you can see the <emphasis>folders</emphasis> and "
2499 "<emphasis>files</emphasis> that are at the location described in "
2500 "the <interface>Location Bar</interface> above. This area is the "
2501 "central part of this application where you navigate to the files "
2502 "you want to use.</para><para>For an elaborate and general "
2503 "introduction to this application <link "
2504 "url='https://userbase.kde.org/Dolphin/File_Management#Introduction_to_Dolphin'>"
2505 "click here</link>. This will open an introductory article from "
2506 "the <emphasis>KDE UserBase Wiki</emphasis>.</para><para>For brief "
2507 "explanations of all the features of this <emphasis>view</emphasis> "
2508 "<link url='help:/dolphin/dolphin-view.html'>click here</link> "
2509 "instead. This will open a page from the <emphasis>Handbook"
2510 "</emphasis> that covers the basics.</para>"));
2513 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings
))
2514 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window "
2515 "that lists the <emphasis>keyboard shortcuts</emphasis>.<nl/>"
2516 "There you can set up key combinations to trigger an action when "
2517 "they are pressed simultaneously. All commands in this application can "
2518 "be triggered this way.</para>"));
2519 actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars
))
2520 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window in which "
2521 "you can change which buttons appear on the <emphasis>Toolbar</emphasis>.</para>"
2522 "<para>All items you see in the <interface>Menu</interface> can also be placed on the Toolbar.</para>"));
2523 actionCollection()->action(KStandardAction::name(KStandardAction::Preferences
))
2524 ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window where you can "
2525 "change a multitude of settings for this application. For an explanation "
2526 "of the various settings go to the chapter <emphasis>Configuring Dolphin"
2527 "</emphasis> in <interface>Help|Dolphin Handbook</interface>."));
2531 // i18n: If the external link isn't available in your language it might make
2532 // sense to state the external link's language in brackets to not
2533 // frustrate the user. If there are multiple languages that the user might
2534 // know with a reasonable chance you might want to have 2 external links.
2535 // The same might be true for any external link you translate.
2536 actionCollection()->action(KStandardAction::name(KStandardAction::HelpContents
))->setWhatsThis(xi18nc("@info:whatsthis handbook", "<para>This opens the Handbook for this application. It provides explanations for every part of <emphasis>Dolphin</emphasis>.</para><para>If you want more elaborate introductions to the different features of <emphasis>Dolphin</emphasis> <link url='https://userbase.kde.org/Dolphin/File_Management'>click here</link>. It will open the dedicated page in the KDE UserBase Wiki.</para>"));
2537 // (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 )
2539 actionCollection()->action(KStandardAction::name(KStandardAction::WhatsThis
))->setWhatsThis(
2540 xi18nc("@info:whatsthis whatsthis button",
2541 "<para>This is the button that invokes the help feature you are "
2542 "using right now! Click it, then click any component of this "
2543 "application to ask \"What's this?\" about it. The mouse cursor "
2544 "will change appearance if no help is available for a spot.</para>"
2545 "<para>There are two other ways to get help: "
2546 "The <link url='help:/dolphin/index.html'>Dolphin Handbook</link> and "
2547 "the <link url='https://userbase.kde.org/Dolphin/File_Management'>KDE "
2548 "UserBase Wiki</link>.</para><para>The \"What's this?\" help is "
2549 "missing in most other windows so don't get too used to this.</para>"));
2551 actionCollection()->action(KStandardAction::name(KStandardAction::ReportBug
))->setWhatsThis(
2552 xi18nc("@info:whatsthis","<para>This opens a "
2553 "window that will guide you through reporting errors or flaws "
2554 "in this application or in other KDE software.</para>"
2555 "<para>High-quality bug reports are much appreciated. To learn "
2556 "how to make your bug report as effective as possible "
2557 "<link url='https://community.kde.org/Get_Involved/Bug_Reporting'>"
2558 "click here</link>.</para>"));
2560 actionCollection()->action(KStandardAction::name(KStandardAction::Donate
))->setWhatsThis(
2561 xi18nc("@info:whatsthis", "<para>This opens a "
2562 "<emphasis>web page</emphasis> where you can donate to "
2563 "support the continued work on this application and many "
2564 "other projects by the <emphasis>KDE</emphasis> community.</para>"
2565 "<para>Donating is the easiest and fastest way to efficiently "
2566 "support KDE and its projects. KDE projects are available for "
2567 "free therefore your donation is needed to cover things that "
2568 "require money like servers, contributor meetings, etc.</para>"
2569 "<para><emphasis>KDE e.V.</emphasis> is the non-profit "
2570 "organization behind the KDE community.</para>"));
2572 actionCollection()->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
))->setWhatsThis(
2573 xi18nc("@info:whatsthis",
2574 "With this you can change the language this application uses."
2575 "<nl/>You can even set secondary languages which will be used "
2576 "if texts are not available in your preferred language."));
2578 actionCollection()->action(KStandardAction::name(KStandardAction::AboutApp
))->setWhatsThis(
2579 xi18nc("@info:whatsthis","This opens a "
2580 "window that informs you about the version, license, "
2581 "used libraries and maintainers of this application."));
2583 actionCollection()->action(KStandardAction::name(KStandardAction::AboutKDE
))->setWhatsThis(
2584 xi18nc("@info:whatsthis","This opens a "
2585 "window with information about <emphasis>KDE</emphasis>. "
2586 "The KDE community are the people behind this free software."
2587 "<nl/>If you like using this application but don't know "
2588 "about KDE or want to see a cute dragon have a look!"));
2591 bool DolphinMainWindow::addHamburgerMenuToToolbar()
2593 QDomDocument domDocument
= KXMLGUIClient::domDocument();
2594 if (domDocument
.isNull()) {
2597 QDomNode toolbar
= domDocument
.elementsByTagName(QStringLiteral("ToolBar")).at(0);
2598 if (toolbar
.isNull()) {
2602 QDomElement hamburgerMenuElement
= domDocument
.createElement(QStringLiteral("Action"));
2603 hamburgerMenuElement
.setAttribute(QStringLiteral("name"), QStringLiteral("hamburger_menu"));
2604 toolbar
.appendChild(hamburgerMenuElement
);
2606 KXMLGUIFactory::saveConfigFile(domDocument
, xmlFile());
2610 // Make sure to also remove the <KXMLGUIFactory> and <QDomDocument> include
2611 // whenever this method is removed (maybe in the year ~2026).
2614 // Set a sane initial window size
2615 QSize
DolphinMainWindow::sizeHint() const
2617 return KXmlGuiWindow::sizeHint().expandedTo(QSize(760, 550));
2620 void DolphinMainWindow::saveNewToolbarConfig()
2622 KXmlGuiWindow::saveNewToolbarConfig(); // Applies the new config. This has to be called first
2623 // because the rest of this method decides things
2624 // based on the new config.
2625 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
2626 (actionCollection()->action(QStringLiteral("url_navigators")));
2627 if (!toolBar()->actions().contains(navigators
)) {
2628 m_tabWidget
->currentTabPage()->insertNavigatorsWidget(navigators
);
2630 updateAllowedToolbarAreas();
2631 (static_cast<KHamburgerMenu
*>(actionCollection()->action(KStandardAction::name(
2632 KStandardAction::HamburgerMenu
))))->hideActionsOf(toolBar());
2635 void DolphinMainWindow::focusTerminalPanel()
2637 if (m_terminalPanel
->isVisible()) {
2638 if (m_terminalPanel
->terminalHasFocus()) {
2639 m_activeViewContainer
->view()->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2640 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2642 m_terminalPanel
->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2643 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2646 actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger();
2647 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2651 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
2652 KIO::FileUndoManager::UiInterface()
2656 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2660 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
2662 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2664 DolphinViewContainer
* container
= mainWin
->activeViewContainer();
2665 container
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
2667 KIO::FileUndoManager::UiInterface::jobError(job
);
2671 bool DolphinMainWindow::isUrlOpen(const QString
&url
)
2673 return m_tabWidget
->isUrlOpen(QUrl::fromUserInput(url
));
2676 bool DolphinMainWindow::isUrlOrParentOpen(const QString
&url
)
2678 return m_tabWidget
->isUrlOrParentOpen(QUrl::fromUserInput(url
));