Skip to content

Commit 0f64846

Browse files
committed
New option: display file sizes in bytes, otherwise added a decimal
1 parent 32e4ec2 commit 0f64846

File tree

4 files changed

+37
-3
lines changed

4 files changed

+37
-3
lines changed

MiniWebCompiler/IAppSettings.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,11 @@ public interface IAppSettings : ISettings
6666
/// Gets or sets the default value of the KeepUnminifiedFiles property for new projects.
6767
/// </summary>
6868
bool KeepUnminifiedFilesDefault { get; set; }
69+
70+
/// <summary>
71+
/// Gets or sets a value indicating whether the compressed file sizes are displayed in bytes
72+
/// instead of B/KiB/MiB.
73+
/// </summary>
74+
bool FileSizesInBytes { get; set; }
6975
}
7076
}

MiniWebCompiler/ViewModels/MainViewModel.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,22 @@ public MainViewModel()
4242
}
4343
SortProjects();
4444
UpdateStatus();
45+
46+
App.Settings.PropertyChanged += Settings_PropertyChanged;
47+
}
48+
}
49+
50+
private void Settings_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs args)
51+
{
52+
if (args.PropertyName == nameof(IAppSettings.FileSizesInBytes))
53+
{
54+
foreach (var project in Projects)
55+
{
56+
foreach (var projectFile in project.Files)
57+
{
58+
projectFile.UpdateCompressedResultSizeStr();
59+
}
60+
}
4561
}
4662
}
4763

MiniWebCompiler/ViewModels/ProjectFile.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,27 @@ public string CompressedResultSizeStr
7575
{
7676
if (CompressedResultSize < 0)
7777
return "";
78-
if (CompressedResultSize < 1024)
79-
return $"{CompressedResultSize} B";
78+
if (CompressedResultSize < 1024 || App.Settings.FileSizesInBytes)
79+
return $"{CompressedResultSize:#,##0} B";
8080
if (CompressedResultSize < 1024 * 10)
81+
return $"{(double)CompressedResultSize / 1024:0.00} KiB";
82+
if (CompressedResultSize < 1024 * 100)
8183
return $"{(double)CompressedResultSize / 1024:0.0} KiB";
8284
if (CompressedResultSize < 1024 * 1024)
8385
return $"{(double)CompressedResultSize / 1024:0} KiB";
8486
if (CompressedResultSize < 1024 * 1024 * 10)
87+
return $"{(double)CompressedResultSize / 1024 / 1024:0.00} MiB";
88+
if (CompressedResultSize < 1024 * 1024 * 100)
8589
return $"{(double)CompressedResultSize / 1024 / 1024:0.0} MiB";
8690
return $"{(double)CompressedResultSize / 1024 / 1024:0} MiB";
8791
}
8892
}
8993

94+
public void UpdateCompressedResultSizeStr()
95+
{
96+
OnPropertyChanged(nameof(CompressedResultSizeStr));
97+
}
98+
9099
#endregion Properties
91100

92101
#region Commands

MiniWebCompiler/Views/SettingsWindow.xaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<RowDefinition Height="Auto"/>
1919
<RowDefinition Height="Auto"/>
2020
<RowDefinition Height="Auto"/>
21+
<RowDefinition Height="Auto"/>
2122
</Grid.RowDefinitions>
2223

2324
<CheckBox Grid.Row="0" IsChecked="{Binding Settings.AskOnWindowClose}" Content="Ask on window close"/>
@@ -30,6 +31,8 @@
3031

3132
<CheckBox Grid.Row="4" Margin="0,2,0,0" IsChecked="{Binding Settings.KeepUnminifiedFilesDefault}" Content="Keep unminified files default"/>
3233

33-
<Button Grid.Row="5" Margin="0,20,0,0" HorizontalAlignment="Right" MinWidth="75" Content="Close" Click="CloseButton_Click"/>
34+
<CheckBox Grid.Row="5" Margin="0,2,0,0" IsChecked="{Binding Settings.FileSizesInBytes}" Content="Always display file sizes in bytes"/>
35+
36+
<Button Grid.Row="6" Margin="0,20,0,0" HorizontalAlignment="Right" MinWidth="75" Content="Close" Click="CloseButton_Click"/>
3437
</Grid>
3538
</Window>

0 commit comments

Comments
 (0)