Zylann / godot_editor_debugger_plugin

A plugin to inspect the editor's scene tree itself, within the editor.
196 stars 20 forks source link

Typed everything; removed redundant funcs #5

Closed Xananax closed 1 year ago

Xananax commented 1 year ago

I had not noticed that there already was a Godot 4 branch, so I did my own. I still submit it here because I think it has several improvements that can be of interest:

image

I also compared it to the current godot4 branch to minimize changes

Xananax commented 1 year ago

Note: the "save branch as scene" button doesn't seem to work for me. I don't know if it's a regression or what, but the signal never fires in Godot 4 (I didn't test it in Godot 3).

I removed the button and replaced it with an item in the popup, which works.

Should I try to fix this as part of this PR?

image

func _on_popup_menu_index_pressed(index: int) -> void:
    if index == 0:
        _on_SaveBranchAsSceneButton_pressed()

func _on_SaveBranchAsSceneButton_pressed() -> void:
    #_save_branch_as_scene_button.accept_event()
    _popup_menu.hide()
    _save_branch_file_dialog.popup_centered_ratio()

We're using this plugin at GDQuest to help us author editor plugins. To make it more useful for our case, we're adding the following right-click functions:

  1. "Copy Path to clipboard", which copies the current path (like: /root/@@16478/@@655/@@656//FileSystem/)
  2. "Copy Node Types to clipboard", which copies node class and name tuples (like [["EditorNode", "@@16478"], ["Control", "@@655"], ["Panel", "@@656"], ["FileSystemDock", "FileSystem"]])

Are you interested in incorporating those, or should we maintain them in a fork?

And if yes, as part of this PR or a different one?

This is the entire code:

func _on_popup_menu_index_pressed(index: int) -> void:
    _popup_menu.hide()
    match index:
        0: # Save Branch as Scene
            _save_branch_file_dialog.popup_centered_ratio()
        1: # Copy Path to Clipboard
            var node_view := _tree_view.get_selected()
            var node := _get_node_from_view(node_view)
            DisplayServer.clipboard_set(node.get_path())
        2: # Copy node types to Clipboard
            var node_view := _tree_view.get_selected()
            var node := _get_node_from_view(node_view)
            var node_types := []
            while node.get_parent():
                var tuple := PackedStringArray([node.get_class(), node.name])
                node_types.append(tuple)
                node = node.get_parent()
            node_types.reverse()
            var node_types_str := "%s"%[node_types]
            DisplayServer.clipboard_set(node_types_str)
Zylann commented 1 year ago

I removed the button and replaced it with an item in the popup, which works.

Which popup? My memory is rusty.

Should I try to fix this as part of this PR?

I'd prefer features to be done in separate PRs, yes. Early comments on the code: don't use raw numbers for indices, prefer named constants. Also instead of index_pressed, use id_pressed (so visual order of items doesnt matter in the handler logic). A downside is that items may be setup in code, but I also prefer that to doing so in tscn. I'm not sure what the goal of option 2 is. "Copy node types", but why? Also it doesnt only copy type, but a tuple of type and name, that feels a bit arbitrary.

Xananax commented 1 year ago

Which popup? My memory is rusty.

There's a PopupMenu that shows on right click, with a button "Save Current Branch as Scene". The button is visually cut off, and doesn't work when pressed. I'll pursue this in a different PR.

Is there anything else that should be part of this PR?

Zylann commented 1 year ago

Should be ok now, thanks!