How to implement code folding in C #

I'm starting to work on the COBOL / BASIC IDE at work (to replace the one we currently have is a small step from Notepad). This will be done in C #. The manual is really interested in implementing some functions like Visual Studio, and the big one is code folding. I looked at MSDN, but I did not see any good ways to collapse lines (or add expand / collapse buttons).

I assume the text area should be a RichTextBox. I'm here? I assume that this can be done using some kind of modified TreeView, but this seems a bit wrong to me. Is there any way to do this that I'm just missing?

+4
source share
5 answers

Why not use your existing IDE and extend it? Writing one from scratch is a huge job (you need a parser, lexer, syntax, and more), and even more difficult if you need to support multiple languages ​​(you specify COBOL and Basic).

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

Edit : Eclipse is another great development environment that has similar support, and as mentioned in the comments, there is a COBOL plugin.

+11
source

I suggest you take a look at SharpDevelop . This is a pretty good IDE with a bunch of Visual Studio, such as already built-in functions. It is written in C # and fully supports code folding with syntax highlighting in several languages. In addition, it is Open Source under the LGPL license. So, if you do not want to use your application in SharpDevelop, you can reuse some of your controls, such as a code editor or toolkit for windows.

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

+6
source

Sometimes embedding Eclipse or a full-fledged editor is not suitable. For some other reason, this is redundant or redundant, or wrong. I appreciate the first tendency suggested in other posts not to reinvent here, but in some cases a little invention is required. For example, the text field used to create messages .... is neither Eclipse nor the built-in Visual Studio. I wonder why?

It is important to ask a question - to build or buy? - but sometimes the correct answer is BUILD IT.


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

Look at that.

alt text

To dynamically implement coloring of XML syntax, when a user enters text, he uses a separate background thread. The reasons and some details are described in a separate answer about stack overflow .

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

+4
source

If your command is used for "Visual Studio functions," I will assume that you use Visual Studio there in the office. Here are my suggestions:

  • Connect the IDE to Visual Studio for the following reasons:
    • Use Visual Studio 2010 if possible. SDK is significantly different since 2008 / earlier.
    • Use Visual Studio 2008/2005 otherwise. Currently, 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 , if you do not decide to use the existing Eclipse plug-in, saving the time of creating a new IDE.
  • If your team does not use Visual Studio 2010, you can use the Visual Studio 2010 shell in integrated mode for free (stand-alone mode is not what you want). This allows you to use Visual Studio 2010 for your development environment at the moment, and if the team upgrades later to one of the full versions of Visual Studio 2010, the IDE for your language will be fully integrated into the full version. Edit: Visual Studio Shell is basically the core of Visual Studio without any specific languages ​​(C #, C ++, VB, etc.). Microsoft provides this kernel for free, and it is a great option especially for people interested in creating their own language support.

Read my answers in the following two questions:

+3
source

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

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

+2
source

Source: https://habr.com/ru/post/1303340/


All Articles