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());
813 m_backAction
->menu()->addAction(action
);
817 void DolphinMainWindow::slotGoBack(QAction
* action
)
819 int gotoIndex
= action
->data().value
<int>();
820 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
821 for (int i
= gotoIndex
- urlNavigator
->historyIndex(); i
> 0; --i
) {
826 void DolphinMainWindow::slotBackForwardActionMiddleClicked(QAction
* action
)
829 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
830 openNewTab(urlNavigator
->locationUrl(action
->data().value
<int>()));
834 void DolphinMainWindow::slotAboutToShowForwardPopupMenu()
836 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
838 m_forwardAction
->menu()->clear();
839 for (int i
= urlNavigator
->historyIndex() - 1; i
>= 0 && entries
< MaxNumberOfNavigationentries
; --i
, ++entries
) {
840 QAction
*action
= urlNavigatorHistoryAction(urlNavigator
, i
, m_forwardAction
->menu());
841 m_forwardAction
->menu()->addAction(action
);
845 void DolphinMainWindow::slotGoForward(QAction
* action
)
847 int gotoIndex
= action
->data().value
<int>();
848 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
849 for (int i
= urlNavigator
->historyIndex() - gotoIndex
; i
> 0; --i
) {
854 void DolphinMainWindow::slotSetSelectionMode(bool enabled
, SelectionMode::BottomBar::Contents bottomBarContents
)
856 m_activeViewContainer
->setSelectionModeEnabled(enabled
, actionCollection(), bottomBarContents
);
859 void DolphinMainWindow::selectAll()
863 // if the URL navigator is editable and focused, select the whole
864 // URL instead of all items of the view
866 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
867 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit();
868 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
869 lineEdit
->hasFocus();
871 lineEdit
->selectAll();
873 m_activeViewContainer
->view()->selectAll();
877 void DolphinMainWindow::invertSelection()
880 m_activeViewContainer
->view()->invertSelection();
883 void DolphinMainWindow::toggleSplitView()
885 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
886 tabPage
->setSplitViewEnabled(!tabPage
->splitViewEnabled(), WithAnimation
);
891 void DolphinMainWindow::toggleSplitStash()
893 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
894 tabPage
->setSplitViewEnabled(false, WithAnimation
);
895 tabPage
->setSplitViewEnabled(true, WithAnimation
, QUrl("stash:/"));
898 void DolphinMainWindow::copyToInactiveSplitView()
900 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
901 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CopyToOtherViewContents
);
903 m_tabWidget
->copyToInactiveSplitView();
904 m_activeViewContainer
->setSelectionModeEnabled(false);
908 void DolphinMainWindow::moveToInactiveSplitView()
910 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
911 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::MoveToOtherViewContents
);
913 m_tabWidget
->moveToInactiveSplitView();
914 m_activeViewContainer
->setSelectionModeEnabled(false);
918 void DolphinMainWindow::reloadView()
921 m_activeViewContainer
->reload();
922 m_activeViewContainer
->statusBar()->updateSpaceInfo();
925 void DolphinMainWindow::stopLoading()
927 m_activeViewContainer
->view()->stopLoading();
930 void DolphinMainWindow::enableStopAction()
932 actionCollection()->action(QStringLiteral("stop"))->setEnabled(true);
935 void DolphinMainWindow::disableStopAction()
937 actionCollection()->action(QStringLiteral("stop"))->setEnabled(false);
940 void DolphinMainWindow::toggleSelectionMode()
942 const bool checked
= !m_activeViewContainer
->isSelectionModeEnabled();
944 m_activeViewContainer
->setSelectionModeEnabled(checked
, actionCollection(), SelectionMode::BottomBar::Contents::GeneralContents
);
945 actionCollection()->action(QStringLiteral("toggle_selection_mode"))->setChecked(checked
);
948 void DolphinMainWindow::showFilterBar()
950 m_activeViewContainer
->setFilterBarVisible(true);
953 void DolphinMainWindow::toggleFilterBar()
955 const bool checked
= !m_activeViewContainer
->isFilterBarVisible();
956 m_activeViewContainer
->setFilterBarVisible(checked
);
958 QAction
* toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
959 toggleFilterBarAction
->setChecked(checked
);
962 void DolphinMainWindow::toggleEditLocation()
966 QAction
* action
= actionCollection()->action(QStringLiteral("editable_location"));
967 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
968 urlNavigator
->setUrlEditable(action
->isChecked());
971 void DolphinMainWindow::replaceLocation()
973 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
974 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit();
976 // If the text field currently has focus and everything is selected,
977 // pressing the keyboard shortcut returns the whole thing to breadcrumb mode
978 if (navigator
->isUrlEditable()
979 && lineEdit
->hasFocus()
980 && lineEdit
->selectedText() == lineEdit
->text() ) {
981 navigator
->setUrlEditable(false);
983 navigator
->setUrlEditable(true);
984 navigator
->setFocus();
985 lineEdit
->selectAll();
989 void DolphinMainWindow::togglePanelLockState()
991 const bool newLockState
= !GeneralSettings::lockPanels();
992 const auto childrenObjects
= children();
993 for (QObject
* child
: childrenObjects
) {
994 DolphinDockWidget
* dock
= qobject_cast
<DolphinDockWidget
*>(child
);
996 dock
->setLocked(newLockState
);
1000 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(newLockState
);
1002 GeneralSettings::setLockPanels(newLockState
);
1005 void DolphinMainWindow::slotTerminalPanelVisibilityChanged()
1007 if (m_terminalPanel
->isHiddenInVisibleWindow() && m_activeViewContainer
) {
1008 m_activeViewContainer
->view()->setFocus();
1012 void DolphinMainWindow::goBack()
1014 DolphinUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
1015 urlNavigator
->goBack();
1017 if (urlNavigator
->locationState().isEmpty()) {
1018 // An empty location state indicates a redirection URL,
1019 // which must be skipped too
1020 urlNavigator
->goBack();
1024 void DolphinMainWindow::goForward()
1026 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goForward();
1029 void DolphinMainWindow::goUp()
1031 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goUp();
1034 void DolphinMainWindow::goHome()
1036 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goHome();
1039 void DolphinMainWindow::goBackInNewTab()
1041 const KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
1042 const int index
= urlNavigator
->historyIndex() + 1;
1043 openNewTab(urlNavigator
->locationUrl(index
));
1046 void DolphinMainWindow::goForwardInNewTab()
1048 const KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
1049 const int index
= urlNavigator
->historyIndex() - 1;
1050 openNewTab(urlNavigator
->locationUrl(index
));
1053 void DolphinMainWindow::goUpInNewTab()
1055 const QUrl currentUrl
= activeViewContainer()->urlNavigator()->locationUrl();
1056 openNewTab(KIO::upUrl(currentUrl
));
1059 void DolphinMainWindow::goHomeInNewTab()
1061 openNewTab(Dolphin::homeUrl());
1064 void DolphinMainWindow::compareFiles()
1066 const KFileItemList items
= m_tabWidget
->currentTabPage()->selectedItems();
1067 if (items
.count() != 2) {
1068 // The action is disabled in this case, but it could have been triggered
1069 // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
1073 QUrl urlA
= items
.at(0).url();
1074 QUrl urlB
= items
.at(1).url();
1076 QString
command(QStringLiteral("kompare -c \""));
1077 command
.append(urlA
.toDisplayString(QUrl::PreferLocalFile
));
1078 command
.append("\" \"");
1079 command
.append(urlB
.toDisplayString(QUrl::PreferLocalFile
));
1080 command
.append('\"');
1082 KIO::CommandLauncherJob
*job
= new KIO::CommandLauncherJob(command
, this);
1083 job
->setDesktopName(QStringLiteral("org.kde.kompare"));
1087 void DolphinMainWindow::toggleShowMenuBar()
1089 const bool visible
= menuBar()->isVisible();
1090 menuBar()->setVisible(!visible
);
1093 QPointer
<QAction
> DolphinMainWindow::preferredSearchTool()
1095 m_searchTools
.clear();
1096 KMoreToolsMenuFactory("dolphin/search-tools").fillMenuFromGroupingNames(
1097 &m_searchTools
, { "files-find" }, m_activeViewContainer
->url()
1099 QList
<QAction
*> actions
= m_searchTools
.actions();
1100 if (actions
.isEmpty()) {
1103 QAction
* action
= actions
.first();
1104 if (action
->isSeparator()) {
1110 void DolphinMainWindow::updateOpenPreferredSearchToolAction()
1112 QAction
* openPreferredSearchTool
= actionCollection()->action(QStringLiteral("open_preferred_search_tool"));
1113 if (!openPreferredSearchTool
) {
1116 QPointer
<QAction
> tool
= preferredSearchTool();
1118 openPreferredSearchTool
->setVisible(true);
1119 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open %1", tool
->text()));
1120 // Only override with the app icon if it is the default, i.e. the user hasn't configured one manually
1121 // https://bugs.kde.org/show_bug.cgi?id=442815
1122 if (openPreferredSearchTool
->icon().name() == QLatin1String("search")) {
1123 openPreferredSearchTool
->setIcon(tool
->icon());
1126 openPreferredSearchTool
->setVisible(false);
1127 // still visible in Shortcuts configuration window
1128 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1129 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1133 void DolphinMainWindow::openPreferredSearchTool()
1135 QPointer
<QAction
> tool
= preferredSearchTool();
1141 void DolphinMainWindow::openTerminal()
1143 openTerminalJob(m_activeViewContainer
->url());
1146 void DolphinMainWindow::openTerminalHere()
1148 QList
<QUrl
> urls
= {};
1150 for (const KFileItem
& item
: m_activeViewContainer
->view()->selectedItems()) {
1151 QUrl url
= item
.targetUrl();
1152 if (item
.isFile()) {
1153 url
.setPath(QFileInfo(url
.path()).absolutePath());
1155 if (!urls
.contains(url
)) {
1160 // No items are selected. Open a terminal window for the current location.
1161 if (urls
.count() == 0) {
1166 if (urls
.count() > 5) {
1167 QString question
= i18np("Are you sure you want to open 1 terminal window?",
1168 "Are you sure you want to open %1 terminal windows?", urls
.count());
1169 const int answer
= KMessageBox::warningYesNo(this, question
, {},
1170 KGuiItem(i18ncp("@action:button", "Open %1 Terminal", "Open %1 Terminals", urls
.count()),
1171 QStringLiteral("utilities-terminal")),
1172 KStandardGuiItem::cancel());
1173 if (answer
!= KMessageBox::Yes
) {
1178 for (const QUrl
& url
: urls
) {
1179 openTerminalJob(url
);
1183 void DolphinMainWindow::openTerminalJob(const QUrl
& url
)
1185 if (url
.isLocalFile()) {
1186 auto job
= new KTerminalLauncherJob(QString());
1187 job
->setWorkingDirectory(url
.toLocalFile());
1192 // Not a local file, with protocol Class ":local", try stat'ing
1193 if (KProtocolInfo::protocolClass(url
.scheme()) == QLatin1String(":local")) {
1194 KIO::StatJob
*job
= KIO::mostLocalUrl(url
);
1195 KJobWidgets::setWindow(job
, this);
1196 connect(job
, &KJob::result
, this, [job
]() {
1198 if (!job
->error()) {
1199 statUrl
= job
->mostLocalUrl();
1202 auto job
= new KTerminalLauncherJob(QString());
1203 job
->setWorkingDirectory(statUrl
.isLocalFile() ? statUrl
.toLocalFile() : QDir::homePath());
1210 // Nothing worked, just use $HOME
1211 auto job
= new KTerminalLauncherJob(QString());
1212 job
->setWorkingDirectory(QDir::homePath());
1216 void DolphinMainWindow::editSettings()
1218 if (!m_settingsDialog
) {
1219 DolphinViewContainer
* container
= activeViewContainer();
1220 container
->view()->writeSettings();
1222 const QUrl url
= container
->url();
1223 DolphinSettingsDialog
* settingsDialog
= new DolphinSettingsDialog(url
, this, actionCollection());
1224 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, this, &DolphinMainWindow::refreshViews
);
1225 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
,
1226 &DolphinUrlNavigatorsController::slotReadSettings
);
1227 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1228 settingsDialog
->show();
1229 m_settingsDialog
= settingsDialog
;
1231 m_settingsDialog
.data()->raise();
1235 void DolphinMainWindow::handleUrl(const QUrl
& url
)
1237 delete m_lastHandleUrlOpenJob
;
1238 m_lastHandleUrlOpenJob
= nullptr;
1240 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1241 activeViewContainer()->setUrl(url
);
1243 m_lastHandleUrlOpenJob
= new KIO::OpenUrlJob(url
);
1244 m_lastHandleUrlOpenJob
->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
1245 m_lastHandleUrlOpenJob
->setShowOpenOrExecuteDialog(true);
1247 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::mimeTypeFound
, this,
1248 [this, url
](const QString
&mimetype
) {
1249 if (mimetype
== QLatin1String("inode/directory")) {
1250 // If it's a dir, we'll take it from here
1251 m_lastHandleUrlOpenJob
->kill();
1252 m_lastHandleUrlOpenJob
= nullptr;
1253 activeViewContainer()->setUrl(url
);
1257 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::result
, this, [this]() {
1258 m_lastHandleUrlOpenJob
= nullptr;
1261 m_lastHandleUrlOpenJob
->start();
1265 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1267 // trash:/ is writable but we don't want to create new items in it.
1268 // TODO: remove the trash check once https://phabricator.kde.org/T8234 is implemented
1269 newFileMenu()->setEnabled(isFolderWritable
&& m_activeViewContainer
->url().scheme() != QLatin1String("trash"));
1272 void DolphinMainWindow::openContextMenu(const QPoint
& pos
,
1273 const KFileItem
& item
,
1274 const KFileItemList
&selectedItems
,
1277 QPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, item
, selectedItems
, url
, &m_fileItemActions
);
1278 contextMenu
.data()->exec(pos
);
1280 // Delete the menu, unless it has been deleted in its own nested event loop already.
1282 contextMenu
->deleteLater();
1286 QMenu
*DolphinMainWindow::createPopupMenu()
1288 QMenu
*menu
= KXmlGuiWindow::createPopupMenu();
1290 menu
->addSeparator();
1291 menu
->addAction(actionCollection()->action(QStringLiteral("lock_panels")));
1296 void DolphinMainWindow::updateHamburgerMenu()
1298 KActionCollection
* ac
= actionCollection();
1299 auto hamburgerMenu
= static_cast<KHamburgerMenu
*>(
1300 ac
->action(KStandardAction::name(KStandardAction::HamburgerMenu
)));
1301 auto menu
= hamburgerMenu
->menu();
1303 menu
= new QMenu(this);
1304 hamburgerMenu
->setMenu(menu
);
1305 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("basic_actions"))->menu());
1306 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("zoom"))->menu());
1310 const QList
<QAction
*> toolbarActions
= toolBar()->actions();
1312 if (!toolBar()->isVisible()) {
1313 // If neither the menu bar nor the toolbar are visible, these actions should be available.
1314 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)));
1315 menu
->addAction(toolBarMenuAction());
1316 menu
->addSeparator();
1319 // This group of actions (until the next separator) contains all the most basic actions
1320 // necessary to use Dolphin effectively.
1321 menu
->addAction(ac
->action(QStringLiteral("go_back")));
1322 menu
->addAction(ac
->action(QStringLiteral("go_forward")));
1324 menu
->addMenu(m_newFileMenu
->menu());
1325 if (!toolBar()->isVisible()
1326 || !toolbarActions
.contains(ac
->action(QStringLiteral("toggle_selection_mode_tool_bar")))
1328 menu
->addAction(ac
->action(QStringLiteral("toggle_selection_mode")));
1330 menu
->addAction(ac
->action(QStringLiteral("basic_actions")));
1331 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Undo
)));
1332 if (!toolBar()->isVisible()
1333 || (!toolbarActions
.contains(ac
->action(QStringLiteral("toggle_search")))
1334 && !toolbarActions
.contains(ac
->action(QStringLiteral("open_preferred_search_tool"))))
1336 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Find
)));
1337 // This way a search action will only be added if none of the three available
1338 // search actions is present on the toolbar.
1340 if (!toolBar()->isVisible()
1341 || !toolbarActions
.contains(ac
->action(QStringLiteral("toggle_filter")))
1343 menu
->addAction(ac
->action(QStringLiteral("show_filter_bar")));
1344 // This way a filter action will only be added if none of the two available
1345 // filter actions is present on the toolbar.
1347 menu
->addSeparator();
1349 // The second group of actions (up until the next separator) contains actions for opening
1350 // additional views to interact with the file system.
1351 menu
->addAction(ac
->action(QStringLiteral("file_new")));
1352 menu
->addAction(ac
->action(QStringLiteral("new_tab")));
1353 if (ac
->action(QStringLiteral("undo_close_tab"))->isEnabled()) {
1354 menu
->addAction(ac
->action(QStringLiteral("closed_tabs")));
1356 menu
->addAction(ac
->action(QStringLiteral("open_terminal")));
1357 menu
->addSeparator();
1359 // The third group contains actions to change what one sees in the view
1360 // and to change the more general UI.
1361 if (!toolBar()->isVisible()
1362 || (!toolbarActions
.contains(ac
->action(QStringLiteral("icons")))
1363 && !toolbarActions
.contains(ac
->action(QStringLiteral("compact")))
1364 && !toolbarActions
.contains(ac
->action(QStringLiteral("details")))
1365 && !toolbarActions
.contains(ac
->action(QStringLiteral("view_mode"))))
1367 menu
->addAction(ac
->action(QStringLiteral("view_mode")));
1369 menu
->addAction(ac
->action(QStringLiteral("show_hidden_files")));
1370 menu
->addAction(ac
->action(QStringLiteral("sort")));
1371 menu
->addAction(ac
->action(QStringLiteral("additional_info")));
1372 if (!GeneralSettings::showStatusBar() || !GeneralSettings::showZoomSlider()) {
1373 menu
->addAction(ac
->action(QStringLiteral("zoom")));
1375 menu
->addAction(ac
->action(QStringLiteral("panels")));
1377 // The "Configure" menu is not added to the actionCollection() because there is hardly
1378 // a good reason for users to put it on their toolbar.
1379 auto configureMenu
= menu
->addMenu(QIcon::fromTheme(QStringLiteral("configure")),
1380 i18nc("@action:inmenu menu for configure actions", "Configure"));
1381 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
)));
1382 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)));
1383 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)));
1384 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Preferences
)));
1385 hamburgerMenu
->hideActionsOf(configureMenu
);
1388 void DolphinMainWindow::slotPlaceActivated(const QUrl
& url
)
1390 DolphinViewContainer
* view
= activeViewContainer();
1392 if (view
->url() == url
) {
1393 // We can end up here if the user clicked a device in the Places Panel
1394 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
1397 view
->disableUrlNavigatorSelectionRequests();
1399 view
->enableUrlNavigatorSelectionRequests();
1403 void DolphinMainWindow::closedTabsCountChanged(unsigned int count
)
1405 actionCollection()->action(QStringLiteral("undo_close_tab"))->setEnabled(count
> 0);
1408 void DolphinMainWindow::activeViewChanged(DolphinViewContainer
* viewContainer
)
1410 DolphinViewContainer
* oldViewContainer
= m_activeViewContainer
;
1411 Q_ASSERT(viewContainer
);
1413 m_activeViewContainer
= viewContainer
;
1415 if (oldViewContainer
) {
1416 const QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
1417 toggleSearchAction
->disconnect(oldViewContainer
);
1419 // Disconnect all signals between the old view container (container,
1420 // view and url navigator) and main window.
1421 oldViewContainer
->disconnect(this);
1422 oldViewContainer
->view()->disconnect(this);
1423 oldViewContainer
->urlNavigatorInternalWithHistory()->disconnect(this);
1424 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
1425 (actionCollection()->action(QStringLiteral("url_navigators")));
1426 navigators
->primaryUrlNavigator()->disconnect(this);
1427 if (auto secondaryUrlNavigator
= navigators
->secondaryUrlNavigator()) {
1428 secondaryUrlNavigator
->disconnect(this);
1431 // except the requestItemInfo so that on hover the information panel can still be updated
1432 connect(oldViewContainer
->view(), &DolphinView::requestItemInfo
,
1433 this, &DolphinMainWindow::requestItemInfo
);
1435 // Disconnect other slots.
1436 disconnect(nullptr, &DolphinViewContainer::selectionModeChanged
,
1437 actionCollection()->action(QStringLiteral("toggle_selection_mode")), &QAction::setChecked
);
1440 connectViewSignals(viewContainer
);
1442 m_actionHandler
->setCurrentView(viewContainer
->view());
1445 updateFileAndEditActions();
1446 updatePasteAction();
1447 updateViewActions();
1449 updateSearchAction();
1451 const QUrl url
= viewContainer
->url();
1452 Q_EMIT
urlChanged(url
);
1455 void DolphinMainWindow::tabCountChanged(int count
)
1457 const bool enableTabActions
= (count
> 1);
1458 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1459 actionCollection()->action(QStringLiteral("activate_tab_%1").arg(i
))->setEnabled(enableTabActions
);
1461 actionCollection()->action(QStringLiteral("activate_last_tab"))->setEnabled(enableTabActions
);
1462 actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions
);
1463 actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions
);
1466 void DolphinMainWindow::updateWindowTitle()
1468 const QString newTitle
= m_activeViewContainer
->captionWindowTitle();
1469 if (windowTitle() != newTitle
) {
1470 setWindowTitle(newTitle
);
1474 void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString
& mountPath
)
1476 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1477 setViewsToHomeIfMountPathOpen(mountPath
);
1480 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectory().startsWith(mountPath
)) {
1481 m_tearDownFromPlacesRequested
= true;
1482 m_terminalPanel
->goHome();
1483 // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged
1485 m_placesPanel
->proceedWithTearDown();
1489 void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString
& mountPath
)
1491 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1492 setViewsToHomeIfMountPathOpen(mountPath
);
1495 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectory().startsWith(mountPath
)) {
1496 m_tearDownFromPlacesRequested
= false;
1497 m_terminalPanel
->goHome();
1501 void DolphinMainWindow::slotKeyBindings()
1503 KShortcutsDialog
dialog(KShortcutsEditor::AllActions
, KShortcutsEditor::LetterShortcutsAllowed
, this);
1504 dialog
.addCollection(actionCollection());
1505 if (m_terminalPanel
) {
1506 KActionCollection
*konsolePartActionCollection
= m_terminalPanel
->actionCollection();
1507 if (konsolePartActionCollection
) {
1508 dialog
.addCollection(konsolePartActionCollection
, QStringLiteral("KonsolePart"));
1514 void DolphinMainWindow::setViewsToHomeIfMountPathOpen(const QString
& mountPath
)
1516 const QVector
<DolphinViewContainer
*> theViewContainers
= viewContainers();
1517 for (DolphinViewContainer
*viewContainer
: theViewContainers
) {
1518 if (viewContainer
&& viewContainer
->url().toLocalFile().startsWith(mountPath
)) {
1519 viewContainer
->setUrl(QUrl::fromLocalFile(QDir::homePath()));
1522 disconnect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, nullptr, nullptr);
1525 void DolphinMainWindow::setupActions()
1527 auto hamburgerMenuAction
= KStandardAction::hamburgerMenu(nullptr, nullptr, actionCollection());
1529 // setup 'File' menu
1530 m_newFileMenu
= new DolphinNewFileMenu(actionCollection(), this);
1531 QMenu
* menu
= m_newFileMenu
->menu();
1532 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1533 menu
->setIcon(QIcon::fromTheme(QStringLiteral("list-add")));
1534 m_newFileMenu
->setPopupMode(QToolButton::InstantPopup
);
1535 connect(menu
, &QMenu::aboutToShow
,
1536 this, &DolphinMainWindow::updateNewMenu
);
1538 QAction
* newWindow
= KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow
, actionCollection());
1539 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1540 newWindow
->setToolTip(i18nc("@info", "Open a new Dolphin window"));
1541 newWindow
->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1542 "window just like this one with the current location and view."
1543 "<nl/>You can drag and drop items between windows."));
1544 newWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1546 QAction
* newTab
= actionCollection()->addAction(QStringLiteral("new_tab"));
1547 newTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1548 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1549 newTab
->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1550 "<emphasis>Tab</emphasis> with the current location and view.<nl/>"
1551 "A tab is an additional view within this window. "
1552 "You can drag and drop items between tabs."));
1553 actionCollection()->setDefaultShortcuts(newTab
, {Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
});
1554 connect(newTab
, &QAction::triggered
, this, &DolphinMainWindow::openNewActivatedTab
);
1556 QAction
* addToPlaces
= actionCollection()->addAction(QStringLiteral("add_to_places"));
1557 addToPlaces
->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new")));
1558 addToPlaces
->setText(i18nc("@action:inmenu Add current folder to places", "Add to Places"));
1559 addToPlaces
->setWhatsThis(xi18nc("@info:whatsthis", "This adds the selected folder "
1560 "to the Places panel."));
1561 connect(addToPlaces
, &QAction::triggered
, this, &DolphinMainWindow::addToPlaces
);
1563 QAction
* closeTab
= KStandardAction::close(m_tabWidget
, QOverload
<>::of(&DolphinTabWidget::closeTab
), actionCollection());
1564 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1565 closeTab
->setWhatsThis(i18nc("@info:whatsthis", "This closes the "
1566 "currently viewed tab. If no more tabs are left this window "
1567 "will close instead."));
1569 QAction
* quitAction
= KStandardAction::quit(this, &DolphinMainWindow::quit
, actionCollection());
1570 quitAction
->setWhatsThis(i18nc("@info:whatsthis quit", "This closes this window."));
1572 // setup 'Edit' menu
1573 KStandardAction::undo(this,
1574 &DolphinMainWindow::undo
,
1575 actionCollection());
1577 // i18n: This will be the last paragraph for the whatsthis for all three:
1578 // Cut, Copy and Paste
1579 const QString cutCopyPastePara
= xi18nc("@info:whatsthis", "<para><emphasis>Cut, "
1580 "Copy</emphasis> and <emphasis>Paste</emphasis> work between many "
1581 "applications and are among the most used commands. That's why their "
1582 "<emphasis>keyboard shortcuts</emphasis> are prominently placed right "
1583 "next to each other on the keyboard: <shortcut>Ctrl+X</shortcut>, "
1584 "<shortcut>Ctrl+C</shortcut> and <shortcut>Ctrl+V</shortcut>.</para>");
1585 QAction
* cutAction
= KStandardAction::cut(this, &DolphinMainWindow::cut
, actionCollection());
1586 m_actionTextHelper
->registerTextWhenNothingIsSelected(cutAction
, i18nc("@action", "Cut…"));
1587 cutAction
->setWhatsThis(xi18nc("@info:whatsthis cut", "This copies the items "
1588 "in your current selection to the <emphasis>clipboard</emphasis>.<nl/>"
1589 "Use the <emphasis>Paste</emphasis> action afterwards to copy them from "
1590 "the clipboard to a new location. The items will be removed from their "
1591 "initial location.") + cutCopyPastePara
);
1592 QAction
* copyAction
= KStandardAction::copy(this, &DolphinMainWindow::copy
, actionCollection());
1593 m_actionTextHelper
->registerTextWhenNothingIsSelected(copyAction
, i18nc("@action", "Copy…"));
1594 copyAction
->setWhatsThis(xi18nc("@info:whatsthis copy", "This copies the "
1595 "items in your current selection to the <emphasis>clipboard</emphasis>."
1596 "<nl/>Use the <emphasis>Paste</emphasis> action afterwards to copy them "
1597 "from the clipboard to a new location.") + cutCopyPastePara
);
1598 QAction
* paste
= KStandardAction::paste(this, &DolphinMainWindow::paste
, actionCollection());
1599 // The text of the paste-action is modified dynamically by Dolphin
1600 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1601 // due to the long text, the text "Paste" is used:
1602 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1603 paste
->setWhatsThis(xi18nc("@info:whatsthis paste", "This copies the items from "
1604 "your <emphasis>clipboard</emphasis> to the currently viewed folder.<nl/>"
1605 "If the items were added to the clipboard by the <emphasis>Cut</emphasis> "
1606 "action they are removed from their old location.") + cutCopyPastePara
);
1608 QAction
* copyToOtherViewAction
= actionCollection()->addAction(QStringLiteral("copy_to_inactive_split_view"));
1609 copyToOtherViewAction
->setText(i18nc("@action:inmenu", "Copy to Inactive Split View"));
1610 m_actionTextHelper
->registerTextWhenNothingIsSelected(copyToOtherViewAction
, i18nc("@action:inmenu", "Copy to Inactive Split View…"));
1611 copyToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Copy", "This copies the selected items from "
1612 "the <emphasis>active</emphasis> view to the inactive split view."));
1613 copyToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
1614 copyToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Copy to Inactive Split View"));
1615 actionCollection()->setDefaultShortcut(copyToOtherViewAction
, Qt::SHIFT
| Qt::Key_F5
);
1616 connect(copyToOtherViewAction
, &QAction::triggered
, this, &DolphinMainWindow::copyToInactiveSplitView
);
1618 QAction
* moveToOtherViewAction
= actionCollection()->addAction(QStringLiteral("move_to_inactive_split_view"));
1619 moveToOtherViewAction
->setText(i18nc("@action:inmenu", "Move to Inactive Split View"));
1620 m_actionTextHelper
->registerTextWhenNothingIsSelected(moveToOtherViewAction
, i18nc("@action:inmenu", "Move to Inactive Split View…"));
1621 moveToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Move", "This moves the selected items from "
1622 "the <emphasis>active</emphasis> view to the inactive split view."));
1623 moveToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-cut")));
1624 moveToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Move to Inactive Split View"));
1625 actionCollection()->setDefaultShortcut(moveToOtherViewAction
, Qt::SHIFT
| Qt::Key_F6
);
1626 connect(moveToOtherViewAction
, &QAction::triggered
, this, &DolphinMainWindow::moveToInactiveSplitView
);
1628 QAction
* showFilterBar
= actionCollection()->addAction(QStringLiteral("show_filter_bar"));
1629 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Filter..."));
1630 showFilterBar
->setToolTip(i18nc("@info:tooltip", "Show Filter Bar"));
1631 showFilterBar
->setWhatsThis(xi18nc("@info:whatsthis", "This opens the "
1632 "<emphasis>Filter Bar</emphasis> at the bottom of the window.<nl/> "
1633 "There you can enter a text to filter the files and folders currently displayed. "
1634 "Only those that contain the text in their name will be kept in view."));
1635 showFilterBar
->setIcon(QIcon::fromTheme(QStringLiteral("view-filter")));
1636 actionCollection()->setDefaultShortcuts(showFilterBar
, {Qt::CTRL
| Qt::Key_I
, Qt::Key_Slash
});
1637 connect(showFilterBar
, &QAction::triggered
, this, &DolphinMainWindow::showFilterBar
);
1639 // toggle_filter acts as a copy of the main showFilterBar to be used mainly
1640 // in the toolbar, with no default shortcut attached, to avoid messing with
1641 // existing workflows (filter bar always open and Ctrl-I to focus)
1642 QAction
*toggleFilter
= actionCollection()->addAction(QStringLiteral("toggle_filter"));
1643 toggleFilter
->setText(i18nc("@action:inmenu", "Toggle Filter Bar"));
1644 toggleFilter
->setIconText(i18nc("@action:intoolbar", "Filter"));
1645 toggleFilter
->setIcon(showFilterBar
->icon());
1646 toggleFilter
->setToolTip(showFilterBar
->toolTip());
1647 toggleFilter
->setWhatsThis(showFilterBar
->whatsThis());
1648 toggleFilter
->setCheckable(true);
1649 connect(toggleFilter
, &QAction::triggered
, this, &DolphinMainWindow::toggleFilterBar
);
1651 QAction
*searchAction
= KStandardAction::find(this, &DolphinMainWindow::find
, actionCollection());
1652 searchAction
->setText(i18n("Search..."));
1653 searchAction
->setToolTip(i18nc("@info:tooltip", "Search for files and folders"));
1654 searchAction
->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This helps you "
1655 "find files and folders by opening a <emphasis>find bar</emphasis>. "
1656 "There you can enter search terms and specify settings to find the "
1657 "objects you are looking for.</para><para>Use this help again on "
1658 "the find bar so we can have a look at it while the settings are "
1659 "explained.</para>"));
1661 // toggle_search acts as a copy of the main searchAction to be used mainly
1662 // in the toolbar, with no default shortcut attached, to avoid messing with
1663 // existing workflows (search bar always open and Ctrl-F to focus)
1664 QAction
*toggleSearchAction
= actionCollection()->addAction(QStringLiteral("toggle_search"));
1665 toggleSearchAction
->setText(i18nc("@action:inmenu", "Toggle Search Bar"));
1666 toggleSearchAction
->setIconText(i18nc("@action:intoolbar", "Search"));
1667 toggleSearchAction
->setIcon(searchAction
->icon());
1668 toggleSearchAction
->setToolTip(searchAction
->toolTip());
1669 toggleSearchAction
->setWhatsThis(searchAction
->whatsThis());
1670 toggleSearchAction
->setCheckable(true);
1672 QAction
*toggleSelectionModeAction
= actionCollection()->addAction(QStringLiteral("toggle_selection_mode"));
1673 // i18n: This action toggles a selection mode.
1674 toggleSelectionModeAction
->setText(i18nc("@action:inmenu", "Select Files and Folders"));
1675 // i18n: Opens a selection mode for selecting files/folders.
1676 // The text is kept so unspecific because it will be shown on the toolbar where space is at a premium.
1677 toggleSelectionModeAction
->setIconText(i18nc("@action:intoolbar", "Select"));
1678 toggleSelectionModeAction
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This application only knows which files or folders should be acted on if they are"
1679 " <emphasis>selected</emphasis> first. Press this to toggle a <emphasis>Selection Mode</emphasis> which makes selecting and deselecting as easy as "
1680 "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."
1682 toggleSelectionModeAction
->setIcon(QIcon::fromTheme(QStringLiteral("quickwizard")));
1683 toggleSelectionModeAction
->setCheckable(true);
1684 actionCollection()->setDefaultShortcut(toggleSelectionModeAction
, Qt::Key_Space
);
1685 connect(toggleSelectionModeAction
, &QAction::triggered
, this, &DolphinMainWindow::toggleSelectionMode
);
1687 // A special version of the toggleSelectionModeAction for the toolbar that also contains a menu
1688 // with the selectAllAction and invertSelectionAction.
1689 auto *toggleSelectionModeToolBarAction
= new KToolBarPopupAction(toggleSelectionModeAction
->icon(), toggleSelectionModeAction
->iconText(), actionCollection());
1690 toggleSelectionModeToolBarAction
->setToolTip(toggleSelectionModeAction
->text());
1691 toggleSelectionModeToolBarAction
->setWhatsThis(toggleSelectionModeAction
->whatsThis());
1692 actionCollection()->addAction(QStringLiteral("toggle_selection_mode_tool_bar"), toggleSelectionModeToolBarAction
);
1693 toggleSelectionModeToolBarAction
->setCheckable(true);
1694 toggleSelectionModeToolBarAction
->setPopupMode(QToolButton::DelayedPopup
);
1695 connect(toggleSelectionModeToolBarAction
, &QAction::triggered
, toggleSelectionModeAction
, &QAction::trigger
);
1696 connect(toggleSelectionModeAction
, &QAction::toggled
, toggleSelectionModeToolBarAction
, &QAction::setChecked
);
1698 QAction
* selectAllAction
= KStandardAction::selectAll(this, &DolphinMainWindow::selectAll
, actionCollection());
1699 selectAllAction
->setWhatsThis(xi18nc("@info:whatsthis", "This selects all "
1700 "files and folders in the current location."));
1702 QAction
* invertSelection
= actionCollection()->addAction(QStringLiteral("invert_selection"));
1703 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1704 invertSelection
->setWhatsThis(xi18nc("@info:whatsthis invert", "This selects all "
1705 "objects that you have currently <emphasis>not</emphasis> selected instead."));
1706 invertSelection
->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-invert")));
1707 actionCollection()->setDefaultShortcut(invertSelection
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1708 connect(invertSelection
, &QAction::triggered
, this, &DolphinMainWindow::invertSelection
);
1710 QMenu
*toggleSelectionModeActionMenu
= new QMenu(this);
1711 toggleSelectionModeActionMenu
->addAction(selectAllAction
);
1712 toggleSelectionModeActionMenu
->addAction(invertSelection
);
1713 toggleSelectionModeToolBarAction
->setMenu(toggleSelectionModeActionMenu
);
1715 // setup 'View' menu
1716 // (note that most of it is set up in DolphinViewActionHandler)
1718 QAction
* split
= actionCollection()->addAction(QStringLiteral("split_view"));
1719 split
->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This splits "
1720 "the folder view below into two autonomous views.</para><para>This "
1721 "way you can see two locations at once and move items between them "
1722 "quickly.</para>Click this again afterwards to recombine the views."));
1723 actionCollection()->setDefaultShortcut(split
, Qt::Key_F3
);
1724 connect(split
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitView
);
1726 QAction
* stashSplit
= actionCollection()->addAction(QStringLiteral("split_stash"));
1727 actionCollection()->setDefaultShortcut(stashSplit
, Qt::CTRL
| Qt::Key_S
);
1728 stashSplit
->setText(i18nc("@action:intoolbar Stash", "Stash"));
1729 stashSplit
->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
1730 stashSplit
->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
1731 stashSplit
->setCheckable(false);
1732 QDBusConnectionInterface
*sessionInterface
= QDBusConnection::sessionBus().interface();
1733 stashSplit
->setVisible(sessionInterface
&& sessionInterface
->isServiceRegistered(QStringLiteral("org.kde.kio.StashNotifier")));
1734 connect(stashSplit
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitStash
);
1736 KStandardAction::redisplay(this, &DolphinMainWindow::reloadView
, actionCollection());
1738 QAction
* stop
= actionCollection()->addAction(QStringLiteral("stop"));
1739 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1740 stop
->setToolTip(i18nc("@info", "Stop loading"));
1741 stop
->setWhatsThis(i18nc("@info", "This stops the loading of the contents of the current folder."));
1742 stop
->setIcon(QIcon::fromTheme(QStringLiteral("process-stop")));
1743 connect(stop
, &QAction::triggered
, this, &DolphinMainWindow::stopLoading
);
1745 KToggleAction
* editableLocation
= actionCollection()->add
<KToggleAction
>(QStringLiteral("editable_location"));
1746 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1747 editableLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1748 "This toggles the <emphasis>Location Bar</emphasis> to be "
1749 "editable so you can directly enter a location you want to go to.<nl/>"
1750 "You can also switch to editing by clicking to the right of the "
1751 "location and switch back by confirming the edited location."));
1752 actionCollection()->setDefaultShortcut(editableLocation
, Qt::Key_F6
);
1753 connect(editableLocation
, &KToggleAction::triggered
, this, &DolphinMainWindow::toggleEditLocation
);
1755 QAction
* replaceLocation
= actionCollection()->addAction(QStringLiteral("replace_location"));
1756 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1757 // i18n: "enter" is used both in the meaning of "writing" and "going to" a new location here.
1758 // Both meanings are useful but not necessary to understand the use of "Replace Location".
1759 // So you might want to be more verbose in your language to convey the meaning but it's up to you.
1760 replaceLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1761 "This switches to editing the location and selects it "
1762 "so you can quickly enter a different location."));
1763 actionCollection()->setDefaultShortcut(replaceLocation
, Qt::CTRL
| Qt::Key_L
);
1764 connect(replaceLocation
, &QAction::triggered
, this, &DolphinMainWindow::replaceLocation
);
1768 QScopedPointer
<QAction
> backAction(KStandardAction::back(nullptr, nullptr, nullptr));
1769 m_backAction
= new KToolBarPopupAction(backAction
->icon(), backAction
->text(), actionCollection());
1770 m_backAction
->setObjectName(backAction
->objectName());
1771 m_backAction
->setShortcuts(backAction
->shortcuts());
1773 m_backAction
->setPopupMode(QToolButton::DelayedPopup
);
1774 connect(m_backAction
, &QAction::triggered
, this, &DolphinMainWindow::goBack
);
1775 connect(m_backAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowBackPopupMenu
);
1776 connect(m_backAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoBack
);
1777 actionCollection()->addAction(m_backAction
->objectName(), m_backAction
);
1779 auto backShortcuts
= m_backAction
->shortcuts();
1780 backShortcuts
.append(QKeySequence(Qt::Key_Backspace
));
1781 actionCollection()->setDefaultShortcuts(m_backAction
, backShortcuts
);
1783 DolphinRecentTabsMenu
* recentTabsMenu
= new DolphinRecentTabsMenu(this);
1784 actionCollection()->addAction(QStringLiteral("closed_tabs"), recentTabsMenu
);
1785 connect(m_tabWidget
, &DolphinTabWidget::rememberClosedTab
,
1786 recentTabsMenu
, &DolphinRecentTabsMenu::rememberClosedTab
);
1787 connect(recentTabsMenu
, &DolphinRecentTabsMenu::restoreClosedTab
,
1788 m_tabWidget
, &DolphinTabWidget::restoreClosedTab
);
1789 connect(recentTabsMenu
, &DolphinRecentTabsMenu::closedTabsCountChanged
,
1790 this, &DolphinMainWindow::closedTabsCountChanged
);
1792 QAction
* undoCloseTab
= actionCollection()->addAction(QStringLiteral("undo_close_tab"));
1793 undoCloseTab
->setText(i18nc("@action:inmenu File", "Undo close tab"));
1794 undoCloseTab
->setWhatsThis(i18nc("@info:whatsthis undo close tab",
1795 "This returns you to the previously closed tab."));
1796 actionCollection()->setDefaultShortcut(undoCloseTab
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_T
);
1797 undoCloseTab
->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo")));
1798 undoCloseTab
->setEnabled(false);
1799 connect(undoCloseTab
, &QAction::triggered
, recentTabsMenu
, &DolphinRecentTabsMenu::undoCloseTab
);
1801 auto undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
1802 undoAction
->setWhatsThis(xi18nc("@info:whatsthis", "This undoes "
1803 "the last change you made to files or folders.<nl/>"
1804 "Such changes include <interface>creating, renaming</interface> "
1805 "and <interface>moving</interface> them to a different location "
1806 "or to the <filename>Trash</filename>. <nl/>Changes that can't "
1807 "be undone will ask for your confirmation."));
1808 undoAction
->setEnabled(false); // undo should be disabled by default
1811 QScopedPointer
<QAction
> forwardAction(KStandardAction::forward(nullptr, nullptr, nullptr));
1812 m_forwardAction
= new KToolBarPopupAction(forwardAction
->icon(), forwardAction
->text(), actionCollection());
1813 m_forwardAction
->setObjectName(forwardAction
->objectName());
1814 m_forwardAction
->setShortcuts(forwardAction
->shortcuts());
1816 m_forwardAction
->setPopupMode(QToolButton::DelayedPopup
);
1817 connect(m_forwardAction
, &QAction::triggered
, this, &DolphinMainWindow::goForward
);
1818 connect(m_forwardAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowForwardPopupMenu
);
1819 connect(m_forwardAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoForward
);
1820 actionCollection()->addAction(m_forwardAction
->objectName(), m_forwardAction
);
1821 actionCollection()->setDefaultShortcuts(m_forwardAction
, m_forwardAction
->shortcuts());
1823 // enable middle-click to open in a new tab
1824 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
1825 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotBackForwardActionMiddleClicked
);
1826 m_backAction
->menu()->installEventFilter(middleClickEventFilter
);
1827 m_forwardAction
->menu()->installEventFilter(middleClickEventFilter
);
1828 KStandardAction::up(this, &DolphinMainWindow::goUp
, actionCollection());
1829 QAction
* homeAction
= KStandardAction::home(this, &DolphinMainWindow::goHome
, actionCollection());
1830 homeAction
->setWhatsThis(xi18nc("@info:whatsthis", "Go to your "
1831 "<filename>Home</filename> folder.<nl/>Every user account "
1832 "has their own <filename>Home</filename> that contains their data "
1833 "including folders that contain personal application data."));
1835 // setup 'Tools' menu
1836 QAction
* compareFiles
= actionCollection()->addAction(QStringLiteral("compare_files"));
1837 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1838 compareFiles
->setIcon(QIcon::fromTheme(QStringLiteral("kompare")));
1839 compareFiles
->setEnabled(false);
1840 connect(compareFiles
, &QAction::triggered
, this, &DolphinMainWindow::compareFiles
);
1842 QAction
* openPreferredSearchTool
= actionCollection()->addAction(QStringLiteral("open_preferred_search_tool"));
1843 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1844 openPreferredSearchTool
->setWhatsThis(xi18nc("@info:whatsthis",
1845 "<para>This opens a preferred search tool for the viewed location.</para>"
1846 "<para>Use <emphasis>More Search Tools</emphasis> menu to configure it.</para>"));
1847 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1848 actionCollection()->setDefaultShortcut(openPreferredSearchTool
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F
);
1849 connect(openPreferredSearchTool
, &QAction::triggered
, this, &DolphinMainWindow::openPreferredSearchTool
);
1851 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1852 QAction
* openTerminal
= actionCollection()->addAction(QStringLiteral("open_terminal"));
1853 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1854 openTerminal
->setWhatsThis(xi18nc("@info:whatsthis",
1855 "<para>This opens a <emphasis>terminal</emphasis> application for the viewed location.</para>"
1856 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1857 openTerminal
->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
1858 actionCollection()->setDefaultShortcut(openTerminal
, Qt::SHIFT
| Qt::Key_F4
);
1859 connect(openTerminal
, &QAction::triggered
, this, &DolphinMainWindow::openTerminal
);
1861 QAction
* openTerminalHere
= actionCollection()->addAction(QStringLiteral("open_terminal_here"));
1862 // i18n: "Here" refers to the location(s) of the currently selected item(s) or the currently viewed location if nothing is selected.
1863 openTerminalHere
->setText(i18nc("@action:inmenu Tools", "Open Terminal Here"));
1864 openTerminalHere
->setWhatsThis(xi18nc("@info:whatsthis",
1865 "<para>This opens <emphasis>terminal</emphasis> applications for the selected items' locations.</para>"
1866 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1867 openTerminalHere
->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
1868 actionCollection()->setDefaultShortcut(openTerminalHere
, Qt::SHIFT
| Qt::ALT
| Qt::Key_F4
);
1869 connect(openTerminalHere
, &QAction::triggered
, this, &DolphinMainWindow::openTerminalHere
);
1872 QAction
* focusTerminalPanel
= actionCollection()->addAction(QStringLiteral("focus_terminal_panel"));
1873 focusTerminalPanel
->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
1874 focusTerminalPanel
->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
1875 actionCollection()->setDefaultShortcut(focusTerminalPanel
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F4
);
1876 connect(focusTerminalPanel
, &QAction::triggered
, this, &DolphinMainWindow::focusTerminalPanel
);
1880 // setup 'Bookmarks' menu
1881 KActionMenu
*bookmarkMenu
= new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this);
1882 bookmarkMenu
->setIcon(QIcon::fromTheme(QStringLiteral("bookmarks")));
1883 // Make the toolbar button version work properly on click
1884 bookmarkMenu
->setPopupMode(QToolButton::InstantPopup
);
1885 m_bookmarkHandler
= new DolphinBookmarkHandler(this, actionCollection(), bookmarkMenu
->menu(), this);
1886 actionCollection()->addAction(QStringLiteral("bookmarks"), bookmarkMenu
);
1888 // setup 'Settings' menu
1889 KToggleAction
* showMenuBar
= KStandardAction::showMenubar(nullptr, nullptr, actionCollection());
1890 showMenuBar
->setWhatsThis(xi18nc("@info:whatsthis",
1891 "<para>This switches between having a <emphasis>Menubar</emphasis> "
1892 "and having a <interface>%1</interface> button. Both "
1893 "contain mostly the same actions and configuration options.</para>"
1894 "<para>The Menubar takes up more space but allows for fast and organised access to all "
1895 "actions an application has to offer.</para><para>The <interface>%1</interface> button "
1896 "is simpler and small which makes triggering advanced actions more time consuming.</para>", hamburgerMenuAction
->text().replace('&', "")));
1897 connect(showMenuBar
, &KToggleAction::triggered
, // Fixes #286822
1898 this, &DolphinMainWindow::toggleShowMenuBar
, Qt::QueuedConnection
);
1900 KToggleAction
* showStatusBar
= KStandardAction::showStatusbar(nullptr, nullptr, actionCollection());
1901 showStatusBar
->setChecked(GeneralSettings::showStatusBar());
1902 connect(GeneralSettings::self(), &GeneralSettings::showStatusBarChanged
, showStatusBar
, &KToggleAction::setChecked
);
1903 connect(showStatusBar
, &KToggleAction::triggered
, this, [this](bool checked
) {
1904 GeneralSettings::setShowStatusBar(checked
);
1908 KStandardAction::keyBindings(this, &DolphinMainWindow::slotKeyBindings
, actionCollection());
1909 KStandardAction::preferences(this, &DolphinMainWindow::editSettings
, actionCollection());
1911 // not in menu actions
1912 QList
<QKeySequence
> nextTabKeys
= KStandardShortcut::tabNext();
1913 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
1915 QList
<QKeySequence
> prevTabKeys
= KStandardShortcut::tabPrev();
1916 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
1918 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1919 QAction
* activateTab
= actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i
));
1920 activateTab
->setText(i18nc("@action:inmenu", "Activate Tab %1", i
+ 1));
1921 activateTab
->setEnabled(false);
1922 connect(activateTab
, &QAction::triggered
, this, [this, i
]() { m_tabWidget
->activateTab(i
); });
1924 // only add default shortcuts for the first 9 tabs regardless of MaxActivateTabShortcuts
1926 actionCollection()->setDefaultShortcut(activateTab
, QStringLiteral("Alt+%1").arg(i
+ 1));
1930 QAction
* activateLastTab
= actionCollection()->addAction(QStringLiteral("activate_last_tab"));
1931 activateLastTab
->setText(i18nc("@action:inmenu", "Activate Last Tab"));
1932 activateLastTab
->setEnabled(false);
1933 connect(activateLastTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateLastTab
);
1934 actionCollection()->setDefaultShortcut(activateLastTab
, Qt::ALT
| Qt::Key_0
);
1936 QAction
* activateNextTab
= actionCollection()->addAction(QStringLiteral("activate_next_tab"));
1937 activateNextTab
->setIconText(i18nc("@action:inmenu", "Next Tab"));
1938 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1939 activateNextTab
->setEnabled(false);
1940 connect(activateNextTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateNextTab
);
1941 actionCollection()->setDefaultShortcuts(activateNextTab
, nextTabKeys
);
1943 QAction
* activatePrevTab
= actionCollection()->addAction(QStringLiteral("activate_prev_tab"));
1944 activatePrevTab
->setIconText(i18nc("@action:inmenu", "Previous Tab"));
1945 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1946 activatePrevTab
->setEnabled(false);
1947 connect(activatePrevTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activatePrevTab
);
1948 actionCollection()->setDefaultShortcuts(activatePrevTab
, prevTabKeys
);
1951 QAction
* showTarget
= actionCollection()->addAction(QStringLiteral("show_target"));
1952 showTarget
->setText(i18nc("@action:inmenu", "Show Target"));
1953 showTarget
->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
1954 showTarget
->setEnabled(false);
1955 connect(showTarget
, &QAction::triggered
, this, &DolphinMainWindow::showTarget
);
1957 QAction
* openInNewTab
= actionCollection()->addAction(QStringLiteral("open_in_new_tab"));
1958 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1959 openInNewTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1960 connect(openInNewTab
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
1962 QAction
* openInNewTabs
= actionCollection()->addAction(QStringLiteral("open_in_new_tabs"));
1963 openInNewTabs
->setText(i18nc("@action:inmenu", "Open in New Tabs"));
1964 openInNewTabs
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1965 connect(openInNewTabs
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
1967 QAction
* openInNewWindow
= actionCollection()->addAction(QStringLiteral("open_in_new_window"));
1968 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1969 openInNewWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1970 connect(openInNewWindow
, &QAction::triggered
, this, &DolphinMainWindow::openInNewWindow
);
1973 void DolphinMainWindow::setupDockWidgets()
1975 const bool lock
= GeneralSettings::lockPanels();
1977 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(lock
);
1979 KDualAction
* lockLayoutAction
= actionCollection()->add
<KDualAction
>(QStringLiteral("lock_panels"));
1980 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1981 lockLayoutAction
->setActiveIcon(QIcon::fromTheme(QStringLiteral("object-unlocked")));
1982 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1983 lockLayoutAction
->setInactiveIcon(QIcon::fromTheme(QStringLiteral("object-locked")));
1984 lockLayoutAction
->setWhatsThis(xi18nc("@info:whatsthis", "This "
1985 "switches between having panels <emphasis>locked</emphasis> or "
1986 "<emphasis>unlocked</emphasis>.<nl/>Unlocked panels can be "
1987 "dragged to the other side of the window and have a close "
1988 "button.<nl/>Locked panels are embedded more cleanly."));
1989 lockLayoutAction
->setActive(lock
);
1990 connect(lockLayoutAction
, &KDualAction::triggered
, this, &DolphinMainWindow::togglePanelLockState
);
1992 // Setup "Information"
1993 DolphinDockWidget
* infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
1994 infoDock
->setLocked(lock
);
1995 infoDock
->setObjectName(QStringLiteral("infoDock"));
1996 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1999 InformationPanel
* infoPanel
= new InformationPanel(infoDock
);
2000 infoPanel
->setCustomContextMenuActions({lockLayoutAction
});
2001 connect(infoPanel
, &InformationPanel::urlActivated
, this, &DolphinMainWindow::handleUrl
);
2002 infoDock
->setWidget(infoPanel
);
2004 QAction
* infoAction
= infoDock
->toggleViewAction();
2005 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-information")), Qt::Key_F11
, infoAction
, QStringLiteral("show_information_panel"));
2007 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
2008 connect(this, &DolphinMainWindow::urlChanged
,
2009 infoPanel
, &InformationPanel::setUrl
);
2010 connect(this, &DolphinMainWindow::selectionChanged
,
2011 infoPanel
, &InformationPanel::setSelection
);
2012 connect(this, &DolphinMainWindow::requestItemInfo
,
2013 infoPanel
, &InformationPanel::requestDelayedItemInfo
);
2014 connect(this, &DolphinMainWindow::fileItemsChanged
,
2015 infoPanel
, &InformationPanel::slotFilesItemChanged
);
2018 // i18n: This is the last paragraph for the "What's This"-texts of all four panels.
2019 const QString panelWhatsThis
= xi18nc("@info:whatsthis", "<para>To show or "
2020 "hide panels like this go to <interface>Menu|Panels</interface> "
2021 "or <interface>View|Panels</interface>.</para>");
2023 actionCollection()->action(QStringLiteral("show_information_panel"))
2024 ->setWhatsThis(xi18nc("@info:whatsthis", "<para> This toggles the "
2025 "<emphasis>information</emphasis> panel at the right side of the "
2026 "window.</para><para>The panel provides in-depth information "
2027 "about the items your mouse is hovering over or about the selected "
2028 "items. Otherwise it informs you about the currently viewed folder.<nl/>"
2029 "For single items a preview of their contents is provided.</para>"));
2031 infoDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
2032 "provides in-depth information about the items your mouse is "
2033 "hovering over or about the selected items. Otherwise it informs "
2034 "you about the currently viewed folder.<nl/>For single items a "
2035 "preview of their contents is provided.</para><para>You can configure "
2036 "which and how details are given here by right-clicking.</para>") + panelWhatsThis
);
2039 DolphinDockWidget
* foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
2040 foldersDock
->setLocked(lock
);
2041 foldersDock
->setObjectName(QStringLiteral("foldersDock"));
2042 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2043 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
2044 foldersPanel
->setCustomContextMenuActions({lockLayoutAction
});
2045 foldersDock
->setWidget(foldersPanel
);
2047 QAction
* foldersAction
= foldersDock
->toggleViewAction();
2048 createPanelAction(QIcon::fromTheme(QStringLiteral("folder")), Qt::Key_F7
, foldersAction
, QStringLiteral("show_folders_panel"));
2050 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
2051 connect(this, &DolphinMainWindow::urlChanged
,
2052 foldersPanel
, &FoldersPanel::setUrl
);
2053 connect(foldersPanel
, &FoldersPanel::folderActivated
,
2054 this, &DolphinMainWindow::changeUrl
);
2055 connect(foldersPanel
, &FoldersPanel::folderInNewTab
,
2056 this, &DolphinMainWindow::openNewTab
);
2057 connect(foldersPanel
, &FoldersPanel::folderInNewActiveTab
,
2058 this, &DolphinMainWindow::openNewTabAndActivate
);
2059 connect(foldersPanel
, &FoldersPanel::errorMessage
,
2060 this, &DolphinMainWindow::showErrorMessage
);
2062 actionCollection()->action(QStringLiteral("show_folders_panel"))
2063 ->setWhatsThis(xi18nc("@info:whatsthis", "This toggles the "
2064 "<emphasis>folders</emphasis> panel at the left side of the window."
2065 "<nl/><nl/>It shows the folders of the <emphasis>file system"
2066 "</emphasis> in a <emphasis>tree view</emphasis>."));
2067 foldersDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
2068 "shows the folders of the <emphasis>file system</emphasis> in a "
2069 "<emphasis>tree view</emphasis>.</para><para>Click a folder to go "
2070 "there. Click the arrow to the left of a folder to see its subfolders. "
2071 "This allows quick switching between any folders.</para>") + panelWhatsThis
);
2075 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
2076 DolphinDockWidget
* terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
2077 terminalDock
->setLocked(lock
);
2078 terminalDock
->setObjectName(QStringLiteral("terminalDock"));
2079 m_terminalPanel
= new TerminalPanel(terminalDock
);
2080 m_terminalPanel
->setCustomContextMenuActions({lockLayoutAction
});
2081 terminalDock
->setWidget(m_terminalPanel
);
2083 connect(m_terminalPanel
, &TerminalPanel::hideTerminalPanel
, terminalDock
, &DolphinDockWidget::hide
);
2084 connect(m_terminalPanel
, &TerminalPanel::changeUrl
, this, &DolphinMainWindow::slotTerminalDirectoryChanged
);
2085 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
,
2086 m_terminalPanel
, &TerminalPanel::dockVisibilityChanged
);
2087 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
,
2088 this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged
);
2090 QAction
* terminalAction
= terminalDock
->toggleViewAction();
2091 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-scripts")), Qt::Key_F4
, terminalAction
, QStringLiteral("show_terminal_panel"));
2093 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
2094 connect(this, &DolphinMainWindow::urlChanged
,
2095 m_terminalPanel
, &TerminalPanel::setUrl
);
2097 if (GeneralSettings::version() < 200) {
2098 terminalDock
->hide();
2101 actionCollection()->action(QStringLiteral("show_terminal_panel"))
2102 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
2103 "<emphasis>terminal</emphasis> panel at the bottom of the window."
2104 "<nl/>The location in the terminal will always match the folder "
2105 "view so you can navigate using either.</para><para>The terminal "
2106 "panel is not needed for basic computer usage but can be useful "
2107 "for advanced tasks. To learn more about terminals use the help "
2108 "in a standalone terminal application like Konsole.</para>"));
2109 terminalDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is "
2110 "the <emphasis>terminal</emphasis> panel. It behaves like a "
2111 "normal terminal but will match the location of the folder view "
2112 "so you can navigate using either.</para><para>The terminal panel "
2113 "is not needed for basic computer usage but can be useful for "
2114 "advanced tasks. To learn more about terminals use the help in a "
2115 "standalone terminal application like Konsole.</para>") + panelWhatsThis
);
2119 if (GeneralSettings::version() < 200) {
2121 foldersDock
->hide();
2125 DolphinDockWidget
* placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
2126 placesDock
->setLocked(lock
);
2127 placesDock
->setObjectName(QStringLiteral("placesDock"));
2128 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2130 m_placesPanel
= new PlacesPanel(placesDock
);
2131 m_placesPanel
->setCustomContextMenuActions({lockLayoutAction
});
2132 placesDock
->setWidget(m_placesPanel
);
2134 QAction
*placesAction
= placesDock
->toggleViewAction();
2135 createPanelAction(QIcon::fromTheme(QStringLiteral("compass")), Qt::Key_F9
, placesAction
, QStringLiteral("show_places_panel"));
2137 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
2138 connect(m_placesPanel
, &PlacesPanel::placeActivated
,
2139 this, &DolphinMainWindow::slotPlaceActivated
);
2140 connect(m_placesPanel
, &PlacesPanel::tabRequested
,
2141 this, &DolphinMainWindow::openNewTab
);
2142 connect(m_placesPanel
, &PlacesPanel::activeTabRequested
,
2143 this, &DolphinMainWindow::openNewTabAndActivate
);
2144 connect(m_placesPanel
, &PlacesPanel::newWindowRequested
, this, [this](const QUrl
&url
) {
2145 Dolphin::openNewWindow({url
}, this);
2147 connect(m_placesPanel
, &PlacesPanel::errorMessage
,
2148 this, &DolphinMainWindow::showErrorMessage
);
2149 connect(this, &DolphinMainWindow::urlChanged
,
2150 m_placesPanel
, &PlacesPanel::setUrl
);
2151 connect(placesDock
, &DolphinDockWidget::visibilityChanged
,
2152 &DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged
);
2153 connect(this, &DolphinMainWindow::settingsChanged
,
2154 m_placesPanel
, &PlacesPanel::readSettings
);
2155 connect(m_placesPanel
, &PlacesPanel::storageTearDownRequested
,
2156 this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested
);
2157 connect(m_placesPanel
, &PlacesPanel::storageTearDownExternallyRequested
,
2158 this, &DolphinMainWindow::slotStorageTearDownExternallyRequested
);
2159 DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged(m_placesPanel
->isVisible());
2161 auto actionShowAllPlaces
= new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this);
2162 actionShowAllPlaces
->setCheckable(true);
2163 actionShowAllPlaces
->setDisabled(true);
2164 actionShowAllPlaces
->setWhatsThis(i18nc("@info:whatsthis", "This displays "
2165 "all places in the places panel that have been hidden. They will "
2166 "appear semi-transparent unless you uncheck their hide property."));
2168 connect(actionShowAllPlaces
, &QAction::triggered
, this, [actionShowAllPlaces
, this](bool checked
){
2169 m_placesPanel
->setShowAll(checked
);
2171 connect(m_placesPanel
, &PlacesPanel::allPlacesShownChanged
, actionShowAllPlaces
, &QAction::setChecked
);
2173 actionCollection()->action(QStringLiteral("show_places_panel"))
2174 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
2175 "<emphasis>places</emphasis> panel at the left side of the window."
2176 "</para><para>It allows you to go to locations you have "
2177 "bookmarked and to access disk or media attached to the computer "
2178 "or to the network. It also contains sections to find recently "
2179 "saved files or files of a certain type.</para>"));
2180 placesDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2181 "<emphasis>Places</emphasis> panel. It allows you to go to locations "
2182 "you have bookmarked and to access disk or media attached to the "
2183 "computer or to the network. It also contains sections to find "
2184 "recently saved files or files of a certain type.</para><para>"
2185 "Click on an entry to go there. Click with the right mouse button "
2186 "instead to open any entry in a new tab or new window.</para>"
2187 "<para>New entries can be added by dragging folders onto this panel. "
2188 "Right-click any section or entry to hide it. Right-click an empty "
2189 "space on this panel and select <interface>Show Hidden Places"
2190 "</interface> to display it again.</para>") + panelWhatsThis
);
2192 // Add actions into the "Panels" menu
2193 KActionMenu
* panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Show Panels"), this);
2194 actionCollection()->addAction(QStringLiteral("panels"), panelsMenu
);
2195 panelsMenu
->setIcon(QIcon::fromTheme(QStringLiteral("view-sidetree")));
2196 panelsMenu
->setPopupMode(QToolButton::InstantPopup
);
2197 const KActionCollection
* ac
= actionCollection();
2198 panelsMenu
->addAction(ac
->action(QStringLiteral("show_places_panel")));
2200 panelsMenu
->addAction(ac
->action(QStringLiteral("show_information_panel")));
2202 panelsMenu
->addAction(ac
->action(QStringLiteral("show_folders_panel")));
2203 panelsMenu
->addAction(ac
->action(QStringLiteral("show_terminal_panel")));
2204 panelsMenu
->addSeparator();
2205 panelsMenu
->addAction(actionShowAllPlaces
);
2206 panelsMenu
->addAction(lockLayoutAction
);
2208 connect(panelsMenu
->menu(), &QMenu::aboutToShow
, this, [actionShowAllPlaces
, this]{
2209 actionShowAllPlaces
->setEnabled(DolphinPlacesModelSingleton::instance().placesModel()->hiddenCount());
2214 void DolphinMainWindow::updateFileAndEditActions()
2216 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
2217 const KActionCollection
* col
= actionCollection();
2218 KFileItemListProperties
capabilitiesSource(list
);
2220 QAction
* renameAction
= col
->action(KStandardAction::name(KStandardAction::RenameFile
));
2221 QAction
* moveToTrashAction
= col
->action(KStandardAction::name(KStandardAction::MoveToTrash
));
2222 QAction
* deleteAction
= col
->action(KStandardAction::name(KStandardAction::DeleteFile
));
2223 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
2224 QAction
* duplicateAction
= col
->action(QStringLiteral("duplicate")); // see DolphinViewActionHandler
2225 QAction
* addToPlacesAction
= col
->action(QStringLiteral("add_to_places"));
2226 QAction
* copyToOtherViewAction
= col
->action(QStringLiteral("copy_to_inactive_split_view"));
2227 QAction
* moveToOtherViewAction
= col
->action(QStringLiteral("move_to_inactive_split_view"));
2228 QAction
* copyLocation
= col
->action(QString("copy_location"));
2230 if (list
.isEmpty()) {
2231 stateChanged(QStringLiteral("has_no_selection"));
2233 // All actions that need a selection to function can be enabled because they should trigger selection mode.
2234 renameAction
->setEnabled(true);
2235 moveToTrashAction
->setEnabled(true);
2236 deleteAction
->setEnabled(true);
2237 cutAction
->setEnabled(true);
2238 duplicateAction
->setEnabled(true);
2239 addToPlacesAction
->setEnabled(true);
2240 copyLocation
->setEnabled(true);
2241 // Them triggering selection mode and not directly acting on selected items is signified by adding "…" to their text.
2242 m_actionTextHelper
->textsWhenNothingIsSelectedEnabled(true);
2245 m_actionTextHelper
->textsWhenNothingIsSelectedEnabled(false);
2246 stateChanged(QStringLiteral("has_selection"));
2248 QAction
* deleteWithTrashShortcut
= col
->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
2249 QAction
* showTarget
= col
->action(QStringLiteral("show_target"));
2251 if (list
.length() == 1 && list
.first().isDir()) {
2252 addToPlacesAction
->setEnabled(true);
2254 addToPlacesAction
->setEnabled(false);
2257 const bool enableMoveToTrash
= capabilitiesSource
.isLocal() && capabilitiesSource
.supportsMoving();
2259 renameAction
->setEnabled(capabilitiesSource
.supportsMoving());
2260 moveToTrashAction
->setEnabled(enableMoveToTrash
);
2261 deleteAction
->setEnabled(capabilitiesSource
.supportsDeleting());
2262 deleteWithTrashShortcut
->setEnabled(capabilitiesSource
.supportsDeleting() && !enableMoveToTrash
);
2263 cutAction
->setEnabled(capabilitiesSource
.supportsMoving());
2264 copyLocation
->setEnabled(list
.length() == 1);
2265 showTarget
->setEnabled(list
.length() == 1 && list
.at(0).isLink());
2266 duplicateAction
->setEnabled(capabilitiesSource
.supportsWriting());
2269 if (m_tabWidget
->currentTabPage()->splitViewEnabled()) {
2270 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
2271 KFileItem capabilitiesDestination
;
2273 if (tabPage
->primaryViewActive()) {
2274 capabilitiesDestination
= tabPage
->secondaryViewContainer()->url();
2276 capabilitiesDestination
= tabPage
->primaryViewContainer()->url();
2279 copyToOtherViewAction
->setEnabled(capabilitiesDestination
.isWritable());
2280 moveToOtherViewAction
->setEnabled((list
.isEmpty() || capabilitiesSource
.supportsMoving()) && capabilitiesDestination
.isWritable());
2282 copyToOtherViewAction
->setEnabled(false);
2283 moveToOtherViewAction
->setEnabled(false);
2287 void DolphinMainWindow::updateViewActions()
2289 m_actionHandler
->updateViewActions();
2291 QAction
* toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
2292 toggleFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
2294 updateSplitAction();
2297 void DolphinMainWindow::updateGoActions()
2299 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
2300 const QUrl currentUrl
= m_activeViewContainer
->url();
2301 // I think this is one of the best places to firstly be confronted
2302 // with a file system and its hierarchy. Talking about the root
2303 // directory might seem too much here but it is the question that
2304 // naturally arises in this context.
2305 goUpAction
->setWhatsThis(xi18nc("@info:whatsthis", "<para>Go to "
2306 "the folder that contains the currently viewed one.</para>"
2307 "<para>All files and folders are organized in a hierarchical "
2308 "<emphasis>file system</emphasis>. At the top of this hierarchy is "
2309 "a directory that contains all data connected to this computer"
2310 "—the <emphasis>root directory</emphasis>.</para>"));
2311 goUpAction
->setEnabled(KIO::upUrl(currentUrl
) != currentUrl
);
2314 void DolphinMainWindow::refreshViews()
2316 m_tabWidget
->refreshViews();
2318 if (GeneralSettings::modifiedStartupSettings()) {
2319 updateWindowTitle();
2322 Q_EMIT
settingsChanged();
2325 void DolphinMainWindow::clearStatusBar()
2327 m_activeViewContainer
->statusBar()->resetToDefaultText();
2330 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
2332 connect(container
, &DolphinViewContainer::showFilterBarChanged
,
2333 this, &DolphinMainWindow::updateFilterBarAction
);
2334 connect(container
, &DolphinViewContainer::writeStateChanged
,
2335 this, &DolphinMainWindow::slotWriteStateChanged
);
2336 connect(container
, &DolphinViewContainer::searchModeEnabledChanged
,
2337 this, &DolphinMainWindow::updateSearchAction
);
2338 connect(container
, &DolphinViewContainer::captionChanged
,
2339 this, &DolphinMainWindow::updateWindowTitle
);
2340 connect(container
, &DolphinViewContainer::tabRequested
,
2341 this, &DolphinMainWindow::openNewTab
);
2342 connect(container
, &DolphinViewContainer::activeTabRequested
,
2343 this, &DolphinMainWindow::openNewTabAndActivate
);
2345 const QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
2346 connect(toggleSearchAction
, &QAction::triggered
, container
, &DolphinViewContainer::setSearchModeEnabled
);
2348 // Make the toggled state of the selection mode actions visually follow the selection mode state of the view.
2349 auto toggleSelectionModeAction
= actionCollection()->action(QStringLiteral("toggle_selection_mode"));
2350 toggleSelectionModeAction
->setChecked(m_activeViewContainer
->isSelectionModeEnabled());
2351 connect(m_activeViewContainer
, &DolphinViewContainer::selectionModeChanged
,
2352 toggleSelectionModeAction
, &QAction::setChecked
);
2354 const DolphinView
* view
= container
->view();
2355 connect(view
, &DolphinView::selectionChanged
,
2356 this, &DolphinMainWindow::slotSelectionChanged
);
2357 connect(view
, &DolphinView::requestItemInfo
,
2358 this, &DolphinMainWindow::requestItemInfo
);
2359 connect(view
, &DolphinView::fileItemsChanged
,
2360 this, &DolphinMainWindow::fileItemsChanged
);
2361 connect(view
, &DolphinView::tabRequested
,
2362 this, &DolphinMainWindow::openNewTab
);
2363 connect(view
, &DolphinView::activeTabRequested
,
2364 this, &DolphinMainWindow::openNewTabAndActivate
);
2365 connect(view
, &DolphinView::windowRequested
,
2366 this, &DolphinMainWindow::openNewWindow
);
2367 connect(view
, &DolphinView::requestContextMenu
,
2368 this, &DolphinMainWindow::openContextMenu
);
2369 connect(view
, &DolphinView::directoryLoadingStarted
,
2370 this, &DolphinMainWindow::enableStopAction
);
2371 connect(view
, &DolphinView::directoryLoadingCompleted
,
2372 this, &DolphinMainWindow::disableStopAction
);
2373 connect(view
, &DolphinView::directoryLoadingCompleted
,
2374 this, &DolphinMainWindow::slotDirectoryLoadingCompleted
);
2375 connect(view
, &DolphinView::goBackRequested
,
2376 this, &DolphinMainWindow::goBack
);
2377 connect(view
, &DolphinView::goForwardRequested
,
2378 this, &DolphinMainWindow::goForward
);
2379 connect(view
, &DolphinView::urlActivated
,
2380 this, &DolphinMainWindow::handleUrl
);
2381 connect(view
, &DolphinView::goUpRequested
,
2382 this, &DolphinMainWindow::goUp
);
2384 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::urlChanged
,
2385 this, &DolphinMainWindow::changeUrl
);
2386 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::historyChanged
,
2387 this, &DolphinMainWindow::updateHistory
);
2389 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
2390 (actionCollection()->action(QStringLiteral("url_navigators")));
2391 const KUrlNavigator
*navigator
= m_tabWidget
->currentTabPage()->primaryViewActive() ?
2392 navigators
->primaryUrlNavigator() :
2393 navigators
->secondaryUrlNavigator();
2395 QAction
*editableLocactionAction
= actionCollection()->action(QStringLiteral("editable_location"));
2396 editableLocactionAction
->setChecked(navigator
->isUrlEditable());
2397 connect(navigator
, &KUrlNavigator::editableStateChanged
,
2398 this, &DolphinMainWindow::slotEditableStateChanged
);
2399 connect(navigator
, &KUrlNavigator::tabRequested
,
2400 this, &DolphinMainWindow::openNewTab
);
2401 connect(navigator
, &KUrlNavigator::activeTabRequested
,
2402 this, &DolphinMainWindow::openNewTabAndActivate
);
2403 connect(navigator
, &KUrlNavigator::newWindowRequested
,
2404 this, &DolphinMainWindow::openNewWindow
);
2408 void DolphinMainWindow::updateSplitAction()
2410 QAction
* splitAction
= actionCollection()->action(QStringLiteral("split_view"));
2411 const DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
2412 if (tabPage
->splitViewEnabled()) {
2413 if (GeneralSettings::closeActiveSplitView() ? tabPage
->primaryViewActive() : !tabPage
->primaryViewActive()) {
2414 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2415 splitAction
->setToolTip(i18nc("@info", "Close left view"));
2416 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close")));
2418 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2419 splitAction
->setToolTip(i18nc("@info", "Close right view"));
2420 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close")));
2423 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2424 splitAction
->setToolTip(i18nc("@info", "Split view"));
2425 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
2429 void DolphinMainWindow::updateAllowedToolbarAreas()
2431 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
2432 (actionCollection()->action(QStringLiteral("url_navigators")));
2433 if (toolBar()->actions().contains(navigators
)) {
2434 toolBar()->setAllowedAreas(Qt::TopToolBarArea
| Qt::BottomToolBarArea
);
2435 if (toolBarArea(toolBar()) == Qt::LeftToolBarArea
||
2436 toolBarArea(toolBar()) == Qt::RightToolBarArea
) {
2437 addToolBar(Qt::TopToolBarArea
, toolBar());
2440 toolBar()->setAllowedAreas(Qt::AllToolBarAreas
);
2444 bool DolphinMainWindow::isKompareInstalled() const
2446 static bool initialized
= false;
2447 static bool installed
= false;
2449 // TODO: maybe replace this approach later by using a menu
2450 // plugin like kdiff3plugin.cpp
2451 installed
= !QStandardPaths::findExecutable(QStringLiteral("kompare")).isEmpty();
2457 void DolphinMainWindow::createPanelAction(const QIcon
& icon
,
2458 const QKeySequence
& shortcut
,
2459 QAction
* dockAction
,
2460 const QString
& actionName
)
2462 QAction
* panelAction
= actionCollection()->addAction(actionName
);
2463 panelAction
->setCheckable(true);
2464 panelAction
->setChecked(dockAction
->isChecked());
2465 panelAction
->setText(dockAction
->text());
2466 panelAction
->setIcon(icon
);
2467 dockAction
->setIcon(icon
);
2468 actionCollection()->setDefaultShortcut(panelAction
, shortcut
);
2470 connect(panelAction
, &QAction::triggered
, dockAction
, &QAction::trigger
);
2471 connect(dockAction
, &QAction::toggled
, panelAction
, &QAction::setChecked
);
2474 void DolphinMainWindow::setupWhatsThis()
2477 menuBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2478 "<emphasis>Menubar</emphasis>. It provides access to commands and "
2479 "configuration options. Left-click on any of the menus on this "
2480 "bar to see its contents.</para><para>The Menubar can be hidden "
2481 "by unchecking <interface>Settings|Show Menubar</interface>. Then "
2482 "most of its contents become available through a <interface>Menu"
2483 "</interface> button on the <emphasis>Toolbar</emphasis>.</para>"));
2484 toolBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2485 "<emphasis>Toolbar</emphasis>. It allows quick access to "
2486 "frequently used actions.</para><para>It is highly customizable. "
2487 "All items you see in the <interface>Menu</interface> or "
2488 "in the <interface>Menubar</interface> can be placed on the "
2489 "Toolbar. Just right-click on it and select <interface>Configure "
2490 "Toolbars…</interface> or find this action within the <interface>"
2492 "</para><para>The location of the bar and the style of its "
2493 "buttons can also be changed in the right-click menu. Right-click "
2494 "a button if you want to show or hide its text.</para>"));
2495 m_tabWidget
->setWhatsThis(xi18nc("@info:whatsthis main view",
2496 "<para>Here you can see the <emphasis>folders</emphasis> and "
2497 "<emphasis>files</emphasis> that are at the location described in "
2498 "the <interface>Location Bar</interface> above. This area is the "
2499 "central part of this application where you navigate to the files "
2500 "you want to use.</para><para>For an elaborate and general "
2501 "introduction to this application <link "
2502 "url='https://userbase.kde.org/Dolphin/File_Management#Introduction_to_Dolphin'>"
2503 "click here</link>. This will open an introductory article from "
2504 "the <emphasis>KDE UserBase Wiki</emphasis>.</para><para>For brief "
2505 "explanations of all the features of this <emphasis>view</emphasis> "
2506 "<link url='help:/dolphin/dolphin-view.html'>click here</link> "
2507 "instead. This will open a page from the <emphasis>Handbook"
2508 "</emphasis> that covers the basics.</para>"));
2511 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings
))
2512 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window "
2513 "that lists the <emphasis>keyboard shortcuts</emphasis>.<nl/>"
2514 "There you can set up key combinations to trigger an action when "
2515 "they are pressed simultaneously. All commands in this application can "
2516 "be triggered this way.</para>"));
2517 actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars
))
2518 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window in which "
2519 "you can change which buttons appear on the <emphasis>Toolbar</emphasis>.</para>"
2520 "<para>All items you see in the <interface>Menu</interface> can also be placed on the Toolbar.</para>"));
2521 actionCollection()->action(KStandardAction::name(KStandardAction::Preferences
))
2522 ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window where you can "
2523 "change a multitude of settings for this application. For an explanation "
2524 "of the various settings go to the chapter <emphasis>Configuring Dolphin"
2525 "</emphasis> in <interface>Help|Dolphin Handbook</interface>."));
2529 // i18n: If the external link isn't available in your language it might make
2530 // sense to state the external link's language in brackets to not
2531 // frustrate the user. If there are multiple languages that the user might
2532 // know with a reasonable chance you might want to have 2 external links.
2533 // The same might be true for any external link you translate.
2534 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>"));
2535 // (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 )
2537 actionCollection()->action(KStandardAction::name(KStandardAction::WhatsThis
))->setWhatsThis(
2538 xi18nc("@info:whatsthis whatsthis button",
2539 "<para>This is the button that invokes the help feature you are "
2540 "using right now! Click it, then click any component of this "
2541 "application to ask \"What's this?\" about it. The mouse cursor "
2542 "will change appearance if no help is available for a spot.</para>"
2543 "<para>There are two other ways to get help: "
2544 "The <link url='help:/dolphin/index.html'>Dolphin Handbook</link> and "
2545 "the <link url='https://userbase.kde.org/Dolphin/File_Management'>KDE "
2546 "UserBase Wiki</link>.</para><para>The \"What's this?\" help is "
2547 "missing in most other windows so don't get too used to this.</para>"));
2549 actionCollection()->action(KStandardAction::name(KStandardAction::ReportBug
))->setWhatsThis(
2550 xi18nc("@info:whatsthis","<para>This opens a "
2551 "window that will guide you through reporting errors or flaws "
2552 "in this application or in other KDE software.</para>"
2553 "<para>High-quality bug reports are much appreciated. To learn "
2554 "how to make your bug report as effective as possible "
2555 "<link url='https://community.kde.org/Get_Involved/Bug_Reporting'>"
2556 "click here</link>.</para>"));
2558 actionCollection()->action(KStandardAction::name(KStandardAction::Donate
))->setWhatsThis(
2559 xi18nc("@info:whatsthis", "<para>This opens a "
2560 "<emphasis>web page</emphasis> where you can donate to "
2561 "support the continued work on this application and many "
2562 "other projects by the <emphasis>KDE</emphasis> community.</para>"
2563 "<para>Donating is the easiest and fastest way to efficiently "
2564 "support KDE and its projects. KDE projects are available for "
2565 "free therefore your donation is needed to cover things that "
2566 "require money like servers, contributor meetings, etc.</para>"
2567 "<para><emphasis>KDE e.V.</emphasis> is the non-profit "
2568 "organization behind the KDE community.</para>"));
2570 actionCollection()->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
))->setWhatsThis(
2571 xi18nc("@info:whatsthis",
2572 "With this you can change the language this application uses."
2573 "<nl/>You can even set secondary languages which will be used "
2574 "if texts are not available in your preferred language."));
2576 actionCollection()->action(KStandardAction::name(KStandardAction::AboutApp
))->setWhatsThis(
2577 xi18nc("@info:whatsthis","This opens a "
2578 "window that informs you about the version, license, "
2579 "used libraries and maintainers of this application."));
2581 actionCollection()->action(KStandardAction::name(KStandardAction::AboutKDE
))->setWhatsThis(
2582 xi18nc("@info:whatsthis","This opens a "
2583 "window with information about <emphasis>KDE</emphasis>. "
2584 "The KDE community are the people behind this free software."
2585 "<nl/>If you like using this application but don't know "
2586 "about KDE or want to see a cute dragon have a look!"));
2589 bool DolphinMainWindow::addHamburgerMenuToToolbar()
2591 QDomDocument domDocument
= KXMLGUIClient::domDocument();
2592 if (domDocument
.isNull()) {
2595 QDomNode toolbar
= domDocument
.elementsByTagName(QStringLiteral("ToolBar")).at(0);
2596 if (toolbar
.isNull()) {
2600 QDomElement hamburgerMenuElement
= domDocument
.createElement(QStringLiteral("Action"));
2601 hamburgerMenuElement
.setAttribute(QStringLiteral("name"), QStringLiteral("hamburger_menu"));
2602 toolbar
.appendChild(hamburgerMenuElement
);
2604 KXMLGUIFactory::saveConfigFile(domDocument
, xmlFile());
2608 // Make sure to also remove the <KXMLGUIFactory> and <QDomDocument> include
2609 // whenever this method is removed (maybe in the year ~2026).
2612 // Set a sane initial window size
2613 QSize
DolphinMainWindow::sizeHint() const
2615 return KXmlGuiWindow::sizeHint().expandedTo(QSize(760, 550));
2618 void DolphinMainWindow::saveNewToolbarConfig()
2620 KXmlGuiWindow::saveNewToolbarConfig(); // Applies the new config. This has to be called first
2621 // because the rest of this method decides things
2622 // based on the new config.
2623 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
2624 (actionCollection()->action(QStringLiteral("url_navigators")));
2625 if (!toolBar()->actions().contains(navigators
)) {
2626 m_tabWidget
->currentTabPage()->insertNavigatorsWidget(navigators
);
2628 updateAllowedToolbarAreas();
2629 (static_cast<KHamburgerMenu
*>(actionCollection()->action(KStandardAction::name(
2630 KStandardAction::HamburgerMenu
))))->hideActionsOf(toolBar());
2633 void DolphinMainWindow::focusTerminalPanel()
2635 if (m_terminalPanel
->isVisible()) {
2636 if (m_terminalPanel
->terminalHasFocus()) {
2637 m_activeViewContainer
->view()->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2638 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2640 m_terminalPanel
->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2641 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2644 actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger();
2645 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2649 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
2650 KIO::FileUndoManager::UiInterface()
2654 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2658 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
2660 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2662 DolphinViewContainer
* container
= mainWin
->activeViewContainer();
2663 container
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
2665 KIO::FileUndoManager::UiInterface::jobError(job
);
2669 bool DolphinMainWindow::isUrlOpen(const QString
&url
)
2671 return m_tabWidget
->isUrlOpen(QUrl::fromUserInput(url
));
2674 bool DolphinMainWindow::isUrlOrParentOpen(const QString
&url
)
2676 return m_tabWidget
->isUrlOrParentOpen(QUrl::fromUserInput(url
));