Update file for #25

This commit is contained in:
Nicolò Santilio 2020-10-13 17:17:22 +02:00 committed by GitHub
parent 6076b056de
commit c1242cb160
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 43 deletions

View File

@ -66,9 +66,7 @@ var current_ini_editor : Control
var current_csv_editor : Control
var current_font : DynamicFont
func _ready():
clean_editor()
update_version()
connect_signals()
@ -361,7 +359,7 @@ func open_file(path : String, font : String = "null"):
current_file_path = path
var vanilla_editor = open_in_vanillaeditor(path)
if font != "null":
if font != "null" and vanilla_editor.get("custom_fonts/font")!=null:
vanilla_editor.set_font(font)
var ini_editor = open_in_inieditor(path)
var csv_editor = open_in_csveditor(path)
@ -372,47 +370,42 @@ func open_file(path : String, font : String = "null"):
current_editor.show()
func generate_file_item(path : String , veditor : Control , inieditor : Control, csveditor : Control):
OpenFileName.set_text(path)
OpenFileList.add_item(path.get_file(),IconLoader.load_icon_from_name("file"),true)
current_file_index = OpenFileList.get_item_count()-1
OpenFileList.set_item_metadata(current_file_index,[veditor,inieditor,csveditor])
OpenFileList.select(OpenFileList.get_item_count()-1)
OpenFileName.set_text(path)
OpenFileList.add_item(path.get_file(),IconLoader.load_icon_from_name("file"),true)
current_file_index = OpenFileList.get_item_count()-1
OpenFileList.set_item_metadata(current_file_index,[veditor,inieditor,csveditor])
OpenFileList.select(OpenFileList.get_item_count()-1)
func open_in_vanillaeditor(path : String) -> Control:
var editor = VanillaEditor.instance()
SplitEditorContainer.add_child(editor,true)
var editor = VanillaEditor.instance()
SplitEditorContainer.add_child(editor,true)
if current_editor and current_editor!=editor:
editor.show()
current_editor.hide()
if current_csv_editor and current_csv_editor.visible:
current_csv_editor.hide()
if current_ini_editor and current_ini_editor.visible:
current_ini_editor.hide()
if current_editor and current_editor!=editor:
editor.show()
current_editor.hide()
if current_csv_editor and current_csv_editor.visible:
current_csv_editor.hide()
if current_ini_editor and current_ini_editor.visible:
current_ini_editor.hide()
current_editor = editor
current_editor = editor
editor.connect("text_changed",self,"_on_vanillaeditor_text_changed")
var current_file : File = File.new()
current_file.open(path,File.READ)
var current_content = ""
current_content = current_file.get_as_text()
editor.connect("text_changed",self,"_on_vanillaeditor_text_changed")
var last_modified = OS.get_datetime_from_unix_time(current_file.get_modified_time(path))
var current_file : File = File.new()
current_file.open(path,File.READ)
var current_content = ""
current_content = current_file.get_as_text()
current_file.close()
editor.new_file_open(current_content,last_modified,current_file_path)
update_list()
var last_modified = OS.get_datetime_from_unix_time(current_file.get_modified_time(path))
if WrapBTN.get_selected_id() == 1:
current_editor.set_wrap_enabled(true)
current_file.close()
editor.new_file_open(current_content,last_modified,current_file_path)
update_list()
if WrapBTN.get_selected_id() == 1:
current_editor.set_wrap_enabled(true)
return editor
return editor
func open_in_inieditor(path : String) -> Control:
var extension = path.get_file().get_extension()

View File

@ -3,6 +3,8 @@ extends Node
const lastopenedfile_path : String = "res://addons/file-editor/lastopenedfiles.lastcfg"
var editor_plugin : EditorPlugin = EditorPlugin.new()
func _ready():
pass
@ -40,3 +42,6 @@ func store_editor_fonts(file_name : String, font_path : String):
file.load(lastopenedfile_path)
file.set_value("Fonts",file_name,font_path)
file.save(lastopenedfile_path)
func get_editor_font():
return editor_plugin.get_editor_interface().get_editor_settings().get_setting("interface/editor/code_font")

View File

@ -25,7 +25,6 @@ var current_path = ""
var current_filename = ""
var Preview = load("res://addons/file-editor/scenes/Preview.tscn")
var search_flag = 0
signal text_changed()
@ -39,6 +38,7 @@ func _ready():
ReadOnly.set("custom_icons/unchecked",IconLoader.load_icon_from_name("edit"))
add_to_group("vanilla_editor")
load_default_font()
func set_font(font_path : String) -> void:
var dynamic_font : DynamicFont = DynamicFont.new()
@ -47,6 +47,11 @@ func set_font(font_path : String) -> void:
dynamic_font.set_font_data(dynamic_font_data)
TextEditor.set("custom_fonts/font",dynamic_font)
func load_default_font() -> void:
var default_font = LastOpenedFiles.get_editor_font()
if default_font:
set_font(default_font)
func set_wrap_enabled(enabled:bool):
TextEditor.set_wrap_enabled(enabled)
TextEditor.update()