diff options
author | David Karlaš <david.karlas@xamarin.com> | 2015-11-24 20:46:28 +0300 |
---|---|---|
committer | David Karlaš <david.karlas@xamarin.com> | 2015-11-24 20:46:28 +0300 |
commit | fdcef13057a9c4a9bc924602c9b2b33c1da3bf63 (patch) | |
tree | f5d45bca682a39c3946dbd9fee281e152288a4aa /main/src/addins/MonoDevelop.Refactoring | |
parent | ee4190106f0d102c4fdce57fc3c5637cbce7b9aa (diff) | |
parent | 07a993cf6d80660fde31099c1aca8029a3035807 (diff) |
Merge branch 'master' into newExceptionDialog
Diffstat (limited to 'main/src/addins/MonoDevelop.Refactoring')
7 files changed, 92 insertions, 41 deletions
diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.AnalysisCore/AnalysisCommands.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.AnalysisCore/AnalysisCommands.cs index 392aacd522..619a60fa9e 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.AnalysisCore/AnalysisCommands.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.AnalysisCore/AnalysisCommands.cs @@ -25,6 +25,7 @@ // THE SOFTWARE. using System; +using MonoDevelop.Components; using MonoDevelop.Components.Commands; using System.Linq; using MonoDevelop.Core; @@ -120,6 +121,8 @@ namespace MonoDevelop.AnalysisCore ((System.Action)dataItem) (); return; } + if (!RefactoringService.CheckUserSettings ()) + return; var action = dataItem as IAnalysisFixAction; if (action != null) { action.Fix (); @@ -289,7 +292,7 @@ namespace MonoDevelop.AnalysisCore { var lang = "text/x-csharp"; - OpenFileDialog dlg = new OpenFileDialog ("Export Rules", FileChooserAction.Save); + OpenFileDialog dlg = new OpenFileDialog ("Export Rules", MonoDevelop.Components.FileChooserAction.Save); dlg.InitialFileName = "rules.html"; if (!dlg.Run ()) return; diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.CodeActions/CodeActionEditorExtension.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.CodeActions/CodeActionEditorExtension.cs index 8cbdfbf6dc..fc93c8dc00 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.CodeActions/CodeActionEditorExtension.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.CodeActions/CodeActionEditorExtension.cs @@ -429,6 +429,8 @@ namespace MonoDevelop.CodeActions void PopulateFixes (FixMenuDescriptor menu, ref int items) { + if (!RefactoringService.ShowFixes) + return; int mnemonic = 1; bool gotImportantFix = false, addedSeparator = false; var fixesAdded = new List<string> (); diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.Rename/RenameItemDialog.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.Rename/RenameItemDialog.cs index e4498221a7..69852183a5 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.Rename/RenameItemDialog.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.Rename/RenameItemDialog.cs @@ -140,6 +140,7 @@ namespace MonoDevelop.Refactoring.Rename buttonPreview.Clicked += OnPreviewClicked; entry.Changed += delegate { buttonPreview.Sensitive = buttonOk.Sensitive = ValidateName (); }; ValidateName (); + this.hbox1.HideAll (); } bool ValidateName () diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.addin.xml b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.addin.xml index 8151d80966..ed0ba0695c 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.addin.xml +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.addin.xml @@ -95,7 +95,7 @@ defaultHandler = "MonoDevelop.Refactoring.ResolveCommandHandler" type="array" _label = "Resolve"/> - + <Command id = "MonoDevelop.Refactoring.RefactoryCommands.CurrentRefactoryOperations" defaultHandler = "MonoDevelop.Refactoring.CurrentRefactoryOperationsHandler" type="array" @@ -182,7 +182,7 @@ func="MonoDevelop.AnalysisCore.Rules.NamingConventions.ClassNaming" />--> </Category> </Extension> - + <Extension path = "/MonoDevelop/AnalysisCore/FixHandlers"> <Handler fixName="RenameMember" class = "MonoDevelop.AnalysisCore.Fixes.RenameMemberHandler" /> <Handler fixName="Generic" class = "MonoDevelop.AnalysisCore.Fixes.GenericFixHandler" /> diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.csproj b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.csproj index d47fae2ad7..6fe3d47b41 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.csproj +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.csproj @@ -42,6 +42,7 @@ <NoWarn>1591;1573</NoWarn> <DebugSymbols>true</DebugSymbols> <DocumentationFile>..\..\..\build\AddIns\MonoDevelop.Refactoring\MonoDevelop.Refactoring.xml</DocumentationFile> + <DebugType>full</DebugType> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'ReleaseMac|AnyCPU' "> <Optimize>true</Optimize> diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/RefactoringService.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/RefactoringService.cs index 64096e8329..9e18efff67 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/RefactoringService.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/RefactoringService.cs @@ -42,6 +42,7 @@ using Mono.TextEditor; using MonoDevelop.Ide.TypeSystem; using System.Diagnostics; using MonoDevelop.Core.Instrumentation; +using MonoDevelop.Ide; namespace MonoDevelop.Refactoring { @@ -293,10 +294,53 @@ namespace MonoDevelop.Refactoring return RunAll (allFixes, refactoringContext, script); } } - + + const string EnableRefactorings = "RefactoringSettings.EnableRefactorings"; + + internal static bool CheckUserSettings() + { + var hasRefactoringSettings = IdeApp.ProjectOperations.CurrentSelectedSolution == null || + IdeApp.ProjectOperations.CurrentSelectedSolution.UserProperties.HasValue (EnableRefactorings); + if (!hasRefactoringSettings) { + var useRefactoringsButton = new AlertButton (GettextCatalog.GetString("Use refactorings on this solution")); + var text = GettextCatalog.GetString ( +@"WARNING: The Xamarin Studio refactoring operations do not yet support C# 6. + +You may continue to use refactoring operations with C# 6, however you should check the results carefully to make sure that they have not made incorrect changes to your code. In particular, the ""?."" null propagating dereference will be changed to ""."", a simple dereference, which can cause unexpected NullReferenceExceptions at runtime."); + var message = new QuestionMessage (text); + message.Buttons.Add (useRefactoringsButton); + message.Buttons.Add (AlertButton.Cancel); + message.Icon = Gtk.Stock.DialogWarning; + message.DefaultButton = 1; + + var result = MessageService.AskQuestion (message); + if (result == AlertButton.Cancel) + return false; + ShowFixes = result == useRefactoringsButton; + } + return ShowFixes; + } + + internal static bool ShowFixes { + get { + if (Ide.IdeApp.ProjectOperations.CurrentSelectedSolution != null) { + var hasRefactoringSettings = IdeApp.ProjectOperations.CurrentSelectedSolution.UserProperties.HasValue (EnableRefactorings); + return !hasRefactoringSettings || IdeApp.ProjectOperations.CurrentSelectedSolution.UserProperties.GetValue<bool> (EnableRefactorings); + } + return true; + } + set { + IdeApp.ProjectOperations.CurrentSelectedSolution.UserProperties.SetValue (EnableRefactorings, value); + IdeApp.ProjectOperations.CurrentSelectedSolution.SaveUserProperties (); + } + } + + public static void ApplyFix (CodeAction action, IRefactoringContext context) { - using(var script = context.CreateScript ()) { + if (!CheckUserSettings ()) + return; + using (var script = context.CreateScript ()) { action.Run (context, script); } } diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/RefactoryCommands.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/RefactoryCommands.cs index 1dd79118c7..d89a7c4081 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/RefactoryCommands.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/RefactoryCommands.cs @@ -269,49 +269,49 @@ namespace MonoDevelop.Refactoring })); added = true; } - - foreach (var refactoring in RefactoringService.Refactorings) { - if (refactoring.IsValid (options)) { - CommandInfo info = new CommandInfo (refactoring.GetMenuDescription (options)); - info.AccelKey = refactoring.AccelKey; - ciset.CommandInfos.Add (info, new Action (new RefactoringOperationWrapper (refactoring, options).Operation)); + if (RefactoringService.ShowFixes) { + foreach (var refactoring in RefactoringService.Refactorings) { + if (refactoring.IsValid (options)) { + CommandInfo info = new CommandInfo (refactoring.GetMenuDescription (options)); + info.AccelKey = refactoring.AccelKey; + ciset.CommandInfos.Add (info, new Action (new RefactoringOperationWrapper (refactoring, options).Operation)); + } } - } - var refactoringInfo = doc.Annotation<RefactoringDocumentInfo> (); - if (refactoringInfo == null) { - refactoringInfo = new RefactoringDocumentInfo (); - doc.AddAnnotation (refactoringInfo); - } - var loc = doc.Editor.Caret.Location; - bool first = true; - if (refactoringInfo.lastDocument != doc.ParsedDocument || loc != lastLocation) { - try { - refactoringInfo.validActions = RefactoringService.GetValidActions (doc, loc, new CancellationTokenSource (500).Token); - } catch (TaskCanceledException) { - } catch (AggregateException ae) { - ae.Flatten ().Handle (x => x is TaskCanceledException); + var refactoringInfo = doc.Annotation<RefactoringDocumentInfo> (); + if (refactoringInfo == null) { + refactoringInfo = new RefactoringDocumentInfo (); + doc.AddAnnotation (refactoringInfo); } + var loc = doc.Editor.Caret.Location; + bool first = true; + if (refactoringInfo.lastDocument != doc.ParsedDocument || loc != lastLocation) { + try { + refactoringInfo.validActions = RefactoringService.GetValidActions (doc, loc, new CancellationTokenSource (500).Token); + } catch (TaskCanceledException) { + } catch (AggregateException ae) { + ae.Flatten ().Handle (x => x is TaskCanceledException); + } - lastLocation = loc; - refactoringInfo.lastDocument = doc.ParsedDocument; - } - if (refactoringInfo.validActions != null && refactoringInfo.lastDocument != null && refactoringInfo.lastDocument.CreateRefactoringContext != null) { - var context = refactoringInfo.lastDocument.CreateRefactoringContext (doc, CancellationToken.None); + lastLocation = loc; + refactoringInfo.lastDocument = doc.ParsedDocument; + } + if (refactoringInfo.validActions != null && refactoringInfo.lastDocument != null && refactoringInfo.lastDocument.CreateRefactoringContext != null) { + var context = refactoringInfo.lastDocument.CreateRefactoringContext (doc, CancellationToken.None); - foreach (var fix_ in refactoringInfo.validActions.OrderByDescending (i => Tuple.Create (CodeActionEditorExtension.IsAnalysisOrErrorFix(i), (int)i.Severity, CodeActionEditorExtension.GetUsage (i.IdString)))) { - if (CodeActionEditorExtension.IsAnalysisOrErrorFix (fix_)) - continue; - var fix = fix_; - if (first) { - first = false; - if (ciset.CommandInfos.Count > 0) - ciset.CommandInfos.AddSeparator (); - } + foreach (var fix_ in refactoringInfo.validActions.OrderByDescending (i => Tuple.Create (CodeActionEditorExtension.IsAnalysisOrErrorFix(i), (int)i.Severity, CodeActionEditorExtension.GetUsage (i.IdString)))) { + if (CodeActionEditorExtension.IsAnalysisOrErrorFix (fix_)) + continue; + var fix = fix_; + if (first) { + first = false; + if (ciset.CommandInfos.Count > 0) + ciset.CommandInfos.AddSeparator (); + } - ciset.CommandInfos.Add (fix.Title, new Action (() => RefactoringService.ApplyFix (fix, context))); + ciset.CommandInfos.Add (fix.Title, new Action (() => RefactoringService.ApplyFix (fix, context))); + } } } - if (ciset.CommandInfos.Count > 0) { ainfo.Add (ciset, null); added = true; |