mirror of
https://invent.kde.org/system/dolphin
synced 2024-10-28 03:21:56 +00:00
Add helper methods to tab widget for view containers
This commit introduces the private getter DolphinTabWidget::viewContainerAt(ViewIndex) and another private method DolphinTabWidget::activateViewContainerAt(ViewIndex). Both methods return nullptr if there is no valid DolphinViewContainer at the specified ViewIndex.
This commit is contained in:
parent
4d81aabd1e
commit
37a98417cd
|
@ -210,13 +210,7 @@ void DolphinTabWidget::openDirectories(const QList<QUrl>& dirs, bool splitView)
|
||||||
// activate it instead of opening a new tab
|
// activate it instead of opening a new tab
|
||||||
if (alreadyOpenDirectory.has_value()) {
|
if (alreadyOpenDirectory.has_value()) {
|
||||||
somethingWasAlreadyOpen = true;
|
somethingWasAlreadyOpen = true;
|
||||||
activateTab(alreadyOpenDirectory->tabIndex);
|
activateViewContainerAt(alreadyOpenDirectory.value());
|
||||||
const auto tabPage = tabPageAt(alreadyOpenDirectory->tabIndex);
|
|
||||||
if (alreadyOpenDirectory->isInPrimaryView) {
|
|
||||||
tabPage->primaryViewContainer()->setActive(true);
|
|
||||||
} else {
|
|
||||||
tabPage->secondaryViewContainer()->setActive(true);
|
|
||||||
}
|
|
||||||
} else if (splitView && (it != dirs.constEnd())) {
|
} else if (splitView && (it != dirs.constEnd())) {
|
||||||
const QUrl& secondaryUrl = *(it++);
|
const QUrl& secondaryUrl = *(it++);
|
||||||
if (somethingWasAlreadyOpen) {
|
if (somethingWasAlreadyOpen) {
|
||||||
|
@ -252,14 +246,8 @@ void DolphinTabWidget::openFiles(const QList<QUrl>& files, bool splitView)
|
||||||
// We also make sure the view will be activated.
|
// We also make sure the view will be activated.
|
||||||
auto viewIndex = viewShowingItem(file);
|
auto viewIndex = viewShowingItem(file);
|
||||||
if (viewIndex.has_value()) {
|
if (viewIndex.has_value()) {
|
||||||
activateTab(viewIndex->tabIndex);
|
viewContainerAt(viewIndex.value())->view()->clearSelection();
|
||||||
if (viewIndex->isInPrimaryView) {
|
activateViewContainerAt(viewIndex.value());
|
||||||
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);
|
|
||||||
}
|
|
||||||
dirsThatWereAlreadyOpen.append(dir);
|
dirsThatWereAlreadyOpen.append(dir);
|
||||||
} else {
|
} else {
|
||||||
dirsThatNeedToBeOpened.append(dir);
|
dirsThatNeedToBeOpened.append(dir);
|
||||||
|
@ -514,6 +502,26 @@ QString DolphinTabWidget::tabName(DolphinTabPage* tabPage) const
|
||||||
return name.replace('&', QLatin1String("&&"));
|
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
|
const std::optional<const DolphinTabWidget::ViewIndex> DolphinTabWidget::viewOpenAtDirectory(const QUrl& directory) const
|
||||||
{
|
{
|
||||||
int i = currentIndex();
|
int i = currentIndex();
|
||||||
|
|
|
@ -226,6 +226,21 @@ private:
|
||||||
const int tabIndex;
|
const int tabIndex;
|
||||||
const bool isInPrimaryView;
|
const bool isInPrimaryView;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for a view container.
|
||||||
|
* @param viewIndex specifies the tab and the view within that tab.
|
||||||
|
* @return the view container specified in @p viewIndex or nullptr if it doesn't exist.
|
||||||
|
*/
|
||||||
|
DolphinViewContainer *viewContainerAt(ViewIndex viewIndex) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Makes the view container specified in @p viewIndex become the active view container within this tab widget.
|
||||||
|
* @param viewIndex Specifies the tab to activate and the view container within the tab to activate.
|
||||||
|
* @return the freshly activated view container or nullptr if there is no view container at @p viewIndex.
|
||||||
|
*/
|
||||||
|
DolphinViewContainer *activateViewContainerAt(ViewIndex viewIndex);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the position of the view within this widget that is open at @p directory.
|
* Get the position of the view within this widget that is open at @p directory.
|
||||||
* @param directory The URL of the directory we want to find.
|
* @param directory The URL of the directory we want to find.
|
||||||
|
|
Loading…
Reference in a new issue