Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLluis Sanchez <lluis@xamarin.com>2016-05-30 18:10:47 +0300
committerLluis Sanchez <lluis@xamarin.com>2016-05-31 10:25:47 +0300
commit942a665be2b7b484f1b746b541022d18abd16a7e (patch)
tree5e909038d06ab77de660a3d6df750242f107650b /main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Execution
parent0dbfcc068768e9614c4bfe13cd1a904804ddf37b (diff)
[Ide] Add execution mode selector
Diffstat (limited to 'main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Execution')
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Execution/ExecutionModeCommandService.cs121
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Execution/ExecutionModeSelectorDialog.cs157
2 files changed, 277 insertions, 1 deletions
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 269960bd81..b13bce51a3 100644
--- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Execution/ExecutionModeCommandService.cs
+++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Execution/ExecutionModeCommandService.cs
@@ -60,7 +60,7 @@ namespace MonoDevelop.Ide.Execution
}
return null;
}
-
+
public static void GenerateExecutionModeCommands (SolutionItem project, CanExecuteDelegate runCheckDelegate, CommandArrayInfo info)
{
CommandExecutionContext ctx = new CommandExecutionContext (project, runCheckDelegate);
@@ -416,6 +416,125 @@ namespace MonoDevelop.Ide.Execution
yield return mode;
}
}
+
+ internal static bool GetExecutionMode (CommandExecutionContext ctx, string id, out IExecutionModeSet modeSet, out IExecutionMode mode)
+ {
+ foreach (IExecutionModeSet mset in Runtime.ProcessService.GetExecutionModes ()) {
+ foreach (IExecutionMode m in mset.ExecutionModes) {
+ if (m.Id == id && ctx.CanExecute (m.ExecutionHandler)) {
+ modeSet = mset;
+ mode = m;
+ return true;
+ }
+ }
+ }
+ modeSet = null;
+ mode = null;
+ return false;
+ }
+
+ public static void GenerateExecutionModeCommands (SolutionItem item, CommandArrayInfo info)
+ {
+ foreach (var c in ExecutionModeCommandService.GetExecutionConfigurations (item)) {
+ info.Add (c.ModeSet.Name + " " + c.RunConfiguration.Name, c);
+ }
+ info.AddSeparator ();
+ info.Add (GettextCatalog.GetString ("Custom Configuration..."), "selector");
+ }
+
+ public static void ExecuteCommand (SolutionItem item, object data)
+ {
+ if (data is string) {
+ if ((string)data == "selector") {
+ using (var dlg = new ExecutionModeSelectorDialog ()) {
+ dlg.Load (item);
+ var cmd = dlg.Run ();
+ if (cmd.Id == "run") {
+
+ // Store the configuration for quick reuse
+ if (!dlg.SelectedConfiguration.IsDefaultConfiguration || (dlg.SelectedExecutionMode.Id != "Run" && dlg.SelectedExecutionMode.Id != "Debug")) {
+ var ec = new ExecutionConfiguration (dlg.SelectedConfiguration, null, dlg.SelectedExecutionMode);
+ var list = ExecutionModeCommandService.GetExecutionConfigurations (item).ToList ();
+ list.Remove (ec);
+ list.Insert (0, ec);
+ while (list.Count > 10)
+ list.RemoveAt (list.Count - 1);
+ ExecutionModeCommandService.SetExecutionConfigurations (item, list.ToArray ());
+ }
+
+ // Run the configuration
+ IdeApp.ProjectOperations.Execute (item, dlg.SelectedExecutionMode.ExecutionHandler);
+ }
+ }
+ }
+ }
+ var c = (ExecutionConfiguration)data;
+ IdeApp.ProjectOperations.Execute (item, c.Mode.ExecutionHandler);
+ }
+
+ internal static ExecutionConfiguration[] GetExecutionConfigurations (SolutionItem item)
+ {
+ var res = item.UserProperties.GetValue<ExecutionConfiguration []> ("ExecutionConfigurations") ?? new ExecutionConfiguration [0];
+ return res.Where (c => c.Resolve (item)).ToArray ();
+ }
+
+ internal static void SetExecutionConfigurations (SolutionItem item, ExecutionConfiguration [] configs)
+ {
+ item.UserProperties.SetValue ("ExecutionConfigurations", configs);
+ }
+ }
+
+ class ExecutionConfiguration
+ {
+ [ItemProperty]
+ string runConfigurationId { get; set; }
+
+ [ItemProperty]
+ string executionModeId { get; set; }
+
+ public IExecutionModeSet ModeSet { get; private set; }
+ public IExecutionMode Mode { get; private set; }
+ public RunConfiguration RunConfiguration { get; private set; }
+
+ internal ExecutionConfiguration ()
+ {
+ }
+
+ public ExecutionConfiguration (RunConfiguration runConfiguration, IExecutionModeSet modeSet, IExecutionMode mode)
+ {
+ runConfigurationId = runConfiguration.Id;
+ executionModeId = mode.Id;
+ }
+
+ internal bool Resolve (SolutionItem item)
+ {
+ if (RunConfiguration != null && Mode != null)
+ return true;
+ RunConfiguration = item.GetRunConfigurations ().FirstOrDefault (co => co.Id == runConfigurationId);
+ if (RunConfiguration == null)
+ return false;
+ var ctx = new CommandExecutionContext (item, h => item.CanExecute (new MonoDevelop.Projects.ExecutionContext (h, null, IdeApp.Workspace.ActiveExecutionTarget), IdeApp.Workspace.ActiveConfiguration, RunConfiguration));
+ IExecutionModeSet modeSet;
+ IExecutionMode mode;
+ if (!ExecutionModeCommandService.GetExecutionMode (ctx, executionModeId, out modeSet, out mode))
+ return false;
+ ModeSet = modeSet;
+ Mode = mode;
+ return true;
+ }
+
+ public override bool Equals (object obj)
+ {
+ var c = obj as ExecutionConfiguration;
+ return c != null && c.runConfigurationId == runConfigurationId && c.executionModeId == executionModeId;
+ }
+
+ public override int GetHashCode ()
+ {
+ unchecked {
+ return runConfigurationId.GetHashCode () ^ executionModeId.GetHashCode ();
+ }
+ }
}
class ExecutionCommandCustomizer: TypeExtensionNode, IExecutionCommandCustomizer
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Execution/ExecutionModeSelectorDialog.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Execution/ExecutionModeSelectorDialog.cs
new file mode 100644
index 0000000000..aa0c46ec49
--- /dev/null
+++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Execution/ExecutionModeSelectorDialog.cs
@@ -0,0 +1,157 @@
+//
+// ExecutionModeSelectorDialog.cs
+//
+// Author:
+// Lluis Sanchez Gual <lluis@xamarin.com>
+//
+// Copyright (c) 2016 Xamarin, Inc (http://www.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 System;
+using Xwt;
+using MonoDevelop.Core;
+using MonoDevelop.Projects;
+using MonoDevelop.Core.Execution;
+using System.Linq;
+
+namespace MonoDevelop.Ide.Execution
+{
+ class ExecutionModeSelectorDialog: Dialog
+ {
+ SolutionItem item;
+
+ ListView listConfigs;
+ TreeView treeModes;
+
+ ListStore storeConfigs;
+ TreeStore storeModes;
+
+ DataField<string> configNameField = new DataField<string> ();
+ DataField<RunConfiguration> configField = new DataField<RunConfiguration> ();
+ DataField<string> modeNameField = new DataField<string> ();
+ DataField<IExecutionMode> modeField = new DataField<IExecutionMode> ();
+
+ public ExecutionModeSelectorDialog ()
+ {
+ Title = GettextCatalog.GetString ("Execution Mode Selector");
+
+ Width = 400;
+ Height = 300;
+
+ var box = new VBox ();
+ Content = box;
+
+ box.PackStart (new Label (GettextCatalog.GetString ("Run Configurations:")));
+
+ storeConfigs = new ListStore (configNameField, configField);
+ listConfigs = new ListView (storeConfigs);
+ listConfigs.Columns.Add (GettextCatalog.GetString ("Name"), configNameField);
+ listConfigs.HeightRequest = 130;
+ box.PackStart (listConfigs);
+
+ box.PackStart (new Label (GettextCatalog.GetString ("Execution Modes:")));
+
+ storeModes = new TreeStore (modeNameField, modeField);
+ treeModes = new TreeView (storeModes);
+ treeModes.Columns.Add (GettextCatalog.GetString ("Name"), modeNameField);
+ treeModes.HeightRequest = 130;
+ box.PackStart (treeModes);
+
+ Buttons.Add (Command.Cancel);
+ Buttons.Add (new Command ("run", GettextCatalog.GetString ("Run")));
+
+ listConfigs.SelectionChanged += (sender, e) => LoadModes ();
+ }
+
+ public void Load (SolutionItem item)
+ {
+ this.item = item;
+ storeConfigs.Clear ();
+ foreach (var c in item.GetRunConfigurations ()) {
+ var r = storeConfigs.AddRow ();
+ storeConfigs.SetValues (r, configNameField, c.Name, configField, c);
+ }
+ listConfigs.SelectRow (0);
+ LoadModes ();
+ }
+
+ void LoadModes ()
+ {
+ storeModes.Clear ();
+ var currentMode = SelectedExecutionMode;
+ bool nodeSelected = false;
+ var ctx = new CommandExecutionContext (item, h => item.CanExecute (new ExecutionContext (h, null, IdeApp.Workspace.ActiveExecutionTarget), IdeApp.Workspace.ActiveConfiguration));
+ foreach (var modeSet in Runtime.ProcessService.GetExecutionModes ()) {
+ TreeNavigator setNode = null;
+ foreach (var mode in modeSet.ExecutionModes) {
+ if (ctx.CanExecute (mode.ExecutionHandler)) {
+ if (setNode == null) {
+ setNode = storeModes.AddNode ();
+ setNode.SetValue (modeNameField, modeSet.Name);
+ setNode.SetValue (modeField, mode);
+ if (mode.Id == currentMode?.Id) {
+ treeModes.SelectRow (setNode.CurrentPosition);
+ nodeSelected = true;
+ }
+ }
+ var node = storeModes.AddNode (setNode.CurrentPosition);
+ node.SetValue (modeNameField, mode.Name);
+ node.SetValue (modeField, mode);
+ if (!nodeSelected && mode.Id == currentMode?.Id) {
+ treeModes.SelectRow (node.CurrentPosition);
+ nodeSelected = true;
+ }
+ }
+ }
+ // If the mode only has one child, remove it, we don't need to show it
+ if (setNode != null && setNode.MoveToChild ()) {
+ var pos = setNode.Clone ();
+ if (!setNode.MoveNext ())
+ pos.Remove ();
+ }
+ }
+ if (!nodeSelected && storeModes.GetFirstNode () != null)
+ treeModes.SelectRow (storeModes.GetFirstNode ().CurrentPosition);
+ }
+
+ protected override void OnCommandActivated (Command cmd)
+ {
+ if (cmd.Id == "run") {
+ Respond (cmd);
+ return;
+ }
+ base.OnCommandActivated (cmd);
+ }
+
+ public RunConfiguration SelectedConfiguration {
+ get {
+ var r = listConfigs.SelectedRow;
+ return r != -1 ? storeConfigs.GetValue (r, configField) : null;
+ }
+ }
+
+ public IExecutionMode SelectedExecutionMode {
+ get {
+ var n = treeModes.SelectedRow;
+ return n != null ? storeModes.GetNavigatorAt (n).GetValue (modeField) : null;
+ }
+ }
+ }
+}
+