Code

stop toggling insensitive state for modification flag updates (fixes critical bug...
[inkscape.git] / src / dialogs / layers-panel.cpp
1 /*
2  * A simple panel for layers
3  *
4  * Authors:
5  *   Jon A. Cruz
6  *
7  * Copyright (C) 2006 Jon A. Cruz
8  *
9  * Released under GNU GPL, read the file 'COPYING' for more information
10  */
11 #ifdef HAVE_CONFIG_H
12 # include <config.h>
13 #endif
15 #include <glibmm/i18n.h>
17 #include <gtk/gtkstock.h>
18 #include <gtk/gtkmain.h>
20 #include "inkscape.h"
22 #include "layers-panel.h"
24 #include "layer-manager.h"
25 #include "layer-fns.h"
27 #include "verbs.h"
28 #include "helper/action.h"
30 #include "document.h"
31 #include "desktop.h"
32 #include "sp-object.h"
33 #include "sp-item.h"
34 #include "widgets/icon.h"
35 #include <gtkmm/widget.h>
36 #include "prefs-utils.h"
37 #include "xml/repr.h"
38 #include "svg/css-ostringstream.h"
39 #include "desktop-style.h"
41 //#define DUMP_LAYERS 1
43 namespace Inkscape {
44 namespace UI {
45 namespace Dialogs {
47 LayersPanel&
48 LayersPanel::getInstance()
49 {
50     return *new LayersPanel();
51 }
53 enum {
54     COL_VISIBLE = 1,
55     COL_LOCKED
56 };
58 enum {
59     BUTTON_NEW = 0,
60     BUTTON_RENAME,
61     BUTTON_TOP,
62     BUTTON_BOTTOM,
63     BUTTON_UP,
64     BUTTON_DOWN,
65 //    BUTTON_DUPLICATE,
66     BUTTON_DELETE
67 };
69 class ImageToggler : public Gtk::CellRendererPixbuf {
70 public:
71     ImageToggler( char const* on, char const* off) :
72         Glib::ObjectBase(typeid(ImageToggler)),
73         Gtk::CellRendererPixbuf(),
74         _pixOnName(on),
75         _pixOffName(off),
76         _property_active(*this, "active", false),
77         _property_activatable(*this, "activatable", true),
78         _property_pixbuf_on(*this, "pixbuf_on", Glib::RefPtr<Gdk::Pixbuf>(0)),
79         _property_pixbuf_off(*this, "pixbuf_off", Glib::RefPtr<Gdk::Pixbuf>(0))
80     {
81         property_mode() = Gtk::CELL_RENDERER_MODE_ACTIVATABLE;
83         Gtk::Widget* thingie = sp_icon_get_icon(_pixOnName.c_str(), Inkscape::ICON_SIZE_DECORATION);
84         if ( thingie ) {
85             if ( SP_IS_ICON(thingie->gobj()) ) {
86                 SPIcon* icon = SP_ICON(thingie->gobj());
87                 sp_icon_fetch_pixbuf( icon );
88                 _property_pixbuf_on = Glib::wrap( icon->pb, true );
89             }
90             delete thingie;
91         }
92         thingie = sp_icon_get_icon(_pixOffName.c_str(), Inkscape::ICON_SIZE_DECORATION);
93         if ( thingie ) {
94             if ( SP_IS_ICON(thingie->gobj()) ) {
95                 SPIcon* icon = SP_ICON(thingie->gobj());
96                 sp_icon_fetch_pixbuf( icon );
97                 _property_pixbuf_off = Glib::wrap( icon->pb, true );
98             }
99             delete thingie;
100         }
101         property_pixbuf() = _property_pixbuf_off.get_value();
102     }
104     sigc::signal<void, const Glib::ustring&> signal_toggled()
105     {
106         return _signal_toggled;
107     }
109     sigc::signal<void, GdkEvent const *> signal_pre_toggle()
110     {
111         return _signal_pre_toggle;
112     }
114     Glib::PropertyProxy<bool> property_active() { return _property_active.get_proxy(); }
115     Glib::PropertyProxy<bool> property_activatable() { return _property_activatable.get_proxy(); }
116     Glib::PropertyProxy< Glib::RefPtr<Gdk::Pixbuf> > property_pixbuf_on();
117     Glib::PropertyProxy< Glib::RefPtr<Gdk::Pixbuf> > property_pixbuf_off();
118 //  virtual Glib::PropertyProxy_Base _property_renderable(); //override
120 protected:
122     virtual void get_size_vfunc( Gtk::Widget& widget,
123                                  const Gdk::Rectangle* cell_area,
124                                  int* x_offset,
125                                  int* y_offset,
126                                  int* width,
127                                  int* height ) const
128     {
129         Gtk::CellRendererPixbuf::get_size_vfunc( widget, cell_area, x_offset, y_offset, width, height );
131         if ( width ) {
132             *width += (*width) >> 1;
133         }
134         if ( height ) {
135             *height += (*height) >> 1;
136         }
137     }
140     virtual void render_vfunc( const Glib::RefPtr<Gdk::Drawable>& window,
141                                Gtk::Widget& widget,
142                                const Gdk::Rectangle& background_area,
143                                const Gdk::Rectangle& cell_area,
144                                const Gdk::Rectangle& expose_area,
145                                Gtk::CellRendererState flags )
146     {
147         property_pixbuf() = _property_active.get_value() ? _property_pixbuf_on : _property_pixbuf_off;
148         Gtk::CellRendererPixbuf::render_vfunc( window, widget, background_area, cell_area, expose_area, flags );
149     }
151     virtual bool activate_vfunc(GdkEvent* event,
152                                 Gtk::Widget& /*widget*/,
153                                 const Glib::ustring& path,
154                                 const Gdk::Rectangle& /*background_area*/,
155                                 const Gdk::Rectangle& /*cell_area*/,
156                                 Gtk::CellRendererState /*flags*/)
157     {
158         _signal_pre_toggle.emit(event);
159         _signal_toggled.emit(path);
161         return false;
162     }
165 private:
166     Glib::ustring _pixOnName;
167     Glib::ustring _pixOffName;
169     Glib::Property<bool> _property_active;
170     Glib::Property<bool> _property_activatable;
171     Glib::Property< Glib::RefPtr<Gdk::Pixbuf> > _property_pixbuf_on;
172     Glib::Property< Glib::RefPtr<Gdk::Pixbuf> > _property_pixbuf_off;
174     sigc::signal<void, const Glib::ustring&> _signal_toggled;
175     sigc::signal<void, GdkEvent const *> _signal_pre_toggle;
176 };
178 class LayersPanel::InternalUIBounce
180 public:
181     int _actionCode;
182     SPObject* _target;
183 };
185 static gboolean layers_panel_activated( GtkObject */*object*/, GdkEvent * /*event*/, gpointer data )
187     if ( data )
188     {
189         LayersPanel* panel = reinterpret_cast<LayersPanel*>(data);
190         panel->setDesktop(panel->getDesktop());
191     }
193     return FALSE;
197 void LayersPanel::_styleButton( Gtk::Button& btn, SPDesktop *desktop, unsigned int code, char const* iconName, char const* fallback )
199     bool set = false;
201     if ( iconName ) {
202         GtkWidget *child = sp_icon_new( Inkscape::ICON_SIZE_SMALL_TOOLBAR, iconName );
203         gtk_widget_show( child );
204         btn.add( *manage(Glib::wrap(child)) );
205         set = true;
206     }
208     if ( desktop ) {
209         Verb *verb = Verb::get( code );
210         if ( verb ) {
211             SPAction *action = verb->get_action(desktop);
212             if ( !set && action && action->image ) {
213                 GtkWidget *child = sp_icon_new( Inkscape::ICON_SIZE_SMALL_TOOLBAR, action->image );
214                 gtk_widget_show( child );
215                 btn.add( *manage(Glib::wrap(child)) );
216                 set = true;
217             }
219             if ( action && action->tip ) {
220                 _tips.set_tip( btn, action->tip );
221             }
222         }
223     }
225     if ( !set && fallback ) {
226         btn.set_label( fallback );
227     }
231 Gtk::MenuItem& LayersPanel::_addPopupItem( SPDesktop *desktop, unsigned int code, char const* iconName, char const* fallback, int id )
233     GtkWidget* iconWidget = 0;
234     const char* label = 0;
236     if ( iconName ) {
237         iconWidget = sp_icon_new( Inkscape::ICON_SIZE_MENU, iconName );
238     }
240     if ( desktop ) {
241         Verb *verb = Verb::get( code );
242         if ( verb ) {
243             SPAction *action = verb->get_action(desktop);
244             if ( !iconWidget && action && action->image ) {
245                 iconWidget = sp_icon_new( Inkscape::ICON_SIZE_MENU, action->image );
246             }
248             if ( action ) {
249                 label = action->name;
250             }
251         }
252     }
254     if ( !label && fallback ) {
255         label = fallback;
256     }
258     Gtk::Widget* wrapped = 0;
259     if ( iconWidget ) {
260         wrapped = manage(Glib::wrap(iconWidget));
261         wrapped->show();
262     }
266     Gtk::Menu::MenuList& menulist = _popupMenu.items();
268     if ( wrapped ) {
269         menulist.push_back( Gtk::Menu_Helpers::ImageMenuElem( label, *wrapped, sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), id)) );
270     } else {
271         menulist.push_back( Gtk::Menu_Helpers::MenuElem( label, sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), id)) );
272     }
273     return menulist.back();
276 void LayersPanel::_fireAction( unsigned int code )
278     if ( _desktop ) {
279         Verb *verb = Verb::get( code );
280         if ( verb ) {
281             SPAction *action = verb->get_action(_desktop);
282             if ( action ) {
283                 sp_action_perform( action, NULL );
284 //             } else {
285 //                 g_message("no action");
286             }
287 //         } else {
288 //             g_message("no verb for %u", code);
289         }
290 //     } else {
291 //         g_message("no active desktop");
292     }
295 //     SP_VERB_LAYER_NEXT,
296 //     SP_VERB_LAYER_PREV,
297 void LayersPanel::_takeAction( int val )
299     if ( !_pending ) {
300         _pending = new InternalUIBounce();
301         _pending->_actionCode = val;
302         _pending->_target = _selectedLayer();
303         Glib::signal_timeout().connect( sigc::mem_fun(*this, &LayersPanel::_executeAction), 0 );
304     }
307 bool LayersPanel::_executeAction()
309     // Make sure selected layer hasn't changed since the action was triggered
310     if ( _pending
311          && (
312              (_pending->_actionCode == BUTTON_NEW)
313              || !( (_desktop && _desktop->currentLayer())
314                    && (_desktop->currentLayer() != _pending->_target)
315                  )
316              )
317         ) {
318         int val = _pending->_actionCode;
319 //        SPObject* target = _pending->_target;
321         switch ( val ) {
322             case BUTTON_NEW:
323             {
324                 _fireAction( SP_VERB_LAYER_NEW );
325             }
326             break;
327             case BUTTON_RENAME:
328             {
329                 _fireAction( SP_VERB_LAYER_RENAME );
330             }
331             break;
332             case BUTTON_TOP:
333             {
334                 _fireAction( SP_VERB_LAYER_TO_TOP );
335             }
336             break;
337             case BUTTON_BOTTOM:
338             {
339                 _fireAction( SP_VERB_LAYER_TO_BOTTOM );
340             }
341             break;
342             case BUTTON_UP:
343             {
344                 _fireAction( SP_VERB_LAYER_RAISE );
345             }
346             break;
347             case BUTTON_DOWN:
348             {
349                 _fireAction( SP_VERB_LAYER_LOWER );
350             }
351             break;
352             case BUTTON_DELETE:
353             {
354                 _fireAction( SP_VERB_LAYER_DELETE );
355             }
356             break;
357         }
359         delete _pending;
360         _pending = 0;
361     }
363     return false;
366 class LayersPanel::ModelColumns : public Gtk::TreeModel::ColumnRecord
368 public:
370     ModelColumns()
371     {
372         add(_colObject);
373         add(_colVisible);
374         add(_colLocked);
375         add(_colLabel);
376     }
377     virtual ~ModelColumns() {}
379     Gtk::TreeModelColumn<SPObject*> _colObject;
380     Gtk::TreeModelColumn<Glib::ustring> _colLabel;
381     Gtk::TreeModelColumn<bool> _colVisible;
382     Gtk::TreeModelColumn<bool> _colLocked;
383 };
385 void LayersPanel::_updateLayer( SPObject *layer ) {
386     _store->foreach( sigc::bind<SPObject*>(sigc::mem_fun(*this, &LayersPanel::_checkForUpdated), layer) );
389 bool LayersPanel::_checkForUpdated(const Gtk::TreePath &/*path*/, const Gtk::TreeIter& iter, SPObject* layer)
391     bool stopGoing = false;
392     Gtk::TreeModel::Row row = *iter;
393     Glib::ustring tmp = row[_model->_colLabel];
394     if ( layer == row[_model->_colObject] )
395     {
396         row[_model->_colLabel] = layer->label() ? layer->label() : SP_OBJECT_ID(layer);
397         row[_model->_colVisible] = SP_IS_ITEM(layer) ? !SP_ITEM(layer)->isHidden() : false;
398         row[_model->_colLocked] = SP_IS_ITEM(layer) ? SP_ITEM(layer)->isLocked() : false;
400         stopGoing = true;
401     }
403     return stopGoing;
406 void LayersPanel::_selectLayer( SPObject *layer ) {
407     if ( !layer || (_desktop && _desktop->doc() && (layer == _desktop->doc()->root)) ) {
408         if ( _tree.get_selection()->count_selected_rows() != 0 ) {
409             _tree.get_selection()->unselect_all();
410         }
411     } else {
412         _store->foreach( sigc::bind<SPObject*>(sigc::mem_fun(*this, &LayersPanel::_checkForSelected), layer) );
413     }
415     _checkTreeSelection();
418 bool LayersPanel::_checkForSelected(const Gtk::TreePath &path, const Gtk::TreeIter& iter, SPObject* layer)
420     bool stopGoing = false;
422     Gtk::TreeModel::Row row = *iter;
423     if ( layer == row[_model->_colObject] )
424     {
425         _tree.expand_to_path( path );
427         Glib::RefPtr<Gtk::TreeSelection> select = _tree.get_selection();
429         select->select(iter);
431         stopGoing = true;
432     }
434     return stopGoing;
437 void LayersPanel::_layersChanged()
439 //    g_message("_layersChanged()");
440     SPDocument* document = _desktop->doc();
441     SPObject* root = document->root;
442     if ( root ) {
443         _selectedConnection.block();
444         if ( _mgr && _mgr->includes( root ) ) {
445             SPObject* target = _desktop->currentLayer();
446             _store->clear();
448 #if DUMP_LAYERS
449             g_message("root:%p  {%s}   [%s]", root, root->id, root->label() );
450 #endif // DUMP_LAYERS
451             _addLayer( document, root, 0, target, 0 );
452         }
453         _selectedConnection.unblock();
454     }
457 void LayersPanel::_addLayer( SPDocument* doc, SPObject* layer, Gtk::TreeModel::Row* parentRow, SPObject* target, int level )
459     if ( layer && (level < _maxNestDepth) ) {
460         unsigned int counter = _mgr->childCount(layer);
461         for ( unsigned int i = 0; i < counter; i++ ) {
462             SPObject *child = _mgr->nthChildOf(layer, i);
463             if ( child ) {
464 #if DUMP_LAYERS
465                 g_message(" %3d    layer:%p  {%s}   [%s]", level, child, child->id, child->label() );
466 #endif // DUMP_LAYERS
468                 Gtk::TreeModel::iterator iter = parentRow ? _store->prepend(parentRow->children()) : _store->prepend();
469                 Gtk::TreeModel::Row row = *iter;
470                 row[_model->_colObject] = child;
471                 row[_model->_colLabel] = child->label() ? child->label() : SP_OBJECT_ID(child);
472                 row[_model->_colVisible] = SP_IS_ITEM(child) ? !SP_ITEM(child)->isHidden() : false;
473                 row[_model->_colLocked] = SP_IS_ITEM(child) ? SP_ITEM(child)->isLocked() : false;
475                 if ( target && child == target ) {
476                     _tree.expand_to_path( _store->get_path(iter) );
478                     Glib::RefPtr<Gtk::TreeSelection> select = _tree.get_selection();
479                     select->select(iter);
481                     _checkTreeSelection();
482                 }
484                 _addLayer( doc, child, &row, target, level + 1 );
485             }
486         }
487     }
490 SPObject* LayersPanel::_selectedLayer()
492     SPObject* obj = 0;
494     Gtk::TreeModel::iterator iter = _tree.get_selection()->get_selected();
495     if ( iter ) {
496         Gtk::TreeModel::Row row = *iter;
497         obj = row[_model->_colObject];
498     }
500     return obj;
503 void LayersPanel::_pushTreeSelectionToCurrent()
505     SPObject* inTree = _selectedLayer();
506     // TODO hunt down the possible API abuse in getting NULL
507     if ( _desktop->currentRoot() ) {
508         if ( inTree ) {
509             SPObject* curr = _desktop->currentLayer();
510             if ( curr != inTree ) {
511                 _mgr->setCurrentLayer( inTree );
512             }
513         } else {
514             _mgr->setCurrentLayer( _desktop->doc()->root );
515         }
516     }
519 void LayersPanel::_checkTreeSelection()
521     bool sensitive = false;
522     bool sensitiveNonTop = false;
523     bool sensitiveNonBottom = false;
524     if ( _tree.get_selection()->count_selected_rows() > 0 ) {
525         sensitive = true;
527         SPObject* inTree = _selectedLayer();
528         if ( inTree ) {
530             sensitiveNonTop = (Inkscape::next_layer(inTree->parent, inTree) != 0);
531             sensitiveNonBottom = (Inkscape::previous_layer(inTree->parent, inTree) != 0);
533         }
534     }
537     for ( std::vector<Gtk::Widget*>::iterator it = _watching.begin(); it != _watching.end(); ++it ) {
538         (*it)->set_sensitive( sensitive );
539     }
540     for ( std::vector<Gtk::Widget*>::iterator it = _watchingNonTop.begin(); it != _watchingNonTop.end(); ++it ) {
541         (*it)->set_sensitive( sensitiveNonTop );
542     }
543     for ( std::vector<Gtk::Widget*>::iterator it = _watchingNonBottom.begin(); it != _watchingNonBottom.end(); ++it ) {
544         (*it)->set_sensitive( sensitiveNonBottom );
545     }
548 void LayersPanel::_preToggle( GdkEvent const *event )
550     if ( _toggleEvent ) {
551         gdk_event_free(_toggleEvent);
552         _toggleEvent = 0;
553     }
555     if ( event && (event->type == GDK_BUTTON_PRESS) ) {
556         // Make a copy so we can keep it around.
557         _toggleEvent = gdk_event_copy(const_cast<GdkEvent*>(event));
558     }
561 void LayersPanel::_toggled( Glib::ustring const& str, int targetCol )
563     Gtk::TreeModel::Children::iterator iter = _tree.get_model()->get_iter(str);
564     Gtk::TreeModel::Row row = *iter;
566     Glib::ustring tmp = row[_model->_colLabel];
568     SPObject* obj = row[_model->_colObject];
569     SPItem* item = ( obj && SP_IS_ITEM(obj) ) ? SP_ITEM(obj) : 0;
570     if ( item ) {
571         switch ( targetCol ) {
572             case COL_VISIBLE:
573             {
574                 bool newValue = !row[_model->_colVisible];
575                 row[_model->_colVisible] = newValue;
576                 item->setHidden( !newValue  );
577                 item->updateRepr();
578                 sp_document_done( _desktop->doc() , SP_VERB_DIALOG_LAYERS, 
579                                   newValue? _("Unhide layer") : _("Hide layer"));
580             }
581             break;
583             case COL_LOCKED:
584             {
585                 bool newValue = !row[_model->_colLocked];
586                 row[_model->_colLocked] = newValue;
587                 item->setLocked( newValue );
588                 item->updateRepr();
589                 sp_document_done( _desktop->doc() , SP_VERB_DIALOG_LAYERS, 
590                                   newValue? _("Lock layer") : _("Unlock layer"));
591             }
592             break;
593         }
594     }
597 void LayersPanel::_handleButtonEvent(GdkEventButton* evt)
599     // TODO - fix to a better is-popup function
600     if ( (evt->type == GDK_BUTTON_PRESS) && (evt->button == 3) ) {
603         {
604             Gtk::TreeModel::Path path;
605             Gtk::TreeViewColumn* col = 0;
606             int x = static_cast<int>(evt->x);
607             int y = static_cast<int>(evt->y);
608             int x2 = 0;
609             int y2 = 0;
610             if ( _tree.get_path_at_pos( x, y,
611                                         path, col,
612                                         x2, y2 ) ) {
613                 _checkTreeSelection();
614                 _popupMenu.popup(evt->button, evt->time);
615             }
616         }
618     }
621 void LayersPanel::_handleRowChange( Gtk::TreeModel::Path const& /*path*/, Gtk::TreeModel::iterator const& iter )
623     Gtk::TreeModel::Row row = *iter;
624     if ( row ) {
625         SPObject* obj = row[_model->_colObject];
626         if ( obj ) {
627             gchar const* oldLabel = obj->label();
628             Glib::ustring tmp = row[_model->_colLabel];
629             if ( oldLabel && oldLabel[0] && !tmp.empty() && (tmp != oldLabel) ) {
630                 _mgr->renameLayer( obj, tmp.c_str() );
631                 row[_model->_colLabel] = obj->label();
632             }
633         }
634     }
637 bool LayersPanel::_rowSelectFunction( Glib::RefPtr<Gtk::TreeModel> const & /*model*/, Gtk::TreeModel::Path const & /*path*/, bool currentlySelected )
639     bool val = true;
640     if ( !currentlySelected && _toggleEvent )
641     {
642         GdkEvent* event = gtk_get_current_event();
643         if ( event ) {
644             // (keep these checks separate, so we know when to call gdk_event_free()
645             if ( event->type == GDK_BUTTON_PRESS ) {
646                 GdkEventButton const* target = reinterpret_cast<GdkEventButton const*>(_toggleEvent);
647                 GdkEventButton const* evtb = reinterpret_cast<GdkEventButton const*>(event);
649                 if ( (evtb->window == target->window)
650                      && (evtb->send_event == target->send_event)
651                      && (evtb->time == target->time)
652                      && (evtb->state == target->state)
653                     )
654                 {
655                     // Ooooh! It's a magic one
656                     val = false;
657                 }
658             }
659             gdk_event_free(event);
660         }
661     }
662     return val;
665 /**
666  * Constructor
667  */
668 LayersPanel::LayersPanel() :
669     UI::Widget::Panel("", "dialogs.layers", SP_VERB_DIALOG_LAYERS),
670     _maxNestDepth(20),
671     _mgr(0),
672     _desktop(0),
673     _model(0),
674     _pending(0),
675     _toggleEvent(0),
676     _compositeSettings(SP_VERB_DIALOG_LAYERS, "layers", UI::Widget::SimpleFilterModifier::BLEND)
678     _maxNestDepth = prefs_get_int_attribute_limited("dialogs.layers", "maxDepth", 20, 1, 1000);
680     ModelColumns *zoop = new ModelColumns();
681     _model = zoop;
683     _store = Gtk::TreeStore::create( *zoop );
685     _tree.set_model( _store );
686     _tree.set_headers_visible(false);
688     ImageToggler* eyeRenderer = manage( new ImageToggler("visible", "hidden") );
689     int visibleColNum = _tree.append_column("vis", *eyeRenderer) - 1;
690     eyeRenderer->signal_pre_toggle().connect( sigc::mem_fun(*this, &LayersPanel::_preToggle) );
691     eyeRenderer->signal_toggled().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_toggled), (int)COL_VISIBLE) );
692     eyeRenderer->property_activatable() = true;
693     Gtk::TreeViewColumn* col = _tree.get_column(visibleColNum);
694     if ( col ) {
695         col->add_attribute( eyeRenderer->property_active(), _model->_colVisible );
696     }
698     ImageToggler * renderer = manage( new ImageToggler("width_height_lock", "lock_unlocked") );
699     int lockedColNum = _tree.append_column("lock", *renderer) - 1;
700     renderer->signal_pre_toggle().connect( sigc::mem_fun(*this, &LayersPanel::_preToggle) );
701     renderer->signal_toggled().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_toggled), (int)COL_LOCKED) );
702     renderer->property_activatable() = true;
703     col = _tree.get_column(lockedColNum);
704     if ( col ) {
705         col->add_attribute( renderer->property_active(), _model->_colLocked );
706     }
708     int nameColNum = _tree.append_column_editable("Name", _model->_colLabel) - 1;
710     _tree.set_expander_column( *_tree.get_column(nameColNum) );
712     _compositeSettings.setSubject(&_subject);
714     _selectedConnection = _tree.get_selection()->signal_changed().connect( sigc::mem_fun(*this, &LayersPanel::_pushTreeSelectionToCurrent) );
715     _tree.get_selection()->set_select_function( sigc::mem_fun(*this, &LayersPanel::_rowSelectFunction) );
717     _tree.get_model()->signal_row_changed().connect( sigc::mem_fun(*this, &LayersPanel::_handleRowChange) );
718     _tree.signal_button_press_event().connect_notify( sigc::mem_fun(*this, &LayersPanel::_handleButtonEvent) );
720     _scroller.add( _tree );
721     _scroller.set_policy( Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC );
723     _watching.push_back( &_compositeSettings );
725     _getContents()->pack_start( _scroller, Gtk::PACK_EXPAND_WIDGET );
727     _getContents()->pack_end(_compositeSettings, Gtk::PACK_SHRINK);
728     _getContents()->pack_end(_buttonsRow, Gtk::PACK_SHRINK);
730     SPDesktop* targetDesktop = getDesktop();
732     _buttonsRow.set_child_min_width( 16 );
734     Gtk::Button* btn = manage( new Gtk::Button() );
735     _styleButton( *btn, targetDesktop, SP_VERB_LAYER_NEW, GTK_STOCK_ADD, _("New") );
736     btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_NEW) );
737     _buttonsRow.add( *btn );
739     btn = manage( new Gtk::Button() );
740     _styleButton( *btn, targetDesktop, SP_VERB_LAYER_TO_TOP, GTK_STOCK_GOTO_TOP, _("Top") );
741     btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_TOP) );
742     _watchingNonTop.push_back( btn );
743     _buttonsRow.add( *btn );
745     btn = manage( new Gtk::Button() );
746     _styleButton( *btn, targetDesktop, SP_VERB_LAYER_RAISE, GTK_STOCK_GO_UP, _("Up") );
747     btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_UP) );
748     _watchingNonTop.push_back( btn );
749     _buttonsRow.add( *btn );
751     btn = manage( new Gtk::Button() );
752     _styleButton( *btn, targetDesktop, SP_VERB_LAYER_LOWER, GTK_STOCK_GO_DOWN, _("Dn") );
753     btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_DOWN) );
754     _watchingNonBottom.push_back( btn );
755     _buttonsRow.add( *btn );
757     btn = manage( new Gtk::Button() );
758     _styleButton( *btn, targetDesktop, SP_VERB_LAYER_TO_BOTTOM, GTK_STOCK_GOTO_BOTTOM, _("Bot") );
759     btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_BOTTOM) );
760     _watchingNonBottom.push_back( btn );
761     _buttonsRow.add( *btn );
763 //     btn = manage( new Gtk::Button("Dup") );
764 //     btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_DUPLICATE) );
765 //     _buttonsRow.add( *btn );
767     btn = manage( new Gtk::Button() );
768     _styleButton( *btn, targetDesktop, SP_VERB_LAYER_DELETE, GTK_STOCK_REMOVE, _("X") );
769     btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_DELETE) );
770     _watching.push_back( btn );
771     _buttonsRow.add( *btn );
776     // -------------------------------------------------------
777     {
778         _watching.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_RENAME, 0, "Rename", (int)BUTTON_RENAME ) );
779         _watching.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_NEW, 0, "New", (int)BUTTON_NEW ) );
781          _popupMenu.items().push_back( Gtk::Menu_Helpers::SeparatorElem() );
783         _watchingNonTop.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_RAISE, GTK_STOCK_GO_UP, "Up", (int)BUTTON_UP ) );
784         _watchingNonBottom.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_LOWER, GTK_STOCK_GO_DOWN, "Down", (int)BUTTON_DOWN ) );
786         _popupMenu.show_all_children();
787     }
788     // -------------------------------------------------------
792     for ( std::vector<Gtk::Widget*>::iterator it = _watching.begin(); it != _watching.end(); ++it ) {
793         (*it)->set_sensitive( false );
794     }
795     for ( std::vector<Gtk::Widget*>::iterator it = _watchingNonTop.begin(); it != _watchingNonTop.end(); ++it ) {
796         (*it)->set_sensitive( false );
797     }
798     for ( std::vector<Gtk::Widget*>::iterator it = _watchingNonBottom.begin(); it != _watchingNonBottom.end(); ++it ) {
799         (*it)->set_sensitive( false );
800     }
802     g_signal_connect( G_OBJECT(INKSCAPE), "activate_desktop", G_CALLBACK( layers_panel_activated ), this );
803     setDesktop( targetDesktop );
805     show_all_children();
807     // restorePanelPrefs();
810 LayersPanel::~LayersPanel()
812     _compositeSettings.setSubject(NULL);
814     if ( _model )
815     {
816         delete _model;
817     }
819     if ( _toggleEvent )
820     {
821         gdk_event_free( _toggleEvent );
822         _toggleEvent = 0;
823     }
827 void LayersPanel::setDesktop( SPDesktop* desktop )
829     Panel::setDesktop(desktop);
831     if ( desktop != _desktop ) {
832         _layerChangedConnection.disconnect();
833         _layerUpdatedConnection.disconnect();
834         _changedConnection.disconnect();
835         if ( _mgr ) {
836             _mgr = 0;
837         }
838         if ( _desktop ) {
839             _desktop = 0;
840         }
842         _desktop = getDesktop();
843         if ( _desktop ) {
844             //setLabel( _desktop->doc()->name );
846             _mgr = _desktop->layer_manager;
847             if ( _mgr ) {
848                 _layerChangedConnection = _mgr->connectCurrentLayerChanged( sigc::mem_fun(*this, &LayersPanel::_selectLayer) );
849                 _layerUpdatedConnection = _mgr->connectLayerDetailsChanged( sigc::mem_fun(*this, &LayersPanel::_updateLayer) );
850                 _changedConnection = _mgr->connectChanged( sigc::mem_fun(*this, &LayersPanel::_layersChanged) );
851             }
853             _layersChanged();
854         }
855     }
856 /*
857     GSList const *layers=sp_document_get_resource_list( _desktop->doc(), "layer" );
858     g_message( "layers list starts at %p", layers );
859     for ( GSList const *iter=layers ; iter ; iter = iter->next ) {
860         SPObject *layer=static_cast<SPObject *>(iter->data);
861         g_message("  {%s}   [%s]", layer->id, layer->label() );
862     }
863 */
868 } //namespace Dialogs
869 } //namespace UI
870 } //namespace Inkscape
873 /*
874   Local Variables:
875   mode:c++
876   c-file-style:"stroustrup"
877   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
878   indent-tabs-mode:nil
879   fill-column:99
880   End:
881 */
882 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :