Skip to content

Commit

Permalink
Merge pull request #195 from VPKSoft/194-move-left-righ-with-arrow-keys
Browse files Browse the repository at this point in the history
Add keyboard seeking with arrow keys
  • Loading branch information
Petteri Kautonen authored Feb 27, 2023
2 parents 90c5122 + 1ad2c3b commit cfbe991
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 19 deletions.
4 changes: 2 additions & 2 deletions EtoForms.Controls.Custom/Drawing/CellPainter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public abstract class CellPainter<T, TValue> : IDisposable
/// <exception cref="InvalidOperationException">The property name must exists within the type T.</exception>
protected CellPainter(GridView gridView, GridColumn column, Func<T, TValue?> getValueFunc)
{
this.GridView = gridView;
GridView = gridView;
if (column.DataCell is DrawableCell drawableCell)
{
cell = drawableCell;
Expand All @@ -63,7 +63,7 @@ protected CellPainter(GridView gridView, GridColumn column, Func<T, TValue?> get
column.DataCell = cell;
}

this.GridView = gridView;
GridView = gridView;
this.getValueFunc = getValueFunc;
cell.Paint += DrawableCell_Paint;
}
Expand Down
1 change: 0 additions & 1 deletion EtoForms.Controls.Custom/PositionSlider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
using EtoForms.Controls.Custom.EventArguments;
using EtoForms.Controls.Custom.Interfaces.BaseClasses;
using EtoForms.Controls.Custom.Properties;
using FluentIcons.Resources.Filled;

namespace EtoForms.Controls.Custom;

Expand Down
1 change: 0 additions & 1 deletion EtoForms.Controls.Custom/RatingSlider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
using System.Linq;
using Eto.Drawing;
using EtoForms.Controls.Custom.Interfaces.BaseClasses;
using EtoForms.Controls.Custom.Properties;
using EtoForms.Controls.Custom.Utilities;
using FluentIcons.Resources.Filled;

Expand Down
8 changes: 4 additions & 4 deletions EtoForms.Controls.Custom/SvgColorization/SvgColorize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ private static string NodeName(SvgElement element)
/// <summary>
/// A regex to match the fill value of the style attribute.
/// </summary>
private static readonly Regex FillRegex = new("fill:.*?;", RegexOptions.Compiled);
private static readonly Regex fillRegex = new("fill:.*?;", RegexOptions.Compiled);

/// <summary>
/// A regex to match the stroke value of the style attribute.
/// </summary>
private static readonly Regex StrokeRegex = new("stroke:.*?;", RegexOptions.Compiled);
private static readonly Regex strokeRegex = new("stroke:.*?;", RegexOptions.Compiled);

/// <summary>
/// Colorizes the elements of the SVG document specified by the <see cref="SvgElement"/> element type.
Expand All @@ -133,7 +133,7 @@ public SvgColorize ColorizeElementsStroke(SvgElement element, SvgColor? stroke)
{
if (SvgDocument.Root != null)
{
ProcessNodes(SvgDocument.Root, element, StrokeRegex, stroke, false);
ProcessNodes(SvgDocument.Root, element, strokeRegex, stroke, false);
}

return this;
Expand Down Expand Up @@ -207,7 +207,7 @@ public SvgColorize ColorizeElementsFill(SvgElement element, SvgColor? fill)
{
if (SvgDocument.Root != null)
{
ProcessNodes(SvgDocument.Root, element, FillRegex, fill, true);
ProcessNodes(SvgDocument.Root, element, fillRegex, fill, true);
}

return this;
Expand Down
2 changes: 1 addition & 1 deletion EtoForms.Controls.Custom/UserIdle/UserIdleEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ public UserIdleEventArgs(bool isUserIdle)
/// Gets a value indicating whether the user is currently idle.
/// </summary>
/// <value><c>true</c> if the user is currently idle; otherwise, <c>false</c>.</value>
private bool IsUserIdle { get; }
public bool IsUserIdle { get; }
}
5 changes: 5 additions & 0 deletions Help/amp-en/docs/keyboard_shortcuts.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
## Display all the album tracks
<kbd>F9</kbd> - This function clears all search filters.

## Track seeking
<kbd>&larr;</kbd> - Seek the track 5 seconds backwards.

<kbd>&rarr;</kbd> - Seek the track 5 seconds forwards.

## Stash current queue
<kbd>Ctrl</kbd>+<kbd>T</kbd> or <kbd>⌘</kbd>+<kbd>T</kbd> - Saves to current queue into the stash.

Expand Down
5 changes: 5 additions & 0 deletions Help/amp-fi/docs/keyboard_shortcuts.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
## Näytä kaikki albumin kappaleet
<kbd>F9</kbd> - Tämä toiminto tyhjentää hakusuodattimet.

## Kappaleen kelaus
<kbd>&larr;</kbd> - Kelaa kappaletta 5 sekuntia taaksepäin.

<kbd>&rarr;</kbd> - Kelaa kappaletta 5 sekuntia eteenpäin.

## Varastoi nykyinen jono
<kbd>Ctrl</kbd>+<kbd>T</kbd> tai <kbd>⌘</kbd>+<kbd>T</kbd> - Tallentaa nykyisen jonon väliaikaiseen varastoon.

Expand Down
6 changes: 3 additions & 3 deletions amp.EtoForms/Classes/CommandLineArguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,20 @@ public class CommandLineArguments
/// Gets or sets the PID (Process Identifier) to wait for before starting the application.
/// </summary>
/// <value>The PID to wait for before starting the application.</value>
[Option('p', "pid", Required = false, HelpText = nameof(amp.Shared.Localization.Messages.AProcessIdentifierPIDToWaitForExitBeforeStartingTheApplication), ResourceType = typeof(amp.Shared.Localization.Messages))]
[Option('p', "pid", Required = false, HelpText = nameof(Shared.Localization.Messages.AProcessIdentifierPIDToWaitForExitBeforeStartingTheApplication), ResourceType = typeof(Shared.Localization.Messages))]
public int? PidWait { get; set; }

/// <summary>
/// Gets or sets the name of the backup file to backup the application data before complete startup.
/// </summary>
/// <value>The name of the backup file.</value>
[Option('b', "backup", Required = false, HelpText = nameof(amp.Shared.Localization.Messages.AFileNameToBackupTheApplicationDataBeforeCompleteStartup), ResourceType = typeof(amp.Shared.Localization.Messages))]
[Option('b', "backup", Required = false, HelpText = nameof(Shared.Localization.Messages.AFileNameToBackupTheApplicationDataBeforeCompleteStartup), ResourceType = typeof(Shared.Localization.Messages))]
public string? BackupFileName { get; set; }

/// <summary>
/// Gets or sets the name of the archive file to restore the backed up application data settings from.
/// </summary>
/// <value>The file name to restore backup the backup from.</value>
[Option('r', "restore", Required = false, HelpText = nameof(amp.Shared.Localization.Messages.RestoresABackupFromAZippedFileIntoTheProgramApplicationDataFolderOverridingTheExisting), ResourceType = typeof(amp.Shared.Localization.Messages))]
[Option('r', "restore", Required = false, HelpText = nameof(Shared.Localization.Messages.RestoresABackupFromAZippedFileIntoTheProgramApplicationDataFolderOverridingTheExisting), ResourceType = typeof(Shared.Localization.Messages))]
public string? RestoreBackupFile { get; set; }
}
9 changes: 8 additions & 1 deletion amp.EtoForms/FormMain.Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private async void FormMain_KeyDown(object? sender, KeyEventArgs e)
{
if (e.Key is Keys.Up or Keys.Down or Keys.PageDown or Keys.PageUp or Keys.Equal or
Keys.F1 or Keys.F2 or Keys.F3 or Keys.F4 or Keys.F5 or Keys.F6 or Keys.F7 or Keys.F8 or Keys.F9 or
Keys.Escape or Keys.Enter or Keys.Add or Keys.Multiply)
Keys.Escape or Keys.Enter or Keys.Add or Keys.Multiply or Keys.Left or Keys.Right)
{
if (gvAudioTracks.SelectedItem == null && gvAudioTracks.DataStore.Any())
{
Expand Down Expand Up @@ -184,6 +184,13 @@ await playbackOrder.MoveToQueueTopOrBottom(tracks, shift, e.Key == Keys.PageUp,
return;
}

if (e.Key is Keys.Right or Keys.Left)
{
playbackManager.SeekSeconds(e.Key == Keys.Right ? 5 : -5);
e.Handled = true;
return;
}

if (e.Modifiers == Keys.None)
{
if (e.IsChar && !(e.Key is Keys.Up or Keys.Down or Keys.PageDown or Keys.PageUp))
Expand Down
10 changes: 7 additions & 3 deletions amp.EtoForms/FormMain.Methods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ private void AddAudioFiles(bool toAlbum)
{
using var dialog = new OpenFileDialog { MultiSelect = true, };
dialog.Filters.Add(new FileFilter(UI.MusicFiles, MusicConstants.SupportedExtensionArray));
if (dialog.ShowDialog(this) == DialogResult.Ok)

var result = dialog.ShowDialog(this);

if (result is DialogResult.Ok or DialogResult.Ignore)
{
FormAddFilesProgress.Show(this, context, toAlbum ? CurrentAlbumId : 0, AddFilesAction, dialog.Filenames.ToArray());
}
Expand All @@ -74,7 +77,9 @@ private void AddFilesAction(bool result)
private void AddDirectory(bool toAlbum)
{
using var dialog = new SelectFolderDialog { Title = UI.SelectMusicFolder, };
if (dialog.ShowDialog(this) == DialogResult.Ok)
var result = dialog.ShowDialog(this);

if (result is DialogResult.Ok or DialogResult.Ignore)
{
FormAddFilesProgress.Show(this, context, dialog.Directory, toAlbum ? CurrentAlbumId : 0, AddFilesAction);
}
Expand Down Expand Up @@ -282,7 +287,6 @@ private void FilterTracks(bool fromUserIdleEvent)
userIdleSelectedRow = -1;
}
var text = tbSearch.Text;
var queueOnly = btnShowQueue.Checked;
var userIdle = idleChecker.IsUserIdle;
if (queueOnly)
Expand Down
2 changes: 1 addition & 1 deletion amp.EtoForms/amp.EtoForms.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<IsOSX Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))' == 'true'">true</IsOSX>
<IsWindows Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Windows)))' == 'true'">true</IsWindows>
<IsLinux Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' == 'true'">true</IsLinux>
<Version>1.0.4.0</Version>
<Version>1.0.5.0</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(IsOSX)'=='true'">
Expand Down
19 changes: 19 additions & 0 deletions amp.Playback/PlaybackManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,25 @@ public double PlaybackPositionPercentage
set => PlaybackPosition = value == 0 ? 0 : PlaybackLength * value / 100;
}

/// <summary>
/// Seeks the <see cref="PlaybackPosition"/> with the specified amount of seconds.
/// </summary>
/// <param name="value">The value in seconds to seek.</param>
public void SeekSeconds(int value)
{
var newPosition = PlaybackPosition + value;
if (newPosition < 0)
{
PlaybackPosition = 0;
return;
}

if (newPosition >= 0 && newPosition < PlaybackLength)
{
PlaybackPosition = newPosition;
}
}

/// <summary>
/// Gets or sets the playback position in seconds.
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions amp.Shared/Classes/UtilityOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public static T GetValueForOSNotNull<T>(T windowsValue, T linuxValue, T macValue
/// <summary>
/// The macOS operating system name in lower case ("macos").
/// </summary>
public const string MacOSNameLowerCase = "macos";
public const string MacOsNameLowerCase = "macos";

/// <summary>
/// The Windows operating system name in lower case ("windows").
Expand All @@ -126,7 +126,7 @@ public static string OsNameLowerCase
{
if (IsMacOS)
{
return MacOSNameLowerCase;
return MacOsNameLowerCase;
}

if (IsLinuxOS)
Expand Down

0 comments on commit cfbe991

Please sign in to comment.