Re: [gnome-love] example request



On Fri, 2004-06-04 at 19:51 -0400, ethan zimmerman wrote:
Yay! Thank you. The GTK+ docs need more intermediate examples like this.
Now onto the bug. hehe

If you choose Edit->Preferences, and then close the preferences window
with the window manager (delete-event), and then choose
Edit->Preferences again it can't find the preferences window (cuz it's
been destroyed?)    ...So does this mean I should connect delete-event
for the preferences window to a function that HIDES the window instead
of the current default which destroys the window?

Hmm, overlooked that use case.  I think you could do that, but I've
never done it that way.  What I would do would be to create a function
called get_pref_window, which would be something like:

GtkWidget *
get_prefs_window ()
{
        GladeXML *xml;
        GtkWidget *prefs, *close, *entry;

        xml = glade_xml_new ("app.glade", "prefs-win", NULL);
        if (!xml)
                g_error ("Failed to load glade file\n";
        prefs = glade_xml_get_widget ("xml", "prefs-win");
        close = glade_xml_get_widget (xml, "close-button");
        if (!close)
                g_error ("Could not get close button widget\n");
        g_signal_connect (G_OBJECT(close), "clicked", G_CALLBACK(close_button_cb), prefs);

        entry = glade_xml_get_widget (xml, "name-entry");
        if (!entry)
                g_error ("Could not get username entry widget\n");
        g_signal_connect (G_OBJECT(entry), "activate", G_CALLBACK(entry_activate_cb), NULL);

        return win;
}

And then change the code of pref_menu_cb to:

void
pref_menu_cb (GtkMenuItem *menuitem, gpointer data)
{
        GtkWidget *win = data;

        if (!win)
                win = get_prefs_win();
        gtk_widget_show_all (win);
}

If you do this you'll should remove the code from main() that duplicates
the functionality of get_prefs_win() and replace it with a call to
get_prefs_win().  You will need to do something similar for the quit
window.

Keith.

PS. I did not test the above code, so it might have some typos etc.




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]