diff options
Diffstat (limited to '')
| -rw-r--r-- | src/InputMediator.cpp | 17 | ||||
| -rw-r--r-- | src/completion/TabsAdapter.cpp | 4 | ||||
| -rw-r--r-- | src/completion/TabsModel.cpp | 11 | ||||
| -rw-r--r-- | src/widgets/WebViewStack.cpp | 7 |
4 files changed, 23 insertions, 16 deletions
diff --git a/src/InputMediator.cpp b/src/InputMediator.cpp index ee7a552..6c797a3 100644 --- a/src/InputMediator.cpp +++ b/src/InputMediator.cpp @@ -1,3 +1,4 @@ +#include <QList> #include <QWidget> #include <QtCore> @@ -28,14 +29,17 @@ InputMediator::InputMediator(InputLine *inputLine, WebViewStack *webViewStack, void InputMediator::onInputSubmit(QString input) { hideInputLine(); + // Evaluate input from command if (dynamic_cast<CommandEval *>(currentEvaluationType)) return evaluateCommand(input); + // Evaluate input from url if (auto urlEval = dynamic_cast<UrlEval *>(currentEvaluationType)) return webViewStack->openUrl(input, urlEval->type()); - if (dynamic_cast<BufferEval *>(currentEvaluationType)) - return webViewStack->focusWebView(1); + // Evaluate input from tab list + if (dynamic_cast<TabsEval *>(currentEvaluationType)) + return webViewStack->focusWebView(input.toLong()); } void InputMediator::hideInputLine() { @@ -56,9 +60,10 @@ void InputMediator::showCommandInput(QString cmd) { showInputLine(); } -void InputMediator::showBufferInput(QString url) { - setEvaluationType(new CommandEval()); - inputLine->setAdapter(new TabsAdapter); +void InputMediator::showTabsInput(QString url) { + setEvaluationType(new TabsEval()); + QList<Tab> tabs = webViewStack->getTabList(); + inputLine->setAdapter(new TabsAdapter(tabs)); inputLine->setInputText(url); showInputLine(); } @@ -103,7 +108,7 @@ void InputMediator::evaluateCommand(QString command) { previousWebView(); break; case CommandType::TabSelect: - showBufferInput(); + showTabsInput(); // focusWebView(long index) // TODO: parse index and select break; case CommandType::Noop: diff --git a/src/completion/TabsAdapter.cpp b/src/completion/TabsAdapter.cpp index 4854b7d..d669151 100644 --- a/src/completion/TabsAdapter.cpp +++ b/src/completion/TabsAdapter.cpp @@ -5,9 +5,9 @@ #include "completion/TabsAdapter.hpp" #include "completion/TabsModel.hpp" -TabsAdapter::TabsAdapter() : Adapter() { +TabsAdapter::TabsAdapter(QList<Tab> tabs) : Adapter() { completerInstance = new Completer(); - completerInstance->setSourceModel(new TabsModel(this)); + completerInstance->setSourceModel(new TabsModel(tabs, this)); } Completer *TabsAdapter::completer() { return completerInstance; } diff --git a/src/completion/TabsModel.cpp b/src/completion/TabsModel.cpp index 37eb1dd..6d14b30 100644 --- a/src/completion/TabsModel.cpp +++ b/src/completion/TabsModel.cpp @@ -4,19 +4,14 @@ #include "completion/TabsModel.hpp" -TabsModel::TabsModel(QObject *parent) : QAbstractListModel(parent) { - items = { - {.url = "https://ediblemonad.dev", .title = "EdibleMonad website"}, - {.url = "https://lite.duckduckgo.com", .title = "DDG lite"}, - {.url = "https://github.com/trending", .title = "Github trending"}, - }; -} +TabsModel::TabsModel(QList<Tab> tabs, QObject *parent) + : QAbstractListModel(parent), items(tabs) {} QVariant TabsModel::data(const QModelIndex &index, int role) const { if (!index.isValid() || index.row() >= items.size()) return QVariant(); - const Buffer &item = items.at(index.row()); + const Tab &item = items.at(index.row()); if (role == Qt::DisplayRole) return index.row(); diff --git a/src/widgets/WebViewStack.cpp b/src/widgets/WebViewStack.cpp index 0d1f7fc..b825623 100644 --- a/src/widgets/WebViewStack.cpp +++ b/src/widgets/WebViewStack.cpp @@ -45,6 +45,13 @@ QWebEngineView *WebViewStack::createNewWebView(QUrl url, bool focus) { return webview; } +QList<Tab> WebViewStack::getTabList() { + QList<Tab> urls; + for (auto &view : webViewList) + urls.append((Tab){.url = view->url().toString(), .title = view->title()}); + return urls; +} + void WebViewStack::onNewWebViewRequest(QWebEngineNewWindowRequest &request) { switch (request.destination()) { case QWebEngineNewWindowRequest::InNewTab: |
