Script change of headline does not set file dirty flag

19 views
Skip to first unread message

SegundoBob

unread,
May 14, 2013, 3:43:59 PM5/14/13
to leo-editor
I have a Leo-Editor script that pops up a window to interact with the
user and when the user is happy with his changes, my script closes the
pop-up window and sets the headline of the currently selected node.
Note that the user may change one or more nodes in this way and move
around in the Leo-Editor file for quite some time before closing the
Leo-Editor file. Unfortunately, when a script changes a headline, Leo-
Editor does NOT set the file dirty flag. This is a serious problem
for my script because the user could easily lose changes he has made.

If you are interested in this problem, I give much more detail here:

https://bugs.launchpad.net/leo-editor/+bug/1174915


So far the best work around I have come up with is:

# Workaround bug: Leo doesn't notice headline change.
self._p.b = self._p.b + ' '
self._p.b = self._p.b[:-1]

That is, append a blank to the body of the changed node then drop the
appended blank. These two steps are required because simply setting
the body to itself unchanged does NOT set the file dirty flag.

Edward requested that discussion of this problem be continued on this
forum hoping that more people will state their views.

My view is that a user expects (and should expect) Leo-Editor to
notice that a headline has been changed. The file dirty flag should
be set. As it is in this case, Leo-Editor is a very quirky, scripting-
unfriendly application.

Terry Brown

unread,
May 14, 2013, 5:57:12 PM5/14/13
to leo-e...@googlegroups.com
On Tue, 14 May 2013 12:43:59 -0700 (PDT)
SegundoBob <bhos...@ieee.org> wrote:

> I have a Leo-Editor script that pops up a window to interact with the
> user and when the user is happy with his changes, my script closes the
> pop-up window and sets the headline of the currently selected node.
> Note that the user may change one or more nodes in this way and move
> around in the Leo-Editor file for quite some time before closing the
> Leo-Editor file. Unfortunately, when a script changes a headline, Leo-
> Editor does NOT set the file dirty flag. This is a serious problem
> for my script because the user could easily lose changes he has made.

If the issue is not becoming dirty for changes made to headlines *by
your script*, then I'd say this:

- the ' ' append trick shouldn't be needed, your script should
set the node and outline dirty explicitly with the relevant methods,
p.v.setDirty(), c.setChanged(True), etc. not sure exactly.

- there are use cases for scripts setting the dirty flags explicitly,
and use cases for scripts changing the outline without making it
dirty. You use case is the former, the latter is when you're
constructing views of data that don't need to be saved.

- at first glance your use case would seem more common and the views
use case less common, arguing for automatic dirtying in response to
scripted changes and the views use case needing to explicitly
undirty the outline

- *but* it's relatively simple to explicitly dirty the nodes /
outline, whereas explicitly undirtying them is tricky, because it
matters whether they were dirty or not before the script started
changing things, so I would argue that the status quo is cleanest
for the broadest range of cases. Scripts usually need to
explicitly call c.redraw() and other things too, so this
requirement isn't unique.

I'm guessing you hadn't seen the p.v.setDirty(), c.setChanged(True)
etc. methods?

Cheers -Terry

SegundoBob

unread,
May 14, 2013, 6:56:11 PM5/14/13
to leo-editor
On May 14, 2:57 pm, Terry Brown <terry_n_br...@yahoo.com> wrote:
> On Tue, 14 May 2013 12:43:59 -0700 (PDT)
>
>  - the ' ' append trick shouldn't be needed, your script should
>    set the node and outline dirty explicitly with the relevant methods,
>    p.v.setDirty(), c.setChanged(True), etc. not sure exactly.
>
> I'm guessing you hadn't seen the p.v.setDirty(), c.setChanged(True)
> etc. methods?

As noted in [1], I tried p.setDirty() and that alone did not help.

No, I had not found c.setChanged(True).

The following two schemes set the file changed flag:

p.h = "Changed"
p.v.setDirty()
c.setChanged(True)

or

p.h = "Changed"
p.setDirty()
c.setChanged(True)

That is, so far as I can tell, p.setDirty() and p.v.setDirty() are
equivalent.

Thanks.

I have no objections to being required to call setDirty() and
setChanged().

[1] https://bugs.launchpad.net/leo-editor/+bug/1174915

Edward K. Ream

unread,
May 15, 2013, 12:21:52 PM5/15/13
to leo-editor
On Tue, May 14, 2013 at 5:56 PM, SegundoBob <bhos...@ieee.org> wrote:

> That is, so far as I can tell, p.setDirty() and p.v.setDirty() are equivalent.

They are very different at the code level.  Here is p.setDirty::

    def setDirty (self,setDescendentsDirty=True):
   
        '''Mark a node and all ancestor @file nodes dirty.'''
   
        p = self ; dirtyVnodeList = []
   
        # g.trace('dirty: %s, setDescendentsDirty: %s' % (
            # p.v.isDirty(),setDescendentsDirty),p.h)
   
        if not p.v.isDirty():
            p.v.setDirty()
            dirtyVnodeList.append(p.v)
   
        # Important: this must be called even if p.v is already dirty.
        # Typing can change the @ignore state!
        dirtyVnodeList2 = p.setAllAncestorAtFileNodesDirty(setDescendentsDirty)
        dirtyVnodeList.extend(dirtyVnodeList2)
   
        return dirtyVnodeList

And here is v.setDirty::

    def setDirty (self):

        self.statusBits |= self.dirtyBit

When in doubt, read the code.

Edward

SegundoBob

unread,
May 15, 2013, 1:43:16 PM5/15/13
to leo-editor
On May 15, 9:21 am, "Edward K. Ream" <edream...@gmail.com> wrote:

> They are very different at the code level.

Which setDirty() should my headline changing script use?

My guess is that it should use p.setDirty().

Edward K. Ream

unread,
May 15, 2013, 7:30:17 PM5/15/13
to leo-editor
I agree.

Edward
Reply all
Reply to author
Forward
0 new messages