4

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?

HaskellElephant
  • 9,819
  • 4
  • 38
  • 67
ctoneal
  • 412
  • 4
  • 14
  • 3
    Why not just use the Eclipse COBOL plug in? – Travis Gockel Mar 06 '10 at 14:40
  • (Edit: Moved comment up here) Unfortunately, my company is extremely paranoid about anything new, and attempting to get a piece of outside software approved for use is virtually impossible. It also needs to integrate with our (proprietary) version control system. Essentially, if it's not created by someone in-house, it's not getting used. We're even having to hide the fact that we're using C# from the upper management, because any deviation from C++ and MFC is viewed as too much change. It's a miracle that I've gotten this project approved to begin with. – ctoneal Mar 06 '10 at 15:04
  • 1
    @ctoneal: Does your company currently use Visual Studio? Does it integrate with your version control? If not, what are you using that does integrate with your version control? – Sam Harwell Mar 06 '10 at 15:06
  • 1
    even if your company is that paranoid, I would still look at SharpDevelop. It's written in C# and has a good code editor control. Even if you don't base the new app on SharpDevelop, you can still reuse their code editor that already has folding and syntax highlighting. The LGPL license means you can include it in a closed source app without royalties. You should take a look. – Mark Ewer Mar 06 '10 at 15:13
  • 2
    @ctoneal: may I suggest you run for it? Clearly your employer doesn’t foster a healthy workplace. – Konrad Rudolph Mar 06 '10 at 15:13
  • My department uses Visual Studio 2005, but we're making this for the other programming department (they code the business logic, which is all done in either COBOL or PICK-BASIC). We do have our version control system integrated with VS. The other programming department has no real version control (they just make copies of files, and merge them by hand), so they're being moved to our version control system. Basically, I'm trying to make another department's life easier with this. – ctoneal Mar 06 '10 at 15:22
  • @ctoneal: Most of my IDE examples target Visual Studio 2005/2008 (their SDKs are *very* similar). If you have it available, why not use it? – Sam Harwell Mar 06 '10 at 15:47
  • 4
    Your company is extremely paranoid about anything new, so they want you to write something completely new? :-) – Ken Mar 06 '10 at 15:54

5 Answers5

11

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
  • 489,969
  • 99
  • 883
  • 1,009
  • 2
    @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 Mar 06 '10 at 15:06
6

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
  • 1,835
  • 13
  • 25
  • 1
    Wow, three comments that all say "don't re-invent the IDE" in less time than I could type my response... – Mark Ewer Mar 06 '10 at 14:45
4

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 Stack Overflow 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 Stack Overflow.

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

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Cheeso
  • 189,189
  • 101
  • 473
  • 713
  • 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. – Sam Harwell Mar 06 '10 at 15:02
  • @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 Mar 06 '10 at 15:12
3

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:

Community
  • 1
  • 1
Sam Harwell
  • 97,721
  • 20
  • 209
  • 280
  • @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 Mar 06 '10 at 16:17
  • 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 Mar 06 '10 at 16:54
  • @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). – Sam Harwell Mar 06 '10 at 17:32
2

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
  • 67,989
  • 17
  • 150
  • 217