From c6950692db6d26daf06d3d555f124e39e3dfb749 Mon Sep 17 00:00:00 2001 From: Jose Miguel Torres Date: Wed, 24 Jul 2019 08:20:34 -0400 Subject: [dotnetcore] Turns SDK Not Installed Dialog into a Infobar --- .../MonoDevelop.DotNetCore.csproj | 2 +- .../DotNetCoreNotInstalledDialog.cs | 95 ---------------------- .../DotNetCoreNotInstalledInfoBar.cs | 63 ++++++++++++++ .../DotNetCoreProjectExtension.cs | 25 +++--- .../MonoDevelop.DotNetCore/DotNetCoreSdk.cs | 6 +- 5 files changed, 80 insertions(+), 111 deletions(-) delete mode 100644 main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreNotInstalledDialog.cs create mode 100644 main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreNotInstalledInfoBar.cs (limited to 'main/src/addins') diff --git a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.csproj b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.csproj index 01aa705bac..bb1c502dc0 100644 --- a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.csproj +++ b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.csproj @@ -26,7 +26,7 @@ - + diff --git a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreNotInstalledDialog.cs b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreNotInstalledDialog.cs deleted file mode 100644 index 9fb149f4f3..0000000000 --- a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreNotInstalledDialog.cs +++ /dev/null @@ -1,95 +0,0 @@ -// -// DotNetCoreNotInstalledDialog.cs -// -// Author: -// Matt Ward -// -// Copyright (c) 2016 Xamarin Inc. (http://xamarin.com) -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -using MonoDevelop.Core; -using MonoDevelop.Ide; -using MonoDevelop.Ide.Gui; -using System; - -namespace MonoDevelop.DotNetCore -{ - class DotNetCoreNotInstalledDialog : IDisposable - { - static readonly string defaultMessage = GettextCatalog.GetString (".NET Core SDK is not installed. This is required to build and run .NET Core projects."); - - GenericMessage message; - AlertButton downloadButton; - string downloadUrl = DotNetCoreDownloadUrl.GetDotNetCoreDownloadUrl (); - - public DotNetCoreNotInstalledDialog () - { - Build (); - } - - void Build () - { - message = new GenericMessage { - Text = defaultMessage, - DefaultButton = 1, - Icon = Stock.Information - }; - - downloadButton = new AlertButton (GettextCatalog.GetString ("Download .NET Core...")); - message.Buttons.Add (AlertButton.Cancel); - message.Buttons.Add (downloadButton); - - message.AlertButtonClicked += AlertButtonClicked; - } - - void AlertButtonClicked (object sender, AlertButtonEventArgs e) - { - if (e.Button == downloadButton) - IdeServices.DesktopService.ShowUrl (downloadUrl); - } - - public void Dispose () - { - message.AlertButtonClicked -= AlertButtonClicked; - } - - public void Show () - { - if (IsUnsupportedVersion || IsNetStandard) //for .net standard we'll show generic message - Message = DotNetCoreSdk.GetNotSupportedVersionMessage (); - else { - Message = DotNetCoreSdk.GetNotSupportedVersionMessage (RequiredDotNetCoreVersion.OriginalString); - downloadUrl = DotNetCoreDownloadUrl.GetDotNetCoreDownloadUrl (RequiredDotNetCoreVersion); - } - - MessageService.GenericAlert (message); - } - - public string Message { - get { return message.Text; } - set { message.Text = value; } - } - - public bool IsUnsupportedVersion { get; set; } - public bool IsNetStandard { get; set; } - public DotNetCoreVersion RequiredDotNetCoreVersion { get; set; } - public string CurrentDotNetCorePath { get; set; } - } -} diff --git a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreNotInstalledInfoBar.cs b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreNotInstalledInfoBar.cs new file mode 100644 index 0000000000..dd4578c87d --- /dev/null +++ b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreNotInstalledInfoBar.cs @@ -0,0 +1,63 @@ +// +// DotNetCoreNotInstalledInfoBar.cs +// +// Author: +// Matt Ward +// +// Copyright (c) 2016 Xamarin Inc. (http://xamarin.com) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using MonoDevelop.Core; +using MonoDevelop.Ide; +using MonoDevelop.Ide.Gui.Components; + +namespace MonoDevelop.DotNetCore +{ + class DotNetCoreNotInstalledInfoBar + { + string downloadUrl = DotNetCoreDownloadUrl.GetDotNetCoreDownloadUrl (); + + public string Message { get; set; } + public bool IsUnsupportedVersion { get; set; } + public bool IsNetStandard { get; set; } + public DotNetCoreVersion RequiredDotNetCoreVersion { get; set; } + public string CurrentDotNetCorePath { get; set; } + + public void Prompt () + { + var items = new InfoBarItem [] { + new InfoBarItem (GettextCatalog.GetString ("Download .NET Core"), InfoBarItemKind.Button, DownloadButtonClicked, true) + }; + + if (IsUnsupportedVersion || IsNetStandard || RequiredDotNetCoreVersion == null) //for .net standard we'll show generic message + Message = DotNetCoreSdk.GetNotSupportedVersionMessage (); + else { + Message = DotNetCoreSdk.GetNotSupportedVersionMessage (RequiredDotNetCoreVersion.OriginalString); + downloadUrl = DotNetCoreDownloadUrl.GetDotNetCoreDownloadUrl (RequiredDotNetCoreVersion); + } + + IdeApp.Workbench.ShowInfoBar (false, new InfoBarOptions (Message) { + Items = items + }); + } + + void DownloadButtonClicked () => IdeServices.DesktopService.ShowUrl (downloadUrl); + } +} diff --git a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreProjectExtension.cs b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreProjectExtension.cs index df43588e79..217a718ff0 100644 --- a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreProjectExtension.cs +++ b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreProjectExtension.cs @@ -194,10 +194,7 @@ namespace MonoDevelop.DotNetCore Task ShowCannotExecuteDotNetCoreApplicationDialog () { return Runtime.RunInMainThread (() => { - using (var dialog = new DotNetCoreNotInstalledDialog ()) { - dialog.Message = GettextCatalog.GetString (".NET Core is required to run this application."); - dialog.Show (); - } + CreateInfoBarInstance ().Prompt (); }); } @@ -206,19 +203,23 @@ namespace MonoDevelop.DotNetCore return Runtime.RunInMainThread (() => { if (ShownDotNetCoreSdkNotInstalledDialogForSolution ()) return; - + Project.ParentSolution.ExtendedProperties [ShownDotNetCoreSdkInstalledExtendedPropertyName] = "true"; - using (var dialog = new DotNetCoreNotInstalledDialog ()) { - dialog.IsUnsupportedVersion = unsupportedSdkVersion; - dialog.RequiredDotNetCoreVersion = DotNetCoreVersion.Parse (Project.TargetFramework.Id.Version); - dialog.CurrentDotNetCorePath = sdkPaths.MSBuildSDKsPath; - dialog.IsNetStandard = Project.TargetFramework.Id.IsNetStandard (); - dialog.Show (); - } + CreateInfoBarInstance (unsupportedSdkVersion).Prompt (); }); } + DotNetCoreNotInstalledInfoBar CreateInfoBarInstance (bool unsupportedSdkVersion = false) + { + return new DotNetCoreNotInstalledInfoBar { + IsUnsupportedVersion = unsupportedSdkVersion, + RequiredDotNetCoreVersion = DotNetCoreVersion.Parse (Project.TargetFramework.Id.Version), + CurrentDotNetCorePath = sdkPaths.MSBuildSDKsPath, + IsNetStandard = Project.TargetFramework.Id.IsNetStandard () + }; + } + bool ShownDotNetCoreSdkNotInstalledDialogForSolution () { return Project.ParentSolution.ExtendedProperties.Contains (ShownDotNetCoreSdkInstalledExtendedPropertyName); diff --git a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreSdk.cs b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreSdk.cs index 60028713d4..50992bf057 100644 --- a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreSdk.cs +++ b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreSdk.cs @@ -184,10 +184,10 @@ namespace MonoDevelop.DotNetCore { string GetMessage (DotNetCoreVersion currentVersion) { - return GettextCatalog.GetString ("NET Core {0}.{1} SDK version {2} is not compatible with this version of Visual Studio for Mac. Install the latest update to the .NET Core {0}.{1} SDK by visiting {3}.", currentVersion.Major, currentVersion.Minor, currentVersion.ToString (), DotNetCoreDownloadUrl.GetDotNetCoreDownloadUrl (currentVersion)); + return GettextCatalog.GetString (".NET Core {0}.{1} SDK version {2} is not compatible with this version of Visual Studio for Mac. Install the latest update to the .NET Core {0}.{1} SDK by visiting {3}", currentVersion.Major, currentVersion.Minor, currentVersion.ToString (), DotNetCoreDownloadUrl.GetDotNetCoreDownloadUrl (currentVersion)); } - var installedVersion = Versions.OrderByDescending (x => x).FirstOrDefault (); + var installedVersion = Versions?.OrderByDescending (x => x).FirstOrDefault (); if (installedVersion != null) { if (installedVersion < DotNetCoreVersion.MinimumSupportedSdkVersion) { return GetMessage (installedVersion); @@ -198,7 +198,7 @@ namespace MonoDevelop.DotNetCore } } - return GettextCatalog.GetString (".NET Core {0} SDK is required to build this application, and is not installed. Install the latest update to the .NET Core {0} SDK by visiting {1}.", version, DotNetCoreDownloadUrl.GetDotNetCoreDownloadUrl (version)); + return GettextCatalog.GetString (".NET Core {0} SDK is required to build this application, and is not installed. Install the latest update to the .NET Core {0} SDK by visiting {1}", version, DotNetCoreDownloadUrl.GetDotNetCoreDownloadUrl (version)); } } } -- cgit v1.2.3