Skip to content

Commit 6be9770

Browse files
committed
refactor: remove default initialization for boolean fields and improve config serialization
1 parent c5f3bc6 commit 6be9770

File tree

3 files changed

+10
-13
lines changed

3 files changed

+10
-13
lines changed

Config.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@ namespace X4LogWatcher
1212
public class Config : INotifyPropertyChanged
1313
{
1414
private static readonly int MaxRecentProfiles = 5;
15-
private bool _isSaving = false; // Flag to prevent recursive saves
15+
private bool _isSaving; // Flag to prevent recursive saves
1616

1717
// Backing fields for properties
1818
private ObservableCollection<string> _recentProfiles = new ObservableCollection<string>();
1919
private string? _activeProfile;
2020
private string? _lastLogFolderPath;
2121
private string _logFileExtension = ".log";
2222
private bool _skipSignatureErrors = true;
23-
private bool _realTimeStamping = false;
23+
private bool _realTimeStamping;
24+
private JsonSerializerOptions _jsonSerializerOptions = new JsonSerializerOptions { WriteIndented = true };
2425

2526
// Properties with notification
2627
public ObservableCollection<string> RecentProfiles
@@ -88,7 +89,7 @@ public static void SaveConfig(Config config)
8889
};
8990

9091
// Serialize the config to JSON and write to file
91-
string jsonConfig = JsonSerializer.Serialize(configToSave, new JsonSerializerOptions { WriteIndented = true });
92+
string jsonConfig = JsonSerializer.Serialize(configToSave, config._jsonSerializerOptions);
9293
File.WriteAllText(configPath, jsonConfig);
9394
}
9495
catch (Exception ex)
@@ -156,11 +157,8 @@ public void AddRecentProfile(string profilePath)
156157

157158
try
158159
{
159-
// Remove the profile if it already exists
160-
if (RecentProfiles.Contains(profilePath))
161-
{
162-
RecentProfiles.Remove(profilePath);
163-
}
160+
// Remove the profile if it already exists (Remove returns true if found and removed)
161+
RecentProfiles.Remove(profilePath);
164162

165163
// Add the profile to the beginning of the list
166164
RecentProfiles.Insert(0, profilePath);

MenuAutoTabsHandlers.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,12 @@ private void MenuAutoTabs_Click(object sender, RoutedEventArgs e)
2323
{
2424
// Add the configs to the menu
2525
foreach (var config in autoTabConfigs)
26-
{
27-
// Create a display name that includes regex pattern details
26+
{ // Create a display name that includes regex pattern details
2827
string configName = config.PatternRegex;
2928

3029
if (configName.Length > 80)
3130
{
32-
configName = configName.Substring(0, 77) + "...";
31+
configName = string.Concat(configName.AsSpan(0, 77), "...");
3332
}
3433

3534
var configMenuItem = new MenuItem { Header = configName, Tag = config };

TabInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class TabInfo : INotifyPropertyChanged, IDisposable
1717
{
1818
public event PropertyChangedEventHandler? PropertyChanged;
1919

20-
private bool _disposed = false;
20+
private bool _disposed;
2121

2222
private string _regexPattern = string.Empty;
2323
public string RegexPattern
@@ -416,7 +416,7 @@ private bool IsUserAtBottom()
416416
/// <summary>
417417
/// Finds the ScrollViewer inside a control using visual tree walking
418418
/// </summary>
419-
private ScrollViewer? FindScrollViewer(DependencyObject parent)
419+
private static ScrollViewer? FindScrollViewer(DependencyObject parent)
420420
{
421421
if (parent == null)
422422
return null;

0 commit comments

Comments
 (0)