1 /*
2 * A simple panel for layers
3 *
4 * Authors:
5 * Jon A. Cruz
6 *
7 * Copyright (C) 2006,2010 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>
16 #include <gtk/gtkmain.h>
17 #include <gtkmm/widget.h>
18 #include <gtkmm/icontheme.h>
19 #include <glibmm/i18n.h>
21 #include "desktop.h"
22 #include "desktop-style.h"
23 #include "document.h"
24 #include "helper/action.h"
25 #include "inkscape.h"
26 #include "layer-fns.h"
27 #include "layer-manager.h"
28 #include "preferences.h"
29 #include "sp-item.h"
30 #include "sp-object.h"
31 #include "svg/css-ostringstream.h"
32 #include "ui/icon-names.h"
33 #include "ui/widget/imagetoggler.h"
34 #include "verbs.h"
35 #include "widgets/icon.h"
36 #include "xml/repr.h"
38 #include "layers.h"
40 //#define DUMP_LAYERS 1
42 namespace Inkscape {
43 namespace UI {
44 namespace Dialog {
46 LayersPanel& LayersPanel::getInstance()
47 {
48 return *new LayersPanel();
49 }
51 enum {
52 COL_VISIBLE = 1,
53 COL_LOCKED
54 };
56 enum {
57 BUTTON_NEW = 0,
58 BUTTON_RENAME,
59 BUTTON_TOP,
60 BUTTON_BOTTOM,
61 BUTTON_UP,
62 BUTTON_DOWN,
63 BUTTON_DUPLICATE,
64 BUTTON_DELETE,
65 BUTTON_SOLO
66 };
68 class LayersPanel::InternalUIBounce
69 {
70 public:
71 int _actionCode;
72 SPObject* _target;
73 };
75 void LayersPanel::_styleButton( Gtk::Button& btn, SPDesktop *desktop, unsigned int code, char const* iconName, char const* fallback )
76 {
77 bool set = false;
79 if ( iconName ) {
80 GtkWidget *child = sp_icon_new( Inkscape::ICON_SIZE_SMALL_TOOLBAR, iconName );
81 gtk_widget_show( child );
82 btn.add( *manage(Glib::wrap(child)) );
83 set = true;
84 }
86 if ( desktop ) {
87 Verb *verb = Verb::get( code );
88 if ( verb ) {
89 SPAction *action = verb->get_action(desktop);
90 if ( !set && action && action->image ) {
91 GtkWidget *child = sp_icon_new( Inkscape::ICON_SIZE_SMALL_TOOLBAR, action->image );
92 gtk_widget_show( child );
93 btn.add( *manage(Glib::wrap(child)) );
94 set = true;
95 }
97 if ( action && action->tip ) {
98 _tips.set_tip( btn, action->tip );
99 }
100 }
101 }
103 if ( !set && fallback ) {
104 btn.set_label( fallback );
105 }
106 }
109 Gtk::MenuItem& LayersPanel::_addPopupItem( SPDesktop *desktop, unsigned int code, char const* iconName, char const* fallback, int id )
110 {
111 GtkWidget* iconWidget = 0;
112 const char* label = 0;
114 if ( iconName ) {
115 iconWidget = sp_icon_new( Inkscape::ICON_SIZE_MENU, iconName );
116 }
118 if ( desktop ) {
119 Verb *verb = Verb::get( code );
120 if ( verb ) {
121 SPAction *action = verb->get_action(desktop);
122 if ( !iconWidget && action && action->image ) {
123 iconWidget = sp_icon_new( Inkscape::ICON_SIZE_MENU, action->image );
124 }
126 if ( action ) {
127 label = action->name;
128 }
129 }
130 }
132 if ( !label && fallback ) {
133 label = fallback;
134 }
136 Gtk::Widget* wrapped = 0;
137 if ( iconWidget ) {
138 wrapped = manage(Glib::wrap(iconWidget));
139 wrapped->show();
140 }
144 Gtk::Menu::MenuList& menulist = _popupMenu.items();
146 if ( wrapped ) {
147 menulist.push_back( Gtk::Menu_Helpers::ImageMenuElem( label, *wrapped, sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), id)) );
148 } else {
149 menulist.push_back( Gtk::Menu_Helpers::MenuElem( label, sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), id)) );
150 }
151 return menulist.back();
152 }
154 void LayersPanel::_fireAction( unsigned int code )
155 {
156 if ( _desktop ) {
157 Verb *verb = Verb::get( code );
158 if ( verb ) {
159 SPAction *action = verb->get_action(_desktop);
160 if ( action ) {
161 sp_action_perform( action, NULL );
162 // } else {
163 // g_message("no action");
164 }
165 // } else {
166 // g_message("no verb for %u", code);
167 }
168 // } else {
169 // g_message("no active desktop");
170 }
171 }
173 // SP_VERB_LAYER_NEXT,
174 // SP_VERB_LAYER_PREV,
175 void LayersPanel::_takeAction( int val )
176 {
177 if ( !_pending ) {
178 _pending = new InternalUIBounce();
179 _pending->_actionCode = val;
180 _pending->_target = _selectedLayer();
181 Glib::signal_timeout().connect( sigc::mem_fun(*this, &LayersPanel::_executeAction), 0 );
182 }
183 }
185 bool LayersPanel::_executeAction()
186 {
187 // Make sure selected layer hasn't changed since the action was triggered
188 if ( _pending
189 && (
190 (_pending->_actionCode == BUTTON_NEW)
191 || !( (_desktop && _desktop->currentLayer())
192 && (_desktop->currentLayer() != _pending->_target)
193 )
194 )
195 ) {
196 int val = _pending->_actionCode;
197 // SPObject* target = _pending->_target;
199 switch ( val ) {
200 case BUTTON_NEW:
201 {
202 _fireAction( SP_VERB_LAYER_NEW );
203 }
204 break;
205 case BUTTON_RENAME:
206 {
207 _fireAction( SP_VERB_LAYER_RENAME );
208 }
209 break;
210 case BUTTON_TOP:
211 {
212 _fireAction( SP_VERB_LAYER_TO_TOP );
213 }
214 break;
215 case BUTTON_BOTTOM:
216 {
217 _fireAction( SP_VERB_LAYER_TO_BOTTOM );
218 }
219 break;
220 case BUTTON_UP:
221 {
222 _fireAction( SP_VERB_LAYER_RAISE );
223 }
224 break;
225 case BUTTON_DOWN:
226 {
227 _fireAction( SP_VERB_LAYER_LOWER );
228 }
229 break;
230 case BUTTON_DUPLICATE:
231 {
232 _fireAction( SP_VERB_LAYER_DUPLICATE );
233 }
234 break;
235 case BUTTON_DELETE:
236 {
237 _fireAction( SP_VERB_LAYER_DELETE );
238 }
239 break;
240 case BUTTON_SOLO:
241 {
242 _fireAction( SP_VERB_LAYER_SOLO );
243 }
244 break;
245 }
247 delete _pending;
248 _pending = 0;
249 }
251 return false;
252 }
254 class LayersPanel::ModelColumns : public Gtk::TreeModel::ColumnRecord
255 {
256 public:
258 ModelColumns()
259 {
260 add(_colObject);
261 add(_colVisible);
262 add(_colLocked);
263 add(_colLabel);
264 }
265 virtual ~ModelColumns() {}
267 Gtk::TreeModelColumn<SPObject*> _colObject;
268 Gtk::TreeModelColumn<Glib::ustring> _colLabel;
269 Gtk::TreeModelColumn<bool> _colVisible;
270 Gtk::TreeModelColumn<bool> _colLocked;
271 };
273 void LayersPanel::_updateLayer( SPObject *layer ) {
274 _store->foreach( sigc::bind<SPObject*>(sigc::mem_fun(*this, &LayersPanel::_checkForUpdated), layer) );
275 }
277 bool LayersPanel::_checkForUpdated(const Gtk::TreePath &/*path*/, const Gtk::TreeIter& iter, SPObject* layer)
278 {
279 bool stopGoing = false;
280 Gtk::TreeModel::Row row = *iter;
281 Glib::ustring tmp = row[_model->_colLabel];
282 if ( layer == row[_model->_colObject] )
283 {
284 row[_model->_colLabel] = layer->label() ? layer->label() : layer->getId();
285 row[_model->_colVisible] = SP_IS_ITEM(layer) ? !SP_ITEM(layer)->isHidden() : false;
286 row[_model->_colLocked] = SP_IS_ITEM(layer) ? SP_ITEM(layer)->isLocked() : false;
288 stopGoing = true;
289 }
291 return stopGoing;
292 }
294 void LayersPanel::_selectLayer( SPObject *layer ) {
295 if ( !layer || (_desktop && _desktop->doc() && (layer == _desktop->doc()->root)) ) {
296 if ( _tree.get_selection()->count_selected_rows() != 0 ) {
297 _tree.get_selection()->unselect_all();
298 }
299 } else {
300 _store->foreach( sigc::bind<SPObject*>(sigc::mem_fun(*this, &LayersPanel::_checkForSelected), layer) );
301 }
303 _checkTreeSelection();
304 }
306 bool LayersPanel::_checkForSelected(const Gtk::TreePath &path, const Gtk::TreeIter& iter, SPObject* layer)
307 {
308 bool stopGoing = false;
310 Gtk::TreeModel::Row row = *iter;
311 if ( layer == row[_model->_colObject] )
312 {
313 _tree.expand_to_path( path );
315 Glib::RefPtr<Gtk::TreeSelection> select = _tree.get_selection();
317 select->select(iter);
319 stopGoing = true;
320 }
322 return stopGoing;
323 }
325 void LayersPanel::_layersChanged()
326 {
327 // g_message("_layersChanged()");
328 if (_desktop) {
329 SPDocument* document = _desktop->doc();
330 SPObject* root = document->root;
331 if ( root ) {
332 _selectedConnection.block();
333 if ( _desktop->layer_manager && _desktop->layer_manager->includes( root ) ) {
334 SPObject* target = _desktop->currentLayer();
335 _store->clear();
337 #if DUMP_LAYERS
338 g_message("root:%p {%s} [%s]", root, root->id, root->label() );
339 #endif // DUMP_LAYERS
340 _addLayer( document, root, 0, target, 0 );
341 }
342 _selectedConnection.unblock();
343 }
344 }
345 }
347 void LayersPanel::_addLayer( SPDocument* doc, SPObject* layer, Gtk::TreeModel::Row* parentRow, SPObject* target, int level )
348 {
349 if ( _desktop && _desktop->layer_manager && layer && (level < _maxNestDepth) ) {
350 unsigned int counter = _desktop->layer_manager->childCount(layer);
351 for ( unsigned int i = 0; i < counter; i++ ) {
352 SPObject *child = _desktop->layer_manager->nthChildOf(layer, i);
353 if ( child ) {
354 #if DUMP_LAYERS
355 g_message(" %3d layer:%p {%s} [%s]", level, child, child->id, child->label() );
356 #endif // DUMP_LAYERS
358 Gtk::TreeModel::iterator iter = parentRow ? _store->prepend(parentRow->children()) : _store->prepend();
359 Gtk::TreeModel::Row row = *iter;
360 row[_model->_colObject] = child;
361 row[_model->_colLabel] = child->label() ? child->label() : child->getId();
362 row[_model->_colVisible] = SP_IS_ITEM(child) ? !SP_ITEM(child)->isHidden() : false;
363 row[_model->_colLocked] = SP_IS_ITEM(child) ? SP_ITEM(child)->isLocked() : false;
365 if ( target && child == target ) {
366 _tree.expand_to_path( _store->get_path(iter) );
368 Glib::RefPtr<Gtk::TreeSelection> select = _tree.get_selection();
369 select->select(iter);
371 _checkTreeSelection();
372 }
374 _addLayer( doc, child, &row, target, level + 1 );
375 }
376 }
377 }
378 }
380 SPObject* LayersPanel::_selectedLayer()
381 {
382 SPObject* obj = 0;
384 Gtk::TreeModel::iterator iter = _tree.get_selection()->get_selected();
385 if ( iter ) {
386 Gtk::TreeModel::Row row = *iter;
387 obj = row[_model->_colObject];
388 }
390 return obj;
391 }
393 void LayersPanel::_pushTreeSelectionToCurrent()
394 {
395 // TODO hunt down the possible API abuse in getting NULL
396 if ( _desktop && _desktop->layer_manager && _desktop->currentRoot() ) {
397 SPObject* inTree = _selectedLayer();
398 if ( inTree ) {
399 SPObject* curr = _desktop->currentLayer();
400 if ( curr != inTree ) {
401 _desktop->layer_manager->setCurrentLayer( inTree );
402 }
403 } else {
404 _desktop->layer_manager->setCurrentLayer( _desktop->doc()->root );
405 }
406 }
407 }
409 void LayersPanel::_checkTreeSelection()
410 {
411 bool sensitive = false;
412 bool sensitiveNonTop = false;
413 bool sensitiveNonBottom = false;
414 if ( _tree.get_selection()->count_selected_rows() > 0 ) {
415 sensitive = true;
417 SPObject* inTree = _selectedLayer();
418 if ( inTree ) {
420 sensitiveNonTop = (Inkscape::next_layer(inTree->parent, inTree) != 0);
421 sensitiveNonBottom = (Inkscape::previous_layer(inTree->parent, inTree) != 0);
423 }
424 }
427 for ( std::vector<Gtk::Widget*>::iterator it = _watching.begin(); it != _watching.end(); ++it ) {
428 (*it)->set_sensitive( sensitive );
429 }
430 for ( std::vector<Gtk::Widget*>::iterator it = _watchingNonTop.begin(); it != _watchingNonTop.end(); ++it ) {
431 (*it)->set_sensitive( sensitiveNonTop );
432 }
433 for ( std::vector<Gtk::Widget*>::iterator it = _watchingNonBottom.begin(); it != _watchingNonBottom.end(); ++it ) {
434 (*it)->set_sensitive( sensitiveNonBottom );
435 }
436 }
438 void LayersPanel::_preToggle( GdkEvent const *event )
439 {
441 if ( _toggleEvent ) {
442 gdk_event_free(_toggleEvent);
443 _toggleEvent = 0;
444 }
446 if ( event && (event->type == GDK_BUTTON_PRESS) ) {
447 // Make a copy so we can keep it around.
448 _toggleEvent = gdk_event_copy(const_cast<GdkEvent*>(event));
449 }
450 }
452 void LayersPanel::_toggled( Glib::ustring const& str, int targetCol )
453 {
454 g_return_if_fail(_desktop != NULL);
456 Gtk::TreeModel::Children::iterator iter = _tree.get_model()->get_iter(str);
457 Gtk::TreeModel::Row row = *iter;
459 Glib::ustring tmp = row[_model->_colLabel];
461 SPObject* obj = row[_model->_colObject];
462 SPItem* item = ( obj && SP_IS_ITEM(obj) ) ? SP_ITEM(obj) : 0;
463 if ( item ) {
464 switch ( targetCol ) {
465 case COL_VISIBLE:
466 {
467 bool newValue = !row[_model->_colVisible];
468 row[_model->_colVisible] = newValue;
469 item->setHidden( !newValue );
470 item->updateRepr();
471 sp_document_done( _desktop->doc() , SP_VERB_DIALOG_LAYERS,
472 newValue? _("Unhide layer") : _("Hide layer"));
473 }
474 break;
476 case COL_LOCKED:
477 {
478 bool newValue = !row[_model->_colLocked];
479 row[_model->_colLocked] = newValue;
480 item->setLocked( newValue );
481 item->updateRepr();
482 sp_document_done( _desktop->doc() , SP_VERB_DIALOG_LAYERS,
483 newValue? _("Lock layer") : _("Unlock layer"));
484 }
485 break;
486 }
487 }
488 }
490 void LayersPanel::_handleButtonEvent(GdkEventButton* evt)
491 {
492 // TODO - fix to a better is-popup function
493 if ( (evt->type == GDK_BUTTON_PRESS) && (evt->button == 3) ) {
496 {
497 Gtk::TreeModel::Path path;
498 Gtk::TreeViewColumn* col = 0;
499 int x = static_cast<int>(evt->x);
500 int y = static_cast<int>(evt->y);
501 int x2 = 0;
502 int y2 = 0;
503 if ( _tree.get_path_at_pos( x, y,
504 path, col,
505 x2, y2 ) ) {
506 _checkTreeSelection();
507 _popupMenu.popup(evt->button, evt->time);
508 }
509 }
511 }
512 }
514 void LayersPanel::_handleRowChange( Gtk::TreeModel::Path const& /*path*/, Gtk::TreeModel::iterator const& iter )
515 {
516 Gtk::TreeModel::Row row = *iter;
517 if ( row && _desktop && _desktop->layer_manager) {
518 SPObject* obj = row[_model->_colObject];
519 if ( obj ) {
520 gchar const* oldLabel = obj->label();
521 Glib::ustring tmp = row[_model->_colLabel];
522 if ( oldLabel && oldLabel[0] && !tmp.empty() && (tmp != oldLabel) ) {
523 _desktop->layer_manager->renameLayer( obj, tmp.c_str(), FALSE );
524 row[_model->_colLabel] = obj->label();
525 }
526 }
527 }
528 }
530 bool LayersPanel::_rowSelectFunction( Glib::RefPtr<Gtk::TreeModel> const & /*model*/, Gtk::TreeModel::Path const & /*path*/, bool currentlySelected )
531 {
532 bool val = true;
533 if ( !currentlySelected && _toggleEvent )
534 {
535 GdkEvent* event = gtk_get_current_event();
536 if ( event ) {
537 // (keep these checks separate, so we know when to call gdk_event_free()
538 if ( event->type == GDK_BUTTON_PRESS ) {
539 GdkEventButton const* target = reinterpret_cast<GdkEventButton const*>(_toggleEvent);
540 GdkEventButton const* evtb = reinterpret_cast<GdkEventButton const*>(event);
542 if ( (evtb->window == target->window)
543 && (evtb->send_event == target->send_event)
544 && (evtb->time == target->time)
545 && (evtb->state == target->state)
546 )
547 {
548 // Ooooh! It's a magic one
549 val = false;
550 }
551 }
552 gdk_event_free(event);
553 }
554 }
555 return val;
556 }
558 /**
559 * Constructor
560 */
561 LayersPanel::LayersPanel() :
562 UI::Widget::Panel("", "/dialogs/layers", SP_VERB_DIALOG_LAYERS),
563 deskTrack(),
564 _maxNestDepth(20),
565 _desktop(0),
566 _model(0),
567 _pending(0),
568 _toggleEvent(0),
569 _compositeSettings(SP_VERB_DIALOG_LAYERS, "layers", UI::Widget::SimpleFilterModifier::BLEND),
570 desktopChangeConn()
571 {
572 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
573 _maxNestDepth = prefs->getIntLimited("/dialogs/layers/maxDepth", 20, 1, 1000);
575 ModelColumns *zoop = new ModelColumns();
576 _model = zoop;
578 _store = Gtk::TreeStore::create( *zoop );
580 _tree.set_model( _store );
581 _tree.set_headers_visible(false);
583 Inkscape::UI::Widget::ImageToggler *eyeRenderer = manage( new Inkscape::UI::Widget::ImageToggler(
584 INKSCAPE_ICON_OBJECT_VISIBLE, INKSCAPE_ICON_OBJECT_HIDDEN) );
585 int visibleColNum = _tree.append_column("vis", *eyeRenderer) - 1;
586 eyeRenderer->signal_pre_toggle().connect( sigc::mem_fun(*this, &LayersPanel::_preToggle) );
587 eyeRenderer->signal_toggled().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_toggled), (int)COL_VISIBLE) );
588 eyeRenderer->property_activatable() = true;
589 Gtk::TreeViewColumn* col = _tree.get_column(visibleColNum);
590 if ( col ) {
591 col->add_attribute( eyeRenderer->property_active(), _model->_colVisible );
592 }
594 Inkscape::UI::Widget::ImageToggler * renderer = manage( new Inkscape::UI::Widget::ImageToggler(
595 INKSCAPE_ICON_OBJECT_LOCKED, INKSCAPE_ICON_OBJECT_UNLOCKED) );
596 int lockedColNum = _tree.append_column("lock", *renderer) - 1;
597 renderer->signal_pre_toggle().connect( sigc::mem_fun(*this, &LayersPanel::_preToggle) );
598 renderer->signal_toggled().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_toggled), (int)COL_LOCKED) );
599 renderer->property_activatable() = true;
600 col = _tree.get_column(lockedColNum);
601 if ( col ) {
602 col->add_attribute( renderer->property_active(), _model->_colLocked );
603 }
605 int nameColNum = _tree.append_column_editable("Name", _model->_colLabel) - 1;
607 _tree.set_expander_column( *_tree.get_column(nameColNum) );
609 _compositeSettings.setSubject(&_subject);
611 _selectedConnection = _tree.get_selection()->signal_changed().connect( sigc::mem_fun(*this, &LayersPanel::_pushTreeSelectionToCurrent) );
612 _tree.get_selection()->set_select_function( sigc::mem_fun(*this, &LayersPanel::_rowSelectFunction) );
614 _tree.get_model()->signal_row_changed().connect( sigc::mem_fun(*this, &LayersPanel::_handleRowChange) );
615 _tree.signal_button_press_event().connect_notify( sigc::mem_fun(*this, &LayersPanel::_handleButtonEvent) );
617 _scroller.add( _tree );
618 _scroller.set_policy( Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC );
619 _scroller.set_shadow_type(Gtk::SHADOW_IN);
621 _watching.push_back( &_compositeSettings );
623 _layersPage.pack_start( _scroller, Gtk::PACK_EXPAND_WIDGET );
624 _layersPage.pack_end(_compositeSettings, Gtk::PACK_SHRINK);
625 _layersPage.pack_end(_buttonsRow, Gtk::PACK_SHRINK);
627 _getContents()->pack_start(_layersPage, Gtk::PACK_EXPAND_WIDGET);
629 SPDesktop* targetDesktop = getDesktop();
631 _buttonsRow.set_child_min_width( 16 );
633 Gtk::Button* btn = manage( new Gtk::Button() );
634 _styleButton( *btn, targetDesktop, SP_VERB_LAYER_NEW, GTK_STOCK_ADD, C_("Layers", "New") );
635 btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_NEW) );
636 _buttonsRow.add( *btn );
638 btn = manage( new Gtk::Button() );
639 _styleButton( *btn, targetDesktop, SP_VERB_LAYER_TO_TOP, GTK_STOCK_GOTO_TOP, C_("Layers", "Top") );
640 btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_TOP) );
641 _watchingNonTop.push_back( btn );
642 _buttonsRow.add( *btn );
644 btn = manage( new Gtk::Button() );
645 _styleButton( *btn, targetDesktop, SP_VERB_LAYER_RAISE, GTK_STOCK_GO_UP, C_("Layers", "Up") );
646 btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_UP) );
647 _watchingNonTop.push_back( btn );
648 _buttonsRow.add( *btn );
650 btn = manage( new Gtk::Button() );
651 _styleButton( *btn, targetDesktop, SP_VERB_LAYER_LOWER, GTK_STOCK_GO_DOWN, C_("Layers", "Dn") );
652 btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_DOWN) );
653 _watchingNonBottom.push_back( btn );
654 _buttonsRow.add( *btn );
656 btn = manage( new Gtk::Button() );
657 _styleButton( *btn, targetDesktop, SP_VERB_LAYER_TO_BOTTOM, GTK_STOCK_GOTO_BOTTOM, C_("Layers", "Bot") );
658 btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_BOTTOM) );
659 _watchingNonBottom.push_back( btn );
660 _buttonsRow.add( *btn );
662 // btn = manage( new Gtk::Button("Dup") );
663 // btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_DUPLICATE) );
664 // _buttonsRow.add( *btn );
666 btn = manage( new Gtk::Button() );
667 _styleButton( *btn, targetDesktop, SP_VERB_LAYER_DELETE, GTK_STOCK_REMOVE, _("X") );
668 btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_DELETE) );
669 _watching.push_back( btn );
670 _buttonsRow.add( *btn );
675 // -------------------------------------------------------
676 {
677 _watching.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_RENAME, 0, "Rename", (int)BUTTON_RENAME ) );
678 _watching.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_DUPLICATE, 0, "Duplicate", (int)BUTTON_DUPLICATE ) );
679 _watching.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_NEW, 0, "New", (int)BUTTON_NEW ) );
680 _watching.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_SOLO, 0, "Solo", (int)BUTTON_SOLO ) );
682 _popupMenu.items().push_back( Gtk::Menu_Helpers::SeparatorElem() );
684 _watchingNonTop.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_RAISE, GTK_STOCK_GO_UP, "Up", (int)BUTTON_UP ) );
685 _watchingNonBottom.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_LOWER, GTK_STOCK_GO_DOWN, "Down", (int)BUTTON_DOWN ) );
687 _popupMenu.show_all_children();
688 }
689 // -------------------------------------------------------
693 for ( std::vector<Gtk::Widget*>::iterator it = _watching.begin(); it != _watching.end(); ++it ) {
694 (*it)->set_sensitive( false );
695 }
696 for ( std::vector<Gtk::Widget*>::iterator it = _watchingNonTop.begin(); it != _watchingNonTop.end(); ++it ) {
697 (*it)->set_sensitive( false );
698 }
699 for ( std::vector<Gtk::Widget*>::iterator it = _watchingNonBottom.begin(); it != _watchingNonBottom.end(); ++it ) {
700 (*it)->set_sensitive( false );
701 }
703 setDesktop( targetDesktop );
705 show_all_children();
707 // restorePanelPrefs();
709 // Connect this up last
710 desktopChangeConn = deskTrack.connectDesktopChanged( sigc::mem_fun(*this, &LayersPanel::setDesktop) );
711 deskTrack.connect(GTK_WIDGET(gobj()));
712 }
714 LayersPanel::~LayersPanel()
715 {
716 setDesktop(NULL);
718 _compositeSettings.setSubject(NULL);
720 if ( _model )
721 {
722 delete _model;
723 _model = 0;
724 }
726 if (_pending) {
727 delete _pending;
728 _pending = 0;
729 }
731 if ( _toggleEvent )
732 {
733 gdk_event_free( _toggleEvent );
734 _toggleEvent = 0;
735 }
737 desktopChangeConn.disconnect();
738 deskTrack.disconnect();
739 }
742 void LayersPanel::setDesktop( SPDesktop* desktop )
743 {
744 Panel::setDesktop(desktop);
746 if ( desktop != _desktop ) {
747 _layerChangedConnection.disconnect();
748 _layerUpdatedConnection.disconnect();
749 _changedConnection.disconnect();
750 if ( _desktop ) {
751 _desktop = 0;
752 }
754 _desktop = Panel::getDesktop();
755 if ( _desktop ) {
756 //setLabel( _desktop->doc()->name );
758 LayerManager *mgr = _desktop->layer_manager;
759 if ( mgr ) {
760 _layerChangedConnection = mgr->connectCurrentLayerChanged( sigc::mem_fun(*this, &LayersPanel::_selectLayer) );
761 _layerUpdatedConnection = mgr->connectLayerDetailsChanged( sigc::mem_fun(*this, &LayersPanel::_updateLayer) );
762 _changedConnection = mgr->connectChanged( sigc::mem_fun(*this, &LayersPanel::_layersChanged) );
763 }
765 _layersChanged();
766 }
767 }
768 /*
769 GSList const *layers=sp_document_get_resource_list( _desktop->doc(), "layer" );
770 g_message( "layers list starts at %p", layers );
771 for ( GSList const *iter=layers ; iter ; iter = iter->next ) {
772 SPObject *layer=static_cast<SPObject *>(iter->data);
773 g_message(" {%s} [%s]", layer->id, layer->label() );
774 }
775 */
776 deskTrack.setBase(desktop);
777 }
781 } //namespace Dialogs
782 } //namespace UI
783 } //namespace Inkscape
786 /*
787 Local Variables:
788 mode:c++
789 c-file-style:"stroustrup"
790 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
791 indent-tabs-mode:nil
792 fill-column:99
793 End:
794 */
795 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :