I've done version 2. It took me longer to figure out your scripts than to write my own. Total scripting time was actually about ten minutes, the rest was in trying to decipher yours so as to figure out what I needed to do.

Using ISM all I had to do was this:

1. Copy and Paste the existing groups in question - Group_SelectFolder, Group_SelectFile and Group_FileContents so there were now two of each.

2. Arrange the new groups nicely in the window.

3. Change any user visible text to read A and B as appropriate.

4. Change the custom properties "cpFolderKind" and "cpFileKind" so that the new groups now read FolderKindB and FileKindB.

That's all I needed to do to get the basic functionality of having 2 x Base Folders, 2 x FIle Lists and 2 x File Contents working. (I repeated this action just now in a test stack and it took less than 5 minutes).

I did exactly the same thing, but I didn't need to do step 4 because my method uses no custom properties. I option-dragged the existing group to create a duplicate. Took 2 seconds, and that is all that was required.


With this working, I needed to add a new Group to do the compare. The pseudo code for this (very close to the real code) is shown below marked as Version 2.


I only added a single button, not in any group, called "Compare". It has a one-liner script:

on mouseup
 compareFiles
end mouseup

After that, all I needed to do was alter the master stack script. I needed to add 1 line to the existing script, and add two new handlers and a constant. Here is what I did:

constant kCompareNumber

on setfolder tFolder -- this one is unchanged
  put the ID of the owner of the target into tGrp
  put tFolder into fld "basefolder" of grp ID tGrp
  put the directory into tOldDir
  set the directory to tFolder
  put the files into fld "folderContents" of grp ID tGrp
  put "" into fld "fileContents" of grp ID tGrp
  set the directory to tOldDir
end setfolder

on putFileContents tFile -- added 1 line at end
  put the ID of the owner of the target into tGrp
  put fld "basefolder" of grp ID tGrp & slash & tFile into tFilePath
  put url ("file:"&tFilePath) into fld "fileContents" of grp ID tGrp
  set the enabled of btn  "Compare" to (the number of items in \
       validFlds() = kCompareNumber)
end putFileContents

on compareFiles -- new handler
  put validFlds() into tFldList
  if the number of items in tFldList <> kCompareNumber
  then exit compareFiles
  repeat for each item i in tFldList
    set the hilitedlines of fld id i to calcCompare(tFldList)
  end repeat
end compareFiles

function validFlds -- new hander
  repeat with x = 1 to the number of grps
if there is a fld "fileContents" of grp x and fld "fileContents" of grp x <> ""
    then put the ID of fld "fileContents" of grp x & comma after tFldList
  end repeat
  delete last char of tFldList
  return tFldList
end validFlds

Because these handlers are all in the same script, changing it affects all existing groups and any new groups that are cloned from the existing. I have made the new handlers extensible so that you could compare 3 or 4 or any number of text fields simply by changing the number of items required, which is stored in the constant kCompareNumber.

You didn't show the actual handler that compares the files, but that's okay, presumably mine and yours would be fairly similar and do the same thing, so we don't have to consider that in our comparison.

I didn't have to change anything in the existing groups, and my scripts are (to my eyes, anyway) easier to follow and debug later. They are much shorter. They don't require any custom properties or special treatment.

Seems easier to me, but maybe I'm just too used to the xtalk paradigm. By comparison, your way looks complex, difficult to debug, and there are scripts in so very many places that following the messaging path in a debugging session seems harder than it really has to be. Again, maybe it's just my own perception.

It's been an interesting exercise for a Saturday afternoon, thanks for the opportunity. I'll bow out now.


Version 2 - Compare files
There are two versions of each of the groups shown in Version 1 already in the card/stack.

Please note that the setting of the CustomProperties "cpFolderKind" and "cpFileKind" are shown here as being initialized in the Script. In reality this is commented out and they are set by the developer in the Property Inspector.

Also note that this uses "me" as in "put empty into me", this causes problems when sending messages to multiple cards and in the real code it now reads "set the text of the long id of me to empty". I didn't bother to change it here as the former style is easier to read.
------------------------------------
 [Field_FileCompareResults]   (Button_FileCompare)

Group_FileCompare

Script for Group_FileCompare:

on ISM_InitializeObject
set the cpFolderKindA of me to "FolderKindA"
set the cpFolderKindB of me to "FolderKindB"

set the cpFileAValidFlag of me to false
set the cpFileBValidFlag of me to false
end ISM_InitializeObject


Script for Button_FileCompare:

on ISM_InitializeObject
disable me
get ISM_ListenForMessages("msg_FolderSelected",the cpFolderKindA of the long owner of me) get ISM_ListenForMessages("msg_FolderSelected",the cpFolderKindB of the long owner of me)

get ISM_ListenForMessages("msg_FileSelected",the cpFileKindA of the long owner of me) get ISM_ListenForMessages("msg_FileSelected",the cpFileKindB of the long owner of me)
end ISM_InitializeObject

on msg_FolderSelected theMessageID, theMessageKind, theFolderPathName
disable me
if theMessageKind = the cpFolderKindA of the long owner of me then
  set the cpFileAValidFlag of the long owner of me to false
else
  set the cpFileBValidFlag of the long owner of me to false
end if
end msg_FolderSelected

on msg_FileSelected theMessageID, theMessageKind, theFilePathName
if theMessageKind = the cpFileKindA of the long owner of me then
  set the cpFileAPathName of the long owner of me to theFilePathName
  set the cpFileAValidFlag of the long owner of me to true
else
  set the cpFileBPathName of the long owner of me to theFilePathName
  set the cpFileBValidFlag of the long owner of me to true
end if

if (the cpFileAValidFlag of the long owner of me = true) and (the cpFileBValidFlag of the long owner of me = true) then
  enable me
else
  disable me
end if
end msg_FileSelected

on mouseUp
get ISM_PutMessage("msg_FileCompare", "KindCompareLines", the cpFileAPathName of the long owner of me & "|" & the cpFileBPathName of the long owner of me)
end mouseUp

Script for Field_FileContents:

on ISM_InitializeObject
put empty into me
get ISM_ListenForMessages("msg_FileCompare","KindCompareLines")
end ISM_InitializeObject

on msg_FileCompare theMessageID, theMessageKind, theFilesToCompare
set the itemDelimiter to "|"
put CompareFiles(item 1 of theFilesToCompare,item 2 of theFilesToCompare) into myDifferentLinesList
set the hilitedlines of the text of me to myDifferentLinesList
end msg_FileCompare

on msg_FolderSelected theMessageID, theMessageKind, theFolderPathName
put empty into me
if theMessageKind = the cpFolderKindA of the long owner of me then
  set the cpFileAValidFlag of the long owner of me to false
else
  set the cpFileBValidFlag of the long owner of me to false
end if
end msg_FolderSelected

on msg_FileSelected theMessageID, theMessageKind, theFilePathName
put empty into me
end msg_FolderSelected


_______________________________________________
use-revolution mailing list
[email protected]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution





--
Jacqueline Landman Gay         |     [EMAIL PROTECTED]
HyperActive Software           |     http://www.hyperactivesw.com
_______________________________________________
use-revolution mailing list
[email protected]
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution

Reply via email to