aboutsummaryrefslogtreecommitdiff
path: root/src/mainwindow
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-05-01 18:38:54 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2018-05-01 18:38:54 +0200
commit19ff096cd450780f16bfe8f699e76f6dc68fe193 (patch)
tree859a86ab8f3612a4bdef2e9fcf797622ae3d225d /src/mainwindow
parentSplit off addressbar into lib/ (diff)
downloadsmolbote-19ff096cd450780f16bfe8f699e76f6dc68fe193.tar.xz
Don't open additional tabs when creating subwindows
Diffstat (limited to 'src/mainwindow')
-rw-r--r--src/mainwindow/mainwindow.cpp17
-rw-r--r--src/mainwindow/mainwindow.h5
-rw-r--r--src/mainwindow/window.cpp9
3 files changed, 24 insertions, 7 deletions
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<std::string>("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<Window *>(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<Window *>(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 <QMainWindow>
#include <memory>
+#include <QUrl>
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()));