diff --git a/src/AddIns/Misc/HelpViewer/HelpViewer.csproj b/src/AddIns/Misc/HelpViewer/HelpViewer.csproj index c5ca9cdc1f..9695dbb948 100644 --- a/src/AddIns/Misc/HelpViewer/HelpViewer.csproj +++ b/src/AddIns/Misc/HelpViewer/HelpViewer.csproj @@ -67,7 +67,10 @@ - + + TocPadControl.xaml + Code + diff --git a/src/AddIns/Misc/HelpViewer/Source/Controls/Pads.cs b/src/AddIns/Misc/HelpViewer/Source/Controls/Pads.cs new file mode 100644 index 0000000000..3e87a3b2d1 --- /dev/null +++ b/src/AddIns/Misc/HelpViewer/Source/Controls/Pads.cs @@ -0,0 +1,20 @@ +using System; +using ICSharpCode.SharpDevelop.Editor.CodeCompletion; +using ICSharpCode.SharpDevelop.Gui; + +namespace MSHelpSystem.Controls +{ + public class Help3TocPad : AbstractPadContent + { + public Help3TocPad() + { + } + + TocPadControl toc = new TocPadControl(); + + public override object Control + { + get { return toc; } + } + } +} diff --git a/src/AddIns/Misc/HelpViewer/Source/Controls/TocEntry.cs b/src/AddIns/Misc/HelpViewer/Source/Controls/TocEntry.cs new file mode 100644 index 0000000000..53e01aa65e --- /dev/null +++ b/src/AddIns/Misc/HelpViewer/Source/Controls/TocEntry.cs @@ -0,0 +1,80 @@ +// +// +// +// +// $Revision: 5842 $ +// +using System; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Net; +using System.Reflection; +using System.Runtime.InteropServices; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Media.Animation; +using System.Xml.Linq; +using System.Xml.XPath; +using ICSharpCode.Core; +using ICSharpCode.SharpDevelop.Gui; +using MSHelpSystem.Core; +using MSHelpSystem.Core.Native; + +namespace MSHelpSystem.Controls +{ + class TocEntry : INotifyPropertyChanged + { + const string url = "ms-xhelp://?method=children&id={3}&format=xml&product={0}&productVersion={1}&locale={2}"; + string id; + WebClient client = new WebClient(); + + public TocEntry(string id) + { + this.id = id; + + client.DownloadStringCompleted += (_, e) => + { + LoggingService.Debug(string.Format("Help 3.0: title \"{0}\"", Title)); + var children = XElement.Parse(e.Result); + Children = children.Elements("topic") + .Select(link => new TocEntry(link.Attribute("id").Value) { Title = link.Element("title").Value }) + .ToArray(); + client.Dispose(); + }; + RaisePropertyChanged("Children"); + } + + public string Title { get; set; } + public string Id { get { return id; } } + + static object[] defaultChild = new object[] { null }; + IEnumerable children; + + public IEnumerable Children + { + get + { + Help3Catalog catalog = Help3Service.ActiveCatalog; + if (children == null && !client.IsBusy) + client.DownloadStringAsync(new Uri(Help3Environment.GetHttpFromMsXHelp(string.Format(url, catalog.ProductCode, catalog.ProductVersion, catalog.Locale, id)))); + return children ?? defaultChild; + } + private set + { + children = value; + RaisePropertyChanged("Children"); + } + } + + public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged; + + protected void RaisePropertyChanged(string name) + { + System.ComponentModel.PropertyChangedEventHandler handler = PropertyChanged; + if (handler != null) handler(this, new System.ComponentModel.PropertyChangedEventArgs(name)); + } + } +} diff --git a/src/AddIns/Misc/HelpViewer/Source/Controls/TocPadControl.xaml b/src/AddIns/Misc/HelpViewer/Source/Controls/TocPadControl.xaml new file mode 100644 index 0000000000..4be583f5c6 --- /dev/null +++ b/src/AddIns/Misc/HelpViewer/Source/Controls/TocPadControl.xaml @@ -0,0 +1,22 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/src/AddIns/Misc/HelpViewer/Source/Controls/TocPadControl.xaml.cs b/src/AddIns/Misc/HelpViewer/Source/Controls/TocPadControl.xaml.cs new file mode 100644 index 0000000000..a8c68ee40c --- /dev/null +++ b/src/AddIns/Misc/HelpViewer/Source/Controls/TocPadControl.xaml.cs @@ -0,0 +1,52 @@ +// +// +// +// +// $Revision: 5842 $ +// +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using ICSharpCode.Core; +using MSHelpSystem.Core; + +namespace MSHelpSystem.Controls +{ + public partial class TocPadControl : UserControl + { + public TocPadControl() + { + InitializeComponent(); + LoadToc(); + Help3Service.ConfigurationUpdated += new EventHandler(Help3ServiceConfigurationUpdated); + } + + void LoadToc() + { + if (!Help3Environment.IsLocalHelp) DataContext = null; + // TODO: Needs a localization + else DataContext = new[] { new TocEntry("-1") { Title = "Help Library" } }; + } + + void Help3TocItemChanged(object sender, RoutedPropertyChangedEventArgs e) + { + string topicId = (string)tocTreeView.SelectedValue; + if (!string.IsNullOrEmpty(topicId)) { + LoggingService.Debug(string.Format("Help 3.0: [TOC] Calling page with Id \"{0}\"", topicId)); + DisplayHelp.Page(topicId); + } + } + + void Help3ServiceConfigurationUpdated(object sender, EventArgs e) + { + LoadToc(); + } + } +} \ No newline at end of file