/// <summary> /// Tries to set the File(s) Type Combo to match the value in /// 'defaultExtension'. Only doing this if 'this' is a Save dialog /// as it makes no sense to do this if only Opening a file. /// </summary> /// /// <param name="dialog">The native/IFileDialog instance.</param> /// private void SyncFileTypeComboToDefaultExtension(IFileDialog dialog) { // make sure it's a Save dialog and that there is a default // extension to sync to. if (!(this is CommonSaveFileDialog) || defaultExtension == null || filters.Count <= 0) { return; } // The native version of SetFileTypeIndex() requires an // unsigned integer as its parameter. This (having it be defined // as a uint right up front) avoids a cast, and the potential // problems of casting a signed value to an unsigned one. uint filtersCounter = 0; CommonFileDialogFilter filter = null; for (filtersCounter = 0; filtersCounter < filters.Count; filtersCounter++) { filter = (CommonFileDialogFilter)filters[(int)filtersCounter]; if (filter.Extensions.Contains(defaultExtension)) { // set the docType combo to match this // extension. property is a 1-based index. dialog.SetFileTypeIndex(filtersCounter + 1); // we're done, exit for break; } } }
private bool ShowDialogCore() { IFileDialog dialog = (IFileDialog) new CFileOpenDialog(); FILEOPENDIALOGOPTIONS options = dialog.GetOptions(); options |= FILEOPENDIALOGOPTIONS.FOS_PICKFOLDERS | FILEOPENDIALOGOPTIONS.FOS_FORCEFILESYSTEM | FILEOPENDIALOGOPTIONS.FOS_NOVALIDATE | FILEOPENDIALOGOPTIONS.FOS_NOTESTFILECREATE | FILEOPENDIALOGOPTIONS.FOS_DONTADDTORECENT; dialog.SetOptions(options); if (InitialFolder != null) { IShellItem folderItem = SafeNativeMethods.CreateShellItem(InitialFolder); dialog.SetFolder(folderItem); } if (DefaultFolder != null) { IShellItem folderItem = SafeNativeMethods.CreateShellItem(DefaultFolder); dialog.SetFolder(folderItem); } if (dialog.Show(SafeNativeMethods.GetActiveWindowHandle()) == HRESULT.S_OK) { Folder = dialog.GetResult().GetDisplayName(SIGDN.SIGDN_FILESYSPATH); return(true); } return(false); }
private bool RunFileDialog(IntPtr hwndOwner) { _hwndOwner = hwndOwner; IFileDialog dialog = null; try { dialog = CreateFileDialog(); SetDialogProperties(dialog); int result = dialog.Show(hwndOwner); if (result < 0) { if ((uint)result == NativeMethods.ERROR_CANCELLED) { return(false); } else { throw System.Runtime.InteropServices.Marshal.GetExceptionForHR(result); } } return(true); } finally { _hwndOwner = IntPtr.Zero; if (dialog != null) { System.Runtime.InteropServices.Marshal.FinalReleaseComObject(dialog); } } }
public ConversionFileViewPresenter(IConversionFileView view, IFileDialog dialog, ConversionFileViewMode viewMode, BatchTaskMode taskMode) { this.view = view; this.dialog = dialog; this.viewMode = viewMode; this.taskMode = taskMode; }
private void ApplyNativeSettings(IFileDialog dialog) { dialog.SetTitle(Title); dialog.SetOptions(NativeMethods.FOS.NOTESTFILECREATE | NativeMethods.FOS.FORCEFILESYSTEM | NativeMethods.FOS.PICKFOLDERS); // Apply option bitflags string directory = string.IsNullOrEmpty(FileName) ? null : System.IO.Path.GetDirectoryName(FileName); if (directory != null) { try { NativeMethods.SHCreateItemFromParsingName(directory, IntPtr.Zero, new System.Guid(IIDGuid.IShellItem), out var folder); if (folder != null) { dialog.SetFolder(folder); } dialog.SetFileName(System.IO.Path.GetFileName(FileName)); } #pragma warning disable CA1031 // 不捕获常规异常类型 catch (Exception x) #pragma warning restore CA1031 // 不捕获常规异常类型 { Debug.WriteLine(x.Message); } } }
protected override void OnTypeChange(IFileDialog dialog) { var filterData = FilterData.CreateFromFilter(Filter); dialog.GetFileTypeIndex(out var index); var entry = filterData.EntryAt(index); var ext = entry.IsAnyFilter() ? DefaultExt : entry.Extensions.FirstOrDefault(); if (!string.IsNullOrEmpty(ext)) { if (ext.StartsWith(".", StringComparison.CurrentCulture)) { ext = ext.Substring(1); } else if (ext.Length == 0) { ext = null; } dialog.SetDefaultExtension(ext); } // Resetting the name is required at this point. dialog.GetFileName(out var fileName); if (string.IsNullOrEmpty(fileName)) { fileName = FileName; } var fileNameWihtoutExtension = Path.GetFileNameWithoutExtension(fileName); dialog.SetFileName($"{fileNameWihtoutExtension}.{ext}"); }
public bool?ShowDialog() { using (new ModalDialogHelper()) { if (this.ShouldUseVistaDialog) { IFileDialog nativeFileDialog = this.NativeFileDialog; nativeFileDialog.SetTitle(this.Title); this.SetFileTypes(nativeFileDialog); try { IShellItem psi = !this.ShouldUseWebFolders ? ExpressionFileDialog.GetShellItemForPath(this.initialDirectory) : ExpressionFileDialog.GetShellItemForWebPath(this.initialDirectory); nativeFileDialog.SetDefaultFolder(psi); nativeFileDialog.SetFolder(psi); } catch (FileNotFoundException ex) { } NativeMethods.FOS pfos; nativeFileDialog.GetOptions(out pfos); nativeFileDialog.SetOptions(this.GenerateNativeDialogOptions() | pfos); return(new bool?(nativeFileDialog.Show(ExpressionFileDialog.GetPointerFromWindow(this.parentWindow)) == 0)); } FileDialog win32FileDialog = this.Win32FileDialog; this.InitializeWin32FileDialog(win32FileDialog); return(win32FileDialog.ShowDialog()); } }
private void SetFileTypes(IFileDialog dialog) { List <NativeMethods.COMDLG_FILTERSPEC> list = this.ParseFilterString(); NativeMethods.COMDLG_FILTERSPEC[] rgFilterSpec = list.ToArray(); dialog.SetFileTypes((uint)list.Count, rgFilterSpec); }
private FileSelector() { // TODO: IoC constructor injection, check on intented use in Caliburn.Micro though as was only designed to be used in framework // code, not application code. _fileDialog = new FileDialog(); _fileDialog.FileSelected += OnFileSelected; }
public HRESULT OnFileOk(IFileDialog pfd) { CancelEventArgs args = new CancelEventArgs(); parent.OnFileOk(args); return(args.Cancel ? HRESULT.S_FALSE : HRESULT.S_OK); }
public MainWindowViewModel(IFileDialog dialog) { lock (_lock) { if (_isPlaying) { return; } _isPlaying = true; MediaPlayer.LoadAsync("abstract.ogg"); MediaPlayer.MediaLoaded += _ => MediaPlayer.Play(); } _dialog = dialog; _kartExecutablePath = string.Empty; _commandLineArguments = string.Empty; _platforms = new ObservableCollection <string> { "Windows", "OSX", "Linux" }; if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { _platform = _platforms[0]; } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { _platform = _platforms[1]; } else { _platform = _platforms[2]; } _resultMessage = string.Empty; }
protected override bool RunDialog(IntPtr hwndOwner) { IFileDialog fileDialog = (IFileDialog) new FileOpenDialogRCW(); uint options; IShellItem resultItem; string szName; fileDialog.GetOptions(out options); options |= 0x2010160; fileDialog.SetOptions(options); if (!string.IsNullOrEmpty(RootFolder)) { IShellItem folderItem; if (SHCreateItemFromParsingName(RootFolder, IntPtr.Zero, Guid.Parse("43826D1E-E718-42EE-BC55-A1E261C37BFE"), out folderItem) == 0L) { fileDialog.SetFolder(folderItem); } } fileDialog.SetTitle(Title); if (fileDialog.Show(hwndOwner) == 0 && fileDialog.GetResult(out resultItem) == 0 && resultItem.GetDisplayName(0x80058000, out szName) == 0) { SelectedPath = szName; return(true); } return(false); }
private void GetResult(IFileDialog dialog) { if (Multiselect) { ((IFileOpenDialog)dialog).GetResults(out IShellItemArray results); results.GetCount(out uint count); string[] folderPaths = new string[count]; for (uint x = 0; x < count; ++x) { results.GetItemAt(x, out IShellItem item); item.GetDisplayName(NativeMethods.SIGDN.SIGDN_FILESYSPATH, out string name); folderPaths[x] = name; } SelectedPaths = folderPaths; } else { dialog.GetResult(out IShellItem item); item.GetDisplayName(NativeMethods.SIGDN.SIGDN_FILESYSPATH, out _selectedPath); } }
public static string Show(IWin32Window parent) { IFileDialog dialog = null; try { dialog = new NativeFileOpenDialog(); dialog.SetOptions(FOS.FOS_PICKFOLDERS); if (dialog.Show(parent != null ? parent.Handle : IntPtr.Zero) == 0) { string result = string.Empty; IShellItem item; dialog.GetResult(out item); return(GetFilePathFromShellItem(item)); } else { return(null); } } finally { if (dialog != null) { Marshal.FinalReleaseComObject(dialog); } } }
public HRESULT OnFileOk(IFileDialog pfd) { if( _dialog.DoFileOk(pfd) ) return HRESULT.S_OK; else return HRESULT.S_FALSE; }
internal override void GetResult(IFileDialog dialog) { if (Multiselect) { IShellItemArray results; ((IFileOpenDialog)dialog).GetResults(out results); uint count; results.GetCount(out count); var fileNames = new string[count]; for (uint x = 0; x < count; ++x) { IShellItem item; results.GetItemAt(x, out item); string name; item.GetDisplayName(NativeMethods.SIGDN.SIGDN_FILESYSPATH, out name); fileNames[x] = name; } FileNamesInternal = fileNames; } else { FileNamesInternal = null; } if (ShowReadOnly) { var customize = (IFileDialogCustomize)dialog; int selected; customize.GetSelectedControlItem(_openDropDownId, out selected); _readOnlyChecked = (selected == _readOnlyItemId); } base.GetResult(dialog); }
private bool RunFileDialog(IntPtr hwndOwner) { IFileDialog dialog = null; try { dialog = CreateFileDialog(); SetDialogProperties(dialog); int result = dialog.Show(hwndOwner); if (result < 0) { if ((uint)result == (uint)HRESULT.ERROR_CANCELLED) { return(false); } else { throw Marshal.GetExceptionForHR(result); } } return(true); } finally { if (dialog != null) { Marshal.FinalReleaseComObject(dialog); } } }
internal virtual void SetDialogProperties(IFileDialog dialog) { uint cookie; dialog.Advise(new VistaFileDialogEvents(this), out cookie); // Set the default file name if (!(_fileNames == null || _fileNames.Length == 0 || string.IsNullOrEmpty(_fileNames[0]))) { string parent = Path.GetDirectoryName(_fileNames[0]); if (parent == null || !Directory.Exists(parent)) { dialog.SetFileName(_fileNames[0]); } else { string folder = Path.GetFileName(_fileNames[0]); dialog.SetFolder(NativeMethods.CreateItemFromParsingName(parent)); dialog.SetFileName(folder); } } // Set the filter if (!string.IsNullOrEmpty(_filter)) { string[] filterElements = _filter.Split(new char[] { '|' }); NativeMethods.COMDLG_FILTERSPEC[] filter = new NativeMethods.COMDLG_FILTERSPEC[filterElements.Length / 2]; for (int x = 0; x < filterElements.Length; x += 2) { filter[x / 2].pszName = filterElements[x]; filter[x / 2].pszSpec = filterElements[x + 1]; } dialog.SetFileTypes((uint)filter.Length, filter); if (_filterIndex > 0 && _filterIndex <= filter.Length) { dialog.SetFileTypeIndex((uint)_filterIndex); } } // Default extension if (_addExtension && !string.IsNullOrEmpty(_defaultExt)) { dialog.SetDefaultExtension(_defaultExt); } // Initial directory if (!string.IsNullOrEmpty(_initialDirectory)) { IShellItem item = NativeMethods.CreateItemFromParsingName(_initialDirectory); dialog.SetDefaultFolder(item); } if (!string.IsNullOrEmpty(_title)) { dialog.SetTitle(_title); } dialog.SetOptions((_options | NativeMethods.FOS.FOS_FORCEFILESYSTEM)); }
private void SetDialogProperties(IFileDialog dialog) { // Description if (!string.IsNullOrEmpty(_description)) { if (UseDescriptionForTitle) { dialog.SetTitle(_description); } else { IFileDialogCustomize customize = (IFileDialogCustomize)dialog; customize.AddText(0, _description); } } dialog.SetOptions(NativeMethods.FOS.FOS_PICKFOLDERS | NativeMethods.FOS.FOS_FORCEFILESYSTEM | NativeMethods.FOS.FOS_FILEMUSTEXIST); if (!string.IsNullOrEmpty(_selectedPath)) { string parent = Path.GetDirectoryName(_selectedPath); if (parent == null || !Directory.Exists(parent)) { dialog.SetFileName(_selectedPath); } else { string folder = Path.GetFileName(_selectedPath); dialog.SetFolder(NativeMethods.CreateItemFromParsingName(parent)); dialog.SetFileName(folder); } } }
private void GetResult(IFileDialog dialog) { IShellItem item; dialog.GetResult(out item); item.GetDisplayName(NativeMethods.SIGDN.SIGDN_FILESYSPATH, out _selectedPath); }
/// <summary> /// Adds a location (folder, library, search connector, known folder) to the list of /// places available for the user to open or save items. This method actually adds an item /// to the <b>Favorite Links</b> or <b>Places</b> section of the Open/Save dialog. Overload method /// takes in a string for the path. /// </summary> /// <param name="path">The item to add to the places list.</param> /// <param name="location">One of the enumeration values that indicates placement of the item in the list.</param> public void AddPlace(string path, FileDialogAddPlaceLocation location) { if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException("path"); } // Get our native dialog if (nativeDialog == null) { InitializeNativeFileDialog(); nativeDialog = GetNativeFileDialog(); } // Create a native shellitem from our path IShellItem2 nativeShellItem; Guid guid = new Guid(ShellIIDGuid.IShellItem2); int retCode = ShellNativeMethods.SHCreateItemFromParsingName(path, IntPtr.Zero, ref guid, out nativeShellItem); if (!CoreErrorHelper.Succeeded(retCode)) { throw new Exception(LocalizedMessages.CommonFileDialogCannotCreateShellItem, Marshal.GetExceptionForHR(retCode)); } // Add the shellitem to the places list if (nativeDialog != null) { nativeDialog.AddPlace(nativeShellItem, (ShellNativeMethods.FileDialogAddPlacement)location); } }
private bool RunDialog(IntPtr owner) { IFileDialog dialog = null; try { dialog = new NativeFileOpenDialog(); SetDialogProperties(dialog); int result = dialog.Show(owner); if (result < 0) { if ((uint)result == (uint)HRESULT.ERROR_CANCELLED) { return(false); } else { throw System.Runtime.InteropServices.Marshal.GetExceptionForHR(result); } } GetResult(dialog); return(true); } finally { if (dialog != null) { System.Runtime.InteropServices.Marshal.FinalReleaseComObject(dialog); } } }
/// <summary> /// Tries to set the File(s) Type Combo to match the value in /// 'DefaultExtension'. Only doing this if 'this' is a Save dialog /// as it makes no sense to do this if only Opening a file. /// </summary> /// /// <param name="dialog">The native/IFileDialog instance.</param> /// private void SyncFileTypeComboToDefaultExtension(IFileDialog dialog) { // make sure it's a Save dialog and that there is a default // extension to sync to. if (!(this is CommonSaveFileDialog) || DefaultExtension == null || filters.Count <= 0) { return; } CommonFileDialogFilter filter = null; for (uint filtersCounter = 0; filtersCounter < filters.Count; filtersCounter++) { filter = (CommonFileDialogFilter)filters[(int)filtersCounter]; if (filter.Extensions.Contains(DefaultExtension)) { // set the docType combo to match this // extension. property is a 1-based index. dialog.SetFileTypeIndex(filtersCounter + 1); // we're done, exit for break; } } }
public FileDialogServiceBase() { FileDialog = CreateFileDialogAdapter(); FilesCore = new List <FileInfoWrapper>(); FileDialog.FileOk += OnDialogFileOk; FileDialog.HelpRequest += OnDialogHelpRequest; }
HRESULT IFileDialogEvents.OnFileOk(IFileDialog pfd) { if (!this._okCallback(pfd)) { return(HRESULT.S_FALSE); } return(HRESULT.S_OK); }
public ConversionSettingsPresenter(IConversionsSettingsControl control, IFileDialog dialog) { _control = control; _dialog = dialog; control.SetPresenter(this); UpdateButtons(); }
public MainViewModel(IDialog dialog, IFileDialog fileDialog) { this.dialog = dialog; this.fileDialog = fileDialog; YesNoCommand = new DelegateCommand <object>(YesNo); AlertCommand = new DelegateCommand <object>(Alert); BrowseCommand = new DelegateCommand <object>(Browse); }
internal bool DoFileOk(IFileDialog dialog) { GetResult(dialog); System.ComponentModel.CancelEventArgs e = new System.ComponentModel.CancelEventArgs(); OnFileOk(e); return(!e.Cancel); }
public HRESULT OnFileOk(IFileDialog pfd) { if (_dialog.DoFileOk(pfd)) { return(HRESULT.S_OK); } return(HRESULT.S_FALSE); }
/// <summary> /// Parses the metadata of the given <paramref name="files"/>. /// </summary> /// <param name="files">Files whose metadata to parse.</param> /// <returns>Task.</returns> private async Task ParseFiles(string[] files) { OnStatusUpdated("Trying to parse selected files..."); List <string> errors = new List <string>(); var newFiles = new List <LoadedFileViewModel>(); await Task.Run(() => { foreach (string file in files) { try { if (SUPPORTEDFILES.Contains(Path.GetExtension(file).ToLower())) { ILocalFile audioFile = _localFileFactory.CreateFile(file); if (string.IsNullOrEmpty(audioFile.Artist)) { throw new Exception("No artist name found"); } if (string.IsNullOrEmpty(audioFile.Track)) { throw new Exception("No track name found"); } var vm = new LoadedFileViewModel(audioFile); vm.ToScrobbleChanged += Vm_ToScrobbleChanged; newFiles.Add(vm); } } catch (Exception ex) { errors.Add(string.Format("{0} {1}", file, ex.Message)); } } }); Scrobbles = new ObservableCollection <LoadedFileViewModel>(Scrobbles.Concat(newFiles)); if (errors.Count > 0) { OnStatusUpdated(string.Format("Finished parsing selected files. {0} files could not be parsed", errors.Count)); if (_windowManager.MessageBoxService.ShowDialog("Some files could not be parsed. Do you want to save a text file with the files that could not be parsed?", "Error parsing files", IMessageBoxServiceButtons.YesNo) == IMessageBoxServiceResult.Yes) { IFileDialog sfd = _windowManager.CreateSaveFileDialog(); sfd.Filter = "Text Files|*.txt"; if (sfd.ShowDialog()) { _fileOperator.WriteAllLines(sfd.FileName, errors.ToArray()); } } } else { OnStatusUpdated("Successfully parsed selected files"); } }
public MyTask5(string name, int number, IFileDialog dialog, HelixViewport3D viewport) : base(name, number, dialog, viewport) { MaxPointOz = 25; MinPointOz = -25; Start = new DelegateCommand(StartTransformation); Stop = new DelegateCommand(StopTask); _myThread = new Thread(Move); }
internal NativeMethods.FOS GetCurrentOptionFlags(IFileDialog dialog) { NativeMethods.FOS currentFlags; dialog.GetOptions(out currentFlags); return currentFlags; }
private bool IsOptionSet(IFileDialog dialog, NativeMethods.FOS flag) { NativeMethods.FOS currentFlags = GetCurrentOptionFlags(dialog); return (currentFlags & flag) == flag; }
public void OnTypeChange(IFileDialog pfd) { }
public HRESULT OnFolderChanging(IFileDialog pfd, IShellItem psiFolder) { return HRESULT.S_OK; }
public void OnOverwrite(IFileDialog pfd, IShellItem psi, out NativeMethods.FDE_OVERWRITE_RESPONSE pResponse) { // TODO: Implement overwrite notification support pResponse = NativeMethods.FDE_OVERWRITE_RESPONSE.FDEOR_ACCEPT; }
public void OnSelectionChange(IFileDialog pfd) { parent.OnSelectionChanged(EventArgs.Empty); }
/// <summary> /// Adds a location (folder, library, search connector, known folder) to the list of /// places available for the user to open or save items. This method actually adds an item /// to the <b>Favorite Links</b> or <b>Places</b> section of the Open/Save dialog. Overload method /// takes in a string for the path. /// </summary> /// <param name="path">The item to add to the places list.</param> /// <param name="location">One of the enumeration values that indicates placement of the item in the list.</param> public void AddPlace(string path, FileDialogAddPlaceLocation location) { if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException("path"); } // Get our native dialog if (nativeDialog == null) { InitializeNativeFileDialog(); nativeDialog = GetNativeFileDialog(); } // Create a native shellitem from our path IShellItem2 nativeShellItem; Guid guid = new Guid(ShellIIDGuid.IShellItem2); int retCode = ShellNativeMethods.SHCreateItemFromParsingName(path, IntPtr.Zero, ref guid, out nativeShellItem); if (!CoreErrorHelper.Succeeded(retCode)) { throw new CommonControlException(LocalizedMessages.CommonFileDialogCannotCreateShellItem, Marshal.GetExceptionForHR(retCode)); } // Add the shellitem to the places list if (nativeDialog != null) { nativeDialog.AddPlace(nativeShellItem, (ShellNativeMethods.FileDialogAddPlacement)location); } }
/// <summary> /// Adds a location, such as a folder, library, search connector, or known folder, to the list of /// places available for a user to open or save items. This method actually adds an item /// to the <b>Favorite Links</b> or <b>Places</b> section of the Open/Save dialog. /// </summary> /// <param name="place">The item to add to the places list.</param> /// <param name="location">One of the enumeration values that indicates placement of the item in the list.</param> public void AddPlace(ShellContainer place, FileDialogAddPlaceLocation location) { if (place == null) { throw new ArgumentNullException("place"); } // Get our native dialog if (nativeDialog == null) { InitializeNativeFileDialog(); nativeDialog = GetNativeFileDialog(); } // Add the shellitem to the places list if (nativeDialog != null) { nativeDialog.AddPlace(place.NativeShellItem, (ShellNativeMethods.FileDialogAddPlacement)location); } }
/// <summary> /// Tries to set the File(s) Type Combo to match the value in /// 'DefaultExtension'. Only doing this if 'this' is a Save dialog /// as it makes no sense to do this if only Opening a file. /// </summary> /// /// <param name="dialog">The native/IFileDialog instance.</param> /// private void SyncFileTypeComboToDefaultExtension(IFileDialog dialog) { if (DefaultExtension == null || filters.Count <= 0) { return; } CommonFileDialogFilter filter = null; for (uint filtersCounter = 0; filtersCounter < filters.Count; filtersCounter++) { filter = (CommonFileDialogFilter)filters[(int)filtersCounter]; if (filter.Extensions.Contains(DefaultExtension)) { // set the docType combo to match this // extension. property is a 1-based index. dialog.SetFileTypeIndex(filtersCounter + 1); // we're done, exit for break; } } }
public void OnOverwrite(IFileDialog pfd, IShellItem psi, out ShellNativeMethods.FileDialogEventOverwriteResponse pResponse) { // Don't accept or reject the dialog, keep default settings pResponse = ShellNativeMethods.FileDialogEventOverwriteResponse.Default; }
public void OnShareViolation( IFileDialog pfd, IShellItem psi, out ShellNativeMethods.FileDialogEventShareViolationResponse pResponse) { // Do nothing: we will ignore share violations, // and don't register // for them, so this method should never be called. pResponse = ShellNativeMethods.FileDialogEventShareViolationResponse.Accept; }
public HResult OnFolderChanging(IFileDialog pfd, IShellItem psiFolder) { CommonFileDialogFolderChangeEventArgs args = new CommonFileDialogFolderChangeEventArgs( CommonFileDialog.GetFileNameFromShellItem(psiFolder)); if (!firstFolderChanged) { parent.OnFolderChanging(args); } return (args.Cancel ? HResult.False : HResult.Ok); }
public HResult OnFileOk(IFileDialog pfd) { CancelEventArgs args = new CancelEventArgs(); parent.OnFileOk(args); if (!args.Cancel) { // Make sure all custom properties are sync'ed if (parent.Controls != null) { foreach (CommonFileDialogControl control in parent.Controls) { CommonFileDialogTextBox textBox; CommonFileDialogGroupBox groupBox; ; if ((textBox = control as CommonFileDialogTextBox) != null) { textBox.SyncValue(); textBox.Closed = true; } // Also check subcontrols else if ((groupBox = control as CommonFileDialogGroupBox) != null) { foreach (CommonFileDialogControl subcontrol in groupBox.Items) { CommonFileDialogTextBox textbox = subcontrol as CommonFileDialogTextBox; if (textbox != null) { textbox.SyncValue(); textbox.Closed = true; } } } } } } return (args.Cancel ? HResult.False : HResult.Ok); }
public HRESULT OnFolderChanging(IFileDialog pfd, IShellItem psiFolder) { CommonFileDialogFolderChangeEventArgs args = new CommonFileDialogFolderChangeEventArgs(parent.GetFileNameFromShellItem(psiFolder)); if (!firstFolderChanged) parent.OnFolderChanging(args); return (args.Cancel ? HRESULT.S_FALSE : HRESULT.S_OK); }
public void OnFolderChange(IFileDialog pfd) { if (firstFolderChanged) { firstFolderChanged = false; parent.OnOpening(EventArgs.Empty); } else parent.OnFolderChanged(EventArgs.Empty); }
/// <summary> /// Displays the dialog. /// </summary> /// <returns>A <see cref="CommonFileDialogResult"/> object.</returns> public CommonFileDialogResult ShowDialog() { CommonFileDialogResult result; // Fetch derived native dialog (i.e. Save or Open). InitializeNativeFileDialog(); nativeDialog = GetNativeFileDialog(); // Apply outer properties to native dialog instance. ApplyNativeSettings(nativeDialog); InitializeEventSink(nativeDialog); // Clear user data if Reset has been called // since the last show. if (resetSelections) { resetSelections = false; } // Show dialog. showState = DialogShowState.Showing; int hresult = nativeDialog.Show(parentWindow); showState = DialogShowState.Closed; // Create return information. if (CoreErrorHelper.Matches(hresult, (int)HResult.Win32ErrorCanceled)) { canceled = true; result = CommonFileDialogResult.Cancel; filenames.Clear(); } else { canceled = false; result = CommonFileDialogResult.Ok; // Populate filenames if user didn't cancel. PopulateWithFileNames(filenames); // Populate the actual IShellItems PopulateWithIShellItems(items); } return result; }
public void OnTypeChange(IFileDialog pfd) { parent.OnFileTypeChanged(EventArgs.Empty); }
private void ApplyNativeSettings(IFileDialog dialog) { Debug.Assert(dialog != null, "No dialog instance to configure"); if (parentWindow == IntPtr.Zero) { if (System.Windows.Application.Current != null && System.Windows.Application.Current.MainWindow != null) { parentWindow = (new WindowInteropHelper(System.Windows.Application.Current.MainWindow)).Handle; } else if (System.Windows.Forms.Application.OpenForms.Count > 0) { parentWindow = System.Windows.Forms.Application.OpenForms[0].Handle; } } Guid guid = new Guid(ShellIIDGuid.IShellItem2); // Apply option bitflags. dialog.SetOptions(CalculateNativeDialogOptionFlags()); // Other property sets. if (title != null) { dialog.SetTitle(title); } if (initialDirectoryShellContainer != null) { dialog.SetFolder(((ShellObject)initialDirectoryShellContainer).NativeShellItem); } if (defaultDirectoryShellContainer != null) { dialog.SetDefaultFolder(((ShellObject)defaultDirectoryShellContainer).NativeShellItem); } if (!string.IsNullOrEmpty(initialDirectory)) { // Create a native shellitem from our path IShellItem2 initialDirectoryShellItem; ShellNativeMethods.SHCreateItemFromParsingName(initialDirectory, IntPtr.Zero, ref guid, out initialDirectoryShellItem); // If we get a real shell item back, // then use that as the initial folder - otherwise, // we'll allow the dialog to revert to the default folder. // (OR should we fail loudly?) if (initialDirectoryShellItem != null) dialog.SetFolder(initialDirectoryShellItem); } if (!string.IsNullOrEmpty(defaultDirectory)) { // Create a native shellitem from our path IShellItem2 defaultDirectoryShellItem; ShellNativeMethods.SHCreateItemFromParsingName(defaultDirectory, IntPtr.Zero, ref guid, out defaultDirectoryShellItem); // If we get a real shell item back, // then use that as the initial folder - otherwise, // we'll allow the dialog to revert to the default folder. // (OR should we fail loudly?) if (defaultDirectoryShellItem != null) { dialog.SetDefaultFolder(defaultDirectoryShellItem); } } // Apply file type filters, if available. if (filters.Count > 0 && !filterSet) { dialog.SetFileTypes( (uint)filters.Count, filters.GetAllFilterSpecs()); filterSet = true; SyncFileTypeComboToDefaultExtension(dialog); } if (cookieIdentifier != Guid.Empty) { dialog.SetClientGuid(ref cookieIdentifier); } // Set the default extension if (!string.IsNullOrEmpty(DefaultExtension)) { dialog.SetDefaultExtension(DefaultExtension); } // Set the default filename dialog.SetFileName(DefaultFileName); }
public CommonFileDialogResult ShowDialog() { CommonFileDialogResult result; try { // Fetch derived native dialog (i.e. Save or Open) InitializeNativeFileDialog(); nativeDialog = GetNativeFileDialog(); // Process custom controls, and validate overall state ProcessControls(); ValidateCurrentDialogState(); // Apply outer properties to native dialog instance ApplyNativeSettings(nativeDialog); InitializeEventSink(nativeDialog); // Show dialog showState = NativeDialogShowState.Showing; int hresult = nativeDialog.Show(GetHandleFromWindow(parentWindow)); showState = NativeDialogShowState.Closed; // Create return information if (ErrorHelper.Matches(hresult, Win32ErrorCode.ERROR_CANCELLED)) { canceled = true; fileNames.Clear(); } else { canceled = false; // Populate filenames - though only if user didn't cancel PopulateWithFileNames(fileNames); } result = new CommonFileDialogResult(canceled.Value); } finally { CleanUpNativeFileDialog(); } return result; }
private void InitializeEventSink(IFileDialog nativeDialog) { // Check if we even need to have a sink if (FileOk != null || FolderChanging != null || FolderChanged != null || SelectionChanged != null || FileTypeChanged != null || Opening != null || (controls != null && controls.Count > 0)) { uint cookie; nativeEventSink = new NativeDialogEventSink(this); nativeDialog.Advise(nativeEventSink, out cookie); nativeEventSink.Cookie = cookie; } }
public HRESULT OnFileOk(IFileDialog pfd) { CancelEventArgs args = new CancelEventArgs(); return (args.Cancel ? HRESULT.S_FALSE : HRESULT.S_OK); }
private void ApplyNativeSettings(IFileDialog dialog) { Debug.Assert(dialog != null, "No dialog instance to configure"); if (parentWindow == null) parentWindow = Helpers.GetDefaultOwnerWindow(); // Apply option bitflags dialog.SetOptions(CalculateNativeDialogOptionFlags()); // Other property sets dialog.SetTitle(title); // TODO: Implement other property sets }
public void OnFolderChange(IFileDialog pfd) { if (_firstFolderChanged) _firstFolderChanged = false; }
public void OnSelectionChange(IFileDialog pfd) { }
public void OnShareViolation(IFileDialog pfd, IShellItem psi, out NativeMethods.RESPONSE pResponse) { // Do nothing: we will ignore share violations, and don't register // for them, so this method should never be called pResponse = NativeMethods.RESPONSE.ACCEPT; }
/// <summary> /// Get the IFileDialogCustomize interface, preparing to add controls. /// </summary> private void GetCustomizedFileDialog() { if (customize == null) { if (nativeDialog == null) { InitializeNativeFileDialog(); nativeDialog = GetNativeFileDialog(); } customize = (IFileDialogCustomize)nativeDialog; } }
public void OnOverwrite(IFileDialog pfd, IShellItem psi, out NativeMethods.RESPONSE pResponse) { pResponse = NativeMethods.RESPONSE.ACCEPT; }