protected DialogResult InvokeDialog() { if (dispatcher.CheckAccess()) { return((DialogResult)Dialog.ShowDialog(parentWindow)); } return(dispatcher.Invoke(() => (DialogResult)Dialog.ShowDialog(parentWindow))); }
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; } } }
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 bool?ShowDialog() { switch (_fd.ShowDialog(WindowParent)) { case CommonFileDialogResult.Ok: return(true); case CommonFileDialogResult.None: return(false); case CommonFileDialogResult.Cancel: return(null); default: return(null); } }
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); }
public virtual MessageBoxResult ShowDialog() { var result = _DialogIO.ShowDialog(); switch (result) { case CommonFileDialogResult.Ok: return(MessageBoxResult.OK); case CommonFileDialogResult.Cancel: return(MessageBoxResult.Cancel); case CommonFileDialogResult.None: default: return(MessageBoxResult.None); } }
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); }
protected Task InvokeDialog() { return(dispatcher.InvokeAsync(() => { var result = Dialog.ShowDialog(); switch (result) { case CommonFileDialogResult.None: Result = DialogResult.None; break; case CommonFileDialogResult.Ok: Result = DialogResult.Ok; break; case CommonFileDialogResult.Cancel: Result = DialogResult.Cancel; break; default: throw new ArgumentOutOfRangeException(); } })); }
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(); }
public CommonFileDialogResult ShowDialog() { return(dlg.ShowDialog()); }