mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
add filter to file dialog for selecting Python exe
This commit is contained in:
parent
65db4e4141
commit
5263bf50dd
3 changed files with 36 additions and 32 deletions
|
|
@ -15,7 +15,7 @@ using System.Windows.Forms;
|
|||
|
||||
namespace Flow.Launcher.Core.ExternalPlugins
|
||||
{
|
||||
internal class PluginEnvironment
|
||||
public class PluginEnvironment
|
||||
{
|
||||
private const string PythonExecutable = "pythonw.exe";
|
||||
|
||||
|
|
@ -211,6 +211,29 @@ namespace Flow.Launcher.Core.ExternalPlugins
|
|||
|
||||
return pluginPairs;
|
||||
}
|
||||
|
||||
|
||||
public static string GetFileFromDialog(string title, string filter="")
|
||||
{
|
||||
var dlg = new OpenFileDialog
|
||||
{
|
||||
InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles),
|
||||
Multiselect = false,
|
||||
CheckFileExists = true,
|
||||
CheckPathExists = true,
|
||||
Title = title,
|
||||
Filter = filter
|
||||
};
|
||||
|
||||
var result = dlg.ShowDialog();
|
||||
if (result == DialogResult.OK)
|
||||
{
|
||||
return dlg.FileName;
|
||||
}
|
||||
else
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,6 +59,7 @@
|
|||
<system:String x:Key="pythonDirectory">Python Directory</system:String>
|
||||
<system:String x:Key="nodeFilePath">Node.js Path</system:String>
|
||||
<system:String x:Key="selectNodeExecutable">Please select the Node.js executable</system:String>
|
||||
<system:String x:Key="selectPythonExecutable">Please select pythonw.exe</system:String>
|
||||
<system:String x:Key="autoUpdates">Auto Update</system:String>
|
||||
<system:String x:Key="select">Select</system:String>
|
||||
<system:String x:Key="hideOnStartup">Hide Flow Launcher on startup</system:String>
|
||||
|
|
|
|||
|
|
@ -72,45 +72,25 @@ namespace Flow.Launcher
|
|||
|
||||
private void OnSelectPythonDirectoryClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var dlg = new FolderBrowserDialog
|
||||
{
|
||||
SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)
|
||||
};
|
||||
var selectedFile = PluginEnvironment.GetFileFromDialog(
|
||||
InternationalizationManager.Instance.GetTranslation("selectPythonExecutable"),
|
||||
"Python|pythonw.exe");
|
||||
|
||||
var result = dlg.ShowDialog();
|
||||
if (result == System.Windows.Forms.DialogResult.OK)
|
||||
if (!string.IsNullOrEmpty(selectedFile))
|
||||
{
|
||||
string pythonDirectory = dlg.SelectedPath;
|
||||
if (!string.IsNullOrEmpty(pythonDirectory))
|
||||
{
|
||||
var pythonPath = Path.Combine(pythonDirectory, PluginsLoader.PythonExecutable);
|
||||
if (File.Exists(pythonPath))
|
||||
{
|
||||
settings.PluginSettings.PythonDirectory = pythonDirectory;
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Can't find python in given directory");
|
||||
}
|
||||
}
|
||||
Constant.PythonPath = selectedFile;
|
||||
settings.PluginSettings.PythonDirectory = Constant.PythonPath;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnSelectNodeFilePathClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var dlg = new OpenFileDialog
|
||||
{
|
||||
InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles),
|
||||
Multiselect = false,
|
||||
CheckFileExists = true,
|
||||
CheckPathExists = true,
|
||||
Title = InternationalizationManager.Instance.GetTranslation("selectNodeExecutable")
|
||||
};
|
||||
var selectedFile = PluginEnvironment.GetFileFromDialog(
|
||||
InternationalizationManager.Instance.GetTranslation("selectNodeExecutable"));
|
||||
|
||||
var result = dlg.ShowDialog();
|
||||
if (result == System.Windows.Forms.DialogResult.OK)
|
||||
if (!string.IsNullOrEmpty(selectedFile))
|
||||
{
|
||||
Constant.NodePath = dlg.FileName;
|
||||
Constant.NodePath = selectedFile;
|
||||
settings.PluginSettings.NodeFilePath = Constant.NodePath;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue