Code

r10985@tres: ted | 2006-02-25 21:56:46 -0800
[inkscape.git] / src / extension / prefdialog.cpp
1 /*
2  * Authors:
3  *   Ted Gould <ted@gould.cx>
4  *
5  * Copyright (C) 2005-2006 Authors
6  *
7  * Released under GNU GPL, read the file 'COPYING' for more information
8  */
10 #include <gtkmm/stock.h>
11 #include <glibmm/i18n.h>
13 #include "../dialogs/dialog-events.h"
15 #include "prefdialog.h"
16 #include "helpdialog.h"
18 namespace Inkscape {
19 namespace Extension {
21 /** \brief  Creates a new preference dialog for extension preferences
22     \param  name  Name of the Extension who's dialog this is
23     \param  help  The help string for the extension (NULL if none)
24     \param  controls  The extension specific widgets in the dialog
25     
26     This function initializes the dialog with the name of the extension
27     in the title.  It adds a few buttons and sets up handlers for
28     them.  It also places the passed in widgets into the dialog.
29 */
30 PrefDialog::PrefDialog (Glib::ustring name, gchar const * help, Gtk::Widget * controls) :
31     Gtk::Dialog::Dialog(name + _(" Preferences"), true, true), _help(help), _name(name)
32 {
33     Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox());
34     hbox->pack_start(*controls, true, true, 6);
35     hbox->show();
36     this->get_vbox()->pack_start(*hbox, true, true, 6);
38     Gtk::Button * help_button = add_button(Gtk::Stock::HELP, Gtk::RESPONSE_HELP);
39     if (_help == NULL)
40         help_button->set_sensitive(false);
41     add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
43     Gtk::Button * ok = add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
44     set_default_response(Gtk::RESPONSE_OK);
45     ok->grab_focus();
46     
47     GtkWidget *dlg = GTK_WIDGET(gobj());
48     sp_transientize(dlg);
50     return;
51 }
53 /** \brief  Runs the dialog
54     \return The response to the dialog
56     This function overrides the run function in the GTKmm dialog
57     class, but basically it only calls it.  This function only
58     handles the \c Gtk::RESPONSE_HELP return, and in that case it
59     brings up the help window.  All other return values are returned
60     to the calling function.
61 */
62 int
63 PrefDialog::run (void) {
64     int resp = Gtk::RESPONSE_HELP;
65     while (resp == Gtk::RESPONSE_HELP) {
66         resp = Gtk::Dialog::run();
67         if (resp == Gtk::RESPONSE_HELP) {
68             HelpDialog help(_name, _help);
69             help.run();
70             help.hide();
71         }
72     }
73     return resp;
74 }
76 }; }; /* namespace Inkscape, Extension */
78 /*
79   Local Variables:
80   mode:c++
81   c-file-style:"stroustrup"
82   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
83   indent-tabs-mode:nil
84   fill-column:99
85   End:
86 */
87 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :