Results 1 to 5 of 5

Thread: [RESOLVED] Auto Indent?!

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2010
    Location
    Connecticut
    Posts
    17

    Resolved [RESOLVED] Auto Indent?!

    Hey visual basic world!

    so i've got an issue! i'm making a program that runs operations and functions threw xml! i got everything working out great! I have most file system/registry operations and a couple user-designated functions goin on, but unfortunate for my developers, my editor is just a text box using Lucinda Console font.

    I noticed on Notepad++ and even in Visual Studio Code Editor, it auto indents! amazing! i'd like to know how to implement that VERY useful but tiny feture into my application. any way this can be done?

    ~Matt

  2. #2

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Sep 2010
    Location
    Connecticut
    Posts
    17

    Re: Auto Indent?!

    No i mean while typing... like visual studio does while typing, i'm not looking to autoindent saves, i'm looking to autoindent while editing, get me?

  4. #4
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: Auto Indent?!

    Oh, that. That's quite a trick. You should analyze the input as the user types in the text and then format it on the fly. That's quite a project all by itself.
    It should be syntax dependable (be that XML or something else).
    Basically you will need a complete parser which can recognize syntax elements (even incomplete ones) and perform formatting with each keypress. That puts an additional requirement - the routine should be fast. No, it should be FASTER. As far as I know, there are no ready-to-use solutions for this. You should develop it yourself.

    For XML you'll need to recognize opening tags, attributes and nesting level. For complete tags you will need regular expressions. Once you recognize an opening tag you increment the nesting level and once the tag is closed you decrement it. Also remember that even Visual Studio doesn't format XML code immediately. You should invoke 'Format Document' menu command to format it.
    I suggest you follow the same path. Wait for the user to complete typing and then format the complete XML fragment using XMLWriter. It will be much easier and less time-consuming.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Sep 2010
    Location
    Connecticut
    Posts
    17

    Re: [RESOLVED] Auto Indent?!

    I could just do the XMLwriter method each time the user inputs a character. Put it in a try method incase the user didnt finish a tag, and it'll format wen the user has finished typing an unfinished tag. Any example on how to use the XMLWriter? I'm guessing its in System.XML namespace...

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width