2022-11-09 21:57:46 +01:00
|
|
|
extends Window
|
2022-06-02 04:13:43 +02:00
|
|
|
|
2022-11-09 21:57:46 +01:00
|
|
|
@onready var rtl = $TextDisplay/RichTextLabel
|
2022-06-02 04:13:43 +02:00
|
|
|
|
|
|
|
func _get_file_as_text(path):
|
|
|
|
var to_return = null
|
2023-01-07 20:26:17 +01:00
|
|
|
var f = FileAccess.open(path, FileAccess.READ)
|
|
|
|
if(f != null):
|
2022-06-02 04:13:43 +02:00
|
|
|
to_return = f.get_as_text()
|
|
|
|
else:
|
2023-01-07 20:26:17 +01:00
|
|
|
to_return = str('ERROR: Could not open file. Error code ', FileAccess.get_open_error())
|
2022-06-02 04:13:43 +02:00
|
|
|
return to_return
|
|
|
|
|
|
|
|
func _ready():
|
|
|
|
rtl.clear()
|
|
|
|
|
|
|
|
func _on_OpenFile_pressed():
|
|
|
|
$FileDialog.popup_centered()
|
|
|
|
|
|
|
|
func _on_FileDialog_file_selected(path):
|
|
|
|
show_file(path)
|
|
|
|
|
|
|
|
func _on_Close_pressed():
|
|
|
|
self.hide()
|
|
|
|
|
|
|
|
func show_file(path):
|
|
|
|
var text = _get_file_as_text(path)
|
2023-01-07 20:26:17 +01:00
|
|
|
if(text == ''):
|
|
|
|
text = '<Empty File>'
|
2022-06-02 04:13:43 +02:00
|
|
|
rtl.set_text(text)
|
|
|
|
self.window_title = path
|
|
|
|
|
|
|
|
func show_open():
|
|
|
|
self.popup_centered()
|
|
|
|
$FileDialog.popup_centered()
|
|
|
|
|
|
|
|
func get_rich_text_label():
|
|
|
|
return $TextDisplay/RichTextLabel
|
|
|
|
|
|
|
|
func _on_Home_pressed():
|
|
|
|
rtl.scroll_to_line(0)
|
|
|
|
|
|
|
|
func _on_End_pressed():
|
2023-01-07 20:26:17 +01:00
|
|
|
rtl.scroll_to_line(rtl.get_line_count() -1)
|
2022-06-02 04:13:43 +02:00
|
|
|
|
|
|
|
func _on_Copy_pressed():
|
|
|
|
OS.clipboard = rtl.text
|
2023-01-07 20:26:17 +01:00
|
|
|
|
|
|
|
func _on_file_dialog_visibility_changed():
|
|
|
|
if rtl.text.length() == 0 and not $FileDialog.visible:
|
|
|
|
self.hide()
|