mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 01:47:34 +00:00
LibGUI: Fix FileSystemModel/FileManager after aeee98b
Previously, the null state of m_root_path was use to (subtly) mark the
parent of the root. The empty path is always replaced with "." so after
aeee98b
there was no "parent of root" node. This lead to the file
manager crashing when opened.
This commit is contained in:
parent
6f783929dd
commit
f0cd7adaf8
2 changed files with 13 additions and 13 deletions
|
@ -232,8 +232,8 @@ Optional<FileSystemModel::Node const&> 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<DeprecatedString> 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<DeprecatedString> 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();
|
||||
|
|
|
@ -102,14 +102,14 @@ public:
|
|||
OwnPtr<Node> create_child(DeprecatedString const& child_name);
|
||||
};
|
||||
|
||||
static NonnullRefPtr<FileSystemModel> create(DeprecatedString root_path = "/", Mode mode = Mode::FilesAndDirectories)
|
||||
static NonnullRefPtr<FileSystemModel> create(Optional<DeprecatedString> 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>);
|
||||
DeprecatedString full_path(ModelIndex const&) const;
|
||||
ModelIndex index(DeprecatedString path, int column) const;
|
||||
|
||||
|
@ -153,7 +153,7 @@ public:
|
|||
void set_allowed_file_extensions(Optional<Vector<DeprecatedString>> const& allowed_file_extensions);
|
||||
|
||||
private:
|
||||
FileSystemModel(DeprecatedString root_path, Mode);
|
||||
FileSystemModel(Optional<DeprecatedString> 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<DeprecatedString> m_root_path;
|
||||
Mode m_mode { Invalid };
|
||||
OwnPtr<Node> m_root { nullptr };
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue