Merge pull request #34437 from Chaosus/fix_toggle_scripts4

Fix ScriptTextEditor encapsulation
This commit is contained in:
Rémi Verschelde 2019-12-19 12:19:29 +01:00 committed by GitHub
commit 8189f23e8c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 13 deletions

View file

@ -1509,7 +1509,7 @@ void CodeTextEditor::_set_show_warnings_panel(bool p_show) {
} }
void CodeTextEditor::_toggle_scripts_pressed() { void CodeTextEditor::_toggle_scripts_pressed() {
toggle_scripts_button->set_icon(ScriptEditor::get_singleton()->toggle_scripts_panel(this) ? get_icon("Back", "EditorIcons") : get_icon("Forward", "EditorIcons")); toggle_scripts_button->set_icon(ScriptEditor::get_singleton()->toggle_scripts_panel() ? get_icon("Back", "EditorIcons") : get_icon("Forward", "EditorIcons"));
} }
void CodeTextEditor::_error_pressed(const Ref<InputEvent> &p_event) { void CodeTextEditor::_error_pressed(const Ref<InputEvent> &p_event) {

View file

@ -987,11 +987,8 @@ Array ScriptEditor::_get_open_scripts() const {
return ret; return ret;
} }
bool ScriptEditor::toggle_scripts_panel(CodeTextEditor *p_editor) { bool ScriptEditor::toggle_scripts_panel() {
list_split->set_visible(!list_split->is_visible()); list_split->set_visible(!list_split->is_visible());
if (p_editor) {
p_editor->update_toggle_scripts_button();
}
return list_split->is_visible(); return list_split->is_visible();
} }
@ -1141,14 +1138,13 @@ void ScriptEditor::_menu_option(int p_option) {
} break; } break;
case TOGGLE_SCRIPTS_PANEL: { case TOGGLE_SCRIPTS_PANEL: {
if (current) { if (current) {
CodeTextEditor *code_editor = NULL; ScriptTextEditor *editor = Object::cast_to<ScriptTextEditor>(current);
ScriptTextEditor *editor = dynamic_cast<ScriptTextEditor *>(current); toggle_scripts_panel();
if (editor) { if (editor) {
code_editor = editor->code_editor; editor->update_toggle_scripts_button();
} }
toggle_scripts_panel(code_editor);
} else { } else {
toggle_scripts_panel(NULL); toggle_scripts_panel();
} }
} }
} }

View file

@ -419,7 +419,7 @@ protected:
public: public:
static ScriptEditor *get_singleton() { return script_editor; } static ScriptEditor *get_singleton() { return script_editor; }
bool toggle_scripts_panel(CodeTextEditor *p_editor); bool toggle_scripts_panel();
bool is_scripts_panel_toggled(); bool is_scripts_panel_toggled();
void ensure_focus_current(); void ensure_focus_current();
void apply_scripts() const; void apply_scripts() const;

View file

@ -966,6 +966,12 @@ void ScriptTextEditor::_lookup_symbol(const String &p_symbol, int p_row, int p_c
} }
} }
void ScriptTextEditor::update_toggle_scripts_button() {
if (code_editor != NULL) {
code_editor->update_toggle_scripts_button();
}
}
void ScriptTextEditor::_update_connected_methods() { void ScriptTextEditor::_update_connected_methods() {
TextEdit *text_edit = code_editor->get_text_edit(); TextEdit *text_edit = code_editor->get_text_edit();
text_edit->clear_info_icons(); text_edit->clear_info_icons();

View file

@ -55,6 +55,7 @@ class ScriptTextEditor : public ScriptEditorBase {
GDCLASS(ScriptTextEditor, ScriptEditorBase); GDCLASS(ScriptTextEditor, ScriptEditorBase);
CodeTextEditor *code_editor;
RichTextLabel *warnings_panel; RichTextLabel *warnings_panel;
Ref<Script> script; Ref<Script> script;
@ -186,12 +187,11 @@ protected:
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);
public: public:
CodeTextEditor *code_editor;
void _update_connected_methods(); void _update_connected_methods();
virtual void add_syntax_highlighter(SyntaxHighlighter *p_highlighter); virtual void add_syntax_highlighter(SyntaxHighlighter *p_highlighter);
virtual void set_syntax_highlighter(SyntaxHighlighter *p_highlighter); virtual void set_syntax_highlighter(SyntaxHighlighter *p_highlighter);
void update_toggle_scripts_button();
virtual void apply_code(); virtual void apply_code();
virtual RES get_edited_resource() const; virtual RES get_edited_resource() const;