'=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
'From:     sim@ecoline.ru
'To:       gis-lab
'Date:     Friday, December 13, 2002
'Subject:  iahotlink with a list option (on shift)
'Comments: Works specially for adding Image Analysis themes
'Name:     IAHotlink
'Filename: IAHotlink
'Version:  1.2
'--====----====----====----====----====----====----====----====----====----===--

aView = av.GetActiveDoc
theVal = SELF
alist = {}

'p = point.make (2514715.189313, 2044723.445152)
if (System.IsShiftKeyDown) then
  theTheme = aView.GetThemes.Get(0)
  p = aView.GetDisplay.ReturnUserPoint
  for each t in aView.GetActiveThemes
    if ((t.HasAttributes) and (t.GetHotField <> nil)) then
      recs = t.FindByPoint(p)
        if (recs.count= 0 )then
          exit
        end
        for each rec in recs
          theField = t.gethotfield
          theVal = t.ReturnValueString(theField.GetName, rec)
          alist.add(theVal.asstring)
        end
      selBoxText = "Select themes to add to TOC," + NL + "Themes which already exist will be removed from TOC"
      selList = MsgBox.MultiListasstring (aList, selBoxText, "Select")
      if (selList = Nil) then
        exit
      end
      for each iName in selList
        if (File.Exists(iName.AsFileName)) then
          mySrcName = IASrc.MakeSrcName(iName)
          myIASrc = IASrc.Make(mySrcName)
          t = IATheme.MakeFromSrc(myIASrc)
          t.SetName(iName.AsFileName.GetBaseName)
          checkTheme = aView.FindTheme (iName.AsFileName.GetBaseName)
            if (checkTheme <> Nil) then
              aView.DeleteTheme(checkTheme)      
            else
              t.SetVisible(TRUE)
              v = av.GetActiveDoc
              v.AddTheme(t)
            end
        else
      MsgBox.Warning("File "+theVal+" not found.","Hot Link")
    end
    end
    end
  end
exit

else
  theVal = SELF
  if (Not (theVal.IsNull)) then
    if (File.Exists(theVal.AsFileName)) then
      mySrcName = IASrc.MakeSrcName(theVal)
      myIASrc = IASrc.Make(mySrcName)
      t = IATheme.MakeFromSrc(myIASrc)
      t.SetName(theVal.AsFileName.GetBaseName)
      checkTheme = aView.FindTheme (theVal.AsFileName.GetBaseName)
        if (checkTheme <> Nil) then
          aView.DeleteTheme(checkTheme)      
        else
          t.SetVisible(TRUE)
          v = av.GetActiveDoc
          v.AddTheme(t)
        end
    else
      MsgBox.Warning("File "+theVal+" not found.","Hot Link")
    end
  end 
end
