예제 #1
0
        public static string GtkSave(IntPtr parent, FileDialogFilters filters)
        {
            if (!gtk_init_check(IntPtr.Zero, IntPtr.Zero))
            {
                throw new Exception();
            }
            var dlg = gtk_file_chooser_dialog_new("Save File", IntPtr.Zero,
                                                  GTK_FILE_CHOOSER_ACTION_SAVE,
                                                  IntPtr.Zero);

            gtk_dialog_add_button(dlg, "_Cancel", GTK_RESPONSE_CANCEL);
            gtk_dialog_add_button(dlg, "_Accept", GTK_RESPONSE_ACCEPT);
            SetFilters(dlg, filters);
            gtk_widget_realize(dlg);
            XSetTransientForHint(gdk_x11_get_default_xdisplay(),
                                 gdk_x11_drawable_get_xid(gtk_widget_get_window(dlg)), parent);
            string result = null;

            if (gtk_dialog_run(dlg) == GTK_RESPONSE_ACCEPT)
            {
                result = UnsafeHelpers.PtrToStringUTF8(gtk_file_chooser_get_filename(dlg));
            }
            WaitCleanup();
            gtk_widget_destroy(dlg);
            WaitCleanup();
            return(result);
        }
예제 #2
0
 public static string Open(FileDialogFilters filters = null)
 {
     if (Platform.RunningOS == OS.Windows)
     {
         string result = null;
         using (var ofd = NewObj("System.Windows.Forms.OpenFileDialog"))
         {
             if (parentForm != null)
             {
                 ofd.Parent = parentForm;
             }
             if (filters != null)
             {
                 ofd.Filter = SwfFilter(filters);
             }
             if (ofd.ShowDialog() == SwfOk())
             {
                 result = ofd.FileName;
             }
         }
         WinformsDoEvents();
         return(result);
     }
     else if (Platform.RunningOS == OS.Linux)
     {
         if (kdialog)
         {
             return(KDialogOpen());
         }
         else if (parentWindow != IntPtr.Zero)
         {
             return(Gtk2.GtkOpen(parentWindow, filters));
         }
         else
         {
             return(Gtk3.GtkOpen(filters));
         }
     }
     else
     {
         //Mac
         throw new NotImplementedException();
     }
 }
예제 #3
0
        static void SetFilters(IntPtr dlg, FileDialogFilters filters)
        {
            if (filters == null)
            {
                return;
            }
            foreach (var managed in filters.Filters)
            {
                var f = gtk_file_filter_new();
                gtk_file_filter_set_name(f, managed.Name);
                foreach (var ext in managed.Extensions)
                {
                    gtk_file_filter_add_pattern(f, "*." + ext);
                }
                gtk_file_chooser_add_filter(dlg, f);
            }
            //Add wildcards
            var wc = gtk_file_filter_new();

            gtk_file_filter_set_name(wc, "*.*");
            gtk_file_filter_add_pattern(wc, "*");
            gtk_file_chooser_add_filter(dlg, wc);
        }
예제 #4
0
        static string SwfFilter(FileDialogFilters filters)
        {
            var  builder = new StringBuilder();
            bool first   = true;

            foreach (var f in filters.Filters)
            {
                if (!first)
                {
                    builder.Append("|");
                }
                else
                {
                    first = false;
                }
                builder.Append(f.Name);
                builder.Append(" (");
                var exts = string.Join(";", f.Extensions.Select((x) => "*." + x));
                builder.Append(exts).Append(")|").Append(exts);
            }
            builder.Append("|All files (*.*)|*.*");
            return(builder.ToString());
        }
예제 #5
0
        public static string GtkSave(FileDialogFilters filters)
        {
            if (!gtk_init_check(IntPtr.Zero, IntPtr.Zero))
            {
                throw new Exception();
            }
            var dlg = gtk_file_chooser_dialog_new("Save File", IntPtr.Zero,
                                                  GTK_FILE_CHOOSER_ACTION_SAVE,
                                                  IntPtr.Zero);

            gtk_dialog_add_button(dlg, "_Cancel", GTK_RESPONSE_CANCEL);
            gtk_dialog_add_button(dlg, "_Accept", GTK_RESPONSE_ACCEPT);
            SetFilters(dlg, filters);
            string result = null;

            if (gtk_dialog_run_HACK(dlg) == GTK_RESPONSE_ACCEPT)
            {
                result = UnsafeHelpers.PtrToStringUTF8(gtk_file_chooser_get_filename(dlg));
            }
            WaitCleanup();
            gtk_widget_destroy(dlg);
            WaitCleanup();
            return(result);
        }