From 19ff096cd450780f16bfe8f699e76f6dc68fe193 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Tue, 1 May 2018 18:38:54 +0200 Subject: Don't open additional tabs when creating subwindows --- src/browser.cpp | 14 +++++++++----- src/mainwindow/mainwindow.cpp | 17 +++++++++++------ src/mainwindow/mainwindow.h | 5 ++++- src/mainwindow/window.cpp | 9 +++++++++ 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/browser.cpp b/src/browser.cpp index 3f4805a..ddaf345 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -83,16 +83,20 @@ void Browser::createSession(const QString &profileName, bool newWindow, const QS auto *mainwindow = m_windows.last(); if(newWindow) { - QUrl firstUrl = WebProfile::defaultProfile()->homepage(); + QString firstUrl;// = WebProfile::defaultProfile()->homepage(); if(!urls.isEmpty()) - firstUrl = QUrl::fromUserInput(urls.at(0)); + firstUrl = urls.at(0); auto *w = mainwindow->createSubWindow(firstUrl); for(int i = 1; i < urls.count() - 1; i++) { w->addTab(QUrl::fromUserInput(urls.at(i))); } } else { - for(const QString &url : urls) { - mainwindow->createTab(QUrl::fromUserInput(url)); + if(urls.isEmpty()) + mainwindow->createTab(WebProfile::defaultProfile()->homepage()); + else { + for(const QString &url : urls) { + mainwindow->createTab(QUrl::fromUserInput(url)); + } } } } @@ -102,7 +106,7 @@ MainWindow *Browser::createWindow() // the window will delete itself when it closes, so we don't need to delete it MainWindow *window = new MainWindow(m_config); connect(window->addressBar, &AddressBar::complete, m_bookmarks.get(), &BookmarksWidget::search); - window->createSubWindow(WebProfile::defaultProfile()->newtab()); + //window->createSubWindow(WebProfile::defaultProfile()->newtab()); auto *bookmarksAction = new QAction(tr("Bookmarks"), window); bookmarksAction->setShortcut(QKeySequence(QString::fromStdString(m_config->value("bookmarks.shortcut").value()))); diff --git a/src/mainwindow/mainwindow.cpp b/src/mainwindow/mainwindow.cpp index 35cc598..f83c2a7 100644 --- a/src/mainwindow/mainwindow.cpp +++ b/src/mainwindow/mainwindow.cpp @@ -102,7 +102,7 @@ void MainWindow::createMenuBar() auto *smolboteMenu = menuBar()->addMenu(qApp->applicationDisplayName()); smolboteMenu->addAction(tr("New tab group"), this, [this]() { - createSubWindow(QUrl::fromUserInput("about:blank")); + createSubWindow(); }, QKeySequence(m_config->value("mainwindow.shortcuts.newGroup").value().c_str())); smolboteMenu->addAction(tr("New window"))->setEnabled(false); @@ -160,13 +160,18 @@ void MainWindow::createTab(const QUrl &url) { auto *w = qobject_cast(mdiArea->currentSubWindow()); if(w == nullptr) { - w = createSubWindow(url); + w = createSubWindow(url.toString()); } else { w->addTab(url); } } -Window *MainWindow::createSubWindow(const QUrl &url) +Window *MainWindow::currentSubWindow() const +{ + return qobject_cast(mdiArea->currentSubWindow()); +} + +Window *MainWindow::createSubWindow(const QString &url) { auto *w = new Window(m_config->section("window"), this); mdiArea->addSubWindow(w); @@ -176,11 +181,11 @@ Window *MainWindow::createSubWindow(const QUrl &url) QJsonObject session; session.insert("profile", ""); QJsonArray urls; - urls.append(url.toString()); + if(!url.isEmpty()) + urls.append(url); session.insert("tabs", urls); - //w->addTab(url); - //w->restoreSession(session); + w->restoreSession(session); return w; } diff --git a/src/mainwindow/mainwindow.h b/src/mainwindow/mainwindow.h index 489075f..2532189 100644 --- a/src/mainwindow/mainwindow.h +++ b/src/mainwindow/mainwindow.h @@ -11,6 +11,7 @@ #include #include +#include class Browser; class QMdiArea; @@ -40,9 +41,11 @@ public: void addAction(ActionLocation where, QAction *action); void addDockWidget(Qt::DockWidgetArea area, QWidget *widget); + Window *currentSubWindow() const; + public slots: void createTab(const QUrl &url); - Window *createSubWindow(const QUrl &url); + Window *createSubWindow(const QString &url = QString()); void setView(WebView *view); diff --git a/src/mainwindow/window.cpp b/src/mainwindow/window.cpp index fb4eb07..055d945 100644 --- a/src/mainwindow/window.cpp +++ b/src/mainwindow/window.cpp @@ -152,6 +152,15 @@ void Window::restoreSession(const QJsonObject &sessionData) Q_ASSERT_X(sessionData.value("tabs") != QJsonValue::Undefined, "Window::restoreSession", "no tabs in json"); const QJsonArray tabs = sessionData.value("tabs").toArray(); + + if(tabs.count() == 0) { + // open a newtab + auto *view = new WebView(profile, this); + view->load(profile->newtab()); + tabWidget->addTab(view); + return; + } + for(const auto tab : tabs) { auto *view = new WebView(profile, this); view->load(QUrl::fromUserInput(tab.toString())); -- cgit v1.2.1