def get_size(arguments):
    is_popup = ("--popup" in arguments or lfEval("g:Lf_WindowPosition") == 'popup') \
            and "--bottom" not in arguments
    string = lfEval("get(g:, 'Lf_ColorPanel_str', 'xxx')")
    string = arguments.get("--str", [string])[0]
    col_len = 4 + len(string) + 1
    default_col = 12 if is_popup else 999
    cols = lfEval("get(g:, 'Lf_ColorPanel_cols', %d)" % default_col)
    cols = arguments.get("--cols", [cols])[0]
    cols = int(cols)
    cols = default_col if cols < 1 else cols
    vim_cols = int(lfEval("&columns"))
    if ("--left" in arguments
            or "--right" in arguments
            or lfEval("g:Lf_WindowPosition") == 'left'
            or lfEval("g:Lf_WindowPosition") == 'right'):
        vim_cols = math.floor(vim_cols / 2)
    max_cols = math.floor((vim_cols - 2) / col_len)
    cols = min(cols, max_cols)
    fit_rows = math.ceil(256 / cols)
    rows = lfEval("get(g:, 'Lf_ColorPanel_rows', %d)" % fit_rows)
    rows = arguments.get("--rows", [rows])[0]
    rows = int(rows)
    rows = fit_rows if rows < 1 else rows
    max_rows = int(lfEval("&lines"))
    if is_popup:
        max_rows -= 2
    rows = min(rows, max_rows, fit_rows) + 2 # input window
    return rows, cols
Ejemplo n.º 2
0
def command__add_file(manager):
    name = lfEval("expand('%:p:t')")
    path = lfEval("expand('%:p')").replace("\\", "/")
    save_context(manager)
    input_prompt(
        manager,
        "add_file",
        [
            {
                "prompt": "(Add file) Path: ",
                "text": path
            },
            {
                "prompt": "(Add file) Name: ",
                "text": name
            },
        ],
    )
Ejemplo n.º 3
0
def command___do_add_dir(manager, context, results):
    path = results[0]
    name = results[1]
    if len(name.strip()) == 0 or len(path.strip()) == 0:
        echo_cancel()
        return

    if name in lfEval("leaderf#Bookmark#load_bookmaks()"):
        echo_error("Already exists in bookmark '{}'".format(name))
        return

    lfCmd('call leaderf#Bookmark#_add("{}", "{}")'.format(name, path))
Ejemplo n.º 4
0
def command___do_mkdir(manager, context, results):
    dir_name = results[0]
    if dir_name == "":
        echo_cancel()
        return

    path = os.path.join(manager._getExplorer().cwd, dir_name)
    if os.path.exists(os.path.join(manager._getExplorer().cwd, dir_name)):
        echo_error(" Already exists. '{}'".format(path.replace("\\", "/")))
        return

    os.makedirs(path)

    if manager._instance.getWinPos() not in ("popup", "floatwin"):
        if lfEval("get(g:, 'Lf_FilerMkdirAutoChdir', 0)") == "1":
            manager._chcwd(path)
        else:
            manager._refresh()
    else:
        if lfEval("get(g:, 'Lf_FilerMkdirAutoChdir', 0)") == "1":
            manager._chcwd(path, write_history=False, normal_mode=True)
        else:
            manager._refresh(write_history=False, normal_mode=True)
    manager._move_cursor_if_fullpath_match(path)
Ejemplo n.º 5
0
def command___do_edit(manager, context, results):
    new_path = results[0]
    new_name = results[1]

    if len(new_name.strip()) == 0 or len(new_path.strip()) == 0:
        echo_cancel()
        return

    if context.get("old_name") != new_name and new_name in lfEval(
            "leaderf#Bookmark#load_bookmaks()"):
        echo_error("Already exists in bookmark '{}'".format(new_name))
        return

    lfCmd('call leaderf#Bookmark#_edit("{}", "{}", "{}")'.format(
        context["old_name"], new_name, new_path))
Ejemplo n.º 6
0
    def help_list(self):
        if self._help_text_list:
            return self._help_text_list

        help = []
        key_cmd_dict = dict()
        for [key, cmd_name] in lfEval("leaderf#Filer#NormalMap()").items():
            key_cmd_dict[cmd_name] = key_cmd_dict.get(cmd_name, []) + [key]

        # sort key
        for [key, val] in key_cmd_dict.items():
            key_cmd_dict[key] = sorted(val)

        for [name, text] in self._help_dict.items():
            if name in key_cmd_dict:
                # key1/key2 : help text
                line = '" {} : {}'.format("/".join(key_cmd_dict[name]), text)
                help.append(line)
        help.sort()
        help.append(
            '" ---------------------------------------------------------')

        self._help_text_list = help
        return help
Ejemplo n.º 7
0
def cd(path):
    # XXX: from defx.nvim
    if lfEval("exists('*chdir')") == "1":
        lfCmd("call chdir('%s')" % path)
    else:
        lfCmd("silent execute (haslocaldir() ? 'lcd' : 'cd') '%s'" % path)
Ejemplo n.º 8
0
def command__mkdir(manager):
    # For dir completion
    save_cwd = lfEval("getcwd()")
    cd(manager._getExplorer().cwd)
    save_context(manager, **{"save_cwd": save_cwd})
    input_prompt(manager, "mkdir", [{"prompt": "Create directory: "}])
Ejemplo n.º 9
0
def command__close_preview_popup(manager):
    if lfEval("has('nvim')"):
        manager._closePreviewPopup()
Ejemplo n.º 10
0
def command__page_down_in_preview(manager):
    if lfEval("has('nvim')"):
        manager._toDownInPopup()
Ejemplo n.º 11
0
def command__page_up_in_preview(manager):
    if lfEval("has('nvim')"):
        manager._toUpInPopup()
Ejemplo n.º 12
0
def command__goto_root_marker_dir(manager):
    root_markers = lfEval("g:Lf_RootMarkers")
    rootMarkersDir = nearestAncestor(root_markers, manager._getExplorer().cwd)
    if rootMarkersDir:
        # exists root_markers
        manager._chcwd(os.path.abspath(rootMarkersDir))