From 0ba1b77aeb67fdf9e4d5ce1c531d85f67224ee7a Mon Sep 17 00:00:00 2001 From: gouldtj Date: Mon, 30 Jan 2006 05:11:13 +0000 Subject: [PATCH] r10815@tres: ted | 2006-01-29 14:46:19 -0800 Basically the menu stuff is working. Still needs features before it can be checked in. But the basics are all there right now. --- src/extension/effect.cpp | 94 ++++++++++++++++++++++++++++++++++++---- src/extension/effect.h | 1 + 2 files changed, 87 insertions(+), 8 deletions(-) diff --git a/src/extension/effect.cpp b/src/extension/effect.cpp index 43bd81830..0b333f3f8 100644 --- a/src/extension/effect.cpp +++ b/src/extension/effect.cpp @@ -26,22 +26,100 @@ 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) { + Inkscape::XML::Node * local_effects_menu = NULL; + + // This is a weird hack + if (!strcmp(this->get_id(), "org.inkscape.filter.dropshadow")) + return; + + 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")) { + printf("Found local effects menu in %s\n", this->get_name()); + local_effects_menu = sp_repr_children(child_repr); + } + } // children of "effect" + break; // there can only be one effect + } // find "effect" + } // children of "inkscape-extension" + } // if we have an XML file + if (_effects_list == NULL) find_effects_list(inkscape_get_menus(INKSCAPE)); if (_effects_list != NULL) { - unsigned start_pos = _effects_list->position(); - _menu_node = sp_repr_new("verb"); _menu_node->setAttribute("verb-id", this->get_id(), false); - _effects_list->parent()->appendChild(_menu_node); - _menu_node->setPosition(start_pos + 1); + merge_menu(_effects_list, local_effects_menu, _menu_node); + } + + return; +} + +void +Effect::merge_menu (Inkscape::XML::Node * base, + Inkscape::XML::Node * patern, + Inkscape::XML::Node * mergee) { + Glib::ustring mergename; + Inkscape::XML::Node * tomerge = NULL; + + if (patern == NULL) { + // Merge the verb name + tomerge = mergee; + mergename = _(this->get_name()); + } else { + gchar const * menuname = patern->attribute("name"); + if (menuname == NULL) menuname = patern->attribute("_name"); + if (menuname == NULL) return; + + tomerge = sp_repr_new("submenu"); + tomerge->setAttribute("name", menuname, false); + + 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; + } + 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; + } + + Glib::ustring compare(_(compare_char)); - Inkscape::GC::release(_menu_node); - } /*else { - printf("Effect %s not added\n", get_name()); - }*/ + if (mergename < compare) { + tomerge->setPosition(menupass->position()); + break; + } + } + + if (patern != NULL) { + printf("Going recursive\n"); + merge_menu(tomerge, patern->firstChild(), mergee); + } return; } diff --git a/src/extension/effect.h b/src/extension/effect.h index 35d0d0a00..fee2e5f8e 100644 --- a/src/extension/effect.h +++ b/src/extension/effect.h @@ -34,6 +34,7 @@ class Effect : public Extension { static Effect * _last_effect; static Inkscape::XML::Node * _effects_list; bool find_effects_list (Inkscape::XML::Node * menustruct); + void merge_menu (Inkscape::XML::Node * base, Inkscape::XML::Node * patern, Inkscape::XML::Node * mergee); class EffectVerb : public Inkscape::Verb { private: -- 2.30.2