Skip to content
This repository has been archived by the owner on May 2, 2024. It is now read-only.

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
*  hide "empty" projects in tool window
* Refresh-Button as Icon
* a bit more theming
  • Loading branch information
nils-a committed Jul 7, 2021
1 parent 3575195 commit 2511f21
Show file tree
Hide file tree
Showing 10 changed files with 205 additions and 111 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,5 @@ docs/input/tasks/*

# Wyam related
config.wyam.*
.vshistory/
.history/
1 change: 1 addition & 0 deletions src/MediatR-vs/MediatR-vs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="Extensions\EnumerableExtensions.cs" />
<Compile Include="MediatrToolWindowViewModel.cs" />
<Compile Include="Models\MediatrElement.cs" />
<Compile Include="Models\MediatrElementType.cs" />
<Compile Include="Models\MediatrProject.cs" />
Expand Down
2 changes: 1 addition & 1 deletion src/MediatR-vs/MediatrToolWindow.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell;

using System;
using System.Runtime.InteropServices;
Expand Down
75 changes: 53 additions & 22 deletions src/MediatR-vs/MediatrToolWindowControl.xaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<UserControl x:Class="MediatRvs.MediatrToolWindowControl"
<UserControl x:Class="MediatRvs.MediatrToolWindowControl"
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"
Expand All @@ -7,35 +7,66 @@
xmlns:local="clr-namespace:MediatRvs"
xmlns:models="clr-namespace:MediatRvs.Models"
xmlns:toolkit="clr-namespace:Community.VisualStudio.Toolkit;assembly=Community.VisualStudio.Toolkit"
xmlns:catalog="clr-namespace:Microsoft.VisualStudio.Imaging;assembly=Microsoft.VisualStudio.ImageCatalog"
xmlns:imaging="clr-namespace:Microsoft.VisualStudio.Imaging;assembly=Microsoft.VisualStudio.Imaging"
toolkit:Themes.UseVsTheme="True"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
d:DataContext="{d:DesignInstance local:MediatrToolWindowControl, IsDesignTimeCreatable=False}"
d:DataContext="{d:DesignInstance local:MediatrToolWindowViewModel, IsDesignTimeCreatable=False}"
Name="MyToolWindow">
<DockPanel>
<Menu DockPanel.Dock="Top">
<MenuItem Command="{Binding Path=RefreshCommand}" Header="Refresh" />
</Menu>
<ToolBarTray DockPanel.Dock="Top"
Background="{DynamicResource VsBrush.CommandBarGradientBegin}">
<ToolBar Background="{DynamicResource VsBrush.CommandBarGradientBegin}"
IsManipulationEnabled="False"
>
<Button Command="{Binding Path=RefreshCommand}"
ToolTip="Refresh">
<imaging:CrispImage Width="16" Height="16" Moniker="{x:Static catalog:KnownMonikers.Refresh}" />
</Button>
</ToolBar>
</ToolBarTray>
<StatusBar DockPanel.Dock="Bottom"></StatusBar>
<TreeView ItemsSource="{Binding Path=Projects}">
<TreeView x:Name="TreeView"
ItemsSource="{Binding Path=Projects}">
<TreeView.ItemContainerStyle>
<Style TargetType="{x:Type TreeViewItem}">
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Margin" Value="0"/>
<Setter Property="Foreground" Value="{DynamicResource VsBrush.WindowText}"/>
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="{DynamicResource VsBrush.TreeView.SelectedItemActive}"/>
<Setter Property="Foreground" Value="{DynamicResource VsBrush.TreeView.SelectedItemActiveText}"/>
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="True"/>
<Condition Property="IsSelectionActive" Value="False"/>
</MultiTrigger.Conditions>
<Setter Property="Background" Value="{DynamicResource VsBrush.TreeView.SelectedItemInactive}"/>
<Setter Property="Foreground" Value="{DynamicResource VsBrush.TreeView.SelectedItemInactiveText}"/>
</MultiTrigger>
</Style.Triggers>
</Style>
</TreeView.ItemContainerStyle>
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type models:MediatrProject}"
ItemsSource="{Binding Elements}">
<Label Content="{Binding Path=Name}"
ToolTip="{Binding Path=Path}"/>
<HierarchicalDataTemplate DataType="{x:Type models:MediatrProject}"
ItemsSource="{Binding Elements}">
<TextBlock Text="{Binding Path= Name}"
ToolTip="{Binding Path= Path}"/>
</HierarchicalDataTemplate>

<HierarchicalDataTemplate DataType="{x:Type models:MediatrElement}">
<StackPanel Orientation="Horizontal"
local:MouseDoubleClick.Command="{Binding Path=OpenDocument}"
ToolTip="{Binding FullName}">
<Label Content="{Binding Path=Name}"/>
<Label Content="[" />
<Label Content="{Binding Path=ElementType}" />
<Label Content="]" />
</StackPanel>
</HierarchicalDataTemplate>

<DataTemplate DataType="{x:Type models:MediatrElement}">
<StackPanel Orientation="Horizontal"
local:MouseDoubleClick.Command="{Binding Path=OpenDocument}"
ToolTip="{Binding FullName}">
<!-- <Image Source="/WpfTutorialSamples;component/Images/user.png" Margin="0,0,5,0" /> -->
<TextBlock Text="{Binding Path= Name}" />
<TextBlock Text=" (" />
<TextBlock Text="{Binding Path=ElementType}" />
<TextBlock Text=")" />
</StackPanel>
</DataTemplate>
</TreeView.Resources>
</TreeView>
</DockPanel>
Expand Down
67 changes: 2 additions & 65 deletions src/MediatR-vs/MediatrToolWindowControl.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,84 +1,21 @@
using System;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Windows.Controls;
using System.Windows.Input;
using MediatRvs.Models;
using Microsoft.VisualStudio.PlatformUI;
using Microsoft.VisualStudio.Shell;
using Task = System.Threading.Tasks.Task;

namespace MediatRvs
{
/// <summary>
/// Interaction logic for MediatrToolWindowControl.
/// </summary>
public partial class MediatrToolWindowControl : UserControl, INotifyPropertyChanged
public partial class MediatrToolWindowControl : UserControl
{
private MediatrProject[] _projects;
private ICommand _refreshCommand;

/// <summary>
/// Initializes a new instance of the <see cref="MediatrToolWindowControl"/> class.
/// </summary>
public MediatrToolWindowControl()
{
InitializeComponent();
DataContext = this;
RefreshCommand = new DelegateCommand(LoadProjects);
ThreadHelper.JoinableTaskFactory.Run(async () => await InitLoadProjectsAsync());
}

public MediatrProject[] Projects
{
get => _projects;
set
{
_projects = value;
OnPropertyChanged();
}
}

public ICommand RefreshCommand
{
get => _refreshCommand;
set
{
_refreshCommand = value;
OnPropertyChanged();
}
}

private async Task InitLoadProjectsAsync()
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
LoadProjects();
}

private void LoadProjects()
{
ThreadHelper.JoinableTaskFactory.Run(async () =>
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
var adapter = new ProjectContentAdapter();
try
{
var projects = adapter.GetMessages().ToArray();
Projects = projects;
}
catch (Exception e)
{
Logger.Log(e);
}
});
DataContext = new MediatrToolWindowViewModel();
}

public event PropertyChangedEventHandler PropertyChanged;

private void OnPropertyChanged([CallerMemberName] string property = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
}
}
}
77 changes: 77 additions & 0 deletions src/MediatR-vs/MediatrToolWindowViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using System;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Windows.Input;
using MediatRvs.Models;
using Microsoft.VisualStudio.PlatformUI;
using Microsoft.VisualStudio.Shell;
using Task = System.Threading.Tasks.Task;

namespace MediatRvs
{
public class MediatrToolWindowViewModel: INotifyPropertyChanged
{
private MediatrProject[] _projects;
private ICommand _refreshCommand;

public MediatrToolWindowViewModel()
{
RefreshCommand = new DelegateCommand(LoadProjects);
ThreadHelper.JoinableTaskFactory.Run(async () => await InitLoadProjectsAsync());

}

public MediatrProject[] Projects
{
get => _projects;
set
{
_projects = value;
OnPropertyChanged();
}
}

public ICommand RefreshCommand
{
get => _refreshCommand;
set
{
_refreshCommand = value;
OnPropertyChanged();
}
}

private async Task InitLoadProjectsAsync()
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
LoadProjects();
}

private void LoadProjects()
{
ThreadHelper.JoinableTaskFactory.Run(async () =>
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
var adapter = new ProjectContentAdapter();
try
{
var elements = adapter.GetMediatRContent();
Projects = elements.ToArray();
}
catch (Exception e)
{
Logger.Log(e);
}
});
}

public event PropertyChangedEventHandler PropertyChanged;

private void OnPropertyChanged([CallerMemberName] string property = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
}

}
}
7 changes: 4 additions & 3 deletions src/MediatR-vs/Models/MediatrProject.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using System.Collections.Generic;
using System.Collections.Generic;

namespace MediatRvs.Models
{
public class MediatrProject
{
public string Name { get; set; }

public IEnumerable<MediatrElement> Elements { get; set; }
public string Path { get; set; }

public IEnumerable<MediatrElement> Elements { get; set; }
}
}
}
15 changes: 7 additions & 8 deletions src/MediatR-vs/MouseDoubleClick.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System;
using System;
using System.Windows;
using System.Windows.Input;

namespace MediatRvs
{
// https://stackoverflow.com/a/4498006/180156
// inspired by https://stackoverflow.com/a/4498006/180156

public class MouseDoubleClick
{
Expand Down Expand Up @@ -91,14 +91,13 @@ private static void OnMouseSingleClick(object sender, RoutedEventArgs e)
var timeBetweenClicks = DateTime.Now - lastClick;
var timeout = GetDoubleClickTimeout((DependencyObject)sender);

if (timeBetweenClicks < timeout)
if (timeBetweenClicks >= timeout)
{
// this is it!
lastSender = null;
OnMouseDoubleClick(sender, e);
return;
}

return;
lastSender = null;
OnMouseDoubleClick(sender, e);
}

// this is the first click
Expand All @@ -114,4 +113,4 @@ private static void OnMouseDoubleClick(object sender, RoutedEventArgs e)
command?.Execute(commandParameter);
}
}
}
}
Loading

0 comments on commit 2511f21

Please sign in to comment.