diff --git a/file-editor/README.md b/file-editor/README.md new file mode 100644 index 0000000..d380eba --- /dev/null +++ b/file-editor/README.md @@ -0,0 +1,14 @@ +# Godot Text Editor +A little plugin to easy-way manage your text files inside your project folder. + +Author: *"Nicolo (fenix) Santilio"* +Version: *0.1.0* +Godot Version: *3.1.1-stable* + +**This repository was pushed directly from Godot Engine Editor thanks to [GitHub Integration](https://github.com/fenix-hub/godot-engine.github-integration)!** + +## What is this? +Building... + +## How does it work? +Building... \ No newline at end of file diff --git a/file-editor/TODO.md b/file-editor/TODO.md new file mode 100644 index 0000000..d42040e --- /dev/null +++ b/file-editor/TODO.md @@ -0,0 +1 @@ +### to do (v-0.x.x) diff --git a/file-editor/VERSION.md b/file-editor/VERSION.md new file mode 100644 index 0000000..b3b0923 --- /dev/null +++ b/file-editor/VERSION.md @@ -0,0 +1,3 @@ +**version 0.1.0** + + diff --git a/file-editor/fonts/Roboto-Black.ttf b/file-editor/fonts/Roboto-Black.ttf new file mode 100644 index 0000000..86ec2b2 Binary files /dev/null and b/file-editor/fonts/Roboto-Black.ttf differ diff --git a/file-editor/fonts/Roboto-Regular.ttf b/file-editor/fonts/Roboto-Regular.ttf new file mode 100644 index 0000000..7d9a6c4 Binary files /dev/null and b/file-editor/fonts/Roboto-Regular.ttf differ diff --git a/file-editor/icon.png b/file-editor/icon.png new file mode 100644 index 0000000..84164c3 Binary files /dev/null and b/file-editor/icon.png differ diff --git a/file-editor/icons/delete.svg b/file-editor/icons/delete.svg new file mode 100644 index 0000000..ee988ab --- /dev/null +++ b/file-editor/icons/delete.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/file-editor/icons/edit.png b/file-editor/icons/edit.png new file mode 100644 index 0000000..32224eb Binary files /dev/null and b/file-editor/icons/edit.png differ diff --git a/file-editor/icons/file.svg b/file-editor/icons/file.svg new file mode 100644 index 0000000..67a081a --- /dev/null +++ b/file-editor/icons/file.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/file-editor/icons/new.svg b/file-editor/icons/new.svg new file mode 100644 index 0000000..1f53043 --- /dev/null +++ b/file-editor/icons/new.svg @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/file-editor/icons/read.svg b/file-editor/icons/read.svg new file mode 100644 index 0000000..e3aff37 --- /dev/null +++ b/file-editor/icons/read.svg @@ -0,0 +1,3 @@ + + + diff --git a/file-editor/icons/save.svg b/file-editor/icons/save.svg new file mode 100644 index 0000000..d85b7ce --- /dev/null +++ b/file-editor/icons/save.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/file-editor/icons/saveas.png b/file-editor/icons/saveas.png new file mode 100644 index 0000000..5fe257a Binary files /dev/null and b/file-editor/icons/saveas.png differ diff --git a/file-editor/plugin.cfg b/file-editor/plugin.cfg new file mode 100644 index 0000000..241200a --- /dev/null +++ b/file-editor/plugin.cfg @@ -0,0 +1,7 @@ +[plugin] + +name="File Editor" +description="An internal file editor to view and edit text files in your project folder." +author="Nicolò 'fenix' Santilio" +version="0.1.0" +script="scripts/file-editor.gd" diff --git a/file-editor/scenes/FileEditor.tscn b/file-editor/scenes/FileEditor.tscn new file mode 100644 index 0000000..976a2c5 --- /dev/null +++ b/file-editor/scenes/FileEditor.tscn @@ -0,0 +1,163 @@ +[gd_scene load_steps=18 format=2] + +[ext_resource path="res://addons/file-editor/scripts/FileEditor.gd" type="Script" id=1] +[ext_resource path="res://addons/file-editor/icons/new.svg" type="Texture" id=2] +[ext_resource path="res://addons/file-editor/icons/file.svg" type="Texture" id=3] +[ext_resource path="res://addons/file-editor/icons/delete.svg" type="Texture" id=4] +[ext_resource path="res://addons/file-editor/fonts/Roboto-Black.ttf" type="DynamicFontData" id=5] +[ext_resource path="res://addons/file-editor/icons/read.svg" type="Texture" id=6] +[ext_resource path="res://addons/file-editor/icons/edit.png" type="Texture" id=7] +[ext_resource path="res://addons/file-editor/icons/save.svg" type="Texture" id=8] +[ext_resource path="res://addons/file-editor/icons/saveas.png" type="Texture" id=9] + +[sub_resource type="DynamicFont" id=1] +outline_size = 3 +outline_color = Color( 0.168627, 0.160784, 0.192157, 1 ) +font_data = ExtResource( 5 ) + +[sub_resource type="StyleBoxEmpty" id=2] + +[sub_resource type="StyleBoxEmpty" id=3] + +[sub_resource type="StyleBoxEmpty" id=4] + +[sub_resource type="StyleBoxEmpty" id=5] + +[sub_resource type="StyleBoxEmpty" id=6] + +[sub_resource type="StyleBoxEmpty" id=7] + +[sub_resource type="DynamicFont" id=8] +font_data = ExtResource( 5 ) + +[node name="FileEditor" type="Control"] +anchor_right = 1.0 +anchor_bottom = 1.0 +script = ExtResource( 1 ) + +[node name="Container" type="VBoxContainer" parent="."] +anchor_right = 1.0 +anchor_bottom = 1.0 + +[node name="Buttons" type="HBoxContainer" parent="Container"] +editor/display_folded = true +margin_right = 1024.0 +margin_bottom = 22.0 + +[node name="newfile_btn" type="Button" parent="Container/Buttons"] +margin_right = 338.0 +margin_bottom = 22.0 +size_flags_horizontal = 3 +text = "Create new File" +icon = ExtResource( 2 ) + +[node name="openfile_btn" type="Button" parent="Container/Buttons"] +margin_left = 342.0 +margin_right = 680.0 +margin_bottom = 22.0 +size_flags_horizontal = 3 +text = "Open File" +icon = ExtResource( 3 ) + +[node name="deletefile_btn" type="Button" parent="Container/Buttons"] +margin_left = 684.0 +margin_right = 1024.0 +margin_bottom = 22.0 +size_flags_horizontal = 3 +text = "Delete File" +icon = ExtResource( 4 ) + +[node name="HSeparator" type="HSeparator" parent="Container"] +margin_top = 26.0 +margin_right = 1024.0 +margin_bottom = 30.0 + +[node name="Label" type="Label" parent="Container"] +margin_top = 34.0 +margin_right = 1024.0 +margin_bottom = 53.0 +custom_fonts/font = SubResource( 1 ) +text = "EDITOR" +align = 1 + +[node name="Editor" type="VBoxContainer" parent="Container"] +margin_top = 57.0 +margin_right = 1024.0 +margin_bottom = 600.0 +size_flags_vertical = 3 + +[node name="TopBar" type="HBoxContainer" parent="Container/Editor"] +margin_right = 1024.0 +margin_bottom = 24.0 + +[node name="Filename" type="LineEdit" parent="Container/Editor/TopBar"] +margin_right = 917.0 +margin_bottom = 24.0 +size_flags_horizontal = 11 +expand_to_text_length = true + +[node name="Readonly" type="CheckBox" parent="Container/Editor/TopBar"] +margin_left = 921.0 +margin_right = 1000.0 +margin_bottom = 24.0 +custom_icons/checked = ExtResource( 6 ) +custom_icons/unchecked = ExtResource( 7 ) +custom_styles/hover = SubResource( 2 ) +custom_styles/pressed = SubResource( 3 ) +custom_styles/focus = SubResource( 4 ) +custom_styles/disabled = SubResource( 5 ) +custom_styles/hover_pressed = SubResource( 6 ) +custom_styles/normal = SubResource( 7 ) +custom_fonts/font = SubResource( 8 ) +custom_colors/font_color = Color( 0.145098, 0.172549, 0.231373, 1 ) +custom_colors/font_color_pressed = Color( 1, 1, 1, 1 ) +text = "Can Edit" +flat = true + +[node name="close_btn" type="Button" parent="Container/Editor/TopBar"] +margin_left = 1004.0 +margin_right = 1024.0 +margin_bottom = 24.0 +text = "X" + +[node name="TextEditor" type="TextEdit" parent="Container/Editor"] +margin_top = 28.0 +margin_right = 1024.0 +margin_bottom = 517.0 +size_flags_vertical = 3 +syntax_highlighting = true +show_line_numbers = true +breakpoint_gutter = true +highlight_all_occurrences = true +smooth_scrolling = true +caret_blink = true +caret_blink_speed = 0.1 + +[node name="EditorButtons" type="HBoxContainer" parent="Container/Editor"] +margin_top = 521.0 +margin_right = 1024.0 +margin_bottom = 543.0 + +[node name="savefile_btn" type="Button" parent="Container/Editor/EditorButtons"] +margin_right = 510.0 +margin_bottom = 22.0 +size_flags_horizontal = 3 +text = "Save File" +icon = ExtResource( 8 ) + +[node name="savefileas_btn" type="Button" parent="Container/Editor/EditorButtons"] +margin_left = 514.0 +margin_right = 1024.0 +margin_bottom = 22.0 +size_flags_horizontal = 3 +text = "Save File as..." +icon = ExtResource( 9 ) + +[node name="FileList" type="FileDialog" parent="."] +margin_top = 24.0 +margin_right = 1024.0 +margin_bottom = 600.0 +size_flags_vertical = 3 +popup_exclusive = true +dialog_hide_on_ok = true +[connection signal="toggled" from="Container/Editor/TopBar/Readonly" to="." method="_on_Readonly_toggled"] diff --git a/file-editor/scripts/FileEditor.gd b/file-editor/scripts/FileEditor.gd new file mode 100644 index 0000000..33f8749 --- /dev/null +++ b/file-editor/scripts/FileEditor.gd @@ -0,0 +1,165 @@ +tool +extends Control + +onready var FileList = $FileList + +onready var TextEditor = $Container/Editor/TextEditor +onready var Filename = $Container/Editor/TopBar/Filename +onready var CloseFile = $Container/Editor/TopBar/close_btn +onready var Editor = $Container/Editor + +onready var OpenFile = $Container/Buttons/openfile_btn +onready var NewFile = $Container/Buttons/newfile_btn +onready var DeleteFile = $Container/Buttons/deletefile_btn + +onready var SaveFile = $Container/Editor/EditorButtons/savefile_btn +onready var SaveFileAs = $Container/Editor/EditorButtons/savefileas_btn + +onready var ReadOnly = $Container/Editor/TopBar/Readonly + +var DIRECTORY : String = "res://" +var EXCEPTIONS : String = "addons" +var EXTENSIONS : PoolStringArray = [ +"*.txt ; Plain Text File", +"*.rtf ; Rich Text Format File", +"*.log ; Log File", +"*.md ; MD File", +"*.doc ; WordPad Document", +"*.doc ; Microsoft Word Document", +"*.docm ; Word Open XML Macro-Enabled Document", +"*.docx ; Microsoft Word Open XML Document", +"*.bbs ; Bulletin Board System Text", +] + +var directories = [] +var files = [] + +# ----- +var current_file : File = File.new() +var current_path : String = "" +var current_content : String = "" +# ----- + +func _ready(): + OpenFile.connect("pressed",self,"open_selected_file") + NewFile.connect("pressed",self,"create_new_file") + DeleteFile.connect("pressed",self,"delete_selected_file") + + SaveFile.connect("pressed",self,"save_file") + SaveFileAs.connect("pressed",self,"save_file_as") + + CloseFile.connect("pressed",self,"close_editor") + + Filename.set_editable(false) + SaveFile.set_disabled(true) + + FileList.set_filters(EXTENSIONS) + + Editor.hide() + +func close_editor(): + Editor.hide() + Filename.set_text("") + TextEditor.set_text("") + current_file.close() + current_file = File.new() + current_path = "" + current_content = "" + +func clear_editor(): + TextEditor.set_text("") + Filename.set_text("") + current_file = File.new() + +func create_new_file(): + close_editor() + SaveFile.set_disabled(true) + Editor.show() + +func open_filelist(): + FileList.update() + FileList.popup() + FileList.set_position(OS.get_screen_size()/2 - FileList.get_size()/2) + +func save_file_as(): + current_content = TextEditor.get_text() + FileList.mode = FileDialog.MODE_SAVE_FILE + FileList.set_title("Save this file as...") + if FileList.is_connected("file_selected",self,"delete_file"): + FileList.disconnect("file_selected",self,"delete_file") + if not FileList.is_connected("file_selected",self,"open_file"): + FileList.connect("file_selected",self,"open_file",[current_content]) + else: + FileList.disconnect("file_selected",self,"open_file") + FileList.connect("file_selected",self,"open_file",[current_content]) + open_filelist() + +func open_selected_file(): + clear_editor() + FileList.mode = FileDialog.MODE_OPEN_FILE + FileList.set_title("Select a file you want to edit") + if FileList.is_connected("file_selected",self,"delete_file"): + FileList.disconnect("file_selected",self,"delete_file") + if not FileList.is_connected("file_selected",self,"open_file"): + FileList.connect("file_selected",self,"open_file",[""]) + else: + FileList.disconnect("file_selected",self,"open_file") + FileList.connect("file_selected",self,"open_file",[""]) + open_filelist() + +func delete_selected_file(): + FileList.mode = FileDialog.MODE_OPEN_FILE + FileList.set_title("Select a file you want to delete") + if FileList.is_connected("file_selected",self,"open_file"): + FileList.disconnect("file_selected",self,"open_file") + if not FileList.is_connected("file_selected",self,"delete_file"): + FileList.connect("file_selected",self,"delete_file") + else: + FileList.disconnect("file_selected",self,"delete_file") + FileList.connect("file_selected",self,"delete_file") + open_filelist() + +func open_file(path : String, content_file : String): + var content = "" + if content_file == "" or content_file == null: + current_file.open(path,File.READ) + content = current_file.get_as_text() + else: + content = content_file + current_file.open(path,File.WRITE) + current_file.store_line(content) + + TextEditor.set_text(content) + Filename.set_text(path) + + current_file.close() + + current_path = path + current_content = content + + Editor.show() + SaveFile.set_disabled(false) + +func save_file(): + if current_path == "" or current_path == null: + save_file_as() + else: + current_file.open(current_path,File.WRITE) + current_content = TextEditor.get_text() + if current_content == null: + current_content = "" + current_file.store_line(current_content) + current_file.close() + +func delete_file(path : String): + clear_editor() + var dir = Directory.new() + dir.remove(path) + +func _on_Readonly_toggled(button_pressed): + if button_pressed: + ReadOnly.set_text("Read Only") + TextEditor.readonly = (true) + else: + ReadOnly.set_text("Can Edit") + TextEditor.readonly = (false) diff --git a/file-editor/scripts/file-editor.gd b/file-editor/scripts/file-editor.gd new file mode 100644 index 0000000..0135adf --- /dev/null +++ b/file-editor/scripts/file-editor.gd @@ -0,0 +1,14 @@ +tool +extends EditorPlugin + +var doc + +func _enter_tree(): + doc = preload("../scenes/FileEditor.tscn").instance() + add_control_to_dock(EditorPlugin.DOCK_SLOT_LEFT_BR,doc) +# add_autoload_singleton("UserData","res://addons/github-integration/scripts/user_data.gd") + +func _exit_tree(): + remove_control_from_docks(doc) +# remove_autoload_singleton("UserData") + doc.queue_free() \ No newline at end of file