public static bool RunModalWin32Dialog(CommonFileDialog dialog, Gtk.Window parent) { while (Gtk.Application.EventsPending()) { Gtk.Application.RunIteration(); } IntPtr ph = HgdiobjGet(parent.GdkWindow); IntPtr hdlg = IntPtr.Zero; dialog.DialogOpening += delegate { try { hdlg = GetDialogHandle(dialog); SetGtkDialogHook(hdlg); } catch (Exception ex) { LoggingService.LogError("Failed to hook win32 dialog messages", ex); } }; bool result; try { result = dialog.ShowDialog(ph) == CommonFileDialogResult.Ok; } finally { if (hdlg != IntPtr.Zero) { ClearGtkDialogHook(hdlg); } } return(result); }
public void Execute(object parameter) { FrameworkElement e = parameter as FrameworkElement; while (e.Parent != null) { e = e.Parent as FrameworkElement; } var w = e as Window; using (CommonFileDialog dialog = (DialogType == DialogType.Open ? new CommonOpenFileDialog() { IsFolderPicker = false, } as CommonFileDialog : new CommonSaveFileDialog() { } as CommonFileDialog)) { dialog.Filters.Add(new CommonFileDialogFilter(FileExtension, FileExtension)); dialog.Title = Title; var f = dialog.ShowDialog(w); if (f == CommonFileDialogResult.Ok) { File = dialog.FileName; } else if (IsClearValueAfterFailNeeded) { File = null; } } }
//for some reason, the API pack doesn't expose this method from the COM interface static List <string> GetSelectedItems(CommonFileDialog dialog) { var filenames = new List <string> (); var nativeDialog = (IFileOpenDialog)dialog.nativeDialog; IShellItemArray resultsArray; uint count; try { nativeDialog.GetSelectedItems(out resultsArray); } catch (Exception ex) { //we get E_FAIL when there is no selection var ce = ex.InnerException as COMException; if (ce != null && ce.ErrorCode == -2147467259) { return(filenames); } throw; } var hr = (int)resultsArray.GetCount(out count); if (hr != 0) { throw Marshal.GetExceptionForHR(hr); } for (int i = 0; i < count; ++i) { var item = CommonFileDialog.GetShellItemAt(resultsArray, i); string val = CommonFileDialog.GetFileNameFromShellItem(item); filenames.Add(val); } return(filenames); }
static void SetDefaultExtension(SelectFileDialogData data, CommonFileDialog dialog) { var defExt = data.DefaultFilter.Patterns [0]; // FileDialog doesn't show the file extension when saving a file, // so we try to look for the precise filter if none was specified. if (!string.IsNullOrEmpty(data.InitialFileName) && data.Action == FileChooserAction.Save && defExt == "*") { string ext = Path.GetExtension(data.InitialFileName); if (!string.IsNullOrEmpty(ext)) { var pattern = "*" + ext; foreach (var f in data.Filters) { foreach (var p in f.Patterns) { if (string.Equals(p, pattern, StringComparison.OrdinalIgnoreCase)) { dialog.DefaultExtension = p.TrimStart('*', '.'); return; } } } } } defExt = defExt.Trim(); defExt = defExt.Replace("*.", null); defExt = defExt.Replace(".", null); dialog.DefaultExtension = defExt; }
private void OpenFileDialogCustomizationClicked(object sender, RoutedEventArgs e) { CommonOpenFileDialog openFileDialog = new CommonOpenFileDialog(); currentFileDialog = openFileDialog; ApplyOpenDialogSettings(openFileDialog); // set the 'allow multi-select' flag openFileDialog.Multiselect = true; openFileDialog.EnsureFileExists = true; AddOpenFileDialogCustomControls(openFileDialog); CommonFileDialogResult result = openFileDialog.ShowDialog(); if (result == CommonFileDialogResult.Ok) { string output = ""; foreach (string fileName in openFileDialog.FileNames) { output += fileName + Environment.NewLine; } output += Environment.NewLine + GetCustomControlValues(); MessageBox.Show(output, "Files Chosen", MessageBoxButton.OK, MessageBoxImage.Information); } }
private void AddOpenFileDialogCustomControls(CommonFileDialog openDialog) { // Add a geometry type ComboBox CommonFileDialogGroupBox geoBox = new CommonFileDialogGroupBox("Geometry"); CommonFileDialogComboBox geoComboBox = new CommonFileDialogComboBox("geoComboBox"); geoComboBox.Items.Add(new CommonFileDialogComboBoxItem(".fbx")); geoComboBox.Items.Add(new CommonFileDialogComboBoxItem(".obj")); geoComboBox.SelectedIndex = 1; geoBox.Items.Add(geoComboBox); openDialog.Controls.Add(geoBox); // Add a texture ComboBox CommonFileDialogGroupBox texBox = new CommonFileDialogGroupBox("Texture"); CommonFileDialogComboBox texComboBox = new CommonFileDialogComboBox("texComboBox"); texComboBox.Items.Add(new CommonFileDialogComboBoxItem(".bmp")); texComboBox.Items.Add(new CommonFileDialogComboBoxItem(".jpg")); texComboBox.Items.Add(new CommonFileDialogComboBoxItem(".png")); texComboBox.Items.Add(new CommonFileDialogComboBoxItem(".tga")); texComboBox.SelectedIndex = 2; texBox.Items.Add(texComboBox); openDialog.Controls.Add(texBox); // Create and add a separator openDialog.Controls.Add(new CommonFileDialogSeparator()); // Add a world or local space option openDialog.Controls.Add(new CommonFileDialogCheckBox("worldSpaceCheckBox", "World Space", false)); // Add a multiple objects or single merged object openDialog.Controls.Add(new CommonFileDialogCheckBox("mergeCheckBox", "Merge", false)); }
internal static void SetCommonFormProperties(this CommonFileDialog dialog, SelectFileDialogData data) { if (!string.IsNullOrEmpty(data.Title)) { dialog.Title = data.Title; } dialog.InitialDirectory = data.CurrentFolder; var fileDialog = dialog as CommonOpenFileDialog; if (fileDialog != null) { fileDialog.Multiselect = data.SelectMultiple; fileDialog.ShowHiddenItems = data.ShowHidden; if (data.Action == FileChooserAction.SelectFolder) { fileDialog.IsFolderPicker = true; return; } } SetFilters(data, dialog); dialog.DefaultFileName = data.InitialFileName; }
private FileDialog(CommonFileDialog commonFileDialog, Window wndParent, Behavior behavior, Type type) { _fd = commonFileDialog; WindowParent = wndParent; CurrentBehavior = behavior; CurrentType = type; }
private void AddCustomControls(CommonFileDialog openDialog) { // Add a RadioButtonList CommonFileDialogRadioButtonList list = new CommonFileDialogRadioButtonList("Options"); list.Items.Add(new CommonFileDialogRadioButtonListItem("Option A")); list.Items.Add(new CommonFileDialogRadioButtonListItem("Option B")); list.SelectedIndexChanged += RBLOptions_SelectedIndexChanged; list.SelectedIndex = 1; openDialog.Controls.Add(list); // Create a groupbox CommonFileDialogGroupBox groupBox = new CommonFileDialogGroupBox("Options"); // Create and add two check boxes to this group CommonFileDialogCheckBox checkA = new CommonFileDialogCheckBox("Option A", true); CommonFileDialogCheckBox checkB = new CommonFileDialogCheckBox("Option B", true); checkA.CheckedChanged += ChkOptionA_CheckedChanged; checkB.CheckedChanged += ChkOptionB_CheckedChanged; groupBox.Items.Add(checkA); groupBox.Items.Add(checkB); // Create and add a separator to this group groupBox.Items.Add(new CommonFileDialogSeparator()); // Create and add a button to this group CommonFileDialogButton btnCFDPushButton = new CommonFileDialogButton("Push Button"); btnCFDPushButton.Click += PushButton_Click; groupBox.Items.Add(btnCFDPushButton); // Add groupbox to dialog openDialog.Controls.Add(groupBox); // Add a Menu CommonFileDialogMenu menu = new CommonFileDialogMenu("Sample Menu"); CommonFileDialogMenuItem itemA = new CommonFileDialogMenuItem("Menu Item 1"); CommonFileDialogMenuItem itemB = new CommonFileDialogMenuItem("Menu Item 2"); itemA.Click += MenuOptionA_Click; itemB.Click += MenuOptionA_Click; menu.Items.Add(itemA); menu.Items.Add(itemB); openDialog.Controls.Add(menu); // Add a TextBox openDialog.Controls.Add(new CommonFileDialogLabel("Enter name")); openDialog.Controls.Add(new CommonFileDialogTextBox("textBox", Environment.UserName)); // Add a ComboBox CommonFileDialogComboBox comboBox = new CommonFileDialogComboBox(); comboBox.SelectedIndexChanged += ComboEncoding_SelectedIndexChanged; comboBox.Items.Add(new CommonFileDialogComboBoxItem("Combobox Item 1")); comboBox.Items.Add(new CommonFileDialogComboBoxItem("Combobox Item 2")); comboBox.SelectedIndex = 1; openDialog.Controls.Add(comboBox); }
protected DialogIO(CommonFileDialog dialog) { if (dialog == null) { throw new ArgumentNullException(nameof(dialog), $"{nameof(dialog)} is null."); } _DialogIO = dialog; }
static void SetFilters(SelectFileDialogData data, CommonFileDialog dialog) { foreach (var f in data.Filters) { dialog.Filters.Add(new CommonFileDialogFilter(f.Name, string.Join(",", f.Patterns))); } SetDefaultExtension(data, dialog); }
private void ApplyOpenDialogSettings(CommonFileDialog openFileDialog) { openFileDialog.Title = "Custom Open File Dialog"; openFileDialog.CookieIdentifier = openDialogGuid; // Add some standard filters. openFileDialog.Filters.Add(CommonFileDialogStandardFilters.TextFiles); openFileDialog.Filters.Add(CommonFileDialogStandardFilters.OfficeFiles); openFileDialog.Filters.Add(CommonFileDialogStandardFilters.PictureFiles); }
/// <summary>表示するコモンダイアログを生成します。</summary> /// <param name="settings">設定情報を表すIDialogSettings。</param> /// <returns>生成したコモンダイアログを表すCommonFileDialog。</returns> private CommonFileDialog createDialog(ICommonDialogSettings settings) { if (settings == null) { return(null); } CommonFileDialog dialog = null; switch (settings) { case ApiPackFolderBrowsDialogSettings f: dialog = new CommonOpenFileDialog() { IsFolderPicker = true }; break; case ApiPackOpenFileDialogSettings o: dialog = new CommonOpenFileDialog(); break; case ApiPackSaveFileDialogSettings s: dialog = new CommonSaveFileDialog(); break; default: return(null); } dialog.InitialDirectory = settings.InitialDirectory; dialog.Title = settings.Title; var filters = new List <CommonFileDialogFilter>(); switch (settings) { case ApiPackOpenFileDialogSettings f: filters = ApiPackDialogFilterCreator.Create(f.Filter); break; case ApiPackSaveFileDialogSettings s: filters = ApiPackDialogFilterCreator.Create(s.Filter); break; default: return(dialog); } filters.ForEach(f => dialog.Filters.Add(f)); return(dialog); }
static IntPtr GetDialogHandle(CommonFileDialog dialog) { var ow = (IOleWindow)dialog.nativeDialog; IntPtr handle; var hr = ow.GetWindow(out handle); if (hr != 0) { throw Marshal.GetExceptionForHR(hr); } return(handle); }
internal static void GetCommonFormProperties(SelectFileDialogData data, CommonFileDialog dialog) { var fileDialog = dialog as CommonOpenFileDialog; if (fileDialog != null) { data.SelectedFiles = fileDialog.FileNames.Select(f => (FilePath)f).ToArray(); } else { data.SelectedFiles = new[] { (FilePath)dialog.FileName } }; }
internal static void GetCommonFormProperties(this CommonFileDialog dialog, SelectFileDialogData data) { var fileDialog = dialog as CommonOpenFileDialog; if (fileDialog != null) { data.SelectedFiles = fileDialog.FileNames.Select(f => FilterFileName(data, f)).ToArray(); } else { data.SelectedFiles = new[] { FilterFileName(data, dialog.FileName) } }; }
public static string GetFilePath(this CommonFileDialog dialog) { if (dialog.ShowDialog() != CommonFileDialogResult.Ok) { return(null); } string path = dialog.FileName; if (dialog is CommonSaveFileDialog s && path == s.ReadInputFilePath() + ".*") { return(s.ReadInputFilePath()); } return(path); }
static IntPtr GetDialogHandle(CommonFileDialog dialog) { var f = typeof(CommonFileDialog).GetField("nativeDialog", BindingFlags.NonPublic | BindingFlags.Instance); var obj = f.GetValue(dialog); var ow = (IOleWindow)obj; IntPtr handle; var hr = ow.GetWindow(out handle); if (hr != 0) { throw Marshal.GetExceptionForHR(hr); } return(handle); }
internal static string Open(CommonFileDialog Dialog, CommonFileDialogFilter Filter = null) { if (Filter != null) { Dialog.Filters.Add(Filter); Dialog.DefaultExtension = Filter.Extensions.First(); } var result = Dialog.ShowDialog(); switch (result) { case CommonFileDialogResult.Ok: return(Dialog.FileName); } return(string.Empty); }
private void ApplyCommonSettings(CommonFileDialog openDialog) { openDialog.Title = "My Open File Dialog"; if (useFirstGuid) { openDialog.UsageIdentifier = dialog1Guid; } else { openDialog.UsageIdentifier = dialog2Guid; } useFirstGuid = !useFirstGuid; // Add custom file filter. openDialog.Filters.Add(new CommonFileDialogFilter("My File Types", "john,doe")); // Add some standard filters. openDialog.Filters.Add(CommonFileDialogStandardFilters.TextFiles); openDialog.Filters.Add(CommonFileDialogStandardFilters.OfficeFiles); }
//for some reason, the API pack doesn't expose this method from the COM interface static List <string> GetSelectedItems(CommonFileDialog dialog) { var filenames = new List <string> (); var nativeDialog = (IFileOpenDialog)dialog.nativeDialog; IShellItemArray resultsArray; uint count; var hr = nativeDialog.GetSelectedItems(out resultsArray); if (hr != 0) { var e = Marshal.GetExceptionForHR(hr); //we get E_FAIL when there is no selection if (hr == -2147467259) { return(filenames); } else if (e is FileNotFoundException) { return(filenames); } throw e; } hr = (int)resultsArray.GetCount(out count); if (hr != 0) { throw Marshal.GetExceptionForHR(hr); } for (int i = 0; i < count; ++i) { var item = CommonFileDialog.GetShellItemAt(resultsArray, i); string val = CommonFileDialog.GetFileNameFromShellItem(item); filenames.Add(val); } return(filenames); }
/// <summary>戻り値を設定します。</summary> /// <param name="dialog">表示したダイアログを表すFileDialog。</param> /// <param name="settings">設定情報を表すIDialogSettings。</param> private void setReturnValues(CommonFileDialog dialog, ICommonDialogSettings settings) { switch (settings) { case ApiPackOpenFileDialogSettings o: o.FileName = dialog.FileName; o.FileNames = (dialog as CommonOpenFileDialog)?.FileNames.ToList(); break; case ApiPackSaveFileDialogSettings s: s.FileName = dialog.FileName; break; case ApiPackFolderBrowsDialogSettings f: f.SelectedFolderPath = dialog.FileName; break; default: break; } }
private string BuildCmd(CommonFileDialog dialog) { List <string> cmdBuilder = new List <string>(new string[] { "--output", logFile, "--url", string.Format("\"{0}\"", url.Text), "--path", string.Format("\"{0}\"", dialog.FileName) }); if (pageStart.Value > 1) { cmdBuilder.Add("--from"); cmdBuilder.Add(pageStart.Value.ToString()); } if (pageEnd.Value > 1) { if (pageStart.Value == 1) { cmdBuilder.Add("--from"); cmdBuilder.Add("1"); } cmdBuilder.Add("--to"); cmdBuilder.Add(pageEnd.Value.ToString()); } if (profilesList.SelectedIndex > 0) { cmdBuilder.Add("--profile"); cmdBuilder.Add((string)profilesList.SelectedValue); } if (threadsNum.Value > 1) { cmdBuilder.Add("--threads"); cmdBuilder.Add("1:" + threadsNum.Value); } return(string.Join(" ", cmdBuilder)); }
private void SaveFileDialogCustomizationXamlClicked(object sender, RoutedEventArgs e) { CommonSaveFileDialog saveFileDialog = FindSaveFileDialog("CustomSaveFileDialog"); saveFileDialog.CookieIdentifier = saveDialogGuid; saveFileDialog.Filters.Add(new CommonFileDialogFilter("My App Type", "*.xyz")); saveFileDialog.DefaultExtension = "xyz"; saveFileDialog.AlwaysAppendDefaultExtension = true; saveFileDialog.Controls["textName"].Text = Environment.UserName; currentFileDialog = saveFileDialog; CommonFileDialogResult result = saveFileDialog.ShowDialog(); if (result == CommonFileDialogResult.Ok) { string output = "File Selected: " + saveFileDialog.FileName + Environment.NewLine; output += Environment.NewLine + GetCustomControlValues(); MessageBox.Show(output, "Save File Dialog Result", MessageBoxButton.OK, MessageBoxImage.Information); } }
public NativeDialogEventSink(CommonFileDialog commonDialog) => parent = commonDialog;
public static CommonFileDialogResult FormsShowDialog(this CommonFileDialog dialog, IWin32Window owner) { return((CommonFileDialogResult)typeof(CommonFileDialog) .GetMethod("ShowDialog", new[] { typeof(IntPtr) }) .Invoke(dialog, new object[] { owner.Handle })); }
public void StartBrowse() { Window parentWindow = Window.GetWindow(this); //Log.Here().Activity($"LastFileLocation is {LastFileLocation} FileLocationText: {FileLocationText}"); if (!String.IsNullOrEmpty(FileLocationText) && FileCommands.IsValidPath(FileLocationText)) { if (BrowseType == FileBrowseType.File) { if (FileCommands.IsValidFilePath(FileLocationText)) { var parentDirectory = new DirectoryInfo(FileLocationText); if (parentDirectory != null) { LastFileLocation = parentDirectory.Parent.FullName; } } else { LastFileLocation = FileLocationText; } } else { var directory = new DirectoryInfo(FileLocationText); if (directory != null) { LastFileLocation = directory.FullName; } } } if (!FileCommands.IsValidPath(LastFileLocation)) { if (AppController.Main.CurrentModule != null && AppController.Main.CurrentModule.ModuleData != null) { LastFileLocation = DefaultPaths.ModuleRootFolder(AppController.Main.CurrentModule.ModuleData); } else { LastFileLocation = DefaultPaths.RootFolder; } // Path.GetFullPath(Assembly.GetExecutingAssembly().Location); } if (BrowseType == FileBrowseType.File) { CommonFileDialog fileDialog = null; if (BrowseMode == FileBrowserMode.Open) { var openFileDialog = new CommonOpenFileDialog(); openFileDialog.Multiselect = false; fileDialog = openFileDialog; } else if (BrowseMode == FileBrowserMode.Save) { var saveFileDialog = new CommonSaveFileDialog(); saveFileDialog.AlwaysAppendDefaultExtension = false; saveFileDialog.OverwritePrompt = true; fileDialog = saveFileDialog; } if (fileDialog != null) { fileDialog.Title = OpenFileText; fileDialog.InitialDirectory = LastFileLocation; string fileName = Path.GetFileName(LastFileLocation); //if (!String.IsNullOrWhiteSpace(DefaultExt)) fileDialog.DefaultExtension = DefaultExt; if (Filters != null) { if (Filters.Count <= 0) { Filters.Add(CommonFileFilters.All); } foreach (var filter in Filters) { fileDialog.Filters.Add(new CommonFileDialogFilter(filter.Name, filter.Values)); } } else { fileDialog.Filters.Add(new CommonFileDialogFilter("All Files", "*.*")); } if (FileCommands.IsValidFilePath(FileLocationText)) { fileDialog.DefaultFileName = Path.GetFileName(FileLocationText); } else if (!String.IsNullOrWhiteSpace(DefaultFileName)) { if (!String.IsNullOrWhiteSpace(DefaultExt)) { fileDialog.DefaultFileName = DefaultFileName + DefaultExt; } else { fileDialog.DefaultFileName = DefaultFileName; } } //Log.Here().Activity($"DefaultFileName: {fileDialog.DefaultFileName}"); var result = fileDialog.ShowDialog(parentWindow); if (result == CommonFileDialogResult.Ok) { string filename = fileDialog.FileName; if (fileDialog is CommonOpenFileDialog openFileDialog) { filename = String.Join(";", openFileDialog.FileNames); } else if (fileDialog is CommonSaveFileDialog saveFileDialog) { filename = saveFileDialog.FileName; } if (!FileCommands.IsValidFilePath(filename)) { filename = filename.CleanFileName(); filename = Path.GetFullPath(filename); } SkipNext = true; if (filename.Contains("%20")) { filename = Uri.UnescapeDataString(filename); // Get rid of %20 } filename = filename.Replace(DefaultPaths.AppFolder, ""); FileLocationText = filename; LastFileLocation = Path.GetDirectoryName(FileLocationText); OnOpen?.Execute(FileLocationText); } } } else if (BrowseType == FileBrowseType.Directory) { /* * VistaFolderBrowserDialog folderDialog = new VistaFolderBrowserDialog(); * folderDialog.SelectedPath = LastFileLocation; * folderDialog.Description = OpenFileText; * folderDialog.UseDescriptionForTitle = true; * folderDialog.ShowNewFolderButton = true; * * Nullable<bool> result = folderDialog.ShowDialog(parentWindow); */ CommonFileDialog fileDialog = null; if (BrowseMode == FileBrowserMode.Open) { var openFileDialog = new CommonOpenFileDialog(); openFileDialog.Multiselect = false; openFileDialog.AllowNonFileSystemItems = true; openFileDialog.IsFolderPicker = true; fileDialog = openFileDialog; } else if (BrowseMode == FileBrowserMode.Save) { fileDialog = new CommonSaveFileDialog(); } if (fileDialog != null) { fileDialog.Title = OpenFileText; fileDialog.InitialDirectory = LastFileLocation; fileDialog.DefaultDirectory = Path.GetFullPath(DefaultPaths.RootFolder); var result = fileDialog.ShowDialog(parentWindow); if (String.IsNullOrWhiteSpace(DefaultFileName)) { if (FileCommands.IsValidFilePath(FileLocationText)) { fileDialog.DefaultFileName = Path.GetDirectoryName(FileLocationText); } } else { fileDialog.DefaultFileName = DefaultFileName; } if (result == CommonFileDialogResult.Ok) { string path = ""; if (BrowseMode == FileBrowserMode.Open && fileDialog is CommonOpenFileDialog openFileDialog) { path = openFileDialog.FileNames.First(); } else { path = fileDialog.FileName; } if (path.Contains("%20")) { path = Uri.UnescapeDataString(path); // Get rid of %20 } path = path.Replace(DefaultPaths.AppFolder, ""); SkipNext = true; FileLocationText = path; LastFileLocation = FileLocationText; OnOpen?.Execute(FileLocationText); } } } AutoScrollTextbox(); }