summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorkamalpreetgrewal <grewalkamal005@gmail.com>2016-07-19 09:09:24 +0000
committerkamalpreetgrewal <grewalkamal005@gmail.com>2016-07-19 09:09:24 +0000
commit96b7038386f56aa59a9d0935989469105234d2fe (patch)
tree7d955e2d4aad8962a268af3b58c13de0f1564c5c /src
parentMerge changes from trunk (diff)
downloadinkscape-96b7038386f56aa59a9d0935989469105234d2fe.tar.gz
inkscape-96b7038386f56aa59a9d0935989469105234d2fe.zip
Update XML & hence drawing when properties are edited in CSS panel
(bzr r14949.1.54)
Diffstat (limited to 'src')
-rw-r--r--src/ui/dialog/cssdialog.cpp18
-rw-r--r--src/ui/dialog/cssdialog.h11
-rw-r--r--src/ui/dialog/styledialog.cpp77
-rw-r--r--src/ui/dialog/styledialog.h3
4 files changed, 88 insertions, 21 deletions
diff --git a/src/ui/dialog/cssdialog.cpp b/src/ui/dialog/cssdialog.cpp
index b0123482b..e12716d6e 100644
--- a/src/ui/dialog/cssdialog.cpp
+++ b/src/ui/dialog/cssdialog.cpp
@@ -21,6 +21,11 @@ namespace Inkscape {
namespace UI {
namespace Dialog {
+/**
+ * Constructor
+ * A treeview whose each row corresponds to a CSS property of selector selected.
+ * TODO: Further, buttons to add and delete properties will be added.
+ */
CssDialog::CssDialog():
UI::Widget::Panel("", "/dialogs/css", SP_VERB_DIALOG_CSS),
_desktop(0)
@@ -53,9 +58,6 @@ CssDialog::CssDialog():
_targetDesktop = getDesktop();
setDesktop(_targetDesktop);
-
- _textRenderer->signal_edited().connect(sigc::mem_fun(*this, &CssDialog::
- _handleEdited));
}
CssDialog::~CssDialog()
@@ -68,16 +70,6 @@ void CssDialog::setDesktop( SPDesktop* desktop )
_desktop = desktop;
}
-void CssDialog::_handleEdited(const Glib::ustring& path, const Glib::ustring& new_text)
-{
- Gtk::TreeModel::iterator iter = _treeView.get_model()->get_iter(path);
- if (iter) {
- Gtk::TreeModel::Row row = *iter;
- row[_cssColumns._propertyLabel] = new_text;
- editedProp = new_text;
- }
-}
-
} // namespace Dialog
} // namespace UI
} // namespace Inkscape
diff --git a/src/ui/dialog/cssdialog.h b/src/ui/dialog/cssdialog.h
index 03ffdf972..4ff79c219 100644
--- a/src/ui/dialog/cssdialog.h
+++ b/src/ui/dialog/cssdialog.h
@@ -24,6 +24,10 @@ namespace Inkscape {
namespace UI {
namespace Dialog {
+/**
+ * @brief The CssDialog class
+ * A list of CSS properties will show up in this dialog.
+ */
class CssDialog : public UI::Widget::Panel
{
public:
@@ -49,13 +53,12 @@ public:
Gtk::TreeView _treeView;
Glib::RefPtr<Gtk::ListStore> _store;
Gtk::ScrolledWindow _scrolledWindow;
- Gtk::TreeModel::Row propRow;
+ Gtk::TreeModel::Row _propRow;
Gtk::CellRendererText *_textRenderer;
Gtk::TreeViewColumn *_propCol;
- Glib::ustring editedProp;
+ Glib::ustring _editedProp;
- void _handleButtonEvent(const Gtk::TreeModel::Path &path, Gtk::TreeViewColumn*col);
- void _handleEdited(const Glib::ustring& path, const Glib::ustring& new_text);
+ void _handleButtonEvent(const Gtk::TreeModel::Path &path, Gtk::TreeViewColumn *col);
};
diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp
index 8eeeda3e6..efbde1767 100644
--- a/src/ui/dialog/styledialog.cpp
+++ b/src/ui/dialog/styledialog.cpp
@@ -684,7 +684,6 @@ bool StyleDialog::_handleButtonEvent(GdkEventButton *event)
* 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 )
{
@@ -703,6 +702,7 @@ void StyleDialog::_buttonEventsSelectObjs(GdkEventButton* event )
_mainBox.pack_end(*_cssPane, Gtk::PACK_SHRINK);
_cssPane->show_all();
}
+
Glib::RefPtr<Gtk::TreeSelection> refTreeSelection = _treeView.get_selection();
Gtk::TreeModel::iterator iter = refTreeSelection->get_selected();
if (iter) {
@@ -734,9 +734,9 @@ void StyleDialog::_buttonEventsSelectObjs(GdkEventButton* event )
while(std::getline(ss, token, ';')) {
REMOVE_SPACES(token);
if (!token.empty()) {
- _cssPane->propRow = *(_cssPane->_store->append());
- _cssPane->propRow[_cssPane->_cssColumns._colUnsetProp] = false;
- _cssPane->propRow[_cssPane->_cssColumns._propertyLabel] = token;
+ _cssPane->_propRow = *(_cssPane->_store->append());
+ _cssPane->_propRow[_cssPane->_cssColumns._colUnsetProp] = false;
+ _cssPane->_propRow[_cssPane->_cssColumns._propertyLabel] = token;
_cssPane->_propCol->add_attribute(_cssPane->_textRenderer
->property_text(),
_cssPane->_cssColumns
@@ -746,6 +746,9 @@ void StyleDialog::_buttonEventsSelectObjs(GdkEventButton* event )
}
}
}
+ _cssPane->_textRenderer->signal_edited().connect(sigc::mem_fun(*this,
+ &StyleDialog::
+ _handleEdited));
}
else {
_cssPane->_store->clear();
@@ -755,6 +758,72 @@ void StyleDialog::_buttonEventsSelectObjs(GdkEventButton* event )
}
/**
+ * @brief StyleDialog::_handleEdited
+ * @param path
+ * @param new_text
+ * This function edits CSS properties of the selector chosen. new_text is used
+ * to update the property in XML repr. The value from selected selector is
+ * obtained and modified as per value of new_text. Later _updateStyleContent() is
+ * called to update XML repr and hence changes are reflected in the drawing too.
+ */
+void StyleDialog::_handleEdited(const Glib::ustring& path, const Glib::ustring& new_text)
+{
+ Gtk::TreeModel::iterator iterCss = _cssPane->_treeView.get_model()->get_iter(path);
+ if (iterCss) {
+ Gtk::TreeModel::Row row = *iterCss;
+ row[_cssPane->_cssColumns._propertyLabel] = new_text;
+ _cssPane->_editedProp = new_text;
+ }
+
+ Glib::RefPtr<Gtk::TreeSelection> refTreeSelection = _treeView.get_selection();
+ Gtk::TreeModel::iterator iter = refTreeSelection->get_selected();
+ if (iter) {
+ Gtk::TreeModel::Row row = *iter;
+ 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, "}");
+ }
+ }
+
+ Glib::ustring selectedRowLabel = row[_mColumns._selectorLabel];
+ std::string matchSelector = selectedRowLabel;
+ REMOVE_SPACES(matchSelector);
+
+ if (key == matchSelector) {
+ std::stringstream ss(value);
+ std::string token;
+ std::size_t found = value.find(";");
+ if (found!=std::string::npos) {
+ while(std::getline(ss, token, ';')) {
+ REMOVE_SPACES(token);
+ if (!token.empty()) {
+ if (token.substr(0, token.find(":")) == _cssPane
+ ->_editedProp.substr(0, _cssPane->_editedProp
+ .find(":")))
+ {
+ token = _cssPane->_editedProp;
+ value.clear();
+ value += token + ";";
+ (*it).second = key + " { " + value + " }\n";
+ _updateStyleContent();
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+/**
* @brief StyleDialog::_selectObjects
* @param eventX
* @param eventY
diff --git a/src/ui/dialog/styledialog.h b/src/ui/dialog/styledialog.h
index 4f5f212b2..31a28dc1f 100644
--- a/src/ui/dialog/styledialog.h
+++ b/src/ui/dialog/styledialog.h
@@ -91,6 +91,9 @@ private:
// Signal handlers
void _addSelector();
void _delSelector();
+
+ // Signal handler for CssDialog
+ void _handleEdited(const Glib::ustring& path, const Glib::ustring& new_text);
};
} // namespace Dialog