1 /*
2 * Authors:
3 * Ted Gould <ted@gould.cx>
4 *
5 * Copyright (C) 2005-2007 Authors
6 *
7 * Released under GNU GPL, read the file 'COPYING' for more information
8 */
10 #include <gtkmm/stock.h>
11 #include <gtkmm/checkbutton.h>
12 #include <gtkmm/separator.h>
13 #include <glibmm/i18n.h>
15 #include "../dialogs/dialog-events.h"
16 #include "xml/repr.h"
18 // Used to get SP_ACTIVE_DESKTOP
19 #include "inkscape.h"
20 #include "desktop.h"
22 #include "preferences.h"
23 #include "effect.h"
25 #include "prefdialog.h"
28 namespace Inkscape {
29 namespace Extension {
32 /** \brief Creates a new preference dialog for extension preferences
33 \param name Name of the Extension who's dialog this is
34 \param help The help string for the extension (NULL if none)
35 \param controls The extension specific widgets in the dialog
37 This function initializes the dialog with the name of the extension
38 in the title. It adds a few buttons and sets up handlers for
39 them. It also places the passed in widgets into the dialog.
40 */
41 PrefDialog::PrefDialog (Glib::ustring name, gchar const * help, Gtk::Widget * controls, ExecutionEnv * exEnv, Effect * effect) :
42 Gtk::Dialog::Dialog(_(name.c_str()), true, true),
43 _help(help),
44 _name(name),
45 _exEnv(exEnv),
46 _button_ok(NULL),
47 _button_cancel(NULL),
48 _button_preview(NULL),
49 _button_pinned(NULL),
50 _param_preview(NULL),
51 _param_pinned(NULL),
52 _effect(effect)
53 {
54 Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox());
55 hbox->pack_start(*controls, true, true, 6);
56 hbox->show();
57 this->get_vbox()->pack_start(*hbox, true, true, 6);
59 /*
60 Gtk::Button * help_button = add_button(Gtk::Stock::HELP, Gtk::RESPONSE_HELP);
61 if (_help == NULL)
62 help_button->set_sensitive(false);
63 */
64 _button_cancel = add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
65 _button_cancel->set_use_stock(true);
67 _button_ok = add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
68 _button_ok->set_use_stock(true);
69 set_default_response(Gtk::RESPONSE_OK);
70 _button_ok->grab_focus();
72 // If we're working with an effect that can be live and
73 // the dialog can be pinned, put those options in too
74 if (_exEnv != NULL) {
75 Gtk::HSeparator * sep = Gtk::manage(new Gtk::HSeparator());
76 sep->show();
77 this->get_vbox()->pack_start(*sep, true, true, 4);
79 hbox = Gtk::manage(new Gtk::HBox());
80 _button_preview = Gtk::manage(new Gtk::CheckButton(_("Live Preview")));
81 _button_preview->show();
82 _button_pinned = Gtk::manage(new Gtk::CheckButton(_("Pin Dialog")));
83 _button_pinned->show();
84 hbox->pack_start(*_button_preview, true, true,6);
85 hbox->pack_start(*_button_pinned, true, true,6);
86 hbox->show();
87 this->get_vbox()->pack_start(*hbox, true, true, 6);
89 preview_toggle();
90 pinned_toggle();
91 _signal_preview.connect(sigc::mem_fun(this, &PrefDialog::preview_toggle));
92 _signal_pinned.connect(sigc::mem_fun(this, &PrefDialog::pinned_toggle));
93 }
95 GtkWidget *dlg = GTK_WIDGET(gobj());
96 sp_transientize(dlg);
98 return;
99 }
101 PrefDialog::~PrefDialog ( )
102 {
103 if (_param_preview != NULL) {
104 delete _param_preview;
105 }
106 if (_param_pinned != NULL) {
107 delete _param_pinned;
108 }
110 return;
111 }
113 /** \brief Runs the dialog
114 \return The response to the dialog
116 This function overrides the run function in the GTKmm dialog
117 class, but basically it only calls it. This function only
118 handles the \c Gtk::RESPONSE_HELP return, and in that case it
119 brings up the help window. All other return values are returned
120 to the calling function.
121 */
122 int
123 PrefDialog::run (void) {
124 int resp = Gtk::RESPONSE_HELP;
125 while (resp == Gtk::RESPONSE_HELP) {
126 resp = Gtk::Dialog::run();
127 if (resp == Gtk::RESPONSE_HELP) {
128 /*
129 if (_helpDialog == NULL) {
130 _helpDialog = new HelpDialog(_help);
131 }
132 */
133 }
134 }
135 return resp;
136 }
138 void
139 PrefDialog::setPreviewState (Glib::ustring state) {
141 }
143 void
144 PrefDialog::preview_toggle (void) {
145 if(_param_preview->get_bool(NULL, NULL) && !_param_pinned->get_bool(NULL, NULL)) {
146 //std::cout << "Live Preview" << std::endl;
147 } else {
148 //std::cout << "No Preview" << std::endl;
149 }
150 }
152 void
153 PrefDialog::pinned_toggle (void) {
154 if (_param_pinned->get_bool(NULL, NULL)) {
155 _button_preview->set_sensitive(false);
156 preview_toggle();
157 set_modal(false);
159 _button_ok->set_label(Gtk::Stock::EXECUTE.id);
160 _button_cancel->set_label(Gtk::Stock::CLOSE.id);
161 } else {
162 _button_preview->set_sensitive(true);
163 set_modal(true);
165 _button_ok->set_label(Gtk::Stock::OK.id);
166 _button_cancel->set_label(Gtk::Stock::CANCEL.id);
167 }
168 }
170 void
171 PrefDialog::on_response (int signal) {
172 if (!_param_pinned->get_bool(NULL, NULL)) {
173 // Not my job if we're not pinned
174 // It's the execution environment's job
175 return;
176 }
178 if (signal == Gtk::RESPONSE_OK) {
179 _effect->effect(SP_ACTIVE_DESKTOP);
180 }
182 this->hide();
183 delete this;
184 }
186 #include "internal/clear-n_.h"
188 const char * PrefDialog::pinned_param_xml = "<param name=\"__pinned__\" type=\"boolean\" gui-text=\"" N_("Pin Dialog") "\" gui-description=\"" N_("Toggles whether the dialog stays for multiple executions or disappears after one") "\" scope=\"user\">false</param>";
189 const char * PrefDialog::live_param_xml = "<param name=\"__live_effect__\" type=\"boolean\" gui-text=\"" N_("Live Preview") "\" gui-description=\"" N_("Controls whether the effect settings are rendered live on canvas") "\" scope=\"user\">false</param>";
191 }; }; /* namespace Inkscape, Extension */
193 /*
194 Local Variables:
195 mode:c++
196 c-file-style:"stroustrup"
197 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
198 indent-tabs-mode:nil
199 fill-column:99
200 End:
201 */
202 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :