diff options
Diffstat (limited to 'editor/filesystem_dock.cpp')
| -rw-r--r-- | editor/filesystem_dock.cpp | 128 |
1 files changed, 41 insertions, 87 deletions
diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp index 1ac66fdd1d..bd69fa7cdf 100644 --- a/editor/filesystem_dock.cpp +++ b/editor/filesystem_dock.cpp @@ -66,7 +66,7 @@ bool FileSystemDock::_create_tree(TreeItem *p_parent, EditorFileSystemDirectory subdirectory_item->set_selectable(0, true); String lpath = p_dir->get_path(); subdirectory_item->set_metadata(0, lpath); - if (!p_select_in_favorites && (path == lpath || ((display_mode_setting == DISPLAY_MODE_SETTING_SPLIT) && path.get_base_dir() == lpath))) { + if (!p_select_in_favorites && (path == lpath || ((display_mode == DISPLAY_MODE_SPLIT) && path.get_base_dir() == lpath))) { subdirectory_item->select(0); } @@ -84,13 +84,13 @@ bool FileSystemDock::_create_tree(TreeItem *p_parent, EditorFileSystemDirectory parent_should_expand = (_create_tree(subdirectory_item, p_dir->get_subdir(i), uncollapsed_paths, p_select_in_favorites) || parent_should_expand); // Create all items for the files in the subdirectory - if (display_mode_setting == DISPLAY_MODE_SETTING_TREE_ONLY) { + if (display_mode == DISPLAY_MODE_TREE_ONLY) { for (int i = 0; i < p_dir->get_file_count(); i++) { String file_name = p_dir->get_file(i); if (searched_string.length() > 0) { if (file_name.to_lower().find(searched_string) < 0) { - // The seached string is not in the file name, we skip it + // The searched string is not in the file name, we skip it continue; } else { // We expand all parents @@ -229,19 +229,20 @@ void FileSystemDock::_update_tree(const Vector<String> p_uncollapsed_paths, bool updating_tree = false; } +void FileSystemDock::set_display_mode(DisplayMode p_display_mode) { + display_mode = p_display_mode; + _update_display_mode(false); +} + void FileSystemDock::_update_display_mode(bool p_force) { // Compute the new display mode - DisplayMode new_display_mode = (display_mode_setting == DISPLAY_MODE_SETTING_TREE_ONLY) ? DISPLAY_MODE_TREE_ONLY : DISPLAY_MODE_SPLIT; - - if (p_force || new_display_mode != display_mode || old_display_mode_setting != display_mode_setting) { - display_mode = new_display_mode; - old_display_mode_setting = display_mode_setting; - button_toggle_display_mode->set_pressed(display_mode_setting == DISPLAY_MODE_SETTING_SPLIT ? true : false); + if (p_force || old_display_mode != display_mode) { + button_toggle_display_mode->set_pressed(display_mode == DISPLAY_MODE_SPLIT ? true : false); switch (display_mode) { case DISPLAY_MODE_TREE_ONLY: tree->show(); tree->set_v_size_flags(SIZE_EXPAND_FILL); - if (display_mode_setting == DISPLAY_MODE_SETTING_TREE_ONLY) { + if (display_mode == DISPLAY_MODE_TREE_ONLY) { tree_search_box->show(); } else { tree_search_box->hide(); @@ -262,6 +263,7 @@ void FileSystemDock::_update_display_mode(bool p_force) { _update_file_list(true); break; } + old_display_mode = display_mode; } } @@ -269,9 +271,6 @@ void FileSystemDock::_notification(int p_what) { switch (p_what) { - case NOTIFICATION_RESIZED: { - _update_display_mode(); - } break; case NOTIFICATION_ENTER_TREE: { if (initialized) @@ -284,8 +283,7 @@ void FileSystemDock::_notification(int p_what) { String ei = "EditorIcons"; button_reload->set_icon(get_icon("Reload", ei)); button_toggle_display_mode->set_icon(get_icon("Panels2", ei)); - _update_file_list_display_mode_button(); - button_file_list_display_mode->connect("pressed", this, "_change_file_display"); + button_file_list_display_mode->connect("pressed", this, "_toggle_file_display"); files->connect("item_activated", this, "_file_list_activate_file"); button_hist_next->connect("pressed", this, "_fw_history"); @@ -302,9 +300,10 @@ void FileSystemDock::_notification(int p_what) { current_path->connect("text_entered", this, "_navigate_to_path"); - display_mode_setting = DisplayModeSetting(int(EditorSettings::get_singleton()->get("docks/filesystem/display_mode"))); always_show_folders = bool(EditorSettings::get_singleton()->get("docks/filesystem/always_show_folders")); + set_file_list_display_mode(FileSystemDock::FILE_LIST_DISPLAY_LIST); + _update_display_mode(); if (EditorFileSystem::get_singleton()->is_scanning()) { @@ -351,7 +350,7 @@ void FileSystemDock::_notification(int p_what) { button_toggle_display_mode->set_icon(get_icon("Panels2", ei)); button_hist_next->set_icon(get_icon("Forward", ei)); button_hist_prev->set_icon(get_icon("Back", ei)); - if (button_file_list_display_mode->is_pressed()) { + if (file_list_display_mode == FILE_LIST_DISPLAY_LIST) { button_file_list_display_mode->set_icon(get_icon("FileThumbnail", "EditorIcons")); } else { button_file_list_display_mode->set_icon(get_icon("FileList", "EditorIcons")); @@ -362,27 +361,10 @@ void FileSystemDock::_notification(int p_what) { file_list_search_box->set_right_icon(get_icon("Search", ei)); file_list_search_box->set_clear_button_enabled(true); - bool should_update_files = false; - - // Update file list display mode - int new_file_list_mode = int(EditorSettings::get_singleton()->get("docks/filesystem/files_display_mode")); - if (new_file_list_mode != file_list_display_mode) { - set_file_list_display_mode(new_file_list_mode); - _update_file_list_display_mode_button(); - should_update_files = true; - } - - // Update display of files in tree - display_mode_setting = DisplayModeSetting(int(EditorSettings::get_singleton()->get("docks/filesystem/display_mode"))); - - // Update allways showfolders + // Update always showfolders bool new_always_show_folders = bool(EditorSettings::get_singleton()->get("docks/filesystem/always_show_folders")); if (new_always_show_folders != always_show_folders) { always_show_folders = new_always_show_folders; - should_update_files = true; - } - - if (should_update_files) { _update_file_list(true); } @@ -519,9 +501,13 @@ void FileSystemDock::_tree_thumbnail_done(const String &p_path, const Ref<Textur } } -void FileSystemDock::_update_file_list_display_mode_button() { +void FileSystemDock::_toggle_file_display() { + _set_file_display(file_list_display_mode != FILE_LIST_DISPLAY_LIST); + emit_signal("display_mode_changed"); +} - if (button_file_list_display_mode->is_pressed()) { +void FileSystemDock::_set_file_display(bool p_active) { + if (p_active) { file_list_display_mode = FILE_LIST_DISPLAY_LIST; button_file_list_display_mode->set_icon(get_icon("FileThumbnail", "EditorIcons")); button_file_list_display_mode->set_tooltip(TTR("View items as a grid of thumbnails.")); @@ -530,13 +516,6 @@ void FileSystemDock::_update_file_list_display_mode_button() { button_file_list_display_mode->set_icon(get_icon("FileList", "EditorIcons")); button_file_list_display_mode->set_tooltip(TTR("View items as a list.")); } -} - -void FileSystemDock::_change_file_display() { - - _update_file_list_display_mode_button(); - - EditorSettings::get_singleton()->set("docks/filesystem/files_display_mode", file_list_display_mode); _update_file_list(true); } @@ -1695,9 +1674,8 @@ void FileSystemDock::_rescan() { } void FileSystemDock::_toggle_split_mode(bool p_active) { - display_mode_setting = p_active ? DISPLAY_MODE_SETTING_SPLIT : DISPLAY_MODE_SETTING_TREE_ONLY; - EditorSettings::get_singleton()->set("docks/filesystem/display_mode", int(display_mode_setting)); - _update_display_mode(); + set_display_mode(p_active ? DISPLAY_MODE_SPLIT : DISPLAY_MODE_TREE_ONLY); + emit_signal("display_mode_changed"); } void FileSystemDock::fix_dependencies(const String &p_for_file) { @@ -1709,13 +1687,12 @@ void FileSystemDock::focus_on_filter() { file_list_search_box->grab_focus(); } -void FileSystemDock::set_file_list_display_mode(int p_mode) { +void FileSystemDock::set_file_list_display_mode(FileListDisplayMode p_mode) { if (p_mode == file_list_display_mode) return; - button_file_list_display_mode->set_pressed(p_mode == FILE_LIST_DISPLAY_LIST); - _change_file_display(); + _toggle_file_display(); } Variant FileSystemDock::get_drag_data_fw(const Point2 &p_point, Control *p_from) { @@ -1855,7 +1832,7 @@ void FileSystemDock::drop_data_fw(const Point2 &p_point, const Variant &p_data, // Drop on the favorite folder drop_position = 0; } else if (ti == resources_item) { - // Drop on the resouce item + // Drop on the resource item drop_position = dirs.size(); } else { // Drop in the list @@ -2046,10 +2023,10 @@ void FileSystemDock::_file_and_folders_fill_popup(PopupMenu *p_popup, Vector<Str if (p_paths.size() >= 1) { if (!all_favorites) { - p_popup->add_item(TTR("Add to favorites"), FILE_ADD_FAVORITE); + p_popup->add_item(TTR("Add to Favorites"), FILE_ADD_FAVORITE); } if (!all_not_favorites) { - p_popup->add_item(TTR("Remove from favorites"), FILE_REMOVE_FAVORITE); + p_popup->add_item(TTR("Remove from Favorites"), FILE_REMOVE_FAVORITE); } p_popup->add_separator(); } @@ -2157,7 +2134,7 @@ void FileSystemDock::select_file(const String &p_file) { void FileSystemDock::_file_multi_selected(int p_index, bool p_selected) { - // Set the path to the current focussed item + // Set the path to the current focused item int current = files->get_current(); if (current == p_index) { String fpath = files->get_item_metadata(current); @@ -2219,7 +2196,7 @@ void FileSystemDock::_update_import_dock() { // List selected Vector<String> selected; - if (display_mode_setting == DISPLAY_MODE_SETTING_TREE_ONLY) { + if (display_mode == DISPLAY_MODE_TREE_ONLY) { // Use the tree selected = _tree_get_selected(); @@ -2303,8 +2280,8 @@ void FileSystemDock::_bind_methods() { ClassDB::bind_method(D_METHOD("_file_list_activate_file"), &FileSystemDock::_file_list_activate_file); ClassDB::bind_method(D_METHOD("_tree_activate_file"), &FileSystemDock::_tree_activate_file); ClassDB::bind_method(D_METHOD("_select_file"), &FileSystemDock::_select_file); - ClassDB::bind_method(D_METHOD("_navigate_to_path"), &FileSystemDock::_navigate_to_path); - ClassDB::bind_method(D_METHOD("_change_file_display"), &FileSystemDock::_change_file_display); + ClassDB::bind_method(D_METHOD("_navigate_to_path"), &FileSystemDock::_navigate_to_path, DEFVAL(false)); + ClassDB::bind_method(D_METHOD("_toggle_file_display"), &FileSystemDock::_toggle_file_display); ClassDB::bind_method(D_METHOD("_fw_history"), &FileSystemDock::_fw_history); ClassDB::bind_method(D_METHOD("_bw_history"), &FileSystemDock::_bw_history); ClassDB::bind_method(D_METHOD("_fs_changed"), &FileSystemDock::_fs_changed); @@ -2334,6 +2311,8 @@ void FileSystemDock::_bind_methods() { ADD_SIGNAL(MethodInfo("folder_removed", PropertyInfo(Variant::STRING, "folder"))); ADD_SIGNAL(MethodInfo("files_moved", PropertyInfo(Variant::STRING, "old_file"), PropertyInfo(Variant::STRING, "new_file"))); ADD_SIGNAL(MethodInfo("folder_moved", PropertyInfo(Variant::STRING, "old_folder"), PropertyInfo(Variant::STRING, "new_file"))); + + ADD_SIGNAL(MethodInfo("display_mode_changed")); } FileSystemDock::FileSystemDock(EditorNode *p_editor) { @@ -2357,13 +2336,13 @@ FileSystemDock::FileSystemDock(EditorNode *p_editor) { button_hist_prev = memnew(ToolButton); button_hist_prev->set_disabled(true); button_hist_prev->set_focus_mode(FOCUS_NONE); - button_hist_prev->set_tooltip(TTR("Previous Directory")); + button_hist_prev->set_tooltip(TTR("Previous Folder/File")); toolbar_hbc->add_child(button_hist_prev); button_hist_next = memnew(ToolButton); button_hist_next->set_disabled(true); button_hist_next->set_focus_mode(FOCUS_NONE); - button_hist_next->set_tooltip(TTR("Next Directory")); + button_hist_next->set_tooltip(TTR("Next Folder/File")); toolbar_hbc->add_child(button_hist_next); current_path = memnew(LineEdit); @@ -2384,7 +2363,7 @@ FileSystemDock::FileSystemDock(EditorNode *p_editor) { button_toggle_display_mode->set_toggle_mode(true); button_toggle_display_mode->connect("toggled", this, "_toggle_split_mode"); button_toggle_display_mode->set_focus_mode(FOCUS_NONE); - button_toggle_display_mode->set_tooltip(TTR("Toggle split mode")); + button_toggle_display_mode->set_tooltip(TTR("Toggle Split Mode")); toolbar_hbc->add_child(button_toggle_display_mode); HBoxContainer *toolbar2_hbc = memnew(HBoxContainer); @@ -2397,29 +2376,6 @@ FileSystemDock::FileSystemDock(EditorNode *p_editor) { tree_search_box->connect("text_changed", this, "_search_changed", varray(tree_search_box)); toolbar2_hbc->add_child(tree_search_box); - //toolbar_hbc->add_spacer(); - - //Control *spacer = memnew( Control); - - /* - button_open = memnew( Button ); - button_open->set_flat(true); - button_open->connect("pressed",this,"_tree_toggle_collapsed"); - toolbar_hbc->add_child(button_open); - button_open->hide(); - button_open->set_focus_mode(FOCUS_NONE); - button_open->set_tooltip("Open the selected file.\nOpen as scene if a scene, or as resource otherwise."); - - - button_instance = memnew( Button ); - button_instance->set_flat(true); - button_instance->connect("pressed",this,"_instance_pressed"); - toolbar_hbc->add_child(button_instance); - button_instance->hide(); - button_instance->set_focus_mode(FOCUS_NONE); - button_instance->set_tooltip(TTR("Instance the selected scene(s) as child of the selected node.")); - -*/ file_list_popup = memnew(PopupMenu); file_list_popup->set_hide_on_window_lose_focus(true); add_child(file_list_popup); @@ -2461,7 +2417,6 @@ FileSystemDock::FileSystemDock(EditorNode *p_editor) { path_hb->add_child(file_list_search_box); button_file_list_display_mode = memnew(ToolButton); - button_file_list_display_mode->set_toggle_mode(true); path_hb->add_child(button_file_list_display_mode); files = memnew(ItemList); @@ -2564,11 +2519,10 @@ FileSystemDock::FileSystemDock(EditorNode *p_editor) { history_max_size = 20; history.push_back("res://"); - display_mode = DISPLAY_MODE_SPLIT; + display_mode = DISPLAY_MODE_TREE_ONLY; + old_display_mode = DISPLAY_MODE_TREE_ONLY; file_list_display_mode = FILE_LIST_DISPLAY_THUMBNAILS; - display_mode_setting = DISPLAY_MODE_SETTING_TREE_ONLY; - old_display_mode_setting = DISPLAY_MODE_SETTING_TREE_ONLY; always_show_folders = false; } |
