예제 #1
0
 public void SaveAs(string filePath, CancellationToken cancel)
 {
     NotebookItemsSaveRequest?.Invoke(this, EventArgs.Empty);
     using var status = WaitStatus.StartCustom(Path.GetFileName(filePath));
     Notebook.SaveAs(filePath,
                     c => status.SetProgress($"{c}% complete"),
                     cancel);
 }
예제 #2
0
    private static void InitHelpNotebook(Notebook notebook, string sqlnbFilePath)
    {
        var exeDir    = Path.GetDirectoryName(Application.ExecutablePath);
        var docDir    = Path.Combine(exeDir, "doc");
        var htmlFiles = (
            from htmlFilePath in Directory.GetFiles(docDir, "*.html", SearchOption.AllDirectories)
            let content = File.ReadAllText(htmlFilePath)
                          select(FilePath: htmlFilePath, Content: content)
            ).ToList();

        notebook.Execute("BEGIN");

        notebook.Execute(
            @"CREATE TABLE docs (
                id INTEGER PRIMARY KEY,
                path TEXT NOT NULL,
                book TEXT NOT NULL, 
                title TEXT NOT NULL,
                html TEXT NOT NULL
            )");
        notebook.Execute(
            @"CREATE TABLE books_txt (number INTEGER PRIMARY KEY, line TEXT NOT NULL)");
        notebook.Execute(
            @"CREATE TABLE art (file_path TEXT PRIMARY KEY, content BLOB)");
        notebook.Execute("CREATE VIRTUAL TABLE docs_fts USING fts5 (id, title, text)");

        using var status = WaitStatus.StartCustom("Documentation index");
        for (var i = 0; i < htmlFiles.Count; i++)
        {
            status.SetProgress($"{i * 100 / htmlFiles.Count}% complete");
            var(filePath, content) = htmlFiles[i];
            var filename = Path.GetFileName(filePath);
            if (filename == "doc.html" || filename == "index.html")
            {
                continue;
            }

            // Parse out the title.
            var title = "(no title)";
            {
                var startIndex = content.IndexOf("<title>");
                var endIndex   = content.IndexOf("</title>");
                if (startIndex >= 0 && endIndex > startIndex)
                {
                    title   = WebUtility.HtmlDecode(content[(startIndex + "<title>".Length)..endIndex]).Trim();