From: Jon A. Cruz Date: Tue, 6 Jul 2010 08:28:56 +0000 (-0700) Subject: Removed "Add" and enabled "Delete" for swatch context menu. Updated swatch marker... X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=e5a27fd62c20932a7c888d6c58087032763f2dc5;p=inkscape.git Removed "Add" and enabled "Delete" for swatch context menu. Updated swatch marker string. --- diff --git a/src/sp-gradient.cpp b/src/sp-gradient.cpp index 9c1ea0da7..2a3142b04 100644 --- a/src/sp-gradient.cpp +++ b/src/sp-gradient.cpp @@ -288,15 +288,19 @@ SPGradientSpread SPGradient::getSpread() const return spread; } -void SPGradient::setSwatch() +void SPGradient::setSwatch( bool swatch ) { - if ( !isSwatch() ) { - if ( hasStops() && (getStopCount() == 0) ) { - repr->setAttribute("osb:paint", "solid"); + if ( swatch != isSwatch() ) { + if ( swatch ) { + if ( hasStops() && (getStopCount() == 0) ) { + repr->setAttribute( "osb:paint", "solid" ); + } else { + repr->setAttribute( "osb:paint", "gradient" ); + } } else { - repr->setAttribute("osb:paint", "gradient"); + repr->setAttribute( "osb:paint", 0 ); } - requestModified(SP_OBJECT_MODIFIED_FLAG); + requestModified( SP_OBJECT_MODIFIED_FLAG ); } } @@ -594,12 +598,19 @@ void SPGradientImpl::childAdded(SPObject *object, Inkscape::XML::Node *child, In gr->invalidateVector(); - if (((SPObjectClass *) gradient_parent_class)->child_added) + if (((SPObjectClass *) gradient_parent_class)->child_added) { (* ((SPObjectClass *) gradient_parent_class)->child_added)(object, child, ref); + } SPObject *ochild = sp_object_get_child_by_repr(object, child); if ( ochild && SP_IS_STOP(ochild) ) { gr->has_stops = TRUE; + if ( gr->getStopCount() > 0 ) { + gchar const * attr = gr->repr->attribute("osb:paint"); + if ( attr && !strcmp(attr, "solid") ) { + gr->repr->setAttribute("osb:paint", "gradient"); + } + } } /// \todo Fixme: should we schedule "modified" here? @@ -628,6 +639,13 @@ void SPGradientImpl::removeChild(SPObject *object, Inkscape::XML::Node *child) } } + if ( gr->getStopCount() == 0 ) { + gchar const * attr = gr->repr->attribute("osb:paint"); + if ( attr && !strcmp(attr, "gradient") ) { + gr->repr->setAttribute("osb:paint", "solid"); + } + } + /* Fixme: should we schedule "modified" here? */ object->requestModified(SP_OBJECT_MODIFIED_FLAG); } diff --git a/src/sp-gradient.h b/src/sp-gradient.h index f1705f1c1..b05cb5fb8 100644 --- a/src/sp-gradient.h +++ b/src/sp-gradient.h @@ -142,7 +142,7 @@ public: SPGradientSpread fetchSpread(); SPGradientUnits fetchUnits(); - void setSwatch(); + void setSwatch(bool swatch = true); private: bool invalidateVector(); diff --git a/src/ui/dialog/swatches.cpp b/src/ui/dialog/swatches.cpp index 70e3800a0..e70cdaccf 100644 --- a/src/ui/dialog/swatches.cpp +++ b/src/ui/dialog/swatches.cpp @@ -74,7 +74,7 @@ class SwatchesPanelHook : public SwatchesPanel { public: static void convertGradient( GtkMenuItem *menuitem, gpointer userData ); - static void addNewGradient( GtkMenuItem *menuitem, gpointer user_data ); + static void deleteGradient( GtkMenuItem *menuitem, gpointer userData ); }; static void handleClick( GtkWidget* /*widget*/, gpointer callback_data ) { @@ -141,53 +141,46 @@ static void editGradient( GtkMenuItem */*menuitem*/, gpointer /*user_data*/ ) } } -void SwatchesPanelHook::addNewGradient( GtkMenuItem */*menuitem*/, gpointer /*user_data*/ ) +void SwatchesPanelHook::convertGradient( GtkMenuItem * /*menuitem*/, gpointer userData ) { if ( bounceTarget ) { SwatchesPanel* swp = bouncePanel; SPDesktop* desktop = swp ? swp->getDesktop() : 0; SPDocument *doc = desktop ? desktop->doc() : 0; - if (doc) { - Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc); - SPGradient * gr = 0; - { - Inkscape::XML::Node *repr = xml_doc->createElement("svg:linearGradient"); - Inkscape::XML::Node *stop = xml_doc->createElement("svg:stop"); - stop->setAttribute("offset", "0"); - stop->setAttribute("style", "stop-color:#000;stop-opacity:1;"); - repr->appendChild(stop); - Inkscape::GC::release(stop); - - SP_OBJECT_REPR( SP_DOCUMENT_DEFS(doc) )->addChild(repr, NULL); + gint index = GPOINTER_TO_INT(userData); + if ( doc && (index >= 0) && (static_cast(index) < popupItems.size()) ) { + Glib::ustring targetName = popupItems[index]; - gr = static_cast(doc->getObjectByRepr(repr)); - Inkscape::GC::release(repr); + const GSList *gradients = sp_document_get_resource_list(doc, "gradient"); + for (const GSList *item = gradients; item; item = item->next) { + SPGradient* grad = SP_GRADIENT(item->data); + if ( targetName == grad->getId() ) { + grad->setSwatch(); + sp_document_done(doc, SP_VERB_CONTEXT_GRADIENT, + _("Add gradient stop")); + break; + } } - - gr->setSwatch(); - - editGradientImpl( gr ); } } } -void SwatchesPanelHook::convertGradient( GtkMenuItem * /*menuitem*/, gpointer userData ) +void SwatchesPanelHook::deleteGradient( GtkMenuItem */*menuitem*/, gpointer /*userData*/ ) { if ( bounceTarget ) { SwatchesPanel* swp = bouncePanel; SPDesktop* desktop = swp ? swp->getDesktop() : 0; SPDocument *doc = desktop ? desktop->doc() : 0; - gint index = GPOINTER_TO_INT(userData); - if ( doc && (index >= 0) && (static_cast(index) < popupItems.size()) ) { - Glib::ustring targetName = popupItems[index]; - + if (doc) { + std::string targetName(bounceTarget->def.descr); const GSList *gradients = sp_document_get_resource_list(doc, "gradient"); for (const GSList *item = gradients; item; item = item->next) { SPGradient* grad = SP_GRADIENT(item->data); if ( targetName == grad->getId() ) { - grad->setSwatch(); + //editGradientImpl( grad ); + grad->setSwatch(false); sp_document_done(doc, SP_VERB_CONTEXT_GRADIENT, - _("Add gradient stop")); + _("Delete")); break; } } @@ -250,17 +243,13 @@ gboolean colorItemHandleButtonPress( GtkWidget* widget, GdkEventButton* event, g gtk_menu_shell_append(GTK_MENU_SHELL(popupMenu), child); popupExtras.push_back(child); - child = gtk_menu_item_new_with_label(_("Add")); + child = gtk_menu_item_new_with_label(_("Delete")); g_signal_connect( G_OBJECT(child), "activate", - G_CALLBACK(SwatchesPanelHook::addNewGradient), + G_CALLBACK(SwatchesPanelHook::deleteGradient), user_data ); gtk_menu_shell_append(GTK_MENU_SHELL(popupMenu), child); popupExtras.push_back(child); - - child = gtk_menu_item_new_with_label(_("Delete")); - gtk_menu_shell_append(GTK_MENU_SHELL(popupMenu), child); - //popupExtras.push_back(child); gtk_widget_set_sensitive( child, FALSE ); child = gtk_menu_item_new_with_label(_("Edit..."));