Skip to content

Commit

Permalink
GH-339 Retain/store variable type filter across popup/restarts
Browse files Browse the repository at this point in the history
  • Loading branch information
Naros committed May 11, 2024
1 parent d29d573 commit 437131b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/editor/search/search_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ void OrchestratorEditorSearchDialog::_notification(int p_what)
disconnect("confirmed", callable_mp(this, &OrchestratorEditorSearchDialog::_on_confirmed));
disconnect("canceled", callable_mp(this, &OrchestratorEditorSearchDialog::_on_canceled));
}
else if (p_what == NOTIFICATION_READY)
{
if (_filters)
_filters->select(_get_default_filter());
}
else if (p_what == NOTIFICATION_VISIBILITY_CHANGED)
{
if (is_visible())
Expand Down Expand Up @@ -467,9 +472,6 @@ void OrchestratorEditorSearchDialog::popup_create(bool p_dont_clear, bool p_repl
{
_search_items = _get_search_items();

if (_filters)
_filters->select(0);

Ref<SearchItem> initial_item = _get_search_item_by_name(p_current_type);
String search_value = initial_item.is_valid() ? initial_item->text : p_current_type;

Expand Down Expand Up @@ -632,5 +634,6 @@ void OrchestratorEditorSearchDialog::_on_item_selected()

void OrchestratorEditorSearchDialog::_on_filter_selected(int p_index)
{
_filter_type_changed(p_index);
_update_search();
}
8 changes: 8 additions & 0 deletions src/editor/search/search_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@ class OrchestratorEditorSearchDialog : public ConfirmationDialog
/// @return the possible filters
virtual Vector<FilterOption> _get_filters() const { return {}; }

/// Get the default filter choice, defaults to first item
/// @return the default filter choice
virtual int _get_default_filter() const { return 0; }

/// Called when the user changes the filter type
/// @param p_index the selected item index
virtual void _filter_type_changed(int p_index) { }

/// Check whether the search item is to be filtered beyond the normal score calculation.
/// @param p_item the search item
/// @param p_text the search text
Expand Down
14 changes: 14 additions & 0 deletions src/editor/search/variable_classification_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "common/scene_utils.h"
#include "common/string_utils.h"
#include "common/variant_utils.h"
#include "plugin/plugin.h"

#include <godot_cpp/classes/editor_interface.hpp>
#include <godot_cpp/classes/engine.hpp>
Expand Down Expand Up @@ -383,6 +384,19 @@ bool OrchestratorVariableTypeSearchDialog::_is_filtered(const Ref<SearchItem>& p
return true;
}

int OrchestratorVariableTypeSearchDialog::_get_default_filter() const
{
Ref<ConfigFile> metadata = OrchestratorPlugin::get_singleton()->get_metadata();
return metadata->get_value("variable_type_search", "filter", 0);
}

void OrchestratorVariableTypeSearchDialog::_filter_type_changed(int p_index)
{
Ref<ConfigFile> metadata = OrchestratorPlugin::get_singleton()->get_metadata();
metadata->set_value("variable_type_search", "filter", p_index);
OrchestratorPlugin::get_singleton()->save_metadata(metadata);
}

String OrchestratorVariableTypeSearchDialog::get_selected_type() const
{
TreeItem* selected = _search_options->get_selected();
Expand Down
2 changes: 2 additions & 0 deletions src/editor/search/variable_classification_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class OrchestratorVariableTypeSearchDialog : public OrchestratorEditorSearchDial
void _save_favorite_items(const Vector<Ref<SearchItem>>& p_favorites) override;
Vector<FilterOption> _get_filters() const override;
bool _is_filtered(const Ref<SearchItem>& p_item, const String& p_text) const override;
int _get_default_filter() const override;
void _filter_type_changed(int p_index) override;
//~ End OrchestratorEditorSearchDialog Interface

/// Creates the class hieararchy path, i.e. "Parent/Child/GrandChild"
Expand Down

0 comments on commit 437131b

Please sign in to comment.