Skip to content

Commit

Permalink
Fixed grouping
Browse files Browse the repository at this point in the history
Filling projects at startup
  • Loading branch information
StefanKert committed Apr 13, 2019
1 parent 58a8042 commit 82e540e
Show file tree
Hide file tree
Showing 13 changed files with 303 additions and 301 deletions.
252 changes: 126 additions & 126 deletions src/BuildVision.UI/Components/ControlView.xaml

Large diffs are not rendered by default.

15 changes: 14 additions & 1 deletion src/BuildVision.UI/Components/ControlView.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System.Globalization;
using System.ComponentModel;
using System.Globalization;
using System.Windows.Controls;
using System.Windows.Markup;
using BuildVision.UI.ViewModels;

namespace BuildVision.UI
{
Expand All @@ -9,12 +11,23 @@ namespace BuildVision.UI
/// </summary>
public partial class ControlView : UserControl
{
public BuildVisionPaneViewModel ViewModel
{
get => (BuildVisionPaneViewModel)DataContext;
set => DataContext = value;
}

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);

if (DesignerProperties.GetIsInDesignMode(new System.Windows.DependencyObject()))
{
ViewModel = new BuildVisionPaneViewModel();
}
}
}
}
98 changes: 36 additions & 62 deletions src/BuildVision.UI/Components/ProjectGrid.xaml

Large diffs are not rendered by default.

54 changes: 28 additions & 26 deletions src/BuildVision.UI/Components/ProjectGrid.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Windows;
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;
using BuildVision.UI.Converters;
using BuildVision.UI.DataGrid;
Expand All @@ -15,73 +18,77 @@ namespace BuildVision.UI.Components
{
public partial class ProjectGrid : UserControl
{
private BuildVisionPaneViewModel _viewModel;
public BuildVisionPaneViewModel ViewModel
{
get => (BuildVisionPaneViewModel)DataContext;
set => DataContext = value;
}

public ProjectGrid()
{
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);
Grid.TargetUpdated += GridOnTargetUpdated;
}

private void GridOnTargetUpdated(object sender, DataTransferEventArgs e)
{
if (e.Property.Name == "ItemsSource")
if (e.Property.Name == nameof(Grid.ItemsSource))
{
RefreshSortDirectionInGrid();
}
}

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

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

private void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
{
_viewModel = (BuildVisionPaneViewModel)DataContext;
_viewModel.SetGridColumnsRef(Grid.Columns);
_viewModel.PropertyChanged += ViewModelOnPropertyChanged;
Debug.Assert(ViewModel != null);
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.BuildInformationModel.CurrentProject != null && e.PropertyName == "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);
Grid.ScrollIntoView(ViewModel.BuildInformationModel.CurrentProject);
}
}

private void DataGridExpanderOnExpanded(object sender, RoutedEventArgs e)
{
ExpanderIsExpandedConverter.SaveState(
(Expander)sender,
false,
_viewModel.ControlSettings.GridSettings.CollapsedGroups);
ExpanderIsExpandedConverter.SaveState((Expander)sender, false, ViewModel.ControlSettings.GridSettings.CollapsedGroups);
e.Handled = true;
}

private void DataGridExpanderOnCollapsed(object sender, RoutedEventArgs e)
{
ExpanderIsExpandedConverter.SaveState(
(Expander)sender,
true,
_viewModel.ControlSettings.GridSettings.CollapsedGroups);
ExpanderIsExpandedConverter.SaveState((Expander)sender, true, ViewModel.ControlSettings.GridSettings.CollapsedGroups);
e.Handled = true;
}

Expand Down Expand Up @@ -114,12 +121,7 @@ private void DataGridRowOnPreviewMouseLeftButtonDown(object sender, MouseButtonE
{
row.Focusable = true;
row.Focus();

// Gets the element with keyboard focus.
var elementWithFocus = Keyboard.FocusedElement as UIElement;

// Change keyboard focus.
if (elementWithFocus != null)
if (Keyboard.FocusedElement is UIElement elementWithFocus)
{
var request = new TraversalRequest(FocusNavigationDirection.Next);
elementWithFocus.MoveFocus(request);
Expand Down
4 changes: 2 additions & 2 deletions src/BuildVision.UI/Converters/ExpanderIsExpandedConverter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Windows.Controls;
Expand All @@ -11,7 +11,7 @@ public class ExpanderIsExpandedConverter : IMultiValueConverter
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
var collectionViewGroup = (CollectionViewGroup)values[0];
var collapsedGroups = (IList<string>)values[1];
var collapsedGroups = values[1] as IList<string>;

if (collapsedGroups == null || collapsedGroups.Count == 0)
return true;
Expand Down
10 changes: 5 additions & 5 deletions src/BuildVision.UI/Models/ProjectItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ public class ProjectItem : BindableBase, IProjectItem
{
private const string ResourcesUri = @"Resources/ProjectItem.Resources.xaml";

public ProjectItem()
{
State = ProjectState.Pending;
}

public bool IsBatchBuildProject { get; set; }

private string _uniqueName;
Expand Down Expand Up @@ -258,6 +253,11 @@ public string SolutionFolder
}
public bool Success { get; set; }

public ProjectItem()
{
State = ProjectState.Pending;
}

public void RaiseBuildElapsedTimeChanged()
{
OnPropertyChanged(nameof(BuildElapsedTime));
Expand Down
13 changes: 4 additions & 9 deletions src/BuildVision.UI/Settings/Models/GridSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ public string GroupName
set => _groupName = value;
}

/// <summary>
/// User-friendly header format for groups.
/// For example, "{title}: {value} - {count} items".
/// Available arguments see in <see cref="GroupHeaderFormatArgs"/>.
/// </summary>
public string GroupHeaderFormat
{
get => _groupHeaderFormat ?? (_groupHeaderFormat = "{title}: {value}");
Expand All @@ -75,18 +70,18 @@ public SortDescription Sort

public List<string> CollapsedGroups => _collapsedGroups ?? (_collapsedGroups = new List<string>());

/// <summary>
/// Converts user-friendly string format with <see cref="GroupHeaderFormatArgs"/> arguments
/// into system format string (with {0},{1},... arguments).
/// </summary>
private static string ConvertGroupHeaderToRawFormat(string userFriendlyFormatString)
{
if (string.IsNullOrEmpty(userFriendlyFormatString))
{
return string.Empty;
}

string rawFormat = userFriendlyFormatString;
for (int i = 0; i < GroupHeaderFormatArgs.Length; i++)
{
rawFormat = rawFormat.Replace("{" + GroupHeaderFormatArgs[i], "{" + i);
}

return rawFormat;
}
Expand Down
13 changes: 7 additions & 6 deletions src/BuildVision.UI/ViewModels/BuildVisionPaneViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public bool HideUpToDateTargets

public ControlSettings ControlSettings { get; }

public ObservableCollection<IProjectItem> Projects { get; set; }
public ObservableCollection<IProjectItem> Projects { get; }

public IBuildInformationModel BuildInformationModel { get; set; }

Expand Down Expand Up @@ -146,14 +146,12 @@ public ListCollectionView GroupedProjectsList
{
get
{
var groupedList = new ListCollectionView(Projects); // todo use projects here ProjectsList);

var groupedList = new ListCollectionView(Projects);
if (!string.IsNullOrWhiteSpace(GridGroupPropertyName))
{
Debug.Assert(groupedList.GroupDescriptions != null);
groupedList.GroupDescriptions.Add(new PropertyGroupDescription(GridGroupPropertyName));
}

groupedList.CustomSort = GetProjectItemSorter(GridSortDescription);
groupedList.IsLiveGrouping = true;
groupedList.IsLiveSorting = true;
Expand Down Expand Up @@ -183,7 +181,7 @@ public ProjectItem SelectedProjectItem
set => SetProperty(ref _selectedProjectItem, value);
}

internal BuildVisionPaneViewModel()
public BuildVisionPaneViewModel()
{
ControlSettings = new ControlSettings();
BuildInformationModel = new BuildInformationModel();
Expand Down Expand Up @@ -347,7 +345,10 @@ private void CopyErrorMessageToClipboard(ProjectItem projectItem)

public ICommand GridSorting => new RelayCommand(obj => ReorderGrid(obj));

public ICommand GridGroupPropertyMenuItemClicked => new RelayCommand(obj => GridGroupPropertyName = (obj != null) ? obj.ToString() : string.Empty);
public ICommand GridGroupPropertyMenuItemClicked => new RelayCommand(obj =>
{
GridGroupPropertyName = (obj != null) ? obj.ToString() : string.Empty;
});

public ICommand SelectedProjectOpenContainingFolderAction => new RelayCommand(obj => OpenContainingFolder(), canExecute: obj => (SelectedProjectItem != null && !string.IsNullOrEmpty(SelectedProjectItem.FullName)));

Expand Down
1 change: 1 addition & 0 deletions src/BuildVision/BuildVision.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
<Compile Include="Commands\ShowToolWindowCommand.cs" />
<Compile Include="Constants\EnvDTECodeModelLanguageConstants2.cs" />
<Compile Include="Extensions\BuildActionsExtensions.cs" />
<Compile Include="Extensions\BuildStateExtensions.cs" />
<Compile Include="Extensions\IServiceProviderExtensions.cs" />
<Compile Include="Services\BuildInformationProvider.cs" />
<Compile Include="Services\ErrorNavigationService.cs" />
Expand Down
35 changes: 35 additions & 0 deletions src/BuildVision/Extensions/BuildStateExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Windows.Shell;
using BuildVision.Contracts;

namespace BuildVision.Extensions
{
public static class BuildStateExtensions
{
public static TaskbarItemProgressState ToTaskBarItemProgressState(this BuildState buildState, BuildScopes buildScope)
{
var progressState = TaskbarItemProgressState.Normal;
if (buildState == BuildState.Cancelled)
{
progressState = TaskbarItemProgressState.Paused;
}
else if (buildState == BuildState.Failed)
{
progressState = TaskbarItemProgressState.Error;
}
else if (buildState != BuildState.InProgress)
{
progressState = TaskbarItemProgressState.None;
}
else if (buildScope != BuildScopes.BuildScopeSolution)
{
progressState = TaskbarItemProgressState.Indeterminate;
}
else
{
progressState = TaskbarItemProgressState.Normal;
}

return progressState;
}
}
}
Loading

0 comments on commit 82e540e

Please sign in to comment.