diff options
author | A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> | 2024-07-26 11:52:26 +0200 |
---|---|---|
committer | A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> | 2024-08-31 15:01:09 +0200 |
commit | 194bdde94787227e8f53a4e3273c192ab70b03ac (patch) | |
tree | c5e9d87fae1c8eb2af98ab34d687bd8c5a4a18d5 /editor/plugins/script_editor_plugin.cpp | |
parent | 61598c5c88d95b96811d386cb20d714c35f4c6d7 (diff) | |
download | redot-engine-194bdde94787227e8f53a4e3273c192ab70b03ac.tar.gz |
Cleanup of raw `nullptr` checks with `Ref`
Using `is_valid/null` over checks with `nullptr` or `ERR_FAIL_NULL` etc.
Diffstat (limited to 'editor/plugins/script_editor_plugin.cpp')
-rw-r--r-- | editor/plugins/script_editor_plugin.cpp | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index d7de5a7223..dd3af119b3 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -510,7 +510,7 @@ void ScriptEditor::_set_execution(Ref<RefCounted> p_script, int p_line) { continue; } - if ((scr != nullptr && se->get_edited_resource() == p_script) || se->get_edited_resource()->get_path() == scr->get_path()) { + if ((scr.is_valid() && se->get_edited_resource() == p_script) || se->get_edited_resource()->get_path() == scr->get_path()) { se->set_executing_line(p_line); } } @@ -526,7 +526,7 @@ void ScriptEditor::_clear_execution(Ref<RefCounted> p_script) { continue; } - if ((scr != nullptr && se->get_edited_resource() == p_script) || se->get_edited_resource()->get_path() == scr->get_path()) { + if ((scr.is_valid() && se->get_edited_resource() == p_script) || se->get_edited_resource()->get_path() == scr->get_path()) { se->clear_executing_line(); } } @@ -711,7 +711,7 @@ void ScriptEditor::_go_to_tab(int p_idx) { } Ref<Script> scr = Object::cast_to<ScriptEditorBase>(c)->get_edited_resource(); - if (scr != nullptr) { + if (scr.is_valid()) { notify_script_changed(scr); } @@ -1017,7 +1017,7 @@ void ScriptEditor::_resave_scripts(const String &p_str) { } Ref<TextFile> text_file = scr; - if (text_file != nullptr) { + if (text_file.is_valid()) { se->apply_code(); _save_text_file(text_file, text_file->get_path()); break; @@ -1228,7 +1228,7 @@ Ref<Script> ScriptEditor::_get_current_script() { if (current) { Ref<Script> scr = current->get_edited_resource(); - return scr != nullptr ? scr : nullptr; + return scr.is_valid() ? scr : nullptr; } else { return nullptr; } @@ -1420,7 +1420,7 @@ void ScriptEditor::_menu_option(int p_option) { Ref<TextFile> text_file = resource; Ref<Script> scr = resource; - if (text_file != nullptr) { + if (text_file.is_valid()) { file_dialog->set_file_mode(EditorFileDialog::FILE_MODE_SAVE_FILE); file_dialog->set_access(EditorFileDialog::ACCESS_FILESYSTEM); file_dialog_option = FILE_SAVE_AS; @@ -1449,7 +1449,7 @@ void ScriptEditor::_menu_option(int p_option) { case FILE_TOOL_RELOAD_SOFT: { Ref<Script> scr = current->get_edited_resource(); - if (scr == nullptr || scr.is_null()) { + if (scr.is_null()) { EditorNode::get_singleton()->show_warning(TTR("Can't obtain the script for reloading.")); break; } @@ -1463,7 +1463,7 @@ void ScriptEditor::_menu_option(int p_option) { case FILE_RUN: { Ref<Script> scr = current->get_edited_resource(); - if (scr == nullptr || scr.is_null()) { + if (scr.is_null()) { EditorToaster::get_singleton()->popup_str(TTR("Cannot run the edited file because it's not a script."), EditorToaster::SEVERITY_WARNING); break; } @@ -1796,7 +1796,7 @@ void ScriptEditor::_close_builtin_scripts_from_scene(const String &p_scene) { if (se) { Ref<Script> scr = se->get_edited_resource(); - if (scr == nullptr || !scr.is_valid()) { + if (scr.is_null()) { continue; } @@ -2500,7 +2500,7 @@ bool ScriptEditor::edit(const Ref<Resource> &p_resource, int p_line, int p_col, continue; } - if ((scr != nullptr && se->get_edited_resource() == p_resource) || se->get_edited_resource()->get_path() == p_resource->get_path()) { + if ((scr.is_valid() && se->get_edited_resource() == p_resource) || se->get_edited_resource()->get_path() == p_resource->get_path()) { if (should_open) { se->enable_editor(this); @@ -2550,7 +2550,7 @@ bool ScriptEditor::edit(const Ref<Resource> &p_resource, int p_line, int p_col, PackedStringArray languages = highlighter->_get_supported_languages(); // If script try language, else use extension. - if (scr != nullptr) { + if (scr.is_valid()) { if (languages.has(scr->get_language()->get_name())) { se->set_syntax_highlighter(highlighter); highlighter_set = true; @@ -2660,7 +2660,7 @@ void ScriptEditor::save_current_script() { Ref<TextFile> text_file = resource; Ref<Script> scr = resource; - if (text_file != nullptr) { + if (text_file.is_valid()) { current->apply_code(); _save_text_file(text_file, text_file->get_path()); return; @@ -2711,7 +2711,7 @@ void ScriptEditor::save_all_scripts() { Ref<TextFile> text_file = edited_res; Ref<Script> scr = edited_res; - if (text_file != nullptr) { + if (text_file.is_valid()) { _save_text_file(text_file, text_file->get_path()); continue; } @@ -2788,7 +2788,7 @@ void ScriptEditor::_reload_scripts(bool p_refresh_only) { } Ref<JSON> json = edited_res; - if (json != nullptr) { + if (json.is_valid()) { Ref<JSON> rel_json = ResourceLoader::load(json->get_path(), json->get_class(), ResourceFormatLoader::CACHE_MODE_IGNORE); ERR_CONTINUE(!rel_json.is_valid()); json->parse(rel_json->get_parsed_text(), true); @@ -3338,7 +3338,7 @@ void ScriptEditor::_make_script_list_context_menu() { context_menu->add_separator(); if (se) { Ref<Script> scr = se->get_edited_resource(); - if (scr != nullptr) { + if (scr.is_valid()) { if (!scr.is_null() && scr->is_tool()) { context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/reload_script_soft"), FILE_TOOL_RELOAD_SOFT); context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/run_file"), FILE_RUN); @@ -3685,7 +3685,7 @@ void ScriptEditor::_update_history_pos(int p_new_pos) { seb->ensure_focus(); Ref<Script> scr = seb->get_edited_resource(); - if (scr != nullptr) { + if (scr.is_valid()) { notify_script_changed(scr); } } @@ -3724,7 +3724,7 @@ Vector<Ref<Script>> ScriptEditor::get_open_scripts() const { } Ref<Script> scr = se->get_edited_resource(); - if (scr != nullptr) { + if (scr.is_valid()) { out_scripts.push_back(scr); } } |