Skip to content

Commit

Permalink
Make sure that the FileSystem is made visible properly when needed in…
Browse files Browse the repository at this point in the history
… both it's normal and it's bottom bar mode.
  • Loading branch information
Relintai committed Oct 13, 2023
1 parent e1f64a8 commit 3b5bd39
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 11 deletions.
1 change: 1 addition & 0 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6960,6 +6960,7 @@ EditorNode::EditorNode() {
if (filesystem_dock_wide) {
filesystem_dock->set_custom_minimum_size(Size2(0, 230 * EDSCALE));
ToolButton *fs_button = add_bottom_panel_item(TTR("FileSystem"), filesystem_dock);
filesystem_dock->set_bottom_panel_tool_button(fs_button);
fs_button->set_shortcut(ED_SHORTCUT("editor/toggle_filesystem_panel", TTR("Toggle FileSystem Panel"), KEY_MASK_CMD | KEY_MASK_ALT | KEY_QUOTELEFT));
}

Expand Down
5 changes: 1 addition & 4 deletions editor/editor_resource_picker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,10 +396,7 @@ void EditorResourcePicker::_edit_menu_cbk(int p_which) {
case OBJ_MENU_SHOW_IN_FILE_SYSTEM: {
FileSystemDock *file_system_dock = EditorNode::get_singleton()->get_filesystem_dock();
file_system_dock->navigate_to_path(edited_resource->get_path());

// Ensure that the FileSystem dock is visible.
TabContainer *tab_container = (TabContainer *)file_system_dock->get_parent_control();
tab_container->set_current_tab(file_system_dock->get_index());
file_system_dock->ensure_visible();
} break;

default: {
Expand Down
23 changes: 23 additions & 0 deletions editor/filesystem_dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
#include "scene/gui/popup_menu.h"
#include "scene/gui/progress_bar.h"
#include "scene/gui/scroll_bar.h"
#include "scene/gui/tab_container.h"
#include "scene/gui/tool_button.h"
#include "scene/gui/tree.h"
#include "scene/main/node.h"
Expand Down Expand Up @@ -2094,6 +2095,24 @@ void FileSystemDock::remove_custom_popup_creation_entry(const int id) {
}
}

void FileSystemDock::ensure_visible() {
if (display_mode == DISPLAY_MODE_WIDE) {
if (bottom_panel_tool_button) {
bottom_panel_tool_button->set_pressed(true);
}
} else {
// Ensure that the FileSystem dock is visible.
TabContainer *tab_container = (TabContainer *)get_parent_control();

if (tab_container) {
tab_container->set_current_tab(get_position_in_parent());
}
}
}
void FileSystemDock::set_bottom_panel_tool_button(ToolButton *fs_button) {
bottom_panel_tool_button = fs_button;
}

Variant FileSystemDock::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
bool all_favorites = true;
bool all_not_favorites = true;
Expand Down Expand Up @@ -2853,6 +2872,7 @@ void FileSystemDock::_bind_methods() {
ClassDB::bind_method(D_METHOD("can_drop_data_fw", "point", "data", "from"), &FileSystemDock::can_drop_data_fw);
ClassDB::bind_method(D_METHOD("drop_data_fw", "point", "data", "from"), &FileSystemDock::drop_data_fw);
ClassDB::bind_method(D_METHOD("navigate_to_path", "path"), &FileSystemDock::navigate_to_path);
ClassDB::bind_method(D_METHOD("ensure_visible"), &FileSystemDock::ensure_visible);

ClassDB::bind_method(D_METHOD("_preview_invalidated"), &FileSystemDock::_preview_invalidated);
ClassDB::bind_method(D_METHOD("_file_multi_selected"), &FileSystemDock::_file_multi_selected);
Expand All @@ -2876,6 +2896,9 @@ FileSystemDock::FileSystemDock(EditorNode *p_editor) {
editor = p_editor;
path = "res://";

file_sort = FILE_SORT_NAME;
bottom_panel_tool_button = NULL;

// `KEY_MASK_CMD | KEY_C` conflicts with other editor shortcuts.
ED_SHORTCUT("filesystem_dock/copy_path", TTR("Copy Path"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_C);
ED_SHORTCUT("filesystem_dock/duplicate", TTR("Duplicate..."), KEY_MASK_CMD | KEY_D);
Expand Down
8 changes: 7 additions & 1 deletion editor/filesystem_dock.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class TextureRect;
class Tree;
class TreeItem;
class DirectoryCreateDialog;
class ToolButton;

class FileSystemDock : public VBoxContainer {
GDCLASS(FileSystemDock, VBoxContainer);
Expand Down Expand Up @@ -122,7 +123,9 @@ class FileSystemDock : public VBoxContainer {
FILE_NEW_CUSTOM_ENTRY_START,
};

FileSortOption file_sort = FILE_SORT_NAME;
FileSortOption file_sort;

ToolButton *bottom_panel_tool_button;

VBoxContainer *scanning_vb;
ProgressBar *scanning_progress;
Expand Down Expand Up @@ -369,6 +372,9 @@ class FileSystemDock : public VBoxContainer {
int add_custom_popup_creation_entry(const String &entry_text, const String &theme_icon_name = "", const String &theme_icon_category = "");
void remove_custom_popup_creation_entry(const int id);

void ensure_visible();
void set_bottom_panel_tool_button(ToolButton *fs_button);

FileSystemDock(EditorNode *p_editor);
~FileSystemDock();
};
Expand Down
4 changes: 1 addition & 3 deletions editor/property_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,7 @@ void CustomPropertyEditor::_menu_option(int p_which) {
RES r = v;
FileSystemDock *file_system_dock = EditorNode::get_singleton()->get_filesystem_dock();
file_system_dock->navigate_to_path(r->get_path());
// Ensure that the FileSystem dock is visible.
TabContainer *tab_container = (TabContainer *)file_system_dock->get_parent_control();
tab_container->set_current_tab(file_system_dock->get_position_in_parent());
file_system_dock->ensure_visible();
} break;
default: {
if (p_which >= CONVERT_BASE_ID) {
Expand Down
4 changes: 1 addition & 3 deletions editor_modules/editor_code_editor/editor_script_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1151,9 +1151,7 @@ void EditorScriptEditor::_menu_option(int p_option) {

FileSystemDock *file_system_dock = EditorNode::get_singleton()->get_filesystem_dock();
file_system_dock->navigate_to_path(path);
// Ensure that the FileSystem dock is visible.
TabContainer *tab_container = (TabContainer *)file_system_dock->get_parent_control();
tab_container->set_current_tab(file_system_dock->get_position_in_parent());
file_system_dock->ensure_visible();
}
} break;
case CLOSE_DOCS: {
Expand Down

0 comments on commit 3b5bd39

Please sign in to comment.