Skip to content

Commit

Permalink
Add error checks, miscellaneous checks, etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben2776 committed Nov 7, 2024
1 parent a40420e commit c7d6809
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 14 deletions.
1 change: 0 additions & 1 deletion src/PicView.Avalonia/CustomControls/PicBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,6 @@ private void RenderImage(DrawingContext context, IImage source, Rect viewPort, S
{
#if DEBUG
Console.WriteLine(e);
TooltipHelper.ShowTooltipMessage(e, true);
#endif
}
}
Expand Down
16 changes: 12 additions & 4 deletions src/PicView.Avalonia/Navigation/Preloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,17 @@ public async Task<bool> RefreshFileInfo(int index, List<string> list)
}

var removed = _preLoadList.TryRemove(index, out var preLoadValue);
if (preLoadValue is not null)
if (preLoadValue is null)
{
return removed;
}

if (preLoadValue.ImageModel != null)
{
preLoadValue.ImageModel.FileInfo = null;
await AddAsync(index, list, preLoadValue.ImageModel).ConfigureAwait(false);
}


await AddAsync(index, list, preLoadValue.ImageModel).ConfigureAwait(false);
return removed;
}

Expand All @@ -134,7 +139,10 @@ public void RefreshAllFileInfo(List<string> list)
{
if (item.Value is null) continue;
var fileInfo = new FileInfo(list[item.Key]);
item.Value.ImageModel.FileInfo = fileInfo;
if (item.Value.ImageModel != null)
{
item.Value.ImageModel.FileInfo = fileInfo;
}
}
}

Expand Down
27 changes: 18 additions & 9 deletions src/PicView.Avalonia/Views/SingleImageResizeView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,27 @@ private void SetIsQualitySliderEnabled()
return;
}

if (JpgItem.IsSelected)
try
{
QualitySlider.IsEnabled = true;
}
else if (vm.FileInfo.Extension.Equals(".jpg", StringComparison.OrdinalIgnoreCase) ||
vm.FileInfo.Extension.Equals(".jpeg", StringComparison.OrdinalIgnoreCase))
{
QualitySlider.IsEnabled = true;
if (JpgItem.IsSelected)
{
QualitySlider.IsEnabled = true;
}
else if (vm.FileInfo.Extension.Equals(".jpg", StringComparison.OrdinalIgnoreCase) ||
vm.FileInfo.Extension.Equals(".jpeg", StringComparison.OrdinalIgnoreCase))
{
QualitySlider.IsEnabled = true;
}
else
{
QualitySlider.IsEnabled = false;
}
}
else
catch (Exception e)
{
QualitySlider.IsEnabled = false;
#if DEBUG
Console.WriteLine(e);
#endif
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/PicView.Avalonia/Views/UC/EditableTitlebar.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ protected override void OnKeyUp(KeyEventArgs e)

private async Task HandleRename()
{
// TODO Add to a separate helper class

if (DataContext is not MainViewModel vm)
{
return;
Expand All @@ -120,7 +122,11 @@ private async Task HandleRename()

if (File.Exists(newPath))
{
CloseTitlebar();
vm.IsLoading = false;
// Show error message to user
// TODO Translate error message
await TooltipHelper.ShowTooltipMessageAsync(TranslationHelper.GetTranslation("FileAlreadyExistsError"), true);
return;
}

Expand Down

0 comments on commit c7d6809

Please sign in to comment.