【z】Storm - the world's best IDE framework for .NET

http://www.codeproject.com/Articles/42799/Storm-the-world-s-best-IDE-framework-for-NET

Storm - the world‘s best IDE framework for .NET

gone000, 4 Feb 2010

   4.96 (79 votes)
 
Rate this:
vote 1vote 2vote 3vote 4vote 5
 

Create fast, flexible, and extensible IDE applications easily with Storm - it takes nearly no code at all!

Moonlite, my IDE that I created with Storm (still WIP)

Introduction

I‘m currently making an IDE application called Moonlite. When I started coding it, I looked for good, already existing code for creating IDEs. I found nothing. So, when I was almost done with it (I‘m not done with it yet, because of this framework taking all my time), I figured that I found it rather unfair that everyone should go through the same as I did for making such an application. (It took me 8 months of hard work - about 7 - 10 hours a day - to create this. Not because the main coding would‘ve taken that long, but because I had to figure out how to do it and what was the most efficient solution.) So I started Storm, and now that it is finished, I‘m going to present it to you! 

Notices

Please note that I did this of my own free will and my own free time. I would be happy if you could respect me and my work and leave me a comment on how to make it better, bug reports, and so on. Thank you for your time 

Using the Code

Using the code is a simple task; simply drag-drop from the toolbox when you have referenced the controls you want, and that should be it. However, for those who want a more in-depth tutorial, go to the folder "doc" in the package and open "index.htm".

How it Works

In this chapter, I will mostly cover docking, plug-ins, and TextEditor, since they are the most advanced ones. I will not cover Win32 and TabControl.

CodeCompletion

CodeCompletion relies on the TextEditor, and it really isn‘t as advanced as some may think. It‘s just a control containing a generic ListBox that can draw icons. The ListBox‘ items are managed by the CodeCompletion itself.CodeCompletion handles the TextEditor‘s KeyUp event, and in that, it displays the members of the ListBox depending on what the user has typed in the TextEditor.

UpdateCodeCompletion is now contained in the TextEditor library!

Every time it registers a key press, it updates a string containing the currently typed string by calling a methodGetLastWord(), which returns the word that the user is currently on. How a string is split up in words is defined in the TextEditor as ‘separators‘. Every time GetLastWord() is called, CodeCompletion calls the native Win32 function ‘LockWindowUpdate‘ along with the parent TextEditor‘s handle to prevent flickering as the OS renderers the TextEditor/CodeCompletion.

Actually, CodeCompletion does this when it auto completes a selected item in the child GListBox, too. Every timeCodeCompletion registers a key that it doesn‘t recognize as a ‘valid‘ character (any non-letter/digit character that isn‘t _), it calls the method SelectItem() along with a specific CompleteType.

Now, what is a CompleteType? You see, CompleteType defines how the SelectItem() will act when auto completing a selected item in the GListBox. There are two modes - Normal and Parenthesis. When Normal is used, the SelectItem() method removes the whole currently typed word; Parenthesis, however, removes the whole currently typed word except the first letter. This might seem strange, but it is necessary when, for example, the user has typed a starting parenthesis. You might find yourself having a wrong auto completed word sometimes, too - this is where you should use Parenthesis instead of Normal as the CompleteType. (You are able to define a custom CompleteType when you add a member item to CodeCompletion.)

Since the users define the tooltips of member items themselves, it is rather easy to display the description of items. When a new item is selected in the GListBox, a method updates the currently displayed ToolTip to match the selected item‘s description/declaration fields. Since a normal TreeNode/ListBoxItem wouldn‘t be able to have multiple Tags, I created the GListBoxItem, which also contains an ImageIndex for the parent GListBoxImageList. The GListBoxItem contains a lot of values that are set by the user, either on initialization or through properties.

Each time the control itself or its tooltip is displayed, their positions are updated. The formula for the tooltip is this:Y = CaretPosition.Y + FontHeight * CaretIndex + Math.Ceiling(FontHeight + 2) for Y. The setting of X is simply CaretPositon.X + 100 + CodeCompletion.Width + 2. The formula for CodeCompletion‘s Y is the same as for the tooltip; however, X is different; X = CaretPosition.X + 100.

Docking

First, I will start out with a Class Diagram to help me out:

As you can see, there are a lot of classes. A DockPane can contain DockPanels, and DockPanels are the panels that are docked inside the DockPane. A DockPanel contains a FormDockCaption, and DockTab. When aDockPanel‘s Form property is set, the DockPanel updates the Form to match the settings needed for it to act as a docked form.

DockCaption is a custom drawn panel. It contains two Glyphs - OptionsGlyph and CloseGlyph - both inheriting the Glyph class, which contains the rendering logic for a general Glyph. The OptionsGlyph andCloseGlyph contain images that are supposed to have a transparent background. A lot of people use very complex solutions for this; however, I found a very, very simple and short solution:

 Collapse | Copy Code

/// <summary>
/// Represents an image with a transparent background.
/// </summary>
[ToolboxItem(false)]
public class TransImage
    : Panel
{
    #region Properties

    /// <summary>
    /// Gets or sets the image of the TransImage.
    /// </summary>
    public Image Image
    {
        get { return this.BackgroundImage; }
        set
        {
                if (value != null)
                {
                    Bitmap bitmap = new Bitmap(value);
                    bitmap.MakeTransparent();

                    this.BackgroundImage = bitmap;
                    Size = bitmap.Size;
                }
        }
        }

        #endregion

        /// <summary>

        /// Initializes a new instance of TransImage.
        /// </summary>
        /// <param name="image">Image that should
        ///        have a transparent background.</param>
        public TransImage(Image image)
        {
            // Set styles to enable transparent background
            this.SetStyle(ControlStyles.Selectable, false);
            this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);

            this.BackColor = Color.Transparent;
            this.Image = image;
        }
    }

As simple as that. A basic panel with transparent background, and of course, an Image property -Bitmap.MakeTransparent() does the rest. Panel is indeed a lovable control. As we proceed in this article, you‘ll find that I base most of my controls on Panel.

Well, the DockCaption handles the undocking of the DockPanel and the moving of the DockForm. Yeah,DockForm. When a DockPanel is undocked from its DockPane container, a DockForm is created, and theDockPanel is added to it. The DockForm is a custom drawn form which can be resized and moved, and looks much like the Visual Studio 2010 Docking Form.

Since the caption bar has been removed from the DockForm, the DockCaption takes care of the moving. This is where Win32 gets into our way - SendMessage and ReleaseCapture are used to do this.

When a DockPanel is added to a DockPane, and there‘s already a DockPanel docked to the side that the user wants to dock the new DockPanel, the DockPane uses the already docked DockPanel‘s DockTab to add the newDockPanel as a TabPage. The user can then switch between DockPanels.

The DockTab inherits the normal TabControl, and overrides its drawing methods. This means that it is completely customizable for the user and very flexible for us to use.

Plug-ins

The plug-ins library is one of the shorter; however, it is probably the most complex too. Since the PluginManagerclass has to locate dynamic link libraries, we should check whether they are actual plug-ins, check if they use the optional plugin attribute, and if they do, store the found information in an IPlugin, and add the found plug-in to the form given by the user if it‘s a UserControl.

So basically, most of these processes happen in the LoadPlugins method. However, the LoadPlugins method is just a wrapper that calls LoadPluginsInDirectory with the PluginsPath set by the user. Now, theLoadPluginsInDirectory method loops through all the files in the specific folder, checks whether their file extension is ".dll" (which indicates that the file is a code library), and then starts the whole "check if library contains plug-ins and check if the plug-ins have any attributes"-process:

This is done with the Assembly class, located in the System.Reflection namespace:

 Collapse | Copy Code

Assembly a = Assembly.LoadFile(file);

Then, an array of System.Type is declared, which is set to a.GetTypes(). This gives us an array of all types (class, enums, interfaces, etc.) in the assembly. We can then loop through each Type in the Type array and check whether it is an actual plug-in, by using this little trick:

 Collapse | Copy Code

(t.IsSubclassOf(typeof(IPlugin)) == true ||
    t.GetInterfaces().Contains(typeof(IPlugin)) == true)

Yeah - simple - this simply can‘t go wrong. Well, we all know that interfaces can‘t get initialized like normal classes. So, instead, we use the System.Activator class‘ CreateInstance method:

 Collapse | Copy Code

IPlugin currentPlugin = (IPlugin)Activator.CreateInstance(t);

Boom. We just initialized an interface like we would with a normal class. Neat, huh? Now, we just need to setup the initialized interface‘s properties to match the options of the PluginManager and the current environment. This can by used by the creator of the plug-ins to create more interactive plug-ins. When we‘ve done this, we simply addIPlugin to the list of loaded plug-ins in the PluginManager.

However, the plug-ins loaded by the PluginManager aren‘t enabled by default. This is where the user has to do some action. The user has to loop through all the IPlugins in the PluginManager.LoadedPlugins list, and call the PluginManager.EnablePlugin(plugin) method on it.

Now, if you have, for example, a plug-in managing form in your application, like Firefox, for example, you can use the PluginManager.GetPluginAttribute method to get an attribute containing information about the plug-in, if provided by the creator of the plug-in.

The way this works, is by creating an object array and setting it to the System.Type method,GetCustomAttributes(). The variable "type" is set to be the plug-in‘s Type property, which is set in the loading of a plug-in.

 Collapse | Copy Code

object[] pAttributes = type.GetCustomAttributes(typeof(Plugin), false);

Add it to the list of plug-ins:

 Collapse | Copy Code

attributes.Add(pAttributes[0] as Plugin);

And, when we‘re done looping, we‘ll finally return the list of found attributes.

TextEditor

Since I love my TextEditor, I will give you a little preview of what it‘s capable of. And it‘s not a little 

As you might have pictured already, this library has incredibly many classes/enums/interfaces/namespaces. Actually, there‘s so many that I won‘t put up a class diagram or explain the links between all the classes.

The TextEditor is basically just a container of the class TextEditorBase; it is actually TextEditorBase that contains all the logic for doing whatever you do in the TextEditor. The TextEditor only manages its fourTextEditorBases along with splitters when you‘ve split up the TextEditor in two or more split views.

However, the TexteditorBase doesn‘t take care of the drawing; it simply contains a DefaultPainter field which contains the logic for rendering all the different stuff. Whenever drawing is needed, the TextEditorBase calls the appropriate rendering methods in the DefaultPainter. The DefaultPainter also contains a method namedRenderAll which, as you might‘ve thought about already, renders all the things that are supposed to be rendered in the TextEditor.

Since the different highlighting modes are defined in XML sheets, an XML sheet reader is required. TheLanguageReader parses a given XML sheet and tells the parser how to parse each token it finds in the typed text in the TextEditor. A user does not use the LanguageReader directly; the user can either use theSetHighlighting method of a TextEditor, which is a wrapper, or use theTextEditorSyntaxLoader.SetSyntax method.

Unfortunately, I can‘t take credit for it all. I based it on DotNetFireball‘s CodeEditor; however, the code was so ugly, inefficient, and unstructured that it would probably have taken me less time to remake it from scratch than fix all these things. The code still isn‘t really that nice; however, it is certainly better than before.

Update: Since I have now gone through all source code and documented and updated it to fit my standards, I claim this TextEditor my own work. However, the way I do things are still the same as the original, therefore I credit the original creators.

I should probably mention that DotNetFireball did not create the CodeEditor. They simply took another component, the SyntaxBox, and changed its name. Just for your information.

Conclusion

So, as you can see (or, I certainly hope you can), it is a gigantic project, which is hard to manage, and I have one advice to you: don‘t do this at home. It has taken so much of my time, not saying that I regret it, but really, if such a framework already exists, why not use it? Making your own would be lame.

Not saying this for my own fault, so I can get more users, I‘m saying this because I don‘t want you to go through the same things I did for such ‘basic‘ things. (Not really basic, but stuff that modern users require applications to have.)

So yeah, I suppose that this is it. The place where you say ‘enjoy‘ and leave the last notes, etc. Yeah, enjoy it, and make good use of it - and let me see some awesome applications made with this, please 

Planned Updates

【z】Storm - the world's best IDE framework for .NET

时间: 2024-10-10 22:16:23

【z】Storm - the world's best IDE framework for .NET的相关文章

如何启用Oracle EBS Form监控【Z】

前言: 有时候,因某些需要,必须知道Oracle的Form被使用的情况,以方面我们做出决策: 例如,如果某个Form被使用的次数非常多,那么,这个Form的相关SQL代码就应该优先处理,以减少服务器负荷,从而提供系统运行速度. 或者,(特别是)在系统要升级的时候,这些数据就显得非常重要了:决定哪个Form应该留,哪个Form应该拿掉. 当然,这个信息只是做出决策的参考数据而已.1. 在Oracle EBS上进行Form跟踪的技术方法:Oracle EBS的一个Profile 提供此功能: Use

【转】storm 开发系列一 第一个程序

原文: http://blog.csdn.net/csfreebird/article/details/49104777 ------------------------------------------------------------------------------------------------- 本文将在本地开发环境创建一个storm程序,力求简单. 首先用mvn创建一个简单的工程hello_storm [plain] view plain copy print? mvn a

【Todo】Storm安装与实验

接上一篇Kafka的安装与实验: http://www.cnblogs.com/charlesblc/p/6046023.html 还有再上一篇Flume的安装与实验: http://www.cnblogs.com/charlesblc/p/6046023.html Storm的安装可以参考这篇: http://shiyanjun.cn/archives/934.html 有1.0后的版本,和0.x的版本,最后为了稳妥,还是下载了0.10的版本.

【Streaming】Storm内部通信机制分析

一.任务执行及通信的单元 Storm中关于任务执行及通信的三个概念:Worker(进程).Executor(线程)和Task(Spout.Bolt) 1.  一个worker进程执行的是一个Topology的子集(不会出现一个worker进程为多个Topology服务),一个worker进程会启动一个或多个executor线程来执行一个topology的component(Spout或Bolt),因此,一个运行中的topology就是由集群中多台物理机上的多个worker进程组成的: 2.  E

【原】storm组件(架构层面)

Strom集群遵循从主模式,主与从之间通过Zookeeper协作.架构层面上包括三个组件: 1) Nimbus Node 2)Supervisor Nodes 3)Zookeeper 其中Nimbus Node是Storm集群中master, 负责分发任务,监控集群状态,重启应用. Supervisor Nodes在Storm集群中负责执行Nimbus分发给它的任务. Nimbus与Supervisor通过Zookeeper协作,如把它们各自的运行信息存储到Zookeeper上. 如下是一张St

ASP.NET HttpModule URL 重写 (一) 【Z】

大家好,又来和大家见面了,此次给大家带来的URL重写,关于URL重写是什么,有什么好处,如何重写,今天我和大家一起分享一下我的经验 一.URL重写 URL重写就是首先获得一个进入的URL请求然后把它重新写成网站可以处理的另一个URL的过程.举个例子来说,如果通过浏览器进来的URL是“UserProfile.aspx?ID=1”那么它可以被重写成 “UserProfile/1.aspx”. 二.URL重写优点 1.有利于百度.谷歌等搜索引擎收录于抓取,如果你是网站优化高手的化,这就是基本功了...

How to set an Apache Kafka multi node – multi broker cluster【z】

Set a multi node Apache ZooKeeper cluster On every node of the cluster add the following lines to the file kafka/config/zookeeper.properties server.1=zNode01:2888:3888 server.2=zNode02:2888:3888 server.3=zNode03:2888:3888 #add here more servers if yo

一个还不错的gridview 样式【Z】

<style type="text/css"> <!-- .datable {background-color: #9FD6FF; color:#333333; font-size:12px;} .datable tr {height:20px;} .datable .lup {background-color: #C8E1FB;font-size: 12px;color: #014F8A;} .datable .lup th {border-top: 1px sol

【Z】段错误Segment Fault定位,即core dump文件与gdb定位

使用C++开发系统有时会出现段错误,即Segment Fault.此类错误程序直接崩溃,通常没有任何有用信息输出,很难定位bug,因而无从解决问题.今天我们介绍core dump文件,并使用gdb进行调试,以此来定位段错误问题.此文同时用以备忘. 一.core dump Core dump也称核心转储, 当程序运行过程中异常退出时, 由操作系统把程序当前的内存状况存储在一个core文件中, 称之为core dump文件. 系统默认不生成core dump文件,可以使用ulimit命令进行查看和设