;IRcap8 09b72b1bf039394cb3f3d9bc24d3f5b6

; ============================================== SWITCH

alias sba.SWITCH {
  sbatit $calc($1 - 12) $m(sbaswitch)
  if ($2 < 60) { unset %sba.ls1.switch | return }

  var %a = $int($calc(($2) / 14 - 1))
  %sba.ls1.switch = 6 $1 $calc($gettok(%sbarra,1,32) - 36) %a 1 0 switchclick @sba1.switch arbol

  guilista @sba sba.ls1.switch

  if ($3 != redib) || (!$line(@sba1.switch,0)) {
    window -hls @sba1.switch
    clear @sba1.switch
    unset %sba.switch2 | switchllena
  }
}

alias switchLLENA {
  clear @sba1.switch
  var %i = 1 | :L1 
  if ($scon(%i).cid) { var %cid = $nnet($scon(%i).server) | if (!%cid) { var %cid = Status } | var %a = 1 | if ($findtok(%sba.switch2,$scon(%i).cid,1,32) != $null) { inc %a }
  $larbol(@sba1.switch,$scon(%i).cid $+ g $+ %cid $+ -- $+ %a $+ ).ana | inc %i | goto L1 }
  var %cid = $cid

  var %ii = 1 | :L2cid | if ($scon(%ii).cid) {
    scid $scon(%ii).cid
    var %i = 1 | :L2 | var %n = $chan(%i) | if (%n) { if ($window(%n).sbcolor) { %n =  $+ %n $+  } | $larbol(@sba1.switch,$cid $+ i $+ %n $+ --8).ana | inc %i | goto L2 }
    var %i = 1 | :L3 | var %n = $query(%i) | if (%n) { if ($window(%n).sbcolor) { %n =  $+ %n $+  } | $larbol(@sba1.switch,$cid $+ i $+ %n $+ --4).ana | inc %i | goto L3 }
    inc %ii | goto L2cid
  }
  var %i = 1 | :L4 | var %n = $chat(%i) | if (%n) { if ($window(%n).sbcolor) { %n =  $+ %n $+  } | $larbol(@sba1.switch,$chat(%i).cid $+ i= $+ %n $+ --4).ana | inc %i | goto L4 }
  var %i = 1 | :L4s | var %n = $send(%i) | if (%n) { $larbol(@sba1.switch,$send(%i).cid $+ i-> $+ %n : $send(%i).file $+ Send %n $send(%i).file $+ -9).ana | inc %i | goto L4s }
  var %i = 1 | :L4g | var %n = $get(%i) | if (%n) { $larbol(@sba1.switch,$get(%i).cid $+ i<- $+ %n : $get(%i).file $+ Get %n $get(%i).file $+ -10).ana | inc %i | goto L4g }

  var %a = 1 | if ($findtok(%sba.switch2,R,1,32)) { inc %a } | $larbol(@sba1.switch,Rg $+ $m(254) $+ -- $+ %a $+ ).ana
  var %i = 1 | :L5 | var %n = $window(@*,%i) | if (%n) { if ($window(%n).icon != off) { $larbol(@sba1.switch,Ri $+ %n $+ --3).ana } | inc %i | goto L5 }

  guilista @sba sba.ls1.switch | drawline @sba | scid %cid
  %sba.switch = $window(*,0) | .timerSBA.switch -oi 0 1 switchCOMP
}

alias switchCLICK {
  if ($gettok($3-,2,8) == g) && ($1 == 2) {
    var %a = $gettok($3-,6,8) | inc %a | if %a > 2 { var %a = 1 } | $larbol(@sba1.switch,$puttok($3-,%a,6,8)).ana | if (%a == 2) { $larbol(@sba1.switch,$gettok($3-,1,8)).delg | %sba.switch2 = %sba.switch2 $gettok($3,1,8) }
    sline -r @sba1.switch
    if (%a == 1) { %sba.switch2 = $remtok(%sba.switch2,$gettok($3,1,8),1,32) | switchllena $gettok($3-,1,8) }
    guilista @sba sba.ls1.switch | guidib @sba
  }
  if ($gettok($3-,2,8) == i) && ($1 == 1) {
    if ($gettok($3-,4,8) != -) { var %w = " $+ $ifmatch $+ " }
    else { var %w = $replace($gettok($3-,3,8),Status,"Status Window") }
    if ($window(%w).state == minimized) || ($lactive != %w) { scid $gettok($3-,1,8) window -a $strip(%w) }
    else { scid $gettok($3-,1,8) window -a %w | .timer -m 1 100 scid $gettok($3-,1,8) window -n $strip(%w) }
  }
  if ($gettok($3-,2,8) == g) && ($1 == 1) {
    scid $gettok($3-,1,8) window -a "Status Window"
  }
}

alias switchCOMP {
  if (!%sba.ls1.switch) return
  if ($window(*,0) != %sba.switch) { switchLLENa }
  %sba.switch = $window(*,0)
}

on 1:text:*:#: if ($active != $chan) || ($cid != $activecid) { resalta $cid $chan }
on 1:text:*:?: if ($active != $nick) || ($cid != $activecid) { resalta $cid $nick }
on 1:chat:*: if ($active != $nick) || ($cid != $activecid) { resalta $cid =$nick }

alias -l Resalta {
  var %l = $fline(@sba1.switch,$1 $+ i $+ $2 $+ *,1)
  if (%l) {
    var %a = $line(@sba1.switch,%l)
    if ( !isin %a) {
      var %a = $puttok(%a, $+ $2 $+ ,3,8)
      rline @sba1.switch %l %a
      guilista @sba sba.ls1.switch | drawline @sba
    }
  }
}

on 1:active:*: {
  var %l = $fline(@sba1.switch,$cid $+ i $+ $active $+ *,1)
  if (%l) {
    var %a = $line(@sba1.switch,%l)
    if ( isin %a) {
      var %a = $puttok(%a,$active,3,8)
      rline @sba1.switch %l %a
      guilista @sba sba.ls1.switch | drawline @sba
    }
  }
}
;EOF