@@ -15,6 +15,15 @@ const PULL_PUSH_TEMP = TMP_DIR + "/godot-device-explorer-plugin"
1515var current_device := ""
1616var show_all := false
1717
18+ enum ContextMenu {
19+ NEW_FILE ,
20+ NEW_DIRECTORY ,
21+ SAVE_AS ,
22+ UPLOAD ,
23+ DELETE ,
24+ SYNCHRONIZE ,
25+ COPY_PATH
26+ }
1827
1928func _ready () -> void :
2029 _setup_ui ()
@@ -23,21 +32,28 @@ func _ready() -> void:
2332
2433func _setup_ui () -> void :
2534 tree .hide_root = true
35+ tree .allow_rmb_select = true
2636 tree .item_collapsed .connect (_on_item_collapsed )
37+ tree .item_mouse_selected .connect (_on_item_mouse_selected )
2738
2839 devices_btn .custom_minimum_size = Vector2 (32 , 32 )
2940 devices_btn .selected = - 1
3041 devices_btn .pressed .connect (_load_devices )
3142 devices_btn .item_selected .connect (_on_device_selected )
3243
33- menu_button .icon = EditorInterface . get_base_control (). get_theme_icon ("GuiTabMenuHl" , "EditorIcons" )
44+ menu_button .icon = get_theme_icon ("GuiTabMenuHl" , "EditorIcons" )
3445 var popup := menu_button .get_popup ()
3546 popup .clear ()
3647 popup .add_check_item ("Show Full Filesystem" , 0 )
3748 popup .set_item_checked (0 , show_all )
3849 popup .id_pressed .connect (_on_menu_item_pressed )
3950
4051
52+ func _on_item_mouse_selected (pos : Vector2 , mouse_button_index : int ) -> void :
53+ if mouse_button_index == MOUSE_BUTTON_RIGHT :
54+ create_context_menu ()
55+
56+
4157func _load_devices () -> void :
4258 var device_list := _get_devices ()
4359 var selected = devices_btn .get_selected_id ()
@@ -85,12 +101,11 @@ func _create_tree_item(parent: TreeItem, text: String, path: String, is_dir: boo
85101 item .set_text (0 , text )
86102 item .set_metadata (0 , {"path" : path , "is_dir" : is_dir })
87103
88- var gui := EditorInterface .get_base_control ()
89104 var icon_name = custom_icon if custom_icon != "" else ("Folder" if is_dir else _get_icon_for_ext (path ))
90- item .set_icon (0 , gui . get_theme_icon (icon_name , "EditorIcons" ))
105+ item .set_icon (0 , get_theme_icon (icon_name , "EditorIcons" ))
91106
92107 if is_dir :
93- item .set_icon_modulate (0 , gui . get_theme_color ("accent_color" , "Editor" ))
108+ item .set_icon_modulate (0 , get_theme_color ("accent_color" , "Editor" ))
94109 if not skip_dummy : _add_dummy (item )
95110
96111 item .collapsed = true
@@ -198,8 +213,44 @@ func _get_icon_for_ext(path: String) -> String:
198213 match ext :
199214 "gd" : return "GDScript"
200215 "tscn" : return "PackedScene"
201- "res" , "tres" : return "Resource"
202216 "png" , "jpg" , "svg" : return "ImageTexture"
203217 "txt" , "json" : return "TextFile"
204218 _ : return "File"
219+
220+
221+ func create_context_menu () -> void :
222+ var item = tree .get_selected ()
223+ if not item : return
224+
225+ var menu = PopupMenu .new ()
226+
227+ var is_dir = item .get_metadata (0 ).is_dir
228+ if is_dir :
229+ var sub_menu = PopupMenu .new ()
230+ sub_menu .add_icon_item (get_theme_icon ("File" , "EditorIcons" ), "File" , ContextMenu .NEW_FILE )
231+ sub_menu .add_icon_item (get_theme_icon ("Folder" , "EditorIcons" ), "Directory" , ContextMenu .NEW_DIRECTORY )
232+ sub_menu .id_pressed .connect (_on_context_menu_item_pressed )
233+ menu .add_submenu_node_item ("New" , sub_menu )
234+ menu .add_separator ()
235+
236+ menu .add_icon_item (get_theme_icon ("MoveDown" , "EditorIcons" ), "Save As" , ContextMenu .SAVE_AS )
237+ if is_dir :
238+ menu .add_icon_item (get_theme_icon ("MoveUp" , "EditorIcons" ), "Upload" , ContextMenu .UPLOAD )
239+ menu .add_icon_item (get_theme_icon ("Remove" , "EditorIcons" ), "Delete" , ContextMenu .DELETE )
240+ menu .add_separator ()
241+ menu .add_icon_item (get_theme_icon ("Reload" , "EditorIcons" ), "Synchronize" , ContextMenu .SYNCHRONIZE )
242+ menu .add_icon_item (get_theme_icon ("ActionCopy" , "EditorIcons" ), "Copy Path" , ContextMenu .COPY_PATH )
243+
244+ menu .id_pressed .connect (_on_context_menu_item_pressed )
245+ menu .popup_hide .connect (menu .queue_free )
246+ add_child (menu )
247+
248+ menu .position = DisplayServer .mouse_get_position ()
249+ menu .popup ()
250+
251+
252+ func _on_context_menu_item_pressed (id : int ) -> void :
253+ var item = tree .get_selected ()
254+ if not item : return
255+ print ("context menu pressed: " , id )
205256
0 commit comments