diff options
| author | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-09-17 10:56:19 +0200 |
|---|---|---|
| committer | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-09-17 10:56:19 +0200 |
| commit | 48d1781fed3f9ea5cfd2b270bd92fd2826605636 (patch) | |
| tree | 8abddf0ae7aaab97426cad1f65038560c8b85b9f /gui/internal/ui/window.go | |
| parent | a2cb20851499e9c00bd3bf642680a9ce3148cae8 (diff) | |
| download | krino-48d1781fed3f9ea5cfd2b270bd92fd2826605636.tar.gz krino-48d1781fed3f9ea5cfd2b270bd92fd2826605636.zip | |
gui: conditions as a nested tree, and a way to add a directory
Diffstat (limited to 'gui/internal/ui/window.go')
| -rw-r--r-- | gui/internal/ui/window.go | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/gui/internal/ui/window.go b/gui/internal/ui/window.go index 12e94a3..ce991d8 100644 --- a/gui/internal/ui/window.go +++ b/gui/internal/ui/window.go @@ -149,6 +149,68 @@ func (w *Window) confirmLeaving() { d.Show() } +// addDirectory asks for a name and a path and makes krino sort that +// directory too - the window had no way to do it (his report, 2026-09-17). +func (w *Window) addDirectory() { + d := gtk.NewWindow() + d.SetTitle("Add a directory") + d.SetTransientFor(&w.win.Window) + d.SetModal(true) + d.SetDefaultSize(520, 200) + + name := gtk.NewEntry() + name.SetPlaceholderText("papers") + name.SetTooltipText("the name krino knows it by: letters, digits, '.', '_' and '-'; its rules go in dirs/NAME.conf") + path := gtk.NewEntry() + path.SetPlaceholderText("~/papers") + path.SetHExpand(true) + path.SetTooltipText("the directory to sort") + + note := gtk.NewLabel("") + note.SetXAlign(0) + note.SetWrap(true) + + box := gtk.NewBox(gtk.OrientationVertical, 8) + box.SetMarginStart(12) + box.SetMarginEnd(12) + box.SetMarginTop(12) + box.SetMarginBottom(12) + box.Append(field("name", name)) + box.Append(field("path", path)) + box.Append(note) + + create := gtk.NewButtonWithLabel("Add") + create.AddCSSClass("suggested-action") + cancel := gtk.NewButtonWithLabel("Cancel") + cancel.ConnectClicked(func() { d.Close() }) + buttons := gtk.NewBox(gtk.OrientationHorizontal, 6) + buttons.SetHAlign(gtk.AlignEnd) + buttons.Append(cancel) + buttons.Append(create) + box.Append(buttons) + + create.ConnectClicked(func() { + file, err := model.AddDirectory(w.engine, strings.TrimSpace(name.Text()), strings.TrimSpace(path.Text())) + if err != nil { + note.SetText(escape(err.Error())) + note.AddCSSClass("error") + return + } + added := strings.TrimSpace(name.Text()) + if err := w.reloadEngine(); err != nil { + note.SetText(escape(err.Error())) + note.AddCSSClass("error") + return + } + w.plan.refreshDirs(w.plan.currentName()) + w.rules.refreshDirs(added) + w.setStatus("added %s; its rules are in %s", escape(added), escape(xdg.Abbrev(file))) + d.Close() + }) + d.SetChild(box) + d.Show() +} + // savePrefsSoon writes the preferences a moment after the last change, so // dragging a divider does not write the file on every pixel. func (w *Window) savePrefsSoon() { |
