static void SetFolderBrowserProperties (SelectFileDialogData data, FolderBrowserDialog dialog) { if (!string.IsNullOrEmpty (data.Title)) dialog.Description = data.Title; dialog.SelectedPath = data.CurrentFolder; }
internal static NSPopUpButton CreateFileFilterPopup (SelectFileDialogData data, NSSavePanel panel) { var filters = data.Filters; //no filtering if (filters == null || filters.Count == 0) { return null; } //filter, but no choice if (filters.Count == 1) { panel.ShouldEnableUrl = GetFileFilter (filters[0]); return null; } var popup = new NSPopUpButton (new RectangleF (0, 6, 200, 18), false); popup.SizeToFit (); var rect = popup.Frame; popup.Frame = new RectangleF (rect.X, rect.Y, 200, rect.Height); foreach (var filter in filters) popup.AddItem (filter.Name); var defaultIndex = data.DefaultFilter == null? 0 : Math.Max (0, filters.IndexOf (data.DefaultFilter)); if (defaultIndex > 0) { popup.SelectItem (defaultIndex); } panel.ShouldEnableUrl = GetFileFilter (filters[defaultIndex]); popup.Activated += delegate { panel.ShouldEnableUrl = GetFileFilter (filters[popup.IndexOfSelectedItem]); panel.Display (); }; return popup; }
public bool Run(SelectFileDialogData data) { FileDialog dlg = null; if (data.Action == Gtk.FileChooserAction.Open) dlg = new OpenFileDialog(); else if (data.Action == Gtk.FileChooserAction.Save) dlg = new SaveFileDialog(); dlg.InitialDirectory = data.CurrentFolder; if (!string.IsNullOrEmpty (data.InitialFileName)) dlg.FileName = data.InitialFileName; bool result = false; try { WinFormsRoot root = new WinFormsRoot(); if (dlg.ShowDialog(root) == DialogResult.Cancel) result = false; else { FilePath[] paths = new FilePath [dlg.FileNames.Length]; for (int n=0; n<dlg.FileNames.Length; n++) paths [n] = dlg.FileNames [n]; data.SelectedFiles = paths; result = true; } } finally { dlg.Dispose(); } return result; }
internal static void SetCommonPanelProperties(SelectFileDialogData data, NSSavePanel panel) { panel.TreatsFilePackagesAsDirectories = true; if (!string.IsNullOrEmpty(data.Title)) { panel.Title = data.Title; } if (!string.IsNullOrEmpty(data.InitialFileName)) { panel.NameFieldStringValue = data.InitialFileName; } if (!string.IsNullOrEmpty(data.CurrentFolder)) { panel.DirectoryUrl = new NSUrl(data.CurrentFolder, true); } panel.ParentWindow = NSApplication.SharedApplication.KeyWindow ?? NSApplication.SharedApplication.MainWindow; var openPanel = panel as NSOpenPanel; if (openPanel != null) { openPanel.AllowsMultipleSelection = data.SelectMultiple; openPanel.ShowsHiddenFiles = data.ShowHidden; } }
internal static void SetCommonFormProperties(SelectFileDialogData data, FileDialog dialog) { if (!string.IsNullOrEmpty(data.Title)) { dialog.Title = data.Title; } dialog.AddExtension = true; dialog.Filter = GetFilterFromData(data.Filters); dialog.FilterIndex = data.DefaultFilter == null ? 1 : GetDefaultFilterIndex(data); dialog.InitialDirectory = data.CurrentFolder; // FileDialog.FileName expects anything but a directory name. if (!Directory.Exists(data.InitialFileName)) { dialog.FileName = data.InitialFileName; } OpenFileDialog openDialog = dialog as OpenFileDialog; if (openDialog != null) { openDialog.Multiselect = data.SelectMultiple; } }
static int GetDefaultFilterIndex(SelectFileDialogData data) { var defFilter = data.DefaultFilter; int idx = data.Filters.IndexOf(defFilter) + 1; // FileDialog doesn't show the file extension when saving a file, // so we try to look fo the precise filter if none was specified. if (data.Action == Gtk.FileChooserAction.Save && defFilter.Patterns.Contains("*")) { string ext = Path.GetExtension(data.InitialFileName); if (!String.IsNullOrEmpty(ext)) { for (int i = 0; i < data.Filters.Count; i++) { var filter = data.Filters [i]; foreach (string pattern in filter.Patterns) { if (pattern.EndsWith(ext)) { return(i + 1); } } } } } return(idx); }
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; }
public bool Run(SelectFileDialogData data) { var parent = data.TransientFor ?? MessageService.RootWindow; CommonFileDialog dialog; if ((data.Action & (FileChooserAction.Open | FileChooserAction.SelectFolder)) != 0) { dialog = new CustomCommonOpenFileDialog(); } else { dialog = new CommonSaveFileDialog(); } dialog.SetCommonFormProperties(data); if (!GdkWin32.RunModalWin32Dialog(dialog, parent)) { return(false); } dialog.GetCommonFormProperties(data); return(true); }
internal static void SetCommonPanelProperties(SelectFileDialogData data, NSSavePanel panel) { panel.TreatsFilePackagesAsDirectories = true; if (!string.IsNullOrEmpty(data.Title)) { panel.Title = data.Title; } //FIXME: 10.6 only //if (!string.IsNullOrEmpty (data.InitialFileName)) // panel.NameFieldStringValue = data.InitialFileName; if (!string.IsNullOrEmpty(data.CurrentFolder)) { panel.Directory = data.CurrentFolder; } //FIXME: 10.6 only // panel.DirectoryUrl = new NSUrl (data.CurrentFolder, true); var openPanel = panel as NSOpenPanel; if (openPanel != null) { openPanel.AllowsMultipleSelection = data.SelectMultiple; } }
static void SetDefaultExtension (SelectFileDialogData data, CommonFileDialog dialog) { var defExt = data.DefaultFilter == null ? null : data.DefaultFilter.Patterns.FirstOrDefault (); if (defExt == null) return; // 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; }
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; }
public bool Run(SelectFileDialogData data) { CommonDialog dlg = null; if (data.Action == Gtk.FileChooserAction.Open) dlg = new OpenFileDialog(); else if (data.Action == Gtk.FileChooserAction.Save) dlg = new SaveFileDialog(); else if (data.Action == Gtk.FileChooserAction.SelectFolder) dlg = new FolderBrowserDialog (); if (dlg is FileDialog) SetCommonFormProperties (data, dlg as FileDialog); else SetFolderBrowserProperties (data, dlg as FolderBrowserDialog); using (dlg) { WinFormsRoot root = new WinFormsRoot(); if (dlg.ShowDialog(root) == DialogResult.Cancel) return false; if (dlg is FileDialog) { var fileDlg = dlg as OpenFileDialog; FilePath[] paths = new FilePath [fileDlg.FileNames.Length]; for (int n=0; n < fileDlg.FileNames.Length; n++) paths [n] = fileDlg.FileNames [n]; data.SelectedFiles = paths; } else { var folderDlg = dlg as FolderBrowserDialog; data.SelectedFiles = new [] { new FilePath (folderDlg.SelectedPath) }; } return true; } }
internal static void SetCommonFormProperties(SelectFileDialogData data, FileDialog dialog) { if (!string.IsNullOrEmpty(data.Title)) { dialog.Title = data.Title; } dialog.AddExtension = true; dialog.Filter = GetFilterFromData(data.Filters); dialog.FilterIndex = data.DefaultFilter == null ? 1 : GetDefaultFilterIndex(data); dialog.InitialDirectory = data.CurrentFolder; // FileDialog.FileName expects anything but a directory name. if (!Directory.Exists(data.InitialFileName)) { dialog.FileName = data.InitialFileName; } // Use the classic dialogs, as the new ones (WPF based) can't handle child controls. dialog.AutoUpgradeEnabled = false; OpenFileDialog openDialog = dialog as OpenFileDialog; if (openDialog != null) { openDialog.Multiselect = data.SelectMultiple; } }
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) }; }
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}; }
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); }
static void SetFolderBrowserProperties(SelectFileDialogData data, FolderBrowserDialog dialog) { if (!string.IsNullOrEmpty(data.Title)) { dialog.Description = data.Title; } dialog.SelectedPath = data.CurrentFolder; }
public bool Run (SelectFileDialogData data) { var options = NavDialogCreationOptions.NewFromDefaults (); NavDialog dialog = null; try { options.Modality = WindowModality.AppModal; if (!string.IsNullOrEmpty (data.Title)) options.WindowTitle = data.Title; options.OptionFlags |= NavDialogOptionFlags.DontAddTranslateItems & NavDialogOptionFlags.DontAutoTranslate & NavDialogOptionFlags.DontConfirmReplacement; if (data.SelectMultiple) options.OptionFlags |= NavDialogOptionFlags.AllowMultipleFiles; else options.OptionFlags ^= NavDialogOptionFlags.AllowMultipleFiles; //data.SelectedFiles switch (data.Action) { case FileChooserAction.CreateFolder: dialog = NavDialog.CreateNewFolderDialog (options); break; case FileChooserAction.Save: options.SaveFileName = data.InitialFileName; dialog = NavDialog.CreatePutFileDialog (options); break; case FileChooserAction.Open: dialog = NavDialog.CreateChooseFileDialog (options); break; case FileChooserAction.SelectFolder: dialog = NavDialog.CreateChooseFolderDialog (options); break; default: throw new InvalidOperationException ("Unknown action " + data.Action.ToString ()); } if (!string.IsNullOrEmpty (data.CurrentFolder)) dialog.SetLocation (data.CurrentFolder); var action = dialog.Run (); if (action == NavUserAction.Cancel || action == NavUserAction.None) return false; using (var reply = dialog.GetReply ()) { } } finally { if (dialog != null) dialog.Dispose (); if (options != null) options.Dispose (); } return true; }
bool RunDialog(SelectFileDialogData data) { Application.EnableVisualStyles(); CommonDialog dlg = null; if (data.Action == Gtk.FileChooserAction.Open) { dlg = new OpenFileDialog(); } else if (data.Action == Gtk.FileChooserAction.Save) { dlg = new SaveFileDialog(); } else if (data.Action == Gtk.FileChooserAction.SelectFolder) { dlg = new FolderBrowserDialog(); } if (dlg is FileDialog) { SetCommonFormProperties(data, dlg as FileDialog); } else { SetFolderBrowserProperties(data, dlg as FolderBrowserDialog); } using (dlg) { rootForm = new WinFormsRoot(); if (dlg.ShowDialog(rootForm) == DialogResult.Cancel) { return(false); } if (dlg is FileDialog) { var fileDlg = dlg as FileDialog; FilePath[] paths = new FilePath [fileDlg.FileNames.Length]; for (int n = 0; n < fileDlg.FileNames.Length; n++) { paths [n] = fileDlg.FileNames [n]; } data.SelectedFiles = paths; } else { var folderDlg = dlg as FolderBrowserDialog; data.SelectedFiles = new [] { new FilePath(folderDlg.SelectedPath) }; } return(true); } }
static FilePath FilterFileName (SelectFileDialogData data, string fileName) { FilePath result = fileName; // FileDialog doesn't show the file extension when saving a file and chooses the extension based // the file filter. But * is no valid extension so the default file name extension needs to be set in that case. if (result.Extension == ".*") { var ext = Path.GetExtension (data.InitialFileName); if (!string.IsNullOrEmpty (ext)) result = result.ChangeExtension (ext); } return result; }
public bool Run(SelectFileDialogData data) { var parentWindow = data.TransientFor ?? MessageService.RootWindow; parentWindow.FocusInEvent += OnParentFocusIn; bool result = RunWinUIMethod(RunDialog, data); parentWindow.FocusInEvent -= OnParentFocusIn; parentWindow.Present(); return(result); }
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 bool Run(SelectFileDialogData data) { NSSavePanel panel = null; try { bool directoryMode = data.Action != Gtk.FileChooserAction.Open; if (data.Action == Gtk.FileChooserAction.Save) { panel = new NSSavePanel(); } else { panel = new NSOpenPanel() { CanChooseDirectories = directoryMode, CanChooseFiles = !directoryMode, }; } SetCommonPanelProperties(data, panel); if (!directoryMode) { var popup = CreateFileFilterPopup(data, panel); if (popup != null) { panel.AccessoryView = popup; } } var action = RunPanel(data, panel); if (action) { data.SelectedFiles = GetSelectedFiles(panel); GtkQuartz.FocusWindow(data.TransientFor ?? MessageService.RootWindow); } else { GtkQuartz.FocusWindow(data.TransientFor ?? MessageService.RootWindow); } return(action); } finally { if (panel != null) { panel.Dispose(); } } }
internal static bool RunPanel(SelectFileDialogData data, NSSavePanel panel) { var dir = string.IsNullOrEmpty(data.CurrentFolder)? null : data.CurrentFolder; var file = string.IsNullOrEmpty(data.InitialFileName)? null : data.InitialFileName; if (panel is NSOpenPanel) { return(((NSOpenPanel)panel).RunModal(dir, file, null) != 0); } else { //FIXME: deprecated on 10.6, alternatives only on 10.6 return(panel.RunModal(dir, file) != 0); } }
static FilePath FilterFileName(SelectFileDialogData data, string fileName) { FilePath result = fileName; // FileDialog doesn't show the file extension when saving a file and chooses the extension based // the file filter. But * is no valid extension so the default file name extension needs to be set in that case. if (result.Extension == ".*") { var ext = Path.GetExtension(data.InitialFileName); if (!string.IsNullOrEmpty(ext)) { result = result.ChangeExtension(ext); } } return(result); }
public bool Run(SelectFileDialogData data) { NSSavePanel panel = null; try { if (data.Action == FileChooserAction.Save) { panel = new NSSavePanel(); } else { panel = new NSOpenPanel { CanChooseDirectories = (data.Action & FileChooserAction.FolderFlags) != 0, CanChooseFiles = (data.Action & FileChooserAction.FileFlags) != 0, CanCreateDirectories = (data.Action & FileChooserAction.CreateFolder) != 0, ResolvesAliases = false, }; } SetCommonPanelProperties(data, panel); if ((data.Action & FileChooserAction.FileFlags) != 0) { var popup = CreateFileFilterPopup(data, panel); if (popup != null) { panel.AccessoryView = popup; } } if (panel.RunModal() == 0) { GtkQuartz.FocusWindow(data.TransientFor ?? MessageService.RootWindow); return(false); } data.SelectedFiles = GetSelectedFiles(panel); GtkQuartz.FocusWindow(data.TransientFor ?? MessageService.RootWindow); return(true); } finally { if (panel != null) { panel.Dispose(); } } }
public bool Run(SelectFileDialogData data) { FileDialog dlg = null; if (data.Action == Gtk.FileChooserAction.Open) { dlg = new OpenFileDialog(); } else if (data.Action == Gtk.FileChooserAction.Save) { dlg = new SaveFileDialog(); } dlg.InitialDirectory = data.CurrentFolder; if (!string.IsNullOrEmpty(data.InitialFileName)) { dlg.FileName = data.InitialFileName; } bool result = false; try { WinFormsRoot root = new WinFormsRoot(); if (dlg.ShowDialog(root) == DialogResult.Cancel) { result = false; } else { FilePath[] paths = new FilePath [dlg.FileNames.Length]; for (int n = 0; n < dlg.FileNames.Length; n++) { paths [n] = dlg.FileNames [n]; } data.SelectedFiles = paths; result = true; } } finally { dlg.Dispose(); } return(result); }
internal static void SetCommonFormProperties (SelectFileDialogData data, FileDialog dialog) { if (!string.IsNullOrEmpty (data.Title)) dialog.Title = data.Title; dialog.AddExtension = true; dialog.Filter = GetFilterFromData (data.Filters); dialog.FilterIndex = data.DefaultFilter == null ? 1 : data.Filters.IndexOf (data.DefaultFilter) + 1; dialog.InitialDirectory = data.CurrentFolder; if (!string.IsNullOrEmpty (data.InitialFileName)) dialog.FileName = data.InitialFileName; OpenFileDialog openDialog = dialog as OpenFileDialog; if (openDialog != null) openDialog.Multiselect = data.SelectMultiple; }
internal static NSPopUpButton CreateFileFilterPopup(SelectFileDialogData data, NSSavePanel panel) { var filters = data.Filters; //no filtering if (filters == null || filters.Count == 0) { return(null); } //filter, but no choice if (filters.Count == 1) { panel.ShouldEnableUrl = GetFileFilter(filters[0]); return(null); } var popup = new NSPopUpButton(new RectangleF(0, 6, 200, 18), false); popup.SizeToFit(); var rect = popup.Frame; popup.Frame = new RectangleF(rect.X, rect.Y, 200, rect.Height); foreach (var filter in filters) { popup.AddItem(filter.Name); } var defaultIndex = data.DefaultFilter == null? 0 : Math.Max(0, filters.IndexOf(data.DefaultFilter)); if (defaultIndex > 0) { popup.SelectItem(defaultIndex); } panel.ShouldEnableUrl = GetFileFilter(filters[defaultIndex]); popup.Activated += delegate { panel.ShouldEnableUrl = GetFileFilter(filters[popup.IndexOfSelectedItem]); panel.Display(); }; return(popup); }
public bool Run (SelectFileDialogData data) { var parent = data.TransientFor ?? MessageService.RootWindow; CommonFileDialog dialog; if (data.Action == FileChooserAction.Open || data.Action == FileChooserAction.SelectFolder) dialog = new CustomCommonOpenFileDialog (); else dialog = new CommonSaveFileDialog (); SetCommonFormProperties (data, dialog); if (!GdkWin32.RunModalWin32Dialog (dialog, parent)) return false; GetCommonFormProperties (data, dialog); return true; }
internal static void SetCommonFormProperties (SelectFileDialogData data, CommonFileDialog dialog) { 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; if (data.Action == FileChooserAction.SelectFolder) { fileDialog.IsFolderPicker = true; return; } } SetFilters (data, dialog); dialog.DefaultFileName = data.InitialFileName; }
public bool Run(SelectFileDialogData data) { Application.EnableVisualStyles (); var parentWindow = data.TransientFor ?? MessageService.RootWindow; CommonDialog dlg = null; if (data.Action == Gtk.FileChooserAction.Open) dlg = new OpenFileDialog(); else if (data.Action == Gtk.FileChooserAction.Save) dlg = new SaveFileDialog(); else if (data.Action == Gtk.FileChooserAction.SelectFolder) dlg = new FolderBrowserDialog (); if (dlg is FileDialog) SetCommonFormProperties (data, dlg as FileDialog); else SetFolderBrowserProperties (data, dlg as FolderBrowserDialog); using (dlg) { WinFormsRoot root = new WinFormsRoot(); if (dlg.ShowDialog(root) == DialogResult.Cancel) { parentWindow.Present (); return false; } if (dlg is FileDialog) { var fileDlg = dlg as FileDialog; FilePath[] paths = new FilePath [fileDlg.FileNames.Length]; for (int n=0; n < fileDlg.FileNames.Length; n++) paths [n] = fileDlg.FileNames [n]; data.SelectedFiles = paths; } else { var folderDlg = dlg as FolderBrowserDialog; data.SelectedFiles = new [] { new FilePath (folderDlg.SelectedPath) }; } parentWindow.Present (); return true; } }
public bool Run (SelectFileDialogData data) { NSSavePanel panel = null; try { bool directoryMode = data.Action != Gtk.FileChooserAction.Open; if (data.Action == Gtk.FileChooserAction.Save) { panel = new NSSavePanel (); } else { panel = new NSOpenPanel () { CanChooseDirectories = directoryMode, CanChooseFiles = !directoryMode, }; } SetCommonPanelProperties (data, panel); if (!directoryMode) { var popup = CreateFileFilterPopup (data, panel); if (popup != null) { panel.AccessoryView = popup; } } var action = RunPanel (data, panel); if (action) { data.SelectedFiles = GetSelectedFiles (panel); GtkQuartz.FocusWindow (data.TransientFor ?? MessageService.RootWindow); } else { GtkQuartz.FocusWindow (data.TransientFor ?? MessageService.RootWindow); } return action; } finally { if (panel != null) panel.Dispose (); } }
public bool Run (SelectFileDialogData data) { NSSavePanel panel = null; try { if (data.Action == FileChooserAction.Save) { panel = new NSSavePanel (); } else { panel = new NSOpenPanel { CanChooseDirectories = (data.Action & FileChooserAction.FolderFlags) != 0, CanChooseFiles = (data.Action & FileChooserAction.FileFlags) != 0, CanCreateDirectories = (data.Action & FileChooserAction.CreateFolder) != 0, ResolvesAliases = false, }; } SetCommonPanelProperties (data, panel); if ((data.Action & FileChooserAction.FileFlags) != 0) { var popup = CreateFileFilterPopup (data, panel); if (popup != null) { panel.AccessoryView = popup; } } if (panel.RunModal () == 0) { GtkQuartz.FocusWindow (data.TransientFor ?? MessageService.RootWindow); return false; } data.SelectedFiles = GetSelectedFiles (panel); GtkQuartz.FocusWindow (data.TransientFor ?? MessageService.RootWindow); return true; } finally { if (panel != null) panel.Dispose (); } }
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); }
internal static void SetCommonPanelProperties (SelectFileDialogData data, NSSavePanel panel) { panel.TreatsFilePackagesAsDirectories = true; if (!string.IsNullOrEmpty (data.Title)) panel.Title = data.Title; //FIXME: 10.6 only //if (!string.IsNullOrEmpty (data.InitialFileName)) // panel.NameFieldStringValue = data.InitialFileName; if (!string.IsNullOrEmpty (data.CurrentFolder)) panel.Directory = data.CurrentFolder; //FIXME: 10.6 only // panel.DirectoryUrl = new NSUrl (data.CurrentFolder, true); var openPanel = panel as NSOpenPanel; if (openPanel != null) { openPanel.AllowsMultipleSelection = data.SelectMultiple; } }
internal static bool RunPanel (SelectFileDialogData data, NSSavePanel panel) { var dir = string.IsNullOrEmpty (data.CurrentFolder)? null : data.CurrentFolder; var file = string.IsNullOrEmpty (data.InitialFileName)? null : data.InitialFileName; if (panel is NSOpenPanel) { return ((NSOpenPanel)panel).RunModal (dir, file, null) != 0; } else { //FIXME: deprecated on 10.6, alternatives only on 10.6 return panel.RunModal (dir, file) != 0; } }
public bool Run(SelectFileDialogData data) { var options = NavDialogCreationOptions.NewFromDefaults(); NavDialog dialog = null; try { options.Modality = WindowModality.AppModal; if (!string.IsNullOrEmpty(data.Title)) { options.WindowTitle = data.Title; } options.OptionFlags |= NavDialogOptionFlags.DontAddTranslateItems & NavDialogOptionFlags.DontAutoTranslate & NavDialogOptionFlags.DontConfirmReplacement; if (data.SelectMultiple) { options.OptionFlags |= NavDialogOptionFlags.AllowMultipleFiles; } else { options.OptionFlags ^= NavDialogOptionFlags.AllowMultipleFiles; } //data.SelectedFiles switch (data.Action) { case FileChooserAction.CreateFolder: dialog = NavDialog.CreateNewFolderDialog(options); break; case FileChooserAction.Save: options.SaveFileName = data.InitialFileName; dialog = NavDialog.CreatePutFileDialog(options); break; case FileChooserAction.Open: dialog = NavDialog.CreateChooseFileDialog(options); break; case FileChooserAction.SelectFolder: dialog = NavDialog.CreateChooseFolderDialog(options); break; default: throw new InvalidOperationException("Unknown action " + data.Action.ToString()); } if (!string.IsNullOrEmpty(data.CurrentFolder)) { dialog.SetLocation(data.CurrentFolder); } var action = dialog.Run(); if (action == NavUserAction.Cancel || action == NavUserAction.None) { return(false); } using (var reply = dialog.GetReply()) { } } finally { if (dialog != null) { dialog.Dispose(); } if (options != null) { options.Dispose(); } } return(true); }
internal static void SetCommonPanelProperties (SelectFileDialogData data, NSSavePanel panel) { panel.TreatsFilePackagesAsDirectories = true; if (!string.IsNullOrEmpty (data.Title)) panel.Title = data.Title; if (!string.IsNullOrEmpty (data.InitialFileName)) panel.NameFieldStringValue = data.InitialFileName; if (!string.IsNullOrEmpty (data.CurrentFolder)) panel.DirectoryUrl = new NSUrl (data.CurrentFolder, true); panel.ParentWindow = NSApplication.SharedApplication.KeyWindow ?? NSApplication.SharedApplication.MainWindow; var openPanel = panel as NSOpenPanel; if (openPanel != null) { openPanel.AllowsMultipleSelection = data.SelectMultiple; openPanel.ShowsHiddenFiles = data.ShowHidden; } }