Sephiroth
http://sephiroth.scifi-action.de/board/

Dialog Position Saver
http://sephiroth.scifi-action.de/board/viewtopic.php?f=4&t=8
Seite 1 von 1

Autor:  Sephiroth [ 18. März 2008 00:04 ]
Betreff des Beitrags:  Dialog Position Saver

;
; Dialog Position Saver
;
; Put this script in a new remote file
;
; Remove the old Settings at first! (unload the old script or type
;   /hfree dialogpos
;   /remove dialogpos.hsh
;
; * Fixed bug in unload event (bracked mismatch)
; + Added dialog to remove the positions and restore the default settings
; + Removing also hash tables on unload
;
; * Fixed bug on clearing list
;

;; Dialog
;test dialog for getting border infos and titlebar height
dialog -l testpos {
  size -1 -1 0 0
  option dbu
  button "", 1,0 0 0 0,ok
}
;another useless dialog \o/
dialog delpos {
  title "Dialog Postition Saver"
  size -1 -1 154 55
  option dbu
  list 1, 2 2 80 50, size
  button "&Remove", 2, 85 2 31 12
  button "Re&fresh", 3, 119 2 31 12
  button "&Clear List", 4, 85 15 65 12
  text "", 5, 85 36 30 8
  text "", 6, 120 36 30 8
  text "", 7, 120 45 30 8
  text "", 8, 85 45 30 8
  text "", 9, 85 28 66 8
}

;; Dialogevents
on *:dialog:*:init:*:{
  if ($dname != testpos) { resetpos $dname }
  if ($dname == delpos) { refreshlist }
}
on *:dialog:*:close:*:{
  if ($dname != testpos) {
    hadd -m dialogpos $dname $dialog($dname).x $dialog($dname).y $dialog($dname).w $dialog($dname).h
    hadd -m dialogpos.title $dname $dialog($dname).title
  }
}
on *:dialog:delpos:sclick:1:xywh $+($hget(dialogpos.title,$did(1).seltext),$chr(9),$replace($hget(dialogpos,$did(1).seltext),$chr(32),$chr(9)))
on *:dialog:delpos:sclick:2:remthis $gettok($did(1).seltext,1,32)
on *:dialog:delpos:sclick:3:refreshlist
on *:dialog:delpos:sclick:4:clearlist

;; 'normal' events
on *:load:{
  echo -sg * Type /dialogpos to open the Dialog for clearing the list.
  if ($hget(dialogpos)) { hfree dialogpos }
}
on *:unload:delall
on *:exit:save
on *:start:init

;; aliases
alias dialogpos { dialog $iif($dialog(dialogpos),-v,-m) delpos delpos }

;alias to reset the dialog to the old postion
on *:signal:resetpos:{ resetpos $1 }
alias -l resetpos {
  var %dname = $1
  tokenize 32 $hget(dialogpos,$1)
  ;opening test dialog
  if (!$dialog(testpos)) {
    dialog -m testpos testpos
  }
  var %theme = $dialog(testpos).w $dialog(testpos).h
  ;check for themechange
  if (%theme != %dpos_old_theme) && (%dpos_old_theme) {
    var %1 = $gettok(%theme,1,32) - $gettok(%dpos_old_theme,1,32)
    var %2 = $gettok(%theme,2,32) - $gettok(%dpos_old_theme,2,32)
    tokenize 32 $1-2 $calc($3 + %1) $calc($4 + %2)
  }
  set %dpos_old_theme %theme
  ;closing test dialog
  dialog -k testpos
  ;checking if dialog still exists
  if ($dialog(%dname)) {
    ;checking if old size exists
    if ($4 != $null) dialog -s %dname $1 $2 $calc($3 - $gettok(%theme,1,32)) $calc($4 - $gettok(%theme,2,32))
    ;activating dialog as active dialog
    dialog -v %dname
  }
}
;load settings
alias -l init {
  hmake dialogpos
  if ($isfile(dialogpos.hsh)) { hload dialogpos dialogpos.hsh }
  hmake dialogpos.title
  if ($isfile(dialogpostitle.hsh)) { hload dialogpos.title dialogpostitle.hsh }
}
;remove settings and files
alias -l delall {
  unset %dpos_old_theme
  if ($isfile(dialogpos.hsh)) { !.remove dialogpos.hsh }
  if ($isfile(dialogpostitle.hsh)) { !.remove dialogpostitle.hsh }
  if ($hget(dialogpos.title)) { hfree dialogpos.title }
  if ($hget(dialogpos)) { hfree dialogpos }
}
;refreshes the list in the dialogpos dialog
alias -l refreshlist {
  did -r $dname 1 | var %x = $hget(dialogpos.title,0).item
  while (%x) { did -a $dname 1 $hget(dialogpos.title,%x).item | dec %x }
  xywh
}
;saves the settings (and i know why i use write -c ;) )
alias -l save {
  if (!$hget(dialogpos)) { hmake dialogpos }
  if (!$hget(dialogpos.title)) { hmake dialogpos.title }
  write -c dialogpos.hsh | hsave dialogpos dialogpos.hsh
  write -c dialogpostitle.hsh | hsave dialogpos.title dialogpostitle.hsh
}
;changes the information output at 'dialogpos settings'
alias -l xywh { tokenize 9 $1- | did -ar $dname 5 x: $2 | did -ar $dname 6 y: $3 | did -ar $dname 7 w: $4 | did -ar $dname 8 h: $5 | did -ar $dname 9 $iif($1,$1,<Dialog Titlebar>) }
;deletes the current selected thing ;)
alias -l remthis { hdel dialogpos $$1 | hdel dialogpos.title $1 | did -d $dname 1 $did(1).sel | xywh | save }
;clears the list
alias -l clearlist { did -r $dname 1 | delall | save | refreshlist }

Seite 1 von 1 Alle Zeiten sind UTC + 1 Stunde
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/