Ejemplo n.º 1
0
        public bool SaveFileDialog(SaveFileDialogParams saveParams, Action <SaveFileDialogParams> callback)
        {
            WinformsSystemWindow.ShowingSystemDialog = true;
            Gtk.Application.Init();

            Gtk.FileChooserDialog fc =
                new Gtk.FileChooserDialog(saveParams.Title,
                                          null,
                                          FileChooserAction.Save,
                                          "Cancel", ResponseType.Cancel,
                                          "Save", ResponseType.Accept);

            Gtk.FileFilter filter = new Gtk.FileFilter();
            filter.Name = saveParams.Filter.Split('|')[0];
            string[] extensions = saveParams.Filter.Split('|')[1].Split(';');
            foreach (string e in extensions)
            {
                filter.AddPattern(e.ToLower());
            }
            fc.AddFilter(filter);

            //Set default filename and add file extension
            fc.CurrentName = saveParams.FileName + extensions[0].TrimStart('*');
            if (saveParams.InitialDirectory != null)
            {
                fc.SetCurrentFolder(saveParams.InitialDirectory);
            }

            fc.KeepAbove = true;

            if (fc.Run() == (int)ResponseType.Accept)
            {
                this.LastDirectoryUsed = Path.GetDirectoryName(fc.Filename);
                saveParams.FileName    = fc.Filename;
                UiThread.RunOnIdle(() =>
                {
                    callback(saveParams);
                });
            }

            fc.Destroy();
            while (Gtk.Application.EventsPending())
            {
                Gtk.Main.Iteration();
            }

            WinformsSystemWindow.ShowingSystemDialog = false;

            return(true);
        }
        public bool SaveFileDialog(SaveFileDialogParams saveParams, Action <SaveFileDialogParams> callback)
        {
            ShowFileDialog((fileText) =>
            {
                if (fileText.Length > 2)
                {
                    string[] files       = fileText.Split(';', ' ').Select(f => f.Trim('\"')).ToArray();
                    saveParams.FileName  = files[0];
                    saveParams.FileNames = files;
                }
                UiThread.RunOnIdle(() => callback?.Invoke(saveParams));
            });

            return(true);
        }
        // WinformFileDialogProvider.cs
        public bool SaveFileDialog(SaveFileDialogParams saveParams, Action <SaveFileDialogParams> callback)
        {
            WinformsSystemWindow.ShowingSystemDialog = true;

            var saveFileDialog1 = new SaveFileDialog
            {
                InitialDirectory             = saveParams.InitialDirectory,
                Filter                       = saveParams.Filter,
                FilterIndex                  = saveParams.FilterIndex,
                RestoreDirectory             = true,
                AddExtension                 = true,
                FileName                     = saveParams.FileName,
                Title                        = saveParams.Title,
                ShowHelp                     = false,
                OverwritePrompt              = true,
                CheckPathExists              = true,
                SupportMultiDottedExtensions = true,
                ValidateNames                = false
            };

            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                saveParams.FileName    = saveFileDialog1.FileName;
                this.LastDirectoryUsed = System.IO.Path.GetDirectoryName(saveParams.FileName);
            }
            else
            {
                saveParams.FileName = null;
            }

            WinformsSystemWindow.ShowingSystemDialog = false;

            UiThread.RunOnIdle(() =>
            {
                callback(saveParams);
            });

            return(true);
        }