Code

draft of layer manager
[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"
20 namespace Inkscape {
22 LayerManager::LayerManager(SPDesktop *desktop)
23 : _desktop(desktop), _document(NULL)
24 {
25     _layer_connection = desktop->connectCurrentLayerChanged(sigc::hide<0>(sigc::mem_fun(*this, &LayerManager::_rebuild)));
26     _document_connection = desktop->connectDocumentReplaced(sigc::hide<0>(sigc::mem_fun(*this, &LayerManager::_setDocument)));
27     _setDocument(desktop->doc());
28 }
30 void LayerManager::_setDocument(SPDocument *document) {
31     if (_document) {
32         _resource_connection.disconnect();
33     }
34     _document = document;
35     if (document) {
36         _resource_connection = sp_document_resources_changed_connect(document, "layer", sigc::mem_fun(*this, &LayerManager::_rebuild));
37     }
38     _rebuild();
39 }
41 void LayerManager::_rebuild() {
42     _clear();
43     GSList const *layers=sp_document_get_resource_list(_document, "layers");
44     for ( GSList const *iter=layers ; iter ; iter = iter->next ) {
45         SPObject *layer=static_cast<SPObject *>(iter->data);
46         _addOne(layer);
47     }
48     SPObject *root=_desktop->currentRoot();
49     SPObject *layer=_desktop->currentLayer();
50     for ( ; layer ; layer = SP_OBJECT_PARENT(layer) ) {
51         if (!includes(layer)) {
52             _addOne(layer);
53         }
54         if ( layer == root ) {
55             break;
56         }
57     }
58 }
60 }
62 /*
63   Local Variables:
64   mode:c++
65   c-file-style:"stroustrup"
66   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
67   indent-tabs-mode:nil
68   fill-column:99
69   End:
70 */
71 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :