From b2cd4a035e4d82a106cc4424c5c3f1b7d7156a9e Mon Sep 17 00:00:00 2001 From: teebarjunk Date: Wed, 13 Oct 2021 13:00:48 -0400 Subject: [PATCH] 1.1 --- CHANGES.md | 7 +- addons/test.txt | 1 + addons/text_editor/TE_FileEditor.gd | 2 +- addons/text_editor/TE_TagsPanel.gd | 17 ++++- addons/text_editor/TE_TextEditor.gd | 81 ++++++++++++-------- addons/text_editor/TE_Util.gd | 114 ++++++++++++++++------------ addons/text_editor/TextEditor.tscn | 28 ------- addons/text_editor/ext/ext_md.gd | 2 +- 8 files changed, 140 insertions(+), 112 deletions(-) create mode 100644 addons/test.txt diff --git a/CHANGES.md b/CHANGES.md index 010b545..74343fe 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,6 @@ # 1.1 -- `fix` Loading settings caused printed an error. -- Get rid of test file. +- Fixed files and directories not being sorted. +- Added `addons` folder hider option. +- Fixed "failed to load settings" error. +- Tweaked syntax coloring. +- Got rid of accidental test file. diff --git a/addons/test.txt b/addons/test.txt new file mode 100644 index 0000000..8d1c8b6 --- /dev/null +++ b/addons/test.txt @@ -0,0 +1 @@ + diff --git a/addons/text_editor/TE_FileEditor.gd b/addons/text_editor/TE_FileEditor.gd index 852268d..62f461c 100644 --- a/addons/text_editor/TE_FileEditor.gd +++ b/addons/text_editor/TE_FileEditor.gd @@ -217,7 +217,7 @@ func update_symbols(): else: tags[tag] += 1 - var _e = TE_Util.sort(tags, true) +# var _e = TE_Util.sort(tags, true) editor._file_symbols_updated(file_path) func close(): diff --git a/addons/text_editor/TE_TagsPanel.gd b/addons/text_editor/TE_TagsPanel.gd index 69707e7..cb707a9 100644 --- a/addons/text_editor/TE_TagsPanel.gd +++ b/addons/text_editor/TE_TagsPanel.gd @@ -36,12 +36,27 @@ func _clicked(id): var tag = tag_indices[int(id)] editor.enable_tag(tag, not editor.is_tag_enabled(tag)) +func sort_tags(tags:Dictionary): + var sorter:Array = [] + for tag in tags: + sorter.append([tag, tags[tag]]) + + sorter.sort_custom(self, "_sort_tags") + + tags.clear() + for item in sorter: + tags[item[0]] = item[1] + return tags + +func _sort_tags(a, b): + return a[0] < b[0] + func _redraw(): var tab = editor.get_selected_tab() var tags = editor.tag_counts var tab_tags = {} if not tab else tab.tags - TE_Util.sort_value(tags) + sort_tags(tags) if not tags: set_bbcode("[color=#%s][i][center]*No tags*" % [Color.webgray.to_html()]) diff --git a/addons/text_editor/TE_TextEditor.gd b/addons/text_editor/TE_TextEditor.gd index 8a32a28..3ce98a7 100644 --- a/addons/text_editor/TE_TextEditor.gd +++ b/addons/text_editor/TE_TextEditor.gd @@ -50,6 +50,7 @@ var show:Dictionary = { hidden=true, gdignore=true, + addons=false, git=false, import=false, trash=false @@ -132,16 +133,17 @@ func _ready(): popup_view_dir.clear() popup_view_dir.set_name("Directories") popup_view_dir.add_font_override("font", FONT_R) - popup_view_dir.add_check_item("Hidden", 0) - popup_view_dir.add_check_item("Empty", 1) - popup_view_dir.add_check_item(".gdignore", 2) + popup_view_dir.add_check_item("Hidden", hash("Hidden")) + popup_view_dir.add_check_item("Empty", hash("Empty")) + popup_view_dir.add_check_item(".gdignore", hash(".gdignore")) popup_view_dir.set_item_checked(0, show.dir.hidden) - popup_view_dir.set_item_checked(1, show.dir.gdignore) - popup_view_dir.set_item_checked(2, show.dir.empty) + popup_view_dir.set_item_checked(1, show.dir.empty) + popup_view_dir.set_item_checked(2, show.dir.gdignore) popup_view_dir.add_separator() - popup_view_dir.add_check_item(".import/", 4) - popup_view_dir.add_check_item(".git/", 5) - popup_view_dir.add_check_item(".trash/", 6) + popup_view_dir.add_check_item("addons/", hash("addons/")) + popup_view_dir.add_check_item(".import/", hash(".import/")) + popup_view_dir.add_check_item(".git/", hash(".git/")) + popup_view_dir.add_check_item(".trash/", hash(".trash/")) popup_view.add_child(popup_view_dir) popup_view.add_submenu_item("Directories", "Directories") @@ -200,7 +202,13 @@ func load_state(): tab_parent.current_tab = selected.get_index() current_directory = state.current - show = state.show + + for k in state.show.dir: + show.dir[k] = state.show.dir[k] + + for k in state.show.file: + show.file[k] = state.show.file[k] + tag_counts = state.tag_counts tags_enabled = state.tags_enabled exts_enabled = state.exts_enabled @@ -232,7 +240,6 @@ func save_state(): TE_Util.save_json(PATH_STATE, state) emit_signal("state_saved") - func _exit_tree(): save_state() @@ -271,33 +278,35 @@ func _apply_fonts(n:Node): n.add_font_override("font", FONT_R) func _menu_file(id): -# var index = popup_file.get_item_index(id) -# var data = popup_file.items[index] -# prints(id, index, data) match id: 100: popup_create_file() # "New File" 200: popup_create_dir() # "New Folder" 300: open_last_file() # "Open last closed" func _menu_view_dir(index:int): - match index: - 0: + var text = popup_view_dir.get_item_text(index) + print(text) + match text: + "Hidden": show.dir.hidden = not show.dir.hidden popup_view_dir.set_item_checked(index, show.dir.hidden) - 1: + "Empty": show.dir.empty = not show.dir.empty popup_view_dir.set_item_checked(index, show.dir.empty) - 2: + ".gdignore": show.dir.gdignore = not show.dir.gdignore popup_view_dir.set_item_checked(index, show.dir.gdignore) - 4: + "addons/": + show.dir.addons = not show.dir.addons + popup_view_dir.set_item_checked(index, show.dir.addons) + ".import/": show.dir.import = not show.dir.import popup_view_dir.set_item_checked(index, show.dir.import) - 5: + ".git/": show.dir.git = not show.dir.git popup_view_dir.set_item_checked(index, show.dir.git) - 6: + ".trash/": show.dir.trash = not show.dir.trash popup_view_dir.set_item_checked(index, show.dir.trash) @@ -444,13 +453,6 @@ func _debug_pressed(): func save_files(): emit_signal("save_files") -func sort_files(): - TE_Util.dig(file_list, self, "_sort") - emit_signal("updated_file_list") - -func _sort(dir:Dictionary): - return TE_Util.sort_on_ext(dir) - func get_selected_file() -> String: var node = get_selected_tab() return node.file_path if node else "" @@ -560,7 +562,6 @@ func recycle_file(file_path:String): # remove by renaming rename_file(file_path, new_path) - print("Send to " + new_path) if tab: tab_parent.remove_child(tab) @@ -636,10 +637,9 @@ func refresh_files(): var dir = Directory.new() if dir.open(current_directory) == OK: _scan_dir("", current_directory, dir, file_list) + emit_signal("updated_file_list") else: push_error("error trying to load %s." % current_directory) - - sort_files() func show_dir(fname:String, base_dir:String) -> bool: if not show.dir.gdignore and File.new().file_exists(base_dir.plus_file(".gdignore")): @@ -650,6 +650,8 @@ func show_dir(fname:String, base_dir:String) -> bool: if not show.dir.import and fname == ".import": return false if not show.dir.git and fname == ".git": return false if not show.dir.trash and fname == ".trash": return false + else: + if not show.dir.addons and fname == "addons": return false return true @@ -698,6 +700,25 @@ func _scan_dir(id:String, path:String, dir:Directory, last_dir:Dictionary): a_dirs.append(p) else: a_files.append(a_dirs_and_files[p]) + + sort_on_ext(a_dirs) + sort_on_ext(a_files) + +func sort_on_ext(items:Array): + var sorted = [] + for a in items: + var k = a.get_file() + if "." in k: + k = k.split(".", true, 1) + k = k[1] + k[0] + sorted.append([k, a]) + sorted.sort_custom(self, "_sort_on_ext") + for i in len(items): + items[i] = sorted[i][1] + return items + +func _sort_on_ext(a, b): + return a[0] < b[0] static func get_extension(file_path:String) -> String: var file = file_path.get_file() diff --git a/addons/text_editor/TE_Util.gd b/addons/text_editor/TE_Util.gd index 51fd4a5..e7a296b 100644 --- a/addons/text_editor/TE_Util.gd +++ b/addons/text_editor/TE_Util.gd @@ -83,14 +83,14 @@ static func file_size(path:String) -> String: return String.humanize_size(bytes) return "-1" -static func sort(d:Dictionary, reverse:bool=false) -> Dictionary: - return Dict.new(d).sort(reverse) - -static func sort_value(d:Dictionary, reverse:bool=false) -> Dictionary: - return Dict.new(d).sort_value(reverse) - -static func sort_on_ext(d:Dictionary, reverse:bool=false) -> Dictionary: - return Dict.new(d).sort_ext(reverse) +#static func sort(d, reverse:bool=false): +# return Dict.new(d).sort(reverse) +# +#static func sort_value(d:Dictionary, reverse:bool=false) -> Dictionary: +# return Dict.new(d).sort_value(reverse) +# +#static func sort_on_ext(d:Dictionary, reverse:bool=false) -> Dictionary: +# return Dict.new(d).sort_ext(reverse) static func split_many(s:String, spliton:String, allow_empty:bool=true) -> PoolStringArray: var parts := PoolStringArray() @@ -116,44 +116,60 @@ static func commas(number) -> String: out += number[i] return out -class Dict: - var d:Dictionary - var a:Array = [] - var i:int = 0 - - func _init(dict:Dictionary): - d = dict - - func _pop(): - for k in d: a.append([k, d[k]]) - - func _unpop() -> Dictionary: - d.clear() - for i in a: d[i[0]] = i[1] - return d - - func sort(reverse:bool=false) -> Dictionary: - _pop() - a.sort_custom(self, "_sort_reverse" if reverse else "_sort") - return _unpop() - - func sort_value(reverse:bool=false) -> Dictionary: - _pop() - i = 1 - a.sort_custom(self, "_sort_reverse" if reverse else "_sort") - return _unpop() - - func sort_ext(reverse:bool=false) -> Dictionary: - for k in d: - if "." in k: - var p = k.split(".", true, 1) - p = p[1] + p[0] - a.append([k, d[k], p + "." + k]) - else: - a.append([k, d[k], "." + k]) - i = 2 - a.sort_custom(self, "_sort_reverse" if reverse else "_sort") - return _unpop() - - func _sort(a, b): return a[i] > b[i] - func _sort_reverse(a, b): return a[i] < b[i] +#class Dict: +# var sort_array:bool = false +# var d:Dictionary +# var a:Array +# var sorter:Array = [] +# var i:int = 0 +# +# func _init(item): +# if item is Array: +# sort_array = true +# a = item +# else: +# d = item +# +# func _pop(): +# if sort_array: +# for i in a: sorter.append(a) +# else: +# for k in d: sorter.append([k, d[k]]) +# +# func _unpop(): +# if sort_array: +# for i in len(sorter): a[i] = sorter[i] +# return a +# else: +# d.clear() +# for i in a: d[i[0]] = i[1] +# return d +# +# func sort(reverse:bool=false): +# _pop() +# a.sort_custom(self, "_sort_reverse" if reverse else "_sort") +# return _unpop() +# +# func sort_value(reverse:bool=false): +# _pop() +# i = 1 +# a.sort_custom(self, "_sort_reverse" if reverse else "_sort") +# return _unpop() +# +# func sort_ext(reverse:bool=false): +# if sort_array: +# for x in a: +# if "." in a: +# for k in d: +# if "." in k: +# var p = k.split(".", true, 1) +# p = p[1] + p[0] +# a.append([k, d[k], p + "." + k]) +# else: +# a.append([k, d[k], "." + k]) +# i = 2 +# a.sort_custom(self, "_sort_reverse" if reverse else "_sort") +# return _unpop() +# +# func _sort(a, b): return a[i] > b[i] +# func _sort_reverse(a, b): return a[i] < b[i] diff --git a/addons/text_editor/TextEditor.tscn b/addons/text_editor/TextEditor.tscn index 874df94..9295960 100644 --- a/addons/text_editor/TextEditor.tscn +++ b/addons/text_editor/TextEditor.tscn @@ -130,35 +130,7 @@ custom_fonts/italics_font = ExtResource( 10 ) custom_fonts/bold_font = ExtResource( 11 ) custom_fonts/normal_font = ExtResource( 12 ) bbcode_enabled = true -bbcode_text = "[url=add_file:0][color=#ff00ff00]+[/color][/url] -[color=#ff4d4d4d][url=d:0][color=#ff333333][/color]🗀▼[b]test_files[/b][/url][/color] -[url=f:0][color=#ff333333][/color][color=#ff333333]┣╸[/color][i][color=#ff404040]questish[/color][/i].[color=#ff666666]yaml[/color][/url] -[url=f:1][color=#ff333333][/color][color=#ff333333]┣╸[/color][i][color=#ff404040]garoyle[/color][/i].[color=#ff666666]md[/color][/url] -[url=f:2][color=#ff333333][/color][color=#ff333333]┣╸[/color][i][color=#ff404040]json[/color][/i].[color=#ff666666]json[/color][/url] -[url=f:3][color=#ff333333][/color][color=#ff333333]┣╸[/color][i][color=#ff404040]config[/color][/i].[color=#ff666666]ini[/color][/url] -[url=f:4][color=#ff333333][/color][color=#ff333333]┣╸[/color][i][color=#ff404040]acc[/color][/i].[color=#ff666666]csv[/color][/url] -[color=#ff4d4d4d][url=d:1][color=#ff333333]┃ [/color]🗀▼[b]afolder[/b][/url][/color] -[url=f:5][color=#ff333333]┃ [/color][color=#ff333333]┣╸[/color][i][color=#ff404040]new_file[/color][/i].[color=#ff666666]yaml[/color][/url] -[url=f:6][color=#ff333333]┃ [/color][color=#ff333333]┣╸[/color][i][color=#ff404040]ass2[/color][/i].[color=#ff666666]yaml[/color][/url] -[url=f:7][color=#ff333333]┃ [/color][color=#ff333333]┣╸[/color][i][color=#ff404040]todo[/color][/i].[color=#ff666666]md[/color][/url] -[url=f:8][color=#ff333333]┃ [/color][color=#ff333333]┣╸[/color][i][color=#ff404040]my_fileok[/color][/i].[color=#ff666666]md[/color][/url] -[color=#ff4d4d4d][url=d:2][color=#ff333333]┃ ┃ [/color]🗀▼[b]New Folder[/b][/url][/color] -[url=f:9][color=#ff333333]┃ ┃ [/color][color=#ff333333]┗╸[/color][i][color=#ff404040]mor[/color][/i].[color=#ff666666]md[/color][/url]" meta_underlined = false -text = "+ -🗀▼test_files -┣╸questish.yaml -┣╸garoyle.md -┣╸json.json -┣╸config.ini -┣╸acc.csv -┃ 🗀▼afolder -┃ ┣╸new_file.yaml -┃ ┣╸ass2.yaml -┃ ┣╸todo.md -┃ ┣╸my_fileok.md -┃ ┃ 🗀▼New Folder -┃ ┃ ┗╸mor.md" script = ExtResource( 3 ) __meta__ = { "_edit_use_anchors_": false diff --git a/addons/text_editor/ext/ext_md.gd b/addons/text_editor/ext/ext_md.gd index 223bb66..31fd0b9 100644 --- a/addons/text_editor/ext/ext_md.gd +++ b/addons/text_editor/ext/ext_md.gd @@ -7,7 +7,7 @@ func toggle_comment(t:TextEdit, head:String=""): func apply_colors(e:TextEditor, t:TextEdit): .apply_colors(e, t) - var code:Color = e.color_text.darkened(.5) + var code:Color = lerp(e.color_text.darkened(.5), Color.yellowgreen, .5) t.add_keyword_color("true", e.color_var) t.add_keyword_color("false", e.color_var)