Skip to content

Commit

Permalink
Merge pull request #27 from fenix-hub/dev
Browse files Browse the repository at this point in the history
Update for #25
  • Loading branch information
fenix-hub authored Oct 13, 2020
2 parents f21b833 + cb7508b commit 3bd1b7b
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 44 deletions.
2 changes: 1 addition & 1 deletion addons/file-editor/plugin.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
name="File Editor"
description="An internal file editor to view and edit text files in your project folder."
author="Nicolo 'fenix' Santilio"
version="1.7.6"
version="1.7.7"
script="scripts/file-editor.gd"
77 changes: 35 additions & 42 deletions addons/file-editor/scripts/FileEditor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand All @@ -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)

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


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()

var last_modified = OS.get_datetime_from_unix_time(current_file.get_modified_time(path))

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
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()

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()

var last_modified = OS.get_datetime_from_unix_time(current_file.get_modified_time(path))

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

func open_in_inieditor(path : String) -> Control:
var extension = path.get_file().get_extension()
Expand Down
5 changes: 5 additions & 0 deletions addons/file-editor/scripts/LastOpenedFiles.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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")
7 changes: 6 additions & 1 deletion addons/file-editor/scripts/VanillaEditor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand Down

0 comments on commit 3bd1b7b

Please sign in to comment.