From 584452e1180672e20d859a167b91b258702df50d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Santilio?= Date: Thu, 29 Oct 2020 12:42:14 +0100 Subject: [PATCH 1/4] Delete CsvEditor.gd --- addons/file-editor/scripts/CsvEditor.gd | 217 ------------------------ 1 file changed, 217 deletions(-) delete mode 100644 addons/file-editor/scripts/CsvEditor.gd diff --git a/addons/file-editor/scripts/CsvEditor.gd b/addons/file-editor/scripts/CsvEditor.gd deleted file mode 100644 index 6530df5..0000000 --- a/addons/file-editor/scripts/CsvEditor.gd +++ /dev/null @@ -1,217 +0,0 @@ -tool -extends Control - -var IconLoader = preload("res://addons/file-editor/scripts/IconLoader.gd").new() -var LastOpenedFiles = preload("res://addons/file-editor/scripts/LastOpenedFiles.gd").new() - -onready var Table = $Editor/TableContainer/ScrollContainer/Table -onready var AlignBTN = $Editor/Buttons/align_bt.get_popup() -onready var EditBTN = $Editor/Buttons/edit_bt.get_popup() -onready var OptionsBTN = $Editor/Buttons/options_btn.get_popup() -onready var FileInfo = $Editor/FileInfo -onready var ReadOnly = $Editor/FileInfo/Readonly - -onready var Horizontal = $Editor/Horizontal -onready var Vertical = $Editor/TableContainer/Vertical - -onready var ChangeDelimiterDialog = $ChangeDelimiterDialog - -var current_file_path : String = "" - -var rows : int -var columns : int -var csv_delimiter : String -var filepath : String - -signal update_file() - -func _ready(): - add_to_group("csv_editor") - connect_signals() - - load_icons() - -func connect_signals(): - AlignBTN.connect("id_pressed",self,"on_align_pressed") - EditBTN.connect("id_pressed",self,"on_edit_pressed") - OptionsBTN.connect("id_pressed",self,"on_options_pressed") - ReadOnly.connect("toggled",self,"_on_Readonly_toggled") - ChangeDelimiterDialog.connect("confirmed",self,"on_changedelimiter_confirmed") - - connect("visibility_changed",self,"_on_visibility_changed") - -func load_icons(): - $Editor/Buttons/align_bt.set_button_icon(IconLoader.load_icon_from_name("align")) - $Editor/Buttons/edit_bt.set_button_icon(IconLoader.load_icon_from_name("edit_")) - - AlignBTN.set_item_icon(0,IconLoader.load_icon_from_name("text-left")) - AlignBTN.set_item_icon(1,IconLoader.load_icon_from_name("text-center")) - AlignBTN.set_item_icon(2,IconLoader.load_icon_from_name("text-right")) - AlignBTN.set_item_icon(3,IconLoader.load_icon_from_name("text-fill")) - - EditBTN.set_item_icon(0,IconLoader.load_icon_from_name("row")) - EditBTN.set_item_icon(1,IconLoader.load_icon_from_name("column")) - EditBTN.set_item_icon(3,IconLoader.load_icon_from_name("save")) - - ReadOnly.set("custom_icons/checked",IconLoader.load_icon_from_name("read")) - ReadOnly.set("custom_icons/unchecked",IconLoader.load_icon_from_name("edit")) - -func open_csv_file(filepath : String, csv_delimiter : String) -> void: - self.filepath = filepath - var csv = File.new() - csv.open(filepath,File.READ) - var rows : Array = [] - var columns = -1 - while not csv.eof_reached(): - var csv_line = csv.get_csv_line(csv_delimiter) - if Array(csv_line) != [""]: - rows.append(csv_line) - if columns == -1: - columns = rows[0].size() - csv.close() - self.csv_delimiter = csv_delimiter - load_file_in_table(rows,columns) - ReadOnly.pressed = (true) - $Editor/FileInfo/delimiter.set_text(csv_delimiter) - ChangeDelimiterDialog.get_node("VBoxContainer/delim_read").set_text(csv_delimiter) - -func load_file_in_table(rows : Array, columns : int) -> void: - Table.set_columns(columns) - for row in rows: - add_row(row.size(),"",row) - update_dimensions(rows.size()-1,columns) - -func add_row(columns : int, cell_text : String = "", cell2text : PoolStringArray = []): - for i in range(0,columns): - if cell2text.size()<1: - var cell = LineEdit.new() - cell.set_h_size_flags(2) - cell.set_h_size_flags(3) - cell.set_text(cell_text) - Table.add_child(cell) - if ReadOnly.pressed: - cell.set_editable(false) - - else: -# if cell2text[i]!="": - var cell = LineEdit.new() - cell.set_h_size_flags(2) - cell.set_h_size_flags(3) - Table.add_child(cell) - if cell2text: - cell.set_text(cell2text[i]) - else: - cell.set_text(cell_text) - if ReadOnly.pressed: - cell.set_editable(false) - -func add_column(rows : int ,cell_text : String = ""): - for i in range(0,rows): - var cell = LineEdit.new() - cell.set_h_size_flags(2) - cell.set_h_size_flags(3) - Table.add_child(cell) - Table.move_child(cell,(columns)*(i+1)-1) - cell.set_text(cell_text) - if ReadOnly.pressed: - cell.set_editable(false) - -func on_align_pressed(index : int) -> void: - for cell in Table.get_children(): - cell.set_align(index) - -func on_edit_pressed(index :int) -> void: - match index: - 0: - update_dimensions(rows+1,columns) - add_row(columns) - 1: - update_dimensions(rows,columns+1) - add_column(rows) - 3: - save_table() - -func on_options_pressed(index : int) -> void: - match index: - 0: - ChangeDelimiterDialog.popup() - -func table_ruler(rows : int, columns : int): - for child in Vertical.get_children(): - child.queue_free() - for child in Horizontal.get_children(): - child.queue_free() - for i in range(0,rows): - var lb = Label.new() - lb.set_h_size_flags(2) - lb.set_h_size_flags(3) - lb.set_text(str(i+1)) - Vertical.add_child(lb) - var lb = Label.new() - lb.set_text(" ") - Horizontal.add_child(lb) - for j in range(0,columns): - var lb2 = Label.new() - lb2.set_h_size_flags(2) - lb2.set_h_size_flags(3) - lb2.set_align(1) - lb2.set_text(str(j+1)) - Horizontal.add_child(lb2) - -func update_dimensions(rows : int, columns : int): - self.rows = rows - self.columns = columns - table_ruler(rows,columns) - Table.set_columns(columns) - FileInfo.get_node("rows").set_text(str(rows)) - FileInfo.get_node("columns").set_text(str(columns)) - -func _on_Readonly_toggled(button_pressed): - if button_pressed: - ReadOnly.set_text("Read Only") - for cell in Table.get_children(): - cell.set_editable(false) - else: - ReadOnly.set_text("Can Edit") - for cell in Table.get_children(): - cell.set_editable(true) - -func save_table(): - var content : Array = [] - var column = 0 - var row_ : PoolStringArray = [] - for cell in Table.get_children(): - if column < columns: - row_.append(cell.get_text()) - column+=1 - else: - content.append(row_) - row_ = [] - row_.append(cell.get_text()) - column = 1 - content.append(row_) - - var file = File.new() - file.open(filepath, File.WRITE) - for line in content: - file.store_csv_line(line,csv_delimiter) - file.close() - - emit_signal("update_file") - -func on_changedelimiter_confirmed(): - change_delimiter(ChangeDelimiterDialog.get_node("VBoxContainer/delim_read").get_text()) - -func change_delimiter(delim : String): - csv_delimiter = delim - reload() - -func reload(): - for element in Table.get_children(): - element.queue_free() - open_csv_file(current_file_path,csv_delimiter) - FileInfo.show() - -func _on_visibility_changed(): - if visible: - reload() From 0038e85263c60d4b4fc1945a4eb2f227ed25a195 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Santilio?= Date: Tue, 17 Nov 2020 18:45:53 +0100 Subject: [PATCH 2/4] Update README.md --- addons/file-editor/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/addons/file-editor/README.md b/addons/file-editor/README.md index 99b9c4c..5b89c9c 100644 --- a/addons/file-editor/README.md +++ b/addons/file-editor/README.md @@ -21,6 +21,7 @@ When opening / creating a file, the editor will open and you will be able to edi You can just *Save* the file, or *Save file As* a new file (if it is a new file but also to make some copies). You will also be able to see some informations about the file you are editing (time and date of last edit) and you can set your editor to *Read Only* if you don't want to make changes but still read the content of the file. Multiple files can be opened in different tabs. +![preview_0](https://imgur.com/X3lA49e.png) ![preview_1](https://imgur.com/qYcRbWM.png) ![preview1](https://i.imgur.com/BbZzKzD.png)![preview2](https://i.imgur.com/asggk4f.png) ![preview3](https://i.imgur.com/omReRZr.png) ![preview4](https://i.imgur.com/d8pMJsE.png) ## How do I install it? From cc0afa07bd217367026b896900e7a07f1aa999aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Santilio?= Date: Tue, 17 Nov 2020 18:46:20 +0100 Subject: [PATCH 3/4] Update README.md --- addons/file-editor/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/file-editor/README.md b/addons/file-editor/README.md index 5b89c9c..81bffb9 100644 --- a/addons/file-editor/README.md +++ b/addons/file-editor/README.md @@ -22,7 +22,8 @@ You can just *Save* the file, or *Save file As* a new file (if it is a new file You will also be able to see some informations about the file you are editing (time and date of last edit) and you can set your editor to *Read Only* if you don't want to make changes but still read the content of the file. Multiple files can be opened in different tabs. ![preview_0](https://imgur.com/X3lA49e.png) ![preview_1](https://imgur.com/qYcRbWM.png) -![preview1](https://i.imgur.com/BbZzKzD.png)![preview2](https://i.imgur.com/asggk4f.png) ![preview3](https://i.imgur.com/omReRZr.png) ![preview4](https://i.imgur.com/d8pMJsE.png) +![preview1](https://i.imgur.com/BbZzKzD.png)![preview2](https://i.imgur.com/asggk4f.png) ![preview3](https://i.imgur.com/omReRZr.png) + ## How do I install it? **Manual** From 48fd4ddb805827eb13d598bba9499eeddc8e2647 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Santilio?= Date: Tue, 17 Nov 2020 18:47:02 +0100 Subject: [PATCH 4/4] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b50594b..31b3e96 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,8 @@ When opening / creating a file, the editor will open and you will be able to edi You can just *Save* the file, or *Save file As* a new file (if it is a new file but also to make some copies). You will also be able to see some informations about the file you are editing (time and date of last edit) and you can set your editor to *Read Only* if you don't want to make changes but still read the content of the file. Multiple files can be opened in different tabs. -![preview1](https://i.imgur.com/BbZzKzD.png)![preview2](https://i.imgur.com/asggk4f.png) ![preview3](https://i.imgur.com/omReRZr.png) ![preview4](https://i.imgur.com/d8pMJsE.png) +![preview_0](https://imgur.com/X3lA49e.png) ![preview_1](https://imgur.com/qYcRbWM.png) +![preview1](https://i.imgur.com/BbZzKzD.png)![preview2](https://i.imgur.com/asggk4f.png) ![preview3](https://i.imgur.com/omReRZr.png) ## How do I install it? **Manual**