From 107d6f8fb1364af4db80f8db7c3c667320c043a3 Mon Sep 17 00:00:00 2001 From: blinry Date: Tue, 10 Nov 2020 15:27:42 +0100 Subject: [PATCH] Show deleted files in the working directory and the index --- scenes/file_browser.gd | 35 +++++++++++++++++++++++------------ scenes/file_browser_item.tscn | 1 - scenes/helpers.gd | 6 ++++++ 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/scenes/file_browser.gd b/scenes/file_browser.gd index 75aa247..4fa21fc 100644 --- a/scenes/file_browser.gd +++ b/scenes/file_browser.gd @@ -34,21 +34,28 @@ func clear(): for item in grid.get_children(): item.queue_free() +func substr2(s): + return s.substr(2) + func update(): if grid: clear() match mode: FileBrowserMode.WORKING_DIRECTORY: if shell: - var file_string = shell.run("find . -type f") - var files = file_string.split("\n") - files = Array(files) + var wd_files = Array(shell.run("find . -type f").split("\n")) # The last entry is an empty string, remove it. - files.pop_back() + wd_files.pop_back() + wd_files = helpers.map(wd_files, self, "substr2") + + var deleted_files = Array(shell.run("git status -s | grep '^.D' | sed -r 's/^...//'").split("\n")) + deleted_files.pop_back() + + var files = wd_files + deleted_files + files.sort_custom(self, "very_best_sort") var is_visible = false for file_path in files: - file_path = file_path.substr(2) if file_path.substr(0, 5) == ".git/": continue is_visible = true @@ -74,9 +81,12 @@ func update(): FileBrowserMode.INDEX: var is_visible = false if repository and repository.there_is_a_git(): - var files = Array(repository.shell.run("git ls-files -s | cut -f2 | uniq").split("\n")) - # The last entry is an empty string, remove it. - files.pop_back() + var index_files = Array(repository.shell.run("git ls-files -s | cut -f2 | uniq").split("\n")) + var deleted_files = Array(repository.shell.run("git status -s | grep '^D' | sed -r 's/^...//'").split("\n")) + # The last entries are empty strings, remove them. + index_files.pop_back() + deleted_files.pop_back() + var files = index_files + deleted_files for file_path in files: var item = preload("res://scenes/file_browser_item.tscn").instance() item.label = file_path @@ -107,6 +117,9 @@ func get_file_status(file_path, shell, idx): return FileBrowserItem.IconStatus.NONE func item_clicked(item): + if item.status == item.IconStatus.REMOVED: + return + match mode: FileBrowserMode.WORKING_DIRECTORY: text_edit.text = helpers.read_file(shell._cwd + item.label) @@ -159,10 +172,8 @@ func _set_title(new_title): title_label.text = new_title func very_best_sort(a,b): - # We're looking at the third character because all entries have the form - # "./.git/bla". - if a.substr(2, 1) == "." and b.substr(2, 1) != ".": + if a[0] == "." and b[0] != ".": return false - if a.substr(2, 1) != "." and b.substr(2, 1) == ".": + if a[0] != "." and b[0] == ".": return true return a.casecmp_to(b) == -1 diff --git a/scenes/file_browser_item.tscn b/scenes/file_browser_item.tscn index 4644d35..09193ac 100644 --- a/scenes/file_browser_item.tscn +++ b/scenes/file_browser_item.tscn @@ -27,7 +27,6 @@ __meta__ = { } [node name="DropArea" parent="Control" instance=ExtResource( 4 )] -show_behind_parent = false position = Vector2( 0, 0 ) [node name="VBoxContainer" type="VBoxContainer" parent="."] diff --git a/scenes/helpers.gd b/scenes/helpers.gd index 8912a35..feff683 100644 --- a/scenes/helpers.gd +++ b/scenes/helpers.gd @@ -11,6 +11,12 @@ func crash(message): # Violent delights have violent ends. get_tree().fatal_error() +func map(array, object, f): + var new_array = [] + for i in range(array.size()): + new_array.push_back(object.call(f, array[i])) + return new_array + # Run a simple command with arguments, blocking, using OS.execute. func exec(command, args=[], crash_on_fail=true): var debug = false