mirror of
https://invent.kde.org/system/dolphin
synced 2024-09-17 15:31:20 +00:00
DolphinTabWidget: cleanup index-by-URL API usage
Summary: Follow-up of D23655 where we didn't have time to polish the code: - add a couple of variables to make the code more clear. - remove the `get` prefix which we usually don't use in Qt code. - make the function private since it's very tied to implementation. - add a new isUrlOpen public method as wrapper. Reviewers: feverfew Subscribers: kfm-devel Tags: #dolphin Differential Revision: https://phabricator.kde.org/D23860
This commit is contained in:
parent
abbb98f57b
commit
ef5732c89b
|
@ -2160,10 +2160,6 @@ void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job* job)
|
||||||
|
|
||||||
bool DolphinMainWindow::isUrlOpen(const QString& url)
|
bool DolphinMainWindow::isUrlOpen(const QString& url)
|
||||||
{
|
{
|
||||||
if (m_tabWidget->getIndexByUrl(QUrl::fromUserInput((url))).first >= 0) {
|
return m_tabWidget->isUrlOpen(QUrl::fromUserInput((url)));
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -130,6 +130,11 @@ void DolphinTabWidget::refreshViews()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool DolphinTabWidget::isUrlOpen(const QUrl &url) const
|
||||||
|
{
|
||||||
|
return indexByUrl(url).first >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
void DolphinTabWidget::openNewActivatedTab()
|
void DolphinTabWidget::openNewActivatedTab()
|
||||||
{
|
{
|
||||||
const DolphinViewContainer* oldActiveViewContainer = currentTabPage()->activeViewContainer();
|
const DolphinViewContainer* oldActiveViewContainer = currentTabPage()->activeViewContainer();
|
||||||
|
@ -187,11 +192,13 @@ void DolphinTabWidget::openDirectories(const QList<QUrl>& dirs, bool splitView)
|
||||||
QList<QUrl>::const_iterator it = dirs.constBegin();
|
QList<QUrl>::const_iterator it = dirs.constBegin();
|
||||||
while (it != dirs.constEnd()) {
|
while (it != dirs.constEnd()) {
|
||||||
const QUrl& primaryUrl = *(it++);
|
const QUrl& primaryUrl = *(it++);
|
||||||
const QPair<int, bool> viewLocation = getIndexByUrl(primaryUrl);
|
const QPair<int, bool> indexInfo = indexByUrl(primaryUrl);
|
||||||
if (viewLocation.first >= 0) {
|
const int index = indexInfo.first;
|
||||||
setCurrentIndex(viewLocation.first);
|
const bool isInPrimaryView = indexInfo.second;
|
||||||
const auto tabPage = tabPageAt(viewLocation.first);
|
if (index >= 0) {
|
||||||
if (viewLocation.second) {
|
setCurrentIndex(index);
|
||||||
|
const auto tabPage = tabPageAt(index);
|
||||||
|
if (isInPrimaryView) {
|
||||||
tabPage->primaryViewContainer()->setActive(true);
|
tabPage->primaryViewContainer()->setActive(true);
|
||||||
} else {
|
} else {
|
||||||
tabPage->secondaryViewContainer()->setActive(true);
|
tabPage->secondaryViewContainer()->setActive(true);
|
||||||
|
@ -400,7 +407,7 @@ QString DolphinTabWidget::tabName(DolphinTabPage* tabPage) const
|
||||||
return name.replace('&', QLatin1String("&&"));
|
return name.replace('&', QLatin1String("&&"));
|
||||||
}
|
}
|
||||||
|
|
||||||
QPair<int, bool> DolphinTabWidget::getIndexByUrl(const QUrl& url) const
|
QPair<int, bool> DolphinTabWidget::indexByUrl(const QUrl& url) const
|
||||||
{
|
{
|
||||||
for (int i = 0; i < count(); i++) {
|
for (int i = 0; i < count(); i++) {
|
||||||
const auto tabPage = tabPageAt(i);
|
const auto tabPage = tabPageAt(i);
|
||||||
|
|
|
@ -79,14 +79,10 @@ public:
|
||||||
void refreshViews();
|
void refreshViews();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param url The URL that we would like
|
* @return Whether any of the tab pages contains @p url in their primary
|
||||||
* @return a QPair with first containing the index of the tab with the
|
* or secondary view.
|
||||||
* desired URL or -1 if not found. Second says true if URL is in primary
|
|
||||||
* view container, false otherwise. False means the URL is in the secondary
|
|
||||||
* view container, unless first == -1. In that case the value of second
|
|
||||||
* is meaningless.
|
|
||||||
*/
|
*/
|
||||||
QPair<int, bool> getIndexByUrl(const QUrl& url) const;
|
bool isUrlOpen(const QUrl& url) const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
/**
|
/**
|
||||||
|
@ -221,6 +217,16 @@ private:
|
||||||
*/
|
*/
|
||||||
QString tabName(DolphinTabPage* tabPage) const;
|
QString tabName(DolphinTabPage* tabPage) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param url The URL that we would like
|
||||||
|
* @return a QPair with first containing the index of the tab with the
|
||||||
|
* desired URL or -1 if not found. Second says true if URL is in primary
|
||||||
|
* view container, false otherwise. False means the URL is in the secondary
|
||||||
|
* view container, unless first == -1. In that case the value of second
|
||||||
|
* is meaningless.
|
||||||
|
*/
|
||||||
|
QPair<int, bool> indexByUrl(const QUrl& url) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** Caches the (negated) places panel visibility */
|
/** Caches the (negated) places panel visibility */
|
||||||
bool m_placesSelectorVisible;
|
bool m_placesSelectorVisible;
|
||||||
|
|
Loading…
Reference in a new issue