Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions addons/gaea/editor/editor_settings.gd
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,31 @@ static func get_preview_max_simulation_size() -> int:
if editor_interface.get_editor_settings().has_setting(PREVIEW_MAX_SIMULATION_SIZE):
return editor_interface.get_editor_settings().get_setting(PREVIEW_MAX_SIMULATION_SIZE)
return PREVIEW_MAX_SIMULATION_SIZE_DEFAULT


static func get_file_list_action_shortcut(action: GaeaFileList.Action, shortcut_key: Key) -> Shortcut:
return _get_shortcut("file_list", GaeaFileList.Action.find_key(action), shortcut_key)


static func get_node_action_shortcut(action: GaeaGraphEdit.Action, shortcut_key: Key) -> Shortcut:
return _get_shortcut("node_context_menu", GaeaGraphEdit.Action.find_key(action), shortcut_key)


static func _get_shortcut(category: String, action_key: String, shortcut_key: Key) -> Shortcut:
var editor_interface = Engine.get_singleton("EditorInterface")
var shortcut_path = StringName(("gaea/%s - %s" % [category.capitalize(), action_key.capitalize()]))

if editor_interface.get_editor_settings().has_shortcut(shortcut_path):
return editor_interface.get_editor_settings().get_shortcut(shortcut_path)

var shortcut = Shortcut.new()
var key_event = InputEventKey.new()
key_event.keycode = shortcut_key & KeyModifierMask.KEY_CODE_MASK
key_event.command_or_control_autoremap = shortcut_key & KeyModifierMask.KEY_MASK_CMD_OR_CTRL
key_event.alt_pressed = shortcut_key & KeyModifierMask.KEY_MASK_ALT
key_event.shift_pressed = shortcut_key & KeyModifierMask.KEY_MASK_SHIFT
shortcut.events = [key_event]

editor_interface.get_editor_settings().add_shortcut(shortcut_path, shortcut)

return shortcut
94 changes: 33 additions & 61 deletions addons/gaea/editor/file_list/file_context_menu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,73 +3,45 @@ class_name GaeaPopupFileContextMenu
extends PopupMenu


signal close_file_selected(file: GaeaGraph)
signal close_all_selected
signal close_others_selected(file: GaeaGraph)
signal save_as_selected(file: GaeaGraph)
signal file_saved(file: GaeaGraph)
signal unsaved_file_found(file: GaeaGraph)
@export var file_system_container: GaeaFileList

enum Action {
SAVE,
SAVE_AS,
CLOSE,
CLOSE_ALL,
CLOSE_OTHER,
COPY_PATH,
SHOW_IN_FILESYSTEM,
OPEN_IN_INSPECTOR
}

var graph: GaeaGraph

func _ready() -> void:
if is_part_of_edited_scene():
return

clear()
add_item("Save File", Action.SAVE)
add_item("Save File As...", Action.SAVE_AS)
add_item("Close", Action.CLOSE)
add_item("Close All", Action.CLOSE_ALL)
add_item("Close Other Tabs", Action.CLOSE_OTHER)
add_separator()
add_item("Copy File Path", Action.COPY_PATH)
add_item("Show in FileSystem", Action.SHOW_IN_FILESYSTEM)
add_item("Open File in Inspector", Action.OPEN_IN_INSPECTOR)

id_pressed.connect(_on_id_pressed)
_add_menu_item(GaeaFileList.Action.SAVE, "Save", KeyModifierMask.KEY_MASK_CMD_OR_CTRL | KeyModifierMask.KEY_MASK_ALT | KEY_S)
_add_menu_item(GaeaFileList.Action.SAVE, "Save As...")

add_separator()
_add_menu_item(GaeaFileList.Action.COPY_PATH, "Copy Graph Path")
_add_menu_item(GaeaFileList.Action.SHOW_IN_FILESYSTEM, "Show in FileSystem")
_add_menu_item(GaeaFileList.Action.OPEN_IN_INSPECTOR, "Open File in Inspector")

func _on_id_pressed(id: int) -> void:
match id:
Action.SAVE:
if graph.resource_path.is_empty():
unsaved_file_found.emit(graph)
return

if not graph.is_built_in():
ResourceSaver.save(graph)
else:
var scene_path := graph.resource_path.get_slice("::", 0)
ResourceSaver.save(load(scene_path))
# Necessary for open scenes.
EditorInterface.reload_scene_from_path(scene_path)
file_saved.emit(graph)
Action.SAVE_AS:
save_as_selected.emit(graph)
Action.CLOSE:
close_file_selected.emit(graph)
Action.CLOSE_ALL:
close_all_selected.emit()
Action.CLOSE_OTHER:
close_others_selected.emit(graph)
Action.COPY_PATH:
DisplayServer.clipboard_set(graph.resource_path)
Action.SHOW_IN_FILESYSTEM:
if not graph.is_built_in():
EditorInterface.select_file(graph.resource_path)
else:
EditorInterface.select_file(graph.resource_path.get_slice("::", 0))
Action.OPEN_IN_INSPECTOR:
EditorInterface.edit_resource(graph)
add_separator()
_add_menu_item(GaeaFileList.Action.CLOSE, "Close", KeyModifierMask.KEY_MASK_CMD_OR_CTRL | KEY_W)
_add_menu_item(GaeaFileList.Action.CLOSE_ALL, "Close All")
_add_menu_item(GaeaFileList.Action.CLOSE_OTHER, "Close Other Tabs")


func _add_menu_item(id: GaeaFileList.Action, text: String, shortcut_key: Variant = KEY_NONE) -> void:
add_item(tr(text), id)
if shortcut_key is StringName and InputMap.has_action(shortcut_key):
var shortcut = Shortcut.new()
shortcut.events = InputMap.action_get_events(shortcut_key)
set_item_shortcut(
get_item_index(id),
shortcut
)
elif shortcut_key is Key and shortcut_key != KEY_NONE:
set_item_shortcut(
get_item_index(id),
GaeaEditorSettings.get_file_list_action_shortcut(id, shortcut_key)
)


func _on_about_to_popup() -> void:
for item_index in item_count:
var action: GaeaFileList.Action = get_item_id(item_index) as GaeaFileList.Action
set_item_disabled(item_index, not file_system_container.can_do_action(action))
100 changes: 75 additions & 25 deletions addons/gaea/editor/file_list/file_system_container.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,26 @@
class_name GaeaFileList
extends VBoxContainer

enum Action {
NEW_GRAPH,
OPEN,
OPEN_RECENT,
SAVE,
SAVE_AS,
CLOSE,
CLOSE_ALL,
CLOSE_OTHER,
COPY_PATH,
SHOW_IN_FILESYSTEM,
OPEN_IN_INSPECTOR,
}


const GRAPH_ICON := preload("uid://cerisdpavr7v3")

@export var graph_edit: GaeaGraphEdit
@export var main_editor: GaeaMainEditor
@export var menu_bar: MenuBar
@export var menu_bar: GaeaFileListMenuBar
@export var file_list: ItemList
@export var context_menu: GaeaPopupFileContextMenu
@export var file_dialog: FileDialog
Expand All @@ -16,28 +30,13 @@ var edited_graphs: Array[EditedGraph]
var _current_saving_graph: GaeaGraph = null


func _ready() -> void:
if is_part_of_edited_scene():
return

file_list.item_selected.connect(_on_item_selected)
file_list.item_clicked.connect(_on_item_clicked)

context_menu.close_file_selected.connect(close_file)
context_menu.close_all_selected.connect(close_all)
context_menu.close_others_selected.connect(close_others)
context_menu.save_as_selected.connect(_start_save_as)
context_menu.file_saved.connect(_on_file_saved)
context_menu.unsaved_file_found.connect(_on_unsaved_file_found)

menu_bar.open_file_selected.connect(open_file)
menu_bar.create_new_graph_selected.connect(_start_new_graph_creation)

file_dialog.file_selected.connect(_on_file_dialog_file_selected)
file_dialog.canceled.connect(_on_file_dialog_canceled)
#region Opening
func open_file_from_path(path: String) -> void:
if not path.is_empty():
open_file(load(path))


#region Opening
func open_file(graph: GaeaGraph) -> void:
if not is_instance_valid(graph):
return
Expand All @@ -57,9 +56,9 @@ func open_file(graph: GaeaGraph) -> void:
file_list.set_item_tooltip(idx, graph.resource_path)
file_list.select(idx)

_on_item_selected(idx)
var edited_graph := EditedGraph.new(graph)
edited_graphs.append(edited_graph)
_on_item_selected(idx)
edited_graph.dirty_changed.connect(_on_edited_graph_dirty_changed.bind(edited_graph))
#endregion

Expand Down Expand Up @@ -97,6 +96,21 @@ func _remove(idx: int) -> void:


#region Saving
func save(file: GaeaGraph) -> void:
if file.resource_path.is_empty():
_on_unsaved_file_found(file)
return

if not file.is_built_in():
ResourceSaver.save(file)
else:
var scene_path := file.resource_path.get_slice("::", 0)
ResourceSaver.save(load(scene_path))
# Necessary for open scenes.
EditorInterface.reload_scene_from_path(scene_path)
_on_file_saved(file)


func _start_save_as(file: GaeaGraph) -> void:
file_dialog.title = "Save Graph As..."
var path: String = "res://"
Expand Down Expand Up @@ -145,7 +159,6 @@ func _on_unsaved_file_found(file: GaeaGraph) -> void:
func _on_item_clicked(index: int, _at_position: Vector2, mouse_button_index: int) -> void:
if mouse_button_index == MOUSE_BUTTON_RIGHT:
main_editor.move_popup_at_mouse(context_menu)
context_menu.graph = file_list.get_item_metadata(index)
context_menu.popup()
elif mouse_button_index == MOUSE_BUTTON_MIDDLE:
_remove(index)
Expand All @@ -159,15 +172,15 @@ func _on_item_selected(index: int) -> void:
if metadata is not GaeaGraph or not is_instance_valid(metadata):
return

graph_edit.unpopulate()
graph_edit.populate(metadata)
if graph_edit.graph != metadata:
graph_edit.unpopulate()
graph_edit.populate(metadata)

var edited: Object = EditorInterface.get_inspector().get_edited_object()
if edited is not GaeaGenerator or (edited as GaeaGenerator).graph != metadata:
EditorInterface.inspect_object.call_deferred(metadata)



func _on_file_dialog_file_selected(path: String) -> void:
var extension: String = path.get_extension()
if extension.is_empty():
Expand Down Expand Up @@ -206,6 +219,43 @@ func _on_edited_graph_dirty_changed(new_value: bool, edited_graph: EditedGraph)
if new_value == true:
text += "(*)"
file_list.set_item_text(idx, text)


func can_do_action(id: Action) -> bool:
match id:
Action.NEW_GRAPH, Action.OPEN:
return true
Action.OPEN_RECENT:
return not menu_bar.is_history_empty()
_:
return not edited_graphs.is_empty()


func _on_action_pressed(id: Action) -> void:
match id:
Action.NEW_GRAPH:
_start_new_graph_creation()
Action.OPEN:
EditorInterface.popup_quick_open(open_file_from_path, [&"GaeaGraph"])
Action.SAVE:
save(graph_edit.graph)
Action.SAVE_AS:
_start_save_as(graph_edit.graph)
Action.CLOSE:
close_file(graph_edit.graph)
Action.CLOSE_ALL:
close_all()
Action.CLOSE_OTHER:
close_others(graph_edit.graph)
Action.COPY_PATH:
DisplayServer.clipboard_set(graph_edit.graph.resource_path)
Action.SHOW_IN_FILESYSTEM:
if not graph_edit.graph.is_built_in():
EditorInterface.select_file(graph_edit.graph.resource_path)
else:
EditorInterface.select_file(graph_edit.graph.resource_path.get_slice("::", 0))
Action.OPEN_IN_INSPECTOR:
EditorInterface.edit_resource(graph_edit.graph)
#endregion


Expand Down
Loading
Loading