diff options
| -rw-r--r-- | share/ui/dialog-css.ui | 1 | ||||
| -rw-r--r-- | src/attributes.cpp | 26 | ||||
| -rw-r--r-- | src/attributes.h | 6 | ||||
| -rw-r--r-- | src/ui/dialog/styledialog.cpp | 99 | ||||
| -rw-r--r-- | src/ui/dialog/styledialog.h | 26 |
5 files changed, 153 insertions, 5 deletions
diff --git a/share/ui/dialog-css.ui b/share/ui/dialog-css.ui index 2374b22f1..c17a3b72c 100644 --- a/share/ui/dialog-css.ui +++ b/share/ui/dialog-css.ui @@ -69,7 +69,6 @@ <property name="valign">start</property> <property name="headers_visible">False</property> <property name="enable_search">False</property> - <property name="fixed_height_mode">True</property> <property name="hover_selection">True</property> <property name="show_expanders">False</property> <property name="activate_on_single_click">True</property> diff --git a/src/attributes.cpp b/src/attributes.cpp index d7081d4c9..575e40b5c 100644 --- a/src/attributes.cpp +++ b/src/attributes.cpp @@ -9,11 +9,13 @@ * Released under GNU GPL v2+, read the file 'COPYING' for more information. */ +#include "attributes.h" #include <cstring> #include <map> +#include <algorithm> #include <glib.h> // g_assert() -#include "attributes.h" + struct SPStyleProp { SPAttributeEnum code; @@ -602,6 +604,28 @@ sp_attribute_name(SPAttributeEnum id) return props[id].name; } +std::vector<Glib::ustring> +sp_attribute_name_list(bool cssattr, bool attr) +{ + std::vector<Glib::ustring> result; + static AttributeLookupImpl const _instance; + bool add = attr; + for (auto prop : props) { + if (prop.code == SP_ATTR_D) { + if (cssattr) { + add = true; + } else if (attr) { + add = false; + } + } + if (add) { + result.push_back(Glib::ustring(prop.name)); + } + } + std::sort(result.begin(), result.end()); + return result; +} + /* Local Variables: diff --git a/src/attributes.h b/src/attributes.h index 512c00499..f49d8d2f9 100644 --- a/src/attributes.h +++ b/src/attributes.h @@ -14,6 +14,7 @@ * * Released under GNU GPL v2+, read the file 'COPYING' for more information. */ +#include <vector> #include <glibmm/value.h> /** @@ -574,6 +575,11 @@ SPAttributeEnum sp_attribute_lookup(gchar const *key); */ gchar const *sp_attribute_name(SPAttributeEnum id); +/** + * Get attribute name css list. + */ +std::vector<Glib::ustring> sp_attribute_name_list(bool cssattr = false, bool attr = false); + #endif diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index e33d9a52f..7bb58cef9 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -25,7 +25,7 @@ #include "ui/widget/iconrenderer.h" #include "verbs.h" #include "svg/svg-color.h" - +#include "attributes.h" #include "xml/attribute-record.h" #include "xml/node-observer.h" @@ -207,8 +207,19 @@ StyleDialog::StyleDialog() alltoggler->pack_start(*infotoggler, false, false, 0); _all_css->set_active(false); _mainBox.pack_start(*alltoggler, false, false, 0); + Glib::RefPtr<Gtk::ListStore> completionModel = Gtk::ListStore::create(_mCSSData); + _entry_completion = Gtk::EntryCompletion::create(); + _entry_completion->set_model(completionModel); + _entry_completion->set_text_column (_mCSSData._colCSSData); + _entry_completion->set_minimum_key_length(1); + _entry_completion->set_popup_completion(true); + for (auto prop : sp_attribute_name_list(true)){ + Gtk::TreeModel::Row row = *(completionModel->append()); + row[_mCSSData._colCSSData] = prop; + } _mainBox.set_orientation(Gtk::ORIENTATION_VERTICAL); - _getContents()->pack_start(_mainBox, Gtk::PACK_EXPAND_WIDGET); + + _getContents()->pack_start(_mainBox, Gtk::PACK_EXPAND_WIDGET); _all_css->get_style_context()->add_class("stylesheettoggler"); // Document & Desktop _desktop_changed_connection = @@ -454,6 +465,7 @@ void StyleDialog::_readStyleElement() label->property_editable() = true; label->signal_edited().connect(sigc::bind<Glib::RefPtr<Gtk::TreeStore>, Gtk::TreeView *>( sigc::mem_fun(*this, &StyleDialog::_nameEdited), store, css_tree)); + label->signal_editing_started().connect(sigc::mem_fun(*this, &StyleDialog::_startNameEdit)); addCol = css_tree->append_column("CSS Property", *label) - 1; col = css_tree->get_column(addCol); if (col) { @@ -464,6 +476,7 @@ void StyleDialog::_readStyleElement() value->property_editable() = true; value->signal_edited().connect( sigc::bind<Glib::RefPtr<Gtk::TreeStore>>(sigc::mem_fun(*this, &StyleDialog::_valueEdited), store)); + //value->signal_editing_started().connect( sigc::bind<Glib::RefPtr<Gtk::TreeStore> >(sigc::mem_fun(*this, &StyleDialog::_startValueEdit), store)); addCol = css_tree->append_column("CSS Value", *value) - 1; col = css_tree->get_column(addCol); if (col) { @@ -916,6 +929,88 @@ bool StyleDialog::_addRow(GdkEventButton *evt, Glib::RefPtr<Gtk::TreeStore> stor return false; } +void +StyleDialog::_startNameEdit(Gtk::CellEditable* cell, const Glib::ustring& path) +{ + Gtk::Entry *entry = dynamic_cast<Gtk::Entry *>(cell); + entry->set_completion(_entry_completion); +} + +/* void +StyleDialog::_setAutocompletion(Gtk::Entry *entry, SPStyleEnum const cssenum[]) +{ + Glib::RefPtr<Gtk::ListStore> completionModel = Gtk::ListStore::create(_mCSSData); + Glib::RefPtr<Gtk::EntryCompletion> entry_completion = Gtk::EntryCompletion::create(); + entry_completion->set_text_column (_mCSSData._colCSSData); + entry_completion->set_minimum_key_length(0); + entry_completion->set_popup_completion(true); + + gint counter = 0; + const char * key = cssenum[counter].key; + while (key) { + Gtk::TreeModel::Row row = *(completionModel->append()); + row[_mCSSData._colCSSData] = Glib::ustring(key); + key = cssenum[counter].key; + counter++; + } +} + +void +StyleDialog::_startValueEdit(Gtk::CellEditable* cell, const Glib::ustring& path, Glib::RefPtr<Gtk::TreeStore> store) +{ + Gtk::TreeModel::Row row = *store->get_iter(path); + Gtk::TreeModel::Path pathel = (Gtk::TreeModel::Path)*store->get_iter(path); + if (row) { + Gtk::Entry *entry = dynamic_cast<Gtk::Entry *>(cell); + Glib::ustring name = row[_mColumns._colName]; + if (name == "fill-rule") { + _setAutocompletion(entry, enum_fill_rule); + } else if (name == "stroke-linecap") { + _setAutocompletion(entry, enum_stroke_linecap); + } else if (name == "stroke-linejoin") { + _setAutocompletion(entry, enum_stroke_linejoin); + } else if (name == "font-style") { + _setAutocompletion(entry, enum_font_style); + } else if (name == "font-variant") { + _setAutocompletion(entry, enum_font_variant); + } else if (name == "font-weight") { + _setAutocompletion(entry, enum_font_weight); + } else if (name == "font-stretch") { + _setAutocompletion(entry, enum_font_stretch); + } else if (name == "font-variant-position") { + _setAutocompletion(entry, enum_font_variant_position); + } else if (name == "text-align") { + _setAutocompletion(entry, enum_text_align); + } else if (name == "text-transform") { + _setAutocompletion(entry, enum_text_transform); + } else if (name == "text-anchor") { + _setAutocompletion(entry, enum_text_anchor); + } else if (name == "white-space") { + _setAutocompletion(entry, enum_white_space); + } else if (name == "direction") { + _setAutocompletion(entry, enum_direction); + } else if (name == "baseline-shift") { + _setAutocompletion(entry, enum_baseline_shift); + } else if (name == "visibility") { + _setAutocompletion(entry, enum_visibility); + } else if (name == "overflow") { + _setAutocompletion(entry, enum_overflow); + } else if (name == "display") { + _setAutocompletion(entry, enum_display); + } else if (name == "shape-rendering") { + _setAutocompletion(entry, enum_shape_rendering); + } else if (name == "color-rendering") { + _setAutocompletion(entry, enum_color_rendering); + } else if (name == "overflow") { + _setAutocompletion(entry, enum_overflow); + } else if (name == "clip-rule") { + _setAutocompletion(entry, enum_clip_rule); + } else if (name == "color-interpolation") { + _setAutocompletion(entry, enum_color_interpolation); + } + } +} */ + /** * @brief StyleDialog::nameEdited * @param event diff --git a/src/ui/dialog/styledialog.h b/src/ui/dialog/styledialog.h index 4bbbb689d..99a0a8ece 100644 --- a/src/ui/dialog/styledialog.h +++ b/src/ui/dialog/styledialog.h @@ -15,8 +15,13 @@ #ifndef STYLEDIALOG_H #define STYLEDIALOG_H +#include "style-enums.h" #include <glibmm/regex.h> #include <gtkmm/builder.h> +#include <gtkmm/cellrenderercombo.h> +#include <gtkmm/celleditable.h> +#include <gtkmm/entry.h> +#include <gtkmm/entrycompletion.h> #include <gtkmm/dialog.h> #include <gtkmm/eventbox.h> #include <gtkmm/paned.h> @@ -25,6 +30,7 @@ #include <gtkmm/treemodelfilter.h> #include <gtkmm/treeselection.h> #include <gtkmm/treestore.h> +#include <gtkmm/liststore.h> #include <gtkmm/treeview.h> #include <ui/widget/panel.h> @@ -91,11 +97,25 @@ class StyleDialog : public Widget::Panel { }; ModelColumns _mColumns; + class CSSData : public Gtk::TreeModel::ColumnRecord { + public: + CSSData() + { + add(_colCSSData); + } + Gtk::TreeModelColumn<Glib::ustring> _colCSSData; // Name of the property. + }; + CSSData _mCSSData; + // Widgets Gtk::ScrolledWindow _scrolledWindow; Gtk::Box _mainBox; Gtk::Box _styleBox; Gtk::Switch *_all_css; + + // TreeViewCssProps + Glib::RefPtr<Gtk::EntryCompletion> _entry_completion; + // Reading and writing the style element. Inkscape::XML::Node *_getStyleTextNode(); void _readStyleElement(); @@ -104,10 +124,14 @@ class StyleDialog : public Widget::Panel { void _activeToggled(const Glib::ustring &path, Glib::RefPtr<Gtk::TreeStore> store); bool _addRow(GdkEventButton *evt, Glib::RefPtr<Gtk::TreeStore> store, Gtk::TreeView *css_tree, Glib::ustring selector, gint pos); + void _onPropDelete(Glib::ustring path, Glib::RefPtr<Gtk::TreeStore> store); void _nameEdited(const Glib::ustring &path, const Glib::ustring &name, Glib::RefPtr<Gtk::TreeStore> store, Gtk::TreeView *css_tree); void _valueEdited(const Glib::ustring &path, const Glib::ustring &value, Glib::RefPtr<Gtk::TreeStore> store); - void _onPropDelete(Glib::ustring path, Glib::RefPtr<Gtk::TreeStore> store); + void _startNameEdit(Gtk::CellEditable* cell, const Glib::ustring& path); + + // void _startValueEdit(Gtk::CellEditable* cell, const Glib::ustring& path, Glib::RefPtr<Gtk::TreeStore> store); + // void _setAutocompletion(Gtk::Entry *entry, SPStyleEnum const cssenum[]); void _reload(); // Update watchers |
