@@ -1246,36 +1246,25 @@ bool FileSystemDock::can_drop_data_fw(const Point2 &p_point, const Variant &p_da
1246
1246
}
1247
1247
1248
1248
if (drag_data.has (" type" ) && String (drag_data[" type" ]) == " resource" ) {
1249
- return true ;
1249
+ String to_dir = _get_drag_target_folder (p_point, p_from);
1250
+ return !to_dir.empty ();
1250
1251
}
1251
1252
1252
1253
if (drag_data.has (" type" ) && (String (drag_data[" type" ]) == " files" || String (drag_data[" type" ]) == " files_and_dirs" )) {
1254
+ String to_dir = _get_drag_target_folder (p_point, p_from);
1255
+ if (to_dir.empty ())
1256
+ return false ;
1253
1257
1258
+ // Attempting to move a folder into itself will fail later
1259
+ // Rather than bring up a message don't try to do it in the first place
1260
+ to_dir = to_dir.ends_with (" /" ) ? to_dir : (to_dir + " /" );
1254
1261
Vector<String> fnames = drag_data[" files" ];
1255
-
1256
- if (p_from == files) {
1257
-
1258
- int at_pos = files->get_item_at_position (p_point);
1259
- if (at_pos != -1 ) {
1260
-
1261
- String dir = files->get_item_metadata (at_pos);
1262
- if (dir.ends_with (" /" ))
1263
- return true ;
1264
- }
1265
- }
1266
-
1267
- if (p_from == tree) {
1268
-
1269
- TreeItem *ti = tree->get_item_at_position (p_point);
1270
- if (!ti)
1271
- return false ;
1272
-
1273
- String fpath = ti->get_metadata (0 );
1274
- if (fpath == String ())
1262
+ for (int i = 0 ; i < fnames.size (); ++i) {
1263
+ if (fnames[i].ends_with (" /" ) && to_dir.begins_with (fnames[i]))
1275
1264
return false ;
1276
-
1277
- return true ;
1278
1265
}
1266
+
1267
+ return true ;
1279
1268
}
1280
1269
1281
1270
return false ;
@@ -1351,66 +1340,16 @@ void FileSystemDock::drop_data_fw(const Point2 &p_point, const Variant &p_data,
1351
1340
1352
1341
if (drag_data.has (" type" ) && String (drag_data[" type" ]) == " resource" ) {
1353
1342
Ref<Resource> res = drag_data[" resource" ];
1354
-
1355
- if (!res.is_valid ()) {
1356
- return ;
1357
- }
1358
-
1359
- if (p_from == tree) {
1360
-
1361
- TreeItem *ti = tree->get_item_at_position (p_point);
1362
- if (!ti)
1363
- return ;
1364
-
1365
- String fpath = ti->get_metadata (0 );
1366
- if (fpath == String ())
1367
- return ;
1368
-
1369
- EditorNode::get_singleton ()->save_resource_as (res, fpath);
1370
- return ;
1371
- }
1372
-
1373
- if (p_from == files) {
1374
- String save_path = path;
1375
-
1376
- int at_pos = files->get_item_at_position (p_point);
1377
- if (at_pos != -1 ) {
1378
- String to_dir = files->get_item_metadata (at_pos);
1379
- if (to_dir.ends_with (" /" )) {
1380
- save_path = to_dir;
1381
- if (save_path != " res://" )
1382
- save_path = save_path.substr (0 , save_path.length () - 1 );
1383
- }
1384
- }
1385
-
1386
- EditorNode::get_singleton ()->save_resource_as (res, save_path);
1387
- return ;
1343
+ String to_dir = _get_drag_target_folder (p_point, p_from);
1344
+ if (res.is_valid () && !to_dir.empty ()) {
1345
+ EditorNode::get_singleton ()->push_item (res.ptr ());
1346
+ EditorNode::get_singleton ()->save_resource_as (res, to_dir);
1388
1347
}
1389
1348
}
1390
1349
1391
1350
if (drag_data.has (" type" ) && (String (drag_data[" type" ]) == " files" || String (drag_data[" type" ]) == " files_and_dirs" )) {
1392
-
1393
- if (p_from == files || p_from == tree) {
1394
-
1395
- String to_dir;
1396
-
1397
- if (p_from == files) {
1398
-
1399
- int at_pos = files->get_item_at_position (p_point);
1400
- ERR_FAIL_COND (at_pos == -1 );
1401
- to_dir = files->get_item_metadata (at_pos);
1402
- } else {
1403
- TreeItem *ti = tree->get_item_at_position (p_point);
1404
- if (!ti)
1405
- return ;
1406
- to_dir = ti->get_metadata (0 );
1407
- ERR_FAIL_COND (to_dir == String ());
1408
- }
1409
-
1410
- if (to_dir != " res://" && to_dir.ends_with (" /" )) {
1411
- to_dir = to_dir.substr (0 , to_dir.length () - 1 );
1412
- }
1413
-
1351
+ String to_dir = _get_drag_target_folder (p_point, p_from);
1352
+ if (!to_dir.empty ()) {
1414
1353
Vector<String> fnames = drag_data[" files" ];
1415
1354
to_move.clear ();
1416
1355
for (int i = 0 ; i < fnames.size (); i++) {
@@ -1421,6 +1360,25 @@ void FileSystemDock::drop_data_fw(const Point2 &p_point, const Variant &p_data,
1421
1360
}
1422
1361
}
1423
1362
1363
+ String FileSystemDock::_get_drag_target_folder (const Point2 &p_point, Control *p_from) const {
1364
+ if (p_from == files) {
1365
+ int pos = files->get_item_at_position (p_point, true );
1366
+ if (pos == -1 )
1367
+ return path;
1368
+
1369
+ String target = files->get_item_metadata (pos);
1370
+ return target.ends_with (" /" ) ? target : path;
1371
+ }
1372
+
1373
+ if (p_from == tree) {
1374
+ TreeItem *ti = tree->get_item_at_position (p_point);
1375
+ if (ti && ti != tree->get_root ()->get_children ())
1376
+ return ti->get_metadata (0 );
1377
+ }
1378
+
1379
+ return String ();
1380
+ }
1381
+
1424
1382
void FileSystemDock::_files_list_rmb_select (int p_item, const Vector2 &p_pos) {
1425
1383
1426
1384
// Right clicking ".." should clear current selection
0 commit comments