mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 01:27:43 +00:00
TextEditor: Propagate errors from read_file()
This commit is contained in:
parent
3454185d08
commit
a053807be5
3 changed files with 9 additions and 11 deletions
|
@ -276,7 +276,8 @@ MainWidget::MainWidget()
|
||||||
if (response.is_error())
|
if (response.is_error())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
read_file(response.value().filename(), response.value().stream());
|
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);
|
||||||
});
|
});
|
||||||
|
|
||||||
m_save_as_action = GUI::CommonActions::make_save_as_action([&](auto&) {
|
m_save_as_action = GUI::CommonActions::make_save_as_action([&](auto&) {
|
||||||
|
@ -746,15 +747,12 @@ void MainWidget::update_title()
|
||||||
window()->set_title(builder.to_deprecated_string());
|
window()->set_title(builder.to_deprecated_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MainWidget::read_file(String const& filename, Core::Stream::File& file)
|
ErrorOr<void> MainWidget::read_file(String const& filename, Core::Stream::File& file)
|
||||||
{
|
{
|
||||||
auto result = file.read_until_eof();
|
m_editor->set_text(TRY(file.read_until_eof()));
|
||||||
if (result.is_error())
|
|
||||||
return false;
|
|
||||||
m_editor->set_text(result.value());
|
|
||||||
set_path(filename);
|
set_path(filename);
|
||||||
m_editor->set_focus(true);
|
m_editor->set_focus(true);
|
||||||
return true;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWidget::open_nonexistent_file(DeprecatedString const& path)
|
void MainWidget::open_nonexistent_file(DeprecatedString const& path)
|
||||||
|
@ -809,7 +807,8 @@ void MainWidget::drop_event(GUI::DropEvent& event)
|
||||||
auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(window(), urls.first().path());
|
auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(window(), urls.first().path());
|
||||||
if (response.is_error())
|
if (response.is_error())
|
||||||
return;
|
return;
|
||||||
read_file(response.value().filename(), response.value().stream());
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ class MainWidget final : public GUI::Widget {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~MainWidget() override = default;
|
virtual ~MainWidget() override = default;
|
||||||
bool read_file(String const& filename, Core::Stream::File&);
|
ErrorOr<void> read_file(String const& filename, Core::Stream::File&);
|
||||||
void open_nonexistent_file(DeprecatedString const& path);
|
void open_nonexistent_file(DeprecatedString const& path);
|
||||||
bool request_close();
|
bool request_close();
|
||||||
|
|
||||||
|
|
|
@ -81,8 +81,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
else
|
else
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
if (!text_widget->read_file(response.value().filename(), response.value().stream()))
|
TRY(text_widget->read_file(response.value().filename(), response.value().stream()));
|
||||||
return 1;
|
|
||||||
text_widget->editor().set_cursor_and_focus_line(parsed_argument.line().value_or(1) - 1, parsed_argument.column().value_or(0));
|
text_widget->editor().set_cursor_and_focus_line(parsed_argument.line().value_or(1) - 1, parsed_argument.column().value_or(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue