#include <KDualAction>
#include <KFileItemListProperties>
#include <KIO/CommandLauncherJob>
-#include <kio_version.h>
-#if KIO_VERSION >= QT_VERSION_CHECK(5, 98, 0)
#include <KIO/JobUiDelegateFactory>
-#else
-#include <KIO/JobUiDelegate>
-#endif
#include <KIO/OpenFileManagerWindowJob>
#include <KIO/OpenUrlJob>
#include <KJobWidgets>
#include <KShell>
#include <KShortcutsDialog>
#include <KStandardAction>
-#include <KStartupInfo>
#include <KSycoca>
#include <KTerminalLauncherJob>
#include <KToggleAction>
#include <KWindowSystem>
#include <KXMLGUIFactory>
-#include <kio_version.h>
#include <kwidgetsaddons_version.h>
#include <QApplication>
#include <QTimer>
#include <QToolButton>
+#include <algorithm>
+
+#if HAVE_X11
+#include <KStartupInfo>
+#endif
+
namespace
{
// Used for GeneralSettings::version() to determine whether
connect(m_actionHandler, &DolphinViewActionHandler::createDirectoryTriggered, this, &DolphinMainWindow::createDirectory);
connect(m_actionHandler, &DolphinViewActionHandler::selectionModeChangeTriggered, this, &DolphinMainWindow::slotSetSelectionMode);
+ Q_CHECK_PTR(actionCollection()->action(QStringLiteral("create_dir")));
+ m_newFileMenu->setNewFolderShortcutAction(actionCollection()->action(QStringLiteral("create_dir")));
+
m_remoteEncoding = new DolphinRemoteEncoding(this, m_actionHandler);
connect(this, &DolphinMainWindow::urlChanged, m_remoteEncoding, &DolphinRemoteEncoding::slotAboutToOpenUrl);
#endif
}
+bool DolphinMainWindow::isSplitViewEnabledInCurrentTab() const
+{
+ return m_tabWidget->currentTabPage()->splitViewEnabled();
+}
+
void DolphinMainWindow::openFiles(const QStringList &files, bool splitView)
{
openFiles(QUrl::fromStringList(files), splitView);
if (KWindowSystem::isPlatformWayland()) {
KWindowSystem::setCurrentXdgActivationToken(activationToken);
- } else {
+ } else if (KWindowSystem::isPlatformX11()) {
+#if HAVE_X11
KStartupInfo::setNewStartupId(window()->windowHandle(), activationToken.toUtf8());
+#endif
}
KWindowSystem::activateWindow(window()->windowHandle());
void DolphinMainWindow::showTarget()
{
- const auto link = m_activeViewContainer->view()->selectedItems().at(0);
- const auto linkLocationDir = QFileInfo(link.localPath()).absoluteDir();
- auto linkDestination = link.linkDest();
- if (QFileInfo(linkDestination).isRelative()) {
- linkDestination = linkLocationDir.filePath(linkDestination);
- }
- if (QFileInfo::exists(linkDestination)) {
- KIO::highlightInFileManager({QUrl::fromLocalFile(linkDestination).adjusted(QUrl::StripTrailingSlash)});
- } else {
- m_activeViewContainer->showMessage(xi18nc("@info", "Could not access <filename>%1</filename>.", linkDestination), DolphinViewContainer::Warning);
+ const KFileItem link = m_activeViewContainer->view()->selectedItems().at(0);
+ const QUrl destinationUrl = link.url().resolved(QUrl(link.linkDest()));
+
+ auto job = KIO::stat(destinationUrl, KIO::StatJob::SourceSide, KIO::StatNoDetails);
+
+ connect(job, &KJob::finished, this, [this, destinationUrl](KJob *job) {
+ KIO::StatJob *statJob = static_cast<KIO::StatJob *>(job);
+
+ if (statJob->error()) {
+ m_activeViewContainer->showMessage(job->errorString(), DolphinViewContainer::Error);
+ } else {
+ KIO::highlightInFileManager({destinationUrl});
+ }
+ });
+}
+
+bool DolphinMainWindow::event(QEvent *event)
+{
+ if (event->type() == QEvent::ShortcutOverride) {
+ const QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
+ if (keyEvent->key() == Qt::Key_Space && m_activeViewContainer->view()->handleSpaceAsNormalKey()) {
+ event->accept();
+ return true;
+ }
}
+
+ return KXmlGuiWindow::event(event);
}
void DolphinMainWindow::showEvent(QShowEvent *event)
void DolphinMainWindow::updateNewMenu()
{
m_newFileMenu->checkUpToDate();
-#if KIO_VERSION >= QT_VERSION_CHECK(5, 97, 0)
m_newFileMenu->setWorkingDirectory(activeViewContainer()->url());
-#else
- m_newFileMenu->setPopupFiles(QList<QUrl>() << activeViewContainer()->url());
-#endif
}
void DolphinMainWindow::createDirectory()
{
-#if KIO_VERSION >= QT_VERSION_CHECK(5, 97, 0)
m_newFileMenu->setWorkingDirectory(activeViewContainer()->url());
-#else
- m_newFileMenu->setPopupFiles(QList<QUrl>() << activeViewContainer()->url());
-#endif
m_newFileMenu->createDirectory();
}
activeViewContainer()->setUrl(url);
} else {
m_lastHandleUrlOpenJob = new KIO::OpenUrlJob(url);
-#if KIO_VERSION >= QT_VERSION_CHECK(5, 98, 0)
m_lastHandleUrlOpenJob->setUiDelegate(KIO::createDefaultJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, this));
-#else
- m_lastHandleUrlOpenJob->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, this));
-#endif
m_lastHandleUrlOpenJob->setShowOpenOrExecuteDialog(true);
connect(m_lastHandleUrlOpenJob, &KIO::OpenUrlJob::mimeTypeFound, this, [this, url](const QString &mimetype) {
connect(oldViewContainer->view(), &DolphinView::requestItemInfo, this, &DolphinMainWindow::requestItemInfo);
// Disconnect other slots.
- disconnect(nullptr,
+ disconnect(oldViewContainer,
&DolphinViewContainer::selectionModeChanged,
actionCollection()->action(QStringLiteral("toggle_selection_mode")),
&QAction::setChecked);
setViewsToHomeIfMountPathOpen(mountPath);
});
- if (m_terminalPanel && m_terminalPanel->currentWorkingDirectory().startsWith(mountPath)) {
+ if (m_terminalPanel && m_terminalPanel->currentWorkingDirectoryIsChildOf(mountPath)) {
m_tearDownFromPlacesRequested = true;
m_terminalPanel->goHome();
// m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged
setViewsToHomeIfMountPathOpen(mountPath);
});
- if (m_terminalPanel && m_terminalPanel->currentWorkingDirectory().startsWith(mountPath)) {
+ if (m_terminalPanel && m_terminalPanel->currentWorkingDirectoryIsChildOf(mountPath)) {
m_tearDownFromPlacesRequested = false;
m_terminalPanel->goHome();
}
auto hamburgerMenuAction = KStandardAction::hamburgerMenu(nullptr, nullptr, actionCollection());
// setup 'File' menu
- m_newFileMenu = new DolphinNewFileMenu(actionCollection(), this);
+ m_newFileMenu = new DolphinNewFileMenu(nullptr, this);
+ actionCollection()->addAction(QStringLiteral("new_menu"), m_newFileMenu);
QMenu *menu = m_newFileMenu->menu();
menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
menu->setIcon(QIcon::fromTheme(QStringLiteral("list-add")));
+ cutCopyPastePara);
QAction *copyToOtherViewAction = actionCollection()->addAction(QStringLiteral("copy_to_inactive_split_view"));
- copyToOtherViewAction->setText(i18nc("@action:inmenu", "Copy to Inactive Split View"));
- m_actionTextHelper->registerTextWhenNothingIsSelected(copyToOtherViewAction, i18nc("@action:inmenu", "Copy to Inactive Split View…"));
+ copyToOtherViewAction->setText(i18nc("@action:inmenu", "Copy to Other View"));
+ m_actionTextHelper->registerTextWhenNothingIsSelected(copyToOtherViewAction, i18nc("@action:inmenu", "Copy to Other View…"));
copyToOtherViewAction->setWhatsThis(xi18nc("@info:whatsthis Copy",
"This copies the selected items from "
"the <emphasis>active</emphasis> view to the inactive split view."));
connect(copyToOtherViewAction, &QAction::triggered, this, &DolphinMainWindow::copyToInactiveSplitView);
QAction *moveToOtherViewAction = actionCollection()->addAction(QStringLiteral("move_to_inactive_split_view"));
- moveToOtherViewAction->setText(i18nc("@action:inmenu", "Move to Inactive Split View"));
- m_actionTextHelper->registerTextWhenNothingIsSelected(moveToOtherViewAction, i18nc("@action:inmenu", "Move to Inactive Split View…"));
+ moveToOtherViewAction->setText(i18nc("@action:inmenu", "Move to Other View"));
+ m_actionTextHelper->registerTextWhenNothingIsSelected(moveToOtherViewAction, i18nc("@action:inmenu", "Move to Other View…"));
moveToOtherViewAction->setWhatsThis(xi18nc("@info:whatsthis Move",
"This moves the selected items from "
"the <emphasis>active</emphasis> view to the inactive split view."));
connect(moveToOtherViewAction, &QAction::triggered, this, &DolphinMainWindow::moveToInactiveSplitView);
QAction *showFilterBar = actionCollection()->addAction(QStringLiteral("show_filter_bar"));
- showFilterBar->setText(i18nc("@action:inmenu Tools", "Filter..."));
+ showFilterBar->setText(i18nc("@action:inmenu Tools", "Filter…"));
showFilterBar->setToolTip(i18nc("@info:tooltip", "Show Filter Bar"));
showFilterBar->setWhatsThis(xi18nc("@info:whatsthis",
"This opens the "
connect(toggleFilter, &QAction::triggered, this, &DolphinMainWindow::toggleFilterBar);
QAction *searchAction = KStandardAction::find(this, &DolphinMainWindow::find, actionCollection());
- searchAction->setText(i18n("Search..."));
+ searchAction->setText(i18n("Search…"));
searchAction->setToolTip(i18nc("@info:tooltip", "Search for files and folders"));
searchAction->setWhatsThis(xi18nc("@info:whatsthis find",
"<para>This helps you "
"</para>"));
toggleSelectionModeAction->setIcon(QIcon::fromTheme(QStringLiteral("quickwizard")));
toggleSelectionModeAction->setCheckable(true);
+ actionCollection()->setDefaultShortcut(toggleSelectionModeAction, Qt::Key_Space );
connect(toggleSelectionModeAction, &QAction::triggered, this, &DolphinMainWindow::toggleSelectionMode);
// A special version of the toggleSelectionModeAction for the toolbar that also contains a menu
stashSplit->setVisible(sessionInterface && sessionInterface->isServiceRegistered(QStringLiteral("org.kde.kio.StashNotifier")));
connect(stashSplit, &QAction::triggered, this, &DolphinMainWindow::toggleSplitStash);
- KStandardAction::redisplay(this, &DolphinMainWindow::reloadView, actionCollection());
+ QAction *redisplay = KStandardAction::redisplay(this, &DolphinMainWindow::reloadView, actionCollection());
+ redisplay->setToolTip(i18nc("@info:tooltip", "Refresh view"));
+ redisplay->setWhatsThis(xi18nc("@info:whatsthis refresh",
+ "<para>This refreshes "
+ "the folder view.</para>"
+ "<para>If the contents of this folder have changed, refreshing will re-scan this folder "
+ "and show you a newly-updated view of the files and folders contained here.</para>"
+ "<para>If the view is split, this refreshes the one that is currently in focus.</para>"));
QAction *stop = actionCollection()->addAction(QStringLiteral("stop"));
stop->setText(i18nc("@action:inmenu View", "Stop"));
actionCollection()->addAction(m_backAction->objectName(), m_backAction);
auto backShortcuts = m_backAction->shortcuts();
- backShortcuts.append(QKeySequence(Qt::Key_Backspace));
+ // Prepend this shortcut, to avoid being hidden by the two-slot UI (#371130)
+ backShortcuts.prepend(QKeySequence(Qt::Key_Backspace));
actionCollection()->setDefaultShortcuts(m_backAction, backShortcuts);
DolphinRecentTabsMenu *recentTabsMenu = new DolphinRecentTabsMenu(this);
duplicateAction->setEnabled(capabilitiesSource.supportsWriting());
}
- if (m_tabWidget->currentTabPage()->splitViewEnabled()) {
+ if (m_tabWidget->currentTabPage()->splitViewEnabled() && !list.isEmpty()) {
DolphinTabPage *tabPage = m_tabWidget->currentTabPage();
KFileItem capabilitiesDestination;
if (tabPage->primaryViewActive()) {
- capabilitiesDestination = tabPage->secondaryViewContainer()->url();
+ capabilitiesDestination = tabPage->secondaryViewContainer()->rootItem();
} else {
- capabilitiesDestination = tabPage->primaryViewContainer()->url();
+ capabilitiesDestination = tabPage->primaryViewContainer()->rootItem();
}
- copyToOtherViewAction->setEnabled(capabilitiesDestination.isWritable());
- moveToOtherViewAction->setEnabled((list.isEmpty() || capabilitiesSource.supportsMoving()) && capabilitiesDestination.isWritable());
+ const auto destUrl = capabilitiesDestination.url();
+ const bool allNotTargetOrigin = std::all_of(list.cbegin(), list.cend(), [destUrl](const KFileItem &item) {
+ return item.url().adjusted(QUrl::RemoveFilename | QUrl::StripTrailingSlash) != destUrl;
+ });
+
+ copyToOtherViewAction->setEnabled(capabilitiesDestination.isWritable() && allNotTargetOrigin);
+ moveToOtherViewAction->setEnabled((list.isEmpty() || capabilitiesSource.supportsMoving()) && capabilitiesDestination.isWritable()
+ && allNotTargetOrigin);
} else {
copyToOtherViewAction->setEnabled(false);
moveToOtherViewAction->setEnabled(false);
panelAction->setText(dockAction->text());
panelAction->setIcon(icon);
dockAction->setIcon(icon);
+ dockAction->setEnabled(true);
actionCollection()->setDefaultShortcut(panelAction, shortcut);
connect(panelAction, &QAction::triggered, dockAction, &QAction::trigger);
{
return m_tabWidget->isItemVisibleInAnyView(QUrl::fromUserInput(urlOfItem));
}
+
+#include "moc_dolphinmainwindow.cpp"