diff options
| author | Jabiertxof <jabier.arraiza@marker.es> | 2019-08-27 21:05:08 +0000 |
|---|---|---|
| committer | Jabier Arraiza <jabier.arraiza@marker.es> | 2019-08-28 15:09:41 +0000 |
| commit | 24d4880042773a9edd32565ab7d2388d930a13da (patch) | |
| tree | 7a0c20f7a17eb56e97f1981e53a35a9b95cef91f /src | |
| parent | Puts back translator comments (diff) | |
| download | inkscape-24d4880042773a9edd32565ab7d2388d930a13da.tar.gz inkscape-24d4880042773a9edd32565ab7d2388d930a13da.zip | |
Fix issues pointed by @ede123 and cssinate
Diffstat (limited to 'src')
| -rw-r--r-- | src/object/sp-style-elem.cpp | 13 | ||||
| -rw-r--r-- | src/ui/dialog/attrdialog.cpp | 116 | ||||
| -rw-r--r-- | src/ui/dialog/attrdialog.h | 3 | ||||
| -rw-r--r-- | src/ui/dialog/selectorsdialog.cpp | 22 | ||||
| -rw-r--r-- | src/ui/dialog/styledialog.cpp | 14 | ||||
| -rw-r--r-- | src/ui/dialog/xml-tree.cpp | 25 |
6 files changed, 138 insertions, 55 deletions
diff --git a/src/object/sp-style-elem.cpp b/src/object/sp-style-elem.cpp index 3b93ff190..a8897fa44 100644 --- a/src/object/sp-style-elem.cpp +++ b/src/object/sp-style-elem.cpp @@ -468,6 +468,9 @@ void SPStyleElem::read_content() { //XML Tree being used directly here while it shouldn't be. Glib::ustring const text = concat_children(*getRepr()); + if (!(text.find_first_not_of(" \t\r\n") != std::string::npos)) { + return; + } CRStatus const parse_status = cr_parser_parse_buf (parser, reinterpret_cast<const guchar *>(text.c_str()), text.bytes(), CR_UTF_8); @@ -491,10 +494,11 @@ void SPStyleElem::read_content() { cr_parser_destroy(parser); delete parse_tmp; - - //Record each css statement as an SPStyle - gint count = cr_stylesheet_nr_rules(style_sheet); - + gint count = 0; + if (style_sheet) { + // Record each css statement as an SPStyle + count = cr_stylesheet_nr_rules(style_sheet); + } // Clean out any previous styles for (auto& style:styles) sp_style_unref(style); @@ -506,7 +510,6 @@ void SPStyleElem::read_content() { item->mergeStatement(statement); styles.push_back(item); } - // If style sheet has changed, we need to cascade the entire object tree, top down // Get root, read style, loop through children update_style_recursively( (SPObject *)document->getRoot() ); diff --git a/src/ui/dialog/attrdialog.cpp b/src/ui/dialog/attrdialog.cpp index 0dbc1f331..26c888b02 100644 --- a/src/ui/dialog/attrdialog.cpp +++ b/src/ui/dialog/attrdialog.cpp @@ -15,7 +15,6 @@ #include "verbs.h" #include "selection.h" #include "document-undo.h" - #include "message-context.h" #include "message-stack.h" #include "style.h" @@ -58,6 +57,7 @@ namespace Inkscape { namespace UI { namespace Dialog { +static gboolean key_callback(GtkWidget *widget, GdkEventKey *event, AttrDialog *attrdialog); /** * Constructor * A treeview whose each row corresponds to an XML attribute of a selected node @@ -91,7 +91,6 @@ AttrDialog::AttrDialog() col->set_widget(*add_icon); add_icon->set_tooltip_text(_("Add a new attribute")); add_icon->show(); - // This gets the GtkButton inside the GtkBox, inside the GtkAlignment, inside the GtkImage icon. auto button = add_icon->get_parent()->get_parent()->get_parent(); // Assign the button event so that create happens BEFORE delete. If this code // isn't in this exact way, the onAttrDelete is called when the header lines are pressed. @@ -152,24 +151,57 @@ AttrDialog::AttrDialog() _scrolled_text_view.set_max_content_height(450); _scrolled_text_view.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); _scrolled_text_view.set_propagate_natural_width(true); - _update = Gtk::manage(new Gtk::Button(_("Update"))); - _update->signal_clicked().connect(sigc::mem_fun(*this, &AttrDialog::valueEditedPop)); - hbox->pack_end(*_update, Gtk::PACK_EXPAND_WIDGET, 3); + Gtk::Label *helpreturn = Gtk::manage(new Gtk::Label(_("Shift+Return new line"))); + helpreturn->get_style_context()->add_class("inksmall"); + Gtk::Button *apply = Gtk::manage(new Gtk::Button()); + Gtk::Image *icon = Gtk::manage(sp_get_icon_image("on", 26)); + apply->set_relief(Gtk::RELIEF_NONE); + icon->show(); + apply->add(*icon); + apply->signal_clicked().connect(sigc::mem_fun(*this, &AttrDialog::valueEditedPop)); + Gtk::Button *cancel = Gtk::manage(new Gtk::Button()); + icon = Gtk::manage(sp_get_icon_image("off", 26)); + cancel->set_relief(Gtk::RELIEF_NONE); + icon->show(); + cancel->add(*icon); + cancel->signal_clicked().connect(sigc::mem_fun(*this, &AttrDialog::valueCanceledPop)); + hbox->pack_end(*apply, Gtk::PACK_SHRINK, 3); + hbox->pack_end(*cancel, Gtk::PACK_SHRINK, 3); + hbox->pack_end(*helpreturn, Gtk::PACK_SHRINK, 3); vbox->pack_start(_scrolled_text_view, Gtk::PACK_EXPAND_WIDGET, 3); vbox->pack_start(*hbox, Gtk::PACK_EXPAND_WIDGET, 3); _popover->add(*vbox); - _popover->hide(); + _popover->show(); _popover->set_relative_to(_treeView); _popover->set_position(Gtk::PositionType::POS_BOTTOM); _popover->signal_closed().connect(sigc::mem_fun(*this, &AttrDialog::popClosed)); - _popover->get_style_context()->add_class("inverted"); _popover->get_style_context()->add_class("attrpop"); attr_reset_context(0); _getContents()->pack_start(_mainBox, Gtk::PACK_EXPAND_WIDGET); setDesktop(getDesktop()); + // I couldent get the signal go well not using C way signals + g_signal_connect(GTK_WIDGET(_popover->gobj()), "key-press-event", G_CALLBACK(key_callback), this); + _popover->hide(); _updating = false; } +static gboolean key_callback(GtkWidget *widget, GdkEventKey *event, AttrDialog *attrdialog) +{ + switch (event->keyval) { + case GDK_KEY_Return: + case GDK_KEY_KP_Enter: { + if (attrdialog->_popover->is_visible()) { + if (!(event->state & GDK_SHIFT_MASK)) { + attrdialog->valueEditedPop(); + attrdialog->_popover->hide(); + return true; + } + } + } break; + } + return false; +} + /** * @brief AttrDialog::~AttrDialog * Class destructor @@ -189,9 +221,10 @@ void AttrDialog::startNameEdit(Gtk::CellEditable *cell, const Glib::ustring &pat entry->signal_key_press_event().connect(sigc::bind(sigc::mem_fun(*this, &AttrDialog::onNameKeyPressed), entry)); } -gboolean sp_show_attr_pop(gpointer data) +gboolean sp_show_pop_realiced(gpointer data) { AttrDialog *attrdialog = reinterpret_cast<AttrDialog *>(data); + auto vscroll = attrdialog->_scrolled_text_view.get_vadjustment(); int height = vscroll->get_upper() + 12; // padding 6+6 if (height < 450) { @@ -202,22 +235,39 @@ gboolean sp_show_attr_pop(gpointer data) return FALSE; } +gboolean sp_show_attr_pop(gpointer data) +{ + AttrDialog *attrdialog = reinterpret_cast<AttrDialog *>(data); + attrdialog->_popover->show_all(); + attrdialog->_popover->check_resize(); + g_timeout_add(50, &sp_show_pop_realiced, attrdialog); + return FALSE; +} + +gboolean sp_close_entry(gpointer data) +{ + Gtk::CellEditable *cell = reinterpret_cast<Gtk::CellEditable *>(data); + cell->editing_done(); + cell->remove_widget(); + return FALSE; +} + void AttrDialog::startValueEdit(Gtk::CellEditable *cell, const Glib::ustring &path) { Gtk::Entry *entry = dynamic_cast<Gtk::Entry *>(cell); - entry->signal_key_press_event().connect(sigc::bind(sigc::mem_fun(*this, &AttrDialog::onValueKeyPressed), entry)); int width = 0; int height = 0; int colwidth = _valueCol->get_width(); - _textview->set_size_request(colwidth - 6, -1); - _popover->set_size_request(colwidth, -1); + _textview->set_size_request(510, -1); + _popover->set_size_request(520, -1); valuepath = path; entry->get_layout()->get_pixel_size(width, height); Gtk::TreeIter iter = *_store->get_iter(path); Gtk::TreeModel::Row row = *iter; if (row && this->_repr) { Glib::ustring name = row[_attrColumns._attributeName]; - if (colwidth < width || name == "content") { + if (colwidth - 10 < width || name == "content") { + valueediting = entry->get_text(); Gtk::TreeIter iter = *_store->get_iter(path); Gdk::Rectangle rect; _treeView.get_cell_area((Gtk::TreeModel::Path)iter, *_valueCol, rect); @@ -228,16 +278,16 @@ void AttrDialog::startValueEdit(Gtk::CellEditable *cell, const Glib::ustring &pa Glib::RefPtr<Gtk::TextBuffer> textbuffer = Gtk::TextBuffer::create(); textbuffer->set_text(entry->get_text()); _textview->set_buffer(textbuffer); - cell->editing_done(); - cell->remove_widget(); int scrolledcontentheight = 20; if (name == "content") { scrolledcontentheight = 450; } _scrolled_text_view.set_min_content_height(scrolledcontentheight); - _popover->show_all(); - _popover->check_resize(); + g_timeout_add(50, &sp_close_entry, cell); g_timeout_add(50, &sp_show_attr_pop, this); + } else { + entry->signal_key_press_event().connect( + sigc::bind(sigc::mem_fun(*this, &AttrDialog::onValueKeyPressed), entry)); } } } @@ -280,12 +330,6 @@ void AttrDialog::setRepr(Inkscape::XML::Node * repr) } } -/** - * @brief AttrDialog::onKeyPressed - * @param event_description - * @return - * Send an undo message and mark this point for undo - */ void AttrDialog::setUndo(Glib::ustring const &event_description) { SPDocument *document = this->_desktop->doc(); @@ -389,11 +433,11 @@ void AttrDialog::onAttrDelete(Glib::ustring path) */ bool AttrDialog::onKeyPressed(GdkEventKey *event) { + bool ret = false; if(this->_repr) { auto selection = this->_treeView.get_selection(); Gtk::TreeModel::Row row = *(selection->get_selected()); Gtk::TreeIter iter = *(selection->get_selected()); - bool ret = false; switch (event->keyval) { case GDK_KEY_Delete: @@ -417,9 +461,19 @@ bool AttrDialog::onKeyPressed(GdkEventKey *event) grab_focus(); ret = true; } break; + case GDK_KEY_Return: + case GDK_KEY_KP_Enter: { + if (_popover->is_visible()) { + if (!(event->state & GDK_SHIFT_MASK)) { + valueEditedPop(); + _popover->hide(); + ret = true; + } + } + } break; } } - return false; + return ret; } bool AttrDialog::onNameKeyPressed(GdkEventKey *event, Gtk::Entry *entry) @@ -498,7 +552,7 @@ void AttrDialog::nameEdited (const Glib::ustring& path, const Glib::ustring& nam row[_attrColumns._attributeName] = name; grab_focus(); _updating = true; - char const *valueto = value.c_str(); // this allow store empty values + // this allow store empty values _repr->setAttribute(name.c_str(), "", false); _updating = false; g_timeout_add(50, &sp_attrdialog_store_move_to_next, this); @@ -511,6 +565,18 @@ void AttrDialog::valueEditedPop() { Glib::ustring value = _textview->get_buffer()->get_text(); valueEdited(valuepath, value); + valueediting = ""; + _popover->hide(); +} + +void AttrDialog::valueCanceledPop() +{ + if (!valueediting.empty()) { + Glib::RefPtr<Gtk::TextBuffer> textbuffer = Gtk::TextBuffer::create(); + textbuffer->set_text(valueediting); + _textview->set_buffer(textbuffer); + } + _popover->hide(); } /** diff --git a/src/ui/dialog/attrdialog.h b/src/ui/dialog/attrdialog.h index 2c57447c4..1939706e6 100644 --- a/src/ui/dialog/attrdialog.h +++ b/src/ui/dialog/attrdialog.h @@ -66,8 +66,8 @@ public: Gtk::TreeModel::Path _modelpath; Gtk::Popover *_popover; Gtk::TextView *_textview; - Gtk::Button *_update; Glib::ustring valuepath; + Glib::ustring valueediting; /** * Status bar @@ -113,6 +113,7 @@ public: void startValueEdit(Gtk::CellEditable *cell, const Glib::ustring &path); void nameEdited(const Glib::ustring &path, const Glib::ustring &name); void valueEdited(const Glib::ustring &path, const Glib::ustring &value); + void valueCanceledPop(); void valueEditedPop(); }; diff --git a/src/ui/dialog/selectorsdialog.cpp b/src/ui/dialog/selectorsdialog.cpp index ba60e56f8..79d5566e9 100644 --- a/src/ui/dialog/selectorsdialog.cpp +++ b/src/ui/dialog/selectorsdialog.cpp @@ -260,7 +260,7 @@ SelectorsDialog::SelectorsDialog() _store = TreeStore::create(this); _treeView.set_model(_store); - _treeView.set_headers_visible(true); + _treeView.set_headers_visible(false); _treeView.enable_model_drag_source(); _treeView.enable_model_drag_dest( Gdk::ACTION_MOVE ); int addCol = _treeView.append_column("", *addRenderer) - 1; @@ -372,15 +372,17 @@ void SelectorsDialog::_showWidgets() _style_dialog->set_name("StyleDialog"); _paned.pack1(*_style_dialog, Gtk::SHRINK); _paned.pack2(_selectors_box, true, true); + _paned.set_wide_handle(true); _getContents()->pack_start(_paned, Gtk::PACK_EXPAND_WIDGET); _getContents()->pack_start(_button_box, false, false, 0); show_all(); - int widthpos = _paned.property_max_position(); - int panedpos = prefs->getInt("/dialogs/selectors/panedpos", 130); - - _paned.set_position(panedpos); + int widthpos = _paned.property_max_position() - _paned.property_min_position(); + int panedpos = prefs->getInt("/dialogs/selectors/panedpos", widthpos / 2); _paned.property_position().signal_changed().connect(sigc::mem_fun(*this, &SelectorsDialog::_childresized)); _paned.signal_size_allocate().connect(sigc::mem_fun(*this, &SelectorsDialog::_panedresized)); + _updating = true; + _paned.property_position() = panedpos; + _updating = false; set_size_request(320, 260); set_name("SelectorsAndStyleDialog"); } @@ -409,13 +411,13 @@ void SelectorsDialog::_resized() bool dir = !prefs->getBool("/dialogs/selectors/vertical", true); int max = int(_paned.property_max_position() * 0.95); int min = int(_paned.property_max_position() * 0.05); - if (_paned.get_position() > max) { + if (_paned.property_position() > max) { _paned.property_position() = max; } - if (_paned.get_position() < min) { + if (_paned.property_position() < min) { _paned.property_position() = min; } - prefs->setInt("/dialogs/selectors/panedpos", _paned.get_position()); + prefs->setInt("/dialogs/selectors/panedpos", _paned.property_position()); _updating = false; } @@ -429,7 +431,7 @@ void SelectorsDialog::_toggleDirection(Gtk::RadioButton *vertical) _paned.check_resize(); int widthpos = _paned.property_max_position() - _paned.property_min_position(); prefs->setInt("/dialogs/selectors/panedpos", widthpos / 2); - _paned.set_position(widthpos / 2); + _paned.property_position() = widthpos / 2; } /** @@ -543,6 +545,7 @@ void SelectorsDialog::_readStyleElement() _updating = false; return; } + _treeView.show_all(); std::vector<std::pair<Glib::ustring, bool>> expanderstatus; for (unsigned i = 0; i < tokens.size() - 1; i += 2) { Glib::ustring selector = tokens[i]; @@ -557,6 +560,7 @@ void SelectorsDialog::_readStyleElement() } _store->clear(); bool rewrite = false; + for (unsigned i = 0; i < tokens.size()-1; i += 2) { Glib::ustring selector = tokens[i]; diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index 7dfe2d7e8..34d0498e1 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -534,16 +534,17 @@ void StyleDialog::_readStyleElement() col = css_tree->get_column(addCol); if (col) { col->add_attribute(value->property_text(), _mColumns._colValue); + col->set_expand(true); col->add_attribute(value->property_strikethrough(), _mColumns._colStrike); } Inkscape::UI::Widget::IconRenderer *urlRenderer = manage(new Inkscape::UI::Widget::IconRenderer()); - urlRenderer->add_icon("empty"); + urlRenderer->add_icon("empty-icon"); urlRenderer->add_icon("edit-redo"); int urlCol = css_tree->append_column("", *urlRenderer) - 1; Gtk::TreeViewColumn *urlcol = css_tree->get_column(urlCol); if (urlcol) { - urlRenderer->signal_activated().connect( - sigc::bind<Glib::RefPtr<Gtk::TreeStore>>(sigc::mem_fun(*this, &StyleDialog::_onLinkObj), store)); + urlcol->set_min_width(40); + urlRenderer->signal_activated().connect(sigc::bind(sigc::mem_fun(*this, &StyleDialog::_onLinkObj), store)); urlcol->add_attribute(urlRenderer->property_icon(), _mColumns._colLinked); } std::map<Glib::ustring, Glib::ustring> attr_prop; @@ -638,12 +639,15 @@ void StyleDialog::_readStyleElement() css_tree->get_style_context()->add_class("style_sheet"); Glib::RefPtr<Gtk::TreeStore> store = Gtk::TreeStore::create(_mColumns); css_tree->set_model(store); - css_selector_event_box->signal_button_release_event().connect( + // I comment this feature, is working but seems obscure to undertand + // the user can edit selector name in current implementation + /* css_selector_event_box->signal_button_release_event().connect( sigc::bind(sigc::mem_fun(*this, &StyleDialog::_selectorStartEdit), css_selector, css_edit_selector)); css_edit_selector->signal_key_press_event().connect(sigc::bind( sigc::mem_fun(*this, &StyleDialog::_selectorEditKeyPress), store, css_selector, css_edit_selector)); css_edit_selector->signal_activate().connect( sigc::bind(sigc::mem_fun(*this, &StyleDialog::_selectorActivate), store, css_selector, css_edit_selector)); + */ Inkscape::UI::Widget::IconRenderer *addRenderer = manage(new Inkscape::UI::Widget::IconRenderer()); addRenderer->add_icon("edit-delete"); int addCol = css_tree->append_column("Delete row", *addRenderer) - 1; @@ -670,6 +674,7 @@ void StyleDialog::_readStyleElement() col = css_tree->get_column(addCol); if (col) { col->set_resizable(true); + col->set_expand(true); col->add_attribute(label->property_text(), _mColumns._colName); } Gtk::CellRendererText *value = Gtk::manage(new Gtk::CellRendererText()); @@ -804,6 +809,7 @@ void StyleDialog::_readStyleElement() col = css_tree->get_column(addCol); if (col) { col->set_resizable(true); + col->set_expand(true); col->add_attribute(label->property_text(), _mColumns._colName); } Gtk::CellRendererText *value = Gtk::manage(new Gtk::CellRendererText()); diff --git a/src/ui/dialog/xml-tree.cpp b/src/ui/dialog/xml-tree.cpp index bbdccf687..c91bcd2ab 100644 --- a/src/ui/dialog/xml-tree.cpp +++ b/src/ui/dialog/xml-tree.cpp @@ -177,6 +177,7 @@ XmlTree::XmlTree() attributes = new AttrDialog(); _paned.set_orientation(dir ? Gtk::ORIENTATION_VERTICAL : Gtk::ORIENTATION_HORIZONTAL); _paned.check_resize(); + _paned.set_wide_handle(true); _paned.pack1(node_box, Gtk::SHRINK); /* attributes */ Gtk::Box *actionsbox = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL)); @@ -221,16 +222,17 @@ XmlTree::XmlTree() desktopChangeConn = deskTrack.connectDesktopChanged( sigc::mem_fun(*this, &XmlTree::set_tree_desktop) ); deskTrack.connect(GTK_WIDGET(gobj())); - int widthpos = _paned.property_max_position(); _paned.property_position().signal_changed().connect(sigc::mem_fun(*this, &XmlTree::_childresized)); _paned.signal_size_allocate().connect(sigc::mem_fun(*this, &XmlTree::_panedresized)); set_name("XMLAndAttributesDialog"); set_spacing(0); set_size_request(320, 260); show_all(); - int panedpos = prefs->getInt("/dialogs/xml/panedpos", 130); - _paned.set_position(panedpos); - _resized(); + int widthpos = _paned.property_max_position() - _paned.property_min_position(); + int panedpos = prefs->getInt("/dialogs/xml/panedpos", widthpos / 2); + _updating = true; + _paned.property_position() = panedpos; + _updating = false; tree_reset_context(); g_assert(desktop != nullptr); @@ -253,17 +255,17 @@ void XmlTree::_resized() int max = int(_paned.property_max_position() * 0.95); int min = int(_paned.property_max_position() * 0.05); bool attrtoggler = prefs->getBool("/dialogs/xml/attrtoggler", true); - if (attrtoggler && _paned.get_position() > max) { + if (attrtoggler && _paned.property_position() > max) { _paned.property_position() = max; } - if (attrtoggler && _paned.get_position() < min) { + if (attrtoggler && _paned.property_position() < min) { _paned.property_position() = min; } if (!attrtoggler) { attributes->hide(); _paned.property_position() = _paned.property_max_position(); } - prefs->setInt("/dialogs/xml/panedpos", _paned.get_position()); + prefs->setInt("/dialogs/xml/panedpos", _paned.property_position()); _updating = false; } @@ -276,7 +278,7 @@ void XmlTree::_toggleDirection(Gtk::RadioButton *vertical) _paned.check_resize(); int widthpos = _paned.property_max_position() - _paned.property_min_position(); prefs->setInt("/dialogs/xml/panedpos", widthpos / 2); - _paned.set_position(widthpos / 2); + _paned.property_position() = widthpos / 2; } void XmlTree::_attrtoggler() @@ -288,11 +290,12 @@ void XmlTree::_attrtoggler() attributes->show(); int widthpos = _paned.property_max_position() - _paned.property_min_position(); prefs->setInt("/dialogs/xml/panedpos", widthpos / 2); - _paned.set_position(widthpos / 2); + _paned.property_position() = widthpos / 2; } else { attributes->hide(); - int widthpos = _paned.property_max_position(); - _paned.set_position(widthpos); + int widthpos = _paned.property_max_position() - _paned.property_min_position(); + prefs->setInt("/dialogs/xml/panedpos", widthpos); + _paned.property_position() = widthpos; } } |
