Beispiel #1
0
def do_action(view: View, defx: Defx, action_name: str,
              context: Context) -> bool:
    """
    Do "action_name" action.
    """
    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 ActionAttr.NO_TAGETS not in action.attr and selected_candidates:
        # Clear marks
        for candidate in selected_candidates:
            candidate['is_selected'] = False
        view.redraw()

    action.func(view, defx, context)

    if action_name != 'repeat':
        view._prev_action = action_name

    if ActionAttr.MARK in action.attr:
        # Update marks
        view.redraw()
    elif ActionAttr.TREE in action.attr:
        view.update_opened_candidates()
        view.redraw()
    elif ActionAttr.REDRAW in action.attr:
        # Redraw
        view.redraw(True)
    return False
Beispiel #2
0
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_opened_candidates()
    view.redraw()
    view.search_file(Path(search_path), defx._index)