summaryrefslogtreecommitdiffstats
path: root/src/ui
diff options
context:
space:
mode:
authorJabiertxof <jabier.arraiza@marker.es>2019-07-05 16:58:08 +0000
committerJabiertxof <jabier.arraiza@marker.es>2019-07-05 16:58:08 +0000
commit92ff5ac3e3d172ca2ff0eea39e1a939557e81cf4 (patch)
tree78eb6fc95bf3fdf9e2f75349c65205db62751de3 /src/ui
parentFix whitespace preserve for inx attributes (diff)
downloadinkscape-92ff5ac3e3d172ca2ff0eea39e1a939557e81cf4.tar.gz
inkscape-92ff5ac3e3d172ca2ff0eea39e1a939557e81cf4.zip
Allow styling def sections and go to the eleemnt
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/dialog/styledialog.cpp58
-rw-r--r--src/ui/dialog/styledialog.h5
-rw-r--r--src/ui/dialog/xml-tree.cpp13
3 files changed, 74 insertions, 2 deletions
diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp
index 4af56346d..05a57b552 100644
--- a/src/ui/dialog/styledialog.cpp
+++ b/src/ui/dialog/styledialog.cpp
@@ -354,6 +354,20 @@ void StyleDialog::setCurrentSelector(Glib::ustring current_selector)
_current_selector = current_selector;
_readStyleElement();
}
+
+//copied from style.cpp:1499
+static bool
+is_url(char const *p)
+{
+ if (p == nullptr)
+ return false;
+/** \todo
+ * FIXME: I'm not sure if this applies to SVG as well, but CSS2 says any URIs
+ * in property values must start with 'url('.
+ */
+ return (g_ascii_strncasecmp(p, "url(", 4) == 0);
+}
+
/**
* Fill the Gtk::TreeStore from the svg:style element.
*/
@@ -369,6 +383,7 @@ void StyleDialog::_readStyleElement()
if (textNode == nullptr) {
std::cerr << "StyleDialog::_readStyleElement: No text node!" << std::endl;
}
+ SPDocument *document = SP_ACTIVE_DOCUMENT;
// Get content from style text node.
std::string content = (textNode->content() ? textNode->content() : "");
@@ -433,6 +448,9 @@ void StyleDialog::_readStyleElement()
if (selection->objects().size() == 1) {
obj = selection->objects().back();
}
+ if (!obj) {
+ obj = getDesktop()->getDocument()->getXMLDialogSelectedObject();
+ }
Glib::ustring gladefile = get_filename(Inkscape::IO::Resource::UIS, "dialog-css.ui");
Glib::RefPtr<Gtk::Builder> _builder;
@@ -490,6 +508,16 @@ void StyleDialog::_readStyleElement()
col->add_attribute(value->property_text(), _mColumns._colValue);
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("edit-redo");
+ int urlCol = css_tree->append_column("Go to", *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->add_attribute(urlRenderer->property_icon(), _mColumns._colLinked);
+ }
std::map<Glib::ustring, Glib::ustring> attr_prop;
Gtk::TreeModel::Path path;
if (!_all_css->get_active() && obj && obj->getRepr()->attribute("style")) {
@@ -505,6 +533,17 @@ void StyleDialog::_readStyleElement()
row[_mColumns._colValue] = iter->get_value();
row[_mColumns._colStrike] = false;
row[_mColumns._colOwner] = Glib::ustring("Value active");
+ row[_mColumns._colHref] = nullptr;
+ row[_mColumns._colLinked] = false;
+ if (is_url(iter->get_value().c_str())) {
+ Glib::ustring id = iter->get_value();
+ id = id.substr(5,id.size()-6);
+ SPObject *elemref = nullptr;
+ if ((elemref = document->getObjectById(id.c_str()))) {
+ row[_mColumns._colHref] = elemref;
+ row[_mColumns._colLinked] = true;
+ }
+ }
_addOwnerStyle(iter->name, "style attribute");
}
}
@@ -809,6 +848,22 @@ bool StyleDialog::_on_foreach_iter(const Gtk::TreeModel::iterator &iter)
return false;
}
+void StyleDialog::_onLinkObj(Glib::ustring path, Glib::RefPtr<Gtk::TreeStore> store)
+{
+ g_debug("StyleDialog::_onLinkObj");
+
+ Gtk::TreeModel::Row row = *store->get_iter(path);
+ if (row && row[_mColumns._colLinked]) {
+ SPObject * linked = row[_mColumns._colHref];
+ if (linked) {
+ Inkscape::Selection *selection = getDesktop()->getSelection();
+ getDesktop()->getDocument()->setXMLDialogSelectedObject(linked);
+ selection->clear();
+ selection->set(linked);
+ }
+ }
+}
+
/**
* @brief StyleDialog::_onPropDelete
* @param event
@@ -883,6 +938,9 @@ void StyleDialog::_writeStyleElement(Glib::RefPtr<Gtk::TreeStore> store, Glib::u
if (selection->objects().size() == 1) {
obj = selection->objects().back();
}
+ if (!obj) {
+ obj = getDesktop()->getDocument()->getXMLDialogSelectedObject();
+ }
if (selection->objects().size() < 2 && !obj && !_all_css->get_active()) {
_readStyleElement();
return;
diff --git a/src/ui/dialog/styledialog.h b/src/ui/dialog/styledialog.h
index 36a261c8c..fa92f49c7 100644
--- a/src/ui/dialog/styledialog.h
+++ b/src/ui/dialog/styledialog.h
@@ -92,6 +92,8 @@ class StyleDialog : public Widget::Panel {
add(_colSelector);
add(_colSelectorPos);
add(_colOwner);
+ add(_colLinked);
+ add(_colHref);
}
Gtk::TreeModelColumn<bool> _colActive; // Active or inactive property
Gtk::TreeModelColumn<Glib::ustring> _colName; // Name of the property.
@@ -100,6 +102,8 @@ class StyleDialog : public Widget::Panel {
Gtk::TreeModelColumn<Glib::ustring> _colSelector; // Style or matching object id.
Gtk::TreeModelColumn<gint> _colSelectorPos; // Position of the selector to handle dup selectors
Gtk::TreeModelColumn<Glib::ustring> _colOwner; // Store the owner of the property for popup
+ Gtk::TreeModelColumn<bool> _colLinked; // Go to another element
+ Gtk::TreeModelColumn<SPObject *> _colHref; // Go to another element
};
ModelColumns _mColumns;
@@ -130,6 +134,7 @@ class StyleDialog : public Widget::Panel {
Gtk::TreeView *css_tree);
bool _onNameKeyReleased(GdkEventKey *event, Gtk::CellEditable *cell);
bool _onValueKeyReleased(GdkEventKey *event, Gtk::CellEditable *cell);
+ void _onLinkObj(Glib::ustring path, Glib::RefPtr<Gtk::TreeStore> store);
void _valueEdited(const Glib::ustring &path, const Glib::ustring &value, Glib::RefPtr<Gtk::TreeStore> store);
void _startNameEdit(Gtk::CellEditable *cell, const Glib::ustring &path);
diff --git a/src/ui/dialog/xml-tree.cpp b/src/ui/dialog/xml-tree.cpp
index 542502c5f..38fb6d026 100644
--- a/src/ui/dialog/xml-tree.cpp
+++ b/src/ui/dialog/xml-tree.cpp
@@ -285,7 +285,9 @@ void XmlTree::present()
XmlTree::~XmlTree ()
{
set_tree_desktop(nullptr);
-
+ if (current_desktop) {
+ current_desktop->getDocument()->setXMLDialogSelectedObject(nullptr);
+ }
_message_changed_connection.disconnect();
_message_context = nullptr;
_message_stack = nullptr;
@@ -379,6 +381,9 @@ void XmlTree::set_tree_select(Inkscape::XML::Node *repr)
}
selected_repr = repr;
+ if (current_desktop) {
+ current_desktop->getDocument()->setXMLDialogSelectedObject(nullptr);
+ }
if (repr) {
GtkTreeIter node;
@@ -454,7 +459,7 @@ void XmlTree::set_dt_select(Inkscape::XML::Node *repr)
} else {
object = nullptr;
}
-
+
blocked++;
if ( object && in_dt_coordsys(*object)
&& !(SP_IS_STRING(object) ||
@@ -463,6 +468,10 @@ void XmlTree::set_dt_select(Inkscape::XML::Node *repr)
/* We cannot set selection to root or string - they are not items and selection is not
* equipped to deal with them */
selection->set(SP_ITEM(object));
+ current_desktop->getDocument()->setXMLDialogSelectedObject(nullptr);
+ } else if (object && !current_desktop->isLayer(object)) {
+ current_desktop->getDocument()->setXMLDialogSelectedObject(object);
+ selection->clear();
}
blocked--;