summaryrefslogtreecommitdiffstats
path: root/src/ui/dialog/symbols.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/dialog/symbols.cpp')
-rw-r--r--src/ui/dialog/symbols.cpp81
1 files changed, 42 insertions, 39 deletions
diff --git a/src/ui/dialog/symbols.cpp b/src/ui/dialog/symbols.cpp
index 4eeb1b5f0..989375bbd 100644
--- a/src/ui/dialog/symbols.cpp
+++ b/src/ui/dialog/symbols.cpp
@@ -49,6 +49,7 @@
#include "inkscape.h"
#include "sp-root.h"
#include "sp-use.h"
+#include "sp-defs.h"
#include "sp-symbol.h"
#ifdef WITH_LIBVISIO
@@ -246,12 +247,19 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) :
key = SPItem::display_key_new(1);
renderDrawing.setRoot(previewDocument->getRoot()->invoke_show(renderDrawing, key, SP_ITEM_SHOW_DISPLAY ));
+ // This might need to be a global variable so setTargetDesktop can modify it
+ SPDefs *defs = currentDocument->getDefs();
+ sigc::connection defsModifiedConn = (SP_OBJECT(defs))->connectModified(
+ sigc::mem_fun(*this, &SymbolsDialog::defsModified));
+ instanceConns.push_back(defsModifiedConn);
+
get_symbols();
draw_symbols( currentDocument ); /* Defaults to current document */
- desktopChangeConn =
+ sigc::connection desktopChangeConn =
deskTrack.connectDesktopChanged( sigc::mem_fun(*this, &SymbolsDialog::setTargetDesktop) );
instanceConns.push_back( desktopChangeConn );
+
deskTrack.connect(GTK_WIDGET(gobj()));
}
@@ -304,6 +312,13 @@ void SymbolsDialog::iconDragDataGet(const Glib::RefPtr<Gdk::DragContext>& /*cont
}
+void SymbolsDialog::defsModified(SPObject *object, guint flags)
+{
+ if ( !symbolSets[symbolSet->get_active_text()] ) {
+ rebuild();
+ }
+}
+
void SymbolsDialog::iconChanged() {
#if WITH_GTKMM_3_0
std::vector<Gtk::TreePath> iconArray = iconView->get_selected_items();
@@ -484,10 +499,8 @@ void SymbolsDialog::get_symbols() {
}
GSList* SymbolsDialog::symbols_in_doc_recursive (SPObject *r, GSList *l)
-{
- if (!r) {
- return l;
- }
+{
+ g_return_val_if_fail(r != NULL, l);
// Stop multiple counting of same symbol
if( SP_IS_USE(r) ) {
@@ -559,32 +572,32 @@ gchar const* SymbolsDialog::style_from_use( gchar const* id, SPDocument* documen
void SymbolsDialog::draw_symbols( SPDocument* symbolDocument ) {
-
- SymbolColumns* columns = getColumns();
-
GSList* l = symbols_in_doc( symbolDocument );
for( ; l != NULL; l = l->next ) {
-
SPObject* symbol = SP_OBJECT(l->data);
- if (!SP_IS_SYMBOL(symbol)) {
- //std::cout << " Error: not symbol" << std::endl;
- continue;
+ if (SP_IS_SYMBOL(symbol)) {
+ draw_symbol( symbol );
}
+ }
+}
- gchar const *id = symbol->getRepr()->attribute("id");
- gchar const *title = symbol->title(); // From title element
- if( !title ) {
- title = id;
- }
+void SymbolsDialog::draw_symbol( SPObject* symbol ) {
+
+ SymbolColumns* columns = getColumns();
- Glib::RefPtr<Gdk::Pixbuf> pixbuf = create_symbol_image(id, symbolDocument, &renderDrawing, key );
- if( pixbuf ) {
+ gchar const *id = symbol->getRepr()->attribute("id");
+ gchar const *title = symbol->title(); // From title element
+ if( !title ) {
+ title = id;
+ }
- Gtk::ListStore::iterator row = store->append();
- (*row)[columns->symbol_id] = Glib::ustring( id );
- (*row)[columns->symbol_title] = Glib::ustring( title );
- (*row)[columns->symbol_image] = pixbuf;
- }
+ Glib::RefPtr<Gdk::Pixbuf> pixbuf = create_symbol_image(id, symbol );
+
+ if( pixbuf ) {
+ Gtk::ListStore::iterator row = store->append();
+ (*row)[columns->symbol_id] = Glib::ustring( id );
+ (*row)[columns->symbol_title] = Glib::ustring( title );
+ (*row)[columns->symbol_image] = pixbuf;
}
delete columns;
@@ -600,18 +613,8 @@ void SymbolsDialog::draw_symbols( SPDocument* symbolDocument ) {
* the temporary document is rendered.
*/
Glib::RefPtr<Gdk::Pixbuf>
-SymbolsDialog::create_symbol_image(gchar const *symbol_id,
- SPDocument *source,
- Inkscape::Drawing* drawing,
- unsigned /*visionkey*/)
+SymbolsDialog::create_symbol_image(gchar const *symbol_id, SPObject *symbol)
{
- // Retrieve the symbol named 'symbol_id' from the source SVG document
- SPObject const* symbol = source->getObjectById(symbol_id);
- if (symbol == NULL) {
- //std::cout << " Failed to find symbol: " << symbol_id << std::endl;
- //return 0;
- }
-
// Create a copy repr of the symbol with id="the_symbol"
Inkscape::XML::Document *xml_doc = previewDocument->getReprDoc();
Inkscape::XML::Node *repr = symbol->getRepr()->duplicate(xml_doc);
@@ -628,10 +631,10 @@ SymbolsDialog::create_symbol_image(gchar const *symbol_id,
gchar const* style = repr->attribute("inkscape:symbol-style");
if( !style ) {
// If no default style in <symbol>, look in documents.
- if( source == currentDocument ) {
- style = style_from_use( symbol_id, source );
+ if( symbol->document == currentDocument ) {
+ style = style_from_use( symbol_id, symbol->document );
} else {
- style = source->getReprRoot()->attribute("style");
+ style = symbol->document->getReprRoot()->attribute("style");
}
}
// Last ditch effort to provide some default styling
@@ -721,7 +724,7 @@ SymbolsDialog::create_symbol_image(gchar const *symbol_id,
scale = atof( previewScaleString.c_str() );
}
- pixbuf = Glib::wrap(render_pixbuf(*drawing, scale, *dbox, psize));
+ pixbuf = Glib::wrap(render_pixbuf(renderDrawing, scale, *dbox, psize));
svg_preview_cache.set_preview_in_cache(key, pixbuf->gobj());
}