From eb2d451ff10e3ea84108bce53a3f5cae2c7c4aa2 Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Tue, 16 Mar 2010 00:24:31 -0700 Subject: [PATCH] Fixing "Auto" palette to be tracked per document, independent of containing panel. --- src/ui/dialog/color-item.cpp | 24 ++- src/ui/dialog/color-item.h | 10 +- src/ui/dialog/swatches.cpp | 339 ++++++++++++++++++++++------------- src/ui/dialog/swatches.h | 16 +- 4 files changed, 244 insertions(+), 145 deletions(-) diff --git a/src/ui/dialog/color-item.cpp b/src/ui/dialog/color-item.cpp index f0f98a347..8eed4e4ac 100644 --- a/src/ui/dialog/color-item.cpp +++ b/src/ui/dialog/color-item.cpp @@ -41,10 +41,13 @@ static std::vector mimeStrings; static std::map mimeToInt; +#if ENABLE_MAGIC_COLORS // TODO remove this soon: -extern std::vector possible; +extern std::vector possible; +#endif // ENABLE_MAGIC_COLORS +#if ENABLE_MAGIC_COLORS static bool bruteForce( SPDocument* document, Inkscape::XML::Node* node, Glib::ustring const& match, int r, int g, int b ) { bool changed = false; @@ -88,6 +91,7 @@ static bool bruteForce( SPDocument* document, Inkscape::XML::Node* node, Glib::u return changed; } +#endif // ENABLE_MAGIC_COLORS static void handleClick( GtkWidget* /*widget*/, gpointer callback_data ) { ColorItem* item = reinterpret_cast(callback_data); @@ -246,21 +250,21 @@ static void colorItemDragBegin( GtkWidget */*widget*/, GdkDragContext* dc, gpoin // } -JustForNow::JustForNow() : +SwatchPage::SwatchPage() : _name(), _prefWidth(0), _colors() { } -JustForNow::~JustForNow() +SwatchPage::~SwatchPage() { } ColorItem::ColorItem(ege::PaintDef::ColorType type) : + Previewable(), def(type), - ptr(0), tips(), _previews(), _isFill(false), @@ -270,6 +274,7 @@ ColorItem::ColorItem(ege::PaintDef::ColorType type) : _linkPercent(0), _linkGray(0), _linkSrc(0), + _grad(0), _pixData(0), _pixWidth(0), _pixHeight(0), @@ -278,8 +283,8 @@ ColorItem::ColorItem(ege::PaintDef::ColorType type) : } ColorItem::ColorItem( unsigned int r, unsigned int g, unsigned int b, Glib::ustring& name ) : + Previewable(), def( r, g, b, name ), - ptr(0), tips(), _previews(), _isFill(false), @@ -289,6 +294,7 @@ ColorItem::ColorItem( unsigned int r, unsigned int g, unsigned int b, Glib::ustr _linkPercent(0), _linkGray(0), _linkSrc(0), + _grad(0), _pixData(0), _pixWidth(0), _pixHeight(0), @@ -445,6 +451,7 @@ void ColorItem::_updatePreviews() } +#if ENABLE_MAGIC_COLORS // Look for objects using this color { SPDesktop *desktop = SP_ACTIVE_DESKTOP; @@ -457,8 +464,8 @@ void ColorItem::_updatePreviews() Glib::ustring paletteName; bool found = false; int index = 0; - for ( std::vector::iterator it2 = possible.begin(); it2 != possible.end() && !found; ++it2 ) { - JustForNow* curr = *it2; + for ( std::vector::iterator it2 = possible.begin(); it2 != possible.end() && !found; ++it2 ) { + SwatchPage* curr = *it2; index = 0; for ( std::vector::iterator zz = curr->_colors.begin(); zz != curr->_colors.end(); ++zz ) { if ( this == *zz ) { @@ -485,6 +492,7 @@ void ColorItem::_updatePreviews() } } } +#endif // ENABLE_MAGIC_COLORS } @@ -715,7 +723,7 @@ void ColorItem::buttonClicked(bool secondary) } } -void ColorItem::_wireMagicColors( JustForNow *colorSet ) +void ColorItem::_wireMagicColors( SwatchPage *colorSet ) { if ( colorSet ) { diff --git a/src/ui/dialog/color-item.h b/src/ui/dialog/color-item.h index a7599964e..4aac86a30 100644 --- a/src/ui/dialog/color-item.h +++ b/src/ui/dialog/color-item.h @@ -25,11 +25,11 @@ namespace Dialogs { class ColorItem; -class JustForNow +class SwatchPage { public: - JustForNow(); - ~JustForNow(); + SwatchPage(); + ~SwatchPage(); Glib::ustring _name; int _prefWidth; @@ -66,9 +66,9 @@ public: bool isStroke() { return _isStroke; } ege::PaintDef def; - void* ptr; private: + static void _dropDataIn( GtkWidget *widget, GdkDragContext *drag_context, gint x, gint y, @@ -84,7 +84,7 @@ private: guint time, gpointer user_data); - static void _wireMagicColors( JustForNow *colorSet ); + static void _wireMagicColors( SwatchPage *colorSet ); static void _colorDefChanged(void* data); void _updatePreviews(); diff --git a/src/ui/dialog/swatches.cpp b/src/ui/dialog/swatches.cpp index b330012ca..76ceb1514 100644 --- a/src/ui/dialog/swatches.cpp +++ b/src/ui/dialog/swatches.cpp @@ -1,3 +1,4 @@ + /** @file * @brief Color swatches dialog */ @@ -48,7 +49,6 @@ #include "display/nr-plain-stuff.h" #include "sp-gradient-reference.h" -#define USE_DOCUMENT_PALETTE 1 namespace Inkscape { namespace UI { @@ -60,8 +60,13 @@ namespace Dialogs { void _loadPaletteFile( gchar const *filename ); +class DocTrack; + +std::vector possible; +static std::map docPalettes; +static std::vector docTrackings; +static std::map docPerPanel; -std::vector possible; static void handleClick( GtkWidget* /*widget*/, gpointer callback_data ) { @@ -81,6 +86,7 @@ static void handleSecondaryClick( GtkWidget* /*widget*/, gint /*arg1*/, gpointer static GtkWidget* popupMenu = 0; static std::vector popupExtras; static ColorItem* bounceTarget = 0; +static SwatchesPanel* bouncePanel = 0; static void redirClick( GtkMenuItem *menuitem, gpointer /*user_data*/ ) { @@ -96,7 +102,6 @@ static void redirSecondaryClick( GtkMenuItem *menuitem, gpointer /*user_data*/ ) } } -#if USE_DOCUMENT_PALETTE static void editGradientImpl( SPGradient* gr ) { if ( gr ) { @@ -108,7 +113,7 @@ static void editGradientImpl( SPGradient* gr ) static void editGradient( GtkMenuItem */*menuitem*/, gpointer /*user_data*/ ) { if ( bounceTarget ) { - SwatchesPanel* swp = bounceTarget->ptr ? reinterpret_cast(bounceTarget->ptr) : 0; + SwatchesPanel* swp = bouncePanel; SPDesktop* desktop = swp ? swp->getDesktop() : 0; SPDocument *doc = desktop ? desktop->doc() : 0; if (doc) { @@ -128,7 +133,7 @@ static void editGradient( GtkMenuItem */*menuitem*/, gpointer /*user_data*/ ) static void addNewGradient( GtkMenuItem */*menuitem*/, gpointer /*user_data*/ ) { if ( bounceTarget ) { - SwatchesPanel* swp = bounceTarget->ptr ? reinterpret_cast(bounceTarget->ptr) : 0; + SwatchesPanel* swp = bouncePanel; SPDesktop* desktop = swp ? swp->getDesktop() : 0; SPDocument *doc = desktop ? desktop->doc() : 0; if (doc) { @@ -150,20 +155,35 @@ static void addNewGradient( GtkMenuItem */*menuitem*/, gpointer /*user_data*/ ) editGradientImpl( gr ); - // Work-around for timing of gradient addition change. Must follow edit. - if ( swp ) { - swp->handleGradientsChange(); - } } } } -#endif // USE_DOCUMENT_PALETTE -gboolean colorItemHandleButtonPress( GtkWidget* /*widget*/, GdkEventButton* event, gpointer user_data) +static SwatchesPanel* findContainingPanel( GtkWidget *widget ) +{ + SwatchesPanel *swp = 0; + + std::map rawObjects; + for (std::map::iterator it = docPerPanel.begin(); it != docPerPanel.end(); ++it) { + rawObjects[GTK_WIDGET(it->first->gobj())] = it->first; + } + + for (GtkWidget* curr = widget; curr && !swp; curr = gtk_widget_get_parent(curr)) { + if (rawObjects.find(curr) != rawObjects.end()) { + swp = rawObjects[curr]; + } + } + + return swp; +} + +gboolean colorItemHandleButtonPress( GtkWidget* widget, GdkEventButton* event, gpointer user_data) { gboolean handled = FALSE; if ( (event->button == 3) && (event->type == GDK_BUTTON_PRESS) ) { + SwatchesPanel* swp = findContainingPanel( widget ); + if ( !popupMenu ) { popupMenu = gtk_menu_new(); GtkWidget* child = 0; @@ -185,7 +205,6 @@ gboolean colorItemHandleButtonPress( GtkWidget* /*widget*/, GdkEventButton* even user_data); gtk_menu_shell_append(GTK_MENU_SHELL(popupMenu), child); -#if USE_DOCUMENT_PALETTE child = gtk_separator_menu_item_new(); gtk_menu_shell_append(GTK_MENU_SHELL(popupMenu), child); popupExtras.push_back(child); @@ -219,20 +238,19 @@ gboolean colorItemHandleButtonPress( GtkWidget* /*widget*/, GdkEventButton* even gtk_menu_shell_append(GTK_MENU_SHELL(popupMenu), child); //popupExtras.push_back(child); gtk_widget_set_sensitive( child, FALSE ); -#endif // USE_DOCUMENT_PALETTE gtk_widget_show_all(popupMenu); } ColorItem* item = reinterpret_cast(user_data); if ( item ) { - SwatchesPanel* swp = item->ptr ? reinterpret_cast(item->ptr) : 0; bool show = swp && (swp->getSelectedIndex() == 0); for ( std::vector::iterator it = popupExtras.begin(); it != popupExtras.end(); ++ it) { gtk_widget_set_sensitive(*it, show); } bounceTarget = item; + bouncePanel = swp; if ( popupMenu ) { gtk_menu_popup(GTK_MENU(popupMenu), NULL, NULL, NULL, NULL, event->button, event->time); handled = TRUE; @@ -288,7 +306,7 @@ void _loadPaletteFile( gchar const *filename ) bool inHeader = true; bool hasErr = false; - JustForNow *onceMore = new JustForNow(); + SwatchPage *onceMore = new SwatchPage(); do { result = fgets( block, sizeof(block), f ); @@ -464,46 +482,45 @@ SwatchesPanel::SwatchesPanel(gchar const* prefsPath) : _remove(0), _currentIndex(0), _currentDesktop(0), - _currentDocument(0), - _ptr(0) + _currentDocument(0) { Gtk::RadioMenuItem* hotItem = 0; _holder = new PreviewHolder(); _clear = new ColorItem( ege::PaintDef::CLEAR ); - _clear->ptr = this; _remove = new ColorItem( ege::PaintDef::NONE ); - _remove->ptr = this; -#if USE_DOCUMENT_PALETTE - { - JustForNow *docPalette = new JustForNow(); + if (docPalettes.empty()) { + SwatchPage *docPalette = new SwatchPage(); docPalette->_name = "Auto"; - possible.push_back(docPalette); - - _ptr = docPalette; + docPalettes[0] = docPalette; } -#endif // USE_DOCUMENT_PALETTE + loadEmUp(); if ( !possible.empty() ) { - JustForNow* first = 0; + SwatchPage* first = 0; int index = 0; Glib::ustring targetName; if ( !_prefs_path.empty() ) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); targetName = prefs->getString(_prefs_path + "/palette"); if (!targetName.empty()) { - for ( std::vector::iterator iter = possible.begin(); iter != possible.end(); ++iter ) { - if ( (*iter)->_name == targetName ) { - first = *iter; - break; - } + if (targetName == "Auto") { + first = docPalettes[0]; + } else { index++; + for ( std::vector::iterator iter = possible.begin(); iter != possible.end(); ++iter ) { + if ( (*iter)->_name == targetName ) { + first = *iter; + break; + } + index++; + } } } } if ( !first ) { - first = possible.front(); + first = docPalettes[0]; _currentIndex = 0; } else { _currentIndex = index; @@ -514,8 +531,9 @@ SwatchesPanel::SwatchesPanel(gchar const* prefsPath) : Gtk::RadioMenuItem::Group groupOne; int i = 0; - for ( std::vector::iterator it = possible.begin(); it != possible.end(); it++ ) { - JustForNow* curr = *it; + std::vector swatchSets = _getSwatchSets(); + for ( std::vector::iterator it = swatchSets.begin(); it != swatchSets.end(); it++ ) { + SwatchPage* curr = *it; Gtk::RadioMenuItem* single = manage(new Gtk::RadioMenuItem(groupOne, curr->_name)); if ( curr == first ) { hotItem = single; @@ -539,13 +557,10 @@ SwatchesPanel::SwatchesPanel(gchar const* prefsPath) : SwatchesPanel::~SwatchesPanel() { + _trackDocument( this, 0 ); + _documentConnection.disconnect(); - _resourceConnection.disconnect(); _selChanged.disconnect(); - _setModified.disconnect(); - _subselChanged.disconnect(); - _defsChanged.disconnect(); - _defsModified.disconnect(); if ( _clear ) { delete _clear; @@ -575,8 +590,6 @@ void SwatchesPanel::setDesktop( SPDesktop* desktop ) if ( _currentDesktop ) { _documentConnection.disconnect(); _selChanged.disconnect(); - _setModified.disconnect(); - _subselChanged.disconnect(); } _currentDesktop = desktop; @@ -597,41 +610,112 @@ void SwatchesPanel::setDesktop( SPDesktop* desktop ) _documentConnection = desktop->connectDocumentReplaced( slot2 ); _setDocument( desktop->doc() ); + handleGradientsChange( desktop->doc() ); } else { _setDocument(0); } } } -void SwatchesPanel::_setDocument( SPDocument *document ) + +class DocTrack { - if ( document != _currentDocument ) { - if ( _currentDocument ) { - _resourceConnection.disconnect(); - _defsChanged.disconnect(); - _defsModified.disconnect(); +public: + DocTrack(SPDocument *doc, sigc::connection &gradientRsrcChanged, sigc::connection &defsChanged, sigc::connection &defsModified) : + doc(doc), + gradientRsrcChanged(gradientRsrcChanged), + defsChanged(defsChanged), + defsModified(defsModified) + { + } + + ~DocTrack() + { + if (doc) { + gradientRsrcChanged.disconnect(); + defsChanged.disconnect(); + defsModified.disconnect(); } - _currentDocument = document; - if ( _currentDocument ) { - _resourceConnection = sp_document_resources_changed_connect(document, - "gradient", - sigc::mem_fun(*this, &SwatchesPanel::handleGradientsChange)); - - // connect to release and modified signals of the defs (i.e. when someone changes gradient) - _defsChanged = SP_DOCUMENT_DEFS(document)->connectRelease(sigc::hide(sigc::mem_fun(*this, &SwatchesPanel::handleDefsModified))); - _defsModified = SP_DOCUMENT_DEFS(document)->connectModified(sigc::hide(sigc::hide(sigc::mem_fun(*this, &SwatchesPanel::handleDefsModified)))); + } + + SPDocument *doc; + sigc::connection gradientRsrcChanged; + sigc::connection defsChanged; + sigc::connection defsModified; + +private: + DocTrack(DocTrack const &); // no copy + DocTrack &operator=(DocTrack const &); // no assign +}; + +void SwatchesPanel::_trackDocument( SwatchesPanel *panel, SPDocument *document ) +{ + SPDocument *oldDoc = 0; + if (docPerPanel.find(panel) != docPerPanel.end()) { + oldDoc = docPerPanel[panel]; + if (!oldDoc) { + docPerPanel.erase(panel); // Should not be needed, but clean up just in case. + } + } + if (oldDoc != document) { + if (oldDoc) { + docPerPanel[panel] = 0; + bool found = false; + for (std::map::iterator it = docPerPanel.begin(); (it != docPerPanel.end()) && !found; ++it) { + found = (it->second == document); + } + if (!found) { + for (std::vector::iterator it = docTrackings.begin(); it != docTrackings.end(); ++it){ + if ((*it)->doc == oldDoc) { + delete *it; + docTrackings.erase(it); + break; + } + } + } + } + + if (document) { + bool found = false; + for (std::map::iterator it = docPerPanel.begin(); (it != docPerPanel.end()) && !found; ++it) { + found = (it->second == document); + } + docPerPanel[panel] = document; + if (!found) { + sigc::connection conn1 = sp_document_resources_changed_connect( document, "gradient", sigc::bind(sigc::ptr_fun(&SwatchesPanel::handleGradientsChange), document) ); + sigc::connection conn2 = SP_DOCUMENT_DEFS(document)->connectRelease( sigc::hide(sigc::bind(sigc::ptr_fun(&SwatchesPanel::handleDefsModified), document)) ); + sigc::connection conn3 = SP_DOCUMENT_DEFS(document)->connectModified( sigc::hide(sigc::hide(sigc::bind(sigc::ptr_fun(&SwatchesPanel::handleDefsModified), document))) ); + + DocTrack *dt = new DocTrack(document, conn1, conn2, conn3); + docTrackings.push_back(dt); + + if (docPalettes.find(document) == docPalettes.end()) { + SwatchPage *docPalette = new SwatchPage(); + docPalette->_name = "Auto"; + docPalettes[document] = docPalette; + } + } } + } - handleGradientsChange(); + std::set docs; + for (std::map::iterator it = docPerPanel.begin(); it != docPerPanel.end(); ++it) { + docs.insert(it->second); + } +} + +void SwatchesPanel::_setDocument( SPDocument *document ) +{ + if ( document != _currentDocument ) { + _trackDocument(this, document); + _currentDocument = document; } } -#if USE_DOCUMENT_PALETTE static void recalcSwatchContents(SPDocument* doc, std::vector &tmpColors, std::map &previewMappings, - std::map &gradMappings, - void* ptr) + std::map &gradMappings) { std::vector newList; @@ -660,7 +744,6 @@ static void recalcSwatchContents(SPDocument* doc, unsigned int g = SP_RGBA32_G_U(together); unsigned int b = SP_RGBA32_B_U(together); ColorItem* item = new ColorItem( r, g, b, name ); - item->ptr = ptr; gint width = PREVIEW_PIXBUF_WIDTH; gint height = VBLOCK; @@ -678,81 +761,90 @@ static void recalcSwatchContents(SPDocument* doc, } } } -#endif // USE_DOCUMENT_PALETTE -void SwatchesPanel::handleGradientsChange() +void SwatchesPanel::handleGradientsChange(SPDocument *document) { -// Invoked when the list of gradients itself changes due to additions, removals, etc. -#if USE_DOCUMENT_PALETTE - if ( _ptr ) { - JustForNow *docPalette = reinterpret_cast(_ptr); - if (docPalette) { - std::vector tmpColors; - std::map tmpPrevs; - std::map tmpGrads; - recalcSwatchContents(_currentDocument, tmpColors, tmpPrevs, tmpGrads, this); - - for (std::map::iterator it = tmpPrevs.begin(); it != tmpPrevs.end(); ++it) { - it->first->setPixData(it->second, PREVIEW_PIXBUF_WIDTH, VBLOCK); - } + SwatchPage *docPalette = (docPalettes.find(document) != docPalettes.end()) ? docPalettes[document] : 0; + if (docPalette) { + std::vector tmpColors; + std::map tmpPrevs; + std::map tmpGrads; + recalcSwatchContents(document, tmpColors, tmpPrevs, tmpGrads); + + for (std::map::iterator it = tmpPrevs.begin(); it != tmpPrevs.end(); ++it) { + it->first->setPixData(it->second, PREVIEW_PIXBUF_WIDTH, VBLOCK); + } - for (std::map::iterator it = tmpGrads.begin(); it != tmpGrads.end(); ++it) { - it->first->setGradient(it->second); - } + for (std::map::iterator it = tmpGrads.begin(); it != tmpGrads.end(); ++it) { + it->first->setGradient(it->second); + } - docPalette->_colors.swap(tmpColors); - for (std::vector::iterator it = tmpColors.begin(); it != tmpColors.end(); ++it) { - delete *it; - } + docPalette->_colors.swap(tmpColors); + for (std::vector::iterator it = tmpColors.begin(); it != tmpColors.end(); ++it) { + delete *it; + } - JustForNow* curr = possible[_currentIndex]; - if (curr == docPalette) { - _rebuild(); + + // Figure out which SwatchesPanel instances are affected and update them. + + for (std::map::iterator it = docPerPanel.begin(); it != docPerPanel.end(); ++it) { + if (it->second == document) { + SwatchesPanel* swp = it->first; + std::vector pages = swp->_getSwatchSets(); + SwatchPage* curr = pages[swp->_currentIndex]; + if (curr == docPalette) { + swp->_rebuild(); + } } } } -#endif // USE_DOCUMENT_PALETTE } -void SwatchesPanel::handleDefsModified() +void SwatchesPanel::handleDefsModified(SPDocument *document) { -#if USE_DOCUMENT_PALETTE - if ( _ptr ) { - JustForNow *docPalette = reinterpret_cast(_ptr); - if (docPalette) { - std::vector tmpColors; - std::map tmpPrevs; - std::map tmpGrads; - recalcSwatchContents(_currentDocument, tmpColors, tmpPrevs, tmpGrads, this); - - int cap = std::min(docPalette->_colors.size(), tmpColors.size()); - for (int i = 0; i < cap; i++) { - ColorItem* newColor = tmpColors[i]; - ColorItem* oldColor = docPalette->_colors[i]; - if ( (newColor->def.getType() != oldColor->def.getType()) || - (newColor->def.getR() != oldColor->def.getR()) || - (newColor->def.getG() != oldColor->def.getG()) || - (newColor->def.getB() != oldColor->def.getB()) ) { - oldColor->def.setRGB(newColor->def.getR(), newColor->def.getG(), newColor->def.getB()); - } - if (tmpGrads.find(newColor) != tmpGrads.end()) { - oldColor->setGradient(tmpGrads[newColor]); - } - if ( tmpPrevs.find(newColor) != tmpPrevs.end() ) { - oldColor->setPixData(tmpPrevs[newColor], PREVIEW_PIXBUF_WIDTH, VBLOCK); - } + SwatchPage *docPalette = (docPalettes.find(document) != docPalettes.end()) ? docPalettes[document] : 0; + if (docPalette) { + std::vector tmpColors; + std::map tmpPrevs; + std::map tmpGrads; + recalcSwatchContents(document, tmpColors, tmpPrevs, tmpGrads); + + int cap = std::min(docPalette->_colors.size(), tmpColors.size()); + for (int i = 0; i < cap; i++) { + ColorItem* newColor = tmpColors[i]; + ColorItem* oldColor = docPalette->_colors[i]; + if ( (newColor->def.getType() != oldColor->def.getType()) || + (newColor->def.getR() != oldColor->def.getR()) || + (newColor->def.getG() != oldColor->def.getG()) || + (newColor->def.getB() != oldColor->def.getB()) ) { + oldColor->def.setRGB(newColor->def.getR(), newColor->def.getG(), newColor->def.getB()); + } + if (tmpGrads.find(newColor) != tmpGrads.end()) { + oldColor->setGradient(tmpGrads[newColor]); + } + if ( tmpPrevs.find(newColor) != tmpPrevs.end() ) { + oldColor->setPixData(tmpPrevs[newColor], PREVIEW_PIXBUF_WIDTH, VBLOCK); } } } -#endif // USE_DOCUMENT_PALETTE } -void SwatchesPanel::_updateFromSelection() +std::vector SwatchesPanel::_getSwatchSets() const { -#if USE_DOCUMENT_PALETTE - if ( _ptr ) { - JustForNow *docPalette = reinterpret_cast(_ptr); + std::vector tmp; + if (docPalettes.find(_currentDocument) != docPalettes.end()) { + tmp.push_back(docPalettes[_currentDocument]); + } + + tmp.insert(tmp.end(), possible.begin(), possible.end()); + return tmp; +} + +void SwatchesPanel::_updateFromSelection() +{ + SwatchPage *docPalette = (docPalettes.find(_currentDocument) != docPalettes.end()) ? docPalettes[_currentDocument] : 0; + if ( docPalette ) { Glib::ustring fillId; Glib::ustring strokeId; @@ -827,7 +919,6 @@ void SwatchesPanel::_updateFromSelection() item->setState( isFill, isStroke ); } } -#endif // USE_DOCUMENT_PALETTE } void SwatchesPanel::_handleAction( int setId, int itemId ) @@ -835,12 +926,13 @@ void SwatchesPanel::_handleAction( int setId, int itemId ) switch( setId ) { case 3: { - if ( itemId >= 0 && itemId < static_cast(possible.size()) ) { + std::vector pages = _getSwatchSets(); + if ( itemId >= 0 && itemId < static_cast(pages.size()) ) { _currentIndex = itemId; if ( !_prefs_path.empty() ) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setString(_prefs_path + "/palette", possible[_currentIndex]->_name); + prefs->setString(_prefs_path + "/palette", pages[_currentIndex]->_name); } _rebuild(); @@ -852,7 +944,8 @@ void SwatchesPanel::_handleAction( int setId, int itemId ) void SwatchesPanel::_rebuild() { - JustForNow* curr = possible[_currentIndex]; + std::vector pages = _getSwatchSets(); + SwatchPage* curr = pages[_currentIndex]; _holder->clear(); if ( curr->_prefWidth > 0 ) { diff --git a/src/ui/dialog/swatches.h b/src/ui/dialog/swatches.h index 9dcf0303b..b18fd6cad 100644 --- a/src/ui/dialog/swatches.h +++ b/src/ui/dialog/swatches.h @@ -22,7 +22,7 @@ class PreviewHolder; namespace Dialogs { class ColorItem; - +class SwatchPage; /** * A panel that displays paint swatches. @@ -41,8 +41,6 @@ public: virtual SPDesktop* getDesktop() {return _currentDesktop;} virtual int getSelectedIndex() {return _currentIndex;} // temporary - virtual void handleGradientsChange(); // temporary - virtual void handleDefsModified(); protected: virtual void _updateFromSelection(); @@ -50,25 +48,25 @@ protected: virtual void _setDocument( SPDocument *document ); virtual void _rebuild(); + virtual std::vector _getSwatchSets() const; + private: SwatchesPanel(SwatchesPanel const &); // no copy SwatchesPanel &operator=(SwatchesPanel const &); // no assign + static void _trackDocument( SwatchesPanel *panel, SPDocument *document ); + static void handleGradientsChange(SPDocument *document); + static void handleDefsModified(SPDocument *document); + PreviewHolder* _holder; ColorItem* _clear; ColorItem* _remove; int _currentIndex; SPDesktop* _currentDesktop; SPDocument* _currentDocument; - void* _ptr; sigc::connection _documentConnection; - sigc::connection _resourceConnection; sigc::connection _selChanged; - sigc::connection _setModified; - sigc::connection _subselChanged; - sigc::connection _defsChanged; - sigc::connection _defsModified; }; } //namespace Dialogs -- 2.30.2