mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-28 13:43:45 +03:00
Ladybird: Add setting for page to open on new tab
This commit is contained in:
parent
80da16e54a
commit
17e9db4fa1
Notes:
sideshowbarker
2024-07-17 05:21:12 +09:00
Author: https://github.com/guerinoni Commit: https://github.com/SerenityOS/serenity/commit/17e9db4fa1 Pull-request: https://github.com/SerenityOS/serenity/pull/17116 Reviewed-by: https://github.com/ADKaster ✅ Reviewed-by: https://github.com/AtkinsSJ
@ -305,7 +305,7 @@ BrowserWindow::BrowserWindow(Browser::CookieJar& cookie_jar, StringView webdrive
|
|||||||
});
|
});
|
||||||
|
|
||||||
QObject::connect(new_tab_action, &QAction::triggered, this, [this] {
|
QObject::connect(new_tab_action, &QAction::triggered, this, [this] {
|
||||||
new_tab("about:blank", Activate::Yes);
|
new_tab(s_settings->new_tab_page(), Activate::Yes);
|
||||||
});
|
});
|
||||||
QObject::connect(settings_action, &QAction::triggered, this, [this] {
|
QObject::connect(settings_action, &QAction::triggered, this, [this] {
|
||||||
new SettingsDialog(this);
|
new SettingsDialog(this);
|
||||||
@ -319,8 +319,7 @@ BrowserWindow::BrowserWindow(Browser::CookieJar& cookie_jar, StringView webdrive
|
|||||||
QObject::connect(m_tabs_container, &QTabWidget::tabCloseRequested, this, &BrowserWindow::close_tab);
|
QObject::connect(m_tabs_container, &QTabWidget::tabCloseRequested, this, &BrowserWindow::close_tab);
|
||||||
QObject::connect(close_current_tab_action, &QAction::triggered, this, &BrowserWindow::close_current_tab);
|
QObject::connect(close_current_tab_action, &QAction::triggered, this, &BrowserWindow::close_current_tab);
|
||||||
|
|
||||||
// We need to load *something* to make the JS console usable.
|
new_tab(s_settings->new_tab_page(), Activate::Yes);
|
||||||
new_tab("about:blank", Activate::Yes);
|
|
||||||
|
|
||||||
setCentralWidget(m_tabs_container);
|
setCentralWidget(m_tabs_container);
|
||||||
}
|
}
|
||||||
|
@ -8,9 +8,9 @@
|
|||||||
|
|
||||||
namespace Browser {
|
namespace Browser {
|
||||||
|
|
||||||
Settings::Settings(QObject* parent)
|
Settings::Settings()
|
||||||
{
|
{
|
||||||
m_qsettings = new QSettings("Serenity", "Ladybird", parent);
|
m_qsettings = new QSettings("Serenity", "Ladybird", this);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Settings::homepage()
|
QString Settings::homepage()
|
||||||
@ -23,4 +23,14 @@ void Settings::set_homepage(QString const& homepage)
|
|||||||
m_qsettings->setValue("homepage", homepage);
|
m_qsettings->setValue("homepage", homepage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString Settings::new_tab_page()
|
||||||
|
{
|
||||||
|
return m_qsettings->value("new_tab_page", "about:blank").toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Settings::set_new_tab_page(QString const& page)
|
||||||
|
{
|
||||||
|
m_qsettings->setValue("new_tab_page", page);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -13,13 +13,16 @@
|
|||||||
|
|
||||||
namespace Browser {
|
namespace Browser {
|
||||||
|
|
||||||
class Settings {
|
class Settings : public QObject {
|
||||||
public:
|
public:
|
||||||
Settings(QObject* parent);
|
Settings();
|
||||||
|
|
||||||
QString homepage();
|
QString homepage();
|
||||||
void set_homepage(QString const& homepage);
|
void set_homepage(QString const& homepage);
|
||||||
|
|
||||||
|
QString new_tab_page();
|
||||||
|
void set_new_tab_page(QString const& page);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QSettings* m_qsettings;
|
QSettings* m_qsettings;
|
||||||
};
|
};
|
||||||
|
@ -16,9 +16,11 @@ SettingsDialog::SettingsDialog(QMainWindow* window)
|
|||||||
{
|
{
|
||||||
m_layout = new QFormLayout(this);
|
m_layout = new QFormLayout(this);
|
||||||
m_homepage = new QLineEdit(this);
|
m_homepage = new QLineEdit(this);
|
||||||
|
m_new_tab_page = new QLineEdit(this);
|
||||||
m_ok_button = new QPushButton("&Save", this);
|
m_ok_button = new QPushButton("&Save", this);
|
||||||
|
|
||||||
m_layout->addRow(new QLabel("HomePage", this), m_homepage);
|
m_layout->addRow(new QLabel("HomePage", this), m_homepage);
|
||||||
|
m_layout->addRow(new QLabel("Page on New Tab", this), m_new_tab_page);
|
||||||
m_layout->addWidget(m_ok_button);
|
m_layout->addWidget(m_ok_button);
|
||||||
|
|
||||||
m_homepage->setText(s_settings->homepage());
|
m_homepage->setText(s_settings->homepage());
|
||||||
@ -44,4 +46,5 @@ void SettingsDialog::save()
|
|||||||
{
|
{
|
||||||
// FIXME: Validate data.
|
// FIXME: Validate data.
|
||||||
s_settings->set_homepage(m_homepage->text());
|
s_settings->set_homepage(m_homepage->text());
|
||||||
|
s_settings->set_new_tab_page(m_new_tab_page->text());
|
||||||
}
|
}
|
||||||
|
@ -25,5 +25,6 @@ private:
|
|||||||
QFormLayout* m_layout;
|
QFormLayout* m_layout;
|
||||||
QPushButton* m_ok_button { nullptr };
|
QPushButton* m_ok_button { nullptr };
|
||||||
QLineEdit* m_homepage { nullptr };
|
QLineEdit* m_homepage { nullptr };
|
||||||
|
QLineEdit* m_new_tab_page { nullptr };
|
||||||
QMainWindow* m_window { nullptr };
|
QMainWindow* m_window { nullptr };
|
||||||
};
|
};
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
#include "Utilities.h"
|
#include "Utilities.h"
|
||||||
#include "WebContentView.h"
|
#include "WebContentView.h"
|
||||||
|
#include <AK/OwnPtr.h>
|
||||||
#include <Browser/CookieJar.h>
|
#include <Browser/CookieJar.h>
|
||||||
#include <Browser/Database.h>
|
#include <Browser/Database.h>
|
||||||
#include <LibCore/ArgsParser.h>
|
#include <LibCore/ArgsParser.h>
|
||||||
@ -21,7 +22,7 @@
|
|||||||
#include <LibSQL/SQLClient.h>
|
#include <LibSQL/SQLClient.h>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
|
||||||
Browser::Settings* s_settings;
|
AK::OwnPtr<Browser::Settings> s_settings;
|
||||||
|
|
||||||
static ErrorOr<void> handle_attached_debugger()
|
static ErrorOr<void> handle_attached_debugger()
|
||||||
{
|
{
|
||||||
@ -106,8 +107,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||||||
|
|
||||||
auto cookie_jar = TRY(Browser::CookieJar::create(*database));
|
auto cookie_jar = TRY(Browser::CookieJar::create(*database));
|
||||||
|
|
||||||
|
s_settings = adopt_own_if_nonnull(new Browser::Settings());
|
||||||
BrowserWindow window(cookie_jar, webdriver_content_ipc_path);
|
BrowserWindow window(cookie_jar, webdriver_content_ipc_path);
|
||||||
s_settings = new Browser::Settings(&window);
|
|
||||||
window.setWindowTitle("Ladybird");
|
window.setWindowTitle("Ladybird");
|
||||||
window.resize(800, 600);
|
window.resize(800, 600);
|
||||||
window.show();
|
window.show();
|
||||||
|
Loading…
Reference in New Issue
Block a user