mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-26 19:48:01 +02:00
Fix dialogs in release mode
... and inline "GetFilterItems" method so we can use scoped allocation
This commit is contained in:
parent
694e663630
commit
4d337e3a31
3 changed files with 28 additions and 45 deletions
|
@ -99,20 +99,30 @@ namespace System.IO
|
||||||
private Result<void> SetFileTypes(Windows.COM_IFileDialog* dialog)
|
private Result<void> SetFileTypes(Windows.COM_IFileDialog* dialog)
|
||||||
{
|
{
|
||||||
List<Windows.COMDLG_FILTERSPEC> filterItems = scope .();
|
List<Windows.COMDLG_FILTERSPEC> filterItems = scope .();
|
||||||
GetFilterItems(filterItems, mFilter);
|
|
||||||
|
|
||||||
if (filterItems.Count == 0)
|
// Expected input types
|
||||||
return .Ok;
|
// "Text files (*.txt)|*.txt|All files (*.*)|*.*"
|
||||||
|
// "Image Files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.*"
|
||||||
defer
|
if (!String.IsNullOrEmpty(mFilter))
|
||||||
{
|
{
|
||||||
for (var filter in filterItems)
|
StringView[] tokens = mFilter.Split!('|');
|
||||||
{
|
if (0 == tokens.Count % 2)
|
||||||
delete filter.pszName;
|
{
|
||||||
delete filter.pszSpec;
|
// All even numbered tokens should be labels
|
||||||
}
|
// Odd numbered tokens are the associated extensions
|
||||||
|
for (int i = 1; i < tokens.Count; i += 2)
|
||||||
|
{
|
||||||
|
Windows.COMDLG_FILTERSPEC ext;
|
||||||
|
ext.pszSpec = tokens[i].ToScopedNativeWChar!::(); // This may be a semicolon delimited list of extensions (that's ok)
|
||||||
|
ext.pszName = tokens[i - 1].ToScopedNativeWChar!::();
|
||||||
|
filterItems.Add(ext);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (filterItems.IsEmpty)
|
||||||
|
return .Ok;
|
||||||
|
|
||||||
Windows.COM_IUnknown.HResult hr = dialog.VT.SetFileTypes(dialog, (uint32)filterItems.Count, filterItems.Ptr);
|
Windows.COM_IUnknown.HResult hr = dialog.VT.SetFileTypes(dialog, (uint32)filterItems.Count, filterItems.Ptr);
|
||||||
if (hr.Failed)
|
if (hr.Failed)
|
||||||
return .Err;
|
return .Err;
|
||||||
|
@ -123,37 +133,6 @@ namespace System.IO
|
||||||
|
|
||||||
return .Ok;
|
return .Ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void GetFilterItems(List<Windows.COMDLG_FILTERSPEC> list, String filter)
|
|
||||||
{
|
|
||||||
mixin ToHeapWChar(var str)
|
|
||||||
{
|
|
||||||
int encodedLen = System.Text.UTF16.GetEncodedLen(str);
|
|
||||||
char16* buf = new char16[encodedLen]* ( ? );
|
|
||||||
System.Text.UTF16.Encode(str, buf, encodedLen);
|
|
||||||
buf
|
|
||||||
}
|
|
||||||
|
|
||||||
// Expected input types
|
|
||||||
// "Text files (*.txt)|*.txt|All files (*.*)|*.*"
|
|
||||||
// "Image Files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.*"
|
|
||||||
if (!String.IsNullOrEmpty(filter))
|
|
||||||
{
|
|
||||||
StringView[] tokens = filter.Split!('|');
|
|
||||||
if (0 == tokens.Count % 2)
|
|
||||||
{
|
|
||||||
// All even numbered tokens should be labels
|
|
||||||
// Odd numbered tokens are the associated extensions
|
|
||||||
for (int i = 1; i < tokens.Count; i += 2)
|
|
||||||
{
|
|
||||||
Windows.COMDLG_FILTERSPEC ext;
|
|
||||||
ext.pszSpec = ToHeapWChar!(tokens[i]); // This may be a semicolon delimited list of extensions (that's ok)
|
|
||||||
ext.pszName = ToHeapWChar!(tokens[i - 1]);
|
|
||||||
list.Add(ext);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
|
@ -120,14 +120,16 @@ namespace System.IO
|
||||||
Windows.COM_IFileOpenDialog* openDialog = (.)dialog;
|
Windows.COM_IFileOpenDialog* openDialog = (.)dialog;
|
||||||
if (Multiselect)
|
if (Multiselect)
|
||||||
{
|
{
|
||||||
openDialog.VT.GetResults(openDialog, let results);
|
Windows.COM_IShellItemArray* results = null;
|
||||||
|
openDialog.VT.GetResults(openDialog, out results);
|
||||||
|
|
||||||
if (results != null)
|
if (results != null)
|
||||||
{
|
{
|
||||||
results.VT.GetCount(results, let count);
|
results.VT.GetCount(results, let count);
|
||||||
for (uint32 i < count)
|
for (uint32 i < count)
|
||||||
{
|
{
|
||||||
results.VT.GetItemAt(results, i, let item);
|
Windows.COM_IShellItem* item = null;
|
||||||
|
results.VT.GetItemAt(results, i, out item);
|
||||||
if (item != null)
|
if (item != null)
|
||||||
{
|
{
|
||||||
let filePath = GetFilePathFromShellItem!(item);
|
let filePath = GetFilePathFromShellItem!(item);
|
||||||
|
@ -140,7 +142,8 @@ namespace System.IO
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
openDialog.VT.GetResult(openDialog, let shellItem);
|
Windows.COM_IShellItem* shellItem = null;
|
||||||
|
openDialog.VT.GetResult(openDialog, out shellItem);
|
||||||
|
|
||||||
if (shellItem != null)
|
if (shellItem != null)
|
||||||
{
|
{
|
||||||
|
|
|
@ -109,7 +109,8 @@ namespace System.IO
|
||||||
}
|
}
|
||||||
|
|
||||||
Windows.COM_IFileSaveDialog* saveDialog = (.)dialog;
|
Windows.COM_IFileSaveDialog* saveDialog = (.)dialog;
|
||||||
saveDialog.VT.GetResult(saveDialog, let shellItem);
|
Windows.COM_IShellItem* shellItem = null;
|
||||||
|
saveDialog.VT.GetResult(saveDialog, out shellItem);
|
||||||
|
|
||||||
if (shellItem != null)
|
if (shellItem != null)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue