Ejemplo n.º 1
0
        public Task<string> ShowFolderDialogAsync(OpenFolderDialog dialog, IWindowImpl parent)
        {
            var tcs = new TaskCompletionSource<string>();
            var dlg = new global::Gtk.FileChooserDialog(dialog.Title, ((WindowImpl)parent),
                FileChooserAction.SelectFolder,
                "Cancel", ResponseType.Cancel,
                "Select Folder", ResponseType.Accept)
            {

            };

            dlg.Modal = true;

            dlg.Response += (_, args) =>
            {
                if (args.ResponseId == ResponseType.Accept)
                    tcs.TrySetResult(dlg.Filename);

                dlg.Hide();
                dlg.Dispose();
            };

            dlg.Close += delegate
            {
                tcs.TrySetResult(null);
                dlg.Dispose();
            };
            dlg.Show();
            return tcs.Task;
        }
Ejemplo n.º 2
0
        public MainWindowViewModel()
        {
            Items = new List<TestItem>();

            for (int i = 0; i < 10; ++i)
            {
                Items.Add(new TestItem($"Item {i}", $"Item {i} Value"));
            }

            Nodes = new List<TestNode>
            {
                new TestNode
                {
                    Header = "Root",
                    SubHeader = "Root Item",
                    IsExpanded = true,
                    Children = new[]
                    {
                        new TestNode
                        {
                            Header = "Child 1",
                            SubHeader = "Child 1 Value",
                        },
                        new TestNode
                        {
                            Header = "Child 2",
                            SubHeader = "Child 2 Value",
                            IsExpanded = false,
                            Children = new[]
                            {
                                new TestNode
                                {
                                    Header = "Grandchild",
                                    SubHeader = "Grandchild Value",
                                },
                                new TestNode
                                {
                                    Header = "Grandmaster Flash",
                                    SubHeader = "White Lines",
                                },
                            }
                        },
                    }
                }
            };

            CollapseNodesCommand = ReactiveCommand.Create();
            CollapseNodesCommand.Subscribe(_ => ExpandNodes(false));
            ExpandNodesCommand = ReactiveCommand.Create();
            ExpandNodesCommand.Subscribe(_ => ExpandNodes(true));

            OpenFileCommand = ReactiveCommand.Create();
            OpenFileCommand.Subscribe(_ =>
            {
                var ofd = new OpenFileDialog();

                ofd.ShowAsync();
            });

            OpenFolderCommand = ReactiveCommand.Create();
            OpenFolderCommand.Subscribe(_ =>
            {
                var ofd = new OpenFolderDialog();

                ofd.ShowAsync();
            });

        }
Ejemplo n.º 3
0
 public Task<string> ShowFolderDialogAsync(OpenFolderDialog dialog, IWindowImpl parent)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 4
0
        public Task<string> ShowFolderDialogAsync(OpenFolderDialog dialog, IWindowImpl parent)
        {                                
            return Task.Factory.StartNew(() =>
            {
                string result = string.Empty;

                var hWnd = parent?.Handle?.Handle ?? IntPtr.Zero;
                var frm = (IFileDialog)(new UnmanagedMethods.FileOpenDialogRCW());
                uint options;
                frm.GetOptions(out options);
                options |= (uint)(UnmanagedMethods.FOS.FOS_PICKFOLDERS | UnmanagedMethods.FOS.FOS_FORCEFILESYSTEM | UnmanagedMethods.FOS.FOS_NOVALIDATE | UnmanagedMethods.FOS.FOS_NOTESTFILECREATE | UnmanagedMethods.FOS.FOS_DONTADDTORECENT);
                frm.SetOptions(options);

                if (dialog.InitialDirectory != null)
                {
                    IShellItem directoryShellItem;
                    var riid = new Guid("43826D1E-E718-42EE-BC55-A1E261C37BFE"); //IShellItem
                    if (UnmanagedMethods.SHCreateItemFromParsingName(dialog.InitialDirectory, IntPtr.Zero, ref riid, out directoryShellItem) == (uint)UnmanagedMethods.HRESULT.S_OK)
                    {
                        frm.SetFolder(directoryShellItem);
                    }
                }

                if (dialog.DefaultDirectory != null)
                {
                    IShellItem directoryShellItem;
                    var riid = new Guid("43826D1E-E718-42EE-BC55-A1E261C37BFE"); //IShellItem
                    if (UnmanagedMethods.SHCreateItemFromParsingName(dialog.DefaultDirectory, IntPtr.Zero, ref riid, out directoryShellItem) == (uint)UnmanagedMethods.HRESULT.S_OK)
                    {
                        frm.SetDefaultFolder(directoryShellItem);
                    }
                }

                if (frm.Show(hWnd) == (uint)UnmanagedMethods.HRESULT.S_OK)
                {
                    IShellItem shellItem;
                    if (frm.GetResult(out shellItem) == (uint)UnmanagedMethods.HRESULT.S_OK)
                    {
                        IntPtr pszString;
                        if (shellItem.GetDisplayName(UnmanagedMethods.SIGDN_FILESYSPATH, out pszString) == (uint)UnmanagedMethods.HRESULT.S_OK)
                        {
                            if (pszString != IntPtr.Zero)
                            {
                                try
                                {
                                    result = Marshal.PtrToStringAuto(pszString);                                    
                                }
                                finally
                                {
                                    Marshal.FreeCoTaskMem(pszString);
                                }
                            }
                        }
                    }
                }

                return result;
            });
        }