Code

stop structure rebuilds on change of selected layer. Added scrolling, pop-up menu...
[inkscape.git] / src / layer-manager.cpp
1 /*
2  * Inkscape::LayerManager - a view of a document's layers, relative
3  *                          to a particular desktop
4  *
5  * Copyright 2006  MenTaLguY  <mental@rydia.net>
6  *
7  * Released under GNU GPL, read the file 'COPYING' for more information
8  */
10 #include <sigc++/functors/mem_fun.h>
11 #include <sigc++/adaptors/hide.h>
12 #include "gc-managed.h"
13 #include "gc-finalized.h"
14 #include "document.h"
15 #include "desktop.h"
16 #include "layer-manager.h"
17 #include "ui/view/view.h"
18 #include "sp-object.h"
19 #include "xml/node.h"
21 namespace Inkscape {
23 LayerManager::LayerManager(SPDesktop *desktop)
24 : _desktop(desktop), _document(NULL)
25 {
26 //    _layer_connection = desktop->connectCurrentLayerChanged( sigc::hide<0>( sigc::mem_fun(*this, &LayerManager::_rebuild) ) );
28     sigc::bound_mem_functor1<void, Inkscape::LayerManager, SPDocument*> first = sigc::mem_fun(*this, &LayerManager::_setDocument);
30     // This next line has problems on gcc 4.0.2
31     sigc::slot<void, SPDocument*> base2 = first;
33     sigc::slot<void,SPDesktop*,SPDocument*> slot2 = sigc::hide<0>( base2 );
34     _document_connection = desktop->connectDocumentReplaced( slot2 );
36     _setDocument(desktop->doc());
37 }
39 void LayerManager::_setDocument(SPDocument *document) {
40     if (_document) {
41         _resource_connection.disconnect();
42     }
43     _document = document;
44     if (document) {
45         _resource_connection = sp_document_resources_changed_connect(document, "layer", sigc::mem_fun(*this, &LayerManager::_rebuild));
46     }
47     _rebuild();
48 }
50 void LayerManager::_rebuild() {
51     _clear();
52     GSList const *layers=sp_document_get_resource_list(_document, "layer");
53     SPObject *root=_desktop->currentRoot();
54     if ( root ) {
55         _addOne(root);
57         for ( GSList const *iter=layers ; iter ; iter = iter->next ) {
58             SPObject *layer=static_cast<SPObject *>(iter->data);
60             for ( SPObject* curr = layer; curr && (curr != root) ; curr = SP_OBJECT_PARENT(curr) ) {
61                 if ( (curr != root) && root->isAncestorOf(curr) && !includes(curr) ) {
62                     // Filter out objects in the middle of being deleted
64                     // Such may have been the cause of bug 1339397.
65                     // See http://sourceforge.net/tracker/index.php?func=detail&aid=1339397&group_id=93438&atid=604306
66                     SPObject const *higher = curr;
67                     while ( higher && (SP_OBJECT_PARENT(higher) != root) ) {
68                         higher = SP_OBJECT_PARENT(higher);
69                     }
70                     Inkscape::XML::Node* node = higher ? SP_OBJECT_REPR(higher) : 0;
71                     if ( node && node->parent() ) {
72                         _addOne(curr);
73                     }
74                 }
75             }
76         }
77     }
78 }
80 }
82 /*
83   Local Variables:
84   mode:c++
85   c-file-style:"stroustrup"
86   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
87   indent-tabs-mode:nil
88   fill-column:99
89   End:
90 */
91 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :