Skip to content

Commit c499978

Browse files
committed
feature: supports to switch change display mode in STASHES page (#1504)
Signed-off-by: leo <[email protected]>
1 parent 92ab85b commit c499978

File tree

4 files changed

+36
-46
lines changed

4 files changed

+36
-46
lines changed

src/ViewModels/Preferences.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,12 @@ public Models.ChangeViewMode CommitChangeViewMode
285285
set => SetProperty(ref _commitChangeViewMode, value);
286286
}
287287

288+
public Models.ChangeViewMode StashChangeViewMode
289+
{
290+
get => _stashChangeViewMode;
291+
set => SetProperty(ref _stashChangeViewMode, value);
292+
}
293+
288294
public string GitInstallPath
289295
{
290296
get => Native.OS.GitExecutable;
@@ -692,6 +698,7 @@ private bool RemoveInvalidRepositoriesRecursive(List<RepositoryNode> collection)
692698
private Models.ChangeViewMode _unstagedChangeViewMode = Models.ChangeViewMode.List;
693699
private Models.ChangeViewMode _stagedChangeViewMode = Models.ChangeViewMode.List;
694700
private Models.ChangeViewMode _commitChangeViewMode = Models.ChangeViewMode.List;
701+
private Models.ChangeViewMode _stashChangeViewMode = Models.ChangeViewMode.List;
695702

696703
private string _gitDefaultCloneDir = string.Empty;
697704

src/ViewModels/StashesPage.cs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,23 +93,23 @@ public List<Models.Change> Changes
9393
private set
9494
{
9595
if (SetProperty(ref _changes, value))
96-
SelectedChange = value is { Count: > 0 } ? value[0] : null;
96+
SelectedChanges = value is { Count: > 0 } ? [value[0]] : [];
9797
}
9898
}
9999

100-
public Models.Change SelectedChange
100+
public List<Models.Change> SelectedChanges
101101
{
102-
get => _selectedChange;
102+
get => _selectedChanges;
103103
set
104104
{
105-
if (SetProperty(ref _selectedChange, value))
105+
if (SetProperty(ref _selectedChanges, value))
106106
{
107-
if (value == null)
107+
if (value is not { Count: 1 })
108108
DiffContext = null;
109-
else if (_untracked.Contains(value))
110-
DiffContext = new DiffContext(_repo.FullPath, new Models.DiffOption(Models.Commit.EmptyTreeSHA1, _selectedStash.Parents[2], value), _diffContext);
109+
else if (_untracked.Contains(value[0]))
110+
DiffContext = new DiffContext(_repo.FullPath, new Models.DiffOption(Models.Commit.EmptyTreeSHA1, _selectedStash.Parents[2], value[0]), _diffContext);
111111
else
112-
DiffContext = new DiffContext(_repo.FullPath, new Models.DiffOption(_selectedStash.Parents[0], _selectedStash.SHA, value), _diffContext);
112+
DiffContext = new DiffContext(_repo.FullPath, new Models.DiffOption(_selectedStash.Parents[0], _selectedStash.SHA, value[0]), _diffContext);
113113
}
114114
}
115115
}
@@ -129,11 +129,11 @@ public void Dispose()
129129
{
130130
_stashes?.Clear();
131131
_changes?.Clear();
132+
_selectedChanges?.Clear();
132133
_untracked.Clear();
133134

134135
_repo = null;
135136
_selectedStash = null;
136-
_selectedChange = null;
137137
_diffContext = null;
138138
}
139139

@@ -217,11 +217,12 @@ public ContextMenu MakeContextMenu(Models.Stash stash)
217217
return menu;
218218
}
219219

220-
public ContextMenu MakeContextMenuForChange(Models.Change change)
220+
public ContextMenu MakeContextMenuForChange()
221221
{
222-
if (change == null)
222+
if (_selectedChanges is not { Count: 1 })
223223
return null;
224224

225+
var change = _selectedChanges[0];
225226
var diffWithMerger = new MenuItem();
226227
diffWithMerger.Header = App.Text("DiffWithMerger");
227228
diffWithMerger.Icon = App.CreateMenuIcon("Icons.OpenWith");
@@ -339,7 +340,7 @@ private void RefreshVisible()
339340
private Models.Stash _selectedStash = null;
340341
private List<Models.Change> _changes = null;
341342
private List<Models.Change> _untracked = [];
342-
private Models.Change _selectedChange = null;
343+
private List<Models.Change> _selectedChanges = [];
343344
private DiffContext _diffContext = null;
344345
}
345346
}

src/Views/StashesPage.axaml

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -109,46 +109,28 @@
109109

110110
<!-- Changes Bar -->
111111
<Border Grid.Row="3" BorderThickness="0,1" BorderBrush="{DynamicResource Brush.Border0}">
112-
<Grid ColumnDefinitions="Auto,*">
112+
<Grid ColumnDefinitions="Auto,*,Auto">
113113
<Path Grid.Column="0" Margin="8,0,0,0" Width="14" Height="14" Fill="{DynamicResource Brush.FG2}" Data="{StaticResource Icons.Changes}"/>
114114
<TextBlock Grid.Column="1" Foreground="{DynamicResource Brush.FG2}" FontWeight="Bold" Margin="4,0,0,0">
115115
<Run Text="{DynamicResource Text.Stashes.Changes}"/>
116116
<Run Text="{Binding Changes, Converter={x:Static c:ListConverters.ToCount}, Mode=OneWay}"/>
117117
</TextBlock>
118+
119+
<v:ChangeViewModeSwitcher Grid.Column="2"
120+
Width="14" Height="14"
121+
Margin="0,0,8,0"
122+
HorizontalAlignment="Right"
123+
ViewMode="{Binding Source={x:Static vm:Preferences.Instance}, Path=StashChangeViewMode, Mode=TwoWay}"/>
118124
</Grid>
119125
</Border>
120126

121127
<!-- View Changes -->
122-
<ListBox Grid.Row="4"
123-
Background="{DynamicResource Brush.Contents}"
124-
ItemsSource="{Binding Changes}"
125-
SelectedItem="{Binding SelectedChange, Mode=TwoWay}"
126-
SelectionMode="Single"
127-
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
128-
ScrollViewer.VerticalScrollBarVisibility="Auto">
129-
<ListBox.Styles>
130-
<Style Selector="ListBoxItem">
131-
<Setter Property="Margin" Value="0"/>
132-
<Setter Property="Padding" Value="0"/>
133-
<Setter Property="Height" Value="26"/>
134-
</Style>
135-
</ListBox.Styles>
136-
137-
<ListBox.ItemsPanel>
138-
<ItemsPanelTemplate>
139-
<VirtualizingStackPanel Orientation="Vertical"/>
140-
</ItemsPanelTemplate>
141-
</ListBox.ItemsPanel>
142-
143-
<ListBox.ItemTemplate>
144-
<DataTemplate DataType="m:Change">
145-
<Grid ColumnDefinitions="24,*" Background="Transparent" ContextRequested="OnChangeContextRequested">
146-
<v:ChangeStatusIcon Grid.Column="0" Width="14" Height="14" Change="{Binding}"/>
147-
<TextBlock Grid.Column="1" Classes="primary" Text="{Binding Path}" Margin="4,0,0,0"/>
148-
</Grid>
149-
</DataTemplate>
150-
</ListBox.ItemTemplate>
151-
</ListBox>
128+
<Border Grid.Row="4" Background="{DynamicResource Brush.Contents}">
129+
<v:ChangeCollectionView ViewMode="{Binding Source={x:Static vm:Preferences.Instance}, Path=StashChangeViewMode, Mode=OneWay}"
130+
Changes="{Binding Changes}"
131+
SelectedChanges="{Binding SelectedChanges, Mode=TwoWay}"
132+
ContextRequested="OnChangeContextRequested"/>
133+
</Border>
152134
</Grid>
153135

154136
<GridSplitter Grid.Column="1"

src/Views/StashesPage.axaml.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ private void OnStashContextRequested(object sender, ContextRequestedEventArgs e)
4848

4949
private void OnChangeContextRequested(object sender, ContextRequestedEventArgs e)
5050
{
51-
if (DataContext is ViewModels.StashesPage vm && sender is Grid grid)
51+
if (DataContext is ViewModels.StashesPage vm && sender is ChangeCollectionView view)
5252
{
53-
var menu = vm.MakeContextMenuForChange(grid.DataContext as Models.Change);
54-
menu?.Open(grid);
53+
var menu = vm.MakeContextMenuForChange();
54+
menu?.Open(view);
5555
}
5656
e.Handled = true;
5757
}

0 commit comments

Comments
 (0)