(self, files)
Sending to trash might be slow
        So we start two threads which run _sender function in parallel and each of them waiting and
        setting certain event:
            1. remove one which signals that _sender need try to call send2trash for current file
               and if it fails collect error message (always ascii, no bother with encoding)
            2. report one which call _status function to display message on status-bar so user
               can see what is going on
        When loop in _sender is finished we refresh view and show errors if any.

        On Windows we call API directly in call_SHFileOperationW class.
Sending to trash might be slow
        So we start two threads which run _sender function in parallel and each of them waiting and
        setting certain event:
            1. remove one which signals that _sender need try to call send2trash for current file
               and if it fails collect error message (always ascii, no bother with encoding)
            2. report one which call _status function to display message on status-bar so user
               can see what is going on
        When loop in _sender is finished we refresh view and show errors if any.
Sending to trash might be slow So we start two threads which run _sender function in parallel and each of them waiting and setting certain event : 1 . remove one which signals that _sender need try to call send2trash for current file and if it fails collect error message ( always ascii no bother with encoding ) 2 . report one which call _status function to display message on status - bar so user can see what is going on When loop in _sender is finished we refresh view and show errors if any .
def _to_trash(self, files):
        '''Sending to trash might be slow
        So we start two threads which run _sender function in parallel and each of them waiting and
        setting certain event:
            1. remove one which signals that _sender need try to call send2trash for current file
               and if it fails collect error message (always ascii, no bother with encoding)
            2. report one which call _status function to display message on status-bar so user
               can see what is going on
        When loop in _sender is finished we refresh view and show errors if any.

        On Windows we call API directly in call_SHFileOperationW class.
        '''
        path = self.path
        if NT:  # use winapi directly, because better errors handling, plus GUI
            sources_move = [join(path, f) for f in files]
            return call_SHFileOperationW(self.view, sources_move, [], '$TRASH$')

        errors = []

        def _status(filename='', done=False):
            if done:
                sublime.set_timeout(lambda: self.view.run_command('dired_refresh'), 1)
                if errors:
                    sublime.error_message(u'Some files couldn’t be sent to trash (perhaps, they are being used by another process): \n\n'
                                          + '\n'.join(errors).replace('Couldn\'t perform operation.', ''))
            else:
                status = u'Please, wait… Removing ' + filename
                sublime.set_timeout(lambda: self.view.set_status("__FileBrowser__", status), 1)

        def _sender(files, event_for_wait, event_for_set):
            for filename in files:
                event_for_wait.wait()
                event_for_wait.clear()
                if event_for_wait is remove_event:
                    try:
                        send2trash.send2trash(join(path, filename))
                    except OSError as e:
                        errors.append(u'{0}:\t{1}'.format(e, filename))
                else:
                    _status(filename)
                event_for_set.set()
            if event_for_wait is remove_event:
                _status(done=True)

        remove_event = threading.Event()
        report_event = threading.Event()
        t1 = threading.Thread(target=_sender, args=(files, remove_event, report_event))
        t2 = threading.Thread(target=_sender, args=(files, report_event, remove_event))
        t1.start()
        t2.start()
        report_event.set()
def _to_trash ( self , files ) : path = self . path if NT : # use winapi directly, because better errors handling, plus GUI sources_move = [ join ( path , f ) for f in files ] return call_SHFileOperationW ( self . view , sources_move , [ ] , '$TRASH$' ) errors = [ ] def _status ( filename = '' , done = False ) : if done : sublime . set_timeout ( lambda : self . view . run_command ( 'dired_refresh' ) , 1 ) if errors : sublime . error_message ( u'Some files couldn’t be sent to trash (perhaps, they are being used by another process): \n\n' + '\n' . join ( errors ) . replace ( 'Couldn\'t perform operation.' , '' ) ) else : status = u'Please, wait… Removing ' + f lename sublime . set_timeout ( lambda : self . view . set_status ( "__FileBrowser__" , status ) , 1 ) def _sender ( files , event_for_wait , event_for_set ) : for filename in files : event_for_wait . wait ( ) event_for_wait . clear ( ) if event_for_wait is remove_event : try : send2trash . send2trash ( join ( path , filename ) ) except OSError as e : errors . append ( u'{0}:\t{1}' . format ( e , filename ) ) else : _status ( filename ) event_for_set . set ( ) if event_for_wait is remove_event : _status ( done = True ) remove_event = threading . Event ( ) report_event = threading . Event ( ) t1 = threading . Thread ( target = _sender , args = ( files , remove_event , report_event ) ) t2 = threading . Thread ( target = _sender , args = ( files , report_event , remove_event ) ) t1 . start ( ) t2 . start ( ) report_event . set ( )