Bläddra i källkod

-Cleaned up find/replace bar for replace (made selection only default if selection exists), also made buttons look like buttons
-Fixed a bug related to theme propagation, may be able to solve #6443, #6302 and others. Please test.

Juan Linietsky 9 år sedan
förälder
incheckning
1bf684cea2

+ 1 - 0
modules/visual_script/visual_script_editor.cpp

@@ -2140,6 +2140,7 @@ Vector<String> VisualScriptEditor::get_functions(){
 
 void VisualScriptEditor::set_edited_script(const Ref<Script>& p_script){
 
+
 	script=p_script;
 	signal_editor->script=p_script;
 	signal_editor->undo_redo=undo_redo;

+ 7 - 9
scene/gui/control.cpp

@@ -431,8 +431,7 @@ void Control::add_child_notify(Node *p_child) {
 		return;
 
 	if (child_c->data.theme.is_null() && data.theme_owner) {
-		child_c->data.theme_owner=data.theme_owner;
-		child_c->notification(NOTIFICATION_THEME_CHANGED);
+		_propagate_theme_changed(child_c,data.theme_owner); //need to propagate here, since many controls may require setting up stuff
 	}
 }
 
@@ -443,8 +442,7 @@ void Control::remove_child_notify(Node *p_child) {
 		return;
 
 	if (child_c->data.theme_owner && child_c->data.theme.is_null()) {
-		child_c->data.theme_owner=NULL;
-		//notification(NOTIFICATION_THEME_CHANGED);
+		_propagate_theme_changed(child_c,NULL);
 	}
 
 }
@@ -482,10 +480,10 @@ void Control::_notification(int p_notification) {
 			if (is_set_as_toplevel()) {
 				data.SI=get_viewport()->_gui_add_subwindow_control(this);
 
-				if (data.theme.is_null() && data.parent && data.parent->data.theme_owner) {
+				/*if (data.theme.is_null() && data.parent && data.parent->data.theme_owner) {
 					data.theme_owner=data.parent->data.theme_owner;
 					notification(NOTIFICATION_THEME_CHANGED);
-				}
+				}*/
 
 			} else {
 
@@ -521,10 +519,10 @@ void Control::_notification(int p_notification) {
 
 				if (parent_control) {
 					//do nothing, has a parent control
-					if (data.theme.is_null() && parent_control->data.theme_owner) {
+					/*if (data.theme.is_null() && parent_control->data.theme_owner) {
 						data.theme_owner=parent_control->data.theme_owner;
 						notification(NOTIFICATION_THEME_CHANGED);
-					}
+					}*/
 				} else if (subwindow) {
 					//is a subwindow (process input before other controls for that canvas)
 					data.SI=get_viewport()->_gui_add_subwindow_control(this);
@@ -1915,7 +1913,7 @@ void Control::_propagate_theme_changed(CanvasItem *p_at,Control *p_owner,bool p_
 
 		CanvasItem *child = p_at->get_child(i)->cast_to<CanvasItem>();
 		if (child) {
-			_propagate_theme_changed(child,p_owner);
+			_propagate_theme_changed(child,p_owner,p_assign);
 		}
 
 	}

+ 22 - 6
tools/editor/code_editor.cpp

@@ -356,7 +356,7 @@ void FindReplaceBar::_show_search() {
 	show();
 	search_text->grab_focus();
 
-	if (text_edit->is_selection_active()) {
+	if (text_edit->is_selection_active() && !selection_only->is_pressed()) {
 		search_text->set_text(text_edit->get_selection_text());
 	}
 
@@ -376,12 +376,16 @@ void FindReplaceBar::popup_search() {
 
 void FindReplaceBar::popup_replace() {
 
+
 	if (!replace_hbc->is_visible() || !replace_options_hbc->is_visible()) {
 		replace_text->clear();
 		replace_hbc->show();
 		replace_options_hbc->show();
+
 	}
 
+	selection_only->set_pressed( (text_edit->is_selection_active() && text_edit->get_selection_from_line() < text_edit->get_selection_to_line()) );
+
 	_show_search();
 }
 
@@ -409,6 +413,14 @@ void FindReplaceBar::_search_text_entered(const String& p_text) {
 	search_next();
 }
 
+void FindReplaceBar::_replace_text_entered(const String& p_text) {
+
+	if (selection_only->is_pressed() && text_edit->is_selection_active()) {
+		_replace_all();
+		_hide_bar();
+	}
+}
+
 String FindReplaceBar::get_search_text() const {
 
 	return search_text->get_text();
@@ -452,6 +464,7 @@ void FindReplaceBar::_bind_methods() {
 	ObjectTypeDB::bind_method("_editor_text_changed",&FindReplaceBar::_editor_text_changed);
 	ObjectTypeDB::bind_method("_search_text_changed",&FindReplaceBar::_search_text_changed);
 	ObjectTypeDB::bind_method("_search_text_entered",&FindReplaceBar::_search_text_entered);
+	ObjectTypeDB::bind_method("_replace_text_entered",&FindReplaceBar::_replace_text_entered);
 	ObjectTypeDB::bind_method("_search_current",&FindReplaceBar::search_current);
 	ObjectTypeDB::bind_method("_search_next",&FindReplaceBar::search_next);
 	ObjectTypeDB::bind_method("_search_prev",&FindReplaceBar::search_prev);
@@ -497,18 +510,19 @@ FindReplaceBar::FindReplaceBar() {
 	replace_text = memnew(LineEdit);
 	replace_hbc->add_child(replace_text);
 	replace_text->set_custom_minimum_size(Size2(200, 0));
-	replace_text->connect("text_entered",this,"_search_text_entered");
+	replace_text->connect("text_entered",this,"_replace_text_entered");
+
 
-	replace = memnew(ToolButton);
+	replace = memnew(Button);
 	replace_hbc->add_child(replace);
 	replace->set_text(TTR("Replace"));
-	replace->set_focus_mode(FOCUS_NONE);
+	//replace->set_focus_mode(FOCUS_NONE);
 	replace->connect("pressed",this,"_replace_pressed");
 
-	replace_all = memnew(ToolButton);
+	replace_all = memnew(Button);
 	replace_hbc->add_child(replace_all);
 	replace_all->set_text(TTR("Replace All"));
-	replace_all->set_focus_mode(FOCUS_NONE);
+	//replace_all->set_focus_mode(FOCUS_NONE);
 	replace_all->connect("pressed",this,"_replace_all_pressed");
 
 	Control *spacer_split = memnew( Control );
@@ -581,8 +595,10 @@ void FindReplaceDialog::popup_search() {
 
 void FindReplaceDialog::popup_replace() {
 
+
 	set_title(TTR("Replace"));
 	bool do_selection=(text_edit->is_selection_active() && text_edit->get_selection_from_line() < text_edit->get_selection_to_line());
+
 	set_replace_selection_only(do_selection);
 
 	if (!do_selection && text_edit->is_selection_active()) {

+ 3 - 2
tools/editor/code_editor.h

@@ -73,8 +73,8 @@ class FindReplaceBar : public HBoxContainer {
 	TextureButton *hide_button;
 
 	LineEdit *replace_text;
-	ToolButton *replace;
-	ToolButton *replace_all;
+	Button *replace;
+	Button *replace_all;
 	CheckBox *selection_only;
 
 	VBoxContainer *text_vbc;
@@ -98,6 +98,7 @@ class FindReplaceBar : public HBoxContainer {
 	void _search_options_changed(bool p_pressed);
 	void _search_text_changed(const String& p_text);
 	void _search_text_entered(const String& p_text);
+	void _replace_text_entered(const String& p_text);
 
 protected:
 	void _notification(int p_what);

+ 3 - 3
tools/editor/editor_node.cpp

@@ -5419,9 +5419,9 @@ EditorNode::EditorNode() {
 	theme_base->add_child(gui_base);
 	gui_base->set_area_as_parent_rect();
 
-	theme_base->set_theme( create_default_theme() );
-	theme = create_editor_theme();
-	gui_base->set_theme(theme);
+	Ref<Theme> theme = create_editor_theme();
+	theme_base->set_theme( theme );
+	gui_base->set_theme(create_custom_theme());
 
 	resource_preview = memnew( EditorResourcePreview );
 	add_child(resource_preview);

+ 6 - 7
tools/editor/editor_themes.cpp

@@ -33,7 +33,7 @@
 #include "editor_settings.h"
 #include "core/io/resource_loader.h"
 
-Ref<Theme> create_default_theme()
+Ref<Theme> create_editor_theme()
 {
 	Ref<Theme> theme = Ref<Theme>( memnew( Theme ) );
 
@@ -57,23 +57,22 @@ Ref<Theme> create_default_theme()
 	return theme;
 }
 
-Ref<Theme> create_editor_theme()
+Ref<Theme> create_custom_theme()
 {
-	Ref<Theme> theme = NULL;
+	Ref<Theme> theme;
 
 	String custom_theme = EditorSettings::get_singleton()->get("global/custom_theme");
 	if (custom_theme!="") {
 		theme = ResourceLoader::load(custom_theme);
 	}
 
-	if (theme.is_null() || !theme.is_valid()) {
-		theme = create_default_theme();
-	}
-
 	String global_font = EditorSettings::get_singleton()->get("global/custom_font");
 	if (global_font!="") {
 		Ref<Font> fnt = ResourceLoader::load(global_font);
 		if (fnt.is_valid()) {
+			if (!theme.is_valid()) {
+				theme.instance();
+			}
 			theme->set_default_theme_font(fnt);
 		}
 	}

+ 2 - 2
tools/editor/editor_themes.h

@@ -31,8 +31,8 @@
 
 #include "scene/resources/theme.h"
 
-Ref<Theme> create_default_theme();
-
 Ref<Theme> create_editor_theme();
 
+Ref<Theme> create_custom_theme();
+
 #endif

+ 1 - 0
tools/editor/plugins/script_editor_plugin.cpp

@@ -1513,6 +1513,7 @@ void ScriptEditor::edit(const Ref<Script>& p_script, bool p_grab_focus) {
 	}
 	ERR_FAIL_COND(!se);
 	tab_container->add_child(se);
+
 	se->set_edited_script(p_script);
 	se->set_tooltip_request_func("_get_debug_tooltip",this);
 	if (se->get_edit_menu()) {

+ 2 - 2
tools/editor/project_manager.cpp

@@ -1196,7 +1196,7 @@ ProjectManager::ProjectManager() {
 	FileDialog::set_default_show_hidden_files(EditorSettings::get_singleton()->get("file_dialog/show_hidden_files"));
 
 	set_area_as_parent_rect();
-	set_theme(create_default_theme());
+	set_theme(create_editor_theme());
 
 	gui_base = memnew( Control );
 	add_child(gui_base);
@@ -1389,7 +1389,7 @@ ProjectManager::ProjectManager() {
 
 	SceneTree::get_singleton()->connect("files_dropped", this, "_files_dropped");
 
-	gui_base->set_theme(create_editor_theme());
+	gui_base->set_theme(create_custom_theme());
 }