diff --git a/Userland/Libraries/LibGUI/FileSystemModel.cpp b/Userland/Libraries/LibGUI/FileSystemModel.cpp index 1d9dd4b1582..6b7266ecbdb 100644 --- a/Userland/Libraries/LibGUI/FileSystemModel.cpp +++ b/Userland/Libraries/LibGUI/FileSystemModel.cpp @@ -232,8 +232,8 @@ Optional FileSystemModel::node_for_path(Deprecated DeprecatedString resolved_path; if (path == m_root_path) resolved_path = "/"; - else if (!m_root_path.is_empty() && path.starts_with(m_root_path)) - resolved_path = LexicalPath::relative_path(path, m_root_path); + else if (m_root_path.has_value() && !m_root_path->is_empty() && path.starts_with(*m_root_path)) + resolved_path = LexicalPath::relative_path(path, *m_root_path); else resolved_path = path; LexicalPath lexical_path(resolved_path); @@ -269,8 +269,8 @@ DeprecatedString FileSystemModel::full_path(ModelIndex const& index) const return node.full_path(); } -FileSystemModel::FileSystemModel(DeprecatedString root_path, Mode mode) - : m_root_path(LexicalPath::canonicalized_path(move(root_path))) +FileSystemModel::FileSystemModel(Optional root_path, Mode mode) + : m_root_path(root_path.map(LexicalPath::canonicalized_path)) , m_mode(mode) { setpwent(); @@ -362,12 +362,12 @@ void FileSystemModel::update_node_on_selection(ModelIndex const& index, bool con node.set_selected(selected); } -void FileSystemModel::set_root_path(DeprecatedString root_path) +void FileSystemModel::set_root_path(Optional root_path) { - if (root_path.is_empty()) + if (!root_path.has_value()) m_root_path = {}; else - m_root_path = LexicalPath::canonicalized_path(move(root_path)); + m_root_path = LexicalPath::canonicalized_path(move(*root_path)); invalidate(); if (m_root->has_error()) { @@ -382,7 +382,7 @@ void FileSystemModel::invalidate() { m_root = adopt_own(*new Node(*this)); - if (m_root_path.is_empty()) + if (!m_root_path.has_value()) m_root->m_parent_of_root = true; m_root->reify_if_needed(); diff --git a/Userland/Libraries/LibGUI/FileSystemModel.h b/Userland/Libraries/LibGUI/FileSystemModel.h index 7eb13024583..ee14d668996 100644 --- a/Userland/Libraries/LibGUI/FileSystemModel.h +++ b/Userland/Libraries/LibGUI/FileSystemModel.h @@ -102,14 +102,14 @@ public: OwnPtr create_child(DeprecatedString const& child_name); }; - static NonnullRefPtr create(DeprecatedString root_path = "/", Mode mode = Mode::FilesAndDirectories) + static NonnullRefPtr create(Optional root_path = "/", Mode mode = Mode::FilesAndDirectories) { return adopt_ref(*new FileSystemModel(root_path, mode)); } virtual ~FileSystemModel() override = default; - DeprecatedString root_path() const { return m_root_path; } - void set_root_path(DeprecatedString); + DeprecatedString root_path() const { return m_root_path.value_or(""); } + void set_root_path(Optional); DeprecatedString full_path(ModelIndex const&) const; ModelIndex index(DeprecatedString path, int column) const; @@ -153,7 +153,7 @@ public: void set_allowed_file_extensions(Optional> const& allowed_file_extensions); private: - FileSystemModel(DeprecatedString root_path, Mode); + FileSystemModel(Optional root_path, Mode); DeprecatedString name_for_uid(uid_t) const; DeprecatedString name_for_gid(gid_t) const; @@ -168,7 +168,7 @@ private: void handle_file_event(Core::FileWatcherEvent const& event); - DeprecatedString m_root_path; + Optional m_root_path; Mode m_mode { Invalid }; OwnPtr m_root { nullptr };