Beispiel #1
0
        public virtual bool ChooseFolder(string title, string initialFolder, out string folder)
        {
            bool ret;

            using (FileChooserDialog fc = new FileChooserDialog(title, null, FileChooserAction.SelectFolder,
                                                                Translator.GetString("OK"), ResponseType.Accept,
                                                                Translator.GetString("Cancel"), ResponseType.Cancel)) {
                DialogBase.PushModalDialog(fc, "ChooseOutputFolder");

                if (!string.IsNullOrEmpty(initialFolder) && Directory.Exists(initialFolder))
                {
                    fc.SetCurrentFolder(initialFolder);
                }

                if (fc.Run() == (int)ResponseType.Accept)
                {
                    folder = fc.CurrentFolder;
                    ret    = true;
                }
                else
                {
                    folder = null;
                    ret    = false;
                }

                fc.Destroy();
                DialogBase.PopModalDialog(fc, "ChooseOutputFolder");
            }

            return(ret);
        }
Beispiel #2
0
        public virtual bool ChooseFileForSave(string title, string initialFolder, string initialFile, out string file, params FileChooserFilter [] filters)
        {
            bool ret;

            using (FileChooserDialog fc = new FileChooserDialog(title, null, FileChooserAction.Save,
                                                                Translator.GetString("Save"), ResponseType.Accept,
                                                                Translator.GetString("Cancel"), ResponseType.Cancel)) {
                DialogBase.PushModalDialog(fc, "ChooseOutputFile");

                if (!string.IsNullOrEmpty(initialFolder) && Directory.Exists(initialFolder))
                {
                    fc.SetCurrentFolder(initialFolder);
                }
                fc.CurrentName = initialFile;

                if (filters != null)
                {
                    foreach (FileChooserFilter filter in filters)
                    {
                        FileFilter ff = new FileFilter {
                            Name = filter.Name
                        };
                        foreach (string mask in filter.FileMasks)
                        {
                            ff.AddPattern(mask);
                        }

                        fc.AddFilter(ff);
                    }
                }

                if (fc.Run() == (int)ResponseType.Accept)
                {
                    file = fc.Filename;
                    ret  = true;
                }
                else
                {
                    file = null;
                    ret  = false;
                }

                fc.Destroy();
                DialogBase.PopModalDialog(fc, "ChooseOutputFile");
            }

            return(ret);
        }