diff options
author | Marius Ungureanu <marius.ungureanu@xamarin.com> | 2015-02-14 02:12:33 +0300 |
---|---|---|
committer | Marius Ungureanu <marius.ungureanu@xamarin.com> | 2015-02-14 02:12:33 +0300 |
commit | 7451e3b31e61a96c6d1d6e38657db1b2ec802cb0 (patch) | |
tree | fc192f9ab69c6f82d8f3465d4e0fe9385cf56772 /main | |
parent | b2953dcae7b891ba6d91450a38e6e2928905d01e (diff) |
[Toolbar] Split SearchBar commands into own handlers.
Diffstat (limited to 'main')
6 files changed, 80 insertions, 34 deletions
diff --git a/main/src/core/MonoDevelop.Ide/ExtensionModel/Commands.addin.xml b/main/src/core/MonoDevelop.Ide/ExtensionModel/Commands.addin.xml index a32860f20d..7697bc917a 100644 --- a/main/src/core/MonoDevelop.Ide/ExtensionModel/Commands.addin.xml +++ b/main/src/core/MonoDevelop.Ide/ExtensionModel/Commands.addin.xml @@ -821,17 +821,20 @@ _description = "Search for and replace text in all files of a directory" /> <Command id = "MonoDevelop.Ide.Commands.SearchCommands.GotoType" + defaultHandler = "MonoDevelop.Components.MainToolbar.GotoTypeHandler" _label = "Go to Type..." _description = "Jump to the declaration of type in the current workspace" shortcut = "Control|Shift|T" macShortcut = "Meta|Shift|T" /> <Command id = "MonoDevelop.Ide.Commands.SearchCommands.GotoFile" + defaultHandler = "MonoDevelop.Components.MainToolbar.GotoFileHandler" _label = "Go to File..." shortcut = "Alt|Shift|O" macShortcut = "Meta|Shift|D" _description = "Jump to a file in the current workspace" icon = "gtk-open" /> <Command id = "MonoDevelop.Components.MainToolbar.Commands.NavigateTo" + defaultHandler = "MonoDevelop.Components.MainToolbar.NavigateToHandler" _label = "Navigate To..." _description = "Jump to a item in the current workspace" shortcut = "Control|," 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 211851a940..43a35fa74a 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.MainToolbar/IMainToolbarView.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.MainToolbar/IMainToolbarView.cs @@ -116,6 +116,8 @@ namespace MonoDevelop.Components.MainToolbar /// </summary> /// <value>The search category.</value> string SearchCategory { set; } + + void FocusSearchBar (); #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 d7c2703ea9..128acbd618 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.MainToolbar/MainToolbar.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.MainToolbar/MainToolbar.cs @@ -124,15 +124,6 @@ namespace MonoDevelop.Components.MainToolbar get { return lastCommandTarget != null ? lastCommandTarget.Target : null; } } - void SetSearchCategory (string category) - { - IdeApp.Workbench.RootWindow.Present (); - matchEntry.Entry.Text = category + ":"; - matchEntry.Entry.GrabFocus (); - var pos = matchEntry.Entry.Text.Length; - matchEntry.Entry.SelectRegion (pos, pos); - } - static bool RuntimeIsSeparator (TreeModel model, TreeIter iter) { return model.GetValue (iter, RuntimeExecutionTarget) == null && model.GetValue (iter, RuntimeCommand) == null; @@ -911,24 +902,6 @@ namespace MonoDevelop.Components.MainToolbar return base.OnExposeEvent (evnt); } - [CommandHandler(Commands.NavigateTo)] - public void NavigateToCommand () - { - matchEntry.Entry.GrabFocus (); - } - - [CommandHandler(SearchCommands.GotoFile)] - public void GotoFileCommand () - { - SetSearchCategory ("file"); - } - - [CommandHandler(SearchCommands.GotoType)] - public void GotoTypeCommand () - { - SetSearchCategory ("type"); - } - void HandleStartButtonClicked (object sender, EventArgs e) { if (RunButtonClicked != null) @@ -989,6 +962,11 @@ namespace MonoDevelop.Components.MainToolbar matchEntry.Entry.SelectRegion (pos, pos); } } + + public void FocusSearchBar () + { + matchEntry.Entry.GrabFocus (); + } #endregion } } diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.MainToolbar/MainToolbarCommandHandlers.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.MainToolbar/MainToolbarCommandHandlers.cs new file mode 100644 index 0000000000..3f5333fbef --- /dev/null +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.MainToolbar/MainToolbarCommandHandlers.cs @@ -0,0 +1,54 @@ +// +// MainToolbarCommandHandlers.cs +// +// Author: +// Marius Ungureanu <marius.ungureanu@xamarin.com> +// +// Copyright (c) 2015 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 MonoDevelop.Components.Commands; + +namespace MonoDevelop.Components.MainToolbar +{ + class NavigateToHandler : CommandHandler + { + protected override void Run () + { + Ide.IdeApp.Workbench.Toolbar.FocusSearchBar (); + } + } + + class GotoTypeHandler : CommandHandler + { + protected override void Run () + { + Ide.IdeApp.Workbench.Toolbar.SetSearchCategory ("type"); + } + } + + class GotoFileHandler : CommandHandler + { + protected override void Run () + { + Ide.IdeApp.Workbench.Toolbar.SetSearchCategory ("file"); + } + } +} 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 25e8caf9a6..a2e00ec22d 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.MainToolbar/MainToolbarController.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.MainToolbar/MainToolbarController.cs @@ -47,23 +47,31 @@ namespace MonoDevelop.Components.MainToolbar // 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:"), + 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; - }; + item.Activated += (o, e) => SetSearchCategory (item.Category); ToolbarView.SearchMenuItems = items; // Register this controller as a commandbar. IdeApp.CommandService.RegisterCommandBar (this); } + public void FocusSearchBar () + { + ToolbarView.FocusSearchBar (); + } + + public void SetSearchCategory (string category) + { + IdeApp.Workbench.Present (); + ToolbarView.SearchCategory = category + ":"; + } + public void ShowCommandBar (string barId) { ToolbarView.ShowCommandBar (barId); diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.csproj b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.csproj index 11a75899ed..bc2dc58a70 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.csproj +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.csproj @@ -3028,6 +3028,7 @@ <Compile Include="MonoDevelop.Ide.Execution\TargetedExecutionHandler.cs" /> <Compile Include="MonoDevelop.Components.MainToolbar\IMainToolbarView.cs" /> <Compile Include="MonoDevelop.Components.MainToolbar\MainToolbarController.cs" /> + <Compile Include="MonoDevelop.Components.MainToolbar\MainToolbarCommandHandlers.cs" /> </ItemGroup> <ItemGroup> <None Include="Makefile.am" /> |