I was trying to create a delete_open_file command, that I can bind to a key and trigger it to delete the file associated with the currently active view
import os.path
import sublime
import sublime_plugin
class DeleteOpenFileCommand(sublime_plugin.WindowCommand):
def run(self):
view = self.window.active_view()
if view is None:
return
file_name = view.file_name()
if file_name is None or not os.path.exists(file_name):
return
if sublime.ok_cancel_dialog("Delete %s?" % file_name, "Delete"):
if not view.close():
return
import Default.send2trash as send2trash
send2trash.send2trash(file_name)
this works but not for image previews for which self.window.active_view() returns None, so how can I implement this correctly ?