diff options
author | Marius Ungureanu <marius.ungureanu@xamarin.com> | 2015-02-14 01:52:34 +0300 |
---|---|---|
committer | Marius Ungureanu <marius.ungureanu@xamarin.com> | 2015-02-14 01:59:59 +0300 |
commit | da3896bbba30a1cda1a95e5734930e43cacd25a6 (patch) | |
tree | 59bb0aa8663402c56088a2c495d8a2a335fb0acd /main | |
parent | 0a13c957cb6565a916f6433d8d5bca8dc43ceb31 (diff) |
[Toolbar] Make MainToolbarController the ICommandBar implementor
Move all the necessary things to compile to IMainToolbarView.
Diffstat (limited to 'main')
4 files changed, 133 insertions, 64 deletions
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.MainToolbar/IMainToolbarView.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.MainToolbar/IMainToolbarView.cs index a54d11045f..17da125c1c 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.MainToolbar/IMainToolbarView.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.MainToolbar/IMainToolbarView.cs @@ -28,9 +28,54 @@ using MonoDevelop.Ide; namespace MonoDevelop.Components.MainToolbar { + public enum OperationIcon { + Run, + Build, + Stop + } + public interface IMainToolbarView { + #region RunButton + /// <summary> + /// Gets or sets a value indicating whether the run button is interactible. + /// </summary> + /// <value><c>true</c> if run button is interactible; otherwise, <c>false</c>.</value> + bool RunButtonSensitivity { get; set; } + + /// <summary> + /// Sets the run button icon type. + /// </summary> + /// <value>The run button icon type.</value> + OperationIcon RunButtonIcon { set; } + #endregion + + #region Configuration/Platform Selector + /// <summary> + /// Gets or sets a value indicating whether the configuration/platform selector is interactible. + /// </summary> + /// <value><c>true</c> if configuration/platform selector is interactible; otherwise, <c>false</c>.</value> + bool ConfigurationPlatformSensitivity { get; set; } + + /// <summary> + /// Occurs when run button clicked. + /// </summary> + event EventHandler RunButtonClicked; + #endregion + + #region SearchEntry + /// <summary> + /// Gets or sets a value indicating whether the search entry is interactible. + /// </summary> + /// <value><c>true</c> if search entry is interactible; otherwise, <c>false</c>.</value> + bool SearchSensivitity { set; } + #endregion + #region StatusBar + /// <summary> + /// Gets the native status bar. + /// </summary> + /// <value>The native status bar.</value> StatusBar StatusBar { get; } #endregion 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 18a224efb1..14f4647e78 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.MainToolbar/MainToolbar.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.MainToolbar/MainToolbar.cs @@ -49,7 +49,7 @@ using System.Text; namespace MonoDevelop.Components.MainToolbar { - class MainToolbar: Gtk.EventBox, ICommandBar, IMainToolbarView + class MainToolbar: Gtk.EventBox, IMainToolbarView { const string ToolbarExtensionPath = "/MonoDevelop/Ide/CommandBar"; const string TargetsMenuPath = "/MonoDevelop/Ide/TargetSelectorCommands"; @@ -383,7 +383,6 @@ namespace MonoDevelop.Components.MainToolbar UpdateCombos (); button.Clicked += HandleStartButtonClicked; - IdeApp.CommandService.RegisterCommandBar (this); IdeApp.CommandService.ActiveWidgetChanged += (sender, e) => { lastCommandTarget = new WeakReference (e.OldActiveWidget); @@ -943,65 +942,12 @@ namespace MonoDevelop.Components.MainToolbar SetSearchCategory ("type"); } - CommandInfo GetStartButtonCommandInfo (out RoundButton.OperationIcon operation) - { - if (!IdeApp.ProjectOperations.CurrentRunOperation.IsCompleted || !IdeApp.ProjectOperations.CurrentBuildOperation.IsCompleted) { - operation = RoundButton.OperationIcon.Stop; - return IdeApp.CommandService.GetCommandInfo (MonoDevelop.Ide.Commands.ProjectCommands.Stop); - } - else { - operation = RoundButton.OperationIcon.Run; - var ci = IdeApp.CommandService.GetCommandInfo ("MonoDevelop.Debugger.DebugCommands.Debug"); - if (!ci.Enabled || !ci.Visible) { - // If debug is not enabled, try Run - ci = IdeApp.CommandService.GetCommandInfo (MonoDevelop.Ide.Commands.ProjectCommands.Run); - if (!ci.Enabled || !ci.Visible) { - // Running is not possible, then allow building - var bci = IdeApp.CommandService.GetCommandInfo (MonoDevelop.Ide.Commands.ProjectCommands.BuildSolution); - if (bci.Enabled && bci.Visible) { - operation = RoundButton.OperationIcon.Build; - ci = bci; - } - } - } - return ci; - } - } - void HandleStartButtonClicked (object sender, EventArgs e) { - RoundButton.OperationIcon operation; - var ci = GetStartButtonCommandInfo (out operation); - if (ci.Enabled) - IdeApp.CommandService.DispatchCommand (ci.Command.Id); + if (RunButtonClicked != null) + RunButtonClicked (sender, e); } - #region ICommandBar implementation - bool toolbarEnabled = true; - - void ICommandBar.Update (object activeTarget) - { - if (!toolbarEnabled) - return; - RoundButton.OperationIcon operation; - var ci = GetStartButtonCommandInfo (out operation); - if (ci.Enabled != button.Sensitive) - button.Sensitive = ci.Enabled; - - button.Icon = operation; - var stopped = operation != RoundButton.OperationIcon.Stop; - if (configurationCombosBox.Sensitive != stopped) - configurationCombosBox.Sensitive = stopped; - } - - void ICommandBar.SetEnabled (bool enabled) - { - toolbarEnabled = enabled; - button.Sensitive = enabled; - matchEntry.Sensitive = enabled; - } - #endregion - protected override void OnDestroyed () { base.OnDestroyed (); @@ -1015,6 +961,28 @@ namespace MonoDevelop.Components.MainToolbar Background = null; } } + + #region IMainToolbarView implementation + public event EventHandler RunButtonClicked; + + public bool RunButtonSensitivity { + get { return button.Sensitive; } + set { button.Sensitive = value; } + } + + public OperationIcon RunButtonIcon { + set { button.Icon = value; } + } + + public bool ConfigurationPlatformSensitivity { + get { return configurationCombosBox.Sensitive; } + set { configurationCombosBox.Sensitive = value; } + } + + public bool SearchSensivitity { + set { matchEntry.Sensitive = value; } + } + #endregion } } 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 b26a2ed4bc..88bca8ac2b 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.MainToolbar/MainToolbarController.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.MainToolbar/MainToolbarController.cs @@ -25,10 +25,11 @@ // THE SOFTWARE. using System; using MonoDevelop.Ide; +using MonoDevelop.Components.Commands; namespace MonoDevelop.Components.MainToolbar { - class MainToolbarController + class MainToolbarController : ICommandBar { internal IMainToolbarView ToolbarView { get; @@ -42,6 +43,8 @@ namespace MonoDevelop.Components.MainToolbar public MainToolbarController (IMainToolbarView toolbarView) { ToolbarView = toolbarView; + toolbarView.RunButtonClicked += HandleStartButtonClicked; + IdeApp.CommandService.RegisterCommandBar (this); } public void ShowCommandBar (string barId) @@ -53,6 +56,65 @@ namespace MonoDevelop.Components.MainToolbar { ToolbarView.HideCommandBar (barId); } + + static void HandleStartButtonClicked (object sender, EventArgs e) + { + OperationIcon operation; + var ci = GetStartButtonCommandInfo (out operation); + if (ci.Enabled) + IdeApp.CommandService.DispatchCommand (ci.Command.Id); + } + + static CommandInfo GetStartButtonCommandInfo (out OperationIcon operation) + { + if (!IdeApp.ProjectOperations.CurrentRunOperation.IsCompleted || !IdeApp.ProjectOperations.CurrentBuildOperation.IsCompleted) { + operation = OperationIcon.Stop; + return IdeApp.CommandService.GetCommandInfo (MonoDevelop.Ide.Commands.ProjectCommands.Stop); + } + else { + operation = OperationIcon.Run; + var ci = IdeApp.CommandService.GetCommandInfo ("MonoDevelop.Debugger.DebugCommands.Debug"); + if (!ci.Enabled || !ci.Visible) { + // If debug is not enabled, try Run + ci = IdeApp.CommandService.GetCommandInfo (MonoDevelop.Ide.Commands.ProjectCommands.Run); + if (!ci.Enabled || !ci.Visible) { + // Running is not possible, then allow building + var bci = IdeApp.CommandService.GetCommandInfo (MonoDevelop.Ide.Commands.ProjectCommands.BuildSolution); + if (bci.Enabled && bci.Visible) { + operation = OperationIcon.Build; + ci = bci; + } + } + } + return ci; + } + } + + #region ICommandBar implementation + bool toolbarEnabled = true; + + void ICommandBar.Update (object activeTarget) + { + if (!toolbarEnabled) + return; + OperationIcon operation; + var ci = GetStartButtonCommandInfo (out operation); + if (ci.Enabled != ToolbarView.RunButtonSensitivity) + ToolbarView.RunButtonSensitivity = ci.Enabled; + + ToolbarView.RunButtonIcon = operation; + var stopped = operation != OperationIcon.Stop; + if (ToolbarView.ConfigurationPlatformSensitivity != stopped) + ToolbarView.ConfigurationPlatformSensitivity = stopped; + } + + void ICommandBar.SetEnabled (bool enabled) + { + toolbarEnabled = enabled; + ToolbarView.RunButtonSensitivity = enabled; + ToolbarView.SearchSensivitity = enabled; + } + #endregion } } diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.MainToolbar/RoundButton.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.MainToolbar/RoundButton.cs index 0b9f439da1..4a7bd9074a 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.MainToolbar/RoundButton.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.MainToolbar/RoundButton.cs @@ -51,12 +51,6 @@ namespace MonoDevelop.Components.MainToolbar Xwt.Drawing.Image iconStopNormal, iconStopDisabled; Xwt.Drawing.Image iconBuildNormal, iconBuildDisabled; - public enum OperationIcon { - Run, - Build, - Stop - } - public RoundButton () { WidgetFlags |= Gtk.WidgetFlags.AppPaintable; |