Adding Objects to Selector (Part 2)

Any changes in the Style Dialog like adding an object to a selector must be updated in XML representation of the drawing. Clicking ‘+’ in front of a selector adds objects to that selector.

If the selector to which object is added is a class selector, then the class attribute of the object is set to the selector name. The screenshot below shows this:

Screenshot from 2016-07-27 12:10:58

If the object is deleted by clicking ‘-‘ in front of its row, then the class attribute that was set due to the selector is unset.

Screenshot from 2016-07-27 12:11:19

This is implemented in _handleButtonEvent(GdkEventButton event). Whenever first column of the selector row that is a ‘+’ is clicked, the _desktop is checked for selection. If it is not empty, those objects are added to selector. Rows are added with their content set as:

childrow =
childrow[_mColumns._selectorLabel] = "#" + std::string(obj->getId());
childrow[_mColumns._colAddRemove] = false;
childrow[_mColumns._colObj] = _desktop->selection->list();

Finally, _styleChild i.e. the style element is obtained and _updateStyleContent() is called to update the XML representation.

Just deletion from treeview

Moving on from adding a selector to the style dialog, my next step is to delete a selector from the selector as well as from the XML representation of the document. Following the approach to get the selection from the treeview, get_selection() is used to obtain the selected row which is then iterated using get_selected().

If the iterator exists, the corresponding row is deleted from the treeview using erase(). Deletion from XML representation is challenging. I tokenized the selector value altogether and compared the first token which is the name of the selector to the selector selected in treeview. If these two are equal, then the corresponding style node is deleted from XML representation.

However, I ended up in a crash of Inkscape while deleting the style node, so currently all it deletes is the row from treeview.