def on_text_changed(self, text: str) -> None: """Update trash model the once when text changed. This is required in addition to on_enter as it is very likely to enter trash completion by typing :undelete. """ if self._initialized: return self.clear() data = [] for path in files.listdir(trash_manager.files_directory()): cmd = "undelete %s" % (os.path.basename(path)) # Get info and format it neatly original, date = trash_manager.trash_info(path) original = original.replace(os.path.expanduser("~"), "~") original = os.path.dirname(original) date = "%s-%s-%s %s:%s" % ( date[2:4], date[4:6], date[6:8], date[9:11], date[11:13], ) # Append data in column form data.append((cmd, original, date)) self.set_data(data) self._initialized = True
def check_show_deletion_date(completiondata, basename): original_path, deletion_date = trash_manager.trash_info(basename) # Space for formatting and remove seconds expected_date = deletion_date.replace("T", " ")[:-3] expected_dir = os.path.dirname(original_path) for completion_text, completion_dir, completion_date in completiondata: completion_basename = completion_text.replace(":undelete ", "") if completion_basename == basename: assert expected_date == completion_date assert expected_dir == completion_dir break else: assert False, f"Completion for '{basename}' not found"
def on_enter(self, text: str) -> None: """Update trash model on enter to include any newly un-/deleted paths.""" data = [] for path in files.listdir(trash_manager.files_directory()): cmd = f":undelete {os.path.basename(path)}" # Get info and format it neatly original, date = trash_manager.trash_info(path) original = original.replace(os.path.expanduser("~"), "~") original = os.path.dirname(original) date = "%s-%s-%s %s:%s" % ( date[2:4], date[4:6], date[6:8], date[9:11], date[11:13], ) # Append data in column form data.append((cmd, original, date)) self.set_data(data)
def on_enter(self, text: str) -> None: """Update trash model on enter to include any newly un-/deleted paths.""" data = [] for path in files.listdir(trash_manager.files_directory()): cmd = f":undelete {api.completion.escape(os.path.basename(path))}" # Get info and format it neatly original, date = trash_manager.trash_info(path) original = original.replace(os.path.expanduser("~"), "~") original = os.path.dirname(original) date_match = self._date_re.match(date) if date_match is None: # Wrong date formatting that was used up to v0.7.0 # TODO remove after releasing v1.0.0 date_match = self._old_date_re.match(date) if date_match is not None: year, month, day, hour, minute, _ = date_match.groups() date = f"{year}-{month}-{day} {hour}:{minute}" else: date = "date unknown" # Append data in column form data.append((cmd, original, date)) self.set_data(data)