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
| File | What it has | Uses Tk |
|---|---|---|
src/main.tcl | The start: the options, the settings, the load of each file | yes |
src/lib/webshim.tcl | The file path commands and encoding for the web build, which has neither | no |
web/index.html | The page of the web version: the loading screen, the file store, the folder button | - |
src/lib/fmt.tcl | The file format: text to chunks and back | no |
src/lib/block.tcl | The analysis of block content, and inline markup | no |
src/lib/date.tcl | Journal dates | no |
src/lib/edn.tcl | The EDN reader | no |
src/lib/graph.tcl | Files, pages, blocks, the index, the cache, transactions, save, search | no |
src/lib/outline.tcl | The edits of the block tree | no |
src/lib/query.tcl | Simple queries | no |
src/lib/datalog.tcl | Advanced queries | no |
src/lib/export.tcl | Export | no |
src/lib/sha256.tcl | SHA-256 for the activity log | no |
src/lib/plugin.tcl | Plugins: manifests, scope, grants, the API, the activity log | no |
src/lib/task.tcl | Agent tasks: the scope, the preview, and the text of a task | no |
src/ui/theme.tcl | Colors, the stylesheet, the tags of a view | yes |
src/ui/view.tcl | A view: rows and their rendered text | yes |
src/ui/edit.tcl | The editor: keys, pointer, selection, clipboard | yes |
src/ui/popup.tcl | The slash menu, the completion lists, templates | yes |
src/ui/app.tcl | The window, navigation, the search, the command list | yes |
src/ui/graphview.tcl | The graph view | yes |
src/ui/dialogs.tcl | The plugin panel, the activity report, the seen list | yes |
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.
| Array | Key | Value |
|---|---|---|
BC, BL, BK, BF | block id | content, level, kind (block, pre, head), file |
BS | block id | the source text. It is absent after an edit of the block |
BX | block id | the cached analysis |
FL, FM | file | the block ids in file order, the format data |
PN, PF, PJ | page key | the name, the file, the journal day |
IR, IU, IA, IM, IT | file | references, block ids, aliases, task markers, title |
RB | page key | the files that reference the page |
TX | file | the 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.