diff --git a/ChangeLog b/ChangeLog index 412a5e87f..ae6316580 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2005-01-20 Dan Winship + + * glib/Marshaller.cs (StringFormat): Calls String.Format and makes + sure the output has no unescaped "%"s. (For wrapping printf-style + unmanaged methods with String.Format-style managed ones.) + + * gtk/MessageDialog.custom (MessageDialog): use it. #71405. Also, + use gtk_message_dialog_new_with_markup by default, and add an + overloaded ctor that lets you use the non-markup version. + + * gtk/Gtk.metadata: hide the GtkMessageDialog ctors so we don't + get ellipsis warnings about them. + + * sample/GtkDemo/DemoApplicationWindow.cs: + * sample/GtkDemo/DemoDialog.cs: simplify the MessageDialog usage; + don't need to call String.Format separately now. + 2005-01-18 Mike Kestner * generator/Method.cs : deal with owned retvals. diff --git a/doc/ChangeLog b/doc/ChangeLog index a8cfee925..b17931498 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,9 @@ +2005-01-18 Dan Winship + + * en/GLib/Marshaller.xml (StringFormat): document + + * en/Gtk/MessageDialog.xml: update ctors + 2005-01-07 Shane Landrum * en/Glade/*: Cleaned up some parameters, added diff --git a/doc/en/GLib/Marshaller.xml b/doc/en/GLib/Marshaller.xml index 60e2edb6e..61feb49e3 100644 --- a/doc/en/GLib/Marshaller.xml +++ b/doc/en/GLib/Marshaller.xml @@ -167,5 +167,23 @@ + + + Method + + System.String + + + + + + + Wrapper for marshalling between String.Format-style methods and printf-style ones + a -style format string + arguments for + a + This is a wrapper for marshalling between managed String.Format-style methods and unmanaged printf-style ones. The managed function should take a format, and a array of , and pass that to . will format the data, and then make sure that any percent signs in the result are doubled so that they can safely be passed to an unmanaged method that expects a printf-style string (and following arguments). + + \ No newline at end of file diff --git a/doc/en/Gtk/MessageDialog.xml b/doc/en/Gtk/MessageDialog.xml index 9bdc737ba..5185c62c7 100644 --- a/doc/en/Gtk/MessageDialog.xml +++ b/doc/en/Gtk/MessageDialog.xml @@ -114,7 +114,7 @@ md.Modal = false; - + Constructor @@ -122,28 +122,56 @@ md.Modal = false; - + + Creates an instance of - an object of type - an object of type - an object of type - an object of type - an object of type - an object of type + the dialog's parent (or ) + the + the type of message dialog to display + the buttons to display + the message format string + optional arguments for + a - Creates an instance of + Creates an instance of MessageDialog md = new MessageDialog (parent_window, Gtk.DialogFlags.DestroyWithParent, - Gtk.MessageType.Error, Gtk.ButtonsType.Close, "Error loading file"); - + Gtk.MessageType.Error, Gtk.ButtonsType.Close, "Error loading file '{0}'", filename); + + + + Constructor + + + + + + + + + + + + Creates an instance of + the dialog's parent (or ) + the + the type of message dialog to display + the buttons to display + whether or not uses Pango markup + the message format string + optional arguments for + a + Like the other constructor, but allows you to pass a non-marked-up string. + + Property @@ -195,5 +223,16 @@ MessageDialog md = new MessageDialog Markup should be in Pango markup format. (TODO: check this.) + + + Constructor + + + + To be added + a + To be added + + - + \ No newline at end of file diff --git a/glib/Marshaller.cs b/glib/Marshaller.cs index 7d1b7e4e5..2f7554ce1 100644 --- a/glib/Marshaller.cs +++ b/glib/Marshaller.cs @@ -58,6 +58,14 @@ namespace GLib { return g_strdup (str); } + public static string StringFormat (string format, params object[] args) { + string ret = String.Format (format, args); + if (ret.IndexOf ('%') == -1) + return ret; + else + return ret.Replace ("%", "%%"); + } + // Argv marshalling -- unpleasantly complex, but // don't know of a better way to do it. // diff --git a/gtk/Gtk.metadata b/gtk/Gtk.metadata index 27f0928ec..c1cc02692 100644 --- a/gtk/Gtk.metadata +++ b/gtk/Gtk.metadata @@ -236,7 +236,8 @@ 1 Canceled Deactivated - 1 + 1 + 1 1 1 Destroyed diff --git a/gtk/MessageDialog.custom b/gtk/MessageDialog.custom index 81a22e6cc..a328c0866 100644 --- a/gtk/MessageDialog.custom +++ b/gtk/MessageDialog.custom @@ -16,9 +16,19 @@ [DllImport ("libgtk-win32-2.0-0.dll")] static extern IntPtr gtk_message_dialog_new (IntPtr parent_window, DialogFlags flags, MessageType type, ButtonsType bt, string msg, params object [] args); -public MessageDialog (Gtk.Window parent_window, DialogFlags flags, MessageType type, ButtonsType bt, string msg) -{ - IntPtr p = (parent_window != null) ? parent_window.Handle : ((IntPtr) 0); +[DllImport ("libgtk-win32-2.0-0.dll")] +static extern IntPtr gtk_message_dialog_new_with_markup (IntPtr parent_window, DialogFlags flags, MessageType type, ButtonsType bt, string msg, params object [] args); - Raw = gtk_message_dialog_new (p, flags, type, bt, msg, null); +public MessageDialog (Gtk.Window parent_window, DialogFlags flags, MessageType type, ButtonsType bt, bool use_markup, string format, params object[] args) +{ + IntPtr p = (parent_window != null) ? parent_window.Handle : IntPtr.Zero; + + if (format == null) + Raw = gtk_message_dialog_new (p, flags, type, bt, null, null); + else if (use_markup) + Raw = gtk_message_dialog_new_with_markup (p, flags, type, bt, GLib.Marshaller.StringFormat (format, args), null); + else + Raw = gtk_message_dialog_new (p, flags, type, bt, GLib.Marshaller.StringFormat (format, args), null); } + +public MessageDialog (Gtk.Window parent_window, DialogFlags flags, MessageType type, ButtonsType bt, string format, params object[] args) : this (parent_window, flags, type, bt, true, format, args) {} diff --git a/sample/GtkDemo/DemoApplicationWindow.cs b/sample/GtkDemo/DemoApplicationWindow.cs index 2720962d8..6dee21e39 100644 --- a/sample/GtkDemo/DemoApplicationWindow.cs +++ b/sample/GtkDemo/DemoApplicationWindow.cs @@ -138,7 +138,7 @@ namespace GtkDemo { Action action = sender as Action; - using (MessageDialog md = new MessageDialog (this, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Close, String.Format ("You activated action: {0}", action.Name))) { + using (MessageDialog md = new MessageDialog (this, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Close, "You activated action: {0}", action.Name)) { md.Run (); md.Hide (); } diff --git a/sample/GtkDemo/DemoDialog.cs b/sample/GtkDemo/DemoDialog.cs index 75170ab2e..5e0025d62 100644 --- a/sample/GtkDemo/DemoDialog.cs +++ b/sample/GtkDemo/DemoDialog.cs @@ -87,13 +87,12 @@ namespace GtkDemo private int i = 1; private void MessageDialogClicked (object o, EventArgs args) { - string message = String.Format ("This message box has been popped up the following\n number of times:\n\n {0:D} ", i); - using (Dialog dialog = new MessageDialog (this, DialogFlags.Modal | DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, - message)) { + "This message box has been popped up the following\n number of times:\n\n {0:D} ", + i)) { dialog.Run (); dialog.Hide (); }