mirror of
https://fastgit.cc/github.com/sourcegit-scm/sourcegit
synced 2026-04-25 03:12:21 +08:00
feature: supports to switch change display mode in STASHES page (#1504)
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
@@ -285,6 +285,12 @@ namespace SourceGit.ViewModels
|
||||
set => SetProperty(ref _commitChangeViewMode, value);
|
||||
}
|
||||
|
||||
public Models.ChangeViewMode StashChangeViewMode
|
||||
{
|
||||
get => _stashChangeViewMode;
|
||||
set => SetProperty(ref _stashChangeViewMode, value);
|
||||
}
|
||||
|
||||
public string GitInstallPath
|
||||
{
|
||||
get => Native.OS.GitExecutable;
|
||||
@@ -692,6 +698,7 @@ namespace SourceGit.ViewModels
|
||||
private Models.ChangeViewMode _unstagedChangeViewMode = Models.ChangeViewMode.List;
|
||||
private Models.ChangeViewMode _stagedChangeViewMode = Models.ChangeViewMode.List;
|
||||
private Models.ChangeViewMode _commitChangeViewMode = Models.ChangeViewMode.List;
|
||||
private Models.ChangeViewMode _stashChangeViewMode = Models.ChangeViewMode.List;
|
||||
|
||||
private string _gitDefaultCloneDir = string.Empty;
|
||||
|
||||
|
||||
@@ -93,23 +93,23 @@ namespace SourceGit.ViewModels
|
||||
private set
|
||||
{
|
||||
if (SetProperty(ref _changes, value))
|
||||
SelectedChange = value is { Count: > 0 } ? value[0] : null;
|
||||
SelectedChanges = value is { Count: > 0 } ? [value[0]] : [];
|
||||
}
|
||||
}
|
||||
|
||||
public Models.Change SelectedChange
|
||||
public List<Models.Change> SelectedChanges
|
||||
{
|
||||
get => _selectedChange;
|
||||
get => _selectedChanges;
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _selectedChange, value))
|
||||
if (SetProperty(ref _selectedChanges, value))
|
||||
{
|
||||
if (value == null)
|
||||
if (value is not { Count: 1 })
|
||||
DiffContext = null;
|
||||
else if (_untracked.Contains(value))
|
||||
DiffContext = new DiffContext(_repo.FullPath, new Models.DiffOption(Models.Commit.EmptyTreeSHA1, _selectedStash.Parents[2], value), _diffContext);
|
||||
else if (_untracked.Contains(value[0]))
|
||||
DiffContext = new DiffContext(_repo.FullPath, new Models.DiffOption(Models.Commit.EmptyTreeSHA1, _selectedStash.Parents[2], value[0]), _diffContext);
|
||||
else
|
||||
DiffContext = new DiffContext(_repo.FullPath, new Models.DiffOption(_selectedStash.Parents[0], _selectedStash.SHA, value), _diffContext);
|
||||
DiffContext = new DiffContext(_repo.FullPath, new Models.DiffOption(_selectedStash.Parents[0], _selectedStash.SHA, value[0]), _diffContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -129,11 +129,11 @@ namespace SourceGit.ViewModels
|
||||
{
|
||||
_stashes?.Clear();
|
||||
_changes?.Clear();
|
||||
_selectedChanges?.Clear();
|
||||
_untracked.Clear();
|
||||
|
||||
_repo = null;
|
||||
_selectedStash = null;
|
||||
_selectedChange = null;
|
||||
_diffContext = null;
|
||||
}
|
||||
|
||||
@@ -217,11 +217,12 @@ namespace SourceGit.ViewModels
|
||||
return menu;
|
||||
}
|
||||
|
||||
public ContextMenu MakeContextMenuForChange(Models.Change change)
|
||||
public ContextMenu MakeContextMenuForChange()
|
||||
{
|
||||
if (change == null)
|
||||
if (_selectedChanges is not { Count: 1 })
|
||||
return null;
|
||||
|
||||
var change = _selectedChanges[0];
|
||||
var diffWithMerger = new MenuItem();
|
||||
diffWithMerger.Header = App.Text("DiffWithMerger");
|
||||
diffWithMerger.Icon = App.CreateMenuIcon("Icons.OpenWith");
|
||||
@@ -339,7 +340,7 @@ namespace SourceGit.ViewModels
|
||||
private Models.Stash _selectedStash = null;
|
||||
private List<Models.Change> _changes = null;
|
||||
private List<Models.Change> _untracked = [];
|
||||
private Models.Change _selectedChange = null;
|
||||
private List<Models.Change> _selectedChanges = [];
|
||||
private DiffContext _diffContext = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,46 +109,28 @@
|
||||
|
||||
<!-- Changes Bar -->
|
||||
<Border Grid.Row="3" BorderThickness="0,1" BorderBrush="{DynamicResource Brush.Border0}">
|
||||
<Grid ColumnDefinitions="Auto,*">
|
||||
<Grid ColumnDefinitions="Auto,*,Auto">
|
||||
<Path Grid.Column="0" Margin="8,0,0,0" Width="14" Height="14" Fill="{DynamicResource Brush.FG2}" Data="{StaticResource Icons.Changes}"/>
|
||||
<TextBlock Grid.Column="1" Foreground="{DynamicResource Brush.FG2}" FontWeight="Bold" Margin="4,0,0,0">
|
||||
<Run Text="{DynamicResource Text.Stashes.Changes}"/>
|
||||
<Run Text="{Binding Changes, Converter={x:Static c:ListConverters.ToCount}, Mode=OneWay}"/>
|
||||
</TextBlock>
|
||||
|
||||
<v:ChangeViewModeSwitcher Grid.Column="2"
|
||||
Width="14" Height="14"
|
||||
Margin="0,0,8,0"
|
||||
HorizontalAlignment="Right"
|
||||
ViewMode="{Binding Source={x:Static vm:Preferences.Instance}, Path=StashChangeViewMode, Mode=TwoWay}"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<!-- View Changes -->
|
||||
<ListBox Grid.Row="4"
|
||||
Background="{DynamicResource Brush.Contents}"
|
||||
ItemsSource="{Binding Changes}"
|
||||
SelectedItem="{Binding SelectedChange, Mode=TwoWay}"
|
||||
SelectionMode="Single"
|
||||
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
|
||||
ScrollViewer.VerticalScrollBarVisibility="Auto">
|
||||
<ListBox.Styles>
|
||||
<Style Selector="ListBoxItem">
|
||||
<Setter Property="Margin" Value="0"/>
|
||||
<Setter Property="Padding" Value="0"/>
|
||||
<Setter Property="Height" Value="26"/>
|
||||
</Style>
|
||||
</ListBox.Styles>
|
||||
|
||||
<ListBox.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<VirtualizingStackPanel Orientation="Vertical"/>
|
||||
</ItemsPanelTemplate>
|
||||
</ListBox.ItemsPanel>
|
||||
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate DataType="m:Change">
|
||||
<Grid ColumnDefinitions="24,*" Background="Transparent" ContextRequested="OnChangeContextRequested">
|
||||
<v:ChangeStatusIcon Grid.Column="0" Width="14" Height="14" Change="{Binding}"/>
|
||||
<TextBlock Grid.Column="1" Classes="primary" Text="{Binding Path}" Margin="4,0,0,0"/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
<Border Grid.Row="4" Background="{DynamicResource Brush.Contents}">
|
||||
<v:ChangeCollectionView ViewMode="{Binding Source={x:Static vm:Preferences.Instance}, Path=StashChangeViewMode, Mode=OneWay}"
|
||||
Changes="{Binding Changes}"
|
||||
SelectedChanges="{Binding SelectedChanges, Mode=TwoWay}"
|
||||
ContextRequested="OnChangeContextRequested"/>
|
||||
</Border>
|
||||
</Grid>
|
||||
|
||||
<GridSplitter Grid.Column="1"
|
||||
|
||||
@@ -48,10 +48,10 @@ namespace SourceGit.Views
|
||||
|
||||
private void OnChangeContextRequested(object sender, ContextRequestedEventArgs e)
|
||||
{
|
||||
if (DataContext is ViewModels.StashesPage vm && sender is Grid grid)
|
||||
if (DataContext is ViewModels.StashesPage vm && sender is ChangeCollectionView view)
|
||||
{
|
||||
var menu = vm.MakeContextMenuForChange(grid.DataContext as Models.Change);
|
||||
menu?.Open(grid);
|
||||
var menu = vm.MakeContextMenuForChange();
|
||||
menu?.Open(view);
|
||||
}
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user