- // Make sure that a '&' inside the directory name is displayed correctly
- // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
- name.replace('&', QLatin1String("&&"));
+ // 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();
+ }
+ // clang-format on
+
+ // Make sure that a '&' inside the directory name is displayed correctly
+ // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
+ return KStringHandler::rsqueeze(name.replace('&', QLatin1String("&&")), 40 /* default maximum visible folder name visible */);
+}
+
+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();
+ if (i < 0) {
+ return std::nullopt;
+ }
+ // loop over the tabs starting from the current one
+ do {
+ const auto tabPage = tabPageAt(i);
+ if (tabPage->primaryViewContainer()->url() == directory) {
+ return std::optional(ViewIndex{i, true});