file extension filter for ManualFills import file dialog
This commit is contained in:
1 parent
2c547f37fb
commit
0f21d9783b
4 files changed
+65
-3
No files matched your search
@@ -26,6 +26,8 @@ namespace bts.shell.manual_fills {
|
||||
}
|
||||
|
||||
static class ManualFillsParser {
|
||||
public const string file_extension = "csv";
|
||||
|
||||
public static Action<ManualFill, object> assign_component(ManualFillComponent component) {
|
||||
switch (component) {
|
||||
case ManualFillComponent.Security: return (mf, val) => mf.SecurityKey = ConvertUtils.try_convert<SecurityImmutable?>(val)?.Id ?? 0;
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace bts.shell.manual_fills {
|
||||
revert_selected_fills_cmd = ObservantCommand.create(() => revert(selection_mon.filtered_items.ToList()), out var revert_selected_fills_observer);
|
||||
remove_selected_fills_cmd = ObservantAsyncCommand.create(remove_selected_fills_async, out var remove_selected_fills_observer);
|
||||
add_fill_cmd = new DelegateCommand(_add_fill);
|
||||
import_fills_cmd = FileDialogCommand.open_file(_import_fills);
|
||||
import_fills_cmd = FileDialogCommand.open_file(_import_fills, extensions: ManualFillsParser.file_extension);
|
||||
//
|
||||
var dirty_or_new_src = dirty_mon.CombineLatest(placeholder_mon, LogicalDelegates.Or);
|
||||
_dispose = Disposable.Create(
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace System.IO {
|
||||
class NativeFileHelper {
|
||||
const uint
|
||||
FILE_ATTRIBUTE_READONLY = 0x00000001,
|
||||
FILE_ATTRIBUTE_HIDDEN = 0x00000002,
|
||||
FILE_ATTRIBUTE_SYSTEM = 0x00000004,
|
||||
FILE_ATTRIBUTE_DIRECTORY = 0x00000010,
|
||||
FILE_ATTRIBUTE_ARCHIVE = 0x00000020,
|
||||
FILE_ATTRIBUTE_DEVICE = 0x00000040,
|
||||
FILE_ATTRIBUTE_NORMAL = 0x00000080,
|
||||
FILE_ATTRIBUTE_TEMPORARY = 0x00000100,
|
||||
FILE_ATTRIBUTE_SPARSE_FILE = 0x00000200,
|
||||
FILE_ATTRIBUTE_REPARSE_POINT = 0x00000400,
|
||||
FILE_ATTRIBUTE_COMPRESSED = 0x00000800,
|
||||
FILE_ATTRIBUTE_OFFLINE = 0x00001000,
|
||||
FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = 0x00002000,
|
||||
FILE_ATTRIBUTE_ENCRYPTED = 0x00004000,
|
||||
FILE_ATTRIBUTE_VIRTUAL = 0x00010000,
|
||||
|
||||
SHGFI_ICON = 0x000000100, // get icon
|
||||
SHGFI_DISPLAYNAME = 0x000000200, // get display name
|
||||
SHGFI_TYPENAME = 0x000000400, // get type name
|
||||
SHGFI_ATTRIBUTES = 0x000000800, // get attributes
|
||||
SHGFI_ICONLOCATION = 0x000001000, // get icon location
|
||||
SHGFI_EXETYPE = 0x000002000, // return exe type
|
||||
SHGFI_SYSICONINDEX = 0x000004000, // get system icon index
|
||||
SHGFI_LINKOVERLAY = 0x000008000, // put a link overlay on icon
|
||||
SHGFI_SELECTED = 0x000010000, // show icon in selected state
|
||||
SHGFI_ATTR_SPECIFIED = 0x000020000, // get only specified attributes
|
||||
SHGFI_LARGEICON = 0x000000000, // get large icon
|
||||
SHGFI_SMALLICON = 0x000000001, // get small icon
|
||||
SHGFI_OPENICON = 0x000000002, // get open icon
|
||||
SHGFI_SHELLICONSIZE = 0x000000004, // get shell size icon
|
||||
SHGFI_PIDL = 0x000000008, // pszPath is a pidl
|
||||
SHGFI_USEFILEATTRIBUTES = 0x000000010; // use passed dwFileAttribute
|
||||
|
||||
public static string get_file_type_description(string file_type) =>
|
||||
SHGetFileInfo(file_type, FILE_ATTRIBUTE_NORMAL, out SHFILEINFO shfi, (uint)Marshal.SizeOf(typeof(SHFILEINFO)), SHGFI_USEFILEATTRIBUTES | SHGFI_TYPENAME) != IntPtr.Zero ?
|
||||
shfi.szTypeName : null;
|
||||
|
||||
[DllImport("shell32")]
|
||||
static extern IntPtr SHGetFileInfo(string pszPath, uint dwFileAttributes, out SHFILEINFO psfi, uint cbFileInfo, uint flags);
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
struct SHFILEINFO {
|
||||
public IntPtr hIcon;
|
||||
public int iIcon;
|
||||
public uint dwAttributes;
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
|
||||
public string szDisplayName;
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]
|
||||
public string szTypeName;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,8 +7,11 @@ using System.Windows.Forms;
|
||||
|
||||
namespace mbts.ui {
|
||||
public static class FileDialogCommand {
|
||||
public static IDialogCommand open_file(Action<string> execute) =>
|
||||
new AnonymousFileDialogCommand<object>(_ => _create_open_file_dialog(), (_, file) => execute(file), _ => true);
|
||||
public static IDialogCommand open_file(Action<string> execute, string initial_dir = null, params string[] extensions) =>
|
||||
open_file(execute, initial_dir, Array.ConvertAll(extensions, ext => (NativeFileHelper.get_file_type_description("." + ext), new[] { ext })));
|
||||
|
||||
public static IDialogCommand open_file(Action<string> execute, string initial_dir, params (string name, string[] extensions)[] extensions) =>
|
||||
new AnonymousFileDialogCommand<object>(_ => _create_open_file_dialog(null, extensions), (_, file) => execute(file), _ => true);
|
||||
|
||||
public static IDialogCommand export_proto<TProto>(
|
||||
Func<TProto> get_proto,
|
||||
|
||||
Reference in new issue
Block a user