Skip to content

Commit 5f1b64c

Browse files
authored
Merge pull request #60 from TheSecEng/delete-confirm-update
Delete confirm "dialog" improvment. We can now cancel the deletion of each file individually, and it looks a lot neater. fix #39
2 parents 2a8a4bf + 6a81c8c commit 5f1b64c

2 files changed

Lines changed: 31 additions & 10 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@ site/
22
test.py
33
__pycache__/
44
Thumbs.db
5+
.DS_STORE
6+
*sublime-project
7+
*sublime-workspace

commands/delete.py

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@ def delete(self, index):
1616
except OSError as e:
1717
sublime.error_message("Unable to send to trash: {}".format(e))
1818
raise OSError("Unable to send {0!r} to trash: {1}".format(path, e))
19+
if index > 1:
20+
view = self.window.find_open_file(self.paths[index - 2])
21+
if view is not None:
22+
close_view(view)
23+
24+
# We substract two, because 0, 1 are populated by Confirm, Cancel
25+
self.paths.remove(self.paths[index - 2])
26+
27+
if self.paths:
28+
refresh_sidebar(self.settings, self.window)
29+
self.run(self.paths)
30+
1931
refresh_sidebar(self.settings, self.window)
2032

2133
def run(self, paths=None, *args, **kwargs):
@@ -25,17 +37,23 @@ def run(self, paths=None, *args, **kwargs):
2537

2638
self.paths = paths or [self.view.file_name()]
2739
if get_settings().get("ask_for_confirmation_on_delete") is not False:
40+
nitems = "{0} ".format(len(self.paths)) if len(self.paths) > 1 else ""
41+
extras = "s" if len(self.paths) > 1 else ""
42+
43+
confirm_title = "Confirm"
44+
confirm_subtitle = "Send {}item{} to trash".format(nitems, extras)
45+
cancel_title = "Cancel All (Select an individual item to remove it from the deletion list)"
46+
cancel_subtitle = "Cancel deletion of {}item{}".format(nitems, extras)
47+
48+
paths_to_display = [
49+
[confirm_title, confirm_subtitle],
50+
[cancel_title, cancel_subtitle],
51+
]
52+
for path in paths:
53+
paths_to_display.append([os.path.basename(path), path])
54+
2855
self.window.show_quick_panel(
29-
[
30-
[
31-
"Send item{0} to trash".format(
32-
("s" if len(self.paths) > 1 else "")
33-
)
34-
]
35-
+ self.paths,
36-
"Cancel",
37-
],
38-
self.delete,
56+
paths_to_display, self.delete,
3957
)
4058
else:
4159
# index 0 is like clicking on the first option of the panel

0 commit comments

Comments
 (0)