mirror of
https://github.com/Relintai/Godot-TextEditor.git
synced 2025-01-26 16:59:19 +01:00
ext filter
This commit is contained in:
parent
af2b69645f
commit
3e482dd5e0
@ -3,7 +3,7 @@
|
|||||||
[ext_resource path="res://addons/text_editor/file_buttons.gd" type="Script" id=1]
|
[ext_resource path="res://addons/text_editor/file_buttons.gd" type="Script" id=1]
|
||||||
[ext_resource path="res://addons/text_editor/TextEditor.gd" type="Script" id=2]
|
[ext_resource path="res://addons/text_editor/TextEditor.gd" type="Script" id=2]
|
||||||
[ext_resource path="res://addons/text_editor/list_files.gd" type="Script" id=3]
|
[ext_resource path="res://addons/text_editor/list_files.gd" type="Script" id=3]
|
||||||
[ext_resource path="res://addons/text_editor/text_edit.gd" type="Script" id=4]
|
[ext_resource path="res://addons/text_editor/FileEditorTab.gd" type="Script" id=4]
|
||||||
[ext_resource path="res://addons/text_editor/list_symbols.gd" type="Script" id=5]
|
[ext_resource path="res://addons/text_editor/list_symbols.gd" type="Script" id=5]
|
||||||
[ext_resource path="res://addons/text_editor/tab_scroll.gd" type="Script" id=6]
|
[ext_resource path="res://addons/text_editor/tab_scroll.gd" type="Script" id=6]
|
||||||
[ext_resource path="res://addons/text_editor/list_tags.gd" type="Script" id=7]
|
[ext_resource path="res://addons/text_editor/list_tags.gd" type="Script" id=7]
|
||||||
|
@ -72,7 +72,6 @@ func _input(e):
|
|||||||
select(f+1, 0, t+1, len(get_line(t+1)))
|
select(f+1, 0, t+1, len(get_line(t+1)))
|
||||||
cursor_set_line(cursor_get_line()+1, false)
|
cursor_set_line(cursor_get_line()+1, false)
|
||||||
|
|
||||||
|
|
||||||
func _unhandled_key_input(e):
|
func _unhandled_key_input(e):
|
||||||
if not visible:
|
if not visible:
|
||||||
return
|
return
|
||||||
@ -82,7 +81,6 @@ func _unhandled_key_input(e):
|
|||||||
helper.toggle_comment(self)
|
helper.toggle_comment(self)
|
||||||
get_tree().set_input_as_handled()
|
get_tree().set_input_as_handled()
|
||||||
|
|
||||||
|
|
||||||
func _file_selected(p:String):
|
func _file_selected(p:String):
|
||||||
if p and p == file_path:
|
if p and p == file_path:
|
||||||
grab_focus()
|
grab_focus()
|
@ -8,8 +8,8 @@ const FONT_B:DynamicFont = preload("res://addons/text_editor/fonts/font_b.tres")
|
|||||||
const FONT_I:DynamicFont = preload("res://addons/text_editor/fonts/font_i.tres")
|
const FONT_I:DynamicFont = preload("res://addons/text_editor/fonts/font_i.tres")
|
||||||
const FONT_BI:DynamicFont = preload("res://addons/text_editor/fonts/font_bi.tres")
|
const FONT_BI:DynamicFont = preload("res://addons/text_editor/fonts/font_bi.tres")
|
||||||
|
|
||||||
const SHOW_EXT:PoolStringArray = PoolStringArray([
|
const EXTENSIONS:PoolStringArray = PoolStringArray([
|
||||||
".txt", ".md", ".json", ".csv", ".ini", ".cfg", ".yaml"
|
"txt", "md", "json", "csv", "cfg", "ini", "yaml"
|
||||||
])
|
])
|
||||||
const FILE_FILTERS:PoolStringArray = PoolStringArray([
|
const FILE_FILTERS:PoolStringArray = PoolStringArray([
|
||||||
"*.txt ; Text",
|
"*.txt ; Text",
|
||||||
@ -34,8 +34,9 @@ onready var tab_prefab:Node = $c/c3/c/c/tab_container/tab_prefab
|
|||||||
onready var popup:ConfirmationDialog = $popup
|
onready var popup:ConfirmationDialog = $popup
|
||||||
onready var popup_unsaved:ConfirmationDialog = $popup_unsaved
|
onready var popup_unsaved:ConfirmationDialog = $popup_unsaved
|
||||||
onready var file_dialog:FileDialog = $file_dialog
|
onready var file_dialog:FileDialog = $file_dialog
|
||||||
onready var menu_file:MenuButton = $c/c/c/file_button
|
|
||||||
onready var line_edit:LineEdit = $c/c3/c/c/line_edit
|
onready var line_edit:LineEdit = $c/c3/c/c/line_edit
|
||||||
|
onready var menu_file:MenuButton = $c/c/c/file_button
|
||||||
|
var ext_menu:PopupMenu = PopupMenu.new()
|
||||||
|
|
||||||
signal updated_file_list()
|
signal updated_file_list()
|
||||||
signal file_opened(file_path)
|
signal file_opened(file_path)
|
||||||
@ -51,16 +52,20 @@ signal save_files()
|
|||||||
var current_directory:String = ""
|
var current_directory:String = ""
|
||||||
var dirs:Array = []
|
var dirs:Array = []
|
||||||
var file_list:Dictionary = {}
|
var file_list:Dictionary = {}
|
||||||
var extensions:Dictionary = {}
|
var ext_counts:Dictionary = {}
|
||||||
var symbols:Dictionary = {}
|
var symbols:Dictionary = {}
|
||||||
var tags:Array = []
|
var tags:Array = []
|
||||||
var tags_enabled:Dictionary = {}
|
var tags_enabled:Dictionary = {}
|
||||||
var tag_counts:Dictionary = {}
|
var tag_counts:Dictionary = {}
|
||||||
|
var exts_enabled:Array = []
|
||||||
|
|
||||||
var opened:Array = []
|
var opened:Array = []
|
||||||
var closed:Array = []
|
var closed:Array = []
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
|
# not needed when editor plugin
|
||||||
|
# get_tree().set_auto_accept_quit(false)
|
||||||
|
|
||||||
var _e
|
var _e
|
||||||
_e = test_button.connect("pressed", self, "_debug_pressed")
|
_e = test_button.connect("pressed", self, "_debug_pressed")
|
||||||
|
|
||||||
@ -78,6 +83,18 @@ func _ready():
|
|||||||
p.add_item("New File")
|
p.add_item("New File")
|
||||||
_e = p.connect("index_pressed", self, "_menu_file")
|
_e = p.connect("index_pressed", self, "_menu_file")
|
||||||
|
|
||||||
|
# extensions
|
||||||
|
ext_menu.set_name("Extensions")
|
||||||
|
ext_menu.add_font_override("font", FONT_R)
|
||||||
|
for i in len(EXTENSIONS):
|
||||||
|
var ext = EXTENSIONS[i]
|
||||||
|
ext_menu.add_check_item(ext, i)
|
||||||
|
ext_menu.set_item_checked(i, true)
|
||||||
|
exts_enabled.append(ext)
|
||||||
|
p.add_child(ext_menu)
|
||||||
|
p.add_submenu_item("Extensions", "Extensions")
|
||||||
|
_e = ext_menu.connect("index_pressed", self, "_menu_extension")
|
||||||
|
|
||||||
# file dialog
|
# file dialog
|
||||||
_e = file_dialog.connect("file_selected", self, "_file_dialog_file")
|
_e = file_dialog.connect("file_selected", self, "_file_dialog_file")
|
||||||
file_dialog.add_font_override("title_font", FONT_R)
|
file_dialog.add_font_override("title_font", FONT_R)
|
||||||
@ -92,6 +109,16 @@ func _ready():
|
|||||||
|
|
||||||
set_directory()
|
set_directory()
|
||||||
|
|
||||||
|
# not needed when an editor plugin
|
||||||
|
#func _notification(what):
|
||||||
|
# match what:
|
||||||
|
# MainLoop.NOTIFICATION_WM_QUIT_REQUEST:
|
||||||
|
# for tab in get_all_tabs():
|
||||||
|
# if tab.modified:
|
||||||
|
# popup.show()
|
||||||
|
# return
|
||||||
|
# get_tree().quit()
|
||||||
|
|
||||||
func _input(e):
|
func _input(e):
|
||||||
if e is InputEventMouseButton and e.control:
|
if e is InputEventMouseButton and e.control:
|
||||||
if e.button_index == BUTTON_WHEEL_DOWN:
|
if e.button_index == BUTTON_WHEEL_DOWN:
|
||||||
@ -111,6 +138,16 @@ func _menu_file(a):
|
|||||||
match menu_file.get_popup().items[a]:
|
match menu_file.get_popup().items[a]:
|
||||||
"New File": popup_create_file()
|
"New File": popup_create_file()
|
||||||
|
|
||||||
|
func _menu_extension(index:int):
|
||||||
|
var ext = EXTENSIONS[index]
|
||||||
|
var toggled = ext in exts_enabled
|
||||||
|
if toggled:
|
||||||
|
exts_enabled.erase(ext)
|
||||||
|
elif not ext in exts_enabled:
|
||||||
|
exts_enabled.append(ext)
|
||||||
|
ext_menu.set_item_checked(index, not toggled)
|
||||||
|
refresh_files()
|
||||||
|
|
||||||
func _file_dialog_file(file_path:String):
|
func _file_dialog_file(file_path:String):
|
||||||
match file_dialog.get_meta("mode"):
|
match file_dialog.get_meta("mode"):
|
||||||
"create": create_file(file_path)
|
"create": create_file(file_path)
|
||||||
@ -385,7 +422,7 @@ func get_all_tabs() -> Array:
|
|||||||
return tab_parent.get_children()
|
return tab_parent.get_children()
|
||||||
|
|
||||||
func refresh_files():
|
func refresh_files():
|
||||||
extensions.clear()
|
ext_counts.clear()
|
||||||
dirs.clear()
|
dirs.clear()
|
||||||
file_list.clear()
|
file_list.clear()
|
||||||
var dir = Directory.new()
|
var dir = Directory.new()
|
||||||
@ -405,6 +442,7 @@ func _scan_dir(id:String, path:String, dir:Directory, list:Dictionary):
|
|||||||
var fname = dir.get_next()
|
var fname = dir.get_next()
|
||||||
|
|
||||||
while fname:
|
while fname:
|
||||||
|
if not fname.begins_with("."):
|
||||||
var file_path = dir.get_current_dir().plus_file(fname)
|
var file_path = dir.get_current_dir().plus_file(fname)
|
||||||
|
|
||||||
if dir.current_is_dir():
|
if dir.current_is_dir():
|
||||||
@ -417,13 +455,14 @@ func _scan_dir(id:String, path:String, dir:Directory, list:Dictionary):
|
|||||||
else:
|
else:
|
||||||
# ignore .import files
|
# ignore .import files
|
||||||
if not file_path.ends_with(".import"):
|
if not file_path.ends_with(".import"):
|
||||||
|
var ext = get_extension(file_path)
|
||||||
|
if ext in exts_enabled:
|
||||||
files[fname] = file_path
|
files[fname] = file_path
|
||||||
|
|
||||||
var ext = get_extension(file_path)
|
if not ext in ext_counts:
|
||||||
if not ext in extensions:
|
ext_counts[ext] = 1
|
||||||
extensions[ext] = 1
|
|
||||||
else:
|
else:
|
||||||
extensions[ext] += 1
|
ext_counts[ext] += 1
|
||||||
|
|
||||||
fname = dir.get_next()
|
fname = dir.get_next()
|
||||||
dir.list_dir_end()
|
dir.list_dir_end()
|
||||||
|
Loading…
Reference in New Issue
Block a user