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

📄 toolbar.cs

📁 C#实现DHTML编辑器功能!
💻 CS
字号:
// 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.Windows.Forms;

using XML_editor.MyForms;

namespace XML_editor.Common
{
	/// <summary>
	/// Summary description for ToolBar.
	/// </summary>
	public class AxToolBar : System.Windows.Forms.ToolBar
	{

		private ToolBarButton toolbarNew = new System.Windows.Forms.ToolBarButton();
		private ToolBarButton toolbarOpen = new System.Windows.Forms.ToolBarButton();
		private ToolBarButton toolbarSave = new System.Windows.Forms.ToolBarButton();
		private ToolBarButton toolbarSaveAll = new System.Windows.Forms.ToolBarButton();

		private ToolBarButton toolbarCut = new System.Windows.Forms.ToolBarButton();
		private ToolBarButton toolbarCopy = new System.Windows.Forms.ToolBarButton();
		private ToolBarButton toolbarPaste = new System.Windows.Forms.ToolBarButton();
		
		private ToolBarButton toolbarIndent = new System.Windows.Forms.ToolBarButton();
		private ToolBarButton toolbarUnindent = new System.Windows.Forms.ToolBarButton();

		private ToolBarButton toolbarFind = new System.Windows.Forms.ToolBarButton();

		private ImageList imgList = new ImageList();

		
		/// <summary>
		/// Odkaz na hlavny formular aplikacie
		/// </summary>
		private MainForm mainForm = null;

		// -------------------------------------------------------------------------
		/// <summary>
		/// Odkaz na hlavny formular aplikacie
		/// </summary>
		public MainForm MainForm
		{
			get 
			{
				return this.mainForm;
			}
		}

		// -------------------------------------------------------------------------
		/// <summary>
		/// Inicializuje instanciu <see cref="AxToolBar"/>
		/// </summary>
		/// <param name="mainForm">referencia na hlavny formular - <see cref="MainForm"/></param>
		public AxToolBar(MainForm mainForm) : base()
		{
			this.mainForm = mainForm;

			this.ImageListLoad();
			this.InicializeToolbarButtons();

			this.ActualTextAreaControlChanged(null, null);
			this.MainForm.ActualTextAreaControlChanged += new System.EventHandler(this.ActualTextAreaControlChanged);
		}

		// -------------------------------------------------------------------------
		/// <summary>
		/// Inicializacia toolbaru
		/// </summary>
		private void InicializeToolbarButtons() 
		{
			this.SuspendLayout();

			this.Appearance = ToolBarAppearance.Flat;
			this.DropDownArrows = true;
			this.Name = "toolBar";
			this.ShowToolTips = true;
			this.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar_ButtonClick);

			// 
			// toolbarNew
			// 
			this.toolbarNew.ToolTipText = "New";
			this.toolbarNew.ImageIndex = 0;

			// 
			// toolbarOpen
			// 
			this.toolbarOpen.ToolTipText = "Open";
			this.toolbarOpen.ImageIndex = 1;

			// 
			// toolbarSave
			// 
			this.toolbarSave.ToolTipText = "Save";
			this.toolbarSave.ImageIndex = 2;

			// 
			// toolbarSaveAll
			// 
			this.toolbarSaveAll.ToolTipText = "Save All";
			this.toolbarSaveAll.ImageIndex = 3;

			// 
			// toolbarCut
			// 
			this.toolbarCut.ToolTipText = "Cut selection to clipboard";
			this.toolbarCut.ImageIndex = 4;

			// 
			// toolbarCopy
			// 
			this.toolbarCopy.ToolTipText = "Copy selection to clipboard";
			this.toolbarCopy.ImageIndex = 5;

			// 
			// toolbarPaste
			// 
			this.toolbarPaste.ToolTipText = "Paste text from clipboard";
			this.toolbarPaste.ImageIndex = 6;

			// 
			// toolbarIndent
			// 
			this.toolbarIndent.ToolTipText = "Increase Indent";
			this.toolbarIndent.ImageIndex = 7;

			// 
			// toolbarUnindent
			// 
			this.toolbarUnindent.ToolTipText = "Decrease Indent";
			this.toolbarUnindent.ImageIndex = 8;

			// 
			// toolbarFind
			// 
			this.toolbarFind.ToolTipText = "Find...";
			this.toolbarFind.ImageIndex = 9;

			// 
			// toolBarSep1
			// 
			ToolBarButton toolBarSep1 = new System.Windows.Forms.ToolBarButton();
			toolBarSep1.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;


			this.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
																																			this.toolbarNew,
  																																		this.toolbarOpen,
																																			this.toolbarSave,
																																			this.toolbarSaveAll,
																																			toolBarSep1,
																																			this.toolbarCut,
																																			this.toolbarCopy,
																																			this.toolbarPaste,
																																			toolBarSep1,
																																			this.toolbarIndent,
																																			this.toolbarUnindent,
																																			toolBarSep1,
																																			this.toolbarFind});
			this.ResumeLayout(false);
		}

		// -------------------------------------------------------------------------
		/// <summary>
		/// Nacita image list
		/// </summary>
		private void ImageListLoad() 
		{
			this.imgList.Images.Add( IconProvider.LoadBitmap(this, "XML_editor.Icons.NewFile.png"));
			this.imgList.Images.Add( IconProvider.LoadBitmap(this, "XML_editor.Icons.OpenFile.png"));
			this.imgList.Images.Add( IconProvider.LoadBitmap(this, "XML_editor.Icons.Save.png"));
			this.imgList.Images.Add( IconProvider.LoadBitmap(this, "XML_editor.Icons.SaveAll.png"));
			this.imgList.Images.Add( IconProvider.LoadBitmap(this, "XML_editor.Icons.Cut.png"));
			this.imgList.Images.Add( IconProvider.LoadBitmap(this, "XML_editor.Icons.Copy.png"));
			this.imgList.Images.Add( IconProvider.LoadBitmap(this, "XML_editor.Icons.Paste.png"));
			this.imgList.Images.Add( IconProvider.LoadBitmap(this, "XML_editor.Icons.indent.png"));
			this.imgList.Images.Add( IconProvider.LoadBitmap(this, "XML_editor.Icons.unindent.png"));
			this.imgList.Images.Add( IconProvider.LoadBitmap(this, "XML_editor.Icons.find.png"));
			this.ImageList = this.imgList;
		}

		// -------------------------------------------------------------------------
		/// <summary>
		/// Kliknutie v toolbare
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void toolBar_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
		{
			switch(this.Buttons.IndexOf(e.Button))
			{
				case 0:
					this.MainForm.FileNew();
					break; 
				case 1:
					this.MainForm.FileOpen();
					break; 
				case 2:
					this.MainForm.FileSave(this.MainForm.SelectedTabPage);
					break; 
				case 3:
					this.MainForm.FileSaveAll();
					break;
				case 5:
					this.MainForm.Clicked_EditCut(null, null);
					break;
				case 6:
					this.MainForm.Clicked_EditCopy(null, null);
					break;
				case 7:
					this.MainForm.Clicked_EditPaste(null, null);
					break;
				case 9:
					this.MainForm.Clicked_FormatIndent(null, null);
					break;
				case 10:
					this.MainForm.Clicked_FormatUnindent(null, null);
					break;
				case 12:
					this.MainForm.Clicked_EditFind(null, null);
					break;
				default:
					break;
			}
		}

		// -------------------------------------------------------------------------
		/// <summary>
		/// Vyvola sa, PO zmene aktualneho <see cref="MainForm.ActualTextAreaControl"/>
		/// - teda ked uzivatel prepne na inu zalozku.
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void ActualTextAreaControlChanged(object sender, System.EventArgs e)
		{
			if (this.MainForm.ActualTextAreaControl == null) 
			{
				this.toolbarSave.Enabled = this.toolbarSaveAll.Enabled = 
					this.toolbarCopy.Enabled = this.toolbarCut.Enabled = 
					this.toolbarIndent.Enabled = this.toolbarPaste.Enabled =
					this.toolbarUnindent.Enabled = this.toolbarFind.Enabled = false;
			} 
			else 
			{
				this.toolbarSave.Enabled = this.toolbarSaveAll.Enabled = 
					this.toolbarCopy.Enabled = this.toolbarCut.Enabled = 
					this.toolbarIndent.Enabled = this.toolbarPaste.Enabled =
					this.toolbarUnindent.Enabled = this.toolbarFind.Enabled = true;
			}
		}

	} // public class ToolBar
} // namespace XML_editor.Common

⌨️ 快捷键说明

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