From: mental Date: Wed, 29 Mar 2006 01:29:44 +0000 (+0000) Subject: draft of layer manager X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=56881241fa725984d8184455e3f0c1b6de305c6b;p=inkscape.git draft of layer manager --- diff --git a/ChangeLog b/ChangeLog index b17a68f4a..304e61651 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2006-03-28 MenTaLguY + + * src/layer-manager.cpp, src/layer-manager.h: draft of layer manager + 2006-03-28 Jon A. Cruz * src/interface.cpp, src/dialogs/eek-color-def.h, diff --git a/src/Makefile_insert b/src/Makefile_insert index 22c1a2209..58cc25d52 100644 --- a/src/Makefile_insert +++ b/src/Makefile_insert @@ -80,6 +80,7 @@ libinkpre_a_SOURCES = \ knot.cpp knot.h \ knotholder.cpp knotholder.h \ layer-fns.cpp layer-fns.h \ + layer-manager.cpp layer-manager.h \ macros.h \ marker-status.cpp marker-status.h \ media.cpp media.h \ diff --git a/src/layer-manager.cpp b/src/layer-manager.cpp new file mode 100644 index 000000000..01af95424 --- /dev/null +++ b/src/layer-manager.cpp @@ -0,0 +1,71 @@ +/* + * Inkscape::LayerManager - a view of a document's layers, relative + * to a particular desktop + * + * Copyright 2006 MenTaLguY + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include +#include +#include "gc-managed.h" +#include "gc-finalized.h" +#include "document.h" +#include "desktop.h" +#include "layer-manager.h" +#include "ui/view/view.h" +#include "sp-object.h" + +namespace Inkscape { + +LayerManager::LayerManager(SPDesktop *desktop) +: _desktop(desktop), _document(NULL) +{ + _layer_connection = desktop->connectCurrentLayerChanged(sigc::hide<0>(sigc::mem_fun(*this, &LayerManager::_rebuild))); + _document_connection = desktop->connectDocumentReplaced(sigc::hide<0>(sigc::mem_fun(*this, &LayerManager::_setDocument))); + _setDocument(desktop->doc()); +} + +void LayerManager::_setDocument(SPDocument *document) { + if (_document) { + _resource_connection.disconnect(); + } + _document = document; + if (document) { + _resource_connection = sp_document_resources_changed_connect(document, "layer", sigc::mem_fun(*this, &LayerManager::_rebuild)); + } + _rebuild(); +} + +void LayerManager::_rebuild() { + _clear(); + GSList const *layers=sp_document_get_resource_list(_document, "layers"); + for ( GSList const *iter=layers ; iter ; iter = iter->next ) { + SPObject *layer=static_cast(iter->data); + _addOne(layer); + } + SPObject *root=_desktop->currentRoot(); + SPObject *layer=_desktop->currentLayer(); + for ( ; layer ; layer = SP_OBJECT_PARENT(layer) ) { + if (!includes(layer)) { + _addOne(layer); + } + if ( layer == root ) { + break; + } + } +} + +} + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : diff --git a/src/layer-manager.h b/src/layer-manager.h new file mode 100644 index 000000000..622cda1f2 --- /dev/null +++ b/src/layer-manager.h @@ -0,0 +1,52 @@ +/* + * Inkscape::LayerManager - a view of a document's layers, relative + * to a particular desktop + * + * Copyright 2006 MenTaLguY + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#ifndef SEEN_INKSCAPE_LAYER_MANAGER_H +#define SEEN_INKSCAPE_LAYER_MANAGER_H + +#include "document-subset.h" +#include "gc-finalized.h" +#include "gc-soft-ptr.h" + +class SPDocument; +class SPDocument; + +namespace Inkscape { + +class LayerManager : public DocumentSubset, + public GC::Finalized +{ +public: + LayerManager(SPDesktop *desktop); + +private: + void _setDocument(SPDocument *document); + void _rebuild(); + + sigc::connection _layer_connection; + sigc::connection _document_connection; + sigc::connection _resource_connection; + + GC::soft_ptr _desktop; + SPDocument *_document; +}; + +} + +#endif +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :