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"
12 #include "config-terminal.h"
14 #include "dolphinbookmarkhandler.h"
15 #include "dolphindockwidget.h"
16 #include "dolphincontextmenu.h"
17 #include "dolphinnavigatorswidgetaction.h"
18 #include "dolphinnewfilemenu.h"
19 #include "dolphinrecenttabsmenu.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/placesitemmodel.h"
26 #include "panels/places/placespanel.h"
27 #include "panels/information/informationpanel.h"
28 #include "panels/terminal/terminalpanel.h"
29 #include "settings/dolphinsettingsdialog.h"
30 #include "statusbar/dolphinstatusbar.h"
31 #include "views/dolphinviewactionhandler.h"
32 #include "views/dolphinremoteencoding.h"
33 #include "views/draganddrophelper.h"
34 #include "views/viewproperties.h"
35 #include "views/dolphinnewfilemenuobserver.h"
36 #include "dolphin_generalsettings.h"
38 #include <KActionCollection>
39 #include <KActionMenu>
40 #include <KAuthorized>
43 #include <KDualAction>
44 #include <KFileItemListProperties>
46 #include <KIO/CommandLauncherJob>
47 #include <KIO/JobUiDelegate>
48 #include <KIO/OpenFileManagerWindowJob>
49 #include <KIO/OpenUrlJob>
50 #include <KJobWidgets>
51 #include <KLocalizedString>
52 #include <KMessageBox>
53 #include <KNS3/KMoreToolsMenuFactory>
54 #include <KProtocolInfo>
55 #include <KProtocolManager>
57 #include <KStandardAction>
58 #include <KStartupInfo>
60 #include <KToggleAction>
62 #include <KToolBarPopupAction>
63 #include <KToolInvocation>
64 #include <KUrlComboBox>
65 #include <KUrlNavigator>
66 #include <KWindowSystem>
68 #include <QApplication>
70 #include <QCloseEvent>
71 #include <QDesktopServices>
76 #include <QPushButton>
78 #include <QStandardPaths>
80 #include <QToolButton>
81 #include <QWhatsThisClickedEvent>
84 // Used for GeneralSettings::version() to determine whether
85 // an updated version of Dolphin is running.
86 const int CurrentDolphinVersion
= 200;
87 // The maximum number of entries in the back/forward popup menu
88 const int MaxNumberOfNavigationentries
= 12;
89 // The maximum number of "Activate Tab" shortcuts
90 const int MaxActivateTabShortcuts
= 9;
93 DolphinMainWindow::DolphinMainWindow() :
94 KXmlGuiWindow(nullptr),
95 m_newFileMenu(nullptr),
98 m_activeViewContainer(nullptr),
99 m_actionHandler(nullptr),
100 m_remoteEncoding(nullptr),
102 m_bookmarkHandler(nullptr),
103 m_controlButton(nullptr),
104 m_updateToolBarTimer(nullptr),
105 m_lastHandleUrlOpenJob(nullptr),
106 m_terminalPanel(nullptr),
107 m_placesPanel(nullptr),
108 m_tearDownFromPlacesRequested(false),
109 m_backAction(nullptr),
110 m_forwardAction(nullptr)
112 Q_INIT_RESOURCE(dolphin
);
114 new MainWindowAdaptor(this);
117 setWindowFlags(Qt::WindowContextHelpButtonHint
);
119 setComponentName(QStringLiteral("dolphin"), QGuiApplication::applicationDisplayName());
120 setObjectName(QStringLiteral("Dolphin#"));
122 connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::errorMessage
,
123 this, &DolphinMainWindow::showErrorMessage
);
125 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
126 undoManager
->setUiInterface(new UndoUiInterface());
128 connect(undoManager
, QOverload
<bool>::of(&KIO::FileUndoManager::undoAvailable
),
129 this, &DolphinMainWindow::slotUndoAvailable
);
130 connect(undoManager
, &KIO::FileUndoManager::undoTextChanged
,
131 this, &DolphinMainWindow::slotUndoTextChanged
);
132 connect(undoManager
, &KIO::FileUndoManager::jobRecordingStarted
,
133 this, &DolphinMainWindow::clearStatusBar
);
134 connect(undoManager
, &KIO::FileUndoManager::jobRecordingFinished
,
135 this, &DolphinMainWindow::showCommand
);
137 const bool firstRun
= (GeneralSettings::version() < 200);
139 GeneralSettings::setViewPropsTimestamp(QDateTime::currentDateTime());
142 setAcceptDrops(true);
144 auto *navigatorsWidgetAction
= new DolphinNavigatorsWidgetAction(this);
145 actionCollection()->addAction(QStringLiteral("url_navigators"), navigatorsWidgetAction
);
146 m_tabWidget
= new DolphinTabWidget(navigatorsWidgetAction
, this);
147 m_tabWidget
->setObjectName("tabWidget");
148 connect(m_tabWidget
, &DolphinTabWidget::activeViewChanged
,
149 this, &DolphinMainWindow::activeViewChanged
);
150 connect(m_tabWidget
, &DolphinTabWidget::tabCountChanged
,
151 this, &DolphinMainWindow::tabCountChanged
);
152 connect(m_tabWidget
, &DolphinTabWidget::currentUrlChanged
,
153 this, &DolphinMainWindow::updateWindowTitle
);
154 setCentralWidget(m_tabWidget
);
158 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
159 connect(m_actionHandler
, &DolphinViewActionHandler::actionBeingHandled
, this, &DolphinMainWindow::clearStatusBar
);
160 connect(m_actionHandler
, &DolphinViewActionHandler::createDirectoryTriggered
, this, &DolphinMainWindow::createDirectory
);
162 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
163 connect(this, &DolphinMainWindow::urlChanged
,
164 m_remoteEncoding
, &DolphinRemoteEncoding::slotAboutToOpenUrl
);
168 setupGUI(Keys
| Save
| Create
| ToolBar
);
169 stateChanged(QStringLiteral("new_file"));
171 QClipboard
* clipboard
= QApplication::clipboard();
172 connect(clipboard
, &QClipboard::dataChanged
,
173 this, &DolphinMainWindow::updatePasteAction
);
175 QAction
* toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
176 toggleFilterBarAction
->setChecked(GeneralSettings::filterBar());
179 menuBar()->setVisible(false);
180 // Assure a proper default size if Dolphin runs the first time
184 const bool showMenu
= !menuBar()->isHidden();
185 QAction
* showMenuBarAction
= actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar
));
186 showMenuBarAction
->setChecked(showMenu
); // workaround for bug #171080
188 createControlButton();
191 updateAllowedToolbarAreas();
193 // enable middle-click on back/forward/up to open in a new tab
194 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
195 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotToolBarActionMiddleClicked
);
196 toolBar()->installEventFilter(middleClickEventFilter
);
200 connect(KSycoca::self(), QOverload
<>::of(&KSycoca::databaseChanged
), this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
202 QTimer::singleShot(0, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
205 DolphinMainWindow::~DolphinMainWindow()
209 QVector
<DolphinViewContainer
*> DolphinMainWindow::viewContainers() const
211 QVector
<DolphinViewContainer
*> viewContainers
;
213 for (int i
= 0; i
< m_tabWidget
->count(); ++i
) {
214 DolphinTabPage
*tabPage
= m_tabWidget
->tabPageAt(i
);
216 viewContainers
<< tabPage
->primaryViewContainer();
217 if (tabPage
->splitViewEnabled()) {
218 viewContainers
<< tabPage
->secondaryViewContainer();
221 return viewContainers
;
224 void DolphinMainWindow::setViewsWithInvalidPathsToHome()
226 const QVector
<DolphinViewContainer
*> theViewContainers
= viewContainers();
227 for (DolphinViewContainer
*viewContainer
: theViewContainers
) {
229 // Only consider local dirs, not remote locations and abstract protocols
230 if (viewContainer
->url().isLocalFile()) {
231 if (!QFileInfo::exists(viewContainer
->url().toLocalFile())) {
232 viewContainer
->setUrl(QUrl::fromLocalFile(QDir::homePath()));
238 void DolphinMainWindow::openDirectories(const QList
<QUrl
>& dirs
, bool splitView
)
240 m_tabWidget
->openDirectories(dirs
, splitView
);
243 void DolphinMainWindow::openDirectories(const QStringList
& dirs
, bool splitView
)
245 openDirectories(QUrl::fromStringList(dirs
), splitView
);
248 void DolphinMainWindow::openFiles(const QList
<QUrl
>& files
, bool splitView
)
250 m_tabWidget
->openFiles(files
, splitView
);
253 bool DolphinMainWindow::isFoldersPanelEnabled() const
255 return actionCollection()->action(QStringLiteral("show_folders_panel"))->isChecked();
258 bool DolphinMainWindow::isInformationPanelEnabled() const
261 return actionCollection()->action(QStringLiteral("show_information_panel"))->isChecked();
267 void DolphinMainWindow::openFiles(const QStringList
& files
, bool splitView
)
269 openFiles(QUrl::fromStringList(files
), splitView
);
272 void DolphinMainWindow::activateWindow()
274 window()->setAttribute(Qt::WA_NativeWindow
, true);
275 KStartupInfo::setNewStartupId(window()->windowHandle(), KStartupInfo::startupId());
276 KWindowSystem::activateWindow(window()->effectiveWinId());
279 void DolphinMainWindow::showCommand(CommandType command
)
281 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
283 case KIO::FileUndoManager::Copy
:
284 statusBar
->setText(i18nc("@info:status", "Successfully copied."));
286 case KIO::FileUndoManager::Move
:
287 statusBar
->setText(i18nc("@info:status", "Successfully moved."));
289 case KIO::FileUndoManager::Link
:
290 statusBar
->setText(i18nc("@info:status", "Successfully linked."));
292 case KIO::FileUndoManager::Trash
:
293 statusBar
->setText(i18nc("@info:status", "Successfully moved to trash."));
295 case KIO::FileUndoManager::Rename
:
296 statusBar
->setText(i18nc("@info:status", "Successfully renamed."));
299 case KIO::FileUndoManager::Mkdir
:
300 statusBar
->setText(i18nc("@info:status", "Created folder."));
308 void DolphinMainWindow::pasteIntoFolder()
310 m_activeViewContainer
->view()->pasteIntoFolder();
313 void DolphinMainWindow::changeUrl(const QUrl
&url
)
315 if (!KProtocolManager::supportsListing(url
)) {
316 // The URL navigator only checks for validity, not
317 // if the URL can be listed. An error message is
318 // shown due to DolphinViewContainer::restoreView().
322 m_activeViewContainer
->setUrl(url
);
323 updateFileAndEditActions();
328 Q_EMIT
urlChanged(url
);
331 void DolphinMainWindow::slotTerminalDirectoryChanged(const QUrl
& url
)
333 if (m_tearDownFromPlacesRequested
&& url
== QUrl::fromLocalFile(QDir::homePath())) {
334 m_placesPanel
->proceedWithTearDown();
335 m_tearDownFromPlacesRequested
= false;
338 m_activeViewContainer
->setAutoGrabFocus(false);
340 m_activeViewContainer
->setAutoGrabFocus(true);
343 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
345 KToggleAction
* editableLocationAction
=
346 static_cast<KToggleAction
*>(actionCollection()->action(QStringLiteral("editable_location")));
347 editableLocationAction
->setChecked(editable
);
350 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
352 updateFileAndEditActions();
354 const int selectedUrlsCount
= m_tabWidget
->currentTabPage()->selectedItemsCount();
356 QAction
* compareFilesAction
= actionCollection()->action(QStringLiteral("compare_files"));
357 if (selectedUrlsCount
== 2) {
358 compareFilesAction
->setEnabled(isKompareInstalled());
360 compareFilesAction
->setEnabled(false);
363 Q_EMIT
selectionChanged(selection
);
366 void DolphinMainWindow::updateHistory()
368 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
369 const int index
= urlNavigator
->historyIndex();
371 QAction
* backAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Back
));
373 backAction
->setToolTip(i18nc("@info", "Go back"));
374 backAction
->setWhatsThis(i18nc("@info:whatsthis go back", "Return to the previously viewed folder."));
375 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
378 QAction
* forwardAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Forward
));
380 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
381 forwardAction
->setWhatsThis(xi18nc("@info:whatsthis go forward",
382 "This undoes a <interface>Go|Back</interface> action."));
383 forwardAction
->setEnabled(index
> 0);
387 void DolphinMainWindow::updateFilterBarAction(bool show
)
389 QAction
* toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
390 toggleFilterBarAction
->setChecked(show
);
393 void DolphinMainWindow::openNewMainWindow()
395 Dolphin::openNewWindow({m_activeViewContainer
->url()}, this);
398 void DolphinMainWindow::openNewActivatedTab()
400 // keep browsers compatibility, new tab is always after last one
401 auto openNewTabAfterLastTabConfigured
= GeneralSettings::openNewTabAfterLastTab();
402 GeneralSettings::setOpenNewTabAfterLastTab(true);
403 m_tabWidget
->openNewActivatedTab();
404 GeneralSettings::setOpenNewTabAfterLastTab(openNewTabAfterLastTabConfigured
);
407 void DolphinMainWindow::addToPlaces()
412 // If nothing is selected, act on the current dir
413 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
414 url
= m_activeViewContainer
->url();
415 name
= m_activeViewContainer
->placesText();
417 const auto dirToAdd
= m_activeViewContainer
->view()->selectedItems().first();
418 url
= dirToAdd
.url();
419 name
= dirToAdd
.name();
422 PlacesItemModel model
;
424 if (m_activeViewContainer
->isSearchModeEnabled()) {
425 icon
= QStringLiteral("folder-saved-search-symbolic");
427 icon
= KIO::iconNameForUrl(url
);
429 model
.createPlacesItem(name
, url
, icon
);
433 void DolphinMainWindow::openNewTab(const QUrl
& url
)
435 m_tabWidget
->openNewTab(url
, QUrl());
438 void DolphinMainWindow::openInNewTab()
440 const KFileItemList
& list
= m_activeViewContainer
->view()->selectedItems();
441 bool tabCreated
= false;
443 for (const KFileItem
& item
: list
) {
444 const QUrl
& url
= DolphinView::openItemAsFolderUrl(item
);
445 if (!url
.isEmpty()) {
451 // if no new tab has been created from the selection
452 // open the current directory in a new tab
454 openNewTab(m_activeViewContainer
->url());
458 void DolphinMainWindow::openInNewWindow()
462 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
463 if (list
.isEmpty()) {
464 newWindowUrl
= m_activeViewContainer
->url();
465 } else if (list
.count() == 1) {
466 const KFileItem
& item
= list
.first();
467 newWindowUrl
= DolphinView::openItemAsFolderUrl(item
);
470 if (!newWindowUrl
.isEmpty()) {
471 Dolphin::openNewWindow({newWindowUrl
}, this);
475 void DolphinMainWindow::showTarget()
477 const auto link
= m_activeViewContainer
->view()->selectedItems().at(0);
478 const auto linkLocationDir
= QFileInfo(link
.localPath()).absoluteDir();
479 auto linkDestination
= link
.linkDest();
480 if (QFileInfo(linkDestination
).isRelative()) {
481 linkDestination
= linkLocationDir
.filePath(linkDestination
);
483 if (QFileInfo::exists(linkDestination
)) {
484 KIO::highlightInFileManager({QUrl::fromLocalFile(linkDestination
).adjusted(QUrl::StripTrailingSlash
)});
486 m_activeViewContainer
->showMessage(xi18nc("@info", "Could not access <filename>%1</filename>.", linkDestination
),
487 DolphinViewContainer::Warning
);
491 void DolphinMainWindow::showEvent(QShowEvent
* event
)
493 KXmlGuiWindow::showEvent(event
);
495 if (!event
->spontaneous()) {
496 m_activeViewContainer
->view()->setFocus();
500 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
502 // Find out if Dolphin is closed directly by the user or
503 // by the session manager because the session is closed
504 bool closedByUser
= true;
505 if (qApp
->isSavingSession()) {
506 closedByUser
= false;
509 if (m_tabWidget
->count() > 1
510 && GeneralSettings::confirmClosingMultipleTabs()
511 && !GeneralSettings::rememberOpenedTabs()
513 // Ask the user if he really wants to quit and close all tabs.
514 // Open a confirmation dialog with 3 buttons:
515 // QDialogButtonBox::Yes -> Quit
516 // QDialogButtonBox::No -> Close only the current tab
517 // QDialogButtonBox::Cancel -> do nothing
518 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
519 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
520 dialog
->setModal(true);
521 QDialogButtonBox
* buttons
= new QDialogButtonBox(QDialogButtonBox::Yes
| QDialogButtonBox::No
| QDialogButtonBox::Cancel
);
522 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KGuiItem(i18nc("@action:button 'Quit Dolphin' button", "&Quit %1", QGuiApplication::applicationDisplayName()), QIcon::fromTheme(QStringLiteral("application-exit"))));
523 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("C&lose Current Tab"), QIcon::fromTheme(QStringLiteral("tab-close"))));
524 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
525 buttons
->button(QDialogButtonBox::Yes
)->setDefault(true);
527 bool doNotAskAgainCheckboxResult
= false;
529 const auto result
= KMessageBox::createKMessageBox(dialog
,
531 QMessageBox::Warning
,
532 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
534 i18n("Do not ask again"),
535 &doNotAskAgainCheckboxResult
,
536 KMessageBox::Notify
);
538 if (doNotAskAgainCheckboxResult
) {
539 GeneralSettings::setConfirmClosingMultipleTabs(false);
543 case QDialogButtonBox::Yes
:
546 case QDialogButtonBox::No
:
547 // Close only the current tab
548 m_tabWidget
->closeTab();
556 if (m_terminalPanel
&& m_terminalPanel
->hasProgramRunning() && GeneralSettings::confirmClosingTerminalRunningProgram() && closedByUser
) {
557 // Ask if the user really wants to quit Dolphin with a program that is still running in the Terminal panel
558 // Open a confirmation dialog with 3 buttons:
559 // QDialogButtonBox::Yes -> Quit
560 // QDialogButtonBox::No -> Show Terminal Panel
561 // QDialogButtonBox::Cancel -> do nothing
562 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
563 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
564 dialog
->setModal(true);
565 auto standardButtons
= QDialogButtonBox::Yes
| QDialogButtonBox::Cancel
;
566 if (!m_terminalPanel
->isVisible()) {
567 standardButtons
|= QDialogButtonBox::No
;
569 QDialogButtonBox
*buttons
= new QDialogButtonBox(standardButtons
);
570 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KStandardGuiItem::quit());
571 if (!m_terminalPanel
->isVisible()) {
573 buttons
->button(QDialogButtonBox::No
),
574 KGuiItem(i18n("Show &Terminal Panel"), QIcon::fromTheme(QStringLiteral("dialog-scripts"))));
576 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
578 bool doNotAskAgainCheckboxResult
= false;
580 const auto result
= KMessageBox::createKMessageBox(
583 QMessageBox::Warning
,
584 i18n("The program '%1' is still running in the Terminal panel. Are you sure you want to quit?", m_terminalPanel
->runningProgramName()),
586 i18n("Do not ask again"),
587 &doNotAskAgainCheckboxResult
,
588 KMessageBox::Dangerous
);
590 if (doNotAskAgainCheckboxResult
) {
591 GeneralSettings::setConfirmClosingTerminalRunningProgram(false);
595 case QDialogButtonBox::Yes
:
598 case QDialogButtonBox::No
:
599 actionCollection()->action("show_terminal_panel")->trigger();
600 // Do not quit, ignore quit event
608 if (GeneralSettings::rememberOpenedTabs()) {
609 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
610 KConfig
*config
= KConfigGui::sessionConfig();
611 saveGlobalProperties(config
);
612 savePropertiesInternal(config
, 1);
616 GeneralSettings::setVersion(CurrentDolphinVersion
);
617 GeneralSettings::self()->save();
619 KXmlGuiWindow::closeEvent(event
);
622 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
624 m_tabWidget
->saveProperties(group
);
627 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
629 m_tabWidget
->readProperties(group
);
632 void DolphinMainWindow::updateNewMenu()
634 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
635 m_newFileMenu
->checkUpToDate();
636 m_newFileMenu
->setPopupFiles(QList
<QUrl
>() << activeViewContainer()->url());
639 void DolphinMainWindow::createDirectory()
641 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
642 m_newFileMenu
->setPopupFiles(QList
<QUrl
>() << activeViewContainer()->url());
643 m_newFileMenu
->createDirectory();
646 void DolphinMainWindow::quit()
651 void DolphinMainWindow::showErrorMessage(const QString
& message
)
653 m_activeViewContainer
->showMessage(message
, DolphinViewContainer::Error
);
656 void DolphinMainWindow::slotUndoAvailable(bool available
)
658 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
660 undoAction
->setEnabled(available
);
664 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
666 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
668 undoAction
->setText(text
);
672 void DolphinMainWindow::undo()
675 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
676 KIO::FileUndoManager::self()->undo();
679 void DolphinMainWindow::cut()
681 m_activeViewContainer
->view()->cutSelectedItemsToClipboard();
684 void DolphinMainWindow::copy()
686 m_activeViewContainer
->view()->copySelectedItemsToClipboard();
689 void DolphinMainWindow::paste()
691 m_activeViewContainer
->view()->paste();
694 void DolphinMainWindow::find()
696 m_activeViewContainer
->setSearchModeEnabled(true);
699 void DolphinMainWindow::updateSearchAction()
701 QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
702 toggleSearchAction
->setChecked(m_activeViewContainer
->isSearchModeEnabled());
705 void DolphinMainWindow::updatePasteAction()
707 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
708 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
709 pasteAction
->setEnabled(pasteInfo
.first
);
710 pasteAction
->setText(pasteInfo
.second
);
713 void DolphinMainWindow::slotDirectoryLoadingCompleted()
718 void DolphinMainWindow::slotToolBarActionMiddleClicked(QAction
*action
)
720 if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Back
))) {
722 } else if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Forward
))) {
724 } else if (action
== actionCollection()->action(QStringLiteral("go_up"))) {
726 } else if (action
== actionCollection()->action(QStringLiteral("go_home"))) {
731 void DolphinMainWindow::slotAboutToShowBackPopupMenu()
733 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
735 m_backAction
->menu()->clear();
736 for (int i
= urlNavigator
->historyIndex() + 1; i
< urlNavigator
->historySize() && entries
< MaxNumberOfNavigationentries
; ++i
, ++entries
) {
737 QAction
* action
= new QAction(urlNavigator
->locationUrl(i
).toString(QUrl::PreferLocalFile
), m_backAction
->menu());
739 m_backAction
->menu()->addAction(action
);
743 void DolphinMainWindow::slotGoBack(QAction
* action
)
745 int gotoIndex
= action
->data().value
<int>();
746 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
747 for (int i
= gotoIndex
- urlNavigator
->historyIndex(); i
> 0; --i
) {
752 void DolphinMainWindow::slotBackForwardActionMiddleClicked(QAction
* action
)
755 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
756 openNewTab(urlNavigator
->locationUrl(action
->data().value
<int>()));
760 void DolphinMainWindow::slotAboutToShowForwardPopupMenu()
762 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
764 m_forwardAction
->menu()->clear();
765 for (int i
= urlNavigator
->historyIndex() - 1; i
>= 0 && entries
< MaxNumberOfNavigationentries
; --i
, ++entries
) {
766 QAction
* action
= new QAction(urlNavigator
->locationUrl(i
).toString(QUrl::PreferLocalFile
), m_forwardAction
->menu());
768 m_forwardAction
->menu()->addAction(action
);
772 void DolphinMainWindow::slotGoForward(QAction
* action
)
774 int gotoIndex
= action
->data().value
<int>();
775 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
776 for (int i
= urlNavigator
->historyIndex() - gotoIndex
; i
> 0; --i
) {
781 void DolphinMainWindow::selectAll()
785 // if the URL navigator is editable and focused, select the whole
786 // URL instead of all items of the view
788 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
789 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit();
790 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
791 lineEdit
->hasFocus();
793 lineEdit
->selectAll();
795 m_activeViewContainer
->view()->selectAll();
799 void DolphinMainWindow::invertSelection()
802 m_activeViewContainer
->view()->invertSelection();
805 void DolphinMainWindow::toggleSplitView()
807 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
808 tabPage
->setSplitViewEnabled(!tabPage
->splitViewEnabled(), WithAnimation
);
813 void DolphinMainWindow::toggleSplitStash()
815 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
816 tabPage
->setSplitViewEnabled(false, WithAnimation
);
817 tabPage
->setSplitViewEnabled(true, WithAnimation
, QUrl("stash:/"));
820 void DolphinMainWindow::reloadView()
823 m_activeViewContainer
->reload();
824 m_activeViewContainer
->statusBar()->updateSpaceInfo();
827 void DolphinMainWindow::stopLoading()
829 m_activeViewContainer
->view()->stopLoading();
832 void DolphinMainWindow::enableStopAction()
834 actionCollection()->action(QStringLiteral("stop"))->setEnabled(true);
837 void DolphinMainWindow::disableStopAction()
839 actionCollection()->action(QStringLiteral("stop"))->setEnabled(false);
842 void DolphinMainWindow::showFilterBar()
844 m_activeViewContainer
->setFilterBarVisible(true);
847 void DolphinMainWindow::toggleFilterBar()
849 const bool checked
= !m_activeViewContainer
->isFilterBarVisible();
850 m_activeViewContainer
->setFilterBarVisible(checked
);
852 QAction
* toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
853 toggleFilterBarAction
->setChecked(checked
);
856 void DolphinMainWindow::toggleEditLocation()
860 QAction
* action
= actionCollection()->action(QStringLiteral("editable_location"));
861 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
862 urlNavigator
->setUrlEditable(action
->isChecked());
865 void DolphinMainWindow::replaceLocation()
867 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
868 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit();
870 // If the text field currently has focus and everything is selected,
871 // pressing the keyboard shortcut returns the whole thing to breadcrumb mode
872 if (navigator
->isUrlEditable()
873 && lineEdit
->hasFocus()
874 && lineEdit
->selectedText() == lineEdit
->text() ) {
875 navigator
->setUrlEditable(false);
877 navigator
->setUrlEditable(true);
878 navigator
->setFocus();
879 lineEdit
->selectAll();
883 void DolphinMainWindow::togglePanelLockState()
885 const bool newLockState
= !GeneralSettings::lockPanels();
886 const auto childrenObjects
= children();
887 for (QObject
* child
: childrenObjects
) {
888 DolphinDockWidget
* dock
= qobject_cast
<DolphinDockWidget
*>(child
);
890 dock
->setLocked(newLockState
);
894 GeneralSettings::setLockPanels(newLockState
);
897 void DolphinMainWindow::slotTerminalPanelVisibilityChanged()
899 if (m_terminalPanel
->isHiddenInVisibleWindow() && m_activeViewContainer
) {
900 m_activeViewContainer
->view()->setFocus();
904 void DolphinMainWindow::goBack()
906 DolphinUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
907 urlNavigator
->goBack();
909 if (urlNavigator
->locationState().isEmpty()) {
910 // An empty location state indicates a redirection URL,
911 // which must be skipped too
912 urlNavigator
->goBack();
916 void DolphinMainWindow::goForward()
918 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goForward();
921 void DolphinMainWindow::goUp()
923 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goUp();
926 void DolphinMainWindow::goHome()
928 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goHome();
931 void DolphinMainWindow::goBackInNewTab()
933 const KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
934 const int index
= urlNavigator
->historyIndex() + 1;
935 openNewTab(urlNavigator
->locationUrl(index
));
938 void DolphinMainWindow::goForwardInNewTab()
940 const KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
941 const int index
= urlNavigator
->historyIndex() - 1;
942 openNewTab(urlNavigator
->locationUrl(index
));
945 void DolphinMainWindow::goUpInNewTab()
947 const QUrl currentUrl
= activeViewContainer()->urlNavigator()->locationUrl();
948 openNewTab(KIO::upUrl(currentUrl
));
951 void DolphinMainWindow::goHomeInNewTab()
953 openNewTab(Dolphin::homeUrl());
956 void DolphinMainWindow::compareFiles()
958 const KFileItemList items
= m_tabWidget
->currentTabPage()->selectedItems();
959 if (items
.count() != 2) {
960 // The action is disabled in this case, but it could have been triggered
961 // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
965 QUrl urlA
= items
.at(0).url();
966 QUrl urlB
= items
.at(1).url();
968 QString
command(QStringLiteral("kompare -c \""));
969 command
.append(urlA
.toDisplayString(QUrl::PreferLocalFile
));
970 command
.append("\" \"");
971 command
.append(urlB
.toDisplayString(QUrl::PreferLocalFile
));
972 command
.append('\"');
974 KIO::CommandLauncherJob
*job
= new KIO::CommandLauncherJob(command
, this);
975 job
->setDesktopName(QStringLiteral("org.kde.kompare"));
979 void DolphinMainWindow::toggleShowMenuBar()
981 const bool visible
= menuBar()->isVisible();
982 menuBar()->setVisible(!visible
);
984 createControlButton();
986 deleteControlButton();
990 QPointer
<QAction
> DolphinMainWindow::preferredSearchTool()
992 m_searchTools
.clear();
993 KMoreToolsMenuFactory("dolphin/search-tools").fillMenuFromGroupingNames(
994 &m_searchTools
, { "files-find" }, m_activeViewContainer
->url()
996 QList
<QAction
*> actions
= m_searchTools
.actions();
997 if (actions
.isEmpty()) {
1000 QAction
* action
= actions
.first();
1001 if (action
->isSeparator()) {
1007 void DolphinMainWindow::updateOpenPreferredSearchToolAction()
1009 QAction
* openPreferredSearchTool
= actionCollection()->action(QStringLiteral("open_preferred_search_tool"));
1010 if (!openPreferredSearchTool
) {
1013 QPointer
<QAction
> tool
= preferredSearchTool();
1015 openPreferredSearchTool
->setVisible(true);
1016 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open %1", tool
->text()));
1017 openPreferredSearchTool
->setIcon(tool
->icon());
1019 openPreferredSearchTool
->setVisible(false);
1020 // still visible in Shortcuts configuration window
1021 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1022 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1026 void DolphinMainWindow::openPreferredSearchTool()
1028 QPointer
<QAction
> tool
= preferredSearchTool();
1034 void DolphinMainWindow::openTerminal()
1036 const QUrl url
= m_activeViewContainer
->url();
1038 if (url
.isLocalFile()) {
1039 KToolInvocation::invokeTerminal(QString(), url
.toLocalFile());
1043 // Not a local file, with protocol Class ":local", try stat'ing
1044 if (KProtocolInfo::protocolClass(url
.scheme()) == QLatin1String(":local")) {
1045 KIO::StatJob
*job
= KIO::mostLocalUrl(url
);
1046 KJobWidgets::setWindow(job
, this);
1047 connect(job
, &KJob::result
, this, [job
]() {
1049 if (!job
->error()) {
1050 statUrl
= job
->mostLocalUrl();
1053 KToolInvocation::invokeTerminal(QString(), statUrl
.isLocalFile() ? statUrl
.toLocalFile() : QDir::homePath());
1059 // Nothing worked, just use $HOME
1060 KToolInvocation::invokeTerminal(QString(), QDir::homePath());
1063 void DolphinMainWindow::editSettings()
1065 if (!m_settingsDialog
) {
1066 DolphinViewContainer
* container
= activeViewContainer();
1067 container
->view()->writeSettings();
1069 const QUrl url
= container
->url();
1070 DolphinSettingsDialog
* settingsDialog
= new DolphinSettingsDialog(url
, this, actionCollection());
1071 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, this, &DolphinMainWindow::refreshViews
);
1072 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
,
1073 &DolphinUrlNavigatorsController::slotReadSettings
);
1074 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1075 settingsDialog
->show();
1076 m_settingsDialog
= settingsDialog
;
1078 m_settingsDialog
.data()->raise();
1082 void DolphinMainWindow::handleUrl(const QUrl
& url
)
1084 delete m_lastHandleUrlOpenJob
;
1085 m_lastHandleUrlOpenJob
= nullptr;
1087 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1088 activeViewContainer()->setUrl(url
);
1090 m_lastHandleUrlOpenJob
= new KIO::OpenUrlJob(url
);
1091 m_lastHandleUrlOpenJob
->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
1092 m_lastHandleUrlOpenJob
->setShowOpenOrExecuteDialog(true);
1094 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::mimeTypeFound
, this,
1095 [this, url
](const QString
&mimetype
) {
1096 if (mimetype
== QLatin1String("inode/directory")) {
1097 // If it's a dir, we'll take it from here
1098 m_lastHandleUrlOpenJob
->kill();
1099 m_lastHandleUrlOpenJob
= nullptr;
1100 activeViewContainer()->setUrl(url
);
1104 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::result
, this, [this]() {
1105 m_lastHandleUrlOpenJob
= nullptr;
1108 m_lastHandleUrlOpenJob
->start();
1112 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1114 // trash:/ is writable but we don't want to create new items in it.
1115 // TODO: remove the trash check once https://phabricator.kde.org/T8234 is implemented
1116 newFileMenu()->setEnabled(isFolderWritable
&& m_activeViewContainer
->url().scheme() != QLatin1String("trash"));
1119 void DolphinMainWindow::openContextMenu(const QPoint
& pos
,
1120 const KFileItem
& item
,
1122 const QList
<QAction
*>& customActions
)
1124 QPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, pos
, item
, url
);
1125 contextMenu
.data()->setCustomActions(customActions
);
1126 const DolphinContextMenu::Command command
= contextMenu
.data()->open();
1129 case DolphinContextMenu::OpenParentFolder
:
1130 changeUrl(KIO::upUrl(item
.url()));
1131 m_activeViewContainer
->view()->markUrlsAsSelected({item
.url()});
1132 m_activeViewContainer
->view()->markUrlAsCurrent(item
.url());
1135 case DolphinContextMenu::OpenParentFolderInNewWindow
:
1136 Dolphin::openNewWindow({item
.url()}, this, Dolphin::OpenNewWindowFlag::Select
);
1139 case DolphinContextMenu::OpenParentFolderInNewTab
:
1140 openNewTab(KIO::upUrl(item
.url()));
1143 case DolphinContextMenu::None
:
1148 // Delete the menu, unless it has been deleted in its own nested event loop already.
1150 contextMenu
->deleteLater();
1154 void DolphinMainWindow::updateControlMenu()
1156 QMenu
* menu
= qobject_cast
<QMenu
*>(sender());
1159 // All actions get cleared by QMenu::clear(). This includes the sub-menus
1160 // because 'menu' is their parent.
1163 KActionCollection
* ac
= actionCollection();
1165 menu
->addMenu(m_newFileMenu
->menu());
1166 addActionToMenu(ac
->action(QStringLiteral("file_new")), menu
);
1167 addActionToMenu(ac
->action(QStringLiteral("new_tab")), menu
);
1168 addActionToMenu(ac
->action(QStringLiteral("closed_tabs")), menu
);
1170 menu
->addSeparator();
1172 // Add "Edit" actions
1173 bool added
= addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Undo
)), menu
) |
1174 addActionToMenu(ac
->action(QString("copy_location")), menu
) |
1175 addActionToMenu(ac
->action(QStringLiteral("copy_to_inactive_split_view")), menu
) |
1176 addActionToMenu(ac
->action(QStringLiteral("move_to_inactive_split_view")), menu
) |
1177 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::SelectAll
)), menu
) |
1178 addActionToMenu(ac
->action(QStringLiteral("invert_selection")), menu
);
1181 menu
->addSeparator();
1184 // Add "View" actions
1185 if (!GeneralSettings::showZoomSlider()) {
1186 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomIn
)), menu
);
1187 addActionToMenu(ac
->action(QStringLiteral("view_zoom_reset")), menu
);
1188 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomOut
)), menu
);
1189 menu
->addSeparator();
1192 added
= addActionToMenu(ac
->action(QStringLiteral("show_preview")), menu
) |
1193 addActionToMenu(ac
->action(QStringLiteral("show_in_groups")), menu
) |
1194 addActionToMenu(ac
->action(QStringLiteral("show_hidden_files")), menu
) |
1195 addActionToMenu(ac
->action(QStringLiteral("additional_info")), menu
) |
1196 addActionToMenu(ac
->action(QStringLiteral("view_properties")), menu
);
1199 menu
->addSeparator();
1202 // Add a curated assortment of items from the "Tools" menu
1203 addActionToMenu(ac
->action(QStringLiteral("show_filter_bar")), menu
);
1204 addActionToMenu(ac
->action(QStringLiteral("open_preferred_search_tool")), menu
);
1205 addActionToMenu(ac
->action(QStringLiteral("open_terminal")), menu
);
1207 menu
->addSeparator();
1209 // Add "Show Panels" menu
1210 addActionToMenu(ac
->action(QStringLiteral("panels")), menu
);
1212 // Add "Settings" menu entries
1213 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)), menu
);
1214 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)), menu
);
1215 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Preferences
)), menu
);
1216 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)), menu
);
1219 auto helpMenu
= m_helpMenu
->menu();
1220 helpMenu
->setIcon(QIcon::fromTheme(QStringLiteral("system-help")));
1221 menu
->addMenu(helpMenu
);
1224 void DolphinMainWindow::updateToolBar()
1226 if (!menuBar()->isVisible()) {
1227 createControlButton();
1231 void DolphinMainWindow::slotControlButtonDeleted()
1233 m_controlButton
= nullptr;
1234 m_updateToolBarTimer
->start();
1237 void DolphinMainWindow::slotPlaceActivated(const QUrl
& url
)
1239 DolphinViewContainer
* view
= activeViewContainer();
1241 if (view
->url() == url
) {
1242 // We can end up here if the user clicked a device in the Places Panel
1243 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
1250 void DolphinMainWindow::closedTabsCountChanged(unsigned int count
)
1252 actionCollection()->action(QStringLiteral("undo_close_tab"))->setEnabled(count
> 0);
1255 void DolphinMainWindow::activeViewChanged(DolphinViewContainer
* viewContainer
)
1257 DolphinViewContainer
* oldViewContainer
= m_activeViewContainer
;
1258 Q_ASSERT(viewContainer
);
1260 m_activeViewContainer
= viewContainer
;
1262 if (oldViewContainer
) {
1263 const QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
1264 toggleSearchAction
->disconnect(oldViewContainer
);
1266 // Disconnect all signals between the old view container (container,
1267 // view and url navigator) and main window.
1268 oldViewContainer
->disconnect(this);
1269 oldViewContainer
->view()->disconnect(this);
1270 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
1271 (actionCollection()->action(QStringLiteral("url_navigators")));
1272 navigators
->primaryUrlNavigator()->disconnect(this);
1273 if (auto secondaryUrlNavigator
= navigators
->secondaryUrlNavigator()) {
1274 secondaryUrlNavigator
->disconnect(this);
1277 // except the requestItemInfo so that on hover the information panel can still be updated
1278 connect(oldViewContainer
->view(), &DolphinView::requestItemInfo
,
1279 this, &DolphinMainWindow::requestItemInfo
);
1282 connectViewSignals(viewContainer
);
1284 m_actionHandler
->setCurrentView(viewContainer
->view());
1287 updateFileAndEditActions();
1288 updatePasteAction();
1289 updateViewActions();
1291 updateSearchAction();
1293 const QUrl url
= viewContainer
->url();
1294 Q_EMIT
urlChanged(url
);
1297 void DolphinMainWindow::tabCountChanged(int count
)
1299 const bool enableTabActions
= (count
> 1);
1300 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1301 actionCollection()->action(QStringLiteral("activate_tab_%1").arg(i
))->setEnabled(enableTabActions
);
1303 actionCollection()->action(QStringLiteral("activate_last_tab"))->setEnabled(enableTabActions
);
1304 actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions
);
1305 actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions
);
1308 void DolphinMainWindow::updateWindowTitle()
1310 const QString newTitle
= m_activeViewContainer
->captionWindowTitle();
1311 if (windowTitle() != newTitle
) {
1312 setWindowTitle(newTitle
);
1316 void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString
& mountPath
)
1318 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1319 setViewsToHomeIfMountPathOpen(mountPath
);
1322 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectory().startsWith(mountPath
)) {
1323 m_tearDownFromPlacesRequested
= true;
1324 m_terminalPanel
->goHome();
1325 // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged
1327 m_placesPanel
->proceedWithTearDown();
1331 void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString
& mountPath
)
1333 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1334 setViewsToHomeIfMountPathOpen(mountPath
);
1337 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectory().startsWith(mountPath
)) {
1338 m_tearDownFromPlacesRequested
= false;
1339 m_terminalPanel
->goHome();
1343 void DolphinMainWindow::setViewsToHomeIfMountPathOpen(const QString
& mountPath
)
1345 const QVector
<DolphinViewContainer
*> theViewContainers
= viewContainers();
1346 for (DolphinViewContainer
*viewContainer
: theViewContainers
) {
1347 if (viewContainer
&& viewContainer
->url().toLocalFile().startsWith(mountPath
)) {
1348 viewContainer
->setUrl(QUrl::fromLocalFile(QDir::homePath()));
1351 disconnect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, nullptr, nullptr);
1354 void DolphinMainWindow::setupActions()
1356 // setup 'File' menu
1357 m_newFileMenu
= new DolphinNewFileMenu(actionCollection(), this);
1358 QMenu
* menu
= m_newFileMenu
->menu();
1359 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1360 menu
->setIcon(QIcon::fromTheme(QStringLiteral("document-new")));
1361 m_newFileMenu
->setDelayed(false);
1362 connect(menu
, &QMenu::aboutToShow
,
1363 this, &DolphinMainWindow::updateNewMenu
);
1365 QAction
* newWindow
= KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow
, actionCollection());
1366 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1367 newWindow
->setToolTip(i18nc("@info", "Open a new Dolphin window"));
1368 newWindow
->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1369 "window just like this one with the current location and view."
1370 "<nl/>You can drag and drop items between windows."));
1371 newWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1373 QAction
* newTab
= actionCollection()->addAction(QStringLiteral("new_tab"));
1374 newTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1375 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1376 newTab
->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1377 "<emphasis>Tab</emphasis> with the current location and view.<nl/>"
1378 "A tab is an additional view within this window. "
1379 "You can drag and drop items between tabs."));
1380 actionCollection()->setDefaultShortcuts(newTab
, {Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
});
1381 connect(newTab
, &QAction::triggered
, this, &DolphinMainWindow::openNewActivatedTab
);
1383 QAction
* addToPlaces
= actionCollection()->addAction(QStringLiteral("add_to_places"));
1384 addToPlaces
->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new")));
1385 addToPlaces
->setText(i18nc("@action:inmenu Add current folder to places", "Add to Places"));
1386 addToPlaces
->setWhatsThis(xi18nc("@info:whatsthis", "This adds the selected folder "
1387 "to the Places panel."));
1388 connect(addToPlaces
, &QAction::triggered
, this, &DolphinMainWindow::addToPlaces
);
1390 QAction
* closeTab
= KStandardAction::close(m_tabWidget
, QOverload
<>::of(&DolphinTabWidget::closeTab
), actionCollection());
1391 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1392 closeTab
->setWhatsThis(i18nc("@info:whatsthis", "This closes the "
1393 "currently viewed tab. If no more tabs are left this window "
1394 "will close instead."));
1396 QAction
* quitAction
= KStandardAction::quit(this, &DolphinMainWindow::quit
, actionCollection());
1397 quitAction
->setWhatsThis(i18nc("@info:whatsthis quit", "This closes this window."));
1399 // setup 'Edit' menu
1400 KStandardAction::undo(this,
1401 &DolphinMainWindow::undo
,
1402 actionCollection());
1404 // i18n: This will be the last paragraph for the whatsthis for all three:
1405 // Cut, Copy and Paste
1406 const QString cutCopyPastePara
= xi18nc("@info:whatsthis", "<para><emphasis>Cut, "
1407 "Copy</emphasis> and <emphasis>Paste</emphasis> work between many "
1408 "applications and are among the most used commands. That's why their "
1409 "<emphasis>keyboard shortcuts</emphasis> are prominently placed right "
1410 "next to each other on the keyboard: <shortcut>Ctrl+X</shortcut>, "
1411 "<shortcut>Ctrl+C</shortcut> and <shortcut>Ctrl+V</shortcut>.</para>");
1412 QAction
* cutAction
= KStandardAction::cut(this, &DolphinMainWindow::cut
, actionCollection());
1413 cutAction
->setWhatsThis(xi18nc("@info:whatsthis cut", "This copies the items "
1414 "in your current selection to the <emphasis>clipboard</emphasis>.<nl/>"
1415 "Use the <emphasis>Paste</emphasis> action afterwards to copy them from "
1416 "the clipboard to a new location. The items will be removed from their "
1417 "initial location.") + cutCopyPastePara
);
1418 QAction
* copyAction
= KStandardAction::copy(this, &DolphinMainWindow::copy
, actionCollection());
1419 copyAction
->setWhatsThis(xi18nc("@info:whatsthis copy", "This copies the "
1420 "items in your current selection to the <emphasis>clipboard</emphasis>."
1421 "<nl/>Use the <emphasis>Paste</emphasis> action afterwards to copy them "
1422 "from the clipboard to a new location.") + cutCopyPastePara
);
1423 QAction
* paste
= KStandardAction::paste(this, &DolphinMainWindow::paste
, actionCollection());
1424 // The text of the paste-action is modified dynamically by Dolphin
1425 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1426 // due to the long text, the text "Paste" is used:
1427 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1428 paste
->setWhatsThis(xi18nc("@info:whatsthis paste", "This copies the items from "
1429 "your <emphasis>clipboard</emphasis> to the currently viewed folder.<nl/>"
1430 "If the items were added to the clipboard by the <emphasis>Cut</emphasis> "
1431 "action they are removed from their old location.") + cutCopyPastePara
);
1433 QAction
* copyToOtherViewAction
= actionCollection()->addAction(QStringLiteral("copy_to_inactive_split_view"));
1434 copyToOtherViewAction
->setText(i18nc("@action:inmenu", "Copy to Inactive Split View"));
1435 copyToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Copy", "This copies the selected items from "
1436 "the <emphasis>active</emphasis> view to the inactive split view."));
1437 copyToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
1438 copyToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Copy to Inactive Split View"));
1439 actionCollection()->setDefaultShortcut(copyToOtherViewAction
, Qt::SHIFT
| Qt::Key_F5
);
1440 connect(copyToOtherViewAction
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::copyToInactiveSplitView
);
1442 QAction
* moveToOtherViewAction
= actionCollection()->addAction(QStringLiteral("move_to_inactive_split_view"));
1443 moveToOtherViewAction
->setText(i18nc("@action:inmenu", "Move to Inactive Split View"));
1444 moveToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Move", "This moves the selected items from "
1445 "the <emphasis>active</emphasis> view to the inactive split view."));
1446 moveToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-cut")));
1447 moveToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Move to Inactive Split View"));
1448 actionCollection()->setDefaultShortcut(moveToOtherViewAction
, Qt::SHIFT
| Qt::Key_F6
);
1449 connect(moveToOtherViewAction
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::moveToInactiveSplitView
);
1451 QAction
* showFilterBar
= actionCollection()->addAction(QStringLiteral("show_filter_bar"));
1452 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Filter..."));
1453 showFilterBar
->setToolTip(i18nc("@info:tooltip", "Toggle Filter Bar"));
1454 showFilterBar
->setWhatsThis(xi18nc("@info:whatsthis", "This opens the "
1455 "<emphasis>Filter Bar</emphasis> at the bottom of the window.<nl/> "
1456 "There you can enter a text to filter the files and folders currently displayed. "
1457 "Only those that contain the text in their name will be kept in view."));
1458 showFilterBar
->setIcon(QIcon::fromTheme(QStringLiteral("view-filter")));
1459 actionCollection()->setDefaultShortcuts(showFilterBar
, {Qt::CTRL
| Qt::Key_I
, Qt::Key_Slash
});
1460 connect(showFilterBar
, &QAction::triggered
, this, &DolphinMainWindow::showFilterBar
);
1462 // toggle_filter acts as a copy of the main showFilterBar to be used mainly
1463 // in the toolbar, with no default shortcut attached, to avoid messing with
1464 // existing workflows (filter bar always open and Ctrl-I to focus)
1465 QAction
*toggleFilter
= actionCollection()->addAction(QStringLiteral("toggle_filter"));
1466 toggleFilter
->setText(i18nc("@action:inmenu", "Toggle Filter Bar"));
1467 toggleFilter
->setIconText(i18nc("@action:intoolbar", "Filter"));
1468 toggleFilter
->setIcon(showFilterBar
->icon());
1469 toggleFilter
->setToolTip(showFilterBar
->toolTip());
1470 toggleFilter
->setWhatsThis(showFilterBar
->whatsThis());
1471 toggleFilter
->setCheckable(true);
1472 connect(toggleFilter
, &QAction::triggered
, this, &DolphinMainWindow::toggleFilterBar
);
1474 QAction
*searchAction
= KStandardAction::find(this, &DolphinMainWindow::find
, actionCollection());
1475 searchAction
->setText(i18n("Search..."));
1476 searchAction
->setToolTip(i18nc("@info:tooltip", "Search for files and folders"));
1477 searchAction
->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This helps you "
1478 "find files and folders by opening a <emphasis>find bar</emphasis>. "
1479 "There you can enter search terms and specify settings to find the "
1480 "objects you are looking for.</para><para>Use this help again on "
1481 "the find bar so we can have a look at it while the settings are "
1482 "explained.</para>"));
1484 // toggle_search acts as a copy of the main searchAction to be used mainly
1485 // in the toolbar, with no default shortcut attached, to avoid messing with
1486 // existing workflows (search bar always open and Ctrl-F to focus)
1487 QAction
*toggleSearchAction
= actionCollection()->addAction(QStringLiteral("toggle_search"));
1488 toggleSearchAction
->setText(i18nc("@action:inmenu", "Toggle Search Bar"));
1489 toggleSearchAction
->setIconText(i18nc("@action:intoolbar", "Search"));
1490 toggleSearchAction
->setIcon(searchAction
->icon());
1491 toggleSearchAction
->setToolTip(searchAction
->toolTip());
1492 toggleSearchAction
->setWhatsThis(searchAction
->whatsThis());
1493 toggleSearchAction
->setCheckable(true);
1495 QAction
* selectAllAction
= KStandardAction::selectAll(this, &DolphinMainWindow::selectAll
, actionCollection());
1496 selectAllAction
->setWhatsThis(xi18nc("@info:whatsthis", "This selects all "
1497 "files and folders in the current location."));
1499 QAction
* invertSelection
= actionCollection()->addAction(QStringLiteral("invert_selection"));
1500 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1501 invertSelection
->setWhatsThis(xi18nc("@info:whatsthis invert", "This selects all "
1502 "objects that you have currently <emphasis>not</emphasis> selected instead."));
1503 invertSelection
->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-invert")));
1504 actionCollection()->setDefaultShortcut(invertSelection
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1505 connect(invertSelection
, &QAction::triggered
, this, &DolphinMainWindow::invertSelection
);
1507 // setup 'View' menu
1508 // (note that most of it is set up in DolphinViewActionHandler)
1510 QAction
* split
= actionCollection()->addAction(QStringLiteral("split_view"));
1511 split
->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This splits "
1512 "the folder view below into two autonomous views.</para><para>This "
1513 "way you can see two locations at once and move items between them "
1514 "quickly.</para>Click this again afterwards to recombine the views."));
1515 actionCollection()->setDefaultShortcut(split
, Qt::Key_F3
);
1516 connect(split
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitView
);
1518 QAction
* stashSplit
= actionCollection()->addAction(QStringLiteral("split_stash"));
1519 actionCollection()->setDefaultShortcut(stashSplit
, Qt::CTRL
| Qt::Key_S
);
1520 stashSplit
->setText(i18nc("@action:intoolbar Stash", "Stash"));
1521 stashSplit
->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
1522 stashSplit
->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
1523 stashSplit
->setCheckable(false);
1524 stashSplit
->setVisible(QDBusConnection::sessionBus().interface()->isServiceRegistered(QStringLiteral("org.kde.kio.StashNotifier")));
1525 connect(stashSplit
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitStash
);
1527 KStandardAction::redisplay(this, &DolphinMainWindow::reloadView
, actionCollection());
1529 QAction
* stop
= actionCollection()->addAction(QStringLiteral("stop"));
1530 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1531 stop
->setToolTip(i18nc("@info", "Stop loading"));
1532 stop
->setWhatsThis(i18nc("@info", "This stops the loading of the contents of the current folder."));
1533 stop
->setIcon(QIcon::fromTheme(QStringLiteral("process-stop")));
1534 connect(stop
, &QAction::triggered
, this, &DolphinMainWindow::stopLoading
);
1536 KToggleAction
* editableLocation
= actionCollection()->add
<KToggleAction
>(QStringLiteral("editable_location"));
1537 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1538 editableLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1539 "This toggles the <emphasis>Location Bar</emphasis> to be "
1540 "editable so you can directly enter a location you want to go to.<nl/>"
1541 "You can also switch to editing by clicking to the right of the "
1542 "location and switch back by confirming the edited location."));
1543 actionCollection()->setDefaultShortcut(editableLocation
, Qt::Key_F6
);
1544 connect(editableLocation
, &KToggleAction::triggered
, this, &DolphinMainWindow::toggleEditLocation
);
1546 QAction
* replaceLocation
= actionCollection()->addAction(QStringLiteral("replace_location"));
1547 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1548 // i18n: "enter" is used both in the meaning of "writing" and "going to" a new location here.
1549 // Both meanings are useful but not necessary to understand the use of "Replace Location".
1550 // So you might want to be more verbose in your language to convey the meaning but it's up to you.
1551 replaceLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1552 "This switches to editing the location and selects it "
1553 "so you can quickly enter a different location."));
1554 actionCollection()->setDefaultShortcut(replaceLocation
, Qt::CTRL
| Qt::Key_L
);
1555 connect(replaceLocation
, &QAction::triggered
, this, &DolphinMainWindow::replaceLocation
);
1559 QScopedPointer
<QAction
> backAction(KStandardAction::back(nullptr, nullptr, nullptr));
1560 m_backAction
= new KToolBarPopupAction(backAction
->icon(), backAction
->text(), actionCollection());
1561 m_backAction
->setObjectName(backAction
->objectName());
1562 m_backAction
->setShortcuts(backAction
->shortcuts());
1564 m_backAction
->setDelayed(true);
1565 m_backAction
->setStickyMenu(false);
1566 connect(m_backAction
, &QAction::triggered
, this, &DolphinMainWindow::goBack
);
1567 connect(m_backAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowBackPopupMenu
);
1568 connect(m_backAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoBack
);
1569 actionCollection()->addAction(m_backAction
->objectName(), m_backAction
);
1571 auto backShortcuts
= m_backAction
->shortcuts();
1572 backShortcuts
.append(QKeySequence(Qt::Key_Backspace
));
1573 actionCollection()->setDefaultShortcuts(m_backAction
, backShortcuts
);
1575 DolphinRecentTabsMenu
* recentTabsMenu
= new DolphinRecentTabsMenu(this);
1576 actionCollection()->addAction(QStringLiteral("closed_tabs"), recentTabsMenu
);
1577 connect(m_tabWidget
, &DolphinTabWidget::rememberClosedTab
,
1578 recentTabsMenu
, &DolphinRecentTabsMenu::rememberClosedTab
);
1579 connect(recentTabsMenu
, &DolphinRecentTabsMenu::restoreClosedTab
,
1580 m_tabWidget
, &DolphinTabWidget::restoreClosedTab
);
1581 connect(recentTabsMenu
, &DolphinRecentTabsMenu::closedTabsCountChanged
,
1582 this, &DolphinMainWindow::closedTabsCountChanged
);
1584 QAction
* undoCloseTab
= actionCollection()->addAction(QStringLiteral("undo_close_tab"));
1585 undoCloseTab
->setText(i18nc("@action:inmenu File", "Undo close tab"));
1586 undoCloseTab
->setWhatsThis(i18nc("@info:whatsthis undo close tab",
1587 "This returns you to the previously closed tab."));
1588 actionCollection()->setDefaultShortcut(undoCloseTab
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_T
);
1589 undoCloseTab
->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo")));
1590 undoCloseTab
->setEnabled(false);
1591 connect(undoCloseTab
, &QAction::triggered
, recentTabsMenu
, &DolphinRecentTabsMenu::undoCloseTab
);
1593 auto undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
1594 undoAction
->setWhatsThis(xi18nc("@info:whatsthis", "This undoes "
1595 "the last change you made to files or folders.<nl/>"
1596 "Such changes include <interface>creating, renaming</interface> "
1597 "and <interface>moving</interface> them to a different location "
1598 "or to the <filename>Trash</filename>. <nl/>Changes that can't "
1599 "be undone will ask for your confirmation."));
1600 undoAction
->setEnabled(false); // undo should be disabled by default
1603 QScopedPointer
<QAction
> forwardAction(KStandardAction::forward(nullptr, nullptr, nullptr));
1604 m_forwardAction
= new KToolBarPopupAction(forwardAction
->icon(), forwardAction
->text(), actionCollection());
1605 m_forwardAction
->setObjectName(forwardAction
->objectName());
1606 m_forwardAction
->setShortcuts(forwardAction
->shortcuts());
1608 m_forwardAction
->setDelayed(true);
1609 m_forwardAction
->setStickyMenu(false);
1610 connect(m_forwardAction
, &QAction::triggered
, this, &DolphinMainWindow::goForward
);
1611 connect(m_forwardAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowForwardPopupMenu
);
1612 connect(m_forwardAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoForward
);
1613 actionCollection()->addAction(m_forwardAction
->objectName(), m_forwardAction
);
1614 actionCollection()->setDefaultShortcuts(m_forwardAction
, m_forwardAction
->shortcuts());
1616 // enable middle-click to open in a new tab
1617 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
1618 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotBackForwardActionMiddleClicked
);
1619 m_backAction
->menu()->installEventFilter(middleClickEventFilter
);
1620 m_forwardAction
->menu()->installEventFilter(middleClickEventFilter
);
1621 KStandardAction::up(this, &DolphinMainWindow::goUp
, actionCollection());
1622 QAction
* homeAction
= KStandardAction::home(this, &DolphinMainWindow::goHome
, actionCollection());
1623 homeAction
->setWhatsThis(xi18nc("@info:whatsthis", "Go to your "
1624 "<filename>Home</filename> folder.<nl/>Every user account "
1625 "has their own <filename>Home</filename> that contains their data "
1626 "including folders that contain personal application data."));
1628 // setup 'Tools' menu
1629 QAction
* compareFiles
= actionCollection()->addAction(QStringLiteral("compare_files"));
1630 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1631 compareFiles
->setIcon(QIcon::fromTheme(QStringLiteral("kompare")));
1632 compareFiles
->setEnabled(false);
1633 connect(compareFiles
, &QAction::triggered
, this, &DolphinMainWindow::compareFiles
);
1635 QAction
* openPreferredSearchTool
= actionCollection()->addAction(QStringLiteral("open_preferred_search_tool"));
1636 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1637 openPreferredSearchTool
->setWhatsThis(xi18nc("@info:whatsthis",
1638 "<para>This opens a preferred search tool for the viewed location.</para>"
1639 "<para>Use <emphasis>More Search Tools</emphasis> menu to configure it.</para>"));
1640 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1641 actionCollection()->setDefaultShortcut(openPreferredSearchTool
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F
);
1642 connect(openPreferredSearchTool
, &QAction::triggered
, this, &DolphinMainWindow::openPreferredSearchTool
);
1644 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1645 QAction
* openTerminal
= actionCollection()->addAction(QStringLiteral("open_terminal"));
1646 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1647 openTerminal
->setWhatsThis(xi18nc("@info:whatsthis",
1648 "<para>This opens a <emphasis>terminal</emphasis> application for the viewed location.</para>"
1649 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1650 openTerminal
->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
1651 actionCollection()->setDefaultShortcut(openTerminal
, Qt::SHIFT
| Qt::Key_F4
);
1652 connect(openTerminal
, &QAction::triggered
, this, &DolphinMainWindow::openTerminal
);
1654 #ifdef HAVE_TERMINAL
1655 QAction
* focusTerminalPanel
= actionCollection()->addAction(QStringLiteral("focus_terminal_panel"));
1656 focusTerminalPanel
->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
1657 focusTerminalPanel
->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
1658 actionCollection()->setDefaultShortcut(focusTerminalPanel
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F4
);
1659 connect(focusTerminalPanel
, &QAction::triggered
, this, &DolphinMainWindow::focusTerminalPanel
);
1663 // setup 'Bookmarks' menu
1664 KActionMenu
*bookmarkMenu
= new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this);
1665 bookmarkMenu
->setIcon(QIcon::fromTheme(QStringLiteral("bookmarks")));
1666 // Make the toolbar button version work properly on click
1667 bookmarkMenu
->setDelayed(false);
1668 m_bookmarkHandler
= new DolphinBookmarkHandler(this, actionCollection(), bookmarkMenu
->menu(), this);
1669 actionCollection()->addAction(QStringLiteral("bookmarks"), bookmarkMenu
);
1671 // setup 'Settings' menu
1672 KToggleAction
* showMenuBar
= KStandardAction::showMenubar(nullptr, nullptr, actionCollection());
1673 showMenuBar
->setWhatsThis(xi18nc("@info:whatsthis",
1674 "This switches between having a <emphasis>Menubar</emphasis> "
1675 "and having a <interface>Control</interface> button. Both "
1676 "contain mostly the same commands and configuration options."));
1677 connect(showMenuBar
, &KToggleAction::triggered
, // Fixes #286822
1678 this, &DolphinMainWindow::toggleShowMenuBar
, Qt::QueuedConnection
);
1679 KStandardAction::preferences(this, &DolphinMainWindow::editSettings
, actionCollection());
1681 // setup 'Help' menu for the m_controlButton. The other one is set up in the base class.
1682 m_helpMenu
= new KHelpMenu(nullptr);
1683 m_helpMenu
->menu()->installEventFilter(this);
1684 // remove duplicate shortcuts
1685 m_helpMenu
->action(KHelpMenu::menuHelpContents
)->setShortcut(QKeySequence());
1686 m_helpMenu
->action(KHelpMenu::menuWhatsThis
)->setShortcut(QKeySequence());
1688 // not in menu actions
1689 QList
<QKeySequence
> nextTabKeys
= KStandardShortcut::tabNext();
1690 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
1692 QList
<QKeySequence
> prevTabKeys
= KStandardShortcut::tabPrev();
1693 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
1695 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1696 QAction
* activateTab
= actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i
));
1697 activateTab
->setText(i18nc("@action:inmenu", "Activate Tab %1", i
+ 1));
1698 activateTab
->setEnabled(false);
1699 connect(activateTab
, &QAction::triggered
, this, [this, i
]() { m_tabWidget
->activateTab(i
); });
1701 // only add default shortcuts for the first 9 tabs regardless of MaxActivateTabShortcuts
1703 actionCollection()->setDefaultShortcut(activateTab
, QStringLiteral("Alt+%1").arg(i
+ 1));
1707 QAction
* activateLastTab
= actionCollection()->addAction(QStringLiteral("activate_last_tab"));
1708 activateLastTab
->setText(i18nc("@action:inmenu", "Activate Last Tab"));
1709 activateLastTab
->setEnabled(false);
1710 connect(activateLastTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateLastTab
);
1711 actionCollection()->setDefaultShortcut(activateLastTab
, Qt::ALT
| Qt::Key_0
);
1713 QAction
* activateNextTab
= actionCollection()->addAction(QStringLiteral("activate_next_tab"));
1714 activateNextTab
->setIconText(i18nc("@action:inmenu", "Next Tab"));
1715 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1716 activateNextTab
->setEnabled(false);
1717 connect(activateNextTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateNextTab
);
1718 actionCollection()->setDefaultShortcuts(activateNextTab
, nextTabKeys
);
1720 QAction
* activatePrevTab
= actionCollection()->addAction(QStringLiteral("activate_prev_tab"));
1721 activatePrevTab
->setIconText(i18nc("@action:inmenu", "Previous Tab"));
1722 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1723 activatePrevTab
->setEnabled(false);
1724 connect(activatePrevTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activatePrevTab
);
1725 actionCollection()->setDefaultShortcuts(activatePrevTab
, prevTabKeys
);
1728 QAction
* showTarget
= actionCollection()->addAction(QStringLiteral("show_target"));
1729 showTarget
->setText(i18nc("@action:inmenu", "Show Target"));
1730 showTarget
->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
1731 showTarget
->setEnabled(false);
1732 connect(showTarget
, &QAction::triggered
, this, &DolphinMainWindow::showTarget
);
1734 QAction
* openInNewTab
= actionCollection()->addAction(QStringLiteral("open_in_new_tab"));
1735 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1736 openInNewTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1737 connect(openInNewTab
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
1739 QAction
* openInNewTabs
= actionCollection()->addAction(QStringLiteral("open_in_new_tabs"));
1740 openInNewTabs
->setText(i18nc("@action:inmenu", "Open in New Tabs"));
1741 openInNewTabs
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1742 connect(openInNewTabs
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
1744 QAction
* openInNewWindow
= actionCollection()->addAction(QStringLiteral("open_in_new_window"));
1745 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1746 openInNewWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1747 connect(openInNewWindow
, &QAction::triggered
, this, &DolphinMainWindow::openInNewWindow
);
1750 void DolphinMainWindow::setupDockWidgets()
1752 const bool lock
= GeneralSettings::lockPanels();
1754 KDualAction
* lockLayoutAction
= actionCollection()->add
<KDualAction
>(QStringLiteral("lock_panels"));
1755 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1756 lockLayoutAction
->setActiveIcon(QIcon::fromTheme(QStringLiteral("object-unlocked")));
1757 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1758 lockLayoutAction
->setInactiveIcon(QIcon::fromTheme(QStringLiteral("object-locked")));
1759 lockLayoutAction
->setWhatsThis(xi18nc("@info:whatsthis", "This "
1760 "switches between having panels <emphasis>locked</emphasis> or "
1761 "<emphasis>unlocked</emphasis>.<nl/>Unlocked panels can be "
1762 "dragged to the other side of the window and have a close "
1763 "button.<nl/>Locked panels are embedded more cleanly."));
1764 lockLayoutAction
->setActive(lock
);
1765 connect(lockLayoutAction
, &KDualAction::triggered
, this, &DolphinMainWindow::togglePanelLockState
);
1767 // Setup "Information"
1768 DolphinDockWidget
* infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
1769 infoDock
->setLocked(lock
);
1770 infoDock
->setObjectName(QStringLiteral("infoDock"));
1771 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1774 InformationPanel
* infoPanel
= new InformationPanel(infoDock
);
1775 infoPanel
->setCustomContextMenuActions({lockLayoutAction
});
1776 connect(infoPanel
, &InformationPanel::urlActivated
, this, &DolphinMainWindow::handleUrl
);
1777 infoDock
->setWidget(infoPanel
);
1779 QAction
* infoAction
= infoDock
->toggleViewAction();
1780 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-information")), Qt::Key_F11
, infoAction
, QStringLiteral("show_information_panel"));
1782 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1783 connect(this, &DolphinMainWindow::urlChanged
,
1784 infoPanel
, &InformationPanel::setUrl
);
1785 connect(this, &DolphinMainWindow::selectionChanged
,
1786 infoPanel
, &InformationPanel::setSelection
);
1787 connect(this, &DolphinMainWindow::requestItemInfo
,
1788 infoPanel
, &InformationPanel::requestDelayedItemInfo
);
1791 // i18n: This is the last paragraph for the "What's This"-texts of all four panels.
1792 const QString panelWhatsThis
= xi18nc("@info:whatsthis", "<para>To show or "
1793 "hide panels like this go to <interface>Control|Panels</interface> "
1794 "or <interface>View|Panels</interface>.</para>");
1796 actionCollection()->action(QStringLiteral("show_information_panel"))
1797 ->setWhatsThis(xi18nc("@info:whatsthis", "<para> This toggles the "
1798 "<emphasis>information</emphasis> panel at the right side of the "
1799 "window.</para><para>The panel provides in-depth information "
1800 "about the items your mouse is hovering over or about the selected "
1801 "items. Otherwise it informs you about the currently viewed folder.<nl/>"
1802 "For single items a preview of their contents is provided.</para>"));
1804 infoDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
1805 "provides in-depth information about the items your mouse is "
1806 "hovering over or about the selected items. Otherwise it informs "
1807 "you about the currently viewed folder.<nl/>For single items a "
1808 "preview of their contents is provided.</para><para>You can configure "
1809 "which and how details are given here by right-clicking.</para>") + panelWhatsThis
);
1812 DolphinDockWidget
* foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
1813 foldersDock
->setLocked(lock
);
1814 foldersDock
->setObjectName(QStringLiteral("foldersDock"));
1815 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1816 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1817 foldersPanel
->setCustomContextMenuActions({lockLayoutAction
});
1818 foldersDock
->setWidget(foldersPanel
);
1820 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1821 createPanelAction(QIcon::fromTheme(QStringLiteral("folder")), Qt::Key_F7
, foldersAction
, QStringLiteral("show_folders_panel"));
1823 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1824 connect(this, &DolphinMainWindow::urlChanged
,
1825 foldersPanel
, &FoldersPanel::setUrl
);
1826 connect(foldersPanel
, &FoldersPanel::folderActivated
,
1827 this, &DolphinMainWindow::changeUrl
);
1828 connect(foldersPanel
, &FoldersPanel::folderMiddleClicked
,
1829 this, &DolphinMainWindow::openNewTab
);
1830 connect(foldersPanel
, &FoldersPanel::errorMessage
,
1831 this, &DolphinMainWindow::showErrorMessage
);
1833 actionCollection()->action(QStringLiteral("show_folders_panel"))
1834 ->setWhatsThis(xi18nc("@info:whatsthis", "This toggles the "
1835 "<emphasis>folders</emphasis> panel at the left side of the window."
1836 "<nl/><nl/>It shows the folders of the <emphasis>file system"
1837 "</emphasis> in a <emphasis>tree view</emphasis>."));
1838 foldersDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
1839 "shows the folders of the <emphasis>file system</emphasis> in a "
1840 "<emphasis>tree view</emphasis>.</para><para>Click a folder to go "
1841 "there. Click the arrow to the left of a folder to see its subfolders. "
1842 "This allows quick switching between any folders.</para>") + panelWhatsThis
);
1845 #ifdef HAVE_TERMINAL
1846 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1847 DolphinDockWidget
* terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1848 terminalDock
->setLocked(lock
);
1849 terminalDock
->setObjectName(QStringLiteral("terminalDock"));
1850 m_terminalPanel
= new TerminalPanel(terminalDock
);
1851 m_terminalPanel
->setCustomContextMenuActions({lockLayoutAction
});
1852 terminalDock
->setWidget(m_terminalPanel
);
1854 connect(m_terminalPanel
, &TerminalPanel::hideTerminalPanel
, terminalDock
, &DolphinDockWidget::hide
);
1855 connect(m_terminalPanel
, &TerminalPanel::changeUrl
, this, &DolphinMainWindow::slotTerminalDirectoryChanged
);
1856 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
,
1857 m_terminalPanel
, &TerminalPanel::dockVisibilityChanged
);
1858 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
,
1859 this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged
);
1861 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1862 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-scripts")), Qt::Key_F4
, terminalAction
, QStringLiteral("show_terminal_panel"));
1864 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1865 connect(this, &DolphinMainWindow::urlChanged
,
1866 m_terminalPanel
, &TerminalPanel::setUrl
);
1868 if (GeneralSettings::version() < 200) {
1869 terminalDock
->hide();
1872 actionCollection()->action(QStringLiteral("show_terminal_panel"))
1873 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
1874 "<emphasis>terminal</emphasis> panel at the bottom of the window."
1875 "<nl/>The location in the terminal will always match the folder "
1876 "view so you can navigate using either.</para><para>The terminal "
1877 "panel is not needed for basic computer usage but can be useful "
1878 "for advanced tasks. To learn more about terminals use the help "
1879 "in a standalone terminal application like Konsole.</para>"));
1880 terminalDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is "
1881 "the <emphasis>terminal</emphasis> panel. It behaves like a "
1882 "normal terminal but will match the location of the folder view "
1883 "so you can navigate using either.</para><para>The terminal panel "
1884 "is not needed for basic computer usage but can be useful for "
1885 "advanced tasks. To learn more about terminals use the help in a "
1886 "standalone terminal application like Konsole.</para>") + panelWhatsThis
);
1890 if (GeneralSettings::version() < 200) {
1892 foldersDock
->hide();
1896 DolphinDockWidget
* placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
1897 placesDock
->setLocked(lock
);
1898 placesDock
->setObjectName(QStringLiteral("placesDock"));
1899 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1901 m_placesPanel
= new PlacesPanel(placesDock
);
1902 m_placesPanel
->setCustomContextMenuActions({lockLayoutAction
});
1903 placesDock
->setWidget(m_placesPanel
);
1905 QAction
*placesAction
= placesDock
->toggleViewAction();
1906 createPanelAction(QIcon::fromTheme(QStringLiteral("compass")), Qt::Key_F9
, placesAction
, QStringLiteral("show_places_panel"));
1908 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1909 connect(m_placesPanel
, &PlacesPanel::placeActivated
,
1910 this, &DolphinMainWindow::slotPlaceActivated
);
1911 connect(m_placesPanel
, &PlacesPanel::placeMiddleClicked
,
1912 this, &DolphinMainWindow::openNewTab
);
1913 connect(m_placesPanel
, &PlacesPanel::errorMessage
,
1914 this, &DolphinMainWindow::showErrorMessage
);
1915 connect(this, &DolphinMainWindow::urlChanged
,
1916 m_placesPanel
, &PlacesPanel::setUrl
);
1917 connect(placesDock
, &DolphinDockWidget::visibilityChanged
,
1918 &DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged
);
1919 connect(this, &DolphinMainWindow::settingsChanged
,
1920 m_placesPanel
, &PlacesPanel::readSettings
);
1921 connect(m_placesPanel
, &PlacesPanel::storageTearDownRequested
,
1922 this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested
);
1923 connect(m_placesPanel
, &PlacesPanel::storageTearDownExternallyRequested
,
1924 this, &DolphinMainWindow::slotStorageTearDownExternallyRequested
);
1925 DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged(m_placesPanel
->isVisible());
1927 auto actionShowAllPlaces
= new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this);
1928 actionShowAllPlaces
->setCheckable(true);
1929 actionShowAllPlaces
->setDisabled(true);
1930 actionShowAllPlaces
->setWhatsThis(i18nc("@info:whatsthis", "This displays "
1931 "all places in the places panel that have been hidden. They will "
1932 "appear semi-transparent unless you uncheck their hide property."));
1934 connect(actionShowAllPlaces
, &QAction::triggered
, this, [actionShowAllPlaces
, this](bool checked
){
1935 actionShowAllPlaces
->setIcon(QIcon::fromTheme(checked
? QStringLiteral("view-visible") : QStringLiteral("view-hidden")));
1936 m_placesPanel
->showHiddenEntries(checked
);
1939 connect(m_placesPanel
, &PlacesPanel::showHiddenEntriesChanged
, this, [actionShowAllPlaces
] (bool checked
){
1940 actionShowAllPlaces
->setChecked(checked
);
1941 actionShowAllPlaces
->setIcon(QIcon::fromTheme(checked
? QStringLiteral("view-visible") : QStringLiteral("view-hidden")));
1944 actionCollection()->action(QStringLiteral("show_places_panel"))
1945 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
1946 "<emphasis>places</emphasis> panel at the left side of the window."
1947 "</para><para>It allows you to go to locations you have "
1948 "bookmarked and to access disk or media attached to the computer "
1949 "or to the network. It also contains sections to find recently "
1950 "saved files or files of a certain type.</para>"));
1951 placesDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
1952 "<emphasis>Places</emphasis> panel. It allows you to go to locations "
1953 "you have bookmarked and to access disk or media attached to the "
1954 "computer or to the network. It also contains sections to find "
1955 "recently saved files or files of a certain type.</para><para>"
1956 "Click on an entry to go there. Click with the right mouse button "
1957 "instead to open any entry in a new tab or new window.</para>"
1958 "<para>New entries can be added by dragging folders onto this panel. "
1959 "Right-click any section or entry to hide it. Right-click an empty "
1960 "space on this panel and select <interface>Show Hidden Places"
1961 "</interface> to display it again.</para>") + panelWhatsThis
);
1963 // Add actions into the "Panels" menu
1964 KActionMenu
* panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Show Panels"), this);
1965 actionCollection()->addAction(QStringLiteral("panels"), panelsMenu
);
1966 panelsMenu
->setIcon(QIcon::fromTheme(QStringLiteral("view-sidetree")));
1967 panelsMenu
->setDelayed(false);
1968 const KActionCollection
* ac
= actionCollection();
1969 panelsMenu
->addAction(ac
->action(QStringLiteral("show_places_panel")));
1971 panelsMenu
->addAction(ac
->action(QStringLiteral("show_information_panel")));
1973 panelsMenu
->addAction(ac
->action(QStringLiteral("show_folders_panel")));
1974 panelsMenu
->addAction(ac
->action(QStringLiteral("show_terminal_panel")));
1975 panelsMenu
->addSeparator();
1976 panelsMenu
->addAction(actionShowAllPlaces
);
1977 panelsMenu
->addAction(lockLayoutAction
);
1979 connect(panelsMenu
->menu(), &QMenu::aboutToShow
, this, [actionShowAllPlaces
, this]{
1980 actionShowAllPlaces
->setEnabled(m_placesPanel
->hiddenListCount());
1985 void DolphinMainWindow::updateFileAndEditActions()
1987 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1988 const KActionCollection
* col
= actionCollection();
1989 KFileItemListProperties
capabilitiesSource(list
);
1991 QAction
* addToPlacesAction
= col
->action(QStringLiteral("add_to_places"));
1992 QAction
* copyToOtherViewAction
= col
->action(QStringLiteral("copy_to_inactive_split_view"));
1993 QAction
* moveToOtherViewAction
= col
->action(QStringLiteral("move_to_inactive_split_view"));
1994 QAction
* copyLocation
= col
->action(QString("copy_location"));
1996 if (list
.isEmpty()) {
1997 stateChanged(QStringLiteral("has_no_selection"));
1999 addToPlacesAction
->setEnabled(true);
2000 copyToOtherViewAction
->setEnabled(false);
2001 moveToOtherViewAction
->setEnabled(false);
2002 copyLocation
->setEnabled(false);
2004 stateChanged(QStringLiteral("has_selection"));
2006 QAction
* renameAction
= col
->action(KStandardAction::name(KStandardAction::RenameFile
));
2007 QAction
* moveToTrashAction
= col
->action(KStandardAction::name(KStandardAction::MoveToTrash
));
2008 QAction
* deleteAction
= col
->action(KStandardAction::name(KStandardAction::DeleteFile
));
2009 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
2010 QAction
* deleteWithTrashShortcut
= col
->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
2011 QAction
* showTarget
= col
->action(QStringLiteral("show_target"));
2012 QAction
* duplicateAction
= col
->action(QStringLiteral("duplicate")); // see DolphinViewActionHandler
2014 if (list
.length() == 1 && list
.first().isDir()) {
2015 addToPlacesAction
->setEnabled(true);
2017 addToPlacesAction
->setEnabled(false);
2020 if (m_tabWidget
->currentTabPage()->splitViewEnabled()) {
2021 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
2022 KFileItem capabilitiesDestination
;
2024 if (tabPage
->primaryViewActive()) {
2025 capabilitiesDestination
= tabPage
->secondaryViewContainer()->url();
2027 capabilitiesDestination
= tabPage
->primaryViewContainer()->url();
2030 copyToOtherViewAction
->setEnabled(capabilitiesDestination
.isWritable());
2031 moveToOtherViewAction
->setEnabled(capabilitiesSource
.supportsMoving() && capabilitiesDestination
.isWritable());
2033 copyToOtherViewAction
->setEnabled(false);
2034 moveToOtherViewAction
->setEnabled(false);
2037 const bool enableMoveToTrash
= capabilitiesSource
.isLocal() && capabilitiesSource
.supportsMoving();
2039 renameAction
->setEnabled(capabilitiesSource
.supportsMoving());
2040 moveToTrashAction
->setEnabled(enableMoveToTrash
);
2041 deleteAction
->setEnabled(capabilitiesSource
.supportsDeleting());
2042 deleteWithTrashShortcut
->setEnabled(capabilitiesSource
.supportsDeleting() && !enableMoveToTrash
);
2043 cutAction
->setEnabled(capabilitiesSource
.supportsMoving());
2044 copyLocation
->setEnabled(list
.length() == 1);
2045 showTarget
->setEnabled(list
.length() == 1 && list
.at(0).isLink());
2046 duplicateAction
->setEnabled(capabilitiesSource
.supportsWriting());
2050 void DolphinMainWindow::updateViewActions()
2052 m_actionHandler
->updateViewActions();
2054 QAction
* toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
2055 toggleFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
2057 updateSplitAction();
2060 void DolphinMainWindow::updateGoActions()
2062 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
2063 const QUrl currentUrl
= m_activeViewContainer
->url();
2064 // I think this is one of the best places to firstly be confronted
2065 // with a file system and its hierarchy. Talking about the root
2066 // directory might seem too much here but it is the question that
2067 // naturally arises in this context.
2068 goUpAction
->setWhatsThis(xi18nc("@info:whatsthis", "<para>Go to "
2069 "the folder that contains the currently viewed one.</para>"
2070 "<para>All files and folders are organized in a hierarchical "
2071 "<emphasis>file system</emphasis>. At the top of this hierarchy is "
2072 "a directory that contains all data connected to this computer"
2073 "—the <emphasis>root directory</emphasis>.</para>"));
2074 goUpAction
->setEnabled(KIO::upUrl(currentUrl
) != currentUrl
);
2077 void DolphinMainWindow::createControlButton()
2079 if (m_controlButton
) {
2082 Q_ASSERT(!m_controlButton
);
2084 m_controlButton
= new QToolButton(this);
2085 m_controlButton
->setAccessibleName(i18nc("@action:intoolbar", "Control"));
2086 m_controlButton
->setIcon(QIcon::fromTheme(QStringLiteral("application-menu")));
2087 m_controlButton
->setToolTip(i18nc("@action", "Show menu"));
2088 m_controlButton
->setAttribute(Qt::WidgetAttribute::WA_CustomWhatsThis
);
2089 m_controlButton
->setPopupMode(QToolButton::InstantPopup
);
2091 QMenu
* controlMenu
= new QMenu(m_controlButton
);
2092 connect(controlMenu
, &QMenu::aboutToShow
, this, &DolphinMainWindow::updateControlMenu
);
2093 controlMenu
->installEventFilter(this);
2095 m_controlButton
->setMenu(controlMenu
);
2097 toolBar()->addWidget(m_controlButton
);
2098 connect(toolBar(), &KToolBar::iconSizeChanged
,
2099 m_controlButton
, &QToolButton::setIconSize
);
2101 // The added widgets are owned by the toolbar and may get deleted when e.g. the toolbar
2102 // gets edited. In this case we must add them again. The adding is done asynchronously by
2103 // m_updateToolBarTimer.
2104 connect(m_controlButton
, &QToolButton::destroyed
, this, &DolphinMainWindow::slotControlButtonDeleted
);
2105 m_updateToolBarTimer
= new QTimer(this);
2106 m_updateToolBarTimer
->setInterval(500);
2107 connect(m_updateToolBarTimer
, &QTimer::timeout
, this, &DolphinMainWindow::updateToolBar
);
2110 void DolphinMainWindow::deleteControlButton()
2112 delete m_controlButton
;
2113 m_controlButton
= nullptr;
2115 delete m_updateToolBarTimer
;
2116 m_updateToolBarTimer
= nullptr;
2119 bool DolphinMainWindow::addActionToMenu(QAction
* action
, QMenu
* menu
)
2124 const KToolBar
* toolBarWidget
= toolBar();
2125 const auto associatedWidgets
= action
->associatedWidgets();
2126 for (const QWidget
* widget
: associatedWidgets
) {
2127 if (widget
== toolBarWidget
) {
2132 menu
->addAction(action
);
2136 void DolphinMainWindow::refreshViews()
2138 m_tabWidget
->refreshViews();
2140 if (GeneralSettings::modifiedStartupSettings()) {
2141 // The startup settings have been changed by the user (see bug #254947).
2142 // Synchronize the split-view setting with the active view:
2143 const bool splitView
= GeneralSettings::splitView();
2144 m_tabWidget
->currentTabPage()->setSplitViewEnabled(splitView
, WithAnimation
);
2145 updateSplitAction();
2146 updateWindowTitle();
2149 Q_EMIT
settingsChanged();
2152 void DolphinMainWindow::clearStatusBar()
2154 m_activeViewContainer
->statusBar()->resetToDefaultText();
2157 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
2159 connect(container
, &DolphinViewContainer::showFilterBarChanged
,
2160 this, &DolphinMainWindow::updateFilterBarAction
);
2161 connect(container
, &DolphinViewContainer::writeStateChanged
,
2162 this, &DolphinMainWindow::slotWriteStateChanged
);
2163 connect(container
, &DolphinViewContainer::searchModeEnabledChanged
,
2164 this, &DolphinMainWindow::updateSearchAction
);
2166 const QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
2167 connect(toggleSearchAction
, &QAction::triggered
, container
, &DolphinViewContainer::setSearchModeEnabled
);
2169 const DolphinView
* view
= container
->view();
2170 connect(view
, &DolphinView::selectionChanged
,
2171 this, &DolphinMainWindow::slotSelectionChanged
);
2172 connect(view
, &DolphinView::requestItemInfo
,
2173 this, &DolphinMainWindow::requestItemInfo
);
2174 connect(view
, &DolphinView::tabRequested
,
2175 this, &DolphinMainWindow::openNewTab
);
2176 connect(view
, &DolphinView::requestContextMenu
,
2177 this, &DolphinMainWindow::openContextMenu
);
2178 connect(view
, &DolphinView::directoryLoadingStarted
,
2179 this, &DolphinMainWindow::enableStopAction
);
2180 connect(view
, &DolphinView::directoryLoadingCompleted
,
2181 this, &DolphinMainWindow::disableStopAction
);
2182 connect(view
, &DolphinView::directoryLoadingCompleted
,
2183 this, &DolphinMainWindow::slotDirectoryLoadingCompleted
);
2184 connect(view
, &DolphinView::goBackRequested
,
2185 this, &DolphinMainWindow::goBack
);
2186 connect(view
, &DolphinView::goForwardRequested
,
2187 this, &DolphinMainWindow::goForward
);
2188 connect(view
, &DolphinView::urlActivated
,
2189 this, &DolphinMainWindow::handleUrl
);
2190 connect(view
, &DolphinView::goUpRequested
,
2191 this, &DolphinMainWindow::goUp
);
2193 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
2194 (actionCollection()->action(QStringLiteral("url_navigators")));
2196 const KUrlNavigator
*navigator
= m_tabWidget
->currentTabPage()->primaryViewActive() ?
2197 navigators
->primaryUrlNavigator() :
2198 navigators
->secondaryUrlNavigator();
2200 connect(navigator
, &KUrlNavigator::urlChanged
,
2201 this, &DolphinMainWindow::changeUrl
);
2202 QAction
*editableLocactionAction
= actionCollection()->action(QStringLiteral("editable_location"));
2203 editableLocactionAction
->setChecked(navigator
->isUrlEditable());
2204 connect(navigator
, &KUrlNavigator::editableStateChanged
,
2205 this, &DolphinMainWindow::slotEditableStateChanged
);
2206 connect(navigator
, &KUrlNavigator::tabRequested
,
2207 this, &DolphinMainWindow::openNewTab
);
2209 disconnect(m_updateHistoryConnection
);
2210 m_updateHistoryConnection
= connect(
2211 container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::historyChanged
,
2212 this, &DolphinMainWindow::updateHistory
);
2215 void DolphinMainWindow::updateSplitAction()
2217 QAction
* splitAction
= actionCollection()->action(QStringLiteral("split_view"));
2218 const DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
2219 if (tabPage
->splitViewEnabled()) {
2220 if (GeneralSettings::closeActiveSplitView() ? tabPage
->primaryViewActive() : !tabPage
->primaryViewActive()) {
2221 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2222 splitAction
->setToolTip(i18nc("@info", "Close left view"));
2223 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close")));
2225 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2226 splitAction
->setToolTip(i18nc("@info", "Close right view"));
2227 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close")));
2230 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2231 splitAction
->setToolTip(i18nc("@info", "Split view"));
2232 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
2236 void DolphinMainWindow::updateAllowedToolbarAreas()
2238 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
2239 (actionCollection()->action(QStringLiteral("url_navigators")));
2240 if (toolBar()->actions().contains(navigators
)) {
2241 toolBar()->setAllowedAreas(Qt::TopToolBarArea
| Qt::BottomToolBarArea
);
2242 if (toolBarArea(toolBar()) == Qt::LeftToolBarArea
||
2243 toolBarArea(toolBar()) == Qt::RightToolBarArea
) {
2244 addToolBar(Qt::TopToolBarArea
, toolBar());
2247 toolBar()->setAllowedAreas(Qt::AllToolBarAreas
);
2251 bool DolphinMainWindow::isKompareInstalled() const
2253 static bool initialized
= false;
2254 static bool installed
= false;
2256 // TODO: maybe replace this approach later by using a menu
2257 // plugin like kdiff3plugin.cpp
2258 installed
= !QStandardPaths::findExecutable(QStringLiteral("kompare")).isEmpty();
2264 void DolphinMainWindow::createPanelAction(const QIcon
& icon
,
2265 const QKeySequence
& shortcut
,
2266 QAction
* dockAction
,
2267 const QString
& actionName
)
2269 QAction
* panelAction
= actionCollection()->addAction(actionName
);
2270 panelAction
->setCheckable(true);
2271 panelAction
->setChecked(dockAction
->isChecked());
2272 panelAction
->setText(dockAction
->text());
2273 panelAction
->setIcon(icon
);
2274 actionCollection()->setDefaultShortcut(panelAction
, shortcut
);
2276 connect(panelAction
, &QAction::triggered
, dockAction
, &QAction::trigger
);
2277 connect(dockAction
, &QAction::toggled
, panelAction
, &QAction::setChecked
);
2280 void DolphinMainWindow::setupWhatsThis()
2283 menuBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2284 "<emphasis>Menubar</emphasis>. It provides access to commands and "
2285 "configuration options. Left-click on any of the menus on this "
2286 "bar to see its contents.</para><para>The Menubar can be hidden "
2287 "by unchecking <interface>Settings|Show Menubar</interface>. Then "
2288 "most of its contents become available through a <interface>Control"
2289 "</interface> button on the <emphasis>Toolbar</emphasis>.</para>"));
2290 toolBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2291 "<emphasis>Toolbar</emphasis>. It allows quick access to "
2292 "frequently used actions.</para><para>It is highly customizable. "
2293 "All items you see in the <interface>Control</interface> menu or "
2294 "in the <interface>Menubar</interface> can be placed on the "
2295 "Toolbar. Just right-click on it and select <interface>Configure "
2296 "Toolbars…</interface> or find this action in the <interface>"
2297 "Control</interface> or <interface>Settings</interface> menu."
2298 "</para><para>The location of the bar and the style of its "
2299 "buttons can also be changed in the right-click menu. Right-click "
2300 "a button if you want to show or hide its text.</para>"));
2301 m_tabWidget
->setWhatsThis(xi18nc("@info:whatsthis main view",
2302 "<para>Here you can see the <emphasis>folders</emphasis> and "
2303 "<emphasis>files</emphasis> that are at the location described in "
2304 "the <interface>Location Bar</interface> above. This area is the "
2305 "central part of this application where you navigate to the files "
2306 "you want to use.</para><para>For an elaborate and general "
2307 "introduction to this application <link "
2308 "url='https://userbase.kde.org/Dolphin/File_Management#Introduction_to_Dolphin'>"
2309 "click here</link>. This will open an introductory article from "
2310 "the <emphasis>KDE UserBase Wiki</emphasis>.</para><para>For brief "
2311 "explanations of all the features of this <emphasis>view</emphasis> "
2312 "<link url='help:/dolphin/dolphin-view.html'>click here</link> "
2313 "instead. This will open a page from the <emphasis>Handbook"
2314 "</emphasis> that covers the basics.</para>"));
2317 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings
))
2318 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window "
2319 "that lists the <emphasis>keyboard shortcuts</emphasis>.<nl/>"
2320 "There you can set up key combinations to trigger an action when "
2321 "they are pressed simultaneously. All commands in this application can "
2322 "be triggered this way.</para>"));
2323 actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars
))
2324 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window in which "
2325 "you can change which buttons appear on the <emphasis>Toolbar</emphasis>.</para>"
2326 "<para>All items you see in the <interface>Control</interface> menu "
2327 "or in the <interface>Menubar</interface> can also be placed on the Toolbar.</para>"));
2328 actionCollection()->action(KStandardAction::name(KStandardAction::Preferences
))
2329 ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window where you can "
2330 "change a multitude of settings for this application. For an explanation "
2331 "of the various settings go to the chapter <emphasis>Configuring Dolphin"
2332 "</emphasis> in <interface>Help|Dolphin Handbook</interface>."));
2335 // The whatsthis has to be set for the m_helpMenu and for the
2336 // StandardAction separately because both are used in different locations.
2337 // m_helpMenu is only used for createControlButton() button.
2339 // Links do not work within the Menubar so texts without links are provided there.
2341 // i18n: If the external link isn't available in your language you should
2342 // probably state the external link language at least in brackets to not
2343 // frustrate the user. If there are multiple languages that the user might
2344 // know with a reasonable chance you might want to have 2 external links.
2345 // The same is in my opinion true for every external link you translate.
2346 const QString whatsThisHelpContents
= xi18nc("@info:whatsthis handbook",
2347 "<para>This opens the Handbook for this application. It provides "
2348 "explanations for every part of <emphasis>Dolphin</emphasis>.</para>");
2349 actionCollection()->action(KStandardAction::name(KStandardAction::HelpContents
))
2350 ->setWhatsThis(whatsThisHelpContents
2351 + xi18nc("@info:whatsthis second half of handbook hb text without link",
2352 "<para>If you want more elaborate introductions to the "
2353 "different features of <emphasis>Dolphin</emphasis> "
2354 "go to the KDE UserBase Wiki.</para>"));
2355 m_helpMenu
->action(KHelpMenu::menuHelpContents
)->setWhatsThis(whatsThisHelpContents
2356 + xi18nc("@info:whatsthis second half of handbook text with link",
2357 "<para>If you want more elaborate introductions to the "
2358 "different features of <emphasis>Dolphin</emphasis> "
2359 "<link url='https://userbase.kde.org/Dolphin/File_Management'>click here</link>. "
2360 "It will open the dedicated page in the KDE UserBase Wiki.</para>"));
2362 const QString whatsThisWhatsThis
= xi18nc("@info:whatsthis whatsthis button",
2363 "<para>This is the button that invokes the help feature you are "
2364 "using right now! Click it, then click any component of this "
2365 "application to ask \"What's this?\" about it. The mouse cursor "
2366 "will change appearance if no help is available for a spot.</para>");
2367 actionCollection()->action(KStandardAction::name(KStandardAction::WhatsThis
))
2368 ->setWhatsThis(whatsThisWhatsThis
2369 + xi18nc("@info:whatsthis second half of whatsthis button text without link",
2370 "<para>There are two other ways to get help for this application: The "
2371 "<interface>Dolphin Handbook</interface> in the <interface>Help"
2372 "</interface> menu and the <emphasis>KDE UserBase Wiki</emphasis> "
2373 "article about <emphasis>File Management</emphasis> online."
2374 "</para><para>The \"What's this?\" help is "
2375 "missing in most other windows so don't get too used to this.</para>"));
2376 m_helpMenu
->action(KHelpMenu::menuWhatsThis
)->setWhatsThis(whatsThisWhatsThis
2377 + xi18nc("@info:whatsthis second half of whatsthis button text with link",
2378 "<para>There are two other ways to get help: "
2379 "The <link url='help:/dolphin/index.html'>Dolphin Handbook</link> and "
2380 "the <link url='https://userbase.kde.org/Dolphin/File_Management'>KDE "
2381 "UserBase Wiki</link>.</para><para>The \"What's this?\" help is "
2382 "missing in most other windows so don't get too used to this.</para>"));
2384 const QString whatsThisReportBug
= xi18nc("@info:whatsthis","<para>This opens a "
2385 "window that will guide you through reporting errors or flaws "
2386 "in this application or in other KDE software.</para>");
2387 actionCollection()->action(KStandardAction::name(KStandardAction::ReportBug
))
2388 ->setWhatsThis(whatsThisReportBug
);
2389 m_helpMenu
->action(KHelpMenu::menuReportBug
)->setWhatsThis(whatsThisReportBug
2390 + xi18nc("@info:whatsthis second half of reportbug text with link",
2391 "<para>High-quality bug reports are much appreciated. To learn "
2392 "how to make your bug report as effective as possible "
2393 "<link url='https://community.kde.org/Get_Involved/Bug_Reporting'>"
2394 "click here</link>.</para>"));
2396 const QString whatsThisDonate
= xi18nc("@info:whatsthis","<para>This opens a "
2397 "<emphasis>web page</emphasis> where you can donate to "
2398 "support the continued work on this application and many "
2399 "other projects by the <emphasis>KDE</emphasis> community.</para>"
2400 "<para>Donating is the easiest and fastest way to efficiently "
2401 "support KDE and its projects. KDE projects are available for "
2402 "free therefore your donation is needed to cover things that "
2403 "require money like servers, contributor meetings, etc.</para>"
2404 "<para><emphasis>KDE e.V.</emphasis> is the non-profit "
2405 "organization behind the KDE community.</para>");
2406 actionCollection()->action(KStandardAction::name(KStandardAction::Donate
))
2407 ->setWhatsThis(whatsThisDonate
);
2408 m_helpMenu
->action(KHelpMenu::menuDonate
)->setWhatsThis(whatsThisDonate
);
2410 const QString whatsThisSwitchLanguage
= xi18nc("@info:whatsthis",
2411 "With this you can change the language this application uses."
2412 "<nl/>You can even set secondary languages which will be used "
2413 "if texts are not available in your preferred language.");
2414 actionCollection()->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
))
2415 ->setWhatsThis(whatsThisSwitchLanguage
);
2416 m_helpMenu
->action(KHelpMenu::menuSwitchLanguage
)->setWhatsThis(whatsThisSwitchLanguage
);
2418 const QString whatsThisAboutApp
= xi18nc("@info:whatsthis","This opens a "
2419 "window that informs you about the version, license, "
2420 "used libraries and maintainers of this application.");
2421 actionCollection()->action(KStandardAction::name(KStandardAction::AboutApp
))
2422 ->setWhatsThis(whatsThisAboutApp
);
2423 m_helpMenu
->action(KHelpMenu::menuAboutApp
)->setWhatsThis(whatsThisAboutApp
);
2425 const QString whatsThisAboutKDE
= xi18nc("@info:whatsthis","This opens a "
2426 "window with information about <emphasis>KDE</emphasis>. "
2427 "The KDE community are the people behind this free software."
2428 "<nl/>If you like using this application but don't know "
2429 "about KDE or want to see a cute dragon have a look!");
2430 actionCollection()->action(KStandardAction::name(KStandardAction::AboutKDE
))
2431 ->setWhatsThis(whatsThisAboutKDE
);
2432 m_helpMenu
->action(KHelpMenu::menuAboutKDE
)->setWhatsThis(whatsThisAboutKDE
);
2435 bool DolphinMainWindow::event(QEvent
*event
)
2437 if (event
->type() == QEvent::WhatsThisClicked
) {
2439 QWhatsThisClickedEvent
* whatsThisEvent
= dynamic_cast<QWhatsThisClickedEvent
*>(event
);
2440 QDesktopServices::openUrl(QUrl(whatsThisEvent
->href()));
2443 return KXmlGuiWindow::event(event
);
2446 bool DolphinMainWindow::eventFilter(QObject
* obj
, QEvent
* event
)
2449 if (event
->type() == QEvent::WhatsThisClicked
) {
2451 QWhatsThisClickedEvent
* whatsThisEvent
= dynamic_cast<QWhatsThisClickedEvent
*>(event
);
2452 QDesktopServices::openUrl(QUrl(whatsThisEvent
->href()));
2458 void DolphinMainWindow::saveNewToolbarConfig()
2460 KXmlGuiWindow::saveNewToolbarConfig(); // Applies the new config. This has to be called first
2461 // because the rest of this method decides things
2462 // based on the new config.
2463 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
2464 (actionCollection()->action(QStringLiteral("url_navigators")));
2465 if (!toolBar()->actions().contains(navigators
)) {
2466 m_tabWidget
->currentTabPage()->insertNavigatorsWidget(navigators
);
2468 updateAllowedToolbarAreas();
2471 void DolphinMainWindow::focusTerminalPanel()
2473 if (m_terminalPanel
->isVisible()) {
2474 if (m_terminalPanel
->terminalHasFocus()) {
2475 m_activeViewContainer
->view()->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2476 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2478 m_terminalPanel
->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2479 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2482 actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger();
2483 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2487 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
2488 KIO::FileUndoManager::UiInterface()
2492 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2496 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
2498 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2500 DolphinViewContainer
* container
= mainWin
->activeViewContainer();
2501 container
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
2503 KIO::FileUndoManager::UiInterface::jobError(job
);
2507 bool DolphinMainWindow::isUrlOpen(const QString
& url
)
2509 return m_tabWidget
->isUrlOpen(QUrl::fromUserInput((url
)));