Bläddra i källkod

LibGUI: Move rotate cw/ccw to CommonActions

The rotate clockwise/rotate counterclockwise actions can be added to
CommonActions since they are repeated in FontEditor, ImageViewer and
PixelPaint. This keeps the shortcuts and icons consistent across
applications.
Marcus Nilsson 3 år sedan
förälder
incheckning
cecbed467b

+ 2 - 2
Userland/Applications/FontEditor/FontEditor.cpp

@@ -335,11 +335,11 @@ FontEditorWidget::FontEditorWidget()
     glyph_mode_toolbar.add_action(*m_paint_glyph_action);
     glyph_mode_toolbar.add_action(*m_paint_glyph_action);
     glyph_mode_toolbar.add_action(*m_move_glyph_action);
     glyph_mode_toolbar.add_action(*m_move_glyph_action);
 
 
-    m_rotate_counterclockwise_action = GUI::Action::create("Rotate Counterclockwise", { Mod_Ctrl | Mod_Shift, Key_Z }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/edit-rotate-ccw.png").release_value_but_fixme_should_propagate_errors(), [&](auto&) {
+    m_rotate_counterclockwise_action = GUI::CommonActions::make_rotate_counterclockwise_action([&](auto&) {
         m_glyph_editor_widget->rotate_90(GlyphEditorWidget::Counterclockwise);
         m_glyph_editor_widget->rotate_90(GlyphEditorWidget::Counterclockwise);
     });
     });
 
 
-    m_rotate_clockwise_action = GUI::Action::create("Rotate Clockwise", { Mod_Ctrl | Mod_Shift, Key_X }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/edit-rotate-cw.png").release_value_but_fixme_should_propagate_errors(), [&](auto&) {
+    m_rotate_clockwise_action = GUI::CommonActions::make_rotate_clockwise_action([&](auto&) {
         m_glyph_editor_widget->rotate_90(GlyphEditorWidget::Clockwise);
         m_glyph_editor_widget->rotate_90(GlyphEditorWidget::Clockwise);
     });
     });
 
 

+ 10 - 12
Userland/Applications/ImageViewer/main.cpp

@@ -149,15 +149,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
             app->quit();
             app->quit();
         });
         });
 
 
-    auto rotate_left_action = GUI::Action::create("Rotate &Left", { Mod_None, Key_L },
-        [&](auto&) {
-            widget->rotate(Gfx::RotationDirection::CounterClockwise);
-        });
+    auto rotate_counterclockwise_action = GUI::CommonActions::make_rotate_counterclockwise_action([&](auto&) {
+        widget->rotate(Gfx::RotationDirection::CounterClockwise);
+    });
 
 
-    auto rotate_right_action = GUI::Action::create("Rotate &Right", { Mod_None, Key_R },
-        [&](auto&) {
-            widget->rotate(Gfx::RotationDirection::Clockwise);
-        });
+    auto rotate_clockwise_action = GUI::CommonActions::make_rotate_clockwise_action([&](auto&) {
+        widget->rotate(Gfx::RotationDirection::Clockwise);
+    });
 
 
     auto vertical_flip_action = GUI::Action::create("Flip &Vertically", { Mod_None, Key_V },
     auto vertical_flip_action = GUI::Action::create("Flip &Vertically", { Mod_None, Key_V },
         [&](auto&) {
         [&](auto&) {
@@ -247,8 +245,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
         bool should_enable_forward_actions = (widget->is_next_available() && should_enable_image_actions);
         bool should_enable_forward_actions = (widget->is_next_available() && should_enable_image_actions);
         bool should_enable_backward_actions = (widget->is_previous_available() && should_enable_image_actions);
         bool should_enable_backward_actions = (widget->is_previous_available() && should_enable_image_actions);
         delete_action->set_enabled(should_enable_image_actions);
         delete_action->set_enabled(should_enable_image_actions);
-        rotate_left_action->set_enabled(should_enable_image_actions);
-        rotate_right_action->set_enabled(should_enable_image_actions);
+        rotate_counterclockwise_action->set_enabled(should_enable_image_actions);
+        rotate_clockwise_action->set_enabled(should_enable_image_actions);
         vertical_flip_action->set_enabled(should_enable_image_actions);
         vertical_flip_action->set_enabled(should_enable_image_actions);
         horizontal_flip_action->set_enabled(should_enable_image_actions);
         horizontal_flip_action->set_enabled(should_enable_image_actions);
         desktop_wallpaper_action->set_enabled(should_enable_image_actions);
         desktop_wallpaper_action->set_enabled(should_enable_image_actions);
@@ -285,8 +283,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
     TRY(file_menu->try_add_action(quit_action));
     TRY(file_menu->try_add_action(quit_action));
 
 
     auto image_menu = TRY(window->try_add_menu("&Image"));
     auto image_menu = TRY(window->try_add_menu("&Image"));
-    TRY(image_menu->try_add_action(rotate_left_action));
-    TRY(image_menu->try_add_action(rotate_right_action));
+    TRY(image_menu->try_add_action(rotate_counterclockwise_action));
+    TRY(image_menu->try_add_action(rotate_clockwise_action));
     TRY(image_menu->try_add_action(vertical_flip_action));
     TRY(image_menu->try_add_action(vertical_flip_action));
     TRY(image_menu->try_add_action(horizontal_flip_action));
     TRY(image_menu->try_add_action(horizontal_flip_action));
     TRY(image_menu->try_add_separator());
     TRY(image_menu->try_add_separator());

+ 6 - 4
Userland/Applications/PixelPaint/MainWidget.cpp

@@ -455,15 +455,17 @@ void MainWidget::initialize_menubar(GUI::Window& window)
             editor->image().flip(Gfx::Orientation::Horizontal);
             editor->image().flip(Gfx::Orientation::Horizontal);
         }));
         }));
     image_menu.add_separator();
     image_menu.add_separator();
-    image_menu.add_action(GUI::Action::create(
-        "Rotate &Left", [&](auto&) {
+
+    image_menu.add_action(GUI::CommonActions::make_rotate_counterclockwise_action(
+        [&](auto&) {
             auto* editor = current_image_editor();
             auto* editor = current_image_editor();
             if (!editor)
             if (!editor)
                 return;
                 return;
             editor->image().rotate(Gfx::RotationDirection::CounterClockwise);
             editor->image().rotate(Gfx::RotationDirection::CounterClockwise);
         }));
         }));
-    image_menu.add_action(GUI::Action::create(
-        "Rotate &Right", [&](auto&) {
+
+    image_menu.add_action(GUI::CommonActions::make_rotate_clockwise_action(
+        [&](auto&) {
             auto* editor = current_image_editor();
             auto* editor = current_image_editor();
             if (!editor)
             if (!editor)
                 return;
                 return;

+ 2 - 0
Userland/Libraries/LibGUI/Action.h

@@ -48,6 +48,8 @@ NonnullRefPtr<Action> make_properties_action(Function<void(Action&)>, Core::Obje
 NonnullRefPtr<Action> make_zoom_in_action(Function<void(Action&)>, Core::Object* parent = nullptr);
 NonnullRefPtr<Action> make_zoom_in_action(Function<void(Action&)>, Core::Object* parent = nullptr);
 NonnullRefPtr<Action> make_zoom_out_action(Function<void(Action&)>, Core::Object* parent = nullptr);
 NonnullRefPtr<Action> make_zoom_out_action(Function<void(Action&)>, Core::Object* parent = nullptr);
 NonnullRefPtr<Action> make_reset_zoom_action(Function<void(Action&)>, Core::Object* parent = nullptr);
 NonnullRefPtr<Action> make_reset_zoom_action(Function<void(Action&)>, Core::Object* parent = nullptr);
+NonnullRefPtr<Action> make_rotate_clockwise_action(Function<void(Action&)>, Core::Object* parent = nullptr);
+NonnullRefPtr<Action> make_rotate_counterclockwise_action(Function<void(Action&)>, Core::Object* parent = nullptr);
 
 
 };
 };
 
 

+ 10 - 0
Userland/Libraries/LibGUI/CommonActions.cpp

@@ -178,6 +178,16 @@ NonnullRefPtr<Action> make_zoom_out_action(Function<void(Action&)> callback, Cor
     return GUI::Action::create("Zoom &Out", { Mod_Ctrl, Key_Minus }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/zoom-out.png").release_value_but_fixme_should_propagate_errors(), move(callback), parent);
     return GUI::Action::create("Zoom &Out", { Mod_Ctrl, Key_Minus }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/zoom-out.png").release_value_but_fixme_should_propagate_errors(), move(callback), parent);
 }
 }
 
 
+NonnullRefPtr<Action> make_rotate_clockwise_action(Function<void(Action&)> callback, Core::Object* parent)
+{
+    return GUI::Action::create("Rotate Clock&wise", { Mod_Ctrl | Mod_Shift, Key_X }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/edit-rotate-cw.png").release_value_but_fixme_should_propagate_errors(), move(callback), parent);
+}
+
+NonnullRefPtr<Action> make_rotate_counterclockwise_action(Function<void(Action&)> callback, Core::Object* parent)
+{
+    return GUI::Action::create("Rotate &Counterclockwise", { Mod_Ctrl | Mod_Shift, Key_Z }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/edit-rotate-ccw.png").release_value_but_fixme_should_propagate_errors(), move(callback), parent);
+}
+
 }
 }
 
 
 }
 }