PixelPaint: New submenu for masking actions

This patch moves the mask related menu actions into a submenu in order
to keep the menu more clear.
This commit is contained in:
Torstennator 2023-07-14 18:44:10 +02:00 committed by Jelle Raaijmakers
parent d8320d0a14
commit 5e6f5a524a
Notes: sideshowbarker 2024-07-16 23:38:54 +09:00

View file

@ -810,13 +810,15 @@ ErrorOr<void> MainWidget::initialize_menubar(GUI::Window& window)
};
};
auto mask_submenu = TRY(m_layer_menu->try_add_submenu("&Masks"_short_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) {
VERIFY(!active_layer->is_masked());
if (auto maybe_error = active_layer->create_mask(Layer::MaskType::BasicMask); maybe_error.is_error())
GUI::MessageBox::show_error(&window, MUST(String::formatted("Failed to create layer mask: {}", maybe_error.release_error())));
}));
TRY(m_layer_menu->try_add_action(*m_add_mask_action));
TRY(mask_submenu->try_add_action(*m_add_mask_action));
m_add_editing_mask_action = GUI::Action::create(
"Add E&diting Mask", { Mod_Ctrl | Mod_Alt, Key_E }, g_icon_bag.add_mask, create_layer_mask_callback("Add Editing Mask", [&](Layer* active_layer) {
@ -824,35 +826,35 @@ ErrorOr<void> MainWidget::initialize_menubar(GUI::Window& window)
if (auto maybe_error = active_layer->create_mask(Layer::MaskType::EditingMask); maybe_error.is_error())
GUI::MessageBox::show_error(&window, MUST(String::formatted("Failed to create layer mask: {}", maybe_error.release_error())));
}));
TRY(m_layer_menu->try_add_action(*m_add_editing_mask_action));
TRY(mask_submenu->try_add_action(*m_add_editing_mask_action));
m_delete_mask_action = GUI::Action::create(
"Delete Mask", create_layer_mask_callback("Delete Mask", [&](Layer* active_layer) {
VERIFY(active_layer->is_masked());
active_layer->delete_mask();
}));
TRY(m_layer_menu->try_add_action(*m_delete_mask_action));
TRY(mask_submenu->try_add_action(*m_delete_mask_action));
m_apply_mask_action = GUI::Action::create(
"Apply Mask", create_layer_mask_callback("Apply Mask", [&](Layer* active_layer) {
VERIFY(active_layer->is_masked());
active_layer->apply_mask();
}));
TRY(m_layer_menu->try_add_action(*m_apply_mask_action));
TRY(mask_submenu->try_add_action(*m_apply_mask_action));
m_invert_mask_action = GUI::Action::create(
"Invert Mask", create_layer_mask_callback("Invert Mask", [&](Layer* active_layer) {
VERIFY(active_layer->is_masked());
active_layer->invert_mask();
}));
TRY(m_layer_menu->try_add_action(*m_invert_mask_action));
TRY(mask_submenu->try_add_action(*m_invert_mask_action));
m_clear_mask_action = GUI::Action::create(
"Clear Mask", create_layer_mask_callback("Clear Mask", [&](Layer* active_layer) {
VERIFY(active_layer->is_masked());
active_layer->clear_mask();
}));
TRY(m_layer_menu->try_add_action(*m_clear_mask_action));
TRY(mask_submenu->try_add_action(*m_clear_mask_action));
m_toggle_mask_visibility_action = GUI::Action::create_checkable(
"Show Mask", [&](auto&) {
@ -866,7 +868,7 @@ ErrorOr<void> MainWidget::initialize_menubar(GUI::Window& window)
editor->update();
});
TRY(m_layer_menu->try_add_action(*m_toggle_mask_visibility_action));
TRY(mask_submenu->try_add_action(*m_toggle_mask_visibility_action));
m_open_luminosity_masking_action = GUI::Action::create(
"Luminosity Masking", [&](auto&) {
@ -880,7 +882,7 @@ ErrorOr<void> MainWidget::initialize_menubar(GUI::Window& window)
m_layer_list_widget->repaint();
});
TRY(m_layer_menu->try_add_action(*m_open_luminosity_masking_action));
TRY(mask_submenu->try_add_action(*m_open_luminosity_masking_action));
m_open_color_masking_action = GUI::Action::create(
"Color Masking", [&](auto&) {
@ -894,7 +896,7 @@ ErrorOr<void> MainWidget::initialize_menubar(GUI::Window& window)
m_layer_list_widget->repaint();
});
TRY(m_layer_menu->try_add_action(*m_open_color_masking_action));
TRY(mask_submenu->try_add_action(*m_open_color_masking_action));
TRY(m_layer_menu->try_add_separator());
@ -1260,13 +1262,16 @@ void MainWidget::set_mask_actions_for_layer(Layer* layer)
{
if (!layer) {
m_add_mask_action->set_visible(true);
m_add_editing_mask_action->set_visible(true);
m_delete_mask_action->set_visible(false);
m_apply_mask_action->set_visible(false);
m_add_mask_action->set_enabled(false);
m_add_editing_mask_action->set_enabled(false);
return;
}
m_add_mask_action->set_enabled(true);
m_add_editing_mask_action->set_enabled(true);
auto masked = layer->is_masked();
m_add_mask_action->set_visible(!masked);