summaryrefslogtreecommitdiff
path: root/Userland/Applications
diff options
context:
space:
mode:
authorLucas CHOLLET <lucas.chollet@free.fr>2023-01-14 17:45:51 -0500
committerJelle Raaijmakers <jelle@gmta.nl>2023-02-03 19:58:41 +0100
commit40f9cf2de64530b06af506596adec1316c3a5f7e (patch)
tree2df6d1b84d7db3f906119ce21c7d6250cace4df0 /Userland/Applications
parent36e66502c98e24fcfe14bc0f2c5ac4584c3e1267 (diff)
downloadserenity-40f9cf2de64530b06af506596adec1316c3a5f7e.zip
TextEditor: Port to `Core::Stream`
Diffstat (limited to 'Userland/Applications')
-rw-r--r--Userland/Applications/TextEditor/MainWidget.cpp29
-rw-r--r--Userland/Applications/TextEditor/MainWidget.h2
-rw-r--r--Userland/Applications/TextEditor/main.cpp4
3 files changed, 19 insertions, 16 deletions
diff --git a/Userland/Applications/TextEditor/MainWidget.cpp b/Userland/Applications/TextEditor/MainWidget.cpp
index dac25b150f..69872cd8fe 100644
--- a/Userland/Applications/TextEditor/MainWidget.cpp
+++ b/Userland/Applications/TextEditor/MainWidget.cpp
@@ -272,11 +272,11 @@ MainWidget::MainWidget()
return;
}
- auto response = FileSystemAccessClient::Client::the().try_open_file_deprecated(window());
+ auto response = FileSystemAccessClient::Client::the().open_file(window());
if (response.is_error())
return;
- read_file(*response.value());
+ read_file(response.value().filename(), response.value().stream());
});
m_save_as_action = GUI::CommonActions::make_save_as_action([&](auto&) {
@@ -284,18 +284,18 @@ MainWidget::MainWidget()
if (extension.is_null() && m_editor->syntax_highlighter())
extension = Syntax::common_language_extension(m_editor->syntax_highlighter()->language());
- auto response = FileSystemAccessClient::Client::the().try_save_file_deprecated(window(), m_name, extension);
+ auto response = FileSystemAccessClient::Client::the().save_file(window(), m_name, extension);
if (response.is_error())
return;
auto file = response.release_value();
- if (!m_editor->write_to_file(*file)) {
+ if (auto result = m_editor->write_to_file(file.stream()); result.is_error()) {
GUI::MessageBox::show(window(), "Unable to save file.\n"sv, "Error"sv, GUI::MessageBox::Type::Error);
return;
}
- set_path(file->filename());
- dbgln("Wrote document to {}", file->filename());
+ set_path(file.filename());
+ dbgln("Wrote document to {}", file.filename());
});
m_save_action = GUI::CommonActions::make_save_action([&](auto&) {
@@ -303,11 +303,11 @@ MainWidget::MainWidget()
m_save_as_action->activate();
return;
}
- auto response = FileSystemAccessClient::Client::the().try_request_file_deprecated(window(), m_path, Core::OpenMode::Truncate | Core::OpenMode::WriteOnly);
+ auto response = FileSystemAccessClient::Client::the().request_file(window(), m_path, Core::Stream::OpenMode::Truncate | Core::Stream::OpenMode::Write);
if (response.is_error())
return;
- if (!m_editor->write_to_file(*response.value())) {
+ if (auto result = m_editor->write_to_file(response.value().stream()); result.is_error()) {
GUI::MessageBox::show(window(), "Unable to save file.\n"sv, "Error"sv, GUI::MessageBox::Type::Error);
}
});
@@ -746,10 +746,13 @@ void MainWidget::update_title()
window()->set_title(builder.to_deprecated_string());
}
-bool MainWidget::read_file(Core::File& file)
+bool MainWidget::read_file(String const& filename, Core::Stream::File& file)
{
- m_editor->set_text(file.read_all());
- set_path(file.filename());
+ auto result = file.read_until_eof();
+ if (result.is_error())
+ return false;
+ m_editor->set_text(result.value());
+ set_path(filename);
m_editor->set_focus(true);
return true;
}
@@ -804,10 +807,10 @@ void MainWidget::drop_event(GUI::DropEvent& event)
return;
// TODO: A drop event should be considered user consent for opening a file
- auto response = FileSystemAccessClient::Client::the().try_request_file_deprecated(window(), urls.first().path(), Core::OpenMode::ReadOnly);
+ auto response = FileSystemAccessClient::Client::the().request_file(window(), urls.first().path(), Core::Stream::OpenMode::Read);
if (response.is_error())
return;
- read_file(*response.value());
+ read_file(response.value().filename(), response.value().stream());
}
}
diff --git a/Userland/Applications/TextEditor/MainWidget.h b/Userland/Applications/TextEditor/MainWidget.h
index 49e78fe264..c21638e9bd 100644
--- a/Userland/Applications/TextEditor/MainWidget.h
+++ b/Userland/Applications/TextEditor/MainWidget.h
@@ -25,7 +25,7 @@ class MainWidget final : public GUI::Widget {
public:
virtual ~MainWidget() override = default;
- bool read_file(Core::File&);
+ bool read_file(String const& filename, Core::Stream::File&);
void open_nonexistent_file(DeprecatedString const& path);
bool request_close();
diff --git a/Userland/Applications/TextEditor/main.cpp b/Userland/Applications/TextEditor/main.cpp
index 178e3848b3..b7368f3ff5 100644
--- a/Userland/Applications/TextEditor/main.cpp
+++ b/Userland/Applications/TextEditor/main.cpp
@@ -73,7 +73,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
if (file_to_edit) {
FileArgument parsed_argument(file_to_edit);
- auto response = FileSystemAccessClient::Client::the().try_request_file_read_only_approved_deprecated(window, parsed_argument.filename());
+ auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(window, parsed_argument.filename());
if (response.is_error()) {
if (response.error().code() == ENOENT)
@@ -81,7 +81,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
else
return 1;
} else {
- if (!text_widget->read_file(*response.value()))
+ if (!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));
}