Skip to content

Commit

Permalink
Dropdown input selectedIndex fix, refactor, misc.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben2776 committed Sep 20, 2024
1 parent a63e306 commit 2d908a2
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 54 deletions.
6 changes: 2 additions & 4 deletions src/PicView.Avalonia/FileSystem/FilePickerHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@ public static class FilePickerHelper
{
Title = $"{TranslationHelper.Translation.OpenFileDialog} - PicView",
AllowMultiple = false,
FileTypeFilter = new[] { AllFileType, FilePickerFileTypes.ImageAll, ArchiveFileType }
FileTypeFilter = [AllFileType, FilePickerFileTypes.ImageAll, ArchiveFileType]
};
IReadOnlyList<IStorageFile> files;
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
files = await provider.OpenFilePickerAsync(new FilePickerOpenOptions
{
});
files = await provider.OpenFilePickerAsync(new FilePickerOpenOptions());
}
else
{
Expand Down
1 change: 1 addition & 0 deletions src/PicView.Avalonia/Navigation/Slideshow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ private static bool InitiateAndStart(MainViewModel vm)
_timer.Elapsed += async (_, _) =>
{
// TODO: add animation
// E.g. https://codepen.io/arrive/pen/EOGyzK
await vm.ImageIterator.NextIteration(NavigateTo.Next);
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/PicView.Avalonia/UI/FunctionsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ public static async Task Open()
}

var path = RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? file.Path.AbsolutePath : file.Path.LocalPath;
_ = Task.Run(() => NavigationHelper.LoadPicFromStringAsync(path, Vm));
await Task.Run(() => NavigationHelper.LoadPicFromStringAsync(path, Vm));
}

public static Task OpenWith()
Expand Down
36 changes: 0 additions & 36 deletions src/PicView.Avalonia/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -635,42 +635,6 @@ public bool IsAutoFit
set => this.RaiseAndSetIfChanged(ref _isAutoFit, value);
}

private bool _isCtrlToZoomEnabled = SettingsHelper.Settings.Zoom.CtrlZoom;

public bool IsCtrlToZoomEnabled
{
get => _isCtrlToZoomEnabled;
set
{
this.RaiseAndSetIfChanged(ref _isCtrlToZoomEnabled, value);
SettingsHelper.Settings.Zoom.CtrlZoom = value;
}
}

private bool _isNavigatingInReverse = SettingsHelper.Settings.Zoom.HorizontalReverseScroll;

public bool IsNavigatingInReverse
{
get => _isNavigatingInReverse;
set
{
this.RaiseAndSetIfChanged(ref _isNavigatingInReverse, value);
SettingsHelper.Settings.Zoom.HorizontalReverseScroll = value;
}
}

private bool _isOpeningLastFileOnStartup = SettingsHelper.Settings.StartUp.OpenLastFile;

public bool IsOpeningLastFileOnStartup
{
get => _isOpeningLastFileOnStartup;
set
{
this.RaiseAndSetIfChanged(ref _isOpeningLastFileOnStartup, value);
SettingsHelper.Settings.StartUp.OpenLastFile = value;
}
}

private bool _isStayingCentered = SettingsHelper.Settings.WindowProperties.KeepCentered;

public bool IsStayingCentered
Expand Down
12 changes: 4 additions & 8 deletions src/PicView.Avalonia/Views/GeneralSettingsView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
Padding="5,7,0,7"
Width="270"
x:Name="MouseWheelBox">
<ComboBoxItem Content="{CompiledBinding CtrlToZoom, Mode=OneWay}" IsSelected="{CompiledBinding IsCtrlToZoomEnabled}" />
<ComboBoxItem Content="{CompiledBinding CtrlToZoom, Mode=OneWay}" />
<ComboBoxItem Content="{CompiledBinding ScrollToZoom, Mode=OneWay}" />
</ComboBox>

Expand All @@ -164,12 +164,8 @@
Padding="5,7,0,7"
Width="270"
x:Name="ScrollDirectionBox">
<ComboBoxItem
Content="{CompiledBinding Reverse,
Mode=OneWay}"
IsSelected="{CompiledBinding IsNavigatingInReverse}"
x:Name="ReverseDirectionBoxItem" />
<ComboBoxItem Content="{CompiledBinding Forward, Mode=OneWay}" x:Name="ForwardDirectionBoxItem" />
<ComboBoxItem Content="{CompiledBinding Reverse, Mode=OneWay}" />
<ComboBoxItem Content="{CompiledBinding Forward, Mode=OneWay}" />
</ComboBox>

<TextBlock
Expand All @@ -190,7 +186,7 @@
Width="270"
x:Name="ApplicationStartupBox">
<ComboBoxItem Content="{CompiledBinding None, Mode=OneWay}" />
<ComboBoxItem Content="{CompiledBinding OpenLastFile, Mode=OneWay}" IsSelected="{CompiledBinding IsOpeningLastFileOnStartup}" />
<ComboBoxItem Content="{CompiledBinding OpenLastFile, Mode=OneWay}" />
</ComboBox>

<TextBlock
Expand Down
22 changes: 19 additions & 3 deletions src/PicView.Avalonia/Views/GeneralSettingsView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,16 @@ public GeneralSettingsView()
InitializeComponent();
Loaded += delegate
{
MouseWheelBox.SelectedIndex = SettingsHelper.Settings.Zoom.CtrlZoom ? 0 : 1;
ScrollDirectionBox.SelectedIndex = SettingsHelper.Settings.Zoom.HorizontalReverseScroll ? 0 : 1;
ApplicationStartupBox.SelectedIndex = SettingsHelper.Settings.StartUp.OpenLastFile ? 1 : 0;

ApplicationStartupBox.SelectionChanged += async delegate
{
if (ApplicationStartupBox.SelectedIndex == -1)
{
return;
}
SettingsHelper.Settings.StartUp.OpenLastFile = ApplicationStartupBox.SelectedIndex == 1;
await SettingsHelper.SaveSettingsAsync();
};
Expand All @@ -27,8 +35,13 @@ public GeneralSettingsView()
ApplicationStartupBox.SelectedIndex = SettingsHelper.Settings.StartUp.OpenLastFile ? 0 : 1;
}
};

MouseWheelBox.SelectionChanged += async delegate
{
if (MouseWheelBox.SelectedIndex == -1)
{
return;
}
SettingsHelper.Settings.Zoom.CtrlZoom = MouseWheelBox.SelectedIndex == 0;
await SettingsHelper.SaveSettingsAsync();
};
Expand All @@ -39,8 +52,13 @@ public GeneralSettingsView()
MouseWheelBox.SelectedIndex = SettingsHelper.Settings.Zoom.CtrlZoom ? 0 : 1;
}
};

ScrollDirectionBox.SelectionChanged += async delegate
{
if (ScrollDirectionBox.SelectedIndex == -1)
{
return;
}
SettingsHelper.Settings.Zoom.HorizontalReverseScroll = ScrollDirectionBox.SelectedIndex == 0;
await SettingsHelper.SaveSettingsAsync();
};
Expand All @@ -51,9 +69,7 @@ public GeneralSettingsView()
ScrollDirectionBox.SelectedIndex = SettingsHelper.Settings.Zoom.HorizontalReverseScroll ? 0 : 1;
}
};
MouseWheelBox.SelectedIndex = SettingsHelper.Settings.Zoom.CtrlZoom ? 0 : 1;
ScrollDirectionBox.SelectedIndex = SettingsHelper.Settings.Zoom.HorizontalReverseScroll ? 0 : 1;
ApplicationStartupBox.SelectedIndex = SettingsHelper.Settings.StartUp.OpenLastFile ? 1 : 0;


var languages = TranslationHelper.GetLanguages().OrderBy(x => x);
foreach (var language in languages)
Expand Down
4 changes: 2 additions & 2 deletions src/PicView.Core/ImageDecoding/EXIFHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ public static string GetExifVersion(IExifProfile? profile)
return exifVersion is null ? string.Empty : Encoding.ASCII.GetString(exifVersion);
}

public static string? GetTitle(IExifProfile? profile)
public static string GetTitle(IExifProfile? profile)
{
var xPTitle = profile?.GetValue(ExifTag.XPTitle)?.Value;
var title = xPTitle is null ? string.Empty : Encoding.ASCII.GetString(xPTitle);
Expand All @@ -470,7 +470,7 @@ public static string GetExifVersion(IExifProfile? profile)
return titleTag ?? string.Empty;
}

public static string? GetSubject(IExifProfile? profile)
public static string GetSubject(IExifProfile? profile)
{
var xPSubject = profile?.GetValue(ExifTag.XPSubject)?.Value;
var subject = xPSubject is null ? string.Empty : Encoding.ASCII.GetString(xPSubject);
Expand Down

0 comments on commit 2d908a2

Please sign in to comment.