mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-13 11:42:38 +03:00
TextEditor: Remove unveil() for CLI file, use FileSystemAccessServer
Previously we unveiled the file specified through the command-line interface. Now, we just make the request through the FileSystemAccessServer instead.
This commit is contained in:
parent
8378ecc67b
commit
3a7e42ba73
Notes:
sideshowbarker
2024-07-18 04:20:01 +09:00
Author: https://github.com/mustafaquraish Commit: https://github.com/SerenityOS/serenity/commit/3a7e42ba73b Pull-request: https://github.com/SerenityOS/serenity/pull/9854 Reviewed-by: https://github.com/IdanHo Reviewed-by: https://github.com/alimpfard
@ -10,6 +10,7 @@
|
||||
#include <LibCore/ArgsParser.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <LibCore/StandardPaths.h>
|
||||
#include <LibFileSystemAccessClient/Client.h>
|
||||
#include <LibGUI/Menubar.h>
|
||||
#include <LibGUI/MessageBox.h>
|
||||
|
||||
@ -34,22 +35,6 @@ int main(int argc, char** argv)
|
||||
|
||||
parser.parse(argc, argv);
|
||||
|
||||
String file_to_edit_full_path;
|
||||
|
||||
if (file_to_edit) {
|
||||
FileArgument parsed_argument(file_to_edit);
|
||||
|
||||
file_to_edit_full_path = Core::File::absolute_path(parsed_argument.filename());
|
||||
VERIFY(!file_to_edit_full_path.is_empty());
|
||||
if (Core::File::exists(parsed_argument.filename())) {
|
||||
dbgln("unveil for: {}", file_to_edit_full_path);
|
||||
if (unveil(file_to_edit_full_path.characters(), "r") < 0) {
|
||||
perror("unveil");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (unveil("/res", "r") < 0) {
|
||||
perror("unveil");
|
||||
return 1;
|
||||
@ -104,29 +89,22 @@ int main(int argc, char** argv)
|
||||
|
||||
text_widget.initialize_menubar(*window);
|
||||
|
||||
window->show();
|
||||
window->set_icon(app_icon.bitmap_for_size(16));
|
||||
|
||||
if (file_to_edit) {
|
||||
// A file name was passed, parse any possible line and column numbers included.
|
||||
FileArgument parsed_argument(file_to_edit);
|
||||
if (Core::File::exists(file_to_edit_full_path)) {
|
||||
auto file = Core::File::open(file_to_edit_full_path, Core::OpenMode::ReadOnly);
|
||||
auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(window->window_id(), parsed_argument.filename());
|
||||
|
||||
if (file.is_error()) {
|
||||
GUI::MessageBox::show_error(window, String::formatted("Opening \"{}\" failed: {}", file_to_edit_full_path, file.error()));
|
||||
if (response.error == 0) {
|
||||
if (!text_widget.read_file_and_close(*response.fd, *response.chosen_file))
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!text_widget.read_file_and_close(file.value()->leak_fd(), file_to_edit_full_path))
|
||||
return 1;
|
||||
|
||||
text_widget.editor().set_cursor_and_focus_line(parsed_argument.line().value_or(1) - 1, parsed_argument.column().value_or(0));
|
||||
} else {
|
||||
text_widget.open_nonexistent_file(file_to_edit_full_path);
|
||||
text_widget.open_nonexistent_file(parsed_argument.filename());
|
||||
}
|
||||
}
|
||||
text_widget.update_title();
|
||||
|
||||
window->show();
|
||||
window->set_icon(app_icon.bitmap_for_size(16));
|
||||
|
||||
return app->exec();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user