RAD - Case Study Version 2

David Burgun dburgun at dsl.pipex.com
Sat Mar 25 11:12:30 EST 2006


Case Study - Version 2

At a later date, I was asked extend the Version 1 of the app so that  
two base folders could be selected (Call them FolderA and FolderB),  
two file lists (FileListA and FileListB) and two file Contents  
(FileContentsA and FileContentsB). The user could then select a file  
from list A and B and then compare the two files on a line by line  
basis high lighting lines that were different in a new group.

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).

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.


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





More information about the use-livecode mailing list