* 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.

svn path=/trunk/gtk-sharp/; revision=39256
This commit is contained in:
Dan Winship 2005-01-20 15:45:13 +00:00
parent a5ea868d90
commit 67e7fc486b
9 changed files with 119 additions and 21 deletions

View File

@ -1,3 +1,20 @@
2005-01-20 Dan Winship <danw@novell.com>
* 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 <mkestner@novell.com>
* generator/Method.cs : deal with owned retvals.

View File

@ -1,3 +1,9 @@
2005-01-18 Dan Winship <danw@novell.com>
* en/GLib/Marshaller.xml (StringFormat): document
* en/Gtk/MessageDialog.xml: update ctors
2005-01-07 Shane Landrum <epicene@pobox.com>
* en/Glade/*: Cleaned up some parameters, added

View File

@ -167,5 +167,23 @@
</remarks>
</Docs>
</Member>
<Member MemberName="StringFormat">
<MemberSignature Language="C#" Value="public static string StringFormat (string format, object [] args);" />
<MemberType>Method</MemberType>
<ReturnValue>
<ReturnType>System.String</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="format" Type="System.String" />
<Parameter Name="args" Type="System.Object[]" />
</Parameters>
<Docs>
<summary>Wrapper for marshalling between String.Format-style methods and printf-style ones</summary>
<param name="format">a <see cref="M:System.Format" />-style format string</param>
<param name="args">arguments for <paramref name="format" /></param>
<returns>a <see cref="T:System.String" /></returns>
<remarks>This is a wrapper for marshalling between managed String.Format-style methods and unmanaged printf-style ones. The managed function should take a <see cref="T:System.String" /> format, and a <see langword="params" /> array of <see cref="T:System.Object" />, and pass that to <see cref="M:GLib.Marshaller.StringFormat" />. <see cref="M:GLib.Marshaller.StringFormat" /> 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).</remarks>
</Docs>
</Member>
</Members>
</Type>

View File

@ -114,7 +114,7 @@ md.Modal = false;
</Docs>
</Member>
<Member MemberName=".ctor">
<MemberSignature Language="C#" Value="public MessageDialog (Gtk.Window parent_window, Gtk.DialogFlags flags, Gtk.MessageType type, Gtk.ButtonsType bt, string msg);" />
<MemberSignature Language="C#" Value="public MessageDialog (Gtk.Window parent_window, Gtk.DialogFlags flags, Gtk.MessageType type, Gtk.ButtonsType bt, string format, object [] args);" />
<MemberType>Constructor</MemberType>
<ReturnValue />
<Parameters>
@ -122,28 +122,56 @@ md.Modal = false;
<Parameter Name="flags" Type="Gtk.DialogFlags" />
<Parameter Name="type" Type="Gtk.MessageType" />
<Parameter Name="bt" Type="Gtk.ButtonsType" />
<Parameter Name="msg" Type="System.String" />
<Parameter Name="format" Type="System.String" />
<Parameter Name="args" Type="System.Object[]" />
</Parameters>
<Docs>
<summary>Creates an instance of <see cref="T:Gtk.MessageDialog" /></summary>
<param name="parent_window">an object of type <see cref="T:Gtk.Window" /></param>
<param name="flags">an object of type <see cref="T:Gtk.DialogFlags" /></param>
<param name="type">an object of type <see cref="T:Gtk.MessageType" /></param>
<param name="bt">an object of type <see cref="T:Gtk.ButtonsType" /></param>
<param name="msg">an object of type <see cref="T:System.String" /></param>
<returns>an object of type <see cref="T:Gtk.MessageDialog" /></returns>
<param name="parent_window">the dialog's parent <see cref="T:Gtk.Window" /> (or <see langword="null" />)</param>
<param name="flags">the <see cref="T:Gtk.DialogFlags" /></param>
<param name="type">the type of message dialog to display</param>
<param name="bt">the buttons to display</param>
<param name="format">the message format string</param>
<param name="args">optional arguments for <paramref name="format" /></param>
<returns>a <see cref="T:Gtk.MessageDialog" /></returns>
<remarks>
<para>
Creates an instance of <see cref="T:Gtk.MessageDialog" /><example>
Creates an instance of <see cref="T:Gtk.MessageDialog" /><example>
<code lang="C#">
MessageDialog md = new MessageDialog
(parent_window, Gtk.DialogFlags.DestroyWithParent,
Gtk.MessageType.Error, Gtk.ButtonsType.Close, "Error loading file");
</code>
Gtk.MessageType.Error, Gtk.ButtonsType.Close, "Error loading file '{0}'", filename);
</code>
</example></para>
</remarks>
</Docs>
</Member>
<Member MemberName=".ctor">
<MemberSignature Language="C#" Value="public MessageDialog (Gtk.Window parent_window, Gtk.DialogFlags flags, Gtk.MessageType type, Gtk.ButtonsType bt, bool use_markup, string format, object [] args);" />
<MemberType>Constructor</MemberType>
<ReturnValue />
<Parameters>
<Parameter Name="parent_window" Type="Gtk.Window" />
<Parameter Name="flags" Type="Gtk.DialogFlags" />
<Parameter Name="type" Type="Gtk.MessageType" />
<Parameter Name="bt" Type="Gtk.ButtonsType" />
<Parameter Name="use_markup" Type="System.Boolean" />
<Parameter Name="format" Type="System.String" />
<Parameter Name="args" Type="System.Object[]" />
</Parameters>
<Docs>
<summary>Creates an instance of <see cref="T:Gtk.MessageDialog" /></summary>
<param name="parent_window">the dialog's parent <see cref="T:Gtk.Window" /> (or <see langword="null" />)</param>
<param name="flags">the <see cref="T:Gtk.DialogFlags" /></param>
<param name="type">the type of message dialog to display</param>
<param name="bt">the buttons to display</param>
<param name="use_markup">whether or not <paramref name="format" /> uses Pango markup</param>
<param name="format">the message format string</param>
<param name="args">optional arguments for <paramref name="format" /></param>
<returns>a <see cref="T:Gtk.MessageDialog" /></returns>
<remarks>Like the other constructor, but allows you to pass a non-marked-up string.</remarks>
</Docs>
</Member>
<Member MemberName="MessageType">
<MemberSignature Language="C#" Value="public Gtk.MessageType MessageType { get; };" />
<MemberType>Property</MemberType>
@ -195,5 +223,16 @@ MessageDialog md = new MessageDialog
<remarks>Markup should be in Pango markup format. (TODO: check this.)</remarks>
</Docs>
</Member>
<Member MemberName=".ctor">
<MemberSignature Language="C#" Value="protected MessageDialog ();" />
<MemberType>Constructor</MemberType>
<ReturnValue />
<Parameters />
<Docs>
<summary>To be added</summary>
<returns>a <see cref="T:Gtk.MessageDialog" /></returns>
<remarks>To be added</remarks>
</Docs>
</Member>
</Members>
</Type>
</Type>

View File

@ -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.
//

View File

@ -236,7 +236,8 @@
<attr path="/api/namespace/object[@cname='GtkMenu']/method[@name='SetScreen']" name="new_flag">1</attr>
<attr path="/api/namespace/object[@cname='GtkMenuShell']/signal[@name='Cancel']" name="name">Canceled</attr>
<attr path="/api/namespace/object[@cname='GtkMenuShell']/signal[@name='Deactivate']" name="name">Deactivated</attr>
<attr path="/api/namespace/object[@cname='GtkMessageDialog']/constructor[@cname='gtk_message_dialog_new']/*/*[@type='GtkWindow*']" name="null_ok">1</attr>
<attr path="/api/namespace/object[@cname='GtkMessageDialog']/constructor[@cname='gtk_message_dialog_new']" name="hidden">1</attr>
<attr path="/api/namespace/object[@cname='GtkMessageDialog']/constructor[@cname='gtk_message_dialog_new_with_markup']" name="hidden">1</attr>
<attr path="/api/namespace/object[@cname='GtkObject']/constructor[@cname='gtk_object_new']" name="hidden">1</attr>
<attr path="/api/namespace/object[@cname='GtkObject']/method[@name='Destroy']" name="hidden">1</attr>
<attr path="/api/namespace/object[@cname='GtkObject']/signal[@name='Destroy']" name="name">Destroyed</attr>

View File

@ -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) {}

View File

@ -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 ();
}

View File

@ -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 ();
}