summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorkamalpreetgrewal <grewalkamal005@gmail.com>2016-07-26 16:15:08 +0000
committerkamalpreetgrewal <grewalkamal005@gmail.com>2016-07-26 16:15:08 +0000
commit39c55178f470bf12c6a7fc51d5d17b65b319faf2 (patch)
treee0ace3704585743c55074375ab3ce21a6b18d017 /src
parentAdd robust implementation of _getSelectorVec() (diff)
downloadinkscape-39c55178f470bf12c6a7fc51d5d17b65b319faf2.tar.gz
inkscape-39c55178f470bf12c6a7fc51d5d17b65b319faf2.zip
Add functionality to add and delete CSS property in CSS panel
(bzr r14949.1.61)
Diffstat (limited to 'src')
-rw-r--r--src/ui/dialog/cssdialog.cpp37
-rw-r--r--src/ui/dialog/cssdialog.h6
-rw-r--r--src/ui/dialog/styledialog.cpp146
-rw-r--r--src/ui/dialog/styledialog.h2
4 files changed, 170 insertions, 21 deletions
diff --git a/src/ui/dialog/cssdialog.cpp b/src/ui/dialog/cssdialog.cpp
index 9007faafc..cd2f74d15 100644
--- a/src/ui/dialog/cssdialog.cpp
+++ b/src/ui/dialog/cssdialog.cpp
@@ -22,6 +22,23 @@ namespace UI {
namespace Dialog {
/**
+ * @brief CssDialog::_styleButton
+ * @param btn
+ * @param iconName
+ * @param tooltip
+ * This function sets the style of '+'button at the bottom of dialog.
+ */
+void CssDialog::_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 whose each row corresponds to a CSS property of selector selected.
* TODO: Further, buttons to add and delete properties will be added.
@@ -54,10 +71,18 @@ CssDialog::CssDialog():
int nameColNum = _treeView.append_column("Property", *_textRenderer) - 1;
_propCol = _treeView.get_column(nameColNum);
+ create = manage(new Gtk::Button());
+ _styleButton(*create, "list-add", "Add a new property");
+
+ _mainBox.pack_end(_buttonBox, Gtk::PACK_SHRINK);
+ _buttonBox.pack_start(*create, Gtk::PACK_SHRINK);
+
_getContents()->pack_start(_mainBox, Gtk::PACK_EXPAND_WIDGET);
_targetDesktop = getDesktop();
setDesktop(_targetDesktop);
+
+ create->signal_clicked().connect(sigc::mem_fun(*this, &CssDialog::_addProperty));
}
CssDialog::~CssDialog()
@@ -70,6 +95,18 @@ void CssDialog::setDesktop( SPDesktop* desktop )
_desktop = desktop;
}
+/**
+ * @brief CssDialog::_addProperty
+ * This function is a slot to signal_clicked for '+' button at the bottom of CSS
+ * panel. A new row is added, double clicking which text for new property can be
+ * added. _newProperty is set to true in which case the value is appended.
+ */
+void CssDialog::_addProperty()
+{
+ _propRow = *(_store->append());
+ _newProperty = true;
+}
+
} // namespace Dialog
} // namespace UI
} // namespace Inkscape
diff --git a/src/ui/dialog/cssdialog.h b/src/ui/dialog/cssdialog.h
index 4ff79c219..ef48686cc 100644
--- a/src/ui/dialog/cssdialog.h
+++ b/src/ui/dialog/cssdialog.h
@@ -50,6 +50,7 @@ public:
SPDesktop* _targetDesktop;
CssColumns _cssColumns;
Gtk::VBox _mainBox;
+ Gtk::HBox _buttonBox;
Gtk::TreeView _treeView;
Glib::RefPtr<Gtk::ListStore> _store;
Gtk::ScrolledWindow _scrolledWindow;
@@ -57,8 +58,11 @@ public:
Gtk::CellRendererText *_textRenderer;
Gtk::TreeViewColumn *_propCol;
Glib::ustring _editedProp;
+ Gtk::Button* create;
+ bool _newProperty;
- void _handleButtonEvent(const Gtk::TreeModel::Path &path, Gtk::TreeViewColumn *col);
+ void _styleButton( Gtk::Button& btn, char const* iconName, char const* tooltip);
+ void _addProperty();
};
diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp
index 259f326e4..7deac22d8 100644
--- a/src/ui/dialog/styledialog.cpp
+++ b/src/ui/dialog/styledialog.cpp
@@ -120,6 +120,10 @@ StyleDialog::StyleDialog() :
false);
_cssPane = new CssDialog;
+
+ _treeView.get_selection()->signal_changed().connect(sigc::mem_fun(*this,
+ &StyleDialog::
+ _selChanged));
}
StyleDialog::~StyleDialog()
@@ -279,6 +283,7 @@ void StyleDialog::_addSelector()
root->addChild(newChild, NULL);
Inkscape::GC::release(newChild);
+ _styleChild = newChild;
}
}
@@ -745,14 +750,29 @@ void StyleDialog::_buttonEventsSelectObjs(GdkEventButton* event )
}
}
}
- _cssPane->_textRenderer->signal_edited().connect(sigc::mem_fun(*this,
- &StyleDialog::
- _handleEdited));
}
else {
_cssPane->_store->clear();
_cssPane->hide();
}
+
+ _cssPane->_textRenderer->signal_edited().connect(sigc::mem_fun(*this,
+ &StyleDialog::
+ _handleEdited));
+ _cssPane->_treeView.signal_button_press_event().connect(sigc::mem_fun
+ (*this, &StyleDialog::
+ _delProperty),
+ false);
+ }
+}
+
+/**
+ * @brief StyleDialog::_selChanged
+ * When no row in _treeView of Style Dialog is selected, the _cssPane is hidden.
+ */
+void StyleDialog::_selChanged() {
+ if (_treeView.get_selection()->count_selected_rows() == 0) {
+ _cssPane->hide();
}
}
@@ -762,8 +782,9 @@ void StyleDialog::_buttonEventsSelectObjs(GdkEventButton* event )
* @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.
+ * obtained and modified as per value of new_text. If a new property is added,
+ * value is appended with 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)
{
@@ -774,6 +795,7 @@ void StyleDialog::_handleEdited(const Glib::ustring& path, const Glib::ustring&
_cssPane->_editedProp = new_text;
}
+ // Selected selector row is obtained here to get corresponding key and value.
Glib::RefPtr<Gtk::TreeSelection> refTreeSelection = _treeView.get_selection();
Gtk::TreeModel::iterator iter = refTreeSelection->get_selected();
if (iter) {
@@ -797,30 +819,114 @@ void StyleDialog::_handleEdited(const Glib::ustring& path, const Glib::ustring&
REMOVE_SPACES(matchSelector);
if (key == matchSelector) {
- std::stringstream ss(value);
- std::string token, editedToken;
- 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(":"))) {
- editedToken = _cssPane->_editedProp;
- size_t startPos = value.find(token);
- value.replace(startPos, token.length(), editedToken);
- (*it)._xmlContent = key + "{" + value + "}\n";
- _updateStyleContent();
+ /** If a new property is added, existing value is appended with new
+ * property, else replacements in value are done in the 'else' block.
+ */
+ if (_cssPane->_newProperty) {
+ value.append((new_text + ";").c_str());
+ _cssPane->_propCol->add_attribute(_cssPane->_textRenderer
+ ->property_text(),
+ _cssPane->_cssColumns
+ ._propertyLabel);
+ _cssPane->_newProperty = false;
+ }
+ else {
+ std::stringstream ss(value);
+ std::string token, editedToken;
+ 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(":"))) {
+ editedToken = _cssPane->_editedProp;
+ size_t startPos = value.find(token);
+ value.replace(startPos, token.length(), editedToken);
+ }
}
}
}
}
+ value.erase(std::remove(value.begin(), value.end(), '\n'), value.end());
+ (*it)._xmlContent = key + "{" + value + "}\n";
+ _updateStyleContent();
}
}
}
}
+
+/**
+ * @brief StyleDialog::_delProperty
+ * @param event
+ * @return
+ * This function deletes property when '-' in front of property in CSS panel is
+ * clicked. The property row is deleted from CSS panel and XML repr is updated.
+ * toDelProperty is the property to be deleted which is looked in 'value' and is
+ * erased from 'value'.
+ */
+bool StyleDialog::_delProperty(GdkEventButton *event)
+{
+ if (event->type == GDK_BUTTON_PRESS && event->button == 1) {
+ Gtk::TreeViewColumn *col = 0;
+ Gtk::TreeModel::Path path;
+ int x = static_cast<int>(event->x);
+ int y = static_cast<int>(event->y);
+ int x2 = 0;
+ int y2 = 0;
+ Gtk::TreeModel::Row cssRow;
+ Glib::ustring toDelProperty;
+ if (_cssPane->_treeView.get_path_at_pos(x, y, path, col, x2, y2)) {
+ if (col == _cssPane->_treeView.get_column(0)) {
+ Gtk::TreeModel::iterator cssIter = _cssPane->_treeView.get_selection()
+ ->get_selected();
+ if (cssIter) {
+ cssRow = *cssIter;
+ toDelProperty = cssRow[_cssPane->_cssColumns._propertyLabel];
+ }
+
+ Gtk::TreeModel::iterator iter = _treeView.get_selection()->get_selected();
+ if (iter) {
+ Gtk::TreeModel::Row row = *iter;
+ std::string sel, key, value;
+ std::vector<InkSelector>::iterator it;
+ for (it = _selectorVec.begin(); it != _selectorVec.end(); ++it) {
+ sel = (*it)._xmlContent;
+ REMOVE_SPACES(sel);
+ if (!sel.empty()) {
+ key = strtok((char*)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::size_t found = value.find(toDelProperty);
+ if (found!=std::string::npos) {
+ if (!toDelProperty.empty()) {
+ value.erase(found, toDelProperty.length()+1);
+ (*it)._xmlContent = key + "{" + value + "}\n";
+ _updateStyleContent();
+ }
+ }
+ }
+ }
+ }
+ _cssPane->_store->erase(cssRow);
+ }
+ }
+ }
+ return false;
+}
+
/**
* @brief StyleDialog::_selectObjects
* @param eventX
diff --git a/src/ui/dialog/styledialog.h b/src/ui/dialog/styledialog.h
index 54d6f5528..a1048a97d 100644
--- a/src/ui/dialog/styledialog.h
+++ b/src/ui/dialog/styledialog.h
@@ -100,9 +100,11 @@ private:
// Signal handlers
void _addSelector();
void _delSelector();
+ void _selChanged();
// Signal handler for CssDialog
void _handleEdited(const Glib::ustring& path, const Glib::ustring& new_text);
+ bool _delProperty(GdkEventButton *event);
};
} // namespace Dialog