From 9657f4cabbdc6608ce0b537549418b860d86b14b Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Fri, 19 Jan 2024 16:18:03 +0000 Subject: [PATCH] LibGUI+Userland: Take ByteString in set_most_recently_open_file() --- Userland/Applications/FontEditor/MainWidget.cpp | 4 ++-- Userland/Applications/HexEditor/HexEditorWidget.cpp | 5 +++-- Userland/Applications/ImageViewer/ViewWidget.cpp | 2 +- Userland/Applications/PDFViewer/PDFViewerWidget.cpp | 2 +- Userland/Applications/PixelPaint/MainWidget.cpp | 8 +++----- Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp | 4 ++-- Userland/Applications/TextEditor/MainWidget.cpp | 4 ++-- Userland/Applications/ThemeEditor/MainWidget.cpp | 9 +++++---- Userland/DevTools/GMLPlayground/MainWidget.cpp | 4 ++-- Userland/Libraries/LibGUI/Application.cpp | 4 ++-- Userland/Libraries/LibGUI/Application.h | 2 +- 11 files changed, 24 insertions(+), 24 deletions(-) diff --git a/Userland/Applications/FontEditor/MainWidget.cpp b/Userland/Applications/FontEditor/MainWidget.cpp index 8ef5fa430c..5fd20cd1d4 100644 --- a/Userland/Applications/FontEditor/MainWidget.cpp +++ b/Userland/Applications/FontEditor/MainWidget.cpp @@ -167,7 +167,7 @@ ErrorOr MainWidget::create_actions() if (auto result = save_file(file.filename(), file.release_stream()); result.is_error()) show_error(result.release_error(), "Saving"sv, file.filename()); else - GUI::Application::the()->set_most_recently_open_file(file.filename()); + GUI::Application::the()->set_most_recently_open_file(file.filename().to_byte_string()); }); m_cut_action = GUI::CommonActions::make_cut_action([this](auto&) { @@ -827,7 +827,7 @@ ErrorOr MainWidget::open_file(StringView path, NonnullOwnPtr f auto unmasked_font = TRY(TRY(Gfx::BitmapFont::try_load_from_mapped_file(move(mapped_file)))->unmasked_character_set()); TRY(initialize(path, move(unmasked_font))); if (!path.is_empty()) - GUI::Application::the()->set_most_recently_open_file(TRY(String::from_utf8(path))); + GUI::Application::the()->set_most_recently_open_file(path); return {}; } diff --git a/Userland/Applications/HexEditor/HexEditorWidget.cpp b/Userland/Applications/HexEditor/HexEditorWidget.cpp index 5e80b94e4f..aa8a5993b0 100644 --- a/Userland/Applications/HexEditor/HexEditorWidget.cpp +++ b/Userland/Applications/HexEditor/HexEditorWidget.cpp @@ -600,8 +600,9 @@ void HexEditorWidget::open_file(String const& filename, NonnullOwnPtrset_modified(false); m_editor->open_file(move(file)); - set_path(filename.to_byte_string()); - GUI::Application::the()->set_most_recently_open_file(filename); + auto filename_byte_string = filename.to_byte_string(); + set_path(filename_byte_string); + GUI::Application::the()->set_most_recently_open_file(filename_byte_string); } bool HexEditorWidget::request_close() diff --git a/Userland/Applications/ImageViewer/ViewWidget.cpp b/Userland/Applications/ImageViewer/ViewWidget.cpp index a6b761f35f..4b6e616656 100644 --- a/Userland/Applications/ImageViewer/ViewWidget.cpp +++ b/Userland/Applications/ImageViewer/ViewWidget.cpp @@ -267,7 +267,7 @@ ErrorOr ViewWidget::try_open_file(String const& path, Core::File& file) } set_path(path); - GUI::Application::the()->set_most_recently_open_file(path); + GUI::Application::the()->set_most_recently_open_file(path.to_byte_string()); if (on_image_change) on_image_change(m_image); diff --git a/Userland/Applications/PDFViewer/PDFViewerWidget.cpp b/Userland/Applications/PDFViewer/PDFViewerWidget.cpp index 2ae9591a27..9b914e61b1 100644 --- a/Userland/Applications/PDFViewer/PDFViewerWidget.cpp +++ b/Userland/Applications/PDFViewer/PDFViewerWidget.cpp @@ -441,7 +441,7 @@ PDF::PDFErrorOr PDFViewerWidget::try_open_file(StringView path, NonnullOwn m_sidebar_open = false; } - GUI::Application::the()->set_most_recently_open_file(TRY(String::from_utf8(path))); + GUI::Application::the()->set_most_recently_open_file(path); return {}; } diff --git a/Userland/Applications/PixelPaint/MainWidget.cpp b/Userland/Applications/PixelPaint/MainWidget.cpp index 565fa58542..850019354a 100644 --- a/Userland/Applications/PixelPaint/MainWidget.cpp +++ b/Userland/Applications/PixelPaint/MainWidget.cpp @@ -208,16 +208,14 @@ ErrorOr MainWidget::initialize_menubar(GUI::Window& window) auto* editor = current_image_editor(); VERIFY(editor); editor->save_project_as(); - auto path_string = String::from_byte_string(editor->path()).release_value_but_fixme_should_propagate_errors(); - GUI::Application::the()->set_most_recently_open_file(path_string); + GUI::Application::the()->set_most_recently_open_file(editor->path()); }); m_save_image_action = GUI::CommonActions::make_save_action([&](auto&) { auto* editor = current_image_editor(); VERIFY(editor); editor->save_project(); - auto path_string = String::from_byte_string(editor->path()).release_value_but_fixme_should_propagate_errors(); - GUI::Application::the()->set_most_recently_open_file(path_string); + GUI::Application::the()->set_most_recently_open_file(editor->path()); }); file_menu->add_action(*m_new_image_action); @@ -1310,7 +1308,7 @@ void MainWidget::open_image(FileSystemAccessClient::File file) editor.set_unmodified(); m_layer_list_widget->set_image(&image); m_toolbox->ensure_tool_selection(); - GUI::Application::the()->set_most_recently_open_file(file.filename()); + GUI::Application::the()->set_most_recently_open_file(file.filename().to_byte_string()); } ErrorOr MainWidget::create_default_image() diff --git a/Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp b/Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp index 6aa357d6de..2baa5faf1e 100644 --- a/Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp +++ b/Userland/Applications/Spreadsheet/SpreadsheetWidget.cpp @@ -569,7 +569,7 @@ void SpreadsheetWidget::save(String const& filename, Core::File& file) } undo_stack().set_current_unmodified(); window()->set_modified(false); - GUI::Application::the()->set_most_recently_open_file(filename); + GUI::Application::the()->set_most_recently_open_file(filename.to_byte_string()); } void SpreadsheetWidget::load_file(String const& filename, Core::File& file) @@ -592,7 +592,7 @@ void SpreadsheetWidget::load_file(String const& filename, Core::File& file) setup_tabs(m_workbook->sheets()); update_window_title(); - GUI::Application::the()->set_most_recently_open_file(filename); + GUI::Application::the()->set_most_recently_open_file(filename.to_byte_string()); } void SpreadsheetWidget::import_sheets(String const& filename, Core::File& file) diff --git a/Userland/Applications/TextEditor/MainWidget.cpp b/Userland/Applications/TextEditor/MainWidget.cpp index 0c905ddc2a..c1f9d4e40d 100644 --- a/Userland/Applications/TextEditor/MainWidget.cpp +++ b/Userland/Applications/TextEditor/MainWidget.cpp @@ -293,7 +293,7 @@ MainWidget::MainWidget() } set_path(file.filename()); - GUI::Application::the()->set_most_recently_open_file(file.filename()); + GUI::Application::the()->set_most_recently_open_file(file.filename().to_byte_string()); dbgln("Wrote document to {}", file.filename()); }); @@ -803,7 +803,7 @@ ErrorOr MainWidget::read_file(String const& filename, Core::File& file) { m_editor->set_text(TRY(file.read_until_eof())); set_path(filename); - GUI::Application::the()->set_most_recently_open_file(filename); + GUI::Application::the()->set_most_recently_open_file(filename.to_byte_string()); m_editor->set_focus(true); return {}; } diff --git a/Userland/Applications/ThemeEditor/MainWidget.cpp b/Userland/Applications/ThemeEditor/MainWidget.cpp index 067f2fc612..25039a62b8 100644 --- a/Userland/Applications/ThemeEditor/MainWidget.cpp +++ b/Userland/Applications/ThemeEditor/MainWidget.cpp @@ -349,9 +349,10 @@ void MainWidget::set_path(ByteString path) update_title(); } -void MainWidget::save_to_file(String const& filename, NonnullOwnPtr file) +void MainWidget::save_to_file(String const& filename_string, NonnullOwnPtr file) { - auto theme = Core::ConfigFile::open(filename.to_byte_string(), move(file)).release_value_but_fixme_should_propagate_errors(); + auto filename = filename_string.to_byte_string(); + auto theme = Core::ConfigFile::open(filename, move(file)).release_value_but_fixme_should_propagate_errors(); #define __ENUMERATE_ALIGNMENT_ROLE(role) theme->write_entry("Alignments", to_string(Gfx::AlignmentRole::role), to_string(m_current_palette.alignment(Gfx::AlignmentRole::role))); ENUMERATE_ALIGNMENT_ROLES(__ENUMERATE_ALIGNMENT_ROLE) @@ -378,7 +379,7 @@ void MainWidget::save_to_file(String const& filename, NonnullOwnPtr GUI::MessageBox::show_error(window(), ByteString::formatted("Failed to save theme file: {}", sync_result.error())); } else { m_last_modified_time = MonotonicTime::now(); - set_path(filename.to_byte_string()); + set_path(filename); window()->set_modified(false); GUI::Application::the()->set_most_recently_open_file(filename); } @@ -676,7 +677,7 @@ ErrorOr MainWidget::load_from_file(String const& filename, NonnullOwnPtrset_modified(false); - GUI::Application::the()->set_most_recently_open_file(filename); + GUI::Application::the()->set_most_recently_open_file(filename.to_byte_string()); return {}; } diff --git a/Userland/DevTools/GMLPlayground/MainWidget.cpp b/Userland/DevTools/GMLPlayground/MainWidget.cpp index 4cac7e66bb..0664558b13 100644 --- a/Userland/DevTools/GMLPlayground/MainWidget.cpp +++ b/Userland/DevTools/GMLPlayground/MainWidget.cpp @@ -129,7 +129,7 @@ void MainWidget::load_file(FileSystemAccessClient::File file) m_file_path = file.filename().to_byte_string(); update_title(); - GUI::Application::the()->set_most_recently_open_file(file.filename()); + GUI::Application::the()->set_most_recently_open_file(file.filename().to_byte_string()); } ErrorOr MainWidget::initialize_menubar(GUI::Window& window) @@ -150,7 +150,7 @@ ErrorOr MainWidget::initialize_menubar(GUI::Window& window) m_file_path = response.value().filename().to_byte_string(); update_title(); - GUI::Application::the()->set_most_recently_open_file(response.value().filename()); + GUI::Application::the()->set_most_recently_open_file(response.value().filename().to_byte_string()); }); m_save_action = GUI::CommonActions::make_save_action([&](auto&) { diff --git a/Userland/Libraries/LibGUI/Application.cpp b/Userland/Libraries/LibGUI/Application.cpp index bc58cdcba6..7d75e9a503 100644 --- a/Userland/Libraries/LibGUI/Application.cpp +++ b/Userland/Libraries/LibGUI/Application.cpp @@ -371,7 +371,7 @@ void Application::update_recent_file_actions() m_recent_file_actions.last()->set_visible(number_of_recently_open_files == 0); } -void Application::set_most_recently_open_file(String new_path) +void Application::set_most_recently_open_file(ByteString new_path) { Vector new_recent_files_list; @@ -386,7 +386,7 @@ void Application::set_most_recently_open_file(String new_path) return existing_path.view() == new_path; }); - new_recent_files_list.prepend(new_path.to_byte_string()); + new_recent_files_list.prepend(new_path); for (size_t i = 0; i < max_recently_open_files(); ++i) { auto& path = new_recent_files_list[i]; diff --git a/Userland/Libraries/LibGUI/Application.h b/Userland/Libraries/LibGUI/Application.h index 692291898d..9e951d3fc5 100644 --- a/Userland/Libraries/LibGUI/Application.h +++ b/Userland/Libraries/LibGUI/Application.h @@ -94,7 +94,7 @@ public: void set_config_domain(String); void update_recent_file_actions(); - void set_most_recently_open_file(String path); + void set_most_recently_open_file(ByteString path); void register_recent_file_actions(Badge, Vector>);