From 96471dd7c869d0b1cbaa21b1fc1694c2e7283124 Mon Sep 17 00:00:00 2001 From: Mathias Simmack Date: Sat, 24 Jun 2006 19:09:16 +0000 Subject: [PATCH] Help 2.0: new config class used git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@1515 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Project/Resources/HtmlHelp2Options.xfrm | 25 ++++- .../Project/src/BaseControls/TocPad.cs | 11 ++- .../Project/src/Service/HtmlHelp2Options.cs | 64 +++++++------ .../Project/src/Service/HtmlHelp2Service.cs | 95 +++++++++++++++---- 4 files changed, 140 insertions(+), 55 deletions(-) diff --git a/src/AddIns/Misc/HtmlHelp2/Project/Resources/HtmlHelp2Options.xfrm b/src/AddIns/Misc/HtmlHelp2/Project/Resources/HtmlHelp2Options.xfrm index 7c5973d621..b97b180ed1 100644 --- a/src/AddIns/Misc/HtmlHelp2/Project/Resources/HtmlHelp2Options.xfrm +++ b/src/AddIns/Misc/HtmlHelp2/Project/Resources/HtmlHelp2Options.xfrm @@ -5,13 +5,13 @@ - + - + --> @@ -40,6 +39,24 @@ + + + + + + + + + + + + + + + + + + diff --git a/src/AddIns/Misc/HtmlHelp2/Project/src/BaseControls/TocPad.cs b/src/AddIns/Misc/HtmlHelp2/Project/src/BaseControls/TocPad.cs index acd114ec4d..e08869c0a9 100644 --- a/src/AddIns/Misc/HtmlHelp2/Project/src/BaseControls/TocPad.cs +++ b/src/AddIns/Misc/HtmlHelp2/Project/src/BaseControls/TocPad.cs @@ -5,8 +5,6 @@ // $Revision$ // -//#define DExplore8Style_NoTOCPictures - namespace HtmlHelp2 { using System; @@ -22,6 +20,7 @@ namespace HtmlHelp2 using HtmlHelp2.ControlsValidation; using HtmlHelp2.ResourcesHelperClass; using PrintOptions = MSHelpServices.HxHierarchy_PrintNode_Options; + using TSC = MSHelpControls.HxTreeStyleConstant; public class ShowTocMenuCommand : AbstractMenuCommand @@ -133,9 +132,8 @@ namespace HtmlHelp2 tocControl.BorderStyle = HxBorderStyle.HxBorderStyle_FixedSingle; tocControl.FontSource = HxFontSourceConstant.HxFontExternal; - #if DExplore8StyleWithNoTocPictures - tocControl.TreeStyle = HxTreeStyleConstant.HxTreeStyle_TreelinesPlusMinusText; - #endif + tocControl.TreeStyle = + (HtmlHelp2Environment.Config.TocPictures)?TSC.HxTreeStyle_TreelinesPlusMinusPictureText:TSC.HxTreeStyle_TreelinesPlusMinusText; printTopic.Image = ResourcesHelper.GetBitmap("HtmlHelp2.16x16.Print.bmp"); printTopic.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText; @@ -321,6 +319,9 @@ namespace HtmlHelp2 private void NamespaceReloaded(object sender, EventArgs e) { this.LoadToc(); + + tocControl.TreeStyle = + (HtmlHelp2Environment.Config.TocPictures)?TSC.HxTreeStyle_TreelinesPlusMinusPictureText:TSC.HxTreeStyle_TreelinesPlusMinusText; } #endregion diff --git a/src/AddIns/Misc/HtmlHelp2/Project/src/Service/HtmlHelp2Options.cs b/src/AddIns/Misc/HtmlHelp2/Project/src/Service/HtmlHelp2Options.cs index b7709db5b8..28416ddb48 100644 --- a/src/AddIns/Misc/HtmlHelp2/Project/src/Service/HtmlHelp2Options.cs +++ b/src/AddIns/Misc/HtmlHelp2/Project/src/Service/HtmlHelp2Options.cs @@ -15,6 +15,7 @@ namespace HtmlHelp2.OptionsPanel using System.Reflection; using System.Windows.Forms; using System.Xml; + using System.Xml.Serialization; using ICSharpCode.Core; using ICSharpCode.SharpDevelop.Gui; using HtmlHelp2.Environment; @@ -23,9 +24,9 @@ namespace HtmlHelp2.OptionsPanel public class HtmlHelp2OptionsPanel : AbstractOptionPanel { - static string help2EnvironmentFile = "help2environment.xml"; - ComboBox help2Collections = null; - string selectedHelp2Collection = HtmlHelp2Environment.DefaultNamespaceName; + ComboBox help2Collections = null; + CheckBox tocPictures = null; + string selectedHelp2Collection = HtmlHelp2Environment.DefaultNamespaceName; public override void LoadPanelContents() { @@ -46,10 +47,14 @@ namespace HtmlHelp2.OptionsPanel { try { - help2Collections = (ComboBox)ControlDictionary["help2Collections"]; - help2Collections.Enabled = HtmlHelp2Environment.IsReady; + help2Collections = (ComboBox)ControlDictionary["help2Collections"]; + help2Collections.Enabled = HtmlHelp2Environment.IsReady; help2Collections.SelectedIndexChanged += new EventHandler(this.NamespaceNameChanged); - selectedHelp2Collection = HtmlHelp2Environment.CurrentSelectedNamespace; + selectedHelp2Collection = HtmlHelp2Environment.CurrentSelectedNamespace; + + tocPictures = (CheckBox)ControlDictionary["tocPictures"]; + tocPictures.Enabled = HtmlHelp2Environment.IsReady; + tocPictures.Checked = HtmlHelp2Environment.Config.TocPictures; Help2RegistryWalker.BuildNamespacesList(help2Collections, selectedHelp2Collection); } @@ -70,29 +75,9 @@ namespace HtmlHelp2.OptionsPanel private void SaveHelp2Config() { - if (selectedHelp2Collection.Length == 0) - { - return; - } - - try - { - XmlDocument xmldoc = new XmlDocument(); - xmldoc.LoadXml(""); - - XmlNode node = xmldoc.CreateElement("collection"); - XmlCDataSection cdata = xmldoc.CreateCDataSection(selectedHelp2Collection); - node.AppendChild(cdata); - xmldoc.DocumentElement.AppendChild(node); - - xmldoc.Save(Path.Combine(PropertyService.ConfigDirectory, help2EnvironmentFile)); - - LoggingService.Info("Help 2.0: new configuration saved"); - } - catch - { - LoggingService.Error("Help 2.0: error while trying to save configuration"); - } + HtmlHelp2Environment.Config.SelectedCollection = selectedHelp2Collection; + HtmlHelp2Environment.Config.TocPictures = tocPictures.Checked; + HtmlHelp2Environment.SaveConfiguration(); } #region ReRegister @@ -118,4 +103,25 @@ namespace HtmlHelp2.OptionsPanel // } #endregion } + + [XmlRoot("help2environment")] + public class HtmlHelp2Options + { + private string selectedCollection = string.Empty; + private bool tocPictures = true; + + [XmlElement("collection")] + public string SelectedCollection + { + get { return selectedCollection; } + set { selectedCollection = value; } + } + + [XmlElement("tocpictures")] + public bool TocPictures + { + get { return tocPictures; } + set { tocPictures = value; } + } + } } diff --git a/src/AddIns/Misc/HtmlHelp2/Project/src/Service/HtmlHelp2Service.cs b/src/AddIns/Misc/HtmlHelp2/Project/src/Service/HtmlHelp2Service.cs index ef5b20d614..dee2a45a7d 100644 --- a/src/AddIns/Misc/HtmlHelp2/Project/src/Service/HtmlHelp2Service.cs +++ b/src/AddIns/Misc/HtmlHelp2/Project/src/Service/HtmlHelp2Service.cs @@ -11,14 +11,15 @@ namespace HtmlHelp2.Environment using System.IO; using System.Windows.Forms; using System.Xml; + using System.Xml.Serialization; using ICSharpCode.Core; using MSHelpServices; using HtmlHelp2.RegistryWalker; using HtmlHelp2.HelperDialog; + using HtmlHelp2.OptionsPanel; public sealed class HtmlHelp2Environment { - static string help2EnvironmentFile = "help2environment.xml"; static Guid TocGuid = new Guid("314111B2-A502-11D2-BBCA-00C04F8EC294"); static Guid IndexGuid = new Guid("314111CC-A502-11D2-BBCA-00C04F8EC294"); static Guid QueryGuid = new Guid("31411193-A502-11D2-BBCA-00C04F8EC294"); @@ -33,6 +34,8 @@ namespace HtmlHelp2.Environment static string defaultPage = "about:blank"; static string searchPage = "http://msdn.microsoft.com"; static bool dynamicHelpIsBusy = false; + static HtmlHelp2Options config = new HtmlHelp2Options(); + static HtmlHelp2Environment() { @@ -81,29 +84,40 @@ namespace HtmlHelp2.Environment { get { return dynamicHelpIsBusy; } } + + public static HtmlHelp2Options Config + { + get { return config; } + } #endregion #region Namespace Functions private static void LoadHelp2Config() { - try - { - XmlDocument xmldoc = new XmlDocument(); - xmldoc.Load(Path.Combine(PropertyService.ConfigDirectory, help2EnvironmentFile)); - - XmlNode node = xmldoc.SelectSingleNode("/help2environment/collection"); - if (node != null) { - if (!string.IsNullOrEmpty(node.InnerText)) { - DefaultNamespaceName = node.InnerText; - } - } - - LoggingService.Info("Help 2.0: using last configuration"); - } - catch + LoadConfiguration(); + if (!string.IsNullOrEmpty(config.SelectedCollection)) { - LoggingService.Info("Help 2.0: using default configuration"); + DefaultNamespaceName = config.SelectedCollection; } + +// try +// { +// XmlDocument xmldoc = new XmlDocument(); +// xmldoc.Load(Path.Combine(PropertyService.ConfigDirectory, help2EnvironmentFile)); +// +// XmlNode node = xmldoc.SelectSingleNode("/help2environment/collection"); +// if (node != null) { +// if (!string.IsNullOrEmpty(node.InnerText)) { +// DefaultNamespaceName = node.InnerText; +// } +// } +// +// LoggingService.Info("Help 2.0: using last configuration"); +// } +// catch +// { +// LoggingService.Info("Help 2.0: using default configuration"); +// } } public static void ReloadNamespace() @@ -309,5 +323,52 @@ namespace HtmlHelp2.Environment } } #endregion + + #region Configuration + public static void LoadConfiguration() + { + try + { + string configFile = + Path.Combine(PropertyService.ConfigDirectory, "help2environment.xml"); + + if(!File.Exists(configFile)) + { + return; + } + + XmlSerializer serialize = new XmlSerializer(typeof(HtmlHelp2Options)); + StreamReader file = new StreamReader(configFile); + config = (HtmlHelp2Options)serialize.Deserialize(file); + file.Close(); + + LoggingService.Info("Help 2.0: Configuration successfully loaded."); + } + catch + { + LoggingService.Error("Help 2.0: Error while trying to load configuration."); + } + } + + public static void SaveConfiguration() + { + try + { + string configFile = + Path.Combine(PropertyService.ConfigDirectory, "help2environment.xml"); + + XmlSerializer serialize = new XmlSerializer(typeof(HtmlHelp2Options)); + StreamWriter file = new StreamWriter(configFile); + serialize.Serialize(file, config); + file.Close(); + + LoggingService.Info("Help 2.0: Configuration successfully saved."); + } + catch + { + LoggingService.Error("Help 2.0: Error while trying to save configuration."); + } + } + #endregion } }