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

📄 indexresultspad.cs

📁 c#源代码
💻 CS
字号:
/* ***********************************************************
 * 
 * Help 2.0 Environment for SharpDevelop
 * Index 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 ShowIndexResultsMenuCommand : AbstractMenuCommand
	{
		public override void Run()
		{
			HtmlHelp2IndexResultsPad indexResults = (HtmlHelp2IndexResultsPad)WorkbenchSingleton.Workbench.GetPad(typeof(HtmlHelp2IndexResultsPad));
			if(indexResults != null) indexResults.BringPadToFront();
		}
	}

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

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

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

		public ListView IndexResultsListView
		{
			get { return listView; }
		}

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

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

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

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

		public void SortLV(int listViewColumn)
		{
			listView.ListViewItemSorter = new ListViewItemComparer(listViewColumn);
			listView.Sort();
		}

		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}");
		}

		private void ListViewResize(object sender, EventArgs e)
		{
			title.Width = location.Width = (listView.Width - 60) / 2;
		}

		private void ListViewDoubleClick(object sender, EventArgs e)
		{
			ListViewItem lvi = listView.SelectedItems[0];
			if(lvi != null && lvi.Tag != null && lvi.Tag is IHxTopic)
			{
				ShowHelpBrowser.OpenHelpView((IHxTopic)lvi.Tag);
			}
		}

		private void ColumnClick(object sender, ColumnClickEventArgs e)
		{
			this.SortLV(e.Column);
		}

		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.
			 */
			 if(listView.Items.Count > 1)
			 {
				 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.ResultsOfIndexResults}",
				                         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)
			{
				return String.Compare(((ListViewItem)x).SubItems[col].Text,
				                      ((ListViewItem)y).SubItems[col].Text);
			}
		}
		#endregion
	}
}

⌨️ 快捷键说明

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