Example: Notes editor
A minimal text editor — a Text widget with a scrollbar, a File menu, native
open/save dialogs, file I/O, dirty-tracking, and a confirm-on-close.
Run it:
scriptweaver internal/scriptweaver/testdata/notes.js
It shows how Menu, dialogs, and
sw.fs compose into a real app.
Editor + scrollbar
The Text widget and a scrollbar are gridded to fill the window and wired
together:
const text = app.Text({ wrap: 'word', undo: true });
const sb = app.TScrollbar({ orient: 'vertical' });
text.grid.configure({ row: 0, column: 0, sticky: 'nsew' });
sb.grid.configure({ row: 0, column: 1, sticky: 'ns' });
app.grid.rowConfigure(0, { weight: 1 });
app.grid.columnConfigure(0, { weight: 1 });
A File menu
Menu entries take a command callback; the menu is attached to the window with
app.menu:
const fileMenu = app.Menu({ tearOff: false });
fileMenu.addCommand({ label: 'Open…', command: openFile });
fileMenu.addCommand({ label: 'Save', command: save });
fileMenu.addSeparator();
fileMenu.addCommand({ label: 'Quit', command: quit });
const menubar = app.Menu({ tearOff: false });
menubar.addCascade({ label: 'File', menu: fileMenu });
app.menu = menubar;
Dialogs + files
Open and save flow through sw.dialog and sw.fs:
function openFile() {
const p = sw.dialog.openFile({ title: 'Open note' });
if (!p) return;
text.setText(sw.fs.readFile(p));
}
function save() {
sw.fs.writeFile(currentPath, text.getText());
}
A <KeyRelease> binding marks the document dirty (the title shows a *), and
app.wm.protocol('WM_DELETE_WINDOW', quit) confirms before closing.
Full source: internal/scriptweaver/testdata/notes.js.