mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-09-14 12:19:08 +00:00
add "Open with" button
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
using System.Windows.Threading;
|
||||
using QuickLook.Helpers;
|
||||
@@ -13,6 +14,8 @@ namespace QuickLook
|
||||
/// </summary>
|
||||
public partial class MainWindowTransparent : Window
|
||||
{
|
||||
private string _path = string.Empty;
|
||||
|
||||
internal MainWindowTransparent()
|
||||
{
|
||||
// this object should be initialized before loading UI components, because many of which are binding to it.
|
||||
@@ -31,10 +34,27 @@ namespace QuickLook
|
||||
};
|
||||
|
||||
buttonCloseWindow.MouseLeftButtonUp += (sender, e) => BeginHide(true);
|
||||
|
||||
/*PreviewKeyUp += (sender, e) =>
|
||||
{
|
||||
if (e.Key == Key.Enter)
|
||||
OpenWithAssocApp();
|
||||
};*/
|
||||
|
||||
buttonOpenWith.Click += (sender, e) => OpenWithAssocApp();
|
||||
}
|
||||
|
||||
public ContextObject ContextObject { get; private set; }
|
||||
|
||||
private void OpenWithAssocApp()
|
||||
{
|
||||
if (string.IsNullOrEmpty(_path))
|
||||
return;
|
||||
|
||||
Process.Start(new ProcessStartInfo(_path) {WorkingDirectory = Path.GetDirectoryName(_path)});
|
||||
BeginHide(true);
|
||||
}
|
||||
|
||||
private new void Show()
|
||||
{
|
||||
// revert UI changes
|
||||
@@ -107,6 +127,8 @@ namespace QuickLook
|
||||
// get window size before showing it
|
||||
ContextObject.ViewerPlugin.Prepare(path, ContextObject);
|
||||
|
||||
SetOpenWithButtonAndPath(path);
|
||||
|
||||
Show();
|
||||
|
||||
// load plugin, do not block UI
|
||||
@@ -128,6 +150,15 @@ namespace QuickLook
|
||||
throw thrown;
|
||||
}
|
||||
|
||||
private void SetOpenWithButtonAndPath(string path)
|
||||
{
|
||||
var isExe = FileHelper.GetAssocApplication(path, out string executePath, out string appFriendlyName);
|
||||
|
||||
_path = executePath;
|
||||
buttonOpenWith.Visibility = isExe == null ? Visibility.Collapsed : Visibility.Visible;
|
||||
buttonOpenWith.Content = isExe == true ? $"Run {appFriendlyName}" : $"Open with {appFriendlyName}";
|
||||
}
|
||||
|
||||
internal bool BeginHide(bool quit = false)
|
||||
{
|
||||
if (quit && App.RunningAsViewer)
|
||||
|
Reference in New Issue
Block a user