; Minimal dialog example
;
; Listbox ID = 21
; Nick editbox ID = 23
; Add button ID = 25
; Delete buton ID = 26
; Color combo ID = 28
;
dialog cnl {
option dbu
title "Colorful nicks"
size -1 -1 115 67
list 21, 5 5 50 50, sort
edit "", 23, 60 5 50 10
combo 28, 60 20 50 80, drop
button "Add", 25, 25 50 30 13
button "Delete", 26, 60 50 30 13
}
alias cnl dialog -m cnl cnl | ; [ Start up the dialog interface ]
on *:DIALOG:cnl:init:0:{ | ; [ Initialize the dialog ]
| ;
did -a $dname 28 00 - White | ; Add all the colors
did -a $dname 28 01 - Black | ;
did -a $dname 28 02 - DkBlue | ;
did -a $dname 28 03 - DkGreen | ;
did -a $dname 28 04 - Red | ;
did -a $dname 28 05 - Brown | ;
did -a $dname 28 06 - DkPurple | ;
did -a $dname 28 07 - Orange | ;
did -a $dname 28 08 - Yellow | ;
did -a $dname 28 09 - LtGreen | ;
did -a $dname 28 10 - Teal | ;
did -a $dname 28 11 - Aqua | ;
did -a $dname 28 12 - LtBlue | ;
did -a $dname 28 13 - LtPurple | ;
did -a $dname 28 14 - DkGrey | ;
did -a $dname 28 15 - LtGrey | ;
| ;
did -c $dname 28 2 | ; Select Black
did -b $dname 25,26 | ; Disable both buttons
| ;
if $lines(nicks.ini) == 0 return | ; If there are no nicks on file, stop
| ;
var %i = 1 | ; Loop index
while $ini(nicks.ini, colors, %i) != $null { | ; While there are more nicks
did -a $dname 21 $ifmatch $readini(nicks.ini, colors, $ifmatch) | ; Add each nick and color value
inc %i | ; Get next nick
} | ;
}
on *:DIALOG:cnl:sclick:25:{ | ; [ Adding or Overwriting ]
| ;
var %nick = $did(23) | ; Nick
var %color = $calc($did(28) - 1) | ; Color
| ;
writeini nicks.ini colors %nick %color | ; Save it disk
set $+(%,cnlcolor.,%nick) %color | ; Save it to variables
set %specialnicks $addtok(%specialnicks, %nick, 32) | ;
| ;
if $did(21, 0).sel == 0 did -a $dname 21 %nick %color | ; If it's new, add it
else did -o $dname 21 $did(21, 1).sel %nick %color | ; Otherwise, overwrite it
| ;
did -r $dname 23 | ; Clear the nick editbox
did -b $dname 25,26 | ; Disable the buttons
}
on *:DIALOG:cnl:sclick:26:{ | ; [ Deleting an entry ]
| ;
if $did(21, 0).sel == 0 return | ; If nothing is selected, stop
| ;
var %nick = $gettok($did(21).seltext, 1, 32) | ; Get the nick to remove
| ;
unset $+(%,cnlcolor.,%nick) | ; Unset the variables
set %specialnicks $remtok(%specialnicks, %nick, 1, 32) | ;
| ;
remini nicks.ini colors %nick | ; Remove from disk
| ;
did -d $dname 21 $did(21).sel | ; Delete the listbox line
did -r $dname 23 | ; Clear the nick editbox
did -b $dname 25,26 | ; Disable the buttons
}
on *:DIALOG:cnl:edit:23: Enable.Add-Overwrite | ; [ Check for status changes on nick edit ]
on *:DIALOG:cnl:sclick:28: Enable.Add-Overwrite | ; [ Or color change ]
on *:DIALOG:cnl:sclick:21:{ | ; [ Selecting a listbox line ]
| ;
did -ra $dname 23 $gettok($did(21, 1).seltext, 1, 32) | ; Insert old nick into nick editbox
did -c $dname 28 $calc($gettok($did(21, 1).seltext, 2, 32) + 1) | ; Select old color
| ;
Enable.Add-Overwrite | ; Check for status changes
}
alias -l Enable.Add-Overwrite { | ; [ Status Changes ]
| ;
var %newnick = $did(23) | ; Nick from editbox
var %newcolor = $calc($did(28).sel - 1) | ; Color from combo
| ;
if $didwm(21, %newnick *) > 0 { | ; If we're back to using the same nick
did -c $dname 21 $ifmatch | ; select it in the listbox
did -ra $dname 25 Overwrite | ; rename to Overwrite
if $gettok(%seltext, 2, 32) == %newcolor { | ; If the color is the same too
did -b $dname 25 | ; disable Overwrite
} | ;
else { | ; Otherwise
did -e $dname 25 | ; enable Overwrite
} | ;
} | ;
| ;
var %seltext = $did(21, 1).seltext | ; Get the old listbox nick and color
var %oldnick = $gettok(%seltext, 1, 32) | ;
var %oldcolor = $gettok(%seltext, 2, 32) | ;
| ;
if %oldnick %oldcolor == %newnick %newcolor { | ; If the lines are the same
did -b $dname 25 | ; disable Overwrite
did -e $dname 26 | ; enable Delete
} | ;
elseif %oldnick != $null && %oldnick != %newnick { | ; If the new nick is different
did -u $dname 21 | ; unselect it
did -ra $dname 25 Add | ; rename Overwrite to Add
if %newnick != $null { | ; If there's a new nick
did -e $dname 25 | ; enable Add
} | ;
else { | ; Otherwise
did -b $dname 25 | ; disable Add
} | ;
did -b $dname 26 | ; and disable Delete (no nick yet added)
} | ;
elseif %oldnick == $null { | ; If there's no selected nick
did -are $dname 25 Add | ; rename Overwrite to Add and enable it
did -b $dname 26 | ; disable Delete
}
}