index 4e6c6fd79522af4730a7182a6ecf0350a9b828c0..615aeac7ae90d4ec006ea92d49f6992eee4597f7 100644 (file)
--- a/src/extension/effect.cpp
+++ b/src/extension/effect.cpp
* Authors:
* Ted Gould <ted@gould.cx>
*
- * Copyright (C) 2002-2006 Authors
+ * Copyright (C) 2002-2007 Authors
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include "inkscape-private.h"
#include "helper/action.h"
-#include "document.h"
-#include "prefdialog.h"
+#include "ui/view/view.h"
+#include "desktop-handles.h"
+#include "selection.h"
+#include "sp-namedview.h"
+#include "desktop.h"
#include "implementation/implementation.h"
#include "effect.h"
-#include "ui/view/view.h"
+#include "execution-env.h"
+#include "timer.h"
+
+
/* Inkscape::Extension::Effect */
Inkscape::XML::Node * Effect::_effects_list = NULL;
Effect::Effect (Inkscape::XML::Node * in_repr, Implementation::Implementation * in_imp)
- : Extension(in_repr, in_imp), _verb(get_id(), get_name(), NULL, NULL, this), _menu_node(NULL)
+ : Extension(in_repr, in_imp),
+ _id_noprefs(Glib::ustring(get_id()) + ".noprefs"),
+ _name_noprefs(Glib::ustring(get_name()) + _(" (No preferences)")),
+ _verb(get_id(), get_name(), NULL, NULL, this, true),
+ _verb_nopref(_id_noprefs.c_str(), _name_noprefs.c_str(), NULL, NULL, this, false),
+ _menu_node(NULL), _workingDialog(true),
+ _prefDialog(NULL)
{
Inkscape::XML::Node * local_effects_menu = NULL;
bool hidden = false;
+ no_doc = false;
+ no_live_preview = false;
+
if (repr != NULL) {
- Inkscape::XML::Node * child_repr;
- for (child_repr = sp_repr_children(repr); child_repr != NULL; child_repr = child_repr->next()) {
- if (!strcmp(child_repr->name(), "effect")) {
- for (child_repr = sp_repr_children(child_repr); child_repr != NULL; child_repr = child_repr->next()) {
- if (!strcmp(child_repr->name(), "effects-menu")) {
+ for (Inkscape::XML::Node *child = sp_repr_children(repr); child != NULL; child = child->next()) {
+ if (!strcmp(child->name(), INKSCAPE_EXTENSION_NS "effect")) {
+ if (child->attribute("needs-document") && !strcmp(child->attribute("needs-document"), "false")) {
+ no_doc = true;
+ }
+ if (child->attribute("needs-live-preview") && !strcmp(child->attribute("needs-live-preview"), "false")) {
+ no_live_preview = true;
+ }
+ for (Inkscape::XML::Node *effect_child = sp_repr_children(child); effect_child != NULL; effect_child = effect_child->next()) {
+ if (!strcmp(effect_child->name(), INKSCAPE_EXTENSION_NS "effects-menu")) {
// printf("Found local effects menu in %s\n", this->get_name());
- local_effects_menu = sp_repr_children(child_repr);
- if (child_repr->attribute("hidden") && !strcmp(child_repr->attribute("hidden"), "yes")) {
+ local_effects_menu = sp_repr_children(effect_child);
+ if (effect_child->attribute("hidden") && !strcmp(effect_child->attribute("hidden"), "true")) {
hidden = true;
}
}
- if (!strcmp(child_repr->name(), "menu-name") ||
- !strcmp(child_repr->name(), "_menu-name")) {
+ if (!strcmp(effect_child->name(), INKSCAPE_EXTENSION_NS "menu-name") ||
+ !strcmp(effect_child->name(), INKSCAPE_EXTENSION_NS "_menu-name")) {
// printf("Found local effects menu in %s\n", this->get_name());
- _verb.set_name(sp_repr_children(child_repr)->content());
+ _verb.set_name(sp_repr_children(effect_child)->content());
}
- if (!strcmp(child_repr->name(), "menu-tip") ||
- !strcmp(child_repr->name(), "_menu-tip")) {
+ if (!strcmp(effect_child->name(), INKSCAPE_EXTENSION_NS "menu-tip") ||
+ !strcmp(effect_child->name(), INKSCAPE_EXTENSION_NS "_menu-tip")) {
// printf("Found local effects menu in %s\n", this->get_name());
- _verb.set_tip(sp_repr_children(child_repr)->content());
+ _verb.set_tip(sp_repr_children(effect_child)->content());
}
} // children of "effect"
break; // there can only be one effect
} // children of "inkscape-extension"
} // if we have an XML file
- if (_effects_list == NULL)
+ if (_effects_list == NULL && INKSCAPE != NULL) {
find_effects_list(inkscape_get_menus(INKSCAPE));
+ }
if (_effects_list != NULL) {
- _menu_node = sp_repr_new("verb");
+ Inkscape::XML::Document *xml_doc;
+ xml_doc = _effects_list->document();
+ _menu_node = xml_doc->createElement("verb");
_menu_node->setAttribute("verb-id", this->get_id(), false);
if (!hidden)
gchar const * menuname = patern->attribute("name");
if (menuname == NULL) menuname = patern->attribute("_name");
if (menuname == NULL) return;
-
- tomerge = sp_repr_new("submenu");
+
+ Inkscape::XML::Document *xml_doc;
+ xml_doc = base->document();
+ tomerge = xml_doc->createElement("submenu");
tomerge->setAttribute("name", menuname, false);
mergename = _(menuname);
bool
Effect::prefs (Inkscape::UI::View::View * doc)
{
- if (!loaded())
- set_state(Extension::STATE_LOADED);
- if (!loaded()) return false;
-
- Gtk::Widget * controls;
- controls = imp->prefs_effect(this, doc);
- if (controls == NULL) {
- // std::cout << "No preferences for Effect" << std::endl;
+ if (_prefDialog != NULL) {
+ _prefDialog->raise();
return true;
}
- PrefDialog * dialog = new PrefDialog(this->get_name(), this->get_help(), controls);
- int response = dialog->run();
- dialog->hide();
+ if (param_visible_count() == 0) {
+ effect(doc);
+ return true;
+ }
- delete dialog;
+ if (!loaded())
+ set_state(Extension::STATE_LOADED);
+ if (!loaded()) return false;
- if (response == Gtk::RESPONSE_OK) return true;
+ _prefDialog = new PrefDialog(this->get_name(), this->get_help(), NULL, this);
+ _prefDialog->show();
- return false;
+ return true;
}
/**
void
Effect::effect (Inkscape::UI::View::View * doc)
{
+ //printf("Execute effect\n");
if (!loaded())
set_state(Extension::STATE_LOADED);
if (!loaded()) return;
- set_last_effect(this);
- imp->effect(this, doc);
- sp_document_done(doc->doc(), SP_VERB_NONE, _(this->get_name()));
+ ExecutionEnv executionEnv(this, doc);
+ timer->lock();
+ executionEnv.run();
+ if (executionEnv.wait()) {
+ executionEnv.commit();
+ } else {
+ executionEnv.cancel();
+ }
+ timer->unlock();
return;
}
+/** \brief Sets which effect was called last
+ \param in_effect The effect that has been called
+
+ This function sets the static variable \c _last_effect and it
+ ensures that the last effect verb is sensitive.
+
+ If the \c in_effect variable is \c NULL then the last effect
+ verb is made insesitive.
+*/
void
Effect::set_last_effect (Effect * in_effect)
{
return Extension::get_info_widget();
}
+void
+Effect::set_pref_dialog (PrefDialog * prefdialog)
+{
+ _prefDialog = prefdialog;
+ return;
+}
+
/** \brief Create an action for a \c EffectVerb
\param view Which view the action should be created for
\return The built action.
SPAction *
Effect::EffectVerb::make_action (Inkscape::UI::View::View * view)
{
- return make_action_helper(view, &vector, static_cast<void *>(_effect));
+ return make_action_helper(view, &vector, static_cast<void *>(this));
}
/** \brief Decode the verb code and take appropriate action */
void
-Effect::EffectVerb::perform (SPAction *action, void * data, void *pdata)
+Effect::EffectVerb::perform( SPAction *action, void * data, void */*pdata*/ )
{
Inkscape::UI::View::View * current_view = sp_action_get_view(action);
// SPDocument * current_document = current_view->doc;
- Effect * effect = reinterpret_cast<Effect *>(data);
+ Effect::EffectVerb * ev = reinterpret_cast<Effect::EffectVerb *>(data);
+ Effect * effect = ev->_effect;
if (effect == NULL) return;
if (current_view == NULL) return;
- // std::cout << "Executing: " << effect->get_name() << std::endl;
- if (effect->prefs(current_view))
+ if (ev->_showPrefs) {
+ effect->prefs(current_view);
+ } else {
effect->effect(current_view);
+ }
return;
}