diff options
author | Lluis Sanchez Gual <lluis@xamarin.com> | 2015-03-20 20:02:08 +0300 |
---|---|---|
committer | Lluis Sanchez Gual <lluis@xamarin.com> | 2015-03-20 20:02:08 +0300 |
commit | 01c48e7c381812d4aa79ae96d85e969e3805c5b0 (patch) | |
tree | 80cac890c3f85a0f59bcb300359b386674f108cf /main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Execution | |
parent | 2f7a4f23f18550d8b382433cef58bcbe4adb5a35 (diff) | |
parent | fb917669e5ead54795e31aa9706c5f2a1f7fb5bf (diff) |
Merge remote-tracking branch 'origin/master' into new-project-model
Conflicts:
main/external/fsharpbinding
main/external/mono-addins
main/external/nrefactory
main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger/DebuggingService.cs
main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger/Extensions.cs
main/src/addins/MonoDevelop.GtkCore/MonoDevelop.GtkCore.GuiBuilder/GtkProjectServiceExtension.cs
main/src/core/MonoDevelop.Core/MonoDevelop.Core/Runtime.cs
main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Formats.MSBuild/MSBuildProjectHandler.cs
main/src/core/MonoDevelop.Core/MonoDevelop.Projects/Project.cs
main/src/core/MonoDevelop.Core/MonoDevelop.Projects/ProjectService.cs
main/src/core/MonoDevelop.Core/MonoDevelop.Projects/SolutionItem.cs
main/src/core/MonoDevelop.Ide/MonoDevelop.Components.MainToolbar/MainToolbar.cs
main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Commands/ProjectCommands.cs
main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CustomTools/CustomToolService.cs
main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.FindInFiles/FindReplace.cs
main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/Workbench.cs
main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Projects/NewProjectController.cs
main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/RootWorkspace.cs
main/tests/UnitTests/UnitTests.csproj
version-checks
Diffstat (limited to 'main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Execution')
3 files changed, 109 insertions, 14 deletions
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Execution/CustomExecutionMode.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Execution/CustomExecutionMode.cs index fb2d3f916b..80dd8a38ff 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Execution/CustomExecutionMode.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Execution/CustomExecutionMode.cs @@ -34,6 +34,7 @@ using MonoDevelop.Ide.Gui.Dialogs; using MonoDevelop.Projects; using MonoDevelop.Core.Serialization; using Mono.Addins; +using System.Linq; namespace MonoDevelop.Ide.Execution { @@ -113,7 +114,8 @@ namespace MonoDevelop.Ide.Execution public bool CanExecute (ExecutionCommand command) { if (Mode != null) - return Mode.ExecutionHandler.CanExecute (command); + return Mode.ExecutionHandler.CanExecute (command) + && GetCachedCustomizers ().All (c => c.Item1.CanCustomize (command)); return false; } @@ -125,35 +127,51 @@ namespace MonoDevelop.Ide.Execution public ProcessAsyncOperation Execute (ExecutionCommand command, IConsole console, bool allowPrompt, bool forcePrompt) { if ((PromptForParameters || forcePrompt) && allowPrompt) { - CommandExecutionContext ctx = new CommandExecutionContext (Project, command); + var ctx = new CommandExecutionContext (Project, command); CustomExecutionMode customMode = ExecutionModeCommandService.ShowParamtersDialog (ctx, Mode, this); if (customMode == null) return new CancelledProcessAsyncOperation (); - else - return customMode.Execute (command, console, false, false); + return customMode.Execute (command, console, false, false); } - if (commandData != null) { - foreach (KeyValuePair<string,object> cmdData in commandData) { - ExecutionCommandCustomizer cc = ExecutionModeCommandService.GetExecutionCommandCustomizer (cmdData.Key); - if (cc != null) - cc.Customize (command, cmdData.Value); - } + + foreach (var cc in GetCachedCustomizers ()) { + cc.Item1.Customize (command, cc.Item2); } - ParameterizedExecutionHandler cmode = Mode.ExecutionHandler as ParameterizedExecutionHandler; + + var cmode = Mode.ExecutionHandler as ParameterizedExecutionHandler; if (cmode != null) { CommandExecutionContext ctx = new CommandExecutionContext (Project, command); return cmode.Execute (command, console, ctx, Data); - } else - return Mode.ExecutionHandler.Execute (command, console); + } + + return Mode.ExecutionHandler.Execute (command, console); } #endregion + + IList<Tuple<ExecutionCommandCustomizer,object>> cachedCustomizers; + + IList<Tuple<ExecutionCommandCustomizer,object>> GetCachedCustomizers () + { + if (cachedCustomizers != null) + return cachedCustomizers; + + if (commandData == null) + return cachedCustomizers = new Tuple<ExecutionCommandCustomizer,object>[0]; + + return cachedCustomizers = commandData + .Select (cmdData => Tuple.Create ( + ExecutionModeCommandService.GetExecutionCommandCustomizer (cmdData.Key), + cmdData.Value)) + .Where (cc => cc != null) + .ToList(); + } } class UnknownModeData { } - internal enum CustomModeScope + enum CustomModeScope { Project = 0, Solution = 1, diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Execution/ExecutionModeCommandService.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Execution/ExecutionModeCommandService.cs index 319e34fb0d..4b18baf4a2 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Execution/ExecutionModeCommandService.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Execution/ExecutionModeCommandService.cs @@ -88,11 +88,36 @@ namespace MonoDevelop.Ide.Execution if (info.Count > 0) info.AddSeparator (); } + + var targets = new List<ExecutionTarget> (); + FlattenExecutionTargets (targets, project.GetExecutionTargets (IdeApp.Workspace.ActiveConfiguration)); + + if (targets.Count > 1) { + foreach (var t in targets) { + var h = new TargetedExecutionHandler (Runtime.ProcessService.DefaultExecutionHandler, t); + CommandInfo ci = info.Add (t.FullName, new CommandItem (ctx, new ExecutionMode (t.Id, t.FullName, h))); + ci.Description = GettextCatalog.GetString ("Run With: {0}", ci.Text); + } + info.AddSeparator (); + } + if (supportsParameterization) { info.AddSeparator (); info.Add (GettextCatalog.GetString ("Edit Custom Modes..."), new CommandItem (ctx, null)); } } + + static void FlattenExecutionTargets (List<ExecutionTarget> addToList, IEnumerable<ExecutionTarget> targets) + { + foreach (var t in targets) { + var group = t as ExecutionTargetGroup; + if (group != null) { + FlattenExecutionTargets (addToList, group); + } else { + addToList.Add (t); + } + } + } public static IExecutionHandler GetExecutionModeForCommand (object data) { diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Execution/TargetedExecutionHandler.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Execution/TargetedExecutionHandler.cs new file mode 100644 index 0000000000..63ba2161d0 --- /dev/null +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Execution/TargetedExecutionHandler.cs @@ -0,0 +1,52 @@ +// +// TargetedExecutionHandler.cs +// +// Author: +// Michael Hutchinson <m.j.hutchinson@gmail.com> +// +// Copyright (c) 2015 Xamarin Inc. +// +// 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.Execution; + +namespace MonoDevelop.Ide.Execution +{ + class TargetedExecutionHandler : ITargetedExecutionHandler + { + public ExecutionTarget Target { get; set; } + public IExecutionHandler Handler { get; set; } + + public TargetedExecutionHandler (IExecutionHandler handler, ExecutionTarget target) + { + Target = target; + Handler = handler; + } + + public bool CanExecute (ExecutionCommand command) + { + return Handler.CanExecute (command); + } + + public IProcessAsyncOperation Execute (ExecutionCommand command, IConsole console) + { + return Handler.Execute (command, console); + } + } +}
\ No newline at end of file |