mirror of
https://github.com/SerenityOS/serenity
synced 2024-09-06 17:06:31 +00:00
LibGUI: Remove Menu::try_add_submenu()
And fall back to the infallible add_submenu().
This commit is contained in:
parent
1525fa3b8f
commit
eec328e2ab
|
@ -395,7 +395,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
window->set_fullscreen(!window->is_fullscreen());
|
||||
}));
|
||||
|
||||
auto& rotation_axis_menu = view_menu.add_submenu("Rotation &Axis"_string);
|
||||
auto rotation_axis_menu = view_menu.add_submenu("Rotation &Axis"_string);
|
||||
auto rotation_x_action = GUI::Action::create_checkable("&X", [&widget](auto&) {
|
||||
widget->toggle_rotate_x();
|
||||
});
|
||||
|
@ -406,14 +406,14 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
widget->toggle_rotate_z();
|
||||
});
|
||||
|
||||
rotation_axis_menu.add_action(*rotation_x_action);
|
||||
rotation_axis_menu.add_action(*rotation_y_action);
|
||||
rotation_axis_menu.add_action(*rotation_z_action);
|
||||
rotation_axis_menu->add_action(*rotation_x_action);
|
||||
rotation_axis_menu->add_action(*rotation_y_action);
|
||||
rotation_axis_menu->add_action(*rotation_z_action);
|
||||
|
||||
rotation_x_action->set_checked(true);
|
||||
rotation_z_action->set_checked(true);
|
||||
|
||||
auto& rotation_speed_menu = view_menu.add_submenu("Rotation &Speed"_string);
|
||||
auto rotation_speed_menu = view_menu.add_submenu("Rotation &Speed"_string);
|
||||
GUI::ActionGroup rotation_speed_actions;
|
||||
rotation_speed_actions.set_exclusive(true);
|
||||
|
||||
|
@ -435,10 +435,10 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
rotation_speed_actions.add_action(*normal_rotation_action);
|
||||
rotation_speed_actions.add_action(*fast_rotation_action);
|
||||
|
||||
rotation_speed_menu.add_action(*no_rotation_action);
|
||||
rotation_speed_menu.add_action(*slow_rotation_action);
|
||||
rotation_speed_menu.add_action(*normal_rotation_action);
|
||||
rotation_speed_menu.add_action(*fast_rotation_action);
|
||||
rotation_speed_menu->add_action(*no_rotation_action);
|
||||
rotation_speed_menu->add_action(*slow_rotation_action);
|
||||
rotation_speed_menu->add_action(*normal_rotation_action);
|
||||
rotation_speed_menu->add_action(*fast_rotation_action);
|
||||
|
||||
normal_rotation_action->set_checked(true);
|
||||
|
||||
|
@ -456,7 +456,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
texture_enabled_action->set_checked(true);
|
||||
texture_menu.add_action(texture_enabled_action);
|
||||
|
||||
auto& wrap_u_menu = texture_menu.add_submenu("Wrap &S"_string);
|
||||
auto wrap_u_menu = texture_menu.add_submenu("Wrap &S"_string);
|
||||
GUI::ActionGroup wrap_s_actions;
|
||||
wrap_s_actions.set_exclusive(true);
|
||||
|
||||
|
@ -474,13 +474,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
wrap_s_actions.add_action(*wrap_u_mirrored_repeat_action);
|
||||
wrap_s_actions.add_action(*wrap_u_clamp_action);
|
||||
|
||||
wrap_u_menu.add_action(*wrap_u_repeat_action);
|
||||
wrap_u_menu.add_action(*wrap_u_mirrored_repeat_action);
|
||||
wrap_u_menu.add_action(*wrap_u_clamp_action);
|
||||
wrap_u_menu->add_action(*wrap_u_repeat_action);
|
||||
wrap_u_menu->add_action(*wrap_u_mirrored_repeat_action);
|
||||
wrap_u_menu->add_action(*wrap_u_clamp_action);
|
||||
|
||||
wrap_u_repeat_action->set_checked(true);
|
||||
|
||||
auto& wrap_t_menu = texture_menu.add_submenu("Wrap &T"_string);
|
||||
auto wrap_t_menu = texture_menu.add_submenu("Wrap &T"_string);
|
||||
GUI::ActionGroup wrap_t_actions;
|
||||
wrap_t_actions.set_exclusive(true);
|
||||
|
||||
|
@ -498,13 +498,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
wrap_t_actions.add_action(*wrap_t_mirrored_repeat_action);
|
||||
wrap_t_actions.add_action(*wrap_t_clamp_action);
|
||||
|
||||
wrap_t_menu.add_action(*wrap_t_repeat_action);
|
||||
wrap_t_menu.add_action(*wrap_t_mirrored_repeat_action);
|
||||
wrap_t_menu.add_action(*wrap_t_clamp_action);
|
||||
wrap_t_menu->add_action(*wrap_t_repeat_action);
|
||||
wrap_t_menu->add_action(*wrap_t_mirrored_repeat_action);
|
||||
wrap_t_menu->add_action(*wrap_t_clamp_action);
|
||||
|
||||
wrap_t_repeat_action->set_checked(true);
|
||||
|
||||
auto& texture_scale_menu = texture_menu.add_submenu("S&cale"_string);
|
||||
auto texture_scale_menu = texture_menu.add_submenu("S&cale"_string);
|
||||
GUI::ActionGroup texture_scale_actions;
|
||||
texture_scale_actions.set_exclusive(true);
|
||||
|
||||
|
@ -534,15 +534,15 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
texture_scale_actions.add_action(*texture_scale_2_action);
|
||||
texture_scale_actions.add_action(*texture_scale_4_action);
|
||||
|
||||
texture_scale_menu.add_action(*texture_scale_025_action);
|
||||
texture_scale_menu.add_action(*texture_scale_05_action);
|
||||
texture_scale_menu.add_action(*texture_scale_1_action);
|
||||
texture_scale_menu.add_action(*texture_scale_2_action);
|
||||
texture_scale_menu.add_action(*texture_scale_4_action);
|
||||
texture_scale_menu->add_action(*texture_scale_025_action);
|
||||
texture_scale_menu->add_action(*texture_scale_05_action);
|
||||
texture_scale_menu->add_action(*texture_scale_1_action);
|
||||
texture_scale_menu->add_action(*texture_scale_2_action);
|
||||
texture_scale_menu->add_action(*texture_scale_4_action);
|
||||
|
||||
texture_scale_1_action->set_checked(true);
|
||||
|
||||
auto& texture_mag_filter_menu = texture_menu.add_submenu("Mag Filter"_string);
|
||||
auto texture_mag_filter_menu = texture_menu.add_submenu("Mag Filter"_string);
|
||||
GUI::ActionGroup texture_mag_filter_actions;
|
||||
texture_mag_filter_actions.set_exclusive(true);
|
||||
|
||||
|
@ -557,8 +557,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
texture_mag_filter_actions.add_action(*texture_mag_filter_nearest_action);
|
||||
texture_mag_filter_actions.add_action(*texture_mag_filter_linear_action);
|
||||
|
||||
texture_mag_filter_menu.add_action(*texture_mag_filter_nearest_action);
|
||||
texture_mag_filter_menu.add_action(*texture_mag_filter_linear_action);
|
||||
texture_mag_filter_menu->add_action(*texture_mag_filter_nearest_action);
|
||||
texture_mag_filter_menu->add_action(*texture_mag_filter_linear_action);
|
||||
|
||||
texture_mag_filter_nearest_action->set_checked(true);
|
||||
|
||||
|
|
|
@ -307,8 +307,8 @@ void BrowserWindow::build_menus()
|
|||
dbgln("Failed to open search-engines file: {}", load_search_engines_result.error());
|
||||
}
|
||||
|
||||
auto& color_scheme_menu = settings_menu.add_submenu("&Color Scheme"_string);
|
||||
color_scheme_menu.set_icon(g_icon_bag.color_chooser);
|
||||
auto color_scheme_menu = settings_menu.add_submenu("&Color Scheme"_string);
|
||||
color_scheme_menu->set_icon(g_icon_bag.color_chooser);
|
||||
{
|
||||
auto current_setting = Web::CSS::preferred_color_scheme_from_string(Config::read_string("Browser"sv, "Preferences"sv, "ColorScheme"sv, Browser::default_color_scheme));
|
||||
m_color_scheme_actions.set_exclusive(true);
|
||||
|
@ -322,7 +322,7 @@ void BrowserWindow::build_menus()
|
|||
this);
|
||||
if (current_setting == preference_value)
|
||||
action->set_checked(true);
|
||||
color_scheme_menu.add_action(action);
|
||||
color_scheme_menu->add_action(action);
|
||||
m_color_scheme_actions.add_action(action);
|
||||
};
|
||||
|
||||
|
@ -398,13 +398,13 @@ void BrowserWindow::build_menus()
|
|||
}));
|
||||
|
||||
m_user_agent_spoof_actions.set_exclusive(true);
|
||||
auto& spoof_user_agent_menu = debug_menu.add_submenu("Spoof &User Agent"_string);
|
||||
auto spoof_user_agent_menu = debug_menu.add_submenu("Spoof &User Agent"_string);
|
||||
m_disable_user_agent_spoofing = GUI::Action::create_checkable("Disabled", [this](auto&) {
|
||||
active_tab().view().debug_request("spoof-user-agent", Web::default_user_agent);
|
||||
});
|
||||
m_disable_user_agent_spoofing->set_status_tip(String::from_utf8(Web::default_user_agent).release_value_but_fixme_should_propagate_errors());
|
||||
spoof_user_agent_menu.add_action(*m_disable_user_agent_spoofing);
|
||||
spoof_user_agent_menu.set_icon(g_icon_bag.spoof);
|
||||
spoof_user_agent_menu->add_action(*m_disable_user_agent_spoofing);
|
||||
spoof_user_agent_menu->set_icon(g_icon_bag.spoof);
|
||||
m_user_agent_spoof_actions.add_action(*m_disable_user_agent_spoofing);
|
||||
m_disable_user_agent_spoofing->set_checked(true);
|
||||
|
||||
|
@ -413,7 +413,7 @@ void BrowserWindow::build_menus()
|
|||
active_tab().view().debug_request("spoof-user-agent", user_agent);
|
||||
});
|
||||
action->set_status_tip(String::from_utf8(user_agent).release_value_but_fixme_should_propagate_errors());
|
||||
spoof_user_agent_menu.add_action(action);
|
||||
spoof_user_agent_menu->add_action(action);
|
||||
m_user_agent_spoof_actions.add_action(action);
|
||||
};
|
||||
add_user_agent("Chrome Linux Desktop", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.128 Safari/537.36"sv);
|
||||
|
@ -432,7 +432,7 @@ void BrowserWindow::build_menus()
|
|||
active_tab().view().debug_request("spoof-user-agent", user_agent.to_deprecated_string());
|
||||
action.set_status_tip(user_agent);
|
||||
});
|
||||
spoof_user_agent_menu.add_action(custom_user_agent);
|
||||
spoof_user_agent_menu->add_action(custom_user_agent);
|
||||
m_user_agent_spoof_actions.add_action(custom_user_agent);
|
||||
|
||||
debug_menu.add_separator();
|
||||
|
@ -468,8 +468,8 @@ void BrowserWindow::build_menus()
|
|||
ErrorOr<void> BrowserWindow::load_search_engines(GUI::Menu& settings_menu)
|
||||
{
|
||||
m_search_engine_actions.set_exclusive(true);
|
||||
auto& search_engine_menu = settings_menu.add_submenu("&Search Engine"_string);
|
||||
search_engine_menu.set_icon(g_icon_bag.find);
|
||||
auto search_engine_menu = settings_menu.add_submenu("&Search Engine"_string);
|
||||
search_engine_menu->set_icon(g_icon_bag.find);
|
||||
bool search_engine_set = false;
|
||||
|
||||
m_disable_search_engine_action = GUI::Action::create_checkable(
|
||||
|
@ -478,7 +478,7 @@ ErrorOr<void> BrowserWindow::load_search_engines(GUI::Menu& settings_menu)
|
|||
Config::write_string("Browser"sv, "Preferences"sv, "SearchEngine"sv, g_search_engine);
|
||||
},
|
||||
this);
|
||||
search_engine_menu.add_action(*m_disable_search_engine_action);
|
||||
search_engine_menu->add_action(*m_disable_search_engine_action);
|
||||
m_search_engine_actions.add_action(*m_disable_search_engine_action);
|
||||
m_disable_search_engine_action->set_checked(true);
|
||||
|
||||
|
@ -502,7 +502,7 @@ ErrorOr<void> BrowserWindow::load_search_engines(GUI::Menu& settings_menu)
|
|||
Config::write_string("Browser"sv, "Preferences"sv, "SearchEngine"sv, g_search_engine);
|
||||
},
|
||||
this);
|
||||
search_engine_menu.add_action(action);
|
||||
search_engine_menu->add_action(action);
|
||||
m_search_engine_actions.add_action(action);
|
||||
|
||||
if (g_search_engine == url_format) {
|
||||
|
@ -532,7 +532,7 @@ ErrorOr<void> BrowserWindow::load_search_engines(GUI::Menu& settings_menu)
|
|||
Config::write_string("Browser"sv, "Preferences"sv, "SearchEngine"sv, g_search_engine);
|
||||
action.set_status_tip(search_engine);
|
||||
});
|
||||
search_engine_menu.add_action(custom_search_engine_action);
|
||||
search_engine_menu->add_action(custom_search_engine_action);
|
||||
m_search_engine_actions.add_action(custom_search_engine_action);
|
||||
|
||||
if (!search_engine_set && !g_search_engine.is_empty()) {
|
||||
|
|
|
@ -362,11 +362,11 @@ bool add_launch_handler_actions_to_menu(RefPtr<GUI::Menu>& menu, DirectoryView c
|
|||
|
||||
if (current_file_launch_handlers.size() > 1) {
|
||||
added_open_menu_items = true;
|
||||
auto& file_open_with_menu = menu->add_submenu("Open with"_string);
|
||||
auto file_open_with_menu = menu->add_submenu("Open with"_string);
|
||||
for (auto& handler : current_file_launch_handlers) {
|
||||
if (handler == default_file_handler)
|
||||
continue;
|
||||
file_open_with_menu.add_action(handler->create_launch_action([&, full_path = move(full_path)](auto& launcher_handler) {
|
||||
file_open_with_menu->add_action(handler->create_launch_action([&, full_path = move(full_path)](auto& launcher_handler) {
|
||||
directory_view.launch(URL::create_with_file_scheme(full_path), launcher_handler);
|
||||
}));
|
||||
}
|
||||
|
@ -1045,7 +1045,7 @@ ErrorOr<int> run_in_windowed_mode(DeprecatedString const& initial_location, Depr
|
|||
show_dotfiles_in_view(show_dotfiles);
|
||||
|
||||
auto view_menu = TRY(window->try_add_menu("&View"_string));
|
||||
auto layout_menu = TRY(view_menu->try_add_submenu("&Layout"_string));
|
||||
auto layout_menu = view_menu->add_submenu("&Layout"_string);
|
||||
TRY(layout_menu->try_add_action(*layout_toolbar_action));
|
||||
TRY(layout_menu->try_add_action(*layout_location_action));
|
||||
TRY(layout_menu->try_add_action(*layout_statusbar_action));
|
||||
|
|
|
@ -776,7 +776,7 @@ ErrorOr<void> MainWidget::initialize_menubar(GUI::Window& window)
|
|||
TRY(go_menu->try_add_action(*m_go_to_glyph_action));
|
||||
|
||||
auto view_menu = TRY(window.try_add_menu("&View"_string));
|
||||
auto layout_menu = TRY(view_menu->try_add_submenu("&Layout"_string));
|
||||
auto layout_menu = view_menu->add_submenu("&Layout"_string);
|
||||
TRY(layout_menu->try_add_action(*m_show_toolbar_action));
|
||||
TRY(layout_menu->try_add_action(*m_show_statusbar_action));
|
||||
TRY(layout_menu->try_add_action(*m_show_metadata_action));
|
||||
|
@ -787,7 +787,7 @@ ErrorOr<void> MainWidget::initialize_menubar(GUI::Window& window)
|
|||
TRY(view_menu->try_add_action(*m_highlight_modifications_action));
|
||||
TRY(view_menu->try_add_action(*m_show_system_emoji_action));
|
||||
view_menu->add_separator();
|
||||
auto scale_menu = TRY(view_menu->try_add_submenu("&Scale"_string));
|
||||
auto scale_menu = view_menu->add_submenu("&Scale"_string);
|
||||
scale_menu->set_icon(g_resources.scale_editor);
|
||||
TRY(scale_menu->try_add_action(*m_scale_five_action));
|
||||
TRY(scale_menu->try_add_action(*m_scale_ten_action));
|
||||
|
|
|
@ -502,7 +502,7 @@ ErrorOr<void> HexEditorWidget::initialize_menubar(GUI::Window& window)
|
|||
m_editor->update();
|
||||
|
||||
m_bytes_per_row_actions.set_exclusive(true);
|
||||
auto bytes_per_row_menu = TRY(view_menu->try_add_submenu("Bytes per &Row"_string));
|
||||
auto bytes_per_row_menu = view_menu->add_submenu("Bytes per &Row"_string);
|
||||
for (int i = 8; i <= 32; i += 8) {
|
||||
auto action = GUI::Action::create_checkable(DeprecatedString::number(i), [this, i](auto&) {
|
||||
m_editor->set_bytes_per_row(i);
|
||||
|
@ -516,7 +516,7 @@ ErrorOr<void> HexEditorWidget::initialize_menubar(GUI::Window& window)
|
|||
}
|
||||
|
||||
m_value_inspector_mode_actions.set_exclusive(true);
|
||||
auto inspector_mode_menu = TRY(view_menu->try_add_submenu("Value Inspector &Mode"_string));
|
||||
auto inspector_mode_menu = view_menu->add_submenu("Value Inspector &Mode"_string);
|
||||
auto little_endian_mode = GUI::Action::create_checkable("&Little Endian", [&](auto& action) {
|
||||
m_value_inspector_little_endian = action.is_checked();
|
||||
update_inspector_values(m_editor->selection_start_offset());
|
||||
|
|
|
@ -346,7 +346,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
TRY(view_menu->try_add_action(zoom_out_action));
|
||||
view_menu->add_separator();
|
||||
|
||||
auto scaling_mode_menu = TRY(view_menu->try_add_submenu("&Scaling Mode"_string));
|
||||
auto scaling_mode_menu = view_menu->add_submenu("&Scaling Mode"_string);
|
||||
scaling_mode_menu->set_icon(TRY(Gfx::Bitmap::load_from_file("/res/icons/16x16/scale.png"sv)));
|
||||
|
||||
auto scaling_mode_group = make<GUI::ActionGroup>();
|
||||
|
|
|
@ -233,7 +233,7 @@ ErrorOr<void> PDFViewerWidget::initialize_menubar(GUI::Window& window)
|
|||
auto view_menu = TRY(window.try_add_menu("&View"_string));
|
||||
TRY(view_menu->try_add_action(*m_toggle_sidebar_action));
|
||||
view_menu->add_separator();
|
||||
auto view_mode_menu = TRY(view_menu->try_add_submenu("View &Mode"_string));
|
||||
auto view_mode_menu = view_menu->add_submenu("View &Mode"_string);
|
||||
TRY(view_mode_menu->try_add_action(*m_page_view_mode_single));
|
||||
TRY(view_mode_menu->try_add_action(*m_page_view_mode_multiple));
|
||||
view_menu->add_separator();
|
||||
|
|
|
@ -223,7 +223,7 @@ ErrorOr<void> MainWidget::initialize_menubar(GUI::Window& window)
|
|||
TRY(file_menu->try_add_action(*m_save_image_action));
|
||||
TRY(file_menu->try_add_action(*m_save_image_as_action));
|
||||
|
||||
m_export_submenu = TRY(file_menu->try_add_submenu("&Export"_string));
|
||||
m_export_submenu = file_menu->add_submenu("&Export"_string);
|
||||
|
||||
TRY(m_export_submenu->try_add_action(
|
||||
GUI::Action::create(
|
||||
|
@ -600,7 +600,7 @@ ErrorOr<void> MainWidget::initialize_menubar(GUI::Window& window)
|
|||
vectorscope_action->set_checked(Config::read_bool("PixelPaint"sv, "Scopes"sv, "ShowVectorscope"sv, false));
|
||||
m_vectorscope_widget->parent_widget()->set_visible(vectorscope_action->is_checked());
|
||||
|
||||
auto scopes_menu = TRY(m_view_menu->try_add_submenu("&Scopes"_string));
|
||||
auto scopes_menu = m_view_menu->add_submenu("&Scopes"_string);
|
||||
TRY(scopes_menu->try_add_action(histogram_action));
|
||||
TRY(scopes_menu->try_add_action(vectorscope_action));
|
||||
|
||||
|
@ -810,7 +810,7 @@ ErrorOr<void> MainWidget::initialize_menubar(GUI::Window& window)
|
|||
};
|
||||
};
|
||||
|
||||
auto mask_submenu = TRY(m_layer_menu->try_add_submenu("&Masks"_string));
|
||||
auto mask_submenu = m_layer_menu->add_submenu("&Masks"_string);
|
||||
|
||||
m_add_mask_action = GUI::Action::create(
|
||||
"Add M&ask", { Mod_Ctrl | Mod_Shift, Key_M }, g_icon_bag.add_mask, create_layer_mask_callback("Add Mask", [&](Layer* active_layer) {
|
||||
|
|
|
@ -461,7 +461,7 @@ ErrorOr<void> MainWidget::initialize_menubar(GUI::Window& window)
|
|||
m_editor->set_ruler_visible(show_ruler);
|
||||
|
||||
auto view_menu = TRY(window.try_add_menu("&View"_string));
|
||||
auto layout_menu = TRY(view_menu->try_add_submenu("&Layout"_string));
|
||||
auto layout_menu = view_menu->add_submenu("&Layout"_string);
|
||||
TRY(layout_menu->try_add_action(*m_layout_toolbar_action));
|
||||
TRY(layout_menu->try_add_action(*m_layout_statusbar_action));
|
||||
TRY(layout_menu->try_add_action(*m_layout_ruler_action));
|
||||
|
@ -481,7 +481,7 @@ ErrorOr<void> MainWidget::initialize_menubar(GUI::Window& window)
|
|||
view_menu->add_separator();
|
||||
|
||||
m_wrapping_mode_actions.set_exclusive(true);
|
||||
auto wrapping_mode_menu = TRY(view_menu->try_add_submenu("&Wrapping Mode"_string));
|
||||
auto wrapping_mode_menu = view_menu->add_submenu("&Wrapping Mode"_string);
|
||||
m_no_wrapping_action = GUI::Action::create_checkable("&No Wrapping", [&](auto&) {
|
||||
m_editor->set_wrapping_mode(GUI::TextEditor::WrappingMode::NoWrap);
|
||||
Config::write_string("TextEditor"sv, "View"sv, "WrappingMode"sv, "None"sv);
|
||||
|
@ -516,7 +516,7 @@ ErrorOr<void> MainWidget::initialize_menubar(GUI::Window& window)
|
|||
}
|
||||
|
||||
m_soft_tab_width_actions.set_exclusive(true);
|
||||
auto soft_tab_width_menu = TRY(view_menu->try_add_submenu("&Tab Width"_string));
|
||||
auto soft_tab_width_menu = view_menu->add_submenu("&Tab Width"_string);
|
||||
m_soft_tab_1_width_action = GUI::Action::create_checkable("1", [&](auto&) {
|
||||
m_editor->set_soft_tab_width(1);
|
||||
});
|
||||
|
@ -594,7 +594,7 @@ ErrorOr<void> MainWidget::initialize_menubar(GUI::Window& window)
|
|||
|
||||
syntax_actions.set_exclusive(true);
|
||||
|
||||
auto syntax_menu = TRY(view_menu->try_add_submenu("&Syntax"_string));
|
||||
auto syntax_menu = view_menu->add_submenu("&Syntax"_string);
|
||||
m_plain_text_highlight = GUI::Action::create_checkable("&Plain Text", [&](auto&) {
|
||||
m_statusbar->set_text(1, "Plain Text"_string);
|
||||
m_editor->set_syntax_highlighter({});
|
||||
|
@ -696,12 +696,12 @@ ErrorOr<void> MainWidget::initialize_menubar(GUI::Window& window)
|
|||
})));
|
||||
TRY(help_menu->try_add_action(GUI::CommonActions::make_about_action("Text Editor", GUI::Icon::default_icon("app-text-editor"sv), &window)));
|
||||
|
||||
auto wrapping_statusbar_menu = TRY(m_line_column_statusbar_menu->try_add_submenu("&Wrapping Mode"_string));
|
||||
auto wrapping_statusbar_menu = m_line_column_statusbar_menu->add_submenu("&Wrapping Mode"_string);
|
||||
TRY(wrapping_statusbar_menu->try_add_action(*m_no_wrapping_action));
|
||||
TRY(wrapping_statusbar_menu->try_add_action(*m_wrap_anywhere_action));
|
||||
TRY(wrapping_statusbar_menu->try_add_action(*m_wrap_at_words_action));
|
||||
|
||||
auto tab_width_statusbar_menu = TRY(m_line_column_statusbar_menu->try_add_submenu("&Tab Width"_string));
|
||||
auto tab_width_statusbar_menu = m_line_column_statusbar_menu->add_submenu("&Tab Width"_string);
|
||||
TRY(tab_width_statusbar_menu->try_add_action(*m_soft_tab_1_width_action));
|
||||
TRY(tab_width_statusbar_menu->try_add_action(*m_soft_tab_2_width_action));
|
||||
TRY(tab_width_statusbar_menu->try_add_action(*m_soft_tab_4_width_action));
|
||||
|
|
|
@ -411,7 +411,7 @@ ErrorOr<void> VideoPlayerWidget::initialize_menubar(GUI::Window& window)
|
|||
auto view_menu = TRY(window.try_add_menu("&View"_string));
|
||||
TRY(view_menu->try_add_action(*m_toggle_fullscreen_action));
|
||||
|
||||
auto sizing_mode_menu = TRY(view_menu->try_add_submenu("&Sizing Mode"_string));
|
||||
auto sizing_mode_menu = view_menu->add_submenu("&Sizing Mode"_string);
|
||||
sizing_mode_menu->set_icon(TRY(Gfx::Bitmap::load_from_file("/res/icons/16x16/fit-image-to-view.png"sv)));
|
||||
|
||||
m_sizing_mode_group = make<GUI::ActionGroup>();
|
||||
|
|
|
@ -415,9 +415,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
|
||||
auto file_menu = TRY(window->try_add_menu("&File"_string));
|
||||
|
||||
auto& export_submenu = file_menu->add_submenu("&Export"_string);
|
||||
auto export_submenu = file_menu->add_submenu("&Export"_string);
|
||||
|
||||
TRY(export_submenu.try_add_action(GUI::Action::create("As &BMP...",
|
||||
TRY(export_submenu->try_add_action(GUI::Action::create("As &BMP...",
|
||||
[&](GUI::Action&) {
|
||||
Optional<DeprecatedString> export_path = GUI::FilePicker::get_save_filepath(window, "untitled", "bmp");
|
||||
if (!export_path.has_value())
|
||||
|
@ -425,7 +425,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
if (auto result = mandelbrot->export_image(export_path.value(), ImageType::BMP); result.is_error())
|
||||
GUI::MessageBox::show_error(window, DeprecatedString::formatted("{}", result.error()));
|
||||
})));
|
||||
TRY(export_submenu.try_add_action(GUI::Action::create("As &PNG...", { Mod_Ctrl | Mod_Shift, Key_S },
|
||||
TRY(export_submenu->try_add_action(GUI::Action::create("As &PNG...", { Mod_Ctrl | Mod_Shift, Key_S },
|
||||
[&](GUI::Action&) {
|
||||
Optional<DeprecatedString> export_path = GUI::FilePicker::get_save_filepath(window, "untitled", "png");
|
||||
if (!export_path.has_value())
|
||||
|
@ -433,7 +433,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
if (auto result = mandelbrot->export_image(export_path.value(), ImageType::PNG); result.is_error())
|
||||
GUI::MessageBox::show_error(window, DeprecatedString::formatted("{}", result.error()));
|
||||
})));
|
||||
TRY(export_submenu.try_add_action(GUI::Action::create("As &QOI...",
|
||||
TRY(export_submenu->try_add_action(GUI::Action::create("As &QOI...",
|
||||
[&](GUI::Action&) {
|
||||
Optional<DeprecatedString> export_path = GUI::FilePicker::get_save_filepath(window, "untitled", "qoi");
|
||||
if (!export_path.has_value())
|
||||
|
@ -442,7 +442,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
GUI::MessageBox::show_error(window, DeprecatedString::formatted("{}", result.error()));
|
||||
})));
|
||||
|
||||
export_submenu.set_icon(TRY(Gfx::Bitmap::load_from_file("/res/icons/16x16/save.png"sv)));
|
||||
export_submenu->set_icon(TRY(Gfx::Bitmap::load_from_file("/res/icons/16x16/save.png"sv)));
|
||||
|
||||
file_menu->add_separator();
|
||||
TRY(file_menu->try_add_action(GUI::CommonActions::make_quit_action([&](auto&) { app->quit(); })));
|
||||
|
|
|
@ -494,15 +494,15 @@ ErrorOr<NonnullRefPtr<GUI::Menu>> HackStudioWidget::create_project_tree_view_con
|
|||
});
|
||||
auto project_tree_view_context_menu = GUI::Menu::construct("Project Files"_string);
|
||||
|
||||
auto& new_file_submenu = project_tree_view_context_menu->add_submenu("N&ew..."_string);
|
||||
auto new_file_submenu = project_tree_view_context_menu->add_submenu("N&ew..."_string);
|
||||
for (auto& new_file_action : m_new_file_actions) {
|
||||
new_file_submenu.add_action(new_file_action);
|
||||
new_file_submenu->add_action(new_file_action);
|
||||
}
|
||||
auto icon = TRY(Gfx::Bitmap::load_from_file("/res/icons/16x16/new.png"sv));
|
||||
new_file_submenu.set_icon(icon);
|
||||
new_file_submenu.add_action(*m_new_plain_file_action);
|
||||
new_file_submenu.add_separator();
|
||||
new_file_submenu.add_action(*m_new_directory_action);
|
||||
new_file_submenu->set_icon(icon);
|
||||
new_file_submenu->add_action(*m_new_plain_file_action);
|
||||
new_file_submenu->add_separator();
|
||||
new_file_submenu->add_action(*m_new_directory_action);
|
||||
|
||||
project_tree_view_context_menu->add_action(*m_open_selected_action);
|
||||
project_tree_view_context_menu->add_action(*m_show_in_file_manager_action);
|
||||
|
@ -1416,23 +1416,23 @@ ErrorOr<void> HackStudioWidget::create_file_menu(GUI::Window& window)
|
|||
{
|
||||
auto& file_menu = window.add_menu("&File"_string);
|
||||
|
||||
auto& new_submenu = file_menu.add_submenu("&New..."_string);
|
||||
new_submenu.add_action(*m_new_project_action);
|
||||
new_submenu.add_separator();
|
||||
auto new_submenu = file_menu.add_submenu("&New..."_string);
|
||||
new_submenu->add_action(*m_new_project_action);
|
||||
new_submenu->add_separator();
|
||||
for (auto& new_file_action : m_new_file_actions) {
|
||||
new_submenu.add_action(new_file_action);
|
||||
new_submenu->add_action(new_file_action);
|
||||
}
|
||||
|
||||
{
|
||||
auto icon = TRY(Gfx::Bitmap::load_from_file("/res/icons/16x16/new.png"sv));
|
||||
new_submenu.set_icon(icon);
|
||||
new_submenu->set_icon(icon);
|
||||
}
|
||||
new_submenu.add_action(*m_new_plain_file_action);
|
||||
new_submenu.add_separator();
|
||||
new_submenu.add_action(*m_new_directory_action);
|
||||
new_submenu->add_action(*m_new_plain_file_action);
|
||||
new_submenu->add_separator();
|
||||
new_submenu->add_action(*m_new_directory_action);
|
||||
|
||||
file_menu.add_action(*m_open_action);
|
||||
m_recent_projects_submenu = &file_menu.add_submenu("Open &Recent"_string);
|
||||
m_recent_projects_submenu = file_menu.add_submenu("Open &Recent"_string);
|
||||
{
|
||||
auto icon = TRY(Gfx::Bitmap::load_from_file("/res/icons/16x16/open-recent.png"sv));
|
||||
m_recent_projects_submenu->set_icon(icon);
|
||||
|
@ -1511,7 +1511,7 @@ ErrorOr<void> HackStudioWidget::create_view_menu(GUI::Window& window)
|
|||
view_menu.add_separator();
|
||||
|
||||
m_wrapping_mode_actions.set_exclusive(true);
|
||||
auto& wrapping_mode_menu = view_menu.add_submenu("&Wrapping Mode"_string);
|
||||
auto wrapping_mode_menu = view_menu.add_submenu("&Wrapping Mode"_string);
|
||||
m_no_wrapping_action = GUI::Action::create_checkable("&No Wrapping", [&](auto&) {
|
||||
m_wrapping_mode = GUI::TextEditor::WrappingMode::NoWrap;
|
||||
for (auto& wrapper : m_all_editor_wrappers)
|
||||
|
@ -1532,9 +1532,9 @@ ErrorOr<void> HackStudioWidget::create_view_menu(GUI::Window& window)
|
|||
m_wrapping_mode_actions.add_action(*m_wrap_anywhere_action);
|
||||
m_wrapping_mode_actions.add_action(*m_wrap_at_words_action);
|
||||
|
||||
wrapping_mode_menu.add_action(*m_no_wrapping_action);
|
||||
wrapping_mode_menu.add_action(*m_wrap_anywhere_action);
|
||||
wrapping_mode_menu.add_action(*m_wrap_at_words_action);
|
||||
wrapping_mode_menu->add_action(*m_no_wrapping_action);
|
||||
wrapping_mode_menu->add_action(*m_wrap_anywhere_action);
|
||||
wrapping_mode_menu->add_action(*m_wrap_at_words_action);
|
||||
|
||||
switch (m_wrapping_mode) {
|
||||
case GUI::TextEditor::NoWrap:
|
||||
|
|
|
@ -165,7 +165,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
|
||||
GUI::ActionGroup engines_action_group;
|
||||
engines_action_group.set_exclusive(true);
|
||||
auto engine_submenu = TRY(engine_menu->try_add_submenu("&Engine"_string));
|
||||
auto engine_submenu = engine_menu->add_submenu("&Engine"_string);
|
||||
auto human_engine_checkbox = GUI::Action::create_checkable("Human", [&](auto&) {
|
||||
widget->set_engine(nullptr);
|
||||
});
|
||||
|
|
|
@ -186,10 +186,10 @@ void BoardWidget::context_menu_event(GUI::ContextMenuEvent& event)
|
|||
if (!m_context_menu) {
|
||||
m_context_menu = GUI::Menu::construct();
|
||||
|
||||
auto& insert_pattern_menu = m_context_menu->add_submenu("&Insert Pattern"_string);
|
||||
auto insert_pattern_menu = m_context_menu->add_submenu("&Insert Pattern"_string);
|
||||
for_each_pattern([&](auto& pattern) {
|
||||
if (pattern.action())
|
||||
insert_pattern_menu.add_action(*pattern.action());
|
||||
insert_pattern_menu->add_action(*pattern.action());
|
||||
});
|
||||
}
|
||||
if (!m_running)
|
||||
|
|
|
@ -123,7 +123,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
GUI::ActionGroup skin_action_group;
|
||||
skin_action_group.set_exclusive(true);
|
||||
|
||||
auto skin_menu = TRY(game_menu->try_add_submenu("&Skin"_string));
|
||||
auto skin_menu = game_menu->add_submenu("&Skin"_string);
|
||||
skin_menu->set_icon(app_icon.bitmap_for_size(16));
|
||||
|
||||
auto add_skin_action = [&](StringView name, bool enable_color) -> ErrorOr<void> {
|
||||
|
|
|
@ -104,29 +104,20 @@ void Menu::set_parent(Menu& menu, int submenu_index)
|
|||
m_index_in_parent_menu = submenu_index;
|
||||
}
|
||||
|
||||
ErrorOr<NonnullRefPtr<Menu>> Menu::try_add_submenu(String name)
|
||||
NonnullRefPtr<Menu> Menu::add_submenu(String name)
|
||||
{
|
||||
// NOTE: We grow the vector first, to get allocation failure handled immediately.
|
||||
TRY(m_items.try_ensure_capacity(m_items.size() + 1));
|
||||
auto submenu = Menu::construct(move(name));
|
||||
|
||||
auto submenu = TRY(Menu::try_create(move(name)));
|
||||
|
||||
auto item = TRY(adopt_nonnull_own_or_enomem(new (nothrow) MenuItem(m_menu_id, submenu)));
|
||||
auto item = make<MenuItem>(m_menu_id, submenu);
|
||||
submenu->set_parent(*this, m_items.size());
|
||||
|
||||
if (m_menu_id != -1)
|
||||
realize_menu_item(*item, m_items.size());
|
||||
|
||||
m_items.unchecked_append(move(item));
|
||||
m_items.append(move(item));
|
||||
return submenu;
|
||||
}
|
||||
|
||||
Menu& Menu::add_submenu(String name)
|
||||
{
|
||||
auto menu = MUST(try_add_submenu(move(name)));
|
||||
return menu;
|
||||
}
|
||||
|
||||
void Menu::add_separator()
|
||||
{
|
||||
auto item = make<MenuItem>(m_menu_id, MenuItem::Type::Separator);
|
||||
|
|
|
@ -42,11 +42,10 @@ public:
|
|||
Action* action_at(size_t);
|
||||
|
||||
ErrorOr<void> try_add_action(NonnullRefPtr<Action>);
|
||||
ErrorOr<NonnullRefPtr<Menu>> try_add_submenu(String name);
|
||||
|
||||
void add_action(NonnullRefPtr<Action>);
|
||||
void add_separator();
|
||||
Menu& add_submenu(String name);
|
||||
[[nodiscard]] NonnullRefPtr<Menu> add_submenu(String name);
|
||||
void remove_all_actions();
|
||||
|
||||
ErrorOr<void> add_recent_files_list(Function<void(Action&)>);
|
||||
|
|
|
@ -151,12 +151,12 @@ ErrorOr<NonnullRefPtr<GUI::Menu>> build_system_menu(GUI::Window& window)
|
|||
VERIFY(parent_menu);
|
||||
}
|
||||
}
|
||||
auto& category_menu = parent_menu->add_submenu(String::from_deprecated_string(child_category).release_value_but_fixme_should_propagate_errors());
|
||||
auto category_menu = parent_menu->add_submenu(String::from_deprecated_string(child_category).release_value_but_fixme_should_propagate_errors());
|
||||
auto category_icon_path = category_icons->read_entry("16x16", category);
|
||||
if (!category_icon_path.is_empty()) {
|
||||
auto icon_or_error = Gfx::Bitmap::load_from_file(category_icon_path);
|
||||
if (!icon_or_error.is_error())
|
||||
category_menu.set_icon(icon_or_error.release_value());
|
||||
category_menu->set_icon(icon_or_error.release_value());
|
||||
}
|
||||
app_category_menus.set(category, category_menu);
|
||||
};
|
||||
|
@ -205,7 +205,7 @@ ErrorOr<NonnullRefPtr<GUI::Menu>> build_system_menu(GUI::Window& window)
|
|||
g_themes_group.set_exclusive(true);
|
||||
g_themes_group.set_unchecking_allowed(false);
|
||||
|
||||
g_themes_menu = &system_menu->add_submenu("&Themes"_string);
|
||||
g_themes_menu = system_menu->add_submenu("&Themes"_string);
|
||||
g_themes_menu->set_icon(TRY(Gfx::Bitmap::load_from_file("/res/icons/16x16/themes.png"sv)));
|
||||
|
||||
g_themes = TRY(Gfx::list_installed_system_themes());
|
||||
|
|
Loading…
Reference in a new issue