Peace & Protection 4.00 — File Browser

PeaceProtection4.00v4.0 / PeaceProtection4.00v4.0 / SCRIPT / GUI.MRC

GUI.MRC — 16.78 KB — Download this file

; #= P&P -rs
; ########################################
; Peace & Protection
; Dialog support code (for extra stuff not built-in
; to mIRC's dialogs)
; ########################################

;
; Drive search selection (returns space-delimited c:\ d:\ etc)
; Use $_drivesearch(1) to include removable media
;
alias _drivesearch set %.dsparm $1 | return $dialog(drivesearch,drivesearch,-4)
dialog drivesearch {
  title "Drive Search"
  size -1 -1 216 183
  text "Select one or more drives to search:", 1, 5 5 200 16
  list 2, 8 25 100 150, extsel sort
  button "Select", 3, 117 80 90 25, default ok
  edit "", 4, 1 1 1 1, hide autohs result
}
on *:DIALOG:drivesearch:init:*:{
  if (%.dsparm) var %types = fixed,cdrom,removable
  else var %types = fixed
  unset %.dsparm
  var %asc = 65
  :loop
  if ($istok(%types,$disk($chr(%asc)).type,44)) did -a $+ $iif(%asc == 67,c) $dname 2 $chr(%asc) $+ :\
  if (%asc < 90) { inc %asc | goto loop }
  if ($did(2).lines == 1) dialog -k $dname
}
on *:DIALOG:drivesearch:dclick:2:dialog -k $dname
on *:DIALOG:drivesearch:sclick:3:{
  var %ret,%num = 1
  :loop
  if ($did(2,$did(2,%num).sel)) {
    %ret = $addtok(%ret,$ifmatch,32)
    inc %num | goto loop
  }
  did -o $dname 4 1 %ret
}

;
; Color selector
;

; call /_cs-prep when dialog opens
; call /_cs-fin when dialog closes
; call /_cs-go xsize ysize allownone when a color is clicked on
; colors are stored in %_color.nn where nn is dialog id
; (color of 16 = none)
; max one dialog at a time with color selectors

;;; save code- make 15 15 always

alias _cs-prep return
alias _cs-fin window -c @Ç | unset %_color
alias _cs-go {
  window -c @Ç
  window -fphkd +fL @Ç $calc($mouse.dx - 5) $calc($mouse.dy - 5) $calc($1 * 4 + 8) $calc($2 * 4 + 8 + $iif($3,$calc($2 + 2),0)) @colpck
  drawrect -nfr @Ç $rgb(face) 1 0 0 200 200
  var %x,%y = 0,%col = 0
  :loopy | %x = 0 | :loopx
  drawrect -nf @Ç %col 1 $calc(%x * ($1 + 2) + 1) $calc(%y * ($2 + 2) + 1) $1 $2
  inc %col
  if (%x < 3) { inc %x | goto loopx }
  if (%y < 3) { inc %y | goto loopy }
  if ($3) drawtext -nr @Ç $rgb(text) "ms sans serif" 14 $int($calc(2 * $1 + 4 - $width(No color,ms sans serif,14,0,0) / 2)) $int($calc(4.5 * $2 + 10 - $height(No color,ms sans serif,14) / 2)) No color
  drawdot @Ç
  window -a @Ç
  titlebar @Ç $calc($1 + 2) $calc($2 + 2)
  %_color = $dname $did
}
menu @colpck {
  mouse:_mcp $leftwin $mouse.x $mouse.y $window($leftwin).title
  uclick:_mcc $leftwin $window($leftwin).title
  leave:_mcp $leftwin -1 -1 $window($leftwin).title
}
alias -l _mcc {
  if ($5 == 4) var %bit = 16
  else var %bit = $calc($4 + $5 * 4)
  %_color. [ $+ [ $gettok(%_color,2,32) ] ] = %bit
  window -c $1
  did -g %_color script\ $+ %bit $+ .bmp
}
alias -l _mcp {
  var %x = $int($calc($2 / $4)),%y = $int($calc($3 / $5))
  if (%y == 4) %x = 0
  if ($6 $7 != %x %y) {
    if ($6 != $null) {
      if ($7 == 4) drawrect -nr $1 $rgb(face) 2 $calc($6 * $4 - 1) $calc($7 * $5 - 1) $calc($4 * 4 + 2) $calc($5 + 2)
      else drawrect -nr $1 $rgb(face) 2 $calc($6 * $4 - 1) $calc($7 * $5 - 1) $calc($4 + 2) $calc($5 + 2)
    }
    if ($2 >= 0) {
      if (%y == 4) {
        drawline -nr $1 $rgb(hilight) 1 0 $calc(%y * $5 + $5 - 1) $calc($4 * 4 - 1) $calc(%y * $5 + $5 - 1) $calc($4 * 4 - 1) $calc(%y * $5 - 1)
        drawline -nr $1 $rgb(shadow) 1 0 $calc(%y * $5 + $5 - 1) 0 $calc(%y * $5) $calc($4 * 4 - 1) $calc(%y * $5)
      }
      else {
        drawline -nr $1 $rgb(hilight) 1 $calc(%x * $4) $calc(%y * $5 + $5 - 1) $calc(%x * $4 + $4 - 1) $calc(%y * $5 + $5 - 1) $calc(%x * $4 + $4 - 1) $calc(%y * $5 - 1)
        drawline -nr $1 $rgb(shadow) 1 $calc(%x * $4) $calc(%y * $5 + $5 - 1) $calc(%x * $4) $calc(%y * $5) $calc(%x * $4 + $4 - 1) $calc(%y * $5)
      }
      titlebar $1 $4-5 %x %y
    }
    else titlebar $1 $4-5
    drawdot $1
  }
}

;
; Font picker- $_pickfont
;;; not currently used
;

alias _pickfont {
  window -pfh +d @.pickfont 50 50 1 1 cancel 13
  window -a @.pickfont | font
  if ($window(@.pickfont).font == cancel) { window -c @.pickfont | return }
  var %font = $window(@.pickfont).font $iif($window(@.pickfont).fontbold,bold) $window(@.pickfont).fontsize
  window -c @.pickfont | return %font
}

;
; Generic entry
;
; $_entry(type,defaultvalue,question)
; default value is $_s2p and $null/%emptyvar works
; question can contain a  to be two lines
; type = 0 only accept data 1 blank is ok 2 return cancel as blank too
; type = -1 to require data and only return one word
; type = -2 to require data be a number
;
dialog entry {
  title "P&P Entry"
  size -1 -1 350 120

  text "", 202, 14 16 285 28
  text "", 203, 14 10 285 20, hide
  text "", 204, 14 25 285 20, hide

  edit %answer, 1, 10 45 330 22, result autohs

  icon 11, 302 6 32 32, script\pnp.ico

  button "OK", 101, 80 86 80 25, OK default
  button "Cancel", 102, 190 86 80 25, cancel
}
on *:DIALOG:entry:init:*:{
  if (%.entry.q2) {
    did -h $dname 202
    did -va $dname 203 & $+ $replace(%.entry.q,&,&&)
    did -va $dname 204 $replace(%.entry.q2,&,&&)
  }
  else did -a $dname 202 & $+ $replace(%.entry.q,&,&&)
  unset %.entry.q %.entry.q2
}
on *:DIALOG:entry:sclick:101:set -u1 %.entry.o 1
alias _entry {
  unset %.entry.o
  var %type = $1,%answer = $_p2s($2)
  set %.entry.q2 $gettok($3-,2,127)
  :retry
  set %.entry.q $gettok($3-,1,127)
  %answer = $dialog(entry,entry,-4)
  if ((%type <= 0) && (%answer == $null)) $$$
  if (%type < 0) %answer = $gettok(%answer,1,32)
  if ((%type == -2) && (%answer !isnum)) { set %.entry.q2 (please enter a number) | goto retry }
  if (%.entry.o) return %answer
  if (%type == 2) return
  $$$
}

;
; Entry based off of a 'recents' list
;
; $_rentry(type,code,defaultvalue,question)
; default value is $_s2p and $null/%emptyvar works (will then use top list of recents)
; question can contain a  to be two lines
; type = recents list name (don't include .lis extension) (as far as entry goes, something must be entered or all is canceled)
; code = 0 for normal .lis, #chan for &channel& replacement .lis
;
dialog rentry {
  title "P&P Entry"
  size -1 -1 350 120

  text "", 202, 14 16 285 28
  text "", 203, 14 10 285 20, hide
  text "", 204, 14 25 285 20, hide

  combo 1, 10 45 330 160, drop result edit

  icon 11, 302 6 32 32, script\pnp.ico

  edit %.entry.t, 100, 1 1 1 1, autohs hide

  button "OK", 101, 30 86 80 25, OK default
  button "Cancel", 102, 140 86 80 25, cancel
  button "Clear list", 103, 270 88 70 21, disable
}
; fills drop down with recents (bdid = clear button to enable if recents; chan = false if n/a)
; /_fillrec dname did bdid file chan [current]
alias _fillrec {
  if ($exists($4)) {
    if ($3) did -e $1 $3
    if ($_ischan($5)) {
      var %num = 1
      :loop1
      if ($read -ntl [ $+ [ %num ] ] $4 != $null) { if ($replace($ifmatch,&channel&,$5) != $6-) did -a $1 $2 $ifmatch | inc %num | goto loop1 }
    }
    else {
      if ($6- == $null) loadbuf -o $1 $2 $4
      else filter -fox $4 $1 $2 $6-
    }
  }
  if ($6 != $null) did -ic $1 $2 1 $6-
  else did -c $1 $2 1
}
on *:DIALOG:rentry:init:*:{
  _fillrec $dname 1 103 %.entry.t %.entry.c %.entry.a
  if (%.entry.q2) {
    did -h $dname 202
    did -va $dname 203 & $+ $replace(%.entry.q,&,&&)
    did -va $dname 204 $replace(%.entry.q2,&,&&)
  }
  else did -a $dname 202 & $+ $replace(%.entry.q,&,&&)
  unset %.entry.t %.entry.c %.entry.a %.entry.q %.entry.q2
}
on *:DIALOG:rentry:sclick:103:{
  did -b $dname 103
  .remove $did(100)
  :loop | if ($did(1,1) != $null) { did -d $dname 1 1 | goto loop }
}
alias _rentry {
  ; if we ever add .rct support, erasure button has to handle this proplerly
  set %.entry.t $_cfg($1.lis)
  set %.entry.c $2
  set %.entry.a $_p2s($3)
  set %.entry.q $gettok($4-,1,127)
  set %.entry.q2 $gettok($4-,2,127)
  return $$dialog(rentry,rentry,-4)
}

;
; Generic buttons
;

; $_yesno(x,prompt)
; x = 0 for no default 1 for yes default
; returns 1/0
alias _yesno {
  set %.yesno $1-
  return $$dialog(yesno,yesno,-4)
}
dialog yesno {
  title "P&P Entry"
  size -1 -1 400 68

  edit "", 202, 1 1 1 1, hide result autohs
  text "", 201, 14 9 280 28

  icon 11, 324 2 32 32, script\check1.ico
  icon 12, 356 2 32 32, script\check2.ico
  icon 13, 324 34 32 32, script\check3.ico
  icon 14, 356 34 32 32, script\check4.ico

  button "&Yes", 101, 13 40 80 25, OK
  button "&No", 102, 113 40 80 25
  button "Cancel", 103, 213 40 80 25, cancel
}
on *:DIALOG:yesno:init:*:{
  did -a $dname 201 $replace($gettok(%.yesno,2-,32),&,&&)
  if ($gettok(%.yesno,1,32)) did -ft $dname 101
  else did -ft $dname 102
  unset %.yesno
}
on *:DIALOG:yesno:sclick:101:if ($did(202) == $null) did -a $dname 202 1
on *:DIALOG:yesno:sclick:102:did -a $dname 202 0 | dialog -k $dname

; $_okcancel(x,prompt) or _okcancel x prompt
; x = 0 for cancel default 1 for ok default
; returns 1 or halts
alias _okcancel {
  set %.okcancel $1-
  return $$dialog(okcancel,okcancel,-4)
}
dialog okcancel {
  title "P&P Confirm"
  size -1 -1 400 68

  edit "1", 202, 1 1 1 1, hide result autohs
  text "", 201, 14 9 280 28

  icon 11, 324 2 32 32, script\check1.ico
  icon 12, 356 2 32 32, script\check2.ico
  icon 13, 324 34 32 32, script\check3.ico
  icon 14, 356 34 32 32, script\check4.ico

  button "OK", 101, 13 40 80 25, OK
  button "Cancel", 102, 113 40 80 25, cancel
}
on *:DIALOG:okcancel:init:*:{
  did -a $dname 201 $replace($gettok(%.okcancel,2-,32),&,&&)
  if ($gettok(%.okcancel,1,32)) did -ft $dname 101
  else did -ft $dname 102
  unset %.okcancel
}

; $_fileopt(x,file) or _fileopt x file
; x = 0 for normal 1 to allow append 2 to make append the default
; returns 1/0 (overwrite/append) halts on cancel
; if overwrite is selected, file is automatically cleared
alias _fileopt {
  set %.fileopt $1-
  return $$dialog(fileopt,fileopt,-4)
}
dialog fileopt {
  title "File Exists"
  size -1 -1 400 68

  edit "", 203, 1 1 1 1, hide autohs
  edit "", 202, 1 1 1 1, hide result autohs
  text "", 201, 14 9 280 28

  icon 11, 324 2 32 32, script\file1.ico
  icon 12, 356 2 32 32, script\file2.ico
  icon 13, 324 34 32 32, script\file3.ico
  icon 14, 356 34 32 32, script\file4.ico

  button "&Overwrite", 101, 13 40 80 25, OK
  button "&Append", 102, 113 40 80 25, disable
  button "Cancel", 103, 213 40 80 25, cancel
}
on *:DIALOG:fileopt:init:*:{
  did -a $dname 203 $gettok(%.fileopt,2-,32)
  did -a $dname 201 File ' $+ $replace($gettok(%.fileopt,2-,32),&,&&) $+ ' already exists:
  if ($gettok(%.fileopt,1,32)) {
    did -e $dname 102
    if ($ifmatch == 2) did -ft $dname 102
    else did -ft $dname 101
  }
  else did -ft $dname 101
  unset %.fileopt
}
on *:DIALOG:fileopt:sclick:101:if ($did(202) == $null) { did -a $dname 202 1 | .remove " $+ $did(203) $+ " }
on *:DIALOG:fileopt:sclick:102:did -a $dname 202 0 | dialog -k $dname

;
; Quick-pick popup
;
; _qp-go xsize cmd word1 2 3 etc
alias _qp-go {
  .timer.qpfin off
  window -c @¶
  window -fphkdo +fL @¶ $calc($mouse.dx - ($1 / 2)) $calc($mouse.dy - 1) $1 $calc($numtok($3-,32) * 20) @quikpck
  drawrect -nfr @¶ $rgb(face) 1 0 0 $1 200
  var %text,%y = 0 | :loopy
  %text = $_p2s($gettok($3-,$calc(%y + 1),32))
  if ($left(%text,1) isin 01) {
    %_plopup. [ $+ [ %y ] ] = $ifmatch
    drawrect -nr @¶ $rgb(hilight) 1 4 $calc(20 * %y + 4) 12 12
    drawline -nr @¶ $rgb(shadow) 1 4 $calc(20 * %y + 15) 4 $calc(20 * %y + 4) 15 $calc(20 * %y + 4)
    if ($left(%text,1) == 1) drawtext -nro @¶ $rgb(text) arial 21 5 $calc(20 * %y - 1) ×
    %text = $right(%text,-1)
  }
  drawtext -nr @¶ $rgb(text) "ms sans serif" 14 24 $calc(%y * 20 + 3) %text
  inc %y | if (%y < $numtok($3-,32)) goto loopy
  %_qpgo = $2
  %.skipit = 1
  .timer.sk@¶ -mo 1 0 unset % $+ .skipit
  drawdot @¶
  window -a @¶
  .timer.qp@¶ -mo 0 100 if (($active != @¶) || ($appactive == $!false)) _qp-fin @¶
}
alias _qp-fin {
  var %do = $_p2s(%_qpgo) $2
  unset %_qpgo
  window -c @¶ | .timer.qp@¶ off
  .timer.qpfin -mo 1 0 unset %_plopup.*
  %do
}
menu @quikpck {
  sclick:_qcp $leftwin $mouse.x $mouse.y $mouse.key $window($leftwin).dw $window($leftwin).title
  mouse:if (%.skipit) return | _qcp $leftwin $mouse.x $mouse.y $mouse.key $window($leftwin).dw $window($leftwin).title
  dclick:_qcp $leftwin $mouse.x $mouse.y $mouse.key $window($leftwin).dw $window($leftwin).title
  uclick:{
    if ($numtok($window($leftwin).title,32) < 1) return
    _qcp $leftwin $mouse.x $mouse.y $mouse.key $window($leftwin).dw $window($leftwin).title
    if (%_plopup. [ $+ [ $result ] ] isnum) {
      %_plopup. [ $+ [ $result ] ] = 1 - $ifmatch
      if ($ifmatch) drawrect -fr $leftwin $rgb(face) 1 5 $calc(20 * $result + 5) 10 10
      else drawtext -ro $leftwin $rgb(text) arial 21 5 $calc(20 * $result - 1) ×
    }
    else _qp-fin $leftwin $gettok($window($leftwin).title,1,32)
  }
  leave:_qcp $leftwin -20 -20 $mouse.key $window($leftwin).dw $window($leftwin).title
}
alias -l _qcp {
  var %y = $int($calc($3 / 20))
  if (($6 != %y) || ($4 != $7)) {
    if ($6 != $null) {
      if ($7 & 1) {
        if (%_plopup. [ $+ [ $6 ] ] isnum) {
          drawrect -nr $1 $rgb(hilight) 1 4 $calc(20 * $6 + 4) 12 12
          drawline -nr $1 $rgb(shadow) 1 4 $calc(20 * $6 + 15) 4 $calc(20 * $6 + 4) 15 $calc(20 * $6 + 4)
        }
        drawscroll -n $1 -1 -1 16 $calc(20 * $6 + 1) $calc($5 - 17) 18
      }
      drawrect -nr $1 $rgb(face) 1 0 $calc(20 * $6) $5 20
    }
    if ($2 >= 0) {
      if ($4 & 1) {
        if (%_plopup. [ $+ [ %y ] ] isnum) drawrect -nr $1 $rgb(face) 1 4 $calc(20 * %y + 4) 12 12
        drawscroll -n $1 1 1 16 $calc(20 * %y + 1) $calc($5 - 17) 18
      }
      drawrect -nr $1 $rgb($iif($4 & 1,hilight,shadow)) 1 0 $calc(20 * %y) $5 20
      drawline -nr $1 $rgb($iif($4 & 1,shadow,hilight)) 1 0 $calc(20 * %y + 19) 0 $calc(20 * %y) $calc($5 - 1) $calc(20 * %y)
      titlebar $1 %y $4
    }
    else titlebar $1
    drawdot $1
  }
  return %y
}
alias _doubleclick {
  var %plopup = $gettok(JoinFavs ListUsers PortScan Reconnect Usermode!Whois DCCChat Ping Clear!Ping ChanCentral Banlist EditTopic Clear!Whois Query DCCChat QuickKick QuickBan!Whois Query DCCChat Ping,$1,33)
  if ($_cfgi(dc. [ $+ [ $1 ] ] ) isnum) {
    if (($mouse.key & 2) || ($mouse.key & 4)) _qp-go 104 _doubleclick² $+ $1 $+ $2 $+ $3 %plopup 1Selectdefault
    else _doubleclick² $1 $2 $3 $_cfgi(dc. [ $+ [ $1 ] ] ) 1
  }
  else _qp-go 104 _doubleclick² $+ $1 $+ $2 $+ $3 %plopup 0Selectdefault
}
alias _doubleclick² {
  if ($4 == $null) return
  if (($1 == 2) || ($1 == 5)) var %bit = 4
  else var %bit = 5
  if (%_plopup. [ $+ [ %bit ] ] == 1) {
    var %plopup = $gettok(JoinFavs ListUsers PortScan Reconnect Usermode!Whois DCCChat Ping Clear!Ping Ch.Central Banlist Edit ClearTopic!Whois Query DCCChat QuickKick QuickBan!Whois Query DCCChat Ping,$1,33)
    _okcancel 1 Set the default $gettok(status query channel nicklist notify,$1,32) double-click action to ' $+ $_p2s($gettok(%plopup,$calc($4 + 1),32)) $+ '?
    _cfgw dc. $+ $1 $4
    return
  }
  if (%_plopup. [ $+ [ %bit ] ] == 0) _cfgw dc. $+ $1
  goto $1 $+ $4
  :20 | :40 | :50 | whois $3 | return
  :41 | :51 | query $3 | return
  :21 | :42 | :52 | dcc chat $3 | return
  :43 | kick $2 $3 | return
  :44 | cb $2 $3 | return
  :22 | :30 | :53 | if (=* iswm $2) dcp $3 | else ping $3 | return
  :31 | if ($5) channel | else { _getcc | set -u1 %.olde $editbox($3) | editbox -n $3 %.cmdchar $+ channel | .timer -o 1 0 editbox $3 % $+ .olde } | return
  :32 | ban $3 | return
  :33 | etopic $3 | return
  :23 | :34 | if (=* iswm $2) clear Chat $3 | else clear $3 | return
  :10 | fav j | return
  :11 | lusers | return
  :12 | ports | return
  :13 | server | return
  :14 | umode | return
}

; Convienience commands

; _bulkdid op dname first last [params]
; like a /did op dname first-last [params] ie on multiples
alias _bulkdid var %num = $3 | :loop | did $1-2 %num $5- | if (%num < $4) { inc %num | goto loop }

; Add to dropdown without duplication
; _ddadd dname did item
alias _ddadd {
  var %num = $did($1,$2).lines
  :loop
  if (%num) {
    if ($3- === $did($1,$2,%num)) return
    dec %num | goto loop
  }
  did -a $1-
}
; _ddaddm dname did addr mask1 mask2...
; (for multiple masks of same addr) uses usermask settings
alias _ddaddm {
  var %num = 4
  :loop
  if ($ [ $+ [ %num ] ] ) { _ddadd $1-2 $_ppmask($3,$_stmasku($ifmatch)) | inc %num | goto loop }
}

; finds a line in a dialog listbox where the first (space) token matches
; returns line number or 0; $_finddid(dname,did,text)
alias _finddid {
  var %num = $did($1,$2).lines
  :loop
  if ($gettok($did($1,$2,%num),1,32) == $3) return %num
  if (%num > 1) { dec %num | goto loop }
  return 0
}

; if dialog is already open, makes it active, else opens it
alias _dialog if ($dialog($2)) dialog -v $2 | else dialog $1-