summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLiam P. White <inkscapebronyat-signgmaildotcom>2014-05-10 19:16:24 +0000
committerLiam P. White <inkscapebronyat-signgmaildotcom>2014-05-10 19:16:24 +0000
commit4038de8b4763974c97aa8fcb9d87b83c1a5daac7 (patch)
treeccad84e7516511ffd107c14688d8b4fb8a34f90d /src
parentFix stubborn bug 1299948 (diff)
downloadinkscape-4038de8b4763974c97aa8fcb9d87b83c1a5daac7.tar.gz
inkscape-4038de8b4763974c97aa8fcb9d87b83c1a5daac7.zip
Add selection sets
(bzr r13090.1.75)
Diffstat (limited to 'src')
-rw-r--r--src/Makefile_insert3
-rw-r--r--src/attributes.cpp1
-rw-r--r--src/attributes.h1
-rw-r--r--src/menus-skeleton.h1
-rw-r--r--src/sp-tag-use-reference.cpp156
-rw-r--r--src/sp-tag-use-reference.h77
-rw-r--r--src/sp-tag-use.cpp205
-rw-r--r--src/sp-tag-use.h54
-rw-r--r--src/sp-tag.cpp154
-rw-r--r--src/sp-tag.h57
-rw-r--r--src/ui/dialog/Makefile_insert2
-rw-r--r--src/ui/dialog/dialog-manager.cpp6
-rw-r--r--src/ui/dialog/tags.cpp1155
-rw-r--r--src/ui/dialog/tags.h181
-rw-r--r--src/verbs.cpp86
-rw-r--r--src/verbs.h4
16 files changed, 2134 insertions, 9 deletions
diff --git a/src/Makefile_insert b/src/Makefile_insert
index 6d0d6b08c..810f706ac 100644
--- a/src/Makefile_insert
+++ b/src/Makefile_insert
@@ -199,6 +199,9 @@ ink_common_sources += \
sp-style-elem.cpp sp-style-elem.h \
sp-switch.cpp sp-switch.h \
sp-symbol.cpp sp-symbol.h \
+ sp-tag.cpp sp-tag.h \
+ sp-tag-use.cpp sp-tag-use.h \
+ sp-tag-use-reference.cpp sp-tag-use-reference.h \
sp-text.cpp sp-text.h \
sp-textpath.h \
sp-title.cpp sp-title.h \
diff --git a/src/attributes.cpp b/src/attributes.cpp
index 4e39b648e..2dc0d8071 100644
--- a/src/attributes.cpp
+++ b/src/attributes.cpp
@@ -52,6 +52,7 @@ static SPStyleProp const props[] = {
{SP_ATTR_XLINK_ACTUATE, "xlink:actuate"},
{SP_ATTR_TARGET, "target"},
{SP_ATTR_INKSCAPE_GROUPMODE, "inkscape:groupmode"},
+ {SP_ATTR_INKSCAPE_EXPANDED, "inkscape:expanded"},
/* SPRoot */
{SP_ATTR_VERSION, "version"},
{SP_ATTR_WIDTH, "width"},
diff --git a/src/attributes.h b/src/attributes.h
index d1c93b819..270296c9a 100644
--- a/src/attributes.h
+++ b/src/attributes.h
@@ -52,6 +52,7 @@ enum SPAttributeEnum {
SP_ATTR_TARGET,
/* SPGroup */
SP_ATTR_INKSCAPE_GROUPMODE,
+ SP_ATTR_INKSCAPE_EXPANDED,
/* SPRoot */
SP_ATTR_VERSION,
SP_ATTR_WIDTH,
diff --git a/src/menus-skeleton.h b/src/menus-skeleton.h
index 67e600edf..18a26d82c 100644
--- a/src/menus-skeleton.h
+++ b/src/menus-skeleton.h
@@ -179,6 +179,7 @@ static char const menus_skeleton[] =
" </submenu>\n"
" <submenu name=\"" N_("_Object") "\">\n"
" <verb verb-id=\"DialogObjects\" />\n"
+" <verb verb-id=\"DialogTags\" />\n"
" <separator/>\n"
" <verb verb-id=\"DialogFillStroke\" />\n"
" <verb verb-id=\"DialogObjectProperties\" />\n"
diff --git a/src/sp-tag-use-reference.cpp b/src/sp-tag-use-reference.cpp
new file mode 100644
index 000000000..50c011812
--- /dev/null
+++ b/src/sp-tag-use-reference.cpp
@@ -0,0 +1,156 @@
+/*
+ * The reference corresponding to href of <inkscape:tagref> element.
+ *
+ * Copyright (C) Theodore Janeczko 2012-2014 <flutterguy317@gmail.com>
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information.
+ */
+
+#include <cstring>
+#include <string>
+#include <string.h>
+
+#include "enums.h"
+#include "sp-tag-use-reference.h"
+
+#include "display/curve.h"
+#include "livarot/Path.h"
+#include "preferences.h"
+#include "sp-shape.h"
+#include "sp-text.h"
+#include "uri.h"
+
+#if 0
+namespace {
+ SPObject* createTagUseReference() {
+ return new SPTag();
+ }
+ bool tagUseReferencesRegistered = SPFactory::instance().registerObject("inkscape:tag", createTag);
+}
+// this SPObject doesn't need to be registered
+#endif
+
+
+bool SPTagUseReference::_acceptObject(SPObject * const obj) const
+{
+ if (SP_IS_ITEM(obj)) {
+ SPObject * const owner = getOwner();
+ // Refuse references to us or to an ancestor.
+ for ( SPObject *iter = owner ; iter ; iter = iter->parent ) {
+ if ( iter == obj ) {
+ return false;
+ }
+ }
+ return true;
+ } else {
+ return false;
+ }
+}
+
+
+static void sp_usepath_href_changed(SPObject *old_ref, SPObject *ref, SPTagUsePath *offset);
+static void sp_usepath_delete_self(SPObject *deleted, SPTagUsePath *offset);
+
+SPTagUsePath::SPTagUsePath(SPObject* i_owner):SPTagUseReference(i_owner)
+{
+ owner=i_owner;
+ originalPath = NULL;
+ sourceDirty=false;
+ sourceHref = NULL;
+ sourceRepr = NULL;
+ sourceObject = NULL;
+ _changed_connection = changedSignal().connect(sigc::bind(sigc::ptr_fun(sp_usepath_href_changed), this)); // listening to myself, this should be virtual instead
+
+ user_unlink = NULL;
+}
+
+SPTagUsePath::~SPTagUsePath(void)
+{
+ delete originalPath;
+ originalPath = NULL;
+
+ _changed_connection.disconnect(); // to do before unlinking
+
+ quit_listening();
+ unlink();
+}
+
+void
+SPTagUsePath::link(char *to)
+{
+ if ( to == NULL ) {
+ quit_listening();
+ unlink();
+ } else {
+ if ( !sourceHref || ( strcmp(to, sourceHref) != 0 ) ) {
+ g_free(sourceHref);
+ sourceHref = g_strdup(to);
+ try {
+ attach(Inkscape::URI(to));
+ } catch (Inkscape::BadURIException &e) {
+ /* TODO: Proper error handling as per
+ * http://www.w3.org/TR/SVG11/implnote.html#ErrorProcessing.
+ */
+ g_warning("%s", e.what());
+ detach();
+ }
+ }
+ }
+}
+
+void
+SPTagUsePath::unlink(void)
+{
+ g_free(sourceHref);
+ sourceHref = NULL;
+ detach();
+}
+
+void
+SPTagUsePath::start_listening(SPObject* to)
+{
+ if ( to == NULL ) {
+ return;
+ }
+ sourceObject = to;
+ sourceRepr = to->getRepr();
+ _delete_connection = to->connectDelete(sigc::bind(sigc::ptr_fun(&sp_usepath_delete_self), this));
+}
+
+void
+SPTagUsePath::quit_listening(void)
+{
+ if ( sourceObject == NULL ) {
+ return;
+ }
+ _delete_connection.disconnect();
+ sourceRepr = NULL;
+ sourceObject = NULL;
+}
+
+static void
+sp_usepath_href_changed(SPObject */*old_ref*/, SPObject */*ref*/, SPTagUsePath *offset)
+{
+ offset->quit_listening();
+ SPItem *refobj = offset->getObject();
+ if ( refobj ) {
+ offset->start_listening(refobj);
+ }
+}
+
+static void
+sp_usepath_delete_self(SPObject */*deleted*/, SPTagUsePath *offset)
+{
+ offset->owner->deleteObject();
+}
+
+/*
+ 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 :
diff --git a/src/sp-tag-use-reference.h b/src/sp-tag-use-reference.h
new file mode 100644
index 000000000..b38e45837
--- /dev/null
+++ b/src/sp-tag-use-reference.h
@@ -0,0 +1,77 @@
+#ifndef SEEN_SP_TAG_USE_REFERENCE_H
+#define SEEN_SP_TAG_USE_REFERENCE_H
+
+/*
+ * The reference corresponding to href of <inkscape:tagref> element.
+ *
+ * Copyright (C) Theodore Janeczko 2012-2014 <flutterguy317@gmail.com>
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information.
+ */
+
+#include "sp-object.h"
+#include "sp-item.h"
+#include <uri-references.h>
+#include <stddef.h>
+#include <sigc++/sigc++.h>
+
+class Path;
+
+namespace Inkscape {
+namespace XML {
+ struct Node;
+}
+}
+
+
+class SPTagUseReference : public Inkscape::URIReference {
+public:
+ SPTagUseReference(SPObject *owner) : URIReference(owner) {}
+
+ SPItem *getObject() const {
+ return static_cast<SPItem *>(URIReference::getObject());
+ }
+
+protected:
+ virtual bool _acceptObject(SPObject * const obj) const;
+
+};
+
+
+class SPTagUsePath : public SPTagUseReference {
+public:
+ Path *originalPath;
+ bool sourceDirty;
+
+ SPObject *owner;
+ gchar *sourceHref;
+ Inkscape::XML::Node *sourceRepr;
+ SPObject *sourceObject;
+
+ sigc::connection _delete_connection;
+ sigc::connection _changed_connection;
+
+ SPTagUsePath(SPObject* i_owner);
+ ~SPTagUsePath(void);
+
+ void link(char* to);
+ void unlink(void);
+ void start_listening(SPObject* to);
+ void quit_listening(void);
+ void refresh_source(void);
+
+ void (*user_unlink) (SPObject *user);
+};
+
+#endif /* !SEEN_SP_USE_REFERENCE_H */
+
+/*
+ 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 :
diff --git a/src/sp-tag-use.cpp b/src/sp-tag-use.cpp
new file mode 100644
index 000000000..ffcfcee3e
--- /dev/null
+++ b/src/sp-tag-use.cpp
@@ -0,0 +1,205 @@
+/*
+ * SVG <inkscape:tagref> implementation
+ *
+ * Authors:
+ * Theodore Janeczko
+ * Liam P White
+ *
+ * Copyright (C) Theodore Janeczko 2012-2014 <flutterguy317@gmail.com>
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <cstring>
+#include <string>
+
+#include <glibmm/i18n.h>
+#include "display/drawing-group.h"
+#include "attributes.h"
+#include "document.h"
+#include "uri.h"
+#include "xml/repr.h"
+#include "preferences.h"
+#include "style.h"
+#include "sp-factory.h"
+#include "sp-symbol.h"
+#include "sp-tag-use.h"
+#include "sp-tag-use-reference.h"
+
+namespace {
+ SPObject* createTagUse() {
+ return new SPTagUse();
+ }
+ bool tagUseRegistered = SPFactory::instance().registerObject("inkscape:tagref", createTagUse);
+}
+
+SPTagUse::SPTagUse()
+{
+ href = NULL;
+ //new (_changed_connection) sigc::connection;
+ ref = new SPTagUseReference(this);
+
+ _changed_connection = ref->changedSignal().connect(sigc::mem_fun(*this, &SPTagUse::href_changed));
+}
+
+SPTagUse::~SPTagUse()
+{
+
+ if (child) {
+ detach(child);
+ child = NULL;
+ }
+
+ ref->detach();
+ delete ref;
+ ref = 0;
+
+ _changed_connection.~connection(); //FIXME why?
+}
+
+void
+SPTagUse::build(SPDocument *document, Inkscape::XML::Node *repr)
+{
+ SPObject::build(document, repr);
+ readAttr( "xlink:href" );
+
+ // We don't need to create child here:
+ // reading xlink:href will attach ref, and that will cause the changed signal to be emitted,
+ // which will call sp_tag_use_href_changed, and that will take care of the child
+}
+
+void
+SPTagUse::release()
+{
+
+ if (child) {
+ detach(child);
+ child = NULL;
+ }
+
+ _changed_connection.disconnect();
+
+ g_free(href);
+ href = NULL;
+
+ ref->detach();
+
+ SPObject::release();
+}
+
+void
+SPTagUse::set(unsigned key, gchar const *value)
+{
+
+ switch (key) {
+ case SP_ATTR_XLINK_HREF: {
+ if ( value && href && ( strcmp(value, href) == 0 ) ) {
+ /* No change, do nothing. */
+ } else {
+ g_free(href);
+ href = NULL;
+ if (value) {
+ // First, set the href field, because sp_tag_use_href_changed will need it.
+ href = g_strdup(value);
+
+ // Now do the attaching, which emits the changed signal.
+ try {
+ ref->attach(Inkscape::URI(value));
+ } catch (Inkscape::BadURIException &e) {
+ g_warning("%s", e.what());
+ ref->detach();
+ }
+ } else {
+ ref->detach();
+ }
+ }
+ break;
+ }
+
+ default:
+ SPObject::set(key, value);
+ break;
+ }
+}
+
+Inkscape::XML::Node *
+SPTagUse::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags)
+{
+ if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) {
+ repr = xml_doc->createElement("inkscape:tagref");
+ }
+
+ SPObject::write(xml_doc, repr, flags);
+
+ if (ref->getURI()) {
+ gchar *uri_string = ref->getURI()->toString();
+ repr->setAttribute("xlink:href", uri_string);
+ g_free(uri_string);
+ }
+
+ return repr;
+}
+
+/**
+ * Returns the ultimate original of a SPTagUse (i.e. the first object in the chain of its originals
+ * which is not an SPTagUse). If no original is found, NULL is returned (it is the responsibility
+ * of the caller to make sure that this is handled correctly).
+ *
+ * Note that the returned is the clone object, i.e. the child of an SPTagUse (of the argument one for
+ * the trivial case) and not the "true original".
+ */
+
+SPItem * SPTagUse::root()
+{
+ SPObject *orig = child;
+ while (orig && SP_IS_TAG_USE(orig)) {
+ orig = SP_TAG_USE(orig)->child;
+ }
+ if (!orig || !SP_IS_ITEM(orig))
+ return NULL;
+ return SP_ITEM(orig);
+}
+
+void
+SPTagUse::href_changed(SPObject */*old_ref*/, SPObject */*ref*/)
+{
+ if (href) {
+ SPItem *refobj = ref->getObject();
+ if (refobj) {
+ Inkscape::XML::Node *childrepr = refobj->getRepr();
+ const std::string typeString = NodeTraits::get_type_string(*childrepr);
+
+ SPObject* child_ = SPFactory::instance().createObject(typeString);
+ if (child_) {
+ attach(child_, lastChild());
+ sp_object_unref(child_, 0);
+ child_->invoke_build(this->document, childrepr, TRUE);
+
+ }
+ }
+ }
+}
+
+SPItem * SPTagUse::get_original()
+{
+ SPItem *ref_ = NULL;
+ if (ref) {
+ ref_ = ref->getObject();
+ }
+ return ref_;
+}
+
+/*
+ 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 :
diff --git a/src/sp-tag-use.h b/src/sp-tag-use.h
new file mode 100644
index 000000000..8a0c3e7fb
--- /dev/null
+++ b/src/sp-tag-use.h
@@ -0,0 +1,54 @@
+#ifndef __SP_TAG_USE_H__
+#define __SP_TAG_USE_H__
+
+/*
+ * SVG <inkscape:tagref> implementation
+ *
+ * Authors:
+ * Theodore Janeczko
+ *
+ * Copyright (C) Theodore Janeczko 2012 <flutterguy317@gmail.com>
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#include <stddef.h>
+#include <sigc++/sigc++.h>
+#include "svg/svg-length.h"
+#include "sp-object.h"
+
+
+#define SP_TAG_USE(obj) (dynamic_cast<SPTagUse*> (obj))
+#define SP_IS_TAG_USE(obj) (dynamic_cast<SPTagUse*> (obj) != NULL)
+
+class SPTagUse;
+class SPTagUseReference;
+
+class SPTagUse : public SPObject {
+
+public:
+ // item built from the original's repr (the visible clone)
+ // relative to the SPUse itself, it is treated as a child, similar to a grouped item relative to its group
+ SPObject *child;
+ gchar *href;
+public:
+ SPTagUse();
+ virtual ~SPTagUse();
+
+ virtual void build(SPDocument *doc, Inkscape::XML::Node *repr);
+ virtual void set(unsigned key, gchar const *value);
+ virtual Inkscape::XML::Node* write(Inkscape::XML::Document* doc, Inkscape::XML::Node* repr, guint flags);
+ virtual void release();
+
+ virtual void href_changed(SPObject* old_ref, SPObject* ref);
+
+ //virtual SPItem* unlink();
+ virtual SPItem* get_original();
+ virtual SPItem* root();
+
+ // the reference to the original object
+ SPTagUseReference *ref;
+ sigc::connection _changed_connection;
+};
+
+#endif
diff --git a/src/sp-tag.cpp b/src/sp-tag.cpp
new file mode 100644
index 000000000..c4b40417f
--- /dev/null
+++ b/src/sp-tag.cpp
@@ -0,0 +1,154 @@
+/** \file
+ * SVG <inkscape:tag> implementation
+ *
+ * Authors:
+ * Theodore Janeczko
+ * Liam P. White
+ *
+ * Copyright (C) Theodore Janeczko 2012-2014 <flutterguy317@gmail.com>
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "attributes.h"
+#include "sp-factory.h"
+#include "sp-tag.h"
+#include "xml/repr.h"
+#include <cstring>
+
+namespace {
+ SPObject* createTag() {
+ return new SPTag();
+ }
+ bool tagsRegistered = SPFactory::instance().registerObject("inkscape:tag", createTag);
+}
+
+/*
+ * Move this SPItem into or after another SPItem in the doc
+ * \param target - the SPItem to move into or after
+ * \param intoafter - move to after the target (false), move inside (sublayer) of the target (true)
+ */
+void SPTag::moveTo(SPObject *target, gboolean intoafter) {
+
+ Inkscape::XML::Node *target_ref = ( target ? target->getRepr() : NULL );
+ Inkscape::XML::Node *our_ref = getRepr();
+ gboolean first = FALSE;
+
+ if (target_ref == our_ref) {
+ // Move to ourself ignore
+ return;
+ }
+
+ if (!target_ref) {
+ // Assume move to the "first" in the top node, find the top node
+ target_ref = our_ref;
+ while (target_ref->parent() != target_ref->root()) {
+ target_ref = target_ref->parent();
+ }
+ first = TRUE;
+ }
+
+ if (intoafter) {
+ // Move this inside of the target at the end
+ our_ref->parent()->removeChild(our_ref);
+ target_ref->addChild(our_ref, NULL);
+ } else if (target_ref->parent() != our_ref->parent()) {
+ // Change in parent, need to remove and add
+ our_ref->parent()->removeChild(our_ref);
+ target_ref->parent()->addChild(our_ref, target_ref);
+ } else if (!first) {
+ // Same parent, just move
+ our_ref->parent()->changeOrder(our_ref, target_ref);
+ }
+}
+
+/**
+ * Reads the Inkscape::XML::Node, and initializes SPTag variables. For this to get called,
+ * our name must be associated with a repr via "sp_object_type_register". Best done through
+ * sp-object-repr.cpp's repr_name_entries array.
+ */
+void
+SPTag::build(SPDocument *document, Inkscape::XML::Node *repr)
+{
+ readAttr( "inkscape:expanded" );
+ SPObject::build(document, repr);
+}
+
+/**
+ * Sets a specific value in the SPTag.
+ */
+void
+SPTag::set(unsigned int key, gchar const *value)
+{
+
+ switch (key)
+ {
+ case SP_ATTR_INKSCAPE_EXPANDED:
+ if ( value && !strcmp(value, "true") ) {
+ setExpanded(true);
+ }
+ break;
+ default:
+ SPObject::set(key, value);
+ break;
+ }
+}
+
+void SPTag::setExpanded(bool isexpanded) {
+ //if ( _expanded != isexpanded ){
+ _expanded = isexpanded;
+ //}
+}
+
+/**
+ * Receives update notifications.
+ */
+void
+SPTag::update(SPCtx *ctx, guint flags)
+{
+ if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG |
+ SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) {
+
+ /* do something to trigger redisplay, updates? */
+
+ }
+ SPObject::update(ctx, flags);
+}
+
+/**
+ * Writes its settings to an incoming repr object, if any.
+ */
+Inkscape::XML::Node *
+SPTag::write(Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags)
+{
+ if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) {
+ repr = doc->createElement("inkscape:tag");
+ }
+
+ // Inkscape-only object, not copied during an "plain SVG" dump:
+ if (flags & SP_OBJECT_WRITE_EXT) {
+ if (_expanded) {
+ repr->setAttribute("inkscape:expanded", "true");
+ } else {
+ repr->setAttribute("inkscape:expanded", NULL);
+ }
+ }
+ SPObject::write(doc, repr, flags);
+ return repr;
+}
+
+
+/*
+ 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:fileencoding=utf-8:textwidth=99 :
diff --git a/src/sp-tag.h b/src/sp-tag.h
new file mode 100644
index 000000000..927bb45d1
--- /dev/null
+++ b/src/sp-tag.h
@@ -0,0 +1,57 @@
+#ifndef SP_TAG_H_SEEN
+#define SP_TAG_H_SEEN
+
+/** \file
+ * SVG <inkscape:tag> implementation
+ *
+ * Authors:
+ * Theodore Janeczko
+ *
+ * Copyright (C) Theodore Janeczko 2012 <flutterguy317@gmail.com>
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#include "sp-object.h"
+
+/* Skeleton base class */
+
+#define SP_TAG(o) (dynamic_cast<SPTag*>(o))
+#define SP_IS_TAG(o) (dynamic_cast<SPTag*>(o) != NULL)
+
+class SPTag;
+
+class SPTag : public SPObject {
+public:
+ SPTag() {}
+ virtual ~SPTag() {}
+
+ virtual void build(SPDocument * doc, Inkscape::XML::Node *repr);
+ //virtual void release();
+ virtual void set(unsigned key, const gchar* value);
+ virtual void update(SPCtx * ctx, unsigned flags);
+
+ virtual Inkscape::XML::Node* write(Inkscape::XML::Document* doc, Inkscape::XML::Node* repr, guint flags);
+
+ bool expanded() const { return _expanded; }
+ void setExpanded(bool isexpanded);
+
+ void moveTo(SPObject *target, gboolean intoafter);
+
+private:
+ bool _expanded;
+};
+
+
+#endif /* !SP_SKELETON_H_SEEN */
+
+/*
+ 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:fileencoding=utf-8:textwidth=99 :
diff --git a/src/ui/dialog/Makefile_insert b/src/ui/dialog/Makefile_insert
index 8a7a4a5dd..1aa73dc5b 100644
--- a/src/ui/dialog/Makefile_insert
+++ b/src/ui/dialog/Makefile_insert
@@ -100,6 +100,8 @@ ink_common_sources += \
ui/dialog/template-load-tab.h \
ui/dialog/template-widget.cpp \
ui/dialog/template-widget.h \
+ ui/dialog/tags.cpp \
+ ui/dialpg/tags.h \
ui/dialog/text-edit.cpp \
ui/dialog/text-edit.h \
ui/dialog/tile.cpp \
diff --git a/src/ui/dialog/dialog-manager.cpp b/src/ui/dialog/dialog-manager.cpp
index 22c41d75e..bd2f1eb12 100644
--- a/src/ui/dialog/dialog-manager.cpp
+++ b/src/ui/dialog/dialog-manager.cpp
@@ -55,7 +55,7 @@
#include "ui/dialog/clonetiler.h"
#include "ui/dialog/svg-fonts-dialog.h"
#include "ui/dialog/objects.h"
-//#include "ui/dialog/tags.h"
+#include "ui/dialog/tags.h"
namespace Inkscape {
namespace UI {
@@ -113,7 +113,7 @@ DialogManager::DialogManager() {
registerFactory("IconPreviewPanel", &create<IconPreviewPanel, FloatingBehavior>);
registerFactory("LayersPanel", &create<LayersPanel, FloatingBehavior>);
registerFactory("ObjectsPanel", &create<ObjectsPanel, FloatingBehavior>);
-// registerFactory("TagsPanel", &create<TagsPanel, FloatingBehavior>);
+ registerFactory("TagsPanel", &create<TagsPanel, FloatingBehavior>);
registerFactory("LivePathEffect", &create<LivePathEffectEditor, FloatingBehavior>);
registerFactory("Memory", &create<Memory, FloatingBehavior>);
registerFactory("Messages", &create<Messages, FloatingBehavior>);
@@ -148,7 +148,7 @@ DialogManager::DialogManager() {
registerFactory("IconPreviewPanel", &create<IconPreviewPanel, DockBehavior>);
registerFactory("LayersPanel", &create<LayersPanel, DockBehavior>);
registerFactory("ObjectsPanel", &create<ObjectsPanel, DockBehavior>);
-// registerFactory("TagsPanel", &create<TagsPanel, DockBehavior>);
+ registerFactory("TagsPanel", &create<TagsPanel, DockBehavior>);
registerFactory("LivePathEffect", &create<LivePathEffectEditor, DockBehavior>);
registerFactory("Memory", &create<Memory, DockBehavior>);
registerFactory("Messages", &create<Messages, DockBehavior>);
diff --git a/src/ui/dialog/tags.cpp b/src/ui/dialog/tags.cpp
new file mode 100644
index 000000000..7fdd2e906
--- /dev/null
+++ b/src/ui/dialog/tags.cpp
@@ -0,0 +1,1155 @@
+/*
+ * A simple panel for tags
+ *
+ * Authors:
+ * Theodore Janeczko
+ *
+ * Copyright (C) Theodore Janeczko 2012 <flutterguy317@gmail.com>
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "tags.h"
+#include <gtkmm/widget.h>
+#include <gtkmm/icontheme.h>
+#include <gtkmm/imagemenuitem.h>
+#include <gtkmm/separatormenuitem.h>
+
+#include <glibmm/i18n.h>
+
+#include "desktop.h"
+#include "desktop-style.h"
+#include "document.h"
+#include "document-undo.h"
+#include "helper/action.h"
+#include "inkscape.h"
+#include "layer-fns.h"
+#include "layer-manager.h"
+#include "preferences.h"
+#include "sp-item.h"
+#include "sp-object.h"
+#include "sp-shape.h"
+#include "svg/css-ostringstream.h"
+#include "ui/icon-names.h"
+#include "ui/widget/layertypeicon.h"
+#include "ui/widget/addtoicon.h"
+#include "verbs.h"
+#include "widgets/icon.h"
+#include "xml/node.h"
+#include "xml/node-observer.h"
+#include "xml/repr.h"
+#include "sp-root.h"
+#include "ui/tools/tool-base.h" //"event-context.h"
+#include "selection.h"
+#include "dialogs/dialog-events.h"
+#include "widgets/sp-color-notebook.h"
+#include "style.h"
+#include "filter-chemistry.h"
+#include "filters/blend.h"
+#include "filters/gaussian-blur.h"
+#include "sp-clippath.h"
+#include "sp-mask.h"
+#include "sp-tag.h"
+#include "sp-defs.h"
+#include "sp-tag-use.h"
+#include "sp-tag-use-reference.h"
+
+//#define DUMP_LAYERS 1
+
+namespace Inkscape {
+namespace UI {
+namespace Dialog {
+
+using Inkscape::XML::Node;
+
+TagsPanel& TagsPanel::getInstance()
+{
+ return *new TagsPanel();
+}
+
+enum {
+ COL_ADD = 1
+};
+
+enum {
+ BUTTON_NEW = 0,
+ BUTTON_TOP,
+ BUTTON_BOTTOM,
+ BUTTON_UP,
+ BUTTON_DOWN,
+ BUTTON_DELETE,
+ DRAGNDROP
+};
+
+class TagsPanel::ObjectWatcher : public Inkscape::XML::NodeObserver {
+public:
+ ObjectWatcher(TagsPanel* pnl, SPObject* obj, Inkscape::XML::Node * repr) :
+ _pnl(pnl),
+ _obj(obj),
+ _repr(repr),
+ _labelAttr(g_quark_from_string("inkscape:label"))
+ {}
+
+ ObjectWatcher(TagsPanel* pnl, SPObject* obj) :
+ _pnl(pnl),
+ _obj(obj),
+ _repr(obj->getRepr()),
+ _labelAttr(g_quark_from_string("inkscape:label"))
+ {}
+
+ virtual void notifyChildAdded( Node &/*node*/, Node &/*child*/, Node */*prev*/ )
+ {
+ if ( _pnl && _obj ) {
+ _pnl->_objectsChanged( _obj );
+ }
+ }
+ virtual void notifyChildRemoved( Node &/*node*/, Node &/*child*/, Node */*prev*/ )
+ {
+ if ( _pnl && _obj ) {
+ _pnl->_objectsChanged( _obj );
+ }
+ }
+ virtual void notifyChildOrderChanged( Node &/*node*/, Node &/*child*/, Node */*old_prev*/, Node */*new_prev*/ )
+ {
+ if ( _pnl && _obj ) {
+ _pnl->_objectsChanged( _obj );
+ }
+ }
+ virtual void notifyContentChanged( Node &/*node*/, Util::ptr_shared<char> /*old_content*/, Util::ptr_shared<char> /*new_content*/ ) {}
+ virtual void notifyAttributeChanged( Node &/*node*/, GQuark name, Util::ptr_shared<char> /*old_value*/, Util::ptr_shared<char> /*new_value*/ ) {
+ if ( _pnl && _obj ) {
+ if ( name == _labelAttr ) {
+ _pnl->_updateObject( _obj);
+ }
+ }
+ }
+
+ TagsPanel* _pnl;
+ SPObject* _obj;
+ Inkscape::XML::Node* _repr;
+ GQuark _labelAttr;
+};
+
+class TagsPanel::InternalUIBounce
+{
+public:
+ int _actionCode;
+};
+
+void TagsPanel::_styleButton( Gtk::Button& btn, SPDesktop *desktop, unsigned int code, char const* iconName, char const* tooltip )
+{
+ bool set = false;
+
+ if ( iconName ) {
+ GtkWidget *child = sp_icon_new( Inkscape::ICON_SIZE_SMALL_TOOLBAR, iconName );
+ gtk_widget_show( child );
+ btn.add( *manage(Glib::wrap(child)) );
+ btn.set_relief(Gtk::RELIEF_NONE);
+ set = true;
+ }
+
+ if ( desktop ) {
+ Verb *verb = Verb::get( code );
+ if ( verb ) {
+ SPAction *action = verb->get_action(desktop);
+ if ( !set && action && action->image ) {
+ GtkWidget *child = sp_icon_new( Inkscape::ICON_SIZE_SMALL_TOOLBAR, action->image );
+ gtk_widget_show( child );
+ btn.add( *manage(Glib::wrap(child)) );
+ set = true;
+ }
+ }
+ }
+
+ btn.set_tooltip_text (tooltip);
+}
+
+
+Gtk::MenuItem& TagsPanel::_addPopupItem( SPDesktop *desktop, unsigned int code, char const* iconName, char const* fallback, int id )
+{
+ GtkWidget* iconWidget = 0;
+ const char* label = 0;
+
+ if ( iconName ) {
+ iconWidget = sp_icon_new( Inkscape::ICON_SIZE_MENU, iconName );
+ }
+
+ if ( desktop ) {
+ Verb *verb = Verb::get( code );
+ if ( verb ) {
+ SPAction *action = verb->get_action(desktop);
+ if ( !iconWidget && action && action->image ) {
+ iconWidget = sp_icon_new( Inkscape::ICON_SIZE_MENU, action->image );
+ }
+
+ if ( action ) {
+ label = action->name;
+ }
+ }
+ }
+
+ if ( !label && fallback ) {
+ label = fallback;
+ }
+
+ Gtk::Widget* wrapped = 0;
+ if ( iconWidget ) {
+ wrapped = manage(Glib::wrap(iconWidget));
+ wrapped->show();
+ }
+
+
+ Gtk::MenuItem* item = 0;
+
+ if (wrapped) {
+ item = Gtk::manage(new Gtk::ImageMenuItem(*wrapped, label, true));
+ } else {
+ item = Gtk::manage(new Gtk::MenuItem(label, true));
+ }
+
+ item->signal_activate().connect(sigc::bind(sigc::mem_fun(*this, &TagsPanel::_takeAction), id));
+ _popupMenu.append(*item);
+
+ return *item;
+}
+
+void TagsPanel::_fireAction( unsigned int code )
+{
+ if ( _desktop ) {
+ Verb *verb = Verb::get( code );
+ if ( verb ) {
+ SPAction *action = verb->get_action(_desktop);
+ if ( action ) {
+ sp_action_perform( action, NULL );
+ }
+ }
+ }
+}
+
+void TagsPanel::_takeAction( int val )
+{
+ if ( !_pending ) {
+ _pending = new InternalUIBounce();
+ _pending->_actionCode = val;
+ Glib::signal_timeout().connect( sigc::mem_fun(*this, &TagsPanel::_executeAction), 0 );
+ }
+}
+
+bool TagsPanel::_executeAction()
+{
+ // Make sure selected layer hasn't changed since the action was triggered
+ if ( _pending)
+ {
+ int val = _pending->_actionCode;
+// SPObject* target = _pending->_target;
+ bool empty = _desktop->selection->isEmpty();
+
+ switch ( val ) {
+ case BUTTON_NEW:
+ {
+ _fireAction( SP_VERB_TAG_NEW );
+ }
+ break;
+ case BUTTON_TOP:
+ {
+ _fireAction( empty ? SP_VERB_LAYER_TO_TOP : SP_VERB_SELECTION_TO_FRONT);
+ }
+ break;
+ case BUTTON_BOTTOM:
+ {
+ _fireAction( empty ? SP_VERB_LAYER_TO_BOTTOM : SP_VERB_SELECTION_TO_BACK );
+ }
+ break;
+ case BUTTON_UP:
+ {
+ _fireAction( empty ? SP_VERB_LAYER_RAISE : SP_VERB_SELECTION_RAISE );
+ }
+ break;
+ case BUTTON_DOWN:
+ {
+ _fireAction( empty ? SP_VERB_LAYER_LOWER : SP_VERB_SELECTION_LOWER );
+ }
+ break;
+ case BUTTON_DELETE:
+ {
+ std::vector<SPObject *> todelete;
+ _tree.get_selection()->selected_foreach_iter(sigc::bind<std::vector<SPObject *>*>(sigc::mem_fun(*this, &TagsPanel::_checkForDeleted), &todelete));
+ for (std::vector<SPObject *>::iterator iter = todelete.begin(); iter != todelete.end(); ++iter) {
+ SPObject * obj = *iter;
+ if (obj && obj->parent && obj->getRepr() && obj->parent->getRepr()) {
+ obj->parent->getRepr()->removeChild(obj->getRepr());
+ }
+ }
+ DocumentUndo::done(_document, SP_VERB_DIALOG_TAGS, _("Remove from selection set"));
+ }
+ break;
+ case DRAGNDROP:
+ {
+ _doTreeMove( );
+ }
+ break;
+ }
+
+ delete _pending;
+ _pending = 0;
+ }
+
+ return false;
+}
+
+
+class TagsPanel::ModelColumns : public Gtk::TreeModel::ColumnRecord
+{
+public:
+
+ ModelColumns()
+ {
+ add(_colParentObject);
+ add(_colObject);
+ add(_colLabel);
+ add(_colAddRemove);
+ add(_colAllowAddRemove);
+ }
+ virtual ~ModelColumns() {}
+
+ Gtk::TreeModelColumn<SPObject*> _colParentObject;
+ Gtk::TreeModelColumn<SPObject*> _colObject;
+ Gtk::TreeModelColumn<Glib::ustring> _colLabel;
+ Gtk::TreeModelColumn<bool> _colAddRemove;
+ Gtk::TreeModelColumn<bool> _colAllowAddRemove;
+};
+
+void TagsPanel::_checkForDeleted(const Gtk::TreeIter& iter, std::vector<SPObject *>* todelete)
+{
+ Gtk::TreeRow row = *iter;
+ SPObject * obj = row[_model->_colObject];
+ if (obj && obj->parent) {
+ todelete->push_back(obj);
+ }
+}
+
+void TagsPanel::_updateObject( SPObject *obj ) {
+ _store->foreach( sigc::bind<SPObject*>(sigc::mem_fun(*this, &TagsPanel::_checkForUpdated), obj) );
+}
+
+bool TagsPanel::_checkForUpdated(const Gtk::TreePath &/*path*/, const Gtk::TreeIter& iter, SPObject* obj)
+{
+ Gtk::TreeModel::Row row = *iter;
+ if ( obj == row[_model->_colObject] )
+ {
+ /*
+ * We get notified of layer update here (from layer->setLabel()) before layer->label() is set
+ * with the correct value (sp-object bug?). So use the inkscape:label attribute instead which
+ * has the correct value (bug #168351)
+ */
+ //row[_model->_colLabel] = layer->label() ? layer->label() : layer->getId();
+ gchar const *label;
+ SPTagUse * use = SP_IS_TAG_USE(obj) ? SP_TAG_USE(obj) : 0;
+ if (use && use->ref->isAttached()) {
+ label = use->ref->getObject()->getAttribute("inkscape:label");
+ } else {
+ label = obj->getAttribute("inkscape:label");
+ }
+ row[_model->_colLabel] = label ? label : obj->getId();
+ row[_model->_colAddRemove] = SP_IS_TAG(obj);
+ }
+
+ return false;
+}
+
+void TagsPanel::_objectsSelected( Selection *sel ) {
+
+ _selectedConnection.block();
+ _tree.get_selection()->unselect_all();
+ for (const GSList * iter = sel->list(); iter != NULL; iter = iter->next)
+ {
+ SPObject *obj = reinterpret_cast<SPObject *>(iter->data);
+ _store->foreach(sigc::bind<SPObject *>( sigc::mem_fun(*this, &TagsPanel::_checkForSelected), obj));
+ }
+ _selectedConnection.unblock();
+ _checkTreeSelection();
+}
+
+bool TagsPanel::_checkForSelected(const Gtk::TreePath &path, const Gtk::TreeIter& iter, SPObject* obj)
+{
+ Gtk::TreeModel::Row row = *iter;
+ SPObject * it = row[_model->_colObject];
+ if ( it && SP_IS_TAG_USE(it) && SP_TAG_USE(it)->ref->getObject() == obj )
+ {
+ Glib::RefPtr<Gtk::TreeSelection> select = _tree.get_selection();
+
+ select->select(iter);
+ }
+ return false;
+}
+
+void TagsPanel::_objectsChanged(SPObject* root)
+{
+ while (!_objectWatchers.empty())
+ {
+ TagsPanel::ObjectWatcher *w = _objectWatchers.back();
+ w->_repr->removeObserver(*w);
+ _objectWatchers.pop_back();
+ delete w;
+ }
+
+ if (_desktop) {
+ SPDocument* document = _desktop->doc();
+ SPDefs* root = document->getDefs();
+ if ( root ) {
+ _selectedConnection.block();
+ _store->clear();
+ _addObject( document, root, 0 );
+ _selectedConnection.unblock();
+ _objectsSelected(_desktop->selection);
+ _checkTreeSelection();
+ }
+ }
+}
+
+void TagsPanel::_addObject( SPDocument* doc, SPObject* obj, Gtk::TreeModel::Row* parentRow )
+{
+ if ( _desktop && obj ) {
+ for ( SPObject *child = obj->children; child != NULL; child = child->next) {
+ if (SP_IS_TAG(child))
+ {
+ Gtk::TreeModel::iterator iter = parentRow ? _store->prepend(parentRow->children()) : _store->prepend();
+ Gtk::TreeModel::Row row = *iter;
+ row[_model->_colObject] = child;
+ row[_model->_colParentObject] = NULL;
+ row[_model->_colLabel] = child->label() ? child->label() : child->getId();
+ row[_model->_colAddRemove] = true;
+ row[_model->_colAllowAddRemove] = true;
+
+ _tree.expand_to_path( _store->get_path(iter) );
+
+ TagsPanel::ObjectWatcher *w = new TagsPanel::ObjectWatcher(this, child);
+ child->getRepr()->addObserver(*w);
+ _objectWatchers.push_back(w);
+ _addObject( doc, child, &row );
+ }
+ }
+ if (SP_IS_TAG(obj) && obj->children)
+ {
+ Gtk::TreeModel::iterator iteritems = parentRow ? _store->append(parentRow->children()) : _store->prepend();
+ Gtk::TreeModel::Row rowitems = *iteritems;
+ rowitems[_model->_colObject] = NULL;
+ rowitems[_model->_colParentObject] = obj;
+ rowitems[_model->_colLabel] = _("Items");
+ rowitems[_model->_colAddRemove] = false;
+ rowitems[_model->_colAllowAddRemove] = false;
+
+ _tree.expand_to_path( _store->get_path(iteritems) );
+
+ for ( SPObject *child = obj->children; child != NULL; child = child->next) {
+ if (SP_IS_TAG_USE(child))
+ {
+ SPItem *item = SP_TAG_USE(child)->ref->getObject();
+ Gtk::TreeModel::iterator iter = _store->prepend(rowitems->children());
+ Gtk::TreeModel::Row row = *iter;
+ row[_model->_colObject] = child;
+ row[_model->_colParentObject] = NULL;
+ row[_model->_colLabel] = item ? (item->label() ? item->label() : item->getId()) : SP_TAG_USE(child)->href;
+ row[_model->_colAddRemove] = false;
+ row[_model->_colAllowAddRemove] = true;
+
+ if (SP_TAG(obj)->expanded()) {
+ _tree.expand_to_path( _store->get_path(iter) );
+ }
+
+ if (item) {
+ TagsPanel::ObjectWatcher *w = new TagsPanel::ObjectWatcher(this, child, item->getRepr());
+ item->getRepr()->addObserver(*w);
+ _objectWatchers.push_back(w);
+ }
+ }
+ }
+ }
+ }
+}
+
+void TagsPanel::_select_tag( SPTag * tag )
+{
+ for (SPObject * child = tag->children; child != NULL; child = child->next)
+ {
+ if (SP_IS_TAG(child)) {
+ _select_tag(SP_TAG(child));
+ } else if (SP_IS_TAG_USE(child)) {
+ SPObject * obj = SP_TAG_USE(child)->ref->getObject();
+ if (obj) {
+ if (_desktop->selection->isEmpty()) _desktop->setCurrentLayer(obj->parent);
+ _desktop->selection->add(obj);
+ }
+ }
+ }
+}
+
+void TagsPanel::_selected_row_callback( const Gtk::TreeModel::iterator& iter )
+{
+ if (iter) {
+ Gtk::TreeModel::Row row = *iter;
+ SPObject *obj = row[_model->_colObject];
+ if (obj) {
+ if (SP_IS_TAG(obj)) {
+ _select_tag(SP_TAG(obj));
+ } else if (SP_IS_TAG_USE(obj)) {
+ SPObject * item = SP_TAG_USE(obj)->ref->getObject();
+ if (item) {
+ if (_desktop->selection->isEmpty()) _desktop->setCurrentLayer(item->parent);
+ _desktop->selection->add(item);
+ }
+ }
+ }
+ }
+}
+
+void TagsPanel::_pushTreeSelectionToCurrent()
+{
+ _selectionChangedConnection.block();
+ // TODO hunt down the possible API abuse in getting NULL
+ if ( _desktop && _desktop->currentRoot() ) {
+ _desktop->selection->clear();
+ _tree.get_selection()->selected_foreach_iter( sigc::mem_fun(*this, &TagsPanel::_selected_row_callback));
+ }
+ _selectionChangedConnection.unblock();
+
+ _checkTreeSelection();
+}
+
+void TagsPanel::_checkTreeSelection()
+{
+ bool sensitive = _tree.get_selection()->count_selected_rows() > 0;
+ bool sensitiveNonTop = true;
+ bool sensitiveNonBottom = true;
+// if ( _tree.get_selection()->count_selected_rows() > 0 ) {
+// sensitive = true;
+//
+// SPObject* inTree = _selectedLayer();
+// if ( inTree ) {
+//
+// sensitiveNonTop = (Inkscape::Nex(inTree->parent, inTree) != 0);
+// sensitiveNonBottom = (Inkscape::previous_layer(inTree->parent, inTree) != 0);
+//
+// }
+// }
+
+
+ for ( std::vector<Gtk::Widget*>::iterator it = _watching.begin(); it != _watching.end(); ++it ) {
+ (*it)->set_sensitive( sensitive );
+ }
+ for ( std::vector<Gtk::Widget*>::iterator it = _watchingNonTop.begin(); it != _watchingNonTop.end(); ++it ) {
+ (*it)->set_sensitive( sensitiveNonTop );
+ }
+ for ( std::vector<Gtk::Widget*>::iterator it = _watchingNonBottom.begin(); it != _watchingNonBottom.end(); ++it ) {
+ (*it)->set_sensitive( sensitiveNonBottom );
+ }
+}
+
+bool TagsPanel::_handleKeyEvent(GdkEventKey *event)
+{
+
+ switch (Inkscape::UI::Tools::get_group0_keyval(event)) {
+ case GDK_KEY_Return:
+ case GDK_KEY_KP_Enter:
+ case GDK_KEY_F2: {
+ Gtk::TreeModel::iterator iter = _tree.get_selection()->get_selected();
+ if (iter && !_text_renderer->property_editable()) {
+ Gtk::TreeRow row = *iter;
+ SPObject * obj = row[_model->_colObject];
+ if (obj && SP_IS_TAG(obj)) {
+ Gtk::TreeModel::Path *path = new Gtk::TreeModel::Path(iter);
+ // Edit the layer label
+ _text_renderer->property_editable() = true;
+ _tree.set_cursor(*path, *_name_column, true);
+ grab_focus();
+ return true;
+ }
+ }
+ }
+ case GDK_KEY_Delete: {
+ std::vector<SPObject *> todelete;
+ _tree.get_selection()->selected_foreach_iter(sigc::bind<std::vector<SPObject *>*>(sigc::mem_fun(*this, &TagsPanel::_checkForDeleted), &todelete));
+ if (!todelete.empty()) {
+ for (std::vector<SPObject *>::iterator iter = todelete.begin(); iter != todelete.end(); ++iter) {
+ SPObject * obj = *iter;
+ if (obj && obj->parent && obj->getRepr() && obj->parent->getRepr()) {
+ obj->parent->getRepr()->removeChild(obj->getRepr());
+ }
+ }
+ DocumentUndo::done(_document, SP_VERB_DIALOG_TAGS, _("Remove from selection set"));
+ }
+ return true;
+ }
+ break;
+ }
+ return false;
+}
+
+bool TagsPanel::_handleButtonEvent(GdkEventButton* event)
+{
+ static unsigned doubleclick = 0;
+
+ if ( (event->type == GDK_BUTTON_PRESS) && (event->button == 3) ) {
+ // TODO - fix to a better is-popup function
+ Gtk::TreeModel::Path path;
+ int x = static_cast<int>(event->x);
+ int y = static_cast<int>(event->y);
+ if ( _tree.get_path_at_pos( x, y, path ) ) {
+ _checkTreeSelection();
+ _popupMenu.popup(event->button, event->time);
+ if (_tree.get_selection()->is_selected(path)) {
+ return true;
+ }
+ }
+ }
+
+ if ( (event->type == GDK_BUTTON_PRESS) && (event->button == 1)) {
+ // Alt left click on the visible/lock columns - eat this event to keep row selection
+ Gtk::TreeModel::Path path;
+ Gtk::TreeViewColumn* col = 0;
+ int x = static_cast<int>(event->x);
+ int y = static_cast<int>(event->y);
+ int x2 = 0;
+ int y2 = 0;
+ if ( _tree.get_path_at_pos( x, y, path, col, x2, y2 ) ) {
+ if (col == _tree.get_column(COL_ADD-1)) {
+ down_at_add = true;
+ return true;
+ } else if ( !(event->state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK)) & _tree.get_selection()->is_selected(path) ) {
+ _tree.get_selection()->set_select_function(sigc::mem_fun(*this, &TagsPanel::_noSelection));
+ _defer_target = path;
+ } else {
+ down_at_add = false;
+ }
+ } else {
+ down_at_add = false;
+ }
+ }
+
+ if ( event->type == GDK_BUTTON_RELEASE) {
+ _tree.get_selection()->set_select_function(sigc::mem_fun(*this, &TagsPanel::_rowSelectFunction));
+ }
+
+ // TODO - ImageToggler doesn't seem to handle Shift/Alt clicks - so we deal with them here.
+ if ( (event->type == GDK_BUTTON_RELEASE) && (event->button == 1)) {
+
+ Gtk::TreeModel::Path path;
+ Gtk::TreeViewColumn* col = 0;
+ int x = static_cast<int>(event->x);
+ int y = static_cast<int>(event->y);
+ int x2 = 0;
+ int y2 = 0;
+ if ( _tree.get_path_at_pos( x, y, path, col, x2, y2 ) ) {
+ if (_defer_target) {
+ if (_defer_target == path && !(event->x == 0 && event->y == 0))
+ {
+ _tree.set_cursor(path, *col, false);
+ }
+ _defer_target = Gtk::TreeModel::Path();
+ } else {
+ Gtk::TreeModel::Children::iterator iter = _tree.get_model()->get_iter(path);
+ Gtk::TreeModel::Row row = *iter;
+
+ SPObject* obj = row[_model->_colObject];
+
+ if (obj) {
+ if (col == _tree.get_column(COL_ADD - 1) && down_at_add) {
+ if (SP_IS_TAG(obj)) {
+ bool wasadded = false;
+ for (const GSList * iter = _desktop->selection->itemList(); iter != NULL; iter = iter->next)
+ {
+ SPObject *newobj = reinterpret_cast<SPObject *>(iter->data);
+ bool addchild = true;
+ for ( SPObject *child = obj->children; child != NULL; child = child->next) {
+ if (SP_IS_TAG_USE(child) && SP_TAG_USE(child)->ref->getObject() == newobj) {
+ addchild = false;
+ }
+ }
+ if (addchild) {
+ Inkscape::XML::Node *clone = _document->getReprDoc()->createElement("inkscape:tagref");
+ clone->setAttribute("xlink:href", g_strdup_printf("#%s", newobj->getRepr()->attribute("id")), false);
+ obj->appendChild(clone);
+ wasadded = true;
+ }
+ }
+ if (wasadded) {
+ DocumentUndo::done(_document, SP_VERB_DIALOG_TAGS, _("Add selection to set"));
+ }
+ } else {
+ std::vector<SPObject *> todelete;
+ _tree.get_selection()->selected_foreach_iter(sigc::bind<std::vector<SPObject *>*>(sigc::mem_fun(*this, &TagsPanel::_checkForDeleted), &todelete));
+ if (!todelete.empty()) {
+ for (std::vector<SPObject *>::iterator iter = todelete.begin(); iter != todelete.end(); ++iter) {
+ SPObject * tobj = *iter;
+ if (tobj && tobj->parent && tobj->getRepr() && tobj->parent->getRepr()) {
+ tobj->parent->getRepr()->removeChild(tobj->getRepr());
+ }
+ }
+ } else if (obj && obj->parent && obj->getRepr() && obj->parent->getRepr()) {
+ obj->parent->getRepr()->removeChild(obj->getRepr());
+ }
+ DocumentUndo::done(_document, SP_VERB_DIALOG_TAGS, _("Remove from selection set"));
+ }
+ }
+ }
+ }
+ }
+ }
+
+
+ if ( (event->type == GDK_2BUTTON_PRESS) && (event->button == 1) ) {
+ doubleclick = 1;
+ }
+
+ if ( event->type == GDK_BUTTON_RELEASE && doubleclick) {
+ doubleclick = 0;
+ Gtk::TreeModel::Path path;
+ Gtk::TreeViewColumn* col = 0;
+ int x = static_cast<int>(event->x);
+ int y = static_cast<int>(event->y);
+ int x2 = 0;
+ int y2 = 0;
+ if ( _tree.get_path_at_pos( x, y, path, col, x2, y2 ) && col == _name_column) {
+ Gtk::TreeModel::Children::iterator iter = _tree.get_model()->get_iter(path);
+ Gtk::TreeModel::Row row = *iter;
+
+ SPObject* obj = row[_model->_colObject];
+ if (obj && (SP_IS_TAG(obj) || (SP_IS_TAG_USE(obj) && SP_TAG_USE(obj)->ref->getObject()))) {
+ // Double click on the Layer name, enable editing
+ _text_renderer->property_editable() = true;
+ _tree.set_cursor (path, *_name_column, true);
+ grab_focus();
+ }
+ }
+ }
+
+ return false;
+}
+
+void TagsPanel::_storeDragSource(const Gtk::TreeModel::iterator& iter)
+{
+ Gtk::TreeModel::Row row = *iter;
+ SPObject* obj = row[_model->_colObject];
+ SPTag* item = ( obj && SP_IS_TAG(obj) ) ? SP_TAG(obj) : 0;
+ if (item)
+ {
+ _dnd_source.push_back(item);
+ }
+}
+
+/*
+ * Drap and drop within the tree
+ * Save the drag source and drop target SPObjects and if its a drag between layers or into (sublayer) a layer
+ */
+bool TagsPanel::_handleDragDrop(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, guint time)
+{
+ int cell_x = 0, cell_y = 0;
+ Gtk::TreeModel::Path target_path;
+ Gtk::TreeView::Column *target_column;
+
+ _dnd_into = true;
+ _dnd_target = _document->getDefs();
+ _dnd_source.clear();
+ _tree.get_selection()->selected_foreach_iter(sigc::mem_fun(*this, &TagsPanel::_storeDragSource));
+
+ if (_dnd_source.empty()) {
+ return true;
+ }
+
+ if (_tree.get_path_at_pos (x, y, target_path, target_column, cell_x, cell_y)) {
+ // Are we before, inside or after the drop layer
+ Gdk::Rectangle rect;
+ _tree.get_background_area (target_path, *target_column, rect);
+ int cell_height = rect.get_height();
+ _dnd_into = (cell_y > (int)(cell_height * 1/3) && cell_y <= (int)(cell_height * 2/3));
+ if (cell_y > (int)(cell_height * 2/3)) {
+ Gtk::TreeModel::Path next_path = target_path;
+ next_path.next();
+ if (_store->iter_is_valid(_store->get_iter(next_path))) {
+ target_path = next_path;
+ } else {
+ // Dragging to the "end"
+ Gtk::TreeModel::Path up_path = target_path;
+ up_path.up();
+ if (_store->iter_is_valid(_store->get_iter(up_path))) {
+ // Drop into parent
+ target_path = up_path;
+ _dnd_into = true;
+ } else {
+ // Drop into the top level
+ _dnd_target = _document->getDefs();
+ _dnd_into = true;
+ }
+ }
+ }
+ Gtk::TreeModel::iterator iter = _store->get_iter(target_path);
+ if (_store->iter_is_valid(iter)) {
+ Gtk::TreeModel::Row row = *iter;
+ SPObject *obj = row[_model->_colObject];
+ SPObject *pobj = row[_model->_colParentObject];
+ if (obj) {
+ if (SP_IS_TAG(obj)) {
+ _dnd_target = SP_TAG(obj);
+ } else if (SP_IS_TAG(obj->parent)) {
+ _dnd_target = SP_TAG(obj->parent);
+ _dnd_into = true;
+ }
+ } else if (pobj && SP_IS_TAG(pobj)) {
+ _dnd_target = SP_TAG(pobj);
+ _dnd_into = true;
+ } else {
+ return true;
+ }
+ }
+ }
+
+ _takeAction(DRAGNDROP);
+
+ return false;
+}
+
+/*
+ * Move a layer in response to a drag & drop action
+ */
+void TagsPanel::_doTreeMove( )
+{
+ if (_dnd_target) {
+ for (std::vector<SPTag *>::iterator iter = _dnd_source.begin(); iter != _dnd_source.end(); ++iter)
+ {
+ SPTag *src = *iter;
+ if (src != _dnd_target) {
+ src->moveTo(_dnd_target, _dnd_into);
+ }
+ }
+ _desktop->selection->clear();
+ while (!_dnd_source.empty())
+ {
+ SPTag *src = _dnd_source.back();
+ _select_tag(src);
+ _dnd_source.pop_back();
+ }
+ DocumentUndo::done( _desktop->doc() , SP_VERB_DIALOG_TAGS,
+ _("Moved sets"));
+ }
+}
+
+
+void TagsPanel::_handleEdited(const Glib::ustring& path, const Glib::ustring& new_text)
+{
+ Gtk::TreeModel::iterator iter = _tree.get_model()->get_iter(path);
+ Gtk::TreeModel::Row row = *iter;
+
+ _renameObject(row, new_text);
+ _text_renderer->property_editable() = false;
+}
+
+void TagsPanel::_handleEditingCancelled()
+{
+ _text_renderer->property_editable() = false;
+}
+
+void TagsPanel::_renameObject(Gtk::TreeModel::Row row, const Glib::ustring& name)
+{
+ if ( row && _desktop) {
+ SPObject* obj = row[_model->_colObject];
+ if ( obj ) {
+ if (SP_IS_TAG(obj)) {
+ gchar const* oldLabel = obj->label();
+ if ( !name.empty() && (!oldLabel || name != oldLabel) ) {
+ obj->setLabel(name.c_str());
+ DocumentUndo::done( _desktop->doc() , SP_VERB_NONE,
+ _("Rename object"));
+ }
+ } else if (SP_IS_TAG_USE(obj) && (obj = SP_TAG_USE(obj)->ref->getObject())) {
+ gchar const* oldLabel = obj->label();
+ if ( !name.empty() && (!oldLabel || name != oldLabel) ) {
+ obj->setLabel(name.c_str());
+ DocumentUndo::done( _desktop->doc() , SP_VERB_NONE,
+ _("Rename object"));
+ }
+ }
+ }
+ }
+}
+
+bool TagsPanel::_noSelection( Glib::RefPtr<Gtk::TreeModel> const & /*model*/, Gtk::TreeModel::Path const & /*path*/, bool currentlySelected )
+{
+ return false;
+}
+
+bool TagsPanel::_rowSelectFunction( Glib::RefPtr<Gtk::TreeModel> const & /*model*/, Gtk::TreeModel::Path const & /*path*/, bool currentlySelected )
+{
+ bool val = true;
+ if ( !currentlySelected && _toggleEvent )
+ {
+ GdkEvent* event = gtk_get_current_event();
+ if ( event ) {
+ // (keep these checks separate, so we know when to call gdk_event_free()
+ if ( event->type == GDK_BUTTON_PRESS ) {
+ GdkEventButton const* target = reinterpret_cast<GdkEventButton const*>(_toggleEvent);
+ GdkEventButton const* evtb = reinterpret_cast<GdkEventButton const*>(event);
+
+ if ( (evtb->window == target->window)
+ && (evtb->send_event == target->send_event)
+ && (evtb->time == target->time)
+ && (evtb->state == target->state)
+ )
+ {
+ // Ooooh! It's a magic one
+ val = false;
+ }
+ }
+ gdk_event_free(event);
+ }
+ }
+ return val;
+}
+
+void TagsPanel::_setExpanded(const Gtk::TreeModel::iterator& iter, const Gtk::TreeModel::Path& /*path*/, bool isexpanded)
+{
+ Gtk::TreeModel::Row row = *iter;
+
+ SPObject* obj = row[_model->_colParentObject];
+ if (obj && SP_IS_TAG(obj))
+ {
+ SP_TAG(obj)->setExpanded(isexpanded);
+ obj->updateRepr(SP_OBJECT_WRITE_NO_CHILDREN | SP_OBJECT_WRITE_EXT);
+ }
+}
+
+/**
+ * Constructor
+ */
+TagsPanel::TagsPanel() :
+ UI::Widget::Panel("", "/dialogs/tags", SP_VERB_DIALOG_TAGS),
+ _rootWatcher(0),
+ deskTrack(),
+ _desktop(0),
+ _document(0),
+ _model(0),
+ _pending(0),
+ _toggleEvent(0),
+ _defer_target(),
+ desktopChangeConn()
+{
+ //Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+
+ ModelColumns *zoop = new ModelColumns();
+ _model = zoop;
+
+ _store = Gtk::TreeStore::create( *zoop );
+
+ _tree.set_model( _store );
+ _tree.set_headers_visible(false);
+ _tree.set_reorderable(true);
+ _tree.enable_model_drag_dest (Gdk::ACTION_MOVE);
+
+ Inkscape::UI::Widget::AddToIcon * addRenderer = manage( new Inkscape::UI::Widget::AddToIcon());
+ int addColNum = _tree.append_column("type", *addRenderer) - 1;
+ Gtk::TreeViewColumn *col = _tree.get_column(addColNum);
+ if ( col ) {
+ col->add_attribute( addRenderer->property_active(), _model->_colAddRemove );
+ col->add_attribute( addRenderer->property_visible(), _model->_colAllowAddRemove );
+ }
+
+ _text_renderer = manage(new Gtk::CellRendererText());
+ int nameColNum = _tree.append_column("Name", *_text_renderer) - 1;
+ _name_column = _tree.get_column(nameColNum);
+ _name_column->add_attribute(_text_renderer->property_text(), _model->_colLabel);
+
+ _tree.set_expander_column( *_tree.get_column(nameColNum) );
+
+ _tree.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
+ _selectedConnection = _tree.get_selection()->signal_changed().connect( sigc::mem_fun(*this, &TagsPanel::_pushTreeSelectionToCurrent) );
+ _tree.get_selection()->set_select_function( sigc::mem_fun(*this, &TagsPanel::_rowSelectFunction) );
+
+ _tree.signal_drag_drop().connect( sigc::mem_fun(*this, &TagsPanel::_handleDragDrop), false);
+ _collapsedConnection = _tree.signal_row_collapsed().connect( sigc::bind<bool>(sigc::mem_fun(*this, &TagsPanel::_setExpanded), false));
+ _expandedConnection = _tree.signal_row_expanded().connect( sigc::bind<bool>(sigc::mem_fun(*this, &TagsPanel::_setExpanded), true));
+
+ _text_renderer->signal_edited().connect( sigc::mem_fun(*this, &TagsPanel::_handleEdited) );
+ _text_renderer->signal_editing_canceled().connect( sigc::mem_fun(*this, &TagsPanel::_handleEditingCancelled) );
+
+ _tree.signal_button_press_event().connect( sigc::mem_fun(*this, &TagsPanel::_handleButtonEvent), false );
+ _tree.signal_button_release_event().connect( sigc::mem_fun(*this, &TagsPanel::_handleButtonEvent), false );
+ _tree.signal_key_press_event().connect( sigc::mem_fun(*this, &TagsPanel::_handleKeyEvent), false );
+
+ _scroller.add( _tree );
+ _scroller.set_policy( Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC );
+ _scroller.set_shadow_type(Gtk::SHADOW_IN);
+ Gtk::Requisition sreq;
+#if WITH_GTKMM_3_0
+ Gtk::Requisition sreq_natural;
+ _scroller.get_preferred_size(sreq_natural, sreq);
+#else
+ sreq = _scroller.size_request();
+#endif
+ int minHeight = 70;
+ if (sreq.height < minHeight) {
+ // Set a min height to see the layers when used with Ubuntu liboverlay-scrollbar
+ _scroller.set_size_request(sreq.width, minHeight);
+ }
+
+ _layersPage.pack_start( _scroller, Gtk::PACK_EXPAND_WIDGET );
+
+ _layersPage.pack_end(_buttonsRow, Gtk::PACK_SHRINK);
+
+ _getContents()->pack_start(_layersPage, Gtk::PACK_EXPAND_WIDGET);
+
+ SPDesktop* targetDesktop = getDesktop();
+
+ Gtk::Button* btn = manage( new Gtk::Button() );
+ _styleButton( *btn, targetDesktop, SP_VERB_TAG_NEW, GTK_STOCK_ADD, _("Add a new selection set") );
+ btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &TagsPanel::_takeAction), (int)BUTTON_NEW) );
+ _buttonsSecondary.pack_start(*btn, Gtk::PACK_SHRINK);
+
+// btn = manage( new Gtk::Button("Dup") );
+// btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_DUPLICATE) );
+// _buttonsRow.add( *btn );
+
+ btn = manage( new Gtk::Button() );
+ _styleButton( *btn, targetDesktop, SP_VERB_LAYER_DELETE, GTK_STOCK_REMOVE, _("Remove Item/Set") );
+ btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &TagsPanel::_takeAction), (int)BUTTON_DELETE) );
+ _watching.push_back( btn );
+ _buttonsSecondary.pack_start(*btn, Gtk::PACK_SHRINK);
+
+ _buttonsRow.pack_start(_buttonsSecondary, Gtk::PACK_EXPAND_WIDGET);
+ _buttonsRow.pack_end(_buttonsPrimary, Gtk::PACK_EXPAND_WIDGET);
+
+ // -------------------------------------------------------
+ {
+ _watching.push_back( &_addPopupItem( targetDesktop, SP_VERB_TAG_NEW, 0, "New", (int)BUTTON_NEW ) );
+
+ _popupMenu.show_all_children();
+ }
+ // -------------------------------------------------------
+
+
+
+ for ( std::vector<Gtk::Widget*>::iterator it = _watching.begin(); it != _watching.end(); ++it ) {
+ (*it)->set_sensitive( false );
+ }
+ for ( std::vector<Gtk::Widget*>::iterator it = _watchingNonTop.begin(); it != _watchingNonTop.end(); ++it ) {
+ (*it)->set_sensitive( false );
+ }
+ for ( std::vector<Gtk::Widget*>::iterator it = _watchingNonBottom.begin(); it != _watchingNonBottom.end(); ++it ) {
+ (*it)->set_sensitive( false );
+ }
+
+ setDesktop( targetDesktop );
+
+ show_all_children();
+
+ // restorePanelPrefs();
+
+ // Connect this up last
+ desktopChangeConn = deskTrack.connectDesktopChanged( sigc::mem_fun(*this, &TagsPanel::setDesktop) );
+ deskTrack.connect(GTK_WIDGET(gobj()));
+}
+
+TagsPanel::~TagsPanel()
+{
+
+ setDesktop(NULL);
+
+ if ( _model )
+ {
+ delete _model;
+ _model = 0;
+ }
+
+ if (_pending) {
+ delete _pending;
+ _pending = 0;
+ }
+
+ if ( _toggleEvent )
+ {
+ gdk_event_free( _toggleEvent );
+ _toggleEvent = 0;
+ }
+
+ desktopChangeConn.disconnect();
+ deskTrack.disconnect();
+}
+
+void TagsPanel::setDocument(SPDesktop* /*desktop*/, SPDocument* document)
+{
+ while (!_objectWatchers.empty())
+ {
+ TagsPanel::ObjectWatcher *w = _objectWatchers.back();
+ w->_repr->removeObserver(*w);
+ _objectWatchers.pop_back();
+ delete w;
+ }
+
+ if (_rootWatcher)
+ {
+ _rootWatcher->_repr->removeObserver(*_rootWatcher);
+ delete _rootWatcher;
+ _rootWatcher = NULL;
+ }
+
+ _document = document;
+
+ if (document && document->getDefs() && document->getDefs()->getRepr())
+ {
+ _rootWatcher = new TagsPanel::ObjectWatcher(this, document->getDefs());
+ document->getDefs()->getRepr()->addObserver(*_rootWatcher);
+ _objectsChanged(document->getDefs());
+ }
+}
+
+void TagsPanel::setDesktop( SPDesktop* desktop )
+{
+ Panel::setDesktop(desktop);
+
+ if ( desktop != _desktop ) {
+ _documentChangedConnection.disconnect();
+ _selectionChangedConnection.disconnect();
+ if ( _desktop ) {
+ _desktop = 0;
+ }
+
+ _desktop = Panel::getDesktop();
+ if ( _desktop ) {
+ //setLabel( _desktop->doc()->name );
+ _documentChangedConnection = _desktop->connectDocumentReplaced( sigc::mem_fun(*this, &TagsPanel::setDocument));
+ _selectionChangedConnection = _desktop->selection->connectChanged( sigc::mem_fun(*this, &TagsPanel::_objectsSelected));
+
+ setDocument(_desktop, _desktop->doc());
+ }
+ }
+/*
+ GSList const *layers = _desktop->doc()->getResourceList( "layer" );
+ g_message( "layers list starts at %p", layers );
+ for ( GSList const *iter=layers ; iter ; iter = iter->next ) {
+ SPObject *layer=static_cast<SPObject *>(iter->data);
+ g_message(" {%s} [%s]", layer->id, layer->label() );
+ }
+*/
+ deskTrack.setBase(desktop);
+}
+
+
+
+
+
+} //namespace Dialogs
+} //namespace UI
+} //namespace Inkscape
+
+
+/*
+ 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:fileencoding=utf-8:textwidth=99 :
diff --git a/src/ui/dialog/tags.h b/src/ui/dialog/tags.h
new file mode 100644
index 000000000..d35dfba01
--- /dev/null
+++ b/src/ui/dialog/tags.h
@@ -0,0 +1,181 @@
+/*
+ * A simple dialog for tags UI.
+ *
+ * Authors:
+ * Theodore Janeczko
+ *
+ * Copyright (C) Theodore Janeczko 2012 <flutterguy317@gmail.com>
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#ifndef SEEN_TAGS_PANEL_H
+#define SEEN_TAGS_PANEL_H
+
+#include <gtkmm/box.h>
+#include <gtkmm/treeview.h>
+#include <gtkmm/treestore.h>
+#include <gtkmm/scrolledwindow.h>
+#include <gtkmm/dialog.h>
+#include "ui/widget/spinbutton.h"
+#include "ui/widget/panel.h"
+#include "ui/widget/object-composite-settings.h"
+#include "desktop-tracker.h"
+#include "ui/widget/style-subject.h"
+#include "selection.h"
+#include "ui/widget/filter-effect-chooser.h"
+
+class SPObject;
+class SPTag;
+struct SPColorSelector;
+
+namespace Inkscape {
+
+namespace UI {
+namespace Dialog {
+
+
+/**
+ * A panel that displays layers.
+ */
+class TagsPanel : public UI::Widget::Panel
+{
+public:
+ TagsPanel();
+ virtual ~TagsPanel();
+
+ //virtual void setOrientation( Gtk::AnchorType how );
+
+ static TagsPanel& getInstance();
+
+ void setDesktop( SPDesktop* desktop );
+ void setDocument( SPDesktop* desktop, SPDocument* document);
+
+protected:
+ //virtual void _handleAction( int setId, int itemId );
+ friend void sp_highlight_picker_color_mod(SPColorSelector *csel, GObject *cp);
+private:
+ class ModelColumns;
+ class InternalUIBounce;
+ class ObjectWatcher;
+
+ TagsPanel(TagsPanel const &); // no copy
+ TagsPanel &operator=(TagsPanel const &); // no assign
+
+ void _styleButton( Gtk::Button& btn, SPDesktop *desktop, unsigned int code, char const* iconName, char const* tooltip );
+ void _fireAction( unsigned int code );
+ Gtk::MenuItem& _addPopupItem( SPDesktop *desktop, unsigned int code, char const* iconName, char const* fallback, int id );
+
+ bool _handleButtonEvent(GdkEventButton *event);
+ bool _handleKeyEvent(GdkEventKey *event);
+
+ void _storeDragSource(const Gtk::TreeModel::iterator& iter);
+ bool _handleDragDrop(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, guint time);
+ void _handleEdited(const Glib::ustring& path, const Glib::ustring& new_text);
+ void _handleEditingCancelled();
+
+ void _doTreeMove();
+ void _renameObject(Gtk::TreeModel::Row row, const Glib::ustring& name);
+
+ void _pushTreeSelectionToCurrent();
+ void _selected_row_callback( const Gtk::TreeModel::iterator& iter );
+ void _select_tag( SPTag * tag );
+
+ void _checkTreeSelection();
+
+ void _takeAction( int val );
+ bool _executeAction();
+
+ void _setExpanded( const Gtk::TreeModel::iterator& iter, const Gtk::TreeModel::Path& path, bool isexpanded );
+
+ bool _noSelection( Glib::RefPtr<Gtk::TreeModel> const & model, Gtk::TreeModel::Path const & path, bool b );
+ bool _rowSelectFunction( Glib::RefPtr<Gtk::TreeModel> const & model, Gtk::TreeModel::Path const & path, bool b );
+
+ void _updateObject(SPObject *obj);
+ bool _checkForUpdated(const Gtk::TreePath &path, const Gtk::TreeIter& iter, SPObject* obj);
+
+ void _objectsSelected(Selection *sel);
+ bool _checkForSelected(const Gtk::TreePath& path, const Gtk::TreeIter& iter, SPObject* layer);
+
+ void _objectsChanged(SPObject *root);
+ void _addObject( SPDocument* doc, SPObject* obj, Gtk::TreeModel::Row* parentRow );
+
+ void _checkForDeleted(const Gtk::TreeIter& iter, std::vector<SPObject *>* todelete);
+
+// std::vector<sigc::connection> groupConnections;
+ TagsPanel::ObjectWatcher* _rootWatcher;
+ std::vector<TagsPanel::ObjectWatcher*> _objectWatchers;
+
+ // Hooked to the layer manager:
+ sigc::connection _documentChangedConnection;
+ sigc::connection _selectionChangedConnection;
+
+ sigc::connection _changedConnection;
+ sigc::connection _addedConnection;
+ sigc::connection _removedConnection;
+
+ // Internal
+ sigc::connection _selectedConnection;
+ sigc::connection _expandedConnection;
+ sigc::connection _collapsedConnection;
+
+ DesktopTracker deskTrack;
+ SPDesktop* _desktop;
+ SPDocument* _document;
+ ModelColumns* _model;
+ InternalUIBounce* _pending;
+ gboolean _dnd_into;
+ std::vector<SPTag*> _dnd_source;
+ SPObject* _dnd_target;
+
+ GdkEvent* _toggleEvent;
+ bool down_at_add;
+
+ Gtk::TreeModel::Path _defer_target;
+
+ Glib::RefPtr<Gtk::TreeStore> _store;
+ std::vector<Gtk::Widget*> _watching;
+ std::vector<Gtk::Widget*> _watchingNonTop;
+ std::vector<Gtk::Widget*> _watchingNonBottom;
+
+ Gtk::TreeView _tree;
+ Gtk::CellRendererText *_text_renderer;
+ Gtk::TreeView::Column *_name_column;
+#if WITH_GTKMM_3_0
+ Gtk::Box _buttonsRow;
+ Gtk::Box _buttonsPrimary;
+ Gtk::Box _buttonsSecondary;
+#else
+ Gtk::HBox _buttonsRow;
+ Gtk::HBox _buttonsPrimary;
+ Gtk::HBox _buttonsSecondary;
+#endif
+ Gtk::ScrolledWindow _scroller;
+ Gtk::Menu _popupMenu;
+ Inkscape::UI::Widget::SpinButton _spinBtn;
+ Gtk::VBox _layersPage;
+
+ sigc::connection desktopChangeConn;
+
+};
+
+
+
+} //namespace Dialogs
+} //namespace UI
+} //namespace Inkscape
+
+
+
+#endif // SEEN_OBJECTS_PANEL_H
+
+/*
+ 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:fileencoding=utf-8:textwidth=99 :
diff --git a/src/verbs.cpp b/src/verbs.cpp
index c20f48e65..e1d6c0583 100644
--- a/src/verbs.cpp
+++ b/src/verbs.cpp
@@ -64,6 +64,7 @@
#include "seltrans.h"
#include "shape-editor.h"
#include "shortcuts.h"
+#include "sp-defs.h"
#include "sp-flowtext.h"
#include "sp-guide.h"
#include "splivarot.h"
@@ -215,6 +216,25 @@ public:
}; // ObjectVerb class
/**
+ * A class to encompass all of the verbs which deal with operations related to tags.
+ */
+class TagVerb : public Verb {
+private:
+ static void perform(SPAction *action, void *mydata);
+protected:
+ virtual SPAction *make_action(Inkscape::ActionContext const & context);
+public:
+ /** Use the Verb initializer with the same parameters. */
+ TagVerb(unsigned int const code,
+ gchar const *id,
+ gchar const *name,
+ gchar const *tip,
+ gchar const *image) :
+ Verb(code, id, name, tip, image, _("Tag"))
+ { }
+}; // TagVerb class
+
+/**
* A class to encompass all of the verbs which deal with operations relative to context.
*/
class ContextVerb : public Verb {
@@ -460,6 +480,19 @@ SPAction *ObjectVerb::make_action(Inkscape::ActionContext const & context)
}
/**
+ * Create an action for a \c TagVerb.
+ *
+ * Calls \c make_action_helper with the \c vector.
+ *
+ * @param view Which view the action should be created for.
+ * @return The built action.
+ */
+SPAction *TagVerb::make_action(Inkscape::ActionContext const & context)
+{
+ return make_action_helper(context, &perform);
+}
+
+/**
* Create an action for a \c ContextVerb.
*
* Calls \c make_action_helper with the \c vector.
@@ -1550,6 +1583,47 @@ void ObjectVerb::perform( SPAction *action, void *data)
/**
* Decode the verb code and take appropriate action.
*/
+void TagVerb::perform( SPAction *action, void *data)
+{
+ SPDesktop *dt = static_cast<SPDesktop*>(sp_action_get_view(action));
+ if (!dt)
+ return;
+
+ //Inkscape::UI::Tools::ToolBase *ec = dt->event_context;
+
+ Inkscape::Selection *sel = sp_desktop_selection(dt);
+
+ Inkscape::XML::Document * doc;
+ Inkscape::XML::Node * repr;
+ gchar *id;
+
+ switch (reinterpret_cast<std::size_t>(data)) {
+ case SP_VERB_TAG_NEW:
+ static int tag_suffix=1;
+ id=NULL;
+ do {
+ g_free(id);
+ id = g_strdup_printf("tag%d", tag_suffix++);
+ } while (dt->doc()->getObjectById(id));
+
+ doc = dt->doc()->getReprDoc();
+ repr = doc->createElement("inkscape:tag");
+ repr->setAttribute("id", id);
+ g_free(id);
+
+ dt->doc()->getDefs()->addChild(repr, NULL);
+ Inkscape::DocumentUndo::done(dt->doc(), SP_VERB_DIALOG_TAGS, _("Create new selection set"));
+ break;
+ default:
+ break;
+ }
+
+} // end of sp_verb_action_tag_perform()
+
+
+/**
+ * Decode the verb code and take appropriate action.
+ */
void ContextVerb::perform(SPAction *action, void *data)
{
SPDesktop *dt;
@@ -2040,9 +2114,9 @@ void DialogVerb::perform(SPAction *action, void *data)
case SP_VERB_DIALOG_OBJECTS:
dt->_dlg_mgr->showDialog("ObjectsPanel");
break;
- /*case SP_VERB_DIALOG_TAGS:
+ case SP_VERB_DIALOG_TAGS:
dt->_dlg_mgr->showDialog("TagsPanel");
- break;*/ //in a moment my dear
+ break;
case SP_VERB_DIALOG_LIVE_PATH_EFFECT:
dt->_dlg_mgr->showDialog("LivePathEffect");
break;
@@ -2647,7 +2721,9 @@ Verb *Verb::_base_verbs[] = {
N_("Edit clipping path"), INKSCAPE_ICON("path-clip-edit")),
new ObjectVerb(SP_VERB_OBJECT_UNSET_CLIPPATH, "ObjectUnSetClipPath", N_("_Release"),
N_("Remove clipping path from selection"), NULL),
-
+ // Tag
+ new TagVerb(SP_VERB_TAG_NEW, "TagNew", N_("_New"),
+ N_("Create new selection set"), NULL),
// Tools
new ContextVerb(SP_VERB_CONTEXT_SELECT, "ToolSelector", NC_("ContextVerb", "Select"),
N_("Select and transform objects"), INKSCAPE_ICON("tool-pointer")),
@@ -2862,8 +2938,8 @@ Verb *Verb::_base_verbs[] = {
N_("View Layers"), INKSCAPE_ICON("dialog-layers")),
new DialogVerb(SP_VERB_DIALOG_OBJECTS, "DialogObjects", N_("Object_s..."),
N_("View Objects"), INKSCAPE_ICON("dialog-layers")),
- /*new DialogVerb(SP_VERB_DIALOG_TAGS, "DialogObjects", N_("Ta_gs..."),
- N_("View Tags"), INKSCAPE_ICON("edit-select-all-layers")),*/
+ new DialogVerb(SP_VERB_DIALOG_TAGS, "DialogTags", N_("Ta_gs..."),
+ N_("View Tags"), INKSCAPE_ICON("edit-select-all-layers")),
new DialogVerb(SP_VERB_DIALOG_LIVE_PATH_EFFECT, "DialogLivePathEffect", N_("Path E_ffects ..."),
N_("Manage, edit, and apply path effects"), NULL),
new DialogVerb(SP_VERB_DIALOG_FILTER_EFFECTS, "DialogFilterEffects", N_("Filter _Editor..."),
diff --git a/src/verbs.h b/src/verbs.h
index 141a9c7e9..821c9ee82 100644
--- a/src/verbs.h
+++ b/src/verbs.h
@@ -177,6 +177,8 @@ enum {
SP_VERB_OBJECT_SET_CLIPPATH,
SP_VERB_OBJECT_EDIT_CLIPPATH,
SP_VERB_OBJECT_UNSET_CLIPPATH,
+ /* Tag */
+ SP_VERB_TAG_NEW,
/* Tools */
SP_VERB_CONTEXT_SELECT,
SP_VERB_CONTEXT_NODE,
@@ -290,7 +292,7 @@ enum {
SP_VERB_DIALOG_EXTENSIONEDITOR,
SP_VERB_DIALOG_LAYERS,
SP_VERB_DIALOG_OBJECTS,
-// SP_VERB_DIALOG_TAGS,
+ SP_VERB_DIALOG_TAGS,
SP_VERB_DIALOG_LIVE_PATH_EFFECT,
SP_VERB_DIALOG_FILTER_EFFECTS,
SP_VERB_DIALOG_SVG_FONTS,