PdfMod.Gui.Client.CreateChooser C# (CSharp) Method

CreateChooser() public method

public CreateChooser ( string title, FileChooserAction action ) : Gtk.FileChooserDialog
title string
action FileChooserAction
return Gtk.FileChooserDialog
        public Gtk.FileChooserDialog CreateChooser (string title, FileChooserAction action)
        {
            var chooser = new Gtk.FileChooserDialog (title, this.Window, action) {
                DefaultResponse = ResponseType.Ok
            };
            chooser.AddButton (Stock.Cancel, ResponseType.Cancel);
            chooser.AddFilter (GtkUtilities.GetFileFilter (Catalog.GetString ("PDF Documents"), new string [] {"pdf"}));
            chooser.AddFilter (GtkUtilities.GetFileFilter (Catalog.GetString ("All Files"), new string [] {"*"}));

            var dirs = new string [] { "DOWNLOAD", "DOCUMENTS" }.Select (s => GetXdgDir (s))
                                                                .Where (d => d != null)
                                                                .ToArray ();
            Hyena.Gui.GtkUtilities.SetChooserShortcuts (chooser, dirs);

            return chooser;
        }

Usage Example

Beispiel #1
0
        // File menu actions

        void OnOpen(object o, EventArgs args)
        {
            var chooser = app.CreateChooser(Catalog.GetString("Select PDF"), FileChooserAction.Open);

            chooser.SelectMultiple = true;
            chooser.AddButton(Stock.Open, ResponseType.Ok);

            if (app.Document != null)
            {
                chooser.SetCurrentFolder(System.IO.Path.GetDirectoryName(app.Document.SuggestedSavePath));
            }
            else
            {
                chooser.SetCurrentFolder(Client.Configuration.LastOpenFolder);
            }

            var response  = chooser.Run();
            var filenames = chooser.Filenames;

            chooser.Destroy();

            if (response == (int)ResponseType.Ok)
            {
                Client.RunIdle(delegate {
                    foreach (var file in filenames)
                    {
                        app.LoadPath(file);
                    }
                });
            }
        }