| 2239 | } |
| 2240 | |
| 2241 | void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) { |
| 2242 | Dictionary d = p_data; |
| 2243 | |
| 2244 | CodeEdit *te = code_editor->get_text_editor(); |
| 2245 | Point2i pos = (p_point == Vector2(Math::INF, Math::INF)) ? Point2i(te->get_caret_line(0), te->get_caret_column(0)) : te->get_line_column_at_pos(p_point); |
| 2246 | int drop_at_line = pos.y; |
| 2247 | int drop_at_column = pos.x; |
| 2248 | int selection_index = te->get_selection_at_line_column(drop_at_line, drop_at_column); |
| 2249 | |
| 2250 | bool is_empty_line = false; |
| 2251 | if (selection_index >= 0) { |
| 2252 | // Dropped on a selection, it will be replaced. |
| 2253 | drop_at_line = te->get_selection_from_line(selection_index); |
| 2254 | drop_at_column = te->get_selection_from_column(selection_index); |
| 2255 | is_empty_line = drop_at_column <= te->get_first_non_whitespace_column(drop_at_line) && te->get_selection_to_column(selection_index) == te->get_line(te->get_selection_to_line(selection_index)).length(); |
| 2256 | } |
| 2257 | |
| 2258 | const bool drop_modifier_pressed = Input::get_singleton()->is_key_pressed(Key::CMD_OR_CTRL); |
| 2259 | const bool allow_uid = Input::get_singleton()->is_key_pressed(Key::SHIFT) != bool(EDITOR_GET("text_editor/behavior/files/drop_preload_resources_as_uid")); |
| 2260 | const String &line = te->get_line(drop_at_line); |
| 2261 | |
| 2262 | if (selection_index < 0) { |
| 2263 | is_empty_line = line.is_empty() || te->get_first_non_whitespace_column(drop_at_line) == line.length(); |
| 2264 | } |
| 2265 | |
| 2266 | String text_to_drop; |
| 2267 | bool add_new_line = false; |
| 2268 | |
| 2269 | const String type = d.get("type", ""); |
| 2270 | if (type == "resource") { |
| 2271 | Ref<Resource> resource = d["resource"]; |
| 2272 | if (resource.is_null()) { |
| 2273 | return; |
| 2274 | } |
| 2275 | |
| 2276 | const String &path = resource->get_path(); |
| 2277 | if (path.is_empty() || path.ends_with("::")) { |
| 2278 | String warning = TTR("The resource does not have a valid path because it has not been saved.\nPlease save the scene or resource that contains this resource and try again."); |
| 2279 | EditorToaster::get_singleton()->popup_str(warning, EditorToaster::SEVERITY_ERROR); |
| 2280 | return; |
| 2281 | } |
| 2282 | |
| 2283 | if (drop_modifier_pressed) { |
| 2284 | if (resource->is_built_in()) { |
| 2285 | String warning = TTR("Preloading internal resources is not supported."); |
| 2286 | EditorToaster::get_singleton()->popup_str(warning, EditorToaster::SEVERITY_ERROR); |
| 2287 | } else { |
| 2288 | text_to_drop = _get_dropped_resource_line(resource, is_empty_line, allow_uid); |
| 2289 | } |
| 2290 | } else { |
| 2291 | text_to_drop = _quote_drop_data(path); |
| 2292 | } |
| 2293 | } |
| 2294 | |
| 2295 | if (type == "files" || type == "files_and_dirs") { |
| 2296 | const PackedStringArray files = d["files"]; |
| 2297 | PackedStringArray parts; |
| 2298 |
nothing calls this directly
no test coverage detected