views:

695

answers:

5

I'm beginning to work on a COBOL/BASIC IDE at work (to replace the one that we have currently that's a slight step up from Notepad). It'll be made in C#. The management is really interested in implementing some Visual Studio type features, and a big one is code folding. I've looked on MSDN, but I didn't see any good way to collapse lines (or to add the expand/collapse buttons).

I'm assuming that the text area should be a RichTextBox. Am I off track here? I suppose it could be done with some sort of modified TreeView, but that seems a little wrong to me. Is there some way of doing this that I'm just missing?

+2  A: 

Writing a complete IDE is a HUGE task. I would recommend trying to find an existing one that has what you want, or make adaptions to an existing open source IDE.

To answer your question: I guess that the Visual Studio IDE uses a custom control, written from scratch, rather than a RichText control.

Anders Abel
+11  A: 

Why not use an existing IDE and extend it? Writing one from scratch is a huge undertaking (you need a parser, lexer, syntax highlighter and more), and is even more complicated if you need to support multiple languages (you mention COBOL and Basic).

Notepad++ has syntax coloring and one can add languages to it - COBOL is one of the ones installed by default. It supports code folding and has many plugins (you can write your own, that will suit your needs).

Edit: Eclipse is another excellent IDE that has similar support, and as mentioned in the comments has a COBOL plug-in.

Oded
@ctoneal - sorry to hear about your constraints. Visual Studio code folding is custom made. I would look at some of the open source IDE code out there (Notepad++, Eclipe, SharpDevelop, MonoDevelop to name a few) and see how _they_ implemented it. That will give you an idea.
Oded
+5  A: 

I suggest you take a look at SharpDevelop. It's a pretty good IDE with a bunch of Visual Studio like features already built in. It's written in C# and fully supports code folding with syntax highlighting in several languages. Plus, it's Open Source under the LGPL license. So, if you don't want to base your app on SharpDevelop then you can still reuse some of their controls like the code editor or windowing toolkit.

You should consider adding the COBOL language to SharpDevelop instead of starting from scratch. If you can't do this, then you can still use the SharpDevelop code as a decent reference on how to make a good IDE work.

Mark Ewer
Wow, three comments that all say "don't re-invent the IDE" in less time than I could type my response...
Mark Ewer
+4  A: 

Whoa!

what's with the non-commenting downvote?

I'm guessing it's because I actually answered the question, rather than dismissing the question as a dumb idea.

Look, sometimes embedding Eclipse or a full-fledged editor is not appropriate. It's overkill or overweight or wrong for some other reason. I appreciate the first inclination suggested in other posts to not re-invent here, but in some cases a small invention is what is necessary. For example, the textbox used to make StackOverflow posts .... is neither Eclipse nor an embedded Visual Studio. I wonder why?

It's important to ask the question - build it or buy it? - but sometimes, the correct answer is BUILD IT.


XPathVisualizer provides a simple example of a code-folding text editor implemented in C#, and based on a RichTextBox. It's not VB, though - it's an XML editor. But the general principles apply.

Here's a look at it.

alt text

To implement XML syntax colorization dynamically, while the user types, it uses a separate background thread. The reasons why and some of the details are described in a separate answer on StackOverflow.

You could do something similar for your COBOL/VB thing. XPathVisualizer is open source, licensed with MS-PL, so you can browse and borrow.

Cheeso
I didn't vote you down, but for a full IDE (as opposed to just syntax highlighting, brace matching, and collapsing code), it's a complete waste of time to start with anything other than a high quality IDE with a full SDK.
280Z28
upvoted (9 chars)
Mike Dunlavey
@280Z28, ya, I agree, building a full-featured IDE would cost millions, and starting with a RichTextBBox for that job would be dumb. But sometimes "IDE" doesn't mean "an IDE on par with Visual-Studio". In my jobs where we produced tools with emebdded editors, they were limited power, limited scope. Basically notepad plus code folding. And it's not worth bundling Eclipse or VS to get that basic function.
Cheeso
+3  A: 

If your team is used to "Visual Studio features," then I'll assume you use Visual Studio there at the office. Here are my suggestions:

  • Base your IDE on Visual Studio, for the following reasons:
    • Use Visual Studio 2010 if possible. The SDK is greatly improved from 2008/earlier.
    • Use Visual Studio 2008/2005 otherwise. At the moment, all of my commercial IDE products only support 2005/2008.
    • If your team uses Visual Studio, they will hate Eclipse. Not even an option to consider in this case unless you choose to use an existing Eclipse plug-in, saving you the time of creating a new IDE.
  • If your team isn't using Visual Studio 2010, you can use the Visual Studio 2010 Shell in Integrated Mode for free (Isolated Mode is not what you want). This lets you use Visual Studio 2010 for your IDE for now, and should the team upgrade later to one of the full versions of Visual Studio 2010, the IDE for your language will cleanly integrate into the full version. Edit: Visual Studio Shell is basically the core of Visual Studio without any specific languages (C#, C++, VB, etc.) included. Microsoft provides this core for free, and it's a great option specifically for people interested in creating their own language support.

Read my answers in the following two questions:

280Z28
@280Z28: Great answer. What would make it better is an explanation of the Visual Studio Shell, and the fact that Visual Studio is already Shell+Extensions. Readers unfamiliar with VSX may not believe this to be possible.
John Saunders
After looking around a bit, it does seem that using Visual Studio Shell and extending it with language support would make some sense (the question of whether the management will approve is another story). Why would I not want Isolated Mode though? I'm not really clear on the differences. Is it solely based on the ability to integrate back into VS in the future?
ctoneal
@ctoneal: If you extend Visual Studio 2005, you won't need to introduce any new software (should they not approve the new shell). Isolated mode is easier to customize if you are trying to rebrand/customize the *entire* environment (all menus, dialogs, etc.). Most of the time it's just extra overhead, plus integrated mode *is* easier to integrate back into VS in the future (Isolated Mode is for people who actively intend to not integrate back into VS).
280Z28