diff options
| author | Jabiertxof <jabier.arraiza@marker.es> | 2019-06-24 18:36:55 +0000 |
|---|---|---|
| committer | Jabiertxof <jabier.arraiza@marker.es> | 2019-06-24 18:36:55 +0000 |
| commit | d1c0d705f63ce234d4b9a73b938fa6c469487774 (patch) | |
| tree | 021b342d16e7a96c0da73237ce089af696d73ab0 /src/ui/dialog/styledialog.cpp | |
| parent | Update pen tool path instantly on mode change (diff) | |
| download | inkscape-d1c0d705f63ce234d4b9a73b938fa6c469487774.tar.gz inkscape-d1c0d705f63ce234d4b9a73b938fa6c469487774.zip | |
Fixes for scrolling on selectors and style dialogs
Diffstat (limited to 'src/ui/dialog/styledialog.cpp')
| -rw-r--r-- | src/ui/dialog/styledialog.cpp | 86 |
1 files changed, 67 insertions, 19 deletions
diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index 3cdf5092b..1427b4964 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -1,10 +1,11 @@ // SPDX-License-Identifier: GPL-2.0-or-later /** @file - * @brief A dialog for CSS selectors + * @brief A dialog for CSS styles */ /* Authors: * Kamalpreet Kaur Grewal * Tavmjong Bah + * Jabiertxof * * Copyright (C) Kamalpreet Kaur Grewal 2016 <grewalkamal005@gmail.com> * Copyright (C) Tavmjong Bah 2017 <tavmjong@free.fr> @@ -35,8 +36,9 @@ #include <gdk/gdkkeysyms.h> #include <glibmm/i18n.h> -//#define DEBUG_STYLEDIALOG -//#define G_LOG_DOMAIN "STYLEDIALOG" +// G_MESSAGES_DEBUG=DEBUG_STYLEDIALOG gdb ./inkscape +// #define DEBUG_STYLEDIALOG +// #define G_LOG_DOMAIN "STYLEDIALOG" using Inkscape::DocumentUndo; using Inkscape::Util::List; @@ -140,6 +142,8 @@ class StyleDialog::NodeWatcher : public Inkscape::XML::NodeObserver { void StyleDialog::_nodeAdded(Inkscape::XML::Node &node) { + g_debug("StyleDialog::_nodeAdded"); + StyleDialog::NodeWatcher *w = new StyleDialog::NodeWatcher(this, &node); node.addObserver(*w); _nodeWatchers.push_back(w); @@ -150,6 +154,8 @@ void StyleDialog::_nodeAdded(Inkscape::XML::Node &node) void StyleDialog::_nodeRemoved(Inkscape::XML::Node &repr) { + g_debug("StyleDialog::_nodeRemoved"); + for (auto it = _nodeWatchers.begin(); it != _nodeWatchers.end(); ++it) { if ((*it)->_repr == &repr) { (*it)->_repr->removeObserver(**it); @@ -160,7 +166,10 @@ void StyleDialog::_nodeRemoved(Inkscape::XML::Node &repr) _readStyleElement(); } -void StyleDialog::_nodeChanged(Inkscape::XML::Node &object) { _readStyleElement(); } +void StyleDialog::_nodeChanged(Inkscape::XML::Node &object) { + g_debug("StyleDialog::_nodeChanged"); + _readStyleElement(); +} /* void StyleDialog::_stylesheetChanged( Inkscape::XML::Node &repr ) { @@ -178,6 +187,7 @@ StyleDialog::StyleDialog() : UI::Widget::Panel("/dialogs/style", SP_VERB_DIALOG_STYLE) , _updating(false) , _textNode(nullptr) + , _scroolpos(0) , _desktopTracker() { g_debug("StyleDialog::StyleDialog"); @@ -191,9 +201,8 @@ StyleDialog::StyleDialog() Gtk::Label *infotoggler = Gtk::manage(new Gtk::Label(_("Edit Full Stylesheet"))); infotoggler->get_style_context()->add_class("inksmall"); _all_css = Gtk::manage(new Gtk::Switch()); - _scroolpos = 0; - vadj = _scrolledWindow.get_vadjustment(); - vadj->signal_changed().connect(sigc::mem_fun(*this, &StyleDialog::_vscrool)); + _vadj = _scrolledWindow.get_vadjustment(); + _vadj->signal_value_changed().connect(sigc::mem_fun(*this, &StyleDialog::_vscrool)); //_all_css->property_active().signal_changed().connect(sigc::mem_fun(*this, &StyleDialog::_reload)); // alltoggler->pack_start(*_all_css, false, false, 0); // alltoggler->pack_start(*infotoggler, false, false, 0); @@ -222,8 +231,11 @@ StyleDialog::StyleDialog() void StyleDialog::_vscrool() { - if (!_updating) { - _scroolpos = vadj->get_value(); + if (!_scroollock) { + _scroolpos = _vadj->get_value(); + } else { + _vadj->set_value(_scroolpos); + _scroollock = false; } } @@ -247,6 +259,7 @@ void StyleDialog::_reload() { _readStyleElement(); } */ Inkscape::XML::Node *StyleDialog::_getStyleTextNode() { + g_debug("StyleDialog::_getStyleTextNoded"); Inkscape::XML::Node *styleNode = nullptr; Inkscape::XML::Node *textNode = nullptr; @@ -299,6 +312,8 @@ Inkscape::XML::Node *StyleDialog::_getStyleTextNode() Glib::RefPtr<Gtk::TreeModel> StyleDialog::_selectTree(Glib::ustring selector) { + g_debug("StyleDialog::_selectTree"); + Gtk::Label *selectorlabel; Glib::RefPtr<Gtk::TreeModel> model; for (auto fullstyle : _styleBox.get_children()) { @@ -334,6 +349,7 @@ Glib::RefPtr<Gtk::TreeModel> StyleDialog::_selectTree(Glib::ustring selector) void StyleDialog::setCurrentSelector(Glib::ustring current_selector) { + g_debug("StyleDialog::setCurrentSelector"); _current_selector = current_selector; _readStyleElement(); } @@ -347,6 +363,7 @@ void StyleDialog::_readStyleElement() if (_updating) return; // Don't read if we wrote style element. _updating = true; + _scroollock = true; Inkscape::XML::Node *textNode = _getStyleTextNode(); if (textNode == nullptr) { std::cerr << "StyleDialog::_readStyleElement: No text node!" << std::endl; @@ -776,6 +793,8 @@ void StyleDialog::_readStyleElement() bool StyleDialog::_on_foreach_iter(const Gtk::TreeModel::iterator &iter) { + g_debug("StyleDialog::_on_foreach_iter"); + Gtk::TreeModel::Row row = *(iter); Glib::ustring owner = row[_mColumns._colOwner]; if (owner.empty()) { @@ -797,6 +816,8 @@ bool StyleDialog::_on_foreach_iter(const Gtk::TreeModel::iterator &iter) */ void StyleDialog::_onPropDelete(Glib::ustring path, Glib::RefPtr<Gtk::TreeStore> store) { + g_debug("StyleDialog::_onPropDelete"); + Gtk::TreeModel::Row row = *store->get_iter(path); if (row) { Glib::ustring selector = row[_mColumns._colSelector]; @@ -808,6 +829,8 @@ void StyleDialog::_onPropDelete(Glib::ustring path, Glib::RefPtr<Gtk::TreeStore> void StyleDialog::_addOwnerStyle(Glib::ustring name, Glib::ustring selector) { + g_debug("StyleDialog::_addOwnerStyle"); + if (_owner_style.find(name) == _owner_style.end()) { _owner_style[name] = selector; } @@ -822,6 +845,8 @@ void StyleDialog::_addOwnerStyle(Glib::ustring name, Glib::ustring selector) */ std::map<Glib::ustring, Glib::ustring> StyleDialog::parseStyle(Glib::ustring style_string) { + g_debug("StyleDialog::parseStyle"); + std::map<Glib::ustring, Glib::ustring> ret; REMOVE_SPACES(style_string); // We'd use const, but we need to trip spaces @@ -847,9 +872,11 @@ std::map<Glib::ustring, Glib::ustring> StyleDialog::parseStyle(Glib::ustring sty */ void StyleDialog::_writeStyleElement(Glib::RefPtr<Gtk::TreeStore> store, Glib::ustring selector) { + g_debug("StyleDialog::_writeStyleElemen"); if (_updating) { return; } + _scroollock = true; Inkscape::Selection *selection = getDesktop()->getSelection(); SPObject *obj = nullptr; if (selection->objects().size() == 1) { @@ -933,8 +960,9 @@ void StyleDialog::_writeStyleElement(Glib::RefPtr<Gtk::TreeStore> store, Glib::u bool StyleDialog::_addRow(GdkEventButton *evt, Glib::RefPtr<Gtk::TreeStore> store, Gtk::TreeView *css_tree, Glib::ustring selector, gint pos) { + g_debug("StyleDialog::_addRow"); + if (evt->type == GDK_BUTTON_RELEASE && evt->button == 1) { - _vscrool(); Gtk::TreeIter iter = store->append(); Gtk::TreeModel::Path path = (Gtk::TreeModel::Path)iter; Gtk::TreeModel::Row row = *(iter); @@ -957,6 +985,8 @@ bool StyleDialog::_addRow(GdkEventButton *evt, Glib::RefPtr<Gtk::TreeStore> stor void StyleDialog::_setAutocompletion(Gtk::Entry *entry, SPStyleEnum const cssenum[]) { + g_debug("StyleDialog::_setAutocompletion"); + Glib::RefPtr<Gtk::ListStore> completionModel = Gtk::ListStore::create(_mCSSData); Glib::RefPtr<Gtk::EntryCompletion> entry_completion = Gtk::EntryCompletion::create(); entry_completion->set_model(completionModel); @@ -976,6 +1006,8 @@ void StyleDialog::_setAutocompletion(Gtk::Entry *entry, SPStyleEnum const cssenu /*Harcode values non in enum*/ void StyleDialog::_setAutocompletion(Gtk::Entry *entry, Glib::ustring name) { + g_debug("StyleDialog::_setAutocompletion"); + Glib::RefPtr<Gtk::ListStore> completionModel = Gtk::ListStore::create(_mCSSData); Glib::RefPtr<Gtk::EntryCompletion> entry_completion = Gtk::EntryCompletion::create(); entry_completion->set_model(completionModel); @@ -1003,7 +1035,9 @@ void StyleDialog::_setAutocompletion(Gtk::Entry *entry, Glib::ustring name) void StyleDialog::_startValueEdit(Gtk::CellEditable* cell, const Glib::ustring& path, Glib::RefPtr<Gtk::TreeStore> store) { - vadj->set_value(_scroolpos); + g_debug("StyleDialog::_startValueEdit"); + + _scroollock = true; Gtk::TreeModel::Row row = *store->get_iter(path); if (row) { Gtk::Entry *entry = dynamic_cast<Gtk::Entry *>(cell); @@ -1062,7 +1096,9 @@ StyleDialog::_startValueEdit(Gtk::CellEditable* cell, const Glib::ustring& path, void StyleDialog::_startNameEdit(Gtk::CellEditable *cell, const Glib::ustring &path) { - vadj->set_value(_scroolpos); + g_debug("StyleDialog::_startNameEdit"); + + _scroollock = true; Glib::RefPtr<Gtk::ListStore> completionModel = Gtk::ListStore::create(_mCSSData); Glib::RefPtr<Gtk::EntryCompletion> entry_completion = Gtk::EntryCompletion::create(); entry_completion->set_model(completionModel); @@ -1087,11 +1123,13 @@ void StyleDialog::_startNameEdit(Gtk::CellEditable *cell, const Glib::ustring &p void StyleDialog::_nameEdited(const Glib::ustring &path, const Glib::ustring &name, Glib::RefPtr<Gtk::TreeStore> store, Gtk::TreeView *css_tree) { + g_debug("StyleDialog::_nameEdited"); + + _scroollock = true; Gtk::TreeModel::Row row = *store->get_iter(path); Gtk::TreeModel::Path pathel = (Gtk::TreeModel::Path)*store->get_iter(path); if (row) { - _vscrool(); Glib::ustring finalname = name; auto i = std::min(finalname.find(";"), finalname.find(":")); if (i != std::string::npos) { @@ -1120,7 +1158,6 @@ void StyleDialog::_nameEdited(const Glib::ustring &path, const Glib::ustring &na css_tree->set_cursor(pathel, *(css_tree->get_column(col)), true); grab_focus(); } - vadj->set_value(_scroolpos); } } @@ -1133,9 +1170,12 @@ void StyleDialog::_nameEdited(const Glib::ustring &path, const Glib::ustring &na void StyleDialog::_valueEdited(const Glib::ustring &path, const Glib::ustring &value, Glib::RefPtr<Gtk::TreeStore> store) { + g_debug("StyleDialog::_valueEdited"); + + _scroollock = true; + Gtk::TreeModel::Row row = *store->get_iter(path); if (row) { - _vscrool(); Glib::ustring finalvalue = value; auto i = std::min(finalvalue.find(";"), finalvalue.find(":")); if (i != std::string::npos) { @@ -1148,24 +1188,26 @@ void StyleDialog::_valueEdited(const Glib::ustring &path, const Glib::ustring &v store->erase(row); } _writeStyleElement(store, selector); - vadj->set_value(_scroolpos); } } void StyleDialog::_activeToggled(const Glib::ustring &path, Glib::RefPtr<Gtk::TreeStore> store) { + g_debug("StyleDialog::_activeToggled"); + + _scroollock = true; Gtk::TreeModel::Row row = *store->get_iter(path); if (row) { row[_mColumns._colActive] = !row[_mColumns._colActive]; Glib::ustring selector = row[_mColumns._colSelector]; - _vscrool(); _writeStyleElement(store, selector); - vadj->set_value(_scroolpos); } } bool StyleDialog::_onNameKeyReleased(GdkEventKey *event, Gtk::CellEditable *cell) { + g_debug("StyleDialog::_onNameKeyReleased"); + switch (event->keyval) { case GDK_KEY_Tab: case GDK_KEY_KP_Tab: @@ -1190,6 +1232,8 @@ bool StyleDialog::_onNameKeyReleased(GdkEventKey *event, Gtk::CellEditable *cell bool StyleDialog::_onValueKeyReleased(GdkEventKey *event, Gtk::CellEditable *cell) { + g_debug("StyleDialog::_onValueKeyReleased"); + switch (event->keyval) { case GDK_KEY_Tab: case GDK_KEY_KP_Tab: @@ -1231,6 +1275,8 @@ void StyleDialog::_addWatcherRecursive(Inkscape::XML::Node *node) */ void StyleDialog::_updateWatchers() { + g_debug("StyleDialog::_updateWatchers"); + _updating = true; // Remove old document watchers @@ -1258,6 +1304,7 @@ void StyleDialog::_updateWatchers() */ std::vector<SPObject *> StyleDialog::_getObjVec(Glib::ustring selector) { + g_debug("StyleDialog::_getObjVec"); std::vector<SPObject *> objVec = SP_ACTIVE_DOCUMENT->getObjectsBySelector(selector); @@ -1305,7 +1352,6 @@ void StyleDialog::_handleDesktopChanged(SPDesktop *desktop) _selection_changed_connection.disconnect(); _document_replaced_connection.disconnect(); - setDesktop(desktop); _selection_changed_connection = @@ -1324,6 +1370,8 @@ void StyleDialog::_handleDesktopChanged(SPDesktop *desktop) void StyleDialog::_handleSelectionChanged() { g_debug("StyleDialog::_handleSelectionChanged()"); + _scroolpos = 0; + _vadj->set_value(0); _readStyleElement(); } |
