mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Merge branch 'dev' into rename-quick-access-links
This commit is contained in:
commit
65eb6484a9
3 changed files with 66 additions and 19 deletions
|
|
@ -57,3 +57,7 @@ LOCALE_TRANSIENT_KEYBOARD1
|
||||||
LOCALE_TRANSIENT_KEYBOARD2
|
LOCALE_TRANSIENT_KEYBOARD2
|
||||||
LOCALE_TRANSIENT_KEYBOARD3
|
LOCALE_TRANSIENT_KEYBOARD3
|
||||||
LOCALE_TRANSIENT_KEYBOARD4
|
LOCALE_TRANSIENT_KEYBOARD4
|
||||||
|
|
||||||
|
SHParseDisplayName
|
||||||
|
SHOpenFolderAndSelectItems
|
||||||
|
CoTaskMemFree
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
|
@ -17,6 +18,7 @@ using Windows.Win32;
|
||||||
using Windows.Win32.Foundation;
|
using Windows.Win32.Foundation;
|
||||||
using Windows.Win32.Graphics.Dwm;
|
using Windows.Win32.Graphics.Dwm;
|
||||||
using Windows.Win32.UI.Input.KeyboardAndMouse;
|
using Windows.Win32.UI.Input.KeyboardAndMouse;
|
||||||
|
using Windows.Win32.UI.Shell.Common;
|
||||||
using Windows.Win32.UI.WindowsAndMessaging;
|
using Windows.Win32.UI.WindowsAndMessaging;
|
||||||
using Point = System.Windows.Point;
|
using Point = System.Windows.Point;
|
||||||
using SystemFonts = System.Windows.SystemFonts;
|
using SystemFonts = System.Windows.SystemFonts;
|
||||||
|
|
@ -753,5 +755,36 @@ namespace Flow.Launcher.Infrastructure
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Explorer
|
||||||
|
|
||||||
|
// https://learn.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-shopenfolderandselectitems
|
||||||
|
|
||||||
|
public static unsafe void OpenFolderAndSelectFile(string filePath)
|
||||||
|
{
|
||||||
|
ITEMIDLIST* pidlFolder = null;
|
||||||
|
ITEMIDLIST* pidlFile = null;
|
||||||
|
|
||||||
|
var folderPath = Path.GetDirectoryName(filePath);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var hrFolder = PInvoke.SHParseDisplayName(folderPath, null, out pidlFolder, 0, null);
|
||||||
|
if (hrFolder.Failed) throw new COMException("Failed to parse folder path", hrFolder);
|
||||||
|
|
||||||
|
var hrFile = PInvoke.SHParseDisplayName(filePath, null, out pidlFile, 0, null);
|
||||||
|
if (hrFile.Failed) throw new COMException("Failed to parse file path", hrFile);
|
||||||
|
|
||||||
|
var hrSelect = PInvoke.SHOpenFolderAndSelectItems(pidlFolder, 1, &pidlFile, 0);
|
||||||
|
if (hrSelect.Failed) throw new COMException("Failed to open folder and select item", hrSelect);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (pidlFile != null) PInvoke.CoTaskMemFree(pidlFile);
|
||||||
|
if (pidlFolder != null) PInvoke.CoTaskMemFree(pidlFolder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ using System.Runtime.CompilerServices;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Input;
|
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using CommunityToolkit.Mvvm.DependencyInjection;
|
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||||
using Flow.Launcher.Core;
|
using Flow.Launcher.Core;
|
||||||
|
|
@ -320,44 +319,54 @@ namespace Flow.Launcher
|
||||||
((PluginJsonStorage<T>)_pluginJsonStorages[type]).Save();
|
((PluginJsonStorage<T>)_pluginJsonStorages[type]).Save();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OpenDirectory(string DirectoryPath, string FileNameOrFilePath = null)
|
public void OpenDirectory(string directoryPath, string fileNameOrFilePath = null)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var explorer = new Process();
|
|
||||||
var explorerInfo = _settings.CustomExplorer;
|
var explorerInfo = _settings.CustomExplorer;
|
||||||
var explorerPath = explorerInfo.Path.Trim().ToLowerInvariant();
|
var explorerPath = explorerInfo.Path.Trim().ToLowerInvariant();
|
||||||
var targetPath = FileNameOrFilePath is null
|
var targetPath = fileNameOrFilePath is null
|
||||||
? DirectoryPath
|
? directoryPath
|
||||||
: Path.IsPathRooted(FileNameOrFilePath)
|
: Path.IsPathRooted(fileNameOrFilePath)
|
||||||
? FileNameOrFilePath
|
? fileNameOrFilePath
|
||||||
: Path.Combine(DirectoryPath, FileNameOrFilePath);
|
: Path.Combine(directoryPath, fileNameOrFilePath);
|
||||||
|
|
||||||
if (Path.GetFileNameWithoutExtension(explorerPath) == "explorer")
|
if (Path.GetFileNameWithoutExtension(explorerPath) == "explorer")
|
||||||
{
|
{
|
||||||
// Windows File Manager
|
// Windows File Manager
|
||||||
explorer.StartInfo = new ProcessStartInfo
|
if (fileNameOrFilePath is null)
|
||||||
{
|
{
|
||||||
FileName = targetPath,
|
// Only Open the directory
|
||||||
UseShellExecute = true
|
using var explorer = new Process();
|
||||||
};
|
explorer.StartInfo = new ProcessStartInfo
|
||||||
|
{
|
||||||
|
FileName = directoryPath,
|
||||||
|
UseShellExecute = true
|
||||||
|
};
|
||||||
|
explorer.Start();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Open the directory and select the file
|
||||||
|
Win32Helper.OpenFolderAndSelectFile(targetPath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Custom File Manager
|
// Custom File Manager
|
||||||
|
using var explorer = new Process();
|
||||||
explorer.StartInfo = new ProcessStartInfo
|
explorer.StartInfo = new ProcessStartInfo
|
||||||
{
|
{
|
||||||
FileName = explorerInfo.Path.Replace("%d", DirectoryPath),
|
FileName = explorerInfo.Path.Replace("%d", directoryPath),
|
||||||
UseShellExecute = true,
|
UseShellExecute = true,
|
||||||
Arguments = FileNameOrFilePath is null
|
Arguments = fileNameOrFilePath is null
|
||||||
? explorerInfo.DirectoryArgument.Replace("%d", DirectoryPath)
|
? explorerInfo.DirectoryArgument.Replace("%d", directoryPath)
|
||||||
: explorerInfo.FileArgument
|
: explorerInfo.FileArgument
|
||||||
.Replace("%d", DirectoryPath)
|
.Replace("%d", directoryPath)
|
||||||
.Replace("%f", targetPath)
|
.Replace("%f", targetPath)
|
||||||
};
|
};
|
||||||
|
explorer.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
explorer.Start();
|
|
||||||
}
|
}
|
||||||
catch (Win32Exception ex) when (ex.NativeErrorCode == 2)
|
catch (Win32Exception ex) when (ex.NativeErrorCode == 2)
|
||||||
{
|
{
|
||||||
|
|
@ -381,6 +390,7 @@ namespace Flow.Launcher
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void OpenUri(Uri uri, bool? inPrivate = null)
|
private void OpenUri(Uri uri, bool? inPrivate = null)
|
||||||
{
|
{
|
||||||
if (uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps)
|
if (uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue