[ANN] Property List Table
Dennis Brown
see3d at writeme.com
Sat May 28 09:33:31 EDT 2005
Thanks Ken,
I will rewrite it once more using what I learned from your comments
(and Richard's) to clean it up (in my own developing style) since
others may look at it to learn from. One thing is that it is too
big. That is because I could not find a small file for the VC and AC
objects on my hard drive. If anyone has a dinky one or knows how to
make a dinky one (I never work with these) I will use it to make the
stack much smaller since it might be used as a reference and kept
around.
More comments below.
On May 28, 2005, at 12:45 AM, Ken Ray wrote:
> On 5/27/05 10:01 PM, "Dennis Brown" <see3d at writeme.com> wrote:
>
>
>> I doubt my scripts would be a model of superb Transcript. Perhaps
>> someone can take a look at it and suggest better ways of doing this
>> simple table task. It seemed very clunky to me for the way I figured
>> out how to click on the header rows for a sort --but it was quick and
>> dirty.
>>
>
> If you don't mind, I'd like to take a stab at it... here's your
> original
> script:
>
> on mouseup
> get me
> if the clickChunk is not empty then
> do "put "&the clickChunk&" into x"
> put "wd,cd,grp,btn,fld,sb,grc,img,player,EPS,vc,ac" into
> objList --wd
> repeat with i=number of items of objList+1 down to 0
> if x contains item i of objList then exit repeat
> end repeat
> set itemdel to tab
> sort it
> if i>0 then sort lines of it descending by item i+1 of each
> put it into me
> end if
> set the textcolor of line one of me to blue
> repeat with i=2 to the number of lines of me
> if i mod 2 = 0 then get darkred else get black
> set the textcolor of line i of me to it
> end repeat
> end mouseup
>
> Here's what I suggest as a more optimal way (watch the line wraps):
>
> on mouseUp
> put itemOffset(the
> clickText,"wd,cd,grp,btn,fld,sb,grc,img,player,EPS,vc,ac")+1 into
> tItemNum
> set itemDel to tab
> put me into tData
> sort tData
> if tItemNum > 1 then sort lines of tData descending by item
> tItemNum of
> each
> put tData into me
> set the textColor of line 1 of me to blue
> repeat with i = 2 to (the number of lines of me) step 2
> set the textColor of line i of me to darkred
> end repeat
> end mouseUp
>
> You can use is the clickText instead of the clickChunk so you can
> get the
> text that was clicked directly. By using 'itemOffset', you can
> directly get
> the comma-delimited item that matches the clickText, and add 1 to
> it. If the
> text isn't found, it will return 0; 0+1 = 1.
>
> Since you already have the location of the matching column in
> tItemNum, you
> can use it to do the sort.
Good Ideas. What I really would have expected of a table field is
that it would have returned the column and row that I clicked in, and
that I could get and put data based on column and row just as if it
were an array. I expect that Rev will develop this soon.
>
> Finally, the 'repeat' control structure allows you to skip every x
> number of
> lines in the data by using the 'step' option; here, I'm using 'step
> 2' to
> make sure that it only handles the even numbered lines. Since by
> default the
> text is black when it is put into the field, you only need to set
> the blue
> and red lines.
I was experimenting with colors other than black also.
>
> I also noticed that you use 'it' a lot (as a result of a 'get').
> Since 'it'
> is a temporary variable, it's lifespan before it gets changed is
> usually
> very small. So I would recommend using 'put' instead of 'get',
> depositing
> the result into a variable of your own naming (I used 'tData' and
> 'tItem'
> here).
Using "it" as much as possible is a goal of mine, as long as the
context is short. I might have stretched the point a bit here.
"get" stands out to identify the context of it. "it" is also my
favorite way to break up a complex statement to make it more readable
and understandable (like parens) without having to create useless
extra names to type and remember. I am still working on developing
my style with variable names.
> Your sorting routines work because you have an inserted space before
> "Property Name", and all the other columns are either X's or blanks
> other
> than the header. This is quite clever! However what might have been
> better
> would be to separate the header into another field that was placed
> atop the
> field with the data in the group. Clicking on the header would
> cause the
> *other* field to sort; the header would be left alone.
I thought of this, but I did not want the extra code to keep the two
fields sized and aligned (incl tab stops) if someone wanted to resize
them. As it is now, someone can take just the display field and
remove it from everything else and still have the all the sort
functionality. The creation button only needed to be executed once,
ever --by me (or again if Rev changes properties).
> Regardless of my attempt at optimizing your scripts, I must say
> that I am
> very encouraged at your rate of progress. Keep up the good work!
Thank you.
Dennis
More information about the use-livecode
mailing list