-- OSCmenu_Utilities
-----------------------------------
-- CREATED:
-- 14.12.2008
--
-- DESCRIPTION:
--              This Script defines the contents of the Utilities menu
--              the handler mShowOSCMenu builds a list with menu entries and corresponding handler calls
--              there are two lists:
--                     one hierarchical list with only the menu items text
--                     and one flat property list which acts as lookup list for each item
--              The lookup list "translates" the text of a menu entry to the corresponding function
--                     and "knows" in which scriptmember that function can be found
--                     so the syntax is:
--                           ["Menu title": ["function name with paramters", "name of the scriptmember to instantiate"]]
--
-- REQUIRES:
--               script "aleXtrasMovieScript" as provider for library scripts -> xscr()
--               script "commonMovieScript" to get the globallist -> mGetGlobalList
--
-- USAGE:
-- 
-----------------------------------

property pCallerSprite
property pCallBackParams

property pLookUpCommandList
-- in order to be able to use nicer command names, we use a lookup list for the real function names


on mShowOSCMenu me, callerSprite
  
  pCallerSprite = callerSprite
  
  isMac = (the last char of the moviepath = ":")
  
  li = []
  pLookUpCommandList = [:]
  
  
  ---------------------------------------------------
  li.add("Glossary")
  subli = []
  li.add(subli)
  
  subli.add("Insert current date")
  pLookUpCommandList.setaprop("Insert current date", ["pasteDate me", "alexUtilities"])
  
  subli.add("Insert divider")
  pLookUpCommandList.setaprop("Insert divider", ["pasteDivider me", "alexUtilities"])
  
  subli.add("Insert lingodoc script abstract")
  pLookUpCommandList.setaprop("Insert lingodoc script abstract", ["snipAbstract me", "alexUtilities"])
  
  subli.add("Insert lingodoc handler description")
  pLookUpCommandList.setaprop("Insert lingodoc handler description", ["snipTitle me", "alexUtilities"])
  
  li.add("")
  
  if isMac = 1 then
    ---------------------------------------------------
    li.add("BBEdit Handlers")
    subli = []
    li.add(subli)
    
    subli.add("Edit in BBEdit")
    pLookUpCommandList.setaprop("Edit in BBEdit", ["mEdit_text_with_BBedit me", "bbedit_Utilities"])
    
    subli.add("Open in BBEdit")
    pLookUpCommandList.setaprop("Open in BBEdit", ["mOpen_text_with_BBedit me", "bbedit_Utilities"])
    
    subli.add("Refresh members edited in BBEdit")
    pLookUpCommandList.setaprop("Refresh members edited in BBEdit", ["mReImport_text_Opened_In_BBedit me", "bbedit_Utilities"])
    
    subli.add("Open linked script in BBEdit")
    pLookUpCommandList.setaprop("Open linked script in BBEdit", ["mOpen_Linked_Script_With_BBedit me", "bbedit_Utilities"])
    
    subli.add("Diff selected script")
    pLookUpCommandList.setaprop("Diff selected script with bbdiff", ["mBBDiff_LiveCompare_SelectedScript me", "bbedit_Utilities"])
    
    subli.add("Batch compare selected scripts")
    pLookUpCommandList.setaprop("Batch compare selected scripts", ["mCompareSelectedScriptmembersBatch me", "bbedit_Utilities"])
    
  end if
  
  
  li.add("External script editor Handlers")
  subli = []
  li.add(subli)
  
  subli.add("Edit in external editor")
  pLookUpCommandList.setaprop("Edit in external editor", ["mEdit_text_in_ext_editor me", "bbedit_Utilities"])
  
  subli.add("Open in external editor")
  pLookUpCommandList.setaprop("Open in external editor", ["mOpen_text_with_ext_editor me", "bbedit_Utilities"])
  
  subli.add("Refresh members edited in external editor")
  pLookUpCommandList.setaprop("Refresh members edited in external editor", ["mReImport_text_Opened_In_ext_editor me", "bbedit_Utilities"])
  
  subli.add("Open linked script")
  pLookUpCommandList.setaprop("Open linked script", ["mOpen_Linked_Script_With_ext_editor me", "bbedit_Utilities"])
  
  subli.add("Diff selected scripts")
  pLookUpCommandList.setaprop("Diff selected scripts", ["mLiveCompare_SelectedScript me, convertLineBreaksToUnix", "bbedit_Utilities"])
  
  
  
  
  
  ---------------------------------------------------
  li.add("FileIO")
  subli = []
  li.add(subli)
  
  subli.add("Choose file...")
  pLookUpCommandList.setaprop("Choose file...", ["mGetFilePathFromUser me", "alexUtilities"])
  
  subli.add("Choose folder...")
  pLookUpCommandList.setaprop("Choose folder...", ["mGetFolderPathFromUser me", "alexUtilities"])
  
  subli.add("Read text from file...")
  pLookUpCommandList.setaprop("Read text from file...", ["mGetTextFromFile me, filepath_optional", "alexUtilities"])
  
  subli.add("Get file list from folder...")
  pLookUpCommandList.setaprop("Get file list from folder...", ["mGetFileList me, folderpath_optional", "alexUtilities"])
  
  subli.add("Get folder list from folder...")
  pLookUpCommandList.setaprop("Get folder list from folder...", ["mGetFolderList me, folderpath_optional", "alexUtilities"])
  
  
  ---------------------------------------------------
  li.add("XML")
  subli = []
  li.add(subli)
  
  subli.add("Read XML file...")
  pLookUpCommandList.setaprop("Read XML file...", ["mReadXML_2_List me", "alexUtilities"])
  
  subli.add("Export list to XML file...")
  pLookUpCommandList.setaprop("Export list to XML file...", ["mSaveList_2_XML me, theList", "alexUtilities"])
  
  
  li.add("")
  
  
  ---------------------------------------------------
  li.add("Linked Members")
  subli = []
  li.add(subli)
  
  subli.add("Unlink bitmap members")
  pLookUpCommandList.setaprop("Unlink bitmap members", ["mUnlinkBitmaps me", "alexUtilities"])
  
  subli.add("")
  subli.add("Link selected text...")
  pLookUpCommandList.setaprop("Link selected text...", ["mLinkSelectedText me", "alexUtilities"])
  
  subli.add("Update all linked texts")
  pLookUpCommandList.setaprop("Update all linked texts", ["mUpdateAllLinkedTexts me", "alexUtilities"])
  
  
  ---------------------------------------------------
  li.add("Export Members")
  subli = []
  li.add(subli)
  
  subli.add("Export selected text as...")
  pLookUpCommandList.setaprop("Export selected text as...", ["mExportSelectedText me, theType_optional", "alexUtilities"])
  
  subli.add("")
  subli.add("Export selected bitmaps...")
  pLookUpCommandList.setaprop("Export selected bitmaps...", ["mExportSelectedBMs me, theType_optional, compr_optional, thePath_optional", "alexUtilities"])
  
  subli.add("Export to bitmap...")
  pLookUpCommandList.setaprop("Export to bitmap...", ["mExportBM me, theMember, thePath_optional, theType_optional, compr_optional", "alexUtilities"])
  
  
  ---------------------------------------------------
  li.add("Export/Import Scriptmembers")
  subli = []
  li.add(subli)
  
  subli.add("Export script-, text-, fieldmember...")
  pLookUpCommandList.setaprop("Export script-, text-, fieldmember...", ["mExportScripttext me, skipIcons_optional, convertLineBreaksToUnix_optional, theFolder_optional", "alexUtilities"])
  
  subli.add("Import script...")
  pLookUpCommandList.setaprop("Import script...", ["mImportScriptWithThumbnail me, thePath_optional, castlibNumber_optional, dontWarn_optional, infolist_optional", "svn_Utilities"])
  
  
  
  li.add("")
  
  ---------------------------------------------------
  li.add("Process Castmembers by Name")
  subli = []
  li.add(subli)
  
  subli.add("Delete Members By Name...")
  pLookUpCommandList.setaprop("Delete Members By Name...", ["mDeleteMembersByName me, startString", "alexUtilities"])
  
  subli.add("")
  subli.add("Name Members...")
  pLookUpCommandList.setaprop("Name Members...", ["mNameMemberNames me, newName", "alexUtilities"])
  
  subli.add("Prefix/Suffix Names...")
  pLookUpCommandList.setaprop("Prefix/Suffix Names...", ["mChangeMemName me, praefix, suffix", "alexUtilities"])
  
  subli.add("Make numbered names...")
  pLookUpCommandList.setaprop("Make numbered names...", ["mNumberMemberNames me, numberOfDigits, startnum, theDelimiter, stepSize", "alexUtilities"])
  
  subli.add("Replace in name...")
  pLookUpCommandList.setaprop("Replace in name...", ["mReplaceInMemName me, searchstr, replacestring", "alexUtilities"])
  
  subli.add("")
  subli.add("Fill empty castslots with dummy members")
  pLookUpCommandList.setaprop("Fill empty castslots with dummy members", ["mFillDummyMember me", "alexUtilities"])
  
  subli.add("Erase dummy members")
  pLookUpCommandList.setaprop("Erase dummy members", ["mRemoveDummyMember me", "alexUtilities"])
  
  
  ---------------------------------------------------
  li.add("Convert Text into Image with Mask")
  subli = []
  li.add(subli)
  
  subli.add("Convert to bitmap")
  pLookUpCommandList.setaprop("Convert to bitmap", ["mConvertToBitmap me", "alexUtilities"])
  
  
  ---------------------------------------------------
  li.add("Find all Instances in Score")
  subli = []
  li.add(subli)
  
  subli.add("Find in GPDL...")
  pLookUpCommandList.setaprop("Find in GPDL...", ["mFindInGPDL me, str_optional", "alexUtilities"])
  
  subli.add("Select member in score...")
  pLookUpCommandList.setaprop("Select member in score...", ["mSelectInScore me, startframe_optional, endframe_optional", "alexUtilities"])
  
  
  li.add("")
  
  ---------------------------------------------------
  li.add("Script Statistics")
  subli = []
  li.add(subli)
  
  subli.add("Put script stats")
  pLookUpCommandList.setaprop("Put script stats", ["GetScriptlines me", "alexUtilities"])
  
  subli.add("Find all Puts")
  pLookUpCommandList.setaprop("Find all Puts", ["mListallPuts me", "alexUtilities"])
  
  
  ---------------------------------------------------
  li.add("Alex Help Miaw Handlers")
  subli = []
  li.add(subli)
  
  subli.add("Lingo help...")
  pLookUpCommandList.setaprop("Lingo help...", ["mGetHelp me, theText", "alexUtilities"])
  
  subli.add("Create help files from selected members")
  pLookUpCommandList.setaprop("Create help files from selected members", ["makeHelpEntries me", "alexUtilities"])
  
  subli.add("Create members for help files from selected script")
  pLookUpCommandList.setaprop("Create members for help files from selected script", ["makeHelpFilesFromScript me, memref_optional, onlyHandlerWithComments_optional", "alexUtilities"])
  
  
  
  if isMac = 1 then
    --------------------------------------------------- my linked script system:
    li.add("")
    li.add("Alex Linked Scripts System")
    subli = []
    li.add(subli)
    subli.add("Link selected alex-linked-library-scripts")
    pLookUpCommandList.setaprop("Link selected alex-linked-library-scripts", ["mLinkScripts me", "bbedit_Utilities"])
    
    subli.add("UnLink selected alex-linked-library-scripts")
    pLookUpCommandList.setaprop("UnLink selected alex-linked-library-scripts", ["mUnLinkScripts me", "bbedit_Utilities"])
    
    subli.add("UnLink all alex-linked-library-scripts")
    pLookUpCommandList.setaprop("UnLink all alex-linked-library-scripts", ["mUnLinkAllScripts me", "bbedit_Utilities"])
    
    subli.add("")
    subli.add("Open counterpart of selected alex-linked-library-script in BBEdit")
    pLookUpCommandList.setaprop("Open counterpart of selected alex-linked-library-script in BBEdit", ["mBBedit me", "bbedit_Utilities"])
    
    subli.add("Check changes in selected alex-linked-library-scripts")
    pLookUpCommandList.setaprop("Check changes in selected alex-linked-library-scripts", ["mCheckLSChange me", "bbedit_Utilities"])
    
    subli.add("")
    subli.add("Refresh selected alex-linked-library-scripts")
    pLookUpCommandList.setaprop("Refresh selected alex-linked-library-scripts", ["mRefreshScripts me", "bbedit_Utilities"])
    
    subli.add("")
    subli.add("Export a list of used alex-linked-library-scripts")
    pLookUpCommandList.setaprop("Export a list of used alex-linked-library-scripts", ["mExportListOfUsedLinkedScripts me", "bbedit_Utilities"])
    
  end if 
  
  
  li.add("")
  li.add("Compare to SVN")
  subli = []
  li.add(subli)
  subli.add("Compare selected scripts with Working Copy...")
  pLookUpCommandList.setaprop("Compare selected scripts with Working Copy...", ["mCompareCurrentScriptToWorkingCopy me, convertLineBreaksToUnix", "svn_Utilities"])
  
  subli.add("Export selected script to Working Copy and Open...")
  pLookUpCommandList.setaprop("Export selected script to Working Copy and Open...", ["mExportCurrentScriptToWorkingCopyAndOpen me, convertLineBreaksToUnix", "svn_Utilities"])
  
  
  
  li.add("")
  li.add("Subversion SVN")
  svn_subli = []
  li.add(svn_subli)
  
  ---------------------------------------------------- most used svn functions:
  svn_subli.add("SVN Quicklinks")
  subli = []
  svn_subli.add(subli)
  
  subli.add("SVN Update all castlibs")
  pLookUpCommandList.setaprop("SVN Update all castlibs", ["mSVN_Update_AllCastlib_and_source me, chooseNewPath_optional, onlyUpdate_SVN_WorkingFolder_optional, revisionNumber_optional", "svn_Utilities"])
  
  subli.add("SVN Update selected castlib(s)...")
  pLookUpCommandList.setaprop("SVN Update selected castlib(s)...", ["mSVN_Update_SelectedCastlib_and_source me, chooseNewPath_optional, onlyUpdate_SVN_WorkingFolder_optional, selectionList_optional, revisionNumber_optional", "svn_Utilities"])
  
  subli.add("")
  
  subli.add("SVN Commit selected castlib(s) (and scripttext)...")
  pLookUpCommandList.setaprop("SVN Commit selected castlib(s) (and scripttext)...", ["mSVN_Commit_SelectedCastlib_AND_Scripttext me, chooseNewPath_optional, commitMsg, selectionList_optional", "svn_Utilities"])
  
  
  
  ---------------------------------------------------- scripttext export functions:
  svn_subli.add("Scripttext ex/import for SVN")
  subli = []
  svn_subli.add(subli)
  subli.add("Export scripts to SVN working copy...")
  pLookUpCommandList.setaprop("Export scripts to SVN working copy...", ["mExportScriptsToFolder me, skipIcons_optional, selectionOnly_optional, convertLineBreaksToUnix, chooseNewPath_optional", "svn_Utilities"])
  
  subli.add("Import script from file...")
  pLookUpCommandList.setaprop("Import script from file...", ["mImportScriptWithThumbnail me, thePath_optional, castlibNumber_optional, dontWarn_optional, infolist_optional", "svn_Utilities"])
  
  subli.add("")
  subli.add("SVN Update ScriptText in Working Copy...")
  pLookUpCommandList.setaprop("SVN Update ScriptText in Working Copy...", ["mSVN_Update_Working_Copy_ScriptText me, revisionNumber_optional, chooseNewPath_optional, selectionOnly_optional", "svn_Utilities"])
  
  subli.add("")
  subli.add("SVN Import Scripts, Text and Fields from working copy...")
  pLookUpCommandList.setaprop("SVN Import Scripts, Text and Fields from working copy...", ["mSVN_Update_And_Import_ScriptsFromFolder me, chooseNewPath_optional, selectionOnly_optional", "svn_Utilities"])
  
  
  subli.add("")
  subli.add("SVN Commit ScriptText only...")
  pLookUpCommandList.setaprop("SVN Commit ScriptText only...", ["mSVN_Commit_CurrentScripts_ScriptText me, selected_Members_Only_optional", "svn_Utilities"])
  
  
  --  subli.add("")
  --  subli.add("SVN Delete Selected Scripts...")
  --  pLookUpCommandList.setaprop("SVN Delete Selected Scripts...", ["mSVN_Delete_Selected_Scripts me, chooseNewPath_optional", "svn_Utilities"])
  
  
  
  ---------------------------------------------------- svn functions:
  
  svn_subli.add("")
  svn_subli.add("Fields and text ex/import for SVN")
  subli = []
  svn_subli.add(subli)
  
  subli.add("Export text members to SVN working copy...")
  pLookUpCommandList.setaprop("Export text members to SVN working copy...", ["mExportTextAndFieldsToFolder me, skipIcons_optional, selectionOnly_optional, convertLineBreaksToUnix, chooseNewPath_optional", "svn_Utilities"])
  
  subli.add("Import text from SVN working copy...")
  pLookUpCommandList.setaprop("Import text from SVN working copy...", ["mImportTextAndFields me, thePath_optional, castlibNumber_optional, dontWarn_optional, infolist_optional", "svn_Utilities"])
  
  subli.add("")
  subli.add("SVN Import Scripts, Text and Fields from working copy...")
  pLookUpCommandList.setaprop("SVN Import Scripts, Text and Fields from working copy...", ["mSVN_Update_And_Import_ScriptsFromFolder me, chooseNewPath_optional, selectionOnly_optional", "svn_Utilities"])
  
  
  ----------------------------------------------------
  
  
  svn_subli.add("")
  svn_subli.add("SVN -- binary director files")
  subli = []
  svn_subli.add(subli)
  
  subli.add("SVN Update selected castlib...")
  pLookUpCommandList.setaprop("SVN Update selected castlib...", ["mSVN_Update_SelectedCastlib me, chooseNewPath_optional, onlyUpdate_SVN_WorkingFolder_optional, selectionList_optional, revisionNumber_optional", "svn_Utilities"])
  
  subli.add("SVN Update Current Movie...")
  pLookUpCommandList.setaprop("SVN Update Current Movie...", ["mSVN_Update_CurrentMovie_Binaries me, chooseNewPath_optional, onlyUpdate_SVN_WorkingFolder_optional, revisionNumber_optional", "svn_Utilities"])
  
  subli.add("")
  subli.add("SVN Commit selected castlib...")
  pLookUpCommandList.setaprop("SVN Commit selected castlib...", ["mSVN_Commit_SelectedCastlib me, chooseNewPath_optional, commitMsg", "svn_Utilities"])
  
  subli.add("SVN Commit current Movie...")
  pLookUpCommandList.setaprop("SVN Commit current Movie...", ["mSVN_Commit_CurrentMovie_Binaries me, chooseNewPath_optional, commitMsg", "svn_Utilities"])
  
  ----------------------------------------------------
  
  svn_subli.add("")
  svn_subli.add("SVN -- binary AND text")
  subli = []
  svn_subli.add(subli)
  
  subli.add("SVN Commit selected Castlib AND Scripttext...")
  pLookUpCommandList.setaprop("SVN Commit selected Castlib AND Scripttext...", ["mSVN_Commit_SelectedCastlib_AND_Scripttext me, chooseNewPath_optional, commitMsg, selectionList_optional", "svn_Utilities"])
  
  subli.add("SVN Commit current Movie AND Scripttext...")
  pLookUpCommandList.setaprop("SVN Commit current Movie AND Scripttext...", ["mSVN_Commit_CurrentMovie_Binaries_AND_Scripttext me, chooseNewPath_optional, commitMsg", "svn_Utilities"])
  
  ----------------------------------------------------
  
  
  li.add("")
  
  li.add("Misc.")
  subli = []
  li.add(subli)
  
  subli.add("Convert textmember to HTML + copy to clipboard")
  pLookUpCommandList.setaprop("Convert textmember to HTML + copy to clipboard", ["mCopyConvert2HTML", "alexUtilities"])
  
  
  ---------------------------------------------------
  subli.add("Fix colors in scriptlists (SES 10 -> SES 9)")
  pLookUpCommandList.setaprop("Fix colors in scriptlists (SES 10 -> SES 9)", ["Authoring_ExchangeScriptListColorsToRGBs me", "alexUtilities"])
  
  
  if isMac = 1 then
    ---------------------------------------------------
    li.add("Unix path")
    subli = []
    li.add(subli)
    
    subli.add("Convert path from HFS to UNIX")
    pLookUpCommandList.setaprop("Convert path from HFS to UNIX", ["mConvertHFS2Unix me, string_HFSPath", "alexUtilities"])
    subli.add("Convert path from UNIX to HFS")
    pLookUpCommandList.setaprop("Convert path from UNIX to HFS", ["mConvertUnix2HFS me, string_UnixPath", "alexUtilities"])
    
  end if
  
  li.add("")
  
  ---------------------------------------------------
  li.add("Castmember Thumbnails")
  subli = []
  li.add(subli)
  
  subli.add("Make castlib label...")
  pLookUpCommandList.setaprop("Make castlib label...", ["makeLabel me, theContent, theBackgroundColor_optional, memberRef_optional", "alexUtilities"])
  
  
  ---------------------------------------------------
  
  li.add("")
  if the platform contains "mac" then fnd = "Finder"
  else fnd = "Explorer"
  li.add("Open containing folder in" && fnd)
  pLookUpCommandList.setaprop("Open containing folder in" && fnd, ["mOpenContainingFolder me", "alexUtilities"])
  
  
  
  
  --------------------------------------------------
  ---------------------------------
  li.add("My own handlers")
  subli = []
  li.add(subli)
  
  menuString = "Do some custom stuff"
  handlerNameWithParameters = "Add_Your_Own_Handler_Here me"
  parentScriptName = "custom_Utilities"
  
  subli.add(menuString)
  pLookUpCommandList.setaprop(menuString, [handlerNameWithParameters, parentScriptName])
  
  -- USAGE NOTES:
  -- <menuString> is what appear visible in th menu
  -- <handlerNameWithParameters> is what is called in script <parentScriptName>
  -- provide the required or optional paramters to <handlerNameWithParameters>
  -- -- -- so the MUI dialog "knows" what to "ask" for
  ---------------------------------
  --------------------------------------------------
  
  
  
  
  r = (the activewindow).rect
  p = sprite(me.spritenum).rect.offset(r.left, r.top)
  
  
  if sprite(me.spritenum).member.type = #OSmenu then
    
    mConvertToOSC li
    
    sprite(me.spritenum).itemList = li
    sprite(me.spritenum).click()
    
  else
    
    theResult = bmMenuAt(li, 16, p[1], p[4])
    
    if count(theResult) > 0 then
      mOSCCallback me, 0, 0, theResult.getLast()
    end if
    
  end if
  
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx


on update me, theIndex, theName
  pCallBackParams = []
  pCallBackParams.add(theIndex)
  pCallBackParams.add(theName)
  xscr().mCreateTimeOut("osc_callback_to", 10, #mOSCCallback, me)
  -- break the event chain up, because when the event was generated in the xtra, we do not get error messages in lingo
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mOSCCallback me, dto, theIndex, theName
  
  if ilk(dto) = #timeout then dto.forget()
  
  if listP(pCallBackParams) then
    if count(pCallBackParams) > 0 then theIndex = pCallBackParams[1]
    if count(pCallBackParams) > 1 then theName = pCallBackParams[2]
  end if
  pCallBackParams = 0
  
  
  if length(theName) then
    
    -- some of the functions are "translated" and appear in a lookup list, in order to have nicer names
    cmdli = pLookUpCommandList.getaprop(theName)
    if not(listP(cmdli)) then
      cmdli = [theName, "alexUtilities"]
    else
      if count(cmdli) < 1 then exit
      if count(cmdli) < 2 then cmdli.add("alexUtilities")
      theName = string(cmdli[1])
    end if
    
    
    if theName = "mCopyConvert2HTML" then
      
      -- this handler must be hardcoded unfortunately
      -- as it requires a moviescript for the callback
      -- while it would be possible, I don't like to create
      -- a temp moviescript in the users movie and delete it when done
      -- instead of this exception...
      mCopyConvert2HTML
      
    else
      
      cmdStr = cmdli[1]
      targetScriptName = cmdli[2]
      
      cmd = cmdStr.word[1]
      delete word 1 of cmdStr
      
      glob = xscr().mGetGlobalList()
      
      olddelim = the itemdelimiter
      the itemdelimiter = ","
      delete item 1 of cmdStr
      the itemdelimiter = olddelim
      
      glob[#cmd] = cmd
      glob[#theParams] = [:]
      
      glob[#copy2ClipBoard] = 0
      
      targetScriptObject = new(script targetScriptName)
      targetScriptObject.setaprop(#pHandlerMenuWindowName, (the activewindow).name)
      glob[#theTargetInstance] = targetScriptObject
      
      if cmdStr.word.count then
        mShowMui cmdStr
      else
        mDoCmd
      end if
    end if
    
  end if
  
  if ilk(pCallerSprite) = #integer then
    sendSprite(pCallerSprite, #mUnhilite)
  end if
  
end

-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

on mouseUp me
  if ilk(pCallerSprite) = #integer then
    sendSprite(pCallerSprite, #mUnhilite)
  end if
end

