Hash Table Manager Dialog II

By Scakk on May 18, 2008

This script has the ability to add new tables , items and data. It can also be used to delete tables , items or data. It can also be used to delete multiple items from a hash table at one time.

Image

Image

Update: Fixed issue if you use the .unset feature of hash tables. If you changed the data part it would not reset the timer function of the .unset feature. ( May 20th 08 )

Update: If only one item was chosen on the mutli delete dialog it would not delete it. Has been fixed. ( May 23rd 08 )

Update: 23Sep08 Fixed a reoccuring bug with the multi delete dialog. Shortened the code a bit and resized the Multi Item Delete Dialog. Added a few more checks into the code also. Name of hash table being owrked on shows in the title of the Multi Item Delete Dialog.

menu channel,status { 
  [Hash Table Manager]: htm
}
alias htm { dialog $iif($dialog(htable), -v, -m) htable htable }

dialog htable {
  title Hash Table Manager
  size -1 -1 500 180
  text "Tables", 1, 5 4 120 20, center
  list 2, 5 25 120 155, sort
  text "Items", 3, 130 4 120 20, center
  list 4, 130 25 120 150, sort
  edit "", 6, 295 25 200 20, read center autohs
  edit "", 7, 295 50 200 20, read center autohs
  edit "", 8, 295 75 200 20, read center autohs
  text "Tables", 9, 250 28 40 30, center
  text "Items", 10, 250 53 40 30, center
  text "Data", 11, 250 78 40 30, center
  button "New Table", 15, 255 103 60 20
  edit "Table Size", 23, 318 103 115 20, flat center autohs
  button "Del Table", 16, 435 103 60 20
  button "New Item", 17, 255 128 60 20
  edit "Item Data", 24, 318 128 115 20, center autohs
  button "Del Item", 18, 435 128 60 20
  button "Edit Data", 19, 255 153 60 20
  edit "", 20, 318 153 175 20, center autohs
  button "Multi Item Delete" 25, 400 4 95 20
}
on *:dialog:htable:*:*: {
  if ($devent == init) { 
    dialog -s htable 510 523 500 180
    did -b $dname 15-20,24,25
    var %x 1
    while ($hget(%x)) {
      did -a $dname 2 $hget(%x)
      inc %x
    }
    did -ra $dname 1 $iif($did(2).lines > 1,Tables,Table) $+([,$did(2).lines,])
  }
  if ($devent == sclick) {
    if ($did == 2) { 
      $iif($dialog(htm2), dialog -x htm2)
      $iif($exists(htl.txt), .remove htl.txt)
      if ($did(2).seltext) {
        did -e $dname 16,24
        did -r $dname 4,6-8,20
        var %x 1
        while ($hget($did(2).seltext,%x).item) {        
          did -a $dname 4 $hget($did(2).seltext,%x).item 
          inc %x
        }
        did -a $dname 6 $($did(2).seltext  $+([,Size:,$chr(32),$hget($did(2).seltext).size,]) )
        did -ra $dname 3 $iif($did(4).lines > 1,Items,Item) $+([,$did(4).lines,])
        did $iif($did(4).lines > 1, -e,-b) $dname 25
      }
      if ($did(2).seltext && !$did(4).seltext) { did -b $dname 18,20 }
    }
    if ($did == 4) {
      if ($did(4).seltext) {
        $iif($dialog(htm2), dialog -x htm2)
        $iif($exists(htl.txt), .remove htl.txt)
        did -e $dname 18,20
        did -r $dname 24
        did -ra $dname 6 $($did(2).seltext  $+([,Size:,$chr(32),$hget($did(2).seltext).size,]) )
        did -ra $dname 7 $did(4).seltext
        if ($hget($did(htable,2).seltext,$did(htable,4).seltext)) { did -ra $dname 8,20 $hget($did(htable,2).seltext,$did(htable,4).seltext) }
        if ($hget($did(htable,2).seltext,$did(htable,4).seltext).unset) { did -ra $dname 8,20 $hget($did(htable,2).seltext,$did(htable,4).seltext).unset }           
      }
    }
    if ($did == 15) { 
      tokenize 32 $did(23) 
      var %1 $1 , %2 $2
      if (%1) {
        .hmake %1 $iif(%2 isin $did(23) && %2 isnum, %2, 100)
        dialog -x htable | dialog -mv htable htable
      }
    }
    if ($did == 16) { 
      if ($input(Hash Table: $did(2).seltext $+ $str($crlf,2) $+ Continue with deletion of hash table $qt($did(2).seltext) $+ ?,y,Delete Hash Table...?)) { 
        .hfree $did(2).seltext 
        dialog -x htable | dialog -mv htable htable
      }
    }
    if ($did == 17) { 
      tokenize 32 $did(24) 
      var %1 $1 , %2 $2-
      if (%1) {
        .hadd -c $did(2).seltext %1 $iif(%2, %2)
        dialog -x htable | dialog -mv htable htable
      }
    }
    if ($did == 18) { 
      if ($input(Hash Table: $did(2).seltext $+ $crlf $+ Item: $did(4).seltext $+ $str($crlf,2) $+ Continue with deletion of item $qt($did(4).seltext) $+ ?,y,Delete Item...?)) { 
        .hdel $did(2).seltext $did(4).seltext
        dialog -x htable | dialog -mv htable htable
      }
    }
    if ($did == 19) { 
      if ($input(Exchange $hget($did(htable,2).seltext,$did(htable,4).seltext) with $did(20) $+ ?,y,Edit Confirmation)) { 
        $iif($hget($did(htable,2).seltext,$did(htable,4).seltext).unset, hadd -u $+ $did(20) $did(2).seltext $did(4).seltext , hadd $did(2).seltext $did(4).seltext $did(20))
        dialog -x htable | dialog -mv htable htable
      }
      else { $iif($hget($did(htable,2).seltext,$did(htable,4).seltext), did -ra $dname 20 $hget($did(htable,2).seltext,$did(htable,4).seltext), did -ra $dname 20 $did(8)) }
    }
    if ($did == 25) { if ($dialog(htm2)) { dialog -x htm2 | dialog -m htm2 htm2 } | else { dialog -m htm2 htm2 } }
  }
  if ($devent == edit) { 
    if ($did == 20) { did $iif($did(20) == $did(8).text, -b,-e) $dname 19 }
    if ($did == 23) { did $iif($did(23).text, -e,-b) $dname 15 }
    if ($did == 24) { did $iif($did(24).text, -e,-b) $dname 17 }
  }
}
dialog htm2 {
  title "Hash Table:"
  size -1 -1 200 150
  list 1, 5 5 190 125, check sort
  button "Delete", 2, 70 125 60 20
}
on *:dialog:htm2:*:*: {
  if ($devent = close) { $iif($exists(htl.txt), .remove htl.txt) }
  if ($devent == init) { 
    dialog -t $dname $did(htable,2).seltext
    did -b $dname 2
    var %x 1
    while ($hget($did(htable,2).seltext,%x).item) {
      did -a htm2 1 $hget($did(htable,2).seltext,%x).item 
      inc %x
    }
  }
  if ($devent == sclick) { 
    if ($did == 1) { 
      if ($did(1).csel >= 1) {
        if ($did(1).seltext) { did -e $dname 2 }
        if ($did(htm2,1,$did(htm2,1).sel).cstate == 1) { write htl.txt $did(1).seltext }
        if ($did(htm2,1,$did(htm2,1).sel).cstate == 0) { write -ds $+ $did(1).seltext htl.txt }
      }
      if ($did(1).csel == 0) { did -b $dname 2 | did -u $dname 1 | .remove htl.txt }
    }
    if ($did == 2) { 
      if ($input(Hash Table: $did(htable,2).seltext $+ $crlf $&
        $+ Items to delete: $+([,$did(1,0).csel,]) $+ $str($crlf,2) $& 
        $+ Ready to delete?,y,Deleting Items...)) { 
        var %t = 1
        while (%t <= $lines(htl.txt)) { 
          hdel $did(htable,2).seltext $read(htl.txt,t,%t)
          inc %t
        }
        .remove htl.txt
        dialog -x htm2
        did -r htable 3,4,6-8
        did -u htable 2
        did -a htable 3 Items
      }
    }
  }
}

Comments

Sign in to comment.
EL   -  Sep 23, 2008

Looks good scakk man cant do my hash codes without it;p.`-.-´

 Respond  
Scakk   -  Sep 23, 2008

Update: 23Sep08 Fixed a reoccuring bug with the multi delete dialog. Shortened the code a bit and resized the Multi Item Delete Dialog. Added a few more checks into the code also. Name of hash table being owrked on shows in the title of the Multi Item Delete Dialog.

 Respond  
vaseline28   -  May 25, 2008

Ah yes, I remember you telling me about this. Great script, and it seems to work smoothly and I\'ve encountered no bugs!

 Respond  
Scakk   -  May 20, 2008

Update: Fixed issue if you use the .unset feature of hash tables. If you changed the data part it would not reset the timer function of the .unset feature.

 Respond  
SnoooP   -  May 19, 2008

wow scakk very good job :) reallt nice snippet

 Respond  
Scakk   -  May 19, 2008

I will be adding more pics later and updating the post as needed. Thanks again :)

 Respond  
Hawkee   -  May 19, 2008

Very nice, it even makes your profile snippets look better.

 Respond  
Scakk   -  May 18, 2008

I will keep that in mind Hawkee. I tend to make dialogs so perhaps pictures will help people out more.

added another picture

 Respond  
Hawkee   -  May 18, 2008

Looks better, you know you can show up to 3 screenshots per snippet.

 Respond  
Scakk   -  May 18, 2008

Thanks Hawkee. Uploaded and added :)

 Respond  
Hawkee   -  May 18, 2008

Scakk, if you upload your screenshots to Hawkee and paste the bbcode to your Introduction you\'ll have thumbnails on the snippets page.

 Respond  
EL   -  May 18, 2008

Awesome Scakk very well done.`-.-´

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.