]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinmainwindow.cpp
Fix Refresh tooltip text and add Refresh whatsThis text
[dolphin.git] / src / dolphinmainwindow.cpp
index 4740b66e9d4690b6127ad2c3e177540a2b9971e7..219c9eb56f16c398d46a3d7cc4cf3c61fe354456 100644 (file)
@@ -88,6 +88,8 @@
 #include <QTimer>
 #include <QToolButton>
 
+#include <algorithm>
+
 namespace
 {
 // Used for GeneralSettings::version() to determine whether
@@ -265,6 +267,11 @@ bool DolphinMainWindow::isInformationPanelEnabled() const
 #endif
 }
 
+bool DolphinMainWindow::isSplitViewEnabledInCurrentTab() const
+{
+    return m_tabWidget->currentTabPage()->splitViewEnabled();
+}
+
 void DolphinMainWindow::openFiles(const QStringList &files, bool splitView)
 {
     openFiles(QUrl::fromStringList(files), splitView);
@@ -499,17 +506,33 @@ void DolphinMainWindow::openInNewWindow()
 
 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::statDetails(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)
@@ -1423,7 +1446,7 @@ void DolphinMainWindow::activeViewChanged(DolphinViewContainer *viewContainer)
         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);
@@ -1469,7 +1492,7 @@ void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString &mo
         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
@@ -1484,7 +1507,7 @@ void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString &mo
         setViewsToHomeIfMountPathOpen(mountPath);
     });
 
-    if (m_terminalPanel && m_terminalPanel->currentWorkingDirectory().startsWith(mountPath)) {
+    if (m_terminalPanel && m_terminalPanel->currentWorkingDirectoryIsChildOf(mountPath)) {
         m_tearDownFromPlacesRequested = false;
         m_terminalPanel->goHome();
     }
@@ -1606,8 +1629,8 @@ void DolphinMainWindow::setupActions()
                         + 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."));
@@ -1617,8 +1640,8 @@ void DolphinMainWindow::setupActions()
     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."));
@@ -1687,6 +1710,7 @@ void DolphinMainWindow::setupActions()
         "</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
@@ -1742,7 +1766,14 @@ void DolphinMainWindow::setupActions()
     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"));
@@ -2277,18 +2308,24 @@ void DolphinMainWindow::updateFileAndEditActions()
         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);