diff options
author | DragonAlex98 <alessandro.antinori@studenti.unicam.it> | 2021-05-16 10:01:29 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-05-16 16:22:21 +0100 |
commit | bce119036a51b6fedc8aa50e47c13535c8a7ba73 (patch) | |
tree | 7a133dbf1d3311bf16364ce5df29052114fbb8c1 /Userland/Applications/ImageViewer/main.cpp | |
parent | 400d3ddb08560c9c052423540247039b066439ff (diff) | |
download | serenity-bce119036a51b6fedc8aa50e47c13535c8a7ba73.zip |
ImageViewer: Disable image actions when there is no image
Previously some actions like Rotate/Flip/Set as Desktop Wallpaper would
make the application crash if no image was loaded. Now image actions are
enabled/disabled based on whether an image has been loaded or not.
Diffstat (limited to 'Userland/Applications/ImageViewer/main.cpp')
-rw-r--r-- | Userland/Applications/ImageViewer/main.cpp | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/Userland/Applications/ImageViewer/main.cpp b/Userland/Applications/ImageViewer/main.cpp index 6475590927..31e2a59a73 100644 --- a/Userland/Applications/ImageViewer/main.cpp +++ b/Userland/Applications/ImageViewer/main.cpp @@ -205,7 +205,7 @@ int main(int argc, char** argv) widget.navigate(ViewWidget::Directions::Last); }); - auto full_sceen_action = GUI::CommonActions::make_fullscreen_action( + auto full_screen_action = GUI::CommonActions::make_fullscreen_action( [&](auto&) { widget.on_doubleclick(); }); @@ -238,6 +238,26 @@ int main(int argc, char** argv) GUI::Clipboard::the().set_bitmap(*widget.bitmap()); }); + widget.on_image_change = [&](const Gfx::Bitmap* bitmap) { + bool should_enable_image_actions = (bitmap != nullptr); + 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); + vertical_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); + go_first_action->set_enabled(should_enable_image_actions); + go_back_action->set_enabled(should_enable_image_actions); + go_forward_action->set_enabled(should_enable_image_actions); + go_last_action->set_enabled(should_enable_image_actions); + zoom_in_action->set_enabled(should_enable_image_actions); + reset_zoom_action->set_enabled(should_enable_image_actions); + zoom_out_action->set_enabled(should_enable_image_actions); + if (!should_enable_image_actions) { + window->set_title("Image Viewer"); + } + }; + main_toolbar.add_action(open_action); main_toolbar.add_action(delete_action); main_toolbar.add_separator(); @@ -273,7 +293,7 @@ int main(int argc, char** argv) navigate_menu.add_action(go_last_action); auto& view_menu = menubar->add_menu("&View"); - view_menu.add_action(full_sceen_action); + view_menu.add_action(full_screen_action); view_menu.add_separator(); view_menu.add_action(zoom_in_action); view_menu.add_action(reset_zoom_action); @@ -291,6 +311,8 @@ int main(int argc, char** argv) if (path != nullptr) { widget.load_from_file(path); + } else { + widget.clear(); } window->show(); |