]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphintabwidget.cpp
GIT_SILENT made messages (after extraction)
[dolphin.git] / src / dolphintabwidget.cpp
index 5a900701297d9158d44f94f3842b1316be535d07..8f78dc227050507ac8b3fa0353c3216173f4fcee 100644 (file)
@@ -15,6 +15,7 @@
 #include <kio/global.h>
 #include <KIO/CommandLauncherJob>
 #include <KAcceleratorManager>
+#include <KLocalizedString>
 
 #include <QApplication>
 #include <QDropEvent>
@@ -204,19 +205,13 @@ void DolphinTabWidget::openDirectories(const QList<QUrl>& dirs, bool splitView)
     QList<QUrl>::const_iterator it = dirs.constBegin();
     while (it != dirs.constEnd()) {
         const QUrl& primaryUrl = *(it++);
-        const std::optional<ViewIndex> alreadyOpenDirectory = viewOpenAtDirectory(primaryUrl);
+        const std::optional<ViewIndex> viewIndexAtDirectory = viewOpenAtDirectory(primaryUrl);
 
         // When the user asks for a URL that's already open,
         // activate it instead of opening a new tab
-        if (alreadyOpenDirectory.has_value()) {
+        if (viewIndexAtDirectory.has_value()) {
             somethingWasAlreadyOpen = true;
-            activateTab(alreadyOpenDirectory->tabIndex);
-            const auto tabPage = tabPageAt(alreadyOpenDirectory->tabIndex);
-            if (alreadyOpenDirectory->isInPrimaryView) {
-                tabPage->primaryViewContainer()->setActive(true);
-            } else {
-                tabPage->secondaryViewContainer()->setActive(true);
-            }
+            activateViewContainerAt(viewIndexAtDirectory.value());
         } else if (splitView && (it != dirs.constEnd())) {
             const QUrl& secondaryUrl = *(it++);
             if (somethingWasAlreadyOpen) {
@@ -252,14 +247,8 @@ void DolphinTabWidget::openFiles(const QList<QUrl>& files, bool splitView)
         // We also make sure the view will be activated.
         auto viewIndex = viewShowingItem(file);
         if (viewIndex.has_value()) {
-            activateTab(viewIndex->tabIndex);
-            if (viewIndex->isInPrimaryView) {
-                tabPageAt(viewIndex->tabIndex)->primaryViewContainer()->view()->clearSelection();
-                tabPageAt(viewIndex->tabIndex)->primaryViewContainer()->setActive(true);
-            } else {
-                tabPageAt(viewIndex->tabIndex)->secondaryViewContainer()->view()->clearSelection();
-                tabPageAt(viewIndex->tabIndex)->secondaryViewContainer()->setActive(true);
-            }
+            viewContainerAt(viewIndex.value())->view()->clearSelection();
+            activateViewContainerAt(viewIndex.value());
             dirsThatWereAlreadyOpen.append(dir);
         } else {
             dirsThatNeedToBeOpened.append(dir);
@@ -508,12 +497,47 @@ QString DolphinTabWidget::tabName(DolphinTabPage* tabPage) const
     if (!tabPage) {
         return QString();
     }
-    QString name = tabPage->activeViewContainer()->caption();
+
+    QString name;
+    if (tabPage->splitViewEnabled()) {
+        if (tabPage->primaryViewActive()) {
+            // i18n: %1 is the primary view and %2 the secondary view. For left to right languages the primary view is on the left so we also want it to be on the
+            // left in the tab name. In right to left languages the primary view would be on the right so the tab name should match.
+            name = i18nc("@title:tab Active primary view | (Inactive secondary view)", "%1 | (%2)", tabPage->primaryViewContainer()->caption(), tabPage->secondaryViewContainer()->caption());
+        } else {
+            // i18n: %1 is the primary view and %2 the secondary view. For left to right languages the primary view is on the left so we also want it to be on the
+            // left in the tab name. In right to left languages the primary view would be on the right so the tab name should match.
+            name = i18nc("@title:tab (Inactive primary view) | Active secondary view", "(%1) | %2", tabPage->primaryViewContainer()->caption(), tabPage->secondaryViewContainer()->caption());
+        }
+    } else {
+        name = tabPage->activeViewContainer()->caption();
+    }
+
     // Make sure that a '&' inside the directory name is displayed correctly
     // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
     return name.replace('&', QLatin1String("&&"));
 }
 
+DolphinViewContainer *DolphinTabWidget::viewContainerAt(DolphinTabWidget::ViewIndex viewIndex) const
+{
+    const auto tabPage = tabPageAt(viewIndex.tabIndex);
+    if (!tabPage) {
+        return nullptr;
+    }
+    return viewIndex.isInPrimaryView ? tabPage->primaryViewContainer() : tabPage->secondaryViewContainer();
+}
+
+DolphinViewContainer *DolphinTabWidget::activateViewContainerAt(DolphinTabWidget::ViewIndex viewIndex)
+{
+    activateTab(viewIndex.tabIndex);
+    auto viewContainer = viewContainerAt(viewIndex);
+    if (!viewContainer) {
+        return nullptr;
+    }
+    viewContainer->setActive(true);
+    return viewContainer;
+}
+
 const std::optional<const DolphinTabWidget::ViewIndex> DolphinTabWidget::viewOpenAtDirectory(const QUrl& directory) const
 {
     int i = currentIndex();