diff --git a/modules/material_maker/editor/widgets/file_dialog/left_panel.cpp b/modules/material_maker/editor/widgets/file_dialog/left_panel.cpp index 062f0c034..9bb815c0f 100644 --- a/modules/material_maker/editor/widgets/file_dialog/left_panel.cpp +++ b/modules/material_maker/editor/widgets/file_dialog/left_panel.cpp @@ -1,167 +1,142 @@ #include "left_panel.h" +#include "core/os/keyboard.h" +#include "scene/gui/item_list.h" +#include "scene/gui/label.h" Array LeftPanel::get_recents() { - return recents; + return recents; } void LeftPanel::set_recents(const Array &val) { -recents = val; + recents = val; } - Array LeftPanel::get_favorites() { - return favorites; + return favorites; } void LeftPanel::set_favorites(const Array &val) { -favorites = val; + favorites = val; } +void LeftPanel::add_recent(const String &file_path) { + if (recents.find(file_path) != -1) { + recents.erase(file_path); + } - - //tool; - Array recents = []; - Array favorites = []; - signal open_directory(dirpath); - //func _ready():; - // if get_node("/root/MainWindow") != null:; - // var config_cache = get_node("/root/MainWindow").config_cache; - // if config_cache.has_section_key("file_dialog", "recents"):; - // var parse_result = JSON.parse(config_cache.get_value("file_dialog", "recents")); - // if parse_result != null:; - // recents = parse_result.result; - // if config_cache.has_section_key("file_dialog", "favorites"):; - // var parse_result = JSON.parse(config_cache.get_value("file_dialog", "favorites")); - // if parse_result != null:; - // favorites = parse_result.result; - // update_lists(); - //func _exit_tree():; - // if get_node("/root/MainWindow") != null:; - // var config_cache = get_node("/root/MainWindow").config_cache; - // config_cache.set_value("file_dialog", "recents", JSON.print(recents)); - // config_cache.set_value("file_dialog", "favorites", JSON.print(favorites)); - - void LeftPanel::add_recent(const String &file_path) { - - if (recents.find(file_path) != -1) { - recents.erase(file_path); + recents.push_front(file_path); + update_lists(); } - recents.push_front(file_path); - update_lists(); +void LeftPanel::add_favorite(const String &file_path) { + if (favorites.find(file_path) == -1) { + favorites.push_back(file_path); + update_lists(); + } } +String LeftPanel::my_basename(const String &s) { + int slash_pos = s.find_last("/"); - void LeftPanel::add_favorite(const String &file_path) { + if (slash_pos == -1 || slash_pos + 1 == s.length()) { + return s; + } - if (favorites.find(file_path) == -1) { - favorites.push_back(file_path); - update_lists(); + return s.right(slash_pos + 1); } +void LeftPanel::update_lists() { + _fav_list->clear(); + + for (int i = 0; i < favorites.size(); ++i) { + String d = favorites[i]; + _fav_list->add_item(my_basename(d)); + _fav_list->set_item_tooltip(_fav_list->get_item_count() - 1, d); + } + + _recent_list->clear(); + + for (int i = 0; i < recents.size(); ++i) { + String d = recents[i]; + _recent_list->add_item(my_basename(d)); + _recent_list->set_item_tooltip(_recent_list->get_item_count() - 1, d); + } } - - String LeftPanel::my_basename(const String &s) { - int slash_pos = s.find_last("/"); - - if (slash_pos == -1 || slash_pos+1 == s.length()) { - return s; +void LeftPanel::_on_FavList_item_activated(const int index) { + emit_signal("open_directory", _fav_list->get_item_tooltip(index)); } - return s.right(slash_pos+1); +void LeftPanel::_on_RecentList_item_activated(const int index) { + emit_signal("open_directory", _recent_list->get_item_tooltip(index)); } +void LeftPanel::_on_FavList_gui_input(const Ref &event) { + Ref iek = event; - void LeftPanel::update_lists() { - $FavList.clear(); - - for (d in favorites) { - $FavList.add_item(my_basename(d)); - $FavList.set_item_tooltip($FavList.get_item_count()-1, d); + if (iek.is_valid() && iek->is_pressed() && iek->get_scancode() == KEY_DELETE) { + if (!_fav_list->get_selected_items().empty()) { + favorites.remove(_fav_list->get_selected_items()[0]); + update_lists(); + } + } } - $RecentList.clear(); +void LeftPanel::_on_RecentList_gui_input(const Ref &event) { + Ref iek = event; - for (d in recents) { - $RecentList.add_item(my_basename(d)); - $RecentList.set_item_tooltip($RecentList.get_item_count()-1, d); + if (iek.is_valid() && iek->is_pressed() && iek->get_scancode() == KEY_DELETE) { + if (!_recent_list->get_selected_items().empty()) { + recents.remove(_recent_list->get_selected_items()[0]); + update_lists(); + } + } } +LeftPanel::LeftPanel() { + set_v_size_flags(SIZE_EXPAND_FILL); + + Label *recentlabel = memnew(Label); + recentlabel->set_text("Recent"); + add_child(recentlabel); + + _recent_list = memnew(ItemList); + _recent_list->set_custom_minimum_size(Vector2(100, 0)); + _recent_list->set_v_size_flags(SIZE_EXPAND_FILL); + add_child(_recent_list); + + Label *favlabel = memnew(Label); + favlabel->set_text("Favorite"); + add_child(favlabel); + + _fav_list = memnew(ItemList); + _fav_list->set_custom_minimum_size(Vector2(100, 0)); + _fav_list->set_v_size_flags(SIZE_EXPAND_FILL); + add_child(_fav_list); } - - void LeftPanel::_on_FavList_item_activated(const Variant &index) { - emit_signal("open_directory", $FavList.get_item_tooltip(index)); +LeftPanel::~LeftPanel() { } +void LeftPanel::_bind_methods() { + ADD_SIGNAL(MethodInfo("open_directory", PropertyInfo(Variant::STRING, "dirpath"))); - void LeftPanel::_on_RecentList_item_activated(const Variant &index) { - emit_signal("open_directory", $RecentList.get_item_tooltip(index)); + ClassDB::bind_method(D_METHOD("get_recents"), &LeftPanel::get_recents); + ClassDB::bind_method(D_METHOD("set_recents", "value"), &LeftPanel::set_recents); + ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "recents"), "set_recents", "get_recents"); + + ClassDB::bind_method(D_METHOD("get_favorites"), &LeftPanel::get_favorites); + ClassDB::bind_method(D_METHOD("set_favorites", "value"), &LeftPanel::set_favorites); + ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "favorites"), "set_favorites", "get_favorites"); + + ClassDB::bind_method(D_METHOD("add_recent", "file_path"), &LeftPanel::add_recent); + ClassDB::bind_method(D_METHOD("add_favorite", "file_path"), &LeftPanel::add_favorite); + ClassDB::bind_method(D_METHOD("my_basename", "s"), &LeftPanel::my_basename); + ClassDB::bind_method(D_METHOD("update_lists"), &LeftPanel::update_lists); + ClassDB::bind_method(D_METHOD("_on_FavList_item_activated", "index"), &LeftPanel::_on_FavList_item_activated); + ClassDB::bind_method(D_METHOD("_on_RecentList_item_activated", "index"), &LeftPanel::_on_RecentList_item_activated); + ClassDB::bind_method(D_METHOD("_on_FavList_gui_input", "event"), &LeftPanel::_on_FavList_gui_input); + ClassDB::bind_method(D_METHOD("_on_RecentList_gui_input", "event"), &LeftPanel::_on_RecentList_gui_input); } - - - void LeftPanel::_on_FavList_gui_input(const Variant &event) { - - if (event is InputEventKey && event.pressed && event.scancode == KEY_DELETE) { - - if (! $FavList.get_selected_items().empty()) { - favorites.remove($FavList.get_selected_items()[0]); - update_lists(); -} - -} - -} - - - void LeftPanel::_on_RecentList_gui_input(const Variant &event) { - - if (event is InputEventKey && event.pressed && event.scancode == KEY_DELETE) { - - if (! $RecentList.get_selected_items().empty()) { - recents.remove($RecentList.get_selected_items()[0]); - update_lists(); -} - -} - -} - -} - - LeftPanel::LeftPanel() { - recents = []; - favorites = []; - } - - LeftPanel::~LeftPanel() { - } - - - static void LeftPanel::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_recents"), &LeftPanel::get_recents); - ClassDB::bind_method(D_METHOD("set_recents", "value"), &LeftPanel::set_recents); - ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "recents"), "set_recents", "get_recents"); - - - ClassDB::bind_method(D_METHOD("get_favorites"), &LeftPanel::get_favorites); - ClassDB::bind_method(D_METHOD("set_favorites", "value"), &LeftPanel::set_favorites); - ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "favorites"), "set_favorites", "get_favorites"); - - - ClassDB::bind_method(D_METHOD("add_recent", "file_path"), &LeftPanel::add_recent); - ClassDB::bind_method(D_METHOD("add_favorite", "file_path"), &LeftPanel::add_favorite); - ClassDB::bind_method(D_METHOD("my_basename", "s"), &LeftPanel::my_basename); - ClassDB::bind_method(D_METHOD("update_lists"), &LeftPanel::update_lists); - ClassDB::bind_method(D_METHOD("_on_FavList_item_activated", "index"), &LeftPanel::_on_FavList_item_activated); - ClassDB::bind_method(D_METHOD("_on_RecentList_item_activated", "index"), &LeftPanel::_on_RecentList_item_activated); - ClassDB::bind_method(D_METHOD("_on_FavList_gui_input", "event"), &LeftPanel::_on_FavList_gui_input); - ClassDB::bind_method(D_METHOD("_on_RecentList_gui_input", "event"), &LeftPanel::_on_RecentList_gui_input); - - } - - - diff --git a/modules/material_maker/editor/widgets/file_dialog/left_panel.ctscn b/modules/material_maker/editor/widgets/file_dialog/left_panel.ctscn deleted file mode 100644 index 4794efb35..000000000 --- a/modules/material_maker/editor/widgets/file_dialog/left_panel.ctscn +++ /dev/null @@ -1,178 +0,0 @@ - -void construct() { - -//Script: res://addons/mat_maker_gd/windows/file_dialog/left_panel.gd -VBoxContainer *leftpanel = memnew(VBoxContainer); -leftpanel->set_name("LeftPanel"); - -leftpanel->set_name("LeftPanel"); -//leftpanel->set("name", LeftPanel)); - -leftpanel->set_filename("res://addons/mat_maker_gd/windows/file_dialog/left_panel.tscn"); -//leftpanel->set("filename", "res://addons/mat_maker_gd/windows/file_dialog/left_panel.tscn"); - -leftpanel->set_margin_right(40); -//leftpanel->set("margin_right", 40); - -leftpanel->set_margin_bottom(40); -//leftpanel->set("margin_bottom", 40); - -leftpanel->set_rect_size(Vector2(40, 40)); -//leftpanel->set("rect_size", Vector2(40, 40)); - -leftpanel->set_size_flags_vertical(3); -//leftpanel->set("size_flags_vertical", 3); - -//leftpanel property __meta__ TYPE_DICTIONARY value: {_edit_use_anchors_:False} - - - -Label *recentlabel_leftpanel = memnew(Label); -recentlabel_leftpanel->set_name("RecentLabel"); -leftpanel->add_child(recentlabel_leftpanel); - -recentlabel_leftpanel->set_name("RecentLabel"); -//recentlabel_leftpanel->set("name", RecentLabel)); - -//recentlabel_leftpanel property owner TYPE_OBJECT value: LeftPanel:[VBoxContainer:37180] - -recentlabel_leftpanel->set_margin_right(100); -//recentlabel_leftpanel->set("margin_right", 100); - -recentlabel_leftpanel->set_margin_bottom(14); -//recentlabel_leftpanel->set("margin_bottom", 14); - -recentlabel_leftpanel->set_rect_size(Vector2(100, 14)); -//recentlabel_leftpanel->set("rect_size", Vector2(100, 14)); - -recentlabel_leftpanel->set_text("Recent"); -//recentlabel_leftpanel->set("text", "Recent"); - - - -ItemList *recentlist_leftpanel = memnew(ItemList); -recentlist_leftpanel->set_name("RecentList"); -leftpanel->add_child(recentlist_leftpanel); - -recentlist_leftpanel->set_name("RecentList"); -//recentlist_leftpanel->set("name", RecentList)); - -//recentlist_leftpanel property owner TYPE_OBJECT value: LeftPanel:[VBoxContainer:37180] - -recentlist_leftpanel->set_margin_top(18); -//recentlist_leftpanel->set("margin_top", 18); - -recentlist_leftpanel->set_margin_right(100); -//recentlist_leftpanel->set("margin_right", 100); - -recentlist_leftpanel->set_margin_bottom(18); -//recentlist_leftpanel->set("margin_bottom", 18); - -recentlist_leftpanel->set_rect_position(Vector2(0, 18)); -//recentlist_leftpanel->set("rect_position", Vector2(0, 18)); - -recentlist_leftpanel->set_rect_global_position(Vector2(0, 18)); -//recentlist_leftpanel->set("rect_global_position", Vector2(0, 18)); - -recentlist_leftpanel->set_rect_size(Vector2(100, 0)); -//recentlist_leftpanel->set("rect_size", Vector2(100, 0)); - -recentlist_leftpanel->set_rect_min_size(Vector2(100, 0)); -//recentlist_leftpanel->set("rect_min_size", Vector2(100, 0)); - -recentlist_leftpanel->set_size_flags_vertical(3); -//recentlist_leftpanel->set("size_flags_vertical", 3); - -//recentlist_leftpanel property __meta__ TYPE_DICTIONARY value: {_edit_use_anchors_:False} - - - -VScrollBar *vscrollbar_recentlist_leftpanel = memnew(VScrollBar); -vscrollbar_recentlist_leftpanel->set_name("VScrollBar"); -recentlist_leftpanel->add_child(vscrollbar_recentlist_leftpanel); - -vscrollbar_recentlist_leftpanel->set_name("VScrollBar"); -//vscrollbar_recentlist_leftpanel->set("name", VScrollBar)); - - - -Label *favlabel_leftpanel = memnew(Label); -favlabel_leftpanel->set_name("FavLabel"); -leftpanel->add_child(favlabel_leftpanel); - -favlabel_leftpanel->set_name("FavLabel"); -//favlabel_leftpanel->set("name", FavLabel)); - -//favlabel_leftpanel property owner TYPE_OBJECT value: LeftPanel:[VBoxContainer:37180] - -favlabel_leftpanel->set_margin_top(22); -//favlabel_leftpanel->set("margin_top", 22); - -favlabel_leftpanel->set_margin_right(100); -//favlabel_leftpanel->set("margin_right", 100); - -favlabel_leftpanel->set_margin_bottom(36); -//favlabel_leftpanel->set("margin_bottom", 36); - -favlabel_leftpanel->set_rect_position(Vector2(0, 22)); -//favlabel_leftpanel->set("rect_position", Vector2(0, 22)); - -favlabel_leftpanel->set_rect_global_position(Vector2(0, 22)); -//favlabel_leftpanel->set("rect_global_position", Vector2(0, 22)); - -favlabel_leftpanel->set_rect_size(Vector2(100, 14)); -//favlabel_leftpanel->set("rect_size", Vector2(100, 14)); - -favlabel_leftpanel->set_text("Favorite"); -//favlabel_leftpanel->set("text", "Favorite"); - - - -ItemList *favlist_leftpanel = memnew(ItemList); -favlist_leftpanel->set_name("FavList"); -leftpanel->add_child(favlist_leftpanel); - -favlist_leftpanel->set_name("FavList"); -//favlist_leftpanel->set("name", FavList)); - -//favlist_leftpanel property owner TYPE_OBJECT value: LeftPanel:[VBoxContainer:37180] - -favlist_leftpanel->set_margin_top(40); -//favlist_leftpanel->set("margin_top", 40); - -favlist_leftpanel->set_margin_right(100); -//favlist_leftpanel->set("margin_right", 100); - -favlist_leftpanel->set_margin_bottom(40); -//favlist_leftpanel->set("margin_bottom", 40); - -favlist_leftpanel->set_rect_position(Vector2(0, 40)); -//favlist_leftpanel->set("rect_position", Vector2(0, 40)); - -favlist_leftpanel->set_rect_global_position(Vector2(0, 40)); -//favlist_leftpanel->set("rect_global_position", Vector2(0, 40)); - -favlist_leftpanel->set_rect_size(Vector2(100, 0)); -//favlist_leftpanel->set("rect_size", Vector2(100, 0)); - -favlist_leftpanel->set_rect_min_size(Vector2(100, 0)); -//favlist_leftpanel->set("rect_min_size", Vector2(100, 0)); - -favlist_leftpanel->set_size_flags_vertical(3); -//favlist_leftpanel->set("size_flags_vertical", 3); - -//favlist_leftpanel property __meta__ TYPE_DICTIONARY value: {_edit_use_anchors_:False} - - - -VScrollBar *vscrollbar_favlist_leftpanel = memnew(VScrollBar); -vscrollbar_favlist_leftpanel->set_name("VScrollBar"); -favlist_leftpanel->add_child(vscrollbar_favlist_leftpanel); - -vscrollbar_favlist_leftpanel->set_name("VScrollBar"); -//vscrollbar_favlist_leftpanel->set("name", VScrollBar)); - - - - -} diff --git a/modules/material_maker/editor/widgets/file_dialog/left_panel.h b/modules/material_maker/editor/widgets/file_dialog/left_panel.h index 9b8857130..870a4f968 100644 --- a/modules/material_maker/editor/widgets/file_dialog/left_panel.h +++ b/modules/material_maker/editor/widgets/file_dialog/left_panel.h @@ -1,55 +1,46 @@ #ifndef LEFT_PANEL_H #define LEFT_PANEL_H +#include "core/array.h" +#include "core/os/input_event.h" +#include "core/ustring.h" + +#include "scene/gui/box_container.h" + +class ItemList; class LeftPanel : public VBoxContainer { - GDCLASS(LeftPanel, VBoxContainer); + GDCLASS(LeftPanel, VBoxContainer); - public: +public: + Array get_recents(); + void set_recents(const Array &val); - Array get_recents(); - void set_recents(const Array &val); + Array get_favorites(); + void set_favorites(const Array &val); - Array get_favorites(); - void set_favorites(const Array &val); + void add_recent(const String &file_path); + void add_favorite(const String &file_path); - void add_recent(const String &file_path); - void add_favorite(const String &file_path); - String my_basename(const String &s); - void update_lists(); - void _on_FavList_item_activated(const Variant &index); - void _on_RecentList_item_activated(const Variant &index); - void _on_FavList_gui_input(const Variant &event); - void _on_RecentList_gui_input(const Variant &event); + String my_basename(const String &s); + void update_lists(); - LeftPanel(); - ~LeftPanel(); + void _on_FavList_item_activated(const int index); + void _on_RecentList_item_activated(const int index); + void _on_FavList_gui_input(const Ref &event); + void _on_RecentList_gui_input(const Ref &event); - protected: - static void _bind_methods(); + LeftPanel(); + ~LeftPanel(); - //tool - Array recents = []; - Array favorites = []; - signal open_directory(dirpath); - //func _ready(): - // if get_node("/root/MainWindow") != null: - // var config_cache = get_node("/root/MainWindow").config_cache - // if config_cache.has_section_key("file_dialog", "recents"): - // var parse_result = JSON.parse(config_cache.get_value("file_dialog", "recents")) - // if parse_result != null: - // recents = parse_result.result - // if config_cache.has_section_key("file_dialog", "favorites"): - // var parse_result = JSON.parse(config_cache.get_value("file_dialog", "favorites")) - // if parse_result != null: - // favorites = parse_result.result - // update_lists() - //func _exit_tree(): - // if get_node("/root/MainWindow") != null: - // var config_cache = get_node("/root/MainWindow").config_cache - // config_cache.set_value("file_dialog", "recents", JSON.print(recents)) - // config_cache.set_value("file_dialog", "favorites", JSON.print(favorites)) +protected: + static void _bind_methods(); + + Array recents; + Array favorites; + + ItemList *_recent_list; + ItemList *_fav_list; }; - #endif