Fix 1368694. You can now add layers to groups and the groups show up immediately...
authordooglus <dooglus@1f10aa63-cdf2-0310-b900-c93c546f37ac>
Fri, 21 Sep 2007 15:05:51 +0000 (15:05 +0000)
committerdooglus <dooglus@1f10aa63-cdf2-0310-b900-c93c546f37ac>
Fri, 21 Sep 2007 15:05:51 +0000 (15:05 +0000)
git-svn-id: http://svn.voria.com/code@731 1f10aa63-cdf2-0310-b900-c93c546f37ac

synfig-core/trunk/src/synfig/canvas.cpp
synfig-core/trunk/src/synfig/canvas.h

index e98b301..035208d 100644 (file)
@@ -700,24 +700,22 @@ Canvas::insert(iterator iter,etl::handle<Layer> x)
        //while(correct_canvas->is_inline())correct_canvas=correct_canvas->parent();
        Layer::LooseHandle loose_layer(x);
 
-       x->signal_added_to_group().connect(
-               sigc::bind(
-                       sigc::mem_fun(
-                               *correct_canvas,
-                               &Canvas::add_group_pair
-                       ),
-                       loose_layer
-               )
-       );
-       x->signal_removed_from_group().connect(
-               sigc::bind(
-                       sigc::mem_fun(
-                               *correct_canvas,
-                               &Canvas::remove_group_pair
-                       ),
-                       loose_layer
-               )
-       );
+       add_connection(x,
+                                  sigc::connection::connection(
+                                          x->signal_added_to_group().connect(
+                                                  sigc::bind(
+                                                          sigc::mem_fun(
+                                                                  *correct_canvas,
+                                                                  &Canvas::add_group_pair),
+                                                          loose_layer))));
+       add_connection(x,
+                                  sigc::connection::connection(
+                                          x->signal_removed_from_group().connect(
+                                                  sigc::bind(
+                                                          sigc::mem_fun(
+                                                                  *correct_canvas,
+                                                                  &Canvas::remove_group_pair),
+                                                          loose_layer))));
 
 
        if(!x->get_group().empty())
@@ -749,8 +747,10 @@ Canvas::erase(Canvas::iterator iter)
        // is using these signals, so I'll just
        // leave these next two lines like they
        // are for now - darco 07-30-2004
-       (*iter)->signal_added_to_group().clear();
-       (*iter)->signal_removed_from_group().clear();
+
+       // so don't wipe them out entirely
+       // - dooglus 09-21-2007
+       disconnect_connections(*iter);
 
        if(!op_flag_)remove_child(iter->get());
 
@@ -1179,6 +1179,21 @@ Canvas::remove_group_pair(String group, etl::handle<Layer> layer)
 }
 
 void
+Canvas::add_connection(etl::handle<Layer> layer, sigc::connection connection)
+{
+       connections_[layer].push_back(connection);
+}
+
+void
+Canvas::disconnect_connections(etl::handle<Layer> layer)
+{
+       std::vector<sigc::connection>::iterator iter;
+       for(iter=connections_[layer].begin();iter!=connections_[layer].end();++iter)
+               iter->disconnect();
+       connections_[layer].clear();
+}
+
+void
 Canvas::rename_group(const String&old_name,const String&new_name)
 {
        if(is_inline() && parent_)
index 470b7c9..972b6cf 100644 (file)
@@ -31,6 +31,7 @@
 #include <list>
 #include <ETL/handle>
 #include <sigc++/signal.h>
+#include <sigc++/connection.h>
 
 #include "vector.h"
 #include "string.h"
@@ -141,6 +142,9 @@ private:
        //! Layer Group database
        std::map<String,std::set<etl::handle<Layer> > > group_db_;
 
+       //! Layer Connection database
+       std::map<etl::handle<Layer>,std::vector<sigc::connection> > connections_;
+
        /*
  -- ** -- S I G N A L S -------------------------------------------------------
        */
@@ -469,6 +473,8 @@ public:
 private:
        void add_group_pair(String group, etl::handle<Layer> layer);
        void remove_group_pair(String group, etl::handle<Layer> layer);
+       void add_connection(etl::handle<Layer> layer, sigc::connection connection);
+       void disconnect_connections(etl::handle<Layer> layer);
 
 protected:
        virtual void on_changed();