예제 #1
0
        private void PickItem(object sender, EventArgs e)
        {
            var pfd = new IFileOpenDialog();

            if (pfd != null)
            {
                var dwOptions = pfd.GetOptions();
                pfd.SetOptions(dwOptions | FILEOPENDIALOGOPTIONS.FOS_ALLNONSTORAGEITEMS | FILEOPENDIALOGOPTIONS.FOS_PICKFOLDERS);
                pfd.SetTitle("Item Picker");
                var hr = pfd.Show(Handle);
                if (hr.Succeeded)
                {
                    if (pfd.GetResult() is IShellItem2 psi)
                    {
                        psiDrop = psi;
                        StartWatching();
                    }
                }
            }
        }
예제 #2
0
        protected override void PerformAction(object parameter)
        {
            var album = parameter as FacebookPhotoAlbum;

            if (album == null)
            {
                return;
            }

            string folderPath = null;

            if (Utility.IsOSVistaOrNewer)
            {
                IFileOpenDialog pFolderDialog = null;
                try
                {
                    pFolderDialog = CLSID.CoCreateInstance <IFileOpenDialog>(CLSID.FileOpenDialog);
                    pFolderDialog.SetOptions(pFolderDialog.GetOptions() | FOS.NOREADONLYRETURN | FOS.PICKFOLDERS);
                    pFolderDialog.SetTitle(string.Format("Select where to save \"{0}\"", album.Title));
                    pFolderDialog.SetOkButtonLabel("Save Album");

                    HRESULT hr = pFolderDialog.Show(new WindowInteropHelper(Application.Current.MainWindow).Handle);
                    if (hr.Failed)
                    {
                        return;
                    }

                    IShellItem pItem = null;
                    try
                    {
                        pItem      = pFolderDialog.GetResult();
                        folderPath = ShellUtil.GetPathFromShellItem(pItem);
                    }
                    finally
                    {
                        Utility.SafeRelease(ref pItem);
                    }
                }
                finally
                {
                    Utility.SafeRelease(ref pFolderDialog);
                }
            }
            else
            {
                var folderDialog = new System.Windows.Forms.FolderBrowserDialog
                {
                    Description         = "Choose where to save the album.",
                    ShowNewFolderButton = true,
                };
                if (folderDialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                {
                    return;
                }

                folderPath = folderDialog.SelectedPath;
            }

            album.SaveToFolder(folderPath, _OnAlbumSaveProgressCallback, null);
            Process.Start(new ProcessStartInfo {
                FileName = folderPath
            });
        }
예제 #3
0
		public SelectFolderDialog()
		{
			fod = new FileOpenDialog();
			ifod = (IFileOpenDialog)fod;

			FOS fos;
			ifod.GetOptions(out fos);
			ifod.SetOptions(fos | FOS.FOS_PICKFOLDERS);

			// Fix an apparent bug where the default folder is inside the last selected folder rather than selecting it in parent folder
			IShellItem defaultFolder;
			ifod.GetFolder(out defaultFolder);
			if (defaultFolder != null)
			{
				IShellItem parentFolder;
				defaultFolder.GetParent(out parentFolder);

				if (parentFolder != null)
				{
					ifod.SetFolder(parentFolder);
				}
			}
		}
예제 #4
0
        protected override bool RunDialog(IntPtr hwndOwner)
        {
            IntPtr          pDisplayName = IntPtr.Zero;
            IFileOpenDialog dlg          = null;
            IShellItem      shStartupDir = null;

            try
            {
                dlg = (IFileOpenDialog)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("DC1C5A9C-E88A-4dde-A5A1-60F82A20AEF7")));
                FOS fos;
                dlg.GetOptions(out fos);
                fos = fos | FOS.FOS_FORCEFILESYSTEM | FOS.FOS_PICKFOLDERS | FOS.FOS_NOCHANGEDIR;
                dlg.SetOptions(fos);

                dlg.SetTitle(this.Description);

                // What if selectedPath is empty?
                if (this.SelectedPath != string.Empty)
                {
                    var startupDir = System.IO.Path.GetFullPath(this.SelectedPath);
                    if (System.IO.Directory.Exists(startupDir))
                    {
                        Shell32.SHCreateItemFromParsingName(startupDir, IntPtr.Zero, new Guid("43826d1e-e718-42ee-bc55-a1e261c37bfe"), out shStartupDir);
                        dlg.SetFolder(shStartupDir);
                    }
                }
                // FIXME: should sig be Int32 (HRESULT)?
                Int32 hrResult = dlg.Show(hwndOwner);
                if (hrResult == -2147023673 /* HRESULT_FROM_WIN32(ERROR_CANCELLED) */)
                {
                    return(false);
                }
                else if (hrResult < 0)
                {
                    throw System.Runtime.InteropServices.Marshal.GetExceptionForHR(hrResult);
                }
                IShellItem result;
                dlg.GetResult(out result);
                result.GetDisplayName(SIGDN.FILESYSPATH, out pDisplayName);
                this.SelectedPath = System.Runtime.InteropServices.Marshal.PtrToStringUni(pDisplayName);
            }
            finally
            {
                if (pDisplayName != IntPtr.Zero)
                {
                    System.Runtime.InteropServices.Marshal.FreeCoTaskMem(pDisplayName);
                }
                if (dlg != null)
                {
                    System.Runtime.InteropServices.Marshal.FinalReleaseComObject(dlg);
                }
                if (shStartupDir != null)
                {
                    System.Runtime.InteropServices.Marshal.FinalReleaseComObject(shStartupDir);
                }
            }

            // TODO: check if selected path exists?

            return(true);
        }