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

📄 templatecompletionwindow.cs

📁 c#精彩编程百例(源代码)
💻 CS
字号:
//  TemplateCompletionWindow.cs 
//  Copyright (C) 2000 Mike Krueger
//
//  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.Windows.Forms;
using System.Drawing;

using SharpDevelop.Tool.Data;
using SharpDevelop.Internal.Templates;

namespace SharpDevelop.Gui.Edit.Text.TemplateCompletion {
	
	public class TemplateCompletionWindow : Form
	{
		string[] data;
		ListView list   = new ListView();
		CodeTemplate selected = null;
	
		public CodeTemplate Value {
			get {
				return selected;
			}
			set {
				selected = value;
			}
		}
		
		void activateitem(object sender, EventArgs e)
		{
			if (list.SelectedItems.Count > 0) {
				Value = ((TemplateListItem)list.SelectedItems[0]).Template;
			}
			Close();
		}
		
		
		bool point = false;
		public bool Point {
			get {
				return point;
			}
		}
		
		protected override bool ProcessDialogKey(Keys keyData)
		{	
			if (keyData == Keys.Escape) {
				Close();
				return true;
			} 
			return base.ProcessDialogKey(keyData);
		}
		
		internal class TemplateListItem : ListViewItem
		{
			public CodeTemplate Template;
			public TemplateListItem(CodeTemplate template) : base(new string[] {template.Description, template.Shortcut})
			{
				this.Template = template;
			}
		}
		
	    CodeTemplate BuildListView(string filter)
	    {
	    	list.Items.Clear();
	    	foreach (CodeTemplate t in CodeTemplateLoader.Template) {
	    		bool addTemplate = filter.Length <= t.Shortcut.Length;
				if (addTemplate)
	    		for (int i = 0; i < filter.Length; ++i)
	    			if (filter[i] != t.Shortcut[i]) {
	    				addTemplate = false;
	    				break;
	    			}
    			if (addTemplate) {
    				if (filter.Length == t.Shortcut.Length) {
    					return t;
    				}
    				list.Items.Add(new TemplateListItem(t));
    			}
	    	}
	    	return null;
	    }
		
		public TemplateCompletionWindow(string word, Point pos)
		{
			this.data   = data;
			Width       = 400;
			Height      = 150;
			FormBorderStyle = FormBorderStyle.None;
			TopMost     = true;
			
			list.Size = Size;
			list.View = View.Details;
			list.AutoArrange = true;
			list.Alignment = ListViewAlignment.Left;
			list.HeaderStyle = ColumnHeaderStyle.None;
			list.Sorting = SortOrder.Ascending;
			list.MultiSelect = false;
			
			//	list.AddOnKeyPress(new KeyPressEventHandler(HandleKeyPress));
			list.ItemActivate += new EventHandler(activateitem);
			list.FullRowSelect = true;
			ColumnHeader Description = new ColumnHeader();
			ColumnHeader Shortcut    = new ColumnHeader();
			
			Shortcut.Text  = "Shortcut";
			Shortcut.Width = 100;
			
			Description.Text  = "Description";
			Description.Width = Width - Shortcut.Width;
			
			list.Columns.Add(Description);
			list.Columns.Add(Shortcut);
			
			this.Controls.Add(list);
			
			list.Select();
			list.Focus();
			Location        = pos;
			StartPosition   = FormStartPosition.Manual;
			CodeTemplate t = BuildListView(word);
			if (t != null) {
				Value = t;
			} else {
				if (list.Items.Count > 1)
				 	ShowDialog();
				else
					if (list.Items.Count == 1)
						Value = (CodeTemplate)CodeTemplateLoader.Template[0];
			}
		}
	}
}

⌨️ 快捷键说明

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