Skip to content

Commit

Permalink
Merge pull request #14 from usysware/BrowsersNavigation
Browse files Browse the repository at this point in the history
Browsers navigation
  • Loading branch information
Sergey M authored Aug 29, 2020
2 parents a6fb65c + a5d5f56 commit ec01a93
Show file tree
Hide file tree
Showing 16 changed files with 242 additions and 43 deletions.
20 changes: 20 additions & 0 deletions DPackRx.Tests/Features/CodeBrowserViewModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ public void OnInitialize(string search, CodeModelFilterFlags flags, int expected
Assert.That(viewModel.FilteredMembers.Count, Is.EqualTo(expectedCount));
Assert.That(viewModel.Search, Is.EqualTo(search));
Assert.That(viewModel.Filter, Is.EqualTo(flags));
Assert.That(viewModel.SameType, Is.True);
Assert.That(viewModel.FileName, Is.EqualTo("test"));
Assert.That(viewModel.Title, Is.Not.Null.And.Not.Empty);
Assert.That(viewModel.Title, Contains.Substring(" - test"));
_fileProcessorMock.Verify(p => p.GetMembers(ProcessorFlags.IncludeFileCodeModel, It.IsAny<CodeModelFilterFlags>()));
_optionsServiceMock.Verify(o => o.GetStringOption(viewModel.Feature, "File", string.Empty));
_optionsServiceMock.Verify(o => o.GetStringOption(viewModel.Feature, "Search", string.Empty));
Expand All @@ -145,6 +149,22 @@ public void OnInitialize(string search, CodeModelFilterFlags flags, int expected
_searchMatchServiceMock.Verify(s => s.MatchItems(search, It.IsAny<IEnumerable<IMatchItem>>()), Times.Once);
}

[Test]
public void OnInitialize_NotSameType()
{
_members.Clear();
_members.AddRange(new[]
{
new MemberCodeModel { Name = "Test1", FullName = "Test1", ElementKind = Kind.Class, Rank = 0, Matched = false },
new MemberCodeModel { Name = "Test2", FullName = "Test2", ElementKind = Kind.Class, Rank = 0, Matched = false },
});
var viewModel = GetViewModel();

viewModel.OnInitialize(CodeModelFilterFlags.All);

Assert.That(viewModel.SameType, Is.False);
}

[Test]
public void OnInitialize_ResetSearch()
{
Expand Down
6 changes: 6 additions & 0 deletions DPackRx/DPackRx.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
<Compile Include="CodeModel\SolutionModel.cs" />
<Compile Include="Extensions\KnownFeatureExtensions.cs" />
<Compile Include="Extensions\LogExtensions.cs" />
<Compile Include="Extensions\UIExtensions.cs" />
<Compile Include="Features\Bookmarks\IBookmarksSimpleTagger.cs" />
<Compile Include="Features\Bookmarks\BookmarksSimpleTagger.cs" />
<Compile Include="Features\Bookmarks\IBookmarkCallbackClient.cs" />
Expand Down Expand Up @@ -206,6 +207,7 @@
<Compile Include="UI\Behaviors\TextBoxSelectAllOnFocus.cs" />
<Compile Include="UI\Commands\RelayCommand.cs" />
<Compile Include="UI\Commands\RelayCommandT.cs" />
<Compile Include="UI\SharedResourceDictionary.cs" />
<Compile Include="UI\ViewModelBase.cs" />
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -502,6 +504,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Properties\DesignTimeResources.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="UI\Styles\OptionsDictionary.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down
9 changes: 7 additions & 2 deletions DPackRx/DPackRx.targets
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@
<PropertyGroup>
<_AssemblyInfoEx>$(MSBuildProjectDirectory)\$(IntermediateOutputPath)AssemblyInfoEx.cs</_AssemblyInfoEx>
<_AssemblyFileVersion Condition=" '$(_AssemblyFileVersion)'=='' ">true</_AssemblyFileVersion>
<_CreateVsix>true</_CreateVsix>
<_CreateVsix Condition=" '$(Configuration)' == 'Debug' AND '$(BuildingInsideVisualStudio)' == 'true' ">false</_CreateVsix>
</PropertyGroup>


<!-- Retrieve VSIX manifest version -->
<Target Name="ResolveVsixVersion">
<Target Name="ResolveVsixVersion"
Condition=" '$(_CreateVsix)' == 'true' ">
<XmlPeek Namespaces="&lt;Namespace Prefix='pkg' Uri='http://schemas.microsoft.com/developer/vsx-schema/2011'/&gt;"
XmlInputPath="$(MSBuildProjectDirectory)\source.extension.vsixmanifest"
Query="/pkg:PackageManifest/pkg:Metadata/pkg:Identity/@Version">
Expand All @@ -48,6 +51,7 @@

<!-- Generate AssemblyInfoEx.cs using VSIX manifest version -->
<Target Name="UpdateAssemblyInfoExFromVsix"
Condition=" '$(_CreateVsix)' == 'true' "
Inputs="$(MSBuildProjectDirectory)\source.extension.vsixmanifest"
Outputs="$(_AssemblyInfoEx)">
<CreateItem Include="System.Reflection.AssemblyVersionAttribute"
Expand All @@ -74,7 +78,8 @@

<!-- Copy VSIX package to project output folder with an extra file name's version suffix -->
<!-- Add copied file name to auto-clean file -->
<Target Name="CopyVsixPackageWithVersion">
<Target Name="CopyVsixPackageWithVersion"
Condition=" '$(_CreateVsix)' == 'true' ">
<ItemGroup>
<_GeneratedVSIXPackage Include="$(TargetVsixContainerName)" />
<_SourceVSIXPackage Include="@(_GeneratedVSIXPackage->'$(TargetDir)%(Filename)%(Extension)')" />
Expand Down
31 changes: 31 additions & 0 deletions DPackRx/Extensions/UIExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Windows.Media;

namespace DPackRx.Extensions
{
public static class UIExtensions
{
/// <summary>
/// Custom: returns child element of a given type.
/// </summary>
public static T GetChild<T>(this Visual element) where T : Visual
{
if (element == null)
return default;

if (element.GetType() == typeof(T))
return element as T;

T result = null;

for (var index = 0; index < VisualTreeHelper.GetChildrenCount(element); index++)
{
var visualElement = VisualTreeHelper.GetChild(element, index) as Visual;
result = visualElement.GetChild<T>();
if (result != null)
break;
}

return result;
}
}
}
29 changes: 21 additions & 8 deletions DPackRx/Features/CodeBrowser/CodeBrowserControl.xaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
<UserControl x:Class="DPackRx.Features.CodeBrowser.CodeBrowserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:local="clr-namespace:DPackRx.Features.CodeBrowser"
xmlns:ui="clr-namespace:DPackRx.UI"
xmlns:converters="clr-namespace:DPackRx.UI.Converters"
xmlns:behaviors="clr-namespace:DPackRx.UI.Behaviors"
mc:Ignorable="d"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="600"
behaviors:UserControlFocusOnLoad.Enabled="True">

<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!-- Must reference resource via pack syntax due to host being VS -->
<ResourceDictionary Source="pack://application:,,,/DPackRx;component/UI/Styles/FeatureDictionary.xaml" />
<ui:SharedResourceDictionary Source="pack://application:,,,/DPackRx;component/UI/Styles/FeatureDictionary.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</ResourceDictionary>
</UserControl.Resources>

<DockPanel LastChildFill="True">
Expand Down Expand Up @@ -104,8 +105,20 @@
</GridViewColumn.Header>
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding ParentFullName, Mode=OneTime}"
ToolTip="{Binding Path=XmlDoc}" />
<TextBlock ToolTip="{Binding Path=XmlDoc}">
<TextBlock.Style>
<Style TargetType="TextBlock">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=DataContext.SameType, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" Value="True">
<Setter Property="Text" Value="{Binding Name, Mode=OneTime}" />
</DataTrigger>
<DataTrigger Binding="{Binding Path=DataContext.SameType, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" Value="False">
<Setter Property="Text" Value="{Binding ParentFullName, Mode=OneTime}" />
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
Expand Down
29 changes: 29 additions & 0 deletions DPackRx/Features/CodeBrowser/CodeBrowserViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Data;
Expand Down Expand Up @@ -35,7 +36,9 @@ public class CodeBrowserViewModel : FeatureViewModelBase
private readonly IShellImageService _shellImageService;
private readonly ObservableCollection<MemberCodeModel> _sourceMembers;
private readonly CollectionViewSource _members;
private string _title;
private string _search = string.Empty;
private bool _sameType;

#endregion

Expand Down Expand Up @@ -79,6 +82,7 @@ public override void OnInitialize(object argument)
throw new ArgumentException("Invalid initialization argument", nameof(argument));

this.FileName = _optionsService.GetStringOption(this.Feature, "File", this.FileName);
this.Title = $"USysWare Code Browser - {Path.GetFileName(this.FileName)}";
_search = _optionsService.GetStringOption(this.Feature, "Search", _search);
this.Filter = (CodeModelFilterFlags)argument;
var filter = (CodeModelFilterFlags)_optionsService.GetIntOption(this.Feature, "Filter", (int)this.Filter);
Expand Down Expand Up @@ -138,6 +142,16 @@ public override void OnClose(bool apply)

#region Properties

public string Title
{
get { return _title; }
set
{
_title = value;
RaisePropertyChanged(nameof(this.Title));
}
}

/// <summary>
/// Search text.
/// </summary>
Expand Down Expand Up @@ -167,6 +181,19 @@ public ICollectionView Members
get { return _members?.View; }
}

/// <summary>
/// Whether all code model members are from the same type declaration.
/// </summary>
public bool SameType
{
get { return _sameType; }
set
{
_sameType = value;
RaisePropertyChanged(nameof(this.SameType));
}
}

/// <summary>
/// Filtered members.
/// </summary>
Expand Down Expand Up @@ -227,6 +254,8 @@ private void ApplyMembers()
var model = _fileProcessor.GetMembers(flags, this.Filter);
var members = model.Members;
var fileName = model.FileName;
this.SameType = model.Members.Count(
m => (m.ElementKind == Kind.Class) || (m.ElementKind == Kind.Interface) || (m.ElementKind == Kind.Struct) || (m.ElementKind == Kind.Enum)) <= 1;

// Reset search on new file
if (!string.IsNullOrEmpty(this.FileName) && !string.IsNullOrEmpty(fileName) && !fileName.Equals(this.FileName, StringComparison.OrdinalIgnoreCase))
Expand Down
6 changes: 3 additions & 3 deletions DPackRx/Features/CodeBrowser/CodeBrowserWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<platformUI:DialogWindow x:Class="DPackRx.Features.CodeBrowser.CodeBrowserWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:DPackRx.Features.CodeBrowser"
xmlns:behaviors="clr-namespace:DPackRx.UI.Behaviors"
xmlns:ui="clr-namespace:DPackRx.UI"
xmlns:platformUI="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Shell.15.0"
mc:Ignorable="d"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance Type=local:CodeBrowserViewModel, IsDesignTimeCreatable=True}"
Icon="Images/CodeBrowser.ico"
Height="400" Width="600" MinHeight="200" MinWidth="400"
Title="USysWare Code Browser" WindowStartupLocation="CenterOwner" ResizeMode="CanResizeWithGrip" ShowInTaskbar="False"
Title="{Binding Title}" WindowStartupLocation="CenterOwner" ResizeMode="CanResizeWithGrip" ShowInTaskbar="False"
behaviors:WindowCloseOnEsc.Enabled="True"
behaviors:WindowClose.DialogResult="{Binding CloseWindow}">

Expand Down
13 changes: 7 additions & 6 deletions DPackRx/Features/FileBrowser/FileBrowserControl.xaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
<UserControl x:Class="DPackRx.Features.FileBrowser.FileBrowserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:local="clr-namespace:DPackRx.Features.FileBrowser"
xmlns:ui="clr-namespace:DPackRx.UI"
xmlns:converters="clr-namespace:DPackRx.UI.Converters"
xmlns:behaviors="clr-namespace:DPackRx.UI.Behaviors"
mc:Ignorable="d"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="600"
behaviors:UserControlFocusOnLoad.Enabled="True">

<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!-- Must reference resource via pack syntax due to host being VS -->
<ResourceDictionary Source="pack://application:,,,/DPackRx;component/UI/Styles/FeatureDictionary.xaml" />
<ui:SharedResourceDictionary Source="pack://application:,,,/DPackRx;component/UI/Styles/FeatureDictionary.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</ResourceDictionary>
</UserControl.Resources>

<DockPanel LastChildFill="True">
Expand Down
9 changes: 5 additions & 4 deletions DPackRx/Options/OptionsFileBrowserControl.xaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
<UserControl x:Class="DPackRx.Options.OptionsFileBrowserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:DPackRx.Options"
xmlns:ui="clr-namespace:DPackRx.UI"
xmlns:behaviors="clr-namespace:DPackRx.UI.Behaviors"
mc:Ignorable="d"
mc:Ignorable="d"
d:DesignHeight="200" d:DesignWidth="400">

<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!-- Must reference resource via pack syntax due to host being VS -->
<ResourceDictionary Source="pack://application:,,,/DPackRx;component/UI/Styles/OptionsDictionary.xaml" />
<ui:SharedResourceDictionary Source="pack://application:,,,/DPackRx;component/UI/Styles/OptionsDictionary.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
Expand Down
3 changes: 2 additions & 1 deletion DPackRx/Options/OptionsGeneralControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:DPackRx.Options"
xmlns:ui="clr-namespace:DPackRx.UI"
mc:Ignorable="d"
d:DesignHeight="200" d:DesignWidth="400">

<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!-- Must reference resource via pack syntax due to host being VS -->
<ResourceDictionary Source="pack://application:,,,/DPackRx;component/UI/Styles/OptionsDictionary.xaml" />
<ui:SharedResourceDictionary Source="pack://application:,,,/DPackRx;component/UI/Styles/OptionsDictionary.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
Expand Down
2 changes: 0 additions & 2 deletions DPackRx/Package/CommandBindings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ public static ICollection<CommandNameAttribute> Commands
{
_commands = new List<CommandNameAttribute>
{
new CommandNameAttribute("View.ViewCode", "F7", ContextGuids.vsContextGuidWindowsFormsDesigner),
new CommandNameAttribute("View.ViewCode", "F7", ContextGuids.vsContextGuidHTMLSourceView),
new CommandNameAttribute("View.ViewCode", "F7", ContextGuids.vsContextGuidTextEditor),
new CommandNameAttribute("View.ViewDesigner", "F7", ContextGuids.vsContextGuidWindowsFormsDesigner),
new CommandNameAttribute("View.ViewDesigner", "F7", ContextGuids.vsContextGuidHTMLSourceView),
new CommandNameAttribute("View.ViewDesigner", "F7", ContextGuids.vsContextGuidTextEditor),
new CommandNameAttribute("EditorContextMenus.CodeWindow.RemoveAndSort", "Ctrl+Shift+Alt+U"),
Expand Down
7 changes: 7 additions & 0 deletions DPackRx/Properties/DesignTimeResources.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!-- Design-time only resource -->
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/DPackRx;component/UI/Styles/FeatureDictionary.xaml" />
<ResourceDictionary Source="pack://application:,,,/DPackRx;component/UI/Styles/OptionsDictionary.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
Loading

0 comments on commit ec01a93

Please sign in to comment.