mirror of
https://github.com/ShareX/ShareX.git
synced 2024-09-30 01:07:21 +13:00
Set initial directory in image file name editor
This commit is contained in:
parent
c9dd17be30
commit
5e5e2d9b31
2 changed files with 24 additions and 4 deletions
|
@ -1526,9 +1526,9 @@ public static Bitmap Slice(Bitmap bmp, int minSliceHeight, int maxSliceHeight, i
|
|||
return bmpResult;
|
||||
}
|
||||
|
||||
public static string OpenImageFileDialog(Form form = null)
|
||||
public static string OpenImageFileDialog(Form form = null, string initialDirectory = null)
|
||||
{
|
||||
string[] images = OpenImageFileDialog(false, form);
|
||||
string[] images = OpenImageFileDialog(false, form, initialDirectory);
|
||||
|
||||
if (images != null && images.Length > 0)
|
||||
{
|
||||
|
@ -1538,7 +1538,7 @@ public static string OpenImageFileDialog(Form form = null)
|
|||
return null;
|
||||
}
|
||||
|
||||
public static string[] OpenImageFileDialog(bool multiselect, Form form = null)
|
||||
public static string[] OpenImageFileDialog(bool multiselect, Form form = null, string initialDirectory = null)
|
||||
{
|
||||
using (OpenFileDialog ofd = new OpenFileDialog())
|
||||
{
|
||||
|
@ -1547,6 +1547,11 @@ public static string[] OpenImageFileDialog(bool multiselect, Form form = null)
|
|||
|
||||
ofd.Multiselect = multiselect;
|
||||
|
||||
if (!string.IsNullOrEmpty(initialDirectory))
|
||||
{
|
||||
ofd.InitialDirectory = initialDirectory;
|
||||
}
|
||||
|
||||
if (ofd.ShowDialog(form) == DialogResult.OK)
|
||||
{
|
||||
return ofd.FileNames;
|
||||
|
|
|
@ -25,6 +25,7 @@ You should have received a copy of the GNU General Public License
|
|||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Windows.Forms.Design;
|
||||
|
||||
namespace ShareX.HelpersLib
|
||||
|
@ -38,7 +39,21 @@ public override object EditValue(ITypeDescriptorContext context, IServiceProvide
|
|||
return base.EditValue(context, provider, value);
|
||||
}
|
||||
|
||||
string filePath = ImageHelpers.OpenImageFileDialog();
|
||||
string filePath = value as string;
|
||||
string initialDirectory = null;
|
||||
|
||||
if (!string.IsNullOrEmpty(filePath))
|
||||
{
|
||||
filePath = Helpers.ExpandFolderVariables(filePath, true);
|
||||
string directoryPath = Path.GetDirectoryName(filePath);
|
||||
|
||||
if (!string.IsNullOrEmpty(directoryPath) && Directory.Exists(directoryPath))
|
||||
{
|
||||
initialDirectory = directoryPath;
|
||||
}
|
||||
}
|
||||
|
||||
filePath = ImageHelpers.OpenImageFileDialog(null, initialDirectory);
|
||||
|
||||
if (!string.IsNullOrEmpty(filePath))
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue