Skip to content

Commit a9a9013

Browse files
Add support for creating NEW_FILE and NEW_DIRECTORY
1 parent 17ceafa commit a9a9013

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

addons/android_device_explorer/device_explorer.gd

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,31 @@ func _show_delete_dialog(remote_path: String, is_dir: bool) -> void:
220220
confirm_dialog.visibility_changed.connect(_dialog_visibility_changed.bind(confirm_dialog))
221221

222222

223+
func _show_create_dialog(remote_path: String, creating_dir: bool) -> void:
224+
var dialog = ConfirmationDialog.new()
225+
var input := LineEdit.new()
226+
if creating_dir:
227+
dialog.title = "Enter a new folder name"
228+
input.text = "MyFolder"
229+
else:
230+
dialog.title = "Enter a new file name"
231+
input.text = "MyFile.txt"
232+
input.size_flags_horizontal = Control.SIZE_EXPAND_FILL
233+
dialog.add_child(input)
234+
235+
input.text_changed.connect(func (new_text: String): dialog.get_ok_button().disabled = new_text.is_empty())
236+
237+
dialog.confirmed.connect(_create_file_or_directory.bind(remote_path.path_join(input.text), creating_dir))
238+
add_child(dialog)
239+
dialog.popup_centered(Vector2i(350, 100))
240+
dialog.visibility_changed.connect(_dialog_visibility_changed.bind(dialog))
241+
242+
223243
func _dialog_visibility_changed(dialog: AcceptDialog) -> void:
224244
if not dialog.visible:
225245
dialog.queue_free()
226246

247+
227248
# ADB Handling--------------------------------------------------------------------------------------
228249

229250
func _run_adb(p_args: PackedStringArray) -> String:
@@ -344,6 +365,23 @@ func _delete(remote_path: String) -> void:
344365
# Finally refresh the tree view
345366
_on_dir_expanded(tree.get_selected().get_parent(), true)
346367

368+
369+
func _create_file_or_directory(path: String, creating_dir: bool) -> void:
370+
var cmd: String
371+
if creating_dir:
372+
cmd = "mkdir '%s'" % path
373+
else:
374+
cmd = "touch '%s'" % path
375+
376+
if path.begins_with(DATA_ROOT):
377+
var a = _run_adb(["shell", "run-as", PACKAGE_NAME, cmd])
378+
print(a)
379+
else:
380+
_run_adb(["shell", cmd])
381+
382+
# Finally refresh the tree view
383+
_on_dir_expanded(tree.get_selected(), true)
384+
347385
#---------------------------------------------------------------------------------------------------
348386

349387
func _get_icon_for_ext(path: String) -> String:
@@ -393,6 +431,10 @@ func _on_context_menu_item_pressed(id: int) -> void:
393431
if not meta: return
394432

395433
match id:
434+
ContextMenu.NEW_FILE:
435+
_show_create_dialog(meta.path, false)
436+
ContextMenu.NEW_DIRECTORY:
437+
_show_create_dialog(meta.path, true)
396438
ContextMenu.SAVE_AS:
397439
_show_file_dialog(meta.path, false, meta.is_dir)
398440
ContextMenu.UPLOAD:

0 commit comments

Comments
 (0)