On *:START: {
  If (!$HGet(FKey)) {
    .hmake FKey 4
    .hload -b FKey $Shortfn($ScriptDir) $+ FKey.hsh
  }
}
On *:EXIT: {
  If ($HGet(FKey)) { .hsave -bo FKey $Shortfn($Scriptdir) $+ FKey.hsh }
}
Alias F1 {
  If ($HGet(FKey, F1)) { $($HGet(FKey, F1), 2) }
}
Alias F2 {
  If ($HGet(FKey, F2)) { $($HGet(FKey, F2), 2) }
}
Alias F3 {
  If ($HGet(FKey, F3)) { $($HGet(FKey, F3), 2) }
}
Alias F4 {
  If ($HGet(FKey, F4)) { $($HGet(FKey, F4), 2) }
}
Alias F5 {
  If ($HGet(FKey, F5)) { $($HGet(FKey, F5), 2) }
}
Alias F6 {
  If ($HGet(FKey, F6)) { $($HGet(FKey, F6), 2) }
}
Alias F7 {
  If ($HGet(FKey, F7)) { $($HGet(FKey, F7), 2) }
}
Alias F8 {
  If ($HGet(FKey, F8)) { $($HGet(FKey, F8), 2) }
}
Alias F9 {
  If ($HGet(FKey, F9)) { $($HGet(FKey, F9), 2) }
}
Alias F10 {
  If ($HGet(FKey, F10)) { $($HGet(FKey, F10), 2) }
}
Alias F11 {
  If ($HGet(FKey, F11)) { $($HGet(FKey, F11), 2) }
}
Alias F12 {
  If ($HGet(FKey, F12)) { $($HGet(FKey, F12), 2) }
}
Alias cF1 {
  If ($HGet(FKey, cF1)) { $($HGet(FKey, cF1), 2) }
}
Alias cF2 {
  If ($HGet(FKey, cF2)) { $($HGet(FKey, cF2), 2) }
}
Alias cF3 {
  If ($HGet(FKey, cF3)) { $($HGet(FKey, cF3), 2) }
}
Alias cF4 {
  If ($HGet(FKey, cF4)) { $($HGet(FKey, cF4), 2) }
}
Alias cF5 {
  If ($HGet(FKey, cF5)) { $($HGet(FKey, cF5), 2) }
}
Alias cF6 {
  If ($HGet(FKey, cF6)) { $($HGet(FKey, cF6), 2) }
}
Alias cF7 {
  If ($HGet(FKey, cF7)) { $($HGet(FKey, cF7), 2) }
}
Alias cF8 {
  If ($HGet(FKey, cF8)) { $($HGet(FKey, cF8), 2) }
}
Alias cF9 {
  If ($HGet(FKey, cF9)) { $($HGet(FKey, cF9), 2) }
}
Alias cF10 {
  If ($HGet(FKey, cF10)) { $($HGet(FKey, cF10), 2) }
}
Alias cF11 {
  If ($HGet(FKey, cF11)) { $($HGet(FKey, cF11), 2) }
}
Alias cF12 {
  If ($HGet(FKey, cF12)) { $($HGet(FKey, cF12), 2) }
}
Alias sF1 {
  If ($HGet(FKey, sF1)) { $($HGet(FKey, sF1), 2) }
}
Alias sF2 {
  If ($HGet(FKey, sF2)) { $($HGet(FKey, sF2), 2) }
}
Alias sF3 {
  If ($HGet(FKey, sF3)) { $($HGet(FKey, sF3), 2) }
}
Alias sF4 {
  If ($HGet(FKey, sF4)) { $($HGet(FKey, sF4), 2) }
}
Alias sF5 {
  If ($HGet(FKey, sF5)) { $($HGet(FKey, sF5), 2) }
}
Alias sF6 {
  If ($HGet(FKey, sF6)) { $($HGet(FKey, sF6), 2) }
}
Alias sF7 {
  If ($HGet(FKey, sF7)) { $($HGet(FKey, sF7), 2) }
}
Alias sF8 {
  If ($HGet(FKey, sF8)) { $($HGet(FKey, sF8), 2) }
}
Alias sF9 {
  If ($HGet(FKey, sF9)) { $($HGet(FKey, sF9), 2) }
}
Alias sF10 {
  If ($HGet(FKey, sF10)) { $($HGet(FKey, sF10), 2) }
}
Alias sF11 {
  If ($HGet(FKey, sF11)) { $($HGet(FKey, sF11), 2) }
}
Alias sF12 {
  If ($HGet(FKey, sF12)) { $($HGet(FKey, sF12), 2) }
}
Alias FKey {
  If (!$Dialog(FKey)) { .dialog -m FKey FKey }
  Else { .dialog -v FKey }
}
dialog FKey {
  title "F-Tasten Manager"
  size -1 -1 132 108
  option dbu
  list 1, 1 11 130 55, size extsel
  button "Hoch", 2, 1 70 30 10, disable
  button "Runter", 3, 31 70 30 10, disable
  text "Hinweis: Trage die Befehle auf F-Tasten ein.", 8, 1 2 120 8, center
  button "Ändern", 4, 61 70 30 10, disable
  button "Löschen", 5, 91 70 30 10, disable
  button "OK", 6, 24 84 30 10, default ok
  button "Abbruch", 7, 69 84 30 10, cancel
}
on *:DIALOG:FKey:init:0: {
  .dll $Shortfn(" $+ $file($mircdir) $+ dll") $+ \MDX.dll MarkDialog FKey
  .dll $Shortfn(" $+ $file($mircdir) $+ dll") $+ \MDX.dll SetControlMDX 1 listview rowselect showsel nosortheader labeltip report > $Shortfn(" $+ $file($mircdir) $+ dll") $+ \views.mdx
  .did -i FKey 1 1 headerdims 78:1 142:2
  .did -i FKey 1 1 headertext F-Taste $Chr(9) Befehl(e)
  If (!$HGet(FKey)) {
    .hmake FKey 4
    var %a = 1
    While (%a <= 12) {
      .hadd FKey $+(F,%a) $iif(%a == 1, /help)
      .did -az FKey 1 $+(F,%a) $Chr(9) $iif(%a == 1, /fkey, <Nichts>)
      inc %a
    }
    var %a = 1
    While (%a <= 12) {
      .hadd FKey $+(CF,%a)
      .did -az FKey 1 $+(Control + F,%a) <Nichts>
      inc %a
    }
    var %a = 1
    While (%a <= 12) {
      .hadd FKey $+(SF,%a)
      .did -az FKey 1 $+(Shift + F,%a) <Nichts>
      inc %a
    }
  }
  Else {
    var %a = 1
    While (%a <= 12) {
      .did -az FKey 1 $+(F,%a) $Chr(9) $iif($HGet(FKey, $+(F,%a)), $HGet(FKey, $+(F,%a)), <Nichts>)
      inc %a
    }
    var %a = 1
    While (%a <= 12) {
      .did -az FKey 1 $+(Control + F,%a) $Chr(9) $iif($HGet(FKey, $+(CF,%a)), $HGet(FKey, $+(CF,%a)), <Nichts>)
      inc %a
    }
    var %a = 1
    While (%a <= 12) {
      .did -az FKey 1 $+(Shift + F,%a) $Chr(9) $iif($HGet(FKey, $+(SF,%a)), $HGet(FKey, $+(SF,%a)), <Nichts>)
      inc %a
    }
  }
}
On *:DIALOG:FKey:sclick:1: {
  If ($Did(FKey, 1).sel > 1) {
    If ($Did(FKey, 1, 0).sel == 1) { .did -e FKey 2,3,4,5 }
    Else {
      .did -b FKey 2,3,4
      .did -e FKey 5
    }
  }
  Else { .did -b FKey 2,3,4,5 }
}
On *:DIALOG:FKey:dclick:1: {
  If ($Did(FKey, 1).sel > 1) {
    var %a = $Did(FKey, 1).seltext, %b = $Did(FKey, 1).sel
    If ($Gettok(%a, 6-7, 32) == Control +) || ($Gettok(%a, 6-7, 32) == Shift +) {
      var %c = $Input(Set $Gettok(%a, 6-8, 32) Command,e,Set $Gettok(%a, 6-8, 32) Command,$Gettok(%a, 13-, 32))
      If (%c) { .did -o FKey 1 %b $Gettok(%a, 6-8, 32) $Chr(9) %c }
    }
    Else {
      var %c = $Input(Set $Gettok(%a, 6, 32) Command,e,Set $Gettok(%a, 6, 32) Command,$Gettok(%a, 11-, 32))
      If (%c) { .did -o FKey 1 %b $Gettok(%a, 6, 32) $Chr(9) %c }
    }
    .did -c FKey 1 %b
    .did -e FKey 2,3,4,5
  }
  Else { .did -b FKey 2,3,4,5 }
}
On *:DIALOG:FKey:sclick:2: {
  If ($Did(FKey, 1).sel == 2) {
    var %b = $Did(FKey, 1, 2)
    If ($Gettok(%b, 6-7, 32) == Control +) || ($Gettok(%b, 6-7, 32) == Shift +) { var %c = $Gettok(%b, 13-, 32), %e = 1 }
    Else { var %c = $Gettok(%b, 11-, 32), %e = 2 }
    var %a = $Did(FKey, 1).lines, %b = $Did(FKey, 1, %a)
    If ($Gettok(%b, 6-7, 32) == Control +) || ($Gettok(%b, 6-7, 32) == Shift +) { var %d = $Gettok(%b, 13-, 32), %f = 1 }
    Else { var %d = $Gettok(%b, 11-, 32), %f = 2 }
    .did -o FKey 1 2 $Gettok($Did(FKey, 1, 2), $iif(%e == 1, 6-8, 6), 32) $Chr(9) %d
    .did -o FKey 1 %a $Gettok(%b, $iif(%f == 1, 6-8, 6), 32) $Chr(9) %c
    .did -c FKey 1 %a
  }
  Elseif ($Did(FKey, 1).sel > 1) {
    var %a = $Did(FKey, 1).sel, %b = $Did(FKey, 1).seltext
    If ($Gettok(%b, 6-7, 32) == Control +) || ($Gettok(%b, 6-7, 32) == Shift +) { var %c = $Gettok(%b, 13-, 32), %e = 1 }
    Else { var %c = $Gettok(%b, 11-, 32), %e = 2 }
    dec %a
    var %b = $Did(FKey, 1, %a)
    If ($Gettok(%b, 6-7, 32) == Control +) || ($Gettok(%b, 6-7, 32) == Shift +) { var %d = $Gettok(%b, 13-, 32), %f = 1 }
    Else { var %d = $Gettok(%b, 11-, 32), %f = 2 }
    .did -o FKey 1 $Calc(%a + 1) $Gettok($Did(FKey, 1).seltext, $iif(%e == 1, 6-8, 6), 32) $Chr(9) %d
    .did -o FKey 1 %a $Gettok(%b, $iif(%f == 1, 6-8, 6), 32) $Chr(9) %c
    .did -c FKey 1 %a
  }
  Else { .did -b FKey 2,3,4,5 }
}
On *:DIALOG:FKey:sclick:3: {
  If ($Did(FKey, 1).sel == $Did(FKey, 1).lines) {
    var %a = $Did(FKey, 1).sel, %b = $Did(FKey, 1).seltext
    If ($Gettok(%b, 6-7, 32) == Control +) || ($Gettok(%b, 6-7, 32) == Shift +) { var %c = $Gettok(%b, 13-, 32), %e = 1 }
    Else { var %c = $Gettok(%b, 11-, 32), %e = 2 }
    var %b = $Did(FKey, 1, 2)
    If ($Gettok(%b, 6-7, 32) == Control +) || ($Gettok(%b, 6-7, 32) == Shift +) { var %d = $Gettok(%b, 13-, 32), %f = 1 }
    Else { var %d = $Gettok(%b, 11-, 32), %f = 2 }
    .did -o FKey 1 %a $Gettok($Did(FKey, 1).seltext, $iif(%e == 1, 6-8, 6), 32) $Chr(9) %d
    .did -o FKey 1 2 $Gettok(%b, $iif(%f == 1, 6-8, 6), 32) $Chr(9) %c
    .did -c FKey 1 2
  }
  Elseif ($Did(FKey, 1).sel > 1) {
    var %a = $Did(FKey, 1).sel, %b = $Did(FKey, 1).seltext
    If ($Gettok(%b, 6-7, 32) == Control +) || ($Gettok(%b, 6-7, 32) == Shift +) { var %c = $Gettok(%b, 13-, 32), %e = 1 }
    Else { var %c = $Gettok(%b, 11-, 32), %e = 2 }
    inc %a
    var %b = $Did(FKey, 1, %a)
    If ($Gettok(%b, 6-7, 32) == Control +) || ($Gettok(%b, 6-7, 32) == Shift +) { var %d = $Gettok(%b, 13-, 32), %f = 1 }
    Else { var %d = $Gettok(%b, 11-, 32), %f = 2 }
    .did -o FKey 1 $Calc(%a - 1) $Gettok($Did(FKey, 1).seltext, $iif(%e == 1, 6-8, 6), 32) $Chr(9) %d
    .did -o FKey 1 %a $Gettok(%b, $iif(%f == 1, 6-8, 6), 32) $Chr(9) %c
    .did -c FKey 1 %a
  }
  Else { .did -b FKey 2,3,4,5 }
}
On *:DIALOG:FKey:sclick:4: {
  If ($Did(FKey, 1).sel > 1) {
    var %a = $Did(FKey, 1).seltext, %b = $Did(FKey, 1).sel
    If ($Gettok(%a, 6-7, 32) == Control +) || ($Gettok(%a, 6-7, 32) == Shift +) {
      var %c = $Input(Ändere $Gettok(%a, 6-8, 32) Befehl,e,Ändere $Gettok(%a, 6-8, 32) Befehl,$Gettok(%a, 13-, 32))
      If (%c) { .did -o FKey 1 %b $Gettok(%a, 6-8, 32) $Chr(9) %c }
    }
    Else {
      var %c = $Input(Ändere $Gettok(%a, 6, 32) Befehl,e,Ändere $Gettok(%a, 6, 32) Befehl,$Gettok(%a, 11-, 32))
      If (%c) { .did -o FKey 1 %b $Gettok(%a, 6, 32) $Chr(9) %c }
    }
    .did -c FKey 1 %b
  }
  Else { .did -b FKey 2,3,4,5 }
}
On *:DIALOG:FKey:sclick:5: {
  If ($Did(FKey, 1).sel > 1) {
    var %a = $Did(FKey, 1, 0).sel, %b = $Did(FKey, 1, 1).sel
    While (%a) {
      If ($Gettok($Did(FKey, 1, $Did(FKey, 1, %a).sel), 6-7, 32) == Control +) || ($Gettok($Did(FKey, 1, $Did(FKey, 1, %a).sel), 6-7, 32) == Shift +) { .did -o FKey 1 $Did(FKey, 1, %a).sel $Gettok($Did(FKey, 1, $Did(FKey, 1, %a).sel), 6-8, 32) $Chr(9) <Nichts> }
      Else { .did -o FKey 1 $Did(FKey, 1, %a).sel $Gettok($Did(FKey, 1, $Did(FKey, 1, %a).sel), 6, 32) $Chr(9) <Nichts> }
      dec %a
    }
    .did -c FKey 1 %b
  }
  Else { .did -b FKey 2,3,4,5 }
}
On *:DIALOG:FKey:sclick:6: {
  If (!$HGet(FKey)) { .hmake FKey 4 }
  var %a = $Did(FKey, 1).lines
  While (%a >= 2) {
    tokenize 32 $Did(FKey, 1, %a)
    If ($6-7 == Control +) || ($6-7 == Shift +) { .hadd FKey $Replace($6-8, $+(Control +,$Chr(32)), C, $+(Shift +,$Chr(32)), S) $iif($13- != <Nichts>, $13-) }
    Else { .hadd FKey $6 $iif($11- != <Nichts>, $11-) }
    dec %a
  }
}
