mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 14:12:44 +00:00 
			
		
		
		
	LibGUI: Make Menu::add_recent_files_list() infallible
This commit is contained in:
		
							parent
							
								
									f2faf2767f
								
							
						
					
					
						commit
						676ef0cc3d
					
				
					 11 changed files with 20 additions and 21 deletions
				
			
		|  | @ -739,7 +739,7 @@ ErrorOr<void> MainWidget::initialize_menubar(GUI::Window& window) | |||
|     file_menu->add_action(*m_save_action); | ||||
|     file_menu->add_action(*m_save_as_action); | ||||
|     file_menu->add_separator(); | ||||
|     TRY(file_menu->add_recent_files_list([this](auto& action) { | ||||
|     file_menu->add_recent_files_list([this](auto& action) { | ||||
|         if (!request_close()) | ||||
|             return; | ||||
|         auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(this->window(), action.text()); | ||||
|  | @ -748,7 +748,7 @@ ErrorOr<void> MainWidget::initialize_menubar(GUI::Window& window) | |||
|         auto file = response.release_value(); | ||||
|         if (auto result = open_file(file.filename(), file.release_stream()); result.is_error()) | ||||
|             show_error(result.release_error(), "Opening"sv, file.filename()); | ||||
|     })); | ||||
|     }); | ||||
|     file_menu->add_action(GUI::CommonActions::make_quit_action([this](auto&) { | ||||
|         if (!request_close()) | ||||
|             return; | ||||
|  |  | |||
|  | @ -418,7 +418,7 @@ ErrorOr<void> HexEditorWidget::initialize_menubar(GUI::Window& window) | |||
|     file_menu->add_action(*m_save_action); | ||||
|     file_menu->add_action(*m_save_as_action); | ||||
|     file_menu->add_separator(); | ||||
|     TRY(file_menu->add_recent_files_list([&](auto& action) { | ||||
|     file_menu->add_recent_files_list([&](auto& action) { | ||||
|         auto path = action.text(); | ||||
|         auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(&window, path); | ||||
|         if (response.is_error()) | ||||
|  | @ -426,7 +426,7 @@ ErrorOr<void> HexEditorWidget::initialize_menubar(GUI::Window& window) | |||
| 
 | ||||
|         auto file = response.release_value(); | ||||
|         open_file(file.filename(), file.release_stream()); | ||||
|     })); | ||||
|     }); | ||||
|     file_menu->add_action(GUI::CommonActions::make_quit_action([this](auto&) { | ||||
|         if (!request_close()) | ||||
|             return; | ||||
|  |  | |||
|  | @ -311,7 +311,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) | |||
|     file_menu->add_action(delete_action); | ||||
|     file_menu->add_separator(); | ||||
| 
 | ||||
|     TRY(file_menu->add_recent_files_list([&](auto& action) { | ||||
|     file_menu->add_recent_files_list([&](auto& action) { | ||||
|         auto path = action.text(); | ||||
|         auto result = FileSystemAccessClient::Client::the().request_file_read_only_approved(window, path); | ||||
|         if (result.is_error()) | ||||
|  | @ -319,7 +319,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) | |||
| 
 | ||||
|         auto value = result.release_value(); | ||||
|         widget->open_file(value.filename(), value.stream()); | ||||
|     })); | ||||
|     }); | ||||
| 
 | ||||
|     file_menu->add_action(quit_action); | ||||
| 
 | ||||
|  |  | |||
|  | @ -221,11 +221,11 @@ ErrorOr<void> PDFViewerWidget::initialize_menubar(GUI::Window& window) | |||
|             open_file(response.value().filename(), response.value().release_stream()); | ||||
|     })); | ||||
|     file_menu->add_separator(); | ||||
|     TRY(file_menu->add_recent_files_list([&](auto& action) { | ||||
|     file_menu->add_recent_files_list([&](auto& action) { | ||||
|         auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(&window, action.text()); | ||||
|         if (!response.is_error()) | ||||
|             open_file(response.value().filename(), response.value().release_stream()); | ||||
|     })); | ||||
|     }); | ||||
|     file_menu->add_action(GUI::CommonActions::make_quit_action([](auto&) { | ||||
|         GUI::Application::the()->quit(); | ||||
|     })); | ||||
|  |  | |||
|  | @ -271,13 +271,13 @@ ErrorOr<void> MainWidget::initialize_menubar(GUI::Window& window) | |||
| 
 | ||||
|     file_menu->add_separator(); | ||||
| 
 | ||||
|     TRY(file_menu->add_recent_files_list([&](auto& action) { | ||||
|     file_menu->add_recent_files_list([&](auto& action) { | ||||
|         auto path = action.text(); | ||||
|         auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(&window, path); | ||||
|         if (response.is_error()) | ||||
|             return; | ||||
|         open_image(response.release_value()); | ||||
|     })); | ||||
|     }); | ||||
| 
 | ||||
|     m_close_image_action = GUI::Action::create("&Close Image", { Mod_Ctrl, Key_W }, g_icon_bag.close_image, [&](auto&) { | ||||
|         auto* active_widget = m_tab_widget->active_widget(); | ||||
|  |  | |||
|  | @ -726,7 +726,7 @@ ErrorOr<void> SpreadsheetWidget::initialize_menubar(GUI::Window& window) | |||
|     file_menu->add_separator(); | ||||
|     file_menu->add_action(*m_import_action); | ||||
|     file_menu->add_separator(); | ||||
|     TRY(file_menu->add_recent_files_list([&](auto& action) { | ||||
|     file_menu->add_recent_files_list([&](auto& action) { | ||||
|         if (!request_close()) | ||||
|             return; | ||||
| 
 | ||||
|  | @ -734,7 +734,7 @@ ErrorOr<void> SpreadsheetWidget::initialize_menubar(GUI::Window& window) | |||
|         if (response.is_error()) | ||||
|             return; | ||||
|         load_file(response.value().filename(), response.value().stream()); | ||||
|     })); | ||||
|     }); | ||||
|     file_menu->add_action(*m_quit_action); | ||||
| 
 | ||||
|     auto edit_menu = TRY(window.try_add_menu("&Edit"_string)); | ||||
|  |  | |||
|  | @ -374,7 +374,7 @@ ErrorOr<void> MainWidget::initialize_menubar(GUI::Window& window) | |||
|     file_menu->add_action(*m_open_folder_action); | ||||
|     file_menu->add_separator(); | ||||
| 
 | ||||
|     TRY(file_menu->add_recent_files_list([&](auto& action) { | ||||
|     file_menu->add_recent_files_list([&](auto& action) { | ||||
|         if (editor().document().is_modified()) { | ||||
|             auto save_document_first_result = GUI::MessageBox::ask_about_unsaved_changes(&window, m_path, editor().document().undo_stack().last_unmodified_timestamp()); | ||||
|             if (save_document_first_result == GUI::Dialog::ExecResult::Yes) | ||||
|  | @ -389,7 +389,7 @@ ErrorOr<void> MainWidget::initialize_menubar(GUI::Window& window) | |||
| 
 | ||||
|         if (auto result = read_file(response.value().filename(), response.value().stream()); result.is_error()) | ||||
|             GUI::MessageBox::show(&window, "Unable to open file.\n"sv, "Error"sv, GUI::MessageBox::Type::Error); | ||||
|     })); | ||||
|     }); | ||||
|     file_menu->add_action(GUI::CommonActions::make_quit_action([this](auto&) { | ||||
|         if (!request_close()) | ||||
|             return; | ||||
|  |  | |||
|  | @ -287,7 +287,7 @@ ErrorOr<void> MainWidget::initialize_menubar(GUI::Window& window) | |||
|     })); | ||||
|     file_menu->add_separator(); | ||||
| 
 | ||||
|     TRY(file_menu->add_recent_files_list([&](auto& action) { | ||||
|     file_menu->add_recent_files_list([&](auto& action) { | ||||
|         if (request_close() == GUI::Window::CloseRequestDecision::StayOpen) | ||||
|             return; | ||||
|         auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(&window, action.text()); | ||||
|  | @ -298,7 +298,7 @@ ErrorOr<void> MainWidget::initialize_menubar(GUI::Window& window) | |||
|             GUI::MessageBox::show_error(&window, DeprecatedString::formatted("Can't open file named {}: {}", response.value().filename(), load_from_file_result.error())); | ||||
|             return; | ||||
|         } | ||||
|     })); | ||||
|     }); | ||||
| 
 | ||||
|     file_menu->add_action(GUI::CommonActions::make_quit_action([&](auto&) { | ||||
|         if (request_close() == GUI::Window::CloseRequestDecision::Close) | ||||
|  |  | |||
|  | @ -192,14 +192,14 @@ ErrorOr<void> MainWidget::initialize_menubar(GUI::Window& window) | |||
|     file_menu->add_action(*m_save_as_action); | ||||
|     file_menu->add_separator(); | ||||
| 
 | ||||
|     TRY(file_menu->add_recent_files_list([&](auto& action) { | ||||
|     file_menu->add_recent_files_list([&](auto& action) { | ||||
|         if (request_close() == GUI::Window::CloseRequestDecision::StayOpen) | ||||
|             return; | ||||
|         auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(&window, action.text()); | ||||
|         if (response.is_error()) | ||||
|             return; | ||||
|         load_file(response.release_value()); | ||||
|     })); | ||||
|     }); | ||||
| 
 | ||||
|     file_menu->add_action(GUI::CommonActions::make_quit_action([&](auto&) { | ||||
|         if (window.on_close_request() == GUI::Window::CloseRequestDecision::Close) | ||||
|  |  | |||
|  | @ -224,7 +224,7 @@ void Menu::realize_menu_item(MenuItem& item, int item_id) | |||
|     } | ||||
| } | ||||
| 
 | ||||
| ErrorOr<void> Menu::add_recent_files_list(Function<void(Action&)> callback) | ||||
| void Menu::add_recent_files_list(Function<void(Action&)> callback) | ||||
| { | ||||
|     m_recent_files_callback = move(callback); | ||||
| 
 | ||||
|  | @ -245,7 +245,6 @@ ErrorOr<void> Menu::add_recent_files_list(Function<void(Action&)> callback) | |||
|     } | ||||
| 
 | ||||
|     add_separator(); | ||||
|     return {}; | ||||
| } | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -46,7 +46,7 @@ public: | |||
|     [[nodiscard]] NonnullRefPtr<Menu> add_submenu(String name); | ||||
|     void remove_all_actions(); | ||||
| 
 | ||||
|     ErrorOr<void> add_recent_files_list(Function<void(Action&)>); | ||||
|     void add_recent_files_list(Function<void(Action&)>); | ||||
| 
 | ||||
|     void popup(Gfx::IntPoint screen_position, RefPtr<Action> const& default_action = nullptr, Gfx::IntRect const& button_rect = {}); | ||||
|     void dismiss(); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling