Quote Dialog - §ågé §¢rípt

By D-Mag on Nov 16, 2009

Well this is my first snippet and my first dialog. I hope it gets good ratings. Its pretty straight forward.

Command to open: /squote

Or you can just right-click and select S-Quote.

All quotes will be sorted. In this dialog there are 6 buttons: Add, Delete, Edit, Search, Random, and Exit. Add will add whatever you put in the edit box. In edit mode, add will be changed to Fix It. Delete is self explanatory and can be used under edit mode and search mode. Edit allows editing of your quotes and it changes the Random Button to Cancel Edit. Random is self explanatory. Search finds all matches and puts them in a new file and displays that and changes the Random Button to Cancel Search.

To display your quote all you have to do is Double-Click the quote in the list box and it will be displayed in the Active Window. This dialog will tell you the Active Window you are in and how many quotes you have.

If you find any problem, want any improvements, fixes, etc. let me know.

Thanks goes to HeatedHeart(my teacher), and DarkWarrior(Error Fixer) :P

;----------;
;--[LOAD]--;
;----------;

on *:LOAD: {
  echo -a 12S14ag12e Q14uot12e D14ialo12g L14oa12d S14uccessfu12l
  if ($isfile(quote.txt) && $isfile(searched.txt)) {
    echo -a All files required were found!
  }
  else if ($isfile(quote.txt) && !$isfile(searched.txt)) {
    write searched.txt
    echo -a The searched.txt was not found, so it was created.
  }
  else if ($isfile(searched.txt) && !$isfile(quote.txt)) {
    write quote.txt
    echo -a The quote.txt was not found, so it was created.
  }
  else { 
    write quote.txt
    write searched.txt
    echo -a No required files were not found, so they were created.
  }
  echo -a 14-12¥14-12§14åg12é §14¢ríp12t14-12¥14-
}

;------------;
;--[DIALOG]--;
;------------;

dialog quoteDialog {
  title §-Quote Dialog ~ D-Mag
  size -1 -1 218 134
  option dbu
  list 1, 1 11 216 60, sort size
  button "Exit", 2, 178 107 37 12, ok cancel
  button "Add", 3, 3 92 37 12
  button "Delete", 4, 3 107 37 12
  button "Edit", 5, 92 107 37 12
  edit "", 6, 1 72 216 10, autohs return
  text "Controls:", 7, 4 83 25 8
  edit "", 8, 1 123 216 10, read
  button "Random", 9, 92 92 37 12
  button "Search", 10, 178 92 37 12
  edit "", 11, 117 1 100 10, read
  edit "", 12, 1 1 100 10, read
}

;-------------------;
;--[POPUP COMMAND]--;
;-------------------;

menu * {
  S-Quotes:dialog -vmd quoteDialog quoteDialog
}

;------------------------;
;--[LOADING THE QUOTES]--;
;------------------------;

on *:dialog:quoteDialog:init:*: {
  refresh.Quotes
}

;-------------------------;
;--[SINGLE CLICK EVENTS]--;
;-------------------------;

on *:dialog:quoteDialog:sclick:*: {  
  if ($did == 1) {
    if ($did(9) == Cancel Edit) {
      did -ra $dname 6 $did(1).seltext
    }
  }

  ;----------------;
  ;--[ADD] BUTTON--;
  ;----------------;

  else if ($did == 3) {
    if ($did(6) == $null) {
      did -ra $dname 8 You must enter a quote in the Text Box!
    }
    else if ($read(quote.txt, w, $did(6).text) == $did(6).text) { 
      did -ra $dname 8 That quote is already in the file!
      did -r $dname 6
    }
    else if ($did(9) == Cancel Edit) {
      delete.Quote
      write quote.txt $did(6)
      did -r $dname 6
      refresh.Quotes
      select.Quote
      did -ra $dname 6 $read(quote.txt,$lines(quote.txt))
    }
    else {
      write quote.txt $did(6)
      did -r $dname 6
      refresh.Quotes
      select.Quote
    }
  }

  ;-------------------;
  ;--[DELETE] BUTTON--;
  ;-------------------;

  else if ($did == 4) {
    var %seldelete $did(1).sel
    delete.Quote
    did -r $dname 1,6
    if ($did(9) == Cancel Search) {
      refresh.Search
      if (%seldelete > $lines(searched.txt)) { dec %seldelete }
    }
    else { 
      refresh.Quotes 
      if (%seldelete > $lines(quote.txt)) { dec %seldelete }
    }
    did -c $dname 1 %seldelete
  }

  ;-----------------;
  ;--[EDIT] BUTTON--;
  ;-----------------;

  else if ($did == 5) {
    if ($did(1).sel == 0) {
      did -c $dname 1 1
    }
    var %fixstring $did(1).seltext
    did -ra $dname 6 $did(1).seltext
    if ($did(9) == Cancel Search) {
      refresh.Quotes
      did -c $dname 1 %fixsel
      var %fixsel 1
      while (%fixstring != $did(1).seltext) { 
        did -c $dname 1 %fixsel    
        inc %fixsel
      }
      dec %fixsel
      did -c $dname 1 %fixsel   
    }

    did -ra $dname 9 Cancel Edit
    did -era $dname 3 Fix It
    clear.search
  }

  ;---------------------------------------------;
  ;--[RANDOM/CANCEL EDIT/CANCEL SEARCH] BUTTON--;
  ;---------------------------------------------;

  else if ($did == 9) {
    if ($did(9) == Random) {
      msg $active 14-12¥14-S-Quote14-12¥14- 12R14andom12: $read(quote.txt)
    }
    else if ($did(9) == Cancel Edit) {
      did -ra $dname 9 Random
      did -r $dname 6
      did -era $dname 3 Add
    }
    else if ($did(9) == Cancel Search) {
      did -ra $dname 9 Random
      did -era $dname 3 Add
      did -r $dname 6
      refresh.Quotes
      clear.search
    }
  }

  ;-------------------;
  ;--[SEARCH] BUTTON--;
  ;-------------------;

  else if ($did == 10) {
    did -ra $dname 9 Cancel Search
    did -bra $dname 3 Add
    if ($did(6) != $null) {
      clear.search
      search.Quote
      did -ra $dname 11 Results Found: $lines(searched.txt) 
    }
    else { 
      search.Quote
      did -ra $dname 8 Search for what?
      did -ra $dname 11 Results Found: $lines(searched.txt)
    }
  }
}

;-------------------------;
;--[DOUBLE-CLICK EVENTS]--;
;-------------------------;

on *:dialog:quoteDialog:dclick:*: {
  if ($did == 1) && ($did(9) == Random) { 
    msg $active 14-12¥14-§-Quote-12¥14- 12 $+ $chr(35) $+ 14 $+ $did(1).sel $+ 12: $did(1).seltext 
  }
  else if ($did(9) == Cancel Search) {
    msg $active 14-12¥14-§-Quote-12¥14-  12S14earched12: $did(1).seltext   
  }
  else { halt }
}

;------------------;
;--[MOUSE EVENTS]--;
;------------------;

on *:dialog:quoteDialog:mouse:*: { 
  did -ra $dname 12 Active Window: $active
  if ($did(9) == Cancel Search) { 
    did -ra $dname 11 Results Found: $lines(searched.txt) 
    if if ($did == 3) { did -ra $dname 8 Adds what is in the edit box to the quote file. }  
    else if ($did == 9) { did -ra $dname 8 Click to Cancel your Searching. }
    help.info
  }
  else if ($did(9) == Cancel Edit) {
    did -ra $dname 11 Total Quotes: $lines(quote.txt)
    if ($did == 3) { did -ra $dname 8 Add your corrected Quote }  
    else if ($did == 9) { did -ra $dname 8 Cancels quote editing.  }
    help.info
  }
  else {
    did -ra $dname 11 Total Quotes: $lines(quote.txt)
    if ($did == 3) { did -ra $dname 8 Adds what is in the edit box to the quote file. }  
    else if ($did == 9) { did -ra $dname 8 Shows a random quote to active channel. }
    help.info
  }
}

;-------------;
;--[ALIASES]--;
;-------------;

alias clear.search {
  while ($read(searched.txt) != $null) {
    write -dl1 searched.txt
  }
}

alias delete.Quote {
  var %delfind 1
  while ($read(quote.txt,%delfind) != $did(1).seltext) { inc %delfind }
  write -dl $+ %delfind quote.txt
  if ($did(9) == Cancel Search) {
    var %delfind 1
    while ($read(searched.txt,%delfind) != $did(1).seltext) { inc %delfind }
    write -dl $+ %delfind searched.txt
  }
}

alias help.info {
  if ($did == 1) { did -ra $dname 8 Double-Click to display on active window. }
  else if ($did == 2) { did -ra $dname 8 Closes the dialog. }  
  else if ($did == 4) { did -ra $dname 8 Deletes a selected quote from the quote file and list box. }  
  else if ($did == 5) { did -ra $dname 8 Allows you to edit a selected quote. }
  else if ($did == 6) { did -ra $dname 8 Enter you quote here. }
  else if ($did == 10) { did -ra $dname 8 Searches for a quote entered in the edit box. } 
}

alias refresh.Quotes {
  loadbuf -ro quoteDialog 1 quote.txt
  did -ra $dname 11 Total Quotes: $lines(quote.txt)
  did -ra $dname 12 Active Window: $active
}

alias refresh.Search {
  loadbuf -ro quoteDialog 1 searched.txt
  did -ra $dname 11 Results Found: $lines(searched.txt)
  did -ra $dname 12 Active Window: $active
}

alias squote { dialog -vmd quoteDialog quoteDialog }

alias search.Quote {
  var %search 1
  while (%search <= $lines(quote.txt)) {
    var %look $read(quote.txt, %search)
    if ($did(6).text isin %look) { 
      write searched.txt %look
    }
    inc %search
  }
  loadbuf -ro quoteDialog 1 searched.txt
  did -r $dname 6
}

alias select.Quote {
  var %selfind 1
  while ($read(quote.txt,$lines(quote.txt)) != $did(1).seltext) { 
    did -c $dname 1 %selfind
    inc %selfind
  }
  dec %selfind
  did -c $dname 1 %selfind
}

Comments

Sign in to comment.
D-Mag   -  Nov 30, 2009

UPDATE: I found a small problem with the delete button. The problem was that if you clicked the delete button while you selected the LAST quote in your LIST BOX, then it would clear the list box completely and it would look as if you lost all your quotes, but they are still there. I just forgot to call the refresh.Quotes alias.

More
 Respond  
DarkWarrior   -  Nov 25, 2009

"Error fixer" lul, good job man. Great script, you've inspired me with ideas on my future scripts with this. However, I need to get over the laziness first x]

Good job, 10/10

More
 Respond  
D-Mag   -  Nov 21, 2009

idk why, but that kind of hurts napa. >.< lol?

More
 Respond  
napa182   -  Nov 21, 2009

i give it a 5/10 maybe get away from txt files an use hash. anyways nice work on ur first snippet. keep it up....

More
 Respond  
HeatedHeart   -  Nov 20, 2009

Tu "Script" es muy excellente mi amigo.

More
 Respond  
Cold_Fussion   -  Nov 20, 2009

k cool ill check it out...

More
 Respond  
D-Mag   -  Nov 19, 2009

maybe you had a global variable with the same name. idk. thanks for the rating!!! :D btw i updated something with the edit button. you can just copy/paste and replace the other edit part. :P I hope i gets moar ratings. :D

More
 Respond  
Cold_Fussion   -  Nov 19, 2009

i know how to use it, just ur code was a bit icky for my mirc... i fixed it by taking the var out so its permanent... fixed it one time... i kept getting error... line 272 invalid something... changed it, now it works, modding it for my spamfilters... thanks man.... ^_^

still 10/10 from me

More
 Respond  
D-Mag   -  Nov 18, 2009

I guess i should have said how to use it. To use Search enter what your looking for in the edit box then click search. You don't have to put anything in the Edit box, but if you don't, all you will see is a blank list box. IF you put something in the Edit box, then if any results are found, then it should write them in the searched file and display that. Hope that help. ._.

More
 Respond  
Cold_Fussion   -  Nov 18, 2009

10/10 well done man... i love it.... great code, no errors found...

VERY GOOD.... slight problem... the search doesnt work on mine...

no idea y... but ill get it to work... the code looks right to me

but this is mirc... anything can happen ^_^

More
 Respond  
D-Mag   -  Nov 18, 2009

Waiting gets boring. b_d

More
 Respond  
D-Mag   -  Nov 17, 2009

/me waits for ratings from Cold_Fussion... And others b.b

More
 Respond  
Cold_Fussion   -  Nov 16, 2009

not bad... ill rate it after some use... wd for 1st one :D

More
 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.