diff options
| author | Yuri Rubinsky <chaosus89@gmail.com> | 2022-12-01 17:08:07 +0300 | 
|---|---|---|
| committer | Yuri Rubinsky <chaosus89@gmail.com> | 2022-12-02 11:11:54 +0300 | 
| commit | 5eeebb3e37641929d67a9f1c88a82daaf58cfcee (patch) | |
| tree | a09f5c5a964049e82462ad0f46a14d2bbd9124ce | |
| parent | bcc061edaeb8676b82dba0d857cfbf66638071b5 (diff) | |
Fix new quick open dialog to be showed at the center of the screen
| -rw-r--r-- | editor/editor_command_palette.cpp | 22 | ||||
| -rw-r--r-- | editor/editor_command_palette.h | 1 | ||||
| -rw-r--r-- | editor/editor_quick_open.cpp | 22 | 
3 files changed, 33 insertions, 12 deletions
diff --git a/editor/editor_command_palette.cpp b/editor/editor_command_palette.cpp index b92b0fca59..609afeb40a 100644 --- a/editor/editor_command_palette.cpp +++ b/editor/editor_command_palette.cpp @@ -38,6 +38,9 @@  EditorCommandPalette *EditorCommandPalette::singleton = nullptr; +static Rect2i prev_rect = Rect2i(); +static bool was_showed = false; +  float EditorCommandPalette::_score_path(const String &p_search, const String &p_path) {  	float score = 0.9f + .1f * (p_search.length() / (float)p_path.length()); @@ -145,6 +148,17 @@ void EditorCommandPalette::_bind_methods() {  	ClassDB::bind_method(D_METHOD("remove_command", "key_name"), &EditorCommandPalette::remove_command);  } +void EditorCommandPalette::_notification(int p_what) { +	switch (p_what) { +		case NOTIFICATION_VISIBILITY_CHANGED: { +			if (!is_visible()) { +				prev_rect = Rect2i(get_position(), get_size()); +				was_showed = true; +			} +		} break; +	} +} +  void EditorCommandPalette::_sbox_input(const Ref<InputEvent> &p_ie) {  	Ref<InputEventKey> k = p_ie;  	if (k.is_valid()) { @@ -171,12 +185,10 @@ void EditorCommandPalette::_confirmed() {  }  void EditorCommandPalette::open_popup() { -	static bool was_showed = false; -	if (!was_showed) { -		was_showed = true; -		popup_centered_clamped(Size2(600, 440) * EDSCALE, 0.8f); +	if (was_showed) { +		popup(prev_rect);  	} else { -		show(); +		popup_centered_clamped(Size2(600, 440) * EDSCALE, 0.8f);  	}  	command_search_box->clear(); diff --git a/editor/editor_command_palette.h b/editor/editor_command_palette.h index 15200552b4..81cf401851 100644 --- a/editor/editor_command_palette.h +++ b/editor/editor_command_palette.h @@ -91,6 +91,7 @@ class EditorCommandPalette : public ConfirmationDialog {  protected:  	static void _bind_methods(); +	void _notification(int p_what);  public:  	void open_popup(); diff --git a/editor/editor_quick_open.cpp b/editor/editor_quick_open.cpp index bb533b88d6..6ddccba0e2 100644 --- a/editor/editor_quick_open.cpp +++ b/editor/editor_quick_open.cpp @@ -34,23 +34,24 @@  #include "editor/editor_node.h"  #include "editor/editor_scale.h" -void EditorQuickOpen::popup_dialog(const String &p_base, bool p_enable_multi, bool p_dontclear) { +static Rect2i prev_rect = Rect2i(); +static bool was_showed = false; + +void EditorQuickOpen::popup_dialog(const String &p_base, bool p_enable_multi, bool p_dont_clear) {  	base_type = p_base;  	allow_multi_select = p_enable_multi;  	search_options->set_select_mode(allow_multi_select ? Tree::SELECT_MULTI : Tree::SELECT_SINGLE); -	static bool was_showed = false; -	if (!was_showed) { -		was_showed = true; -		popup_centered_clamped(Size2(600, 440) * EDSCALE, 0.8f); +	if (was_showed) { +		popup(prev_rect);  	} else { -		show(); +		popup_centered_clamped(Size2(600, 440) * EDSCALE, 0.8f);  	}  	EditorFileSystemDirectory *efsd = EditorFileSystem::get_singleton()->get_filesystem();  	_build_search_cache(efsd); -	if (p_dontclear) { +	if (p_dont_clear) {  		search_box->select_all();  		_update_search();  	} else { @@ -251,6 +252,13 @@ void EditorQuickOpen::_notification(int p_what) {  			search_box->set_clear_button_enabled(true);  		} break; +		case NOTIFICATION_VISIBILITY_CHANGED: { +			if (!is_visible()) { +				prev_rect = Rect2i(get_position(), get_size()); +				was_showed = true; +			} +		} break; +  		case NOTIFICATION_EXIT_TREE: {  			disconnect("confirmed", callable_mp(this, &EditorQuickOpen::_confirmed));  		} break;  |