| 2530 | } |
| 2531 | |
| 2532 | bool ScriptEditor::edit(const Ref<Resource> &p_resource, int p_line, int p_col, bool p_grab_focus) { |
| 2533 | if (p_resource.is_null()) { |
| 2534 | return false; |
| 2535 | } |
| 2536 | |
| 2537 | Ref<Script> scr = p_resource; |
| 2538 | |
| 2539 | // Don't open dominant script if using an external editor. |
| 2540 | bool use_external_editor = |
| 2541 | external_editor_active || |
| 2542 | (scr.is_valid() && scr->get_language()->overrides_external_editor()); |
| 2543 | use_external_editor = use_external_editor && !(scr.is_valid() && scr->is_built_in()); // Ignore external editor for built-in scripts. |
| 2544 | |
| 2545 | if (use_external_editor && restoring_layout && bool(EDITOR_GET("text_editor/external/prefer_tabs_in_external_editor"))) { |
| 2546 | use_external_editor = false; // Let it open internally, bulk open will handle the external editor. |
| 2547 | } |
| 2548 | |
| 2549 | const bool open_dominant = EDITOR_GET("text_editor/behavior/files/open_dominant_script_on_scene_change"); |
| 2550 | |
| 2551 | const bool should_open = (open_dominant && !use_external_editor) || !EditorNode::get_singleton()->is_changing_scene(); |
| 2552 | |
| 2553 | if (scr.is_valid() && scr->get_language()->overrides_external_editor()) { |
| 2554 | if (should_open) { |
| 2555 | Error err = scr->get_language()->open_in_external_editor(scr, p_line >= 0 ? p_line : 0, p_col); |
| 2556 | if (err != OK) { |
| 2557 | ERR_PRINT("Couldn't open script in the overridden external text editor"); |
| 2558 | } |
| 2559 | } |
| 2560 | return false; |
| 2561 | } |
| 2562 | |
| 2563 | if (use_external_editor && |
| 2564 | (EditorDebuggerNode::get_singleton()->get_dump_stack_script() != p_resource || EditorDebuggerNode::get_singleton()->get_debug_with_external_editor()) && |
| 2565 | p_resource->get_path().is_resource_file()) { |
| 2566 | String path = EDITOR_GET("text_editor/external/exec_path"); |
| 2567 | String flags = EDITOR_GET("text_editor/external/exec_flags"); |
| 2568 | |
| 2569 | List<String> args; |
| 2570 | bool has_file_flag = false; |
| 2571 | String script_path = ProjectSettings::get_singleton()->globalize_path(p_resource->get_path()); |
| 2572 | |
| 2573 | if (flags.size()) { |
| 2574 | String project_path = ProjectSettings::get_singleton()->get_resource_path(); |
| 2575 | |
| 2576 | flags = flags.replacen("{line}", itos(MAX(p_line + 1, 1))); |
| 2577 | flags = flags.replacen("{col}", itos(p_col + 1)); |
| 2578 | flags = flags.strip_edges().replace("\\\\", "\\"); |
| 2579 | |
| 2580 | int from = 0; |
| 2581 | int num_chars = 0; |
| 2582 | bool inside_quotes = false; |
| 2583 | |
| 2584 | for (int i = 0; i < flags.size(); i++) { |
| 2585 | if (flags[i] == '"' && (!i || flags[i - 1] != '\\')) { |
| 2586 | if (!inside_quotes) { |
| 2587 | from++; |
| 2588 | } |
| 2589 | inside_quotes = !inside_quotes; |
no test coverage detected