зеркало из https://github.com/mono/mail-archives.git
209 строки
9.0 KiB
HTML
209 строки
9.0 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
|
<HTML>
|
|
<HEAD>
|
|
<TITLE> [Gtk-sharp-list] Re: How to validate input on Gtk.Dialog?
|
|
</TITLE>
|
|
<LINK REL="Index" HREF="index.html" >
|
|
<LINK REL="made" HREF="mailto:gtk-sharp-list%40lists.ximian.com?Subject=%5BGtk-sharp-list%5D%20Re%3A%20How%20to%20validate%20input%20on%20Gtk.Dialog%3F&In-Reply-To=">
|
|
<META NAME="robots" CONTENT="index,nofollow">
|
|
<META http-equiv="Content-Type" content="text/html; charset=us-ascii">
|
|
<LINK REL="Previous" HREF="006377.html">
|
|
<LINK REL="Next" HREF="006372.html">
|
|
</HEAD>
|
|
<BODY BGCOLOR="#ffffff">
|
|
<H1>[Gtk-sharp-list] Re: How to validate input on Gtk.Dialog?</H1>
|
|
<B>Paul Wallimann</B>
|
|
<A HREF="mailto:gtk-sharp-list%40lists.ximian.com?Subject=%5BGtk-sharp-list%5D%20Re%3A%20How%20to%20validate%20input%20on%20Gtk.Dialog%3F&In-Reply-To="
|
|
TITLE="[Gtk-sharp-list] Re: How to validate input on Gtk.Dialog?">pwallimann at hotmail.com
|
|
</A><BR>
|
|
<I>Fri Sep 9 12:46:45 EDT 2005</I>
|
|
<P><UL>
|
|
<LI>Previous message: <A HREF="006377.html">[Gtk-sharp-list] How to validate input on Gtk.Dialog?
|
|
</A></li>
|
|
<LI>Next message: <A HREF="006372.html">[Gtk-sharp-list] Windows installer for .NET
|
|
</A></li>
|
|
<LI> <B>Messages sorted by:</B>
|
|
<a href="date.html#6380">[ date ]</a>
|
|
<a href="thread.html#6380">[ thread ]</a>
|
|
<a href="subject.html#6380">[ subject ]</a>
|
|
<a href="author.html#6380">[ author ]</a>
|
|
</LI>
|
|
</UL>
|
|
<HR>
|
|
<!--beginarticle-->
|
|
<PRE>Hi Rafael,
|
|
|
|
Thanks for sharing your solution. Before I got to read your solution I have
|
|
found a way to accomplish the required functionality. What I do now is
|
|
|
|
Button b = new Button(Stock.Ok);
|
|
this.ActionArea.Add(b);
|
|
b.Clicked += OnButtonOKClicked;
|
|
b.Show(); //Required to make button visible. Why not automatically?
|
|
|
|
instead of
|
|
|
|
this.AddButton(Stock.Ok, ResponseType.Ok);
|
|
|
|
|
|
In the handler OnButtonOKClicked I first do the input validation and if it
|
|
succeeds then I call
|
|
|
|
this.Respond(ResponseType.Ok);
|
|
|
|
which closes the dialog and returns to the caller.
|
|
|
|
Regards,
|
|
Paul
|
|
|
|
|
|
|
|
Rafael Teixeira wrote:
|
|
|
|
><i> Small clarification:
|
|
</I>><i>
|
|
</I>><i> I use Glade and a wrapping class generator and windowWidget is of type
|
|
</I>><i> Gtk.Dialog.
|
|
</I>><i>
|
|
</I>><i> :)
|
|
</I>><i>
|
|
</I>><i>
|
|
</I>><i> On 9/8/05, Rafael Teixeira <<A HREF="http://lists.ximian.com/mailman/listinfo/gtk-sharp-list">monoman at gmail.com</A>> wrote:
|
|
</I>>><i> I normally design a common form (window) and create a Run method somewhat
|
|
</I>>><i> like
|
|
</I>>><i>
|
|
</I>>><i> private string password;
|
|
</I>>><i>
|
|
</I>>><i> public string Run()
|
|
</I>>><i> {
|
|
</I>>><i> try {
|
|
</I>>><i> windowWidget.ShowAll();
|
|
</I>>><i> while (true) {
|
|
</I>>><i> ResponseType response = (ResponseType)windowWidget.Run();
|
|
</I>>><i> if (response == ResponseType.Ok && validate(password))
|
|
</I>>><i> break;
|
|
</I>>><i> if (response == ResponseType.Cancel) {
|
|
</I>>><i> password = null;
|
|
</I>>><i> break;
|
|
</I>>><i> }
|
|
</I>>><i> }
|
|
</I>>><i> } catch (Exception ex) {
|
|
</I>>><i> password = null;
|
|
</I>>><i> }
|
|
</I>>><i> windowWidget.Hide();
|
|
</I>>><i> return password;
|
|
</I>>><i> }
|
|
</I>>><i>
|
|
</I>>><i> some event/signal is catched to update the 'password' variable as
|
|
</I>>><i> needed, or some code like:
|
|
</I>>><i>
|
|
</I>>><i> password = entryPassword.Text;
|
|
</I>>><i>
|
|
</I>>><i> can be put before the first 'if'
|
|
</I>>><i>
|
|
</I>>><i> :)
|
|
</I>>><i>
|
|
</I>>><i> On 9/5/05, Paul Wallimann <<A HREF="http://lists.ximian.com/mailman/listinfo/gtk-sharp-list">pwallimann at hotmail.com</A>> wrote:
|
|
</I>>><i> > I am still rather new to GTK# and currently struggling with the
|
|
</I>>><i> > following: I want to implement a (modal) Login Dialog that only returns
|
|
</I>>><i> > to the calling method when the user either hits Cancel or enters the
|
|
</I>>><i> > correct password and hits OK. When the user enters the wrong password
|
|
</I>>><i> > and hits OK the dialog should remain open.
|
|
</I>>><i> >
|
|
</I>>><i> > I thought I could implement this by simply subclassing from Gtk.Dialog.
|
|
</I>>><i> > Unfortunately, the dialog gets closed immediately after either of the 2
|
|
</I>>><i> > buttons is hit and I have not found a way to execute the validation and
|
|
</I>>><i> > keep the dialog open when the password is wrong. Following is my code
|
|
</I>>><i> > (using gtk-sharp, Version=2.4.0.0):
|
|
</I>>><i> >
|
|
</I>>><i> > using System;
|
|
</I>>><i> > using Gtk;
|
|
</I>>><i> >
|
|
</I>>><i> > namespace Testing
|
|
</I>>><i> > {
|
|
</I>>><i> > public class LoginDialog : Dialog
|
|
</I>>><i> > {
|
|
</I>>><i> > public static void Main (string[] args)
|
|
</I>>><i> > {
|
|
</I>>><i> > Application.Init();
|
|
</I>>><i> >
|
|
</I>>><i> > LoginDialog dlg = new LoginDialog();
|
|
</I>>><i> > dlg.Modal = true;
|
|
</I>>><i> > int response = dlg.Run();
|
|
</I>>><i> > Console.WriteLine("Main: Response was {0}",
|
|
</I>>><i> > (ResponseType)response); dlg.Destroy();
|
|
</I>>><i> > }
|
|
</I>>><i> >
|
|
</I>>><i> > public LoginDialog()
|
|
</I>>><i> > : base()
|
|
</I>>><i> > {
|
|
</I>>><i> > this.AddButton(Stock.Cancel,
|
|
</I>>><i> > ResponseType.Cancel); this.AddButton(Stock.Ok,
|
|
</I>>><i> > ResponseType.Ok); this.Response += new
|
|
</I>>><i> > ResponseHandler(On_dialog_response);
|
|
</I>>><i> > }
|
|
</I>>><i> > private void On_dialog_response (object obj,
|
|
</I>>><i> > ResponseArgs args)
|
|
</I>>><i> > {
|
|
</I>>><i> > Console.WriteLine ("On_dialog_response: args.ResponseId =
|
|
</I>>><i> > {0}",
|
|
</I>>><i> > args.ResponseId);
|
|
</I>>><i> > if (args.ResponseId == ResponseType.Ok)
|
|
</I>>><i> > args.RetVal = false; // keep dialog open
|
|
</I>>><i> > }
|
|
</I>>><i> > protected override bool OnDeleteEvent(Gdk.Event e)
|
|
</I>>><i> > {
|
|
</I>>><i> > // This method is not called. Why?
|
|
</I>>><i> > Console.WriteLine("OnDeleteEvent: called");
|
|
</I>>><i> > return false;
|
|
</I>>><i> > }
|
|
</I>>><i> > }
|
|
</I>>><i> > }
|
|
</I>>><i> >
|
|
</I>>><i> >
|
|
</I>>><i> > I would appreciate if someone could tell me how to do it correctly or
|
|
</I>>><i> > point me to an appropriate resource on the internet. Thanks in advance.
|
|
</I>>><i> >
|
|
</I>>><i> > Regards,
|
|
</I>>><i> > Paul Wallimann
|
|
</I>>><i> >
|
|
</I>>><i> > _______________________________________________
|
|
</I>>><i> > Gtk-sharp-list maillist - <A HREF="http://lists.ximian.com/mailman/listinfo/gtk-sharp-list">Gtk-sharp-list at lists.ximian.com</A>
|
|
</I>>><i> > <A HREF="http://lists.ximian.com/mailman/listinfo/gtk-sharp-list">http://lists.ximian.com/mailman/listinfo/gtk-sharp-list</A>
|
|
</I>>><i> >
|
|
</I>>><i>
|
|
</I>>><i>
|
|
</I>>><i> --
|
|
</I>>><i> Rafael "Monoman" Teixeira
|
|
</I>>><i> ---------------------------------------
|
|
</I>>><i> I'm trying to become a "Rosh Gadol" before my own eyes.
|
|
</I>>><i> See <A HREF="http://www.joelonsoftware.com/items/2004/12/06.html">http://www.joelonsoftware.com/items/2004/12/06.html</A> for enlightment.
|
|
</I>>><i> It hurts!
|
|
</I>>><i>
|
|
</I>><i>
|
|
</I>><i>
|
|
</I>
|
|
|
|
</PRE>
|
|
|
|
<!--endarticle-->
|
|
<HR>
|
|
<P><UL>
|
|
<!--threads-->
|
|
<LI>Previous message: <A HREF="006377.html">[Gtk-sharp-list] How to validate input on Gtk.Dialog?
|
|
</A></li>
|
|
<LI>Next message: <A HREF="006372.html">[Gtk-sharp-list] Windows installer for .NET
|
|
</A></li>
|
|
<LI> <B>Messages sorted by:</B>
|
|
<a href="date.html#6380">[ date ]</a>
|
|
<a href="thread.html#6380">[ thread ]</a>
|
|
<a href="subject.html#6380">[ subject ]</a>
|
|
<a href="author.html#6380">[ author ]</a>
|
|
</LI>
|
|
</UL>
|
|
|
|
<hr>
|
|
<a href="http://lists.ximian.com/mailman/listinfo/gtk-sharp-list">More information about the Gtk-sharp-list
|
|
mailing list</a><br>
|
|
</body></html>
|