66a04dc1def0fb7c9b4283aaaf7fff25254eefa6
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 if (_param_preview == NULL) {
76 XML::Document * doc = sp_repr_read_mem(live_param_xml, strlen(live_param_xml), NULL);
77 _param_preview = Parameter::make(doc->root(), _exEnv->_effect);
78 }
79 if (_param_pinned == NULL) {
80 XML::Document * doc = sp_repr_read_mem(pinned_param_xml, strlen(pinned_param_xml), NULL);
81 _param_pinned = Parameter::make(doc->root(), _exEnv->_effect);
82 }
84 Gtk::HSeparator * sep = Gtk::manage(new Gtk::HSeparator());
85 sep->show();
86 this->get_vbox()->pack_start(*sep, true, true, 4);
88 hbox = Gtk::manage(new Gtk::HBox());
89 _button_preview = _param_preview->get_widget(NULL, NULL, &_signal_preview);
90 _button_preview->show();
91 _button_pinned = _param_pinned->get_widget(NULL, NULL, &_signal_pinned);
92 _button_pinned->show();
93 hbox->pack_start(*_button_preview, true, true,6);
94 hbox->pack_start(*_button_pinned, true, true,6);
95 hbox->show();
96 this->get_vbox()->pack_start(*hbox, true, true, 6);
98 preview_toggle();
99 pinned_toggle();
100 _signal_preview.connect(sigc::mem_fun(this, &PrefDialog::preview_toggle));
101 _signal_pinned.connect(sigc::mem_fun(this, &PrefDialog::pinned_toggle));
102 }
104 GtkWidget *dlg = GTK_WIDGET(gobj());
105 sp_transientize(dlg);
107 return;
108 }
110 PrefDialog::~PrefDialog ( )
111 {
112 if (_param_preview != NULL) {
113 delete _param_preview;
114 }
115 if (_param_pinned != NULL) {
116 delete _param_pinned;
117 }
119 return;
120 }
122 /** \brief Runs the dialog
123 \return The response to the dialog
125 This function overrides the run function in the GTKmm dialog
126 class, but basically it only calls it. This function only
127 handles the \c Gtk::RESPONSE_HELP return, and in that case it
128 brings up the help window. All other return values are returned
129 to the calling function.
130 */
131 int
132 PrefDialog::run (void) {
133 int resp = Gtk::RESPONSE_HELP;
134 while (resp == Gtk::RESPONSE_HELP) {
135 resp = Gtk::Dialog::run();
136 if (resp == Gtk::RESPONSE_HELP) {
137 /*
138 if (_helpDialog == NULL) {
139 _helpDialog = new HelpDialog(_help);
140 }
141 */
142 }
143 }
144 return resp;
145 }
147 void
148 PrefDialog::setPreviewState (Glib::ustring state) {
150 }
152 void
153 PrefDialog::preview_toggle (void) {
154 if(_param_preview->get_bool(NULL, NULL) && !_param_pinned->get_bool(NULL, NULL)) {
155 //std::cout << "Live Preview" << std::endl;
156 } else {
157 //std::cout << "No Preview" << std::endl;
158 }
159 }
161 void
162 PrefDialog::pinned_toggle (void) {
163 if (_param_pinned->get_bool(NULL, NULL)) {
164 _button_preview->set_sensitive(false);
165 preview_toggle();
166 set_modal(false);
168 _button_ok->set_label(Gtk::Stock::EXECUTE.id);
169 _button_cancel->set_label(Gtk::Stock::CLOSE.id);
170 } else {
171 _button_preview->set_sensitive(true);
172 set_modal(true);
174 _button_ok->set_label(Gtk::Stock::OK.id);
175 _button_cancel->set_label(Gtk::Stock::CANCEL.id);
176 }
177 }
179 void
180 PrefDialog::on_response (int signal) {
181 if (!_param_pinned->get_bool(NULL, NULL)) {
182 // Not my job if we're not pinned
183 // It's the execution environment's job
184 return;
185 }
187 if (signal == Gtk::RESPONSE_OK) {
188 _effect->effect(SP_ACTIVE_DESKTOP);
189 }
191 this->hide();
192 delete this;
193 }
195 #include "internal/clear-n_.h"
197 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>";
198 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>";
200 }; }; /* namespace Inkscape, Extension */
202 /*
203 Local Variables:
204 mode:c++
205 c-file-style:"stroustrup"
206 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
207 indent-tabs-mode:nil
208 fill-column:99
209 End:
210 */
211 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :