| 1 |
extends WindowDialog |
| 2 |
|
| 3 |
onready var rtl = $TextDisplay/RichTextLabel |
| 4 |
var _has_opened_file = false |
| 5 |
|
| 6 |
func _get_file_as_text(path): |
| 7 |
var to_return = null |
| 8 |
var f = File.new() |
| 9 |
var result = f.open(path, f.READ) |
| 10 |
if(result == OK): |
| 11 |
to_return = f.get_as_text() |
| 12 |
f.close() |
| 13 |
else: |
| 14 |
to_return = str('ERROR: Could not open file. Error code ', result) |
| 15 |
return to_return |
| 16 |
|
| 17 |
func _ready(): |
| 18 |
rtl.clear() |
| 19 |
|
| 20 |
func _on_OpenFile_pressed(): |
| 21 |
$FileDialog.popup_centered() |
| 22 |
|
| 23 |
func _on_FileDialog_file_selected(path): |
| 24 |
show_file(path) |
| 25 |
|
| 26 |
func _on_Close_pressed(): |
| 27 |
self.hide() |
| 28 |
|
| 29 |
func show_file(path): |
| 30 |
var text = _get_file_as_text(path) |
| 31 |
if(text == ''): |
| 32 |
text = '<Empty File>' |
| 33 |
rtl.set_text(text) |
| 34 |
self.window_title = path |
| 35 |
|
| 36 |
func show_open(): |
| 37 |
self.popup_centered() |
| 38 |
$FileDialog.popup_centered() |
| 39 |
|
| 40 |
func _on_FileDialog_popup_hide(): |
| 41 |
if(rtl.text.length() == 0): |
| 42 |
self.hide() |
| 43 |
|
| 44 |
func get_rich_text_label(): |
| 45 |
return $TextDisplay/RichTextLabel |
| 46 |
|
| 47 |
func _on_Home_pressed(): |
| 48 |
rtl.scroll_to_line(0) |
| 49 |
|
| 50 |
func _on_End_pressed(): |
| 51 |
rtl.scroll_to_line(rtl.get_line_count() -1) |
| 52 |
|
| 53 |
|
| 54 |
func _on_Copy_pressed(): |
| 55 |
OS.clipboard = rtl.text |