-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit bff163c
Showing
20 changed files
with
568 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
.gd_local_history/gd_local_history.gd/gd_local_history.gd-1718243264.519.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
@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() |
37 changes: 37 additions & 0 deletions
37
.gd_local_history/gd_local_history.gd/gd_local_history.gd-1718246148.107.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
@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() |
40 changes: 40 additions & 0 deletions
40
.gd_local_history/gd_local_history.gd/gd_local_history.gd-1718246187.014.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
@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() |
62 changes: 62 additions & 0 deletions
62
.gd_local_history/local_history_panel.gd/local_history_panel.gd-1718246233.895.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
@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()) |
62 changes: 62 additions & 0 deletions
62
.gd_local_history/local_history_panel.gd/local_history_panel.gd-1718246242.124.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
@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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Normalize EOL for all files that Git considers text files. | ||
* text=auto eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Godot 4+ specific ignores | ||
.godot/ | ||
|
||
# Godot-specific ignores | ||
.import/ | ||
export.cfg | ||
export_presets.cfg | ||
|
||
# Imported translations (automatically generated from CSV files) | ||
*.translation | ||
|
||
# Mono-specific ignores | ||
.mono/ | ||
data_*/ | ||
mono_crash.*.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Jayden Sipe | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# gd-local-history | ||
A local history plugin for Godot, similar to those found in many IDEs. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
@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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[plugin] | ||
|
||
name="GDLocalHistory" | ||
description="" | ||
author="" | ||
version="" | ||
script="gd_local_history.gd" |
62 changes: 62 additions & 0 deletions
62
addons/gd_local_history/ui/local_history_panel/local_history_panel.gd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
@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()) |
Oops, something went wrong.