diff --git a/src/lib/navigation/completer/locationcompletermodel.cpp b/src/lib/navigation/completer/locationcompletermodel.cpp index 88ab9a6fe..869a0f65f 100644 --- a/src/lib/navigation/completer/locationcompletermodel.cpp +++ b/src/lib/navigation/completer/locationcompletermodel.cpp @@ -39,6 +39,7 @@ bool countBiggerThan(const QStandardItem* i1, const QStandardItem* i2) void LocationCompleterModel::refreshCompletions(const QString &string) { if (m_lastCompletion == string) { + refreshTabPositions(); return; } @@ -200,13 +201,21 @@ QSqlQuery LocationCompleterModel::createQuery(const QString &searchString, const TabPosition LocationCompleterModel::tabPositionForUrl(const QUrl& url) const { - for(int win=0; win < mApp->windowCount(); ++win) { - QupZilla* mainWin = mApp->mainWindows().at(win); + return tabPositionForEncodedUrl(url.toEncoded()); +} + +TabPosition LocationCompleterModel::tabPositionForEncodedUrl(const QString& encodedUrl) const +{ + QList windows = mApp->mainWindows(); + int currentWindowIdx = windows.indexOf(mApp->getWindow()); + windows.prepend(mApp->getWindow()); + for(int win=0; win < windows.count(); ++win) { + QupZilla* mainWin = windows.at(win); QList tabs = mainWin->tabWidget()->allTabs(); for(int tab=0; tab < tabs.count(); ++tab) { - if(tabs[tab]->url() == url) { + if(tabs[tab]->url().toEncoded() == encodedUrl) { TabPosition pos; - pos.windowIndex = win; + pos.windowIndex = win == 0 ? currentWindowIdx : win-1; pos.tabIndex = tab; return pos; } @@ -214,3 +223,18 @@ TabPosition LocationCompleterModel::tabPositionForUrl(const QUrl& url) const } return TabPosition(); } + +void LocationCompleterModel::refreshTabPositions() +{ + if (!qzSettings->showSwitchTab) { + return; + } + + for (int row = 0; row < rowCount(); ++row) { + QStandardItem* aItem = item(row); + if (!aItem) { + continue; + } + aItem->setData(QVariant::fromValue(tabPositionForEncodedUrl(aItem->text())), TabPositionRole); + } +} diff --git a/src/lib/navigation/completer/locationcompletermodel.h b/src/lib/navigation/completer/locationcompletermodel.h index d3f046eab..73d497438 100644 --- a/src/lib/navigation/completer/locationcompletermodel.h +++ b/src/lib/navigation/completer/locationcompletermodel.h @@ -62,6 +62,8 @@ private: QSqlQuery createQuery(const QString &searchString, const QString &orderBy, const QList &alreadyFound, int limit, bool bookmarks = false, bool exactMatch = false); TabPosition tabPositionForUrl(const QUrl& url) const; + TabPosition tabPositionForEncodedUrl(const QString& encodedUrl) const; + void refreshTabPositions(); QString m_lastCompletion; }; diff --git a/src/lib/navigation/completer/locationcompleterview.cpp b/src/lib/navigation/completer/locationcompleterview.cpp index d178d20eb..7e8261138 100644 --- a/src/lib/navigation/completer/locationcompleterview.cpp +++ b/src/lib/navigation/completer/locationcompleterview.cpp @@ -23,6 +23,7 @@ #include "history.h" #include "tabwidget.h" #include "qzsettings.h" +#include "tabbedwebview.h" #include #include @@ -75,7 +76,6 @@ bool LocationCompleterView::eventFilter(QObject* object, QEvent* event) TabPosition pos = idx.data(LocationCompleterModel::TabPositionRole).value(); if(pos.windowIndex!= -1) { activateTab(pos); - close(); return true; } } @@ -256,7 +256,6 @@ void LocationCompleterView::mouseReleaseEvent(QMouseEvent* event) if(pos.windowIndex != -1) { event->accept(); activateTab(pos); - close(); } else { QListView::mouseReleaseEvent(event); @@ -269,8 +268,17 @@ void LocationCompleterView::mouseReleaseEvent(QMouseEvent* event) void LocationCompleterView::activateTab(TabPosition pos) { - emit aboutToActivateTab(pos); QupZilla* win = mApp->mainWindows().at(pos.windowIndex); - win->activateWindow(); - win->tabWidget()->setCurrentIndex(pos.tabIndex); + if (mApp->getWindow() != win || mApp->getWindow()->tabWidget()->currentIndex() != pos.tabIndex) { + emit aboutToActivateTab(pos); + close(); + win->tabWidget()->setCurrentIndex(pos.tabIndex); + win->show(); + win->activateWindow(); + win->raise(); + } + else { + close(); + win->weView()->setFocus(); + } } diff --git a/src/lib/preferences/preferences.cpp b/src/lib/preferences/preferences.cpp index 156d6bf3b..9fe1aefba 100644 --- a/src/lib/preferences/preferences.cpp +++ b/src/lib/preferences/preferences.cpp @@ -43,6 +43,7 @@ #include "tabbedwebview.h" #include "clearprivatedata.h" #include "useragentdialog.h" +#include "registerqappassociation.h" #include #include