diff options
author | Timothy <timmot@users.noreply.github.com> | 2021-06-30 06:13:06 -0700 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-07-10 15:33:46 +0200 |
commit | 73ae5200a9701f104726b673752752250beafa4d (patch) | |
tree | bd021cab74749eb840ddddc88c1cdb536ab53e6c /Userland/Libraries | |
parent | 41ce2debda1de75f80a4971afbf5ec7dcddf5ba3 (diff) | |
download | serenity-73ae5200a9701f104726b673752752250beafa4d.zip |
TextEditor+LibGUI: Use unveil and FileSystemAccessServer
Making use of the new FileSystemAccessServer we are able to use
unveil without restricting our ability to open and save files.
A file argument will be unveiled automatically however all other files
require user action via the FileSystemAccessServer to gain access.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibGUI/TextEditor.cpp | 7 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/TextEditor.h | 3 |
2 files changed, 8 insertions, 2 deletions
diff --git a/Userland/Libraries/LibGUI/TextEditor.cpp b/Userland/Libraries/LibGUI/TextEditor.cpp index 3a9617d0e8..bf7e18fa4d 100644 --- a/Userland/Libraries/LibGUI/TextEditor.cpp +++ b/Userland/Libraries/LibGUI/TextEditor.cpp @@ -1198,7 +1198,7 @@ void TextEditor::timer_event(Core::TimerEvent&) update_cursor(); } -bool TextEditor::write_to_file(const String& path) +bool TextEditor::write_to_file(String const& path) { int fd = open(path.characters(), O_WRONLY | O_CREAT | O_TRUNC, 0666); if (fd < 0) { @@ -1206,6 +1206,11 @@ bool TextEditor::write_to_file(const String& path) return false; } + return write_to_file_and_close(fd); +} + +bool TextEditor::write_to_file_and_close(int fd) +{ ScopeGuard fd_guard = [fd] { close(fd); }; off_t file_size = 0; diff --git a/Userland/Libraries/LibGUI/TextEditor.h b/Userland/Libraries/LibGUI/TextEditor.h index ecbbf53eae..a287c0c6b1 100644 --- a/Userland/Libraries/LibGUI/TextEditor.h +++ b/Userland/Libraries/LibGUI/TextEditor.h @@ -116,7 +116,8 @@ public: TextRange normalized_selection() const { return m_selection.normalized(); } void insert_at_cursor_or_replace_selection(const StringView&); - bool write_to_file(const String& path); + bool write_to_file(String const& path); + bool write_to_file_and_close(int fd); bool has_selection() const { return m_selection.is_valid(); } String selected_text() const; size_t number_of_selected_words() const; |