示例#1
0
    def run(self, start=None):
        """Run command."""

        if FuzzyFileNavCommand.active:
            self.window.run_command("hide_overlay")
        self.cls = FuzzyFileNavCommand
        previous = self.cls.cwd
        self.cls.active = True
        self.cls.win_id = self.window.id()
        self.regex_exclude = sublime.load_settings(FUZZY_SETTINGS).get("regex_exclude", [])
        FuzzyPathCompleteCommand.reset_autocomplete()

        debug_log("start - %s" % start if start is not None else "None")

        # Check if a start destination has been given
        # and ensure it is valid.
        directory = get_root_path() if start is None or not path.exists(start) or not path.isdir(start) else start
        self.cls.cwd = directory if PLATFORM == "windows" and directory == "" else path.normpath(directory)

        debug_log("cwd - %s" % self.cls.cwd)

        # Get and display options.
        try:
            self.display_files(self.cls.cwd)
        except Exception:
            if self.cls.fuzzy_reload:
                # Reloading, so fuzzy panel must be up, so preserve previous state
                self.cls.fuzzy_reload = False
                self.cls.cwd = previous
            else:
                # Not reloading, so go ahead and reset the state
                self.cls.reset()
            notify("%s is not accessible!" % self.cls.cwd)
示例#2
0
    def check_selection(self, selection):
        """Check the users selection and navigate to directory or open file."""

        debug_log("Process selection")
        if selection > -1:
            self.cls.fuzzy_reload = False
            # The first selection is the "go up a directory" option.
            directory = back_dir(
                self.cls.cwd) if selection == 0 else path.join(
                    self.cls.cwd, self.cls.files[selection])
            self.cls.cwd = directory if PLATFORM == "windows" and directory == "" else path.normpath(
                directory)

            # Check if the option is a folder or if we are at the root (needed for windows)
            try:
                if (path.isdir(self.cls.cwd)
                        or self.cls.cwd == get_root_path()):
                    # List directories content
                    self.display_files(self.cls.cwd)
                else:
                    multi = (bool(
                        sublime.load_settings(FUZZY_SETTINGS).get(
                            "keep_panel_open_after_action", False)) and "open"
                             not in sublime.load_settings(FUZZY_SETTINGS).get(
                                 "keep_panel_open_exceptions", []))

                    # Open file
                    new_view = self.window.open_file(self.cls.cwd)
                    if new_view is not None:

                        # Horrible ugly hack to ensure opened file gets focus
                        def fun(v, multi):
                            """Function to focus view."""

                            v.window().focus_view(v)
                            if not multi:
                                v.window().show_quick_panel(["None"], None)
                                v.window().run_command("hide_overlay")

                        sublime.set_timeout(lambda: fun(new_view, multi), 500)

                    # If multi-file open is set, leave panel open after opening file
                    if multi:
                        self.cls.cwd = path.normpath(back_dir(self.cls.cwd))
                        self.display_files(self.cls.cwd, selection)
                    else:
                        self.cls.reset()
            except Exception:
                # Inaccessible folder try backing up
                notify("%s is not accessible!" % self.cls.cwd)
                self.cls.cwd = back_dir(self.cls.cwd)
                self.display_files(self.cls.cwd)
        elif not self.cls.fuzzy_reload:
            # Reset if not reloading
            self.cls.reset()
        else:
            # Reset reload flag if reloading
            self.cls.fuzzy_reload = False
示例#3
0
    def check_selection(self, selection):
        """Check the users selection and navigate to directory or open file."""

        debug_log("Process selection")
        if selection > -1:
            self.cls.fuzzy_reload = False
            # The first selection is the "go up a directory" option.
            directory = back_dir(self.cls.cwd) if selection == 0 else path.join(self.cls.cwd, self.cls.files[selection])
            self.cls.cwd = directory if PLATFORM == "windows" and directory == "" else path.normpath(directory)

            # Check if the option is a folder or if we are at the root (needed for windows)
            try:
                if (path.isdir(self.cls.cwd) or self.cls.cwd == get_root_path()):
                    # List directories content
                    self.display_files(self.cls.cwd)
                else:
                    multi = (
                        bool(sublime.load_settings(FUZZY_SETTINGS).get("keep_panel_open_after_action", False)) and
                        "open" not in sublime.load_settings(FUZZY_SETTINGS).get("keep_panel_open_exceptions", [])
                    )

                    # Open file
                    new_view = self.window.open_file(self.cls.cwd)
                    if new_view is not None:

                        # Horrible ugly hack to ensure opened file gets focus
                        def fun(v, multi):
                            """Function to focus view."""

                            v.window().focus_view(v)
                            if not multi:
                                v.window().show_quick_panel(["None"], None)
                                v.window().run_command("hide_overlay")

                        sublime.set_timeout(lambda: fun(new_view, multi), 500)

                    # If multi-file open is set, leave panel open after opening file
                    if multi:
                        self.cls.cwd = path.normpath(back_dir(self.cls.cwd))
                        self.display_files(self.cls.cwd, selection)
                    else:
                        self.cls.reset()
            except Exception:
                # Inaccessible folder try backing up
                notify("%s is not accessible!" % self.cls.cwd)
                self.cls.cwd = back_dir(self.cls.cwd)
                self.display_files(self.cls.cwd)
        elif not self.cls.fuzzy_reload:
            # Reset if not reloading
            self.cls.reset()
        else:
            # Reset reload flag if reloading
            self.cls.fuzzy_reload = False
示例#4
0
    def run(self, start=None):
        """Run command."""

        if FuzzyFileNavCommand.active:
            self.window.run_command("hide_overlay")
        self.cls = FuzzyFileNavCommand
        previous = self.cls.cwd
        self.cls.active = True
        self.cls.win_id = self.window.id()
        self.regex_exclude = sublime.load_settings(FUZZY_SETTINGS).get(
            "regex_exclude", [])
        FuzzyPathCompleteCommand.reset_autocomplete()

        debug_log("start - %s" % start if start is not None else "None")

        # Check if a start destination has been given
        # and ensure it is valid.
        directory = get_root_path() if start is None or not path.exists(
            start) or not path.isdir(start) else start
        self.cls.cwd = directory if PLATFORM == "windows" and directory == "" else path.normpath(
            directory)

        debug_log("cwd - %s" % self.cls.cwd)

        # Get and display options.
        try:
            self.display_files(self.cls.cwd)
        except Exception:
            if self.cls.fuzzy_reload:
                # Reloading, so fuzzy panel must be up, so preserve previous state
                self.cls.fuzzy_reload = False
                self.cls.cwd = previous
            else:
                # Not reloading, so go ahead and reset the state
                self.cls.reset()
            notify("%s is not accessible!" % self.cls.cwd)
示例#5
0
    def on_query_context(self, view, key, operator, operand, match_all):
        """Capture shortcuts in a FuzzyNavPanel."""

        active = FuzzyFileNavCommand.active is True
        if active and FuzzyFileNavCommand.view is not None and FuzzyFileNavCommand.view.id() == view.id():
            FuzzyPanelText.set_content(view.substr(view.line(view.sel()[0])))
            full_name = path.join(FuzzyFileNavCommand.cwd, FuzzyPanelText.get_content())
            empty = (FuzzyPanelText.get_content() == "")
            # See if this is the auto-complete path command
            if key in [
                "fuzzy_path_complete", "fuzzy_path_complete_back", "fuzzy_toggle_hidden",
                "fuzzy_bookmarks_load", "fuzzy_get_cwd", "fuzzy_cwv"
            ]:
                return active
            elif key == "fuzzy_open_folder":
                if (
                    (
                        (not empty and path.exists(full_name) and path.isdir(full_name)) or
                        (empty and path.exists(FuzzyFileNavCommand.cwd))
                    )
                ):
                    return active
            elif key in ["fuzzy_reveal", "fuzzy_search"]:
                if path.exists(FuzzyFileNavCommand.cwd):
                    return active
                else:
                    notify("%s does not exist!" % FuzzyFileNavCommand.cwd)
            elif key in ["fuzzy_quick_open"]:
                sels = view.sel()
                if len(sels) == 1:
                    if sels[0].a == sels[0].b and sels[0].a == view.size():
                        return active
                    else:
                        pass
            elif key == "fuzzy_delete":
                if not empty and path.exists(full_name):
                    return active
                elif not empty:
                    notify("%s does not exist!" % full_name)
            elif key in ["fuzzy_make_file", "fuzzy_make_folder"]:
                if not empty and not path.exists(full_name):
                    return active
                elif not empty:
                    notify("%s already exists!" % full_name)
            elif key == "fuzzy_save_as":
                if not empty and (not path.exists(full_name) or not path.isdir(full_name)):
                    return active
                elif not empty:
                    notify("%s is a directory!" % full_name)
            elif key == "fuzzy_copy":
                if not empty and path.exists(full_name):
                    return active
                elif not empty:
                    notify("%s does not exist!" % full_name)
            elif key == "fuzzy_cut":
                if path.exists(FuzzyFileNavCommand.cwd):
                    return active
                else:
                    notify("%s does not exist!" % FuzzyFileNavCommand.cwd)
            elif key == "fuzzy_paste":
                if path.exists(FuzzyFileNavCommand.cwd) and len(FuzzyClipboardCommand.clips):
                    return active
                else:
                    notify("%s does not exist!" % FuzzyFileNavCommand.cwd)
        return False
示例#6
0
    def on_query_context(self, view, key, operator, operand, match_all):
        """Capture shortcuts in a FuzzyNavPanel."""

        active = FuzzyFileNavCommand.active is True
        if active and FuzzyFileNavCommand.view is not None and FuzzyFileNavCommand.view.id(
        ) == view.id():
            FuzzyPanelText.set_content(view.substr(view.line(view.sel()[0])))
            full_name = path.join(FuzzyFileNavCommand.cwd,
                                  FuzzyPanelText.get_content())
            empty = (FuzzyPanelText.get_content() == "")
            # See if this is the auto-complete path command
            if key in [
                    "fuzzy_path_complete", "fuzzy_path_complete_back",
                    "fuzzy_toggle_hidden", "fuzzy_bookmarks_load",
                    "fuzzy_get_cwd", "fuzzy_cwv"
            ]:
                return active
            elif key == "fuzzy_open_folder":
                if (((not empty and path.exists(full_name)
                      and path.isdir(full_name))
                     or (empty and path.exists(FuzzyFileNavCommand.cwd)))):
                    return active
            elif key in ["fuzzy_reveal", "fuzzy_search"]:
                if path.exists(FuzzyFileNavCommand.cwd):
                    return active
                else:
                    notify("%s does not exist!" % FuzzyFileNavCommand.cwd)
            elif key in ["fuzzy_quick_open"]:
                sels = view.sel()
                if len(sels) == 1:
                    if sels[0].a == sels[0].b and sels[0].a == view.size():
                        return active
                    else:
                        pass
            elif key == "fuzzy_delete":
                if not empty and path.exists(full_name):
                    return active
                elif not empty:
                    notify("%s does not exist!" % full_name)
            elif key in ["fuzzy_make_file", "fuzzy_make_folder"]:
                if not empty and not path.exists(full_name):
                    return active
                elif not empty:
                    notify("%s already exists!" % full_name)
            elif key == "fuzzy_save_as":
                if not empty and (not path.exists(full_name)
                                  or not path.isdir(full_name)):
                    return active
                elif not empty:
                    notify("%s is a directory!" % full_name)
            elif key == "fuzzy_copy":
                if not empty and path.exists(full_name):
                    return active
                elif not empty:
                    notify("%s does not exist!" % full_name)
            elif key == "fuzzy_cut":
                if path.exists(FuzzyFileNavCommand.cwd):
                    return active
                else:
                    notify("%s does not exist!" % FuzzyFileNavCommand.cwd)
            elif key == "fuzzy_paste":
                if path.exists(FuzzyFileNavCommand.cwd) and len(
                        FuzzyClipboardCommand.clips):
                    return active
                else:
                    notify("%s does not exist!" % FuzzyFileNavCommand.cwd)
        return False