Hi,

I don't see what is to be gained using setProp's in this example? Surely:

function setEditMode pMode
  if pMode then
    enable button "Save"
    enable button "TextColor"
    set the lockText of fld "myfld" to true
    set the traversalOn of fld "myFld" to true
  else
    disable button "Save"
    disable button "TextColor"
    set the lockText of fld "myfld" to false
    set the traversalOn of fld "myFld" to false
  end if
end setEditMode

---------------

get setEditMode(true/false)

Would do the same job with less lines of code and be much easier to follow?

All the Best
Dave

There is a bit of truth in both.

The way I would code the above is
   setProp/getProp editMode -- [t/f]

in the main script
    set the editmode of me to true
    viewrefresh

then

--
on viewrefresh
 if the editmode of me is true then
    enable button "Save"
    enable button "TextColor"
    set the lockText of fld "myfld" to true
    set the traversalOn of fld "myFld" to true
  else
    disable button "Save"
    disable button "TextColor"
    set the lockText of fld "myfld" to false
    set the traversalOn of fld "myFld" to false
  end if
end viewrefresh
--

Custom properties are best used to hold model data.

Concrete example. This corresponds to a small widget to open and display the content of a file. On the interface,
I have
1) a button with the icon of a folder (answer file)
2) a textfield that displays the name of the file in a special format (if the name of the file is longer than 40 characters, then ellipses are added)
3) a textfield that displays the content of the file
4) a button with double arrows as icon (refresh the display)

Don't mind the use of vw["UIobject"]. I use it so that the view objects are defined out of the script. Similarly, the defaults[""] are used to store default values, so that the user can change the custom prop value and then change its mind and restore to a default one.

------------------------------------------------------------------------ --------------------------------------
/*
|   @dependencies:   file.getcontent()   [lib_files]
|   @dependencies:   path.convert2ellipsest()   [lib_files]
*/

####################################
#
#     Model
#
#
####################################
/* ________________________
|        Model Data
__________________________
|
|       file_name
|       file_content
|        extension_filter  -- not implemented
|       dialog_prompt
___________________________
*/


---  getters ------------------------

getProp file_name
  put the  file_name of me into tValue
if tValue is empty then put the defaults[" file_name"] of me into tValue
  return tValue
end file_name

getProp file_content
  put the file_name of me into tFileName
  return file.getcontent(tFileName)
end file_content

getProp extension_filter
  put the  extension_filter of me into tValue
if tValue is empty then put the defaults["extension_filter"] of me into tValue
  if tValue is empty then put "*" into tValue
  return tValue
end extension_filter

getProp dialog_prompt
  put the dialog_prompt of me into tValue
if tValue is empty then put the defaults["dialog_prompt"] of me into tValue
  if tValue is empty then put "Please Select a file" into tValue
  return tValue
end dialog_prompt

/* ________________________
|        Model Methods
__________________________
| (strictly speaking, affect the view, but let's not discuss this here))
|       file.getcontent
|       path.convert2ellipses
___________________________
*/

-- that include business is so that I can automatically -- update this part of the script from my main library

# @include file.getcontent of lib_files
function file.getcontent pFile
  return URL ("file://" & pFile)
end file.getcontent
#include@

# @include path.convert2ellipses of lib_files
function path.convert2ellipses pPath, pNbChars
  if pPath is empty then return empty
  if pNbChars >= length(pPath) then return pPath
  --- now we are in a situation where elipses (...) need to be added
  set the itemdel to "/"
  put item -1 of pPath into tName
  put item 1 to -2 ofpPath into tPath
  ----------------
  -- Number of characters to hide
  put (length(pPath) - pNbChars) into pNbCharsToHide
  ----------------
  -- locate the half of the string
  put length(tPath)  into tLength
  if tLength < pNbCharsToHide then put length(pPath) into tLength
  put round(tLength/2) into tHalfOfString
  if tHalfOfString mod 2 = 0 then add -1 to tHalfOfString
  ----------------
  put tHalfOfString - round(pNbCharsToHide/2) into tStartOfHide
  put tHalfOfString + round(pNbCharsToHide/2) into tEndOfHide
  -- answer tHalfOfString, pNbCharsToHide, tStartOfHide, tEndOfHide
  if pNbCharsToHide mod 2 = 1 then add 1 to tEndOfHide
  put "..." into char tStartOfHide to tEndOfHide of pPath
  return pPath
end path.convert2ellipses
#include@


####################################
#
#    Controller (behaviours being implemented)
#
#
####################################
/* ________________________
|        controller's behaviours
|__________________________

|       askforfile (mouseup on directory icon)
|       view.refresh (mouseup on refresh icon)
___________________________
*/

on mouseup
  if the behavior["mouseup"] of the target is empty then pass mouseup
  send (the behavior["mouseup"] of the target)
end mouseup

on askforfile
    answer file empty
    set the file_name of me to it
    view.refresh
end askforfile


####################################
#
#    View (ui elements being updated)
#
#
####################################

on view.refresh
  -- file content
  put the long ID of the vw["file_content"] of me into tContentObject
  put the file_content of me into tFileContent
  set the text of tContentObject to  tFileContent
  -- file name
  put the file_name of me into tFileName
  put the file_length of me into tNbChars
  put path.convert2ellipses(tFileName, tNbChars) into tFormatedName
  put the long ID of the vw["file_name"] of me into tFileNameObject
  set the text of tFileNameObject to tFormatedName
end view.refresh


------------------------------------------------------------------------ --------------------------------------
Marielle Lange (PhD),  Psycholinguist

Alternative emails: [EMAIL PROTECTED],

Homepage http://homepages.widged.com/mlange/ Easy access to lexical databases http:// lexicall.widged.com/ Supporting Education Technologists http:// revolution.widged.com/wiki/


_______________________________________________
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