;###########
;CONTROL PANEL EDITOR
;##############

alias cpe cpanel.edit
alias cpanel.edit { $wdialog(cpanel.edit) }
dialog cpanel.edit {
  title "Control Panel Editor [/cpe]"
  size -1 -1 377 278
  icon icons\10.ico, 0
  list 2, 7 5 364 155, size extsel
  box "", 8, 7 160 263 115
  text "Description:", 15, 20 248 80 16
  edit "", 10, 102 177 160 22, autohs
  text "Command:", 13, 20 226 50 15
  edit "", 12, 102 199 141 22, autohs
  button "?", 19, 244 200 17 20
  text "Icon:", 11, 20 204 24 16
  edit "", 14, 102 221 160 22, autohs
  text "Name:", 9, 20 183 31 16
  edit "", 16, 102 242 160 22, autohs
  box "", 17, 277 160 94 115
  button "5", 3, 286 173 38 25
  button "6", 4, 323 173 38 25
  button "Change", 20, 286 197 75 25
  button "New", 22, 286 221 75 25
  button "Add", 25, 286 221 75 25, hide
  button "Delete", 23, 286 245 75 25
  button "Button", 1, 4 1 13 15, hide ok
}
on *:dialog:cpanel.edit:init:0:{
  mdx.fonts $dname 2,8,9,16,11,14,13,12,15,10,17,20,22,25,23,19
  mdx SetFont $dname 12 12 400 tahoma
  mdx.buttons $dname 20,22,25,23,19,3
  mdx SetControlMDX $dname 2 listview icon smallicons alignleft rowselect showsel single labeltip $rcon(display,list.style) > $views 
  did -i $dname 2 1 headerdims 75:1 75:2 75:3 85:4
  did -i $dname 2 1 headertext Name $+ $chr(9) $+ Icon $+ $chr(9) $+ Command $+ $chr(9) $+ Info
  did -b $dname 10,12,14,16,20
  cpanel.all
}

alias cpanel.all {
  did -i cpanel.edit 2 1 clearicons list | did -r $dname 2
  var %c = 1,%d = $+($prodir,cpanel.txt)
  while ($read(%d,%c)) {
    var %b = $read(%d,%c)
    did -i cpanel.edit 2 1 seticon list 0 $gettok(%b,2,169)
    did -a cpanel.edit 2 0 + %c 1 1 $gettok(%b,1,169) $chr(9) $gettok(%b,2,169) $chr(9) $gettok(%b,3,169) $chr(9) $gettok(%b,4,169) 
    inc %c
  }
}
on *:dialog:cpanel.edit:sclick:*:{
  var %c = $calc($did($dname,2).sel - 1),%d = $+($prodir,cpanel.txt),%t = $read $+(-l,%c) %d
  if ($did == 3) { if ($did($dname,2).sel isnum) { set %c.temp %t | write -dl $+ %c %d | write $+(-il,$calc(%c - 1)) %d %c.temp  | cpanel.all | did -c $dname 2 $calc(%c) | unset %c.temp } }
  if ($did == 4) { if ($did($dname,2).sel isnum) { set %c.temp %t | write -dl $+ %c %d | write $+(-il,$calc(%c + 1)) %d %c.temp | cpanel.all | did -c $dname 2 $calc(%c + 2) | unset %c.temp } }
  if ($did == 2) { did -e $dname 20 | did -era $dname 10 $gettok(%t,1,169) | did -era $dname 12 $gettok(%t,2,169)  | did -era $dname 14 $gettok(%t,3,169) | did -era $dname 16 $gettok(%t,4,169) }
  if ($did == 20) { write -l $+ %c %d $+($did(10),$chr(169),$did(12),$chr(169),$did(14),$chr(169),$did(16)) | did -r $dname 2 | $cpanel.all | did -br $dname 10,12,14,16 | did -b $dname 20 }
  if ($did == 22) { did -er $dname 10,12,14,16 | did -b $dname 2,3,4,20,23 | did -h $dname 22 | did -v $dname 25 }
  if ($did == 25) { if ($did(10)) && ($did(12)) && ($did(14)) && ($did(16)) { did -h $dname 25 |  did -v $dname 22 | did -e $dname 2,3,4,20,23 | write %d $+($did(10),©,$did(12),©,$did(14),©,$did(16)) | did -r $dname 2 | $cpanel.all | did -br $dname 10,12,14,16 | did -b $dname 20 } | else { derror Error Please verify that all editboxes are complete } }
  if ($did == 19) { did -ra $dname 12 $$sfile($mircdirDuygusohbet\cpanel\,Select an Icon,Select) }
  if ($did == 23) { if ($did($dname,2).sel isnum) { write -dl $+ %c $+($prodir,cpanel.txt) | did -r $dname 2 | $cpanel.all | did -br $dname 10,12,14,16 | did -b $dname 20 } }
}

;###########
;CONTROL PANEL
;##############
alias cpe cpanel
alias cpanel { $wdialog(cpanel) }
dialog cpanel {
  title "Araçlar"
  ;option dbu
  size -1 -1 430 261
  icon icons\10.ico,0
  menu "&Dosya", 149
  item "Yenile", 157, 149
  item "Kapat", 150, 149
  menu "&Görünüm", 158
  item "Büyük", 159, 158
  item "Küçük", 160, 158
  item "Liste", 161, 158
  item "Detaylar", 162, 158
  list 1, 0 0 240 177, size extsel
  list 2, 0 177 242 22, size
  button "",3,1 1 1 1, cancel hide
  button "",4,1 1 1 1, ok hide
  button "Positioner", 5, 1 1 1 1, hide 
}

on *:dialog:cpanel:init:0:{
  mdx.fonts $dname 8,10
  mdx SetDialog $dname style title border sysmenu minbox
  mdx SetControlMDX cpanel 1 listview $cpanel.list > $views
  mdx SetControlMDX cpanel 5 positioner maxbox minbox size > $mddlg 
  ;  mdx SetFont $dname 12,8 +b 13 100 Tahoma
  mdx SetBorderStyle $dname 1,2 staticedge
  did -i $dname 1 1 headerdims 120:1 225:2
  did -i $dname 1 1 headertext Name $+ $chr(9) $+ Description
  mdx SetControlMDX $dname 2 StatusBar > $mdbars
  load.cpanel
  cpanel.list


}
ON *:DIALOG:cpanel:menu:159,160,161,162:{
  did -u $dname 159,160,161,162
  did -c $dname $did
  mdx SetMDXStyle cpanel 1 $cpanel.list
  $wcon(cpanel,liststyle,$did)
}
on *:dialog:cpanel:menu:*:{ 
  if ($did == 165) { var %v = $input(Are you Sure you want to Reset the Cpanel to Default Icons?,296,title,text) | if (%v == $yes) { .copy -o Duygusohbet\cpanel_copy.txt $+($prodir,cpanel.txt) } } 
  if ($did == 150) { dialog -x cpanel }
  if ($did == 157) { did -r $dname 1 | set %cpanel.t $ticks | .timer56 1 0 load.cpanel | did -i $dname 2 2 +b YükLeniyor... Lütfen BekLeyin... }
}
on *:dialog:cpanel:menu:*:{ 
  if ($did == 165) { var %v = $input(Are you Sure you want to Reset the Cpanel to Default Icons?,296,title,text) | if (%v == $yes) { .copy -o Duygusohbet\cpanel_copy.txt $+($prodir,cpanel.txt) } } 
  if ($did == 150) { dialog -x cpanel }
  if ($did == 157) { did -r $dname 1 | set %cpanel.t $ticks | .timer56 1 0 load.cpanel | did -i $dname 2 2 +b Loading, please wait... }
}
ON *:DIALOG:cpanel:sclick:5:{
  var %w = $dialog($dname).cw,%h = $dialog($dname).ch
  if ($istok(size minimize maximize restore,$gettok($did($dname,$did),1,32),32)) {
    mdx MoveControl $dname 1 * * $calc(%w - 1) $calc(%h - 25)
    mdx MoveControl $dname 2 * $calc(%h - 22) %w *
  }
  $wcon(cpanel,cw,%w) | $wcon(cpanel,ch,$calc(%h + 19)) 
  $wcon(cpanel,xpos,$dialog($dname).x) | $wcon(cpanel,ypos,$dialog($dname).y) 
  ; echo aaaa %w //// %h
}

; did -i $dname 2 1 1 seticon small $gettok($cpanel.read.2,2,169) | 
on *:dialog:cpanel:sclick:*:{ var %d = $+($prodir,cpanel.txt) | var %s = $calc($did(cpanel,1).sel - 1) |  if ($did == 1) { if ($did(cpanel,1).sel) { did -i $dname 2 2 +b %s $gettok($read(%d,%s),4,169) } } }
on *:dialog:cpanel:dclick:*:{ if ($did == 1) { if ($did(cpanel,1).sel) { $gettok($read($+($prodir,cpanel.txt),$calc($did(cpanel,1).sel - 1)),3,169) } } }

alias cpanel.list { 
  var %c = showsel single autoarrange
  if ($did($dname,162).state) { var %c = %c report rowselect nosortheader }
  elseif ($did($dname,160).state) { var %c = %c icon smallicon }
  elseif ($did($dname,161).state) { var %c = %c list }
  else { var %c = %c icon }
  return %c 
}
alias cpanel { set %cpanel.t $ticks | $wdialog(cpanel)  }
alias load.cpanel {
  var %d = $+($prodir,cpanel.txt),%c = 1
  did -r cpanel 1 | did -i cpanel 1 1 clearicons list
  while ($read(%d,%c)) {
    var %b = $read(%d,%c)
    did -i cpanel 1,2 1 seticon list %c, $+ $gettok(%b,2,169) 
    did -a cpanel 1 0 + %c 1  $gettok(%b,1,169) $chr(9) $gettok(%b,4,169) 
    inc %c
  }
  var %l = $lines($+($prodir,cpanel.txt))
  set %ticks $ticks
  balloon Loaded > Successfully loaded the Control Panel in $+($round($calc((%ticks - %cpanel.t) / 1000),2),secs..) 
  did -i cpanel 2 2 +b 0 %l $+(Obje ,$iif(%l > 1,)) Var Açılan Sayfada İyi Eğlenceler...
  var %j = $rcon(cpanel,style)
  if (%j == 2) { did -i cpanel 1 1 setbkg url $rcon(cpanel,layout) $rcon(cpanel,url) }
  elseif (%j == 4) { did -i cpanel 1 1 setbkg color $rcon(cpanel,bg) }
  elseif (%j == 5) { did -i cpanel 1 1 setbkg none }
  did -i cpanel 1 1 settxt color $rcon(cpanel,text)
  did -i cpanel 1 1 settxt bgcolor $rcon(cpanel,textbg)
  unset %cpanel.t | unset %ticks
}
