Code

Refactoring SPColor to C++ and removing legacy CMYK implementation
[inkscape.git] / src / dialogs / layers-panel.cpp
index 4faaec2979c42919457310b17aa474caa26d7096..383d11f57b0e54a0559bd418c21ce9e09bf2fa6b 100644 (file)
@@ -33,7 +33,6 @@
 #include "sp-item.h"
 #include "widgets/icon.h"
 #include <gtkmm/widget.h>
-#include <gtkmm/spinbutton.h>
 #include "prefs-utils.h"
 #include "xml/repr.h"
 #include "svg/css-ostringstream.h"
@@ -47,13 +46,14 @@ namespace Dialogs {
 
 LayersPanel* LayersPanel::instance = 0;
 
-LayersPanel& LayersPanel::getInstance()
+LayersPanel*
+LayersPanel::create(Inkscape::UI::Dialog::Behavior::BehaviorFactory behavior_factory)
 {
     if ( !instance ) {
-        instance = new LayersPanel();
+        instance = new LayersPanel(behavior_factory);
     }
 
-    return *instance;
+    return instance;
 }
 
 enum {
@@ -314,9 +314,13 @@ bool LayersPanel::_executeAction()
 {
     // Make sure selected layer hasn't changed since the action was triggered
     if ( _pending
-         && !( (_desktop && _desktop->currentLayer())
-               && (_desktop->currentLayer() != _pending->_target)
-             ) ) {
+         && (
+             (_pending->_actionCode == BUTTON_NEW)
+             || !( (_desktop && _desktop->currentLayer())
+                   && (_desktop->currentLayer() != _pending->_target)
+                 )
+             )
+        ) {
         int val = _pending->_actionCode;
 //        SPObject* target = _pending->_target;
 
@@ -442,6 +446,7 @@ void LayersPanel::_layersChanged()
     SPDocument* document = _desktop->doc();
     SPObject* root = document->root;
     if ( root ) {
+        _selectedConnection.block();
         if ( _mgr && _mgr->includes( root ) ) {
             SPObject* target = _desktop->currentLayer();
             _store->clear();
@@ -451,6 +456,7 @@ void LayersPanel::_layersChanged()
 #endif // DUMP_LAYERS
             _addLayer( document, root, 0, target, 0 );
         }
+        _selectedConnection.unblock();
     }
 }
 
@@ -533,7 +539,9 @@ void LayersPanel::_checkTreeSelection()
             if ( inTree->repr ) {
                 SPCSSAttr *css = sp_repr_css_attr(inTree->repr, "style");
                 if ( css ) {
-                    _opacity.set_value( sp_repr_css_double_property( css, "opacity", 1.0 ) );
+                    _opacityConnection.block();
+                    _opacity.set_value( sp_repr_css_double_property( css, "opacity", 1.0 ) * 100 );
+                    _opacityConnection.unblock();
                 }
             }
         }
@@ -581,7 +589,8 @@ void LayersPanel::_toggled( Glib::ustring const& str, int targetCol )
                 row[_model->_colVisible] = newValue;
                 item->setHidden( !newValue  );
                 item->updateRepr();
-                sp_document_done( _desktop->doc() );
+                sp_document_done( _desktop->doc() , SP_VERB_DIALOG_LAYERS, 
+                                  newValue? _("Unhide layer") : _("Hide layer"));
             }
             break;
 
@@ -591,7 +600,8 @@ void LayersPanel::_toggled( Glib::ustring const& str, int targetCol )
                 row[_model->_colLocked] = newValue;
                 item->setLocked( newValue );
                 item->updateRepr();
-                sp_document_done( _desktop->doc() );
+                sp_document_done( _desktop->doc() , SP_VERB_DIALOG_LAYERS, 
+                                  newValue? _("Lock layer") : _("Unlock layer"));
             }
             break;
         }
@@ -674,12 +684,11 @@ void LayersPanel::_opacityChanged()
     if ( _desktop && layer && !_opacityConnection.blocked() ) {
         _opacityConnection.block();
 
-
         Gtk::Adjustment* adj = _opacity.get_adjustment();
         SPCSSAttr *css = sp_repr_css_attr_new();
 
         Inkscape::CSSOStringStream os;
-        os << CLAMP( adj->get_value(), 0.0, 1.0 );
+        os << CLAMP( adj->get_value() / 100, 0.0, 1.0 );
         sp_repr_css_set_property( css, "opacity", os.str().c_str() );
 
         sp_desktop_apply_css_recursive( layer, css, true );
@@ -687,7 +696,8 @@ void LayersPanel::_opacityChanged()
 
         sp_repr_css_attr_unref( css );
 
-        sp_document_maybe_done( _desktop->doc(), "layers:opacity" );
+        sp_document_maybe_done( _desktop->doc(), "layers:opacity", SP_VERB_DIALOG_LAYERS, 
+                                _("Change layer opacity"));
 
         _opacityConnection.unblock();
     }
@@ -698,8 +708,8 @@ void LayersPanel::_opacityChanged()
 /**
  * Constructor
  */
-LayersPanel::LayersPanel() :
-    Inkscape::UI::Widget::Panel( Glib::ustring(), "dialogs.layers" ),
+LayersPanel::LayersPanel(Inkscape::UI::Dialog::Behavior::BehaviorFactory behavior_factory) :
+    Inkscape::UI::Dialog::Dialog(behavior_factory, "dialogs.layers", SP_VERB_DIALOG_LAYERS),
     _maxNestDepth(20),
     _mgr(0),
     _desktop(0),
@@ -742,7 +752,7 @@ LayersPanel::LayersPanel() :
     _tree.set_expander_column( *_tree.get_column(nameColNum) );
 
 
-    _tree.get_selection()->signal_changed().connect( sigc::mem_fun(*this, &LayersPanel::_pushTreeSelectionToCurrent) );
+    _selectedConnection = _tree.get_selection()->signal_changed().connect( sigc::mem_fun(*this, &LayersPanel::_pushTreeSelectionToCurrent) );
     _tree.get_selection()->set_select_function( sigc::mem_fun(*this, &LayersPanel::_rowSelectFunction) );
 
     _tree.get_model()->signal_row_changed().connect( sigc::mem_fun(*this, &LayersPanel::_handleRowChange) );
@@ -752,23 +762,24 @@ LayersPanel::LayersPanel() :
     _scroller.set_policy( Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC );
 
 
-    _opacityBox.pack_start( *manage( new Gtk::Label(_("Opacity:"))), Gtk::PACK_SHRINK );
+    _opacityBox.pack_start( *manage( new Gtk::Label(_("Opacity, %:"))), Gtk::PACK_SHRINK );
 
     _opacity.set_draw_value(false);
-    _opacity.set_value(1.0);
-    _opacity.set_range(0.0, 1.0);
-    _opacity.set_increments(0.01, 0.1);
+    _opacity.set_value(100.0);
+    _opacity.set_range(0.0, 100.0);
+    _opacity.set_increments(1, 10);
     _opacityBox.pack_start( _opacity, Gtk::PACK_EXPAND_WIDGET );
 
-    Gtk::SpinButton* spinBtn = manage( new Gtk::SpinButton(*_opacity.get_adjustment(), 0.0, 3) );
+    _spinBtn.configure(*_opacity.get_adjustment(), 0, 1);
 
-    _opacityBox.pack_end( *spinBtn, Gtk::PACK_SHRINK );
+    _spinBtn.set_width_chars(5);
+    _opacityBox.pack_end( _spinBtn, Gtk::PACK_SHRINK );
     _watching.push_back( &_opacityBox );
 
-    _getContents()->pack_start( _scroller, Gtk::PACK_EXPAND_WIDGET );
+    get_vbox()->pack_start( _scroller, Gtk::PACK_EXPAND_WIDGET );
 
-    _getContents()->pack_end(_opacityBox, Gtk::PACK_SHRINK);
-    _getContents()->pack_end(_buttonsRow, Gtk::PACK_SHRINK);
+    get_vbox()->pack_end(_opacityBox, Gtk::PACK_SHRINK);
+    get_vbox()->pack_end(_buttonsRow, Gtk::PACK_SHRINK);
 
     _opacityConnection = _opacity.get_adjustment()->signal_value_changed().connect( sigc::mem_fun(*this, &LayersPanel::_opacityChanged) );
 
@@ -845,15 +856,11 @@ LayersPanel::LayersPanel() :
     }
 
     g_signal_connect( G_OBJECT(INKSCAPE), "activate_desktop", G_CALLBACK( layers_panel_activated ), this );
-
-
     setDesktop( targetDesktop );
 
-
-
     show_all_children();
 
-    restorePanelPrefs();
+    // restorePanelPrefs();
 }
 
 LayersPanel::~LayersPanel()
@@ -886,7 +893,7 @@ void LayersPanel::setDesktop( SPDesktop* desktop )
 
         _desktop = SP_ACTIVE_DESKTOP;
         if ( _desktop ) {
-            setLabel( _desktop->doc()->name );
+            //setLabel( _desktop->doc()->name );
 
             _mgr = _desktop->layer_manager;
             if ( _mgr ) {