Esempio n. 1
0
    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))
Esempio n. 2
0
    def create_file(self, package, file):
        if not file:
            return log("No help file given; skipping creation", status=True)

        pkg_info = help_index_list().get(package)
        local_path = local_help_filename(pkg_info, file)

        help_file = os.path.split(local_path)

        os.makedirs(help_file[0], exist_ok=True)

        view = self.window.new_file()
        view.settings().set("_hh_auth", True)
        view.settings().set("default_dir", help_file[0])
        view.set_name(help_file[1])
        apply_authoring_settings(view)

        template = format_template(
            """
            %%hyperhelp title="${1:Title}" date="${2:%s}"

            $0
            """,
            datetime.date.today().strftime("%Y-%m-%d"))

        view.run_command("insert_snippet", {"contents": template})
Esempio n. 3
0
    def run(self, edit, quiet=False):
        now = datetime.date.today().strftime("%Y-%m-%d")

        h_line = self.view.line(0)
        header = self.view.substr(h_line)

        msg = "Help file date header is already current"
        match = _header_date_re.match(header)
        if match and match.group(2) != now:
            header = match.expand(r'\g<1>%s\g<3>' % now)
            self.view.replace(edit, h_line, header)

            msg = "Help file date header updated to the most recent date"

        if not quiet:
            log(msg, status=True)
Esempio n. 4
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)
Esempio n. 5
0
    def run(self):
        target = find_lint_target(self.window.active_view())
        linters = get_linters(target)

        spp = sublime.packages_path()
        doc_root = target.pkg_info.doc_root

        for file in target.files:
            view = get_lint_file(os.path.join(spp, doc_root, file))
            if view is not None:
                for linter in linters:
                    linter.lint(view, file)

            else:
                log("Unable to lint '%s' in '%s'", file,
                    target.pkg_info.package)

        issues = list()
        for linter in linters:
            issues += linter.results()

        format_lint(target.pkg_info, issues, self.window)
Esempio n. 6
0
    def run(self, edit):
        filename = self.filename()
        if filename is None:
            return log("Cannot reload help index; not in package", status=True)

        filename = os.path.relpath(filename, sublime.packages_path())
        package = os.path.split(filename)[0].split(os.sep)[0]

        # If package is missing, force a complete rescan.
        if package not in help_index_list():
            package = None

        help_index_list(reload=True, package=package)
Esempio n. 7
0
    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)
Esempio n. 8
0
    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)
Esempio n. 9
0
def open_help_index(pkg_info, window=None):
    """
    Attempt to open the provided help index file localy for editing.
    """
    window = window if window is not None else sublime.active_window()

    # The index file is stored as a resource file spec, so strip the prefix
    local_path = os.path.join(sublime.packages_path(),
                              pkg_info.index_file[len("Packages/"):])

    if not os.path.exists(local_path):
        return log(format_template("""
            Specified help index does not exist; cannot open.

            Note: HyperHelpAuthor can not currently open help
            indexes from packed packages for editing.
            """),
                   dialog=True)

    window.open_file(local_path)
Esempio n. 10
0
def open_local_help(pkg_info, help_file, window=None):
    """
    Attempt to open the provided help file locally for editing.
    """
    window = window if window is not None else sublime.active_window()
    local_path = local_help_filename(pkg_info, help_file)

    if not os.path.exists(local_path):
        return log(format_template("""
            Specified help file does not exist; cannot open.

            Note: HyperHelpAuthor can not currently open help
            files from packed packages for editing.
            """),
                   dialog=True)

    view = window.open_file(local_path)
    view.settings().set("_hh_auth", True)
    if not view.is_loading():
        apply_authoring_settings(view)
Esempio n. 11
0
 def reload(self, help_view, help_file):
     if reload_help_file(help_index_list(), help_view):
         log("Reloaded help file '%s'", help_file, status=True)
Esempio n. 12
0
def _error_dialog(message, *args):
    """
    Simple local helper for displaying an error dialog using the log function.
    """
    log(format_template(message, *args), dialog=True)