Skip to content

Commit

Permalink
Allow single click to open resource from sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
firedfromlife committed Jul 30, 2024
1 parent 1a24c54 commit a312db7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
37 changes: 29 additions & 8 deletions addons/dialogic/Editor/Common/sidebar.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@tool
extends Control
class_name DialogicEditorSidebar extends Control

## Script that handles the editor sidebar.

Expand Down Expand Up @@ -62,8 +62,12 @@ func _ready() -> void:
%RightClickMenu.add_separator()
%RightClickMenu.add_icon_item(get_theme_icon("ActionCopy", "EditorIcons"), "Copy Identifier", 4)
%RightClickMenu.add_separator()
%RightClickMenu.add_icon_item(get_theme_icon("Filesystem", "EditorIcons"), "Show in FileSystem", 2)
%RightClickMenu.add_icon_item(get_theme_icon("ExternalLink", "EditorIcons"), "Open in External Program", 3)
%RightClickMenu.add_icon_item(
get_theme_icon("Filesystem", "EditorIcons"), "Show in FileSystem", 2
)
%RightClickMenu.add_icon_item(
get_theme_icon("ExternalLink", "EditorIcons"), "Open in External Program", 3
)

await get_tree().process_frame
if DialogicUtil.get_editor_setting("sidebar_collapsed", false):
Expand Down Expand Up @@ -161,6 +165,8 @@ func update_resource_list(resources_list: PackedStringArray = []) -> void:

if character_items.size() > 0:
var character_tree = resource_tree.create_item(root)
if character_tree == null:
return
character_tree.set_text(0, "Characters")
character_tree.set_icon(0, get_theme_icon("Folder", "EditorIcons"))
character_tree.set_custom_bg_color(0, get_theme_color("base_color", "Editor"))
Expand Down Expand Up @@ -201,17 +207,27 @@ func _on_resources_tree_item_activated() -> void:
var item := resource_tree.get_selected()
if item.get_metadata(0) == null:
return
editors_manager.edit_resource(load(item.get_metadata(0)))
# editors_manager.edit_resource(load(item.get_metadata(0)))
edit_resource(item.get_metadata(0))


func _on_resources_tree_item_clicked(_pos: Vector2, mouse_button_index: int) -> void:
if mouse_button_index == MOUSE_BUTTON_LEFT:
var selected_item := resource_tree.get_selected()
if selected_item == null:
return
if selected_item.get_metadata(0) == null:
return
var resource_item := load(selected_item.get_metadata(0))
call_deferred("edit_resource", resource_item)
return
if mouse_button_index == MOUSE_BUTTON_MIDDLE:
remove_item_from_list(resource_tree.get_selected())
return
if mouse_button_index == MOUSE_BUTTON_RIGHT:
%RightClickMenu.popup_on_parent(Rect2(get_global_mouse_position(), Vector2()))
(%RightClickMenu as PopupMenu).set_meta("item_clicked", resource_tree.get_selected())
return


func _on_search_text_changed(new_text: String) -> void:
Expand All @@ -232,7 +248,7 @@ func _on_search_text_submitted(new_text: String) -> void:
var item := resource_tree.get_selected()
if item.get_metadata(0) == null:
return
editors_manager.edit_resource(load(item.get_metadata(0)))
edit_resource(item.get_metadata(0))
%Search.clear()


Expand Down Expand Up @@ -278,7 +294,7 @@ func update_content_list(list: PackedStringArray) -> void:
DialogicResourceUtil.set_label_cache(label_directory)


func remove_item_from_list(item:TreeItem) -> void:
func remove_item_from_list(item: TreeItem) -> void:
var new_list := []
for entry in DialogicUtil.get_editor_setting("last_resources", []):
if entry != item.get_metadata(0):
Expand Down Expand Up @@ -313,6 +329,13 @@ func _sort_by_item_text(a: ResourceListItem, b: ResourceListItem) -> bool:
return a.text < b.text


func edit_resource(resource_item: Variant) -> void:
if resource_item is Resource:
editors_manager.edit_resource(resource_item)
else:
editors_manager.edit_resource(load(resource_item))


class ResourceListItem:
extends Object
var text: String
Expand All @@ -321,13 +344,11 @@ class ResourceListItem:
var metadata: String
var tooltip: String


func add_to_item_list(item_list: ItemList, current_file: String) -> void:
item_list.add_item(text, icon)
item_list.set_item_metadata(item_list.item_count - 1, metadata)
item_list.set_item_tooltip(item_list.item_count - 1, tooltip)


func current_file(sidebar: Control, resource_list: ItemList, current_file: String) -> void:
if metadata == current_file:
resource_list.select(index)
Expand Down
8 changes: 4 additions & 4 deletions addons/dialogic/Editor/editor_main.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
[ext_resource type="Script" path="res://addons/dialogic/Editor/Common/update_manager.gd" id="14_l6b1p"]
[ext_resource type="PackedScene" uid="uid://vv3m5m68fwg7" path="res://addons/dialogic/Editor/Common/update_install_window.tscn" id="15_cu4xj"]

[sub_resource type="Image" id="Image_fmy01"]
[sub_resource type="Image" id="Image_0ofnu"]
data = {
"data": PackedByteArray(255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 94, 94, 127, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 93, 93, 255, 255, 94, 94, 127, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 94, 94, 127, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 94, 94, 127, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 231, 255, 94, 94, 54, 255, 94, 94, 57, 255, 93, 93, 233, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 231, 255, 94, 94, 54, 255, 94, 94, 57, 255, 93, 93, 233, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 97, 97, 42, 255, 255, 255, 0, 255, 255, 255, 0, 255, 97, 97, 42, 255, 93, 93, 233, 255, 93, 93, 232, 255, 93, 93, 41, 255, 255, 255, 0, 255, 255, 255, 0, 255, 97, 97, 42, 255, 93, 93, 233, 255, 93, 93, 232, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 96, 96, 45, 255, 93, 93, 44, 255, 255, 255, 0, 255, 97, 97, 42, 255, 97, 97, 42, 255, 255, 255, 0, 255, 96, 96, 45, 255, 93, 93, 44, 255, 255, 255, 0, 255, 97, 97, 42, 255, 97, 97, 42, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 96, 96, 45, 255, 93, 93, 235, 255, 94, 94, 234, 255, 95, 95, 43, 255, 255, 255, 0, 255, 255, 255, 0, 255, 96, 96, 45, 255, 93, 93, 235, 255, 94, 94, 234, 255, 95, 95, 43, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 235, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 233, 255, 95, 95, 59, 255, 96, 96, 61, 255, 93, 93, 235, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 233, 255, 95, 95, 59, 255, 96, 96, 61, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0),
"format": "RGBA8",
Expand All @@ -25,9 +25,9 @@ data = {
}

[sub_resource type="ImageTexture" id="ImageTexture_drcn6"]
image = SubResource("Image_fmy01")
image = SubResource("Image_0ofnu")

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_danxo"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_hrkym"]
content_margin_left = 8.0
content_margin_top = 8.0
content_margin_right = 8.0
Expand Down Expand Up @@ -134,7 +134,7 @@ content_scale_aspect = 4
script = ExtResource("10_xbkrt")

[node name="Manager" parent="ReferenceManager" instance=ExtResource("10_l1rf8")]
theme_override_styles/panel = SubResource("StyleBoxFlat_danxo")
theme_override_styles/panel = SubResource("StyleBoxFlat_hrkym")

[node name="UpdateManager" type="Node" parent="."]
script = ExtResource("14_l6b1p")
Expand Down

0 comments on commit a312db7

Please sign in to comment.