Code

fix lpe dialog updating
[inkscape.git] / src / ui / dialog / livepatheffect-editor.cpp
index f6b9975282cd6cd638747fc24783cddc783a3937..62ed4e63996da17a5bd47a436754afae036f4a28 100644 (file)
@@ -1,13 +1,12 @@
-/**
- * \brief LivePathEffect dialog
- *
- * Authors:
+/** @file
+ * @brief Live Path Effect editing dialog - implementation
+ */
+/* Authors:
  *   Johan Engelen <j.b.c.engelen@utwente.nl>
  *   Steren Giannini <steren.giannini@gmail.com>
  *   Bastien Bouclet <bgkweb@gmail.com>
  *
- * Copyright (C) 2007 Author
- *
+ * Copyright (C) 2007 Authors
  * Released under GNU GPL.  Read the file 'COPYING' for more information.
  */
 
 #endif
 
 #include <glibmm/i18n.h>
-#include "livepatheffect-editor.h"
-#include "ui/widget/imagetoggler.h"
-#include "verbs.h"
+#include <gtkmm/stock.h>
+#include <gtkmm/toolbar.h>
+#include <vector>
+
+#include "desktop.h"
+#include "desktop-handles.h"
+#include "document.h"
+#include "gtkmm/widget.h"
+#include "inkscape.h"
+#include "live_effects/effect.h"
+#include "live_effects/lpeobject.h"
+#include "live_effects/lpeobject-reference.h"
+#include "path-chemistry.h"
 #include "selection.h"
-#include "sp-shape.h"
 #include "sp-item-group.h"
+#include "sp-lpe-item.h"
 #include "sp-path.h"
 #include "sp-rect.h"
-#include "sp-lpe-item.h"
-#include "path-chemistry.h"
-#include "live_effects/effect.h"
-#include "live_effects/lpeobject.h"
-#include "gtkmm/widget.h"
-#include <vector>
-#include "inkscape.h"
-#include "desktop-handles.h"
-#include "desktop.h"
-#include "document.h"
+#include "sp-shape.h"
+#include "ui/icon-names.h"
+#include "ui/widget/imagetoggler.h"
+#include "verbs.h"
 #include "xml/node.h"
-#include <gtkmm/stock.h>
-#include <gtkmm/toolbar.h>
 
-#include "live_effects/lpeobject-reference.h"
+#include "livepatheffect-editor.h"
 
 namespace Inkscape {
 class Application;
@@ -50,9 +51,10 @@ namespace Dialog {
 /*####################
  * Callback functions
  */
-static void lpeeditor_selection_changed (Inkscape::Selection * selection, gpointer data)
+void lpeeditor_selection_changed (Inkscape::Selection * selection, gpointer data)
 {
     LivePathEffectEditor *lpeeditor = static_cast<LivePathEffectEditor *>(data);
+    lpeeditor->lpe_list_locked = false;
     lpeeditor->onSelectionChanged(selection);
 }
 
@@ -68,10 +70,12 @@ static void lpeeditor_selection_modified (Inkscape::Selection * selection, guint
  */
 
 LivePathEffectEditor::LivePathEffectEditor()
-    : UI::Widget::Panel("", "dialogs.livepatheffect", SP_VERB_DIALOG_LIVE_PATH_EFFECT),
+    : UI::Widget::Panel("", "/dialogs/livepatheffect", SP_VERB_DIALOG_LIVE_PATH_EFFECT),
+      lpe_list_locked(false),
       combo_effecttype(Inkscape::LivePathEffect::LPETypeConverter),
       effectwidget(NULL),
       explain_label("", Gtk::ALIGN_CENTER),
+      // TRANSLATORS: this dialog is accessible via menu Path - Path Effect Editor...
       effectapplication_frame(_("Apply new effect")),
       effectcontrol_frame(_("Current effect")),
       effectlist_frame(_("Effect list")),
@@ -125,7 +129,6 @@ LivePathEffectEditor::LivePathEffectEditor()
     effectlist_store = Gtk::ListStore::create(columns);
     effectlist_view.set_model(effectlist_store);
 
-    effectlist_view.set_rules_hint();
     effectlist_view.set_headers_visible(false);
 
     // Handle tree selections
@@ -133,7 +136,8 @@ LivePathEffectEditor::LivePathEffectEditor()
     effectlist_selection->signal_changed().connect( sigc::mem_fun(*this, &LivePathEffectEditor::on_effect_selection_changed) );
 
     //Add the visibility icon column:
-    Inkscape::UI::Widget::ImageToggler *eyeRenderer = manage( new Inkscape::UI::Widget::ImageToggler("visible", "hidden") );
+    Inkscape::UI::Widget::ImageToggler *eyeRenderer = manage( new Inkscape::UI::Widget::ImageToggler(
+        INKSCAPE_ICON_OBJECT_VISIBLE, INKSCAPE_ICON_OBJECT_HIDDEN) );
     int visibleColNum = effectlist_view.append_column("is_visible", *eyeRenderer) - 1;
     eyeRenderer->signal_toggled().connect( sigc::mem_fun(*this, &LivePathEffectEditor::on_visibility_toggled) );
     eyeRenderer->property_activatable() = true;
@@ -176,7 +180,7 @@ LivePathEffectEditor::~LivePathEffectEditor()
 }
 
 void
-LivePathEffectEditor::showParams(LivePathEffect::Effect* effect)
+LivePathEffectEditor::showParams(LivePathEffect::Effect& effect)
 {
     if (effectwidget) {
         effectcontrol_vbox.remove(*effectwidget);
@@ -184,8 +188,8 @@ LivePathEffectEditor::showParams(LivePathEffect::Effect* effect)
         effectwidget = NULL;
     }
 
-    explain_label.set_markup("<b>" + effect->getName() + "</b>");
-    effectwidget = effect->newWidget(&tooltips);
+    explain_label.set_markup("<b>" + effect.getName() + "</b>");
+    effectwidget = effect.newWidget(&tooltips);
     if (effectwidget) {
         effectcontrol_vbox.pack_start(*effectwidget, true, true);
     }
@@ -195,6 +199,17 @@ LivePathEffectEditor::showParams(LivePathEffect::Effect* effect)
     // fixme: add resizing of dialog
 }
 
+void
+LivePathEffectEditor::selectInList(LivePathEffect::Effect* effect)
+{
+    Gtk::TreeNodeChildren chi = effectlist_view.get_model()->children();
+    for (Gtk::TreeIter ci = chi.begin() ; ci != chi.end(); ci++) {
+        if (ci->get_value(columns.lperef)->lpeobject->get_lpe() == effect)
+            effectlist_view.get_selection()->select(ci);
+    }
+}
+
+
 void
 LivePathEffectEditor::showText(Glib::ustring const &str)
 {
@@ -225,6 +240,12 @@ LivePathEffectEditor::set_sensitize_all(bool sensitive)
 void
 LivePathEffectEditor::onSelectionChanged(Inkscape::Selection *sel)
 {
+    if (lpe_list_locked) {
+        // this was triggered by selecting a row in the list, so skip reloading
+        lpe_list_locked = false;
+        return;
+    } 
+
     effectlist_store->clear();
     current_lpeitem = NULL;
 
@@ -242,7 +263,9 @@ LivePathEffectEditor::onSelectionChanged(Inkscape::Selection *sel)
                 if ( sp_lpe_item_has_path_effect(lpeitem) ) {
                     Inkscape::LivePathEffect::Effect *lpe = sp_lpe_item_get_current_lpe(lpeitem);
                     if (lpe) {
-                        showParams(lpe);
+                        showParams(*lpe);
+                        lpe_list_locked = true; 
+                        selectInList(lpe);
                     } else {
                         showText(_("Unknown effect is applied"));
                     }
@@ -276,10 +299,17 @@ LivePathEffectEditor::effect_list_reload(SPLPEItem *lpeitem)
     PathEffectList::iterator it;
     for( it = effectlist.begin() ; it!=effectlist.end(); it++ )
     {
-         Gtk::TreeModel::Row row = *(effectlist_store->append());
-         row[columns.col_name] = (*it)->lpeobject->lpe->getName();
-         row[columns.lperef] = *it;
-         row[columns.col_visible] = (*it)->lpeobject->lpe->isVisible();
+        if ((*it)->lpeobject->get_lpe()) {
+            Gtk::TreeModel::Row row = *(effectlist_store->append());
+            row[columns.col_name] = (*it)->lpeobject->get_lpe()->getName();
+            row[columns.lperef] = *it;
+            row[columns.col_visible] = (*it)->lpeobject->get_lpe()->isVisible();
+        } else {
+            Gtk::TreeModel::Row row = *(effectlist_store->append());
+            row[columns.col_name] = _("Unknown effect");
+            row[columns.lperef] = *it;
+            row[columns.col_visible] = false;
+        }
     }
 }
 
@@ -298,6 +328,7 @@ LivePathEffectEditor::setDesktop(SPDesktop *desktop)
         selection_modified_connection.disconnect();
     }
 
+    lpe_list_locked = false;
     current_desktop = desktop;
     if (desktop) {
         Inkscape::Selection *selection = sp_desktop_selection(desktop);
@@ -335,7 +366,7 @@ LivePathEffectEditor::onApply()
 
             // If item is a SPRect, convert it to path first:
             if ( SP_IS_RECT(item) ) {
-                sp_selected_path_to_curves(false);
+                sp_selected_path_to_curves(current_desktop, false);
                 item = sel->singleItem(); // get new item
             }
 
@@ -344,6 +375,7 @@ LivePathEffectEditor::onApply()
             sp_document_done(doc, SP_VERB_DIALOG_LIVE_PATH_EFFECT,
                      _("Create and apply path effect"));
 
+            lpe_list_locked = false;
             onSelectionChanged(sel);
         }
     }
@@ -408,8 +440,11 @@ void LivePathEffectEditor::on_effect_selection_changed()
     LivePathEffect::LPEObjectReference * lperef = (*it)[columns.lperef];
 
     if (lperef && current_lpeitem) {
-        sp_lpe_item_set_current_path_effect(current_lpeitem, lperef);
-        showParams(lperef->lpeobject->lpe);
+        if (lperef->lpeobject->get_lpe()) {
+            lpe_list_locked = true; // prevent reload of the list which would lose selection
+            sp_lpe_item_set_current_path_effect(current_lpeitem, lperef);
+            showParams(*lperef->lpeobject->get_lpe());
+        }
     }
 }
 
@@ -420,14 +455,14 @@ void LivePathEffectEditor::on_visibility_toggled( Glib::ustring const& str )
 
     LivePathEffect::LPEObjectReference * lpeobjref = row[columns.lperef];
 
-    if ( lpeobjref ) {
+    if ( lpeobjref && lpeobjref->lpeobject->get_lpe() ) {
         bool newValue = !row[columns.col_visible];
         row[columns.col_visible] = newValue;
         /* FIXME: this explicit writing to SVG is wrong. The lpe_item should have a method to disable/enable an effect within its stack.
          * So one can call:  lpe_item->setActive(lpeobjref->lpeobject); */
-        lpeobjref->lpeobject->lpe->getRepr()->setAttribute("is_visible", newValue ? "true" : "false");
+        lpeobjref->lpeobject->get_lpe()->getRepr()->setAttribute("is_visible", newValue ? "true" : "false");
         sp_document_done( sp_desktop_document(current_desktop), SP_VERB_DIALOG_LIVE_PATH_EFFECT,
-                          _("Change path effect's visibility") );
+                          newValue ? _("Activate path effect") : _("Deactivate path effect"));
     }
 }