diff options
author | Marius Ungureanu <marius.ungureanu@xamarin.com> | 2015-09-11 15:12:02 +0300 |
---|---|---|
committer | Marius Ungureanu <marius.ungureanu@xamarin.com> | 2015-09-17 18:38:42 +0300 |
commit | 0ad322ab91249209873cac51dc18772ea443dff6 (patch) | |
tree | c4ef9608c16495766bfc167a3b6ce63aeb2496ec /main/src/core/MonoDevelop.Ide/MonoDevelop.Components.MainToolbar | |
parent | ed383b37aaf8d81be9ff1ace90a524ce63196c02 (diff) |
[Ide] Migrate IRuntimeModel to have a self-contained mutable structure
Diffstat (limited to 'main/src/core/MonoDevelop.Ide/MonoDevelop.Components.MainToolbar')
3 files changed, 103 insertions, 79 deletions
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.MainToolbar/MainToolbar.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.MainToolbar/MainToolbar.cs index 0c2f09ee5c..751ebc8329 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.MainToolbar/MainToolbar.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.MainToolbar/MainToolbar.cs @@ -110,19 +110,22 @@ namespace MonoDevelop.Components.MainToolbar return; } - renderer.Visible = runtime.Visible; - renderer.Sensitive = runtime.Enabled; - renderer.Xpad = (uint)(runtime.IsIndented ? 18 : 3); - - if (!runtimeCombo.PopupShown) { - // no need to ident text when the combo dropdown is not showing - if (Platform.IsWindows) - renderer.Xpad = 3; - renderer.Text = runtime.FullDisplayString; - renderer.Attributes = normalAttributes; - } else { - renderer.Text = runtime.DisplayString; - renderer.Attributes = runtime.Notable ? boldAttributes : normalAttributes; + using (var mutableModel = runtime.GetMutableModel ()) { + renderer.Visible = mutableModel.Visible; + renderer.Sensitive = mutableModel.Enabled; + renderer.Xpad = (uint)(runtime.IsIndented ? 18 : 3); + + if (!runtimeCombo.PopupShown) { + // no need to ident text when the combo dropdown is not showing + if (Platform.IsWindows) + renderer.Xpad = 3; + renderer.Text = mutableModel.FullDisplayString; + renderer.Attributes = normalAttributes; + } else { + renderer.Text = mutableModel.DisplayString; + renderer.Attributes = runtime.Notable ? boldAttributes : normalAttributes; + } + } } diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.MainToolbar/MainToolbarController.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.MainToolbar/MainToolbarController.cs index e07e8dd7e3..46bb8df993 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.MainToolbar/MainToolbarController.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.MainToolbar/MainToolbarController.cs @@ -343,8 +343,10 @@ namespace MonoDevelop.Components.MainToolbar var runtimes = ToolbarView.RuntimeModel.Cast<RuntimeModel> ().ToList (); for (int iter = 0; iter < runtimes.Count; ++iter) { var item = runtimes [iter]; - if (!item.Enabled) - continue; + using (var model = item.GetMutableModel ()) { + if (!model.Enabled) + continue; + } var target = item.ExecutionTarget; if (target == null || !target.Enabled) @@ -762,8 +764,6 @@ namespace MonoDevelop.Components.MainToolbar public RuntimeModel (MainToolbarController controller, ExecutionTarget target) : this (controller) { ExecutionTarget = target; - Enabled = !(ExecutionTarget is ExecutionTargetGroup); - Visible = true; } public RuntimeModel (MainToolbarController controller, ExecutionTarget target, RuntimeModel parent) : this (controller, target) @@ -785,6 +785,7 @@ namespace MonoDevelop.Components.MainToolbar public IEnumerable<IRuntimeModel> Children { get { return children; } } + public bool Notable { get { return ExecutionTarget != null && ExecutionTarget.Notable; } } @@ -799,16 +800,6 @@ namespace MonoDevelop.Components.MainToolbar set; } - public bool Visible { - get; - private set; - } - - public bool Enabled { - get; - private set; - } - public bool IsSeparator { get { return Command == null && ExecutionTarget == null; } } @@ -818,43 +809,64 @@ namespace MonoDevelop.Components.MainToolbar set; } - public string DisplayString { - get { - if (Command != null) { - var ci = IdeApp.CommandService.GetCommandInfo (Command, new CommandTargetRoute (Controller.lastCommandTarget)); - Visible = ci.Visible; - Enabled = ci.Enabled; - return RemoveUnderline (ci.Text); - } + public bool NotifyActivated () + { + if (Command != null && IdeApp.CommandService.DispatchCommand (Command, CommandSource.ContextMenu)) + return true; + return false; + } - if (ExecutionTarget == null) - return ""; + public IRuntimeMutableModel GetMutableModel () + { + return Command != null ? new RuntimeMutableModel (Controller, Command) : new RuntimeMutableModel (ExecutionTarget, HasParent); + } + } + + class RuntimeMutableModel : IRuntimeMutableModel + { + public RuntimeMutableModel (MainToolbarController controller, object command) + { + var ci = IdeApp.CommandService.GetCommandInfo (command, new CommandTargetRoute (controller.lastCommandTarget)); + Visible = ci.Visible; + Enabled = ci.Enabled; + DisplayString = FullDisplayString = RemoveUnderline (ci.Text); + } - return !HasParent ? ExecutionTarget.FullName : ExecutionTarget.Name; + public RuntimeMutableModel (ExecutionTarget target, bool hasParent) + { + Enabled = !(target is ExecutionTargetGroup); + Visible = true; + if (target == null) + DisplayString = FullDisplayString = string.Empty; + else { + FullDisplayString = target.FullName; + DisplayString = !hasParent ? target.FullName : target.Name; } } - public string FullDisplayString { - get { - if (Command != null) { - var ci = IdeApp.CommandService.GetCommandInfo (Command, new CommandTargetRoute (Controller.lastCommandTarget)); - Visible = ci.Visible; - Enabled = ci.Enabled; - return RemoveUnderline (ci.Text); - } + // Marker so it won't be reused. + public void Dispose () + { + } - if (ExecutionTarget == null) - return ""; + public bool Visible { + get; + private set; + } - return ExecutionTarget.FullName; - } + public bool Enabled { + get; + private set; } - public bool NotifyActivated () - { - if (Command != null && IdeApp.CommandService.DispatchCommand (Command, CommandSource.ContextMenu)) - return true; - return false; + public string DisplayString { + get; + private set; + } + + public string FullDisplayString { + get; + private set; } static string RemoveUnderline (string s) diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.MainToolbar/MainToolbarModels.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.MainToolbar/MainToolbarModels.cs index bdd0036f0d..eb814b067b 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.MainToolbar/MainToolbarModels.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.MainToolbar/MainToolbarModels.cs @@ -51,30 +51,6 @@ namespace MonoDevelop.Components.MainToolbar IEnumerable<IRuntimeModel> Children { get; } /// <summary> - /// Gets the display string to be used inside a context menu. - /// </summary> - /// <value>The display string.</value> - string DisplayString { get; } - - /// <summary> - /// Gets the display string to be for selected items. - /// </summary> - /// <value>The full display string.</value> - string FullDisplayString { get; } - - /// <summary> - /// Gets whether the menu item is visible. - /// </summary> - /// <value><c>true</c> if visible; otherwise, <c>false</c>.</value> - bool Visible { get; } - - /// <summary> - /// Gets whether the menu item is enabled. - /// </summary> - /// <value><c>true</c> if enabled; otherwise, <c>false</c>.</value> - bool Enabled { get; } - - /// <summary> /// Gets whether the menu item is a separator. /// </summary> /// <value><c>true</c> if this instance is separator; otherwise, <c>false</c>.</value> @@ -100,6 +76,39 @@ namespace MonoDevelop.Components.MainToolbar /// </remarks> /// <value><c>true</c> if this instance has a parent; otherwise, <c>false</c>.</value> bool HasParent { get; } + + /// <summary> + /// Gets the runtime combo item model. + /// </summary> + /// <value>The runtime combo item.</value> + IRuntimeMutableModel GetMutableModel(); + } + + public interface IRuntimeMutableModel : IDisposable + { + /// <summary> + /// Gets the display string to be used inside a context menu. + /// </summary> + /// <value>The display string.</value> + string DisplayString { get; } + + /// <summary> + /// Gets the display string to be for selected items. + /// </summary> + /// <value>The full display string.</value> + string FullDisplayString { get; } + + /// <summary> + /// Gets whether the menu item is visible. + /// </summary> + /// <value><c>true</c> if visible; otherwise, <c>false</c>.</value> + bool Visible { get; } + + /// <summary> + /// Gets whether the menu item is enabled. + /// </summary> + /// <value><c>true</c> if enabled; otherwise, <c>false</c>.</value> + bool Enabled { get; } } public interface ISearchMenuModel |