Strange Undo action for caching based on transient properties

  • Hi,

    Probably this question is rather NSUndoManager related and not
    specific to the CoreData, but anyway.. I think it's quite natural to
    face this problem while working with CoreData/transient properties
    used for caching.. Any hints are appreciated. So..

    I'm using caching for some calculated properties and store the cached
    values in transient properties. All works fine (including Undo) and
    I'm pretty happy.

    However, there's a problem:

    >>
    When "caching" takes place it's recorded in undo manager - that's OK.

    Unfortunately, if such a caching happens *without* other changes in
    the data (e.g. when user just inspects calculated property, which
    value has not been cached), as the result, a "strange" (from the user
    perspective) Undo action becomes available.

    The Undo action results in "emptying" the cache - that's
    understandable from the developer perspective - it's not a question
    why it's available and what it does.
    >>

    So, I'd like to get rid of that effect (strange undo action available
    for user), however I need to keep the "caching" recorded for Undo and
    therefore "undoable" (and etc.).

    I'm thinking of "joining" that "caching"-related undo record with a
    previous "undo record" (or even "next" one), but I'm a bit lost on how
    to accomplish that, or whether there's a better solution.

    Any thoughts?

    Many thanks in advance,
    Grigory
  • You can "join" it with the previous undo like so:

    NSManagedObjectContext *moc = [self managedObjectContext];
    [moc processPendingChanges];
    [[moc undoManager] disableUndoRegistration];

    Do the work here

    [moc processPendingChanges];
    [[moc undoManager] enableUndoRegistration];

    On 22 Nov 2007, at 03:40, Grigory Entin wrote:

    > Hi,
    >
    > Probably this question is rather NSUndoManager related and not
    > specific to the CoreData, but anyway.. I think it's quite natural to
    > face this problem while working with CoreData/transient properties
    > used for caching.. Any hints are appreciated. So..
    >
    > I'm using caching for some calculated properties and store the cached
    > values in transient properties. All works fine (including Undo) and
    > I'm pretty happy.
    >
    > However, there's a problem:
    >
    >>>
    > When "caching" takes place it's recorded in undo manager - that's OK.
    >
    > Unfortunately, if such a caching happens *without* other changes in
    > the data (e.g. when user just inspects calculated property, which
    > value has not been cached), as the result, a "strange" (from the user
    > perspective) Undo action becomes available.
    >
    > The Undo action results in "emptying" the cache - that's
    > understandable from the developer perspective - it's not a question
    > why it's available and what it does.
    >>>
    >
    > So, I'd like to get rid of that effect (strange undo action available
    > for user), however I need to keep the "caching" recorded for Undo and
    > therefore "undoable" (and etc.).
    >
    > I'm thinking of "joining" that "caching"-related undo record with a
    > previous "undo record" (or even "next" one), but I'm a bit lost on how
    > to accomplish that, or whether there's a better solution.
    >
    > Any thoughts?
    >
    > Many thanks in advance,
    > Grigory
  • Hello Mike,

    On Thu Nov 22 2007 at 14:01, Mike Abdullah <cocoadev...> wrote:

    > You can "join" it with the previous undo like so:
    >
    > NSManagedObjectContext *moc = [self managedObjectContext];
    > [moc processPendingChanges];
    > [[moc undoManager] disableUndoRegistration];
    >
    > Do the work here
    >
    > [moc processPendingChanges];
    > [[moc undoManager] enableUndoRegistration];

    Thanks a lot, Mike!!! It works!

    Though, frankly I don't understand why it results in the "join"..

    I do understand from the documentation that -processPendingChanges
    should record the pending changes in the undo manager, but I think it
    should be "nop" if undo registration is disabled. But as far as I see
    now, I'm wrong..

    Is it some magic? Is -processPendingChanges a "priveleged" method that
    results in the "join" if undo registration is disabled, due to some
    inner "contract" between moc and undo manager? Or is it just some
    aspect of undo manager that I don't understand? It just doesn't fit in
    my head..

    Regards,
    Grigory
previous month november 2007 next month
MTWTFSS
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    
Go to today