Code

remove mnemonic which does not work anyway
[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 <gtkmm/icontheme.h>
22 #include "inkscape.h"
24 #include "layers-panel.h"
26 #include "layer-manager.h"
27 #include "layer-fns.h"
29 #include "verbs.h"
30 #include "helper/action.h"
32 #include "document.h"
33 #include "desktop.h"
34 #include "sp-object.h"
35 #include "sp-item.h"
36 #include "widgets/icon.h"
37 #include "ui/widget/imagetoggler.h"
38 #include <gtkmm/widget.h>
39 #include "preferences.h"
40 #include "xml/repr.h"
41 #include "svg/css-ostringstream.h"
42 #include "desktop-style.h"
44 //#define DUMP_LAYERS 1
46 namespace Inkscape {
47 namespace UI {
48 namespace Dialogs {
50 LayersPanel&
51 LayersPanel::getInstance()
52 {
53     return *new LayersPanel();
54 }
56 enum {
57     COL_VISIBLE = 1,
58     COL_LOCKED
59 };
61 enum {
62     BUTTON_NEW = 0,
63     BUTTON_RENAME,
64     BUTTON_TOP,
65     BUTTON_BOTTOM,
66     BUTTON_UP,
67     BUTTON_DOWN,
68     BUTTON_DUPLICATE,
69     BUTTON_DELETE,
70     BUTTON_SOLO
71 };
73 class LayersPanel::InternalUIBounce
74 {
75 public:
76     int _actionCode;
77     SPObject* _target;
78 };
80 static gboolean layers_panel_activated( GtkObject */*object*/, GdkEvent * /*event*/, gpointer data )
81 {
82     if ( data )
83     {
84         LayersPanel* panel = reinterpret_cast<LayersPanel*>(data);
85         panel->setDesktop(panel->getDesktop());
86     }
88     return FALSE;
89 }
91 static gboolean layers_panel_deactivated( GtkObject */*object*/, GdkEvent * /*event*/, gpointer data )
92 {
93     if ( data )
94     {
95         LayersPanel* panel = reinterpret_cast<LayersPanel*>(data);
96         panel->setDesktop(NULL);
97     }
99     return FALSE;
103 void LayersPanel::_styleButton( Gtk::Button& btn, SPDesktop *desktop, unsigned int code, char const* iconName, char const* fallback )
105     bool set = false;
107     if ( iconName ) {
108         GtkWidget *child = sp_icon_new( Inkscape::ICON_SIZE_SMALL_TOOLBAR, iconName );
109         gtk_widget_show( child );
110         btn.add( *manage(Glib::wrap(child)) );
111         set = true;
112     }
114     if ( desktop ) {
115         Verb *verb = Verb::get( code );
116         if ( verb ) {
117             SPAction *action = verb->get_action(desktop);
118             if ( !set && action && action->image ) {
119                 GtkWidget *child = sp_icon_new( Inkscape::ICON_SIZE_SMALL_TOOLBAR, action->image );
120                 gtk_widget_show( child );
121                 btn.add( *manage(Glib::wrap(child)) );
122                 set = true;
123             }
125             if ( action && action->tip ) {
126                 _tips.set_tip( btn, action->tip );
127             }
128         }
129     }
131     if ( !set && fallback ) {
132         btn.set_label( fallback );
133     }
137 Gtk::MenuItem& LayersPanel::_addPopupItem( SPDesktop *desktop, unsigned int code, char const* iconName, char const* fallback, int id )
139     GtkWidget* iconWidget = 0;
140     const char* label = 0;
142     if ( iconName ) {
143         iconWidget = sp_icon_new( Inkscape::ICON_SIZE_MENU, iconName );
144     }
146     if ( desktop ) {
147         Verb *verb = Verb::get( code );
148         if ( verb ) {
149             SPAction *action = verb->get_action(desktop);
150             if ( !iconWidget && action && action->image ) {
151                 iconWidget = sp_icon_new( Inkscape::ICON_SIZE_MENU, action->image );
152             }
154             if ( action ) {
155                 label = action->name;
156             }
157         }
158     }
160     if ( !label && fallback ) {
161         label = fallback;
162     }
164     Gtk::Widget* wrapped = 0;
165     if ( iconWidget ) {
166         wrapped = manage(Glib::wrap(iconWidget));
167         wrapped->show();
168     }
172     Gtk::Menu::MenuList& menulist = _popupMenu.items();
174     if ( wrapped ) {
175         menulist.push_back( Gtk::Menu_Helpers::ImageMenuElem( label, *wrapped, sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), id)) );
176     } else {
177         menulist.push_back( Gtk::Menu_Helpers::MenuElem( label, sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), id)) );
178     }
179     return menulist.back();
182 void LayersPanel::_fireAction( unsigned int code )
184     if ( _desktop ) {
185         Verb *verb = Verb::get( code );
186         if ( verb ) {
187             SPAction *action = verb->get_action(_desktop);
188             if ( action ) {
189                 sp_action_perform( action, NULL );
190 //             } else {
191 //                 g_message("no action");
192             }
193 //         } else {
194 //             g_message("no verb for %u", code);
195         }
196 //     } else {
197 //         g_message("no active desktop");
198     }
201 //     SP_VERB_LAYER_NEXT,
202 //     SP_VERB_LAYER_PREV,
203 void LayersPanel::_takeAction( int val )
205     if ( !_pending ) {
206         _pending = new InternalUIBounce();
207         _pending->_actionCode = val;
208         _pending->_target = _selectedLayer();
209         Glib::signal_timeout().connect( sigc::mem_fun(*this, &LayersPanel::_executeAction), 0 );
210     }
213 bool LayersPanel::_executeAction()
215     // Make sure selected layer hasn't changed since the action was triggered
216     if ( _pending
217          && (
218              (_pending->_actionCode == BUTTON_NEW)
219              || !( (_desktop && _desktop->currentLayer())
220                    && (_desktop->currentLayer() != _pending->_target)
221                  )
222              )
223         ) {
224         int val = _pending->_actionCode;
225 //        SPObject* target = _pending->_target;
227         switch ( val ) {
228             case BUTTON_NEW:
229             {
230                 _fireAction( SP_VERB_LAYER_NEW );
231             }
232             break;
233             case BUTTON_RENAME:
234             {
235                 _fireAction( SP_VERB_LAYER_RENAME );
236             }
237             break;
238             case BUTTON_TOP:
239             {
240                 _fireAction( SP_VERB_LAYER_TO_TOP );
241             }
242             break;
243             case BUTTON_BOTTOM:
244             {
245                 _fireAction( SP_VERB_LAYER_TO_BOTTOM );
246             }
247             break;
248             case BUTTON_UP:
249             {
250                 _fireAction( SP_VERB_LAYER_RAISE );
251             }
252             break;
253             case BUTTON_DOWN:
254             {
255                 _fireAction( SP_VERB_LAYER_LOWER );
256             }
257             break;
258             case BUTTON_DUPLICATE:
259             {
260                 _fireAction( SP_VERB_LAYER_DUPLICATE );
261             }
262             break;
263             case BUTTON_DELETE:
264             {
265                 _fireAction( SP_VERB_LAYER_DELETE );
266             }
267             case BUTTON_SOLO:
268             {
269                 _fireAction( SP_VERB_LAYER_SOLO );
270             }
271             break;
272         }
274         delete _pending;
275         _pending = 0;
276     }
278     return false;
281 class LayersPanel::ModelColumns : public Gtk::TreeModel::ColumnRecord
283 public:
285     ModelColumns()
286     {
287         add(_colObject);
288         add(_colVisible);
289         add(_colLocked);
290         add(_colLabel);
291     }
292     virtual ~ModelColumns() {}
294     Gtk::TreeModelColumn<SPObject*> _colObject;
295     Gtk::TreeModelColumn<Glib::ustring> _colLabel;
296     Gtk::TreeModelColumn<bool> _colVisible;
297     Gtk::TreeModelColumn<bool> _colLocked;
298 };
300 void LayersPanel::_updateLayer( SPObject *layer ) {
301     _store->foreach( sigc::bind<SPObject*>(sigc::mem_fun(*this, &LayersPanel::_checkForUpdated), layer) );
304 bool LayersPanel::_checkForUpdated(const Gtk::TreePath &/*path*/, const Gtk::TreeIter& iter, SPObject* layer)
306     bool stopGoing = false;
307     Gtk::TreeModel::Row row = *iter;
308     Glib::ustring tmp = row[_model->_colLabel];
309     if ( layer == row[_model->_colObject] )
310     {
311         row[_model->_colLabel] = layer->label() ? layer->label() : SP_OBJECT_ID(layer);
312         row[_model->_colVisible] = SP_IS_ITEM(layer) ? !SP_ITEM(layer)->isHidden() : false;
313         row[_model->_colLocked] = SP_IS_ITEM(layer) ? SP_ITEM(layer)->isLocked() : false;
315         stopGoing = true;
316     }
318     return stopGoing;
321 void LayersPanel::_selectLayer( SPObject *layer ) {
322     if ( !layer || (_desktop && _desktop->doc() && (layer == _desktop->doc()->root)) ) {
323         if ( _tree.get_selection()->count_selected_rows() != 0 ) {
324             _tree.get_selection()->unselect_all();
325         }
326     } else {
327         _store->foreach( sigc::bind<SPObject*>(sigc::mem_fun(*this, &LayersPanel::_checkForSelected), layer) );
328     }
330     _checkTreeSelection();
333 bool LayersPanel::_checkForSelected(const Gtk::TreePath &path, const Gtk::TreeIter& iter, SPObject* layer)
335     bool stopGoing = false;
337     Gtk::TreeModel::Row row = *iter;
338     if ( layer == row[_model->_colObject] )
339     {
340         _tree.expand_to_path( path );
342         Glib::RefPtr<Gtk::TreeSelection> select = _tree.get_selection();
344         select->select(iter);
346         stopGoing = true;
347     }
349     return stopGoing;
352 void LayersPanel::_layersChanged()
354 //    g_message("_layersChanged()");
355     SPDocument* document = _desktop->doc();
356     SPObject* root = document->root;
357     if ( root ) {
358         _selectedConnection.block();
359         if ( _mgr && _mgr->includes( root ) ) {
360             SPObject* target = _desktop->currentLayer();
361             _store->clear();
363 #if DUMP_LAYERS
364             g_message("root:%p  {%s}   [%s]", root, root->id, root->label() );
365 #endif // DUMP_LAYERS
366             _addLayer( document, root, 0, target, 0 );
367         }
368         _selectedConnection.unblock();
369     }
372 void LayersPanel::_addLayer( SPDocument* doc, SPObject* layer, Gtk::TreeModel::Row* parentRow, SPObject* target, int level )
374     if ( layer && (level < _maxNestDepth) ) {
375         unsigned int counter = _mgr->childCount(layer);
376         for ( unsigned int i = 0; i < counter; i++ ) {
377             SPObject *child = _mgr->nthChildOf(layer, i);
378             if ( child ) {
379 #if DUMP_LAYERS
380                 g_message(" %3d    layer:%p  {%s}   [%s]", level, child, child->id, child->label() );
381 #endif // DUMP_LAYERS
383                 Gtk::TreeModel::iterator iter = parentRow ? _store->prepend(parentRow->children()) : _store->prepend();
384                 Gtk::TreeModel::Row row = *iter;
385                 row[_model->_colObject] = child;
386                 row[_model->_colLabel] = child->label() ? child->label() : SP_OBJECT_ID(child);
387                 row[_model->_colVisible] = SP_IS_ITEM(child) ? !SP_ITEM(child)->isHidden() : false;
388                 row[_model->_colLocked] = SP_IS_ITEM(child) ? SP_ITEM(child)->isLocked() : false;
390                 if ( target && child == target ) {
391                     _tree.expand_to_path( _store->get_path(iter) );
393                     Glib::RefPtr<Gtk::TreeSelection> select = _tree.get_selection();
394                     select->select(iter);
396                     _checkTreeSelection();
397                 }
399                 _addLayer( doc, child, &row, target, level + 1 );
400             }
401         }
402     }
405 SPObject* LayersPanel::_selectedLayer()
407     SPObject* obj = 0;
409     Gtk::TreeModel::iterator iter = _tree.get_selection()->get_selected();
410     if ( iter ) {
411         Gtk::TreeModel::Row row = *iter;
412         obj = row[_model->_colObject];
413     }
415     return obj;
418 void LayersPanel::_pushTreeSelectionToCurrent()
420     SPObject* inTree = _selectedLayer();
421     // TODO hunt down the possible API abuse in getting NULL
422     if ( _desktop->currentRoot() ) {
423         if ( inTree ) {
424             SPObject* curr = _desktop->currentLayer();
425             if ( curr != inTree ) {
426                 _mgr->setCurrentLayer( inTree );
427             }
428         } else {
429             _mgr->setCurrentLayer( _desktop->doc()->root );
430         }
431     }
434 void LayersPanel::_checkTreeSelection()
436     bool sensitive = false;
437     bool sensitiveNonTop = false;
438     bool sensitiveNonBottom = false;
439     if ( _tree.get_selection()->count_selected_rows() > 0 ) {
440         sensitive = true;
442         SPObject* inTree = _selectedLayer();
443         if ( inTree ) {
445             sensitiveNonTop = (Inkscape::next_layer(inTree->parent, inTree) != 0);
446             sensitiveNonBottom = (Inkscape::previous_layer(inTree->parent, inTree) != 0);
448         }
449     }
452     for ( std::vector<Gtk::Widget*>::iterator it = _watching.begin(); it != _watching.end(); ++it ) {
453         (*it)->set_sensitive( sensitive );
454     }
455     for ( std::vector<Gtk::Widget*>::iterator it = _watchingNonTop.begin(); it != _watchingNonTop.end(); ++it ) {
456         (*it)->set_sensitive( sensitiveNonTop );
457     }
458     for ( std::vector<Gtk::Widget*>::iterator it = _watchingNonBottom.begin(); it != _watchingNonBottom.end(); ++it ) {
459         (*it)->set_sensitive( sensitiveNonBottom );
460     }
463 void LayersPanel::_preToggle( GdkEvent const *event )
465     if ( _toggleEvent ) {
466         gdk_event_free(_toggleEvent);
467         _toggleEvent = 0;
468     }
470     if ( event && (event->type == GDK_BUTTON_PRESS) ) {
471         // Make a copy so we can keep it around.
472         _toggleEvent = gdk_event_copy(const_cast<GdkEvent*>(event));
473     }
476 void LayersPanel::_toggled( Glib::ustring const& str, int targetCol )
478     Gtk::TreeModel::Children::iterator iter = _tree.get_model()->get_iter(str);
479     Gtk::TreeModel::Row row = *iter;
481     Glib::ustring tmp = row[_model->_colLabel];
483     SPObject* obj = row[_model->_colObject];
484     SPItem* item = ( obj && SP_IS_ITEM(obj) ) ? SP_ITEM(obj) : 0;
485     if ( item ) {
486         switch ( targetCol ) {
487             case COL_VISIBLE:
488             {
489                 bool newValue = !row[_model->_colVisible];
490                 row[_model->_colVisible] = newValue;
491                 item->setHidden( !newValue  );
492                 item->updateRepr();
493                 sp_document_done( _desktop->doc() , SP_VERB_DIALOG_LAYERS,
494                                   newValue? _("Unhide layer") : _("Hide layer"));
495             }
496             break;
498             case COL_LOCKED:
499             {
500                 bool newValue = !row[_model->_colLocked];
501                 row[_model->_colLocked] = newValue;
502                 item->setLocked( newValue );
503                 item->updateRepr();
504                 sp_document_done( _desktop->doc() , SP_VERB_DIALOG_LAYERS,
505                                   newValue? _("Lock layer") : _("Unlock layer"));
506             }
507             break;
508         }
509     }
512 void LayersPanel::_handleButtonEvent(GdkEventButton* evt)
514     // TODO - fix to a better is-popup function
515     if ( (evt->type == GDK_BUTTON_PRESS) && (evt->button == 3) ) {
518         {
519             Gtk::TreeModel::Path path;
520             Gtk::TreeViewColumn* col = 0;
521             int x = static_cast<int>(evt->x);
522             int y = static_cast<int>(evt->y);
523             int x2 = 0;
524             int y2 = 0;
525             if ( _tree.get_path_at_pos( x, y,
526                                         path, col,
527                                         x2, y2 ) ) {
528                 _checkTreeSelection();
529                 _popupMenu.popup(evt->button, evt->time);
530             }
531         }
533     }
536 void LayersPanel::_handleRowChange( Gtk::TreeModel::Path const& /*path*/, Gtk::TreeModel::iterator const& iter )
538     Gtk::TreeModel::Row row = *iter;
539     if ( row ) {
540         SPObject* obj = row[_model->_colObject];
541         if ( obj ) {
542             gchar const* oldLabel = obj->label();
543             Glib::ustring tmp = row[_model->_colLabel];
544             if ( oldLabel && oldLabel[0] && !tmp.empty() && (tmp != oldLabel) ) {
545                 _mgr->renameLayer( obj, tmp.c_str() );
546                 row[_model->_colLabel] = obj->label();
547             }
548         }
549     }
552 bool LayersPanel::_rowSelectFunction( Glib::RefPtr<Gtk::TreeModel> const & /*model*/, Gtk::TreeModel::Path const & /*path*/, bool currentlySelected )
554     bool val = true;
555     if ( !currentlySelected && _toggleEvent )
556     {
557         GdkEvent* event = gtk_get_current_event();
558         if ( event ) {
559             // (keep these checks separate, so we know when to call gdk_event_free()
560             if ( event->type == GDK_BUTTON_PRESS ) {
561                 GdkEventButton const* target = reinterpret_cast<GdkEventButton const*>(_toggleEvent);
562                 GdkEventButton const* evtb = reinterpret_cast<GdkEventButton const*>(event);
564                 if ( (evtb->window == target->window)
565                      && (evtb->send_event == target->send_event)
566                      && (evtb->time == target->time)
567                      && (evtb->state == target->state)
568                     )
569                 {
570                     // Ooooh! It's a magic one
571                     val = false;
572                 }
573             }
574             gdk_event_free(event);
575         }
576     }
577     return val;
580 /**
581  * Constructor
582  */
583 LayersPanel::LayersPanel() :
584     UI::Widget::Panel("", "/dialogs/layers", SP_VERB_DIALOG_LAYERS),
585     _maxNestDepth(20),
586     _mgr(0),
587     _desktop(0),
588     _model(0),
589     _pending(0),
590     _toggleEvent(0),
591     _compositeSettings(SP_VERB_DIALOG_LAYERS, "layers", UI::Widget::SimpleFilterModifier::BLEND)
593     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
594     _maxNestDepth = prefs->getIntLimited("/dialogs/layers/maxDepth", 20, 1, 1000);
596     ModelColumns *zoop = new ModelColumns();
597     _model = zoop;
599     _store = Gtk::TreeStore::create( *zoop );
601     _tree.set_model( _store );
602     _tree.set_headers_visible(false);
604     Inkscape::UI::Widget::ImageToggler *eyeRenderer = manage( new Inkscape::UI::Widget::ImageToggler("visible", "hidden") );
605     int visibleColNum = _tree.append_column("vis", *eyeRenderer) - 1;
606     eyeRenderer->signal_pre_toggle().connect( sigc::mem_fun(*this, &LayersPanel::_preToggle) );
607     eyeRenderer->signal_toggled().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_toggled), (int)COL_VISIBLE) );
608     eyeRenderer->property_activatable() = true;
609     Gtk::TreeViewColumn* col = _tree.get_column(visibleColNum);
610     if ( col ) {
611         col->add_attribute( eyeRenderer->property_active(), _model->_colVisible );
612     }
614     Inkscape::UI::Widget::ImageToggler * renderer = manage( new Inkscape::UI::Widget::ImageToggler("width_height_lock", "lock_unlocked") );
615     int lockedColNum = _tree.append_column("lock", *renderer) - 1;
616     renderer->signal_pre_toggle().connect( sigc::mem_fun(*this, &LayersPanel::_preToggle) );
617     renderer->signal_toggled().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_toggled), (int)COL_LOCKED) );
618     renderer->property_activatable() = true;
619     col = _tree.get_column(lockedColNum);
620     if ( col ) {
621         col->add_attribute( renderer->property_active(), _model->_colLocked );
622     }
624     int nameColNum = _tree.append_column_editable("Name", _model->_colLabel) - 1;
626     _tree.set_expander_column( *_tree.get_column(nameColNum) );
628     _compositeSettings.setSubject(&_subject);
630     _selectedConnection = _tree.get_selection()->signal_changed().connect( sigc::mem_fun(*this, &LayersPanel::_pushTreeSelectionToCurrent) );
631     _tree.get_selection()->set_select_function( sigc::mem_fun(*this, &LayersPanel::_rowSelectFunction) );
633     _tree.get_model()->signal_row_changed().connect( sigc::mem_fun(*this, &LayersPanel::_handleRowChange) );
634     _tree.signal_button_press_event().connect_notify( sigc::mem_fun(*this, &LayersPanel::_handleButtonEvent) );
636     _scroller.add( _tree );
637     _scroller.set_policy( Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC );
638     _scroller.set_shadow_type(Gtk::SHADOW_IN);
640     _watching.push_back( &_compositeSettings );
642     _layersPage.pack_start( _scroller, Gtk::PACK_EXPAND_WIDGET );
643     _layersPage.pack_end(_compositeSettings, Gtk::PACK_SHRINK);
644     _layersPage.pack_end(_buttonsRow, Gtk::PACK_SHRINK);
646     _notebook.append_page(_layersPage, _("Layers"));
648     _getContents()->pack_start(_notebook, Gtk::PACK_EXPAND_WIDGET);
650     SPDesktop* targetDesktop = getDesktop();
652     _buttonsRow.set_child_min_width( 16 );
654     Gtk::Button* btn = manage( new Gtk::Button() );
655     _styleButton( *btn, targetDesktop, SP_VERB_LAYER_NEW, GTK_STOCK_ADD, _("New") );
656     btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_NEW) );
657     _buttonsRow.add( *btn );
659     btn = manage( new Gtk::Button() );
660     _styleButton( *btn, targetDesktop, SP_VERB_LAYER_TO_TOP, GTK_STOCK_GOTO_TOP, _("Top") );
661     btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_TOP) );
662     _watchingNonTop.push_back( btn );
663     _buttonsRow.add( *btn );
665     btn = manage( new Gtk::Button() );
666     _styleButton( *btn, targetDesktop, SP_VERB_LAYER_RAISE, GTK_STOCK_GO_UP, _("Up") );
667     btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_UP) );
668     _watchingNonTop.push_back( btn );
669     _buttonsRow.add( *btn );
671     btn = manage( new Gtk::Button() );
672     _styleButton( *btn, targetDesktop, SP_VERB_LAYER_LOWER, GTK_STOCK_GO_DOWN, _("Dn") );
673     btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_DOWN) );
674     _watchingNonBottom.push_back( btn );
675     _buttonsRow.add( *btn );
677     btn = manage( new Gtk::Button() );
678     _styleButton( *btn, targetDesktop, SP_VERB_LAYER_TO_BOTTOM, GTK_STOCK_GOTO_BOTTOM, _("Bot") );
679     btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_BOTTOM) );
680     _watchingNonBottom.push_back( btn );
681     _buttonsRow.add( *btn );
683 //     btn = manage( new Gtk::Button("Dup") );
684 //     btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_DUPLICATE) );
685 //     _buttonsRow.add( *btn );
687     btn = manage( new Gtk::Button() );
688     _styleButton( *btn, targetDesktop, SP_VERB_LAYER_DELETE, GTK_STOCK_REMOVE, _("X") );
689     btn->signal_clicked().connect( sigc::bind( sigc::mem_fun(*this, &LayersPanel::_takeAction), (int)BUTTON_DELETE) );
690     _watching.push_back( btn );
691     _buttonsRow.add( *btn );
696     // -------------------------------------------------------
697     {
698         _watching.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_RENAME, 0, "Rename", (int)BUTTON_RENAME ) );
699         _watching.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_DUPLICATE, 0, "Duplicate", (int)BUTTON_DUPLICATE ) );
700         _watching.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_NEW, 0, "New", (int)BUTTON_NEW ) );
701         _watching.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_SOLO, 0, "Solo", (int)BUTTON_SOLO ) );
703          _popupMenu.items().push_back( Gtk::Menu_Helpers::SeparatorElem() );
705         _watchingNonTop.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_RAISE, GTK_STOCK_GO_UP, "Up", (int)BUTTON_UP ) );
706         _watchingNonBottom.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_LOWER, GTK_STOCK_GO_DOWN, "Down", (int)BUTTON_DOWN ) );
708         _popupMenu.show_all_children();
709     }
710     // -------------------------------------------------------
714     for ( std::vector<Gtk::Widget*>::iterator it = _watching.begin(); it != _watching.end(); ++it ) {
715         (*it)->set_sensitive( false );
716     }
717     for ( std::vector<Gtk::Widget*>::iterator it = _watchingNonTop.begin(); it != _watchingNonTop.end(); ++it ) {
718         (*it)->set_sensitive( false );
719     }
720     for ( std::vector<Gtk::Widget*>::iterator it = _watchingNonBottom.begin(); it != _watchingNonBottom.end(); ++it ) {
721         (*it)->set_sensitive( false );
722     }
724     g_signal_connect( G_OBJECT(INKSCAPE), "activate_desktop", G_CALLBACK( layers_panel_activated ), this );
725     g_signal_connect( G_OBJECT(INKSCAPE), "deactivate_desktop", G_CALLBACK( layers_panel_deactivated ), this );
726     setDesktop( targetDesktop );
728     show_all_children();
730     // restorePanelPrefs();
733 LayersPanel::~LayersPanel()
735     setDesktop(NULL);
737     _compositeSettings.setSubject(NULL);
739     if ( _model )
740     {
741         delete _model;
742     }
744     if ( _toggleEvent )
745     {
746         gdk_event_free( _toggleEvent );
747         _toggleEvent = 0;
748     }
752 void LayersPanel::setDesktop( SPDesktop* desktop )
754     Panel::setDesktop(desktop);
756     if ( desktop != _desktop ) {
757         _layerChangedConnection.disconnect();
758         _layerUpdatedConnection.disconnect();
759         _changedConnection.disconnect();
760         if ( _mgr ) {
761             _mgr = 0;
762         }
763         if ( _desktop ) {
764             _desktop = 0;
765         }
767         _desktop = getDesktop();
768         if ( _desktop ) {
769             //setLabel( _desktop->doc()->name );
771             _mgr = _desktop->layer_manager;
772             if ( _mgr ) {
773                 _layerChangedConnection = _mgr->connectCurrentLayerChanged( sigc::mem_fun(*this, &LayersPanel::_selectLayer) );
774                 _layerUpdatedConnection = _mgr->connectLayerDetailsChanged( sigc::mem_fun(*this, &LayersPanel::_updateLayer) );
775                 _changedConnection = _mgr->connectChanged( sigc::mem_fun(*this, &LayersPanel::_layersChanged) );
776             }
778             _layersChanged();
779         }
780     }
781 /*
782     GSList const *layers=sp_document_get_resource_list( _desktop->doc(), "layer" );
783     g_message( "layers list starts at %p", layers );
784     for ( GSList const *iter=layers ; iter ; iter = iter->next ) {
785         SPObject *layer=static_cast<SPObject *>(iter->data);
786         g_message("  {%s}   [%s]", layer->id, layer->label() );
787     }
788 */
793 } //namespace Dialogs
794 } //namespace UI
795 } //namespace Inkscape
798 /*
799   Local Variables:
800   mode:c++
801   c-file-style:"stroustrup"
802   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
803   indent-tabs-mode:nil
804   fill-column:99
805   End:
806 */
807 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :