Skip to content

Instantly share code, notes, and snippets.

@gmolop
Created March 28, 2017 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gmolop/3f43c6176ca05c4c2efc26b5094e21a2 to your computer and use it in GitHub Desktop.
Save gmolop/3f43c6176ca05c4c2efc26b5094e21a2 to your computer and use it in GitHub Desktop.
Sublime Text 3: Confirm dialog to delete file(s)
# Source: http://stackoverflow.com/a/35630637/1601332
# Credit: @iron77
# File path: ~/Library/Application Support/Sublime Text 3/Packages/User/confirm_delete.py
from Default.side_bar import *
class DeleteFileCommand(sublime_plugin.WindowCommand):
def run(self, files):
if len(files) == 1:
message = "Delete File %s?" % files[0]
else:
message = "Delete %d Files?" % len(files)
if sublime.ok_cancel_dialog(message, "Delete") != True:
return
# Import send2trash on demand, to avoid initialising ctypes for as long as possible
import Default.send2trash as send2trash
for f in files:
v = self.window.find_open_file(f)
if v != None and not v.close():
return
send2trash.send2trash(f)
def is_visible(self, files):
return len(files) > 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment