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 "dolphinnewfilemenu.h"
18 #include "dolphinrecenttabsmenu.h"
19 #include "dolphinviewcontainer.h"
20 #include "dolphintabpage.h"
21 #include "middleclickactioneventfilter.h"
22 #include "panels/folders/folderspanel.h"
23 #include "panels/places/placesitemmodel.h"
24 #include "panels/places/placespanel.h"
25 #include "panels/information/informationpanel.h"
26 #include "panels/terminal/terminalpanel.h"
27 #include "settings/dolphinsettingsdialog.h"
28 #include "statusbar/dolphinstatusbar.h"
29 #include "views/dolphinviewactionhandler.h"
30 #include "views/dolphinremoteencoding.h"
31 #include "views/draganddrophelper.h"
32 #include "views/viewproperties.h"
33 #include "views/dolphinnewfilemenuobserver.h"
34 #include "dolphin_generalsettings.h"
36 #include <KActionCollection>
37 #include <KActionMenu>
38 #include <KAuthorized>
41 #include <KDualAction>
42 #include <KFileItemListProperties>
44 #include <KIO/CommandLauncherJob>
45 #include <KIO/JobUiDelegate>
46 #include <KIO/OpenFileManagerWindowJob>
47 #include <KIO/OpenUrlJob>
48 #include <KJobWidgets>
49 #include <KLocalizedString>
50 #include <KMessageBox>
51 #include <KNS3/KMoreToolsMenuFactory>
52 #include <KProtocolInfo>
53 #include <KProtocolManager>
55 #include <KStandardAction>
56 #include <KStartupInfo>
58 #include <KToggleAction>
60 #include <KToolBarPopupAction>
61 #include <KToolInvocation>
62 #include <KUrlComboBox>
63 #include <KUrlNavigator>
64 #include <KWindowSystem>
66 #include <QApplication>
68 #include <QCloseEvent>
69 #include <QDesktopServices>
74 #include <QPushButton>
76 #include <QStandardPaths>
78 #include <QToolButton>
79 #include <QWhatsThisClickedEvent>
82 // Used for GeneralSettings::version() to determine whether
83 // an updated version of Dolphin is running.
84 const int CurrentDolphinVersion
= 200;
85 // The maximum number of entries in the back/forward popup menu
86 const int MaxNumberOfNavigationentries
= 12;
87 // The maximum number of "Activate Tab" shortcuts
88 const int MaxActivateTabShortcuts
= 9;
91 DolphinMainWindow::DolphinMainWindow() :
92 KXmlGuiWindow(nullptr),
93 m_newFileMenu(nullptr),
96 m_activeViewContainer(nullptr),
97 m_actionHandler(nullptr),
98 m_remoteEncoding(nullptr),
100 m_bookmarkHandler(nullptr),
101 m_controlButton(nullptr),
102 m_updateToolBarTimer(nullptr),
103 m_lastHandleUrlOpenJob(nullptr),
104 m_terminalPanel(nullptr),
105 m_placesPanel(nullptr),
106 m_tearDownFromPlacesRequested(false),
107 m_backAction(nullptr),
108 m_forwardAction(nullptr)
110 Q_INIT_RESOURCE(dolphin
);
112 new MainWindowAdaptor(this);
115 setWindowFlags(Qt::WindowContextHelpButtonHint
);
117 setComponentName(QStringLiteral("dolphin"), QGuiApplication::applicationDisplayName());
118 setObjectName(QStringLiteral("Dolphin#"));
120 connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::errorMessage
,
121 this, &DolphinMainWindow::showErrorMessage
);
123 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
124 undoManager
->setUiInterface(new UndoUiInterface());
126 connect(undoManager
, QOverload
<bool>::of(&KIO::FileUndoManager::undoAvailable
),
127 this, &DolphinMainWindow::slotUndoAvailable
);
128 connect(undoManager
, &KIO::FileUndoManager::undoTextChanged
,
129 this, &DolphinMainWindow::slotUndoTextChanged
);
130 connect(undoManager
, &KIO::FileUndoManager::jobRecordingStarted
,
131 this, &DolphinMainWindow::clearStatusBar
);
132 connect(undoManager
, &KIO::FileUndoManager::jobRecordingFinished
,
133 this, &DolphinMainWindow::showCommand
);
135 GeneralSettings
* generalSettings
= GeneralSettings::self();
136 const bool firstRun
= (generalSettings
->version() < 200);
138 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
141 setAcceptDrops(true);
143 m_tabWidget
= new DolphinTabWidget(this);
144 m_tabWidget
->setObjectName("tabWidget");
145 connect(m_tabWidget
, &DolphinTabWidget::activeViewChanged
,
146 this, &DolphinMainWindow::activeViewChanged
);
147 connect(m_tabWidget
, &DolphinTabWidget::tabCountChanged
,
148 this, &DolphinMainWindow::tabCountChanged
);
149 connect(m_tabWidget
, &DolphinTabWidget::currentUrlChanged
,
150 this, &DolphinMainWindow::updateWindowTitle
);
151 setCentralWidget(m_tabWidget
);
155 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
156 connect(m_actionHandler
, &DolphinViewActionHandler::actionBeingHandled
, this, &DolphinMainWindow::clearStatusBar
);
157 connect(m_actionHandler
, &DolphinViewActionHandler::createDirectoryTriggered
, this, &DolphinMainWindow::createDirectory
);
159 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
160 connect(this, &DolphinMainWindow::urlChanged
,
161 m_remoteEncoding
, &DolphinRemoteEncoding::slotAboutToOpenUrl
);
165 setupGUI(Keys
| Save
| Create
| ToolBar
);
166 stateChanged(QStringLiteral("new_file"));
168 QClipboard
* clipboard
= QApplication::clipboard();
169 connect(clipboard
, &QClipboard::dataChanged
,
170 this, &DolphinMainWindow::updatePasteAction
);
172 QAction
* showFilterBarAction
= actionCollection()->action(QStringLiteral("show_filter_bar"));
173 showFilterBarAction
->setChecked(generalSettings
->filterBar());
176 menuBar()->setVisible(false);
177 // Assure a proper default size if Dolphin runs the first time
181 const bool showMenu
= !menuBar()->isHidden();
182 QAction
* showMenuBarAction
= actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar
));
183 showMenuBarAction
->setChecked(showMenu
); // workaround for bug #171080
185 createControlButton();
188 // enable middle-click on back/forward/up to open in a new tab
189 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
190 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotToolBarActionMiddleClicked
);
191 toolBar()->installEventFilter(middleClickEventFilter
);
195 connect(KSycoca::self(), QOverload
<>::of(&KSycoca::databaseChanged
), this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
197 QTimer::singleShot(0, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
200 DolphinMainWindow::~DolphinMainWindow()
204 QVector
<DolphinViewContainer
*> DolphinMainWindow::viewContainers() const
206 QVector
<DolphinViewContainer
*> viewContainers
;
208 for (int i
= 0; i
< m_tabWidget
->count(); ++i
) {
209 DolphinTabPage
*tabPage
= m_tabWidget
->tabPageAt(i
);
211 viewContainers
<< tabPage
->primaryViewContainer();
212 if (tabPage
->splitViewEnabled()) {
213 viewContainers
<< tabPage
->secondaryViewContainer();
216 return viewContainers
;
219 void DolphinMainWindow::openDirectories(const QList
<QUrl
>& dirs
, bool splitView
)
221 m_tabWidget
->openDirectories(dirs
, splitView
);
224 void DolphinMainWindow::openDirectories(const QStringList
& dirs
, bool splitView
)
226 openDirectories(QUrl::fromStringList(dirs
), splitView
);
229 void DolphinMainWindow::openFiles(const QList
<QUrl
>& files
, bool splitView
)
231 m_tabWidget
->openFiles(files
, splitView
);
234 void DolphinMainWindow::openFiles(const QStringList
& files
, bool splitView
)
236 openFiles(QUrl::fromStringList(files
), splitView
);
239 void DolphinMainWindow::activateWindow()
241 window()->setAttribute(Qt::WA_NativeWindow
, true);
242 KStartupInfo::setNewStartupId(window()->windowHandle(), KStartupInfo::startupId());
243 KWindowSystem::activateWindow(window()->effectiveWinId());
246 void DolphinMainWindow::showCommand(CommandType command
)
248 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
250 case KIO::FileUndoManager::Copy
:
251 statusBar
->setText(i18nc("@info:status", "Successfully copied."));
253 case KIO::FileUndoManager::Move
:
254 statusBar
->setText(i18nc("@info:status", "Successfully moved."));
256 case KIO::FileUndoManager::Link
:
257 statusBar
->setText(i18nc("@info:status", "Successfully linked."));
259 case KIO::FileUndoManager::Trash
:
260 statusBar
->setText(i18nc("@info:status", "Successfully moved to trash."));
262 case KIO::FileUndoManager::Rename
:
263 statusBar
->setText(i18nc("@info:status", "Successfully renamed."));
266 case KIO::FileUndoManager::Mkdir
:
267 statusBar
->setText(i18nc("@info:status", "Created folder."));
275 void DolphinMainWindow::pasteIntoFolder()
277 m_activeViewContainer
->view()->pasteIntoFolder();
280 void DolphinMainWindow::changeUrl(const QUrl
&url
)
282 if (!KProtocolManager::supportsListing(url
)) {
283 // The URL navigator only checks for validity, not
284 // if the URL can be listed. An error message is
285 // shown due to DolphinViewContainer::restoreView().
289 m_activeViewContainer
->setUrl(url
);
290 updateFileAndEditActions();
295 emit
urlChanged(url
);
298 void DolphinMainWindow::slotTerminalDirectoryChanged(const QUrl
& url
)
300 if (m_tearDownFromPlacesRequested
&& url
== QUrl::fromLocalFile(QDir::homePath())) {
301 m_placesPanel
->proceedWithTearDown();
302 m_tearDownFromPlacesRequested
= false;
305 m_activeViewContainer
->setAutoGrabFocus(false);
307 m_activeViewContainer
->setAutoGrabFocus(true);
310 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
312 KToggleAction
* editableLocationAction
=
313 static_cast<KToggleAction
*>(actionCollection()->action(QStringLiteral("editable_location")));
314 editableLocationAction
->setChecked(editable
);
317 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
319 updateFileAndEditActions();
321 const int selectedUrlsCount
= m_tabWidget
->currentTabPage()->selectedItemsCount();
323 QAction
* compareFilesAction
= actionCollection()->action(QStringLiteral("compare_files"));
324 if (selectedUrlsCount
== 2) {
325 compareFilesAction
->setEnabled(isKompareInstalled());
327 compareFilesAction
->setEnabled(false);
330 emit
selectionChanged(selection
);
333 void DolphinMainWindow::updateHistory()
335 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
336 const int index
= urlNavigator
->historyIndex();
338 QAction
* backAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Back
));
340 backAction
->setToolTip(i18nc("@info", "Go back"));
341 backAction
->setWhatsThis(i18nc("@info:whatsthis go back", "Return to the previously viewed folder."));
342 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
345 QAction
* forwardAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Forward
));
347 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
348 forwardAction
->setWhatsThis(xi18nc("@info:whatsthis go forward",
349 "This undoes a <interface>Go|Back</interface> action."));
350 forwardAction
->setEnabled(index
> 0);
354 void DolphinMainWindow::updateFilterBarAction(bool show
)
356 QAction
* showFilterBarAction
= actionCollection()->action(QStringLiteral("show_filter_bar"));
357 showFilterBarAction
->setChecked(show
);
360 void DolphinMainWindow::openNewMainWindow()
362 Dolphin::openNewWindow({m_activeViewContainer
->url()}, this);
365 void DolphinMainWindow::openNewActivatedTab()
367 m_tabWidget
->openNewActivatedTab();
370 void DolphinMainWindow::addToPlaces()
375 // If nothing is selected, act on the current dir
376 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
377 url
= m_activeViewContainer
->url();
378 name
= m_activeViewContainer
->placesText();
380 const auto dirToAdd
= m_activeViewContainer
->view()->selectedItems().first();
381 url
= dirToAdd
.url();
382 name
= dirToAdd
.name();
385 PlacesItemModel model
;
387 if (m_activeViewContainer
->isSearchModeEnabled()) {
388 icon
= QStringLiteral("folder-saved-search-symbolic");
390 icon
= KIO::iconNameForUrl(url
);
392 model
.createPlacesItem(name
, url
, icon
);
396 void DolphinMainWindow::openNewTab(const QUrl
& url
, DolphinTabWidget::TabPlacement tabPlacement
)
398 m_tabWidget
->openNewTab(url
, QUrl(), tabPlacement
);
401 void DolphinMainWindow::openNewTabAfterCurrentTab(const QUrl
& url
)
403 m_tabWidget
->openNewTab(url
, QUrl(), DolphinTabWidget::AfterCurrentTab
);
406 void DolphinMainWindow::openNewTabAfterLastTab(const QUrl
& url
)
408 m_tabWidget
->openNewTab(url
, QUrl(), DolphinTabWidget::AfterLastTab
);
411 void DolphinMainWindow::openInNewTab()
413 const KFileItemList
& list
= m_activeViewContainer
->view()->selectedItems();
414 bool tabCreated
= false;
416 foreach (const KFileItem
& item
, list
) {
417 const QUrl
& url
= DolphinView::openItemAsFolderUrl(item
);
418 if (!url
.isEmpty()) {
419 openNewTabAfterCurrentTab(url
);
424 // if no new tab has been created from the selection
425 // open the current directory in a new tab
427 openNewTabAfterCurrentTab(m_activeViewContainer
->url());
431 void DolphinMainWindow::openInNewWindow()
435 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
436 if (list
.isEmpty()) {
437 newWindowUrl
= m_activeViewContainer
->url();
438 } else if (list
.count() == 1) {
439 const KFileItem
& item
= list
.first();
440 newWindowUrl
= DolphinView::openItemAsFolderUrl(item
);
443 if (!newWindowUrl
.isEmpty()) {
444 Dolphin::openNewWindow({newWindowUrl
}, this);
448 void DolphinMainWindow::showTarget()
450 const auto link
= m_activeViewContainer
->view()->selectedItems().at(0);
451 const auto linkLocationDir
= QFileInfo(link
.localPath()).absoluteDir();
452 auto linkDestination
= link
.linkDest();
453 if (QFileInfo(linkDestination
).isRelative()) {
454 linkDestination
= linkLocationDir
.filePath(linkDestination
);
456 if (QFileInfo::exists(linkDestination
)) {
457 KIO::highlightInFileManager({QUrl::fromLocalFile(linkDestination
).adjusted(QUrl::StripTrailingSlash
)});
459 m_activeViewContainer
->showMessage(xi18nc("@info", "Could not access <filename>%1</filename>.", linkDestination
),
460 DolphinViewContainer::Warning
);
464 void DolphinMainWindow::showEvent(QShowEvent
* event
)
466 KXmlGuiWindow::showEvent(event
);
468 if (!event
->spontaneous()) {
469 m_activeViewContainer
->view()->setFocus();
473 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
475 // Find out if Dolphin is closed directly by the user or
476 // by the session manager because the session is closed
477 bool closedByUser
= true;
478 if (qApp
->isSavingSession()) {
479 closedByUser
= false;
482 if (m_tabWidget
->count() > 1
483 && GeneralSettings::confirmClosingMultipleTabs()
484 && !GeneralSettings::rememberOpenedTabs()
486 // Ask the user if he really wants to quit and close all tabs.
487 // Open a confirmation dialog with 3 buttons:
488 // QDialogButtonBox::Yes -> Quit
489 // QDialogButtonBox::No -> Close only the current tab
490 // QDialogButtonBox::Cancel -> do nothing
491 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
492 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
493 dialog
->setModal(true);
494 QDialogButtonBox
* buttons
= new QDialogButtonBox(QDialogButtonBox::Yes
| QDialogButtonBox::No
| QDialogButtonBox::Cancel
);
495 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KGuiItem(i18nc("@action:button 'Quit Dolphin' button", "&Quit %1", QGuiApplication::applicationDisplayName()), QIcon::fromTheme(QStringLiteral("application-exit"))));
496 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("C&lose Current Tab"), QIcon::fromTheme(QStringLiteral("tab-close"))));
497 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
498 buttons
->button(QDialogButtonBox::Yes
)->setDefault(true);
500 bool doNotAskAgainCheckboxResult
= false;
502 const auto result
= KMessageBox::createKMessageBox(dialog
,
504 QMessageBox::Warning
,
505 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
507 i18n("Do not ask again"),
508 &doNotAskAgainCheckboxResult
,
509 KMessageBox::Notify
);
511 if (doNotAskAgainCheckboxResult
) {
512 GeneralSettings::setConfirmClosingMultipleTabs(false);
516 case QDialogButtonBox::Yes
:
519 case QDialogButtonBox::No
:
520 // Close only the current tab
521 m_tabWidget
->closeTab();
529 if (m_terminalPanel
&& m_terminalPanel
->hasProgramRunning() && GeneralSettings::confirmClosingTerminalRunningProgram() && closedByUser
) {
530 // Ask if the user really wants to quit Dolphin with a program that is still running in the Terminal panel
531 // Open a confirmation dialog with 3 buttons:
532 // QDialogButtonBox::Yes -> Quit
533 // QDialogButtonBox::No -> Show Terminal Panel
534 // QDialogButtonBox::Cancel -> do nothing
535 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
536 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
537 dialog
->setModal(true);
538 auto standardButtons
= QDialogButtonBox::Yes
| QDialogButtonBox::Cancel
;
539 if (!m_terminalPanel
->isVisible()) {
540 standardButtons
|= QDialogButtonBox::No
;
542 QDialogButtonBox
*buttons
= new QDialogButtonBox(standardButtons
);
543 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KStandardGuiItem::quit());
544 if (!m_terminalPanel
->isVisible()) {
546 buttons
->button(QDialogButtonBox::No
),
547 KGuiItem(i18n("Show &Terminal Panel"), QIcon::fromTheme(QStringLiteral("dialog-scripts"))));
549 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
551 bool doNotAskAgainCheckboxResult
= false;
553 const auto result
= KMessageBox::createKMessageBox(
556 QMessageBox::Warning
,
557 i18n("The program '%1' is still running in the Terminal panel. Are you sure you want to quit?", m_terminalPanel
->runningProgramName()),
559 i18n("Do not ask again"),
560 &doNotAskAgainCheckboxResult
,
561 KMessageBox::Dangerous
);
563 if (doNotAskAgainCheckboxResult
) {
564 GeneralSettings::setConfirmClosingTerminalRunningProgram(false);
568 case QDialogButtonBox::Yes
:
571 case QDialogButtonBox::No
:
572 actionCollection()->action("show_terminal_panel")->trigger();
573 // Do not quit, ignore quit event
581 if (GeneralSettings::rememberOpenedTabs()) {
582 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
583 KConfig
*config
= KConfigGui::sessionConfig();
584 saveGlobalProperties(config
);
585 savePropertiesInternal(config
, 1);
589 GeneralSettings::setVersion(CurrentDolphinVersion
);
590 GeneralSettings::self()->save();
592 KXmlGuiWindow::closeEvent(event
);
595 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
597 m_tabWidget
->saveProperties(group
);
600 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
602 m_tabWidget
->readProperties(group
);
605 void DolphinMainWindow::updateNewMenu()
607 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
608 m_newFileMenu
->checkUpToDate();
609 m_newFileMenu
->setPopupFiles(QList
<QUrl
>() << activeViewContainer()->url());
612 void DolphinMainWindow::createDirectory()
614 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
615 m_newFileMenu
->setPopupFiles(QList
<QUrl
>() << activeViewContainer()->url());
616 m_newFileMenu
->createDirectory();
619 void DolphinMainWindow::quit()
624 void DolphinMainWindow::showErrorMessage(const QString
& message
)
626 m_activeViewContainer
->showMessage(message
, DolphinViewContainer::Error
);
629 void DolphinMainWindow::slotUndoAvailable(bool available
)
631 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
633 undoAction
->setEnabled(available
);
637 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
639 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
641 undoAction
->setText(text
);
645 void DolphinMainWindow::undo()
648 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
649 KIO::FileUndoManager::self()->undo();
652 void DolphinMainWindow::cut()
654 m_activeViewContainer
->view()->cutSelectedItemsToClipboard();
657 void DolphinMainWindow::copy()
659 m_activeViewContainer
->view()->copySelectedItemsToClipboard();
662 void DolphinMainWindow::paste()
664 m_activeViewContainer
->view()->paste();
667 void DolphinMainWindow::find()
669 m_activeViewContainer
->setSearchModeEnabled(true);
672 void DolphinMainWindow::updateSearchAction()
674 QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
675 toggleSearchAction
->setChecked(m_activeViewContainer
->isSearchModeEnabled());
678 void DolphinMainWindow::updatePasteAction()
680 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
681 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
682 pasteAction
->setEnabled(pasteInfo
.first
);
683 pasteAction
->setText(pasteInfo
.second
);
686 void DolphinMainWindow::slotDirectoryLoadingCompleted()
691 void DolphinMainWindow::slotToolBarActionMiddleClicked(QAction
*action
)
693 if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Back
))) {
695 } else if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Forward
))) {
697 } else if (action
== actionCollection()->action(QStringLiteral("go_up"))) {
699 } else if (action
== actionCollection()->action(QStringLiteral("go_home"))) {
704 void DolphinMainWindow::slotAboutToShowBackPopupMenu()
706 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
708 m_backAction
->menu()->clear();
709 for (int i
= urlNavigator
->historyIndex() + 1; i
< urlNavigator
->historySize() && entries
< MaxNumberOfNavigationentries
; ++i
, ++entries
) {
710 QAction
* action
= new QAction(urlNavigator
->locationUrl(i
).toString(QUrl::PreferLocalFile
), m_backAction
->menu());
712 m_backAction
->menu()->addAction(action
);
716 void DolphinMainWindow::slotGoBack(QAction
* action
)
718 int gotoIndex
= action
->data().value
<int>();
719 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
720 for (int i
= gotoIndex
- urlNavigator
->historyIndex(); i
> 0; --i
) {
725 void DolphinMainWindow::slotBackForwardActionMiddleClicked(QAction
* action
)
728 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
729 openNewTabAfterCurrentTab(urlNavigator
->locationUrl(action
->data().value
<int>()));
733 void DolphinMainWindow::slotAboutToShowForwardPopupMenu()
735 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
737 m_forwardAction
->menu()->clear();
738 for (int i
= urlNavigator
->historyIndex() - 1; i
>= 0 && entries
< MaxNumberOfNavigationentries
; --i
, ++entries
) {
739 QAction
* action
= new QAction(urlNavigator
->locationUrl(i
).toString(QUrl::PreferLocalFile
), m_forwardAction
->menu());
741 m_forwardAction
->menu()->addAction(action
);
745 void DolphinMainWindow::slotGoForward(QAction
* action
)
747 int gotoIndex
= action
->data().value
<int>();
748 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
749 for (int i
= urlNavigator
->historyIndex() - gotoIndex
; i
> 0; --i
) {
754 void DolphinMainWindow::selectAll()
758 // if the URL navigator is editable and focused, select the whole
759 // URL instead of all items of the view
761 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
762 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit();
763 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
764 lineEdit
->hasFocus();
766 lineEdit
->selectAll();
768 m_activeViewContainer
->view()->selectAll();
772 void DolphinMainWindow::invertSelection()
775 m_activeViewContainer
->view()->invertSelection();
778 void DolphinMainWindow::toggleSplitView()
780 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
781 tabPage
->setSplitViewEnabled(!tabPage
->splitViewEnabled());
786 void DolphinMainWindow::toggleSplitStash()
788 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
789 tabPage
->setSplitViewEnabled(false);
790 tabPage
->setSplitViewEnabled(true, QUrl("stash:/"));
793 void DolphinMainWindow::reloadView()
796 m_activeViewContainer
->reload();
797 m_activeViewContainer
->statusBar()->updateSpaceInfo();
800 void DolphinMainWindow::stopLoading()
802 m_activeViewContainer
->view()->stopLoading();
805 void DolphinMainWindow::enableStopAction()
807 actionCollection()->action(QStringLiteral("stop"))->setEnabled(true);
810 void DolphinMainWindow::disableStopAction()
812 actionCollection()->action(QStringLiteral("stop"))->setEnabled(false);
815 void DolphinMainWindow::showFilterBar()
817 m_activeViewContainer
->setFilterBarVisible(true);
820 void DolphinMainWindow::toggleEditLocation()
824 QAction
* action
= actionCollection()->action(QStringLiteral("editable_location"));
825 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
826 urlNavigator
->setUrlEditable(action
->isChecked());
829 void DolphinMainWindow::replaceLocation()
831 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
832 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit();
834 // If the text field currently has focus and everything is selected,
835 // pressing the keyboard shortcut returns the whole thing to breadcrumb mode
836 if (navigator
->isUrlEditable()
837 && lineEdit
->hasFocus()
838 && lineEdit
->selectedText() == lineEdit
->text() ) {
839 navigator
->setUrlEditable(false);
841 navigator
->setUrlEditable(true);
842 navigator
->setFocus();
843 lineEdit
->selectAll();
847 void DolphinMainWindow::togglePanelLockState()
849 const bool newLockState
= !GeneralSettings::lockPanels();
850 foreach (QObject
* child
, children()) {
851 DolphinDockWidget
* dock
= qobject_cast
<DolphinDockWidget
*>(child
);
853 dock
->setLocked(newLockState
);
857 GeneralSettings::setLockPanels(newLockState
);
860 void DolphinMainWindow::slotTerminalPanelVisibilityChanged()
862 if (m_terminalPanel
->isHiddenInVisibleWindow() && m_activeViewContainer
) {
863 m_activeViewContainer
->view()->setFocus();
867 void DolphinMainWindow::goBack()
869 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
870 urlNavigator
->goBack();
872 if (urlNavigator
->locationState().isEmpty()) {
873 // An empty location state indicates a redirection URL,
874 // which must be skipped too
875 urlNavigator
->goBack();
879 void DolphinMainWindow::goForward()
881 m_activeViewContainer
->urlNavigator()->goForward();
884 void DolphinMainWindow::goUp()
886 m_activeViewContainer
->urlNavigator()->goUp();
889 void DolphinMainWindow::goHome()
891 m_activeViewContainer
->urlNavigator()->goHome();
894 void DolphinMainWindow::goBackInNewTab()
896 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
897 const int index
= urlNavigator
->historyIndex() + 1;
898 openNewTabAfterCurrentTab(urlNavigator
->locationUrl(index
));
901 void DolphinMainWindow::goForwardInNewTab()
903 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
904 const int index
= urlNavigator
->historyIndex() - 1;
905 openNewTabAfterCurrentTab(urlNavigator
->locationUrl(index
));
908 void DolphinMainWindow::goUpInNewTab()
910 const QUrl currentUrl
= activeViewContainer()->urlNavigator()->locationUrl();
911 openNewTabAfterCurrentTab(KIO::upUrl(currentUrl
));
914 void DolphinMainWindow::goHomeInNewTab()
916 openNewTabAfterCurrentTab(Dolphin::homeUrl());
919 void DolphinMainWindow::compareFiles()
921 const KFileItemList items
= m_tabWidget
->currentTabPage()->selectedItems();
922 if (items
.count() != 2) {
923 // The action is disabled in this case, but it could have been triggered
924 // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
928 QUrl urlA
= items
.at(0).url();
929 QUrl urlB
= items
.at(1).url();
931 QString
command(QStringLiteral("kompare -c \""));
932 command
.append(urlA
.toDisplayString(QUrl::PreferLocalFile
));
933 command
.append("\" \"");
934 command
.append(urlB
.toDisplayString(QUrl::PreferLocalFile
));
935 command
.append('\"');
937 KIO::CommandLauncherJob
*job
= new KIO::CommandLauncherJob(command
, this);
938 job
->setDesktopName(QStringLiteral("org.kde.kompare"));
942 void DolphinMainWindow::toggleShowMenuBar()
944 const bool visible
= menuBar()->isVisible();
945 menuBar()->setVisible(!visible
);
947 createControlButton();
949 deleteControlButton();
953 QPointer
<QAction
> DolphinMainWindow::preferredSearchTool()
955 m_searchTools
.clear();
956 KMoreToolsMenuFactory("dolphin/search-tools").fillMenuFromGroupingNames(
957 &m_searchTools
, { "files-find" }, m_activeViewContainer
->url()
959 QList
<QAction
*> actions
= m_searchTools
.actions();
960 if (actions
.isEmpty()) {
963 QAction
* action
= actions
.first();
964 if (action
->isSeparator()) {
970 void DolphinMainWindow::updateOpenPreferredSearchToolAction()
972 QAction
* openPreferredSearchTool
= actionCollection()->action(QStringLiteral("open_preferred_search_tool"));
973 if (!openPreferredSearchTool
) {
976 QPointer
<QAction
> tool
= preferredSearchTool();
978 openPreferredSearchTool
->setVisible(true);
979 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open %1", tool
->text()));
980 openPreferredSearchTool
->setIcon(tool
->icon());
982 openPreferredSearchTool
->setVisible(false);
983 // still visible in Shortcuts configuration window
984 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
985 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
989 void DolphinMainWindow::openPreferredSearchTool()
991 QPointer
<QAction
> tool
= preferredSearchTool();
997 void DolphinMainWindow::openTerminal()
999 const QUrl url
= m_activeViewContainer
->url();
1001 if (url
.isLocalFile()) {
1002 KToolInvocation::invokeTerminal(QString(), url
.toLocalFile());
1006 // Not a local file, with protocol Class ":local", try stat'ing
1007 if (KProtocolInfo::protocolClass(url
.scheme()) == QLatin1String(":local")) {
1008 KIO::StatJob
*job
= KIO::mostLocalUrl(url
);
1009 KJobWidgets::setWindow(job
, this);
1010 connect(job
, &KJob::result
, this, [job
]() {
1012 if (!job
->error()) {
1013 statUrl
= job
->mostLocalUrl();
1016 KToolInvocation::invokeTerminal(QString(), statUrl
.isLocalFile() ? statUrl
.toLocalFile() : QDir::homePath());
1022 // Nothing worked, just use $HOME
1023 KToolInvocation::invokeTerminal(QString(), QDir::homePath());
1026 void DolphinMainWindow::editSettings()
1028 if (!m_settingsDialog
) {
1029 DolphinViewContainer
* container
= activeViewContainer();
1030 container
->view()->writeSettings();
1032 const QUrl url
= container
->url();
1033 DolphinSettingsDialog
* settingsDialog
= new DolphinSettingsDialog(url
, this);
1034 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, this, &DolphinMainWindow::refreshViews
);
1035 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1036 settingsDialog
->show();
1037 m_settingsDialog
= settingsDialog
;
1039 m_settingsDialog
.data()->raise();
1043 void DolphinMainWindow::handleUrl(const QUrl
& url
)
1045 delete m_lastHandleUrlOpenJob
;
1046 m_lastHandleUrlOpenJob
= nullptr;
1048 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1049 activeViewContainer()->setUrl(url
);
1051 m_lastHandleUrlOpenJob
= new KIO::OpenUrlJob(url
);
1052 m_lastHandleUrlOpenJob
->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
1053 m_lastHandleUrlOpenJob
->setRunExecutables(true);
1055 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::mimeTypeFound
, this,
1056 [this, url
](const QString
&mimetype
) {
1057 if (mimetype
== QLatin1String("inode/directory")) {
1058 // If it's a dir, we'll take it from here
1059 m_lastHandleUrlOpenJob
->kill();
1060 m_lastHandleUrlOpenJob
= nullptr;
1061 activeViewContainer()->setUrl(url
);
1065 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::result
, this, [this]() {
1066 m_lastHandleUrlOpenJob
= nullptr;
1069 m_lastHandleUrlOpenJob
->start();
1073 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1075 // trash:/ is writable but we don't want to create new items in it.
1076 // TODO: remove the trash check once https://phabricator.kde.org/T8234 is implemented
1077 newFileMenu()->setEnabled(isFolderWritable
&& m_activeViewContainer
->url().scheme() != QLatin1String("trash"));
1080 void DolphinMainWindow::openContextMenu(const QPoint
& pos
,
1081 const KFileItem
& item
,
1083 const QList
<QAction
*>& customActions
)
1085 QPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, pos
, item
, url
);
1086 contextMenu
.data()->setCustomActions(customActions
);
1087 const DolphinContextMenu::Command command
= contextMenu
.data()->open();
1090 case DolphinContextMenu::OpenParentFolder
:
1091 changeUrl(KIO::upUrl(item
.url()));
1092 m_activeViewContainer
->view()->markUrlsAsSelected({item
.url()});
1093 m_activeViewContainer
->view()->markUrlAsCurrent(item
.url());
1096 case DolphinContextMenu::OpenParentFolderInNewWindow
:
1097 Dolphin::openNewWindow({item
.url()}, this, Dolphin::OpenNewWindowFlag::Select
);
1100 case DolphinContextMenu::OpenParentFolderInNewTab
:
1101 openNewTabAfterLastTab(KIO::upUrl(item
.url()));
1104 case DolphinContextMenu::None
:
1109 // Delete the menu, unless it has been deleted in its own nested event loop already.
1111 contextMenu
->deleteLater();
1115 void DolphinMainWindow::updateControlMenu()
1117 QMenu
* menu
= qobject_cast
<QMenu
*>(sender());
1120 // All actions get cleared by QMenu::clear(). This includes the sub-menus
1121 // because 'menu' is their parent.
1124 KActionCollection
* ac
= actionCollection();
1126 menu
->addMenu(m_newFileMenu
->menu());
1127 addActionToMenu(ac
->action(QStringLiteral("file_new")), menu
);
1128 addActionToMenu(ac
->action(QStringLiteral("new_tab")), menu
);
1129 addActionToMenu(ac
->action(QStringLiteral("closed_tabs")), menu
);
1131 menu
->addSeparator();
1133 // Add "Edit" actions
1134 bool added
= addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Undo
)), menu
) |
1135 addActionToMenu(ac
->action(QString("copy_location")), menu
) |
1136 addActionToMenu(ac
->action(QStringLiteral("copy_to_inactive_split_view")), menu
) |
1137 addActionToMenu(ac
->action(QStringLiteral("move_to_inactive_split_view")), menu
) |
1138 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::SelectAll
)), menu
) |
1139 addActionToMenu(ac
->action(QStringLiteral("invert_selection")), menu
);
1142 menu
->addSeparator();
1145 // Add "View" actions
1146 if (!GeneralSettings::showZoomSlider()) {
1147 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomIn
)), menu
);
1148 addActionToMenu(ac
->action(QStringLiteral("view_zoom_reset")), menu
);
1149 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomOut
)), menu
);
1150 menu
->addSeparator();
1153 added
= addActionToMenu(ac
->action(QStringLiteral("show_preview")), menu
) |
1154 addActionToMenu(ac
->action(QStringLiteral("show_in_groups")), menu
) |
1155 addActionToMenu(ac
->action(QStringLiteral("show_hidden_files")), menu
) |
1156 addActionToMenu(ac
->action(QStringLiteral("additional_info")), menu
) |
1157 addActionToMenu(ac
->action(QStringLiteral("view_properties")), menu
);
1160 menu
->addSeparator();
1163 // Add a curated assortment of items from the "Tools" menu
1164 addActionToMenu(ac
->action(QStringLiteral("show_filter_bar")), menu
);
1165 addActionToMenu(ac
->action(QStringLiteral("open_preferred_search_tool")), menu
);
1166 addActionToMenu(ac
->action(QStringLiteral("open_terminal")), menu
);
1168 menu
->addSeparator();
1170 // Add "Show Panels" menu
1171 addActionToMenu(ac
->action(QStringLiteral("panels")), menu
);
1173 // Add "Settings" menu entries
1174 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)), menu
);
1175 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)), menu
);
1176 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Preferences
)), menu
);
1177 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)), menu
);
1180 auto helpMenu
= m_helpMenu
->menu();
1181 helpMenu
->setIcon(QIcon::fromTheme(QStringLiteral("system-help")));
1182 menu
->addMenu(helpMenu
);
1185 void DolphinMainWindow::updateToolBar()
1187 if (!menuBar()->isVisible()) {
1188 createControlButton();
1192 void DolphinMainWindow::slotControlButtonDeleted()
1194 m_controlButton
= nullptr;
1195 m_updateToolBarTimer
->start();
1198 void DolphinMainWindow::slotPlaceActivated(const QUrl
& url
)
1200 DolphinViewContainer
* view
= activeViewContainer();
1202 if (view
->url() == url
) {
1203 // We can end up here if the user clicked a device in the Places Panel
1204 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
1211 void DolphinMainWindow::closedTabsCountChanged(unsigned int count
)
1213 actionCollection()->action(QStringLiteral("undo_close_tab"))->setEnabled(count
> 0);
1216 void DolphinMainWindow::activeViewChanged(DolphinViewContainer
* viewContainer
)
1218 DolphinViewContainer
* oldViewContainer
= m_activeViewContainer
;
1219 Q_ASSERT(viewContainer
);
1221 m_activeViewContainer
= viewContainer
;
1223 if (oldViewContainer
) {
1224 const QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
1225 toggleSearchAction
->disconnect(oldViewContainer
);
1227 // Disconnect all signals between the old view container (container,
1228 // view and url navigator) and main window.
1229 oldViewContainer
->disconnect(this);
1230 oldViewContainer
->view()->disconnect(this);
1231 oldViewContainer
->urlNavigator()->disconnect(this);
1233 // except the requestItemInfo so that on hover the information panel can still be updated
1234 connect(oldViewContainer
->view(), &DolphinView::requestItemInfo
,
1235 this, &DolphinMainWindow::requestItemInfo
);
1238 connectViewSignals(viewContainer
);
1240 m_actionHandler
->setCurrentView(viewContainer
->view());
1243 updateFileAndEditActions();
1244 updatePasteAction();
1245 updateViewActions();
1247 updateSearchAction();
1249 const QUrl url
= viewContainer
->url();
1250 emit
urlChanged(url
);
1253 void DolphinMainWindow::tabCountChanged(int count
)
1255 const bool enableTabActions
= (count
> 1);
1256 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1257 actionCollection()->action(QStringLiteral("activate_tab_%1").arg(i
))->setEnabled(enableTabActions
);
1259 actionCollection()->action(QStringLiteral("activate_last_tab"))->setEnabled(enableTabActions
);
1260 actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions
);
1261 actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions
);
1264 void DolphinMainWindow::updateWindowTitle()
1266 const QString newTitle
= m_activeViewContainer
->captionWindowTitle();
1267 if (windowTitle() != newTitle
) {
1268 setWindowTitle(newTitle
);
1272 void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString
& mountPath
)
1274 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1275 setViewsToHomeIfMountPathOpen(mountPath
);
1278 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectory().startsWith(mountPath
)) {
1279 m_tearDownFromPlacesRequested
= true;
1280 m_terminalPanel
->goHome();
1281 // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged
1283 m_placesPanel
->proceedWithTearDown();
1287 void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString
& mountPath
)
1289 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1290 setViewsToHomeIfMountPathOpen(mountPath
);
1293 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectory().startsWith(mountPath
)) {
1294 m_tearDownFromPlacesRequested
= false;
1295 m_terminalPanel
->goHome();
1299 void DolphinMainWindow::setViewsToHomeIfMountPathOpen(const QString
& mountPath
)
1301 const QVector
<DolphinViewContainer
*> theViewContainers
= viewContainers();
1302 for (DolphinViewContainer
*viewContainer
: theViewContainers
) {
1303 if (viewContainer
&& viewContainer
->url().toLocalFile().startsWith(mountPath
)) {
1304 viewContainer
->setUrl(QUrl::fromLocalFile(QDir::homePath()));
1307 disconnect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, nullptr, nullptr);
1310 void DolphinMainWindow::setupActions()
1312 // setup 'File' menu
1313 m_newFileMenu
= new DolphinNewFileMenu(actionCollection(), this);
1314 QMenu
* menu
= m_newFileMenu
->menu();
1315 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1316 menu
->setIcon(QIcon::fromTheme(QStringLiteral("document-new")));
1317 m_newFileMenu
->setDelayed(false);
1318 connect(menu
, &QMenu::aboutToShow
,
1319 this, &DolphinMainWindow::updateNewMenu
);
1321 QAction
* newWindow
= KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow
, actionCollection());
1322 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1323 newWindow
->setToolTip(i18nc("@info", "Open a new Dolphin window"));
1324 newWindow
->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1325 "window just like this one with the current location and view."
1326 "<nl/>You can drag and drop items between windows."));
1327 newWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1329 QAction
* newTab
= actionCollection()->addAction(QStringLiteral("new_tab"));
1330 newTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1331 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1332 newTab
->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1333 "<emphasis>Tab</emphasis> with the current location and view.<nl/>"
1334 "A tab is an additional view within this window. "
1335 "You can drag and drop items between tabs."));
1336 actionCollection()->setDefaultShortcuts(newTab
, {Qt::CTRL
+ Qt::Key_T
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_N
});
1337 connect(newTab
, &QAction::triggered
, this, &DolphinMainWindow::openNewActivatedTab
);
1339 QAction
* addToPlaces
= actionCollection()->addAction(QStringLiteral("add_to_places"));
1340 addToPlaces
->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new")));
1341 addToPlaces
->setText(i18nc("@action:inmenu Add current folder to places", "Add to Places"));
1342 addToPlaces
->setWhatsThis(xi18nc("@info:whatsthis", "This adds the selected folder "
1343 "to the Places panel."));
1344 connect(addToPlaces
, &QAction::triggered
, this, &DolphinMainWindow::addToPlaces
);
1346 QAction
* closeTab
= KStandardAction::close(m_tabWidget
, QOverload
<>::of(&DolphinTabWidget::closeTab
), actionCollection());
1347 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1348 closeTab
->setWhatsThis(i18nc("@info:whatsthis", "This closes the "
1349 "currently viewed tab. If no more tabs are left this window "
1350 "will close instead."));
1352 QAction
* quitAction
= KStandardAction::quit(this, &DolphinMainWindow::quit
, actionCollection());
1353 quitAction
->setWhatsThis(i18nc("@info:whatsthis quit", "This closes this window."));
1355 // setup 'Edit' menu
1356 KStandardAction::undo(this,
1357 &DolphinMainWindow::undo
,
1358 actionCollection());
1360 // i18n: This will be the last paragraph for the whatsthis for all three:
1361 // Cut, Copy and Paste
1362 const QString cutCopyPastePara
= xi18nc("@info:whatsthis", "<para><emphasis>Cut, "
1363 "Copy</emphasis> and <emphasis>Paste</emphasis> work between many "
1364 "applications and are among the most used commands. That's why their "
1365 "<emphasis>keyboard shortcuts</emphasis> are prominently placed right "
1366 "next to each other on the keyboard: <shortcut>Ctrl+X</shortcut>, "
1367 "<shortcut>Ctrl+C</shortcut> and <shortcut>Ctrl+V</shortcut>.</para>");
1368 QAction
* cutAction
= KStandardAction::cut(this, &DolphinMainWindow::cut
, actionCollection());
1369 cutAction
->setWhatsThis(xi18nc("@info:whatsthis cut", "This copies the items "
1370 "in your current selection to the <emphasis>clipboard</emphasis>.<nl/>"
1371 "Use the <emphasis>Paste</emphasis> action afterwards to copy them from "
1372 "the clipboard to a new location. The items will be removed from their "
1373 "initial location.") + cutCopyPastePara
);
1374 QAction
* copyAction
= KStandardAction::copy(this, &DolphinMainWindow::copy
, actionCollection());
1375 copyAction
->setWhatsThis(xi18nc("@info:whatsthis copy", "This copies the "
1376 "items in your current selection to the <emphasis>clipboard</emphasis>."
1377 "<nl/>Use the <emphasis>Paste</emphasis> action afterwards to copy them "
1378 "from the clipboard to a new location.") + cutCopyPastePara
);
1379 QAction
* paste
= KStandardAction::paste(this, &DolphinMainWindow::paste
, actionCollection());
1380 // The text of the paste-action is modified dynamically by Dolphin
1381 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1382 // due to the long text, the text "Paste" is used:
1383 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1384 paste
->setWhatsThis(xi18nc("@info:whatsthis paste", "This copies the items from "
1385 "your <emphasis>clipboard</emphasis> to the currently viewed folder.<nl/>"
1386 "If the items were added to the clipboard by the <emphasis>Cut</emphasis> "
1387 "action they are removed from their old location.") + cutCopyPastePara
);
1389 QAction
* copyToOtherViewAction
= actionCollection()->addAction(QStringLiteral("copy_to_inactive_split_view"));
1390 copyToOtherViewAction
->setText(i18nc("@action:inmenu", "Copy to Inactive Split View"));
1391 copyToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Copy", "This copies the selected items from "
1392 "the <emphasis>active</emphasis> view to the inactive split view."));
1393 copyToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
1394 copyToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Copy to Inactive Split View"));
1395 actionCollection()->setDefaultShortcut(copyToOtherViewAction
, Qt::SHIFT
+ Qt::Key_F5
);
1396 connect(copyToOtherViewAction
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::copyToInactiveSplitView
);
1398 QAction
* moveToOtherViewAction
= actionCollection()->addAction(QStringLiteral("move_to_inactive_split_view"));
1399 moveToOtherViewAction
->setText(i18nc("@action:inmenu", "Move to Inactive Split View"));
1400 moveToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Move", "This moves the selected items from "
1401 "the <emphasis>active</emphasis> view to the inactive split view."));
1402 moveToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-cut")));
1403 moveToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Move to Inactive Split View"));
1404 actionCollection()->setDefaultShortcut(moveToOtherViewAction
, Qt::SHIFT
+ Qt::Key_F6
);
1405 connect(moveToOtherViewAction
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::moveToInactiveSplitView
);
1407 QAction
*searchAction
= KStandardAction::find(this, &DolphinMainWindow::find
, actionCollection());
1408 searchAction
->setText(i18n("Search..."));
1409 searchAction
->setToolTip(i18nc("@info:tooltip", "Search for files and folders"));
1410 searchAction
->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This helps you "
1411 "find files and folders by opening a <emphasis>find bar</emphasis>. "
1412 "There you can enter search terms and specify settings to find the "
1413 "objects you are looking for.</para><para>Use this help again on "
1414 "the find bar so we can have a look at it while the settings are "
1415 "explained.</para>"));
1417 // toggle_search acts as a copy of the main searchAction to be used mainly
1418 // in the toolbar, with no default shortcut attached, to avoid messing with
1419 // existing workflows (search bar always open and Ctrl-F to focus)
1420 QAction
*toggleSearchAction
= actionCollection()->addAction(QStringLiteral("toggle_search"));
1421 toggleSearchAction
->setText(i18nc("@action:inmenu", "Toggle Search Bar"));
1422 toggleSearchAction
->setIconText(i18nc("@action:intoolbar", "Search"));
1423 toggleSearchAction
->setIcon(searchAction
->icon());
1424 toggleSearchAction
->setToolTip(searchAction
->toolTip());
1425 toggleSearchAction
->setWhatsThis(searchAction
->whatsThis());
1426 toggleSearchAction
->setCheckable(true);
1428 QAction
* selectAllAction
= KStandardAction::selectAll(this, &DolphinMainWindow::selectAll
, actionCollection());
1429 selectAllAction
->setWhatsThis(xi18nc("@info:whatsthis", "This selects all "
1430 "files and folders in the current location."));
1432 QAction
* invertSelection
= actionCollection()->addAction(QStringLiteral("invert_selection"));
1433 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1434 invertSelection
->setWhatsThis(xi18nc("@info:whatsthis invert", "This selects all "
1435 "objects that you have currently <emphasis>not</emphasis> selected instead."));
1436 invertSelection
->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-invert")));
1437 actionCollection()->setDefaultShortcut(invertSelection
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_A
);
1438 connect(invertSelection
, &QAction::triggered
, this, &DolphinMainWindow::invertSelection
);
1440 // setup 'View' menu
1441 // (note that most of it is set up in DolphinViewActionHandler)
1443 QAction
* split
= actionCollection()->addAction(QStringLiteral("split_view"));
1444 split
->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This splits "
1445 "the folder view below into two autonomous views.</para><para>This "
1446 "way you can see two locations at once and move items between them "
1447 "quickly.</para>Click this again afterwards to recombine the views."));
1448 actionCollection()->setDefaultShortcut(split
, Qt::Key_F3
);
1449 connect(split
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitView
);
1451 QAction
* stashSplit
= actionCollection()->addAction(QStringLiteral("split_stash"));
1452 actionCollection()->setDefaultShortcut(stashSplit
, Qt::CTRL
+ Qt::Key_S
);
1453 stashSplit
->setText(i18nc("@action:intoolbar Stash", "Stash"));
1454 stashSplit
->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
1455 stashSplit
->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
1456 stashSplit
->setCheckable(false);
1457 stashSplit
->setVisible(KProtocolInfo::isKnownProtocol("stash"));
1458 connect(stashSplit
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitStash
);
1460 KStandardAction::redisplay(this, &DolphinMainWindow::reloadView
, actionCollection());
1462 QAction
* stop
= actionCollection()->addAction(QStringLiteral("stop"));
1463 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1464 stop
->setToolTip(i18nc("@info", "Stop loading"));
1465 stop
->setWhatsThis(i18nc("@info", "This stops the loading of the contents of the current folder."));
1466 stop
->setIcon(QIcon::fromTheme(QStringLiteral("process-stop")));
1467 connect(stop
, &QAction::triggered
, this, &DolphinMainWindow::stopLoading
);
1469 KToggleAction
* editableLocation
= actionCollection()->add
<KToggleAction
>(QStringLiteral("editable_location"));
1470 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1471 editableLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1472 "This toggles the <emphasis>Location Bar</emphasis> to be "
1473 "editable so you can directly enter a location you want to go to.<nl/>"
1474 "You can also switch to editing by clicking to the right of the "
1475 "location and switch back by confirming the edited location."));
1476 actionCollection()->setDefaultShortcut(editableLocation
, Qt::Key_F6
);
1477 connect(editableLocation
, &KToggleAction::triggered
, this, &DolphinMainWindow::toggleEditLocation
);
1479 QAction
* replaceLocation
= actionCollection()->addAction(QStringLiteral("replace_location"));
1480 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1481 // i18n: "enter" is used both in the meaning of "writing" and "going to" a new location here.
1482 // Both meanings are useful but not necessary to understand the use of "Replace Location".
1483 // So you might want to be more verbose in your language to convey the meaning but it's up to you.
1484 replaceLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1485 "This switches to editing the location and selects it "
1486 "so you can quickly enter a different location."));
1487 actionCollection()->setDefaultShortcut(replaceLocation
, Qt::CTRL
+ Qt::Key_L
);
1488 connect(replaceLocation
, &QAction::triggered
, this, &DolphinMainWindow::replaceLocation
);
1492 QScopedPointer
<QAction
> backAction(KStandardAction::back(nullptr, nullptr, nullptr));
1493 m_backAction
= new KToolBarPopupAction(backAction
->icon(), backAction
->text(), actionCollection());
1494 m_backAction
->setObjectName(backAction
->objectName());
1495 m_backAction
->setShortcuts(backAction
->shortcuts());
1497 m_backAction
->setDelayed(true);
1498 m_backAction
->setStickyMenu(false);
1499 connect(m_backAction
, &QAction::triggered
, this, &DolphinMainWindow::goBack
);
1500 connect(m_backAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowBackPopupMenu
);
1501 connect(m_backAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoBack
);
1502 actionCollection()->addAction(m_backAction
->objectName(), m_backAction
);
1504 auto backShortcuts
= m_backAction
->shortcuts();
1505 backShortcuts
.append(QKeySequence(Qt::Key_Backspace
));
1506 actionCollection()->setDefaultShortcuts(m_backAction
, backShortcuts
);
1508 DolphinRecentTabsMenu
* recentTabsMenu
= new DolphinRecentTabsMenu(this);
1509 actionCollection()->addAction(QStringLiteral("closed_tabs"), recentTabsMenu
);
1510 connect(m_tabWidget
, &DolphinTabWidget::rememberClosedTab
,
1511 recentTabsMenu
, &DolphinRecentTabsMenu::rememberClosedTab
);
1512 connect(recentTabsMenu
, &DolphinRecentTabsMenu::restoreClosedTab
,
1513 m_tabWidget
, &DolphinTabWidget::restoreClosedTab
);
1514 connect(recentTabsMenu
, &DolphinRecentTabsMenu::closedTabsCountChanged
,
1515 this, &DolphinMainWindow::closedTabsCountChanged
);
1517 QAction
* undoCloseTab
= actionCollection()->addAction(QStringLiteral("undo_close_tab"));
1518 undoCloseTab
->setText(i18nc("@action:inmenu File", "Undo close tab"));
1519 undoCloseTab
->setWhatsThis(i18nc("@info:whatsthis undo close tab",
1520 "This returns you to the previously closed tab."));
1521 actionCollection()->setDefaultShortcut(undoCloseTab
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_T
);
1522 undoCloseTab
->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo")));
1523 undoCloseTab
->setEnabled(false);
1524 connect(undoCloseTab
, &QAction::triggered
, recentTabsMenu
, &DolphinRecentTabsMenu::undoCloseTab
);
1526 auto undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
1527 undoAction
->setWhatsThis(xi18nc("@info:whatsthis", "This undoes "
1528 "the last change you made to files or folders.<nl/>"
1529 "Such changes include <interface>creating, renaming</interface> "
1530 "and <interface>moving</interface> them to a different location "
1531 "or to the <filename>Trash</filename>. <nl/>Changes that can't "
1532 "be undone will ask for your confirmation."));
1533 undoAction
->setEnabled(false); // undo should be disabled by default
1536 QScopedPointer
<QAction
> forwardAction(KStandardAction::forward(nullptr, nullptr, nullptr));
1537 m_forwardAction
= new KToolBarPopupAction(forwardAction
->icon(), forwardAction
->text(), actionCollection());
1538 m_forwardAction
->setObjectName(forwardAction
->objectName());
1539 m_forwardAction
->setShortcuts(forwardAction
->shortcuts());
1541 m_forwardAction
->setDelayed(true);
1542 m_forwardAction
->setStickyMenu(false);
1543 connect(m_forwardAction
, &QAction::triggered
, this, &DolphinMainWindow::goForward
);
1544 connect(m_forwardAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowForwardPopupMenu
);
1545 connect(m_forwardAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoForward
);
1546 actionCollection()->addAction(m_forwardAction
->objectName(), m_forwardAction
);
1547 actionCollection()->setDefaultShortcuts(m_forwardAction
, m_forwardAction
->shortcuts());
1549 // enable middle-click to open in a new tab
1550 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
1551 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotBackForwardActionMiddleClicked
);
1552 m_backAction
->menu()->installEventFilter(middleClickEventFilter
);
1553 m_forwardAction
->menu()->installEventFilter(middleClickEventFilter
);
1554 KStandardAction::up(this, &DolphinMainWindow::goUp
, actionCollection());
1555 QAction
* homeAction
= KStandardAction::home(this, &DolphinMainWindow::goHome
, actionCollection());
1556 homeAction
->setWhatsThis(xi18nc("@info:whatsthis", "Go to your "
1557 "<filename>Home</filename> folder.<nl/>Every user account "
1558 "has their own <filename>Home</filename> that contains their data "
1559 "including folders that contain personal application data."));
1561 // setup 'Tools' menu
1562 QAction
* showFilterBar
= actionCollection()->addAction(QStringLiteral("show_filter_bar"));
1563 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1564 showFilterBar
->setWhatsThis(xi18nc("@info:whatsthis", "This opens the "
1565 "<emphasis>Filter Bar</emphasis> at the bottom of the window.<nl/> "
1566 "There you can enter a text to filter the files and folders currently displayed. "
1567 "Only those that contain the text in their name will be kept in view."));
1568 showFilterBar
->setIcon(QIcon::fromTheme(QStringLiteral("view-filter")));
1569 actionCollection()->setDefaultShortcuts(showFilterBar
, {Qt::CTRL
+ Qt::Key_I
, Qt::Key_Slash
});
1570 connect(showFilterBar
, &QAction::triggered
, this, &DolphinMainWindow::showFilterBar
);
1572 QAction
* compareFiles
= actionCollection()->addAction(QStringLiteral("compare_files"));
1573 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1574 compareFiles
->setIcon(QIcon::fromTheme(QStringLiteral("kompare")));
1575 compareFiles
->setEnabled(false);
1576 connect(compareFiles
, &QAction::triggered
, this, &DolphinMainWindow::compareFiles
);
1578 QAction
* openPreferredSearchTool
= actionCollection()->addAction(QStringLiteral("open_preferred_search_tool"));
1579 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1580 openPreferredSearchTool
->setWhatsThis(xi18nc("@info:whatsthis",
1581 "<para>This opens a preferred search tool for the viewed location.</para>"
1582 "<para>Use <emphasis>More Search Tools</emphasis> menu to configure it.</para>"));
1583 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1584 actionCollection()->setDefaultShortcut(openPreferredSearchTool
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_F
);
1585 connect(openPreferredSearchTool
, &QAction::triggered
, this, &DolphinMainWindow::openPreferredSearchTool
);
1587 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1588 QAction
* openTerminal
= actionCollection()->addAction(QStringLiteral("open_terminal"));
1589 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1590 openTerminal
->setWhatsThis(xi18nc("@info:whatsthis",
1591 "<para>This opens a <emphasis>terminal</emphasis> application for the viewed location.</para>"
1592 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1593 openTerminal
->setIcon(QIcon::fromTheme(QStringLiteral("dialog-scripts")));
1594 actionCollection()->setDefaultShortcut(openTerminal
, Qt::SHIFT
+ Qt::Key_F4
);
1595 connect(openTerminal
, &QAction::triggered
, this, &DolphinMainWindow::openTerminal
);
1597 #ifdef HAVE_TERMINAL
1598 QAction
* focusTerminalPanel
= actionCollection()->addAction(QStringLiteral("focus_terminal_panel"));
1599 focusTerminalPanel
->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
1600 focusTerminalPanel
->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
1601 actionCollection()->setDefaultShortcut(focusTerminalPanel
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_F4
);
1602 connect(focusTerminalPanel
, &QAction::triggered
, this, &DolphinMainWindow::focusTerminalPanel
);
1606 // setup 'Bookmarks' menu
1607 KActionMenu
*bookmarkMenu
= new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this);
1608 bookmarkMenu
->setIcon(QIcon::fromTheme(QStringLiteral("bookmarks")));
1609 // Make the toolbar button version work properly on click
1610 bookmarkMenu
->setDelayed(false);
1611 m_bookmarkHandler
= new DolphinBookmarkHandler(this, actionCollection(), bookmarkMenu
->menu(), this);
1612 actionCollection()->addAction(QStringLiteral("bookmarks"), bookmarkMenu
);
1614 // setup 'Settings' menu
1615 KToggleAction
* showMenuBar
= KStandardAction::showMenubar(nullptr, nullptr, actionCollection());
1616 showMenuBar
->setWhatsThis(xi18nc("@info:whatsthis",
1617 "This switches between having a <emphasis>Menubar</emphasis> "
1618 "and having a <interface>Control</interface> button. Both "
1619 "contain mostly the same commands and configuration options."));
1620 connect(showMenuBar
, &KToggleAction::triggered
, // Fixes #286822
1621 this, &DolphinMainWindow::toggleShowMenuBar
, Qt::QueuedConnection
);
1622 KStandardAction::preferences(this, &DolphinMainWindow::editSettings
, actionCollection());
1624 // setup 'Help' menu for the m_controlButton. The other one is set up in the base class.
1625 m_helpMenu
= new KHelpMenu(nullptr);
1626 m_helpMenu
->menu()->installEventFilter(this);
1627 // remove duplicate shortcuts
1628 m_helpMenu
->action(KHelpMenu::menuHelpContents
)->setShortcut(QKeySequence());
1629 m_helpMenu
->action(KHelpMenu::menuWhatsThis
)->setShortcut(QKeySequence());
1631 // not in menu actions
1632 QList
<QKeySequence
> nextTabKeys
= KStandardShortcut::tabNext();
1633 nextTabKeys
.append(QKeySequence(Qt::CTRL
+ Qt::Key_Tab
));
1635 QList
<QKeySequence
> prevTabKeys
= KStandardShortcut::tabPrev();
1636 prevTabKeys
.append(QKeySequence(Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_Tab
));
1638 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1639 QAction
* activateTab
= actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i
));
1640 activateTab
->setText(i18nc("@action:inmenu", "Activate Tab %1", i
+ 1));
1641 activateTab
->setEnabled(false);
1642 connect(activateTab
, &QAction::triggered
, this, [this, i
]() { m_tabWidget
->activateTab(i
); });
1644 // only add default shortcuts for the first 9 tabs regardless of MaxActivateTabShortcuts
1646 actionCollection()->setDefaultShortcut(activateTab
, QStringLiteral("Alt+%1").arg(i
+ 1));
1650 QAction
* activateLastTab
= actionCollection()->addAction(QStringLiteral("activate_last_tab"));
1651 activateLastTab
->setText(i18nc("@action:inmenu", "Activate Last Tab"));
1652 activateLastTab
->setEnabled(false);
1653 connect(activateLastTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateLastTab
);
1654 actionCollection()->setDefaultShortcut(activateLastTab
, Qt::ALT
+ Qt::Key_0
);
1656 QAction
* activateNextTab
= actionCollection()->addAction(QStringLiteral("activate_next_tab"));
1657 activateNextTab
->setIconText(i18nc("@action:inmenu", "Next Tab"));
1658 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1659 activateNextTab
->setEnabled(false);
1660 connect(activateNextTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateNextTab
);
1661 actionCollection()->setDefaultShortcuts(activateNextTab
, nextTabKeys
);
1663 QAction
* activatePrevTab
= actionCollection()->addAction(QStringLiteral("activate_prev_tab"));
1664 activatePrevTab
->setIconText(i18nc("@action:inmenu", "Previous Tab"));
1665 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1666 activatePrevTab
->setEnabled(false);
1667 connect(activatePrevTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activatePrevTab
);
1668 actionCollection()->setDefaultShortcuts(activatePrevTab
, prevTabKeys
);
1671 QAction
* showTarget
= actionCollection()->addAction(QStringLiteral("show_target"));
1672 showTarget
->setText(i18nc("@action:inmenu", "Show Target"));
1673 showTarget
->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
1674 showTarget
->setEnabled(false);
1675 connect(showTarget
, &QAction::triggered
, this, &DolphinMainWindow::showTarget
);
1677 QAction
* openInNewTab
= actionCollection()->addAction(QStringLiteral("open_in_new_tab"));
1678 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1679 openInNewTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1680 connect(openInNewTab
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
1682 QAction
* openInNewTabs
= actionCollection()->addAction(QStringLiteral("open_in_new_tabs"));
1683 openInNewTabs
->setText(i18nc("@action:inmenu", "Open in New Tabs"));
1684 openInNewTabs
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1685 connect(openInNewTabs
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
1687 QAction
* openInNewWindow
= actionCollection()->addAction(QStringLiteral("open_in_new_window"));
1688 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1689 openInNewWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1690 connect(openInNewWindow
, &QAction::triggered
, this, &DolphinMainWindow::openInNewWindow
);
1693 void DolphinMainWindow::setupDockWidgets()
1695 const bool lock
= GeneralSettings::lockPanels();
1697 KDualAction
* lockLayoutAction
= actionCollection()->add
<KDualAction
>(QStringLiteral("lock_panels"));
1698 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1699 lockLayoutAction
->setActiveIcon(QIcon::fromTheme(QStringLiteral("object-unlocked")));
1700 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1701 lockLayoutAction
->setInactiveIcon(QIcon::fromTheme(QStringLiteral("object-locked")));
1702 lockLayoutAction
->setWhatsThis(xi18nc("@info:whatsthis", "This "
1703 "switches between having panels <emphasis>locked</emphasis> or "
1704 "<emphasis>unlocked</emphasis>.<nl/>Unlocked panels can be "
1705 "dragged to the other side of the window and have a close "
1706 "button.<nl/>Locked panels are embedded more cleanly."));
1707 lockLayoutAction
->setActive(lock
);
1708 connect(lockLayoutAction
, &KDualAction::triggered
, this, &DolphinMainWindow::togglePanelLockState
);
1710 // Setup "Information"
1711 DolphinDockWidget
* infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
1712 infoDock
->setLocked(lock
);
1713 infoDock
->setObjectName(QStringLiteral("infoDock"));
1714 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1717 InformationPanel
* infoPanel
= new InformationPanel(infoDock
);
1718 infoPanel
->setCustomContextMenuActions({lockLayoutAction
});
1719 connect(infoPanel
, &InformationPanel::urlActivated
, this, &DolphinMainWindow::handleUrl
);
1720 infoDock
->setWidget(infoPanel
);
1722 QAction
* infoAction
= infoDock
->toggleViewAction();
1723 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-information")), Qt::Key_F11
, infoAction
, QStringLiteral("show_information_panel"));
1725 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1726 connect(this, &DolphinMainWindow::urlChanged
,
1727 infoPanel
, &InformationPanel::setUrl
);
1728 connect(this, &DolphinMainWindow::selectionChanged
,
1729 infoPanel
, &InformationPanel::setSelection
);
1730 connect(this, &DolphinMainWindow::requestItemInfo
,
1731 infoPanel
, &InformationPanel::requestDelayedItemInfo
);
1734 // i18n: This is the last paragraph for the "What's This"-texts of all four panels.
1735 const QString panelWhatsThis
= xi18nc("@info:whatsthis", "<para>To show or "
1736 "hide panels like this go to <interface>Control|Panels</interface> "
1737 "or <interface>View|Panels</interface>.</para>");
1739 actionCollection()->action(QStringLiteral("show_information_panel"))
1740 ->setWhatsThis(xi18nc("@info:whatsthis", "<para> This toggles the "
1741 "<emphasis>information</emphasis> panel at the right side of the "
1742 "window.</para><para>The panel provides in-depth information "
1743 "about the items your mouse is hovering over or about the selected "
1744 "items. Otherwise it informs you about the currently viewed folder.<nl/>"
1745 "For single items a preview of their contents is provided.</para>"));
1747 infoDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
1748 "provides in-depth information about the items your mouse is "
1749 "hovering over or about the selected items. Otherwise it informs "
1750 "you about the currently viewed folder.<nl/>For single items a "
1751 "preview of their contents is provided.</para><para>You can configure "
1752 "which and how details are given here by right-clicking.</para>") + panelWhatsThis
);
1755 DolphinDockWidget
* foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
1756 foldersDock
->setLocked(lock
);
1757 foldersDock
->setObjectName(QStringLiteral("foldersDock"));
1758 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1759 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1760 foldersPanel
->setCustomContextMenuActions({lockLayoutAction
});
1761 foldersDock
->setWidget(foldersPanel
);
1763 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1764 createPanelAction(QIcon::fromTheme(QStringLiteral("folder")), Qt::Key_F7
, foldersAction
, QStringLiteral("show_folders_panel"));
1766 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1767 connect(this, &DolphinMainWindow::urlChanged
,
1768 foldersPanel
, &FoldersPanel::setUrl
);
1769 connect(foldersPanel
, &FoldersPanel::folderActivated
,
1770 this, &DolphinMainWindow::changeUrl
);
1771 connect(foldersPanel
, &FoldersPanel::folderMiddleClicked
,
1772 this, &DolphinMainWindow::openNewTabAfterCurrentTab
);
1773 connect(foldersPanel
, &FoldersPanel::errorMessage
,
1774 this, &DolphinMainWindow::showErrorMessage
);
1776 actionCollection()->action(QStringLiteral("show_folders_panel"))
1777 ->setWhatsThis(xi18nc("@info:whatsthis", "This toggles the "
1778 "<emphasis>folders</emphasis> panel at the left side of the window."
1779 "<nl/><nl/>It shows the folders of the <emphasis>file system"
1780 "</emphasis> in a <emphasis>tree view</emphasis>."));
1781 foldersDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
1782 "shows the folders of the <emphasis>file system</emphasis> in a "
1783 "<emphasis>tree view</emphasis>.</para><para>Click a folder to go "
1784 "there. Click the arrow to the left of a folder to see its subfolders. "
1785 "This allows quick switching between any folders.</para>") + panelWhatsThis
);
1788 #ifdef HAVE_TERMINAL
1789 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1790 DolphinDockWidget
* terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1791 terminalDock
->setLocked(lock
);
1792 terminalDock
->setObjectName(QStringLiteral("terminalDock"));
1793 m_terminalPanel
= new TerminalPanel(terminalDock
);
1794 m_terminalPanel
->setCustomContextMenuActions({lockLayoutAction
});
1795 terminalDock
->setWidget(m_terminalPanel
);
1797 connect(m_terminalPanel
, &TerminalPanel::hideTerminalPanel
, terminalDock
, &DolphinDockWidget::hide
);
1798 connect(m_terminalPanel
, &TerminalPanel::changeUrl
, this, &DolphinMainWindow::slotTerminalDirectoryChanged
);
1799 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
,
1800 m_terminalPanel
, &TerminalPanel::dockVisibilityChanged
);
1801 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
,
1802 this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged
);
1804 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1805 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-scripts")), Qt::Key_F4
, terminalAction
, QStringLiteral("show_terminal_panel"));
1807 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1808 connect(this, &DolphinMainWindow::urlChanged
,
1809 m_terminalPanel
, &TerminalPanel::setUrl
);
1811 if (GeneralSettings::version() < 200) {
1812 terminalDock
->hide();
1815 actionCollection()->action(QStringLiteral("show_terminal_panel"))
1816 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
1817 "<emphasis>terminal</emphasis> panel at the bottom of the window."
1818 "<nl/>The location in the terminal will always match the folder "
1819 "view so you can navigate using either.</para><para>The terminal "
1820 "panel is not needed for basic computer usage but can be useful "
1821 "for advanced tasks. To learn more about terminals use the help "
1822 "in a standalone terminal application like Konsole.</para>"));
1823 terminalDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is "
1824 "the <emphasis>terminal</emphasis> panel. It behaves like a "
1825 "normal terminal but will match the location of the folder view "
1826 "so you can navigate using either.</para><para>The terminal panel "
1827 "is not needed for basic computer usage but can be useful for "
1828 "advanced tasks. To learn more about terminals use the help in a "
1829 "standalone terminal application like Konsole.</para>") + panelWhatsThis
);
1833 if (GeneralSettings::version() < 200) {
1835 foldersDock
->hide();
1839 DolphinDockWidget
* placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
1840 placesDock
->setLocked(lock
);
1841 placesDock
->setObjectName(QStringLiteral("placesDock"));
1842 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1844 m_placesPanel
= new PlacesPanel(placesDock
);
1845 m_placesPanel
->setCustomContextMenuActions({lockLayoutAction
});
1846 placesDock
->setWidget(m_placesPanel
);
1848 QAction
*placesAction
= placesDock
->toggleViewAction();
1849 createPanelAction(QIcon::fromTheme(QStringLiteral("bookmarks")), Qt::Key_F9
, placesAction
, QStringLiteral("show_places_panel"));
1851 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1852 connect(m_placesPanel
, &PlacesPanel::placeActivated
,
1853 this, &DolphinMainWindow::slotPlaceActivated
);
1854 connect(m_placesPanel
, &PlacesPanel::placeMiddleClicked
,
1855 this, &DolphinMainWindow::openNewTabAfterCurrentTab
);
1856 connect(m_placesPanel
, &PlacesPanel::errorMessage
,
1857 this, &DolphinMainWindow::showErrorMessage
);
1858 connect(this, &DolphinMainWindow::urlChanged
,
1859 m_placesPanel
, &PlacesPanel::setUrl
);
1860 connect(placesDock
, &DolphinDockWidget::visibilityChanged
,
1861 m_tabWidget
, &DolphinTabWidget::slotPlacesPanelVisibilityChanged
);
1862 connect(this, &DolphinMainWindow::settingsChanged
,
1863 m_placesPanel
, &PlacesPanel::readSettings
);
1864 connect(m_placesPanel
, &PlacesPanel::storageTearDownRequested
,
1865 this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested
);
1866 connect(m_placesPanel
, &PlacesPanel::storageTearDownExternallyRequested
,
1867 this, &DolphinMainWindow::slotStorageTearDownExternallyRequested
);
1868 m_tabWidget
->slotPlacesPanelVisibilityChanged(m_placesPanel
->isVisible());
1870 auto actionShowAllPlaces
= new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this);
1871 actionShowAllPlaces
->setCheckable(true);
1872 actionShowAllPlaces
->setDisabled(true);
1873 actionShowAllPlaces
->setWhatsThis(i18nc("@info:whatsthis", "This displays "
1874 "all places in the places panel that have been hidden. They will "
1875 "appear semi-transparent unless you uncheck their hide property."));
1877 connect(actionShowAllPlaces
, &QAction::triggered
, this, [actionShowAllPlaces
, this](bool checked
){
1878 actionShowAllPlaces
->setIcon(QIcon::fromTheme(checked
? QStringLiteral("view-visible") : QStringLiteral("view-hidden")));
1879 m_placesPanel
->showHiddenEntries(checked
);
1882 connect(m_placesPanel
, &PlacesPanel::showHiddenEntriesChanged
, this, [actionShowAllPlaces
] (bool checked
){
1883 actionShowAllPlaces
->setChecked(checked
);
1884 actionShowAllPlaces
->setIcon(QIcon::fromTheme(checked
? QStringLiteral("view-visible") : QStringLiteral("view-hidden")));
1887 actionCollection()->action(QStringLiteral("show_places_panel"))
1888 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
1889 "<emphasis>places</emphasis> panel at the left side of the window."
1890 "</para><para>It allows you to go to locations you have "
1891 "bookmarked and to access disk or media attached to the computer "
1892 "or to the network. It also contains sections to find recently "
1893 "saved files or files of a certain type.</para>"));
1894 placesDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
1895 "<emphasis>Places</emphasis> panel. It allows you to go to locations "
1896 "you have bookmarked and to access disk or media attached to the "
1897 "computer or to the network. It also contains sections to find "
1898 "recently saved files or files of a certain type.</para><para>"
1899 "Click on an entry to go there. Click with the right mouse button "
1900 "instead to open any entry in a new tab or new window.</para>"
1901 "<para>New entries can be added by dragging folders onto this panel. "
1902 "Right-click any section or entry to hide it. Right-click an empty "
1903 "space on this panel and select <interface>Show Hidden Places"
1904 "</interface> to display it again.</para>") + panelWhatsThis
);
1906 // Add actions into the "Panels" menu
1907 KActionMenu
* panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Show Panels"), this);
1908 actionCollection()->addAction(QStringLiteral("panels"), panelsMenu
);
1909 panelsMenu
->setIcon(QIcon::fromTheme(QStringLiteral("view-sidetree")));
1910 panelsMenu
->setDelayed(false);
1911 const KActionCollection
* ac
= actionCollection();
1912 panelsMenu
->addAction(ac
->action(QStringLiteral("show_places_panel")));
1914 panelsMenu
->addAction(ac
->action(QStringLiteral("show_information_panel")));
1916 panelsMenu
->addAction(ac
->action(QStringLiteral("show_folders_panel")));
1917 panelsMenu
->addAction(ac
->action(QStringLiteral("show_terminal_panel")));
1918 panelsMenu
->addSeparator();
1919 panelsMenu
->addAction(actionShowAllPlaces
);
1920 panelsMenu
->addAction(lockLayoutAction
);
1922 connect(panelsMenu
->menu(), &QMenu::aboutToShow
, this, [actionShowAllPlaces
, this]{
1923 actionShowAllPlaces
->setEnabled(m_placesPanel
->hiddenListCount());
1928 void DolphinMainWindow::updateFileAndEditActions()
1930 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1931 const KActionCollection
* col
= actionCollection();
1932 KFileItemListProperties
capabilitiesSource(list
);
1934 QAction
* addToPlacesAction
= col
->action(QStringLiteral("add_to_places"));
1935 QAction
* copyToOtherViewAction
= col
->action(QStringLiteral("copy_to_inactive_split_view"));
1936 QAction
* moveToOtherViewAction
= col
->action(QStringLiteral("move_to_inactive_split_view"));
1937 QAction
* copyLocation
= col
->action(QString("copy_location"));
1939 if (list
.isEmpty()) {
1940 stateChanged(QStringLiteral("has_no_selection"));
1942 addToPlacesAction
->setEnabled(true);
1943 copyToOtherViewAction
->setEnabled(false);
1944 moveToOtherViewAction
->setEnabled(false);
1945 copyLocation
->setEnabled(false);
1947 stateChanged(QStringLiteral("has_selection"));
1949 QAction
* renameAction
= col
->action(KStandardAction::name(KStandardAction::RenameFile
));
1950 QAction
* moveToTrashAction
= col
->action(KStandardAction::name(KStandardAction::MoveToTrash
));
1951 QAction
* deleteAction
= col
->action(KStandardAction::name(KStandardAction::DeleteFile
));
1952 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1953 QAction
* deleteWithTrashShortcut
= col
->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
1954 QAction
* showTarget
= col
->action(QStringLiteral("show_target"));
1955 QAction
* duplicateAction
= col
->action(QStringLiteral("duplicate")); // see DolphinViewActionHandler
1957 if (list
.length() == 1 && list
.first().isDir()) {
1958 addToPlacesAction
->setEnabled(true);
1960 addToPlacesAction
->setEnabled(false);
1963 if (m_tabWidget
->currentTabPage()->splitViewEnabled()) {
1964 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
1965 KFileItem capabilitiesDestination
;
1967 if (tabPage
->primaryViewActive()) {
1968 capabilitiesDestination
= tabPage
->secondaryViewContainer()->url();
1970 capabilitiesDestination
= tabPage
->primaryViewContainer()->url();
1973 copyToOtherViewAction
->setEnabled(capabilitiesDestination
.isWritable());
1974 moveToOtherViewAction
->setEnabled(capabilitiesSource
.supportsMoving() && capabilitiesDestination
.isWritable());
1976 copyToOtherViewAction
->setEnabled(false);
1977 moveToOtherViewAction
->setEnabled(false);
1980 const bool enableMoveToTrash
= capabilitiesSource
.isLocal() && capabilitiesSource
.supportsMoving();
1982 renameAction
->setEnabled(capabilitiesSource
.supportsMoving());
1983 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1984 deleteAction
->setEnabled(capabilitiesSource
.supportsDeleting());
1985 deleteWithTrashShortcut
->setEnabled(capabilitiesSource
.supportsDeleting() && !enableMoveToTrash
);
1986 cutAction
->setEnabled(capabilitiesSource
.supportsMoving());
1987 copyLocation
->setEnabled(list
.length() == 1);
1988 showTarget
->setEnabled(list
.length() == 1 && list
.at(0).isLink());
1989 duplicateAction
->setEnabled(capabilitiesSource
.supportsWriting());
1993 void DolphinMainWindow::updateViewActions()
1995 m_actionHandler
->updateViewActions();
1997 QAction
* showFilterBarAction
= actionCollection()->action(QStringLiteral("show_filter_bar"));
1998 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
2000 updateSplitAction();
2002 QAction
* editableLocactionAction
= actionCollection()->action(QStringLiteral("editable_location"));
2003 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
2004 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
2007 void DolphinMainWindow::updateGoActions()
2009 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
2010 const QUrl currentUrl
= m_activeViewContainer
->url();
2011 // I think this is one of the best places to firstly be confronted
2012 // with a file system and its hierarchy. Talking about the root
2013 // directory might seem too much here but it is the question that
2014 // naturally arises in this context.
2015 goUpAction
->setWhatsThis(xi18nc("@info:whatsthis", "<para>Go to "
2016 "the folder that contains the currently viewed one.</para>"
2017 "<para>All files and folders are organized in a hierarchical "
2018 "<emphasis>file system</emphasis>. At the top of this hierarchy is "
2019 "a directory that contains all data connected to this computer"
2020 "—the <emphasis>root directory</emphasis>.</para>"));
2021 goUpAction
->setEnabled(KIO::upUrl(currentUrl
) != currentUrl
);
2024 void DolphinMainWindow::createControlButton()
2026 if (m_controlButton
) {
2029 Q_ASSERT(!m_controlButton
);
2031 m_controlButton
= new QToolButton(this);
2032 m_controlButton
->setAccessibleName(i18nc("@action:intoolbar", "Control"));
2033 m_controlButton
->setIcon(QIcon::fromTheme(QStringLiteral("application-menu")));
2034 m_controlButton
->setToolTip(i18nc("@action", "Show menu"));
2035 m_controlButton
->setAttribute(Qt::WidgetAttribute::WA_CustomWhatsThis
);
2036 m_controlButton
->setPopupMode(QToolButton::InstantPopup
);
2038 QMenu
* controlMenu
= new QMenu(m_controlButton
);
2039 connect(controlMenu
, &QMenu::aboutToShow
, this, &DolphinMainWindow::updateControlMenu
);
2040 controlMenu
->installEventFilter(this);
2042 m_controlButton
->setMenu(controlMenu
);
2044 toolBar()->addWidget(m_controlButton
);
2045 connect(toolBar(), &KToolBar::iconSizeChanged
,
2046 m_controlButton
, &QToolButton::setIconSize
);
2048 // The added widgets are owned by the toolbar and may get deleted when e.g. the toolbar
2049 // gets edited. In this case we must add them again. The adding is done asynchronously by
2050 // m_updateToolBarTimer.
2051 connect(m_controlButton
, &QToolButton::destroyed
, this, &DolphinMainWindow::slotControlButtonDeleted
);
2052 m_updateToolBarTimer
= new QTimer(this);
2053 m_updateToolBarTimer
->setInterval(500);
2054 connect(m_updateToolBarTimer
, &QTimer::timeout
, this, &DolphinMainWindow::updateToolBar
);
2057 void DolphinMainWindow::deleteControlButton()
2059 delete m_controlButton
;
2060 m_controlButton
= nullptr;
2062 delete m_updateToolBarTimer
;
2063 m_updateToolBarTimer
= nullptr;
2066 bool DolphinMainWindow::addActionToMenu(QAction
* action
, QMenu
* menu
)
2071 const KToolBar
* toolBarWidget
= toolBar();
2072 foreach (const QWidget
* widget
, action
->associatedWidgets()) {
2073 if (widget
== toolBarWidget
) {
2078 menu
->addAction(action
);
2082 void DolphinMainWindow::refreshViews()
2084 m_tabWidget
->refreshViews();
2086 if (GeneralSettings::modifiedStartupSettings()) {
2087 // The startup settings have been changed by the user (see bug #254947).
2088 // Synchronize the split-view setting with the active view:
2089 const bool splitView
= GeneralSettings::splitView();
2090 m_tabWidget
->currentTabPage()->setSplitViewEnabled(splitView
);
2091 updateSplitAction();
2092 updateWindowTitle();
2095 emit
settingsChanged();
2098 void DolphinMainWindow::clearStatusBar()
2100 m_activeViewContainer
->statusBar()->resetToDefaultText();
2103 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
2105 connect(container
, &DolphinViewContainer::showFilterBarChanged
,
2106 this, &DolphinMainWindow::updateFilterBarAction
);
2107 connect(container
, &DolphinViewContainer::writeStateChanged
,
2108 this, &DolphinMainWindow::slotWriteStateChanged
);
2109 connect(container
, &DolphinViewContainer::searchModeEnabledChanged
,
2110 this, &DolphinMainWindow::updateSearchAction
);
2112 const QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
2113 connect(toggleSearchAction
, &QAction::triggered
, container
, &DolphinViewContainer::setSearchModeEnabled
);
2115 const DolphinView
* view
= container
->view();
2116 connect(view
, &DolphinView::selectionChanged
,
2117 this, &DolphinMainWindow::slotSelectionChanged
);
2118 connect(view
, &DolphinView::requestItemInfo
,
2119 this, &DolphinMainWindow::requestItemInfo
);
2120 connect(view
, &DolphinView::tabRequested
,
2121 this, &DolphinMainWindow::openNewTab
);
2122 connect(view
, &DolphinView::requestContextMenu
,
2123 this, &DolphinMainWindow::openContextMenu
);
2124 connect(view
, &DolphinView::directoryLoadingStarted
,
2125 this, &DolphinMainWindow::enableStopAction
);
2126 connect(view
, &DolphinView::directoryLoadingCompleted
,
2127 this, &DolphinMainWindow::disableStopAction
);
2128 connect(view
, &DolphinView::directoryLoadingCompleted
,
2129 this, &DolphinMainWindow::slotDirectoryLoadingCompleted
);
2130 connect(view
, &DolphinView::goBackRequested
,
2131 this, &DolphinMainWindow::goBack
);
2132 connect(view
, &DolphinView::goForwardRequested
,
2133 this, &DolphinMainWindow::goForward
);
2134 connect(view
, &DolphinView::urlActivated
,
2135 this, &DolphinMainWindow::handleUrl
);
2136 connect(view
, &DolphinView::goUpRequested
,
2137 this, &DolphinMainWindow::goUp
);
2139 const KUrlNavigator
* navigator
= container
->urlNavigator();
2140 connect(navigator
, &KUrlNavigator::urlChanged
,
2141 this, &DolphinMainWindow::changeUrl
);
2142 connect(navigator
, &KUrlNavigator::historyChanged
,
2143 this, &DolphinMainWindow::updateHistory
);
2144 connect(navigator
, &KUrlNavigator::editableStateChanged
,
2145 this, &DolphinMainWindow::slotEditableStateChanged
);
2146 connect(navigator
, &KUrlNavigator::tabRequested
,
2147 this, &DolphinMainWindow::openNewTabAfterLastTab
);
2150 void DolphinMainWindow::updateSplitAction()
2152 QAction
* splitAction
= actionCollection()->action(QStringLiteral("split_view"));
2153 const DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
2154 if (tabPage
->splitViewEnabled()) {
2155 if (GeneralSettings::closeActiveSplitView() ? tabPage
->primaryViewActive() : !tabPage
->primaryViewActive()) {
2156 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2157 splitAction
->setToolTip(i18nc("@info", "Close left view"));
2158 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close")));
2160 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2161 splitAction
->setToolTip(i18nc("@info", "Close right view"));
2162 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close")));
2165 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2166 splitAction
->setToolTip(i18nc("@info", "Split view"));
2167 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
2171 bool DolphinMainWindow::isKompareInstalled() const
2173 static bool initialized
= false;
2174 static bool installed
= false;
2176 // TODO: maybe replace this approach later by using a menu
2177 // plugin like kdiff3plugin.cpp
2178 installed
= !QStandardPaths::findExecutable(QStringLiteral("kompare")).isEmpty();
2184 void DolphinMainWindow::createPanelAction(const QIcon
& icon
,
2185 const QKeySequence
& shortcut
,
2186 QAction
* dockAction
,
2187 const QString
& actionName
)
2189 QAction
* panelAction
= actionCollection()->addAction(actionName
);
2190 panelAction
->setCheckable(true);
2191 panelAction
->setChecked(dockAction
->isChecked());
2192 panelAction
->setText(dockAction
->text());
2193 panelAction
->setIcon(icon
);
2194 actionCollection()->setDefaultShortcut(panelAction
, shortcut
);
2196 connect(panelAction
, &QAction::triggered
, dockAction
, &QAction::trigger
);
2197 connect(dockAction
, &QAction::toggled
, panelAction
, &QAction::setChecked
);
2200 void DolphinMainWindow::setupWhatsThis()
2203 menuBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2204 "<emphasis>Menubar</emphasis>. It provides access to commands and "
2205 "configuration options. Left-click on any of the menus on this "
2206 "bar to see its contents.</para><para>The Menubar can be hidden "
2207 "by unchecking <interface>Settings|Show Menubar</interface>. Then "
2208 "most of its contents become available through a <interface>Control"
2209 "</interface> button on the <emphasis>Toolbar</emphasis>.</para>"));
2210 toolBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2211 "<emphasis>Toolbar</emphasis>. It allows quick access to "
2212 "frequently used actions.</para><para>It is highly customizable. "
2213 "All items you see in the <interface>Control</interface> menu or "
2214 "in the <interface>Menubar</interface> can be placed on the "
2215 "Toolbar. Just right-click on it and select <interface>Configure "
2216 "Toolbars…</interface> or find this action in the <interface>"
2217 "Control</interface> or <interface>Settings</interface> menu."
2218 "</para><para>The location of the bar and the style of its "
2219 "buttons can also be changed in the right-click menu. Right-click "
2220 "a button if you want to show or hide its text.</para>"));
2221 m_tabWidget
->setWhatsThis(xi18nc("@info:whatsthis main view",
2222 "<para>Here you can see the <emphasis>folders</emphasis> and "
2223 "<emphasis>files</emphasis> that are at the location described in "
2224 "the <interface>Location Bar</interface> above. This area is the "
2225 "central part of this application where you navigate to the files "
2226 "you want to use.</para><para>For an elaborate and general "
2227 "introduction to this application <link "
2228 "url='https://userbase.kde.org/Dolphin/File_Management#Introduction_to_Dolphin'>"
2229 "click here</link>. This will open an introductory article from "
2230 "the <emphasis>KDE UserBase Wiki</emphasis>.</para><para>For brief "
2231 "explanations of all the features of this <emphasis>view</emphasis> "
2232 "<link url='help:/dolphin/dolphin-view.html'>click here</link> "
2233 "instead. This will open a page from the <emphasis>Handbook"
2234 "</emphasis> that covers the basics.</para>"));
2237 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings
))
2238 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window "
2239 "that lists the <emphasis>keyboard shortcuts</emphasis>.<nl/>"
2240 "There you can set up key combinations to trigger an action when "
2241 "they are pressed simultaneously. All commands in this application can "
2242 "be triggered this way.</para>"));
2243 actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars
))
2244 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window in which "
2245 "you can change which buttons appear on the <emphasis>Toolbar</emphasis>.</para>"
2246 "<para>All items you see in the <interface>Control</interface> menu "
2247 "or in the <interface>Menubar</interface> can also be placed on the Toolbar.</para>"));
2248 actionCollection()->action(KStandardAction::name(KStandardAction::Preferences
))
2249 ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window where you can "
2250 "change a multitude of settings for this application. For an explanation "
2251 "of the various settings go to the chapter <emphasis>Configuring Dolphin"
2252 "</emphasis> in <interface>Help|Dolphin Handbook</interface>."));
2255 // The whatsthis has to be set for the m_helpMenu and for the
2256 // StandardAction separately because both are used in different locations.
2257 // m_helpMenu is only used for createControlButton() button.
2259 // Links do not work within the Menubar so texts without links are provided there.
2261 // i18n: If the external link isn't available in your language you should
2262 // probably state the external link language at least in brackets to not
2263 // frustrate the user. If there are multiple languages that the user might
2264 // know with a reasonable chance you might want to have 2 external links.
2265 // The same is in my opinion true for every external link you translate.
2266 const QString whatsThisHelpContents
= xi18nc("@info:whatsthis handbook",
2267 "<para>This opens the Handbook for this application. It provides "
2268 "explanations for every part of <emphasis>Dolphin</emphasis>.</para>");
2269 actionCollection()->action(KStandardAction::name(KStandardAction::HelpContents
))
2270 ->setWhatsThis(whatsThisHelpContents
2271 + xi18nc("@info:whatsthis second half of handbook hb text without link",
2272 "<para>If you want more elaborate introductions to the "
2273 "different features of <emphasis>Dolphin</emphasis> "
2274 "go to the KDE UserBase Wiki.</para>"));
2275 m_helpMenu
->action(KHelpMenu::menuHelpContents
)->setWhatsThis(whatsThisHelpContents
2276 + xi18nc("@info:whatsthis second half of handbook text with link",
2277 "<para>If you want more elaborate introductions to the "
2278 "different features of <emphasis>Dolphin</emphasis> "
2279 "<link url='https://userbase.kde.org/Dolphin/File_Management'>click here</link>. "
2280 "It will open the dedicated page in the KDE UserBase Wiki.</para>"));
2282 const QString whatsThisWhatsThis
= xi18nc("@info:whatsthis whatsthis button",
2283 "<para>This is the button that invokes the help feature you are "
2284 "using right now! Click it, then click any component of this "
2285 "application to ask \"What's this?\" about it. The mouse cursor "
2286 "will change appearance if no help is available for a spot.</para>");
2287 actionCollection()->action(KStandardAction::name(KStandardAction::WhatsThis
))
2288 ->setWhatsThis(whatsThisWhatsThis
2289 + xi18nc("@info:whatsthis second half of whatsthis button text without link",
2290 "<para>There are two other ways to get help for this application: The "
2291 "<interface>Dolphin Handbook</interface> in the <interface>Help"
2292 "</interface> menu and the <emphasis>KDE UserBase Wiki</emphasis> "
2293 "article about <emphasis>File Management</emphasis> online."
2294 "</para><para>The \"What's this?\" help is "
2295 "missing in most other windows so don't get too used to this.</para>"));
2296 m_helpMenu
->action(KHelpMenu::menuWhatsThis
)->setWhatsThis(whatsThisWhatsThis
2297 + xi18nc("@info:whatsthis second half of whatsthis button text with link",
2298 "<para>There are two other ways to get help: "
2299 "The <link url='help:/dolphin/index.html'>Dolphin Handbook</link> and "
2300 "the <link url='https://userbase.kde.org/Dolphin/File_Management'>KDE "
2301 "UserBase Wiki</link>.</para><para>The \"What's this?\" help is "
2302 "missing in most other windows so don't get too used to this.</para>"));
2304 const QString whatsThisReportBug
= xi18nc("@info:whatsthis","<para>This opens a "
2305 "window that will guide you through reporting errors or flaws "
2306 "in this application or in other KDE software.</para>");
2307 actionCollection()->action(KStandardAction::name(KStandardAction::ReportBug
))
2308 ->setWhatsThis(whatsThisReportBug
);
2309 m_helpMenu
->action(KHelpMenu::menuReportBug
)->setWhatsThis(whatsThisReportBug
2310 + xi18nc("@info:whatsthis second half of reportbug text with link",
2311 "<para>High-quality bug reports are much appreciated. To learn "
2312 "how to make your bug report as effective as possible "
2313 "<link url='https://community.kde.org/Get_Involved/Bug_Reporting'>"
2314 "click here</link>.</para>"));
2316 const QString whatsThisDonate
= xi18nc("@info:whatsthis","<para>This opens a "
2317 "<emphasis>web page</emphasis> where you can donate to "
2318 "support the continued work on this application and many "
2319 "other projects by the <emphasis>KDE</emphasis> community.</para>"
2320 "<para>Donating is the easiest and fastest way to efficiently "
2321 "support KDE and its projects. KDE projects are available for "
2322 "free therefore your donation is needed to cover things that "
2323 "require money like servers, contributor meetings, etc.</para>"
2324 "<para><emphasis>KDE e.V.</emphasis> is the non-profit "
2325 "organization behind the KDE community.</para>");
2326 actionCollection()->action(KStandardAction::name(KStandardAction::Donate
))
2327 ->setWhatsThis(whatsThisDonate
);
2328 m_helpMenu
->action(KHelpMenu::menuDonate
)->setWhatsThis(whatsThisDonate
);
2330 const QString whatsThisSwitchLanguage
= xi18nc("@info:whatsthis",
2331 "With this you can change the language this application uses."
2332 "<nl/>You can even set secondary languages which will be used "
2333 "if texts are not available in your preferred language.");
2334 actionCollection()->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
))
2335 ->setWhatsThis(whatsThisSwitchLanguage
);
2336 m_helpMenu
->action(KHelpMenu::menuSwitchLanguage
)->setWhatsThis(whatsThisSwitchLanguage
);
2338 const QString whatsThisAboutApp
= xi18nc("@info:whatsthis","This opens a "
2339 "window that informs you about the version, license, "
2340 "used libraries and maintainers of this application.");
2341 actionCollection()->action(KStandardAction::name(KStandardAction::AboutApp
))
2342 ->setWhatsThis(whatsThisAboutApp
);
2343 m_helpMenu
->action(KHelpMenu::menuAboutApp
)->setWhatsThis(whatsThisAboutApp
);
2345 const QString whatsThisAboutKDE
= xi18nc("@info:whatsthis","This opens a "
2346 "window with information about <emphasis>KDE</emphasis>. "
2347 "The KDE community are the people behind this free software."
2348 "<nl/>If you like using this application but don't know "
2349 "about KDE or want to see a cute dragon have a look!");
2350 actionCollection()->action(KStandardAction::name(KStandardAction::AboutKDE
))
2351 ->setWhatsThis(whatsThisAboutKDE
);
2352 m_helpMenu
->action(KHelpMenu::menuAboutKDE
)->setWhatsThis(whatsThisAboutKDE
);
2355 bool DolphinMainWindow::event(QEvent
*event
)
2357 if (event
->type() == QEvent::WhatsThisClicked
) {
2359 QWhatsThisClickedEvent
* whatsThisEvent
= dynamic_cast<QWhatsThisClickedEvent
*>(event
);
2360 QDesktopServices::openUrl(QUrl(whatsThisEvent
->href()));
2363 return KXmlGuiWindow::event(event
);
2366 bool DolphinMainWindow::eventFilter(QObject
* obj
, QEvent
* event
)
2369 if (event
->type() == QEvent::WhatsThisClicked
) {
2371 QWhatsThisClickedEvent
* whatsThisEvent
= dynamic_cast<QWhatsThisClickedEvent
*>(event
);
2372 QDesktopServices::openUrl(QUrl(whatsThisEvent
->href()));
2378 void DolphinMainWindow::focusTerminalPanel()
2380 if (m_terminalPanel
->isVisible()) {
2381 if (m_terminalPanel
->terminalHasFocus()) {
2382 m_activeViewContainer
->view()->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2383 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2385 m_terminalPanel
->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2386 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2389 actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger();
2390 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2394 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
2395 KIO::FileUndoManager::UiInterface()
2399 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2403 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
2405 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2407 DolphinViewContainer
* container
= mainWin
->activeViewContainer();
2408 container
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
2410 KIO::FileUndoManager::UiInterface::jobError(job
);
2414 bool DolphinMainWindow::isUrlOpen(const QString
& url
)
2416 return m_tabWidget
->isUrlOpen(QUrl::fromUserInput((url
)));