def rename(self, key=None): if key: if self.list_entry_for_renaming: exit_action_key = self.action_map[action.exit].keybinding navigate_mode_action_key = self.action_map[ action.navigate_mode].keybinding if key in (exit_action_key, navigate_mode_action_key): if key == exit_action_key: new_name = self.list_entry_for_renaming.edit_text operate.rename(self.list_entry_for_renaming.entry, new_name) self.list_entry_for_renaming.editing = False self.list.render(self.list_size, focus=True) self.list_entry_for_renaming = None self.active_action = None self.enter_navigate_mode() else: self.list_entry_for_renaming.keypress( self.filter_size, key) return True else: if self.navigator.is_navigation_key(key): target = self.navigator.current_entry.get_child_for_key( Key(key)) notify.clear() list_entry = self.list.get_list_entry(target) if list_entry: list_entry.editing = True self.list.selection = list_entry self.list.render(self.list_size, focus=True) self.list_entry_for_renaming = list_entry return True else: notify.show("rename what?", duration=0) self.active_action = self.rename
def toggle_dotfiles(self): self.model.show_hidden_files = not self.model.show_hidden_files if self.model.show_hidden_files: message = 'show dotfiles' else: message = 'hide dotfiles' notify.show(message, duration=0.7)
def yank_to_clipboard(self, text: str): try: pyperclip.copy(text) text_to_log = text[0:60].replace("\n", "") if len(text) > 60: text_to_log += "..." logger.info(f"Yanked '{text_to_log}' to system clipboard") notify.show(f"Yanked to clipboard", duration=1) except pyperclip.PyperclipException: logger.exception(f"Failed to yank") notify.show("Failed to yank: system has no clipboard", duration=2)
def delete(self, key=None): if key: if self.navigator.is_navigation_key(key): target = self.navigator.current_entry.get_child_for_key( Key(key)) buffer.registers[0].move_to(target) self.navigator.reload_current_entry() self.active_action = None self.enter_navigate_mode() return True else: notify.show("delete what?", duration=0) self.active_action = self.delete
def yank(self, key=None): if key: if self.navigator.is_navigation_key(key): target = self.navigator.current_entry.get_child_for_key( Key(key)) buffer.registers[0].copy_to(target) notify.show(f"yanked {target.path}") self.active_action = None self.enter_navigate_mode() return True else: notify.show("yank what?", duration=0) self.active_action = self.yank
def handle_keypress(self, size, key): try: self.calculate_sizes(size) handled = False if self.filter.active: self.filter.keypress(self.filter_size, key) handled = True elif self.active_action: handled = self.active_action.__call__(key=key) if not handled: if not self.handle_key_individually(key): for action in self.action_map.values(): if action.handle(key): break except PermissionError: notify.show((AttrSpec(theme.forbidden + ',bold', '', colors=16), "PERMISSION DENIED")) except FileNotFoundError: notify.show((AttrSpec(theme.forbidden + ',bold', '', colors=16), "FILE NOT FOUND"))