summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJabier Arraiza <jabier.arraiza@marker.es>2019-08-30 20:25:05 +0000
committerJabier Arraiza <jabier.arraiza@marker.es>2019-08-30 20:25:05 +0000
commit088d3e67ab547d5b3f15c28c0a86d8748c9b00fb (patch)
tree06ed06ca6bd6dbd066e2bed8d7ba9b08bbaff94a /src
parentadd improvements to selectors and merge stylesheet on copy to work between docs (diff)
downloadinkscape-088d3e67ab547d5b3f15c28c0a86d8748c9b00fb.tar.gz
inkscape-088d3e67ab547d5b3f15c28c0a86d8748c9b00fb.zip
Improvements and bug fixes to XMLDialog
Diffstat (limited to 'src')
-rw-r--r--src/ui/dialog/attrdialog.cpp97
-rw-r--r--src/ui/dialog/attrdialog.h5
-rw-r--r--src/widgets/sp-xmlview-tree.cpp39
3 files changed, 108 insertions, 33 deletions
diff --git a/src/ui/dialog/attrdialog.cpp b/src/ui/dialog/attrdialog.cpp
index 26c888b02..7368fc806 100644
--- a/src/ui/dialog/attrdialog.cpp
+++ b/src/ui/dialog/attrdialog.cpp
@@ -24,8 +24,8 @@
#include "xml/node-event-vector.h"
#include "xml/attribute-record.h"
-#include <glibmm/i18n.h>
#include <gdk/gdkkeysyms.h>
+#include <glibmm/i18n.h>
static void on_attr_changed (Inkscape::XML::Node * repr,
const gchar * name,
@@ -134,7 +134,7 @@ AttrDialog::AttrDialog()
_treeView.append_column(_("Value"), *_valueRenderer);
_valueCol = _treeView.get_column(2);
if (_valueCol) {
- _valueCol->add_attribute(_valueRenderer->property_text(), _attrColumns._attributeValue);
+ _valueCol->add_attribute(_valueRenderer->property_text(), _attrColumns._attributeValueRender);
}
_popover = Gtk::manage(new Gtk::Popover());
Gtk::Box *vbox = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_VERTICAL));
@@ -144,6 +144,7 @@ AttrDialog::AttrDialog()
_textview->set_editable(true);
_textview->set_monospace(true);
_textview->set_border_width(6);
+ _textview->signal_map().connect(sigc::mem_fun(*this, &AttrDialog::textViewMap));
Glib::RefPtr<Gtk::TextBuffer> textbuffer = Gtk::TextBuffer::create();
textbuffer->set_text("");
_textview->set_buffer(textbuffer);
@@ -185,6 +186,25 @@ AttrDialog::AttrDialog()
_updating = false;
}
+void AttrDialog::textViewMap()
+{
+ auto vscroll = _scrolled_text_view.get_vadjustment();
+ int height = vscroll->get_upper() + 12; // padding 6+6
+ if (height < 450) {
+ _scrolled_text_view.set_min_content_height(height);
+ vscroll->set_value(vscroll->get_lower());
+ } else {
+ _scrolled_text_view.set_min_content_height(450);
+ }
+}
+
+gboolean sp_show_pop_map(gpointer data)
+{
+ AttrDialog *attrdialog = reinterpret_cast<AttrDialog *>(data);
+ attrdialog->textViewMap();
+ return FALSE;
+}
+
static gboolean key_callback(GtkWidget *widget, GdkEventKey *event, AttrDialog *attrdialog)
{
switch (event->keyval) {
@@ -195,6 +215,8 @@ static gboolean key_callback(GtkWidget *widget, GdkEventKey *event, AttrDialog *
attrdialog->valueEditedPop();
attrdialog->_popover->hide();
return true;
+ } else {
+ g_timeout_add(50, &sp_show_pop_map, attrdialog);
}
}
} break;
@@ -221,34 +243,22 @@ 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_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) {
- attrdialog->_scrolled_text_view.set_min_content_height(height);
- } else {
- attrdialog->_scrolled_text_view.set_min_content_height(450);
- }
- 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();
+ if (cell) {
+ cell->property_editing_canceled() = true;
+ cell->remove_widget();
+ }
return FALSE;
}
@@ -266,9 +276,9 @@ void AttrDialog::startValueEdit(Gtk::CellEditable *cell, const Glib::ustring &pa
Gtk::TreeModel::Row row = *iter;
if (row && this->_repr) {
Glib::ustring name = row[_attrColumns._attributeName];
- if (colwidth - 10 < width || name == "content") {
+ if (row[_attrColumns._attributeValue] != row[_attrColumns._attributeValueRender] || 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);
if (_popover->get_position() == Gtk::PositionType::POS_BOTTOM) {
@@ -276,13 +286,8 @@ void AttrDialog::startValueEdit(Gtk::CellEditable *cell, const Glib::ustring &pa
}
_popover->set_pointing_to(rect);
Glib::RefPtr<Gtk::TextBuffer> textbuffer = Gtk::TextBuffer::create();
- textbuffer->set_text(entry->get_text());
+ textbuffer->set_text(row[_attrColumns._attributeValue]);
_textview->set_buffer(textbuffer);
- int scrolledcontentheight = 20;
- if (name == "content") {
- scrolledcontentheight = 450;
- }
- _scrolled_text_view.set_min_content_height(scrolledcontentheight);
g_timeout_add(50, &sp_close_entry, cell);
g_timeout_add(50, &sp_show_attr_pop, this);
} else {
@@ -297,6 +302,7 @@ void AttrDialog::popClosed()
Glib::RefPtr<Gtk::TextBuffer> textbuffer = Gtk::TextBuffer::create();
textbuffer->set_text("");
_textview->set_buffer(textbuffer);
+ _scrolled_text_view.set_min_content_height(20);
}
/**
@@ -358,6 +364,29 @@ void AttrDialog::attr_reset_context(gint attr)
}
}
+// TODO: improve and find a good location
+// duplicated in sp-xmlview.cpp:315
+Glib::ustring sp_remove_newlines_and_tabs(Glib::ustring val)
+{
+ int pos = 0;
+ Glib::ustring newlinesign = "␤";
+ Glib::ustring tabsign = "⇥";
+ while ((pos = val.find("\r\n")) != std::string::npos) {
+ val.erase(pos, 2);
+ val.insert(pos, newlinesign);
+ }
+ pos = 0;
+ while ((pos = val.find('\n')) != std::string::npos) {
+ val.erase(pos, 1);
+ val.insert(pos, newlinesign);
+ }
+ pos = 0;
+ while ((pos = val.find('\t')) != std::string::npos) {
+ val.erase(pos, 1);
+ val.insert(pos, tabsign);
+ }
+ return val;
+}
/**
* @brief AttrDialog::onAttrChanged
* This is called when the XML has an updated attribute
@@ -367,6 +396,10 @@ void AttrDialog::onAttrChanged(Inkscape::XML::Node *repr, const gchar * name, co
if (_updating) {
return;
}
+ Glib::ustring renderval = "";
+ if (new_value) {
+ renderval = sp_remove_newlines_and_tabs(Glib::ustring(new_value));
+ }
for(auto iter: this->_store->children())
{
Gtk::TreeModel::Row row = *iter;
@@ -374,6 +407,7 @@ void AttrDialog::onAttrChanged(Inkscape::XML::Node *repr, const gchar * name, co
if(name == col_name) {
if(new_value) {
row[_attrColumns._attributeValue] = new_value;
+ row[_attrColumns._attributeValueRender] = renderval;
new_value = nullptr; // Don't make a new one
} else {
_store->erase(iter);
@@ -385,6 +419,7 @@ void AttrDialog::onAttrChanged(Inkscape::XML::Node *repr, const gchar * name, co
Gtk::TreeModel::Row row = *(_store->prepend());
row[_attrColumns._attributeName] = name;
row[_attrColumns._attributeValue] = new_value;
+ row[_attrColumns._attributeValueRender] = renderval;
}
}
@@ -510,8 +545,10 @@ gboolean sp_attrdialog_store_move_to_next(gpointer data)
AttrDialog *attrdialog = reinterpret_cast<AttrDialog *>(data);
auto selection = attrdialog->_treeView.get_selection();
Gtk::TreeIter iter = *(selection->get_selected());
- Gtk::TreeModel::Path model = (Gtk::TreeModel::Path)iter;
- if (model == attrdialog->_modelpath) {
+ Gtk::TreeModel::Path path = (Gtk::TreeModel::Path)iter;
+ Gtk::TreeViewColumn *focus_column;
+ attrdialog->_treeView.get_cursor(path, focus_column);
+ if (path == attrdialog->_modelpath && focus_column == attrdialog->_treeView.get_column(1)) {
attrdialog->_treeView.set_cursor(attrdialog->_modelpath, *attrdialog->_valueCol, true);
}
return FALSE;
@@ -602,6 +639,8 @@ void AttrDialog::valueEdited (const Glib::ustring& path, const Glib::ustring& va
}
if(!value.empty()) {
row[_attrColumns._attributeValue] = value;
+ Glib::ustring renderval = sp_remove_newlines_and_tabs(value);
+ row[_attrColumns._attributeValueRender] = renderval;
}
Inkscape::Selection *selection = _desktop->getSelection();
SPObject *obj = nullptr;
diff --git a/src/ui/dialog/attrdialog.h b/src/ui/dialog/attrdialog.h
index 1939706e6..23437f0db 100644
--- a/src/ui/dialog/attrdialog.h
+++ b/src/ui/dialog/attrdialog.h
@@ -50,9 +50,11 @@ public:
AttrColumns() {
add(_attributeName);
add(_attributeValue);
- }
+ add(_attributeValueRender);
+ }
Gtk::TreeModelColumn<Glib::ustring> _attributeName;
Gtk::TreeModelColumn<Glib::ustring> _attributeValue;
+ Gtk::TreeModelColumn<Glib::ustring> _attributeValueRender;
};
AttrColumns _attrColumns;
@@ -113,6 +115,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 textViewMap();
void valueCanceledPop();
void valueEditedPop();
};
diff --git a/src/widgets/sp-xmlview-tree.cpp b/src/widgets/sp-xmlview-tree.cpp
index 2424336c0..cb5726c6f 100644
--- a/src/widgets/sp-xmlview-tree.cpp
+++ b/src/widgets/sp-xmlview-tree.cpp
@@ -179,7 +179,9 @@ add_node (SPXMLViewTree * tree, GtkTreeIter *parent, GtkTreeIter *before, Inksca
}
GtkTreeRowReference *rowref = tree_iter_to_ref (tree, &iter);
+
data = node_data_new (tree, &iter, rowref, repr);
+
g_assert (data != nullptr);
gtk_tree_store_set (tree->store, &iter, STORE_TEXT_COL, default_text, STORE_DATA_COL, data, STORE_REPR_COL, repr, -1);
@@ -310,6 +312,28 @@ void element_order_changed(Inkscape::XML::Node * /*repr*/, Inkscape::XML::Node *
}
}
+Glib::ustring sp_remove_newlines_and_tabs(Glib::ustring val)
+{
+ int pos = 0;
+ Glib::ustring newlinesign = "␤";
+ Glib::ustring tabsign = "⇥";
+ while ((pos = val.find("\r\n")) != std::string::npos) {
+ val.erase(pos, 2);
+ val.insert(pos, newlinesign);
+ }
+ pos = 0;
+ while ((pos = val.find('\n')) != std::string::npos) {
+ val.erase(pos, 1);
+ val.insert(pos, newlinesign);
+ }
+ pos = 0;
+ while ((pos = val.find('\t')) != std::string::npos) {
+ val.erase(pos, 1);
+ val.insert(pos, tabsign);
+ }
+ return val;
+}
+
void text_content_changed(Inkscape::XML::Node * /*repr*/, const gchar * /*old_content*/, const gchar * new_content, gpointer ptr)
{
NodeData *data = static_cast<NodeData *>(ptr);
@@ -317,9 +341,12 @@ void text_content_changed(Inkscape::XML::Node * /*repr*/, const gchar * /*old_co
if (data->tree->blocked) return;
gchar *label = g_strdup_printf ("\"%s\"", new_content);
+ Glib::ustring nolinecontent = label;
+ nolinecontent = sp_remove_newlines_and_tabs(nolinecontent);
+
GtkTreeIter iter;
if (tree_ref_to_iter(data->tree, &iter, data->rowref)) {
- gtk_tree_store_set (GTK_TREE_STORE(data->tree->store), &iter, STORE_TEXT_COL, label, -1);
+ gtk_tree_store_set(GTK_TREE_STORE(data->tree->store), &iter, STORE_TEXT_COL, nolinecontent.c_str(), -1);
}
g_free (label);
@@ -332,9 +359,12 @@ void comment_content_changed(Inkscape::XML::Node * /*repr*/, const gchar * /*old
if (data->tree->blocked) return;
gchar *label = g_strdup_printf ("<!--%s-->", new_content);
+ Glib::ustring nolinecontent = label;
+ nolinecontent = sp_remove_newlines_and_tabs(nolinecontent);
+
GtkTreeIter iter;
if (tree_ref_to_iter(data->tree, &iter, data->rowref)) {
- gtk_tree_store_set (GTK_TREE_STORE(data->tree->store), &iter, STORE_TEXT_COL, label, -1);
+ gtk_tree_store_set(GTK_TREE_STORE(data->tree->store), &iter, STORE_TEXT_COL, nolinecontent.c_str(), -1);
}
g_free (label);
}
@@ -346,9 +376,12 @@ void pi_content_changed(Inkscape::XML::Node *repr, const gchar * /*old_content*/
if (data->tree->blocked) return;
gchar *label = g_strdup_printf ("<?%s %s?>", repr->name(), new_content);
+ Glib::ustring nolinecontent = label;
+ nolinecontent = sp_remove_newlines_and_tabs(nolinecontent);
+
GtkTreeIter iter;
if (tree_ref_to_iter(data->tree, &iter, data->rowref)) {
- gtk_tree_store_set (GTK_TREE_STORE(data->tree->store), &iter, STORE_TEXT_COL, label, -1);
+ gtk_tree_store_set(GTK_TREE_STORE(data->tree->store), &iter, STORE_TEXT_COL, nolinecontent.c_str(), -1);
}
g_free (label);
}