summaryrefslogtreecommitdiff
path: root/Userland/Applications/FontEditor
diff options
context:
space:
mode:
authorthankyouverycool <66646555+thankyouverycool@users.noreply.github.com>2022-08-15 07:20:20 -0400
committerAndreas Kling <kling@serenityos.org>2022-11-19 15:41:09 +0100
commit92a75ccaeda7d3dbe30ad428e3b0339172d07c59 (patch)
tree2933c987693142018f7fd6e4281178ad5115f237 /Userland/Applications/FontEditor
parent9725fd162feffc59c1c8e0a256a99bf7a3d3a238 (diff)
downloadserenity-92a75ccaeda7d3dbe30ad428e3b0339172d07c59.zip
FontEditor: Include file basename in error messages when available
And write messages in the [action] failed: [error] format to match common error message formatting elsewhere in Userland.
Diffstat (limited to 'Userland/Applications/FontEditor')
-rw-r--r--Userland/Applications/FontEditor/MainWidget.cpp32
-rw-r--r--Userland/Applications/FontEditor/MainWidget.h2
-rw-r--r--Userland/Applications/FontEditor/UndoSelection.h12
3 files changed, 24 insertions, 22 deletions
diff --git a/Userland/Applications/FontEditor/MainWidget.cpp b/Userland/Applications/FontEditor/MainWidget.cpp
index 45d6e1b477..d2869a7965 100644
--- a/Userland/Applications/FontEditor/MainWidget.cpp
+++ b/Userland/Applications/FontEditor/MainWidget.cpp
@@ -101,9 +101,9 @@ ErrorOr<void> MainWidget::create_actions()
new_font_wizard->hide();
auto maybe_font = new_font_wizard->create_font();
if (maybe_font.is_error())
- return show_error("Failed to create new font"sv, maybe_font.error());
+ return show_error(maybe_font.error(), "Creating new font failed"sv);
if (auto result = initialize({}, move(maybe_font.value())); result.is_error())
- show_error("Failed to initialize font"sv, result.error());
+ show_error(result.error(), "Initializing new font failed"sv);
});
m_new_action->set_status_tip("Create a new font");
@@ -114,14 +114,14 @@ ErrorOr<void> MainWidget::create_actions()
if (!open_path.has_value())
return;
if (auto result = open_file(open_path.value()); result.is_error())
- show_error("Failed to open font"sv, result.error());
+ show_error(result.error(), "Opening"sv, LexicalPath { open_path.value() }.basename());
});
m_save_action = GUI::CommonActions::make_save_action([&](auto&) {
if (m_path.is_empty())
return m_save_as_action->activate();
if (auto result = save_file(m_path); result.is_error())
- show_error("Failed to save font"sv, result.error());
+ show_error(result.error(), "Saving"sv, LexicalPath { m_path }.basename());
});
m_save_as_action = GUI::CommonActions::make_save_as_action([&](auto&) {
@@ -130,17 +130,17 @@ ErrorOr<void> MainWidget::create_actions()
if (!save_path.has_value())
return;
if (auto result = save_file(save_path.value()); result.is_error())
- show_error("Failed to save font"sv, result.error());
+ show_error(result.error(), "Saving"sv, lexical_path.basename());
});
m_cut_action = GUI::CommonActions::make_cut_action([&](auto&) {
if (auto result = cut_selected_glyphs(); result.is_error())
- show_error("Failed to cut selection"sv, result.error());
+ show_error(result.error(), "Cutting selection failed"sv);
});
m_copy_action = GUI::CommonActions::make_copy_action([&](auto&) {
if (auto result = copy_selected_glyphs(); result.is_error())
- show_error("Failed to copy selection"sv, result.error());
+ show_error(result.error(), "Copying selection failed"sv);
});
m_paste_action = GUI::CommonActions::make_paste_action([&](auto&) {
@@ -177,7 +177,7 @@ ErrorOr<void> MainWidget::create_actions()
m_open_preview_action = GUI::Action::create("&Preview Font", { Mod_Ctrl, Key_P }, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/find.png"sv)), [&](auto&) {
if (!m_font_preview_window) {
if (auto maybe_window = create_preview_window(); maybe_window.is_error())
- show_error("Failed to create preview window"sv, maybe_window.error());
+ show_error(maybe_window.error(), "Creating preview window failed"sv);
else
m_font_preview_window = maybe_window.release_value();
}
@@ -775,12 +775,12 @@ void MainWidget::push_undo()
{
auto maybe_state = m_undo_selection->save_state();
if (maybe_state.is_error())
- return show_error("Failed to save undo state"sv, maybe_state.error());
+ return show_error(maybe_state.error(), "Saving undo state failed"sv);
auto maybe_command = try_make<SelectionUndoCommand>(*m_undo_selection, move(maybe_state.value()));
if (maybe_command.is_error())
- return show_error("Failed to make undo command"sv, maybe_command.error());
+ return show_error(maybe_command.error(), "Making undo command failed"sv);
if (auto maybe_push = m_undo_stack->try_push(move(maybe_command.value())); maybe_push.is_error())
- show_error("Failed to push undo stack"sv, maybe_push.error());
+ show_error(maybe_push.error(), "Pushing undo stack failed"sv);
}
void MainWidget::reset_selection_and_push_undo()
@@ -950,7 +950,7 @@ void MainWidget::drop_event(GUI::DropEvent& event)
return;
if (auto result = open_file(urls.first().path()); result.is_error())
- show_error("Failed to load font"sv, result.error());
+ show_error(result.error(), "Opening"sv, LexicalPath { urls.first().path() }.basename());
}
}
@@ -1056,9 +1056,13 @@ void MainWidget::delete_selected_glyphs()
update_statusbar();
}
-void MainWidget::show_error(StringView preface, Error error)
+void MainWidget::show_error(Error error, StringView preface, StringView basename)
{
- auto formatted_error = String::formatted("{}: {}", preface, error);
+ String formatted_error;
+ if (basename.is_empty())
+ formatted_error = String::formatted("{}: {}", preface, error);
+ else
+ formatted_error = String::formatted("{} \"{}\" failed: {}", preface, basename, error);
GUI::MessageBox::show_error(window(), formatted_error);
warnln(formatted_error);
}
diff --git a/Userland/Applications/FontEditor/MainWidget.h b/Userland/Applications/FontEditor/MainWidget.h
index d531f5d8d0..54f98d5c20 100644
--- a/Userland/Applications/FontEditor/MainWidget.h
+++ b/Userland/Applications/FontEditor/MainWidget.h
@@ -84,7 +84,7 @@ private:
void push_undo();
void reset_selection_and_push_undo();
- void show_error(StringView preface, Error);
+ void show_error(Error, StringView action, StringView basename = {});
RefPtr<Gfx::BitmapFont> m_edited_font;
diff --git a/Userland/Applications/FontEditor/UndoSelection.h b/Userland/Applications/FontEditor/UndoSelection.h
index f9444e03e8..4961a4687e 100644
--- a/Userland/Applications/FontEditor/UndoSelection.h
+++ b/Userland/Applications/FontEditor/UndoSelection.h
@@ -82,12 +82,10 @@ public:
virtual void undo() override
{
if (!m_redo_state) {
- if (auto maybe_state = m_undo_state->save_state(); !maybe_state.is_error()) {
- auto state = maybe_state.release_value();
- m_redo_state = move(state);
- } else {
- warnln("Failed to save redo state: {}", maybe_state.error());
- }
+ if (auto maybe_state = m_undo_state->save_state(); !maybe_state.is_error())
+ m_redo_state = move(maybe_state.value());
+ else
+ warnln("Saving redo state failed: {}", maybe_state.error());
}
m_undo_selection.restore_state(*m_undo_state);
}
@@ -96,7 +94,7 @@ public:
if (m_redo_state)
m_undo_selection.restore_state(*m_redo_state);
else
- warnln("Failed to restore state");
+ warnln("Restoring state failed");
}
private: