def do_action(view: View, defx: Defx, action_name: str, context: Context) -> bool: """ Do "action_name" action. """ if not defx._source: return True actions: typing.Dict[str, ActionTable] = defx._source.kind.get_actions() if action_name not in actions: return True action = actions[action_name] selected_candidates = [x for x in view._candidates if x['is_selected']] if (selected_candidates and ActionAttr.NO_TAGETS not in action.attr and ActionAttr.TREE not in action.attr): # Clear marks for candidate in selected_candidates: candidate['is_selected'] = False view.redraw() if ActionAttr.CURSOR_TARGET in action.attr: # Use cursor candidate only cursor_candidate = view.get_cursor_candidate(context.cursor) if not cursor_candidate: return True context = context._replace( targets=[cursor_candidate], ) action.func(view, defx, context) if action_name != 'repeat': view._prev_action = action_name if ActionAttr.MARK in action.attr: # Update marks view.update_candidates() view.redraw() elif ActionAttr.TREE in action.attr: view.update_candidates() view.redraw() elif ActionAttr.REDRAW in action.attr: # Redraw view.redraw(True) return False
def _search(view: View, defx: Defx, context: Context) -> None: if not context.args or not context.args[0]: return search_path = context.args[0] path = Path(search_path) parents: typing.List[Path] = [] while view.get_candidate_pos( path, defx._index) < 0 and path.parent != path: path = path.parent parents.append(path) for parent in reversed(parents): view.open_tree(parent, defx._index, 0) view.update_candidates() view.redraw() view.search_file(Path(search_path), defx._index)