Notepad Dialog

By Conscious on Jan 16, 2011

One of my first dialogs, my first published dialog.

Usage: Right click in the status window, a channel or a PM and click on "Notepads" Which will bring up the notepad.

There's 5 different saved notepads, just click up the top to change. Note: if you change notepads and you'll be reverted back to the last save. A popup should come up reminding you (will only popup if you haven't saved since an edit) to save if you want to.

;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;Conscious' Notepad Dialog;;;;
;;;;Feel free to edit or take;;;;
;;;;apart in any manner and ;;;;;
;;;;Republish in any form ;;;;;;;
;;;;Excluding Direct copying ;;;;
;;;;;;;;;Of the script.;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

dialog Npad1 {
  title "Notepad"
  size -1 -1 250 250
  option dbu
  edit "", 1, 14 34 225 194, multi return vsbar
  button "Clear current without saving", 2, 20 20 106 12
  button "Delete All", 3, 129 20 106 12
  button "Delete Current", 4, 17 230 40 18, multi
  button "Revert to last save", 5, 61 230 40 18, multi
  button "Exit without saving", 6, 105 230 40 18, multi
  button "Save", 7, 149 230 40 18, multi
  button "Save and close", 8, 193 230 40 18, multi ok
  button "Notepad 1", 9, 21 5 37 12
  button "Notepad 2", 310, 65 5 37 12
  button "Notepad 3", 11, 109 5 37 12
  button "Notepad 4", 12, 154 5 37 12
  button "Notepad 5", 13, 198 5 37 12
}
on *:dialog:Npad1:close:*: {
  unset %did==1
}
on *:DIALOG:Npad1:edit:*:{
  set %did==1 Yes
}
on *:dialog:Npad1:init:*: {
  unset %did==1
  notepadwrite
  var %linesnpad1.txt 1
  while (%linesnpad1.txt <= $lines(npad1.txt)) {
    var %did $read(npad1.txt,%linesnpad1.txt)
    did -na npad1 1 %did $+ $crlf
    inc %linesnpad1.txt
  }
  set %npadno 1
}
on *:dialog:npad1:sclick:*: {
  if ($did == 2) { 
    did -r npad1 1 
    set %did==1 Yes
  }
  if ($did == 4) {
    var %yesorno $$?!="Are you sure you want to delete the whole contents of this notepad?"
    if (%yesorno == $true) { write -c npad $+ %npadno $+ .txt
      did -r npad1 1
    }
  }
  if ($did == 3) {
    var %yesorno2 $$?!="Are you sure you want to delete all the contents of all 5 notepads?"
    if (%yesorno2 == $true) { 
      write -c npad1.txt
      write -c npad2.txt
      write -c npad3.txt
      write -c npad4.txt
      write -c npad5.txt
      did -r npad1 1
    }
  }
  if ($did == 5) { 
    var %yesorno $$?!="Are you sure you want to revert to the last save of this notepad?"
    if (%yesorno == $true) {
      did -r npad1 1 
      var %linesnpad.txt 1
      while (%linesnpad.txt <= $lines(npad $+ %npadno $+ .txt)) {
        var %did $read(npad $+ %npadno $+ .txt, %linesnpad.txt) 
        did -na npad1 1 %did $+ $crlf
        inc %linesnpad.txt
      }
    }
  }
  if ($did == 6) {
    var %exit $$?!="Are you sure you want to exit without saving?"
    if (%exit == $true) {
      dialog -x npad1 npad1
    }
  }
  if ($did == 7) {
    unset %did==1
    write -c npad $+ %npadno $+ .txt
    var %did 1
    while (%did <= $did(1).lines) {
      write npad $+ %npadno $+ .txt $did(1,%did)
      inc %did
    }
  }
  if ($did == 8) {
    write -c npad $+ %npadno $+ .txt
    var %did 1
    write -c npad $+ %npadno $+ .txt
    while (%did <= $did(1).lines) {
      write npad $+ %npadno $+ .txt $did(1,%did)
      inc %did
    }
    dialog -x npad1 npad1
  }
  if ($did == 9) { 
    if (%npadno == 1) { dialog -m notepadfail notepadfail }
    else {
      var %savedpad $iif(%did==1 == yes,$$?!="Would you like to save your current notepad?",False)
      unset %did==1
      if (%savepad == $true) {
        write -c npad $+ %npadno $+ .txt
        var %did 1
        write -c npad $+ %npadno $+ .txt
        while (%did <= $did(1).lines) {
          write npad $+ %npadno $+ .txt $did(1,%did)
          inc %did
        }
      }
      did -r npad1 1
      var %linesnpad.txt 1
      set %npadno 1
      while (%linesnpad.txt <= $lines(npad $+ %npadno $+ .txt)) {
        var %did $read(npad $+ %npadno $+ .txt, %linesnpad.txt) 
        did -na npad1 1 %did $+ $crlf
        inc %linesnpad.txt
      }
    }
  }
  if ($did == 10) { 
    if (%npadno == 2) { dialog -m notepadfail notepadfail }
    else {
      var %savedpad $iif(%did==1 == yes,$$?!="Would you like to save your current notepad?",False)
      unset %did==1
      if (%savepad == $true) {
        write -c npad $+ %npadno $+ .txt
        var %did 1
        write -c npad $+ %npadno $+ .txt
        while (%did <= $did(1).lines) {
          write npad $+ %npadno $+ .txt $did(1,%did)
          inc %did
        }
      }
      did -r npad1 1
      set %npadno 2
      var %linesnpad.txt 1
      while (%linesnpad.txt <= $lines(npad $+ %npadno $+ .txt)) {
        var %did $read(npad $+ %npadno $+ .txt, %linesnpad.txt) 
        did -na npad1 1 %did $+ $crlf
        inc %linesnpad.txt
      }
    }
  }
  if ($did == 11) { 
    if (%npadno == 3) { dialog -m notepadfail notepadfail }
    else {
      var %savedpad $iif(%did==1 == yes,$$?!="Would you like to save your current notepad?",False)
      unset %did==1
      if (%savepad == $true) {
        write -c npad $+ %npadno $+ .txt
        var %did 1
        write -c npad $+ %npadno $+ .txt
        while (%did <= $did(1).lines) {
          write npad $+ %npadno $+ .txt $did(1,%did)
          inc %did
        }
      }
      did -r npad1 1
      var %linesnpad.txt 1
      set %npadno 3
      while (%linesnpad.txt <= $lines(npad $+ %npadno $+ .txt)) {
        var %did $read(npad $+ %npadno $+ .txt, %linesnpad.txt) 
        did -na npad1 1 %did $+ $crlf
        inc %linesnpad.txt
      }
    }
  }
  if ($did == 12) { 
    if (%npadno == 4) { dialog -m notepadfail notepadfail }
    else {
      var %savedpad $iif(%did==1 == yes,$$?!="Would you like to save your current notepad?",False)
      unset %did==1
      if (%savepad == $true) {
        write -c npad $+ %npadno $+ .txt
        var %did 1
        write -c npad $+ %npadno $+ .txt
        while (%did <= $did(1).lines) {
          write npad $+ %npadno $+ .txt $did(1,%did)
          inc %did
        }
      }
      did -r npad1 1
      var %linesnpad.txt 1
      set %npadno 4
      while (%linesnpad.txt <= $lines(npad $+ %npadno $+ .txt)) {
        var %did $read(npad $+ %npadno $+ .txt, %linesnpad.txt) 
        did -na npad1 1 %did $+ $crlf
        inc %linesnpad.txt
      }
    }
  }
  if ($did == 13) { 
    if (%npadno == 5) { dialog -m notepadfail notepadfail }
    else {
      var %savedpad $iif(%did==1 == yes,$$?!="Would you like to save your current notepad?",False)
      unset %did==1
      if (%savepad == $true) {
        write -c npad $+ %npadno $+ .txt
        var %did 1
        write -c npad $+ %npadno $+ .txt
        while (%did <= $did(1).lines) {
          write npad $+ %npadno $+ .txt $did(1,%did)
          inc %did
        }
      }
      did -r npad1 1
      var %linesnpad.txt 1
      set %npadno 5
      while (%linesnpad.txt <= $lines(npad $+ %npadno $+ .txt)) {
        var %did $read(npad $+ %npadno $+ .txt, %linesnpad.txt) 
        did -na npad1 1 %did $+ $crlf
        inc %linesnpad.txt
      }
    }
  }
}
on *:START:{ notepadwrite }
alias -l notepadwrite {
 tokenize 32 $regsubex($str(.,5),/./g,$+($chr(32),$+(npad,\n,.txt)))
  scon -r $!iif(!$isfile( $* ),write $* )
}

alias notepad dialog -m npad1 npad1
dialog notepadfail {
  title "Error"
  size -1 -1 141 64
  option dbu
  text "You are already on this notepad! Click Okay to continue.", 1, 11 8 121 24
  button "Okay", 2, 52 44 37 12, ok
}
menu * {
  Notepads: notepad
}

Comments

Sign in to comment.
Firstmate   -  Jan 26, 2011

Add the n parameter to the $read identifier he uses to load the files. The 'n' param prevents mIRC from evaluating the stuff it reads.

@Author: I suggest you use /filter or even /loadbuf for loading files.

 Respond  
Conscious   -  Jan 26, 2011

Hmm... just realised it changed things like $rand(1,1) to 1, and doesn't display extra spaces + returns... No clue how to fix that.. any pointers?

 Respond  
napa182   -  Jan 17, 2011

well to do that asking on the net is not the way to go.. =P

 Respond  
Jethro   -  Jan 17, 2011

napa182, if you could make me disappear on the face of the earth, that'd be priceless.

 Respond  
napa182   -  Jan 17, 2011

well I can set you up with a whole new life.....For a price that is. ;x

 Respond  
Jethro   -  Jan 17, 2011

napa182, I don't even have a true identity, and I live in a place called never-never land. Jk..lol

 Respond  
napa182   -  Jan 17, 2011

Jethro_ the Undocumented worker? =P

 Respond  
Jethro   -  Jan 17, 2011

Firstmate, this has nothing do with recommendations but to show a way of going at it. Learning is about expending the spectrum of absorbing something new, documented or not.

 Respond  
Firstmate   -  Jan 17, 2011

Why recommend an undocumented feature? Provided it can do it in less lines of code, and while there is no lack of functionality, it's still undocumented.

 Respond  
Jethro   -  Jan 16, 2011

Conscious wrote:> How would I get the $iif(!isfile(npad#.txt)),blah) into that?

tokenize 32 $regsubex($str(.,5),/./g,$&
$+($chr(32),$+(npad,\n,.txt)))
scon -r $!iif(!$isfile( $* ),write $* )
 Respond  
Conscious   -  Jan 16, 2011

How would I get the $iif(!isfile(npad#.txt)),blah) into that?

 Respond  
Jethro   -  Jan 16, 2011

The $ is an internal loop upon all the tokens; a "cheap" way of looping. I use /scon -r to re-evaluate so that the $ gets the evaluation priority. And the ! between the $!+ is to avoid it being evaluated before the $*

 Respond  
Conscious   -  Jan 16, 2011

I got the tokenize 32 (space) bit... but O_O

 Respond  
Conscious   -  Jan 16, 2011

What the hell is that? O_O

 Respond  
Jethro   -  Jan 16, 2011

And for > write -c npad1.txt
write -c npad2.txt
write -c npad3.txt
write -c npad4.txt
write -c npad5.txtyou could do:

  tokenize 32 npad1 npad2 npad3 npad4 npad5
  scon -r write -c $!+( $* ,.txt)
 Respond  
Jethro   -  Jan 16, 2011

Why not use a while loop:

alias -l notepadwrite {
  var %x 1
  while %x <= 5 {
    if !$isfile($+(npad,%x,.txt)) {
      write $+(npad,%x,.txt)
    }
    inc %x
  }
}

You don't need to specify "here is your first notepad, etc..." the text files will be created with 0 bytes.

 Respond  
Conscious   -  Jan 16, 2011

Fixed, thanks.

Fail copy and paste on my behalf.

 Respond  
mSLChampagne   -  Jan 16, 2011

Your local alias /notepadwrite seems to have been pasted incorrectly. As it is now the alias will not function properly.

 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.