From ec16bb8e3015a921a51d1285611f8f09aad07d7d Mon Sep 17 00:00:00 2001 From: Jayden Sipe Date: Wed, 12 Jun 2024 22:40:11 -0400 Subject: [PATCH] Add .gitignore for .gd_local_history folder --- .../gd_local_history.gd-1718243264.519.txt | 36 ----------- .../gd_local_history.gd-1718246148.107.txt | 37 ----------- .../gd_local_history.gd-1718246187.014.txt | 40 ------------ .../local_history_panel.gd-1718246233.895.txt | 62 ------------------- .../local_history_panel.gd-1718246242.124.txt | 62 ------------------- .gitignore | 1 + 6 files changed, 1 insertion(+), 237 deletions(-) delete mode 100644 .gd_local_history/gd_local_history.gd/gd_local_history.gd-1718243264.519.txt delete mode 100644 .gd_local_history/gd_local_history.gd/gd_local_history.gd-1718246148.107.txt delete mode 100644 .gd_local_history/gd_local_history.gd/gd_local_history.gd-1718246187.014.txt delete mode 100644 .gd_local_history/local_history_panel.gd/local_history_panel.gd-1718246233.895.txt delete mode 100644 .gd_local_history/local_history_panel.gd/local_history_panel.gd-1718246242.124.txt diff --git a/.gd_local_history/gd_local_history.gd/gd_local_history.gd-1718243264.519.txt b/.gd_local_history/gd_local_history.gd/gd_local_history.gd-1718243264.519.txt deleted file mode 100644 index 664dc6b..0000000 --- a/.gd_local_history/gd_local_history.gd/gd_local_history.gd-1718243264.519.txt +++ /dev/null @@ -1,36 +0,0 @@ -@tool -extends EditorPlugin - -var _previous_saved_files: Dictionary = {} -var local_history_panel: LocalHistoryPanel = preload("res://addons/gd_local_history/ui/local_history_panel/local_history_panel.tscn").instantiate() - -func _enter_tree() -> void: - # Add custom button to bottom panel - add_control_to_bottom_panel(local_history_panel, "Local History") - - # Add signal connection - resource_saved.connect(_local_history_save.bind()) - -func _exit_tree() -> void: - # Remove custom button from bottom panel - remove_control_from_bottom_panel(local_history_panel) - - # Remove signal connection - resource_saved.disconnect(_local_history_save.bind()) - -func _local_history_save(_resource: Resource) -> void: - if (_resource is not Script): return - - var file_name: String = _resource.resource_path.get_file() - var source_code: String = _resource.source_code - if (_previous_saved_files.get_or_add(file_name, "") == source_code): return - _previous_saved_files[file_name] = source_code - - var path: String = "res://.gd_local_history/%s/" % file_name - if (!DirAccess.dir_exists_absolute(path)): - DirAccess.make_dir_recursive_absolute(path) - local_history_panel.create_file_tree_item(file_name) - - var file: FileAccess = FileAccess.open(path + "%s-%s.txt" % [file_name, Time.get_unix_time_from_system()], FileAccess.WRITE) - file.store_string(_resource.source_code) - file.close() diff --git a/.gd_local_history/gd_local_history.gd/gd_local_history.gd-1718246148.107.txt b/.gd_local_history/gd_local_history.gd/gd_local_history.gd-1718246148.107.txt deleted file mode 100644 index cf2b209..0000000 --- a/.gd_local_history/gd_local_history.gd/gd_local_history.gd-1718246148.107.txt +++ /dev/null @@ -1,37 +0,0 @@ -@tool -extends EditorPlugin - -var _previous_saved_files: Dictionary = {} -var local_history_panel: LocalHistoryPanel = preload("res://addons/gd_local_history/ui/local_history_panel/local_history_panel.tscn").instantiate() - -func _enter_tree() -> void: - # Add custom button to bottom panel - add_control_to_bottom_panel(local_history_panel, "Local History") - - # Add signal connection - resource_saved.connect(_local_history_save.bind()) - -func _exit_tree() -> void: - # Remove custom button from bottom panel - remove_control_from_bottom_panel(local_history_panel) - - # Remove signal connection - resource_saved.disconnect(_local_history_save.bind()) - -func _local_history_save(_resource: Resource) -> void: - if (_resource is not Script): return - - var file_name: String = _resource.resource_path.get_file() - var source_code: String = _resource.source_code - - if (_previous_saved_files.get_or_add(file_name, "") == source_code): return - _previous_saved_files[file_name] = source_code - - var path: String = "res://.gd_local_history/%s/" % file_name - if (!DirAccess.dir_exists_absolute(path)): - DirAccess.make_dir_recursive_absolute(path) - local_history_panel.create_file_tree_item(file_name) - - var file: FileAccess = FileAccess.open(path + "%s-%s.txt" % [file_name, Time.get_unix_time_from_system()], FileAccess.WRITE) - file.store_string(_resource.source_code) - file.close() diff --git a/.gd_local_history/gd_local_history.gd/gd_local_history.gd-1718246187.014.txt b/.gd_local_history/gd_local_history.gd/gd_local_history.gd-1718246187.014.txt deleted file mode 100644 index 360f1f4..0000000 --- a/.gd_local_history/gd_local_history.gd/gd_local_history.gd-1718246187.014.txt +++ /dev/null @@ -1,40 +0,0 @@ -@tool -extends EditorPlugin - -var _previous_saved_files: Dictionary = {} -var local_history_panel: LocalHistoryPanel = preload("res://addons/gd_local_history/ui/local_history_panel/local_history_panel.tscn").instantiate() - -# TODO: -# Add project setting for setting destination - -func _enter_tree() -> void: - # Add custom button to bottom panel - add_control_to_bottom_panel(local_history_panel, "Local History") - - # Add signal connection - resource_saved.connect(_local_history_save.bind()) - -func _exit_tree() -> void: - # Remove custom button from bottom panel - remove_control_from_bottom_panel(local_history_panel) - - # Remove signal connection - resource_saved.disconnect(_local_history_save.bind()) - -func _local_history_save(_resource: Resource) -> void: - if (_resource is not Script): return - - var file_name: String = _resource.resource_path.get_file() - var source_code: String = _resource.source_code - - if (_previous_saved_files.get_or_add(file_name, "") == source_code): return - _previous_saved_files[file_name] = source_code - - var path: String = "res://.gd_local_history/%s/" % file_name - if (!DirAccess.dir_exists_absolute(path)): - DirAccess.make_dir_recursive_absolute(path) - local_history_panel.create_file_tree_item(file_name) - - var file: FileAccess = FileAccess.open(path + "%s-%s.txt" % [file_name, Time.get_unix_time_from_system()], FileAccess.WRITE) - file.store_string(_resource.source_code) - file.close() diff --git a/.gd_local_history/local_history_panel.gd/local_history_panel.gd-1718246233.895.txt b/.gd_local_history/local_history_panel.gd/local_history_panel.gd-1718246233.895.txt deleted file mode 100644 index a9b4c2a..0000000 --- a/.gd_local_history/local_history_panel.gd/local_history_panel.gd-1718246233.895.txt +++ /dev/null @@ -1,62 +0,0 @@ -@tool -extends Control -class_name LocalHistoryPanel - -@onready var tree: Tree = $HSplitContainer/Tree -@onready var code_edit: CodeEdit = $HSplitContainer/CodeEdit -const RELOAD = preload("res://addons/gd_local_history/ui/reload.svg") -const REMOVE = preload("res://addons/gd_local_history/ui/remove.svg") -var _tree_root: TreeItem - -func _ready() -> void: - var _tree_root: TreeItem = tree.create_item() - var directories: PackedStringArray = DirAccess.get_directories_at("res://.gd_local_history") - for directory: String in directories: - create_file_tree_item(directory) - -func create_file_tree_item(file_name: String) -> void: - var child: TreeItem = tree.create_item(_tree_root) - child.set_text(0, file_name) - child.set_custom_color(0, Color.WHITE_SMOKE) - child.add_button(0, REMOVE, 1) - child.add_button(0, RELOAD, 2) - child.set_button_tooltip_text(0, 0, "Delete %s" % file_name) - child.set_button_color(0, 0, Color.INDIAN_RED) - child.set_button_tooltip_text(0, 1, "Refresh %s" % file_name) - -func _on_tree_item_selected() -> void: - var selected_tree_item: TreeItem = tree.get_selected() - var metadata: Variant = selected_tree_item.get_metadata(0) - if (metadata != null): - code_edit.text = metadata - return - - var folder_path: String = "res://.gd_local_history/%s" % selected_tree_item.get_text(0) - _refresh_tree_item(selected_tree_item, folder_path) - -func _on_tree_button_clicked(item: TreeItem, column: int, id: int, mouse_button_index: int) -> void: - var folder_path: String = "res://.gd_local_history/%s" % item.get_text(0) - match (id): - 1: - _clear_tree_item(item, folder_path, true) - 2: - _refresh_tree_item(item, folder_path) - _: - pass - -func _clear_tree_item(tree_item: TreeItem, folder_path: String = "", delete_files: bool = false) -> void: - if (delete_files): - for source_code_file_name: String in DirAccess.get_files_at(folder_path): - DirAccess.remove_absolute(folder_path + "/%s" % source_code_file_name) - DirAccess.remove_absolute(folder_path) - tree_item.free() - else: - for child: TreeItem in tree_item.get_children(): - tree_item.remove_child(child) - -func _refresh_tree_item(tree_item: TreeItem, folder_path: String) -> void: - _clear_tree_item(tree_item) - for source_code_file_name: String in DirAccess.get_files_at(folder_path): - var txt_child: TreeItem = tree_item.create_child() - txt_child.set_text(0, source_code_file_name) - txt_child.set_metadata(0, FileAccess.open(folder_path + "/%s" % source_code_file_name, FileAccess.READ).get_as_text()) diff --git a/.gd_local_history/local_history_panel.gd/local_history_panel.gd-1718246242.124.txt b/.gd_local_history/local_history_panel.gd/local_history_panel.gd-1718246242.124.txt deleted file mode 100644 index 0ad1b1c..0000000 --- a/.gd_local_history/local_history_panel.gd/local_history_panel.gd-1718246242.124.txt +++ /dev/null @@ -1,62 +0,0 @@ -@tool -extends Control -class_name LocalHistoryPanel - -@onready var tree: Tree = $HSplitContainer/Tree -@onready var code_edit: CodeEdit = $HSplitContainer/CodeEdit -const RELOAD = preload("res://addons/gd_local_history/ui/reload.svg") -const REMOVE = preload("res://addons/gd_local_history/ui/remove.svg") -var _tree_root: TreeItem - -func _ready() -> void: - var _tree_root: TreeItem = tree.create_item() - var directories: PackedStringArray = DirAccess.get_directories_at("res://.gd_local_history") - for directory: String in directories: - create_file_tree_item(directory) - -func create_file_tree_item(file_name: String) -> void: - var child: TreeItem = tree.create_item(_tree_root) - child.set_text(0, file_name) - child.set_custom_color(0, Color.WHITE_SMOKE) - child.add_button(0, REMOVE, 1) - child.set_button_color(0, 0, Color.INDIAN_RED) - child.add_button(0, RELOAD, 2) - child.set_button_tooltip_text(0, 0, "Delete %s" % file_name) - child.set_button_tooltip_text(0, 1, "Refresh %s" % file_name) - -func _on_tree_item_selected() -> void: - var selected_tree_item: TreeItem = tree.get_selected() - var metadata: Variant = selected_tree_item.get_metadata(0) - if (metadata != null): - code_edit.text = metadata - return - - var folder_path: String = "res://.gd_local_history/%s" % selected_tree_item.get_text(0) - _refresh_tree_item(selected_tree_item, folder_path) - -func _on_tree_button_clicked(item: TreeItem, column: int, id: int, mouse_button_index: int) -> void: - var folder_path: String = "res://.gd_local_history/%s" % item.get_text(0) - match (id): - 1: - _clear_tree_item(item, folder_path, true) - 2: - _refresh_tree_item(item, folder_path) - _: - pass - -func _clear_tree_item(tree_item: TreeItem, folder_path: String = "", delete_files: bool = false) -> void: - if (delete_files): - for source_code_file_name: String in DirAccess.get_files_at(folder_path): - DirAccess.remove_absolute(folder_path + "/%s" % source_code_file_name) - DirAccess.remove_absolute(folder_path) - tree_item.free() - else: - for child: TreeItem in tree_item.get_children(): - tree_item.remove_child(child) - -func _refresh_tree_item(tree_item: TreeItem, folder_path: String) -> void: - _clear_tree_item(tree_item) - for source_code_file_name: String in DirAccess.get_files_at(folder_path): - var txt_child: TreeItem = tree_item.create_child() - txt_child.set_text(0, source_code_file_name) - txt_child.set_metadata(0, FileAccess.open(folder_path + "/%s" % source_code_file_name, FileAccess.READ).get_as_text()) diff --git a/.gitignore b/.gitignore index d9aac21..01f0381 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # Godot 4+ specific ignores .godot/ +.gd_local_history/ # Godot-specific ignores .import/