mirror of
https://github.com/godotengine/godot.git
synced 2025-01-24 11:32:51 -05:00
Improve Create Dialog search ranking and refactor calculation.
Code changes: - Improved search ranking with various features (position in type string, string length proportion, in favorite list, in recent list). - Recent items are now stored in an ItemList (no visual change). - Removed results that had a parent that matched the search term to improve clarity. Performance: - Reduce types to process upon opening the dialog (instead of every search change), reduces number of types by 4~5. - Clear arrays after closing dialog instead of keeping them. - Various other optimizations.
This commit is contained in:
parent
c069f5f5ca
commit
85ced4746f
2 changed files with 433 additions and 533 deletions
File diff suppressed because it is too large
Load diff
|
@ -35,60 +35,65 @@
|
||||||
#include "scene/gui/button.h"
|
#include "scene/gui/button.h"
|
||||||
#include "scene/gui/dialogs.h"
|
#include "scene/gui/dialogs.h"
|
||||||
#include "scene/gui/item_list.h"
|
#include "scene/gui/item_list.h"
|
||||||
#include "scene/gui/label.h"
|
|
||||||
#include "scene/gui/line_edit.h"
|
#include "scene/gui/line_edit.h"
|
||||||
#include "scene/gui/tree.h"
|
#include "scene/gui/tree.h"
|
||||||
|
|
||||||
class CreateDialog : public ConfirmationDialog {
|
class CreateDialog : public ConfirmationDialog {
|
||||||
GDCLASS(CreateDialog, ConfirmationDialog);
|
GDCLASS(CreateDialog, ConfirmationDialog);
|
||||||
|
|
||||||
Vector<String> favorite_list;
|
|
||||||
Tree *favorites;
|
|
||||||
Tree *recent;
|
|
||||||
|
|
||||||
Button *favorite;
|
|
||||||
LineEdit *search_box;
|
LineEdit *search_box;
|
||||||
Tree *search_options;
|
Tree *search_options;
|
||||||
HashMap<String, TreeItem *> search_options_types;
|
|
||||||
HashMap<String, RES> search_loaded_scripts;
|
|
||||||
bool is_replace_mode;
|
|
||||||
String base_type;
|
String base_type;
|
||||||
|
String icon_fallback;
|
||||||
String preferred_search_result_type;
|
String preferred_search_result_type;
|
||||||
|
|
||||||
|
Button *favorite;
|
||||||
|
Vector<String> favorite_list;
|
||||||
|
Tree *favorites;
|
||||||
|
ItemList *recent;
|
||||||
EditorHelpBit *help_bit;
|
EditorHelpBit *help_bit;
|
||||||
|
|
||||||
|
HashMap<String, TreeItem *> search_options_types;
|
||||||
|
HashMap<String, String> custom_type_parents;
|
||||||
|
HashMap<String, int> custom_type_indices;
|
||||||
List<StringName> type_list;
|
List<StringName> type_list;
|
||||||
Set<StringName> type_blacklist;
|
Set<StringName> type_blacklist;
|
||||||
|
|
||||||
|
void _update_search();
|
||||||
|
bool _should_hide_type(const String &p_type) const;
|
||||||
|
void _add_type(const String &p_current, bool p_cpp_type);
|
||||||
|
void _configure_search_option_item(TreeItem *r_item, const String &p_type, const bool p_cpp_type);
|
||||||
|
String _top_result(const Vector<String> p_candidates, const String &p_search_text) const;
|
||||||
|
float _score_type(const String &p_type, const String &p_search) const;
|
||||||
|
bool _is_type_preferred(const String &p_type) const;
|
||||||
|
|
||||||
|
void _fill_type_list();
|
||||||
|
void _cleanup();
|
||||||
|
|
||||||
|
void _sbox_input(const Ref<InputEvent> &p_ie);
|
||||||
|
void _text_changed(const String &p_newtext);
|
||||||
|
void select_type(const String &p_type);
|
||||||
void _item_selected();
|
void _item_selected();
|
||||||
void _hide_requested();
|
void _hide_requested();
|
||||||
|
|
||||||
void _update_search();
|
void _confirmed();
|
||||||
void _update_favorite_list();
|
virtual void cancel_pressed();
|
||||||
void _save_favorite_list();
|
|
||||||
void _favorite_toggled();
|
void _favorite_toggled();
|
||||||
|
|
||||||
void _history_selected();
|
void _history_selected(int p_idx);
|
||||||
void _favorite_selected();
|
void _favorite_selected();
|
||||||
|
|
||||||
void _history_activated();
|
void _history_activated(int p_idx);
|
||||||
void _favorite_activated();
|
void _favorite_activated();
|
||||||
|
|
||||||
void _sbox_input(const Ref<InputEvent> &p_ie);
|
|
||||||
|
|
||||||
void _confirmed();
|
|
||||||
void _text_changed(const String &p_newtext);
|
|
||||||
|
|
||||||
Ref<Texture2D> _get_editor_icon(const String &p_type) const;
|
|
||||||
|
|
||||||
void add_type(const String &p_type, HashMap<String, TreeItem *> &p_types, TreeItem *p_root, TreeItem **to_select);
|
|
||||||
|
|
||||||
void select_type(const String &p_type);
|
|
||||||
|
|
||||||
Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
|
Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
|
||||||
bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
|
bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
|
||||||
void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
|
void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
|
||||||
|
|
||||||
bool _is_class_disabled_by_feature_profile(const StringName &p_class);
|
bool _is_class_disabled_by_feature_profile(const StringName &p_class) const;
|
||||||
bool _is_type_prefered(const String &type);
|
void _load_favorites_and_history();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void _notification(int p_what);
|
void _notification(int p_what);
|
||||||
|
@ -100,11 +105,11 @@ public:
|
||||||
Object *instance_selected();
|
Object *instance_selected();
|
||||||
String get_selected_type();
|
String get_selected_type();
|
||||||
|
|
||||||
void set_base_type(const String &p_base);
|
void set_base_type(const String &p_base) { base_type = p_base; }
|
||||||
String get_base_type() const;
|
String get_base_type() const { return base_type; }
|
||||||
|
|
||||||
void set_preferred_search_result_type(const String &p_preferred_type);
|
void set_preferred_search_result_type(const String &p_preferred_type) { preferred_search_result_type = p_preferred_type; }
|
||||||
String get_preferred_search_result_type();
|
String get_preferred_search_result_type() { return preferred_search_result_type; }
|
||||||
|
|
||||||
void popup_create(bool p_dont_clear, bool p_replace_mode = false, const String &p_select_type = "Node");
|
void popup_create(bool p_dont_clear, bool p_replace_mode = false, const String &p_select_type = "Node");
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue