1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:17:45 +00:00

LibGUI+Applications: Add --open-tab option to FooSettings applications

Similar to SystemMonitor's option of the same name, this allows you to
launch the given application with the specific tab open.
This commit is contained in:
Sam Atkins 2022-04-21 15:34:53 +01:00 committed by Linus Groh
parent ded5ba1f87
commit 5702f016f0
9 changed files with 67 additions and 0 deletions

View file

@ -7,6 +7,7 @@
#include "BrowserSettingsWidget.h"
#include "ContentFilterSettingsWidget.h"
#include <LibConfig/Client.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/System.h>
#include <LibGUI/Application.h>
#include <LibGUI/Icon.h>
@ -19,6 +20,11 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto app = TRY(GUI::Application::try_create(arguments));
Config::pledge_domain("Browser");
StringView selected_tab;
Core::ArgsParser args_parser;
args_parser.add_option(selected_tab, "Tab, one of 'browser' or 'content-filtering'", "open-tab", 't', "tab");
args_parser.parse(arguments);
TRY(Core::System::unveil("/res", "r"));
TRY(Core::System::unveil("/home", "r"));
TRY(Core::System::unveil("/home/anon/.config/BrowserContentFilters.txt", "rwc"));
@ -30,6 +36,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
window->set_icon(app_icon.bitmap_for_size(16));
(void)TRY(window->add_tab<BrowserSettingsWidget>("Browser", "browser"));
(void)TRY(window->add_tab<ContentFilterSettingsWidget>("Content Filtering", "content-filtering"));
window->set_active_tab(selected_tab);
window->show();
return app->exec();

View file

@ -7,6 +7,7 @@
#include "ClockSettingsWidget.h"
#include "TimeZoneSettingsWidget.h"
#include <LibConfig/Client.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/System.h>
#include <LibGUI/Application.h>
#include <LibGUI/Icon.h>
@ -20,6 +21,12 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto app = TRY(GUI::Application::try_create(arguments));
Config::pledge_domain("Taskbar");
StringView selected_tab;
Core::ArgsParser args_parser;
args_parser.add_option(selected_tab, "Tab, one of 'clock' or 'time-zone'", "open-tab", 't', "tab");
args_parser.parse(arguments);
TRY(Core::System::pledge("stdio rpath recvfd sendfd proc exec"));
TRY(Core::System::unveil("/res", "r"));
TRY(Core::System::unveil("/bin/timezone", "x"));
@ -33,6 +40,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
(void)TRY(window->add_tab<TimeZoneSettingsWidget>("Time Zone", "time-zone"));
window->set_icon(app_icon.bitmap_for_size(16));
window->resize(540, 570);
window->set_active_tab(selected_tab);
window->show();
return app->exec();

View file

@ -12,6 +12,7 @@
#include "MonitorSettingsWidget.h"
#include "ThemesSettingsWidget.h"
#include <LibConfig/Client.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/System.h>
#include <LibGUI/Application.h>
#include <LibGUI/Icon.h>
@ -25,6 +26,11 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto app = TRY(GUI::Application::try_create(arguments));
Config::pledge_domain("WindowManager");
StringView selected_tab;
Core::ArgsParser args_parser;
args_parser.add_option(selected_tab, "Tab, one of 'background', 'fonts', 'monitor', 'themes', or 'workspaces'", "open-tab", 't', "tab");
args_parser.parse(arguments);
auto app_icon = GUI::Icon::default_icon("app-display-settings");
bool background_settings_changed = false;
@ -35,6 +41,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
(void)TRY(window->add_tab<DisplaySettings::FontSettingsWidget>("Fonts", "fonts"));
(void)TRY(window->add_tab<DisplaySettings::MonitorSettingsWidget>("Monitor", "monitor"));
(void)TRY(window->add_tab<DisplaySettings::DesktopSettingsWidget>("Workspaces", "workspaces"));
window->set_active_tab(selected_tab);
window->set_icon(app_icon.bitmap_for_size(16));

View file

@ -6,6 +6,7 @@
*/
#include "KeyboardSettingsWidget.h"
#include <LibCore/ArgsParser.h>
#include <LibCore/System.h>
#include <LibGUI/Application.h>
#include <LibGUI/SettingsWindow.h>
@ -20,6 +21,11 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto app = TRY(GUI::Application::try_create(arguments));
Config::pledge_domain("KeyboardSettings");
StringView selected_tab;
Core::ArgsParser args_parser;
args_parser.add_option(selected_tab, "Tab, only option is 'keyboard'", "open-tab", 't', "tab");
args_parser.parse(arguments);
TRY(Core::System::pledge("stdio rpath recvfd sendfd proc exec"));
TRY(Core::System::unveil("/res", "r"));
TRY(Core::System::unveil("/bin/keymap", "x"));
@ -32,6 +38,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto window = TRY(GUI::SettingsWindow::create("Keyboard Settings"));
window->set_icon(app_icon.bitmap_for_size(16));
auto keyboard_settings_widget = TRY(window->add_tab<KeyboardSettingsWidget>("Keyboard", "keyboard"));
window->set_active_tab(selected_tab);
window->on_active_window_change = [&](bool is_active_window) {
keyboard_settings_widget->window_activated(is_active_window);

View file

@ -7,6 +7,7 @@
#include "MailSettingsWidget.h"
#include <LibConfig/Client.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/System.h>
#include <LibGUI/Application.h>
#include <LibGUI/Icon.h>
@ -21,6 +22,11 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
Config::pledge_domain("Mail");
StringView selected_tab;
Core::ArgsParser args_parser;
args_parser.add_option(selected_tab, "Tab, only option is 'mail'", "open-tab", 't', "tab");
args_parser.parse(arguments);
TRY(Core::System::pledge("stdio rpath recvfd sendfd"));
TRY(Core::System::unveil("/res", "r"));
TRY(Core::System::unveil(nullptr, nullptr));
@ -30,6 +36,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto window = TRY(GUI::SettingsWindow::create("Mail Settings", GUI::SettingsWindow::ShowDefaultsButton::Yes));
(void)TRY(window->add_tab<MailSettingsWidget>("Mail", "mail"));
window->set_icon(app_icon.bitmap_for_size(16));
window->set_active_tab(selected_tab);
window->show();
return app->exec();

View file

@ -9,6 +9,7 @@
#include "MouseWidget.h"
#include "ThemeWidget.h"
#include <LibCore/ArgsParser.h>
#include <LibCore/System.h>
#include <LibGUI/Application.h>
#include <LibGUI/Icon.h>
@ -23,12 +24,18 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
TRY(Core::System::pledge("stdio cpath rpath recvfd sendfd"));
StringView selected_tab;
Core::ArgsParser args_parser;
args_parser.add_option(selected_tab, "Tab, one of 'cursor-theme' or 'mouse'", "open-tab", 't', "tab");
args_parser.parse(arguments);
auto app_icon = GUI::Icon::default_icon("app-mouse");
auto window = TRY(GUI::SettingsWindow::create("Mouse Settings", GUI::SettingsWindow::ShowDefaultsButton::Yes));
(void)TRY(window->add_tab<MouseWidget>("Mouse", "mouse"));
(void)TRY(window->add_tab<ThemeWidget>("Cursor Theme", "cursor-theme"));
window->set_icon(app_icon.bitmap_for_size(16));
window->set_active_tab(selected_tab);
window->show();
return app->exec();

View file

@ -5,6 +5,7 @@
*/
#include "TerminalSettingsWidget.h"
#include <LibCore/ArgsParser.h>
#include <LibCore/System.h>
#include <LibGUI/Application.h>
#include <LibGUI/ConnectionToWindowServer.h>
@ -20,6 +21,11 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto app = TRY(GUI::Application::try_create(arguments));
Config::pledge_domain("Terminal");
StringView selected_tab;
Core::ArgsParser args_parser;
args_parser.add_option(selected_tab, "Tab, one of 'terminal' or 'view'", "open-tab", 't', "tab");
args_parser.parse(arguments);
TRY(Core::System::pledge("stdio rpath recvfd sendfd"));
TRY(Core::System::unveil("/res", "r"));
TRY(Core::System::unveil(nullptr, nullptr));
@ -30,6 +36,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
window->set_icon(app_icon.bitmap_for_size(16));
(void)TRY(window->add_tab<TerminalSettingsMainWidget>("Terminal", "terminal"));
(void)TRY(window->add_tab<TerminalSettingsViewWidget>("View", "view"));
window->set_active_tab(selected_tab);
window->show();
return app->exec();

View file

@ -76,4 +76,18 @@ ErrorOr<NonnullRefPtr<SettingsWindow>> SettingsWindow::create(String title, Show
return window;
}
Optional<NonnullRefPtr<SettingsWindow::Tab>> SettingsWindow::get_tab(StringView id) const
{
auto tab = m_tabs.find(id);
if (tab == m_tabs.end())
return {};
return tab->value;
}
void SettingsWindow::set_active_tab(StringView id)
{
if (auto tab = get_tab(id); tab.has_value())
m_tab_widget->set_active_widget(tab.value());
}
}

View file

@ -42,6 +42,9 @@ public:
return tab;
}
Optional<NonnullRefPtr<Tab>> get_tab(StringView id) const;
void set_active_tab(StringView id);
private:
SettingsWindow() = default;