Code

Added forgotten #ifdef HAVE_CAIRO_PDF/#endif pair
[inkscape.git] / src / extension / effect.cpp
index 0b333f3f8440593f1d5602e92e069246cb6eb942..71ddf3e247216509297ae421e9d49dfdfba3dc55 100644 (file)
@@ -2,7 +2,7 @@
  * Authors:
  *   Ted Gould <ted@gould.cx>
  *
- * Copyright (C) 2002-2005 Authors
+ * Copyright (C) 2002-2006 Authors
  *
  * Released under GNU GPL, read the file 'COPYING' for more information
  */
@@ -39,9 +39,19 @@ Effect::Effect (Inkscape::XML::Node * in_repr, Implementation::Implementation *
             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")) {
-                        printf("Found local effects menu in %s\n", this->get_name());
+                        // printf("Found local effects menu in %s\n", this->get_name());
                         local_effects_menu = sp_repr_children(child_repr);
                     }
+                    if (!strcmp(child_repr->name(), "menu-name") ||
+                            !strcmp(child_repr->name(), "_menu-name")) {
+                        // printf("Found local effects menu in %s\n", this->get_name());
+                        _verb.set_name(sp_repr_children(child_repr)->content());
+                    }
+                    if (!strcmp(child_repr->name(), "menu-tip") ||
+                            !strcmp(child_repr->name(), "_menu-tip")) {
+                        // printf("Found local effects menu in %s\n", this->get_name());
+                        _verb.set_tip(sp_repr_children(child_repr)->content());
+                    }
                 } // children of "effect"
                 break; // there can only be one effect
             } // find "effect"
@@ -55,7 +65,7 @@ Effect::Effect (Inkscape::XML::Node * in_repr, Implementation::Implementation *
         _menu_node = sp_repr_new("verb");
         _menu_node->setAttribute("verb-id", this->get_id(), false);
 
-        merge_menu(_effects_list, local_effects_menu, _menu_node);
+        merge_menu(_effects_list->parent(), _effects_list, local_effects_menu, _menu_node);
     }
 
     return;
@@ -63,10 +73,17 @@ Effect::Effect (Inkscape::XML::Node * in_repr, Implementation::Implementation *
 
 void
 Effect::merge_menu (Inkscape::XML::Node * base,
+                    Inkscape::XML::Node * start,
                     Inkscape::XML::Node * patern,
                     Inkscape::XML::Node * mergee) {
     Glib::ustring mergename;
     Inkscape::XML::Node * tomerge = NULL;
+    Inkscape::XML::Node * submenu = NULL;
+
+    /* printf("Merge menu with '%s' '%s' '%s'\n",
+            base != NULL ? base->name() : "NULL",
+            patern != NULL ? patern->name() : "NULL",
+            mergee != NULL ? mergee->name() : "NULL"); */
 
     if (patern == NULL) {
         // Merge the verb name
@@ -83,42 +100,57 @@ Effect::merge_menu (Inkscape::XML::Node * base,
         mergename = _(menuname);
     }
 
-    base->parent()->appendChild(tomerge);
-    Inkscape::GC::release(tomerge);
-
-    Inkscape::XML::Node * menupass;
-    for (menupass = base->next(); menupass != NULL; menupass = menupass->next()) {
-        gchar const * compare_char = NULL;
-        if (!strcmp(menupass->name(), "verb")) {
-            gchar const * verbid = menupass->attribute("verb-id");
-            Inkscape::Verb * verb = Inkscape::Verb::getbyid(verbid);
-            if (verb == NULL) {
-                printf("Unable to find verb\n");
-                return;
+    int position = -1;
+
+    if (start != NULL) {
+        Inkscape::XML::Node * menupass;
+        for (menupass = start->next(); menupass != NULL; menupass = menupass->next()) {
+            gchar const * compare_char = NULL;
+            if (!strcmp(menupass->name(), "verb")) {
+                gchar const * verbid = menupass->attribute("verb-id");
+                Inkscape::Verb * verb = Inkscape::Verb::getbyid(verbid);
+                if (verb == NULL) {
+                    continue;
+                }
+                compare_char = verb->get_name();
+            } else if (!strcmp(menupass->name(), "submenu")) {
+                compare_char = menupass->attribute("name");
+                if (compare_char == NULL)
+                    compare_char = menupass->attribute("_name");
             }
-            compare_char = verb->get_name();
-        } else { // submenu
-            compare_char = menupass->attribute("name");
-            if (compare_char == NULL)
-                compare_char = menupass->attribute("_name");
-        }
 
-        if (compare_char == NULL) {
-            printf("Nothing to compare against\n");
-            return;
-        }
+            /* This will cause us to skip tags we don't understand */
+            if (compare_char == NULL) {
+                continue;
+            }
 
-        Glib::ustring compare(_(compare_char));
+            Glib::ustring compare(_(compare_char));
 
-        if (mergename < compare) {
-            tomerge->setPosition(menupass->position());
-            break;
-        }
+            if (mergename == compare) {
+                Inkscape::GC::release(tomerge);
+                tomerge = NULL;
+                submenu = menupass;
+                break;
+            }
+
+            if (mergename < compare) {
+                position = menupass->position();
+                break;
+            }
+        } // for menu items
+    } // start != NULL
+
+    if (tomerge != NULL) {
+        base->appendChild(tomerge);
+        Inkscape::GC::release(tomerge);
+        if (position != -1)
+            tomerge->setPosition(position);
     }
 
     if (patern != NULL) {
-        printf("Going recursive\n");
-        merge_menu(tomerge, patern->firstChild(), mergee);
+        if (submenu == NULL)
+            submenu = tomerge;
+        merge_menu(submenu, submenu->firstChild(), patern->firstChild(), mergee);
     }
 
     return;
@@ -159,7 +191,7 @@ Effect::prefs (Inkscape::UI::View::View * doc)
         return true;
     }
 
-    PrefDialog * dialog = new PrefDialog(this->get_name(), controls);
+    PrefDialog * dialog = new PrefDialog(this->get_name(), this->get_help(), controls);
     int response = dialog->run();
     dialog->hide();
 
@@ -190,7 +222,8 @@ Effect::effect (Inkscape::UI::View::View * doc)
     set_last_effect(this);
     imp->effect(this, doc);
 
-    sp_document_done(doc->doc());
+    sp_document_done(doc->doc(), SP_VERB_NONE, 
+                     /* TODO: annotate */ "effect.cpp:226");
 
     return;
 }
@@ -231,6 +264,12 @@ Effect::find_effects_list (Inkscape::XML::Node * menustruct)
     return false;
 }
 
+Gtk::VBox *
+Effect::get_info_widget(void)
+{
+    return Extension::get_info_widget();
+}
+
 /** \brief  Create an action for a \c EffectVerb
     \param  view  Which view the action should be created for
     \return The built action.
@@ -266,7 +305,7 @@ Effect::EffectVerb::perform (SPAction *action, void * data, void *pdata)
  * is called.
  */
 SPActionEventVector Effect::EffectVerb::vector =
-            {{NULL},Effect::EffectVerb::perform, NULL, NULL, NULL};
+            {{NULL}, Effect::EffectVerb::perform, NULL, NULL, NULL, NULL};
 
 
 } }  /* namespace Inkscape, Extension */