def is_enabled(self, package=None, prompt=False): if prompt == False: package = package or current_help_package() if package is None: return False return True
def run(self, edit): v = self.view regions = v.find_by_selector("meta.link") default_pkg = current_help_package(self.view) v.add_regions("_hh_links", regions, "", flags=sublime.HIDDEN | sublime.PERSISTENT) hh_links = [None] * len(regions) for idx,region in enumerate(reversed(regions)): base_text = v.substr(region) pkg_name, topic, text = parse_link_body(base_text) pkg_name = pkg_name or default_pkg if text is None: topic = "_broken" text = base_text v.replace(edit, region, text) hh_links[len(regions) - idx - 1] = { "pkg": pkg_name, "topic": topic } v.settings().set("_hh_links", hh_links) v.run_command("hyperhelp_internal_flag_links")
def run(self, package=None, file=None, prompt=False): package = package or current_help_package(window=self.window) if package is None or prompt: return help_package_prompt(help_index_list(), on_select=lambda p: self.run(p, file)) pkg_info = help_index_list().get(package, None) if pkg_info is None: return log("Cannot edit help file; package '%s' unknown", package, dialog=True) files = pkg_info.help_files items = [[key, files[key]] for key in files] if not items: return log("The help index for '%s' lists no help files", package, dialog=True) if file is not None: return open_local_help(pkg_info, file, window=self.window) def pick(index): if index >= 0: open_local_help(pkg_info, items[index][0], window=self.window) self.window.show_quick_panel( items=items, on_select=lambda index: pick(index))
def run(self, package=None, initial_text=None, prompt=False): package = package or current_help_package() if package is None or prompt: return help_package_prompt(help_index_list(), on_select=lambda pkg: self.run(pkg, initial_text)) pkg_info = help_index_list().get(package, None) if pkg_info is None: return log("Cannot display topic index; unknown package '%s", package, status=True) topics = [pkg_info.help_topics.get(topic) for topic in sorted(pkg_info.help_topics.keys())] items = [[t["caption"], t["topic"]] for t in topics] if not items: return log("No help topics defined for package '%s'", package, status=True) sublime.active_window().show_quick_panel( items, on_select=lambda index: self.select(pkg_info, items, index)) if initial_text: sublime.active_window().run_command("insert", {"characters": initial_text})
def run(self, edit): pkg = current_help_package(self.view, self.view.window()) file = current_help_file(self.view, self.view.window()) self.view.window().run_command("hyperhelp_author_edit_help", { "package": pkg, "file": file })
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)
def description(self, no_help_fmt="No help currently visible", help_fmt="Viewing help for: '%s'"): package = current_help_package(window=self.window) if package is None: return no_help_fmt pkg_info = help_index_list().get(package) package = package if pkg_info is None else pkg_info.description return help_fmt % package
def run(self, package=None, topic="index.txt"): package = package or current_help_package() topic = topic or "index.txt" if package is None: return log("Cannot display topic '%s'; cannot determine package", topic, status=True) show_help_topic(package, topic, history=True)
def run(self, edit): pkg = current_help_package(self.view, self.view.window()) if pkg is None: pkg_info = package_for_view(self.view) if pkg_info is not None: pkg = pkg_info.package if pkg is not None: self.view.window().run_command("hyperhelp_author_edit_index", {"package": pkg})
def run(self, package=None, prompt=False): package = package or current_help_package() if package is None or prompt: return help_package_prompt(help_index_list(), on_select=lambda pkg: self.run(pkg)) pkg_info = help_index_list().get(package, None) if pkg_info is None: return log("Cannot display table of contents; unknown package '%s", package, status=True) self.show_toc(pkg_info, pkg_info.help_toc, [])
def run(self, package=None, prompt=False): package = package or current_help_package(window=self.window) if package is None or prompt: return help_package_prompt(help_index_list(), on_select=lambda pkg: self.run(pkg)) pkg_info = help_index_list().get(package, None) if pkg_info is None: return log("Cannot edit help file; package '%s' unknown", package, dialog=True) open_help_index(pkg_info)
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
def initial_text(self): v = self.view 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)) if self.bmark_type == "topic" and link_info is not None: pkg_info = help_index_list().get(link_info["pkg"]) if pkg_info is not None: topic = lookup_help_topic(pkg_info, link_info["topic"]) return topic["caption"] file = current_help_file() name = "File {} in help package {}".format(file, current_help_package()) pkg_info = help_index_list().get(current_help_package()) if pkg_info is not None and file in pkg_info.help_files: name = pkg_info.help_files[file] if self.bmark_type == "view": name = name + " (view)" return name
def run(self, package=None, file=None, prompt=False): package = package or current_help_package(window=self.window) if package is None or prompt: return help_package_prompt(help_index_list(), on_select=lambda p: self.run(p, file)) if help_index_list().get(package, None) is None: return log("Cannot add help file; package '%s' unknown", package, dialog=True) if file is not None: return self.create_file(package, file) self.window.show_input_panel( "New Help File (%s)" % package, "", lambda file: self.create_file(package, file), None, None)
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)
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 })