diff options
author | Marius Ungureanu <marius.ungureanu@xamarin.com> | 2015-02-14 02:05:35 +0300 |
---|---|---|
committer | Marius Ungureanu <marius.ungureanu@xamarin.com> | 2015-02-14 02:05:35 +0300 |
commit | b2953dcae7b891ba6d91450a38e6e2928905d01e (patch) | |
tree | bbbb8b855b1a7d16139bb0ce2c9e6fb67aa122d4 /main | |
parent | da3896bbba30a1cda1a95e5734930e43cacd25a6 (diff) |
[Toolbar] Introduce SearchMenuItem and fix a bug regarding search category.
Diffstat (limited to 'main')
3 files changed, 84 insertions, 13 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 17da125c1c..211851a940 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.MainToolbar/IMainToolbarView.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.MainToolbar/IMainToolbarView.cs @@ -34,6 +34,41 @@ namespace MonoDevelop.Components.MainToolbar Stop } + public class SearchMenuItem + { + internal SearchMenuItem (string displayString, string category) + { + DisplayString = displayString; + Category = category; + } + + /// <summary> + /// Notifies the activated. + /// </summary> + public void NotifyActivated () + { + if (Activated != null) + Activated (null, null); + } + + /// <summary> + /// Gets or sets the display string. + /// </summary> + /// <value>The display string.</value> + public string DisplayString { get; private set; } + + /// <summary> + /// Gets or sets the category. + /// </summary> + /// <value>The category.</value> + internal string Category { get; set; } + + /// <summary> + /// Occurs when the menu item is activated. + /// </summary> + internal event EventHandler Activated; + } + public interface IMainToolbarView { #region RunButton @@ -69,6 +104,18 @@ namespace MonoDevelop.Components.MainToolbar /// </summary> /// <value><c>true</c> if search entry is interactible; otherwise, <c>false</c>.</value> bool SearchSensivitity { set; } + + /// <summary> + /// Sets the search menu items. + /// </summary> + /// <value>The search menu items.</value> + SearchMenuItem[] SearchMenuItems { set; } + + /// <summary> + /// Sets the search category. + /// </summary> + /// <value>The search category.</value> + string SearchCategory { set; } #endregion #region StatusBar 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 14f4647e78..d7c2703ea9 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.MainToolbar/MainToolbar.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.MainToolbar/MainToolbar.cs @@ -291,19 +291,6 @@ namespace MonoDevelop.Components.MainToolbar matchEntry = new SearchEntry (); - var searchFiles = this.matchEntry.AddMenuItem (GettextCatalog.GetString ("Search Files")); - searchFiles.Activated += delegate { - SetSearchCategory ("files"); - }; - var searchTypes = this.matchEntry.AddMenuItem (GettextCatalog.GetString ("Search Types")); - searchTypes.Activated += delegate { - SetSearchCategory ("type"); - }; - var searchMembers = this.matchEntry.AddMenuItem (GettextCatalog.GetString ("Search Members")); - searchMembers.Activated += delegate { - SetSearchCategory ("member"); - }; - matchEntry.ForceFilterButtonVisible = true; matchEntry.Entry.FocusOutEvent += delegate { matchEntry.Entry.Text = ""; @@ -982,6 +969,26 @@ namespace MonoDevelop.Components.MainToolbar public bool SearchSensivitity { set { matchEntry.Sensitive = value; } } + + public SearchMenuItem[] SearchMenuItems { + set { + foreach (var item in value) { + var menuItem = matchEntry.AddMenuItem (item.DisplayString); + menuItem.Activated += delegate { + item.NotifyActivated (); + }; + } + } + } + + public string SearchCategory { + set { + matchEntry.Entry.Text = value; + matchEntry.Entry.GrabFocus (); + var pos = matchEntry.Entry.Text.Length; + matchEntry.Entry.SelectRegion (pos, pos); + } + } #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 88bca8ac2b..25e8caf9a6 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.MainToolbar/MainToolbarController.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.MainToolbar/MainToolbarController.cs @@ -26,6 +26,7 @@ using System; using MonoDevelop.Ide; using MonoDevelop.Components.Commands; +using MonoDevelop.Core; namespace MonoDevelop.Components.MainToolbar { @@ -43,7 +44,23 @@ namespace MonoDevelop.Components.MainToolbar public MainToolbarController (IMainToolbarView toolbarView) { ToolbarView = toolbarView; + // Attach run button click handler. toolbarView.RunButtonClicked += HandleStartButtonClicked; + var items = new[] { + new SearchMenuItem (GettextCatalog.GetString ("Search Files"), "file:"), + new SearchMenuItem (GettextCatalog.GetString ("Search Types"), "type:"), + new SearchMenuItem (GettextCatalog.GetString ("Search Members"), "member:"), + }; + + // Attach menu category handlers. + foreach (var item in items) + item.Activated += delegate { + IdeApp.Workbench.Present (); + ToolbarView.SearchCategory = item.Category; + }; + ToolbarView.SearchMenuItems = items; + + // Register this controller as a commandbar. IdeApp.CommandService.RegisterCommandBar (this); } |