From 46bff7b31a99784086c5f5589956e647c862e944 Mon Sep 17 00:00:00 2001 From: kamalpreetgrewal Date: Sat, 4 Jun 2016 20:02:59 +0530 Subject: Register style dialog with support to add selector (bzr r14949.1.1) --- src/menus-skeleton.h | 1 + src/ui/CMakeLists.txt | 2 + src/ui/dialog/dialog-manager.cpp | 3 ++ src/ui/dialog/styledialog.cpp | 113 +++++++++++++++++++++++++++++++++++++++ src/ui/dialog/styledialog.h | 69 ++++++++++++++++++++++++ src/verbs.cpp | 5 ++ src/verbs.h | 1 + 7 files changed, 194 insertions(+) create mode 100644 src/ui/dialog/styledialog.cpp create mode 100644 src/ui/dialog/styledialog.h (limited to 'src') diff --git a/src/menus-skeleton.h b/src/menus-skeleton.h index 9c7c65140..9b8586ec2 100644 --- a/src/menus-skeleton.h +++ b/src/menus-skeleton.h @@ -183,6 +183,7 @@ static char const menus_skeleton[] = " \n" " \n" " \n" +" \n" " \n" " \n" " \n" diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index 587974b90..4be3fa3d2 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -99,6 +99,7 @@ set(ui_SRC dialog/print-colors-preview-dialog.cpp dialog/print.cpp dialog/spellcheck.cpp + dialog/styledialog.cpp dialog/svg-fonts-dialog.cpp dialog/swatches.cpp dialog/symbols.cpp @@ -240,6 +241,7 @@ set(ui_SRC dialog/print-colors-preview-dialog.h dialog/print.h dialog/spellcheck.h + dialog/styledialog.h dialog/svg-fonts-dialog.h dialog/swatches.h dialog/symbols.h diff --git a/src/ui/dialog/dialog-manager.cpp b/src/ui/dialog/dialog-manager.cpp index 49853277c..4bb5215fd 100644 --- a/src/ui/dialog/dialog-manager.cpp +++ b/src/ui/dialog/dialog-manager.cpp @@ -60,6 +60,7 @@ #include "ui/dialog/svg-fonts-dialog.h" #include "ui/dialog/objects.h" #include "ui/dialog/tags.h" +#include "ui/dialog/styledialog.h" namespace Inkscape { namespace UI { @@ -128,6 +129,7 @@ DialogManager::DialogManager() { registerFactory("Swatches", &create); registerFactory("TileDialog", &create); registerFactory("Symbols", &create); + registerFactory("StyleDialog", &create); #if HAVE_POTRACE registerFactory("Trace", &create); @@ -167,6 +169,7 @@ DialogManager::DialogManager() { registerFactory("Swatches", &create); registerFactory("TileDialog", &create); registerFactory("Symbols", &create); + registerFactory("StyleDialog", &create); #if HAVE_POTRACE registerFactory("Trace", &create); diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp new file mode 100644 index 000000000..7e555ddb2 --- /dev/null +++ b/src/ui/dialog/styledialog.cpp @@ -0,0 +1,113 @@ +#include "styledialog.h" +#include "widgets/icon.h" +#include "verbs.h" +#include "sp-object.h" +#include "selection.h" + +namespace Inkscape { +namespace UI { +namespace Dialog { + +void StyleDialog::_styleButton(Gtk::Button& btn, char const* iconName, + char const* tooltip) +{ + GtkWidget *child = sp_icon_new(Inkscape::ICON_SIZE_SMALL_TOOLBAR, iconName); + gtk_widget_show(child); + btn.add(*manage(Glib::wrap(child))); + btn.set_relief(Gtk::RELIEF_NONE); + btn.set_tooltip_text (tooltip); +} + +/** + * Constructor + * A treeview and a set of two buttons are added to the dialog. _addSelector + * adds selectors to treeview. Currently, delete button is disabled. + */ +StyleDialog::StyleDialog() : + UI::Widget::Panel("", "/dialogs/style", SP_VERB_DIALOG_STYLE), + _desktop(0) +{ + set_size_request(200, 200); + add(_mainBox); + + _mainBox.pack_start(_scrolledWindow, Gtk::PACK_EXPAND_WIDGET); + _treeView.set_headers_visible(false); + _scrolledWindow.add(_treeView); + _scrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); + + _store = Gtk::ListStore::create(_mColumns); + _treeView.set_model(_store); + _treeView.append_column("Selector Number", _mColumns._selectorNumber); + _treeView.append_column("Selector Name", _mColumns._selectorLabel); + + Gtk::Button* create = manage( new Gtk::Button() ); + _styleButton(*create, "list-add", "Add a new CSS Selector"); + create->signal_clicked().connect(sigc::mem_fun(*this, + &StyleDialog::_addSelector)); + + Gtk::Button* del = manage( new Gtk::Button() ); + _styleButton(*del, "list-remove", "Remove a CSS Selector"); + del->set_sensitive(false); + + _mainBox.pack_start(_buttonBox, Gtk::PACK_SHRINK); + _buttonBox.pack_start(*create, Gtk::PACK_SHRINK); + _buttonBox.pack_start(*del, Gtk::PACK_SHRINK); + + SPDesktop* targetDesktop = getDesktop(); + setDesktop(targetDesktop); +} + +StyleDialog::~StyleDialog() +{ + setDesktop(NULL); +} + +void StyleDialog::setDesktop( SPDesktop* desktop ) +{ + Panel::setDesktop(desktop); + _desktop = Panel::getDesktop(); +} + +void StyleDialog::_addSelector() +{ + Gtk::TreeModel::Row row = *(_store->append()); + + /** + * On clicking '+' button, an entrybox with default text opens up. If an + * object is already selected, 'class' attribute with value in the entry + * is added to the selected object. + */ + Gtk::Dialog *textDialogPtr = new Gtk::Dialog(); + Gtk::Entry *textEditPtr = manage ( new Gtk::Entry() ); + textDialogPtr->add_button("Add", Gtk::RESPONSE_OK); + textDialogPtr->get_vbox()->pack_start(*textEditPtr, Gtk::PACK_SHRINK); + textEditPtr->set_text("Class1"); + + textDialogPtr->set_size_request(200, 100); + textDialogPtr->show_all(); + int result = textDialogPtr->run(); + static int number = 1; + + switch (result) { + case Gtk::RESPONSE_OK: + textDialogPtr->hide(); + row[_mColumns._selectorNumber] = number; + row[_mColumns._selectorLabel] = textEditPtr->get_text(); + number++; + break; + default: + break; + } + + if (_desktop->selection) { + std::vector selected = _desktop->getSelection()->list(); + for (int i = 0; i < selected.size(); ++i ) { + SPObject *obj = selected.at(i); + obj->setAttribute("class", textEditPtr->get_text()); + } + } +} + +} // namespace Dialog +} // namespace UI +} // namespace Inkscape diff --git a/src/ui/dialog/styledialog.h b/src/ui/dialog/styledialog.h new file mode 100644 index 000000000..044737add --- /dev/null +++ b/src/ui/dialog/styledialog.h @@ -0,0 +1,69 @@ +/** @file + * @brief A dialog for CSS selectors + */ +/* Authors: + * Kamalpreet Kaur Grewal + * + * Copyright (C) Kamalpreet Kaur Grewal 2016 + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#ifndef STYLEDIALOG_H +#define STYLEDIALOG_H + +#include +#include +#include +#include +#include + +#include "desktop.h" + +namespace Inkscape { +namespace UI { +namespace Dialog { + +/** + * @brief The StyleDialog class + * A list of CSS selectors will show up in this dialog. + */ + +class StyleDialog : public UI::Widget::Panel +{ +public: + StyleDialog(); + ~StyleDialog(); + + static StyleDialog &getInstance() { return *new StyleDialog(); } + void setDesktop( SPDesktop* desktop); + +private: + void _styleButton( Gtk::Button& btn, char const* iconName, char const* tooltip); + + class ModelColumns : public Gtk::TreeModel::ColumnRecord + { + public: + ModelColumns() + { add(_selectorNumber); add(_selectorLabel); } + Gtk::TreeModelColumn _selectorNumber; + Gtk::TreeModelColumn _selectorLabel; + }; + + SPDesktop* _desktop; + ModelColumns _mColumns; + Gtk::VBox _mainBox; + Gtk::HBox _buttonBox; + Gtk::TreeView _treeView; + Glib::RefPtr _store; + Gtk::ScrolledWindow _scrolledWindow; + + // Signal handlers + void _addSelector(); +}; + +} // namespace Dialog +} // namespace UI +} // namespace Inkscape + +#endif // STYLEDIALOG_H diff --git a/src/verbs.cpp b/src/verbs.cpp index 299cfe8e7..2908ae580 100644 --- a/src/verbs.cpp +++ b/src/verbs.cpp @@ -2119,6 +2119,9 @@ void DialogVerb::perform(SPAction *action, void *data) case SP_VERB_DIALOG_PRINT_COLORS_PREVIEW: dt->_dlg_mgr->showDialog("PrintColorsPreviewDialog"); break; + case SP_VERB_DIALOG_STYLE: + dt->_dlg_mgr->showDialog("StyleDialog"); + break; default: break; @@ -2949,6 +2952,8 @@ Verb *Verb::_base_verbs[] = { N_("View Objects"), INKSCAPE_ICON("dialog-layers")), new DialogVerb(SP_VERB_DIALOG_TAGS, "DialogTags", N_("Selection se_ts..."), N_("View Tags"), INKSCAPE_ICON("edit-select-all-layers")), + new DialogVerb(SP_VERB_DIALOG_STYLE, "DialogStyle", N_("Style Dialog..."), + N_("View Style Dialog"), NULL), new DialogVerb(SP_VERB_DIALOG_LIVE_PATH_EFFECT, "DialogLivePathEffect", N_("Path E_ffects ..."), N_("Manage, edit, and apply path effects"), INKSCAPE_ICON("dialog-path-effects")), new DialogVerb(SP_VERB_DIALOG_FILTER_EFFECTS, "DialogFilterEffects", N_("Filter _Editor..."), diff --git a/src/verbs.h b/src/verbs.h index ffb9b23d8..35a9ca738 100644 --- a/src/verbs.h +++ b/src/verbs.h @@ -308,6 +308,7 @@ enum { SP_VERB_DIALOG_LAYERS, SP_VERB_DIALOG_OBJECTS, SP_VERB_DIALOG_TAGS, + SP_VERB_DIALOG_STYLE, SP_VERB_DIALOG_LIVE_PATH_EFFECT, SP_VERB_DIALOG_FILTER_EFFECTS, SP_VERB_DIALOG_SVG_FONTS, -- cgit v1.2.3 From 8970301df8e29722a113e20295239c64e070d0d7 Mon Sep 17 00:00:00 2001 From: kamalpreetgrewal Date: Mon, 6 Jun 2016 22:50:06 +0530 Subject: Set class attribute values of selected objects using style dialog (bzr r14949.1.3) --- src/ui/dialog/styledialog.cpp | 71 +++++++++++++++++++++++++++++++++++++++++-- src/ui/dialog/styledialog.h | 1 + 2 files changed, 70 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index 7e555ddb2..6681a7c56 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -1,3 +1,14 @@ +/** @file + * @brief A dialog for CSS selectors + */ +/* Authors: + * Kamalpreet Kaur Grewal + * + * Copyright (C) Kamalpreet Kaur Grewal 2016 + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + #include "styledialog.h" #include "widgets/icon.h" #include "verbs.h" @@ -8,6 +19,13 @@ namespace Inkscape { namespace UI { namespace Dialog { +/** + * @brief StyleDialog::_styleButton + * @param btn + * @param iconName + * @param tooltip + * This function sets the style of '+' and '-' buttons at the bottom of dialog. + */ void StyleDialog::_styleButton(Gtk::Button& btn, char const* iconName, char const* tooltip) { @@ -68,6 +86,11 @@ void StyleDialog::setDesktop( SPDesktop* desktop ) _desktop = Panel::getDesktop(); } +/** + * @brief StyleDialog::_addSelector + * This function is the slot to the signal emitted when '+' at the bottom of + * the dialog is clicked. + */ void StyleDialog::_addSelector() { Gtk::TreeModel::Row row = *(_store->append()); @@ -81,7 +104,18 @@ void StyleDialog::_addSelector() Gtk::Entry *textEditPtr = manage ( new Gtk::Entry() ); textDialogPtr->add_button("Add", Gtk::RESPONSE_OK); textDialogPtr->get_vbox()->pack_start(*textEditPtr, Gtk::PACK_SHRINK); - textEditPtr->set_text("Class1"); + + /** + * By default, the entrybox contains 'Class1' as text. However, if object(s) + * is(are) selected and user clicks '+' at the bottom of dialog, the + * entrybox will have the id(s) of the selected objects as text. + */ + if (_desktop->selection->isEmpty()) + textEditPtr->set_text("Class1"); + else { + std::vector selected = _desktop->getSelection()->list(); + textEditPtr->set_text(_setClassAttribute(selected)); + } textDialogPtr->set_size_request(200, 100); textDialogPtr->show_all(); @@ -99,15 +133,48 @@ void StyleDialog::_addSelector() break; } + /** + * The 'class' attribute of the selected objects is set to the text that + * the user sets in the entrybox. If the attribute does not exist, it is + * created. In case the attribute already has a value, the new value entered + * is appended to the values. + */ if (_desktop->selection) { std::vector selected = _desktop->getSelection()->list(); for (int i = 0; i < selected.size(); ++i ) { SPObject *obj = selected.at(i); - obj->setAttribute("class", textEditPtr->get_text()); + const char *classExists = obj->getAttribute("class"); + + if (classExists) { + if (strlen(classExists) == 0) + obj->setAttribute("class", textEditPtr->get_text()); + else + obj->setAttribute("class", std::string(classExists) + " " + + textEditPtr->get_text()); + } + else { + obj->setAttribute("class", textEditPtr->get_text()); + } } } } +/** + * @brief StyleDialog::_setClassAttribute + * @param sel + * @return This function returns the ids of objects selected which are passed + * to entrybox. + */ +std::string StyleDialog::_setClassAttribute(std::vector sel) +{ + std::string str = ""; + for (int i = 0; i < sel.size(); ++i ) { + SPObject *obj = sel.at(i); + str = str + " " + std::string(obj->getId()); + } + return str; +} + } // namespace Dialog } // namespace UI } // namespace Inkscape diff --git a/src/ui/dialog/styledialog.h b/src/ui/dialog/styledialog.h index 044737add..281585d9d 100644 --- a/src/ui/dialog/styledialog.h +++ b/src/ui/dialog/styledialog.h @@ -40,6 +40,7 @@ public: private: void _styleButton( Gtk::Button& btn, char const* iconName, char const* tooltip); + std::string _setClassAttribute(std::vector); class ModelColumns : public Gtk::TreeModel::ColumnRecord { -- cgit v1.2.3 From d05e7ac156a8dedc0e80390a80edaa90b6260a4c Mon Sep 17 00:00:00 2001 From: kamalpreetgrewal Date: Fri, 10 Jun 2016 14:10:53 +0530 Subject: Add selector to style element (bzr r14949.1.5) --- src/ui/dialog/styledialog.cpp | 100 +++++++++++++++++++++++++++++++++--------- src/ui/dialog/styledialog.h | 2 + 2 files changed, 81 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index 6681a7c56..992e75285 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -14,6 +14,10 @@ #include "verbs.h" #include "sp-object.h" #include "selection.h" +#include "xml/attribute-record.h" + +using Inkscape::Util::List; +using Inkscape::XML::AttributeRecord; namespace Inkscape { namespace UI { @@ -97,8 +101,8 @@ void StyleDialog::_addSelector() /** * On clicking '+' button, an entrybox with default text opens up. If an - * object is already selected, 'class' attribute with value in the entry - * is added to the selected object. + * object is already selected, a selector with value in the entry + * is added to a new style element. */ Gtk::Dialog *textDialogPtr = new Gtk::Dialog(); Gtk::Entry *textEditPtr = manage ( new Gtk::Entry() ); @@ -110,7 +114,7 @@ void StyleDialog::_addSelector() * is(are) selected and user clicks '+' at the bottom of dialog, the * entrybox will have the id(s) of the selected objects as text. */ - if (_desktop->selection->isEmpty()) + if ( _desktop->selection->isEmpty() ) textEditPtr->set_text("Class1"); else { std::vector selected = _desktop->getSelection()->list(); @@ -120,13 +124,28 @@ void StyleDialog::_addSelector() textDialogPtr->set_size_request(200, 100); textDialogPtr->show_all(); int result = textDialogPtr->run(); + + /** + * @brief selectorName + * This string stores selector name. If '#' or a '.' is present in the + * beginning of string, text from entrybox is saved directly as name for + * selector. If text like 'red' is written in entrybox, it is prefixed + * with a dot. + */ + std::string selectorName = ""; + if ( textEditPtr->get_text().at(0) == '#' || + textEditPtr->get_text().at(0) == '.' ) + selectorName = textEditPtr->get_text(); + else + selectorName = "." + textEditPtr->get_text(); + static int number = 1; switch (result) { case Gtk::RESPONSE_OK: textDialogPtr->hide(); row[_mColumns._selectorNumber] = number; - row[_mColumns._selectorLabel] = textEditPtr->get_text(); + row[_mColumns._selectorLabel] = selectorName; number++; break; default: @@ -134,27 +153,49 @@ void StyleDialog::_addSelector() } /** - * The 'class' attribute of the selected objects is set to the text that - * the user sets in the entrybox. If the attribute does not exist, it is + * The selector name objects is set to the text that the user sets in the + * entrybox. If the attribute does not exist, it is * created. In case the attribute already has a value, the new value entered * is appended to the values. */ - if (_desktop->selection) { + if ( _desktop->selection ) { std::vector selected = _desktop->getSelection()->list(); - for (int i = 0; i < selected.size(); ++i ) { + std::string selectorValue; + for ( unsigned i = 0; i < selected.size(); ++i ) { SPObject *obj = selected.at(i); - const char *classExists = obj->getAttribute("class"); - - if (classExists) { - if (strlen(classExists) == 0) - obj->setAttribute("class", textEditPtr->get_text()); - else - obj->setAttribute("class", std::string(classExists) + " " + - textEditPtr->get_text()); - } - else { - obj->setAttribute("class", textEditPtr->get_text()); + + std::string style = std::string(obj->getRepr()->attribute("style")); + style = row[_mColumns._selectorLabel] + ";" + style; + + for ( List iter = obj->getRepr()->attributeList() ; + iter ; ++iter ) { + gchar const * property = g_quark_to_string(iter->key); + gchar const * value = iter->value; + + if ( std::string(property) == "style" ) + { + selectorValue = row[_mColumns._selectorLabel] + "{" + + "\n" + std::string(value) + "\n" + "}"; + } } + + /** + * @brief root + * A new style element is added to the document with value obtained + * from selectorValue above. + */ + Inkscape::XML::Node *root = obj->getRepr()->document()->root(); + Inkscape::XML::Node *newChild = obj->getRepr()->document() + ->createElement("svg:style"); + + Inkscape::XML::Node *smallChildren = obj->getRepr()->document() + ->createTextNode(selectorValue.c_str()); + + newChild->appendChild(smallChildren); + Inkscape::GC::release(smallChildren); + + root->addChild(newChild, NULL); + Inkscape::GC::release(newChild); } } } @@ -168,13 +209,30 @@ void StyleDialog::_addSelector() std::string StyleDialog::_setClassAttribute(std::vector sel) { std::string str = ""; - for (int i = 0; i < sel.size(); ++i ) { + for (unsigned i = 0; i < sel.size(); ++i) { SPObject *obj = sel.at(i); - str = str + " " + std::string(obj->getId()); + str = str + "#" + std::string(obj->getId()) + " "; } return str; } +/** + * @brief StyleDialog::_populateTree + * @param _selMap + * This function will populate the treeview with selectors available in the + * stylesheet. Not used yet. + */ +void StyleDialog::_populateTree(std::map _selMap) +{ + std::map _selectMap = _selMap; + + for(std::map::iterator it = _selectMap.begin(); + it != _selectMap.end(); ++it) { + Gtk::TreeModel::Row row = *(_store->append()); + row[_mColumns._selectorLabel] = it->first; + } +} + } // namespace Dialog } // namespace UI } // namespace Inkscape diff --git a/src/ui/dialog/styledialog.h b/src/ui/dialog/styledialog.h index 281585d9d..21c33ab6e 100644 --- a/src/ui/dialog/styledialog.h +++ b/src/ui/dialog/styledialog.h @@ -41,6 +41,8 @@ public: private: void _styleButton( Gtk::Button& btn, char const* iconName, char const* tooltip); std::string _setClassAttribute(std::vector); + std::map_selectorMap; + void _populateTree(std::map); class ModelColumns : public Gtk::TreeModel::ColumnRecord { -- cgit v1.2.3 From 0792b241079daea6c984d9fd6761b9bdfbe85455 Mon Sep 17 00:00:00 2001 From: kamalpreetgrewal Date: Fri, 10 Jun 2016 20:13:26 +0530 Subject: Populate style dialog with existing selectors in stylesheet (bzr r14949.1.7) --- src/ui/dialog/styledialog.cpp | 49 +++++++++++++++++++++++++++++++------------ src/ui/dialog/styledialog.h | 4 ++-- 2 files changed, 38 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index 992e75285..7a3dfeaff 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -59,7 +59,6 @@ StyleDialog::StyleDialog() : _store = Gtk::ListStore::create(_mColumns); _treeView.set_model(_store); - _treeView.append_column("Selector Number", _mColumns._selectorNumber); _treeView.append_column("Selector Name", _mColumns._selectorLabel); Gtk::Button* create = manage( new Gtk::Button() ); @@ -77,6 +76,32 @@ StyleDialog::StyleDialog() : SPDesktop* targetDesktop = getDesktop(); setDesktop(targetDesktop); + + /** + * @brief document + * If an existing document is opened, its XML representation is obtained + * and if it contains any style element with a style selector, the selector + * name and its value is extracted and saved to a map. This map is then used + * to populate the treeview with the already existing selectors. + */ + SPDocument * document = targetDesktop->doc(); + unsigned num = document->getReprRoot()->childCount(); + + std::string key, value; + std::map selMap; + + for ( unsigned i = 0; i < num; ++i ) + { + if ( std::string(document->getReprRoot()->nthChild(i)->name()) == "svg:style" ) + { + char *str = strdup(document->getReprRoot()->nthChild(i)->firstChild() + ->content()); + key = strtok(str, " "); + value = strtok(NULL, ""); + selMap[key] = value; + } + } + _populateTree(selMap); } StyleDialog::~StyleDialog() @@ -134,19 +159,15 @@ void StyleDialog::_addSelector() */ std::string selectorName = ""; if ( textEditPtr->get_text().at(0) == '#' || - textEditPtr->get_text().at(0) == '.' ) + textEditPtr->get_text().at(0) == '.' ) selectorName = textEditPtr->get_text(); else selectorName = "." + textEditPtr->get_text(); - static int number = 1; - switch (result) { case Gtk::RESPONSE_OK: textDialogPtr->hide(); - row[_mColumns._selectorNumber] = number; row[_mColumns._selectorLabel] = selectorName; - number++; break; default: break; @@ -167,8 +188,8 @@ void StyleDialog::_addSelector() std::string style = std::string(obj->getRepr()->attribute("style")); style = row[_mColumns._selectorLabel] + ";" + style; - for ( List iter = obj->getRepr()->attributeList() ; - iter ; ++iter ) { + for ( List iter = obj->getRepr()->attributeList(); + iter; ++iter ) { gchar const * property = g_quark_to_string(iter->key); gchar const * value = iter->value; @@ -196,6 +217,8 @@ void StyleDialog::_addSelector() root->addChild(newChild, NULL); Inkscape::GC::release(newChild); + + _selectorMap[selectorName] = selectorValue; } } } @@ -209,7 +232,7 @@ void StyleDialog::_addSelector() std::string StyleDialog::_setClassAttribute(std::vector sel) { std::string str = ""; - for (unsigned i = 0; i < sel.size(); ++i) { + for ( unsigned i = 0; i < sel.size(); ++i ) { SPObject *obj = sel.at(i); str = str + "#" + std::string(obj->getId()) + " "; } @@ -219,15 +242,15 @@ std::string StyleDialog::_setClassAttribute(std::vector sel) /** * @brief StyleDialog::_populateTree * @param _selMap - * This function will populate the treeview with selectors available in the - * stylesheet. Not used yet. + * This function populates the treeview with selectors available in the + * stylesheet. */ void StyleDialog::_populateTree(std::map _selMap) { std::map _selectMap = _selMap; - for(std::map::iterator it = _selectMap.begin(); - it != _selectMap.end(); ++it) { + for( std::map::iterator it = _selectMap.begin(); + it != _selectMap.end(); ++it ) { Gtk::TreeModel::Row row = *(_store->append()); row[_mColumns._selectorLabel] = it->first; } diff --git a/src/ui/dialog/styledialog.h b/src/ui/dialog/styledialog.h index 21c33ab6e..79ff41559 100644 --- a/src/ui/dialog/styledialog.h +++ b/src/ui/dialog/styledialog.h @@ -19,6 +19,7 @@ #include #include "desktop.h" +#include "document.h" namespace Inkscape { namespace UI { @@ -48,8 +49,7 @@ private: { public: ModelColumns() - { add(_selectorNumber); add(_selectorLabel); } - Gtk::TreeModelColumn _selectorNumber; + { add(_selectorLabel); } Gtk::TreeModelColumn _selectorLabel; }; -- cgit v1.2.3 From 3bbe3debb72ae45a17eaa0133f73d8bc37c55b7b Mon Sep 17 00:00:00 2001 From: kamalpreetgrewal Date: Sat, 11 Jun 2016 10:57:36 +0530 Subject: Apply patch for broken automake (bzr r14949.1.9) --- src/ui/dialog/Makefile_insert | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/ui/dialog/Makefile_insert b/src/ui/dialog/Makefile_insert index 71628973e..982908731 100644 --- a/src/ui/dialog/Makefile_insert +++ b/src/ui/dialog/Makefile_insert @@ -92,6 +92,8 @@ ink_common_sources += \ ui/dialog/print-colors-preview-dialog.h \ ui/dialog/spellcheck.cpp \ ui/dialog/spellcheck.h \ + ui/dialog/styledialog.cpp \ + ui/dialog/styledialog.h \ ui/dialog/svg-fonts-dialog.cpp \ ui/dialog/svg-fonts-dialog.h \ ui/dialog/swatches.cpp \ -- cgit v1.2.3 From 2e2712f1a6f1b31b18b40f9cffc58c8ef7b9198e Mon Sep 17 00:00:00 2001 From: kamalpreetgrewal Date: Sat, 11 Jun 2016 23:46:45 +0530 Subject: Delete selector from style dialog (not from repr yet) (bzr r14949.1.12) --- src/ui/dialog/styledialog.cpp | 115 +++++++++++++++++++++++++++++++++--------- src/ui/dialog/styledialog.h | 7 +++ 2 files changed, 97 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index 7a3dfeaff..14213f97d 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -61,47 +61,31 @@ StyleDialog::StyleDialog() : _treeView.set_model(_store); _treeView.append_column("Selector Name", _mColumns._selectorLabel); - Gtk::Button* create = manage( new Gtk::Button() ); + create = manage( new Gtk::Button() ); _styleButton(*create, "list-add", "Add a new CSS Selector"); create->signal_clicked().connect(sigc::mem_fun(*this, &StyleDialog::_addSelector)); - Gtk::Button* del = manage( new Gtk::Button() ); + del = manage( new Gtk::Button() ); _styleButton(*del, "list-remove", "Remove a CSS Selector"); + del->signal_clicked().connect(sigc::mem_fun(*this, + &StyleDialog::_delSelector)); del->set_sensitive(false); _mainBox.pack_start(_buttonBox, Gtk::PACK_SHRINK); _buttonBox.pack_start(*create, Gtk::PACK_SHRINK); _buttonBox.pack_start(*del, Gtk::PACK_SHRINK); - SPDesktop* targetDesktop = getDesktop(); - setDesktop(targetDesktop); + _targetDesktop = getDesktop(); + setDesktop(_targetDesktop); /** * @brief document * If an existing document is opened, its XML representation is obtained - * and if it contains any style element with a style selector, the selector - * name and its value is extracted and saved to a map. This map is then used - * to populate the treeview with the already existing selectors. + * and is then used to populate the treeview with the already existing + * selectors in the style element. */ - SPDocument * document = targetDesktop->doc(); - unsigned num = document->getReprRoot()->childCount(); - - std::string key, value; - std::map selMap; - - for ( unsigned i = 0; i < num; ++i ) - { - if ( std::string(document->getReprRoot()->nthChild(i)->name()) == "svg:style" ) - { - char *str = strdup(document->getReprRoot()->nthChild(i)->firstChild() - ->content()); - key = strtok(str, " "); - value = strtok(NULL, ""); - selMap[key] = value; - } - } - _populateTree(selMap); + _populateTree(_getSelectorMap()); } StyleDialog::~StyleDialog() @@ -173,6 +157,8 @@ void StyleDialog::_addSelector() break; } + del->set_sensitive(true); + /** * The selector name objects is set to the text that the user sets in the * entrybox. If the attribute does not exist, it is @@ -223,6 +209,52 @@ void StyleDialog::_addSelector() } } +/** + * @brief StyleDialog::_delSelector + * This function deletes selector when '-' at the bottom is clicked. Currently + * selectors are deleted from StyleDialog and not from repr of the document. + */ +void StyleDialog::_delSelector() +{ + Glib::RefPtr refTreeSelection = _treeView.get_selection(); + Gtk::TreeModel::iterator iter = refTreeSelection->get_selected(); + std::mapselMap = _getSelectorMap(); + + if (iter) + { + Gtk::TreeModel::Row row = *iter; + for( unsigned it = 0; it < selMap.size(); ++it ) { + std::string key = strtok(strdup(_document->getReprRoot() + ->nthChild(it) + ->firstChild()->content()), " "); + + /** + * @brief toDeleteNode + * The node to be deleted is obtained using nthChild and the selector + * name and corresponding style node from the repr of document are + * saved to a map. Keys of this map and labels of selected rows of + * dialog are compared and deleted. + */ + Inkscape::XML::Node *toDeleteNode = _document->getReprRoot()->nthChild(it); + std::maptoDeleteMap; + toDeleteMap[key] = toDeleteNode; + + for( std::map::iterator i = + toDeleteMap.begin(); i != toDeleteMap.end(); ++i ) { + if( row[_mColumns._selectorLabel] == i->first) + { + std::cout << i->second->name() << std::endl; + /** + This should work but uncommenting it causes a crash currently. + */ + //_document->getReprRoot()->removeChild(toDeleteNode); + } + } + } + _store->erase(row); + } +} + /** * @brief StyleDialog::_setClassAttribute * @param sel @@ -239,6 +271,36 @@ std::string StyleDialog::_setClassAttribute(std::vector sel) return str; } +/** + * @brief StyleDialog::_getSelectorMap + * @return selMap + * This function returns a map whose key is the style selector name and value is + * the style properties. All style selectors are extracted from svg:style + * element. + */ +std::mapStyleDialog::_getSelectorMap() +{ + _document = _targetDesktop->doc(); + unsigned num = _document->getReprRoot()->childCount(); + + std::string key, value; + std::map selMap; + + for ( unsigned i = 0; i < num; ++i ) + { + if ( std::string(_document->getReprRoot()->nthChild(i)->name()) == "svg:style" ) + { + char *str = strdup(_document->getReprRoot()->nthChild(i)->firstChild() + ->content()); + key = strtok(str, " "); + value = strtok(NULL, ""); + selMap[key] = value; + } + } + + return selMap; +} + /** * @brief StyleDialog::_populateTree * @param _selMap @@ -254,6 +316,9 @@ void StyleDialog::_populateTree(std::map _selMap) Gtk::TreeModel::Row row = *(_store->append()); row[_mColumns._selectorLabel] = it->first; } + + if (_selectMap.size() > 0) + del->set_sensitive(true); } } // namespace Dialog diff --git a/src/ui/dialog/styledialog.h b/src/ui/dialog/styledialog.h index 79ff41559..f206b1e23 100644 --- a/src/ui/dialog/styledialog.h +++ b/src/ui/dialog/styledialog.h @@ -17,6 +17,7 @@ #include #include #include +#include #include "desktop.h" #include "document.h" @@ -43,6 +44,7 @@ private: void _styleButton( Gtk::Button& btn, char const* iconName, char const* tooltip); std::string _setClassAttribute(std::vector); std::map_selectorMap; + std::map _getSelectorMap(); void _populateTree(std::map); class ModelColumns : public Gtk::TreeModel::ColumnRecord @@ -54,15 +56,20 @@ private: }; SPDesktop* _desktop; + SPDesktop* _targetDesktop; ModelColumns _mColumns; Gtk::VBox _mainBox; Gtk::HBox _buttonBox; Gtk::TreeView _treeView; Glib::RefPtr _store; Gtk::ScrolledWindow _scrolledWindow; + Gtk::Button* del; + Gtk::Button* create; + SPDocument* _document; // Signal handlers void _addSelector(); + void _delSelector(); }; } // namespace Dialog -- cgit v1.2.3 From b9f56542de1f33e8ac45325653dcac11691e3e47 Mon Sep 17 00:00:00 2001 From: kamalpreetgrewal Date: Mon, 13 Jun 2016 12:27:11 +0530 Subject: Correct parsing of style element (bzr r14949.1.14) --- src/ui/dialog/styledialog.cpp | 67 ++++++++++++++++++++++++++----------------- 1 file changed, 40 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index 14213f97d..9abcc1562 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -19,6 +19,8 @@ using Inkscape::Util::List; using Inkscape::XML::AttributeRecord; +#define REMOVE_SPACES(x) x.erase(std::remove(x.begin(), x.end(), ' '), x.end()); + namespace Inkscape { namespace UI { namespace Dialog { @@ -181,8 +183,8 @@ void StyleDialog::_addSelector() if ( std::string(property) == "style" ) { - selectorValue = row[_mColumns._selectorLabel] + "{" + - "\n" + std::string(value) + "\n" + "}"; + selectorValue = "\n" + row[_mColumns._selectorLabel] + "{" + + std::string(value) + "}"; } } @@ -223,10 +225,10 @@ void StyleDialog::_delSelector() if (iter) { Gtk::TreeModel::Row row = *iter; - for( unsigned it = 0; it < selMap.size(); ++it ) { - std::string key = strtok(strdup(_document->getReprRoot() - ->nthChild(it) - ->firstChild()->content()), " "); +// for( unsigned it = 0; it < selMap.size(); ++it ) { +// std::string key = strtok(strdup(_document->getReprRoot() +// ->nthChild(it) +// ->firstChild()->content()), "{"); /** * @brief toDeleteNode @@ -235,22 +237,22 @@ void StyleDialog::_delSelector() * saved to a map. Keys of this map and labels of selected rows of * dialog are compared and deleted. */ - Inkscape::XML::Node *toDeleteNode = _document->getReprRoot()->nthChild(it); - std::maptoDeleteMap; - toDeleteMap[key] = toDeleteNode; - - for( std::map::iterator i = - toDeleteMap.begin(); i != toDeleteMap.end(); ++i ) { - if( row[_mColumns._selectorLabel] == i->first) - { - std::cout << i->second->name() << std::endl; - /** - This should work but uncommenting it causes a crash currently. - */ - //_document->getReprRoot()->removeChild(toDeleteNode); - } - } - } +// Inkscape::XML::Node *toDeleteNode = _document->getReprRoot()->nthChild(it); +// std::maptoDeleteMap; +// toDeleteMap[key] = toDeleteNode; + +// for( std::map::iterator i = +// toDeleteMap.begin(); i != toDeleteMap.end(); ++i ) { +// if( row[_mColumns._selectorLabel] == i->first) +// { +// std::cout << i->second->name() << std::endl; +// /** +// This should work but uncommenting it causes a crash currently. +// */ +// //_document->getReprRoot()->removeChild(toDeleteNode); +// } +// } +// } _store->erase(row); } } @@ -290,11 +292,22 @@ std::mapStyleDialog::_getSelectorMap() { if ( std::string(_document->getReprRoot()->nthChild(i)->name()) == "svg:style" ) { - char *str = strdup(_document->getReprRoot()->nthChild(i)->firstChild() - ->content()); - key = strtok(str, " "); - value = strtok(NULL, ""); - selMap[key] = value; + std::stringstream str; + str << _document->getReprRoot()->nthChild(i)->firstChild()->content(); + std::string sel; + + while (str != NULL) + { + while(std::getline(str, sel, '\n')){ + REMOVE_SPACES(sel); + if (!sel.empty()) + { + key = strtok(strdup(sel.c_str()), "{"); + value = strtok(NULL, "}"); + selMap[key] = value; + } + } + } } } -- cgit v1.2.3 From d35fb3b6e570691908282543b97076591510c5f3 Mon Sep 17 00:00:00 2001 From: kamalpreetgrewal Date: Mon, 13 Jun 2016 13:31:06 +0530 Subject: Fix crash when object without style attribute is added to selector (bzr r14949.1.15) --- src/ui/dialog/styledialog.cpp | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index 9abcc1562..997d8b230 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -173,21 +173,28 @@ void StyleDialog::_addSelector() for ( unsigned i = 0; i < selected.size(); ++i ) { SPObject *obj = selected.at(i); - std::string style = std::string(obj->getRepr()->attribute("style")); - style = row[_mColumns._selectorLabel] + ";" + style; - - for ( List iter = obj->getRepr()->attributeList(); - iter; ++iter ) { - gchar const * property = g_quark_to_string(iter->key); - gchar const * value = iter->value; - - if ( std::string(property) == "style" ) - { - selectorValue = "\n" + row[_mColumns._selectorLabel] + "{" - + std::string(value) + "}"; + if (obj->getRepr()->attribute("style")) + { + std::string style = std::string(obj->getRepr()->attribute("style")); + style = row[_mColumns._selectorLabel] + ";" + style; + + for ( List iter = obj->getRepr()->attributeList(); + iter; ++iter ) { + gchar const * property = g_quark_to_string(iter->key); + gchar const * value = iter->value; + + if ( std::string(property) == "style" ) + { + selectorValue = "\n" + row[_mColumns._selectorLabel] + "{" + + std::string(value) + "}"; + } } } + else + std::cout << "This object does not have a style attribute. Add " + "one first."; + /** * @brief root * A new style element is added to the document with value obtained -- cgit v1.2.3 From a2c9a2962f6b9d4419b689ed4924f2cae2485332 Mon Sep 17 00:00:00 2001 From: kamalpreetgrewal Date: Mon, 13 Jun 2016 18:43:40 +0530 Subject: Set style and class attribute of object approprialtely when adding new style selector (bzr r14949.1.16) --- src/ui/dialog/styledialog.cpp | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index 997d8b230..15c870e5d 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -165,17 +165,20 @@ void StyleDialog::_addSelector() * The selector name objects is set to the text that the user sets in the * entrybox. If the attribute does not exist, it is * created. In case the attribute already has a value, the new value entered - * is appended to the values. + * is appended to the values. If a style attribute does not exist, it is + * created with an empty value. Also if a class selector is added, then + * class attribute for the selected object is set too. */ if ( _desktop->selection ) { std::vector selected = _desktop->getSelection()->list(); std::string selectorValue; for ( unsigned i = 0; i < selected.size(); ++i ) { SPObject *obj = selected.at(i); + std::string style; if (obj->getRepr()->attribute("style")) { - std::string style = std::string(obj->getRepr()->attribute("style")); + style = std::string(obj->getRepr()->attribute("style")); style = row[_mColumns._selectorLabel] + ";" + style; for ( List iter = obj->getRepr()->attributeList(); @@ -192,8 +195,23 @@ void StyleDialog::_addSelector() } else - std::cout << "This object does not have a style attribute. Add " - "one first."; + { + style = " "; + std::cout << "style" << style; + obj->getRepr()->setAttribute("style", style); + } + + if ( strcmp(selectorName.substr(0,1).c_str(), ".") == 0 ){ + if (!obj->getRepr()->attribute("class")) + obj->getRepr()->setAttribute("class", textEditPtr->get_text() + .erase(0,1)); + else + obj->getRepr()->setAttribute("class", std::string(obj-> + getRepr()-> + attribute("class")) + + " " + textEditPtr->get_text() + .erase(0,0)); + } /** * @brief root @@ -303,16 +321,13 @@ std::mapStyleDialog::_getSelectorMap() str << _document->getReprRoot()->nthChild(i)->firstChild()->content(); std::string sel; - while (str != NULL) - { - while(std::getline(str, sel, '\n')){ - REMOVE_SPACES(sel); - if (!sel.empty()) - { - key = strtok(strdup(sel.c_str()), "{"); - value = strtok(NULL, "}"); - selMap[key] = value; - } + while(std::getline(str, sel, '\n')){ + REMOVE_SPACES(sel); + if (!sel.empty()) + { + key = strtok(strdup(sel.c_str()), "{"); + value = strtok(NULL, "}"); + selMap[key] = value; } } } -- cgit v1.2.3 From cf648cc9b825188b3a790eeeb202b52b07ff6cef Mon Sep 17 00:00:00 2001 From: kamalpreetgrewal Date: Wed, 15 Jun 2016 19:54:38 +0530 Subject: Add selector to single style element & replace storage map by a vector (bzr r14949.1.18) --- src/ui/dialog/styledialog.cpp | 106 +++++++++++++++++++++++++++--------------- src/ui/dialog/styledialog.h | 8 ++-- 2 files changed, 74 insertions(+), 40 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index 15c870e5d..bab08390c 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -10,6 +10,7 @@ */ #include "styledialog.h" +#include "ui/widget/addtoicon.h" #include "widgets/icon.h" #include "verbs.h" #include "sp-object.h" @@ -61,6 +62,11 @@ StyleDialog::StyleDialog() : _store = Gtk::ListStore::create(_mColumns); _treeView.set_model(_store); + + Inkscape::UI::Widget::AddToIcon * addRenderer = manage( + new Inkscape::UI::Widget::AddToIcon() ); + addRenderer->property_active() = true; + _treeView.append_column("type", *addRenderer); _treeView.append_column("Selector Name", _mColumns._selectorLabel); create = manage( new Gtk::Button() ); @@ -87,7 +93,8 @@ StyleDialog::StyleDialog() : * and is then used to populate the treeview with the already existing * selectors in the style element. */ - _populateTree(_getSelectorMap()); + _styleExists = false; + _sValue = _populateTree(_getSelectorVec()); } StyleDialog::~StyleDialog() @@ -178,9 +185,6 @@ void StyleDialog::_addSelector() if (obj->getRepr()->attribute("style")) { - style = std::string(obj->getRepr()->attribute("style")); - style = row[_mColumns._selectorLabel] + ";" + style; - for ( List iter = obj->getRepr()->attributeList(); iter; ++iter ) { gchar const * property = g_quark_to_string(iter->key); @@ -188,8 +192,8 @@ void StyleDialog::_addSelector() if ( std::string(property) == "style" ) { - selectorValue = "\n" + row[_mColumns._selectorLabel] + "{" - + std::string(value) + "}"; + selectorValue = row[_mColumns._selectorLabel] + "{" + + std::string(value) + "}" + "\n"; } } } @@ -197,7 +201,6 @@ void StyleDialog::_addSelector() else { style = " "; - std::cout << "style" << style; obj->getRepr()->setAttribute("style", style); } @@ -216,22 +219,45 @@ void StyleDialog::_addSelector() /** * @brief root * A new style element is added to the document with value obtained - * from selectorValue above. + * from selectorValue above. If style element already exists, then + * the new selector's content is appended to its previous content. */ - Inkscape::XML::Node *root = obj->getRepr()->document()->root(); - Inkscape::XML::Node *newChild = obj->getRepr()->document() - ->createElement("svg:style"); - - Inkscape::XML::Node *smallChildren = obj->getRepr()->document() - ->createTextNode(selectorValue.c_str()); - - newChild->appendChild(smallChildren); - Inkscape::GC::release(smallChildren); - - root->addChild(newChild, NULL); - Inkscape::GC::release(newChild); + unsigned num = _document->getReprRoot()->childCount(); + Inkscape::XML::Node *styleChild; + for ( unsigned i = 0; i < num; ++i ) + { + if ( std::string(_document->getReprRoot()->nthChild(i)->name()) + == "svg:style" ) + { + _styleExists = true; + styleChild = _document->getReprRoot()->nthChild(i); + break; + } + else + _styleExists = false; + } - _selectorMap[selectorName] = selectorValue; + if ( _styleExists ) + { + _sValue = _sValue + selectorValue; + styleChild->firstChild()->setContent(_sValue.c_str()); + } + else + { + _sValue = selectorValue; + Inkscape::XML::Node *root = obj->getRepr()->document()->root(); + Inkscape::XML::Node *newChild = obj->getRepr()->document() + ->createElement("svg:style"); + Inkscape::XML::Node *smallChildren = obj->getRepr()->document() + ->createTextNode(selectorValue.c_str()); + + newChild->appendChild(smallChildren); + Inkscape::GC::release(smallChildren); + + root->addChild(newChild, NULL); + Inkscape::GC::release(newChild); + } + _selectorVec.push_back(std::make_pair(selectorName, selectorValue)); } } } @@ -245,7 +271,7 @@ void StyleDialog::_delSelector() { Glib::RefPtr refTreeSelection = _treeView.get_selection(); Gtk::TreeModel::iterator iter = refTreeSelection->get_selected(); - std::mapselMap = _getSelectorMap(); + std::vector >selVec = _getSelectorVec(); if (iter) { @@ -299,19 +325,19 @@ std::string StyleDialog::_setClassAttribute(std::vector sel) } /** - * @brief StyleDialog::_getSelectorMap - * @return selMap - * This function returns a map whose key is the style selector name and value is - * the style properties. All style selectors are extracted from svg:style + * @brief StyleDialog::_getSelectorVec + * @return selVec + * This function returns a vector whose key is the style selector name and value + * is the style properties. All style selectors are extracted from svg:style * element. */ -std::mapStyleDialog::_getSelectorMap() +std::vector >StyleDialog::_getSelectorVec() { _document = _targetDesktop->doc(); unsigned num = _document->getReprRoot()->childCount(); std::string key, value; - std::map selMap; + std::vector > selVec; for ( unsigned i = 0; i < num; ++i ) { @@ -327,33 +353,39 @@ std::mapStyleDialog::_getSelectorMap() { key = strtok(strdup(sel.c_str()), "{"); value = strtok(NULL, "}"); - selMap[key] = value; + selVec.push_back(std::make_pair(key, value)); } } } } - return selMap; + return selVec; } /** * @brief StyleDialog::_populateTree - * @param _selMap + * @param _selVec * This function populates the treeview with selectors available in the * stylesheet. */ -void StyleDialog::_populateTree(std::map _selMap) +std::string StyleDialog::_populateTree(std::vector > _selVec) { - std::map _selectMap = _selMap; + std::vector > _selectVec = _selVec; + std::string selectorValue; - for( std::map::iterator it = _selectMap.begin(); - it != _selectMap.end(); ++it ) { + for( unsigned it = 0; it < _selectVec.size(); ++it ) { Gtk::TreeModel::Row row = *(_store->append()); - row[_mColumns._selectorLabel] = it->first; + row[_mColumns._selectorLabel] = _selectVec[it].first; + std::string selValue = _selectVec[it].first + " { " + + _selectVec[it].second + " }" + "\n"; + selectorValue.append(selValue.c_str()); } - if (_selectMap.size() > 0) + if (_selectVec.size() > 0) del->set_sensitive(true); + + return selectorValue; } } // namespace Dialog diff --git a/src/ui/dialog/styledialog.h b/src/ui/dialog/styledialog.h index f206b1e23..0cba3bf5b 100644 --- a/src/ui/dialog/styledialog.h +++ b/src/ui/dialog/styledialog.h @@ -43,9 +43,9 @@ public: private: void _styleButton( Gtk::Button& btn, char const* iconName, char const* tooltip); std::string _setClassAttribute(std::vector); - std::map_selectorMap; - std::map _getSelectorMap(); - void _populateTree(std::map); + std::vector >_selectorVec; + std::vector > _getSelectorVec(); + std::string _populateTree(std::vector >); class ModelColumns : public Gtk::TreeModel::ColumnRecord { @@ -66,6 +66,8 @@ private: Gtk::Button* del; Gtk::Button* create; SPDocument* _document; + bool _styleExists; + std::string _sValue ; // Signal handlers void _addSelector(); -- cgit v1.2.3 From c21fa260cf5dde3e3558414ad69b05e04f173a73 Mon Sep 17 00:00:00 2001 From: kamalpreetgrewal Date: Thu, 16 Jun 2016 00:14:01 +0530 Subject: Implement deletion of style selector both from repr and treeview (bzr r14949.1.19) --- src/ui/dialog/styledialog.cpp | 70 ++++++++++++++++++++----------------------- src/ui/dialog/styledialog.h | 2 ++ 2 files changed, 34 insertions(+), 38 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index bab08390c..a56277054 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -94,6 +94,8 @@ StyleDialog::StyleDialog() : * selectors in the style element. */ _styleExists = false; + _document = _targetDesktop->doc(); + _num = _document->getReprRoot()->childCount(); _sValue = _populateTree(_getSelectorVec()); } @@ -222,15 +224,13 @@ void StyleDialog::_addSelector() * from selectorValue above. If style element already exists, then * the new selector's content is appended to its previous content. */ - unsigned num = _document->getReprRoot()->childCount(); - Inkscape::XML::Node *styleChild; - for ( unsigned i = 0; i < num; ++i ) + for ( unsigned i = 0; i < _num; ++i ) { if ( std::string(_document->getReprRoot()->nthChild(i)->name()) == "svg:style" ) { _styleExists = true; - styleChild = _document->getReprRoot()->nthChild(i); + _styleChild = _document->getReprRoot()->nthChild(i); break; } else @@ -240,7 +240,7 @@ void StyleDialog::_addSelector() if ( _styleExists ) { _sValue = _sValue + selectorValue; - styleChild->firstChild()->setContent(_sValue.c_str()); + _styleChild->firstChild()->setContent(_sValue.c_str()); } else { @@ -264,46 +264,34 @@ void StyleDialog::_addSelector() /** * @brief StyleDialog::_delSelector - * This function deletes selector when '-' at the bottom is clicked. Currently - * selectors are deleted from StyleDialog and not from repr of the document. + * This function deletes selector when '-' at the bottom is clicked. The index + * of selected row is obtained and the corresponding selector and its values are + * deleted from the selector vector. Then _sValue's content is reset and contains + * only selectors remaining in the selVec (or treeview). */ void StyleDialog::_delSelector() { Glib::RefPtr refTreeSelection = _treeView.get_selection(); Gtk::TreeModel::iterator iter = refTreeSelection->get_selected(); std::vector >selVec = _getSelectorVec(); + Gtk::TreeModel::Path path; if (iter) { Gtk::TreeModel::Row row = *iter; -// for( unsigned it = 0; it < selMap.size(); ++it ) { -// std::string key = strtok(strdup(_document->getReprRoot() -// ->nthChild(it) -// ->firstChild()->content()), "{"); + path = _treeView.get_model()->get_path(iter); + int i = atoi(path.to_string().c_str()); + selVec.erase(selVec.begin()+i); + _sValue.clear(); - /** - * @brief toDeleteNode - * The node to be deleted is obtained using nthChild and the selector - * name and corresponding style node from the repr of document are - * saved to a map. Keys of this map and labels of selected rows of - * dialog are compared and deleted. - */ -// Inkscape::XML::Node *toDeleteNode = _document->getReprRoot()->nthChild(it); -// std::maptoDeleteMap; -// toDeleteMap[key] = toDeleteNode; - -// for( std::map::iterator i = -// toDeleteMap.begin(); i != toDeleteMap.end(); ++i ) { -// if( row[_mColumns._selectorLabel] == i->first) -// { -// std::cout << i->second->name() << std::endl; -// /** -// This should work but uncommenting it causes a crash currently. -// */ -// //_document->getReprRoot()->removeChild(toDeleteNode); -// } -// } -// } + for (unsigned i = 0; i < selVec.size(); ++i) + { + std::string selValue = (selVec[i].first + "{" + + selVec[i].second + " }\n"); + _sValue.append(selValue.c_str()); + } + + _styleChild->firstChild()->setContent(_sValue.c_str()); _store->erase(row); } } @@ -333,13 +321,10 @@ std::string StyleDialog::_setClassAttribute(std::vector sel) */ std::vector >StyleDialog::_getSelectorVec() { - _document = _targetDesktop->doc(); - unsigned num = _document->getReprRoot()->childCount(); - std::string key, value; std::vector > selVec; - for ( unsigned i = 0; i < num; ++i ) + for ( unsigned i = 0; i < _num; ++i ) { if ( std::string(_document->getReprRoot()->nthChild(i)->name()) == "svg:style" ) { @@ -385,6 +370,15 @@ std::string StyleDialog::_populateTree(std::vector 0) del->set_sensitive(true); + for ( unsigned i = 0; i < _num; ++i ) + { + if ( std::string(_document->getReprRoot()->nthChild(i)->name()) + == "svg:style" ) + { + _styleChild = _document->getReprRoot()->nthChild(i); + } + } + return selectorValue; } diff --git a/src/ui/dialog/styledialog.h b/src/ui/dialog/styledialog.h index 0cba3bf5b..502a7a3d4 100644 --- a/src/ui/dialog/styledialog.h +++ b/src/ui/dialog/styledialog.h @@ -68,6 +68,8 @@ private: SPDocument* _document; bool _styleExists; std::string _sValue ; + Inkscape::XML::Node *_styleChild; + unsigned _num; // Signal handlers void _addSelector(); -- cgit v1.2.3 From 736149f0b6b617c2cf6f6bef55b4606cd70e416b Mon Sep 17 00:00:00 2001 From: kamalpreetgrewal Date: Fri, 17 Jun 2016 11:22:07 +0530 Subject: Remove unwanted empty space at top in style dialog (bzr r14949.1.21) --- src/ui/dialog/styledialog.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index a56277054..622bbcdb9 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -53,7 +53,6 @@ StyleDialog::StyleDialog() : _desktop(0) { set_size_request(200, 200); - add(_mainBox); _mainBox.pack_start(_scrolledWindow, Gtk::PACK_EXPAND_WIDGET); _treeView.set_headers_visible(false); @@ -80,10 +79,13 @@ StyleDialog::StyleDialog() : &StyleDialog::_delSelector)); del->set_sensitive(false); - _mainBox.pack_start(_buttonBox, Gtk::PACK_SHRINK); + _mainBox.pack_end(_buttonBox, Gtk::PACK_SHRINK); + _buttonBox.pack_start(*create, Gtk::PACK_SHRINK); _buttonBox.pack_start(*del, Gtk::PACK_SHRINK); + _getContents()->pack_start(_mainBox, Gtk::PACK_EXPAND_WIDGET); + _targetDesktop = getDesktop(); setDesktop(_targetDesktop); -- cgit v1.2.3 From 0ce1eb6fcfa054641be8225cf65ef7d01bf0a813 Mon Sep 17 00:00:00 2001 From: kamalpreetgrewal Date: Fri, 17 Jun 2016 14:49:21 +0530 Subject: Fix a crash while deleting when there was single selector in the style dialog (bzr r14949.1.23) --- src/ui/dialog/styledialog.cpp | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index 622bbcdb9..f81faec97 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -283,17 +283,44 @@ void StyleDialog::_delSelector() Gtk::TreeModel::Row row = *iter; path = _treeView.get_model()->get_path(iter); int i = atoi(path.to_string().c_str()); - selVec.erase(selVec.begin()+i); - _sValue.clear(); - for (unsigned i = 0; i < selVec.size(); ++i) + if (selVec.size() != 0) { - std::string selValue = (selVec[i].first + "{" - + selVec[i].second + " }\n"); - _sValue.append(selValue.c_str()); - } + selVec.erase(selVec.begin()+i); + _sValue.clear(); + + if (selVec.size() != 0) + { + for (unsigned i = 0; i < selVec.size(); ++i) + { + std::string selValue = (selVec[i].first + "{" + + selVec[i].second + " }\n"); + _sValue.append(selValue.c_str()); + } - _styleChild->firstChild()->setContent(_sValue.c_str()); + } + + /** + * Only if a value exists in _sValue and there is a _styleChild + * which contains the style element, then the content in style + * element is updated else the _styleChild is set and its content + * is set to an empty string. + */ + if (!_sValue.empty() && _styleChild) + _styleChild->firstChild()->setContent(_sValue.c_str()); + else + { + for ( unsigned i = 0; i < _num; ++i ) + { + if ( std::string(_document->getReprRoot()->nthChild(i)->name()) + == "svg:style" ) + { + _styleChild = _document->getReprRoot()->nthChild(i); + } + } + _styleChild->firstChild()->setContent(""); + } + } _store->erase(row); } } -- cgit v1.2.3 From 71959483ca7952c2b90c9b04651c187b6e17a19b Mon Sep 17 00:00:00 2001 From: kamalpreetgrewal Date: Sun, 19 Jun 2016 16:29:01 +0530 Subject: Resolve crash when empty string was added via entrybox in style dialog (bzr r14949.1.24) --- src/ui/dialog/styledialog.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index f81faec97..a7a803edd 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -155,11 +155,16 @@ void StyleDialog::_addSelector() * with a dot. */ std::string selectorName = ""; - if ( textEditPtr->get_text().at(0) == '#' || - textEditPtr->get_text().at(0) == '.' ) - selectorName = textEditPtr->get_text(); - else - selectorName = "." + textEditPtr->get_text(); + if ( !textEditPtr->get_text().empty() ) { + if ( textEditPtr->get_text().at(0) == '#' || + textEditPtr->get_text().at(0) == '.' ) + selectorName = textEditPtr->get_text(); + else + selectorName = "." + textEditPtr->get_text(); + } + else { + selectorName = ".Class1"; + } switch (result) { case Gtk::RESPONSE_OK: -- cgit v1.2.3 From 47a71e1eb00db2a3b6030ff545f624283a95e174 Mon Sep 17 00:00:00 2001 From: kamalpreetgrewal Date: Sun, 26 Jun 2016 09:24:02 +0530 Subject: Add/Remove objects to/from selector (bzr r14949.1.27) --- src/ui/dialog/styledialog.cpp | 252 ++++++++++++++++++++++++++++-------------- src/ui/dialog/styledialog.h | 11 +- 2 files changed, 178 insertions(+), 85 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index a7a803edd..6cb970eae 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -59,13 +59,20 @@ StyleDialog::StyleDialog() : _scrolledWindow.add(_treeView); _scrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); - _store = Gtk::ListStore::create(_mColumns); + _store = Gtk::TreeStore::create(_mColumns); _treeView.set_model(_store); Inkscape::UI::Widget::AddToIcon * addRenderer = manage( new Inkscape::UI::Widget::AddToIcon() ); addRenderer->property_active() = true; - _treeView.append_column("type", *addRenderer); + + int addCol = _treeView.append_column("type", *addRenderer) - 1; + + Gtk::TreeViewColumn *col = _treeView.get_column(addCol); + if ( col ) { + col->add_attribute( addRenderer->property_active(), _mColumns._colAddRemove ); + } + _treeView.append_column("Selector Name", _mColumns._selectorLabel); create = manage( new Gtk::Button() ); @@ -99,6 +106,11 @@ StyleDialog::StyleDialog() : _document = _targetDesktop->doc(); _num = _document->getReprRoot()->childCount(); _sValue = _populateTree(_getSelectorVec()); + + _treeView.signal_button_press_event().connect(sigc::mem_fun(*this, + &StyleDialog:: + _handleButtonEvent), + false); } StyleDialog::~StyleDialog() @@ -119,7 +131,7 @@ void StyleDialog::setDesktop( SPDesktop* desktop ) */ void StyleDialog::_addSelector() { - Gtk::TreeModel::Row row = *(_store->append()); + _row = *(_store->append()); /** * On clicking '+' button, an entrybox with default text opens up. If an @@ -154,22 +166,22 @@ void StyleDialog::_addSelector() * selector. If text like 'red' is written in entrybox, it is prefixed * with a dot. */ - std::string selectorName = ""; if ( !textEditPtr->get_text().empty() ) { if ( textEditPtr->get_text().at(0) == '#' || textEditPtr->get_text().at(0) == '.' ) - selectorName = textEditPtr->get_text(); + _selectorName = textEditPtr->get_text(); else - selectorName = "." + textEditPtr->get_text(); + _selectorName = "." + textEditPtr->get_text(); } else { - selectorName = ".Class1"; + _selectorName = ".Class1"; } switch (result) { case Gtk::RESPONSE_OK: textDialogPtr->hide(); - row[_mColumns._selectorLabel] = selectorName; + _row[_mColumns._selectorLabel] = _selectorName; + _row[_mColumns._colAddRemove] = true; break; default: break; @@ -185,11 +197,11 @@ void StyleDialog::_addSelector() * created with an empty value. Also if a class selector is added, then * class attribute for the selected object is set too. */ - if ( _desktop->selection ) { + SPObject *obj; + if ( !_desktop->getSelection()->list().empty() ) { std::vector selected = _desktop->getSelection()->list(); - std::string selectorValue; for ( unsigned i = 0; i < selected.size(); ++i ) { - SPObject *obj = selected.at(i); + obj = selected.at(i); std::string style; if (obj->getRepr()->attribute("style")) @@ -201,7 +213,7 @@ void StyleDialog::_addSelector() if ( std::string(property) == "style" ) { - selectorValue = row[_mColumns._selectorLabel] + "{" + _selectorValue = _row[_mColumns._selectorLabel] + "{" + std::string(value) + "}" + "\n"; } } @@ -213,7 +225,7 @@ void StyleDialog::_addSelector() obj->getRepr()->setAttribute("style", style); } - if ( strcmp(selectorName.substr(0,1).c_str(), ".") == 0 ){ + if ( strcmp(_selectorName.substr(0,1).c_str(), ".") == 0 ){ if (!obj->getRepr()->attribute("class")) obj->getRepr()->setAttribute("class", textEditPtr->get_text() .erase(0,1)); @@ -224,49 +236,49 @@ void StyleDialog::_addSelector() + " " + textEditPtr->get_text() .erase(0,0)); } + } + } + else { + _selectorValue = _selectorName + "{" + "}" + "\n"; + } - /** - * @brief root - * A new style element is added to the document with value obtained - * from selectorValue above. If style element already exists, then - * the new selector's content is appended to its previous content. - */ - for ( unsigned i = 0; i < _num; ++i ) - { - if ( std::string(_document->getReprRoot()->nthChild(i)->name()) - == "svg:style" ) - { - _styleExists = true; - _styleChild = _document->getReprRoot()->nthChild(i); - break; - } - else - _styleExists = false; - } - - if ( _styleExists ) - { - _sValue = _sValue + selectorValue; - _styleChild->firstChild()->setContent(_sValue.c_str()); - } - else - { - _sValue = selectorValue; - Inkscape::XML::Node *root = obj->getRepr()->document()->root(); - Inkscape::XML::Node *newChild = obj->getRepr()->document() - ->createElement("svg:style"); - Inkscape::XML::Node *smallChildren = obj->getRepr()->document() - ->createTextNode(selectorValue.c_str()); - - newChild->appendChild(smallChildren); - Inkscape::GC::release(smallChildren); - - root->addChild(newChild, NULL); - Inkscape::GC::release(newChild); - } - _selectorVec.push_back(std::make_pair(selectorName, selectorValue)); + /** + * @brief root + * A new style element is added to the document with value obtained + * from selectorValue above. If style element already exists, then + * the new selector's content is appended to its previous content. + */ + for ( unsigned i = 0; i < _num; ++i ) { + if ( std::string(_document->getReprRoot()->nthChild(i)->name()) + == "svg:style" ) { + _styleExists = true; + _styleChild = _document->getReprRoot()->nthChild(i); + break; } + else { + _styleExists = false; + } + } + + if ( _styleExists ) { + _sValue = _sValue + _selectorValue; + _styleChild->firstChild()->setContent(_sValue.c_str()); + } + else { + _sValue = _selectorValue; + Inkscape::XML::Node *root = _document->getReprDoc()->root(); + Inkscape::XML::Node *newChild = _document->getReprDoc() + ->createElement("svg:style"); + Inkscape::XML::Node *smallChildren = _document->getReprDoc() + ->createTextNode(_selectorValue.c_str()); + + newChild->appendChild(smallChildren); + Inkscape::GC::release(smallChildren); + + root->addChild(newChild, NULL); + Inkscape::GC::release(newChild); } + _selectorVec.push_back(std::make_pair(_selectorName, _selectorValue)); } /** @@ -283,26 +295,19 @@ void StyleDialog::_delSelector() std::vector >selVec = _getSelectorVec(); Gtk::TreeModel::Path path; - if (iter) - { + if (iter) { Gtk::TreeModel::Row row = *iter; path = _treeView.get_model()->get_path(iter); int i = atoi(path.to_string().c_str()); - if (selVec.size() != 0) - { + if ( selVec.size() != 0 ) { selVec.erase(selVec.begin()+i); _sValue.clear(); - if (selVec.size() != 0) - { - for (unsigned i = 0; i < selVec.size(); ++i) - { - std::string selValue = (selVec[i].first + "{" - + selVec[i].second + " }\n"); - _sValue.append(selValue.c_str()); - } - + for ( unsigned i = 0; i < selVec.size(); ++i ) { + std::string selValue = (selVec[i].first + "{" + + selVec[i].second + " }\n"); + _sValue.append(selValue.c_str()); } /** @@ -311,17 +316,13 @@ void StyleDialog::_delSelector() * element is updated else the _styleChild is set and its content * is set to an empty string. */ - if (!_sValue.empty() && _styleChild) + if ( !_sValue.empty() && _styleChild ) _styleChild->firstChild()->setContent(_sValue.c_str()); - else - { - for ( unsigned i = 0; i < _num; ++i ) - { + else { + for ( unsigned i = 0; i < _num; ++i ) { if ( std::string(_document->getReprRoot()->nthChild(i)->name()) == "svg:style" ) - { _styleChild = _document->getReprRoot()->nthChild(i); - } } _styleChild->firstChild()->setContent(""); } @@ -358,20 +359,26 @@ std::vector >StyleDialog::_getSelectorVec() std::string key, value; std::vector > selVec; - for ( unsigned i = 0; i < _num; ++i ) - { + for ( unsigned i = 0; i < _num; ++i ) { if ( std::string(_document->getReprRoot()->nthChild(i)->name()) == "svg:style" ) { std::stringstream str; str << _document->getReprRoot()->nthChild(i)->firstChild()->content(); std::string sel; - while(std::getline(str, sel, '\n')){ + /** + * If a selector without any style attribute content is added, the + * value is set to empty so that its corresponding XML repr is added. + */ + while( std::getline(str, sel, '\n') ){ REMOVE_SPACES(sel); - if (!sel.empty()) + if ( !sel.empty() ) { key = strtok(strdup(sel.c_str()), "{"); - value = strtok(NULL, "}"); + if ( strtok(NULL, "}") != NULL ) + value = strtok(NULL, "}"); + else + value = ""; selVec.push_back(std::make_pair(key, value)); } } @@ -404,18 +411,99 @@ std::string StyleDialog::_populateTree(std::vector 0) del->set_sensitive(true); - for ( unsigned i = 0; i < _num; ++i ) - { + for ( unsigned i = 0; i < _num; ++i ) { if ( std::string(_document->getReprRoot()->nthChild(i)->name()) == "svg:style" ) - { _styleChild = _document->getReprRoot()->nthChild(i); - } } return selectorValue; } +/** + * @brief StyleDialog::_handleButtonEvent + * @param event + * @return + * This function handles the event when '+' button in front of a selector name + * is clicked. The selected objects (if any) is added to the selector as a child + * in the treeview. + * TODO: Appending children in XML repr. + */ + +bool StyleDialog::_handleButtonEvent(GdkEventButton *event) +{ + if ( event->type == GDK_BUTTON_PRESS && event->button == 1 ) + { + Gtk::TreeViewColumn *col = 0; + + Gtk::TreeModel::Path path; + int x = static_cast(event->x); + int y = static_cast(event->y); + int x2 = 0; + int y2 = 0; + if ( _treeView.get_path_at_pos( x, y, path, col, x2, y2 ) ) { + if ( col == _treeView.get_column(0) ) + { + if ( _desktop->selection ) + { + std::vectorsel = _desktop->selection->list(); + for (unsigned i = 0; i < sel.size(); ++i) + { + SPObject *obj = sel[i]; + Glib::RefPtr refTreeSelection = + _treeView.get_selection(); + Gtk::TreeModel::iterator iter = refTreeSelection-> + get_selected(); + + if ( iter ) + { + Gtk::TreeModel::Row row = *iter; +// SPObject *object = row[_mColumns._colObj]; + + typedef Gtk::TreeModel::Children type_children; + type_children children = row->children(); + Gtk::TreeModel::Row childrow; + + if ( children.size() == 0 && row->parent() == 0 ) + { + childrow = *(_store->append(row->children())); + childrow[_mColumns._selectorLabel] = obj->getId(); + childrow[_mColumns._colAddRemove] = false; +// childrow[_mColumns._colObj] = obj; +// object->getRepr()->appendChild(obj->getRepr()); + } + else + { + for( type_children::iterator it = children.begin(); + it != children.end(); ++it ) + { + Gtk::TreeModel::iterator i = it; + path = _treeView.get_model()->get_path(i); + + if( (*it)->get_value(_mColumns._selectorLabel) + != obj->getId() ) + { + childrow = *(_store->append(row.children())); + childrow[_mColumns._selectorLabel] = obj->getId(); + childrow[_mColumns._colAddRemove] = false; +// childrow[_mColumns._colObj] = obj; +// object->getRepr()->appendChild(obj->getRepr()); + + } + else { + std::cout << "Do nothing" << std::endl; + } + } + } +// std::cout << "repr" << object->getRepr()->content(); + } + } + } + } + } + } +} + } // namespace Dialog } // namespace UI } // namespace Inkscape diff --git a/src/ui/dialog/styledialog.h b/src/ui/dialog/styledialog.h index 502a7a3d4..ff4de9a97 100644 --- a/src/ui/dialog/styledialog.h +++ b/src/ui/dialog/styledialog.h @@ -14,7 +14,7 @@ #include #include -#include +#include #include #include #include @@ -46,13 +46,15 @@ private: std::vector >_selectorVec; std::vector > _getSelectorVec(); std::string _populateTree(std::vector >); + bool _handleButtonEvent(GdkEventButton *event); class ModelColumns : public Gtk::TreeModel::ColumnRecord { public: ModelColumns() - { add(_selectorLabel); } + { add(_selectorLabel); add(_colAddRemove); } Gtk::TreeModelColumn _selectorLabel; + Gtk::TreeModelColumn _colAddRemove; }; SPDesktop* _desktop; @@ -61,7 +63,7 @@ private: Gtk::VBox _mainBox; Gtk::HBox _buttonBox; Gtk::TreeView _treeView; - Glib::RefPtr _store; + Glib::RefPtr _store; Gtk::ScrolledWindow _scrolledWindow; Gtk::Button* del; Gtk::Button* create; @@ -70,6 +72,9 @@ private: std::string _sValue ; Inkscape::XML::Node *_styleChild; unsigned _num; + std::string _selectorName = ""; + std::string _selectorValue; + Gtk::TreeModel::Row _row; // Signal handlers void _addSelector(); -- cgit v1.2.3 From a401c22ec8acb2a94701ea0fbb7ecf08683ebca1 Mon Sep 17 00:00:00 2001 From: kamalpreetgrewal Date: Sun, 26 Jun 2016 11:33:48 +0530 Subject: Fix a crash when deleting selectors and some coding style corrections (bzr r14949.1.29) --- src/ui/dialog/styledialog.cpp | 134 +++++++++++++++++++----------------------- 1 file changed, 59 insertions(+), 75 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index 6cb970eae..3c1ed0a5d 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -148,8 +148,9 @@ void StyleDialog::_addSelector() * is(are) selected and user clicks '+' at the bottom of dialog, the * entrybox will have the id(s) of the selected objects as text. */ - if ( _desktop->selection->isEmpty() ) + if (_desktop->selection->isEmpty()) { textEditPtr->set_text("Class1"); + } else { std::vector selected = _desktop->getSelection()->list(); textEditPtr->set_text(_setClassAttribute(selected)); @@ -166,12 +167,14 @@ void StyleDialog::_addSelector() * selector. If text like 'red' is written in entrybox, it is prefixed * with a dot. */ - if ( !textEditPtr->get_text().empty() ) { - if ( textEditPtr->get_text().at(0) == '#' || - textEditPtr->get_text().at(0) == '.' ) + if (!textEditPtr->get_text().empty()) { + if (textEditPtr->get_text().at(0) == '#' || + textEditPtr->get_text().at(0) == '.') { _selectorName = textEditPtr->get_text(); - else + } + else { _selectorName = "." + textEditPtr->get_text(); + } } else { _selectorName = ".Class1"; @@ -198,43 +201,41 @@ void StyleDialog::_addSelector() * class attribute for the selected object is set too. */ SPObject *obj; - if ( !_desktop->getSelection()->list().empty() ) { + if (!_desktop->getSelection()->list().empty()) { std::vector selected = _desktop->getSelection()->list(); - for ( unsigned i = 0; i < selected.size(); ++i ) { + for (unsigned i = 0; i < selected.size(); ++i) { obj = selected.at(i); std::string style; - if (obj->getRepr()->attribute("style")) - { - for ( List iter = obj->getRepr()->attributeList(); - iter; ++iter ) { + if (obj->getRepr()->attribute("style")) { + for (List iter = obj->getRepr()->attributeList(); + iter; ++iter) { gchar const * property = g_quark_to_string(iter->key); gchar const * value = iter->value; - if ( std::string(property) == "style" ) - { + if (std::string(property) == "style") { _selectorValue = _row[_mColumns._selectorLabel] + "{" + std::string(value) + "}" + "\n"; } } } - - else - { + else { style = " "; obj->getRepr()->setAttribute("style", style); } - if ( strcmp(_selectorName.substr(0,1).c_str(), ".") == 0 ){ - if (!obj->getRepr()->attribute("class")) + if (strcmp(_selectorName.substr(0,1).c_str(), ".") == 0) { + if (!obj->getRepr()->attribute("class")) { obj->getRepr()->setAttribute("class", textEditPtr->get_text() .erase(0,1)); - else + } + else { obj->getRepr()->setAttribute("class", std::string(obj-> getRepr()-> attribute("class")) + " " + textEditPtr->get_text() .erase(0,0)); + } } } } @@ -248,9 +249,9 @@ void StyleDialog::_addSelector() * from selectorValue above. If style element already exists, then * the new selector's content is appended to its previous content. */ - for ( unsigned i = 0; i < _num; ++i ) { - if ( std::string(_document->getReprRoot()->nthChild(i)->name()) - == "svg:style" ) { + for (unsigned i = 0; i < _num; ++i) { + if (std::string(_document->getReprRoot()->nthChild(i)->name()) + == "svg:style") { _styleExists = true; _styleChild = _document->getReprRoot()->nthChild(i); break; @@ -260,7 +261,7 @@ void StyleDialog::_addSelector() } } - if ( _styleExists ) { + if (_styleExists) { _sValue = _sValue + _selectorValue; _styleChild->firstChild()->setContent(_sValue.c_str()); } @@ -300,11 +301,11 @@ void StyleDialog::_delSelector() path = _treeView.get_model()->get_path(iter); int i = atoi(path.to_string().c_str()); - if ( selVec.size() != 0 ) { + if (selVec.size() != 0) { selVec.erase(selVec.begin()+i); _sValue.clear(); - for ( unsigned i = 0; i < selVec.size(); ++i ) { + for (unsigned i = 0; i < selVec.size(); ++i) { std::string selValue = (selVec[i].first + "{" + selVec[i].second + " }\n"); _sValue.append(selValue.c_str()); @@ -316,13 +317,15 @@ void StyleDialog::_delSelector() * element is updated else the _styleChild is set and its content * is set to an empty string. */ - if ( !_sValue.empty() && _styleChild ) + if (!_sValue.empty() && _styleChild) { _styleChild->firstChild()->setContent(_sValue.c_str()); + } else { - for ( unsigned i = 0; i < _num; ++i ) { - if ( std::string(_document->getReprRoot()->nthChild(i)->name()) - == "svg:style" ) + for (unsigned i = 0; i < _num; ++i) { + if (std::string(_document->getReprRoot()->nthChild(i)->name()) + == "svg:style") { _styleChild = _document->getReprRoot()->nthChild(i); + } } _styleChild->firstChild()->setContent(""); } @@ -359,9 +362,8 @@ std::vector >StyleDialog::_getSelectorVec() std::string key, value; std::vector > selVec; - for ( unsigned i = 0; i < _num; ++i ) { - if ( std::string(_document->getReprRoot()->nthChild(i)->name()) == "svg:style" ) - { + for (unsigned i = 0; i < _num; ++i) { + if (std::string(_document->getReprRoot()->nthChild(i)->name()) == "svg:style") { std::stringstream str; str << _document->getReprRoot()->nthChild(i)->firstChild()->content(); std::string sel; @@ -370,21 +372,19 @@ std::vector >StyleDialog::_getSelectorVec() * If a selector without any style attribute content is added, the * value is set to empty so that its corresponding XML repr is added. */ - while( std::getline(str, sel, '\n') ){ + while(std::getline(str, sel, '\n')) { REMOVE_SPACES(sel); - if ( !sel.empty() ) - { + if (!sel.empty()) { key = strtok(strdup(sel.c_str()), "{"); - if ( strtok(NULL, "}") != NULL ) - value = strtok(NULL, "}"); - else - value = ""; + char *temp = strtok(NULL, "}"); + if (strtok(temp, "}") != NULL) { + value = strtok(temp, "}"); + } selVec.push_back(std::make_pair(key, value)); } } } } - return selVec; } @@ -400,7 +400,7 @@ std::string StyleDialog::_populateTree(std::vector > _selectVec = _selVec; std::string selectorValue; - for( unsigned it = 0; it < _selectVec.size(); ++it ) { + for(unsigned it = 0; it < _selectVec.size(); ++it) { Gtk::TreeModel::Row row = *(_store->append()); row[_mColumns._selectorLabel] = _selectVec[it].first; std::string selValue = _selectVec[it].first + " { " @@ -408,13 +408,15 @@ std::string StyleDialog::_populateTree(std::vector 0) + if (_selectVec.size() > 0) { del->set_sensitive(true); + } - for ( unsigned i = 0; i < _num; ++i ) { - if ( std::string(_document->getReprRoot()->nthChild(i)->name()) - == "svg:style" ) + for (unsigned i = 0; i < _num; ++i) { + if (std::string(_document->getReprRoot()->nthChild(i)->name()) + == "svg:style") { _styleChild = _document->getReprRoot()->nthChild(i); + } } return selectorValue; @@ -432,70 +434,52 @@ std::string StyleDialog::_populateTree(std::vectortype == GDK_BUTTON_PRESS && event->button == 1 ) - { + if (event->type == GDK_BUTTON_PRESS && event->button == 1) { Gtk::TreeViewColumn *col = 0; - Gtk::TreeModel::Path path; int x = static_cast(event->x); int y = static_cast(event->y); int x2 = 0; int y2 = 0; - if ( _treeView.get_path_at_pos( x, y, path, col, x2, y2 ) ) { - if ( col == _treeView.get_column(0) ) - { - if ( _desktop->selection ) - { + if (_treeView.get_path_at_pos(x, y, path, col, x2, y2)) { + if (col == _treeView.get_column(0)) { + if (_desktop->selection) { std::vectorsel = _desktop->selection->list(); - for (unsigned i = 0; i < sel.size(); ++i) - { + for (unsigned i = 0; i < sel.size(); ++i) { SPObject *obj = sel[i]; Glib::RefPtr refTreeSelection = _treeView.get_selection(); Gtk::TreeModel::iterator iter = refTreeSelection-> get_selected(); - if ( iter ) - { + if (iter) { Gtk::TreeModel::Row row = *iter; -// SPObject *object = row[_mColumns._colObj]; - typedef Gtk::TreeModel::Children type_children; type_children children = row->children(); Gtk::TreeModel::Row childrow; - if ( children.size() == 0 && row->parent() == 0 ) - { + if (children.size() == 0 && row->parent() == 0) { childrow = *(_store->append(row->children())); childrow[_mColumns._selectorLabel] = obj->getId(); childrow[_mColumns._colAddRemove] = false; -// childrow[_mColumns._colObj] = obj; -// object->getRepr()->appendChild(obj->getRepr()); } - else - { - for( type_children::iterator it = children.begin(); - it != children.end(); ++it ) - { + else { + for(type_children::iterator it = children.begin(); + it != children.end(); ++it) { Gtk::TreeModel::iterator i = it; path = _treeView.get_model()->get_path(i); - if( (*it)->get_value(_mColumns._selectorLabel) - != obj->getId() ) - { + if((*it)->get_value(_mColumns._selectorLabel) + != obj->getId()) { childrow = *(_store->append(row.children())); childrow[_mColumns._selectorLabel] = obj->getId(); childrow[_mColumns._colAddRemove] = false; -// childrow[_mColumns._colObj] = obj; -// object->getRepr()->appendChild(obj->getRepr()); - } else { std::cout << "Do nothing" << std::endl; } } } -// std::cout << "repr" << object->getRepr()->content(); } } } -- cgit v1.2.3 From 4a85a11d89d34739eb43496047ee7af67d635c1c Mon Sep 17 00:00:00 2001 From: kamalpreetgrewal Date: Sun, 26 Jun 2016 18:52:52 +0530 Subject: Select objects corresponding to selector selected in treeview (bzr r14949.1.30) --- src/ui/dialog/styledialog.cpp | 79 ++++++++++++++++++++++++++++++++++++------- src/ui/dialog/styledialog.h | 6 +++- 2 files changed, 72 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index 3c1ed0a5d..1dba1d2df 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -111,6 +111,10 @@ StyleDialog::StyleDialog() : &StyleDialog:: _handleButtonEvent), false); + + _treeView.signal_row_activated().connect(sigc::mem_fun(*this, + &StyleDialog:: + _selectedRowCallback)); } StyleDialog::~StyleDialog() @@ -180,16 +184,6 @@ void StyleDialog::_addSelector() _selectorName = ".Class1"; } - switch (result) { - case Gtk::RESPONSE_OK: - textDialogPtr->hide(); - _row[_mColumns._selectorLabel] = _selectorName; - _row[_mColumns._colAddRemove] = true; - break; - default: - break; - } - del->set_sensitive(true); /** @@ -201,10 +195,12 @@ void StyleDialog::_addSelector() * class attribute for the selected object is set too. */ SPObject *obj; + bool objExists = false; if (!_desktop->getSelection()->list().empty()) { std::vector selected = _desktop->getSelection()->list(); for (unsigned i = 0; i < selected.size(); ++i) { obj = selected.at(i); + objExists = true; std::string style; if (obj->getRepr()->attribute("style")) { @@ -214,7 +210,7 @@ void StyleDialog::_addSelector() gchar const * value = iter->value; if (std::string(property) == "style") { - _selectorValue = _row[_mColumns._selectorLabel] + "{" + _selectorValue = _selectorName + "{" + std::string(value) + "}" + "\n"; } } @@ -241,9 +237,22 @@ void StyleDialog::_addSelector() } else { _selectorValue = _selectorName + "{" + "}" + "\n"; + objExists = false; } - /** + switch (result) { + case Gtk::RESPONSE_OK: + textDialogPtr->hide(); + _row[_mColumns._selectorLabel] = _selectorName; + _row[_mColumns._colAddRemove] = true; + if (objExists) { + _row[_mColumns._colObj] = obj; + } + break; + default: + break; + } + /** * @brief root * A new style element is added to the document with value obtained * from selectorValue above. If style element already exists, then @@ -462,6 +471,7 @@ bool StyleDialog::_handleButtonEvent(GdkEventButton *event) childrow = *(_store->append(row->children())); childrow[_mColumns._selectorLabel] = obj->getId(); childrow[_mColumns._colAddRemove] = false; + childrow[_mColumns._colObj] = obj; } else { for(type_children::iterator it = children.begin(); @@ -474,6 +484,7 @@ bool StyleDialog::_handleButtonEvent(GdkEventButton *event) childrow = *(_store->append(row.children())); childrow[_mColumns._selectorLabel] = obj->getId(); childrow[_mColumns._colAddRemove] = false; + childrow[_mColumns._colObj] = obj; } else { std::cout << "Do nothing" << std::endl; @@ -488,6 +499,50 @@ bool StyleDialog::_handleButtonEvent(GdkEventButton *event) } } +/** + * @brief StyleDialog::_selected_row_callback + * @param path + * This function selects objects in the drawing corresponding to the selector + * selected in the treeview. + */ +void StyleDialog::_selectedRowCallback(const Gtk::TreeModel::Path& path, + Gtk::TreeViewColumn* /* column */) +{ + _desktop->selection->clear(); + Gtk::TreeModel::iterator iter = _store->get_iter(path); + if (iter) { + Gtk::TreeModel::Row row = *iter; + Gtk::TreeModel::Children children = row.children(); + + if (row[_mColumns._colObj]) { + SPObject *obj = row[_mColumns._colObj]; + _desktop->selection->add(obj); + } + + if (children) { + _checkAllChildren(children); + } + } +} + +/** + * @brief StyleDialog::_checkAllChildren + * @param children + * This function iterates children of the row selected in treeview and selects + * the objects corresponding to any selector in child rows. + */ +void StyleDialog::_checkAllChildren(Gtk::TreeModel::Children& children) +{ + for (Gtk::TreeModel::Children::iterator iter = children.begin(); + iter!= children.end(); ++iter) { + Gtk::TreeModel::Row childrow = *iter; + if (childrow[_mColumns._colObj]) { + SPObject *obj = childrow[_mColumns._colObj]; + _desktop->selection->add(obj); + } + } +} + } // namespace Dialog } // namespace UI } // namespace Inkscape diff --git a/src/ui/dialog/styledialog.h b/src/ui/dialog/styledialog.h index ff4de9a97..79897a5b6 100644 --- a/src/ui/dialog/styledialog.h +++ b/src/ui/dialog/styledialog.h @@ -47,14 +47,18 @@ private: std::vector > _getSelectorVec(); std::string _populateTree(std::vector >); bool _handleButtonEvent(GdkEventButton *event); + void _selectedRowCallback(const Gtk::TreeModel::Path& path, + Gtk::TreeViewColumn* /* column */); + void _checkAllChildren(Gtk::TreeModel::Children& children); class ModelColumns : public Gtk::TreeModel::ColumnRecord { public: ModelColumns() - { add(_selectorLabel); add(_colAddRemove); } + { add(_selectorLabel); add(_colAddRemove); add(_colObj); } Gtk::TreeModelColumn _selectorLabel; Gtk::TreeModelColumn _colAddRemove; + Gtk::TreeModelColumn _colObj; }; SPDesktop* _desktop; -- cgit v1.2.3 From 94e53ff6ca6d0a595415b6f930a4a05adaeb68be Mon Sep 17 00:00:00 2001 From: kamalpreetgrewal Date: Tue, 28 Jun 2016 22:18:31 +0530 Subject: Update XML repr when objects are added to selector & some code cleanup (bzr r14949.1.31) --- src/ui/dialog/styledialog.cpp | 180 +++++++++++++++++++++--------------------- src/ui/dialog/styledialog.h | 2 + 2 files changed, 91 insertions(+), 91 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index 1dba1d2df..1b93fb550 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -172,13 +172,7 @@ void StyleDialog::_addSelector() * with a dot. */ if (!textEditPtr->get_text().empty()) { - if (textEditPtr->get_text().at(0) == '#' || - textEditPtr->get_text().at(0) == '.') { _selectorName = textEditPtr->get_text(); - } - else { - _selectorName = "." + textEditPtr->get_text(); - } } else { _selectorName = ".Class1"; @@ -252,27 +246,24 @@ void StyleDialog::_addSelector() default: break; } - /** - * @brief root + + /** * A new style element is added to the document with value obtained * from selectorValue above. If style element already exists, then * the new selector's content is appended to its previous content. */ - for (unsigned i = 0; i < _num; ++i) { - if (std::string(_document->getReprRoot()->nthChild(i)->name()) - == "svg:style") { - _styleExists = true; - _styleChild = _document->getReprRoot()->nthChild(i); - break; - } - else { - _styleExists = false; - } + _selectorVec.push_back(std::make_pair(_selectorName, _selectorValue)); + + if (_styleElementNode()) { + _styleChild = _styleElementNode(); + _styleExists = true; + } + else { + _styleExists = false; } if (_styleExists) { - _sValue = _sValue + _selectorValue; - _styleChild->firstChild()->setContent(_sValue.c_str()); + _updateStyleContent(); } else { _sValue = _selectorValue; @@ -288,7 +279,20 @@ void StyleDialog::_addSelector() root->addChild(newChild, NULL); Inkscape::GC::release(newChild); } - _selectorVec.push_back(std::make_pair(_selectorName, _selectorValue)); +} + +/** + * @brief StyleDialog::_updateStyleContent + * This function updates the content in style element as new selectors (or + * objects) are added/removed. + */ +void StyleDialog::_updateStyleContent() +{ + std::string styleContent = ""; + for (unsigned i = 0; i < _selectorVec.size(); ++i) { + styleContent = styleContent + _selectorVec[i].second; + } + _styleElementNode()->firstChild()->setContent(styleContent.c_str()); } /** @@ -297,12 +301,13 @@ void StyleDialog::_addSelector() * of selected row is obtained and the corresponding selector and its values are * deleted from the selector vector. Then _sValue's content is reset and contains * only selectors remaining in the selVec (or treeview). + * TODO: get index of children of rows for correct deletion of rows having + * children. */ void StyleDialog::_delSelector() { Glib::RefPtr refTreeSelection = _treeView.get_selection(); Gtk::TreeModel::iterator iter = refTreeSelection->get_selected(); - std::vector >selVec = _getSelectorVec(); Gtk::TreeModel::Path path; if (iter) { @@ -310,39 +315,46 @@ void StyleDialog::_delSelector() path = _treeView.get_model()->get_path(iter); int i = atoi(path.to_string().c_str()); - if (selVec.size() != 0) { - selVec.erase(selVec.begin()+i); - _sValue.clear(); - - for (unsigned i = 0; i < selVec.size(); ++i) { - std::string selValue = (selVec[i].first + "{" - + selVec[i].second + " }\n"); - _sValue.append(selValue.c_str()); - } + if (_selectorVec.size() != 0) { + _selectorVec.erase(_selectorVec.begin()+i); /** - * Only if a value exists in _sValue and there is a _styleChild - * which contains the style element, then the content in style - * element is updated else the _styleChild is set and its content - * is set to an empty string. + * If there is a _styleChild which contains the style element, then + * the content in style element is updated else the _styleChild is + * obtained and its content is set. */ - if (!_sValue.empty() && _styleChild) { - _styleChild->firstChild()->setContent(_sValue.c_str()); + if (_styleChild) { + _updateStyleContent(); } else { - for (unsigned i = 0; i < _num; ++i) { - if (std::string(_document->getReprRoot()->nthChild(i)->name()) - == "svg:style") { - _styleChild = _document->getReprRoot()->nthChild(i); - } - } - _styleChild->firstChild()->setContent(""); + _styleChild = _styleElementNode(); + _updateStyleContent(); } } _store->erase(row); } } +/** + * @brief StyleDialog::_styleElementNode + * @return + * This function returns the node containing style element. The document's + * children are iterated and the repr of the style element that occurs is + * obtained. + */ +Inkscape::XML::Node* StyleDialog::_styleElementNode() +{ + for (unsigned i = 0; i < _num; ++i) { + if (std::string(_document->getReprRoot()->nthChild(i)->name()) + == "svg:style") { + return _document->getReprRoot()->nthChild(i); + } + else { + return NULL; + } + } +} + /** * @brief StyleDialog::_setClassAttribute * @param sel @@ -412,8 +424,8 @@ std::string StyleDialog::_populateTree(std::vectorappend()); row[_mColumns._selectorLabel] = _selectVec[it].first; - std::string selValue = _selectVec[it].first + " { " - + _selectVec[it].second + " }" + "\n"; + std::string selValue = _selectVec[it].first + "{" + + _selectVec[it].second + "}" + "\n"; selectorValue.append(selValue.c_str()); } @@ -421,12 +433,7 @@ std::string StyleDialog::_populateTree(std::vectorset_sensitive(true); } - for (unsigned i = 0; i < _num; ++i) { - if (std::string(_document->getReprRoot()->nthChild(i)->name()) - == "svg:style") { - _styleChild = _document->getReprRoot()->nthChild(i); - } - } + _styleChild = _styleElementNode(); return selectorValue; } @@ -438,9 +445,7 @@ std::string StyleDialog::_populateTree(std::vectortype == GDK_BUTTON_PRESS && event->button == 1) { @@ -461,37 +466,30 @@ bool StyleDialog::_handleButtonEvent(GdkEventButton *event) Gtk::TreeModel::iterator iter = refTreeSelection-> get_selected(); - if (iter) { + if (iter) + { Gtk::TreeModel::Row row = *iter; typedef Gtk::TreeModel::Children type_children; - type_children children = row->children(); Gtk::TreeModel::Row childrow; - - if (children.size() == 0 && row->parent() == 0) { - childrow = *(_store->append(row->children())); - childrow[_mColumns._selectorLabel] = obj->getId(); - childrow[_mColumns._colAddRemove] = false; - childrow[_mColumns._colObj] = obj; - } - else { - for(type_children::iterator it = children.begin(); + path = _treeView.get_model()->get_path(iter); + childrow = *(_store->append(row->children())); + childrow[_mColumns._selectorLabel] = obj->getId(); + childrow[_mColumns._colAddRemove] = false; + childrow[_mColumns._colObj] = obj; + Gtk::TreeModel::Children children = row.children(); + std::string childStyle; + if (children) { + for(Gtk::TreeModel::Children::iterator it = children.begin(); it != children.end(); ++it) { - Gtk::TreeModel::iterator i = it; - path = _treeView.get_model()->get_path(i); - - if((*it)->get_value(_mColumns._selectorLabel) - != obj->getId()) { - childrow = *(_store->append(row.children())); - childrow[_mColumns._selectorLabel] = obj->getId(); - childrow[_mColumns._colAddRemove] = false; - childrow[_mColumns._colObj] = obj; - } - else { - std::cout << "Do nothing" << std::endl; - } + Gtk::TreeModel::Row row = *it; + SPObject *obj = row[_mColumns._colObj]; + childStyle = "#" + std::string(obj->getId()) + "{" + + std::string(obj->getAttribute("style")) + "}\n"; } } + _selectorVec.push_back(std::make_pair(obj->getId(), childStyle)); } + _updateStyleContent(); } } } @@ -506,21 +504,21 @@ bool StyleDialog::_handleButtonEvent(GdkEventButton *event) * selected in the treeview. */ void StyleDialog::_selectedRowCallback(const Gtk::TreeModel::Path& path, - Gtk::TreeViewColumn* /* column */) + Gtk::TreeViewColumn* column ) { _desktop->selection->clear(); - Gtk::TreeModel::iterator iter = _store->get_iter(path); - if (iter) { - Gtk::TreeModel::Row row = *iter; - Gtk::TreeModel::Children children = row.children(); - - if (row[_mColumns._colObj]) { - SPObject *obj = row[_mColumns._colObj]; - _desktop->selection->add(obj); - } - - if (children) { - _checkAllChildren(children); + if (column == _treeView.get_column(1)) { + Gtk::TreeModel::iterator iter = _store->get_iter(path); + if (iter) { + Gtk::TreeModel::Row row = *iter; + Gtk::TreeModel::Children children = row.children(); + if (row[_mColumns._colObj]) { + SPObject *obj = row[_mColumns._colObj]; + _desktop->selection->add(obj); + } + if (children) { + _checkAllChildren(children); + } } } } diff --git a/src/ui/dialog/styledialog.h b/src/ui/dialog/styledialog.h index 79897a5b6..4193752e3 100644 --- a/src/ui/dialog/styledialog.h +++ b/src/ui/dialog/styledialog.h @@ -50,6 +50,8 @@ private: void _selectedRowCallback(const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* /* column */); void _checkAllChildren(Gtk::TreeModel::Children& children); + Inkscape::XML::Node *_styleElementNode(); + void _updateStyleContent(); class ModelColumns : public Gtk::TreeModel::ColumnRecord { -- cgit v1.2.3 From cc89ba02cda5257f76df813d86318b57469ee81e Mon Sep 17 00:00:00 2001 From: kamalpreetgrewal Date: Thu, 30 Jun 2016 15:02:15 +0530 Subject: If selectors(children) of a row in treeview are deleted, XML repr is updated and also remove duplicate style element(if one already exists) (bzr r14949.1.33) --- src/ui/dialog/styledialog.cpp | 96 ++++++++++++++++++++++++++++--------------- src/ui/dialog/styledialog.h | 2 +- 2 files changed, 65 insertions(+), 33 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index 1b93fb550..3b01faa10 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -83,7 +83,7 @@ StyleDialog::StyleDialog() : del = manage( new Gtk::Button() ); _styleButton(*del, "list-remove", "Remove a CSS Selector"); del->signal_clicked().connect(sigc::mem_fun(*this, - &StyleDialog::_delSelector)); + &StyleDialog::_delSelector)); del->set_sensitive(false); _mainBox.pack_end(_buttonBox, Gtk::PACK_SHRINK); @@ -105,7 +105,7 @@ StyleDialog::StyleDialog() : _styleExists = false; _document = _targetDesktop->doc(); _num = _document->getReprRoot()->childCount(); - _sValue = _populateTree(_getSelectorVec()); + _selectorValue = _populateTree(_getSelectorVec()); _treeView.signal_button_press_event().connect(sigc::mem_fun(*this, &StyleDialog:: @@ -172,7 +172,7 @@ void StyleDialog::_addSelector() * with a dot. */ if (!textEditPtr->get_text().empty()) { - _selectorName = textEditPtr->get_text(); + _selectorName = textEditPtr->get_text(); } else { _selectorName = ".Class1"; @@ -199,7 +199,7 @@ void StyleDialog::_addSelector() if (obj->getRepr()->attribute("style")) { for (List iter = obj->getRepr()->attributeList(); - iter; ++iter) { + iter; ++iter) { gchar const * property = g_quark_to_string(iter->key); gchar const * value = iter->value; @@ -256,17 +256,12 @@ void StyleDialog::_addSelector() if (_styleElementNode()) { _styleChild = _styleElementNode(); - _styleExists = true; - } - else { - _styleExists = false; + _updateStyleContent(); } - - if (_styleExists) { + else if (_styleExists && !_newDrawing) { _updateStyleContent(); } - else { - _sValue = _selectorValue; + else if (!_styleExists) { Inkscape::XML::Node *root = _document->getReprDoc()->root(); Inkscape::XML::Node *newChild = _document->getReprDoc() ->createElement("svg:style"); @@ -292,17 +287,16 @@ void StyleDialog::_updateStyleContent() for (unsigned i = 0; i < _selectorVec.size(); ++i) { styleContent = styleContent + _selectorVec[i].second; } - _styleElementNode()->firstChild()->setContent(styleContent.c_str()); + _styleChild->firstChild()->setContent(styleContent.c_str()); } /** * @brief StyleDialog::_delSelector * This function deletes selector when '-' at the bottom is clicked. The index * of selected row is obtained and the corresponding selector and its values are - * deleted from the selector vector. Then _sValue's content is reset and contains - * only selectors remaining in the selVec (or treeview). - * TODO: get index of children of rows for correct deletion of rows having - * children. + * deleted from the selector vector. If a row has no parent, it is directly + * erased from the vector else the string containing selector row's selector value + * is updated after parsing. */ void StyleDialog::_delSelector() { @@ -316,7 +310,37 @@ void StyleDialog::_delSelector() int i = atoi(path.to_string().c_str()); if (_selectorVec.size() != 0) { - _selectorVec.erase(_selectorVec.begin()+i); + if (!row.parent()) { + _selectorVec.erase(_selectorVec.begin()+i); + } + else { + std::stringstream str; + std::string sel, key, value; + int i; + + for (unsigned it = 0; it < _selectorVec.size(); ++it) { + str << _selectorVec[it].second; + i = it; + } + + while (std::getline(str, sel, '\n')) { + REMOVE_SPACES(sel); + if (!sel.empty()) { + key = strtok(strdup(sel.c_str()), "{"); + char *temp = strtok(NULL, "}"); + if (strtok(temp, "}") != NULL) { + value = strtok(temp, "}"); + } + if (key == "#" + row[_mColumns._selectorLabel]) { + sel = ""; + } + else { + sel = sel; + } + _selectorVec[i].second = sel; + } + } + } /** * If there is a _styleChild which contains the style element, then @@ -347,6 +371,8 @@ Inkscape::XML::Node* StyleDialog::_styleElementNode() for (unsigned i = 0; i < _num; ++i) { if (std::string(_document->getReprRoot()->nthChild(i)->name()) == "svg:style") { + _styleExists = true; + _newDrawing = true; return _document->getReprRoot()->nthChild(i); } else { @@ -376,15 +402,17 @@ std::string StyleDialog::_setClassAttribute(std::vector sel) * @return selVec * This function returns a vector whose key is the style selector name and value * is the style properties. All style selectors are extracted from svg:style - * element. + * element. _newDrawing is flag is set to false check if an existing drawing is + * opened. */ std::vector >StyleDialog::_getSelectorVec() { std::string key, value; - std::vector > selVec; - for (unsigned i = 0; i < _num; ++i) { if (std::string(_document->getReprRoot()->nthChild(i)->name()) == "svg:style") { + _styleExists = true; + _newDrawing = false; + _styleChild = _document->getReprRoot()->nthChild(i); std::stringstream str; str << _document->getReprRoot()->nthChild(i)->firstChild()->content(); std::string sel; @@ -401,12 +429,12 @@ std::vector >StyleDialog::_getSelectorVec() if (strtok(temp, "}") != NULL) { value = strtok(temp, "}"); } - selVec.push_back(std::make_pair(key, value)); + _selectorVec.push_back(std::make_pair(key, sel)); } } } } - return selVec; + return _selectorVec; } /** @@ -418,23 +446,21 @@ std::vector >StyleDialog::_getSelectorVec() std::string StyleDialog::_populateTree(std::vector > _selVec) { - std::vector > _selectVec = _selVec; + _selectorVec = _selVec; std::string selectorValue; - for(unsigned it = 0; it < _selectVec.size(); ++it) { + for(unsigned it = 0; it < _selectorVec.size(); ++it) { Gtk::TreeModel::Row row = *(_store->append()); - row[_mColumns._selectorLabel] = _selectVec[it].first; - std::string selValue = _selectVec[it].first + "{" - + _selectVec[it].second + "}" + "\n"; + row[_mColumns._selectorLabel] = _selectorVec[it].first; + _selectorVec[it].second = _selectorVec[it].second + "\n"; + std::string selValue = _selectorVec[it].second; selectorValue.append(selValue.c_str()); } - if (_selectVec.size() > 0) { + if (_selectorVec.size() > 0) { del->set_sensitive(true); } - _styleChild = _styleElementNode(); - return selectorValue; } @@ -489,7 +515,13 @@ bool StyleDialog::_handleButtonEvent(GdkEventButton *event) } _selectorVec.push_back(std::make_pair(obj->getId(), childStyle)); } - _updateStyleContent(); + if (_styleElementNode()) { + _styleChild = _styleElementNode(); + _updateStyleContent(); + } + else if (_styleExists && !_newDrawing) { + _updateStyleContent(); + } } } } diff --git a/src/ui/dialog/styledialog.h b/src/ui/dialog/styledialog.h index 4193752e3..fef1a954b 100644 --- a/src/ui/dialog/styledialog.h +++ b/src/ui/dialog/styledialog.h @@ -75,12 +75,12 @@ private: Gtk::Button* create; SPDocument* _document; bool _styleExists; - std::string _sValue ; Inkscape::XML::Node *_styleChild; unsigned _num; std::string _selectorName = ""; std::string _selectorValue; Gtk::TreeModel::Row _row; + bool _newDrawing; // Signal handlers void _addSelector(); -- cgit v1.2.3 From 0af04b99d1160cf2cfc38adb3a0f74c185da4370 Mon Sep 17 00:00:00 2001 From: kamalpreetgrewal Date: Thu, 30 Jun 2016 18:43:15 +0530 Subject: Solve some compiler errors (bzr r14949.1.34) --- src/ui/dialog/styledialog.cpp | 12 +++++------- src/ui/dialog/styledialog.h | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index 3b01faa10..3d2091aef 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -316,11 +316,11 @@ void StyleDialog::_delSelector() else { std::stringstream str; std::string sel, key, value; - int i; + int index; for (unsigned it = 0; it < _selectorVec.size(); ++it) { str << _selectorVec[it].second; - i = it; + index = it; } while (std::getline(str, sel, '\n')) { @@ -337,7 +337,7 @@ void StyleDialog::_delSelector() else { sel = sel; } - _selectorVec[i].second = sel; + _selectorVec[index].second = sel; } } } @@ -375,10 +375,8 @@ Inkscape::XML::Node* StyleDialog::_styleElementNode() _newDrawing = true; return _document->getReprRoot()->nthChild(i); } - else { - return NULL; - } } + return NULL; } /** @@ -495,7 +493,6 @@ bool StyleDialog::_handleButtonEvent(GdkEventButton *event) if (iter) { Gtk::TreeModel::Row row = *iter; - typedef Gtk::TreeModel::Children type_children; Gtk::TreeModel::Row childrow; path = _treeView.get_model()->get_path(iter); childrow = *(_store->append(row->children())); @@ -527,6 +524,7 @@ bool StyleDialog::_handleButtonEvent(GdkEventButton *event) } } } + return false; } /** diff --git a/src/ui/dialog/styledialog.h b/src/ui/dialog/styledialog.h index fef1a954b..0192b3987 100644 --- a/src/ui/dialog/styledialog.h +++ b/src/ui/dialog/styledialog.h @@ -77,7 +77,7 @@ private: bool _styleExists; Inkscape::XML::Node *_styleChild; unsigned _num; - std::string _selectorName = ""; + std::string _selectorName; std::string _selectorValue; Gtk::TreeModel::Row _row; bool _newDrawing; -- cgit v1.2.3 From 2c22c31cb8650ad49f5e83c9221524f4cdcd3ddd Mon Sep 17 00:00:00 2001 From: kamalpreetgrewal Date: Fri, 1 Jul 2016 12:37:35 +0530 Subject: Solve a spacing issue & fix buttons to add selectors when existing drawing is opened (bzr r14949.1.35) --- src/ui/dialog/styledialog.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index 3d2091aef..3ee0e44f7 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -20,7 +20,7 @@ using Inkscape::Util::List; using Inkscape::XML::AttributeRecord; -#define REMOVE_SPACES(x) x.erase(std::remove(x.begin(), x.end(), ' '), x.end()); +#define REMOVE_SPACES(x) x.erase(0, x.find_first_not_of(' ')); namespace Inkscape { namespace UI { @@ -450,6 +450,7 @@ std::string StyleDialog::_populateTree(std::vectorappend()); row[_mColumns._selectorLabel] = _selectorVec[it].first; + row[_mColumns._colAddRemove] = true; _selectorVec[it].second = _selectorVec[it].second + "\n"; std::string selValue = _selectorVec[it].second; selectorValue.append(selValue.c_str()); -- cgit v1.2.3 From 7c35f8e864197a1b2620a5337947bcdfd0b52d5a Mon Sep 17 00:00:00 2001 From: kamalpreetgrewal Date: Fri, 1 Jul 2016 17:19:45 +0530 Subject: Add support to select corresponding treeview rows when objects are selected (bzr r14949.1.36) --- src/ui/dialog/styledialog.cpp | 55 ++++++++++++++++++++++++++++++++++++------- src/ui/dialog/styledialog.h | 8 ++++--- 2 files changed, 52 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index 3ee0e44f7..406b984d7 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -20,7 +20,8 @@ using Inkscape::Util::List; using Inkscape::XML::AttributeRecord; -#define REMOVE_SPACES(x) x.erase(0, x.find_first_not_of(' ')); +#define REMOVE_SPACES(x) x.erase(0, x.find_first_not_of(' ')); \ + x.erase(x.find_last_not_of(' ') + 1); namespace Inkscape { namespace UI { @@ -126,6 +127,8 @@ void StyleDialog::setDesktop( SPDesktop* desktop ) { Panel::setDesktop(desktop); _desktop = Panel::getDesktop(); + _desktop->selection->connectChanged(sigc::mem_fun(*this, &StyleDialog:: + _selectRow)); } /** @@ -189,6 +192,7 @@ void StyleDialog::_addSelector() * class attribute for the selected object is set too. */ SPObject *obj; + SPObject *selectorObj; bool objExists = false; if (!_desktop->getSelection()->list().empty()) { std::vector selected = _desktop->getSelection()->list(); @@ -241,6 +245,7 @@ void StyleDialog::_addSelector() _row[_mColumns._colAddRemove] = true; if (objExists) { _row[_mColumns._colObj] = obj; + selectorObj = obj; } break; default: @@ -252,7 +257,8 @@ void StyleDialog::_addSelector() * from selectorValue above. If style element already exists, then * the new selector's content is appended to its previous content. */ - _selectorVec.push_back(std::make_pair(_selectorName, _selectorValue)); + _selectorVec.push_back(std::make_pair(std::make_pair(_selectorName, selectorObj), + _selectorValue)); if (_styleElementNode()) { _styleChild = _styleElementNode(); @@ -403,7 +409,7 @@ std::string StyleDialog::_setClassAttribute(std::vector sel) * element. _newDrawing is flag is set to false check if an existing drawing is * opened. */ -std::vector >StyleDialog::_getSelectorVec() +std::vector, std::string> > StyleDialog::_getSelectorVec() { std::string key, value; for (unsigned i = 0; i < _num; ++i) { @@ -427,7 +433,12 @@ std::vector >StyleDialog::_getSelectorVec() if (strtok(temp, "}") != NULL) { value = strtok(temp, "}"); } - _selectorVec.push_back(std::make_pair(key, sel)); + std::string selId = key.erase(0, key.find_first_not_of('#')); + REMOVE_SPACES(selId); + REMOVE_SPACES(key); + SPObject *obj = _document->getObjectById(selId); + _selectorVec.push_back(std::make_pair(std::make_pair(key, obj), + sel)); } } } @@ -441,16 +452,17 @@ std::vector >StyleDialog::_getSelectorVec() * This function populates the treeview with selectors available in the * stylesheet. */ -std::string StyleDialog::_populateTree(std::vector > _selVec) +std::string StyleDialog::_populateTree(std::vector, std::string> > _selVec) { _selectorVec = _selVec; std::string selectorValue; for(unsigned it = 0; it < _selectorVec.size(); ++it) { Gtk::TreeModel::Row row = *(_store->append()); - row[_mColumns._selectorLabel] = _selectorVec[it].first; + row[_mColumns._selectorLabel] = _selectorVec[it].first.first; row[_mColumns._colAddRemove] = true; + row[_mColumns._colObj] = _selectorVec[it].first.second; _selectorVec[it].second = _selectorVec[it].second + "\n"; std::string selValue = _selectorVec[it].second; selectorValue.append(selValue.c_str()); @@ -511,7 +523,9 @@ bool StyleDialog::_handleButtonEvent(GdkEventButton *event) std::string(obj->getAttribute("style")) + "}\n"; } } - _selectorVec.push_back(std::make_pair(obj->getId(), childStyle)); + _selectorVec.push_back(std::make_pair(std::make_pair + (obj->getId(), obj), + childStyle)); } if (_styleElementNode()) { _styleChild = _styleElementNode(); @@ -572,6 +586,31 @@ void StyleDialog::_checkAllChildren(Gtk::TreeModel::Children& children) } } +/** + * @brief StyleDialog::_selectRow + * This function selects the rows in treeview corresponding to an object selected + * in the drawing. + */ +void StyleDialog::_selectRow(Selection */*sel*/) +{ + if (!_desktop->selection->list().empty()) { + SPObject *obj; + std::vector selected = _desktop->getSelection()->list(); + for (unsigned i = 0; i < selected.size(); ++i) { + obj = selected.at(i); + } + + Gtk::TreeModel::Children children = _store->children(); + for(Gtk::TreeModel::Children::iterator iter = children.begin(); + iter != children.end(); ++iter) { + Gtk::TreeModel::Row row = *iter; + if (obj == row[_mColumns._colObj]) { + _treeView.get_selection()->select(row); + } + } + } +} + } // namespace Dialog } // namespace UI } // namespace Inkscape diff --git a/src/ui/dialog/styledialog.h b/src/ui/dialog/styledialog.h index 0192b3987..6e1ffbb2c 100644 --- a/src/ui/dialog/styledialog.h +++ b/src/ui/dialog/styledialog.h @@ -43,15 +43,17 @@ public: private: void _styleButton( Gtk::Button& btn, char const* iconName, char const* tooltip); std::string _setClassAttribute(std::vector); - std::vector >_selectorVec; - std::vector > _getSelectorVec(); - std::string _populateTree(std::vector >); + std::vector, std::string> >_selectorVec; + std::vector, std::string> > _getSelectorVec(); + std::string _populateTree(std::vector, + std::string> >); bool _handleButtonEvent(GdkEventButton *event); void _selectedRowCallback(const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* /* column */); void _checkAllChildren(Gtk::TreeModel::Children& children); Inkscape::XML::Node *_styleElementNode(); void _updateStyleContent(); + void _selectRow(Selection *); class ModelColumns : public Gtk::TreeModel::ColumnRecord { -- cgit v1.2.3 From f7724473cc5e15c9b9d0e7c2fe362ebedaa69f55 Mon Sep 17 00:00:00 2001 From: kamalpreetgrewal Date: Tue, 5 Jul 2016 13:39:43 +0530 Subject: Fix deletion and selection of objects clicking on styledialog rows and vice-versa (bzr r14949.1.39) --- src/ui/dialog/styledialog.cpp | 159 ++++++++++++++++++++++++++++++------------ src/ui/dialog/styledialog.h | 12 ++-- 2 files changed, 122 insertions(+), 49 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index 406b984d7..b6e3d10ec 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -192,7 +192,8 @@ void StyleDialog::_addSelector() * class attribute for the selected object is set too. */ SPObject *obj; - SPObject *selectorObj; + std::vector objVec; + bool objExists = false; if (!_desktop->getSelection()->list().empty()) { std::vector selected = _desktop->getSelection()->list(); @@ -244,8 +245,8 @@ void StyleDialog::_addSelector() _row[_mColumns._selectorLabel] = _selectorName; _row[_mColumns._colAddRemove] = true; if (objExists) { - _row[_mColumns._colObj] = obj; - selectorObj = obj; + _row[_mColumns._colObj] = _desktop->selection->list(); + objVec = _row[_mColumns._colObj]; } break; default: @@ -257,7 +258,7 @@ void StyleDialog::_addSelector() * from selectorValue above. If style element already exists, then * the new selector's content is appended to its previous content. */ - _selectorVec.push_back(std::make_pair(std::make_pair(_selectorName, selectorObj), + _selectorVec.push_back(std::make_pair(std::make_pair(_selectorName, objVec), _selectorValue)); if (_styleElementNode()) { @@ -320,19 +321,14 @@ void StyleDialog::_delSelector() _selectorVec.erase(_selectorVec.begin()+i); } else { - std::stringstream str; std::string sel, key, value; - int index; - for (unsigned it = 0; it < _selectorVec.size(); ++it) { - str << _selectorVec[it].second; - index = it; - } - - while (std::getline(str, sel, '\n')) { + sel = _selectorVec[it].second; REMOVE_SPACES(sel); + std::cout << "sel" << sel << std::endl; if (!sel.empty()) { key = strtok(strdup(sel.c_str()), "{"); + REMOVE_SPACES(key); char *temp = strtok(NULL, "}"); if (strtok(temp, "}") != NULL) { value = strtok(temp, "}"); @@ -343,7 +339,7 @@ void StyleDialog::_delSelector() else { sel = sel; } - _selectorVec[index].second = sel; + _selectorVec[it].second = sel; } } } @@ -376,7 +372,7 @@ Inkscape::XML::Node* StyleDialog::_styleElementNode() { for (unsigned i = 0; i < _num; ++i) { if (std::string(_document->getReprRoot()->nthChild(i)->name()) - == "svg:style") { + == "svg:style") { _styleExists = true; _newDrawing = true; return _document->getReprRoot()->nthChild(i); @@ -409,9 +405,9 @@ std::string StyleDialog::_setClassAttribute(std::vector sel) * element. _newDrawing is flag is set to false check if an existing drawing is * opened. */ -std::vector, std::string> > StyleDialog::_getSelectorVec() +std::vector<_selectorVecType> StyleDialog::_getSelectorVec() { - std::string key, value; + std::string key, value, selId; for (unsigned i = 0; i < _num; ++i) { if (std::string(_document->getReprRoot()->nthChild(i)->name()) == "svg:style") { _styleExists = true; @@ -426,19 +422,74 @@ std::vector, std::string> > StyleDi * value is set to empty so that its corresponding XML repr is added. */ while(std::getline(str, sel, '\n')) { + std::vectorobjVec; REMOVE_SPACES(sel); if (!sel.empty()) { key = strtok(strdup(sel.c_str()), "{"); + _selectorName = key; char *temp = strtok(NULL, "}"); if (strtok(temp, "}") != NULL) { value = strtok(temp, "}"); } - std::string selId = key.erase(0, key.find_first_not_of('#')); - REMOVE_SPACES(selId); - REMOVE_SPACES(key); - SPObject *obj = _document->getObjectById(selId); - _selectorVec.push_back(std::make_pair(std::make_pair(key, obj), - sel)); + + std::stringstream ss(key); + std::string token; + std::size_t found = key.find(","); + if (found!=std::string::npos) { + while(std::getline(ss, token, ',')) { + REMOVE_SPACES(token); + + if (strcmp(token.substr(0,1).c_str(), ".") == 0) { + token.erase(0, token.find_first_not_of('.')); + for (unsigned i = 0; i < _num; ++i) { + if (_document->getReprRoot()-> + nthChild(i)->attribute("class") && + _document->getReprRoot()->nthChild(i) + ->attribute("class") == token) { + selId = _document->getReprRoot()->nthChild(i) + ->attribute("id"); + objVec.push_back( _document->getObjectById(selId)); + } + } + } + else if (strcmp(token.substr(0,1).c_str(), "#") == 0) { + token.erase(0, token.find_first_not_of('#')); + selId = token; + objVec.push_back(_document->getObjectById(selId)); + } + else { + std::cout << "simple text" << std::endl; + } + } + } + else { + REMOVE_SPACES(key); + std::string tkn = key; + if (strcmp(tkn.substr(0,1).c_str(), ".") == 0) { + tkn.erase(0, tkn.find_first_not_of('.')); + for (unsigned i = 0; i < _num; ++i) { + if (_document->getReprRoot()-> + nthChild(i)->attribute("class") && + _document->getReprRoot()->nthChild(i) + ->attribute("class") == tkn) { + selId = _document->getReprRoot()->nthChild(i) + ->attribute("id"); + objVec.push_back(_document->getObjectById(selId)); + } + } + } + else if (strcmp(tkn.substr(0,1).c_str(), "#") == 0) { + tkn.erase(0, key.find_first_not_of('#')); + selId = tkn; + objVec.push_back(_document->getObjectById(selId)); + } + else { + std::cout << "simple text" << std::endl; + } + } + _selectorValue = _selectorName + "{" + value + "}\n"; + _selectorVec.push_back(std::make_pair(std::make_pair(key, objVec), + _selectorValue)); } } } @@ -452,8 +503,7 @@ std::vector, std::string> > StyleDi * This function populates the treeview with selectors available in the * stylesheet. */ -std::string StyleDialog::_populateTree(std::vector, std::string> > _selVec) +std::string StyleDialog::_populateTree(std::vector<_selectorVecType> _selVec) { _selectorVec = _selVec; std::string selectorValue; @@ -463,7 +513,6 @@ std::string StyleDialog::_populateTree(std::vectorget_path(iter); - childrow = *(_store->append(row->children())); - childrow[_mColumns._selectorLabel] = obj->getId(); - childrow[_mColumns._colAddRemove] = false; - childrow[_mColumns._colObj] = obj; - Gtk::TreeModel::Children children = row.children(); + int i = atoi(path.to_string().c_str()); + Gtk::TreeModel::Row row = *iter; std::string childStyle; - if (children) { - for(Gtk::TreeModel::Children::iterator it = children.begin(); - it != children.end(); ++it) { - Gtk::TreeModel::Row row = *it; - SPObject *obj = row[_mColumns._colObj]; + + if (_selectorVec.size() != 0) { + if (!row.parent()) { + Gtk::TreeModel::Row childrow; + childrow = *(_store->append(row->children())); + std::cout << "_store->children() " << _store->children() + ->children().size() << std::endl; + + childrow[_mColumns._selectorLabel] = obj->getId(); + childrow[_mColumns._colAddRemove] = false; + childrow[_mColumns._colObj] = _desktop->selection->list(); childStyle = "#" + std::string(obj->getId()) + "{" + std::string(obj->getAttribute("style")) + "}\n"; } } + _selectorVec.push_back(std::make_pair(std::make_pair - (obj->getId(), obj), + (obj->getId(), + sel), childStyle)); } if (_styleElementNode()) { @@ -557,8 +609,9 @@ void StyleDialog::_selectedRowCallback(const Gtk::TreeModel::Path& path, if (iter) { Gtk::TreeModel::Row row = *iter; Gtk::TreeModel::Children children = row.children(); - if (row[_mColumns._colObj]) { - SPObject *obj = row[_mColumns._colObj]; + std::vector objVec = row[_mColumns._colObj]; + for (unsigned i = 0; i < objVec.size(); ++i) { + SPObject *obj = objVec[i]; _desktop->selection->add(obj); } if (children) { @@ -579,8 +632,9 @@ void StyleDialog::_checkAllChildren(Gtk::TreeModel::Children& children) for (Gtk::TreeModel::Children::iterator iter = children.begin(); iter!= children.end(); ++iter) { Gtk::TreeModel::Row childrow = *iter; - if (childrow[_mColumns._colObj]) { - SPObject *obj = childrow[_mColumns._colObj]; + std::vector objVec = childrow[_mColumns._colObj]; + for (unsigned i = 0; i < objVec.size(); ++i) { + SPObject *obj = objVec[i]; _desktop->selection->add(obj); } } @@ -604,8 +658,25 @@ void StyleDialog::_selectRow(Selection */*sel*/) for(Gtk::TreeModel::Children::iterator iter = children.begin(); iter != children.end(); ++iter) { Gtk::TreeModel::Row row = *iter; - if (obj == row[_mColumns._colObj]) { - _treeView.get_selection()->select(row); + std::vector objVec = row[_mColumns._colObj]; + std::vector childObjVec; + Gtk::TreeModel::Row childRow; + if (row.children()) { + for(Gtk::TreeModel::Children::iterator it = row.children().begin(); + it != row.children().end(); ++it) { + childRow = *it; + childObjVec = childRow[_mColumns._colObj]; + } + } + for (unsigned i = 0; i < objVec.size(); ++i) { + if (obj->getId() == objVec[i]->getId()) { + _treeView.get_selection()->select(row); + } + } + for (unsigned j = 0; j < childObjVec.size(); ++j) { + if (obj->getId() == childObjVec[j]->getId()) { + _treeView.get_selection()->select(childRow); + } } } } diff --git a/src/ui/dialog/styledialog.h b/src/ui/dialog/styledialog.h index 6e1ffbb2c..e47fbc96d 100644 --- a/src/ui/dialog/styledialog.h +++ b/src/ui/dialog/styledialog.h @@ -30,6 +30,8 @@ namespace Dialog { * @brief The StyleDialog class * A list of CSS selectors will show up in this dialog. */ +typedef std::pair >, std::string> +_selectorVecType; class StyleDialog : public UI::Widget::Panel { @@ -43,10 +45,10 @@ public: private: void _styleButton( Gtk::Button& btn, char const* iconName, char const* tooltip); std::string _setClassAttribute(std::vector); - std::vector, std::string> >_selectorVec; - std::vector, std::string> > _getSelectorVec(); - std::string _populateTree(std::vector, - std::string> >); + + std::vector<_selectorVecType>_selectorVec; + std::vector<_selectorVecType> _getSelectorVec(); + std::string _populateTree(std::vector<_selectorVecType>); bool _handleButtonEvent(GdkEventButton *event); void _selectedRowCallback(const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* /* column */); @@ -62,7 +64,7 @@ private: { add(_selectorLabel); add(_colAddRemove); add(_colObj); } Gtk::TreeModelColumn _selectorLabel; Gtk::TreeModelColumn _colAddRemove; - Gtk::TreeModelColumn _colObj; + Gtk::TreeModelColumn > _colObj; }; SPDesktop* _desktop; -- cgit v1.2.3 From 7c612210cbeecef13c9148a3e35a5f73dd5a6347 Mon Sep 17 00:00:00 2001 From: kamalpreetgrewal Date: Wed, 6 Jul 2016 14:38:04 +0530 Subject: Fix issues related to updating style content and selection of rows in treeview (bzr r14949.1.40) --- src/ui/dialog/styledialog.cpp | 62 ++++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index b6e3d10ec..72fea5dc6 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -200,23 +200,16 @@ void StyleDialog::_addSelector() for (unsigned i = 0; i < selected.size(); ++i) { obj = selected.at(i); objExists = true; - std::string style; - - if (obj->getRepr()->attribute("style")) { - for (List iter = obj->getRepr()->attributeList(); - iter; ++iter) { - gchar const * property = g_quark_to_string(iter->key); - gchar const * value = iter->value; + if (!obj->getRepr()->attribute("style")) { + obj->getRepr()->setAttribute("style", NULL); + } - if (std::string(property) == "style") { - _selectorValue = _selectorName + "{" - + std::string(value) + "}" + "\n"; - } - } + if (obj->getAttribute("style") == NULL) { + _selectorValue = _selectorName + "{" + "}" + "\n"; } else { - style = " "; - obj->getRepr()->setAttribute("style", style); + _selectorValue = _selectorName + "{" + + obj->getAttribute("style") + "}" + "\n"; } if (strcmp(_selectorName.substr(0,1).c_str(), ".") == 0) { @@ -647,13 +640,20 @@ void StyleDialog::_checkAllChildren(Gtk::TreeModel::Children& children) */ void StyleDialog::_selectRow(Selection */*sel*/) { + SPObject *obj = NULL; + bool objExists = false; if (!_desktop->selection->list().empty()) { - SPObject *obj; std::vector selected = _desktop->getSelection()->list(); - for (unsigned i = 0; i < selected.size(); ++i) { - obj = selected.at(i); - } + obj = selected.back(); + } + /** + * If obj has some SPObject, then it is added to desktop's selection. If a + * row in treeview has children, those rows are checked too against selected + * object's id. If an object which is not present in any selector is selected, + * the treeview's selections are unselected. + */ + if (obj != NULL) { Gtk::TreeModel::Children children = _store->children(); for(Gtk::TreeModel::Children::iterator iter = children.begin(); iter != children.end(); ++iter) { @@ -661,24 +661,32 @@ void StyleDialog::_selectRow(Selection */*sel*/) std::vector objVec = row[_mColumns._colObj]; std::vector childObjVec; Gtk::TreeModel::Row childRow; + + for (unsigned i = 0; i < objVec.size(); ++i) { + if (obj->getId() == objVec[i]->getId()) { + _treeView.get_selection()->select(row); + objExists = true; + } + } + if (row.children()) { for(Gtk::TreeModel::Children::iterator it = row.children().begin(); it != row.children().end(); ++it) { childRow = *it; childObjVec = childRow[_mColumns._colObj]; } - } - for (unsigned i = 0; i < objVec.size(); ++i) { - if (obj->getId() == objVec[i]->getId()) { - _treeView.get_selection()->select(row); - } - } - for (unsigned j = 0; j < childObjVec.size(); ++j) { - if (obj->getId() == childObjVec[j]->getId()) { - _treeView.get_selection()->select(childRow); + for (unsigned j = 0; j < childObjVec.size(); ++j) { + if (obj->getId() == childObjVec[j]->getId()) { + _treeView.get_selection()->select(childRow); + objExists = true; + } } } } + + if (!objExists) { + _treeView.get_selection()->unselect_all(); + } } } -- cgit v1.2.3 From 67f04a5e0e1bff0523a97d4aa16357849e51e1d8 Mon Sep 17 00:00:00 2001 From: kamalpreetgrewal Date: Fri, 8 Jul 2016 17:19:12 +0530 Subject: Selects matching objects for single as well as double click on selector (bzr r14949.1.42) --- src/ui/dialog/styledialog.cpp | 89 +++++++++++++++++++++++++++---------------- src/ui/dialog/styledialog.h | 4 +- 2 files changed, 59 insertions(+), 34 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index 72fea5dc6..7e0cb135f 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -113,9 +113,10 @@ StyleDialog::StyleDialog() : _handleButtonEvent), false); - _treeView.signal_row_activated().connect(sigc::mem_fun(*this, - &StyleDialog:: - _selectedRowCallback)); + _treeView.signal_button_press_event().connect_notify(sigc::mem_fun + (*this, &StyleDialog:: + _buttonEventsSelectObjs), + false); } StyleDialog::~StyleDialog() @@ -548,18 +549,14 @@ bool StyleDialog::_handleButtonEvent(GdkEventButton *event) if (iter) { path = _treeView.get_model()->get_path(iter); - int i = atoi(path.to_string().c_str()); Gtk::TreeModel::Row row = *iter; std::string childStyle; - if (_selectorVec.size() != 0) { if (!row.parent()) { Gtk::TreeModel::Row childrow; childrow = *(_store->append(row->children())); - std::cout << "_store->children() " << _store->children() - ->children().size() << std::endl; - - childrow[_mColumns._selectorLabel] = obj->getId(); + childrow[_mColumns._selectorLabel] = "#" + + std::string(obj->getId()); childrow[_mColumns._colAddRemove] = false; childrow[_mColumns._colObj] = _desktop->selection->list(); childStyle = "#" + std::string(obj->getId()) + "{" + @@ -588,27 +585,59 @@ bool StyleDialog::_handleButtonEvent(GdkEventButton *event) } /** - * @brief StyleDialog::_selected_row_callback - * @param path + * @brief StyleDialog::_selectObjects + * @param event + * This function detects single or double click on a selector in any row. Single + * click on a selector selects the matching objects. A double click on any + * selector selects the matching objects as well as will open CSS dialog. It + * calls _selectObjects to add objects to selection. + * TODO: Open CSS dialog on double click. + */ +void StyleDialog::_buttonEventsSelectObjs(GdkEventButton* event ) +{ + if (event->type == GDK_BUTTON_PRESS && event->button == 1) { + int x = static_cast(event->x); + int y = static_cast(event->y); + _selectObjects(x, y); + } + else if (event->type == GDK_2BUTTON_PRESS && event->button == 1) { + int x = static_cast(event->x); + int y = static_cast(event->y); + _selectObjects(x, y); + //Open CSS dialog here. + } +} + +/** + * @brief StyleDialog::_selectObjects + * @param eventX + * @param eventY * This function selects objects in the drawing corresponding to the selector * selected in the treeview. */ -void StyleDialog::_selectedRowCallback(const Gtk::TreeModel::Path& path, - Gtk::TreeViewColumn* column ) +void StyleDialog::_selectObjects(int eventX, int eventY) { _desktop->selection->clear(); - if (column == _treeView.get_column(1)) { - Gtk::TreeModel::iterator iter = _store->get_iter(path); - if (iter) { - Gtk::TreeModel::Row row = *iter; - Gtk::TreeModel::Children children = row.children(); - std::vector objVec = row[_mColumns._colObj]; - for (unsigned i = 0; i < objVec.size(); ++i) { - SPObject *obj = objVec[i]; - _desktop->selection->add(obj); - } - if (children) { - _checkAllChildren(children); + Gtk::TreeViewColumn *col = _treeView.get_column(1); + Gtk::TreeModel::Path path; + int x = eventX; + int y = eventY; + int x2 = 0; + int y2 = 0; + if (_treeView.get_path_at_pos(x, y, path, col, x2, y2)) { + if (col == _treeView.get_column(1)) { + Gtk::TreeModel::iterator iter = _store->get_iter(path); + if (iter) { + Gtk::TreeModel::Row row = *iter; + Gtk::TreeModel::Children children = row.children(); + std::vector objVec = row[_mColumns._colObj]; + for (unsigned i = 0; i < objVec.size(); ++i) { + SPObject *obj = objVec[i]; + _desktop->selection->add(obj); + } + if (children) { + _checkAllChildren(children); + } } } } @@ -641,7 +670,6 @@ void StyleDialog::_checkAllChildren(Gtk::TreeModel::Children& children) void StyleDialog::_selectRow(Selection */*sel*/) { SPObject *obj = NULL; - bool objExists = false; if (!_desktop->selection->list().empty()) { std::vector selected = _desktop->getSelection()->list(); obj = selected.back(); @@ -665,7 +693,6 @@ void StyleDialog::_selectRow(Selection */*sel*/) for (unsigned i = 0; i < objVec.size(); ++i) { if (obj->getId() == objVec[i]->getId()) { _treeView.get_selection()->select(row); - objExists = true; } } @@ -678,15 +705,13 @@ void StyleDialog::_selectRow(Selection */*sel*/) for (unsigned j = 0; j < childObjVec.size(); ++j) { if (obj->getId() == childObjVec[j]->getId()) { _treeView.get_selection()->select(childRow); - objExists = true; } } } } - - if (!objExists) { - _treeView.get_selection()->unselect_all(); - } + } + else { + _treeView.get_selection()->unselect_all(); } } diff --git a/src/ui/dialog/styledialog.h b/src/ui/dialog/styledialog.h index e47fbc96d..08061d923 100644 --- a/src/ui/dialog/styledialog.h +++ b/src/ui/dialog/styledialog.h @@ -50,8 +50,8 @@ private: std::vector<_selectorVecType> _getSelectorVec(); std::string _populateTree(std::vector<_selectorVecType>); bool _handleButtonEvent(GdkEventButton *event); - void _selectedRowCallback(const Gtk::TreeModel::Path& path, - Gtk::TreeViewColumn* /* column */); + void _buttonEventsSelectObjs(GdkEventButton *event); + void _selectObjects(int, int); void _checkAllChildren(Gtk::TreeModel::Children& children); Inkscape::XML::Node *_styleElementNode(); void _updateStyleContent(); -- cgit v1.2.3 From f57322fc77c604c6102132b6a254280e1f597064 Mon Sep 17 00:00:00 2001 From: kamalpreetgrewal Date: Sat, 9 Jul 2016 16:04:31 +0530 Subject: Delete objects from selector by clicking '-' in front of objects (bzr r14949.1.44) --- src/ui/dialog/styledialog.cpp | 148 +++++++++++++++++++++++++++++------------- 1 file changed, 104 insertions(+), 44 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index 7e0cb135f..ac51e36c1 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -223,7 +223,7 @@ void StyleDialog::_addSelector() getRepr()-> attribute("class")) + " " + textEditPtr->get_text() - .erase(0,0)); + .erase(0,1)); } } } @@ -296,46 +296,43 @@ void StyleDialog::_updateStyleContent() * This function deletes selector when '-' at the bottom is clicked. The index * of selected row is obtained and the corresponding selector and its values are * deleted from the selector vector. If a row has no parent, it is directly - * erased from the vector else the string containing selector row's selector value - * is updated after parsing. + * erased from the vector along with its child rows. The style element is updated + * accordingly. */ void StyleDialog::_delSelector() { Glib::RefPtr refTreeSelection = _treeView.get_selection(); Gtk::TreeModel::iterator iter = refTreeSelection->get_selected(); - Gtk::TreeModel::Path path; - if (iter) { Gtk::TreeModel::Row row = *iter; - path = _treeView.get_model()->get_path(iter); - int i = atoi(path.to_string().c_str()); + std::string sel, key, value; + std::vector<_selectorVecType>::iterator it; + for (it = _selectorVec.begin(); it != _selectorVec.end(); ++it ) { + sel = (*it).second; + REMOVE_SPACES(sel); + if (!sel.empty()) { + key = strtok(strdup(sel.c_str()), "{"); + REMOVE_SPACES(key); + char *temp = strtok(NULL, "}"); + if (strtok(temp, "}") != NULL) { + value = strtok(temp, "}"); + } + } + } if (_selectorVec.size() != 0) { if (!row.parent()) { - _selectorVec.erase(_selectorVec.begin()+i); - } - else { - std::string sel, key, value; - for (unsigned it = 0; it < _selectorVec.size(); ++it) { - sel = _selectorVec[it].second; - REMOVE_SPACES(sel); - std::cout << "sel" << sel << std::endl; - if (!sel.empty()) { - key = strtok(strdup(sel.c_str()), "{"); - REMOVE_SPACES(key); - char *temp = strtok(NULL, "}"); - if (strtok(temp, "}") != NULL) { - value = strtok(temp, "}"); - } - if (key == "#" + row[_mColumns._selectorLabel]) { - sel = ""; - } - else { - sel = sel; + if (!row.children().empty()) { + for (Gtk::TreeModel::Children::iterator child = row.children().begin(); + child != row.children().end(); ++child) { + Gtk::TreeModel::Row childrow = *child; + if (key == childrow[_mColumns._selectorLabel]) { + _selectorVec.erase(it); } - _selectorVec[it].second = sel; } } + _selectorVec.erase(it); + _store->erase(row); } /** @@ -351,7 +348,6 @@ void StyleDialog::_delSelector() _updateStyleContent(); } } - _store->erase(row); } } @@ -537,22 +533,29 @@ bool StyleDialog::_handleButtonEvent(GdkEventButton *event) int y2 = 0; if (_treeView.get_path_at_pos(x, y, path, col, x2, y2)) { if (col == _treeView.get_column(0)) { - if (_desktop->selection) { - std::vectorsel = _desktop->selection->list(); - for (unsigned i = 0; i < sel.size(); ++i) { - SPObject *obj = sel[i]; - Glib::RefPtr refTreeSelection = - _treeView.get_selection(); - Gtk::TreeModel::iterator iter = refTreeSelection-> - get_selected(); - - if (iter) - { - path = _treeView.get_model()->get_path(iter); - Gtk::TreeModel::Row row = *iter; + Glib::RefPtr refTreeSelection = + _treeView.get_selection(); + Gtk::TreeModel::iterator iter = refTreeSelection-> + get_selected(); + Gtk::TreeModel::Row row = *iter; + + /** + * This adds child rows to selected rows. If the parent row is + * a class selector, then the class attribute of object added + * to child row is appended with class in the parent row. The + * else below deletes objects from selectors when 'delete' button + * in front of child row is clicked. The class attribute is updated + * by removing the parent row's class selector name. + */ + if (!row.parent()) { + if (_desktop->selection) { + std::vectorsel = _desktop->selection->list(); + for (unsigned i = 0; i < sel.size(); ++i) { + SPObject *obj = sel[i]; std::string childStyle; - if (_selectorVec.size() != 0) { - if (!row.parent()) { + if (iter) { + path = _treeView.get_model()->get_path(iter); + if (_selectorVec.size() != 0) { Gtk::TreeModel::Row childrow; childrow = *(_store->append(row->children())); childrow[_mColumns._selectorLabel] = "#" + @@ -561,6 +564,19 @@ bool StyleDialog::_handleButtonEvent(GdkEventButton *event) childrow[_mColumns._colObj] = _desktop->selection->list(); childStyle = "#" + std::string(obj->getId()) + "{" + std::string(obj->getAttribute("style")) + "}\n"; + Glib::ustring key = row[_mColumns._selectorLabel]; + if (strcmp(key.substr(0,1).c_str(), ".") == 0) { + if (!obj->getRepr()->attribute("class")) { + obj->setAttribute("class", key.erase(0,1)); + } + else { + obj->setAttribute("class", std::string + (obj->getRepr()-> + attribute("class")) + + " " + key + .erase(0,1)); + } + } } } @@ -578,6 +594,50 @@ bool StyleDialog::_handleButtonEvent(GdkEventButton *event) } } } + + else { + std::string sel, key, value; + std::vector<_selectorVecType>::iterator it; + for (it = _selectorVec.begin(); it != _selectorVec.end(); ++it ) { + sel = (*it).second; + REMOVE_SPACES(sel); + if (!sel.empty()) { + key = strtok(strdup(sel.c_str()), "{"); + REMOVE_SPACES(key); + char *temp = strtok(NULL, "}"); + if (strtok(temp, "}") != NULL) { + value = strtok(temp, "}"); + } + } + } + if (key == row[_mColumns._selectorLabel]) { + Gtk::TreeModel::Row parentRow = *(row.parent()); + Glib::ustring parentKey = parentRow[_mColumns._selectorLabel]; + if (strcmp(parentKey.substr(0,1).c_str(), ".") == 0) { + std::vector objVec = row[_mColumns._colObj]; + for (unsigned i = 0; i < objVec.size(); ++i) { + SPObject *obj = objVec[i]; + std::string classAttr = std::string(obj->getRepr() + ->attribute("class")); + std::size_t found = classAttr.find(parentKey.erase(0,1)); + if (found != std::string::npos) { + classAttr.erase(found, parentKey.length()+1); + obj->getRepr()->setAttribute("class", classAttr); + } + } + } + _selectorVec.erase(it); + } + + if (_styleChild) { + _updateStyleContent(); + } + else { + _styleChild = _styleElementNode(); + _updateStyleContent(); + } + _store->erase(row); + } } } } -- cgit v1.2.3 From 798cda4430354143e90fb7ce81c3593a6dc24bc5 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah <> Date: Wed, 13 Jul 2016 08:12:57 +0530 Subject: Propagate changes to object tree with changes in style element (bzr r14949.1.46) --- src/path-chemistry.cpp | 6 +- src/sp-flowtext.cpp | 2 +- src/sp-object.cpp | 4 +- src/sp-style-elem.cpp | 25 ++++++- src/style-internal.cpp | 200 ++++++++++++++++++++++--------------------------- src/style-internal.h | 36 +++++++-- src/style.cpp | 160 +++++++++++++++++++-------------------- src/style.h | 7 +- 8 files changed, 233 insertions(+), 207 deletions(-) (limited to 'src') diff --git a/src/path-chemistry.cpp b/src/path-chemistry.cpp index 1a345b565..f66c8cbf5 100644 --- a/src/path-chemistry.cpp +++ b/src/path-chemistry.cpp @@ -493,7 +493,7 @@ sp_selected_item_to_curved_repr(SPItem *item, guint32 /*text_grouping_policy*/) /* Whole text's style */ Glib::ustring style_str = - item->style->write( SP_STYLE_FLAG_IFDIFF, item->parent ? item->parent->style : NULL); // TODO investigate posibility + item->style->write( SP_STYLE_FLAG_IFDIFF, SP_STYLE_SRC_UNSET, item->parent ? item->parent->style : NULL); // TODO investigate posibility g_repr->setAttribute("style", style_str.c_str()); Inkscape::Text::Layout::iterator iter = te_get_layout(item)->begin(); @@ -514,7 +514,7 @@ sp_selected_item_to_curved_repr(SPItem *item, guint32 /*text_grouping_policy*/) pos_obj = pos_obj->parent; // SPStrings don't have style } Glib::ustring style_str = - pos_obj->style->write( SP_STYLE_FLAG_IFDIFF, pos_obj->parent ? pos_obj->parent->style : NULL); // TODO investigate posibility + pos_obj->style->write( SP_STYLE_FLAG_IFDIFF, SP_STYLE_SRC_UNSET, pos_obj->parent ? pos_obj->parent->style : NULL); // TODO investigate posibility // get path from iter to iter_next: SPCurve *curve = te_get_layout(item)->convertToCurves(iter, iter_next); @@ -573,7 +573,7 @@ sp_selected_item_to_curved_repr(SPItem *item, guint32 /*text_grouping_policy*/) /* Style */ Glib::ustring style_str = - item->style->write( SP_STYLE_FLAG_IFDIFF, item->parent ? item->parent->style : NULL); // TODO investigate posibility + item->style->write( SP_STYLE_FLAG_IFDIFF, SP_STYLE_SRC_UNSET, item->parent ? item->parent->style : NULL); // TODO investigate posibility repr->setAttribute("style", style_str.c_str()); /* Mask */ diff --git a/src/sp-flowtext.cpp b/src/sp-flowtext.cpp index 51fb3ae89..90d4be87c 100644 --- a/src/sp-flowtext.cpp +++ b/src/sp-flowtext.cpp @@ -540,7 +540,7 @@ Inkscape::XML::Node *SPFlowtext::getAsText() this->layout.getSourceOfCharacter(it, &rawptr, &span_text_start_iter); SPObject *source_obj = reinterpret_cast(rawptr); - Glib::ustring style_text = (dynamic_cast(source_obj) ? source_obj->parent : source_obj)->style->write( SP_STYLE_FLAG_IFDIFF, this->style); + Glib::ustring style_text = (dynamic_cast(source_obj) ? source_obj->parent : source_obj)->style->write( SP_STYLE_FLAG_IFDIFF, SP_STYLE_SRC_UNSET, this->style); if (!style_text.empty()) { span_tspan->setAttribute("style", style_text.c_str()); } diff --git a/src/sp-object.cpp b/src/sp-object.cpp index d1659eedc..6d36ec833 100644 --- a/src/sp-object.cpp +++ b/src/sp-object.cpp @@ -1043,7 +1043,9 @@ Inkscape::XML::Node* SPObject::write(Inkscape::XML::Document *doc, Inkscape::XML } if (style) { - Glib::ustring s = style->write(SP_STYLE_FLAG_IFSET); + // Write if property set by style attribute in this object + Glib::ustring s = + style->write(SP_STYLE_FLAG_IFSET & SP_STYLE_FLAG_IFSRC, SP_STYLE_SRC_STYLE_PROP); // Check for valid attributes. This may be time consuming. // It is useful, though, for debugging Inkscape code. diff --git a/src/sp-style-elem.cpp b/src/sp-style-elem.cpp index 80e45677c..0f5af619b 100644 --- a/src/sp-style-elem.cpp +++ b/src/sp-style-elem.cpp @@ -3,6 +3,7 @@ #include "xml/repr.h" #include "document.h" #include "sp-style-elem.h" +#include "sp-root.h" #include "attributes.h" #include "style.h" using Inkscape::XML::TEXT_NODE; @@ -64,6 +65,7 @@ content_changed_cb(Inkscape::XML::Node *, gchar const *, gchar const *, SPObject *obj = reinterpret_cast(data); g_assert(data != NULL); obj->read_content(); + obj->document->getRoot()->emitModified( SP_OBJECT_MODIFIED_CASCADE ); } static void @@ -249,6 +251,19 @@ property_cb(CRDocHandler *const a_handler, g_return_if_fail(append_status == CR_OK); } +void update_style_recursively( SPObject *object ) { + if (object) { + // std::cout << "update_style_recursively: " + // << (object->getId()?object->getId():"null") << std::endl; + if (object->style) { + object->style->readFromObject( object ); + } + for (SPObject *child = object->children; child; child = child->next) { + update_style_recursively( child ); + } + } +} + void SPStyleElem::read_content() { /* fixme: If there's more than one