Skip to content

Commit 8b1f28a

Browse files
committed
enhance: show file size change in image diff
1 parent 54ef9c0 commit 8b1f28a

File tree

3 files changed

+26
-13
lines changed

3 files changed

+26
-13
lines changed

src/Models/DiffResult.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -570,8 +570,11 @@ public class ImageDiff
570570
public Bitmap Old { get; set; } = null;
571571
public Bitmap New { get; set; } = null;
572572

573-
public string OldSize => Old != null ? $"{Old.PixelSize.Width} x {Old.PixelSize.Height}" : "0 x 0";
574-
public string NewSize => New != null ? $"{New.PixelSize.Width} x {New.PixelSize.Height}" : "0 x 0";
573+
public long OldFileSize { get; set; } = 0;
574+
public long NewFileSize { get; set; } = 0;
575+
576+
public string OldImageSize => Old != null ? $"{Old.PixelSize.Width} x {Old.PixelSize.Height}" : "0 x 0";
577+
public string NewImageSize => New != null ? $"{New.PixelSize.Width} x {New.PixelSize.Height}" : "0 x 0";
575578
}
576579

577580
public class NoOrEOLChange

src/ViewModels/DiffContext.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,19 @@ private void LoadDiffContent()
157157
var imgDiff = new Models.ImageDiff();
158158
if (_option.Revisions.Count == 2)
159159
{
160-
imgDiff.Old = BitmapFromRevisionFile(_repo, _option.Revisions[0], oldPath);
161-
imgDiff.New = BitmapFromRevisionFile(_repo, _option.Revisions[1], oldPath);
160+
(imgDiff.Old, imgDiff.OldFileSize) = BitmapFromRevisionFile(_repo, _option.Revisions[0], oldPath);
161+
(imgDiff.New, imgDiff.NewFileSize) = BitmapFromRevisionFile(_repo, _option.Revisions[1], oldPath);
162162
}
163163
else
164164
{
165165
var fullPath = Path.Combine(_repo, _option.Path);
166-
imgDiff.Old = BitmapFromRevisionFile(_repo, "HEAD", oldPath);
167-
imgDiff.New = File.Exists(fullPath) ? new Bitmap(fullPath) : null;
166+
(imgDiff.Old, imgDiff.OldFileSize) = BitmapFromRevisionFile(_repo, "HEAD", oldPath);
167+
168+
if (File.Exists(fullPath))
169+
{
170+
imgDiff.New = new Bitmap(fullPath);
171+
imgDiff.NewFileSize = new FileInfo(fullPath).Length;
172+
}
168173
}
169174
rs = imgDiff;
170175
}
@@ -207,10 +212,11 @@ private void LoadDiffContent()
207212
});
208213
}
209214

210-
private Bitmap BitmapFromRevisionFile(string repo, string revision, string file)
215+
private (Bitmap, long) BitmapFromRevisionFile(string repo, string revision, string file)
211216
{
212217
var stream = Commands.QueryFileContent.Run(repo, revision, file);
213-
return stream.Length > 0 ? new Bitmap(stream) : null;
218+
var size = stream.Length;
219+
return size > 0 ? (new Bitmap(stream), size) : (null, size);
214220
}
215221

216222
private static readonly HashSet<string> IMG_EXTS = new HashSet<string>()

src/Views/DiffView.axaml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,18 +177,22 @@
177177
<!-- Image Diff -->
178178
<DataTemplate DataType="m:ImageDiff">
179179
<Grid RowDefinitions="Auto,*,Auto" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="8,8,8,0">
180-
<Grid Grid.Row="0" ColumnDefinitions="Auto,Auto,*,Auto,Auto">
181-
<Border Grid.Column="0" Height="16" Background="{DynamicResource Brush.Badge}" CornerRadius="8" VerticalAlignment="Center">
180+
<Grid Grid.Row="0" RowDefinitions="24,24" ColumnDefinitions="Auto,Auto,Auto,Auto">
181+
<Border Grid.Row="0" Grid.Column="0" Height="16" Background="{DynamicResource Brush.Badge}" CornerRadius="8" VerticalAlignment="Center">
182182
<TextBlock Classes="monospace" Text="{DynamicResource Text.Diff.Binary.Old}" Margin="8,0" FontSize="10"/>
183183
</Border>
184184

185-
<TextBlock Grid.Column="1" Classes="monospace" Text="{Binding OldSize}" Foreground="{DynamicResource Brush.FG2}" Margin="8,0,0,0"/>
185+
<TextBlock Grid.Row="0" Grid.Column="1" Classes="monospace" Text="{Binding OldImageSize}" Margin="8,0,0,0"/>
186+
<TextBlock Grid.Row="0" Grid.Column="2" Classes="monospace" Text="{Binding OldFileSize}" Foreground="{DynamicResource Brush.FG2}" Margin="16,0,0,0" HorizontalAlignment="Right"/>
187+
<TextBlock Grid.Row="0" Grid.Column="3" Classes="monospace" Text="{DynamicResource Text.Bytes}" Foreground="{DynamicResource Brush.FG2}" Margin="2,0,0,0"/>
186188

187-
<Border Grid.Column="3" Height="16" Background="Green" CornerRadius="8" VerticalAlignment="Center" Margin="32,0,0,0">
189+
<Border Grid.Row="1" Grid.Column="0" Height="16" Background="Green" CornerRadius="8" VerticalAlignment="Center">
188190
<TextBlock Classes="monospace" Text="{DynamicResource Text.Diff.Binary.New}" Margin="8,0" FontSize="10"/>
189191
</Border>
190192

191-
<TextBlock Grid.Column="4" Classes="monospace" Text="{Binding NewSize}" Foreground="{DynamicResource Brush.FG2}" Margin="8,0,0,0"/>
193+
<TextBlock Grid.Row="1" Grid.Column="1" Classes="monospace" Text="{Binding NewImageSize}" Margin="8,0,0,0"/>
194+
<TextBlock Grid.Row="1" Grid.Column="2" Classes="monospace" Text="{Binding NewFileSize}" Foreground="{DynamicResource Brush.FG2}" Margin="16,0,0,0" HorizontalAlignment="Right"/>
195+
<TextBlock Grid.Row="1" Grid.Column="3" Classes="monospace" Text="{DynamicResource Text.Bytes}" Foreground="{DynamicResource Brush.FG2}" Margin="2,0,0,0"/>
192196
</Grid>
193197

194198
<Border Grid.Row="1" Background="{DynamicResource Brush.Window}" Effect="drop-shadow(0 0 8 #A0000000)" Margin="0,8,0,0" HorizontalAlignment="Center">

0 commit comments

Comments
 (0)