Skip to content

Commit ac60cb5

Browse files
committed
general cleanup
1 parent bb9c335 commit ac60cb5

File tree

4 files changed

+20
-15
lines changed

4 files changed

+20
-15
lines changed

Gui/Models/Converters/EnumToMaterialIconConverter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ public class EnumToMaterialIconConverter : IValueConverter
1414
return TryGetIcon(value, DatTypeMapping)
1515
?? TryGetIcon(value, ObjectMapping)
1616
?? TryGetIcon(value, VehicleMapping)
17-
?? TryGetIcon(value, SourceGameMapping);
17+
?? TryGetIcon(value, SourceGameMapping)
18+
?? "CircleSmall";
1819

1920
static string? TryGetIcon<T>(object? value, Dictionary<T, string> mapping) where T : struct
2021
{

Gui/ViewModels/FolderTreeViewModel.cs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -155,21 +155,14 @@ public static int CountNodes(FileSystemItemBase fib)
155155
{
156156
if (fib.SubNodes == null || fib.SubNodes.Count == 0)
157157
{
158-
return 0;
158+
return 1;
159159
}
160160

161161
var count = 0;
162162

163163
foreach (var node in fib.SubNodes)
164164
{
165-
if (node is FileSystemItemBase)
166-
{
167-
count++;
168-
}
169-
else
170-
{
171-
count += CountNodes(node);
172-
}
165+
count += CountNodes(node);
173166
}
174167

175168
return count;
@@ -238,7 +231,7 @@ void UpdateGrid(List<FileSystemItemBase> items)
238231
}),
239232
x => x.SubNodes),
240233

241-
new TextColumn<FileSystemItemBase, ObjectSource?>("Source", x => x.ObjectSource),
234+
new TextColumn<FileSystemItemBase, string?>("Source", x => GetNiceObjectSource(x.ObjectSource)),
242235
new TextColumn<FileSystemItemBase, FileLocation?>("Origin", x => x.FileLocation),
243236
new TextColumn<FileSystemItemBase, string?>("Location", x => x.Filename),
244237
new TextColumn<FileSystemItemBase, DateTimeOffset?>("Created", x => x.CreatedDate),
@@ -249,7 +242,18 @@ void UpdateGrid(List<FileSystemItemBase> items)
249242
TreeDataGridSource.RowSelection!.SelectionChanged += SelectionChanged;
250243

251244
this.RaisePropertyChanged(nameof(TreeDataGridSource));
245+
252246
}
247+
string GetNiceObjectSource(ObjectSource? os)
248+
=> os switch
249+
{
250+
ObjectSource.Custom => "Custom",
251+
ObjectSource.LocomotionSteam => "Steam",
252+
ObjectSource.LocomotionGoG => "GoG",
253+
ObjectSource.OpenLoco => "OpenLoco",
254+
null => string.Empty,
255+
_ => throw new NotImplementedException(),
256+
};
253257

254258
void SelectionChanged(object? sender, TreeSelectionModelSelectionChangedEventArgs<FileSystemItemBase> e)
255259
{

Gui/ViewModels/MainWindowViewModel.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ public MainWindowViewModel()
9494
_ = FolderTreeViewModel.WhenAnyValue(o => o.CurrentlySelectedObject)
9595
.Subscribe((x) =>
9696
{
97-
if (x is FileSystemItemBase fsi && fsi?.SubNodes?.Count == 0)
97+
if (x != null && (x.SubNodes == null || x.SubNodes?.Count == 0))
9898
{
99-
SetObjectViewModel(fsi);
99+
SetObjectViewModel(x);
100100
}
101101
});
102102

@@ -234,7 +234,7 @@ public async Task LoadSingleObject()
234234
}
235235
}
236236

237-
void SetObjectViewModel(FileSystemItemObject fsi)
237+
void SetObjectViewModel(FileSystemItemBase fsi)
238238
{
239239
if (fsi != null && !CurrentTabModel.DocumentExistsWithFile(fsi))
240240
{

Gui/ViewModels/TabViewPageViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ void ClearDocumentsExcept(ILocoFileViewModel tabToKeep)
8080
Documents.Add(tabToKeep);
8181
}
8282

83-
public bool DocumentExistsWithFile(FileSystemItem fsi)
83+
public bool DocumentExistsWithFile(FileSystemItemBase fsi)
8484
=> Documents.Any(x => x.CurrentFile == fsi);
8585
}
8686
}

0 commit comments

Comments
 (0)