diff --git a/src/VsChromium/Features/ToolWindows/CodeSearch/CodeSearchControl.xaml b/src/VsChromium/Features/ToolWindows/CodeSearch/CodeSearchControl.xaml index e26e9719..b015d388 100644 --- a/src/VsChromium/Features/ToolWindows/CodeSearch/CodeSearchControl.xaml +++ b/src/VsChromium/Features/ToolWindows/CodeSearch/CodeSearchControl.xaml @@ -183,6 +183,12 @@ + + + + + + diff --git a/src/VsChromium/Features/ToolWindows/CodeSearch/CodeSearchControl.xaml.cs b/src/VsChromium/Features/ToolWindows/CodeSearch/CodeSearchControl.xaml.cs index 0383454d..6c0e14ed 100644 --- a/src/VsChromium/Features/ToolWindows/CodeSearch/CodeSearchControl.xaml.cs +++ b/src/VsChromium/Features/ToolWindows/CodeSearch/CodeSearchControl.xaml.cs @@ -189,7 +189,8 @@ void ViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e) { e.PropertyName == ReflectionUtils.GetPropertyName(ViewModel, x => x.MatchWholeWord) || e.PropertyName == ReflectionUtils.GetPropertyName(ViewModel, x => x.UseRegex) || e.PropertyName == ReflectionUtils.GetPropertyName(ViewModel, x => x.IncludeSymLinks) || - e.PropertyName == ReflectionUtils.GetPropertyName(ViewModel, x => x.UnderstandBuildOutputPaths)) { + e.PropertyName == ReflectionUtils.GetPropertyName(ViewModel, x => x.UnderstandBuildOutputPaths) || + e.PropertyName == ReflectionUtils.GetPropertyName(ViewModel, x => x.ExpandAll)) { RefreshSearchResults(true); } } diff --git a/src/VsChromium/Features/ToolWindows/CodeSearch/CodeSearchController.cs b/src/VsChromium/Features/ToolWindows/CodeSearch/CodeSearchController.cs index 70cca6fe..765c69e0 100644 --- a/src/VsChromium/Features/ToolWindows/CodeSearch/CodeSearchController.cs +++ b/src/VsChromium/Features/ToolWindows/CodeSearch/CodeSearchController.cs @@ -421,6 +421,7 @@ private void GlobalSettingsOnPropertyChanged(object sender, PropertyChangedEvent ViewModel.DisplayFontSize = setting.DisplayFont.Size; ViewModel.PathFontFamily = setting.PathFont.FontFamily.Name; ViewModel.PathFontSize = setting.PathFont.Size; + ViewModel.ExpandAll = setting.ExpandAll; } private void ViewModelOnPropertyChanged(object sender, PropertyChangedEventArgs args) { @@ -430,6 +431,7 @@ private void ViewModelOnPropertyChanged(object sender, PropertyChangedEventArgs settings.SearchMatchWholeWord = model.MatchWholeWord; settings.SearchUseRegEx = model.UseRegex; settings.SearchIncludeSymLinks = model.IncludeSymLinks; + settings.ExpandAll = model.ExpandAll; } private void OnIndexingStateChanged() { @@ -772,7 +774,7 @@ private void SearchFilesPaths(string searchPattern, bool immediate) { msg += ", Column " + (searchInfo.ColumnNumber + 1); } var limitMsg = CreateMaxResultsHitMessage(response.HitCount, maxResults); - var viewModel = CreateSearchFilePathsResult(searchInfo, response.SearchResult, msg, limitMsg, true); + var viewModel = CreateSearchFilePathsResult(searchInfo, response.SearchResult, msg, limitMsg, ViewModel.ExpandAll); _searchResultDocumentChangeTracker.Disable(); ViewModel.SetSearchFilePathsResult(viewModel); } @@ -812,7 +814,7 @@ private void SearchCode(string searchPattern, string filePathPattern, bool immed msg += string.Format(", File Paths: \"{0}\"", filePathPattern); } var limitMsg = CreateMaxResultsHitMessage(response.HitCount, maxResults); - bool expandAll = response.HitCount < HardCodedSettings.SearchCodeExpandMaxResults; + bool expandAll = response.HitCount < HardCodedSettings.SearchCodeExpandMaxResults || ViewModel.ExpandAll; var result = CreateSearchCodeResultViewModel(response.SearchResults, msg, limitMsg, expandAll); ViewModel.SetSearchCodeResult(result); _searchResultDocumentChangeTracker.Enable(response.SearchResults); diff --git a/src/VsChromium/Features/ToolWindows/CodeSearch/CodeSearchItemViewModelBase.cs b/src/VsChromium/Features/ToolWindows/CodeSearch/CodeSearchItemViewModelBase.cs index 81c9d763..3caa97c6 100644 --- a/src/VsChromium/Features/ToolWindows/CodeSearch/CodeSearchItemViewModelBase.cs +++ b/src/VsChromium/Features/ToolWindows/CodeSearch/CodeSearchItemViewModelBase.cs @@ -12,6 +12,9 @@ public CodeSearchItemViewModelBase( bool lazyLoadChildren) : base(controller.StandarImageSourceFactory, parent, lazyLoadChildren) { _controller = controller; + var con = controller as CodeSearchController; + if (con != null && con.ViewModel.ExpandAll) + LazySelect = (TreeViewItemViewModel x) => { ExpandAll(x); }; } public ICodeSearchController Controller { get { return _controller; } } diff --git a/src/VsChromium/Features/ToolWindows/CodeSearch/CodeSearchToolWindow.cs b/src/VsChromium/Features/ToolWindows/CodeSearch/CodeSearchToolWindow.cs index 7d9a03c8..b4dd87aa 100644 --- a/src/VsChromium/Features/ToolWindows/CodeSearch/CodeSearchToolWindow.cs +++ b/src/VsChromium/Features/ToolWindows/CodeSearch/CodeSearchToolWindow.cs @@ -2,12 +2,19 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +using EnvDTE; using System.Collections.Generic; using System.ComponentModel.Design; using System.Runtime.InteropServices; +using Microsoft.VisualStudio; using Microsoft.VisualStudio.OLE.Interop; +using Microsoft.VisualStudio.Text; +using Microsoft.VisualStudio.Editor; +using Microsoft.VisualStudio.Text.Editor; using Microsoft.VisualStudio.Shell; using Microsoft.VisualStudio.Shell.Interop; +using Microsoft.VisualStudio.ComponentModelHost; +using Microsoft.VisualStudio.TextManager.Interop; using VsChromium.Commands; using VsChromium.Features.AutoUpdate; using VsChromium.Package.CommandHandler; @@ -26,6 +33,10 @@ namespace VsChromium.Features.ToolWindows.CodeSearch { [Guid(GuidList.GuidCodeSearchToolWindowString)] public class CodeSearchToolWindow : ToolWindowPane, IOleCommandTarget { private VsWindowFrameNotifyHandler _frameNotify; + private IVsTextManager _txtMgr; + private IComponentModel _componentModel; + private IVsEditorAdaptersFactoryService _editorAdaptersFactoryService; + private EnvDTE.WindowEvents WindowEvents { get; set; } /// /// Standard constructor for the tool window. @@ -48,10 +59,52 @@ public CodeSearchToolWindow() ExplorerControl = new CodeSearchControl(); } + private string GetSelectedOrWord() + { + string selection = string.Empty; + IVsTextView vTextView = null; + int mustHaveFocus = 1; + _txtMgr.GetActiveView(mustHaveFocus, null, out vTextView); + if (vTextView == null) + return selection; + vTextView.GetSelectedText(out selection); + if (!selection.Equals("")) + return selection; + var textView = _editorAdaptersFactoryService.GetWpfTextView(vTextView); + var viewadatper = _editorAdaptersFactoryService.GetViewAdapter(textView); + if (textView == null || viewadatper == null) + return selection; + var position = textView.Caret.Position.BufferPosition; + position = position.TranslateTo(textView.TextSnapshot, PointTrackingMode.Positive); + TextSpan[] spans = new TextSpan[1]; + var containingline = position.GetContainingLine(); + if (ErrorHandler.Failed(viewadatper.GetWordExtent(containingline.LineNumber, position - containingline.Start, (uint)WORDEXTFLAGS.WORDEXT_CURRENT, spans))) + return selection; + var wordstring = string.Empty; + var span = spans[0]; + vTextView.GetTextStream(span.iStartLine, span.iStartIndex, span.iEndLine, span.iEndIndex, out wordstring); + return wordstring; + } + public override void OnToolWindowCreated() { base.OnToolWindowCreated(); ExplorerControl.OnVsToolWindowCreated(this); - + _txtMgr = (IVsTextManager)GetService(typeof(SVsTextManager)); + _componentModel = (IComponentModel)GetService(typeof(SComponentModel)); + _editorAdaptersFactoryService = (IVsEditorAdaptersFactoryService)_componentModel.GetService(); + + EnvDTE.DTE dte = (EnvDTE.DTE)GetService(typeof(EnvDTE.DTE)); + EnvDTE80.Events2 events = (EnvDTE80.Events2)dte.Events; + this.WindowEvents = (EnvDTE.WindowEvents)events.get_WindowEvents(null); + this.WindowEvents.WindowActivated += (Window GotFocus, Window LostFocus) => { + if (GotFocus.ObjectKind.ToString().ToLower().Equals("{" + GuidList.GuidCodeSearchToolWindowString + "}")) + { + var word = GetSelectedOrWord(); + if (word.Equals("")) + return; + ExplorerControl.SearchCodeCombo.Text = word; + } + }; // Advise IVsWindowFrameNotify so we know when we get hidden, etc. var frame = Frame as IVsWindowFrame2; if (frame != null) { diff --git a/src/VsChromium/Features/ToolWindows/CodeSearch/CodeSearchViewModel.cs b/src/VsChromium/Features/ToolWindows/CodeSearch/CodeSearchViewModel.cs index 5ecb9238..85e6c212 100644 --- a/src/VsChromium/Features/ToolWindows/CodeSearch/CodeSearchViewModel.cs +++ b/src/VsChromium/Features/ToolWindows/CodeSearch/CodeSearchViewModel.cs @@ -37,6 +37,7 @@ public class CodeSearchViewModel : ChromiumExplorerViewModelBase { private bool _serverIsRunning; private bool _serverHasStarted; private bool _fileSystemTreeAvailable; + private bool _expandall; public enum DisplayKind { InformationMessages, @@ -158,6 +159,36 @@ public string UseRegexToolTip { } } + /// + /// Databound! + /// + public bool ExpandAll + { + get { return _expandall; } + set + { + if (_expandall != value) + { + _expandall = value; + OnPropertyChanged(ReflectionUtils.GetPropertyName(this, x => x.ExpandAll)); + } + } + } + + /// + /// Databound! + /// + public string ExpandAllTip + { + get + { + return string.Format( + "Toggle expand all search results. " + + "Currently {0}.", + _expandall ? "yes" : "no"); + } + } + /// /// Databound! /// diff --git a/src/VsChromium/Features/ToolWindows/TreeViewItemViewModel.cs b/src/VsChromium/Features/ToolWindows/TreeViewItemViewModel.cs index 4e3d551c..840aef5a 100644 --- a/src/VsChromium/Features/ToolWindows/TreeViewItemViewModel.cs +++ b/src/VsChromium/Features/ToolWindows/TreeViewItemViewModel.cs @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; @@ -25,6 +26,7 @@ public class TreeViewItemViewModel : INotifyPropertyChanged, IHierarchyObject { private readonly LazyObservableCollection _children; private bool _isExpanded; private bool _isSelected; + private Action _lazeselect; /// /// This is used to create the DummyChild instance. @@ -137,6 +139,11 @@ public static void ExpandNodes(IEnumerable source, bool e }); } + public Action LazySelect + { get { if (_lazeselect == null) return (TreeViewItemViewModel x) => { }; else return _lazeselect; } + set { _lazeselect = value; } + } + public static void ExpandAll(TreeViewItemViewModel item) { item.IsExpanded = true; item.Children.ForAll(ExpandAll); @@ -195,8 +202,9 @@ private LazyItemViewModel CreateLazyItemViewModel() { result.Text = string.Format("(Click to expand {0:n0} additional items...)", ChildrenCount - HardCodedSettings.MaxExpandedTreeViewItemCount); result.Selected += () => { - var node = _children.ExpandLazyNode(); - node.IsSelected = true; + var node = _children.ExpandLazyNode(); + node.IsSelected = true; + _children.ForAll(x => LazySelect(x)); }; return result; } diff --git a/src/VsChromium/Settings/GlobalSettings.cs b/src/VsChromium/Settings/GlobalSettings.cs index 9a965475..e6196920 100644 --- a/src/VsChromium/Settings/GlobalSettings.cs +++ b/src/VsChromium/Settings/GlobalSettings.cs @@ -29,6 +29,7 @@ public class GlobalSettings : INotifyPropertyChanged { private Font _displayFont; private Font _textExtractFont; private Font _pathFont; + private bool _expandall; public event PropertyChangedEventHandler PropertyChanged; @@ -194,6 +195,18 @@ public bool SearchUnderstandBuildOutputPaths { OnPropertyChanged(ReflectionUtils.GetPropertyName(this, x => x.SearchUnderstandBuildOutputPaths)); } } + public bool ExpandAll + { + get { return _expandall; } + set + { + if (value == _expandall) + return; + + _expandall = value; + OnPropertyChanged(ReflectionUtils.GetPropertyName(this, x => x.ExpandAll)); + } + } #region Chromium Coding Style