I think you need to mark the node as dirty - p.setDirty() - and also
c.setChanged(). I'm not sure why the first doesn't also set the second,
but it doesn't.
You might also want to save undo data. Here's an example where I write
text into the body and make it undoable. The outline asks if I want to
save before closing.
p, u, = c.p, c.undoer
bunch = u.beforeChangeBody(p)
title = p.h
title += '\n' + '-'*(len(title) + 1)
time_string = ':created: ' + c.getTime(body=True) + '\n'
zettel_str = f'{title}\n\n:id: {p.gnx}\n{time_string}\n'
w = c.frame.body.wrapper
w.setInsertPoint(0)
p.b = zettel_str + p.b
u.afterChangeBody(p, 'zettel-convert-card', bunch)
For undoing a headline change, you could use u.beforeChangeHeadline() /
u.afterChangeHeadline() instead. I haven't tried this to change a headline
but I presume the node and outline would also show as changed.
On Friday, May 24, 2024 at 7:37:42 PM UTC-4 lewis wrote:
> I wrote a script to add a datestamp to the top node of a file. It modifies
> the headline and the headline icon changes to show it has changed.
> However when I close the leo file there is no prompt to save the file and
> the update is lost.
>
> I'm obviously missing some important detail and look forward to a helpful
> explanation of why the file is not recognised as changed.
> Here is the script:
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> *@language pythonfrom datetime import datetimenow =
> datetime.now()TIME_STAMP = (f"{now.day}/{now.month}/{now.year}
> {now.hour}:{now.minute}:{now.second}")def datestamp_node(): # POSITION
> c.selectPosition(c.rootPosition()) # select root node position and move
> to it # MOVES TO FIRST NODE p = c.p # NODE headline p.h
> = "datestamp Leo" + " " + TIME_STAMP # timestamp "datestamp Leo" node
> c.setHeadString(p, p.h) # write the new headline. g.es_print(f" ====
> new headline is: ", p.h) c.redraw(p) datestamp_node()*
>
>
--
You received this message because you are subscribed to the Google Groups
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/leo-editor/08221d9f-6dd7-4d00-8e19-8ddcb43a76adn%40googlegroups.com.