•[C]a§§IoPe[A] [S]cRiP[t]•

on *:START: {
  if (!$Hget(AcroManager)) {
    .hmake AcroManager 100
    .hload -b AcroManager $Shortfn($Scriptdir) $+ Acronyms.hsh
  }
}
on *:LOAD: {
  echo -a Acronym Manager is loaded - Trigger: /acros
  if ($Version < 6) { echo -a Note: Your mIRC $Version might not work with this addon which is intended for mIRC 6.xx. }
}
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
  }
}

alias acros { /dialog -m acroedit acroedit }

dialog acroedit {
  title "•[C]a§§IoPe[A] [S]cRiP[t]• Crea Acronimo"
  size -1 -1 170 43
  option dbu
  edit "", 1, 3 13 40 10, autohs
  edit "", 2, 45 13 120 10, autohs
  button "OK", 3, 45 28 32 10
  button "Cancel", 4, 82 28 32 10
  text "Parola", 5, 5 4 27 8
  text "Acronimo", 6, 50 4 25 8
}
on *:DIALOG:acroedit:init: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 }
  Else { .dialog -v acronyms acronyms }
}
dialog acronyms {
  title "Acronimi •[C]a§§IoPe[A] [S]cRiP[t]•"
  size -1 -1 154 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 27 8
  text "Acro", 5, 52 5 21 8
  button "Aggiungi", 6, 91 14 32 10, disable
  check "Attiva Acronimi", 7, 2 84 56 7
  button "Modifica", 8, 59 83 32 10, disable
  button "Cancella", 9, 91 83 32 10, disable
}
on *:DIALOG:acronyms:init:0: {
  .dll $Shortfn($Scriptdir $+ mdx\mdx.dll) MarkDialog acronyms
  .dll $Shortfn($Scriptdir $+ 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
  }
  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
  }
  Else { .dialog -v acroedit }
}
on *:DIALOG:acronyms:sclick:9: {
  var %x $input(Sei sicuro di voler eliminare questo acronimo?,552,Elimina Acronimo ) | if %x = $yes {
    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
