ad2678141fd7d238df0a03dc236dd148afa095c8
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 <gtk/gtkstock.h>
17 #include "inkscape.h"
19 #include "layers-panel.h"
21 #include "layer-manager.h"
22 #include "layer-fns.h"
24 #include "verbs.h"
25 #include "helper/action.h"
27 #include "document.h"
28 #include "desktop.h"
29 #include "sp-object.h"
30 #include "sp-item.h"
31 #include "widgets/icon.h"
32 #include <gtkmm/widget.h>
33 #include "prefs-utils.h"
35 //#define DUMP_LAYERS 1
37 namespace Inkscape {
38 namespace UI {
39 namespace Dialogs {
41 LayersPanel* LayersPanel::instance = 0;
43 LayersPanel& LayersPanel::getInstance()
44 {
45 if ( !instance ) {
46 instance = new LayersPanel();
47 }
49 return *instance;
50 }
52 enum {
53 COL_VISIBLE = 1,
54 COL_LOCKED
55 };
57 enum {
58 BUTTON_NEW = 0,
59 BUTTON_RENAME,
60 BUTTON_TOP,
61 BUTTON_BOTTOM,
62 BUTTON_UP,
63 BUTTON_DOWN,
64 // BUTTON_DUPLICATE,
65 BUTTON_DELETE
66 };
68 class ImageToggler : public Gtk::CellRendererPixbuf {
69 public:
70 ImageToggler( char const* on, char const* off) :
71 Glib::ObjectBase(typeid(ImageToggler)),
72 Gtk::CellRendererPixbuf(),
73 _pixOnName(on),
74 _pixOffName(off),
75 _property_active(*this, "active", false),
76 _property_activatable(*this, "activatable", true),
77 _property_pixbuf_on(*this, "pixbuf_on", Glib::RefPtr<Gdk::Pixbuf>(0)),
78 _property_pixbuf_off(*this, "pixbuf_off", Glib::RefPtr<Gdk::Pixbuf>(0))
79 {
80 property_mode() = Gtk::CELL_RENDERER_MODE_ACTIVATABLE;
82 Gtk::Widget* thingie = sp_icon_get_icon(_pixOnName.c_str(), Inkscape::ICON_SIZE_DECORATION);
83 if ( thingie ) {
84 if ( SP_IS_ICON(thingie->gobj()) ) {
85 SPIcon* icon = SP_ICON(thingie->gobj());
86 sp_icon_fetch_pixbuf( icon );
87 _property_pixbuf_on = Glib::wrap( icon->pb, true );
88 }
89 delete thingie;
90 }
91 thingie = sp_icon_get_icon(_pixOffName.c_str(), Inkscape::ICON_SIZE_DECORATION);
92 if ( thingie ) {
93 if ( SP_IS_ICON(thingie->gobj()) ) {
94 SPIcon* icon = SP_ICON(thingie->gobj());
95 sp_icon_fetch_pixbuf( icon );
96 _property_pixbuf_off = Glib::wrap( icon->pb, true );
97 }
98 delete thingie;
99 }
100 property_pixbuf() = _property_pixbuf_off.get_value();
101 }
103 sigc::signal<void, const Glib::ustring&> signal_toggled()
104 {
105 return _signal_toggled;
106 }
108 Glib::PropertyProxy<bool> property_active() { return _property_active.get_proxy(); }
109 Glib::PropertyProxy<bool> property_activatable() { return _property_activatable.get_proxy(); }
110 Glib::PropertyProxy< Glib::RefPtr<Gdk::Pixbuf> > property_pixbuf_on();
111 Glib::PropertyProxy< Glib::RefPtr<Gdk::Pixbuf> > property_pixbuf_off();
112 // virtual Glib::PropertyProxy_Base _property_renderable(); //override
114 protected:
115 virtual void render_vfunc( const Glib::RefPtr<Gdk::Drawable>& window,
116 Gtk::Widget& widget,
117 const Gdk::Rectangle& background_area,
118 const Gdk::Rectangle& cell_area,
119 const Gdk::Rectangle& expose_area,
120 Gtk::CellRendererState flags )
121 {
122 property_pixbuf() = _property_active.get_value() ? _property_pixbuf_on : _property_pixbuf_off;
123 Gtk::CellRendererPixbuf::render_vfunc( window, widget, background_area, cell_area, expose_area, flags );
124 }
126 virtual bool activate_vfunc(GdkEvent* event,
127 Gtk::Widget& widget,
128 const Glib::ustring& path,
129 const Gdk::Rectangle& background_area,
130 const Gdk::Rectangle& cell_area,
131 Gtk::CellRendererState flags) {
132 bool val = false;
133 _signal_toggled.emit(path);
134 return val;
135 }
138 private:
139 Glib::ustring _pixOnName;
140 Glib::ustring _pixOffName;
142 Glib::Property<bool> _property_active;
143 Glib::Property<bool> _property_activatable;
144 Glib::Property< Glib::RefPtr<Gdk::Pixbuf> > _property_pixbuf_on;
145 Glib::Property< Glib::RefPtr<Gdk::Pixbuf> > _property_pixbuf_off;
147 sigc::signal<void, const Glib::ustring&> _signal_toggled;
148 };
150 class LayersPanel::InternalUIBounce
151 {
152 public:
153 int _actionCode;
154 SPObject* _target;
155 };
157 static gboolean layers_panel_activated( GtkObject *object, GdkEvent * /*event*/, gpointer data )
158 {
159 if ( data )
160 {
161 LayersPanel* panel = reinterpret_cast<LayersPanel*>(data);
162 panel->setDesktop( SP_ACTIVE_DESKTOP );
163 }
165 return FALSE;
166 }
169 void LayersPanel::_styleButton( Gtk::Button& btn, SPDesktop *desktop, unsigned int code, char const* iconName, char const* fallback )
170 {
171 bool set = false;
173 if ( iconName ) {
174 GtkWidget *child = sp_icon_new( Inkscape::ICON_SIZE_SMALL_TOOLBAR, iconName );
175 gtk_widget_show( child );
176 btn.add( *manage(Glib::wrap(child)) );
177 set = true;
178 }
180 if ( desktop ) {
181 Verb *verb = Verb::get( code );
182 if ( verb ) {
183 SPAction *action = verb->get_action(desktop);
184 if ( !set && action && action->image ) {
185 GtkWidget *child = sp_icon_new( Inkscape::ICON_SIZE_SMALL_TOOLBAR, action->image );
186 gtk_widget_show( child );
187 btn.add( *manage(Glib::wrap(child)) );
188 set = true;
189 }
191 if ( action && action->tip ) {
192 _tips.set_tip( btn, action->tip );
193 }
194 }
195 }
197 if ( !set && fallback ) {
198 btn.set_label( fallback );
199 }
200 }
203 Gtk::MenuItem& LayersPanel::_addPopupItem( SPDesktop *desktop, unsigned int code, char const* iconName, char const* fallback, int id )
204 {
205 GtkWidget* iconWidget = 0;
206 const char* label = 0;
208 if ( iconName ) {
209 iconWidget = sp_icon_new( Inkscape::ICON_SIZE_MENU, iconName );
210 }
212 if ( desktop ) {
213 Verb *verb = Verb::get( code );
214 if ( verb ) {
215 SPAction *action = verb->get_action(desktop);
216 if ( !iconWidget && action && action->image ) {
217 iconWidget = sp_icon_new( Inkscape::ICON_SIZE_MENU, action->image );
218 }
220 if ( action ) {
221 label = action->name;
222 }
223 }
224 }
226 if ( !label && fallback ) {
227 label = fallback;
228 }
230 Gtk::Widget* wrapped = 0;
231 if ( iconWidget ) {
232 wrapped = manage(Glib::wrap(iconWidget));
233 wrapped->show();
234 }
238 Gtk::Menu::MenuList& menulist = _popupMenu.items();
240 if ( wrapped ) {
241 menulist.push_back( Gtk::Menu_Helpers::ImageMenuElem( label, *wrapped, sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), id)) );
242 } else {
243 menulist.push_back( Gtk::Menu_Helpers::MenuElem( label, sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), id)) );
244 }
245 return menulist.back();
246 }
248 void LayersPanel::_fireAction( unsigned int code )
249 {
250 if ( _desktop ) {
251 Verb *verb = Verb::get( code );
252 if ( verb ) {
253 SPAction *action = verb->get_action(_desktop);
254 if ( action ) {
255 sp_action_perform( action, NULL );
256 // } else {
257 // g_message("no action");
258 }
259 // } else {
260 // g_message("no verb for %u", code);
261 }
262 // } else {
263 // g_message("no active desktop");
264 }
265 }
267 // SP_VERB_LAYER_NEXT,
268 // SP_VERB_LAYER_PREV,
269 void LayersPanel::_takeAction( int val )
270 {
271 if ( !_pending ) {
272 _pending = new InternalUIBounce();
273 _pending->_actionCode = val;
274 _pending->_target = _selectedLayer();
275 Glib::signal_timeout().connect( sigc::mem_fun(*this, &LayersPanel::_executeAction), 0 );
276 }
277 }
279 bool LayersPanel::_executeAction()
280 {
281 // Make sure selected layer hasn't changed since the action was triggered
282 if ( _pending
283 && !( (_desktop && _desktop->currentLayer())
284 && (_desktop->currentLayer() != _pending->_target)
285 ) ) {
286 int val = _pending->_actionCode;
287 // SPObject* target = _pending->_target;
289 switch ( val ) {
290 case BUTTON_NEW:
291 {
292 _fireAction( SP_VERB_LAYER_NEW );
293 }
294 break;
295 case BUTTON_RENAME:
296 {
297 _fireAction( SP_VERB_LAYER_RENAME );
298 }
299 break;
300 case BUTTON_TOP:
301 {
302 _fireAction( SP_VERB_LAYER_TO_TOP );
303 }
304 break;
305 case BUTTON_BOTTOM:
306 {
307 _fireAction( SP_VERB_LAYER_TO_BOTTOM );
308 }
309 break;
310 case BUTTON_UP:
311 {
312 _fireAction( SP_VERB_LAYER_RAISE );
313 }
314 break;
315 case BUTTON_DOWN:
316 {
317 _fireAction( SP_VERB_LAYER_LOWER );
318 }
319 break;
320 case BUTTON_DELETE:
321 {
322 _fireAction( SP_VERB_LAYER_DELETE );
323 }
324 break;
325 }
327 delete _pending;
328 _pending = 0;
329 }
331 return false;
332 }
334 class LayersPanel::ModelColumns : public Gtk::TreeModel::ColumnRecord
335 {
336 public:
338 ModelColumns()
339 {
340 add(_colObject);
341 add(_colVisible);
342 add(_colLocked);
343 add(_colLabel);
344 }
345 virtual ~ModelColumns() {}
347 Gtk::TreeModelColumn<SPObject*> _colObject;
348 Gtk::TreeModelColumn<Glib::ustring> _colLabel;
349 Gtk::TreeModelColumn<bool> _colVisible;
350 Gtk::TreeModelColumn<bool> _colLocked;
351 };
353 void LayersPanel::_updateLayer( SPObject *layer ) {
354 _store->foreach( sigc::bind<SPObject*>(sigc::mem_fun(*this, &LayersPanel::_checkForUpdated), layer) );
355 }
357 bool LayersPanel::_checkForUpdated(const Gtk::TreePath &path, const Gtk::TreeIter& iter, SPObject* layer)
358 {
359 bool stopGoing = false;
360 Gtk::TreeModel::Row row = *iter;
361 Glib::ustring tmp = row[_model->_colLabel];
362 if ( layer == row[_model->_colObject] )
363 {
364 row[_model->_colLabel] = layer->label() ? layer->label() : SP_OBJECT_ID(layer);
365 row[_model->_colVisible] = SP_IS_ITEM(layer) ? !SP_ITEM(layer)->isHidden() : false;
366 row[_model->_colLocked] = SP_IS_ITEM(layer) ? SP_ITEM(layer)->isLocked() : false;
368 stopGoing = true;
369 }
371 return stopGoing;
372 }
374 void LayersPanel::_selectLayer( SPObject *layer ) {
375 if ( !layer || (_desktop && _desktop->doc() && (layer == _desktop->doc()->root)) ) {
376 if ( _tree.get_selection()->count_selected_rows() != 0 ) {
377 _tree.get_selection()->unselect_all();
378 }
379 } else {
380 _store->foreach( sigc::bind<SPObject*>(sigc::mem_fun(*this, &LayersPanel::_checkForSelected), layer) );
381 }
383 _checkTreeSelection();
384 }
386 bool LayersPanel::_checkForSelected(const Gtk::TreePath &path, const Gtk::TreeIter& iter, SPObject* layer)
387 {
388 bool stopGoing = false;
390 Gtk::TreeModel::Row row = *iter;
391 Glib::ustring tmp = row[_model->_colLabel];
392 if ( layer == row[_model->_colObject] )
393 {
394 _tree.expand_to_path( path );
396 Glib::RefPtr<Gtk::TreeSelection> select = _tree.get_selection();
397 select->select(iter);
399 stopGoing = true;
400 }
402 return stopGoing;
403 }
405 void LayersPanel::_layersChanged()
406 {
407 // g_message("_layersChanged()");
408 SPDocument* document = _desktop->doc();
409 SPObject* root = document->root;
410 if ( root ) {
411 if ( _mgr && _mgr->includes( root ) ) {
412 SPObject* target = _desktop->currentLayer();
413 _store->clear();
415 #if DUMP_LAYERS
416 g_message("root:%p {%s} [%s]", root, root->id, root->label() );
417 #endif // DUMP_LAYERS
418 _addLayer( document, root, 0, target, 0 );
419 }
420 }
421 }
423 void LayersPanel::_addLayer( SPDocument* doc, SPObject* layer, Gtk::TreeModel::Row* parentRow, SPObject* target, int level )
424 {
425 if ( layer && (level < _maxNestDepth) ) {
426 unsigned int counter = _mgr->childCount(layer);
427 for ( unsigned int i = 0; i < counter; i++ ) {
428 SPObject *child = _mgr->nthChildOf(layer, i);
429 if ( child ) {
430 #if DUMP_LAYERS
431 g_message(" %3d layer:%p {%s} [%s]", level, child, child->id, child->label() );
432 #endif // DUMP_LAYERS
434 Gtk::TreeModel::iterator iter = parentRow ? _store->prepend(parentRow->children()) : _store->prepend();
435 Gtk::TreeModel::Row row = *iter;
436 row[_model->_colObject] = child;
437 row[_model->_colLabel] = child->label() ? child->label() : SP_OBJECT_ID(child);
438 row[_model->_colVisible] = SP_IS_ITEM(child) ? !SP_ITEM(child)->isHidden() : false;
439 row[_model->_colLocked] = SP_IS_ITEM(child) ? SP_ITEM(child)->isLocked() : false;
441 if ( target && child == target ) {
442 _tree.expand_to_path( _store->get_path(iter) );
444 Glib::RefPtr<Gtk::TreeSelection> select = _tree.get_selection();
445 select->select(iter);
446 _checkTreeSelection();
447 }
449 _addLayer( doc, child, &row, target, level + 1 );
450 }
451 }
452 }
453 }
455 SPObject* LayersPanel::_selectedLayer()
456 {
457 SPObject* obj = 0;
459 Gtk::TreeModel::iterator iter = _tree.get_selection()->get_selected();
460 if ( iter ) {
461 Gtk::TreeModel::Row row = *iter;
462 obj = row[_model->_colObject];
463 }
465 return obj;
466 }
468 void LayersPanel::_pushTreeSelectionToCurrent()
469 {
470 SPObject* inTree = _selectedLayer();
471 if ( inTree ) {
472 SPObject* curr = _desktop->currentLayer();
473 if ( curr != inTree ) {
474 _desktop->setCurrentLayer( inTree );
475 }
476 } else {
477 _desktop->setCurrentLayer( _desktop->doc()->root );
478 }
479 }
481 void LayersPanel::_checkTreeSelection()
482 {
483 bool sensitive = false;
484 bool sensitiveNonTop = false;
485 bool sensitiveNonBottom = false;
486 if ( _tree.get_selection()->count_selected_rows() > 0 ) {
487 sensitive = true;
489 SPObject* inTree = _selectedLayer();
490 if ( inTree ) {
492 sensitiveNonTop = (Inkscape::next_layer(inTree->parent, inTree) != 0);
493 sensitiveNonBottom = (Inkscape::previous_layer(inTree->parent, inTree) != 0);
494 }
495 }
497 for ( std::vector<Gtk::Widget*>::iterator it = _watching.begin(); it != _watching.end(); ++it ) {
498 (*it)->set_sensitive( sensitive );
499 }
500 for ( std::vector<Gtk::Widget*>::iterator it = _watchingNonTop.begin(); it != _watchingNonTop.end(); ++it ) {
501 (*it)->set_sensitive( sensitiveNonTop );
502 }
503 for ( std::vector<Gtk::Widget*>::iterator it = _watchingNonBottom.begin(); it != _watchingNonBottom.end(); ++it ) {
504 (*it)->set_sensitive( sensitiveNonBottom );
505 }
506 }
508 void LayersPanel::_toggled( Glib::ustring const& str, int targetCol )
509 {
510 Gtk::TreeModel::Children::iterator iter = _tree.get_model()->get_iter(str);
511 Gtk::TreeModel::Row row = *iter;
513 Glib::ustring tmp = row[_model->_colLabel];
515 SPObject* obj = row[_model->_colObject];
516 SPItem* item = ( obj && SP_IS_ITEM(obj) ) ? SP_ITEM(obj) : 0;
517 if ( item ) {
518 switch ( targetCol ) {
519 case COL_VISIBLE:
520 {
521 bool newValue = !row[_model->_colVisible];
522 row[_model->_colVisible] = newValue;
523 item->setHidden( !newValue );
524 item->updateRepr();
525 sp_document_done( _desktop->doc() );
526 }
527 break;
529 case COL_LOCKED:
530 {
531 bool newValue = !row[_model->_colLocked];
532 row[_model->_colLocked] = newValue;
533 item->setLocked( newValue );
534 item->updateRepr();
535 sp_document_done( _desktop->doc() );
536 }
537 break;
538 }
539 }
540 }
542 void LayersPanel::_handleButtonEvent(GdkEventButton* evt)
543 {
544 if ( (evt->type == GDK_BUTTON_PRESS) && (evt->button == 3) ) {
547 {
548 Gtk::TreeModel::Path path;
549 Gtk::TreeViewColumn* col = 0;
550 int x = static_cast<int>(evt->x);
551 int y = static_cast<int>(evt->y);
552 int x2 = 0;
553 int y2 = 0;
554 if ( _tree.get_path_at_pos( x, y,
555 path, col,
556 x2, y2 ) ) {
557 _checkTreeSelection();
558 _popupMenu.popup(evt->button, evt->time);
559 }
560 }
562 }
563 }
565 void LayersPanel::_handleRowChange( Gtk::TreeModel::Path const& path, Gtk::TreeModel::iterator const& iter )
566 {
567 Gtk::TreeModel::Row row = *iter;
568 if ( row ) {
569 SPObject* obj = row[_model->_colObject];
570 if ( obj ) {
571 gchar const* oldLabel = obj->label();
572 Glib::ustring tmp = row[_model->_colLabel];
573 if ( oldLabel && oldLabel[0] && !tmp.empty() && (tmp != oldLabel) ) {
574 obj->setLabel(tmp.c_str());
575 }
576 }
577 }
578 }
580 /**
581 * Constructor
582 */
583 LayersPanel::LayersPanel() :
584 Inkscape::UI::Widget::Panel( Glib::ustring(), "dialogs.layers" ),
585 _maxNestDepth(20),
586 _mgr(0),
587 _desktop(0),
588 _model(0),
589 _pending(0)
590 {
591 _maxNestDepth = prefs_get_int_attribute_limited("dialogs.layers", "maxDepth", 20, 1, 1000);
593 ModelColumns *zoop = new ModelColumns();
594 _model = zoop;
596 _store = Gtk::TreeStore::create( *zoop );
598 _tree.set_model( _store );
599 _tree.set_headers_visible(false);
601 ImageToggler* eyeRenderer = manage( new ImageToggler("visible", "hidden") );
602 int visibleColNum = _tree.append_column("vis", *eyeRenderer) - 1;
603 eyeRenderer->signal_toggled().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_toggled), (int)COL_VISIBLE) );
604 eyeRenderer->property_activatable() = true;
605 Gtk::TreeViewColumn* col = _tree.get_column(visibleColNum);
606 if ( col ) {
607 col->add_attribute( eyeRenderer->property_active(), _model->_colVisible );
608 }
610 ImageToggler * renderer = manage( new ImageToggler("width_height_lock", "lock_unlocked") );
611 int lockedColNum = _tree.append_column("lock", *renderer) - 1;
612 renderer->signal_toggled().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_toggled), (int)COL_LOCKED) );
613 renderer->property_activatable() = true;
614 col = _tree.get_column(lockedColNum);
615 if ( col ) {
616 col->add_attribute( renderer->property_active(), _model->_colLocked );
617 }
619 int nameColNum = _tree.append_column_editable("Name", _model->_colLabel) - 1;
621 _tree.set_expander_column( *_tree.get_column(nameColNum) );
624 _tree.get_selection()->signal_changed().connect( sigc::mem_fun(*this, &LayersPanel::_pushTreeSelectionToCurrent) );
626 _tree.get_model()->signal_row_changed().connect( sigc::mem_fun(*this, &LayersPanel::_handleRowChange) );
627 _tree.signal_button_press_event().connect_notify( sigc::mem_fun(*this, &LayersPanel::_handleButtonEvent) );
629 _scroller.add( _tree );
630 _scroller.set_policy( Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC );
631 _getContents()->pack_start( _scroller, Gtk::PACK_EXPAND_WIDGET );
632 _getContents()->pack_end(_buttonsRow, Gtk::PACK_SHRINK);
634 SPDesktop* targetDesktop = SP_ACTIVE_DESKTOP;
636 Gtk::Button* btn = manage( new Gtk::Button() );
637 _styleButton( *btn, targetDesktop, SP_VERB_LAYER_NEW, GTK_STOCK_ADD, "Ne" );
638 btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_NEW) );
639 _buttonsRow.pack_start( *btn );
641 btn = manage( new Gtk::Button() );
642 _styleButton( *btn, targetDesktop, SP_VERB_LAYER_TO_TOP, GTK_STOCK_GOTO_TOP, "Top" );
643 btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_TOP) );
644 _watchingNonTop.push_back( btn );
645 _buttonsRow.pack_start( *btn );
647 btn = manage( new Gtk::Button() );
648 _styleButton( *btn, targetDesktop, SP_VERB_LAYER_RAISE, GTK_STOCK_GO_UP, "Up" );
649 btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_UP) );
650 _watchingNonTop.push_back( btn );
651 _buttonsRow.pack_start( *btn );
653 btn = manage( new Gtk::Button() );
654 _styleButton( *btn, targetDesktop, SP_VERB_LAYER_LOWER, GTK_STOCK_GO_DOWN, "Dn" );
655 btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_DOWN) );
656 _watchingNonBottom.push_back( btn );
657 _buttonsRow.pack_start( *btn );
659 btn = manage( new Gtk::Button() );
660 _styleButton( *btn, targetDesktop, SP_VERB_LAYER_TO_BOTTOM, GTK_STOCK_GOTO_BOTTOM, "Btm" );
661 btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_BOTTOM) );
662 _watchingNonBottom.push_back( btn );
663 _buttonsRow.pack_start( *btn );
665 // btn = manage( new Gtk::Button("Dup") );
666 // btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_DUPLICATE) );
667 // _buttonsRow.pack_start( *btn );
669 btn = manage( new Gtk::Button() );
670 _styleButton( *btn, targetDesktop, SP_VERB_LAYER_DELETE, GTK_STOCK_REMOVE, "X" );
671 btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_DELETE) );
672 _watching.push_back( btn );
673 _buttonsRow.pack_start( *btn );
678 // -------------------------------------------------------
679 {
680 _watching.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_RENAME, 0, "Rename", (int)BUTTON_RENAME ) );
681 _watching.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_NEW, 0, "New", (int)BUTTON_NEW ) );
683 _popupMenu.items().push_back( Gtk::Menu_Helpers::SeparatorElem() );
685 _watchingNonTop.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_RAISE, GTK_STOCK_GO_UP, "Up", (int)BUTTON_UP ) );
686 _watchingNonBottom.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_LOWER, GTK_STOCK_GO_DOWN, "Down", (int)BUTTON_DOWN ) );
688 _popupMenu.show_all_children();
689 }
690 // -------------------------------------------------------
694 for ( std::vector<Gtk::Widget*>::iterator it = _watching.begin(); it != _watching.end(); ++it ) {
695 (*it)->set_sensitive( false );
696 }
697 for ( std::vector<Gtk::Widget*>::iterator it = _watchingNonTop.begin(); it != _watchingNonTop.end(); ++it ) {
698 (*it)->set_sensitive( false );
699 }
700 for ( std::vector<Gtk::Widget*>::iterator it = _watchingNonBottom.begin(); it != _watchingNonBottom.end(); ++it ) {
701 (*it)->set_sensitive( false );
702 }
704 g_signal_connect( G_OBJECT(INKSCAPE), "activate_desktop", G_CALLBACK( layers_panel_activated ), this );
707 setDesktop( targetDesktop );
711 show_all_children();
713 restorePanelPrefs();
714 }
716 LayersPanel::~LayersPanel()
717 {
718 if ( _model )
719 {
720 delete _model;
721 }
722 }
725 void LayersPanel::setDesktop( SPDesktop* desktop )
726 {
727 if ( desktop != _desktop ) {
728 _layerChangedConnection.disconnect();
729 _layerUpdatedConnection.disconnect();
730 _changedConnection.disconnect();
731 if ( _mgr ) {
732 _mgr = 0;
733 }
734 if ( _desktop ) {
735 _desktop = 0;
736 }
738 _desktop = SP_ACTIVE_DESKTOP;
739 if ( _desktop ) {
740 setLabel( _desktop->doc()->name );
742 _mgr = _desktop->layer_manager;
743 if ( _mgr ) {
744 _layerChangedConnection = _mgr->connectCurrentLayerChanged( sigc::mem_fun(*this, &LayersPanel::_selectLayer) );
745 _layerUpdatedConnection = _mgr->connectLayerDetailsChanged( sigc::mem_fun(*this, &LayersPanel::_updateLayer) );
746 _changedConnection = _mgr->connectChanged( sigc::mem_fun(*this, &LayersPanel::_layersChanged) );
747 }
749 _layersChanged();
750 }
751 }
752 /*
753 GSList const *layers=sp_document_get_resource_list( _desktop->doc(), "layer" );
754 g_message( "layers list starts at %p", layers );
755 for ( GSList const *iter=layers ; iter ; iter = iter->next ) {
756 SPObject *layer=static_cast<SPObject *>(iter->data);
757 g_message(" {%s} [%s]", layer->id, layer->label() );
758 }
759 */
760 }
764 } //namespace Dialogs
765 } //namespace UI
766 } //namespace Inkscape
769 /*
770 Local Variables:
771 mode:c++
772 c-file-style:"stroustrup"
773 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
774 indent-tabs-mode:nil
775 fill-column:99
776 End:
777 */
778 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :