Add file dialoge helpers
This commit is contained in:
parent
a1e94b8c3d
commit
a019faa13f
@ -164,17 +164,12 @@ public partial class ReCodeItForm : Form
|
||||
|
||||
private void LoadMappingFileButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
var fDialog = new OpenFileDialog
|
||||
{
|
||||
Title = "Select a mapping file",
|
||||
Filter = "JSON Files (*.json)|*.json|JSONC Files (*.jsonc)|*.jsonc|All Files (*.*)|*.*",
|
||||
Multiselect = false
|
||||
};
|
||||
var result = GUIHelpers.OpenFileDialog("Select a mapping file",
|
||||
"JSON Files (*.json)|*.json|JSONC Files (*.jsonc)|*.jsonc|All Files (*.*)|*.*");
|
||||
|
||||
if (fDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
DataProvider.LoadMappingFile(fDialog.FileName);
|
||||
}
|
||||
if (result == string.Empty) { return; }
|
||||
|
||||
DataProvider.LoadMappingFile(result);
|
||||
|
||||
RemapTreeView.Nodes.Clear();
|
||||
|
||||
@ -186,31 +181,24 @@ public partial class ReCodeItForm : Form
|
||||
|
||||
private void PickAssemblyPathButton_Click_1(object sender, EventArgs e)
|
||||
{
|
||||
OpenFileDialog fDialog = new()
|
||||
{
|
||||
Title = "Select a DLL file",
|
||||
Filter = "DLL Files (*.dll)|*.dll|All Files (*.*)|*.*",
|
||||
Multiselect = false
|
||||
};
|
||||
var result = GUIHelpers.OpenFileDialog("Select a DLL file",
|
||||
"DLL Files (*.dll)|*.dll|All Files (*.*)|*.*");
|
||||
|
||||
if (fDialog.ShowDialog() == DialogResult.OK)
|
||||
if (result != string.Empty)
|
||||
{
|
||||
DataProvider.Settings.Remapper.AssemblyPath = fDialog.FileName;
|
||||
TargetAssemblyPath.Text = fDialog.FileName;
|
||||
DataProvider.Settings.Remapper.AssemblyPath = result;
|
||||
TargetAssemblyPath.Text = result;
|
||||
}
|
||||
}
|
||||
|
||||
private void OutputDirectoryButton_Click_1(object sender, EventArgs e)
|
||||
{
|
||||
using FolderBrowserDialog fDialog = new();
|
||||
var result = GUIHelpers.OpenFolderDialog("Select an output directory");
|
||||
|
||||
fDialog.Description = "Select a directory";
|
||||
fDialog.ShowNewFolderButton = true;
|
||||
|
||||
if (fDialog.ShowDialog() == DialogResult.OK)
|
||||
if (result != string.Empty)
|
||||
{
|
||||
DataProvider.Settings.Remapper.OutputPath = fDialog.SelectedPath;
|
||||
RemapperOutputDirectoryPath.Text = fDialog.SelectedPath;
|
||||
DataProvider.Settings.Remapper.OutputPath = result;
|
||||
RemapperOutputDirectoryPath.Text = result;
|
||||
}
|
||||
}
|
||||
|
||||
@ -517,32 +505,25 @@ public partial class ReCodeItForm : Form
|
||||
|
||||
private void AutoMapperChooseTargetPathButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
OpenFileDialog fDialog = new()
|
||||
{
|
||||
Title = "Select a DLL file",
|
||||
Filter = "DLL Files (*.dll)|*.dll|All Files (*.*)|*.*",
|
||||
Multiselect = false
|
||||
};
|
||||
var result = GUIHelpers.OpenFileDialog("Select a DLL file",
|
||||
"DLL Files (*.dll)|*.dll|All Files (*.*)|*.*");
|
||||
|
||||
if (fDialog.ShowDialog() == DialogResult.OK)
|
||||
if (result != string.Empty)
|
||||
{
|
||||
DataProvider.Settings.AutoMapper.AssemblyPath = fDialog.FileName;
|
||||
TargetAssemblyPath.Text = fDialog.FileName;
|
||||
DataProvider.Settings.AutoMapper.AssemblyPath = result;
|
||||
TargetAssemblyPath.Text = result;
|
||||
DataProvider.SaveAppSettings();
|
||||
}
|
||||
}
|
||||
|
||||
private void AutoMapperChooseOutpathButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
using FolderBrowserDialog fDialog = new();
|
||||
var result = GUIHelpers.OpenFolderDialog("Select an output directory");
|
||||
|
||||
fDialog.Description = "Select a directory";
|
||||
fDialog.ShowNewFolderButton = true;
|
||||
|
||||
if (fDialog.ShowDialog() == DialogResult.OK)
|
||||
if (result != string.Empty)
|
||||
{
|
||||
DataProvider.Settings.AutoMapper.OutputPath = fDialog.SelectedPath;
|
||||
RemapperOutputDirectoryPath.Text = fDialog.SelectedPath;
|
||||
DataProvider.Settings.AutoMapper.OutputPath = result;
|
||||
RemapperOutputDirectoryPath.Text = result;
|
||||
DataProvider.SaveAppSettings();
|
||||
}
|
||||
}
|
||||
|
@ -238,4 +238,47 @@ internal static class GUIHelpers
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens and returns a path from a file dialogue
|
||||
/// </summary>
|
||||
/// <param name="title"></param>
|
||||
/// <param name="filter"></param>
|
||||
/// <returns>Path if selected, or empty string</returns>
|
||||
public static string OpenFileDialog(string title, string filter)
|
||||
{
|
||||
OpenFileDialog fDialog = new()
|
||||
{
|
||||
Title = title,
|
||||
Filter = filter,
|
||||
Multiselect = false
|
||||
};
|
||||
|
||||
if (fDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
return fDialog.FileName;
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens and returns a path from a folder dialogue
|
||||
/// </summary>
|
||||
/// <param name="description"></param>
|
||||
/// <returns></returns>
|
||||
public static string OpenFolderDialog(string description)
|
||||
{
|
||||
using FolderBrowserDialog fDialog = new();
|
||||
|
||||
fDialog.Description = description;
|
||||
fDialog.ShowNewFolderButton = true;
|
||||
|
||||
if (fDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
return fDialog.SelectedPath;
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user