on *:START: {
  if (!$Hget(AcroManager)) {
    .hmake AcroManager 100
    .hload -b AcroManager $Shortfn($Scriptdir) $+ Acronyms.hsh
  }
}
on *:UNLOAD: {
  if ($Hget(AcroManager)) {
    .hsave -bo AcroManager $Shortfn($Scriptdir) $+ Acronyms.hsh
    .hfree AcroManager
    .hfree TempText
    if ($Dialog(acronyms)) { .dialog -x acronyms }
    if ($Dialog(acroedit)) { .dialog -x acroedit }
  }
}
on *:EXIT: {
  if ($Hget(AcroManager)) {
    .hsave -bo AcroManager $Shortfn($Scriptdir) $+ Acronyms.hsh
  }
}
dialog acroedit {
  title "Acronimi di Aecan]G[elo Script "
  size -1 -1 90 43
  option dbu
  edit "", 1, 3 13 32 10, autohs
  edit "", 2, 37 13 50 10, autohs
  button "OK", 3, 10 28 32 10
  button "Cancel", 4, 47 28 32 10
  text "Parola", 5, 5 4 15 6
  text "Acronimo", 6, 50 4 22 6
}
on *:DIALOG:acroedit:init:0: {
  dll dlls/mdx/mdx.dll SetMircVersion $version
  dll dlls/mdx/mdx.dll MarkDialog $dname
  if (%unome == 1) {
    dll dlls/mdx/mdx.dll SetMircVersion $version
    dll dlls/mdx/mdx.dll MarkDialog $dname $dialog($dname).hwnd
    dll dlls/mdx/mdx.dll SetDialog $dname bgcolor $rgb(0,72,170)
    dll dlls/mdx/mdx.dll  SetColor $dname 3,4 background $rgb(0,72,170)
    dll dlls/mdx/mdx.dll  SetColor $dname 5,6 textbg $rgb(0,72,170)
    dll dlls/mdx/mdx.dll  SetColor $dname 1,2 textbg $rgb(0,0,0)
    dll dlls/mdx/mdx.dll  SetColor 1,2,5,6 text $rgb(255,255,255)
    dll dlls/mdx/mdx.dll  SetColor $dname 3,4 background $rgb(0,0,0)
    dll dlls/mdx/mdx.dll SetColor 1,2 background $dname bgcolor $rgb(0,0,0)
  }
  if (%unome == 2) {
    dll dlls/mdx/mdx.dll SetMircVersion $version
    dll dlls/mdx/mdx.dll MarkDialog $dname $dialog($dname).hwnd
    dll dlls/mdx/mdx.dll SetDialog $dname bgcolor $rgb(0,0,95)
    dll dlls/mdx/mdx.dll  SetColor $dname 3,4 background $rgb(0,0,95)
    dll dlls/mdx/mdx.dll  SetColor $dname 5,6 textbg $rgb(0,0,95)
    dll dlls/mdx/mdx.dll  SetColor $dname 1,2 textbg $rgb(0,0,0)
    dll dlls/mdx/mdx.dll  SetColor 1,2,5,6 text $rgb(255,255,255)
    dll dlls/mdx/mdx.dll  SetColor $dname 3,4 background $rgb(0,0,0)
    dll dlls/mdx/mdx.dll SetColor 1,2 background $dname bgcolor $rgb(0,0,0) 
  }
  if ($Did(acronyms, 3).sel) {
    .did -o acroedit 1 1 $Gettok(%amsfacro, 6, 32)
    .did -o acroedit 2 1 $Gettok(%amsfacro, 11-, 32)
  }
}
on *:DIALOG:acroedit:close:0: { .unset %amsfacro }
on *:DIALOG:acroedit:edit:1: {
  if (!$Did(acroedit, 1)) { .did -b acroedit 3 }
  Else { .did -e acroedit 3 }
}
on *:DIALOG:acroedit:edit:2: {
  if (!$Did(acroedit, 1)) { .did -b acroedit 3 }
  Else { .did -e acroedit 3 }
}
on *:DIALOG:acroedit:sclick:3: {
  if ($Did(acroedit, 1)) && ($Did(acroedit, 2)) {
    if ($Hget(AcroManager, $Gettok(%amsfacro, 6, 32))) && ($Numtok($Did(acroedit, 1), 32) == 1) {
      .hdel AcroManager $Gettok(%amsfacro, 6, 32)
      .hadd -m AcroManager $Did(acroedit, 1) $Did(acroedit, 2)
      if ($Dialog(Acronyms)) {
        .did -r acronyms 3
        .var %a = 1, %b = $Hget(AcroManager, 0).item
        While (%a <= %b) {
          if ($Hget(AcroManager, %a).item == $Did(acroedit, 1)) { .did -ac acronyms 3 1 $Hget(AcroManager, %a).item $Chr(9) $Hget(AcroManager, $Hget(AcroManager, %a).item) }
          Else { .did -a acronyms 3 1 $Hget(AcroManager, %a).item $Chr(9) $Hget(AcroManager, $Hget(AcroManager, %a).item) }
          .inc %a
        }
        .did -z acronyms 3
      }
      .unset %amsfacro
      .dialog -x acroedit
    }
    Elseif ($Numtok($Did(acroedit, 1), 32) > 1) { .echo -q $Input(Parola has to be 1 word!, o, Error!) }
    Else { .echo -q $Input(Edited Acronym doesn't exist!, o, Error!) }
  }
  Else { .echo -q $Input(Not enough information inputed!, o, Error!) }
}
on *:DIALOG:acroedit:sclick:4: {
  .unset %amsfacro
  .dialog -x acroedit
}
Alias acros {
  if (!$Dialog(acronyms)) { .dialog -m acronyms acronyms |  if ( %cc181p == on ) { $tunder TDDialog $dialog(acronyms).hwnd > 2 } }
  Else { .dialog -v acronyms acronyms }
}
dialog acronyms {
  title "Manager Acronimi di Arcan]G[elo Script"
  size -1 -1 126 100
  option dbu
  edit "", 1, 2 14 32 10, autohs
  edit "", 2, 37 14 50 10, autohs
  list 3, 2 29 122 51, sort size extsel
  text "Parola", 4, 5 5 15 6
  text "Acro", 5, 52 5 11 6
  button "Aggiungi", 6, 91 14 32 10, disable
  check "", 7, 2 84 6 6
  button "Modifica", 8, 59 83 32 10, disable
  button "Cancella", 9, 91 83 32 10, disable
}
on *:DIALOG:acronyms:init:0: {
  if (%unome == 1) {
    dll dlls/mdx/mdx.dll SetMircVersion $version
    dll dlls/mdx/mdx.dll MarkDialog $dname $dialog($dname).hwnd
    dll dlls/mdx/mdx.dll SetDialog $dname bgcolor $rgb(0,72,170)
    dll dlls/mdx/mdx.dll  SetColor $dname 3,4,5 background $rgb(0,72,170)
    dll dlls/mdx/mdx.dll  SetColor $dname 4,5,6 textbg $rgb(0,72,170)
    dll dlls/mdx/mdx.dll  SetColor $dname 1,2 textbg $rgb(0,0,0)
    dll dlls/mdx/mdx.dll  SetColor 1,2,3,4,5,7 text $rgb(255,255,255)
    dll dlls/mdx/mdx.dll  SetColor $dname 6,8,9 background $rgb(0,72,170)
    dll dlls/mdx/mdx.dll SetColor 1,2,3,4,5,7 background $dname bgcolor $rgb(0,0,0)
    dll dlls/mdx/mdx.dll SetControlMDX 3 listview rowselect showsel single sortascending labeltip report > $Shortfn($Scriptdir $+ mdx\views.mdx)
  }
  if (%unome == 2) {
    dll dlls/mdx/mdx.dll SetMircVersion $version
    dll dlls/mdx/mdx.dll MarkDialog $dname $dialog($dname).hwnd
    dll dlls/mdx/mdx.dll SetDialog $dname bgcolor $rgb(0,0,95)
    dll dlls/mdx/mdx.dll  SetColor $dname 3,4,5 background $rgb(0,0,95)
    dll dlls/mdx/mdx.dll  SetColor $dname 4,5,6 textbg $rgb(0,0,95)
    dll dlls/mdx/mdx.dll  SetColor $dname 1,2 textbg $rgb(0,0,0)
    dll dlls/mdx/mdx.dll  SetColor 1,2,3,4,5,7 text $rgb(255,255,255)
    dll dlls/mdx/mdx.dll  SetColor $dname 6,8,9 background $rgb(0,0,95)
    dll dlls/mdx/mdx.dll SetColor 1,2,3,4,5,7 background $dname bgcolor $rgb(0,0,0)
    dll dlls/mdx/mdx.dll SetControlMDX 3 listview rowselect showsel single sortascending labeltip report > $Shortfn($Scriptdir $+ mdx\views.mdx)
  }
  .did -i acronyms 3 1 headerdims 72:1 151:2
  .did -i acronyms 3 1 headertext Parola $Chr(9) Acronimo
  .var %a = 1, %b = $Hget(AcroManager, 0).item
  While (%a <= %b) {
    .did -az acronyms 3 $Hget(AcroManager, %a).item $Chr(9) $Hget(AcroManager, $Hget(AcroManager, %a).item)
    .inc %a
  }
  If ($Group(#AcroManager) == On) { .did -c acronyms 7 }
}
on *:DIALOG:acronyms:edit:1: {
  if ($Did(acronyms, 1)) && ($Did(acronyms, 2)) { .did -e acronyms 6 }
  Else { .did -b acronyms 6 }
}
on *:DIALOG:acronyms:edit:2: {
  if ($Did(acronyms, 1)) && ($Did(acronyms, 2)) { .did -e acronyms 6 }
  Else { .did -b acronyms 6 }
}
on *:DIALOG:acronyms:sclick:3: {
  .did -e acronyms 8
  .did -e acronyms 9
}
on *:DIALOG:acronyms:sclick:6: {
  if ($Did(acronyms, 1)) && ($Did(acronyms, 2)) {
    if (!$Hget(AcroManager, $Did(acronyms, 1))) && ($Numtok($Did(acronyms, 1), 32) == 1) {
      .hadd -m AcroManager $Did(acronyms, 1) $Did(acronyms, 2)
      .did -acz acronyms 3 $Did(acronyms, 1) $Chr(9) $Did(acronyms, 2)
      .did -r acronyms 1
      .did -r acronyms 2
      .did -e acronyms 8
      .did -e acronyms 9
      .did -z acronyms 3
    }
    Elseif ($Numtok($Did(acronyms, 1), 32) > 1) { .echo -q $Input(Short word has to be 1 word!, o, Error!) }
    Else { .echo -q $Input(Acronym already exists!, o, Error!) }
  }
  Else { .echo -q $Input(Not enough information inputed!, o, Error!) }
}
on *:DIALOG:acronyms:sclick:7: {
  if ($Group(#AcroManager) == Off) {
    .enable #AcroManager
    .did -c acronyms 7
    if (%sdre = on) { set %sdre == off }
  }
  Else {
    .disable #AcroManager
    .did -u acronyms 7
  }
}
on *:DIALOG:acronyms:sclick:8: {
  if (!$Dialog(acroedit)) {
    .set %amsfacro $Did(acronyms, 3, 1).seltext
    .dialog -m acroedit acroedit | if ( %cc181p == on ) { $tunder TDDialog $dialog(acroedit).hwnd > 10 } 
  }
  Else { .dialog -v acroedit }
}
on *:DIALOG:acronyms:sclick:9: {
  if ($Did(acronyms, 3).sel) {
    .var %a = $Did(acronyms, 3, 0).sel
    While (%a) {
      .hdel AcroManager $Gettok($Did(acronyms, 3, %a).seltext, 6, 32)
      .did -d acronyms 3 $Did(acronyms, 3, %a).sel
      .dec %a
    }
    .did -z acronyms 3
    .did -b acronyms 8
    .did -b acronyms 9
  }
}
#AcroManager on
on *:INPUT:*: {
  if ($Left($1,1) != /) && (!$Ctrlenter) && ($Active != Status Window) && ($Status == connected) {
    .var %a = $0
    If ($Hget(TempText)) { .hfree TempText }
    .hmake TempText 1
    While (%a) {
      if ($Hget(AcroManager, $Gettok($1-, %a, 32))) { .hadd TempText TempText $Hget(AcroManager, $Gettok($1-, %a, 32)) $Hget(TempText, TempText) }
      Else { .hadd TempText TempText $Gettok($1-, %a, 32) $Hget(TempText, TempText) }
      .dec %a
    }
    say $Hget(TempText, TempText)
    halt
  }
}
#AcroManager End
