feature<WorkingCopy>: add grid layout for unstaged and staged files mode

This commit is contained in:
leo 2020-11-27 18:47:32 +08:00
parent ab98191875
commit 8a6d970498
8 changed files with 278 additions and 30 deletions

View file

@ -0,0 +1,66 @@
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;
namespace SourceGit.Converters {
public class FilesDisplayModeToIcon : IValueConverter {
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
var mode = (Git.Preference.FilesDisplayMode)value;
switch (mode) {
case Git.Preference.FilesDisplayMode.Grid:
return App.Current.FindResource("Icon.Grid") as Geometry;
case Git.Preference.FilesDisplayMode.List:
return App.Current.FindResource("Icon.List") as Geometry;
default:
return App.Current.FindResource("Icon.Tree") as Geometry;
}
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
throw new NotImplementedException();
}
}
public class FilesDisplayModeToList : IValueConverter {
public bool TreatGridAsList { get; set; } = true;
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
var mode = (Git.Preference.FilesDisplayMode)value;
if (mode == Git.Preference.FilesDisplayMode.Tree) return Visibility.Collapsed;
if (mode == Git.Preference.FilesDisplayMode.List) return Visibility.Visible;
if (TreatGridAsList) return Visibility.Visible;
return Visibility.Collapsed;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
throw new NotImplementedException();
}
}
public class FilesDisplayModeToGrid : IValueConverter {
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
return (Git.Preference.FilesDisplayMode)value == Git.Preference.FilesDisplayMode.Grid ? Visibility.Visible : Visibility.Collapsed;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
throw new NotImplementedException();
}
}
public class FilesDisplayModeToTree : IValueConverter {
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
return (Git.Preference.FilesDisplayMode)value == Git.Preference.FilesDisplayMode.Tree ? Visibility.Visible : Visibility.Collapsed;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
throw new NotImplementedException();
}
}
}

29
src/Converters/Path.cs Normal file
View file

@ -0,0 +1,29 @@
using System;
using System.Globalization;
using System.IO;
using System.Windows.Data;
namespace SourceGit.Converters {
public class PathToFileName : IValueConverter {
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
return Path.GetFileName(value as string);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
throw new NotImplementedException();
}
}
public class PathToFolderName : IValueConverter {
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
return Path.GetDirectoryName(value as string);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
throw new NotImplementedException();
}
}
}

View file

@ -32,6 +32,15 @@ namespace SourceGit.Git {
public bool IsExpended { get; set; }
}
/// <summary>
/// File's display mode.
/// </summary>
public enum FilesDisplayMode {
Tree,
List,
Grid,
}
#region STATICS
/// <summary>
/// Storage path for Preference.
@ -99,15 +108,15 @@ namespace SourceGit.Git {
/// </summary>
public bool UIUseHorizontalLayout { get; set; }
/// <summary>
/// Use list instead of tree in unstaged view
/// Files' display mode in unstage view.
/// </summary>
public bool UIUseListInUnstaged { get; set; }
public FilesDisplayMode UIUnstageDisplayMode { get; set; } = FilesDisplayMode.Grid;
/// <summary>
/// Use list instead of tree in staged view.
/// Files' display mode in staged view.
/// </summary>
public bool UIUseListInStaged { get; set; }
public FilesDisplayMode UIStagedDisplayMode { get; set; } = FilesDisplayMode.Grid;
/// <summary>
/// Use list instead of tree in change view.
/// Using datagrid instead of tree in changes.
/// </summary>
public bool UIUseListInChanges { get; set; }
/// <summary>

View file

@ -20,6 +20,7 @@
<Geometry x:Key="Icon.List">M51.2 204.8h102.4v102.4H51.2V204.8z m204.8 0h716.8v102.4H256V204.8zM51.2 460.8h102.4v102.4H51.2V460.8z m204.8 0h716.8v102.4H256V460.8z m-204.8 256h102.4v102.4H51.2v-102.4z m204.8 0h716.8v102.4H256v-102.4z</Geometry>
<Geometry x:Key="Icon.Tree">M912 737l0 150L362 887l0-100 0-50 0-150 0-150 0-150L112 287l0-150 450 0 0 150L412 287l0 150L912 437l0 150L412 587l0 150L912 737z</Geometry>
<Geometry x:Key="Icon.Grid">M256 256l220.16 0 0 220.16-220.16 0 0-220.16ZM547.84 256l220.16 0 0 220.16-220.16 0 0-220.16ZM256 547.84l220.16 0 0 220.16-220.16 0 0-220.16ZM547.84 547.84l220.16 0 0 220.16-220.16 0 0-220.16Z</Geometry>
<Geometry x:Key="Icon.MoveUp">M868 545.5L536.1 163c-12.7-14.7-35.5-14.7-48.3 0L156 545.5c-4.5 5.2-0.8 13.2 6 13.2h81c4.6 0 9-2 12.1-5.5L474 300.9V864c0 4.4 3.6 8 8 8h60c4.4 0 8-3.6 8-8V300.9l218.9 252.3c3 3.5 7.4 5.5 12.1 5.5h81c6.8 0 10.5-8 6-13.2z</Geometry>
<Geometry x:Key="Icon.MoveDown">M862 465.3h-81c-4.6 0-9 2-12.1 5.5L550 723.1V160c0-4.4-3.6-8-8-8h-60c-4.4 0-8 3.6-8 8v563.1L255.1 470.8c-3-3.5-7.4-5.5-12.1-5.5h-81c-6.8 0-10.5 8.1-6 13.2L487.9 861c12.7 14.7 35.5 14.7 48.3 0L868 478.5c4.5-5.2 0.8-13.2-6-13.2z</Geometry>

View file

@ -0,0 +1,49 @@
<UserControl x:Class="SourceGit.UI.FilesDisplayModeSwitch"
x:Name="me"
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:converters="clr-namespace:SourceGit.Converters"
mc:Ignorable="d">
<Grid>
<Grid.Resources>
<converters:FilesDisplayModeToIcon x:Key="FilesDisplayModeToIcon"/>
<Style x:Key="Style.Icon.DisplayMode" TargetType="{x:Type Path}" BasedOn="{StaticResource Style.Icon}">
<Setter Property="Fill" Value="Transparent"/>
<Setter Property="Stroke" Value="{StaticResource Brush.FG}"/>
<Setter Property="StrokeThickness" Value=".4"/>
<Setter Property="Width" Value="12"/>
<Setter Property="Height" Value="12"/>
</Style>
</Grid.Resources>
<Button Click="OpenModeSelector" ToolTip="CHANGE FILES DISPLAY MODE" Margin="4,0">
<Button.ContextMenu>
<ContextMenu x:Name="selector" Placement="Bottom" StaysOpen="False" Focusable="True">
<MenuItem Header="Show As Grid" Click="UseGrid">
<MenuItem.Icon>
<Path Style="{StaticResource Style.Icon.DisplayMode}" Data="{StaticResource Icon.Grid}"/>
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Show As List" Click="UseList">
<MenuItem.Icon>
<Path Style="{StaticResource Style.Icon.DisplayMode}" Data="{StaticResource Icon.List}"/>
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Show As Tree" Click="UseTree">
<MenuItem.Icon>
<Path Style="{StaticResource Style.Icon.DisplayMode}" Data="{StaticResource Icon.Tree}"/>
</MenuItem.Icon>
</MenuItem>
</ContextMenu>
</Button.ContextMenu>
<Path
Style="{StaticResource Style.Icon.DisplayMode}"
Data="{Binding ElementName=me, Path=Mode, Converter={StaticResource FilesDisplayModeToIcon}}"/>
</Button>
</Grid>
</UserControl>

View file

@ -0,0 +1,46 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace SourceGit.UI {
/// <summary>
/// Interaction logic for FilesDisplayModeSwitch.xaml
/// </summary>
public partial class FilesDisplayModeSwitch : UserControl {
public static readonly DependencyProperty ModeProperty =
DependencyProperty.Register(
"Mode",
typeof(Git.Preference.FilesDisplayMode),
typeof(FilesDisplayModeSwitch),
new PropertyMetadata(Git.Preference.FilesDisplayMode.Grid));
public Git.Preference.FilesDisplayMode Mode {
get { return (Git.Preference.FilesDisplayMode)GetValue(ModeProperty); }
set { SetValue(ModeProperty, value); }
}
public FilesDisplayModeSwitch() {
InitializeComponent();
}
private void OpenModeSelector(object sender, RoutedEventArgs e) {
selector.PlacementTarget = sender as Button;
selector.IsOpen = true;
e.Handled = true;
}
private void UseGrid(object sender, RoutedEventArgs e) {
Mode = Git.Preference.FilesDisplayMode.Grid;
}
private void UseList(object sender, RoutedEventArgs e) {
Mode = Git.Preference.FilesDisplayMode.List;
}
private void UseTree(object sender, RoutedEventArgs e) {
Mode = Git.Preference.FilesDisplayMode.Tree;
}
}
}

View file

@ -18,6 +18,12 @@
<converters:FileStatusToIcon x:Key="UnstagedStatusIconConverter" OnlyWorkTree="True"/>
<converters:FileStatusToColor x:Key="StagedStatusConverter"/>
<converters:FileStatusToIcon x:Key="StagedStatusIconConverter"/>
<converters:FilesDisplayModeToList x:Key="FilesDisplayModeToList"/>
<converters:FilesDisplayModeToList x:Key="FilesDisplayModeToListOnly" TreatGridAsList="False"/>
<converters:FilesDisplayModeToTree x:Key="FilesDisplayModeToTree"/>
<converters:FilesDisplayModeToGrid x:Key="FilesDisplayModeToGrid"/>
<converters:PathToFileName x:Key="PathToFileName"/>
<converters:PathToFolderName x:Key="PathToFolderName"/>
</UserControl.Resources>
<Grid Background="{StaticResource Brush.BG3}">
@ -51,13 +57,10 @@
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<ToggleButton
<local:FilesDisplayModeSwitch
Grid.Column="0"
x:Name="toggleUnstangedMode"
Margin="4,0,4,0"
ToolTip="SWITCH TO LIST/TREE VIEW"
Style="{StaticResource Style.ToggleButton.ListOrTree}"
IsChecked="{Binding Source={x:Static source:App.Preference}, Path=UIUseListInUnstaged, Mode=TwoWay}"/>
Mode="{Binding Source={x:Static source:App.Preference}, Path=UIUnstageDisplayMode, Mode=TwoWay}"
Opacity=".4"/>
<Label Grid.Column="1" Content="UNSTAGED" FontWeight="Bold" Foreground="{StaticResource Brush.FG}" Opacity=".4"/>
<Button Grid.Column="3" Click="Stage" Margin="4,0" ToolTip="STAGE" Background="Transparent">
<Path Width="14" Height="14" Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Down}" Opacity=".4"/>
@ -71,7 +74,7 @@
Grid.Row="1"
x:Name="unstagedTree"
Background="{StaticResource Brush.BG2}"
Visibility="{Binding ElementName=toggleUnstangedMode, Path=IsChecked, Converter={StaticResource InverseBoolToCollapsed}}"
Visibility="{Binding Source={x:Static source:App.Preference}, Path=UIUnstageDisplayMode, Converter={StaticResource FilesDisplayModeToTree}}"
FontFamily="Consolas"
PreviewMouseWheel="TreeMouseWheel"
helpers:TreeViewHelper.EnableMultiSelection="True"
@ -124,7 +127,7 @@
<DataGrid
Grid.Row="1"
x:Name="unstagedList"
Visibility="{Binding ElementName=toggleUnstangedMode, Path=IsChecked, Converter={StaticResource BoolToCollapsed}}"
Visibility="{Binding Source={x:Static source:App.Preference}, Path=UIUnstageDisplayMode, Converter={StaticResource FilesDisplayModeToList}}"
RowHeight="24"
SelectionChanged="UnstagedListSelectionChanged"
SelectionMode="Extended"
@ -133,6 +136,7 @@
<DataGrid.Resources>
<Style x:Key="Style.DataGridText.VerticalCenter" TargetType="{x:Type TextBlock}">
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Padding" Value="4,0"/>
</Style>
<RoutedUICommand x:Key="SelectWholeDataGridCommand" Text="SelectWholeDataGrid"/>
@ -156,7 +160,30 @@
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Width="*" Binding="{Binding Path}" Foreground="{StaticResource Brush.FG}" FontFamily="Consolas" ElementStyle="{StaticResource Style.DataGridText.VerticalCenter}"/>
<DataGridTextColumn
Width="Auto"
Visibility="{Binding Source={x:Static source:App.Preference}, Path=UIUnstageDisplayMode, Converter={StaticResource FilesDisplayModeToGrid}}"
Binding="{Binding Path, Converter={StaticResource PathToFileName}}"
Foreground="{StaticResource Brush.FG}"
FontFamily="Consolas"
ElementStyle="{StaticResource Style.DataGridText.VerticalCenter}"/>
<DataGridTextColumn
Width="*"
Visibility="{Binding Source={x:Static source:App.Preference}, Path=UIUnstageDisplayMode, Converter={StaticResource FilesDisplayModeToGrid}}"
Binding="{Binding Path, Converter={StaticResource PathToFolderName}}"
Foreground="{StaticResource Brush.FG2}"
FontFamily="Consolas"
ElementStyle="{StaticResource Style.DataGridText.VerticalCenter}"/>
<DataGridTextColumn
Width="*"
Visibility="{Binding Source={x:Static source:App.Preference}, Path=UIUnstageDisplayMode, Converter={StaticResource FilesDisplayModeToListOnly}}"
Binding="{Binding Path}"
Foreground="{StaticResource Brush.FG}"
FontFamily="Consolas"
ElementStyle="{StaticResource Style.DataGridText.VerticalCenter}"/>
</DataGrid.Columns>
<DataGrid.RowStyle>
@ -186,13 +213,10 @@
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<ToggleButton
<local:FilesDisplayModeSwitch
Grid.Column="0"
x:Name="toggleStagedMode"
Margin="4,0,4,0"
ToolTip="SWITCH TO LIST/TREE VIEW"
Style="{StaticResource Style.ToggleButton.ListOrTree}"
IsChecked="{Binding Source={x:Static source:App.Preference}, Path=UIUseListInStaged, Mode=TwoWay}"/>
Mode="{Binding Source={x:Static source:App.Preference}, Path=UIStagedDisplayMode, Mode=TwoWay}"
Opacity=".4"/>
<Label Grid.Column="1" Content="STAGED" FontWeight="Bold" Foreground="{StaticResource Brush.FG}" Opacity=".4"/>
<Button Grid.Column="3" Click="Unstage" ToolTip="UNSTAGE" Margin="4,0" Background="Transparent">
<Path Width="14" Height="14" Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Up}" Opacity=".4"/>
@ -205,8 +229,8 @@
<TreeView
Grid.Row="1"
x:Name="stageTree"
Visibility="{Binding Source={x:Static source:App.Preference}, Path=UIStagedDisplayMode, Converter={StaticResource FilesDisplayModeToTree}}"
Background="{StaticResource Brush.BG2}"
Visibility="{Binding ElementName=toggleStagedMode, Path=IsChecked, Converter={StaticResource InverseBoolToCollapsed}}"
FontFamily="Consolas"
PreviewMouseWheel="TreeMouseWheel"
helpers:TreeViewHelper.EnableMultiSelection="True"
@ -259,8 +283,8 @@
<DataGrid
Grid.Row="1"
x:Name="stageList"
Visibility="{Binding ElementName=toggleStagedMode, Path=IsChecked, Converter={StaticResource BoolToCollapsed}}"
RowHeight="24"
Visibility="{Binding Source={x:Static source:App.Preference}, Path=UIStagedDisplayMode, Converter={StaticResource FilesDisplayModeToList}}"
SelectionChanged="StagedListSelectionChanged"
SelectionMode="Extended"
SelectionUnit="FullRow"
@ -268,6 +292,7 @@
<DataGrid.Resources>
<Style x:Key="Style.DataGridText.VerticalCenter" TargetType="{x:Type TextBlock}">
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Padding" Value="4,0"/>
</Style>
<RoutedUICommand x:Key="SelectWholeDataGridCommand" Text="SelectWholeDataGrid"/>
@ -291,7 +316,30 @@
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Width="*" Binding="{Binding Path}" Foreground="{StaticResource Brush.FG}" FontFamily="Consolas" ElementStyle="{StaticResource Style.DataGridText.VerticalCenter}"/>
<DataGridTextColumn
Width="Auto"
Visibility="{Binding Source={x:Static source:App.Preference}, Path=UIStagedDisplayMode, Converter={StaticResource FilesDisplayModeToGrid}}"
Binding="{Binding Path, Converter={StaticResource PathToFileName}}"
Foreground="{StaticResource Brush.FG}"
FontFamily="Consolas"
ElementStyle="{StaticResource Style.DataGridText.VerticalCenter}"/>
<DataGridTextColumn
Width="*"
Visibility="{Binding Source={x:Static source:App.Preference}, Path=UIStagedDisplayMode, Converter={StaticResource FilesDisplayModeToGrid}}"
Binding="{Binding Path, Converter={StaticResource PathToFolderName}}"
Foreground="{StaticResource Brush.FG2}"
FontFamily="Consolas"
ElementStyle="{StaticResource Style.DataGridText.VerticalCenter}"/>
<DataGridTextColumn
Width="*"
Visibility="{Binding Source={x:Static source:App.Preference}, Path=UIStagedDisplayMode, Converter={StaticResource FilesDisplayModeToListOnly}}"
Binding="{Binding Path}"
Foreground="{StaticResource Brush.FG}"
FontFamily="Consolas"
ElementStyle="{StaticResource Style.DataGridText.VerticalCenter}"/>
</DataGrid.Columns>
<DataGrid.RowStyle>

View file

@ -495,7 +495,7 @@ namespace SourceGit.UI {
private async void Stage(object sender, RoutedEventArgs e) {
var files = new List<string>();
if (App.Preference.UIUseListInUnstaged) {
if (App.Preference.UIUnstageDisplayMode != Git.Preference.FilesDisplayMode.Tree) {
var selected = unstagedList.SelectedItems;
foreach (var one in selected) {
var node = one as Git.Change;
@ -695,7 +695,7 @@ namespace SourceGit.UI {
private async void Unstage(object sender, RoutedEventArgs e) {
var files = new List<string>();
if (App.Preference.UIUseListInStaged) {
if (App.Preference.UIStagedDisplayMode != Git.Preference.FilesDisplayMode.Tree) {
var selected = stageList.SelectedItems;
foreach (var one in selected) {
var node = one as Git.Change;
@ -867,7 +867,7 @@ namespace SourceGit.UI {
}
string file = null;
if (App.Preference.UIUseListInUnstaged) {
if (App.Preference.UIUnstageDisplayMode != Git.Preference.FilesDisplayMode.Tree) {
var selected = unstagedList.SelectedItems;
if (selected.Count <= 0) return;
@ -894,7 +894,7 @@ namespace SourceGit.UI {
private async void UseTheirs(object sender, RoutedEventArgs e) {
var files = new List<string>();
if (App.Preference.UIUseListInUnstaged) {
if (App.Preference.UIUnstageDisplayMode != Git.Preference.FilesDisplayMode.Tree) {
var selected = unstagedList.SelectedItems;
foreach (var one in selected) {
var node = one as Git.Change;
@ -923,7 +923,7 @@ namespace SourceGit.UI {
private async void UseMine(object sender, RoutedEventArgs e) {
var files = new List<string>();
if (App.Preference.UIUseListInUnstaged) {
if (App.Preference.UIUnstageDisplayMode != Git.Preference.FilesDisplayMode.Tree) {
var selected = unstagedList.SelectedItems;
foreach (var one in selected) {
var node = one as Git.Change;