Skip to content

Commit

Permalink
Add support for drag'n'drop onto the application in file explorer. (#1)
Browse files Browse the repository at this point in the history
A small change to the duration decrement feature to only wqhalve the duration at faster speeds.
  • Loading branch information
mjh65 authored Dec 15, 2023
1 parent 0386d42 commit dcd46e7
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
1 change: 1 addition & 0 deletions Slideshow/App.xaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Application x:Class="Slideshow.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Startup="App_Startup"
StartupUri="MainWindow.xaml">
<Application.Resources>

Expand Down
13 changes: 13 additions & 0 deletions Slideshow/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,18 @@ namespace Slideshow
/// </summary>
public partial class App : Application
{
void App_Startup(object sender, StartupEventArgs e)
{
if (e.Args.Length > 0)
{
dragNdropArg = e.Args[0];
}
else
{
dragNdropArg = "";
}
}

public static string dragNdropArg;
}
}
33 changes: 29 additions & 4 deletions Slideshow/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,18 @@ void MainWindow_KeyDown(object sender, KeyEventArgs e)
case Key.Subtract:
// Break intentionally omitted.
case Key.OemMinus:
if (imageDurationSeconds - imageDurationOffset < 1)
if (imageDurationSeconds <= 1)
{
break;
}

imageDurationSeconds -= imageDurationOffset;
if (imageDurationSeconds >= (imageDurationOffset * 2))
{
imageDurationSeconds -= imageDurationOffset;
}
else
{
imageDurationSeconds /= 2;
}
imageTimer.Interval = new TimeSpan(0, 0, imageDurationSeconds);
Toast(String.Format("Decreased duration to {0} seconds", imageDurationSeconds));
break;
Expand Down Expand Up @@ -233,7 +239,15 @@ private void ReadExifInfo(FileStream imageStream)
private void LoadImages()
{
string[] validExtensions = new string[] { ".jpg", ".jpeg" };
DirectoryInfo directory = new DirectoryInfo(GetAssemblyDirectory());
DirectoryInfo directory;
if (Slideshow.App.dragNdropArg.Length > 0)
{
directory = new DirectoryInfo(GetSelectedDirectory(Slideshow.App.dragNdropArg));
}
else
{
directory = new DirectoryInfo(GetAssemblyDirectory());
}
IEnumerable<FileInfo> files = from f in directory.EnumerateFiles()
where validExtensions.Any(f.Extension.ToLower().Contains)
select f;
Expand All @@ -253,5 +267,16 @@ private string GetAssemblyDirectory()
string assemblyPath = Uri.UnescapeDataString(uri.Path);
return Path.GetDirectoryName(assemblyPath);
}

private string GetSelectedDirectory(string arg)
{
UriBuilder uri = new UriBuilder(arg);
string argPath = Uri.UnescapeDataString(uri.Path);
if (Directory.Exists(argPath))
{
return argPath;
}
return Path.GetDirectoryName(argPath);
}
}
}

0 comments on commit dcd46e7

Please sign in to comment.