@@ -576,9 +576,9 @@ void FileSystemDock::_notification(int p_what) {
576576 if ((String (dd[" favorite" ]) == " all" )) {
577577 tree->set_drop_mode_flags (Tree::DROP_MODE_INBETWEEN);
578578 }
579- } else if ((String (dd[" type" ]) == " files" ) || (String (dd[" type" ]) == " files_and_dirs" ) || ( String (dd[ " type " ]) == " resource " ) ) {
579+ } else if ((String (dd[" type" ]) == " files" ) || (String (dd[" type" ]) == " files_and_dirs" )) {
580580 tree->set_drop_mode_flags (Tree::DROP_MODE_ON_ITEM | Tree::DROP_MODE_INBETWEEN);
581- } else if ((String (dd[" type" ]) == " nodes" )) {
581+ } else if ((String (dd[" type" ]) == " nodes" ) || ( String (dd[ " type " ]) == " resource " ) ) {
582582 holding_branch = true ;
583583 TreeItem *item = tree->get_next_selected (tree->get_root ());
584584 while (item) {
@@ -2757,7 +2757,7 @@ bool FileSystemDock::can_drop_data_fw(const Point2 &p_point, const Variant &p_da
27572757 String to_dir;
27582758 bool favorite;
27592759 _get_drag_target_folder (to_dir, favorite, p_point, p_from);
2760- return !to_dir. is_empty () ;
2760+ return !favorite ;
27612761 }
27622762
27632763 if (drag_data.has (" type" ) && (String (drag_data[" type" ]) == " files" || String (drag_data[" type" ]) == " files_and_dirs" )) {
@@ -2872,7 +2872,12 @@ void FileSystemDock::drop_data_fw(const Point2 &p_point, const Variant &p_data,
28722872 Ref<Resource> res = drag_data[" resource" ];
28732873 String to_dir;
28742874 bool favorite;
2875+ tree->set_drop_mode_flags (Tree::DROP_MODE_ON_ITEM);
28752876 _get_drag_target_folder (to_dir, favorite, p_point, p_from);
2877+ if (to_dir.is_empty ()) {
2878+ to_dir = get_current_directory ();
2879+ }
2880+
28762881 if (res.is_valid () && !to_dir.is_empty ()) {
28772882 EditorNode::get_singleton ()->push_item (res.ptr ());
28782883 EditorNode::get_singleton ()->save_resource_as (res, to_dir);
@@ -2918,7 +2923,11 @@ void FileSystemDock::drop_data_fw(const Point2 &p_point, const Variant &p_data,
29182923 if (drag_data.has (" type" ) && String (drag_data[" type" ]) == " nodes" ) {
29192924 String to_dir;
29202925 bool favorite;
2926+ tree->set_drop_mode_flags (Tree::DROP_MODE_ON_ITEM);
29212927 _get_drag_target_folder (to_dir, favorite, p_point, p_from);
2928+ if (to_dir.is_empty ()) {
2929+ to_dir = get_current_directory ();
2930+ }
29222931 SceneTreeDock::get_singleton ()->save_branch_to_file (to_dir);
29232932 }
29242933}
@@ -2931,6 +2940,7 @@ void FileSystemDock::_get_drag_target_folder(String &target, bool &target_favori
29312940 if (p_from == files) {
29322941 int pos = files->get_item_at_position (p_point, true );
29332942 if (pos == -1 ) {
2943+ target = get_current_directory ();
29342944 return ;
29352945 }
29362946
@@ -3454,37 +3464,41 @@ void FileSystemDock::_tree_gui_input(Ref<InputEvent> p_event) {
34543464void FileSystemDock::_file_list_gui_input (Ref<InputEvent> p_event) {
34553465 Ref<InputEventMouseMotion> mm = p_event;
34563466 if (mm.is_valid () && holding_branch) {
3457- const int item_idx = files->get_item_at_position (mm->get_position ());
3467+ const int item_idx = files->get_item_at_position (mm->get_position (), true );
3468+ files->deselect_all ();
3469+ String fpath;
34583470 if (item_idx != -1 ) {
3459- files->deselect_all ();
3460- String fpath = files->get_item_metadata (item_idx);
3471+ fpath = files->get_item_metadata (item_idx);
34613472 if (fpath.ends_with (" /" ) || fpath == " res://" ) {
34623473 files->select (item_idx);
34633474 }
3475+ } else {
3476+ fpath = get_current_directory ();
3477+ }
34643478
3465- TreeItem *deselect_item = tree->get_next_selected (tree->get_root ());
3466- while (deselect_item) {
3467- deselect_item->deselect (0 );
3468- deselect_item = tree->get_next_selected (deselect_item);
3479+ TreeItem *deselect_item = tree->get_next_selected (tree->get_root ());
3480+ while (deselect_item) {
3481+ deselect_item->deselect (0 );
3482+ deselect_item = tree->get_next_selected (deselect_item);
3483+ }
3484+
3485+ // Try to select the corresponding tree item.
3486+ TreeItem *tree_item = (item_idx != -1 ) ? tree->get_item_with_text (files->get_item_text (item_idx)) : nullptr ;
3487+
3488+ if (tree_item) {
3489+ tree_item->select (0 );
3490+ } else {
3491+ // Find parent folder.
3492+ fpath = fpath.substr (0 , fpath.rfind (" /" ) + 1 );
3493+ if (fpath.size () > String (" res://" ).size ()) {
3494+ fpath = fpath.left (fpath.size () - 2 ); // Remove last '/'.
3495+ const int slash_idx = fpath.rfind (" /" );
3496+ fpath = fpath.substr (slash_idx + 1 , fpath.size () - slash_idx - 1 );
34693497 }
34703498
3471- // Try to select the corresponding tree item.
3472- TreeItem *tree_item = tree->get_item_with_text (files->get_item_text (item_idx));
3499+ tree_item = tree->get_item_with_text (fpath);
34733500 if (tree_item) {
34743501 tree_item->select (0 );
3475- } else {
3476- // Find parent folder.
3477- fpath = fpath.substr (0 , fpath.rfind (" /" ) + 1 );
3478- if (fpath.size () > String (" res://" ).size ()) {
3479- fpath = fpath.left (fpath.size () - 2 ); // Remove last '/'.
3480- const int slash_idx = fpath.rfind (" /" );
3481- fpath = fpath.substr (slash_idx + 1 , fpath.size () - slash_idx - 1 );
3482- }
3483-
3484- tree_item = tree->get_item_with_text (fpath);
3485- if (tree_item) {
3486- tree_item->select (0 );
3487- }
34883502 }
34893503 }
34903504 }
0 commit comments