Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix root folder logic in the filesystem #100161

Merged
merged 1 commit into from
Jan 3, 2025

Conversation

alessand10
Copy link
Contributor

This PR should:
Fix #100159
Fix #99932

The previous logic appears to check that the root folder is not selected using the following bit of logic:

p_paths[0] != "res://"

But the function that populates p_path, which is _tree_get_selected(...), inserts the actively selected item at p_path[0]. This means that the root folder may still be selected, but may not be the first element in p_path:

Vector<String> FileSystemDock::_tree_get_selected(bool remove_self_inclusion, bool p_include_unselected_cursor) const {
	// Build a list of selected items with the active one at the first position.
	Vector<String> selected_strings;

	TreeItem *cursor_item = tree->get_selected();
	if (cursor_item && (p_include_unselected_cursor || cursor_item->is_selected(0)) && cursor_item != favorites_item) {
		selected_strings.push_back(cursor_item->get_metadata(0));
	}
        ... 

The root folder will only be at p_path[0] if it is the actively selected item, but otherwise it will exist at p_path[1]. To compensate for this, I have added an additional check that verifies that the root folder is not at p_path[0] and also not at p_path[1] before determining if the root folder is selected:

bool root_path_not_selected = p_paths[0] != "res://" && (p_paths.size() <= 1 || p_paths[1] != "res://");

@alessand10 alessand10 requested a review from a team as a code owner December 8, 2024 00:28
@Chaosus Chaosus added this to the 4.4 milestone Dec 8, 2024
Copy link
Member

@KoBeWi KoBeWi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like res:// is reliably either at p_paths[0] or p_paths[1], so this works 🤔

@akien-mga akien-mga force-pushed the fix-filesystem-logic branch from 2b2489d to e330b79 Compare January 2, 2025 16:51
@akien-mga akien-mga merged commit 3a20c3e into godotengine:master Jan 3, 2025
20 checks passed
@akien-mga
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Root folder color can be changed if selected in a particular order Folder color is bugged in FileSystem
4 participants