⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ide.cs

📁 compiler programming, code something
💻 CS
📖 第 1 页 / 共 3 页
字号:
/*
Magic IDE
Copyright (C) 2003  Michael Bebenita

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

using Crownwood.Magic;
using Crownwood.Magic.Docking;
using Crownwood.Magic.Common;

using UtilityLibrary.Menus;
using UtilityLibrary.CommandBars;
using UtilityLibrary.WinControls;
using UtilityLibrary.General;
using UtilityLibrary.Win32;
using UtilityLibrary.Collections;

using System.Diagnostics;
using System.IO;

using ICSharpCode.TextEditor;
using System.Runtime.InteropServices;

using Core;
using Core.Compilation;

namespace Magic_IDE
{
	public enum IconIndex
	{
		Project_Explorer = 51,
		Object_Explorer = 53,
		Parse_Tree = 4,
		New_Project = 65,
		New_File = 85,
		Open_Project = 84,
		Open_File = 35,
		Save_File = 0,
		Save_Files = 1,
		Output = 52,
		Build = 31,

		File = 88,
		Project = 51,

		Terminal = 7,
		NonTerminal = 6,

		Module = 6,
		Structure = 8,
		Function = 12,
		Variable = 16,
		Expression = 41,
		Body = 47
	}
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class IDE : System.Windows.Forms.Form
	{
		[DllImport("User32.Dll")]
		private static extern int SendMessage(IntPtr hWnd,int Msg,int  wParam,int  lParam);			
	

		private System.ComponentModel.IContainer components;

		public IDE()
		{
			//
			// Required for Windows Form Designer support
			//

			InitializeComponent();
			InitializeImageLists();
			InitializeDockingSystem();
			InitializeMenu();

			InitializeCompiler();

			UpdateUIState();
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			// 
			// IDE
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(688, 422);
			this.Name = "IDE";
			this.Text = "Sharp IDE";
			this.Closing += new System.ComponentModel.CancelEventHandler(this.IDE_Closing);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			//Application.Run(new Test());
			Application.Run(new IDE());
		}

		private DockingManager m_Docker = null;
		private TreeView m_tvProjectExplorer = null;
		private TreeView m_tvObjectExplorer = null;
		private TreeView m_tvParseTree = null;
		private TreeView m_tvSyntaxTree = null;

		private RichTextBox m_Output = null;
		private Crownwood.Magic.Controls.TabControl m_Files = null;
		private StatusBar m_Status = null;
		private ImageList m_ImageList = null;

		private Language m_Language = null;

		private void InitializeCompiler()
		{
			m_Language = Language.FromFile("Sharp.cgt");
		}

		private void InitializeImageLists()
		{
			Bitmap strip = (Bitmap)Bitmap.FromFile("Images.bmp");
			m_ImageList = new ImageList();
			m_ImageList.ImageSize = new Size(16,16);
			m_ImageList.TransparentColor = Color.FromArgb(0,255,0);
			m_ImageList.Images.AddStrip(strip);
		}

		Content m_OutputContent = null;
		Content m_ProjectExplorerContent = null;
		Content m_ObjectExplorerContent = null;
		Content m_ParseTreeContent = null;
		Content m_SyntaxTreeContent = null;

		private void InitializeDockingSystem()
		{
			//
			// Setup File Tabs
			//

			m_Files = new Crownwood.Magic.Controls.TabControl();
			m_Files.Appearance = Crownwood.Magic.Controls.TabControl.VisualAppearance.MultiDocument;
			m_Files.Dock = DockStyle.Fill;
			m_Files.Style = Crownwood.Magic.Common.VisualStyle.IDE;
			m_Files.IDEPixelBorder = true;

			m_Files.ClosePressed += new EventHandler(OnFilesClosed);
			m_Files.PageGotFocus += new EventHandler(OnPageGotFocus);

			Controls.Add(m_Files);

			m_Docker = new DockingManager(this, Crownwood.Magic.Common.VisualStyle.IDE);

			//
			// Setup Output
			//

			m_Output = new RichTextBox();
			m_Output.WordWrap = false;
			m_Output.ScrollBars = RichTextBoxScrollBars.Both;
			m_Output.Font = new Font("Courier New",8);
			m_Output.BackColor = Color.Black;
			m_Output.ForeColor = Color.GreenYellow;

			m_OutputContent = m_Docker.Contents.Add(
				m_Output, "Output");
			m_OutputContent.ImageList = m_ImageList;
			m_OutputContent.ImageIndex = (int)IconIndex.Output;
			WindowContent bottomWindow = m_Docker.AddContentWithState(
				m_OutputContent, Crownwood.Magic.Docking.State.DockBottom) as WindowContent;

			//
			// Setup Project and Object explorers.
			//

			// Project Explorer
			m_tvProjectExplorer = new TreeView();
			m_tvProjectExplorer.ImageList = m_ImageList;
			m_tvProjectExplorer.DoubleClick += new EventHandler(OnProjectExplorerDoubleClick);
			m_ProjectExplorerContent = m_Docker.Contents.Add(
				m_tvProjectExplorer, "Project Explorer");
			m_ProjectExplorerContent.ImageList = m_ImageList;
			m_ProjectExplorerContent.ImageIndex = (int)IconIndex.Project_Explorer;

			WindowContent leftWindow = m_Docker.AddContentWithState(
				m_ProjectExplorerContent, Crownwood.Magic.Docking.State.DockLeft) as WindowContent;

			// Object Explorer
			m_tvObjectExplorer = new TreeView();
			m_tvObjectExplorer.ImageList = m_ImageList;
			m_ObjectExplorerContent = m_Docker.Contents.Add(
				m_tvObjectExplorer, "Object Explorer");
			m_ObjectExplorerContent.ImageList = m_ImageList;
			m_ObjectExplorerContent.ImageIndex = (int)IconIndex.Object_Explorer;
			m_Docker.AddContentToWindowContent(m_ObjectExplorerContent, leftWindow);

			// Parse Tree
			m_tvParseTree = new TreeView();
			m_tvParseTree.ImageList = m_ImageList;
			m_ParseTreeContent = m_Docker.Contents.Add(m_tvParseTree,"Parse Tree");
			m_ParseTreeContent.ImageList = m_ImageList;
			m_ParseTreeContent.ImageIndex = (int)IconIndex.Parse_Tree;
			m_Docker.AddContentToWindowContent(m_ParseTreeContent, leftWindow);

			// Syntax Tree
			m_tvSyntaxTree = new TreeView();
			m_tvSyntaxTree.ImageList = m_ImageList;
			m_SyntaxTreeContent = m_Docker.Contents.Add(m_tvSyntaxTree,"Syntax Tree");
			m_SyntaxTreeContent.ImageList = m_ImageList;
			m_SyntaxTreeContent.ImageIndex = (int)IconIndex.Parse_Tree;
			m_Docker.AddContentToWindowContent(m_SyntaxTreeContent, leftWindow);

			m_Status = new StatusBar();
			m_Status.Dock = DockStyle.Bottom;
			Controls.Add(m_Status);
			m_Docker.InnerControl = m_Files;
			m_Docker.OuterControl = m_Status;
			m_Docker.HideAllContents();
			m_Docker.ShowAllContents();
			m_Docker.LoadConfigFromFile("Config.dck");
		}

		private ReBar m_Toolbars = null;

		private ToolBarEx m_Menu = null;
			private ToolBarItem m_FileMenu = null;
				private MenuItemEx m_New = null;
					private MenuItemEx m_NewProject = null;
					private MenuItemEx m_NewFile = null;

				private MenuItemEx m_OpenProject = null;
				private MenuItemEx m_CloseProject = null;

				private MenuItemEx m_SaveFile = null;
				private MenuItemEx m_SaveAllFiles = null;

				private MenuItemEx m_Exit = null;
			private ToolBarItem m_ProjectMenu = null;
				private MenuItemEx m_AddNewFile = null;
				private MenuItemEx m_RemoveFile = null;
				private MenuItemEx m_DeleteFile = null;

			private ToolBarItem m_ViewMenu = null;
				private MenuItemEx m_ViewProjectExplorer = null;
				private MenuItemEx m_ViewObjectExplorer = null;
				private MenuItemEx m_ViewOutput = null;

			private ToolBarItem m_ToolsMenu = null;
				private MenuItemEx m_BuildParseTree = null;
				private MenuItemEx m_BuildSyntaxTree = null;
					
		private ToolBarEx m_Tools = null;
			private ToolBarItem m_NewTool = null;
				private MenuItemEx m_NewProjectTool = null;
				private MenuItemEx m_NewFileTool = null;
			private ToolBarItem m_AddNewFileTool = null;
			private ToolBarItem m_SaveFileTool = null;
			private ToolBarItem m_SaveAllFilesTool = null;
			private ToolBarItem m_BuildTool = null;

		private ToolBarEx m_FullScreenTools = null;
			private ToolBarItem m_FullScreenTool = null;

		private void InitializeMenu()
		{
			//
			// Menu
			//

			ToolBarEx m_Menu = new ToolBarEx(BarType.MenuBar);
			m_Menu.ImageList = m_ImageList;

			m_FileMenu = new ToolBarItem("&File");
				m_New = new MenuItemEx("&New",null);
					m_NewProject = new MenuItemEx("&Project",m_ImageList,(int)IconIndex.New_Project,Shortcut.CtrlShiftN,new EventHandler(OnNewProject));
					m_NewFile = new MenuItemEx("&File",m_ImageList,(int)IconIndex.New_File,Shortcut.CtrlN,new EventHandler(OnNewFile));
					m_New.MenuItems.Add(m_NewProject);
					m_New.MenuItems.Add(m_NewFile);

				m_OpenProject = new MenuItemEx("&Open Project",m_ImageList,(int)IconIndex.Open_Project,Shortcut.CtrlO,new EventHandler(OnOpenProject));
				m_CloseProject = new MenuItemEx("&Close Project",new EventHandler(OnCloseProject));
				m_SaveFile = new MenuItemEx("&Save File",m_ImageList,(int)IconIndex.Save_File,Shortcut.CtrlS ,new EventHandler(OnSaveFile));
				m_SaveAllFiles = new MenuItemEx("&Save All",m_ImageList,(int)IconIndex.Save_Files,Shortcut.CtrlShiftS,new EventHandler(OnSaveAllFiles));
				m_Exit = new MenuItemEx("&Exit",new EventHandler(OnExit));

			m_FileMenu.MenuItems.Add(m_New);
			m_FileMenu.MenuItems.Add(m_OpenProject);
			m_FileMenu.MenuItems.Add(m_CloseProject);
			m_FileMenu.MenuItems.Add(new MenuItemEx("-",null));
			m_FileMenu.MenuItems.Add(m_SaveFile);
			m_FileMenu.MenuItems.Add(m_SaveAllFiles);
			m_FileMenu.MenuItems.Add(new MenuItemEx("-",null));
			m_FileMenu.MenuItems.Add(m_Exit);

			m_ViewMenu = new ToolBarItem("&View");
			m_ViewProjectExplorer = new MenuItemEx("&Project Explorer",m_ImageList,(int)IconIndex.Project_Explorer,Shortcut.CtrlShiftP,new EventHandler(OnView));
			m_ViewObjectExplorer = new MenuItemEx("&Object Explorer",m_ImageList,(int)IconIndex.Object_Explorer,Shortcut.CtrlShiftB,new EventHandler(OnView));
			m_ViewOutput = new MenuItemEx("&Output",m_ImageList,(int)IconIndex.Output,Shortcut.CtrlShiftO,new EventHandler(OnView));

			m_ViewMenu.MenuItems.Add(m_ViewProjectExplorer);
			m_ViewMenu.MenuItems.Add(m_ViewObjectExplorer);
			m_ViewMenu.MenuItems.Add(m_ViewOutput);

			m_ProjectMenu = new ToolBarItem("&Project");
			m_ProjectMenu.DropDown += new EventHandler(OnProjectMenuDropDown);

				m_AddNewFile = new MenuItemEx("&Add Exisiting File",m_ImageList,(int)IconIndex.New_File,Shortcut.None,new EventHandler(OnAddFile));
				m_RemoveFile = new MenuItemEx("&Remove File",new EventHandler(OnRemoveFile),Shortcut.CtrlR);
				m_DeleteFile = new MenuItemEx("&Delete File",new EventHandler(OnDeleteFile),Shortcut.CtrlD);
				m_ProjectMenu.MenuItems.Add(m_AddNewFile);
				m_ProjectMenu.MenuItems.Add(m_RemoveFile);
				m_ProjectMenu.MenuItems.Add(m_DeleteFile);
				
			m_ToolsMenu = new ToolBarItem("&Tools");
			m_ToolsMenu.DropDown += new EventHandler(OnToolsMenuDropDown);
				m_BuildParseTree = new MenuItemEx("Build &Parse Tree",m_ImageList,(int)IconIndex.Parse_Tree,Shortcut.CtrlP,new EventHandler(OnBuildParseTree));
				m_BuildSyntaxTree = new MenuItemEx("Build &Syntax Tree",m_ImageList,(int)IconIndex.Parse_Tree,Shortcut.CtrlS,new EventHandler(OnBuildSyntaxTree));
				m_ToolsMenu.MenuItems.Add(m_BuildParseTree);
				m_ToolsMenu.MenuItems.Add(m_BuildSyntaxTree);

			m_Menu.Items.Add(m_FileMenu);
			m_Menu.Items.Add(m_ViewMenu);
			m_Menu.Items.Add(m_ProjectMenu);
			m_Menu.Items.Add(m_ToolsMenu);

			//
			// Toolbar
			//

			m_Tools = new ToolBarEx();
			m_Tools.ImageList = m_ImageList;

			m_NewTool = new ToolBarItem();
			m_NewTool.ImageListIndex = (int)IconIndex.New_Project;
			m_NewTool.Style = ToolBarItemStyle.DropDownButton;
			m_NewTool.DropDown += new EventHandler(OnToolbarDropDown);
			m_NewTool.Text = "New";
				m_NewProjectTool = new MenuItemEx("&Project",m_ImageList,(int)IconIndex.New_Project,Shortcut.None,new EventHandler(OnNewProject));
				m_NewFileTool = new MenuItemEx("&File",m_ImageList,(int)IconIndex.New_File,Shortcut.None,new EventHandler(OnNewFile));
			m_Tools.Items.Add(m_NewTool);

			m_AddNewFileTool = new ToolBarItem();
			m_AddNewFileTool.ImageListIndex = (int)IconIndex.New_File;
			m_AddNewFileTool.Style = ToolBarItemStyle.PushButton;
			m_AddNewFileTool.Text = "Add Existing File";
			m_AddNewFileTool.Click += new EventHandler(OnAddFile);
			m_Tools.Items.Add(m_AddNewFileTool);

			m_SaveFileTool = new ToolBarItem();
			m_SaveFileTool.ImageListIndex = (int)IconIndex.Save_File;
			m_SaveFileTool.Style = ToolBarItemStyle.PushButton;
			m_SaveFileTool.Text = "Save File";
			m_SaveFileTool.Click += new EventHandler(OnSaveFile);
			m_Tools.Items.Add(m_SaveFileTool);

			m_SaveAllFilesTool = new ToolBarItem();
			m_SaveAllFilesTool.ImageListIndex = (int)IconIndex.Save_Files;
			m_SaveAllFilesTool.Style = ToolBarItemStyle.PushButton;
			m_SaveAllFilesTool.Text = "Save All";
			m_SaveAllFilesTool.Click += new EventHandler(OnSaveAllFiles);
			m_Tools.Items.Add(m_SaveAllFilesTool);

			ToolBarItem separator = new ToolBarItem();
			separator.Style = ToolBarItemStyle.Separator;
			m_Tools.Items.Add(separator);
			
			m_BuildTool = new ToolBarItem();
			m_BuildTool.ImageListIndex = (int)IconIndex.Build;
			m_BuildTool.Style = ToolBarItemStyle.PushButton;
			m_BuildTool.Click += new EventHandler(OnBuild);
			m_BuildTool.Text = "Build";
			m_Tools.Items.Add(m_BuildTool);

			//
			// Full Screen Tools
			//

			m_FullScreenTools = new ToolBarEx();
			m_FullScreenTools.ImageList = m_ImageList;

			m_FullScreenTool = new ToolBarItem();
			m_FullScreenTool.Style = ToolBarItemStyle.PushButton;
			m_FullScreenTool.Text = "Full Screen";
			m_FullScreenTool.Click += new EventHandler(OnFullScreenTool);

			m_FullScreenTools.Items.Add(m_FullScreenTool);

			// ////////////////////////////

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -