mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-27 21:21:50 +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] {
|
||||
new_tab("about:blank", Activate::Yes);
|
||||
new_tab(s_settings->new_tab_page(), Activate::Yes);
|
||||
});
|
||||
QObject::connect(settings_action, &QAction::triggered, this, [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(close_current_tab_action, &QAction::triggered, this, &BrowserWindow::close_current_tab);
|
||||
|
||||
// We need to load *something* to make the JS console usable.
|
||||
new_tab("about:blank", Activate::Yes);
|
||||
new_tab(s_settings->new_tab_page(), Activate::Yes);
|
||||
|
||||
setCentralWidget(m_tabs_container);
|
||||
}
|
||||
|
@ -8,9 +8,9 @@
|
||||
|
||||
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()
|
||||
@ -23,4 +23,14 @@ void Settings::set_homepage(QString const& 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 {
|
||||
|
||||
class Settings {
|
||||
class Settings : public QObject {
|
||||
public:
|
||||
Settings(QObject* parent);
|
||||
Settings();
|
||||
|
||||
QString homepage();
|
||||
void set_homepage(QString const& homepage);
|
||||
|
||||
QString new_tab_page();
|
||||
void set_new_tab_page(QString const& page);
|
||||
|
||||
private:
|
||||
QSettings* m_qsettings;
|
||||
};
|
||||
|
@ -16,9 +16,11 @@ SettingsDialog::SettingsDialog(QMainWindow* window)
|
||||
{
|
||||
m_layout = new QFormLayout(this);
|
||||
m_homepage = new QLineEdit(this);
|
||||
m_new_tab_page = new QLineEdit(this);
|
||||
m_ok_button = new QPushButton("&Save", this);
|
||||
|
||||
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_homepage->setText(s_settings->homepage());
|
||||
@ -44,4 +46,5 @@ void SettingsDialog::save()
|
||||
{
|
||||
// FIXME: Validate data.
|
||||
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;
|
||||
QPushButton* m_ok_button { nullptr };
|
||||
QLineEdit* m_homepage { nullptr };
|
||||
QLineEdit* m_new_tab_page { nullptr };
|
||||
QMainWindow* m_window { nullptr };
|
||||
};
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "Settings.h"
|
||||
#include "Utilities.h"
|
||||
#include "WebContentView.h"
|
||||
#include <AK/OwnPtr.h>
|
||||
#include <Browser/CookieJar.h>
|
||||
#include <Browser/Database.h>
|
||||
#include <LibCore/ArgsParser.h>
|
||||
@ -21,7 +22,7 @@
|
||||
#include <LibSQL/SQLClient.h>
|
||||
#include <QApplication>
|
||||
|
||||
Browser::Settings* s_settings;
|
||||
AK::OwnPtr<Browser::Settings> s_settings;
|
||||
|
||||
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));
|
||||
|
||||
s_settings = adopt_own_if_nonnull(new Browser::Settings());
|
||||
BrowserWindow window(cookie_jar, webdriver_content_ipc_path);
|
||||
s_settings = new Browser::Settings(&window);
|
||||
window.setWindowTitle("Ladybird");
|
||||
window.resize(800, 600);
|
||||
window.show();
|
||||
|
Loading…
Reference in New Issue
Block a user