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/mainwindow/mainwindow.cpp | 17 +++++++++++------ src/mainwindow/mainwindow.h | 5 ++++- src/mainwindow/window.cpp | 9 +++++++++ 3 files changed, 24 insertions(+), 7 deletions(-) (limited to 'src/mainwindow') 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