summaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
authorMarc Jeanmougin <marc@jeanmougin.fr>2018-09-11 20:00:01 +0000
committerMarc Jeanmougin <marc@jeanmougin.fr>2018-09-11 20:00:01 +0000
commit9f11d4ba5a2bbbcf52946abf5eb2ed52dc12586f (patch)
treea82dc320a9eadb43280ae6d8221c7de1f6f6b8b7 /src/widgets
parentAdd gitlab job for protected code (diff)
parentUpdate CONTRIBUTING.md (diff)
downloadinkscape-9f11d4ba5a2bbbcf52946abf5eb2ed52dc12586f.tar.gz
inkscape-9f11d4ba5a2bbbcf52946abf5eb2ed52dc12586f.zip
Merge branch 'master' of gitlab.com:inkscape/inkscape
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/CMakeLists.txt2
-rw-r--r--src/widgets/sp-xmlview-attr-list.cpp128
-rw-r--r--src/widgets/sp-xmlview-attr-list.h12
-rw-r--r--src/widgets/sp-xmlview-content.cpp136
-rw-r--r--src/widgets/sp-xmlview-content.h45
5 files changed, 93 insertions, 230 deletions
diff --git a/src/widgets/CMakeLists.txt b/src/widgets/CMakeLists.txt
index 052e82347..3853bb91a 100644
--- a/src/widgets/CMakeLists.txt
+++ b/src/widgets/CMakeLists.txt
@@ -22,7 +22,6 @@ set(widgets_SRC
sp-color-selector.cpp
sp-widget.cpp
sp-xmlview-attr-list.cpp
- sp-xmlview-content.cpp
sp-xmlview-tree.cpp
spinbutton-events.cpp
spw-utilities.cpp
@@ -55,7 +54,6 @@ set(widgets_SRC
sp-color-selector.h
sp-widget.h
sp-xmlview-attr-list.h
- sp-xmlview-content.h
sp-xmlview-tree.h
spinbutton-events.h
spw-utilities.h
diff --git a/src/widgets/sp-xmlview-attr-list.cpp b/src/widgets/sp-xmlview-attr-list.cpp
index 720856ba5..8fc1981e3 100644
--- a/src/widgets/sp-xmlview-attr-list.cpp
+++ b/src/widgets/sp-xmlview-attr-list.cpp
@@ -25,11 +25,11 @@ static void sp_xmlview_attr_list_destroy(GtkWidget * object);
static void event_attr_changed (Inkscape::XML::Node * repr, const gchar * name, const gchar * old_value, const gchar * new_value, bool is_interactive, gpointer data);
static Inkscape::XML::NodeEventVector repr_events = {
- nullptr, /* child_added */
- nullptr, /* child_removed */
- event_attr_changed,
- nullptr, /* content_changed */
- nullptr /* order_changed */
+ nullptr, /* child_added */
+ nullptr, /* child_removed */
+ event_attr_changed,
+ nullptr, /* content_changed */
+ nullptr /* order_changed */
};
GtkWidget *sp_xmlview_attr_list_new (Inkscape::XML::Node * repr)
@@ -56,8 +56,11 @@ GtkWidget *sp_xmlview_attr_list_new (Inkscape::XML::Node * repr)
column = gtk_tree_view_get_column (GTK_TREE_VIEW(attr_list), colpos);
gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
gtk_cell_renderer_set_padding (cell, 2, 0);
+ g_object_set(cell, "editable", TRUE, NULL);
sp_xmlview_attr_list_set_repr (attr_list, repr);
+ g_signal_connect(cell, "edited", (GCallback) attr_value_edited, attr_list);
+ g_signal_connect( G_OBJECT(attr_list), "key-press-event", G_CALLBACK(attr_key_pressed), NULL);
return GTK_WIDGET(attr_list);
}
@@ -65,26 +68,26 @@ GtkWidget *sp_xmlview_attr_list_new (Inkscape::XML::Node * repr)
void
sp_xmlview_attr_list_set_repr (SPXMLViewAttrList * list, Inkscape::XML::Node * repr)
{
- if ( repr == list->repr ) return;
- if (list->repr) {
- gtk_list_store_clear(list->store);
- sp_repr_remove_listener_by_data (list->repr, list);
- Inkscape::GC::release(list->repr);
- }
- list->repr = repr;
- if (repr) {
- Inkscape::GC::anchor(repr);
- sp_repr_add_listener (repr, &repr_events, list);
- sp_repr_synthesize_events (repr, &repr_events, list);
- }
+ if ( repr == list->repr ) return;
+ if (list->repr) {
+ gtk_list_store_clear(list->store);
+ sp_repr_remove_listener_by_data (list->repr, list);
+ Inkscape::GC::release(list->repr);
+ }
+ list->repr = repr;
+ if (repr) {
+ Inkscape::GC::anchor(repr);
+ sp_repr_add_listener (repr, &repr_events, list);
+ sp_repr_synthesize_events (repr, &repr_events, list);
+ }
}
G_DEFINE_TYPE(SPXMLViewAttrList, sp_xmlview_attr_list, GTK_TYPE_TREE_VIEW);
void sp_xmlview_attr_list_class_init (SPXMLViewAttrListClass * klass)
{
- auto widget_class = GTK_WIDGET_CLASS(klass);
- widget_class->destroy = sp_xmlview_attr_list_destroy;
+ auto widget_class = GTK_WIDGET_CLASS(klass);
+ widget_class->destroy = sp_xmlview_attr_list_destroy;
g_signal_new("row-value-changed",
G_TYPE_FROM_CLASS(klass),
@@ -92,27 +95,33 @@ void sp_xmlview_attr_list_class_init (SPXMLViewAttrListClass * klass)
G_STRUCT_OFFSET (SPXMLViewAttrListClass, row_changed),
nullptr, nullptr,
g_cclosure_marshal_VOID__STRING,
- G_TYPE_NONE, 1,
- G_TYPE_STRING);
+ G_TYPE_NONE, 1, G_TYPE_STRING);
+ g_signal_new("attr-value-edited",
+ G_TYPE_FROM_CLASS(klass),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (SPXMLViewAttrListClass, row_changed),
+ nullptr, nullptr,
+ sp_marshal_VOID__STRING_STRING,
+ G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_STRING);
}
void
sp_xmlview_attr_list_init (SPXMLViewAttrList * list)
{
list->store = nullptr;
- list->repr = nullptr;
+ list->repr = nullptr;
}
void sp_xmlview_attr_list_destroy(GtkWidget * object)
{
- SPXMLViewAttrList * list;
+ SPXMLViewAttrList * list;
- list = SP_XMLVIEW_ATTR_LIST (object);
+ list = SP_XMLVIEW_ATTR_LIST (object);
- g_object_unref(list->store);
- sp_xmlview_attr_list_set_repr (list, nullptr);
+ g_object_unref(list->store);
+ sp_xmlview_attr_list_set_repr (list, nullptr);
- GTK_WIDGET_CLASS(sp_xmlview_attr_list_parent_class)->destroy (object);
+ GTK_WIDGET_CLASS(sp_xmlview_attr_list_parent_class)->destroy (object);
}
void sp_xmlview_attr_list_select_row_by_key(SPXMLViewAttrList * list, const gchar *name)
@@ -141,6 +150,43 @@ void sp_xmlview_attr_list_select_row_by_key(SPXMLViewAttrList * list, const gcha
}
void
+attr_value_edited (GtkCellRendererText *cell,
+ gchar * path_string,
+ gchar * new_value,
+ gpointer data) {
+
+ SPXMLViewAttrList * list = SP_XMLVIEW_ATTR_LIST (data);
+ GtkTreeIter iter;
+ gboolean valid = gtk_tree_model_get_iter_from_string( GTK_TREE_MODEL(list->store), &iter, path_string );
+ if(valid) {
+ gchar *name = nullptr;
+ gtk_tree_model_get (GTK_TREE_MODEL(list->store), &iter, ATTR_COL_NAME, &name, -1);
+ g_signal_emit_by_name(G_OBJECT (list), "attr-value-edited", name, new_value );
+ }
+}
+
+gboolean
+attr_key_pressed(GtkWidget *attributes, GdkEventKey *event, gpointer /*data*/)
+{
+ GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(attributes));
+ GtkTreeIter iter;
+ GtkTreeModel *model;
+ gchar *name = nullptr;
+ if (gtk_tree_selection_get_selected (selection, &model, &iter)) {
+ gtk_tree_model_get (model, &iter, 0, &name, -1);
+
+ switch (event->keyval)
+ {
+ case GDK_KEY_Delete:
+ case GDK_KEY_KP_Delete:
+ g_signal_emit_by_name(G_OBJECT (attributes), "attr-value-edited", name, nullptr);
+ return true;
+ }
+ }
+ return false;
+}
+
+void
event_attr_changed (Inkscape::XML::Node * /*repr*/,
const gchar * name,
const gchar * /*old_value*/,
@@ -148,10 +194,8 @@ event_attr_changed (Inkscape::XML::Node * /*repr*/,
bool /*is_interactive*/,
gpointer data)
{
- gint row = -1;
- SPXMLViewAttrList * list;
-
- list = SP_XMLVIEW_ATTR_LIST (data);
+ gint row = -1;
+ SPXMLViewAttrList * list = SP_XMLVIEW_ATTR_LIST (data);
GtkTreeIter iter;
gboolean valid = gtk_tree_model_get_iter_first( GTK_TREE_MODEL(list->store), &iter );
@@ -171,18 +215,18 @@ event_attr_changed (Inkscape::XML::Node * /*repr*/,
}
}
- if (match) {
- if (new_value) {
- gtk_list_store_set (list->store, &iter, ATTR_COL_NAME, name, ATTR_COL_VALUE, new_value, ATTR_COL_ATTR, g_quark_from_string (name), -1);
- } else {
- gtk_list_store_remove (list->store, &iter);
- }
- } else if (new_value != nullptr) {
- gtk_list_store_append (list->store, &iter);
+ if (match) {
+ if (new_value) {
+ gtk_list_store_set (list->store, &iter, ATTR_COL_NAME, name, ATTR_COL_VALUE, new_value, ATTR_COL_ATTR, g_quark_from_string (name), -1);
+ } else {
+ gtk_list_store_remove (list->store, &iter);
+ }
+ } else if (new_value != nullptr) {
+ gtk_list_store_append (list->store, &iter);
gtk_list_store_set (list->store, &iter, ATTR_COL_NAME, name, ATTR_COL_VALUE, new_value, ATTR_COL_ATTR, g_quark_from_string (name), -1);
- }
+ }
- // send a "changed" signal so widget owners will know I've updated
- g_signal_emit_by_name(G_OBJECT (list), "row-value-changed", name );
+ // send a "changed" signal so widget owners will know I've updated
+ g_signal_emit_by_name(G_OBJECT (list), "row-value-changed", name );
}
diff --git a/src/widgets/sp-xmlview-attr-list.h b/src/widgets/sp-xmlview-attr-list.h
index 799dbe76a..1367b0628 100644
--- a/src/widgets/sp-xmlview-attr-list.h
+++ b/src/widgets/sp-xmlview-attr-list.h
@@ -21,17 +21,17 @@
struct SPXMLViewAttrList
{
- GtkTreeView list;
- GtkListStore *store;
+ GtkTreeView list;
+ GtkListStore *store;
- Inkscape::XML::Node * repr;
+ Inkscape::XML::Node * repr;
};
struct SPXMLViewAttrListClass
{
- GtkTreeViewClass parent_class;
+ GtkTreeViewClass parent_class;
- void (* row_changed) (SPXMLViewAttrList *list, gint row);
+ void (* row_changed) (SPXMLViewAttrList *list, gint row);
};
GType sp_xmlview_attr_list_get_type ();
@@ -41,6 +41,8 @@ GtkWidget * sp_xmlview_attr_list_new (Inkscape::XML::Node * repr);
void sp_xmlview_attr_list_set_repr (SPXMLViewAttrList * list, Inkscape::XML::Node * repr);
void sp_xmlview_attr_list_select_row_by_key(SPXMLViewAttrList * list, const gchar *name);
+void attr_value_edited (GtkCellRendererText *cell, gchar * path_string, gchar * new_value, gpointer data);
+gboolean attr_key_pressed(GtkWidget *attributes, GdkEventKey *event, gpointer data);
/* Attribute list store columns */
enum {ATTR_COL_NAME=0, ATTR_COL_ATTR=1, ATTR_COL_VALUE=2, ATTR_N_COLS=3 };
diff --git a/src/widgets/sp-xmlview-content.cpp b/src/widgets/sp-xmlview-content.cpp
deleted file mode 100644
index 6fc08c4ac..000000000
--- a/src/widgets/sp-xmlview-content.cpp
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * Specialization of GtkTextView for the XML tree view
- *
- * Authors:
- * MenTaLguY <mental@rydia.net>
- *
- * Copyright (C) 2002 MenTaLguY
- * Abhishek Sharma
- *
- * Released under the GNU GPL; see COPYING for details
- */
-
-#include <cstring>
-#include <glibmm/i18n.h>
-
-#include "xml/node-event-vector.h"
-#include "sp-xmlview-content.h"
-#include "desktop.h"
-#include "document-private.h"
-#include "document-undo.h"
-#include "inkscape.h"
-#include "verbs.h"
-
-using Inkscape::DocumentUndo;
-
-static void sp_xmlview_content_destroy(GtkWidget * object);
-
-void sp_xmlview_content_changed (GtkTextBuffer *tb, SPXMLViewContent *text);
-
-static void event_content_changed (Inkscape::XML::Node * repr, const gchar * old_content, const gchar * new_content, gpointer data);
-
-static Inkscape::XML::NodeEventVector repr_events = {
- nullptr, /* child_added */
- nullptr, /* child_removed */
- nullptr, /* attr_changed */
- event_content_changed,
- nullptr /* order_changed */
-};
-
-GtkWidget *sp_xmlview_content_new(Inkscape::XML::Node * repr)
-{
- GtkTextBuffer *tb = gtk_text_buffer_new(nullptr);
- SPXMLViewContent *text = SP_XMLVIEW_CONTENT(g_object_new(SP_TYPE_XMLVIEW_CONTENT, nullptr));
- gtk_text_view_set_buffer (GTK_TEXT_VIEW (text), tb);
- gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (text), GTK_WRAP_CHAR);
-
- g_signal_connect (G_OBJECT (tb), "changed", G_CALLBACK (sp_xmlview_content_changed), text);
-
- /* should we alter the scrolling adjustments here? */
-
- sp_xmlview_content_set_repr (text, repr);
-
- return GTK_WIDGET(text);
-}
-
-void
-sp_xmlview_content_set_repr (SPXMLViewContent * text, Inkscape::XML::Node * repr)
-{
- if ( repr == text->repr ) return;
- if (text->repr) {
- sp_repr_remove_listener_by_data (text->repr, text);
- Inkscape::GC::release(text->repr);
- }
- text->repr = repr;
- if (repr) {
- Inkscape::GC::anchor(repr);
- sp_repr_add_listener (repr, &repr_events, text);
- sp_repr_synthesize_events (repr, &repr_events, text);
- } else {
- gtk_text_buffer_set_text (gtk_text_view_get_buffer (GTK_TEXT_VIEW (text)), "", 0);
- gtk_text_view_set_editable (GTK_TEXT_VIEW (text), FALSE);
- }
-}
-
-G_DEFINE_TYPE(SPXMLViewContent, sp_xmlview_content, GTK_TYPE_TEXT_VIEW);
-
-void sp_xmlview_content_class_init(SPXMLViewContentClass * klass)
-{
- auto widget_class = GTK_WIDGET_CLASS(klass);
- widget_class->destroy = sp_xmlview_content_destroy;
-}
-
-void
-sp_xmlview_content_init (SPXMLViewContent *text)
-{
- text->repr = nullptr;
- text->blocked = FALSE;
-}
-
-void sp_xmlview_content_destroy(GtkWidget * object)
-{
- SPXMLViewContent * text = SP_XMLVIEW_CONTENT (object);
-
- sp_xmlview_content_set_repr (text, nullptr);
-
- GTK_WIDGET_CLASS (sp_xmlview_content_parent_class)->destroy (object);
-}
-
-void
-event_content_changed (Inkscape::XML::Node * /*repr*/, const gchar * /*old_content*/, const gchar * new_content, gpointer data)
-{
- SPXMLViewContent * text;
- text = SP_XMLVIEW_CONTENT (data);
-
- if (text->blocked) return;
-
- text->blocked = TRUE;
-
- if (new_content) {
- gtk_text_buffer_set_text (gtk_text_view_get_buffer (GTK_TEXT_VIEW (text)), new_content, strlen (new_content));
- } else {
- gtk_text_buffer_set_text (gtk_text_view_get_buffer (GTK_TEXT_VIEW (text)), "", 0);
- }
- gtk_text_view_set_editable (GTK_TEXT_VIEW (text), new_content != nullptr);
-
- text->blocked = FALSE;
-}
-
-void
-sp_xmlview_content_changed (GtkTextBuffer *tb, SPXMLViewContent *text)
-{
- if (text->blocked) return;
-
- if (text->repr) {
- GtkTextIter start, end;
- gchar *data;
- text->blocked = TRUE;
- gtk_text_buffer_get_bounds (tb, &start, &end);
- data = gtk_text_buffer_get_text (tb, &start, &end, TRUE);
- text->repr->setContent(data);
- g_free (data);
- text->blocked = FALSE;
- DocumentUndo::done(SP_ACTIVE_DESKTOP->getDocument(), SP_VERB_DIALOG_XML_EDITOR,
- _("Type text in a text node"));
- }
-}
diff --git a/src/widgets/sp-xmlview-content.h b/src/widgets/sp-xmlview-content.h
deleted file mode 100644
index 962b80738..000000000
--- a/src/widgets/sp-xmlview-content.h
+++ /dev/null
@@ -1,45 +0,0 @@
-#ifndef __SP_XMLVIEW_CONTENT_H__
-#define __SP_XMLVIEW_CONTENT_H__
-
-/*
- * Specialization of GtkTextView for editing XML node text
- *
- * Authors:
- * MenTaLguY <mental@rydia.net>
- *
- * Copyright (C) 2002 MenTaLguY
- *
- * Released under the GNU GPL; see COPYING for details
- */
-
-#include <config.h>
-#include <gtk/gtk.h>
-
-#define SP_TYPE_XMLVIEW_CONTENT (sp_xmlview_content_get_type ())
-#define SP_XMLVIEW_CONTENT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), SP_TYPE_XMLVIEW_CONTENT, SPXMLViewContent))
-#define SP_IS_XMLVIEW_CONTENT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), SP_TYPE_XMLVIEW_CONTENT))
-#define SP_XMLVIEW_CONTENT_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), SP_TYPE_XMLVIEW_CONTENT))
-
-struct SPXMLViewContent
-{
- GtkTextView textview;
-
- Inkscape::XML::Node * repr;
- gint blocked;
-};
-
-struct SPXMLViewContentClass
-{
- GtkTextViewClass parent_class;
-};
-
-GType sp_xmlview_content_get_type ();
-GtkWidget * sp_xmlview_content_new (Inkscape::XML::Node * repr);
-
-#define SP_XMLVIEW_CONTENT_GET_REPR(text) (SP_XMLVIEW_CONTENT (text)->repr)
-
-void sp_xmlview_content_set_repr (SPXMLViewContent * text, Inkscape::XML::Node * repr);
-
-
-
-#endif