Skip to content

Commit

Permalink
Smaller cleanups and fixes to sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanKert committed Apr 7, 2019
1 parent 51c606f commit 77e7aac
Show file tree
Hide file tree
Showing 31 changed files with 93 additions and 217 deletions.
4 changes: 0 additions & 4 deletions src/BuildVision.UI/BuildVision.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,6 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Components\UserControl_ForTesting.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Controls\BuildVisionProgressBar.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
2 changes: 0 additions & 2 deletions src/BuildVision.UI/Components/ControlView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
xmlns:viewModels="clr-namespace:BuildVision.UI.ViewModels"
xmlns:extensions="clr-namespace:BuildVision.UI.Extensions"
xmlns:helpers="clr-namespace:BuildVision.UI.Helpers"
xmlns:contracts="clr-namespace:BuildVision.Contracts;assembly=BuildVision.Contracts"
xmlns:customButtons="clr-namespace:BuildVision.UI.Controls.Buttons"
xmlns:indicators="clr-namespace:BuildVision.UI.Controls.Indicators"
xmlns:controls="clr-namespace:BuildVision.UI.Controls"
Expand All @@ -16,7 +15,6 @@
mc:Ignorable="d"
Name="OwnerUserControl"
Background="{DynamicResource ToolWindowBackgroundKey}"
DataContextChanged="OnDataContextChanged"
SnapsToDevicePixels="True"
UseLayoutRounding="True"
d:DesignHeight="148"
Expand Down
40 changes: 1 addition & 39 deletions src/BuildVision.UI/Components/ControlView.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
using BuildVision.UI.Converters;
using BuildVision.UI.DataGrid;
using BuildVision.UI.Helpers;
using BuildVision.UI.Models;
using BuildVision.UI.ViewModels;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Windows;
using System.Globalization;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Markup;
using System.Windows.Media;

namespace BuildVision.UI
{
Expand All @@ -24,35 +9,12 @@ namespace BuildVision.UI
/// </summary>
public partial class ControlView : UserControl
{
private BuildVisionPaneViewModel _viewModel;

public ControlView()
{
InitializeComponent();
// Ensure the current culture passed into bindings is the OS culture.
// By default, WPF uses en-US as the culture, regardless of the system settings.
Language = XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag);
}

private void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
{
Debug.Assert(DataContext != null);

_viewModel = (BuildVisionPaneViewModel) DataContext;
_viewModel.PropertyChanged += ViewModelOnPropertyChanged;
}

private void ViewModelOnPropertyChanged(object sender, PropertyChangedEventArgs e)
{
//TODO implement logic for scrolling tu currentproject
//if (_viewModel.CurrentProject != null && e.PropertyName == "CurrentProject")
//{
// // TODO: Remove SelectedIndex = -1 and implement Unselect row feature by clicking on selected row.
// Grid.SelectedIndex = -1;

// if (Grid.SelectedIndex == -1)
// Grid.ScrollIntoView(_viewModel.CurrentProject);
//}
}
}
}
69 changes: 22 additions & 47 deletions src/BuildVision.UI/Components/ProjectGrid.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.IsDeferredScrollingEnabled="False"
ScrollViewer.VerticalScrollBarVisibility="Auto"
SelectedItem="{Binding SelectedProjectItem}"
SelectedItem="{Binding BuildInformationModel.CurrentProject}"
SelectionMode="Single"
SelectionUnit="FullRow"
Sorting="GridOnSorting"
Expand Down Expand Up @@ -172,21 +172,13 @@

<DataGrid.RowStyle>
<Style TargetType="DataGridRow">

<Setter Property="Foreground"
Value="{DynamicResource ToolWindowTextKey}" />
<Setter Property="BorderThickness"
Value="0,1,0,1" />
<Setter Property="BorderBrush"
Value="{Binding Background, RelativeSource={RelativeSource self}}" />

<Setter Property="DetailsVisibility"
Value="{Binding ErrorsCount, Mode=OneWay, Converter={StaticResource PositiveNumberToVisibilityConverter}}" />
<EventSetter Event="PreviewMouseLeftButtonDown"
Handler="DataGridRowOnPreviewMouseLeftButtonDown" />
<Setter Property="Foreground" Value="{DynamicResource ToolWindowTextKey}" />
<Setter Property="BorderThickness" Value="0,1,0,1" />
<Setter Property="BorderBrush" Value="{Binding Background, RelativeSource={RelativeSource self}}" />
<Setter Property="DetailsVisibility" Value="{Binding ErrorsCount, Mode=OneWay, Converter={StaticResource PositiveNumberToVisibilityConverter}}" />
<EventSetter Event="PreviewMouseLeftButtonDown" Handler="DataGridRowOnPreviewMouseLeftButtonDown" />

<Style.Triggers>

<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Value="{x:Static contracts:ProjectState.UpToDate}" Binding="{Binding Path=State}"/>
Expand All @@ -195,7 +187,6 @@
<Setter Property="Visibility" Value="Collapsed"/>
</MultiDataTrigger>


<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Value="{x:Static contracts:ProjectState.Pending}" Binding="{Binding Path=State}"/>
Expand All @@ -207,24 +198,18 @@
<DataTrigger Value="True">
<DataTrigger.Binding>
<MultiBinding Converter="{StaticResource ObjectsReferencesEqualsConverter}">
<Binding Path="DataContext.CurrentProject"
RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type UserControl}}" />
<Binding Path="DataContext.CurrentProject" RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type UserControl}}" />
<Binding Path="." />
</MultiBinding>
</DataTrigger.Binding>
<Setter Property="BorderBrush"
Value="CornflowerBlue" />
<Setter Property="BorderThickness"
Value="0,1,0,1" />
<Setter Property="BorderBrush" Value="CornflowerBlue" />
<Setter Property="BorderThickness" Value="0,1,0,1" />
</DataTrigger>

<!-- TODO: Make Selected row style similar to style in VisualStudio.-->
<Trigger Property="IsSelected"
Value="True">
<Setter Property="BorderBrush"
Value="DodgerBlue" />
<Setter Property="BorderThickness"
Value="0,1,0,1" />
<Trigger Property="IsSelected" Value="True">
<Setter Property="BorderBrush" Value="DodgerBlue" />
<Setter Property="BorderThickness" Value="0,1,0,1" />
</Trigger>

</Style.Triggers>
Expand All @@ -235,23 +220,19 @@
<ContextMenu>
<MenuItem Header="{x:Static res:Resources.SelectedProjectItemMenuItems}"
ItemsSource="{Binding Source={StaticResource SelectedProjectMenuItems}}"
Visibility="{Binding SelectedProjectItem,
Converter={StaticResource NotNullToVisibilityConverter}}" />
<Separator Visibility="{Binding SelectedProjectItem,
Converter={StaticResource NotNullToVisibilityConverter}}" />
Visibility="{Binding SelectedProjectItem, Converter={StaticResource NotNullToVisibilityConverter}}" />
<Separator Visibility="{Binding SelectedProjectItem, Converter={StaticResource NotNullToVisibilityConverter}}" />
<MenuItem Header="{x:Static res:Resources.GridHeaderVisibleMenuItem}"
IsCheckable="True"
IsChecked="{Binding GridHeadersVisibility,
Converter={StaticResource ResourceKey=ColumnHeadersVisibilityToBool}}" />
IsChecked="{Binding GridHeadersVisibility, Converter={StaticResource ResourceKey=ColumnHeadersVisibilityToBool}}" />
<MenuItem Header="{x:Static res:Resources.HideUpToDateTargetsMenuItem}"
IsCheckable="True"
IsChecked="{Binding HideUpToDateTargets}" />
<MenuItem Header="{x:Static res:Resources.GridColumnsMenuItems}"
ItemsSource="{Binding Source={StaticResource GridColumnsMenuItems}}">
<MenuItem.ItemContainerStyle>
<Style TargetType="{x:Type MenuItem}">
<Setter Property="StaysOpenOnClick"
Value="True" />
<Setter Property="StaysOpenOnClick" Value="True" />
<Setter Property="IsCheckable"
Value="True" />
<Setter Property="IsChecked"
Expand Down Expand Up @@ -284,24 +265,18 @@
OverridesDefaultStyle="True"
Template="{StaticResource ExpanderTemplate}">
<Expander.IsExpanded>
<MultiBinding Converter="{StaticResource ResourceKey=ExpanderIsExpandedConverter}"
Mode="OneWay">
<MultiBinding Converter="{StaticResource ResourceKey=ExpanderIsExpandedConverter}" Mode="OneWay">
<Binding Mode="OneWay" />
<Binding Path="DataContext.ControlSettings.GridSettings.CollapsedGroups"
Source="{x:Reference OwnerUserControl}" />
<Binding Path="DataContext.ControlSettings.GridSettings.CollapsedGroups" Source="{RelativeSource FindAncestor, AncestorType={x:Type UserControl}}" />
</MultiBinding>
</Expander.IsExpanded>
<Expander.Header>
<StackPanel VerticalAlignment="Center"
Orientation="Horizontal">
<StackPanel VerticalAlignment="Center" Orientation="Horizontal">
<TextBlock Foreground="{DynamicResource GrayTextKey}">
<TextBlock.Text>
<MultiBinding Converter="{StaticResource ResourceKey=MultiBindingStringFormatConverter}"
Mode="OneWay">
<Binding Path="DataContext.ControlSettings.GridSettings.GroupHeaderRawFormat"
Source="{x:Reference OwnerUserControl}" />
<Binding Path="DataContext.GridGroupHeaderName"
Source="{x:Reference OwnerUserControl}" />
<MultiBinding Converter="{StaticResource ResourceKey=MultiBindingStringFormatConverter}" Mode="OneWay">
<Binding Path="DataContext.ControlSettings.GridSettings.GroupHeaderRawFormat" Source="{RelativeSource FindAncestor, AncestorType={x:Type UserControl}}" />
<Binding Path="DataContext.GridGroupHeaderName" Source="{RelativeSource FindAncestor, AncestorType={x:Type UserControl}}" />
<Binding Path="Name" />
<Binding Path="ItemCount" />
</MultiBinding>
Expand Down
52 changes: 23 additions & 29 deletions src/BuildVision.UI/Components/ProjectGrid.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,18 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using BuildVision.UI.Converters;
using BuildVision.UI.DataGrid;
using BuildVision.UI.Helpers;
using BuildVision.UI.ViewModels;

namespace BuildVision.UI.Components
{
/// <summary>
/// Interaction logic for ProjectGrid.xaml
/// </summary>
public partial class ProjectGrid : UserControl
{
private BuildVisionPaneViewModel _viewModel;
Expand All @@ -42,41 +32,45 @@ private void GridOnTargetUpdated(object sender, DataTransferEventArgs e)

private void RefreshSortDirectionInGrid()
{
//DataGridColumn dataGridColumn = Grid.Columns.FirstOrDefault(col => col.GetBindedProperty() == _viewModel.GridSortDescription.Property);
//if (dataGridColumn != null)
// dataGridColumn.SortDirection = _viewModel.GridSortDescription.Order.ToSystem();
DataGridColumn dataGridColumn = Grid.Columns.FirstOrDefault(col => col.GetBindedProperty() == _viewModel.GridSortDescription.Property);
if (dataGridColumn != null)
{
dataGridColumn.SortDirection = _viewModel.GridSortDescription.Order.ToSystem();
}
}

private void GridOnSorting(object sender, DataGridSortingEventArgs e)
{
if (_viewModel.GridSorting.CanExecute(e))
{
_viewModel.GridSorting.Execute(e);
}
}

private void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
{
_viewModel = (BuildVisionPaneViewModel) DataContext;
_viewModel = (BuildVisionPaneViewModel)DataContext;
_viewModel.SetGridColumnsRef(Grid.Columns);
_viewModel.PropertyChanged += ViewModelOnPropertyChanged;
}

private void ViewModelOnPropertyChanged(object sender, PropertyChangedEventArgs e)
{
//TODO implement logic for scrolling tu currentproject
//if (_viewModel.CurrentProject != null && e.PropertyName == "CurrentProject")
//{
// // TODO: Remove SelectedIndex = -1 and implement Unselect row feature by clicking on selected row.
// Grid.SelectedIndex = -1;

// if (Grid.SelectedIndex == -1)
// Grid.ScrollIntoView(_viewModel.CurrentProject);
//}
if (_viewModel.BuildInformationModel.CurrentProject != null && e.PropertyName == "CurrentProject")
{
// TODO: Remove SelectedIndex = -1 and implement Unselect row feature by clicking on selected row.
Grid.SelectedIndex = -1;

if (Grid.SelectedIndex == -1)
Grid.ScrollIntoView(_viewModel.BuildInformationModel.CurrentProject);
}
}

private void DataGridExpanderOnExpanded(object sender, RoutedEventArgs e)
{
ExpanderIsExpandedConverter.SaveState(
(Expander) sender,
(Expander)sender,
false,
_viewModel.ControlSettings.GridSettings.CollapsedGroups);
e.Handled = true;
Expand All @@ -85,7 +79,7 @@ private void DataGridExpanderOnExpanded(object sender, RoutedEventArgs e)
private void DataGridExpanderOnCollapsed(object sender, RoutedEventArgs e)
{
ExpanderIsExpandedConverter.SaveState(
(Expander) sender,
(Expander)sender,
true,
_viewModel.ControlSettings.GridSettings.CollapsedGroups);
e.Handled = true;
Expand All @@ -101,7 +95,7 @@ private void DataGridExpanderOnPreviewMouseWheel(object sender, MouseWheelEventA
Source = sender
};

var parent = (UIElement) VisualTreeHelper.GetParent((DependencyObject) sender);
var parent = (UIElement)VisualTreeHelper.GetParent((DependencyObject)sender);
parent.RaiseEvent(eventArg);
}

Expand All @@ -115,7 +109,7 @@ private void DataGridRowDetailsOnMouseLeftButtonDown(object sender, MouseButtonE
// Autofocus for RowDetails (without extra mouse click).
private void DataGridRowOnPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
var row = (DataGridRow) sender;
var row = (DataGridRow)sender;
if (!row.IsSelected && e.Source is DataGridDetailsPresenter)
{
row.Focusable = true;
Expand Down
38 changes: 0 additions & 38 deletions src/BuildVision.UI/Components/UserControl_ForTesting.xaml

This file was deleted.

4 changes: 2 additions & 2 deletions src/BuildVision.UI/Enums/BuildExtraMessageFormat.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using BuildVision.UI.Helpers;
using BuildVision.UI.Helpers;

namespace BuildVision.UI.Models
{
Expand All @@ -16,4 +16,4 @@ public enum BuildExtraMessageFormat
[DisplayString(ResourceName = nameof(Resources.EnumBuildStateExtraLabelTemplate_TotalMinutesWithSeconds))]
TotalMinutesWithSeconds
}
}
}
2 changes: 1 addition & 1 deletion src/BuildVision.UI/Enums/BuildMajorMessageFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ public enum BuildMajorMessageFormat
[DisplayString(ResourceName = nameof(Resources.EnumBuildStateLabelTemplate_ShortForm))]
Unnamed
}
}
}
Loading

0 comments on commit 77e7aac

Please sign in to comment.