Outliner

Architecture

Outliner is Tcl code that runs on the ztk program. tools/build.sh puts the scripts in one program file with ztk bundle. The port plan maps each part to the module of Logseq that it follows.

The files

FileWhat it hasUses Tk
src/main.tclThe start: the options, the settings, the load of each fileyes
src/lib/webshim.tclThe file path commands and encoding for the web build, which has neitherno
web/index.htmlThe page of the web version: the loading screen, the file store, the folder button-
src/lib/fmt.tclThe file format: text to chunks and backno
src/lib/block.tclThe analysis of block content, and inline markupno
src/lib/date.tclJournal datesno
src/lib/edn.tclThe EDN readerno
src/lib/graph.tclFiles, pages, blocks, the index, the cache, transactions, save, searchno
src/lib/outline.tclThe edits of the block treeno
src/lib/query.tclSimple queriesno
src/lib/datalog.tclAdvanced queriesno
src/lib/export.tclExportno
src/lib/sha256.tclSHA-256 for the activity logno
src/lib/plugin.tclPlugins: manifests, scope, grants, the API, the activity logno
src/lib/task.tclAgent tasks: the scope, the preview, and the text of a taskno
src/ui/theme.tclColors, the stylesheet, the tags of a viewyes
src/ui/view.tclA view: rows and their rendered textyes
src/ui/edit.tclThe editor: keys, pointer, selection, clipboardyes
src/ui/popup.tclThe slash menu, the completion lists, templatesyes
src/ui/app.tclThe window, navigation, the search, the command listyes
src/ui/graphview.tclThe graph viewyes
src/ui/dialogs.tclThe plugin panel, the activity report, the seen listyes

The files of src/lib use no Tk command. The tests of tests/t-*.tcl load only them.

The layers

ui/app, ui/dialogs, ui/graphview
ui/edit, ui/popup
ui/view, ui/theme
lib/plugin, lib/query, lib/datalog, lib/export
lib/outline
lib/graph
lib/fmt, lib/block, lib/date, lib/edn, lib/sha256

A file uses the files of its layer and of the layers below.

The graph

ol::graph keeps its data in arrays. The letters are the names in the code.

ArrayKeyValue
BC, BL, BK, BFblock idcontent, level, kind (block, pre, head), file
BSblock idthe source text. It is absent after an edit of the block
BXblock idthe cached analysis
FL, FMfilethe block ids in file order, the format data
PN, PF, PJpage keythe name, the file, the journal day
IR, IU, IA, IM, ITfilereferences, block ids, aliases, task markers, title
RBpage keythe files that reference the page
TXfilethe text in lower case, for the search

An edit runs between ol::graph::begin and ol::graph::commit. The commit makes one undo step, makes the index of each changed file again, and calls the listeners. ol::graph::flush writes the changed files.

A view

ol::view::BuildRows gives the rows of a view as a list of {kind id depth extra}. Render makes the text of all rows and inserts it in one call. Each row has one text mark at its start, so RowAt finds the row of an index with a binary search over the marks. A row keeps its actions as {line first last action}, so a click needs no tag for each link.

ol::view::refresh runs after each commit. It builds the rows again. With the same list of rows it renders only the rows with new content.

The editor (ol::edit) replaces the rendered text of one row with the source text, between the marks es and ee. The text widget edits the text with its class bindings. The bind tag OlEdit comes before Text and handles the keys that change the tree. The bind tag OlPost comes after Text and keeps the caret between the marks.

Add a slash command or a command

ol::popup::add_command "My command" {apply {t {ol::edit::ins $t "text"}}}
ol::app::add_command "My window command" {ol::app::open {journals}}

Code of the app can use these. A plugin uses the plugin API.