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

📄 searchresultspad.cs

📁 c#源代码
💻 CS
字号:
/* ***********************************************************
 *
 * Help 2.0 Environment for SharpDevelop
 * Search results Pad
 * Copyright (c) 2005, Mathias Simmack. All rights reserved.
 *
 * ********************************************************* */
namespace HtmlHelp2
{
	using System;
	using System.Collections;
	using System.Windows.Forms;
	using ICSharpCode.Core.AddIns.Codons;
	using ICSharpCode.Core.Services;
	using ICSharpCode.SharpDevelop.Gui;
	using ICSharpCode.SharpDevelop.Services;
	using MSHelpServices;
	using HtmlHelp2Browser;
	using HtmlHelp2Service;

	public class ShowSearchResultsMenuCommand : AbstractMenuCommand
	{
		public override void Run()
		{
			HtmlHelp2SearchResultsPad searchResults = (HtmlHelp2SearchResultsPad)WorkbenchSingleton.Workbench.GetPad(typeof(HtmlHelp2SearchResultsPad));
			if(searchResults != null) searchResults.BringPadToFront();
		}
	}

	public class HtmlHelp2SearchResultsPad : AbstractPadContent
	{
		ListView listView         = new ListView();
		ColumnHeader title        = new ColumnHeader();
		ColumnHeader location     = new ColumnHeader();
		ColumnHeader rank         = new ColumnHeader();

		public override Control Control
		{
			get { return listView;	}
		}

		public override void RedrawContent()
		{
			this.SetListViewHeader();
		}

		public ListView SearchResultsListView
		{
			get { return listView; }
		}

		public HtmlHelp2SearchResultsPad() : base("${res:AddIns.HtmlHelp2.SearchResults}", "HtmlHelp2.16x16.SearchResults")
		{
			HtmlHelp2Environment h2env = (HtmlHelp2Environment)ServiceManager.Services.GetService(typeof(HtmlHelp2Environment));

			this.SetListViewHeader();
			listView.Columns.Add(title);
			listView.Columns.Add(location);
			listView.Columns.Add(rank);

			listView.FullRowSelect     = true;
			listView.AutoArrange       = true;
			listView.Enabled           = (h2env != null & h2env.Help2EnvironmentIsReady);
			listView.Alignment         = ListViewAlignment.Left;
			listView.View              = View.Details;
			listView.Dock              = DockStyle.Fill;
			ListViewResize(this,null);

			listView.Resize           += new EventHandler(ListViewResize);
			listView.DoubleClick      += new EventHandler(ListViewDoubleClick);
			listView.ColumnClick      += new ColumnClickEventHandler(ColumnClick);
			listView.CreateControl();
		}

		private void SetListViewHeader()
		{
			StringParserService sps = (StringParserService)ServiceManager.Services.GetService(typeof(StringParserService));
			title.Text              = sps.Parse("${res:AddIns.HtmlHelp2.Title}");
			location.Text           = sps.Parse("${res:AddIns.HtmlHelp2.Location}");
			rank.Text               = sps.Parse("${res:AddIns.HtmlHelp2.Rank}");
		}

		private void ListViewResize(object sender, EventArgs e)
		{
			rank.Width     = 80;
			int w          = (listView.Width - rank.Width - 40) / 2;
			title.Width    = w;
			location.Width = w;
		}

		private void ListViewDoubleClick(object sender, EventArgs e)
		{
			HtmlHelp2SearchPad search = (HtmlHelp2SearchPad)WorkbenchSingleton.Workbench.GetPad(typeof(HtmlHelp2SearchPad));
			bool hiliteMatches = (search != null && search.HiliteEnabled);

			ListViewItem lvi = listView.SelectedItems[0];
			if(lvi != null && lvi.Tag != null && lvi.Tag is IHxTopic)
			{
				ShowHelpBrowser.OpenHelpView((IHxTopic)lvi.Tag, hiliteMatches);
			}
		}

		private void ColumnClick(object sender, ColumnClickEventArgs e)
		{
			listView.ListViewItemSorter = new ListViewItemComparer(e.Column);
			listView.Sort();
		}

		public void CleanUp()
		{
			foreach(ListViewItem lvi in listView.Items)
			{
				if(lvi.Tag != null) { lvi.Tag = null; }
			}

			listView.Items.Clear();
		}

		public void SetStatusMessage(string indexTerm)
		{
			/*
			 * @SharpDevelop developers: I would like to have the possibility to
			 * change the Pad's title. It works without, but it would look
			 * better if I could write what was searched and how many topics are
			 * matching.
			 */
			 IStatusBarService statusBarService = (IStatusBarService)ICSharpCode.Core.Services.ServiceManager.Services.GetService(typeof(IStatusBarService));
			 StringParserService sps = (StringParserService)ServiceManager.Services.GetService(typeof(StringParserService));
			 string text = sps.Parse("${res:AddIns.HtmlHelp2.ResultsOfSearchResults}",
			                         new string[,]
			                         {{"0", indexTerm},
			                          {"1", listView.Items.Count.ToString()},
			                          {"2", (listView.Items.Count == 1)?"${res:AddIns.HtmlHelp2.SingleTopic}":"${res:AddIns.HtmlHelp2.MultiTopic}"}}
			                        );

			 statusBarService.SetMessage(text);
		}

		#region Sorting
		class ListViewItemComparer : IComparer
		{
			private int col;

			public ListViewItemComparer(int column)
			{
				col = column;
			}

			public int Compare(object x, object y)
			{
				switch(col)
				{
					case 2:
						int a = Int32.Parse(((ListViewItem)x).SubItems[col].Text);
						int b = Int32.Parse(((ListViewItem)y).SubItems[col].Text);
						if(a > b) return 1;
							else if(a < b) return -1;
								else return 0;
					default:
						return String.Compare(((ListViewItem)x).SubItems[col].Text,
								              ((ListViewItem)y).SubItems[col].Text);
				}
			}
		}
		#endregion
	}
}

⌨️ 快捷键说明

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