From 181f2f0372764b144ee87db64d1d126fb1387b5b Mon Sep 17 00:00:00 2001 From: Mathias Simmack Date: Wed, 26 May 2010 10:50:56 +0000 Subject: [PATCH] new properties for the Help3Catalog class and translatable messages and labels git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5850 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- src/AddIns/Misc/HelpViewer/HelpViewer.addin | 8 +-- .../HelpViewer/Source/Controls/TocEntry.cs | 10 ++-- .../Source/Controls/TocPadControl.xaml.cs | 3 +- .../HelpViewer/Source/Core/DisplayHelp.cs | 52 ++++++++----------- .../HelpViewer/Source/Core/Help3Catalog.cs | 10 ++++ .../HelpViewer/Source/Core/Help3Service.cs | 5 -- .../Source/Core/HelpLibraryAgent.cs | 24 +++++++++ .../Source/Core/HelpLibraryManager.cs | 5 +- .../HelpViewer/Source/Help3OptionsPanel.xaml | 10 ++-- .../Source/Help3OptionsPanel.xaml.cs | 7 +-- 10 files changed, 76 insertions(+), 58 deletions(-) diff --git a/src/AddIns/Misc/HelpViewer/HelpViewer.addin b/src/AddIns/Misc/HelpViewer/HelpViewer.addin index 5f29de8d8c..615c1b1be4 100644 --- a/src/AddIns/Misc/HelpViewer/HelpViewer.addin +++ b/src/AddIns/Misc/HelpViewer/HelpViewer.addin @@ -17,17 +17,17 @@ - + - + @@ -36,7 +36,7 @@ diff --git a/src/AddIns/Misc/HelpViewer/Source/Controls/TocEntry.cs b/src/AddIns/Misc/HelpViewer/Source/Controls/TocEntry.cs index 53e01aa65e..a5e07799c6 100644 --- a/src/AddIns/Misc/HelpViewer/Source/Controls/TocEntry.cs +++ b/src/AddIns/Misc/HelpViewer/Source/Controls/TocEntry.cs @@ -27,7 +27,7 @@ namespace MSHelpSystem.Controls { class TocEntry : INotifyPropertyChanged { - const string url = "ms-xhelp://?method=children&id={3}&format=xml&product={0}&productVersion={1}&locale={2}"; + const string url = "ms-xhelp://?method=children&id={1}&format=xml&{0}"; string id; WebClient client = new WebClient(); @@ -57,9 +57,11 @@ namespace MSHelpSystem.Controls { 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)))); + if (Help3Service.ActiveCatalog != null) { + if (children == null && !client.IsBusy && HelpLibraryAgent.PortIsReady) { + client.DownloadStringAsync(new Uri(Help3Environment.GetHttpFromMsXHelp(string.Format(url, Help3Service.ActiveCatalog.AsMsXHelpParam, id)))); + } + } return children ?? defaultChild; } private set diff --git a/src/AddIns/Misc/HelpViewer/Source/Controls/TocPadControl.xaml.cs b/src/AddIns/Misc/HelpViewer/Source/Controls/TocPadControl.xaml.cs index a8c68ee40c..c0ee8e6fe8 100644 --- a/src/AddIns/Misc/HelpViewer/Source/Controls/TocPadControl.xaml.cs +++ b/src/AddIns/Misc/HelpViewer/Source/Controls/TocPadControl.xaml.cs @@ -31,8 +31,7 @@ namespace MSHelpSystem.Controls void LoadToc() { if (!Help3Environment.IsLocalHelp) DataContext = null; - // TODO: Needs a localization - else DataContext = new[] { new TocEntry("-1") { Title = "Help Library" } }; + else DataContext = new[] { new TocEntry("-1") { Title = StringParser.Parse("${res:AddIns.HelpViewer.HelpLibraryRootTitle}") } }; } void Help3TocItemChanged(object sender, RoutedPropertyChangedEventArgs e) diff --git a/src/AddIns/Misc/HelpViewer/Source/Core/DisplayHelp.cs b/src/AddIns/Misc/HelpViewer/Source/Core/DisplayHelp.cs index 3e3792bfc5..4884e57a1e 100644 --- a/src/AddIns/Misc/HelpViewer/Source/Core/DisplayHelp.cs +++ b/src/AddIns/Misc/HelpViewer/Source/Core/DisplayHelp.cs @@ -19,18 +19,16 @@ namespace MSHelpSystem.Core public static void Catalog() { if (!Help3Environment.IsLocalHelp) { - MessageBox.Show("You requested an offline feature in the online help mode. You have to change the mode in order to use this feature.", - "Help Viewer", + MessageBox.Show(StringParser.Parse("${res:AddIns.HelpViewer.OfflineFeatureRequestMsg}"), + StringParser.Parse("${res:AddIns.HelpViewer.MicrosoftHelpViewerTitle}"), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - Help3Catalog catalog = Help3Service.ActiveCatalog; - if (catalog == null) { - throw new ArgumentNullException("c"); + if (Help3Service.ActiveCatalog == null) { + throw new ArgumentNullException("Help3Service.ActiveCatalog"); } - string helpCatalogUrl = string.Format(@"ms-xhelp://?method=page&id=-1&product={0}&productVersion={1}&locale={2}", - catalog.ProductCode, catalog.ProductVersion, catalog.Locale); + string helpCatalogUrl = string.Format(@"ms-xhelp://?method=page&id=-1&{0}", Help3Service.ActiveCatalog.AsMsXHelpParam); LoggingService.Debug(string.Format("Help 3.0: {0}", helpCatalogUrl)); DisplayLocalHelp(helpCatalogUrl); } @@ -41,18 +39,16 @@ namespace MSHelpSystem.Core throw new ArgumentNullException("pageId"); } if (!Help3Environment.IsLocalHelp) { - MessageBox.Show("You requested an offline feature in the online help mode. You have to change the mode in order to use this feature.", - "Help Viewer", + MessageBox.Show(StringParser.Parse("${res:AddIns.HelpViewer.OfflineFeatureRequestMsg}"), + StringParser.Parse("${res:AddIns.HelpViewer.MicrosoftHelpViewerTitle}"), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - Help3Catalog catalog = Help3Service.ActiveCatalog; - if (catalog == null) { - throw new ArgumentNullException("c"); + if (Help3Service.ActiveCatalog == null) { + throw new ArgumentNullException("Help3Service.ActiveCatalog"); } - string helpPageUrl = string.Format(@"ms-xhelp://?method=page&id={3}&product={0}&productVersion={1}&locale={2}", - catalog.ProductCode, catalog.ProductVersion, catalog.Locale, pageId); + string helpPageUrl = string.Format(@"ms-xhelp://?method=page&id={1}&{0}", Help3Service.ActiveCatalog.AsMsXHelpParam, pageId); LoggingService.Debug(string.Format("Help 3.0: {0}", helpPageUrl)); DisplayLocalHelp(helpPageUrl); } @@ -66,12 +62,10 @@ namespace MSHelpSystem.Core DisplayHelpOnMSDN(contextual); return; } - Help3Catalog catalog = Help3Service.ActiveCatalog; - if (catalog == null) { - throw new ArgumentNullException("c"); + if (Help3Service.ActiveCatalog == null) { + throw new ArgumentNullException("Help3Service.ActiveCatalog"); } - string helpContextualUrl = string.Format(@"ms-xhelp://?method=f1&query={3}&product={0}&productVersion={1}&locale={2}", - catalog.ProductCode, catalog.ProductVersion, catalog.Locale, contextual); + string helpContextualUrl = string.Format(@"ms-xhelp://?method=f1&query={1}&{0}", Help3Service.ActiveCatalog.AsMsXHelpParam, contextual); LoggingService.Debug(string.Format("Help 3.0: {0}", helpContextualUrl)); DisplayLocalHelp(helpContextualUrl); } @@ -85,12 +79,10 @@ namespace MSHelpSystem.Core DisplaySearchOnMSDN(searchWords); return; } - Help3Catalog catalog = Help3Service.ActiveCatalog; - if (catalog == null) { - throw new ArgumentNullException("c"); + if (Help3Service.ActiveCatalog == null) { + throw new ArgumentNullException("Help3Service.ActiveCatalog"); } - string helpSearchUrl = string.Format(@"ms-xhelp://?method=search&query={3}&product={0}&productVersion={1}&locale={2}", - catalog.ProductCode, catalog.ProductVersion, catalog.Locale, searchWords.Replace(" ", "+")); + string helpSearchUrl = string.Format(@"ms-xhelp://?method=search&query={1}&{0}", Help3Service.ActiveCatalog.AsMsXHelpParam, searchWords.Replace(" ", "+")); LoggingService.Debug(string.Format("Help 3.0: {0}", helpSearchUrl)); DisplayLocalHelp(helpSearchUrl); } @@ -101,18 +93,16 @@ namespace MSHelpSystem.Core throw new ArgumentNullException("keywords"); } if (!Help3Environment.IsLocalHelp) { - MessageBox.Show("You requested an offline feature in the online help mode. You have to change the mode in order to use this feature.", - "Help Viewer", + MessageBox.Show(StringParser.Parse("${res:AddIns.HelpViewer.OfflineFeatureRequestMsg}"), + StringParser.Parse("${res:AddIns.HelpViewer.MicrosoftHelpViewerTitle}"), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - Help3Catalog catalog = Help3Service.ActiveCatalog; - if (catalog == null) { - throw new ArgumentNullException("c"); + if (Help3Service.ActiveCatalog == null) { + throw new ArgumentNullException("Help3Service.ActiveCatalog"); } - string helpKeywordsUrl = string.Format(@"ms-xhelp://?method=keywords&query={3}&product={0}&productVersion={1}&locale={2}", - catalog.ProductCode, catalog.ProductVersion, catalog.Locale, keywords); + string helpKeywordsUrl = string.Format(@"ms-xhelp://?method=keywords&query={1}&{0}", Help3Service.ActiveCatalog.AsMsXHelpParam, keywords.Replace(" ", "+")); LoggingService.Debug(string.Format("Help 3.0: {0}", helpKeywordsUrl)); DisplayLocalHelp(helpKeywordsUrl); } diff --git a/src/AddIns/Misc/HelpViewer/Source/Core/Help3Catalog.cs b/src/AddIns/Misc/HelpViewer/Source/Core/Help3Catalog.cs index 259b85bd84..e14317953f 100644 --- a/src/AddIns/Misc/HelpViewer/Source/Core/Help3Catalog.cs +++ b/src/AddIns/Misc/HelpViewer/Source/Core/Help3Catalog.cs @@ -62,5 +62,15 @@ namespace MSHelpSystem.Core { get { return brandingPackage; } } + + public string AsMsXHelpParam + { + get { return string.Format("product={0}&productVersion={1}&locale={2}", productCode, productVersion, productLocale); } + } + + public string AsCmdLineParam + { + get { return string.Format("/product {0} /version {1} /locale {2}", productCode, productVersion, productLocale); } + } } } \ No newline at end of file diff --git a/src/AddIns/Misc/HelpViewer/Source/Core/Help3Service.cs b/src/AddIns/Misc/HelpViewer/Source/Core/Help3Service.cs index 44be723831..58bd36eaee 100644 --- a/src/AddIns/Misc/HelpViewer/Source/Core/Help3Service.cs +++ b/src/AddIns/Misc/HelpViewer/Source/Core/Help3Service.cs @@ -94,11 +94,6 @@ namespace MSHelpSystem.Core #endregion - public static int Count - { - get { return catalogs.Count; } - } - public static ReadOnlyCollection Items { get diff --git a/src/AddIns/Misc/HelpViewer/Source/Core/HelpLibraryAgent.cs b/src/AddIns/Misc/HelpViewer/Source/Core/HelpLibraryAgent.cs index 68627dca15..8ecd3cfdf1 100644 --- a/src/AddIns/Misc/HelpViewer/Source/Core/HelpLibraryAgent.cs +++ b/src/AddIns/Misc/HelpViewer/Source/Core/HelpLibraryAgent.cs @@ -1,6 +1,8 @@ using System; using System.Diagnostics; using System.IO; +using System.Net; +using System.Net.Sockets; using Microsoft.Win32; using ICSharpCode.Core; @@ -50,6 +52,28 @@ namespace MSHelpSystem.Core } } + public static bool PortIsReady + { + get + { + try { + Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); + socket.Connect(IPAddress.Parse("127.0.0.1"), PortNumber); + bool isReady = socket.Connected; + socket.Close(); + return isReady; + } + catch (SocketException ex) { + if (ex.ErrorCode == 10061) { + LoggingService.Debug("Help 3.0: Port is available but not ready"); + return true; + } + LoggingService.Error(string.Format("Help 3.0: {0}", ex.ToString())); + } + return false; + } + } + public static int ProcessId { get diff --git a/src/AddIns/Misc/HelpViewer/Source/Core/HelpLibraryManager.cs b/src/AddIns/Misc/HelpViewer/Source/Core/HelpLibraryManager.cs index 856af88236..9bb71b8d7d 100644 --- a/src/AddIns/Misc/HelpViewer/Source/Core/HelpLibraryManager.cs +++ b/src/AddIns/Misc/HelpViewer/Source/Core/HelpLibraryManager.cs @@ -181,10 +181,7 @@ namespace MSHelpSystem.Core ProcessStartInfo psi = new ProcessStartInfo(); psi.FileName = Manager; psi.WorkingDirectory = Help3Environment.AppRoot; - psi.Arguments = string.Format("/product {0} /version {1} /locale {2}", - Help3Service.ActiveCatalog.ProductCode, - Help3Service.ActiveCatalog.ProductVersion, - Help3Service.ActiveCatalog.Locale); + psi.Arguments = Help3Service.ActiveCatalog.AsCmdLineParam; psi.UseShellExecute = true; psi.Verb = "runas"; psi.WindowStyle = ProcessWindowStyle.Normal; diff --git a/src/AddIns/Misc/HelpViewer/Source/Help3OptionsPanel.xaml b/src/AddIns/Misc/HelpViewer/Source/Help3OptionsPanel.xaml index c15d45ca78..da665bac61 100644 --- a/src/AddIns/Misc/HelpViewer/Source/Help3OptionsPanel.xaml +++ b/src/AddIns/Misc/HelpViewer/Source/Help3OptionsPanel.xaml @@ -1,27 +1,27 @@  - + - + diff --git a/src/AddIns/Misc/HelpViewer/Source/Help3OptionsPanel.xaml.cs b/src/AddIns/Misc/HelpViewer/Source/Help3OptionsPanel.xaml.cs index 6472351cb3..b3178d454c 100644 --- a/src/AddIns/Misc/HelpViewer/Source/Help3OptionsPanel.xaml.cs +++ b/src/AddIns/Misc/HelpViewer/Source/Help3OptionsPanel.xaml.cs @@ -24,10 +24,11 @@ namespace MSHelpSystem { HelpLibraryAgent.Start(); DataContext = Help3Service.Items; - // TODO: Needs a localization - groupBox1.Header = string.Format("{0} ({1})", "Installed Help catalogs", Help3Service.Count); + groupBox1.Header = string.Format("{0} ({1})", + StringParser.Parse("${res:AddIns.HelpViewer.InstalledHelpCatalogsLabel}"), + Help3Service.Items.Count); help3Catalogs.SelectedValue = Help3Service.ActiveCatalog.ShortName; - help3Catalogs.IsEnabled = (Help3Service.Count > 1 && Help3Service.Config.OfflineMode); + help3Catalogs.IsEnabled = (Help3Service.Items.Count > 1 && Help3Service.Config.OfflineMode); onlineMode.IsChecked = !Help3Service.Config.OfflineMode; }