Skip to content

Commit

Permalink
move folder to folder
Browse files Browse the repository at this point in the history
  • Loading branch information
exelia-antonov committed Apr 23, 2023
1 parent 793bb5b commit f51413b
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions addons/dialogic/Other/DialogicUtil.gd
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,15 @@ static func rename_folder(flat_structure: Dictionary, tree:String, path:Dictiona
return OK

static func move_folder_to_folder(flat_structure:Dictionary, tree:String, original_data:Dictionary, destination_data:Dictionary, drop_position = 0):

#abort if its trying to move folder to wrong tree
if original_data['category'] != destination_data['category']:
return ERR_INVALID_DATA

var insert_position = destination_data['step']
#adjust for the drop position
if drop_position != -1:
insert_position = insert_position + 1

# check if the name is allowed
var new_path = destination_data['path']
Expand All @@ -329,25 +334,25 @@ static func move_folder_to_folder(flat_structure:Dictionary, tree:String, origin
original_folder = original_data['orig_path'] + original_data['name']
replace_folder = destination_data['path'] + destination_data['name'] + '/' + original_data['name']
else:
destination_data['step'] = destination_data['step'] - 1
original_folder = original_data['orig_path'] + original_data['name']
replace_folder = destination_data['path'] + original_data['name']

#first iterate through and find all the items that need to be renamed
for idx in flat_structure[tree +"_Array"].size():
if original_folder in flat_structure[tree +"_Array"][idx]['key']:
var item = flat_structure[tree +"_Array"][idx]
var item = flat_structure[tree +"_Array"][idx].duplicate()
item['key'] = item['key'].replace(original_folder, replace_folder)
if 'path' in item['value']:
item['value']['path'] = item['value']['path'].replace(original_folder, replace_folder)
rename_array.append(item)
else:
new_array.append(flat_structure[tree +"_Array"][idx])


#now merge in and replace the original ones
while rename_array.size() > 0:
new_array.insert(destination_data['step'] + 1, rename_array.pop_back())
new_array.insert(insert_position, rename_array.pop_back())

#return ERR_INVALID_DATA

flat_structure[tree +"_Array"] = new_array

Expand All @@ -360,12 +365,6 @@ static func move_folder_to_folder(flat_structure:Dictionary, tree:String, origin
## FILE FUNCTIONS
static func move_file_to_folder(flat_structure:Dictionary, tree:String, original_data:Dictionary, destination_data:Dictionary, drop_position = 0):
#abort if its trying to move folder to wrong tree
print("Move:")
print (original_data)
print("To:")
print(destination_data)
print("Position:")
print(drop_position)
if original_data['category'] != destination_data['category']:
return ERR_INVALID_DATA

Expand All @@ -378,12 +377,9 @@ static func move_file_to_folder(flat_structure:Dictionary, tree:String, original
if 'folded' in flat_structure[tree +"_Array"][destination_data['step']]['value']:
var destination_folder = ""
if drop_position == -1:
print("moving to before item: " + flat_structure[tree +"_Array"][insert_position]['key'])
destination_folder = destination_data['path']
else:
print("moving into item: " + flat_structure[tree +"_Array"][insert_position]['key'])
destination_folder = destination_data['path'] + destination_data['name'] + "/"
print(flat_structure[tree +"_Array"][insert_position]['key'])

#var destination_path =
var searching = true
Expand All @@ -399,18 +395,16 @@ static func move_file_to_folder(flat_structure:Dictionary, tree:String, original
#if flat_structure[tree +"_Array"][insert_position]['key']:
#flat_structure[tree +"_Array"][insert_position]['value']['path'] != destination_data['path'] + destination_data['folder'] + "/"

print("Final move position: " + str(insert_position))

#if the file came from before where we are moving it to, we need to decrease the position since orders being changed
if original_data['original_step'] < destination_data['step']:
insert_position = insert_position - 1

print("inserting to: " + str(insert_position))

var moving = flat_structure[tree +"_Array"].pop_at(original_data['original_step'])

if destination_data['editortype'] == "folder":
if drop_position != 1:
if drop_position != -1:
moving['key'] = moving['key'].replace(original_data['orig_path'], destination_data['path'] + destination_data['name'] + "/")
moving['value']['path'] = destination_data['path'] + destination_data['name'] + "/"
else:
Expand Down Expand Up @@ -565,6 +559,7 @@ static func flat_structure_to_editor_array(flat_structure: Dictionary, tree:Stri
return flat_structure

static func editor_array_to_flat_structure(flat_structure: Dictionary, tree:String="all") -> Dictionary:
print("editor array to flat strucutre")
if tree != "all":
flat_structure[tree] = {}

Expand Down

0 comments on commit f51413b

Please sign in to comment.