Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add expandall feature & auto get selected text or current word in act… #59

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@
</Button.Style>
</Button>
<Separator Style="{StaticResource {x:Static ToolBar.SeparatorStyleKey}}" Width="2" />
<ToggleButton Style="{StaticResource {x:Static ToolBar.ToggleButtonStyleKey}}" Content="ExpandAll" IsChecked="{Binding ExpandAll}" IsTabStop="False" Foreground="{DynamicResource VsBrush.WindowText}">
<ToggleButton.ToolTip>
<TextBlock Text="{Binding ExpandAllTip}"/>
</ToggleButton.ToolTip>
</ToggleButton>
<Separator Style="{StaticResource {x:Static ToolBar.SeparatorStyleKey}}" Width="2" />
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="1" HorizontalAlignment="Right" Orientation="Horizontal">
<!-- The server info button -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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() {
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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; }

/// <summary>
/// Standard constructor for the tool window.
Expand All @@ -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<IVsEditorAdaptersFactoryService>();

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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class CodeSearchViewModel : ChromiumExplorerViewModelBase {
private bool _serverIsRunning;
private bool _serverHasStarted;
private bool _fileSystemTreeAvailable;
private bool _expandall;

public enum DisplayKind {
InformationMessages,
Expand Down Expand Up @@ -158,6 +159,36 @@ public string UseRegexToolTip {
}
}

/// <summary>
/// Databound!
/// </summary>
public bool ExpandAll
{
get { return _expandall; }
set
{
if (_expandall != value)
{
_expandall = value;
OnPropertyChanged(ReflectionUtils.GetPropertyName(this, x => x.ExpandAll));
}
}
}

/// <summary>
/// Databound!
/// </summary>
public string ExpandAllTip
{
get
{
return string.Format(
"Toggle expand all search results. " +
"Currently {0}.",
_expandall ? "yes" : "no");
}
}

/// <summary>
/// Databound!
/// </summary>
Expand Down
12 changes: 10 additions & 2 deletions src/VsChromium/Features/ToolWindows/TreeViewItemViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,6 +26,7 @@ public class TreeViewItemViewModel : INotifyPropertyChanged, IHierarchyObject {
private readonly LazyObservableCollection<TreeViewItemViewModel> _children;
private bool _isExpanded;
private bool _isSelected;
private Action<TreeViewItemViewModel> _lazeselect;

/// <summary>
/// This is used to create the DummyChild instance.
Expand Down Expand Up @@ -137,6 +139,11 @@ public static void ExpandNodes(IEnumerable<TreeViewItemViewModel> source, bool e
});
}

public Action<TreeViewItemViewModel> 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);
Expand Down Expand Up @@ -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;
}
Expand Down
13 changes: 13 additions & 0 deletions src/VsChromium/Settings/GlobalSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class GlobalSettings : INotifyPropertyChanged {
private Font _displayFont;
private Font _textExtractFont;
private Font _pathFont;
private bool _expandall;

public event PropertyChangedEventHandler PropertyChanged;

Expand Down Expand Up @@ -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

Expand Down