How to know if an object has been edited/modified?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

sritcp
Posts: 431
Joined: Tue Jun 05, 2012 5:38 pm

How to know if an object has been edited/modified?

Post by sritcp » Fri Jul 25, 2014 6:30 pm

Is it possible to set a flag (set the cEdited of object "X" to false) and have it update when the object is modified in some way (the text, or backgroundColor, or anything at all) ?

My example below uses a DataGrid, but my question is general to any object.

I have a DataGrid on each card. When a card is closed, it use the data of the DataGrid to update a master data table. Many times, the user may go to a card to view information and not alter the data. It would be wasteful and inefficient to write the data out when nothing was modified. It would be helpful if, on openCard, we could set the cEdited of the DataGrid to false, and, on closeCard, the program could look at the custom property to see if the object has been modified, and update only when necessary.

Thanks,
Sri.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10333
Joined: Wed May 06, 2009 2:28 pm

Re: How to know if an object has been edited/modified?

Post by dunbarx » Fri Jul 25, 2014 7:38 pm

Check out this thread:

http://forums.livecode.com/viewtopic.ph ... sal#p20678

It should be touted more loudly. It ought to do what you need, if you write a handler high up in your stack hierarchy.

Craig newman

sritcp
Posts: 431
Joined: Tue Jun 05, 2012 5:38 pm

Re: How to know if an object has been edited/modified?

Post by sritcp » Fri Jul 25, 2014 9:04 pm

Hi Craig:

I went over the thread and I must admit that it was somewhat above my pay grade!

I understand frontscript and the concept of pre-handling a message, but it is not clear to me how to code the "modification" of an object. For instance, the user may click to open a DataGrid cell (or even a simple text field), and leave without entering/modifying the text. In such a case, openField and closeField messages would be sent to the field (not sure what messages in the case of DataGrid), but it doesn't say anything about whether the object was modified (in this case, if the text was edited).

Regards,
Sri.

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: How to know if an object has been edited/modified?

Post by jmburnod » Fri Jul 25, 2014 10:12 pm

Hi Sri,

Why not something like that pseudocode ?:
• at opencard
Build the list of the relevant properties for each object of the card
• at closecard
Compare this list with a new list of the relevant properties for each object of the card

Best regards
Jean-Marc
https://alternatic.ch

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Re: How to know if an object has been edited/modified?

Post by magice » Fri Jul 25, 2014 10:49 pm

You could modify the scripts of each object in question to include a line that changes the value of a custom property. So, on openCard you set the cNeedsToBeSaved of this stack to false. Now each modifiable field could have on keyDown set the cNeedsToBeSaved of this stack to true. Since I assume that the end user will be using a standalone and not the stack, any backgrounds and colors and sizes would have to be changed by script, so include that same custom property change in those scripts. Now on closeCard if the cNeedsToBeSaved of this stack is true then doYourThing.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10333
Joined: Wed May 06, 2009 2:28 pm

Re: How to know if an object has been edited/modified?

Post by dunbarx » Fri Jul 25, 2014 11:59 pm

hi,

That thread dealt with a generalized message, er message. In other words, script changes.

Are you familiar with the "properties" property? You can store the whole list in a custom property, and check it en masse at any subsequent time. In this way, you do not need to delineate any particular property or properties, you simply run the entire list and pull out those lines that have changed.

If you are interested only in certain properties, then do as Bernd or Magice suggested, and form a custom list. The idea is the same, but the complete list is more robust in that you never need to worry about adding or subtracting properties, since only the ones that have changed need be reported.

Note that the script of an object is a property of that object. This, too would appear in that list of changes.

Craig

sritcp
Posts: 431
Joined: Tue Jun 05, 2012 5:38 pm

Re: How to know if an object has been edited/modified?

Post by sritcp » Sat Jul 26, 2014 12:16 am

I agree and understand that by long-handed scripting we can check if each property of each object has changed.
I was wondering if there was a short-cut, in the form of an existing message or command.

I think it would be great if a generic "objectModified" message is sent to an object when any of its property is modified.
I am sure there is a ton of ways in which it could be put to use.
May be someone could put in a suggestion to RunRev.

Thanks,
Sri.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10333
Joined: Wed May 06, 2009 2:28 pm

Re: How to know if an object has been edited/modified?

Post by dunbarx » Sat Jul 26, 2014 12:19 am

It is a good idea, sort of along the lines of the "setProp"/"getProp" control structures. But these only work with custom properties, not mainstream ones.

Put it into the features request pane.

Craig

sritcp
Posts: 431
Joined: Tue Jun 05, 2012 5:38 pm

Re: How to know if an object has been edited/modified?

Post by sritcp » Sat Jul 26, 2014 2:32 pm

dunbarx wrote: Put it into the features request pane.
I did.

This is also relevant to autosaving a stack. I'd like to set it to save every 5 minutes (or 30 minutes), but only if the stack has been modified. I don't want an unmodified stack saved 12 times when I went away from the computer for an hour!

How do you handle this currently?

Regards,
Sri.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10333
Joined: Wed May 06, 2009 2:28 pm

Re: How to know if an object has been edited/modified?

Post by dunbarx » Sat Jul 26, 2014 2:52 pm

This goes right back to the original issue. Though in this case, you do not care what property has been modified, only that at least one has been. So create a routine somewhere that sends a message every five minutes. Test the "properties" property of your stack against the previous state of that property, stored in a custom property. If it is different, save the stack.

Craig

sritcp
Posts: 431
Joined: Tue Jun 05, 2012 5:38 pm

Re: How to know if an object has been edited/modified?

Post by sritcp » Sat Jul 26, 2014 5:16 pm

dunbarx wrote: Test the "properties" property of your stack against the previous state of that property, stored in a custom property. Craig
It is more involved than that. If any property of any object has changed, we'd need to save the stack. This would mean comparing before and after of each property of each object in the stack every 5 minutes - which is not practical.

If LiveCode were to send an "objectModified" message to an object every time a property is changed, we could trap the message at the stack level (in the message path) and flag that the stack needs to be saved.
I am sure such a message can be used in all sorts of ways to increase efficiency.

Thanks,
Sri.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: How to know if an object has been edited/modified?

Post by FourthWorld » Sat Jul 26, 2014 6:07 pm

Do you really want to save the stack, or the data the user had edited?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

sritcp
Posts: 431
Joined: Tue Jun 05, 2012 5:38 pm

Re: How to know if an object has been edited/modified?

Post by sritcp » Sat Jul 26, 2014 6:22 pm

Save the stack.
Take an example. While developing a program, I am the "user", and I'd like to autosave my work, say, every 5 minutes. (I've had LiveCode crash a few times, losing unsaved work).
Much of the time the program is open, even when I am not working on it.
I don't want it to save it every 5 min if I have done nothing to the stack.
I want it to save only when the content of the stack has changed.

Thanks,
Sri.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: How to know if an object has been edited/modified?

Post by FourthWorld » Sat Jul 26, 2014 7:21 pm

If you haven't done anything in several minutes or might be time to take a break. :)

There's an auto-same plugin available, possibly even included in the install.

Just how long does it take to save your stack file?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

sritcp
Posts: 431
Joined: Tue Jun 05, 2012 5:38 pm

Re: How to know if an object has been edited/modified?

Post by sritcp » Sun Jul 27, 2014 1:27 pm

FourthWorld wrote:If you haven't done anything in several minutes or might be time to take a break. :)
"I know hard work never killed anyone, but why take a chance?" Ronald Reagan
Just how long does it take to save your stack file?
Misses the point. May be my example wasn't a great one.

I couldn't believe there wasn't a simple, non-convoluted way to determine when an object has been modified.
It appears there isn't.

Regards,
Sri.

Post Reply