31e9823c6a4797952061a8ae9ad9ecfe94cccd7e
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 "desktop-handles.h"
30 #include "selection.h"
31 #include "sp-object.h"
32 #include "sp-item.h"
33 #include "widgets/icon.h"
34 #include <gtkmm/widget.h>
35 #include "prefs-utils.h"
37 //#define DUMP_LAYERS 1
39 namespace Inkscape {
40 namespace UI {
41 namespace Dialogs {
43 LayersPanel* LayersPanel::instance = 0;
45 LayersPanel& LayersPanel::getInstance()
46 {
47 if ( !instance ) {
48 instance = new LayersPanel();
49 }
51 return *instance;
52 }
54 enum {
55 COL_VISIBLE = 1,
56 COL_LOCKED
57 };
59 enum {
60 BUTTON_NEW = 0,
61 BUTTON_RENAME,
62 BUTTON_TOP,
63 BUTTON_BOTTOM,
64 BUTTON_UP,
65 BUTTON_DOWN,
66 // BUTTON_DUPLICATE,
67 BUTTON_DELETE
68 };
70 class ImageToggler : public Gtk::CellRendererPixbuf {
71 public:
72 ImageToggler( char const* on, char const* off) :
73 Glib::ObjectBase(typeid(ImageToggler)),
74 Gtk::CellRendererPixbuf(),
75 _pixOnName(on),
76 _pixOffName(off),
77 _property_active(*this, "active", false),
78 _property_activatable(*this, "activatable", true),
79 _property_pixbuf_on(*this, "pixbuf_on", Glib::RefPtr<Gdk::Pixbuf>(0)),
80 _property_pixbuf_off(*this, "pixbuf_off", Glib::RefPtr<Gdk::Pixbuf>(0))
81 {
82 property_mode() = Gtk::CELL_RENDERER_MODE_ACTIVATABLE;
84 Gtk::Widget* thingie = sp_icon_get_icon(_pixOnName.c_str(), Inkscape::ICON_SIZE_DECORATION);
85 if ( thingie ) {
86 if ( SP_IS_ICON(thingie->gobj()) ) {
87 SPIcon* icon = SP_ICON(thingie->gobj());
88 sp_icon_fetch_pixbuf( icon );
89 _property_pixbuf_on = Glib::wrap( icon->pb, true );
90 }
91 delete thingie;
92 }
93 thingie = sp_icon_get_icon(_pixOffName.c_str(), Inkscape::ICON_SIZE_DECORATION);
94 if ( thingie ) {
95 if ( SP_IS_ICON(thingie->gobj()) ) {
96 SPIcon* icon = SP_ICON(thingie->gobj());
97 sp_icon_fetch_pixbuf( icon );
98 _property_pixbuf_off = Glib::wrap( icon->pb, true );
99 }
100 delete thingie;
101 }
102 property_pixbuf() = _property_pixbuf_off.get_value();
103 }
105 sigc::signal<void, const Glib::ustring&> signal_toggled()
106 {
107 return _signal_toggled;
108 }
110 Glib::PropertyProxy<bool> property_active() { return _property_active.get_proxy(); }
111 Glib::PropertyProxy<bool> property_activatable() { return _property_activatable.get_proxy(); }
112 Glib::PropertyProxy< Glib::RefPtr<Gdk::Pixbuf> > property_pixbuf_on();
113 Glib::PropertyProxy< Glib::RefPtr<Gdk::Pixbuf> > property_pixbuf_off();
114 // virtual Glib::PropertyProxy_Base _property_renderable(); //override
116 protected:
117 virtual void render_vfunc( const Glib::RefPtr<Gdk::Drawable>& window,
118 Gtk::Widget& widget,
119 const Gdk::Rectangle& background_area,
120 const Gdk::Rectangle& cell_area,
121 const Gdk::Rectangle& expose_area,
122 Gtk::CellRendererState flags )
123 {
124 property_pixbuf() = _property_active.get_value() ? _property_pixbuf_on : _property_pixbuf_off;
125 Gtk::CellRendererPixbuf::render_vfunc( window, widget, background_area, cell_area, expose_area, flags );
126 }
128 virtual bool activate_vfunc(GdkEvent* event,
129 Gtk::Widget& widget,
130 const Glib::ustring& path,
131 const Gdk::Rectangle& background_area,
132 const Gdk::Rectangle& cell_area,
133 Gtk::CellRendererState flags) {
134 bool val = false;
135 _signal_toggled.emit(path);
136 return val;
137 }
140 private:
141 Glib::ustring _pixOnName;
142 Glib::ustring _pixOffName;
144 Glib::Property<bool> _property_active;
145 Glib::Property<bool> _property_activatable;
146 Glib::Property< Glib::RefPtr<Gdk::Pixbuf> > _property_pixbuf_on;
147 Glib::Property< Glib::RefPtr<Gdk::Pixbuf> > _property_pixbuf_off;
149 sigc::signal<void, const Glib::ustring&> _signal_toggled;
150 };
152 class LayersPanel::InternalUIBounce
153 {
154 public:
155 int _actionCode;
156 SPObject* _target;
157 };
159 static gboolean layers_panel_activated( GtkObject *object, GdkEvent * /*event*/, gpointer data )
160 {
161 if ( data )
162 {
163 LayersPanel* panel = reinterpret_cast<LayersPanel*>(data);
164 panel->setDesktop( SP_ACTIVE_DESKTOP );
165 }
167 return FALSE;
168 }
171 void LayersPanel::_styleButton( Gtk::Button& btn, SPDesktop *desktop, unsigned int code, char const* iconName, char const* fallback )
172 {
173 bool set = false;
175 if ( iconName ) {
176 GtkWidget *child = sp_icon_new( Inkscape::ICON_SIZE_SMALL_TOOLBAR, iconName );
177 gtk_widget_show( child );
178 btn.add( *manage(Glib::wrap(child)) );
179 set = true;
180 }
182 if ( desktop ) {
183 Verb *verb = Verb::get( code );
184 if ( verb ) {
185 SPAction *action = verb->get_action(desktop);
186 if ( !set && action && action->image ) {
187 GtkWidget *child = sp_icon_new( Inkscape::ICON_SIZE_SMALL_TOOLBAR, action->image );
188 gtk_widget_show( child );
189 btn.add( *manage(Glib::wrap(child)) );
190 set = true;
191 }
193 if ( action && action->tip ) {
194 _tips.set_tip( btn, action->tip );
195 }
196 }
197 }
199 if ( !set && fallback ) {
200 btn.set_label( fallback );
201 }
202 }
205 Gtk::MenuItem& LayersPanel::_addPopupItem( SPDesktop *desktop, unsigned int code, char const* iconName, char const* fallback, int id )
206 {
207 GtkWidget* iconWidget = 0;
208 const char* label = 0;
210 if ( iconName ) {
211 iconWidget = sp_icon_new( Inkscape::ICON_SIZE_MENU, iconName );
212 }
214 if ( desktop ) {
215 Verb *verb = Verb::get( code );
216 if ( verb ) {
217 SPAction *action = verb->get_action(desktop);
218 if ( !iconWidget && action && action->image ) {
219 iconWidget = sp_icon_new( Inkscape::ICON_SIZE_MENU, action->image );
220 }
222 if ( action ) {
223 label = action->name;
224 }
225 }
226 }
228 if ( !label && fallback ) {
229 label = fallback;
230 }
232 Gtk::Widget* wrapped = 0;
233 if ( iconWidget ) {
234 wrapped = manage(Glib::wrap(iconWidget));
235 wrapped->show();
236 }
240 Gtk::Menu::MenuList& menulist = _popupMenu.items();
242 if ( wrapped ) {
243 menulist.push_back( Gtk::Menu_Helpers::ImageMenuElem( label, *wrapped, sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), id)) );
244 } else {
245 menulist.push_back( Gtk::Menu_Helpers::MenuElem( label, sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), id)) );
246 }
247 return menulist.back();
248 }
250 void LayersPanel::_fireAction( unsigned int code )
251 {
252 if ( _desktop ) {
253 Verb *verb = Verb::get( code );
254 if ( verb ) {
255 SPAction *action = verb->get_action(_desktop);
256 if ( action ) {
257 sp_action_perform( action, NULL );
258 // } else {
259 // g_message("no action");
260 }
261 // } else {
262 // g_message("no verb for %u", code);
263 }
264 // } else {
265 // g_message("no active desktop");
266 }
267 }
269 // SP_VERB_LAYER_NEXT,
270 // SP_VERB_LAYER_PREV,
271 void LayersPanel::_takeAction( int val )
272 {
273 if ( !_pending ) {
274 _pending = new InternalUIBounce();
275 _pending->_actionCode = val;
276 _pending->_target = _selectedLayer();
277 Glib::signal_timeout().connect( sigc::mem_fun(*this, &LayersPanel::_executeAction), 0 );
278 }
279 }
281 bool LayersPanel::_executeAction()
282 {
283 // Make sure selected layer hasn't changed since the action was triggered
284 if ( _pending
285 && !( (_desktop && _desktop->currentLayer())
286 && (_desktop->currentLayer() != _pending->_target)
287 ) ) {
288 int val = _pending->_actionCode;
289 // SPObject* target = _pending->_target;
291 switch ( val ) {
292 case BUTTON_NEW:
293 {
294 _fireAction( SP_VERB_LAYER_NEW );
295 }
296 break;
297 case BUTTON_RENAME:
298 {
299 _fireAction( SP_VERB_LAYER_RENAME );
300 }
301 break;
302 case BUTTON_TOP:
303 {
304 _fireAction( SP_VERB_LAYER_TO_TOP );
305 }
306 break;
307 case BUTTON_BOTTOM:
308 {
309 _fireAction( SP_VERB_LAYER_TO_BOTTOM );
310 }
311 break;
312 case BUTTON_UP:
313 {
314 _fireAction( SP_VERB_LAYER_RAISE );
315 }
316 break;
317 case BUTTON_DOWN:
318 {
319 _fireAction( SP_VERB_LAYER_LOWER );
320 }
321 break;
322 case BUTTON_DELETE:
323 {
324 _fireAction( SP_VERB_LAYER_DELETE );
325 }
326 break;
327 }
329 delete _pending;
330 _pending = 0;
331 }
333 return false;
334 }
336 class LayersPanel::ModelColumns : public Gtk::TreeModel::ColumnRecord
337 {
338 public:
340 ModelColumns()
341 {
342 add(_colObject);
343 add(_colVisible);
344 add(_colLocked);
345 add(_colLabel);
346 }
347 virtual ~ModelColumns() {}
349 Gtk::TreeModelColumn<SPObject*> _colObject;
350 Gtk::TreeModelColumn<Glib::ustring> _colLabel;
351 Gtk::TreeModelColumn<bool> _colVisible;
352 Gtk::TreeModelColumn<bool> _colLocked;
353 };
355 void LayersPanel::_updateLayer( SPObject *layer ) {
356 _store->foreach( sigc::bind<SPObject*>(sigc::mem_fun(*this, &LayersPanel::_checkForUpdated), layer) );
357 }
359 bool LayersPanel::_checkForUpdated(const Gtk::TreePath &path, const Gtk::TreeIter& iter, SPObject* layer)
360 {
361 bool stopGoing = false;
362 Gtk::TreeModel::Row row = *iter;
363 Glib::ustring tmp = row[_model->_colLabel];
364 if ( layer == row[_model->_colObject] )
365 {
366 row[_model->_colLabel] = layer->label() ? layer->label() : SP_OBJECT_ID(layer);
367 row[_model->_colVisible] = SP_IS_ITEM(layer) ? !SP_ITEM(layer)->isHidden() : false;
368 row[_model->_colLocked] = SP_IS_ITEM(layer) ? SP_ITEM(layer)->isLocked() : false;
370 stopGoing = true;
371 }
373 return stopGoing;
374 }
376 void LayersPanel::_selectLayer( SPObject *layer ) {
377 if ( !layer || (_desktop && _desktop->doc() && (layer == _desktop->doc()->root)) ) {
378 if ( _tree.get_selection()->count_selected_rows() != 0 ) {
379 _tree.get_selection()->unselect_all();
380 }
381 } else {
382 _store->foreach( sigc::bind<SPObject*>(sigc::mem_fun(*this, &LayersPanel::_checkForSelected), layer) );
383 }
385 _checkTreeSelection();
386 }
388 bool LayersPanel::_checkForSelected(const Gtk::TreePath &path, const Gtk::TreeIter& iter, SPObject* layer)
389 {
390 bool stopGoing = false;
392 Gtk::TreeModel::Row row = *iter;
393 if ( layer == row[_model->_colObject] )
394 {
395 _tree.expand_to_path( path );
397 Glib::RefPtr<Gtk::TreeSelection> select = _tree.get_selection();
398 select->select(iter);
400 stopGoing = true;
401 }
403 return stopGoing;
404 }
406 void LayersPanel::_layersChanged()
407 {
408 // g_message("_layersChanged()");
409 SPDocument* document = _desktop->doc();
410 SPObject* root = document->root;
411 if ( root ) {
412 if ( _mgr && _mgr->includes( root ) ) {
413 SPObject* target = _desktop->currentLayer();
414 _store->clear();
416 #if DUMP_LAYERS
417 g_message("root:%p {%s} [%s]", root, root->id, root->label() );
418 #endif // DUMP_LAYERS
419 _addLayer( document, root, 0, target, 0 );
420 }
421 }
422 }
424 void LayersPanel::_addLayer( SPDocument* doc, SPObject* layer, Gtk::TreeModel::Row* parentRow, SPObject* target, int level )
425 {
426 if ( layer && (level < _maxNestDepth) ) {
427 unsigned int counter = _mgr->childCount(layer);
428 for ( unsigned int i = 0; i < counter; i++ ) {
429 SPObject *child = _mgr->nthChildOf(layer, i);
430 if ( child ) {
431 #if DUMP_LAYERS
432 g_message(" %3d layer:%p {%s} [%s]", level, child, child->id, child->label() );
433 #endif // DUMP_LAYERS
435 Gtk::TreeModel::iterator iter = parentRow ? _store->prepend(parentRow->children()) : _store->prepend();
436 Gtk::TreeModel::Row row = *iter;
437 row[_model->_colObject] = child;
438 row[_model->_colLabel] = child->label() ? child->label() : SP_OBJECT_ID(child);
439 row[_model->_colVisible] = SP_IS_ITEM(child) ? !SP_ITEM(child)->isHidden() : false;
440 row[_model->_colLocked] = SP_IS_ITEM(child) ? SP_ITEM(child)->isLocked() : false;
442 if ( target && child == target ) {
443 _tree.expand_to_path( _store->get_path(iter) );
445 Glib::RefPtr<Gtk::TreeSelection> select = _tree.get_selection();
446 select->select(iter);
447 _checkTreeSelection();
448 }
450 _addLayer( doc, child, &row, target, level + 1 );
451 }
452 }
453 }
454 }
456 SPObject* LayersPanel::_selectedLayer()
457 {
458 SPObject* obj = 0;
460 Gtk::TreeModel::iterator iter = _tree.get_selection()->get_selected();
461 if ( iter ) {
462 Gtk::TreeModel::Row row = *iter;
463 obj = row[_model->_colObject];
464 }
466 return obj;
467 }
469 void LayersPanel::_pushTreeSelectionToCurrent()
470 {
471 SPObject* inTree = _selectedLayer();
472 if ( inTree ) {
473 SPObject* curr = _desktop->currentLayer();
474 if ( curr != inTree ) {
475 // TODO - move these to a function in layer-manager.cpp
476 _desktop->setCurrentLayer( inTree );
477 sp_desktop_selection(_desktop)->clear();
478 }
479 } else {
480 // TODO - move these to a function in layer-manager.cpp
481 _desktop->setCurrentLayer( _desktop->doc()->root );
482 sp_desktop_selection(_desktop)->clear();
483 }
484 }
486 void LayersPanel::_checkTreeSelection()
487 {
488 bool sensitive = false;
489 bool sensitiveNonTop = false;
490 bool sensitiveNonBottom = false;
491 if ( _tree.get_selection()->count_selected_rows() > 0 ) {
492 sensitive = true;
494 SPObject* inTree = _selectedLayer();
495 if ( inTree ) {
497 sensitiveNonTop = (Inkscape::next_layer(inTree->parent, inTree) != 0);
498 sensitiveNonBottom = (Inkscape::previous_layer(inTree->parent, inTree) != 0);
499 }
500 }
502 for ( std::vector<Gtk::Widget*>::iterator it = _watching.begin(); it != _watching.end(); ++it ) {
503 (*it)->set_sensitive( sensitive );
504 }
505 for ( std::vector<Gtk::Widget*>::iterator it = _watchingNonTop.begin(); it != _watchingNonTop.end(); ++it ) {
506 (*it)->set_sensitive( sensitiveNonTop );
507 }
508 for ( std::vector<Gtk::Widget*>::iterator it = _watchingNonBottom.begin(); it != _watchingNonBottom.end(); ++it ) {
509 (*it)->set_sensitive( sensitiveNonBottom );
510 }
511 }
513 void LayersPanel::_toggled( Glib::ustring const& str, int targetCol )
514 {
515 Gtk::TreeModel::Children::iterator iter = _tree.get_model()->get_iter(str);
516 Gtk::TreeModel::Row row = *iter;
518 Glib::ustring tmp = row[_model->_colLabel];
520 SPObject* obj = row[_model->_colObject];
521 SPItem* item = ( obj && SP_IS_ITEM(obj) ) ? SP_ITEM(obj) : 0;
522 if ( item ) {
523 switch ( targetCol ) {
524 case COL_VISIBLE:
525 {
526 bool newValue = !row[_model->_colVisible];
527 row[_model->_colVisible] = newValue;
528 item->setHidden( !newValue );
529 item->updateRepr();
530 sp_document_done( _desktop->doc() );
531 }
532 break;
534 case COL_LOCKED:
535 {
536 bool newValue = !row[_model->_colLocked];
537 row[_model->_colLocked] = newValue;
538 item->setLocked( newValue );
539 item->updateRepr();
540 sp_document_done( _desktop->doc() );
541 }
542 break;
543 }
544 }
545 }
547 void LayersPanel::_handleButtonEvent(GdkEventButton* evt)
548 {
549 if ( (evt->type == GDK_BUTTON_PRESS) && (evt->button == 3) ) {
552 {
553 Gtk::TreeModel::Path path;
554 Gtk::TreeViewColumn* col = 0;
555 int x = static_cast<int>(evt->x);
556 int y = static_cast<int>(evt->y);
557 int x2 = 0;
558 int y2 = 0;
559 if ( _tree.get_path_at_pos( x, y,
560 path, col,
561 x2, y2 ) ) {
562 _checkTreeSelection();
563 _popupMenu.popup(evt->button, evt->time);
564 }
565 }
567 }
568 }
570 void LayersPanel::_handleRowChange( Gtk::TreeModel::Path const& path, Gtk::TreeModel::iterator const& iter )
571 {
572 Gtk::TreeModel::Row row = *iter;
573 if ( row ) {
574 SPObject* obj = row[_model->_colObject];
575 if ( obj ) {
576 gchar const* oldLabel = obj->label();
577 Glib::ustring tmp = row[_model->_colLabel];
578 if ( oldLabel && oldLabel[0] && !tmp.empty() && (tmp != oldLabel) ) {
579 _mgr->renameLayer( obj, tmp.c_str() );
580 row[_model->_colLabel] = obj->label();
581 }
582 }
583 }
584 }
586 /**
587 * Constructor
588 */
589 LayersPanel::LayersPanel() :
590 Inkscape::UI::Widget::Panel( Glib::ustring(), "dialogs.layers" ),
591 _maxNestDepth(20),
592 _mgr(0),
593 _desktop(0),
594 _model(0),
595 _pending(0)
596 {
597 _maxNestDepth = prefs_get_int_attribute_limited("dialogs.layers", "maxDepth", 20, 1, 1000);
599 ModelColumns *zoop = new ModelColumns();
600 _model = zoop;
602 _store = Gtk::TreeStore::create( *zoop );
604 _tree.set_model( _store );
605 _tree.set_headers_visible(false);
607 ImageToggler* eyeRenderer = manage( new ImageToggler("visible", "hidden") );
608 int visibleColNum = _tree.append_column("vis", *eyeRenderer) - 1;
609 eyeRenderer->signal_toggled().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_toggled), (int)COL_VISIBLE) );
610 eyeRenderer->property_activatable() = true;
611 Gtk::TreeViewColumn* col = _tree.get_column(visibleColNum);
612 if ( col ) {
613 col->add_attribute( eyeRenderer->property_active(), _model->_colVisible );
614 }
616 ImageToggler * renderer = manage( new ImageToggler("width_height_lock", "lock_unlocked") );
617 int lockedColNum = _tree.append_column("lock", *renderer) - 1;
618 renderer->signal_toggled().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_toggled), (int)COL_LOCKED) );
619 renderer->property_activatable() = true;
620 col = _tree.get_column(lockedColNum);
621 if ( col ) {
622 col->add_attribute( renderer->property_active(), _model->_colLocked );
623 }
625 int nameColNum = _tree.append_column_editable("Name", _model->_colLabel) - 1;
627 _tree.set_expander_column( *_tree.get_column(nameColNum) );
630 _tree.get_selection()->signal_changed().connect( sigc::mem_fun(*this, &LayersPanel::_pushTreeSelectionToCurrent) );
632 _tree.get_model()->signal_row_changed().connect( sigc::mem_fun(*this, &LayersPanel::_handleRowChange) );
633 _tree.signal_button_press_event().connect_notify( sigc::mem_fun(*this, &LayersPanel::_handleButtonEvent) );
635 _scroller.add( _tree );
636 _scroller.set_policy( Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC );
637 _getContents()->pack_start( _scroller, Gtk::PACK_EXPAND_WIDGET );
638 _getContents()->pack_end(_buttonsRow, Gtk::PACK_SHRINK);
640 SPDesktop* targetDesktop = SP_ACTIVE_DESKTOP;
642 Gtk::Button* btn = manage( new Gtk::Button() );
643 _styleButton( *btn, targetDesktop, SP_VERB_LAYER_NEW, GTK_STOCK_ADD, "Ne" );
644 btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_NEW) );
645 _buttonsRow.pack_start( *btn );
647 btn = manage( new Gtk::Button() );
648 _styleButton( *btn, targetDesktop, SP_VERB_LAYER_TO_TOP, GTK_STOCK_GOTO_TOP, "Top" );
649 btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_TOP) );
650 _watchingNonTop.push_back( btn );
651 _buttonsRow.pack_start( *btn );
653 btn = manage( new Gtk::Button() );
654 _styleButton( *btn, targetDesktop, SP_VERB_LAYER_RAISE, GTK_STOCK_GO_UP, "Up" );
655 btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_UP) );
656 _watchingNonTop.push_back( btn );
657 _buttonsRow.pack_start( *btn );
659 btn = manage( new Gtk::Button() );
660 _styleButton( *btn, targetDesktop, SP_VERB_LAYER_LOWER, GTK_STOCK_GO_DOWN, "Dn" );
661 btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_DOWN) );
662 _watchingNonBottom.push_back( btn );
663 _buttonsRow.pack_start( *btn );
665 btn = manage( new Gtk::Button() );
666 _styleButton( *btn, targetDesktop, SP_VERB_LAYER_TO_BOTTOM, GTK_STOCK_GOTO_BOTTOM, "Btm" );
667 btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_BOTTOM) );
668 _watchingNonBottom.push_back( btn );
669 _buttonsRow.pack_start( *btn );
671 // btn = manage( new Gtk::Button("Dup") );
672 // btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_DUPLICATE) );
673 // _buttonsRow.pack_start( *btn );
675 btn = manage( new Gtk::Button() );
676 _styleButton( *btn, targetDesktop, SP_VERB_LAYER_DELETE, GTK_STOCK_REMOVE, "X" );
677 btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_DELETE) );
678 _watching.push_back( btn );
679 _buttonsRow.pack_start( *btn );
684 // -------------------------------------------------------
685 {
686 _watching.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_RENAME, 0, "Rename", (int)BUTTON_RENAME ) );
687 _watching.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_NEW, 0, "New", (int)BUTTON_NEW ) );
689 _popupMenu.items().push_back( Gtk::Menu_Helpers::SeparatorElem() );
691 _watchingNonTop.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_RAISE, GTK_STOCK_GO_UP, "Up", (int)BUTTON_UP ) );
692 _watchingNonBottom.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_LOWER, GTK_STOCK_GO_DOWN, "Down", (int)BUTTON_DOWN ) );
694 _popupMenu.show_all_children();
695 }
696 // -------------------------------------------------------
700 for ( std::vector<Gtk::Widget*>::iterator it = _watching.begin(); it != _watching.end(); ++it ) {
701 (*it)->set_sensitive( false );
702 }
703 for ( std::vector<Gtk::Widget*>::iterator it = _watchingNonTop.begin(); it != _watchingNonTop.end(); ++it ) {
704 (*it)->set_sensitive( false );
705 }
706 for ( std::vector<Gtk::Widget*>::iterator it = _watchingNonBottom.begin(); it != _watchingNonBottom.end(); ++it ) {
707 (*it)->set_sensitive( false );
708 }
710 g_signal_connect( G_OBJECT(INKSCAPE), "activate_desktop", G_CALLBACK( layers_panel_activated ), this );
713 setDesktop( targetDesktop );
717 show_all_children();
719 restorePanelPrefs();
720 }
722 LayersPanel::~LayersPanel()
723 {
724 if ( _model )
725 {
726 delete _model;
727 }
728 }
731 void LayersPanel::setDesktop( SPDesktop* desktop )
732 {
733 if ( desktop != _desktop ) {
734 _layerChangedConnection.disconnect();
735 _layerUpdatedConnection.disconnect();
736 _changedConnection.disconnect();
737 if ( _mgr ) {
738 _mgr = 0;
739 }
740 if ( _desktop ) {
741 _desktop = 0;
742 }
744 _desktop = SP_ACTIVE_DESKTOP;
745 if ( _desktop ) {
746 setLabel( _desktop->doc()->name );
748 _mgr = _desktop->layer_manager;
749 if ( _mgr ) {
750 _layerChangedConnection = _mgr->connectCurrentLayerChanged( sigc::mem_fun(*this, &LayersPanel::_selectLayer) );
751 _layerUpdatedConnection = _mgr->connectLayerDetailsChanged( sigc::mem_fun(*this, &LayersPanel::_updateLayer) );
752 _changedConnection = _mgr->connectChanged( sigc::mem_fun(*this, &LayersPanel::_layersChanged) );
753 }
755 _layersChanged();
756 }
757 }
758 /*
759 GSList const *layers=sp_document_get_resource_list( _desktop->doc(), "layer" );
760 g_message( "layers list starts at %p", layers );
761 for ( GSList const *iter=layers ; iter ; iter = iter->next ) {
762 SPObject *layer=static_cast<SPObject *>(iter->data);
763 g_message(" {%s} [%s]", layer->id, layer->label() );
764 }
765 */
766 }
770 } //namespace Dialogs
771 } //namespace UI
772 } //namespace Inkscape
775 /*
776 Local Variables:
777 mode:c++
778 c-file-style:"stroustrup"
779 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
780 indent-tabs-mode:nil
781 fill-column:99
782 End:
783 */
784 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :