Text File Viewer and Manager Dialog

By Scakk on Oct 16, 2007

This little dialog can be used to view your .txt files , delete a .txt file or create a new .txt file.

Image

Update 1: It will now allow you to view all .txt files. I had to fix the deleting part to work with the new way that had to be listed.

Update 2: hsbar added to the list box.

Update 3: If the .txt file name is in use it will not create it.

Update 4: The file name including .txt must be at least 5 characters in length.

Update 5 21Sep08: Removed the 'List' button , changed the way it list the .txt in the list box, changed to where it loads all the .txt files in your $mircdir upon opening, made the 'View , New and Delete' buttons show when opening and cleaned the code up a bit here and there.

menu status,channel {
  [Text Files]: dialog $iif(!$dialog(textfiles), -m, -va) textfiles textfiles
}
dialog textfiles {
  title ".txt Files"
  size -1 -1 200 230
  list 2, 10 5 183 170, hsbar vsbar sort
  text "File", 3, 5 178 30 25, center
  edit "", 4, 35 175 158 20, read autohs center
  button "View", 5, 5 200 55 25
  button "New" 7, 72 200 55 25
  button "Delete", 6, 140 200 55 25
  text "New File", 8, 10 235 50 25
  edit "", 9, 60 232 133 20, autohs
  button "Create", 10, 5 260 90 25
  button "Cancel", 11, 105 260 90 25
}
on *:dialog:textfiles:*:*: {
  if ($devent = init) { 
    did -b $dname 5,6
    var %x = 1
    while ($findfile($mircdir,*.txt,%x)) {
      did -a $dname 2 $remove($findfile($mircdir,*.txt,%x,2),$mircdir)
      inc %x
    }
    did -z $dname 2 190 350
    dialog -t $dname $+($chr(91),$did(2).lines,$chr(93)) .txt files
  }
  if ($devent = sclick) {
    if ($did == 2) { 
      if ($did(2).seltext) {
        did -e $dname 5,6
        dialog -s $dname -1 -1 200 230
        did -ra $dname 4 $+($mircdir,$did(2).seltext)
      }
    }
    if ($did == 5) { run $did(2).seltext | did -b $dname 5,6 | did -u $dname 2 }
    if ($did == 6) { 
      if ($input(Continue with deletion of $str($crlf,2) $qt($+($mircdir,$did(2).seltext)) $+ ?,cy,Deletion of $qt($remove($did(2).seltext,$mircdir)))) {
        .remove $qt($+($mircdir,$did(2).seltext))
        did -d $dname 2 $did(2).sel
        dialog -t $dname $+($chr(91),$did(2).lines,$chr(93)) .txt files
        did -f $dname 9
        did -b $dname 5,6 
        did -u $dname 2
        did -r $dname 4
      }
      else { did -f $dname 9 | did -b $dname 5,6 | did -u $dname 2 | did -r $dname 4 }
    }
    if ($did == 7) {
      dialog -s $dname -1 -1 200 290
      did -f $dname 9
      did -b $dname 5,6 
      did -u $dname 2
      did -r $dname 4
    }
    if ($did == 10) {
      if (!$did(9).text) { 
        echo -ag No information given for a .txt file to be created. 
        dialog -s $dname -1 -1 200 230
        did -r $dname 9
      }
      if ($did(9).text) {
        if (($right($did(9),4) == .txt) && ($len($did(9)) < 5)) { 
          echo -ag The length including .txt must be at least 5 characters in length.
          dialog -s $dname -1 -1 200 230 
          did -r $dname 9
        }
        elseif ($right($did(9),4) != .txt) { 
          echo -ag Please use " .txt " at the end of the name for the new file. 
          dialog -s $dname -1 -1 200 230 
          did -r $dname 9
        }
        elseif ($exists($did(9))) { 
          echo -ag That .txt file name is already in use.
          dialog -s $dname -1 -1 200 230
          did -r $dname 9
        }
        else { 
          write $did(9) 
          did -a $dname 2 $did(9) 
          did -f $dname 9
          did -b $dname 5,6 
          did -u $dname 2
          did -r $dname 4
          dialog -s $dname -1 -1 200 230
          dialog -t $dname $+($chr(91),$did(2).lines,$chr(93)) .txt files
        }
      }
    }
    if ($did == 11) { dialog -s $dname -1 -1 200 230 | did -r $dname 9 }
  }
}

Comments

Sign in to comment.
Scakk   -  Sep 21, 2008

Update 5 21Sep08: Removed the 'List' button , changed the way it list the .txt in the list box, changed to where it loads all the .txt files in your $mircdir upon opening, made the 'View , New and Delete' buttons show when opening and cleaned the code up a bit here and there.

 Respond  
Korvin   -  Dec 16, 2007
while ($findfile($mircdir,*.txt,%x)) {
  did -a $dname 2 $shortfn($findfile($mircdir,*.txt,%x))
  inc %x
}
 Respond  
EL   -  Dec 16, 2007

This is very handy.Theres no reason to load then look at scripts then delete from the editor and its better then opening your directory and having 785094732150 files open on your desk top.Only thin i had a problem with is freezing my comp for about 30 seconds thought it mite have been infinite but i waited so i didn\'t break, was just busy doing its thing.i did notice that when you delete a file the dialog goes back to the list button state to list the files again an you can close or list again from there.Is there any way after you delete a file that the dialog can auto list the .txt files again? not that it takes much effort to list again,just push the button.Think that just comes from me loading an unloading files,that whole fun tedious loop.Any way nice job on this very useful 8/10.`-.-

 Respond  
Scakk   -  Oct 16, 2007

@mountaindew Added the hsbar to the list box.

 Respond  
Kyousoukyoku   -  Oct 16, 2007

if i give it a 10 i might get yelled at from hawkee for such little coding :)

I\'m not really saying you should give this a ten lol. But, it wouldn\'t hurt to review this snippet a bit and rate it based on what you find. =D On the contrary, your opinions are not my decision. So whatever you rate it is based on what you look for in a snippet. So eh, w/e. ;)

 Respond  
guest598594   -  Oct 16, 2007

nvm then, i guess it works with just one

 Respond  
guest598594   -  Oct 16, 2007
        dialog -x textfiles 

i believe ur forgetting a textfiles, dialog -x textfiles textfiles

 Respond  
Anti   -  Oct 16, 2007

if i give it a 10 i might get yelled at from hawkee for such little coding :)

 Respond  
Kyousoukyoku   -  Oct 16, 2007

I must say this is a pretty useful snippet for filtering out those txt files that aren\'t needed. One thing that disappoints me is the appreciation this snippet receives. I would, well right now, rate this a 6. It makes me wonder how people rate snippets.

Anyway, it would be interesting if you could display the file\'s data in a new dialog or an expansion to the current dialog. I don\'t really see a use of resizing the dialog with a button when you can directly list them. ;) It would be great to have this support other file types, and just include it in one pack. But I\'d have to say this is pretty nice, good work Scakk.

 Respond  
guest598594   -  Oct 16, 2007

*is, not if

 Respond  
guest598594   -  Oct 16, 2007

If you mean using $nopath when getting the list of .txt files then I tried that. Using $nopath and $nofile cause it to not allow you to open some of the .txt files it list in the dialog. Doing it as it is above you get the full list , you can open them all and you can delete any of them no matter how deep they are in the mIRC directory.
then u shold at least add a hsbar and did -z, cuz all i currently see if the beginning of the $mircdir, and i cant even see the file

 Respond  
Anti   -  Oct 16, 2007

makes you feel better ill rate it :)

 Respond  
Anti   -  Oct 16, 2007

well dont complain :)

 Respond  
Kyousoukyoku   -  Oct 16, 2007

Well, I think the author of a snippet wouldn\'t post it here if they didn\'t think they didn\'t do a good hob on their snippet. :P Seems okay from the coding, will test it out soon and rate this snippet accordingly. As of now, nice job Scakk.

 Respond  
Anti   -  Oct 16, 2007

Tell me scakk do you think you did a good job?

 Respond  
Scakk   -  Oct 16, 2007

I only ask incase there is something needed , something wanted or possibly and error that needs to be fixed. The actual score of it does not matter to me. I just like it if people that decide to rate something with a low score they explain why they gave it a low not just rate and run so to speak.

 Respond  
Anti   -  Oct 16, 2007

3 (Not useful) < ROFL! that answer you\'re question>!

 Respond  
Anti   -  Oct 16, 2007

what! :P just live with you get or will ever get rofl

 Respond  
Scakk   -  Oct 16, 2007

To the person that rated it a \"3\". What was wrong with it? What does it need?

 Respond  
Scakk   -  Oct 16, 2007

If you mean using $nopath when getting the list of .txt files then I tried that. Using $nopath and $nofile cause it to not allow you to open some of the .txt files it list in the dialog. Doing it as it is above you get the full list , you can open them all and you can delete any of them no matter how deep they are in the mIRC directory.

 Respond  
guest598594   -  Oct 16, 2007

i would use $nopath, either that or put a hsbar, just loop it, and when everythings done, did -z $dname $did

 Respond  
Scakk   -  Oct 16, 2007

Update: It will now allow you to view all .txt files. I had to fix the deleting part to work with the new way that had to be listed.

 Respond  
kerstt   -  Oct 16, 2007

add a . for remove to hide the \"blabla removed\" notice in your status bar :)

 Respond  
Gummo   -  Oct 16, 2007

I believe it\'s because channels.txt is in a subfolder. Your dialog does /run from what\'s selected, while it actually needs channels/channels.txt
You could solve this problem by doing a $findfile when you click run. :)

 Respond  
Scakk   -  Oct 16, 2007

For some reason it will not open all .txt files. I have not quite figured out how to get it to open those. Any suggestions?

 Respond  
Gummo   -  Oct 16, 2007

Nice way to only open text files in your folder. :)
However, it wouldn\'t open channels.txt while it opened the others normally..

  • /run: unable to open \'channels.txt\' (line 37, viewtext.mrc)
 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.