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

📄 mainform.cs

📁 C#实现DHTML编辑器功能!
💻 CS
📖 第 1 页 / 共 4 页
字号:
// DINAMIC XML Editor
//
// Copyright (c) 2002-2003 Dusan Hlavaty
// mailto: duddo@atlas.cz
//
// This software is licensed under the terms of
// GNU General Public license
//
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
//using System.Data;

using Crownwood.Magic.Menus;

using XML_editor.DockingPanels;
using XML_editor.Common;

namespace XML_editor.MyForms
{

	/// <summary>
	/// Tento delegat je pouzivany pre <see cref="MainForm.TextAreaControlClosed"/> event.
	/// </summary>
	/// <param name="tab"><see cref="XML_editor.TabPages.TextAreaTabPage"/>, ktory sa prave zatovril.
	/// <c>null</c> - ak sa zatvorili vsetky</param>
	public delegate void TextAreaControlClosedHandler(XML_editor.TabPages.TextAreaTabPage tab);

	/// <summary>
	/// Hlavny formular (okno) celej aplikacie
	/// </summary>
	public class MainForm : Form
	{
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		/// <summary>
		/// Status bar - zobrazuje stavove informacie
		/// </summary>
		private XML_editor.MyComponents.SdStatusBar statusBar = null;
		
		/// <summary>
		/// Tool bar
		/// </summary>
		private AxToolBar toolBar = null;

		/// <summary>
		/// <see cref="Crownwood.Magic.Controls.TabControl"/> ktory sa bude starat
		/// o jednotlive okna editora.
		/// </summary>
		private Crownwood.Magic.Controls.TabControl tabControl = null;

		/// <summary>
		/// Docking manazer, ktory sa bude starat o vsetky okna, ktore sa
		/// budu dat v aplikacii dokovat.
		/// </summary>
		private Crownwood.Magic.Docking.DockingManager dockingManager = null;

		/// <summary>
		/// V tejto 'hesovacej' tabulke su ulozene vsetky dokovatelne panely,
		/// ktore sa v aplikacii mozu vyskytovat.
		/// </summary>
		private Hashtable dockingPanels = new Hashtable();

		/// <summary>
		/// Hlavne menu aplikacie
		/// </summary>
		private Crownwood.Magic.Menus.MenuControl topMenu;

		/// <summary>
		/// Vizualny styl, ktory budu pouzivat vsetky komponenty aplikacie
		/// </summary>
		private Crownwood.Magic.Common.VisualStyle commonVisualStyle;

		/// <summary>
		/// Odkaz na aktualny <see cref="DLTextEditor.TextAreaControl"/>, ktory je prave 'navrchu'
		/// </summary>
		private DLTextEditor.TextAreaControl actualTextAreaControl = null;

		/// <summary>
		/// Odkaz na 'hladaci formular'
		/// </summary>
		private SearchForm searchForm = null;


		// -------------------------------------------------------------------------
		/// <summary>
		/// Aktualny <see cref="DLTextEditor.TextAreaControl"/>, ktory je prave 'navrchu'
		/// </summary>
		public DLTextEditor.TextAreaControl ActualTextAreaControl
		{
			get 
			{
				return this.actualTextAreaControl;
			}
			set 
			{
				if (Object.ReferenceEquals(this.actualTextAreaControl, value) != true)
				{
					this.actualTextAreaControl = value;
					this.OnActualTextAreaControlChanged();
				}
			}
		}

		// -------------------------------------------------------------------------
		/// <summary>
		/// Prave aktivny <see cref="XML_editor.TabPages.TextAreaTabPage"/> - teda
		/// ten ktory je 'navrchu'
		/// </summary>
		public XML_editor.TabPages.TextAreaTabPage SelectedTabPage
		{
			get 
			{
				if (this.tabControl.SelectedTab == null) 
				{
					return null;
				}
				return ((XML_editor.TabPages.TextAreaTabPage)this.tabControl.SelectedTab);
			}
		}

		// -------------------------------------------------------------------------
		/// <summary>
		/// Docking manazer, ktory sa bude starat o vsetky okna, ktore sa
		/// budu dat v aplikacii dokovat.
		/// </summary>
		public Crownwood.Magic.Docking.DockingManager DockingManager
		{
			get 
			{
				return this.dockingManager;
			}
		}

		// -------------------------------------------------------------------------
		/// <summary>
		/// Dokovaci panel, do ktoreho sa budu vypisovat vysledky operacii
		/// </summary>
		public OutputPanel OutputPanel
		{
			get 
			{
				OutputPanel panel = (this.dockingPanels["OutputPanel"] as OutputPanel);
				if (panel == null) 
				{
#if DEBUG
					System.Diagnostics.Debug.Write("Creating OutputPanel docking panel");
#endif
					panel = new OutputPanel(this, this.dockingManager);
					this.dockingPanels.Add("OutputPanel", panel);
#if DEBUG
					System.Diagnostics.Debug.WriteLine("- OK");
#endif
				} 
				else 
				{
#if DEBUG
					System.Diagnostics.Debug.WriteLine("Found OutputPanel docking panel - using it");
#endif
				}
				return panel;
			}
		}

		// -------------------------------------------------------------------------
		/// <summary>
		/// Dokovaci panel, do ktoreho ktory bude obsahovat TaskList
		/// </summary>
		public TaskListPanel TaskListPanel
		{
			get 
			{
				TaskListPanel panel = (this.dockingPanels["TaskListPanel"] as TaskListPanel);
				if (panel == null) 
				{
#if DEBUG
					System.Diagnostics.Debug.Write("Creating TaskListPanel docking panel");
#endif
					panel = new TaskListPanel(this, this.dockingManager);
					this.dockingPanels.Add("TaskListPanel", panel);
#if DEBUG
					System.Diagnostics.Debug.WriteLine("- OK");
#endif
				} 
				else 
				{
#if DEBUG
					System.Diagnostics.Debug.WriteLine("Found TaskListPanel docking panel - using it");
#endif
				}
				return panel;
			}
		}

		// -------------------------------------------------------------------------
		/// <summary>
		/// Kolekcia vsetkych TabPages v programe
		/// </summary>
		public Crownwood.Magic.Collections.TabPageCollection TabPages
		{
			get 
			{
				return this.tabControl.TabPages;
			}
		}

		#region Konstruktor a destruktor

		// -------------------------------------------------------------------------
		/// <summary>
		/// Inicializuje Hlavny formular aplikacie
		/// </summary>
		public MainForm()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			this.commonVisualStyle = Crownwood.Magic.Common.VisualStyle.IDE;

			//
			// Potrebne pre moj vlastny design support
			//
			MyInitializeComponent();

			this.OutputPanel.Clear();
			this.TaskListPanel.Clear();
			statusBar.SetMessage("Ready");
		}

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

		#endregion

		#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()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(MainForm));
			// 
			// MainForm
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.ClientSize = new System.Drawing.Size(664, 437);
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.Name = "MainForm";
			this.Text = "DINAMIC XML Editor";

		}
		#endregion

		#region Inicializacia komponentov a spol.
		// -------------------------------------------------------------------------
		/// <summary>
		/// Inicializuje komponenty - je to moj vlastny design support
		/// </summary>
		private void MyInitializeComponent()
		{
			// Temporarily suspends the layout logic for the control.
			this.SuspendLayout();
			
			this.Closing += new System.ComponentModel.CancelEventHandler(this.MainForm_Closing);

			// TabControl
			this.tabControl = new Crownwood.Magic.Controls.TabControl();
			this.tabControl.Appearance = Crownwood.Magic.Controls.TabControl.VisualAppearance.MultiDocument;
			this.tabControl.Dock = DockStyle.Fill;
			this.tabControl.Style = this.commonVisualStyle;
			this.tabControl.IDEPixelBorder = true;
			this.tabControl.HotTrack = true;
			this.tabControl.SelectionChanged += new EventHandler(OnSelectionChanged);
			this.tabControl.ClosePressed += new EventHandler(OnClosePressed);
			Controls.Add(this.tabControl);

			// Docking Manager
			this.dockingManager = new Crownwood.Magic.Docking.DockingManager(this, this.commonVisualStyle);
			this.dockingManager.InnerControl = this.tabControl;

			// Status bar
			this.statusBar = new XML_editor.MyComponents.SdStatusBar();
// HACK: ---			
			this.statusBar.SetInsertMode(true);
			this.Controls.Add( this.statusBar );

			this.dockingManager.OuterControl = this.statusBar;

			// Toolbar
			this.toolBar = new AxToolBar(this);
			this.Controls.Add(this.toolBar);

			// Hlavne menu
			this.topMenu = this.CreateMainMenu();
			this.Controls.Add( this.topMenu );

			// Resumes normal layout logic.
			this.ResumeLayout(true);

		}

		// -------------------------------------------------------------------------
		/// <summary>
		/// Vytvori <see cref="Crownwood.Magic.Menus.MenuControl"/>. Teda hlavne menu
		/// aplikacie.
		/// </summary>
		/// <returns><see cref="Crownwood.Magic.Menus.MenuControl"/> instanciu
		/// predstavujucu hlavne menu aplikacie</returns>
		private Crownwood.Magic.Menus.MenuControl CreateMainMenu()
		{
			Crownwood.Magic.Menus.MenuControl topMenu = new Crownwood.Magic.Menus.MenuControl();
			topMenu.Style = commonVisualStyle;
			topMenu.MultiLine = false;
			topMenu.Dock = DockStyle.Top;
				
			// Hlavny pruh
			MenuCommand topFile = new MenuCommand("&File");
			MenuCommand topEdit = new MenuCommand("&Edit");
			MenuCommand topView = new MenuCommand("&View");
			MenuCommand topFormat = new MenuCommand("&Format");
			MenuCommand topTools = new MenuCommand("&Tools");
			MenuCommand topAbout = new MenuCommand("&About");
			topMenu.MenuCommands.AddRange(new MenuCommand[]{topFile, topEdit, topView, topFormat, topTools, topAbout});

			// File
			MenuCommand fileNew  = new MenuCommand("&New", Shortcut.CtrlN, new EventHandler(this.Clicked_FileNew));
			fileNew.Image = IconProvider.LoadBitmap(this, "XML_editor.Icons.NewFile.png");
			MenuCommand fileOpen = new MenuCommand("&Open", Shortcut.CtrlO, new EventHandler(this.Clicked_FileOpen));
			fileOpen.Image = IconProvider.LoadBitmap(this, "XML_editor.Icons.OpenFile.png");
			MenuCommand fileClose = new MenuCommand("&Close", new EventHandler(this.Clicked_FileClose));
			MenuCommand fileCloseAll = new MenuCommand("&Close All", new EventHandler(this.Clicked_FileCloseAll));
			MenuCommand fileSep1 = new MenuCommand("-");
			MenuCommand fileSave = new MenuCommand("&Save", Shortcut.CtrlS, new EventHandler(this.Clicked_FileSave));
			fileSave.Image = IconProvider.LoadBitmap(this, "XML_editor.Icons.Save.png");
			MenuCommand fileSaveAs = new MenuCommand("Save &As...", new EventHandler(this.Clicked_FileSaveAs));
			MenuCommand fileSaveAll = new MenuCommand("Save A&ll Files", new EventHandler(this.Clicked_FileSaveAll));
			fileSaveAll.Image = IconProvider.LoadBitmap(this, "XML_editor.Icons.SaveAll.png");
			MenuCommand fileSep4 = new MenuCommand("-");
			MenuCommand fileExit  = new MenuCommand("E&xit", new EventHandler(this.Clicked_FileExit));
			fileExit.Image = IconProvider.LoadBitmap(this, "XML_editor.Icons.Exit.png");
			topFile.MenuCommands.AddRange(new MenuCommand[]{fileNew,fileOpen,fileClose,fileCloseAll,fileSep1,fileSave,fileSaveAs,fileSaveAll,fileSep4,fileExit});
			topFile.PopupStart += new CommandHandler(BeforeFilePopup);

			// Edit
			MenuCommand editUndo = new MenuCommand("&Undo", Shortcut.CtrlZ, new EventHandler(this.Clicked_EditUndo));
			editUndo.Image = IconProvider.LoadBitmap(this, "XML_editor.Icons.UndoIcon.png");
			MenuCommand editRedo = new MenuCommand("&Redo", Shortcut.CtrlShiftZ, new EventHandler(this.Clicked_EditRedo));
			editRedo.Image = IconProvider.LoadBitmap(this, "XML_editor.Icons.RedoIcon.png");
			MenuCommand fileSep2 = new MenuCommand("-");
			MenuCommand editCut = new MenuCommand("Cu&t", Shortcut.CtrlX, new EventHandler(this.Clicked_EditCut));
			editCut.Image = IconProvider.LoadBitmap(this, "XML_editor.Icons.Cut.png");
			MenuCommand editCopy = new MenuCommand("&Copy", Shortcut.CtrlC, new EventHandler(this.Clicked_EditCopy));
			editCopy.Image = IconProvider.LoadBitmap(this, "XML_editor.Icons.Copy.png");
			MenuCommand editPaste = new MenuCommand("&Paste", Shortcut.CtrlV, new EventHandler(this.Clicked_EditPaste));
			editPaste.Image = IconProvider.LoadBitmap(this, "XML_editor.Icons.Paste.png");
			MenuCommand fileSep3 = new MenuCommand("-");
			MenuCommand editSelectAll = new MenuCommand("Select &All", Shortcut.CtrlA, new EventHandler(this.Clicked_EditSelectAll));
			MenuCommand editFind = new MenuCommand("&Find...", Shortcut.AltF7, new EventHandler(this.Clicked_EditFind));
			editFind.Image = IconProvider.LoadBitmap(this, "XML_editor.Icons.find.png", true, new Point(0,0));
			MenuCommand editFindNext = new MenuCommand("Find &Next", Shortcut.F3, new EventHandler(this.Clicked_EditFindNext));
			topEdit.MenuCommands.AddRange(new MenuCommand[]{editUndo, editRedo, fileSep2, editCut, editCopy, editPaste, fileSep3, editSelectAll, fileSep3, editFind, editFindNext});
			topEdit.PopupStart += new CommandHandler(BeforeEditPopup);

			// View
			MenuCommand viewTaskList = new MenuCommand("Task &List", new EventHandler(this.Clicked_ViewTaskList));
			viewTaskList.Image = IconProvider.LoadBitmap(this, "XML_editor.Icons.TaskList.bmp", true, new Point(0,0));
			MenuCommand viewOutput = new MenuCommand("&Output", new EventHandler(this.Clicked_ViewOutput));

⌨️ 快捷键说明

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