mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 16:18:12 +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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue