@@ -145,16 +145,26 @@ static constexpr int s_zoom_level_fit_height = 9;
145
145
static constexpr int s_zoom_level_fit_image = 10 ;
146
146
// Note: Update these together! ^
147
147
148
- void MainWidget::initialize_menubar (GUI::Window& window)
148
+ ErrorOr< void > MainWidget::initialize_menubar (GUI::Window& window)
149
149
{
150
150
auto & file_menu = window.add_menu (" &File" );
151
151
152
152
m_new_image_action = GUI::Action::create (
153
153
" &New Image..." , { Mod_Ctrl, Key_N }, g_icon_bag.filetype_pixelpaint , [&](auto &) {
154
154
auto dialog = PixelPaint::CreateNewImageDialog::construct (&window);
155
155
if (dialog->exec () == GUI::Dialog::ExecResult::OK) {
156
- auto image = PixelPaint::Image::try_create_with_size (dialog->image_size ()).release_value_but_fixme_should_propagate_errors ();
157
- auto bg_layer = PixelPaint::Layer::try_create_with_size (*image, image->size (), " Background" ).release_value_but_fixme_should_propagate_errors ();
156
+ auto image_result = PixelPaint::Image::try_create_with_size (dialog->image_size ());
157
+ if (image_result.is_error ()) {
158
+ GUI::MessageBox::show_error (&window, DeprecatedString::formatted (" Failed to create image with size {}, error: {}" , dialog->image_size (), image_result.error ()));
159
+ return ;
160
+ }
161
+ auto image = image_result.release_value ();
162
+ auto bg_layer_result = PixelPaint::Layer::try_create_with_size (*image, image->size (), " Background" );
163
+ if (bg_layer_result.is_error ()) {
164
+ GUI::MessageBox::show_error (&window, DeprecatedString::formatted (" Failed to create layer with size {}, error: {}" , image->size (), bg_layer_result.error ()));
165
+ return ;
166
+ }
167
+ auto bg_layer = bg_layer_result.release_value ();
158
168
image->add_layer (*bg_layer);
159
169
auto background_color = dialog->background_color ();
160
170
if (background_color != Gfx::Color::Transparent)
@@ -174,7 +184,10 @@ void MainWidget::initialize_menubar(GUI::Window& window)
174
184
175
185
m_new_image_from_clipboard_action = GUI::Action::create (
176
186
" &New Image from Clipboard" , { Mod_Ctrl | Mod_Shift, Key_V }, g_icon_bag.new_clipboard , [&](auto &) {
177
- create_image_from_clipboard ();
187
+ auto result = create_image_from_clipboard ();
188
+ if (result.is_error ()) {
189
+ GUI::MessageBox::show_error (&window, DeprecatedString::formatted (" Failed to create image from clipboard: {}" , result.error ()));
190
+ }
178
191
});
179
192
180
193
m_open_image_action = GUI::CommonActions::make_open_action ([&](auto &) {
@@ -314,15 +327,23 @@ void MainWidget::initialize_menubar(GUI::Window& window)
314
327
m_paste_action = GUI::CommonActions::make_paste_action ([&](auto &) {
315
328
auto * editor = current_image_editor ();
316
329
if (!editor) {
317
- create_image_from_clipboard ();
330
+ auto result = create_image_from_clipboard ();
331
+ if (result.is_error ()) {
332
+ GUI::MessageBox::show_error (&window, DeprecatedString::formatted (" Failed to create image from clipboard: {}" , result.error ()));
333
+ }
318
334
return ;
319
335
}
320
336
321
337
auto bitmap = GUI::Clipboard::the ().fetch_data_and_type ().as_bitmap ();
322
338
if (!bitmap)
323
339
return ;
324
340
325
- auto layer = PixelPaint::Layer::try_create_with_bitmap (editor->image (), *bitmap, " Pasted layer" ).release_value_but_fixme_should_propagate_errors ();
341
+ auto layer_result = PixelPaint::Layer::try_create_with_bitmap (editor->image (), *bitmap, " Pasted layer" );
342
+ if (layer_result.is_error ()) {
343
+ GUI::MessageBox::show_error (&window, DeprecatedString::formatted (" Could not create bitmap when pasting: {}" , layer_result.error ()));
344
+ return ;
345
+ }
346
+ auto layer = layer_result.release_value ();
326
347
editor->image ().add_layer (*layer);
327
348
editor->set_active_layer (layer);
328
349
editor->image ().selection ().clear ();
@@ -556,15 +577,15 @@ void MainWidget::initialize_menubar(GUI::Window& window)
556
577
}));
557
578
m_image_menu->add_separator ();
558
579
559
- m_image_menu->add_action (GUI::Action::create (" Rotate Image &Counterclockwise" , { Mod_Ctrl | Mod_Shift, Key_LessThan }, Gfx::Bitmap::try_load_from_file (" /res/icons/16x16/edit-rotate-ccw.png" sv). release_value_but_fixme_should_propagate_errors ( ),
580
+ m_image_menu->add_action (GUI::Action::create (" Rotate Image &Counterclockwise" , { Mod_Ctrl | Mod_Shift, Key_LessThan }, TRY ( Gfx::Bitmap::try_load_from_file (" /res/icons/16x16/edit-rotate-ccw.png" sv)),
560
581
[&](auto &) {
561
582
auto * editor = current_image_editor ();
562
583
VERIFY (editor);
563
584
editor->image ().rotate (Gfx::RotationDirection::CounterClockwise);
564
585
editor->did_complete_action (" Rotate Image Counterclockwise" sv);
565
586
}));
566
587
567
- m_image_menu->add_action (GUI::Action::create (" Rotate Image Clock&wise" , { Mod_Ctrl | Mod_Shift, Key_GreaterThan }, Gfx::Bitmap::try_load_from_file (" /res/icons/16x16/edit-rotate-cw.png" sv). release_value_but_fixme_should_propagate_errors ( ),
588
+ m_image_menu->add_action (GUI::Action::create (" Rotate Image Clock&wise" , { Mod_Ctrl | Mod_Shift, Key_GreaterThan }, TRY ( Gfx::Bitmap::try_load_from_file (" /res/icons/16x16/edit-rotate-cw.png" sv)),
568
589
[&](auto &) {
569
590
auto * editor = current_image_editor ();
570
591
VERIFY (editor);
@@ -750,7 +771,12 @@ void MainWidget::initialize_menubar(GUI::Window& window)
750
771
auto & next_active_layer = editor->image ().layer (active_layer_index > 0 ? active_layer_index - 1 : 0 );
751
772
editor->set_active_layer (&next_active_layer);
752
773
} else {
753
- auto layer = PixelPaint::Layer::try_create_with_size (editor->image (), editor->image ().size (), " Background" ).release_value_but_fixme_should_propagate_errors ();
774
+ auto layer_result = PixelPaint::Layer::try_create_with_size (editor->image (), editor->image ().size (), " Background" );
775
+ if (layer_result.is_error ()) {
776
+ GUI::MessageBox::show_error (&window, DeprecatedString::formatted (" Failed to create layer with size {}, error: {}" , editor->image ().size (), layer_result.error ()));
777
+ return ;
778
+ }
779
+ auto layer = layer_result.release_value ();
754
780
editor->image ().add_layer (move (layer));
755
781
editor->layers_did_change ();
756
782
m_layer_list_widget->select_top_layer ();
@@ -822,7 +848,7 @@ void MainWidget::initialize_menubar(GUI::Window& window)
822
848
}));
823
849
m_layer_menu->add_separator ();
824
850
825
- m_layer_menu->add_action (GUI::Action::create (" Rotate Layer &Counterclockwise" , Gfx::Bitmap::try_load_from_file (" /res/icons/16x16/edit-rotate-ccw.png" sv). release_value_but_fixme_should_propagate_errors ( ),
851
+ m_layer_menu->add_action (GUI::Action::create (" Rotate Layer &Counterclockwise" , TRY ( Gfx::Bitmap::try_load_from_file (" /res/icons/16x16/edit-rotate-ccw.png" sv)),
826
852
[&](auto &) {
827
853
auto * editor = current_image_editor ();
828
854
VERIFY (editor);
@@ -833,7 +859,7 @@ void MainWidget::initialize_menubar(GUI::Window& window)
833
859
editor->did_complete_action (" Rotate Layer Counterclockwise" sv);
834
860
}));
835
861
836
- m_layer_menu->add_action (GUI::Action::create (" Rotate Layer Clock&wise" , Gfx::Bitmap::try_load_from_file (" /res/icons/16x16/edit-rotate-cw.png" sv). release_value_but_fixme_should_propagate_errors ( ),
862
+ m_layer_menu->add_action (GUI::Action::create (" Rotate Layer Clock&wise" , TRY ( Gfx::Bitmap::try_load_from_file (" /res/icons/16x16/edit-rotate-cw.png" sv)),
837
863
[&](auto &) {
838
864
auto * editor = current_image_editor ();
839
865
VERIFY (editor);
@@ -967,6 +993,8 @@ void MainWidget::initialize_menubar(GUI::Window& window)
967
993
968
994
toolbar.add_separator ();
969
995
toolbar.add_action (*m_levels_dialog_action);
996
+
997
+ return {};
970
998
}
971
999
972
1000
void MainWidget::set_actions_enabled (bool enabled)
@@ -1006,11 +1034,11 @@ void MainWidget::open_image(Core::File& file)
1006
1034
m_layer_list_widget->set_image (&image);
1007
1035
}
1008
1036
1009
- void MainWidget::create_default_image ()
1037
+ ErrorOr< void > MainWidget::create_default_image ()
1010
1038
{
1011
- auto image = Image::try_create_with_size ({ 510 , 356 }). release_value_but_fixme_should_propagate_errors ( );
1039
+ auto image = TRY ( Image::try_create_with_size ({ 510 , 356 }));
1012
1040
1013
- auto bg_layer = Layer::try_create_with_size (*image, image->size (), " Background" ). release_value_but_fixme_should_propagate_errors ( );
1041
+ auto bg_layer = TRY ( Layer::try_create_with_size (*image, image->size (), " Background" ));
1014
1042
image->add_layer (*bg_layer);
1015
1043
bg_layer->content_bitmap ().fill (Color::Transparent);
1016
1044
@@ -1020,25 +1048,27 @@ void MainWidget::create_default_image()
1020
1048
editor.set_title (" Untitled" );
1021
1049
editor.set_active_layer (bg_layer);
1022
1050
editor.set_unmodified ();
1051
+
1052
+ return {};
1023
1053
}
1024
1054
1025
- void MainWidget::create_image_from_clipboard ()
1055
+ ErrorOr< void > MainWidget::create_image_from_clipboard ()
1026
1056
{
1027
1057
auto bitmap = GUI::Clipboard::the ().fetch_data_and_type ().as_bitmap ();
1028
1058
if (!bitmap) {
1029
- GUI::MessageBox::show (window (), " There is no image in a clipboard to paste." sv, " PixelPaint" sv, GUI::MessageBox::Type::Warning);
1030
- return ;
1059
+ return Error::from_string_view (" There is no image in a clipboard to paste." sv);
1031
1060
}
1032
1061
1033
- auto image = PixelPaint::Image::try_create_with_size (bitmap->size ()). release_value_but_fixme_should_propagate_errors ( );
1034
- auto layer = PixelPaint::Layer::try_create_with_bitmap (image, *bitmap, " Pasted layer" ). release_value_but_fixme_should_propagate_errors ( );
1062
+ auto image = TRY ( PixelPaint::Image::try_create_with_size (bitmap->size ()));
1063
+ auto layer = TRY ( PixelPaint::Layer::try_create_with_bitmap (image, *bitmap, " Pasted layer" ));
1035
1064
image->add_layer (*layer);
1036
1065
1037
1066
auto & editor = create_new_editor (*image);
1038
1067
editor.set_title (" Untitled" );
1039
1068
1040
1069
m_layer_list_widget->set_image (image);
1041
1070
m_layer_list_widget->set_selected_layer (layer);
1071
+ return {};
1042
1072
}
1043
1073
1044
1074
bool MainWidget::request_close ()
0 commit comments