X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fextension%2Fprefdialog.cpp;h=9d3abae762e4f7138c43fb13a58179d43817537a;hb=eaedc86c02c5a96cc5369d1a216cedcf13eb5704;hp=d9596986de0765bbc18a7c0c6746661698514c23;hpb=3fbc4e85ba5509840d49e33bae9e9fa94f887ab8;p=inkscape.git diff --git a/src/extension/prefdialog.cpp b/src/extension/prefdialog.cpp index d9596986d..9d3abae76 100644 --- a/src/extension/prefdialog.cpp +++ b/src/extension/prefdialog.cpp @@ -2,7 +2,7 @@ * Authors: * Ted Gould * - * Copyright (C) 2005-2007 Authors + * Copyright (C) 2005-2008 Authors * * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -19,8 +19,8 @@ #include "inkscape.h" #include "desktop.h" -#include "preferences.h" #include "effect.h" +#include "implementation/implementation.h" #include "prefdialog.h" @@ -33,27 +33,32 @@ namespace Extension { \param name Name of the Extension who's dialog this is \param help The help string for the extension (NULL if none) \param controls The extension specific widgets in the dialog - + This function initializes the dialog with the name of the extension in the title. It adds a few buttons and sets up handlers for them. It also places the passed in widgets into the dialog. */ -PrefDialog::PrefDialog (Glib::ustring name, gchar const * help, Gtk::Widget * controls, ExecutionEnv * exEnv, Effect * effect, sigc::signal * changeSignal) : +PrefDialog::PrefDialog (Glib::ustring name, gchar const * help, Gtk::Widget * controls, Effect * effect) : Gtk::Dialog::Dialog(_(name.c_str()), true, true), _help(help), _name(name), - _exEnv(exEnv), - _createdExEnv(false), _button_ok(NULL), _button_cancel(NULL), _button_preview(NULL), - _button_pinned(NULL), _param_preview(NULL), - _param_pinned(NULL), - _signal_param_change(changeSignal), - _effect(effect) + _effect(effect), + _exEnv(NULL) { Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox()); + if (controls == NULL) { + if (_effect == NULL) { + std::cout << "AH!!! No controls and no effect!!!" << std::endl; + return; + } + controls = _effect->get_imp()->prefs_effect(_effect, SP_ACTIVE_DESKTOP, &_signal_param_change, NULL); + _signal_param_change.connect(sigc::mem_fun(this, &PrefDialog::param_change)); + } + hbox->pack_start(*controls, true, true, 6); hbox->show(); this->get_vbox()->pack_start(*hbox, true, true, 6); @@ -63,24 +68,18 @@ PrefDialog::PrefDialog (Glib::ustring name, gchar const * help, Gtk::Widget * co if (_help == NULL) help_button->set_sensitive(false); */ - _button_cancel = add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); + _button_cancel = add_button(_effect == NULL ? Gtk::Stock::CANCEL : Gtk::Stock::CLOSE, Gtk::RESPONSE_CANCEL); _button_cancel->set_use_stock(true); - _button_ok = add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK); + _button_ok = add_button(_effect == NULL ? Gtk::Stock::OK : Gtk::Stock::APPLY, Gtk::RESPONSE_OK); _button_ok->set_use_stock(true); set_default_response(Gtk::RESPONSE_OK); _button_ok->grab_focus(); - - // If we're working with an effect that can be live and - // the dialog can be pinned, put those options in too - if (_exEnv != NULL) { + + if (_effect != NULL && !_effect->no_live_preview) { if (_param_preview == NULL) { XML::Document * doc = sp_repr_read_mem(live_param_xml, strlen(live_param_xml), NULL); - _param_preview = Parameter::make(doc->root(), _exEnv->_effect); - } - if (_param_pinned == NULL) { - XML::Document * doc = sp_repr_read_mem(pinned_param_xml, strlen(pinned_param_xml), NULL); - _param_pinned = Parameter::make(doc->root(), _exEnv->_effect); + _param_preview = Parameter::make(doc->root(), _effect); } Gtk::HSeparator * sep = Gtk::manage(new Gtk::HSeparator()); @@ -90,45 +89,48 @@ PrefDialog::PrefDialog (Glib::ustring name, gchar const * help, Gtk::Widget * co hbox = Gtk::manage(new Gtk::HBox()); _button_preview = _param_preview->get_widget(NULL, NULL, &_signal_preview); _button_preview->show(); - _button_pinned = _param_pinned->get_widget(NULL, NULL, &_signal_pinned); - _button_pinned->show(); hbox->pack_start(*_button_preview, true, true,6); - hbox->pack_start(*_button_pinned, true, true,6); hbox->show(); this->get_vbox()->pack_start(*hbox, true, true, 6); + Gtk::HBox * hbox = dynamic_cast(_button_preview); + if (hbox != NULL) { + Gtk::Widget * back = hbox->children().back().get_widget(); + Gtk::CheckButton * cb = dynamic_cast(back); + _checkbox_preview = cb; + } + preview_toggle(); - pinned_toggle(); _signal_preview.connect(sigc::mem_fun(this, &PrefDialog::preview_toggle)); - _signal_pinned.connect(sigc::mem_fun(this, &PrefDialog::pinned_toggle)); - } GtkWidget *dlg = GTK_WIDGET(gobj()); sp_transientize(dlg); - if (_effect != NULL) { - _effect->set_pref_dialog(this); - } - return; } PrefDialog::~PrefDialog ( ) { - if (_effect != NULL) { - _effect->set_pref_dialog(NULL); - } if (_param_preview != NULL) { delete _param_preview; + _param_preview = NULL; + } + + if (_exEnv != NULL) { + _exEnv->cancel(); + delete _exEnv; + _exEnv = NULL; } - if (_param_pinned != NULL) { - delete _param_pinned; + + if (_effect != NULL) { + _effect->set_pref_dialog(NULL); } return; } +#if 0 /** \brief Runs the dialog \return The response to the dialog @@ -153,72 +155,76 @@ PrefDialog::run (void) { } return resp; } - -void -PrefDialog::setPreviewState (Glib::ustring state) { - (void)state; -} +#endif void PrefDialog::preview_toggle (void) { - if(_param_preview->get_bool(NULL, NULL) && !_param_pinned->get_bool(NULL, NULL)) { - _exEnv->livePreview(true); + if(_param_preview->get_bool(NULL, NULL)) { + set_modal(true); + if (_exEnv == NULL) { + _exEnv = new ExecutionEnv(_effect, SP_ACTIVE_DESKTOP, NULL, false, false); + _exEnv->run(); + } } else { - _exEnv->livePreview(false); - } -} - -void -PrefDialog::pinned_toggle (void) { - if (_param_pinned->get_bool(NULL, NULL)) { - _button_preview->set_sensitive(false); - preview_toggle(); set_modal(false); - - _button_ok->set_label(Gtk::Stock::EXECUTE.id); - _button_cancel->set_label(Gtk::Stock::CLOSE.id); - if (_exEnv != NULL) { - _exEnv->shutdown(_createdExEnv); + _exEnv->cancel(); + _exEnv->undo(); + delete _exEnv; _exEnv = NULL; } - } else { - _button_preview->set_sensitive(true); - set_modal(true); + } +} - _button_ok->set_label(Gtk::Stock::OK.id); - _button_cancel->set_label(Gtk::Stock::CANCEL.id); +void +PrefDialog::param_change (void) { + if (_exEnv != NULL) { + _timersig.disconnect(); + _timersig = Glib::signal_timeout().connect(sigc::mem_fun(this, &PrefDialog::param_timer_expire), + 250, /* ms */ + Glib::PRIORITY_DEFAULT_IDLE); + } - if (_exEnv == NULL) { - _exEnv = new ExecutionEnv(_effect, SP_ACTIVE_DESKTOP, NULL, _signal_param_change, this); - _createdExEnv = true; - preview_toggle(); - _exEnv->run(); - } + return; +} + +bool +PrefDialog::param_timer_expire (void) { + if (_exEnv != NULL) { + _exEnv->cancel(); + _exEnv->undo(); + _exEnv->run(); } + + return false; } void PrefDialog::on_response (int signal) { - if (!_exEnv) { - // apparantly this effect does not use the new ExecutionEnv stuff. - // _param_pinned and _effect will be null, and the code below will crash: return here! - return; + if (signal == Gtk::RESPONSE_OK) { + if (_exEnv == NULL) { + if (_effect != NULL) { + _effect->effect(SP_ACTIVE_DESKTOP); + } else { + // Shutdown run() + return; + } + } else { + if (_exEnv->wait()) { + _exEnv->commit(); + } else { + _exEnv->undo(); + } + delete _exEnv; + _exEnv = NULL; + } } - //printf("Got signal %d\n", signal); - if (!_param_pinned->get_bool(NULL, NULL)) { - // Not my job if we're not pinned (either not pinned, or not even a pinned checkbox) - // It's the execution environment's job - return; + + if (_param_preview != NULL) { + _checkbox_preview->set_active(false); } - if (signal == Gtk::RESPONSE_OK) { - _effect->effect(SP_ACTIVE_DESKTOP); - } else { - this->hide(); - delete _signal_param_change; // This is not in the destructor because - // it is the only situation that we need - // to delete it in + if ((signal == Gtk::RESPONSE_CANCEL || signal == Gtk::RESPONSE_DELETE_EVENT) && _effect != NULL) { delete this; } @@ -227,8 +233,7 @@ PrefDialog::on_response (int signal) { #include "internal/clear-n_.h" -const char * PrefDialog::pinned_param_xml = "false"; -const char * PrefDialog::live_param_xml = "false"; +const char * PrefDialog::live_param_xml = "false"; }; }; /* namespace Inkscape, Extension */