示例#1
0
    def input(self, args):
        bmark_type = args.get("bmark_type")
        if bmark_type is None:
            return BookmarkTypeInputHandler(find_help_view())

        if args.get("bmark_name") is None:
            return BookmarkNameInputHandler(find_help_view(), bmark_type)
示例#2
0
    def run(self, action, index=-1):
        if action in ["next", "prev"]:
            navigate_help_history(find_help_view(),
                                  True if action == "prev" else False)
        elif action == "clear":
            clear_help_history(find_help_view())

        else:
            self.show_history(index)
示例#3
0
    def on_query_context(self, view, key, operator, operand, match_all):
        """
        Provide custom key binding contexts for binding keys in hyperhelp
        views.
        """
        if key == "hyperhelp.is_help_view":
            help_view = find_help_view(view.window())
            lhs = help_view is not None and help_view.id() == view.id()
            rhs = bool(operand)

        elif key == "hyperhelp.is_help_source":
            lhs = (view.match_selector(0, "text.hyperhelp.help")
                   and view.is_read_only() == False)
            rhs = bool(operand)

        elif key == "hyperhelp.is_help":
            lhs = view.match_selector(0, "text.hyperhelp.help")
            rhs = bool(operand)

        elif key == "hyperhelp.is_help_index":
            lhs = view.match_selector(0, "text.hyperhelp.index")
            rhs = bool(operand)

        elif key == "hyperhelp.is_help_visible":
            lhs = find_help_view(view.window()) is not None
            rhs = bool(operand)

        elif key == "hyperhelp.is_help_package":
            lhs = current_help_package(window=view.window())
            rhs = str(operand)

        elif key == "hyperhelp.is_help_file":
            lhs = current_help_file(window=view.window())
            rhs = str(operand)

        # This one is the legacy; remove this once the others are fully
        # tested.
        elif key == "hyperhelp.is_authoring":
            lhs = view.is_read_only() == False
            rhs = bool(operand)
        else:
            return None

        if operator == sublime.OP_EQUAL:
            return lhs == rhs
        elif operator == sublime.OP_NOT_EQUAL:
            return lhs != rhs

        return None
示例#4
0
    def run(self, bookmark_idx):
        all_bookmarks = hh_setting("bookmarks")
        try:
            bookmark = all_bookmarks[bookmark_idx]
        except IndexError:
            return log("Bookmark index was out of range", status=True)

        pkg = bookmark.get("package")
        topic = bookmark.get("topic")
        caret = bookmark.get("caret")
        viewport = bookmark.get("viewport")

        if pkg is None or topic is None:
            return log("Bookmark at index specified is not valid", status=True)

        if show_help_topic(pkg, topic, history=True) == "file":
            help_view = find_help_view()
            if caret is not None:
                help_view.sel().clear()
                help_view.sel().add(sublime.Region(caret[0], caret[1]))

                if viewport is not None:
                    help_view.set_viewport_position(viewport, True)
                else:
                    help_view.show_at_center(help_view.sel()[0])
示例#5
0
    def is_enabled(self, *kwargs):
        window = sublime.active_window()
        current_view = window.active_view() if window is not None else None
        help_view = find_help_view(window)

        return (current_view == help_view and
                current_view is not None and
                help_index_list().get(current_help_package()) is not None)
示例#6
0
    def get_history_info(self, help_view=None):
        help_view = help_view or find_help_view()

        if help_view is not None:
            settings = help_view.settings()
            return (
                settings.get("_hh_hist_pos"),
                settings.get("_hh_hist")
            )

        return (None, None)
示例#7
0
    def follow_link(self):
        help_view = find_help_view()
        point = help_view.sel()[0].begin()

        if help_view.match_selector(point, "text.hyperhelp meta.link"):
            topic = "_broken"
            package = help_view.settings().get("_hh_pkg")

            link_region = help_view.extract_scope(point)
            topic_dat = _get_link_topic(help_view, link_region)
            if topic_dat is not None:
                topic = topic_dat["topic"]
                package = topic_dat["pkg"] or package

            show_help_topic(package, topic, history=True)
示例#8
0
    def is_enabled(self, action, index=-1):
        help_view = find_help_view()
        if help_view is None or action not in self.available_actions:
            return False

        h_pos, h_info = self.get_history_info(help_view)
        h_len = len(h_info)

        if action in ["next", "prev"]:
            prev = True if action == "prev" else False
            if (prev and h_pos == 0) or (not prev and h_pos == h_len - 1):
                return False

        if action in ["clear", "jump"] and h_len == 1:
            return False

        return True
示例#9
0
    def anchor_nav(self, prev):
        help_view = find_help_view()
        anchors = help_view.get_regions("_hh_anchors")
        if not anchors:
            return

        point = help_view.sel()[0].begin()
        fallback = anchors[-1] if prev else anchors[0]

        pick = lambda p: (point < p.a) if not prev else (point > p.a)
        for pos in reversed(anchors) if prev else anchors:
            if pick(pos):
                return help_view.run_command("hyperhelp_focus",
                    {"position": [pos.b, pos.a]})

        help_view.run_command("hyperhelp_focus",
            {"position": [fallback.b, fallback.a]})
示例#10
0
    def run(self, edit):
        # Running directly on the help view
        settings = self.view.settings()
        if settings.has("_hh_pkg") and settings.has("_hh_file"):
            return self.reload(self.view, current_help_file())

        # File must have a name and be in the packages folder.
        name = self.view.file_name()
        if name is None or not name.startswith(sublime.packages_path()):
            return log("Unable to reload help; help file is not in a package",
                       status=True)

        name = os.path.relpath(name, sublime.packages_path())
        pkg = name.split(os.sep)[0]
        file = os.path.split(name)[1]

        if pkg == current_help_package() and file == current_help_file():
            return self.reload(find_help_view(), file)

        log("Unable to reload help; this is not the current help file",
            status=True)
示例#11
0
    def run(self, bmark_type, bmark_name):
        v = find_help_view(sublime.active_window())

        link_info = None
        if len(v.sel()) > 0 and v.match_selector(v.sel()[0].b, "meta.link"):
            link_info = _get_link_topic(v, v.extract_scope(v.sel()[0].b))

        pkg_name = current_help_package()
        topic = current_help_file()

        if bmark_type == "topic" and link_info is not None:
            pkg_name = link_info["pkg"]
            topic = link_info["topic"]

        caret = (v.sel()[0].a, v.sel()[0].b) if bmark_type == "view" else None
        viewport = v.viewport_position() if bmark_type == "view" else None

        sublime.run_command("hyperhelp_create_bookmark", {
            "name": bmark_name,
            "package": pkg_name,
            "topic": topic,
            "caret": caret,
            "viewport": viewport
            })
示例#12
0
def plugin_loaded():
    PackageIndexWatcher()
    for window in sublime.windows():
        view = find_help_view(window)
        if view:
            view.run_command("hyperhelp_internal_flag_links")
示例#13
0
    def is_enabled(self, nav, prev=False):
        help_view = find_help_view()
        if help_view is None or nav not in self.available_nav:
            return False

        return True
示例#14
0
 def next_input(self, args):
     if args.get("bmark_name") is None:
         return BookmarkNameInputHandler(find_help_view(), self.bmark_type)