Skip to content

Commit

Permalink
Request for hotkeys for skipping +/-10 images and +/-100 images #172
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben2776 committed Oct 25, 2024
1 parent 0059ff8 commit eb7f143
Show file tree
Hide file tree
Showing 18 changed files with 241 additions and 23 deletions.
40 changes: 25 additions & 15 deletions src/PicView.Avalonia/Navigation/ImageIterator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -389,10 +389,17 @@ public async Task QuickReload()
await IterateToIndex(CurrentIndex).ConfigureAwait(false);
}

public int GetIteration(int index, NavigateTo navigateTo, bool skip1 = false)
public int GetIteration(int index, NavigateTo navigateTo, bool skip1 = false, bool skip10 = false, bool skip100 = false)
{
int next;
var skipAmount = skip1 ? 2 : 1;

if (skip100)
{
PreLoader.Clear();
}

// Determine skipAmount based on input flags
var skipAmount = skip100 ? 100 : skip10 ? 10 : skip1 ? 2 : 1;

switch (navigateTo)
{
Expand All @@ -403,26 +410,18 @@ public int GetIteration(int index, NavigateTo navigateTo, bool skip1 = false)

if (SettingsHelper.Settings.UIProperties.Looping)
{
// Calculate new index with looping
next = (index + indexChange + ImagePaths.Count) % ImagePaths.Count;
}
else
{
// Calculate new index without looping and ensure bounds
var newIndex = index + indexChange;

// Ensure the new index doesn't go out of bounds
if (newIndex < 0)
{
return 0;
}

if (newIndex >= ImagePaths.Count)
{
return ImagePaths.Count - 1;
}
if (newIndex < 0) return 0;
if (newIndex >= ImagePaths.Count) return ImagePaths.Count - 1;

next = newIndex;
}

break;

case NavigateTo.First:
Expand All @@ -431,7 +430,6 @@ public int GetIteration(int index, NavigateTo navigateTo, bool skip1 = false)
{
PreLoader.Clear();
}

next = navigateTo == NavigateTo.First ? 0 : ImagePaths.Count - 1;
break;

Expand Down Expand Up @@ -459,6 +457,18 @@ public async Task NextIteration(NavigateTo navigateTo)
await TimerIteration(index);
}
}

public async Task Next10Iteration(bool forwards)
{
var index = GetIteration(CurrentIndex, forwards ? NavigateTo.Next : NavigateTo.Previous, false, true);
await IterateToIndex(index).ConfigureAwait(false);
}

public async Task Next100Iteration(bool forwards)
{
var index = GetIteration(CurrentIndex, forwards ? NavigateTo.Next : NavigateTo.Previous, false, false, true);
await IterateToIndex(index).ConfigureAwait(false);
}

public async Task IterateToIndex(int index)
{
Expand Down
25 changes: 25 additions & 0 deletions src/PicView.Avalonia/UI/FunctionsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public static Task<Func<Task>> GetFunctionByName(string functionName)
"Down" => Down,
"Last" => Last,
"First" => First,
"Next10" => Next10,
"Prev10" => Prev10,
"Next100" => Next100,
"Prev100" => Prev100,

// Rotate
"RotateLeft" => RotateLeft,
Expand Down Expand Up @@ -227,6 +231,27 @@ public static async Task First()
{
await NavigationHelper.NavigateFirstOrLast(last: false, Vm);
}

public static async Task Next10()
{
await Vm?.ImageIterator.Next10Iteration(true);
}

public static async Task Next100()
{
await Vm?.ImageIterator.Next100Iteration(true);
}

public static async Task Prev10()
{
await Vm?.ImageIterator.Next10Iteration(false);
}

public static async Task Prev100()
{
await Vm?.ImageIterator.Next100Iteration(false);
}


public static async Task Up()
{
Expand Down
4 changes: 4 additions & 0 deletions src/PicView.Avalonia/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,10 @@ public bool IsFillSquareMenuChecked
public ReactiveCommand<Unit, Unit>? PreviousFolderCommand { get; }
public ReactiveCommand<Unit, Unit>? FirstCommand { get; }
public ReactiveCommand<Unit, Unit>? LastCommand { get; }
public ReactiveCommand<Unit, Unit>? Skip10Command { get; }
public ReactiveCommand<Unit, Unit>? Prev10Command { get; }
public ReactiveCommand<Unit, Unit>? Skip100Command { get; }
public ReactiveCommand<Unit, Unit>? Prev100Command { get; }
public ReactiveCommand<Unit, Unit>? OpenFileCommand { get; }
public ReactiveCommand<Unit, Unit>? SaveFileCommand { get; }
public ReactiveCommand<Unit, Unit>? SaveFileAsCommand { get; }
Expand Down
36 changes: 36 additions & 0 deletions src/PicView.Avalonia/ViewModels/ViewModelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,46 @@ public void UpdateLanguage()
Quality = TranslationHelper.Translation.Quality;
SaveAs = TranslationHelper.Translation.SaveAs;
Reset = TranslationHelper.Translation.Reset;
AdvanceBy10Images = TranslationHelper.Translation.AdvanceBy10Images;
AdvanceBy100Images = TranslationHelper.Translation.AdvanceBy100Images;
GoBackBy10Images = TranslationHelper.Translation.GoBackBy10Images;
GoBackBy100Images = TranslationHelper.Translation.GoBackBy100Images;
}

#region Strings

private string? _advanceBy10Images;

public string? AdvanceBy10Images
{
get => _advanceBy10Images;
set => this.RaiseAndSetIfChanged(ref _advanceBy10Images, value);
}

private string? _advanceBy100Images;

public string? AdvanceBy100Images
{
get => _advanceBy100Images;
set => this.RaiseAndSetIfChanged(ref _advanceBy100Images, value);
}

private string? _goBackBy10Images;

public string? GoBackBy10Images
{
get => _goBackBy10Images;
set => this.RaiseAndSetIfChanged(ref _goBackBy10Images, value);
}

private string? _goBackBy100Images;

public string? GoBackBy100Images
{
get => _goBackBy100Images;
set => this.RaiseAndSetIfChanged(ref _goBackBy100Images, value);
}

private string? _reset;

public string? Reset
Expand Down
103 changes: 97 additions & 6 deletions src/PicView.Avalonia/Views/ShortcutsView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
TextAlignment="Center"
x:Name="NavigationTextBlock" />

<!-- Next image -->
<StackPanel Margin="15,0,10,10" Orientation="Horizontal">
<TextBlock
Classes="txt"
Expand All @@ -67,46 +68,49 @@
Width="140" />
</StackPanel>

<!-- Next 10 images -->
<StackPanel Margin="15,0,10,10" Orientation="Horizontal">
<TextBlock
Classes="txt"
FontFamily="/Assets/Fonts/Roboto-Bold.ttf#Roboto"
Text="{CompiledBinding LastImage}"
Text="{CompiledBinding AdvanceBy10Images}"
Width="170" />
<customControls:KeybindTextBox
Alt="False"
Classes="hover TStyle"
MethodName="Last"
MethodName="Next10"
ToolTip.Tip="{CompiledBinding ChangeKeybindingTooltip}"
Width="140" />
<customControls:KeybindTextBox
Alt="True"
Classes="hover TStyle"
MethodName="Last"
MethodName="Next10"
ToolTip.Tip="{CompiledBinding ChangeKeybindingTooltip}"
Width="140" />
</StackPanel>

<!-- Next 100 images -->
<StackPanel Margin="15,0,10,10" Orientation="Horizontal">
<TextBlock
Classes="txt"
FontFamily="/Assets/Fonts/Roboto-Bold.ttf#Roboto"
Text="{CompiledBinding NextFolder}"
Text="{CompiledBinding AdvanceBy100Images}"
Width="170" />
<customControls:KeybindTextBox
Alt="False"
Classes="hover TStyle"
MethodName="NextFolder"
MethodName="Next100"
ToolTip.Tip="{CompiledBinding ChangeKeybindingTooltip}"
Width="140" />
<customControls:KeybindTextBox
Alt="True"
Classes="hover TStyle"
MethodName="NextFolder"
MethodName="Next100"
ToolTip.Tip="{CompiledBinding ChangeKeybindingTooltip}"
Width="140" />
</StackPanel>

<!-- Previous image -->
<StackPanel Margin="15,5,10,10" Orientation="Horizontal">
<TextBlock
Classes="txt"
Expand All @@ -126,6 +130,70 @@
Width="140" />
</StackPanel>

<!-- Previous 10 images -->
<StackPanel Margin="15,0,10,10" Orientation="Horizontal">
<TextBlock
Classes="txt"
FontFamily="/Assets/Fonts/Roboto-Bold.ttf#Roboto"
Text="{CompiledBinding GoBackBy10Images}"
Width="170" />
<customControls:KeybindTextBox
Alt="False"
Classes="hover TStyle"
MethodName="Prev10"
ToolTip.Tip="{CompiledBinding ChangeKeybindingTooltip}"
Width="140" />
<customControls:KeybindTextBox
Alt="True"
Classes="hover TStyle"
MethodName="Prev10"
ToolTip.Tip="{CompiledBinding ChangeKeybindingTooltip}"
Width="140" />
</StackPanel>

<!-- Previous 100 images -->
<StackPanel Margin="15,0,10,10" Orientation="Horizontal">
<TextBlock
Classes="txt"
FontFamily="/Assets/Fonts/Roboto-Bold.ttf#Roboto"
Text="{CompiledBinding GoBackBy100Images}"
Width="170" />
<customControls:KeybindTextBox
Alt="False"
Classes="hover TStyle"
MethodName="Prev100"
ToolTip.Tip="{CompiledBinding ChangeKeybindingTooltip}"
Width="140" />
<customControls:KeybindTextBox
Alt="True"
Classes="hover TStyle"
MethodName="Prev100"
ToolTip.Tip="{CompiledBinding ChangeKeybindingTooltip}"
Width="140" />
</StackPanel>

<!-- Last image -->
<StackPanel Margin="15,0,10,10" Orientation="Horizontal">
<TextBlock
Classes="txt"
FontFamily="/Assets/Fonts/Roboto-Bold.ttf#Roboto"
Text="{CompiledBinding LastImage}"
Width="170" />
<customControls:KeybindTextBox
Alt="False"
Classes="hover TStyle"
MethodName="Last"
ToolTip.Tip="{CompiledBinding ChangeKeybindingTooltip}"
Width="140" />
<customControls:KeybindTextBox
Alt="True"
Classes="hover TStyle"
MethodName="Last"
ToolTip.Tip="{CompiledBinding ChangeKeybindingTooltip}"
Width="140" />
</StackPanel>

<!-- First image -->
<StackPanel Margin="15,0,10,10" Orientation="Horizontal">
<TextBlock
Classes="txt"
Expand All @@ -145,6 +213,29 @@
Width="140" />
</StackPanel>

<StackPanel Margin="15,0,10,10" Orientation="Horizontal">
<TextBlock
Classes="txt"
FontFamily="/Assets/Fonts/Roboto-Bold.ttf#Roboto"
Text="{CompiledBinding NextFolder}"
Width="170" />
<customControls:KeybindTextBox
Alt="False"
Classes="hover TStyle"
MethodName="NextFolder"
ToolTip.Tip="{CompiledBinding ChangeKeybindingTooltip}"
Width="140" />
<customControls:KeybindTextBox
Alt="True"
Classes="hover TStyle"
MethodName="NextFolder"
ToolTip.Tip="{CompiledBinding ChangeKeybindingTooltip}"
Width="140" />
</StackPanel>




<StackPanel Margin="15,0,10,10" Orientation="Horizontal">
<TextBlock
Classes="txt"
Expand Down
4 changes: 4 additions & 0 deletions src/PicView.Core/Config/Languages/da.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"AdjustTimingForSlideshow": "Juster timing for slideshowet",
"AdjustTimingForZoom": "Justér zooming hastighed",
"AdjustZoomLevel": "Juster zoom niveau",
"AdvanceBy100Images": "Gå 100 billeder frem",
"AdvanceBy10Images": "Gå 10 billeder frem",
"AllowZoomOut": "Undgå at zoome ud på billedet, når det allerede er i maksimal størrelse",
"Alt": "Alt",
"Altitude": "Højde",
Expand Down Expand Up @@ -151,6 +153,8 @@
"GlassTheme": "Glas tema",
"GlassTile": "Glasflise",
"Gloom": "Gloom",
"GoBackBy100Images": "Gå 100 billeder tilbage",
"GoBackBy10Images": "Gå 10 billeder tilbage",
"GoToImageAtSpecifiedIndex": "Indlæs billede ved bestemt numerisk placering",
"Hard": "Hård",
"Height": "Højde",
Expand Down
6 changes: 5 additions & 1 deletion src/PicView.Core/Config/Languages/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"AdjustTimingForSlideshow": "Timing für Diashow anpassen",
"AdjustTimingForZoom": "Zoomgeschwindigkeit anpassen",
"AdjustZoomLevel": "Zoomstufe anpassen",
"AdvanceBy100Images": "100 Bilder vorwärts gehen",
"AdvanceBy10Images": "10 Bilder vorwärts gehen",
"AllowZoomOut": "Herauszoomen des Bildes vermeiden, wenn es bereits maximale Größe hat",
"Alt": "Alt",
"Altitude": "Höhe",
Expand Down Expand Up @@ -151,6 +153,8 @@
"GlassTheme": "Glas",
"GlassTile": "Glaskachel",
"Gloom": "Dunkelheit",
"GoBackBy100Images": "100 Bilder zurück gehen",
"GoBackBy10Images": "10 Bilder zurück gehen",
"GoToImageAtSpecifiedIndex": "Zu Bild mit angegebenen Index gehen",
"Hard": "Hart",
"Height": "Höhe",
Expand Down Expand Up @@ -280,8 +284,8 @@
"ScrollToBottom": "Zum Ende scrollen",
"ScrollToTop": "Zum Anfang scrollen",
"ScrollToZoom": "Mit Mausrad zoomen, mit Strg navigieren",
"ScrollUp": "Nach unten scrollen",
"ScrollUp": "Nach oben scrollen",
"ScrollUp": "Nach unten scrollen",
"Scrolling": "Scrollen",
"ScrollingDisabled": "Scrollen deaktiviert",
"ScrollingEnabled": "Scrollen aktiviert",
Expand Down
Loading

0 comments on commit eb7f143

Please sign in to comment.