summaryrefslogtreecommitdiffstats
path: root/src/ui/dialog/livepatheffect-editor.cpp
blob: 9705dc86b796534410c34bc713a27a46da26ff9c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
// SPDX-License-Identifier: GPL-2.0-or-later
/**
 * @file
 * 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>
 *   Abhishek Sharma
 *
 * Copyright (C) 2007 Authors
 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
 */

#include "livepatheffect-editor.h"

#include <gtkmm/expander.h>

#include "document-undo.h"
#include "document.h"
#include "inkscape.h"
#include "livepatheffect-add.h"
#include "path-chemistry.h"
#include "selection-chemistry.h"
#include "svg/svg.h"
#include "ui/icon-loader.h"

#include "live_effects/effect.h"
#include "live_effects/lpeobject-reference.h"
#include "live_effects/lpeobject.h"

#include "object/sp-item-group.h"
#include "object/sp-path.h"
#include "object/sp-use.h"
#include "object/sp-symbol.h"
#include "object/sp-text.h"

#include "ui/icon-names.h"
#include "ui/tools/node-tool.h"
#include "ui/widget/imagetoggler.h"

namespace Inkscape {
namespace UI {
namespace Dialog {


/*####################
 * Callback functions
 */


void LivePathEffectEditor::selectionChanged(Inkscape::Selection * selection)
{
    selection_changed_lock = true;
    lpe_list_locked = false;
    onSelectionChanged(selection);
    _on_button_release(nullptr); //to force update widgets
    selection_changed_lock = false;
}

void LivePathEffectEditor::selectionModified(Inkscape::Selection * selection, guint flags)
{
    lpe_list_locked = false;
    onSelectionChanged(selection);
}

static void lpe_style_button(Gtk::Button& btn, char const* iconName)
{
    GtkWidget *child = sp_get_icon_image(iconName, GTK_ICON_SIZE_SMALL_TOOLBAR);
    gtk_widget_show( child );
    btn.add(*Gtk::manage(Glib::wrap(child)));
    btn.set_relief(Gtk::RELIEF_NONE);
}


/*
 * LivePathEffectEditor
 *
 * TRANSLATORS: this dialog is accessible via menu Path - Path Effect Editor...
 *
 */

LivePathEffectEditor::LivePathEffectEditor()
    : DialogBase("/dialogs/livepatheffect", "LivePathEffect")
    , lpe_list_locked(false)
    , effectwidget(nullptr)
    , status_label("", Gtk::ALIGN_CENTER)
    , effectcontrol_frame("")
    , button_add()
    , button_remove()
    , button_original()
    , button_up()
    , button_down()
    , current_lpeitem(nullptr)
    , current_lperef(nullptr)
    , effectcontrol_vbox(Gtk::ORIENTATION_VERTICAL)
    , effectlist_vbox(Gtk::ORIENTATION_VERTICAL)
    , effectapplication_hbox(Gtk::ORIENTATION_HORIZONTAL, 4)
{
    set_spacing(4);

    //Add the TreeView, inside a ScrolledWindow, with the button underneath:
    scrolled_window.add(effectlist_view);
    scrolled_window.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
    scrolled_window.set_shadow_type(Gtk::SHADOW_IN);
    scrolled_window.set_size_request(210, 70);
    fix_inner_scroll(&scrolled_window);

    effectcontrol_vbox.set_spacing(4);

    effectlist_vbox.pack_start(scrolled_window, Gtk::PACK_EXPAND_WIDGET);
    effectlist_vbox.pack_end(toolbar_hbox, Gtk::PACK_SHRINK);
    effectcontrol_eventbox.add_events(Gdk::BUTTON_RELEASE_MASK);
    effectcontrol_eventbox.signal_button_release_event().connect(sigc::mem_fun(*this, &LivePathEffectEditor::_on_button_release) );
    effectcontrol_eventbox.add(effectcontrol_vbox);
    effectcontrol_frame.add(effectcontrol_eventbox);

    button_add.set_tooltip_text(_("Add path effect"));
    lpe_style_button(button_add, INKSCAPE_ICON("list-add"));
    button_add.set_relief(Gtk::RELIEF_NONE);

    button_remove.set_tooltip_text(_("Delete current path effect"));
    lpe_style_button(button_remove, INKSCAPE_ICON("list-remove"));
    button_remove.set_relief(Gtk::RELIEF_NONE);

    button_original.set_tooltip_text(_("Select origin item"));
    lpe_style_button(button_original, INKSCAPE_ICON("clone-original"));
    button_original.set_relief(Gtk::RELIEF_NONE);

    button_up.set_tooltip_text(_("Raise the current path effect"));
    lpe_style_button(button_up, INKSCAPE_ICON("go-up"));
    button_up.set_relief(Gtk::RELIEF_NONE);

    button_down.set_tooltip_text(_("Lower the current path effect"));
    lpe_style_button(button_down, INKSCAPE_ICON("go-down"));
    button_down.set_relief(Gtk::RELIEF_NONE);

    // Add toolbar items to toolbar
    toolbar_hbox.set_layout (Gtk::BUTTONBOX_END);
    toolbar_hbox.add( button_add );
    toolbar_hbox.set_child_secondary( button_add , true);
    toolbar_hbox.add( button_remove );
    toolbar_hbox.set_child_secondary( button_remove , true);
    toolbar_hbox.add(button_original);
    toolbar_hbox.add( button_up );
    toolbar_hbox.add( button_down );
    toolbar_hbox.set_child_non_homogeneous (button_add,true);
    toolbar_hbox.set_child_non_homogeneous (button_remove,true);
    toolbar_hbox.set_child_non_homogeneous (button_up,true);
    toolbar_hbox.set_child_non_homogeneous (button_down,true);
    toolbar_hbox.set_child_non_homogeneous(button_original, true);

    //Create the Tree model:
    effectlist_store = Gtk::ListStore::create(columns);
    effectlist_view.set_model(effectlist_store);
    effectlist_view.set_headers_visible(false);

    // Handle tree selections
    effectlist_selection = effectlist_view.get_selection();
    effectlist_selection->signal_changed().connect( sigc::mem_fun(*this, &LivePathEffectEditor::on_effect_selection_changed) );

    //Add the visibility icon column:
    Inkscape::UI::Widget::ImageToggler *eyeRenderer = Gtk::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;
    Gtk::TreeViewColumn* col = effectlist_view.get_column(visibleColNum);
    if ( col ) {
        col->add_attribute( eyeRenderer->property_active(), columns.col_visible );
    }

    //Add the effect name column:
    effectlist_view.append_column("Effect", columns.col_name);

    pack_start(effectlist_vbox, true, true);
    pack_start(status_label, false, false);
    pack_start(effectcontrol_frame, false, false);

    effectcontrol_frame.hide();
    selection_changed_lock = false;
    // connect callback functions to buttons
    button_add.signal_clicked().connect(sigc::mem_fun(*this, &LivePathEffectEditor::onAdd));
    button_remove.signal_clicked().connect(sigc::mem_fun(*this, &LivePathEffectEditor::onRemove));
    button_original.signal_clicked().connect(sigc::mem_fun(*this, &LivePathEffectEditor::onOriginal));
    button_up.signal_clicked().connect(sigc::mem_fun(*this, &LivePathEffectEditor::onUp));
    button_down.signal_clicked().connect(sigc::mem_fun(*this, &LivePathEffectEditor::onDown));

    show_all_children();
}

LivePathEffectEditor::~LivePathEffectEditor()
{
    if (effectwidget) {
        effectcontrol_vbox.remove(*effectwidget);
        delete effectwidget;
        effectwidget = nullptr;
    }
}

bool LivePathEffectEditor::_on_button_release(GdkEventButton* button_event) {
    Glib::RefPtr<Gtk::TreeSelection> sel = effectlist_view.get_selection();
    if (sel->count_selected_rows () == 0) {
        return true;
    }
    Gtk::TreeModel::iterator it = sel->get_selected();
    std::shared_ptr<LivePathEffect::LPEObjectReference> lperef = (*it)[columns.lperef];
    if (lperef && current_lpeitem && current_lperef != lperef) {
        if (lperef->getObject()) {
            LivePathEffect::Effect * effect = lperef->lpeobject->get_lpe();
            if (effect) {
                effect->refresh_widgets = true;
                showParams(*effect);
            }
        }
    }
    return true;
}

void
LivePathEffectEditor::showParams(LivePathEffect::Effect& effect)
{
    if (effectwidget && !effect.refresh_widgets) {
        return;
    }
    if (effectwidget) {
        effectcontrol_vbox.remove(*effectwidget);
        delete effectwidget;
        effectwidget = nullptr;
    }
    effectwidget = effect.newWidget();
    effectcontrol_frame.set_label(effect.getName());
    effectcontrol_vbox.pack_start(*effectwidget, true, true);

    button_remove.show();
    status_label.hide();
    effectcontrol_frame.show();
    effectcontrol_vbox.show_all_children();
    // fixme: add resizing of dialog
    effect.refresh_widgets = false;
}

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()) {
            effectlist_view.get_selection()->select(ci);
            break;
        }
    }
}


void
LivePathEffectEditor::showText(Glib::ustring const &str)
{
    if (effectwidget) {
        effectcontrol_vbox.remove(*effectwidget);
        delete effectwidget;
        effectwidget = nullptr;
    }

    status_label.show();
    status_label.set_label(str);

    effectcontrol_frame.hide();

    // fixme: do resizing of dialog ?
}

void
LivePathEffectEditor::set_sensitize_all(bool sensitive)
{
    //combo_effecttype.set_sensitive(sensitive);
    button_add.set_sensitive(sensitive);
    button_remove.set_sensitive(sensitive);
    effectlist_view.set_sensitive(sensitive);
    button_up.set_sensitive(sensitive);
    button_down.set_sensitive(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;
    }
    current_lpeitem = nullptr;
    effectlist_store->clear();
    button_original.set_sensitive(false);
    if ( sel && !sel->isEmpty() ) {
        SPItem *item = sel->singleItem();
        if ( item ) {
            button_original.set_sensitive(true);
            SPLPEItem *lpeitem = dynamic_cast<SPLPEItem *>(item);
            if ( lpeitem ) {
                effect_list_reload(lpeitem);
                current_lpeitem = lpeitem;
                set_sensitize_all(true);
                if ( lpeitem->hasPathEffect() ) {
                    Inkscape::LivePathEffect::Effect *lpe = lpeitem->getCurrentLPE();
                    if (lpe) {
                        showParams(*lpe);
                        lpe_list_locked = true;
                        selectInList(lpe);
                    } else {
                        showText(_("Unknown effect is applied"));
                    }
                } else {
                    showText(_("Click button to add an effect"));
                    button_remove.set_sensitive(false);
                    button_up.set_sensitive(false);
                    button_down.set_sensitive(false);
                }
            } else {
                SPUse *use = dynamic_cast<SPUse *>(item);
                if (use) {
                    // test whether linked object is supported by the CLONE_ORIGINAL LPE
                    SPItem *root = use->root();
                    SPItem *orig = use->get_original();
                    if (dynamic_cast<SPSymbol *>(root)) {
                        showText(_("Path effect cannot be applied to symbols"));
                        set_sensitize_all(false);
                    } else if (dynamic_cast<SPShape *>(orig) || dynamic_cast<SPGroup *>(orig) ||
                               dynamic_cast<SPText *>(orig)) {
                        // Note that an SP_USE cannot have an LPE applied, so we only need to worry about the "add
                        // effect" case.
                        set_sensitize_all(true);
                        showText(_("Click add button to convert clone"));
                        button_remove.set_sensitive(false);
                        button_up.set_sensitive(false);
                        button_down.set_sensitive(false);
                    } else {
                        showText(_("Select a path or shape"));
                        set_sensitize_all(false);
                    }
                } else {
                    showText(_("Select a path or shape"));
                    set_sensitize_all(false);
                }
            }
        } else {
            showText(_("Only one item can be selected"));
            set_sensitize_all(false);
        }
    } else {
        showText(_("Select a path or shape"));
        set_sensitize_all(false);
    }
}

/*
 * First clears the effectlist_store, then appends all effects from the effectlist.
 */
void
LivePathEffectEditor::effect_list_reload(SPLPEItem *lpeitem)
{
    effectlist_store->clear();

    PathEffectList effectlist = lpeitem->getEffectList();
    PathEffectList::iterator it;
    for( it = effectlist.begin() ; it!=effectlist.end(); ++it)
    {
        if ( !(*it)->lpeobject ) {
            continue;
        }

        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;
        }
    }
}

/*########################################################################
# BUTTON CLICK HANDLERS    (callbacks)
########################################################################*/

// TODO:  factor out the effect applying code which can be called from anywhere. (selection-chemistry.cpp also needs it)
void LivePathEffectEditor::onAdd()
{
    auto selection = getSelection();
    if (selection && !selection->isEmpty() ) {
        SPItem *item = selection->singleItem();
        if (item) {
            if ( dynamic_cast<SPLPEItem *>(item) ) {
                // show effectlist dialog
                using Inkscape::UI::Dialog::LivePathEffectAdd;
                LivePathEffectAdd::show(getDesktop());
                if ( !LivePathEffectAdd::isApplied()) {
                    return;
                }

                const LivePathEffect::EnumEffectData<LivePathEffect::EffectType> *data =
                    LivePathEffectAdd::getActiveData();
                if (!data) {
                    return;
                }
                item = selection->singleItem(); // get new item

                LivePathEffect::Effect::createAndApply(data->key.c_str(), getDocument(), item);
                DocumentUndo::done(getDocument(), _("Create and apply path effect"), INKSCAPE_ICON("dialog-path-effects"));

                lpe_list_locked = false;
                onSelectionChanged(selection);
            } else {
                SPUse *use = dynamic_cast<SPUse *>(item);
                if ( use ) {
                    // item is a clone. do not show effectlist dialog.
                    // convert to path, apply CLONE_ORIGINAL LPE, link it to the cloned path

                    // test whether linked object is supported by the CLONE_ORIGINAL LPE
                    SPItem *orig = use->get_original();
                    if ( dynamic_cast<SPShape *>(orig) ||
                         dynamic_cast<SPGroup *>(orig) ||
                         dynamic_cast<SPText *>(orig) )
                    {
                        // select original
                        selection->set(orig);

                        // delete clone but remember its id and transform
                        gchar *id = g_strdup(item->getAttribute("id"));
                        gchar *transform = g_strdup(item->getAttribute("transform"));
                        item->deleteObject(false);
                        item = nullptr;

                        // run sp_selection_clone_original_path_lpe
                        selection->cloneOriginalPathLPE(true);

                        SPItem *new_item = selection->singleItem();
                        // Check that the cloning was successful. We don't want to change the ID of the original referenced path!
                        if (new_item && (new_item != orig)) {
                            new_item->setAttribute("id", id);
                            if (transform) {
                                Geom::Affine item_t(Geom::identity());
                                sp_svg_transform_read(transform, &item_t);
                                new_item->transform *= item_t;
                                new_item->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
                            }
                            new_item->setAttribute("class", "fromclone");
                        }
                        g_free(id);
                        g_free(transform);

                        /// \todo Add the LPE stack of the original path?

                        DocumentUndo::done(getDocument(), _("Create and apply Clone original path effect"), INKSCAPE_ICON("dialog-path-effects"));

                        lpe_list_locked = false;
                        onSelectionChanged(selection);
                    }
                }
            }
        }
    }
}

void
LivePathEffectEditor::onRemove()
{
    auto selection = getSelection();
    if (selection && !selection->isEmpty() ) {
        SPItem *item = selection->singleItem();
        SPLPEItem *lpeitem  = dynamic_cast<SPLPEItem *>(item);
        if (lpeitem) {
            sp_lpe_item_update_patheffect(lpeitem, false, false);
            lpeitem->removeCurrentPathEffect(false);
            current_lperef = nullptr;
            DocumentUndo::done(getDocument(), _("Remove path effect"), INKSCAPE_ICON("dialog-path-effects"));
            lpe_list_locked = false;
            onSelectionChanged(selection);
        }
    }

}

gboolean removeselectclass(gpointer data)
{
    SPItem *item = reinterpret_cast<SPItem *>(data);
    const gchar *classitem = item->getAttribute("class");
    if (classitem) {
        Glib::ustring classtoparent = classitem;
        classtoparent.erase(classtoparent.find("lpeselectparent "), 16);
        if (classtoparent.empty()) {
            item->setAttribute("class", nullptr);
        } else {
            item->setAttribute("class", classtoparent.c_str());
        }
    }
    return FALSE;
}

void LivePathEffectEditor::onOriginal()
{
    auto selection = getSelection();
    if (selection && !selection->isEmpty()) {
        if (SPItem *item = selection->singleItem()) {
            const gchar *classtoparentchar = item->getAttribute("class");
            Glib::ustring classtoparent = "lpeselectparent ";
            if (classtoparentchar) {
                classtoparent += classtoparentchar;
            }
            // here we fire a update and the lpe original check for this class and select
            item->setAttribute("class", classtoparent.c_str());
            selection->set(item);
            g_timeout_add(100, &removeselectclass, item);
        }
    }
}

void LivePathEffectEditor::onUp()
{
    auto selection = getSelection();
    if (selection && !selection->isEmpty() ) {
        SPItem *item = selection->singleItem();
        SPLPEItem *lpeitem = dynamic_cast<SPLPEItem *>(item);
        if (lpeitem) {
            Inkscape::LivePathEffect::Effect *lpe = lpeitem->getCurrentLPE();
            lpeitem->upCurrentPathEffect();
            DocumentUndo::done(getDocument(), _("Move path effect up"), INKSCAPE_ICON("dialog-path-effects"));
            effect_list_reload(lpeitem);
            if (lpe) {
                showParams(*lpe);
                lpe_list_locked = true;
                selectInList(lpe);
            }
        }
    }
}

void LivePathEffectEditor::onDown()
{
    auto selection = getSelection();
    if (selection && !selection->isEmpty() ) {
        SPItem *item = selection->singleItem();
        SPLPEItem *lpeitem = dynamic_cast<SPLPEItem *>(item);
        if ( lpeitem ) {
            Inkscape::LivePathEffect::Effect *lpe = lpeitem->getCurrentLPE();
            lpeitem->downCurrentPathEffect();
            DocumentUndo::done(getDocument(), _("Move path effect down"), INKSCAPE_ICON("dialog-path-effects"));
            effect_list_reload(lpeitem);
            if (lpe) {
                showParams(*lpe);
                lpe_list_locked = true;
                selectInList(lpe);
            }
        }
    }
}

void LivePathEffectEditor::on_effect_selection_changed()
{
    Glib::RefPtr<Gtk::TreeSelection> sel = effectlist_view.get_selection();
    if (sel->count_selected_rows () == 0) {
        button_remove.set_sensitive(false);
        return;
    }
    button_remove.set_sensitive(true);
    Gtk::TreeModel::iterator it = sel->get_selected();
    std::shared_ptr<LivePathEffect::LPEObjectReference> lperef = (*it)[columns.lperef];

    if (lperef && current_lpeitem && current_lperef != lperef) {
        // The last condition ignore Gtk::TreeModel may occasionally be changed emitted when nothing has happened
        if (current_lpeitem->pathEffectsEnabled() && lperef->getObject()) {
            lpe_list_locked = true; // prevent reload of the list which would lose selection
            current_lpeitem->setCurrentPathEffect(lperef);
            current_lperef = lperef;
            LivePathEffect::Effect * effect = lperef->lpeobject->get_lpe();
            if (effect) {
                effect->refresh_widgets = true;
                showParams(*effect);
                // To reload knots and helper paths
                auto selection = getSelection();
                if (selection && !selection->isEmpty() && !selection_changed_lock) {
                    SPLPEItem *lpeitem = dynamic_cast<SPLPEItem *>(selection->singleItem());
                    if (lpeitem) {
                        // this is need because set dont update selected LPE knots
                        selection->clear();
                        selection->add(lpeitem);
                        Inkscape::UI::Tools::sp_update_helperpath(getDesktop());
                    }
                }
            }
        }
    }
}

void LivePathEffectEditor::on_visibility_toggled( Glib::ustring const& str )
{

    Gtk::TreeModel::Children::iterator iter = effectlist_view.get_model()->get_iter(str);
    Gtk::TreeModel::Row row = *iter;

    std::shared_ptr<LivePathEffect::LPEObjectReference> lpeobjref = row[columns.lperef];

    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->get_lpe()->getRepr()->setAttribute("is_visible", newValue ? "true" : "false");
        auto selection = getSelection();
        if (selection && !selection->isEmpty() ) {
            SPItem *item = selection->singleItem();
            SPLPEItem *lpeitem  = dynamic_cast<SPLPEItem *>(item);
            if ( lpeitem ) {
                lpeobjref->lpeobject->get_lpe()->doOnVisibilityToggled(lpeitem);
            }
        }
        DocumentUndo::done(getDocument(), newValue ? _("Activate path effect") : _("Deactivate path effect"), INKSCAPE_ICON("dialog-path-effects"));
    }
}

} // namespace Dialog
} // namespace UI
} // namespace Inkscape

/*
  Local Variables:
  mode:c++
  c-file-style:"stroustrup"
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
  indent-tabs-mode:nil
  fill-column:99
  End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :