📄 tocpad.cs
字号:
/* ***********************************************************
*
* Help 2.0 Environment for SharpDevelop
* Table of Contents Pad
* Copyright (c) 2005, Mathias Simmack. All rights reserved.
*
* ********************************************************* */
//#define DExplore8Style_NoTOCPictures
namespace HtmlHelp2
{
using System;
using System.Drawing;
using System.Windows.Forms;
using ICSharpCode.Core.AddIns.Codons;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.Core.Services;
using AxMSHelpControls;
using MSHelpControls;
using MSHelpServices;
using HtmlHelp2Service;
using HtmlHelp2Browser;
public class ShowTocMenuCommand : AbstractMenuCommand
{
public override void Run()
{
HtmlHelp2TocPad toc = (HtmlHelp2TocPad)WorkbenchSingleton.Workbench.GetPad(typeof(HtmlHelp2TocPad));
if(toc != null) toc.BringPadToFront();
}
}
public class HtmlHelp2TocPad : AbstractPadContent
{
protected MsHelp2TocControl help2TocControl;
Panel containerPanel;
public override Control Control {
get { return containerPanel; }
}
public override void Dispose()
{
if (help2TocControl != null)
{
help2TocControl.Dispose();
}
}
public override void RedrawContent()
{
if (help2TocControl != null)
{
help2TocControl.RedrawContent();
}
}
public HtmlHelp2TocPad() : base("${res:AddIns.HtmlHelp2.Contents}", "HtmlHelp2.16x16.Toc")
{
containerPanel = new Panel();
containerPanel.VisibleChanged += new EventHandler(OnVisibleChanged);
containerPanel.SizeChanged += new EventHandler(OnVisibleChanged);
}
void OnVisibleChanged(object sender, EventArgs e)
{
if (containerPanel.IsHandleCreated && containerPanel.Width > 0 && containerPanel.Visible)
{
containerPanel.BeginInvoke(new MethodInvoker(InitIfVisible));
}
}
void InitIfVisible()
{
if (containerPanel.Width > 0 && containerPanel.Visible)
{
Init();
}
}
void Init()
{
if (help2TocControl == null)
{
containerPanel.VisibleChanged -= new EventHandler(OnVisibleChanged);
containerPanel.SizeChanged -= new EventHandler(OnVisibleChanged);
help2TocControl = new MsHelp2TocControl();
help2TocControl.LoadToc();
help2TocControl.Dock = DockStyle.Fill;
containerPanel.Controls.Add(help2TocControl);
}
}
public void SyncToc(string topicUrl)
{
Init();
if(help2TocControl.IsEnabled) help2TocControl.SynToc(topicUrl);
}
public void GetPrevFromNode()
{
Init();
if(help2TocControl.IsEnabled) help2TocControl.GetPrevFromNode();
}
public void GetPrevFromUrl(string topicUrl)
{
Init();
if(help2TocControl.IsEnabled) help2TocControl.GetPrevFromUrl(topicUrl);
}
public void GetNextFromNode()
{
Init();
if(help2TocControl.IsEnabled) help2TocControl.GetNextFromNode();
}
public void GetNextFromUrl(string topicUrl)
{
Init();
if(help2TocControl.IsEnabled) help2TocControl.GetNextFromUrl(topicUrl);
}
}
public class MsHelp2TocControl : UserControl
{
HtmlHelp2Environment h2env = null;
AxHxTocCtrl tocControl = null;
ComboBox filterCombobox = new ComboBox();
ContextMenu printPopup = new ContextMenu();
Label label1 = new Label();
MenuItem printTopic = new MenuItem();
MenuItem printChildTopics = new MenuItem();
bool controlIsEnabled = false;
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if(disposing && tocControl != null)
{
tocControl.Dispose();
}
}
public bool IsEnabled
{
get { return this.controlIsEnabled; }
}
public void RedrawContent()
{
StringParserService sps = (StringParserService)ServiceManager.Services.GetService(typeof(StringParserService));
label1.Text = sps.Parse("${res:AddIns.HtmlHelp2.FilteredBy}");
}
public MsHelp2TocControl()
{
StringParserService sps = (StringParserService)ServiceManager.Services.GetService(typeof(StringParserService));
h2env = (HtmlHelp2Environment)ServiceManager.Services.GetService(typeof(HtmlHelp2Environment));
this.controlIsEnabled = (h2env != null && h2env.Help2EnvironmentIsReady && Help2ControlsValidation.IsTocControlRegistered);
if(this.controlIsEnabled)
{
try
{
tocControl = new AxHxTocCtrl();
tocControl.BeginInit();
tocControl.Dock = DockStyle.Fill;
tocControl.NodeClick += new AxMSHelpControls.IHxTreeViewEvents_NodeClickEventHandler(this.TocNodeClicked);
tocControl.NodeRightClick += new AxMSHelpControls.IHxTreeViewEvents_NodeRightClickEventHandler(this.TocNodeRightClicked);
tocControl.EndInit();
Controls.Add(tocControl);
tocControl.CreateControl();
tocControl.BorderStyle = HxBorderStyle.HxBorderStyle_FixedSingle;
tocControl.FontSource = HxFontSourceConstant.HxFontExternal;
#if DExplore8Style_NoTOCPictures
tocControl.TreeStyle = HxTreeStyleConstant.HxTreeStyle_TreelinesPlusMinusText;
#endif
printTopic.Text = sps.Parse("${res:AddIns.HtmlHelp2.PrintTopic}");
printChildTopics.Text = sps.Parse("${res:AddIns.HtmlHelp2.PrintSubtopics}");
printPopup.MenuItems.Add(printTopic);
printTopic.Click += new EventHandler(this.PrintTopic);
printPopup.MenuItems.Add(printChildTopics);
printChildTopics.Click += new EventHandler(this.PrintTopicAndSubtopics);
}
catch
{
this.FakeHelpControl();
}
}
else
{
this.FakeHelpControl();
}
// Combobox panel
Panel panel1 = new Panel();
Controls.Add(panel1);
panel1.Dock = DockStyle.Top;
panel1.Height = filterCombobox.Height + 7;
panel1.Controls.Add(filterCombobox);
filterCombobox.Dock = DockStyle.Top;
filterCombobox.DropDownStyle = ComboBoxStyle.DropDownList;
filterCombobox.Sorted = true;
filterCombobox.Enabled = this.controlIsEnabled;
filterCombobox.SelectedIndexChanged += new EventHandler(this.FilterChanged);
// Filter label
Controls.Add(label1);
label1.Text = sps.Parse("${res:AddIns.HtmlHelp2.FilteredBy}");
label1.Dock = DockStyle.Top;
label1.TextAlign = ContentAlignment.MiddleLeft;
label1.Enabled = this.controlIsEnabled;
if(this.controlIsEnabled)
{
h2env.FilterQueryChanged += new EventHandler(this.FilterQueryChanged);
h2env.NamespaceReloaded += new EventHandler(this.NamespaceReloaded);
}
}
private void FakeHelpControl()
{
if(tocControl != null) tocControl.Dispose();
tocControl = null;
Panel nohelpPanel = new Panel();
Controls.Add(nohelpPanel);
nohelpPanel.Dock = DockStyle.Fill;
nohelpPanel.BorderStyle = BorderStyle.Fixed3D;
}
public void LoadToc()
{
if(!this.controlIsEnabled) return;
tocControl.Hierarchy = h2env.GetTocHierarchy(h2env.CurrentFilterQuery);
filterCombobox.SelectedIndexChanged -= new EventHandler(this.FilterChanged);
h2env.BuildFilterList(filterCombobox);
filterCombobox.SelectedIndexChanged += new EventHandler(this.FilterChanged);
}
private void FilterChanged(object sender, EventArgs e)
{
string selectedString = filterCombobox.SelectedItem.ToString();
if(selectedString != null && selectedString != "")
{
Cursor.Current = Cursors.WaitCursor;
tocControl.Hierarchy = h2env.GetTocHierarchy(h2env.FindFilterQuery(selectedString));
Cursor.Current = Cursors.Default;
}
}
#region Help 2.0 Environment Events
private void FilterQueryChanged(object sender, EventArgs e)
{
Application.DoEvents();
string currentFilterName = filterCombobox.SelectedItem.ToString();
if(String.Compare(currentFilterName, h2env.CurrentFilterName) != 0)
{
filterCombobox.SelectedIndexChanged -= new EventHandler(this.FilterChanged);
filterCombobox.SelectedIndex = filterCombobox.Items.IndexOf(h2env.CurrentFilterName);
tocControl.Hierarchy = h2env.GetTocHierarchy(h2env.CurrentFilterQuery);
filterCombobox.SelectedIndexChanged += new EventHandler(this.FilterChanged);
}
}
private void NamespaceReloaded(object sender, EventArgs e)
{
this.LoadToc();
}
#endregion
private void CallHelp(string topicUrl, bool syncToc)
{
if(topicUrl != null && topicUrl != "")
{
if(syncToc) this.SynToc(topicUrl);
ShowHelpBrowser.OpenHelpView(topicUrl);
}
}
private void TocNodeClicked(object sender, IHxTreeViewEvents_NodeClickEvent e)
{
string TopicUrl = tocControl.Hierarchy.GetURL(e.hNode);
this.CallHelp(TopicUrl,false);
}
#region Printing
private void TocNodeRightClicked(object sender, IHxTreeViewEvents_NodeRightClickEvent e)
{
StringParserService sps = (StringParserService)ServiceManager.Services.GetService(typeof(StringParserService));
if(e.hNode != 0)
{
printTopic.Enabled = tocControl.Hierarchy.GetURL(e.hNode) != "";
printChildTopics.Enabled = tocControl.Hierarchy.GetFirstChild(e.hNode) != 0;
printChildTopics.Text = sps.Parse((tocControl.Hierarchy.GetFirstChild(e.hNode) == 0 || tocControl.Hierarchy.GetURL(e.hNode) == "")?
"${res:AddIns.HtmlHelp2.PrintSubtopics}":
"${res:AddIns.HtmlHelp2.PrintTopicAndSubtopics}");
Point p = new Point(e.x, e.y);
p = this.PointToClient(p);
printPopup.Show(this, p);
}
}
private void PrintTopic(object sender, EventArgs e)
{
if(tocControl.Selection != 0)
{
tocControl.Hierarchy.PrintNode(0,
tocControl.Selection,
HxHierarchy_PrintNode_Options.HxHierarchy_PrintNode_Option_Node);
}
}
private void PrintTopicAndSubtopics(object sender, EventArgs e)
{
if(tocControl.Selection != 0)
{
tocControl.Hierarchy.PrintNode(0,
tocControl.Selection,
HxHierarchy_PrintNode_Options.HxHierarchy_PrintNode_Option_Children);
}
}
#endregion
#region published Help2 TOC Commands
public void SynToc(string topicUrl)
{
tocControl.Synchronize(topicUrl);
}
public void GetNextFromNode()
{
int currentNode = tocControl.Hierarchy.GetNextFromNode(tocControl.Selection);
string topicUrl = tocControl.Hierarchy.GetURL(currentNode);
this.CallHelp(topicUrl, true);
}
public void GetNextFromUrl(string url)
{
int currentNode = tocControl.Hierarchy.GetNextFromUrl(url);
string topicUrl = tocControl.Hierarchy.GetURL(currentNode);
this.CallHelp(topicUrl, true);
}
public void GetPrevFromNode()
{
int currentNode = tocControl.Hierarchy.GetPrevFromNode(tocControl.Selection);
string TopicUrl = tocControl.Hierarchy.GetURL(currentNode);
this.CallHelp(TopicUrl, true);
}
public void GetPrevFromUrl(string url)
{
int currentNode = tocControl.Hierarchy.GetPrevFromUrl(url);
string topicUrl = tocControl.Hierarchy.GetURL(currentNode);
this.CallHelp(topicUrl, true);
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -