mirror of
https://github.com/Relintai/godot-engine.file-editor.git
synced 2024-11-12 22:27:22 +01:00
Types part 2.
This commit is contained in:
parent
c382671951
commit
a01c7c4bca
@ -62,7 +62,7 @@ var confirmation_close : ConfirmationDialog = null
|
||||
|
||||
var select_font_dialog : FileDialog = null
|
||||
|
||||
var LastOpenedFiles = null
|
||||
var LastOpenedFiles : Reference = null
|
||||
|
||||
var Preview = preload("res://addons/file-editor/scripts/Preview.gd")
|
||||
var VanillaEditor = preload("res://addons/file-editor/scripts/VanillaEditor.gd")
|
||||
@ -77,7 +77,7 @@ var current_font : DynamicFont
|
||||
|
||||
var editing_file : bool = false
|
||||
|
||||
func _init():
|
||||
func _init() -> void:
|
||||
set_anchors_and_margins_preset(Control.PRESET_WIDE)
|
||||
size_flags_vertical = SIZE_EXPAND_FILL
|
||||
size_flags_horizontal = SIZE_EXPAND_FILL
|
||||
@ -270,7 +270,7 @@ func _init():
|
||||
select_font_dialog.filters = farr
|
||||
|
||||
|
||||
func _ready():
|
||||
func _ready() -> void:
|
||||
if not Engine.is_editor_hint():
|
||||
return
|
||||
|
||||
@ -285,7 +285,7 @@ func _ready():
|
||||
file_list.set_filters(EXTENSIONS)
|
||||
|
||||
|
||||
func connect_signals():
|
||||
func connect_signals() -> void:
|
||||
file_list.connect("confirmed",self,"update_list")
|
||||
file_btn_popup.connect("id_pressed",self,"_on_file_btn_pressed")
|
||||
preview_btn_popup.connect("id_pressed",self,"_on_preview_btn_pressed")
|
||||
@ -298,7 +298,7 @@ func connect_signals():
|
||||
select_font_dialog.connect("file_selected",self,"_on_font_selected")
|
||||
|
||||
|
||||
func create_selected_file():
|
||||
func create_selected_file() -> void:
|
||||
update_list()
|
||||
|
||||
file_list.mode = FileDialog.MODE_SAVE_FILE
|
||||
@ -315,7 +315,7 @@ func create_selected_file():
|
||||
|
||||
open_file_list()
|
||||
|
||||
func open_selected_file():
|
||||
func open_selected_file() -> void:
|
||||
update_list()
|
||||
|
||||
file_list.mode = FileDialog.MODE_OPEN_FILE
|
||||
@ -332,7 +332,7 @@ func open_selected_file():
|
||||
|
||||
open_file_list()
|
||||
|
||||
func delete_selected_file():
|
||||
func delete_selected_file() -> void:
|
||||
update_list()
|
||||
|
||||
file_list.mode = FileDialog.MODE_OPEN_FILES
|
||||
@ -349,7 +349,7 @@ func delete_selected_file():
|
||||
|
||||
open_file_list()
|
||||
|
||||
func save_current_file_as():
|
||||
func save_current_file_as() -> void:
|
||||
update_list()
|
||||
file_list.mode = FileDialog.MODE_SAVE_FILE
|
||||
file_list.set_title("Save this File as...")
|
||||
@ -365,7 +365,7 @@ func save_current_file_as():
|
||||
|
||||
open_file_list()
|
||||
|
||||
func _on_file_btn_pressed(index : int):
|
||||
func _on_file_btn_pressed(index : int) -> void:
|
||||
match index:
|
||||
FileMenuOptions.FILE_MENU_OPTION_NEW:
|
||||
create_selected_file()
|
||||
@ -392,7 +392,7 @@ func _on_file_btn_pressed(index : int):
|
||||
FileMenuOptions.FILE_MENU_OPTION_REPLACE:
|
||||
current_editor.open_replace_box()
|
||||
|
||||
func _on_preview_btn_pressed(id : int):
|
||||
func _on_preview_btn_pressed(id : int) -> void:
|
||||
if id == 0:
|
||||
bbcode_preview()
|
||||
elif id == 1:
|
||||
@ -402,16 +402,16 @@ func _on_preview_btn_pressed(id : int):
|
||||
elif id == 3:
|
||||
csv_preview()
|
||||
|
||||
func _on_settings_btn_pressed(index : int):
|
||||
func _on_settings_btn_pressed(index : int) -> void:
|
||||
match index:
|
||||
0:
|
||||
select_font_dialog.popup()
|
||||
|
||||
func _on_font_selected(font_path : String):
|
||||
func _on_font_selected(font_path : String) -> void:
|
||||
current_editor.set_font(font_path)
|
||||
LastOpenedFiles.store_editor_fonts(current_file_path.get_file(), font_path)
|
||||
|
||||
func _on_fileitem_pressed(index : int):
|
||||
func _on_fileitem_pressed(index : int) -> void:
|
||||
current_file_index = index
|
||||
var selected_item_metadata : Array = open_file_list.get_item_metadata(current_file_index)
|
||||
var extension : String = selected_item_metadata[0].current_path.get_file().get_extension()
|
||||
@ -441,7 +441,7 @@ func _on_fileitem_pressed(index : int):
|
||||
else:
|
||||
current_editor.draw_minimap(false)
|
||||
|
||||
func open_file(path : String, font : String = "null"):
|
||||
func open_file(path : String, font : String = "null") -> void:
|
||||
if current_file_path != path:
|
||||
current_file_path = path
|
||||
|
||||
@ -456,7 +456,7 @@ func open_file(path : String, font : String = "null"):
|
||||
|
||||
current_editor.show()
|
||||
|
||||
func generate_file_item(path : String , veditor : Control):
|
||||
func generate_file_item(path : String , veditor : Control) -> void:
|
||||
open_file_name.set_text(path)
|
||||
open_file_list.add_item(path.get_file(), null,true)
|
||||
|
||||
@ -495,13 +495,13 @@ func open_in_vanillaeditor(path : String) -> Control:
|
||||
|
||||
return editor
|
||||
|
||||
func close_file(index):
|
||||
func close_file(index) -> void:
|
||||
if editing_file:
|
||||
confirmation_close.popup()
|
||||
else:
|
||||
confirm_close(index)
|
||||
|
||||
func confirm_close(index):
|
||||
func confirm_close(index) -> void:
|
||||
LastOpenedFiles.remove_opened_file(index,open_file_list)
|
||||
open_file_list.remove_item(index)
|
||||
open_file_name.clear()
|
||||
@ -511,7 +511,7 @@ func confirm_close(index):
|
||||
open_file_list.select(index-1)
|
||||
_on_fileitem_pressed(index-1)
|
||||
|
||||
func _on_update_file():
|
||||
func _on_update_file() -> void:
|
||||
var current_file : File = File.new()
|
||||
current_file.open(current_file_path,File.READ)
|
||||
|
||||
@ -522,23 +522,23 @@ func _on_update_file():
|
||||
|
||||
current_editor.new_file_open(current_content,last_modified,current_file_path)
|
||||
|
||||
func delete_file(files_selected : PoolStringArray):
|
||||
func delete_file(files_selected : PoolStringArray) -> void:
|
||||
var dir = Directory.new()
|
||||
for file in files_selected:
|
||||
dir.remove(file)
|
||||
|
||||
update_list()
|
||||
|
||||
func open_new_file_dialogue():
|
||||
func open_new_file_dialogue() -> void:
|
||||
new_file_dialogue.popup()
|
||||
new_file_dialogue.set_position(OS.get_screen_size()/2 - new_file_dialogue.get_size()/2)
|
||||
|
||||
func open_file_list():
|
||||
func open_file_list() -> void:
|
||||
update_list()
|
||||
file_list.popup()
|
||||
file_list.set_position(OS.get_screen_size()/2 - file_list.get_size()/2)
|
||||
|
||||
func create_new_file(given_path : String):
|
||||
func create_new_file(given_path : String) -> void:
|
||||
var current_file : File = File.new()
|
||||
current_file.open(given_path,File.WRITE)
|
||||
|
||||
@ -548,7 +548,7 @@ func create_new_file(given_path : String):
|
||||
|
||||
open_file(given_path)
|
||||
|
||||
func save_file(current_path : String):
|
||||
func save_file(current_path : String) -> void:
|
||||
print("Saving file: ",current_path)
|
||||
var current_file : File = File.new()
|
||||
current_file.open(current_path,File.WRITE)
|
||||
@ -579,7 +579,7 @@ func save_file(current_path : String):
|
||||
|
||||
update_list()
|
||||
|
||||
func clean_editor() -> void :
|
||||
func clean_editor() -> void:
|
||||
var nodes : Array = get_tree().get_nodes_in_group("vanilla_editor")
|
||||
|
||||
for i in range(nodes.size()):
|
||||
@ -590,7 +590,7 @@ func clean_editor() -> void :
|
||||
open_file_list.clear()
|
||||
|
||||
|
||||
func csv_preview():
|
||||
func csv_preview() -> void:
|
||||
var preview : Control = Preview.new()
|
||||
get_parent().get_parent().get_parent().add_child(preview)
|
||||
preview.popup()
|
||||
@ -603,21 +603,21 @@ func csv_preview():
|
||||
|
||||
preview.print_csv(rows)
|
||||
|
||||
func bbcode_preview():
|
||||
func bbcode_preview() -> void:
|
||||
var preview : Control = Preview.new()
|
||||
get_parent().get_parent().get_parent().add_child(preview)
|
||||
preview.popup()
|
||||
preview.window_title += " ("+current_file_path.get_file()+")"
|
||||
preview.print_bb(current_editor.text_editor.get_text())
|
||||
|
||||
func markdown_preview():
|
||||
func markdown_preview() -> void:
|
||||
var preview : Control = Preview.new()
|
||||
get_parent().get_parent().get_parent().add_child(preview)
|
||||
preview.popup()
|
||||
preview.window_title += " ("+current_file_path.get_file()+")"
|
||||
preview.print_markdown(current_editor.text_editor.get_text())
|
||||
|
||||
func html_preview():
|
||||
func html_preview() -> void:
|
||||
var preview : Control = Preview.new()
|
||||
get_parent().get_parent().get_parent().add_child(preview)
|
||||
preview.popup()
|
||||
@ -625,32 +625,32 @@ func html_preview():
|
||||
preview.print_html(current_editor.text_editor.get_text())
|
||||
|
||||
|
||||
func _on_vanillaeditor_text_changed():
|
||||
func _on_vanillaeditor_text_changed() -> void:
|
||||
if not open_file_list.get_item_text(current_file_index).begins_with("(*)"):
|
||||
open_file_list.set_item_text(current_file_index,"(*)"+open_file_list.get_item_text(current_file_index))
|
||||
editing_file = true
|
||||
|
||||
func update_list():
|
||||
func update_list() -> void:
|
||||
file_list.invalidate()
|
||||
|
||||
func on_wrap_button(index:int):
|
||||
func on_wrap_button(index:int) -> void:
|
||||
match index:
|
||||
0:
|
||||
current_editor.set_wrap_enabled(false)
|
||||
1:
|
||||
current_editor.set_wrap_enabled(true)
|
||||
|
||||
func on_minimap_button(index:int):
|
||||
func on_minimap_button(index:int) -> void:
|
||||
match index:
|
||||
0:
|
||||
current_editor.draw_minimap(false)
|
||||
1:
|
||||
current_editor.draw_minimap(true)
|
||||
|
||||
func check_file_preview(file : String):
|
||||
func check_file_preview(file : String) -> void:
|
||||
# check whether the opened file has a corresponding preview session for its extension
|
||||
pass
|
||||
|
||||
|
||||
func _on_ConfirmationDialog_confirmed():
|
||||
func _on_ConfirmationDialog_confirmed() -> void:
|
||||
confirm_close(current_file_index)
|
||||
|
@ -7,12 +7,12 @@ func _ready():
|
||||
pass
|
||||
|
||||
func load_icon_from_name(icon_name : String) -> ImageTexture:
|
||||
var file = File.new()
|
||||
var image = Image.new()
|
||||
var texture = ImageTexture.new()
|
||||
var file : File = File.new()
|
||||
var image : Image = Image.new()
|
||||
var texture : ImageTexture = ImageTexture.new()
|
||||
|
||||
file.open("res://addons/file-editor/icons.pngs/"+icon_name+".png.buttonicon", File.READ)
|
||||
var buffer = file.get_buffer(file.get_len())
|
||||
var buffer : PoolByteArray = file.get_buffer(file.get_len())
|
||||
file.close()
|
||||
|
||||
image.load_png_from_buffer(buffer)
|
||||
|
@ -4,7 +4,7 @@ extends Reference
|
||||
var editor_plugin : EditorPlugin = null
|
||||
var editor_settings : EditorSettings = null
|
||||
|
||||
func store_opened_files(filecontainer : Control):
|
||||
func store_opened_files(filecontainer : Control) -> void:
|
||||
var arr : Array = Array()
|
||||
|
||||
for child in range(filecontainer.get_item_count()):
|
||||
@ -18,7 +18,7 @@ func store_opened_files(filecontainer : Control):
|
||||
|
||||
editor_settings.set_project_metadata("file_editor", "files", arr)
|
||||
|
||||
func remove_opened_file(index : int , filecontainer : Control):
|
||||
func remove_opened_file(index : int , filecontainer : Control) -> void:
|
||||
var filepath : String = filecontainer.get_item_metadata(index)[0].current_path
|
||||
var f : String = filepath.get_file()
|
||||
|
||||
@ -60,7 +60,7 @@ func load_opened_files() -> Array:
|
||||
|
||||
return keys
|
||||
|
||||
func store_editor_fonts(file_name : String, font_path : String):
|
||||
func store_editor_fonts(file_name : String, font_path : String) -> void:
|
||||
var fonts_dict : Dictionary = editor_settings.get_project_metadata("file_editor", "file_fonts", Dictionary())
|
||||
fonts_dict[file_name] = font_path
|
||||
editor_settings.set_project_metadata("file_editor", "file_fonts", fonts_dict)
|
||||
|
@ -9,7 +9,7 @@ signal image_loaded()
|
||||
|
||||
var imgBuffer : Image
|
||||
|
||||
func _init():
|
||||
func _init() -> void:
|
||||
window_title = "File preview"
|
||||
resizable = true
|
||||
set_anchors_and_margins_preset(Control.PRESET_WIDE)
|
||||
@ -38,15 +38,15 @@ func _init():
|
||||
|
||||
connect("popup_hide", self, "_on_Preview_popup_hide")
|
||||
|
||||
func print_preview(content : String):
|
||||
func print_preview(content : String) -> void:
|
||||
text_preview.append_bbcode(content)
|
||||
text_preview.show()
|
||||
|
||||
func print_bb(content : String):
|
||||
func print_bb(content : String) -> void:
|
||||
text_preview.append_bbcode(content)
|
||||
text_preview.show()
|
||||
|
||||
func print_markdown(content : String):
|
||||
func print_markdown(content : String) -> void:
|
||||
var result : Array = Array()
|
||||
var bolded : Array = Array()
|
||||
var italics : Array = Array()
|
||||
@ -156,7 +156,7 @@ func print_markdown(content : String):
|
||||
text_preview.append_bbcode(content)
|
||||
text_preview.show()
|
||||
|
||||
func print_html(content : String):
|
||||
func print_html(content : String) -> void:
|
||||
content = content.replace("<i>","[i]")
|
||||
content = content.replace("</i>","[/i]")
|
||||
content = content.replace("<b>","[b]")
|
||||
@ -183,7 +183,7 @@ func print_html(content : String):
|
||||
text_preview.append_bbcode(content)
|
||||
text_preview.show()
|
||||
|
||||
func print_csv(rows : Array):
|
||||
func print_csv(rows : Array) -> void:
|
||||
table_preview.columns = rows[0].size()
|
||||
for item in rows:
|
||||
for string in item:
|
||||
@ -196,5 +196,5 @@ func print_csv(rows : Array):
|
||||
|
||||
table_preview.show()
|
||||
|
||||
func _on_Preview_popup_hide():
|
||||
func _on_Preview_popup_hide() -> void:
|
||||
queue_free()
|
||||
|
@ -31,7 +31,7 @@ var search_flag : int = 0
|
||||
|
||||
signal text_changed()
|
||||
|
||||
func _init():
|
||||
func _init() -> void:
|
||||
size_flags_vertical = SIZE_EXPAND_FILL
|
||||
set_anchors_and_margins_preset(Control.PRESET_WIDE)
|
||||
|
||||
@ -169,7 +169,7 @@ func _init():
|
||||
file_info_read_only.flat = true
|
||||
file_info_read_only.size_flags_horizontal = SIZE_EXPAND | SIZE_SHRINK_END
|
||||
|
||||
func _ready():
|
||||
func _ready() -> void:
|
||||
text_editor.connect("text_changed", self, "_on_text_editor_text_changed")
|
||||
|
||||
#FileList = get_parent().get_parent().get_parent().get_parent().get_node("FileList")
|
||||
@ -195,15 +195,15 @@ func load_default_font() -> void:
|
||||
if default_font != "":
|
||||
set_font(default_font)
|
||||
|
||||
func set_wrap_enabled(enabled:bool):
|
||||
func set_wrap_enabled(enabled:bool) -> void:
|
||||
text_editor.set_wrap_enabled(enabled)
|
||||
text_editor.update()
|
||||
|
||||
func draw_minimap(value:bool):
|
||||
func draw_minimap(value:bool) -> void:
|
||||
text_editor.draw_minimap(value)
|
||||
text_editor.update()
|
||||
|
||||
func color_region(filextension : String): # -----------------------------> dal momento che voglio creare un editor per ogni file, renderò questa funzione singola in base all'estensione del file
|
||||
func color_region(filextension : String) -> void:
|
||||
match(filextension):
|
||||
"bbs":
|
||||
text_editor.add_color_region("[b]","[/b]",Color8(153,153,255,255),false)
|
||||
@ -254,7 +254,7 @@ func color_region(filextension : String): # -----------------------------> dal m
|
||||
_:
|
||||
pass
|
||||
|
||||
func clean_editor():
|
||||
func clean_editor() -> void:
|
||||
text_editor.set_text("")
|
||||
#file_info_last_modified_icon.texture = IconLoader.load_icon_from_name("save")
|
||||
file_info_last_modified.set_text("")
|
||||
@ -262,7 +262,7 @@ func clean_editor():
|
||||
current_filename = ""
|
||||
current_path = ""
|
||||
|
||||
func new_file_open(file_content : String, last_modified : Dictionary, current_file_path : String):
|
||||
func new_file_open(file_content : String, last_modified : Dictionary, current_file_path : String) -> void:
|
||||
current_path = current_file_path
|
||||
current_filename = current_file_path.get_file()
|
||||
color_region(current_filename.get_extension())
|
||||
@ -271,16 +271,16 @@ func new_file_open(file_content : String, last_modified : Dictionary, current_fi
|
||||
file_list.invalidate()
|
||||
count_characters()
|
||||
|
||||
func update_lastmodified(last_modified : Dictionary, icon : String):
|
||||
func update_lastmodified(last_modified : Dictionary, icon : String) -> void:
|
||||
file_info_last_modified.set_text(str(last_modified.hour)+":"+str(last_modified.minute)+" "+str(last_modified.day)+"/"+str(last_modified.month)+"/"+str(last_modified.year))
|
||||
#file_info_last_modified_icon.texture = IconLoader.load_icon_from_name(icon)
|
||||
|
||||
func new_file_create(file_name):
|
||||
func new_file_create(file_name) -> void:
|
||||
text_editor.set_text("")
|
||||
|
||||
file_list.invalidate()
|
||||
|
||||
func _on_Readonly_toggled(button_pressed):
|
||||
func _on_Readonly_toggled(button_pressed) -> void:
|
||||
if button_pressed:
|
||||
file_info_read_only.set_text("Read Only")
|
||||
text_editor.readonly = (true)
|
||||
@ -288,12 +288,12 @@ func _on_Readonly_toggled(button_pressed):
|
||||
file_info_read_only.set_text("Can Edit")
|
||||
text_editor.readonly = (false)
|
||||
|
||||
func _on_text_editor_text_changed():
|
||||
func _on_text_editor_text_changed() -> void:
|
||||
#file_info_last_modified_icon.texture = IconLoader.load_icon_from_name("saveas")
|
||||
count_characters()
|
||||
emit_signal("text_changed")
|
||||
|
||||
func count_characters():
|
||||
func count_characters() -> void:
|
||||
var counted : int = 0
|
||||
|
||||
for line in range(text_editor.get_line_count()):
|
||||
@ -301,7 +301,7 @@ func count_characters():
|
||||
|
||||
file_info_c_counter.set_text(str(counted))
|
||||
|
||||
func _on_LineEdit_text_changed(new_text : String):
|
||||
func _on_LineEdit_text_changed(new_text : String) -> void:
|
||||
var linecount : int = text_editor.get_line_count()
|
||||
if new_text != "":
|
||||
var found : PoolIntArray
|
||||
@ -321,7 +321,7 @@ func _on_LineEdit_text_changed(new_text : String):
|
||||
else:
|
||||
text_editor.select(0,0,0,0)
|
||||
|
||||
func _on_matchcase_toggled(button_pressed : bool):
|
||||
func _on_matchcase_toggled(button_pressed : bool) -> void:
|
||||
if button_pressed:
|
||||
search_flag = 1
|
||||
else:
|
||||
@ -332,7 +332,7 @@ func _on_matchcase_toggled(button_pressed : bool):
|
||||
|
||||
_on_LineEdit_text_changed(search_box_line_edit.get_text())
|
||||
|
||||
func _on_wholewords_toggled(button_pressed : bool):
|
||||
func _on_wholewords_toggled(button_pressed : bool) -> void:
|
||||
if button_pressed:
|
||||
search_flag = 2
|
||||
else:
|
||||
@ -343,32 +343,32 @@ func _on_wholewords_toggled(button_pressed : bool):
|
||||
|
||||
_on_LineEdit_text_changed(search_box_line_edit.get_text())
|
||||
|
||||
func _on_close_pressed():
|
||||
func _on_close_pressed() -> void:
|
||||
search_box.hide()
|
||||
|
||||
func open_search_box():
|
||||
func open_search_box() -> void:
|
||||
if search_box.visible:
|
||||
search_box.hide()
|
||||
else:
|
||||
search_box.show()
|
||||
search_box.get_node("LineEdit").grab_focus()
|
||||
|
||||
func _on_Button_pressed():
|
||||
func _on_Button_pressed() -> void:
|
||||
var linecount : int = text_editor.get_line_count()-1
|
||||
var old_text : String = replace_box_replace_le.get_text()
|
||||
var new_text : String = replace_box_with.get_text()
|
||||
var text : String = text_editor.get_text()
|
||||
text_editor.set_text(text.replace(old_text,new_text))
|
||||
|
||||
func open_replace_box():
|
||||
func open_replace_box() -> void:
|
||||
if replace_box.visible:
|
||||
replace_box.hide()
|
||||
else:
|
||||
replace_box.show()
|
||||
replace_box.get_node("replace").grab_focus()
|
||||
|
||||
func _on_close2_pressed():
|
||||
func _on_close2_pressed() -> void:
|
||||
replace_box.hide()
|
||||
|
||||
func _on_LineEdit_focus_entered():
|
||||
func _on_LineEdit_focus_entered() -> void:
|
||||
_on_LineEdit_text_changed(search_box_line_edit.get_text())
|
||||
|
Loading…
Reference in New Issue
Block a user