diff options
| author | Jabier Arraiza <jabier.arraiza@marker.es> | 2019-04-06 01:23:31 +0000 |
|---|---|---|
| committer | Jabier Arraiza <jabier.arraiza@marker.es> | 2019-06-02 09:50:16 +0000 |
| commit | 099344712de8f79db29196442411c7bbdf1d227a (patch) | |
| tree | 12ff796f40c9d2c49dbcd532b98a98290eca5b5d /src | |
| parent | Cache bounding box of shapes (diff) | |
| download | inkscape-099344712de8f79db29196442411c7bbdf1d227a.tar.gz inkscape-099344712de8f79db29196442411c7bbdf1d227a.zip | |
Add CSSDialog simplify
Diffstat (limited to 'src')
| -rw-r--r-- | src/ui/dialog/styledialog.cpp | 105 | ||||
| -rw-r--r-- | src/ui/dialog/styledialog.h | 11 |
2 files changed, 78 insertions, 38 deletions
diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index 93f699ec2..68c957dc7 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -83,8 +83,6 @@ StyleDialog::StyleDialog() Gtk::TreeViewColumn *col = _treeView.get_column(addCol); if (col) { col->add_attribute(addRenderer->property_visible(), _cssColumns.deleteButton); - col->set_sort_column(_cssColumns.deleteButton); - Gtk::Image *add_icon = Gtk::manage(sp_get_icon_image("list-add", Gtk::ICON_SIZE_SMALL_TOOLBAR)); col->set_clickable(true); col->set_widget(*add_icon); @@ -105,33 +103,22 @@ StyleDialog::StyleDialog() if (_propCol) { _propCol->add_attribute(renderer->property_text(), _cssColumns.label); _propCol->add_attribute(renderer->property_foreground_rgba(), _cssColumns.label_color); - _propCol->set_sort_column(_cssColumns.label); } - + renderer->signal_edited().connect(sigc::mem_fun(*this, &CssDialog::nameEdited)); renderer = Gtk::manage(new Gtk::CellRendererText()); - renderer->property_editable() = false; - int attrColNum = _treeView.append_column("Set", *renderer) - 1; + renderer->property_editable() = true; + int attrColNum = _treeView.append_column("Value", *renderer) - 1; _attrCol = _treeView.get_column(attrColNum); if (_attrCol) { _attrCol->add_attribute(renderer->property_text(), _cssColumns._styleAttrVal); _attrCol->add_attribute(renderer->property_foreground_rgba(), _cssColumns.attr_color); - _attrCol->add_attribute(renderer->property_strikethrough(), _cssColumns.attr_strike); - _attrCol->add_attribute(renderer->property_editable(), _cssColumns.editable); - _attrCol->set_sort_column(_cssColumns._styleAttrVal); } - + renderer->signal_edited().connect(sigc::mem_fun(*this, &CssDialog::valueEdited)); renderer = Gtk::manage(new Gtk::CellRendererText()); renderer->property_editable() = true; - int sheetColNum = _treeView.append_column("Actual", *renderer) - 1; - _sheetCol = _treeView.get_column(sheetColNum); - if (_sheetCol) { - _sheetCol->add_attribute(renderer->property_text(), _cssColumns._styleSheetVal); - _sheetCol->add_attribute(renderer->property_foreground_rgba(), _cssColumns.label_color); - _sheetCol->set_sort_column(_cssColumns._styleSheetVal); - } // Set the initial sort column (and direction) to place real attributes at the top. - _store->set_sort_column(_cssColumns.deleteButton, Gtk::SORT_DESCENDING); + _store->set_sort_column(_cssColumns.label, Gtk::SORT_ASCENDING); _getContents()->pack_start(*_scrolledWindow, Gtk::PACK_EXPAND_WIDGET); @@ -264,24 +251,24 @@ void StyleDialog::onAttrChanged(Inkscape::XML::Node *repr, const gchar *name, co std::map<Glib::ustring, Glib::ustring> attr_prop = parseStyle(new_value); for (auto iter : obj->style->properties()) { - if (iter->style && iter->style_src != SP_STYLE_SRC_UNSET) { - Gtk::TreeModel::Row row = *(_store->append()); - // Delete is available to attribute properties only in attr mode. - row[_cssColumns.deleteButton] = iter->style_src == SP_STYLE_SRC_ATTRIBUTE; - row[_cssColumns.label] = iter->name; + if (iter->style_src != SP_STYLE_SRC_UNSET) { if (attr_prop.count(iter->name)) { + Gtk::TreeModel::Row row = *(_store->append()); + // Delete is available to attribute properties only in attr mode. + row[_cssColumns.deleteButton] = iter->style_src == SP_STYLE_SRC_ATTRIBUTE; + row[_cssColumns.label] = iter->name; row[_cssColumns._styleAttrVal] = attr_prop[iter->name]; - if (attr_prop[iter->name] != iter->get_value()) { - row[_cssColumns._styleSheetVal] = iter->get_value(); - row[_cssColumns.attr_color] = Gdk::RGBA("gray"); - row[_cssColumns.attr_strike] = true; - } row[_cssColumns.deleteButton] = true; - } else { - row[_cssColumns._styleSheetVal] = iter->get_value(); +/* } else if (iter->style) { + Gtk::TreeModel::Row row = *(_store->append()); + // Delete is available to attribute properties only in attr mode. + row[_cssColumns.deleteButton] = iter->style_src == SP_STYLE_SRC_ATTRIBUTE; + row[_cssColumns.label] = iter->name; + row[_cssColumns._styleAttrVal] = iter->get_value(); row[_cssColumns.label_color] = Gdk::RGBA("gray"); row[_cssColumns.attr_color] = Gdk::RGBA("gray"); row[_cssColumns.deleteButton] = false; + */ } } } @@ -362,6 +349,64 @@ bool StyleDialog::onPropertyCreate(GdkEventButton *event) return false; } +/** + * @brief CssDialog::onKeyPressed + * @param event_description + * @return + * Send an undo message and mark this point for undo + */ +void CssDialog::setUndo(Glib::ustring const &event_description) +{ + SPDocument *document = this->_desktop->doc(); + DocumentUndo::done(document, SP_VERB_DIALOG_XML_EDITOR, event_description); +} + +/** + * @brief CssDialog::nameEdited + * @param event + * @return + * Called when the name is edited in the TreeView editable column + */ +void CssDialog::nameEdited (const Glib::ustring& path, const Glib::ustring& name) +{ + Gtk::TreeModel::Row row = *_store->get_iter(path); + if(row && this->_repr) { + Glib::ustring old_name = row[_cssColumns.label]; + Glib::ustring value = row[_cssColumns._styleAttrVal]; + // Move to editing value, we set the name as a temporary store value + if (!old_name.empty()) { + // Remove old named value + onPropertyDelete(path); + setStyleProperty(name, " "); + } + if (!name.empty()) { + row[_cssColumns.label] = name; + } + this->setUndo(_("Rename CSS attribute")); + } +} + +/** + * @brief CssDialog::valueEdited + * @param event + * @return + * Called when the value is edited in the TreeView editable column + */ +void CssDialog::valueEdited (const Glib::ustring& path, const Glib::ustring& value) +{ + Gtk::TreeModel::Row row = *_store->get_iter(path); + if(row && this->_repr) { + Glib::ustring name = row[_cssColumns.label]; + if(name.empty()) return; + setStyleProperty(name, value); + if(!value.empty()) { + row[_cssColumns._styleAttrVal] = value; + } + + this->setUndo(_("Change attribute value")); + } +} + } // namespace Dialog } // namespace UI } // namespace Inkscape diff --git a/src/ui/dialog/styledialog.h b/src/ui/dialog/styledialog.h index 07d409ded..bb7c8b6e3 100644 --- a/src/ui/dialog/styledialog.h +++ b/src/ui/dialog/styledialog.h @@ -57,21 +57,15 @@ public: CssColumns() { add(deleteButton); add(label); - add(_styleSheetVal); add(_styleAttrVal); add(label_color); add(attr_color); - add(attr_strike); - add(editable); } Gtk::TreeModelColumn<bool> deleteButton; Gtk::TreeModelColumn<Glib::ustring> label; Gtk::TreeModelColumn<Glib::ustring> _styleAttrVal; - Gtk::TreeModelColumn<Glib::ustring> _styleSheetVal; Gtk::TreeModelColumn<Gdk::RGBA> label_color; Gtk::TreeModelColumn<Gdk::RGBA> attr_color; - Gtk::TreeModelColumn<bool> attr_strike; - Gtk::TreeModelColumn<bool> editable; }; CssColumns _cssColumns; @@ -86,7 +80,6 @@ public: Glib::RefPtr<Gtk::ListStore> _store; Gtk::TreeModel::Row _propRow; Gtk::TreeViewColumn *_propCol; - Gtk::TreeViewColumn *_sheetCol; Gtk::TreeViewColumn *_attrCol; Gtk::HBox status_box; Gtk::Label status; @@ -116,7 +109,9 @@ public: private: Glib::RefPtr<Glib::Regex> r_props = Glib::Regex::create("\\s*;\\s*"); Glib::RefPtr<Glib::Regex> r_pair = Glib::Regex::create("\\s*:\\s*"); - + void setUndo(Glib::ustring const &event_description); + void valueEdited (const Glib::ustring& path, const Glib::ustring& value); + void nameEdited (const Glib::ustring& path, const Glib::ustring& name); bool onPropertyCreate(GdkEventButton *event); void onPropertyDelete(Glib::ustring path); bool setStyleProperty(Glib::ustring name, Glib::ustring value); |
