mirror of
https://github.com/SerenityOS/serenity
synced 2024-10-15 12:23:15 +00:00
LibGUI+Userland: Take ByteString in set_most_recently_open_file()
This commit is contained in:
parent
d30f13a88d
commit
9657f4cabb
|
@ -167,7 +167,7 @@ ErrorOr<void> MainWidget::create_actions()
|
||||||
if (auto result = save_file(file.filename(), file.release_stream()); result.is_error())
|
if (auto result = save_file(file.filename(), file.release_stream()); result.is_error())
|
||||||
show_error(result.release_error(), "Saving"sv, file.filename());
|
show_error(result.release_error(), "Saving"sv, file.filename());
|
||||||
else
|
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&) {
|
m_cut_action = GUI::CommonActions::make_cut_action([this](auto&) {
|
||||||
|
@ -827,7 +827,7 @@ ErrorOr<void> MainWidget::open_file(StringView path, NonnullOwnPtr<Core::File> f
|
||||||
auto unmasked_font = TRY(TRY(Gfx::BitmapFont::try_load_from_mapped_file(move(mapped_file)))->unmasked_character_set());
|
auto unmasked_font = TRY(TRY(Gfx::BitmapFont::try_load_from_mapped_file(move(mapped_file)))->unmasked_character_set());
|
||||||
TRY(initialize(path, move(unmasked_font)));
|
TRY(initialize(path, move(unmasked_font)));
|
||||||
if (!path.is_empty())
|
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 {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -600,8 +600,9 @@ void HexEditorWidget::open_file(String const& filename, NonnullOwnPtr<Core::File
|
||||||
{
|
{
|
||||||
window()->set_modified(false);
|
window()->set_modified(false);
|
||||||
m_editor->open_file(move(file));
|
m_editor->open_file(move(file));
|
||||||
set_path(filename.to_byte_string());
|
auto filename_byte_string = filename.to_byte_string();
|
||||||
GUI::Application::the()->set_most_recently_open_file(filename);
|
set_path(filename_byte_string);
|
||||||
|
GUI::Application::the()->set_most_recently_open_file(filename_byte_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HexEditorWidget::request_close()
|
bool HexEditorWidget::request_close()
|
||||||
|
|
|
@ -267,7 +267,7 @@ ErrorOr<void> ViewWidget::try_open_file(String const& path, Core::File& file)
|
||||||
}
|
}
|
||||||
|
|
||||||
set_path(path);
|
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)
|
if (on_image_change)
|
||||||
on_image_change(m_image);
|
on_image_change(m_image);
|
||||||
|
|
|
@ -441,7 +441,7 @@ PDF::PDFErrorOr<void> PDFViewerWidget::try_open_file(StringView path, NonnullOwn
|
||||||
m_sidebar_open = false;
|
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 {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
|
@ -208,16 +208,14 @@ ErrorOr<void> MainWidget::initialize_menubar(GUI::Window& window)
|
||||||
auto* editor = current_image_editor();
|
auto* editor = current_image_editor();
|
||||||
VERIFY(editor);
|
VERIFY(editor);
|
||||||
editor->save_project_as();
|
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(editor->path());
|
||||||
GUI::Application::the()->set_most_recently_open_file(path_string);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
m_save_image_action = GUI::CommonActions::make_save_action([&](auto&) {
|
m_save_image_action = GUI::CommonActions::make_save_action([&](auto&) {
|
||||||
auto* editor = current_image_editor();
|
auto* editor = current_image_editor();
|
||||||
VERIFY(editor);
|
VERIFY(editor);
|
||||||
editor->save_project();
|
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(editor->path());
|
||||||
GUI::Application::the()->set_most_recently_open_file(path_string);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
file_menu->add_action(*m_new_image_action);
|
file_menu->add_action(*m_new_image_action);
|
||||||
|
@ -1310,7 +1308,7 @@ void MainWidget::open_image(FileSystemAccessClient::File file)
|
||||||
editor.set_unmodified();
|
editor.set_unmodified();
|
||||||
m_layer_list_widget->set_image(&image);
|
m_layer_list_widget->set_image(&image);
|
||||||
m_toolbox->ensure_tool_selection();
|
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<void> MainWidget::create_default_image()
|
ErrorOr<void> MainWidget::create_default_image()
|
||||||
|
|
|
@ -569,7 +569,7 @@ void SpreadsheetWidget::save(String const& filename, Core::File& file)
|
||||||
}
|
}
|
||||||
undo_stack().set_current_unmodified();
|
undo_stack().set_current_unmodified();
|
||||||
window()->set_modified(false);
|
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)
|
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());
|
setup_tabs(m_workbook->sheets());
|
||||||
update_window_title();
|
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)
|
void SpreadsheetWidget::import_sheets(String const& filename, Core::File& file)
|
||||||
|
|
|
@ -293,7 +293,7 @@ MainWidget::MainWidget()
|
||||||
}
|
}
|
||||||
|
|
||||||
set_path(file.filename());
|
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());
|
dbgln("Wrote document to {}", file.filename());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -803,7 +803,7 @@ ErrorOr<void> MainWidget::read_file(String const& filename, Core::File& file)
|
||||||
{
|
{
|
||||||
m_editor->set_text(TRY(file.read_until_eof()));
|
m_editor->set_text(TRY(file.read_until_eof()));
|
||||||
set_path(filename);
|
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);
|
m_editor->set_focus(true);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
|
@ -349,9 +349,10 @@ void MainWidget::set_path(ByteString path)
|
||||||
update_title();
|
update_title();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWidget::save_to_file(String const& filename, NonnullOwnPtr<Core::File> file)
|
void MainWidget::save_to_file(String const& filename_string, NonnullOwnPtr<Core::File> 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)));
|
#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)
|
ENUMERATE_ALIGNMENT_ROLES(__ENUMERATE_ALIGNMENT_ROLE)
|
||||||
|
@ -378,7 +379,7 @@ void MainWidget::save_to_file(String const& filename, NonnullOwnPtr<Core::File>
|
||||||
GUI::MessageBox::show_error(window(), ByteString::formatted("Failed to save theme file: {}", sync_result.error()));
|
GUI::MessageBox::show_error(window(), ByteString::formatted("Failed to save theme file: {}", sync_result.error()));
|
||||||
} else {
|
} else {
|
||||||
m_last_modified_time = MonotonicTime::now();
|
m_last_modified_time = MonotonicTime::now();
|
||||||
set_path(filename.to_byte_string());
|
set_path(filename);
|
||||||
window()->set_modified(false);
|
window()->set_modified(false);
|
||||||
GUI::Application::the()->set_most_recently_open_file(filename);
|
GUI::Application::the()->set_most_recently_open_file(filename);
|
||||||
}
|
}
|
||||||
|
@ -676,7 +677,7 @@ ErrorOr<void> MainWidget::load_from_file(String const& filename, NonnullOwnPtr<C
|
||||||
|
|
||||||
m_last_modified_time = MonotonicTime::now();
|
m_last_modified_time = MonotonicTime::now();
|
||||||
window()->set_modified(false);
|
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());
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -129,7 +129,7 @@ void MainWidget::load_file(FileSystemAccessClient::File file)
|
||||||
m_file_path = file.filename().to_byte_string();
|
m_file_path = file.filename().to_byte_string();
|
||||||
update_title();
|
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<void> MainWidget::initialize_menubar(GUI::Window& window)
|
ErrorOr<void> MainWidget::initialize_menubar(GUI::Window& window)
|
||||||
|
@ -150,7 +150,7 @@ ErrorOr<void> MainWidget::initialize_menubar(GUI::Window& window)
|
||||||
m_file_path = response.value().filename().to_byte_string();
|
m_file_path = response.value().filename().to_byte_string();
|
||||||
update_title();
|
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&) {
|
m_save_action = GUI::CommonActions::make_save_action([&](auto&) {
|
||||||
|
|
|
@ -371,7 +371,7 @@ void Application::update_recent_file_actions()
|
||||||
m_recent_file_actions.last()->set_visible(number_of_recently_open_files == 0);
|
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<ByteString> new_recent_files_list;
|
Vector<ByteString> new_recent_files_list;
|
||||||
|
|
||||||
|
@ -386,7 +386,7 @@ void Application::set_most_recently_open_file(String new_path)
|
||||||
return existing_path.view() == 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) {
|
for (size_t i = 0; i < max_recently_open_files(); ++i) {
|
||||||
auto& path = new_recent_files_list[i];
|
auto& path = new_recent_files_list[i];
|
||||||
|
|
|
@ -94,7 +94,7 @@ public:
|
||||||
|
|
||||||
void set_config_domain(String);
|
void set_config_domain(String);
|
||||||
void update_recent_file_actions();
|
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<GUI::Menu>, Vector<NonnullRefPtr<GUI::Action>>);
|
void register_recent_file_actions(Badge<GUI::Menu>, Vector<NonnullRefPtr<GUI::Action>>);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue