summaryrefslogtreecommitdiff
path: root/tikzit/src/gtk/PropertyListEditor.m
diff options
context:
space:
mode:
authorAlex Merry <alex.merry@cs.ox.ac.uk>2013-02-04 18:08:38 +0000
committerAlex Merry <alex.merry@cs.ox.ac.uk>2013-02-04 18:08:38 +0000
commitdc720cc5d5e3f5b2f3d8119947a9dd8c69f4b2df (patch)
tree7b3eeeaca920b37f45d3c762ea6dc6c625760780 /tikzit/src/gtk/PropertyListEditor.m
parent0f2452356ae718b73e9467e388092c8af6752a8f (diff)
GTK: prevent the user from creating invalid tikz
The free-form entry fields (graph element properties and node labels) are a potential source of invalid tikz code. Since we quote any dodgy-looking text with { and }, we just need to make sure there are no unmatched curly braces entered in those fields. This will turn the entry widgets red when there are unmatched braces, and refuse to make use of any such values.
Diffstat (limited to 'tikzit/src/gtk/PropertyListEditor.m')
-rw-r--r--tikzit/src/gtk/PropertyListEditor.m52
1 files changed, 52 insertions, 0 deletions
diff --git a/tikzit/src/gtk/PropertyListEditor.m b/tikzit/src/gtk/PropertyListEditor.m
index ba909da..72b7441 100644
--- a/tikzit/src/gtk/PropertyListEditor.m
+++ b/tikzit/src/gtk/PropertyListEditor.m
@@ -16,6 +16,7 @@
*/
#import "PropertyListEditor.h"
+#import "gtkhelpers.h"
// {{{ Constants
@@ -45,6 +46,12 @@ static void add_atom_clicked_cb (GtkButton *button,
PropertyListEditor *editor);
static void remove_clicked_cb (GtkButton *button,
PropertyListEditor *editor);
+static void text_editing_started (GtkCellRenderer *cell,
+ GtkCellEditable *editable,
+ const gchar *path,
+ PropertyListEditor *editor);
+static void text_changed_cb (GtkEditable *editable,
+ PropertyListEditor *pane);
// }}}
// {{{ Private
@@ -95,6 +102,10 @@ static void remove_clicked_cb (GtkButton *button,
NULL);
gtk_tree_view_append_column (GTK_TREE_VIEW (view), column);
g_signal_connect (G_OBJECT (renderer),
+ "editing-started",
+ G_CALLBACK (text_editing_started),
+ self);
+ g_signal_connect (G_OBJECT (renderer),
"edited",
G_CALLBACK (name_edited_cb),
self);
@@ -237,6 +248,9 @@ static void remove_clicked_cb (GtkButton *button,
@implementation PropertyListEditor (Private)
- (void) updatePath:(gchar*)pathStr withValue:(NSString*)newText {
+ if (![newText isValidTikz])
+ return;
+
GtkTreeIter iter;
GtkTreePath *path = gtk_tree_path_new_from_string (pathStr);
@@ -265,6 +279,9 @@ static void remove_clicked_cb (GtkButton *button,
}
- (void) updatePath:(gchar*)pathStr withName:(NSString*)newText {
+ if (![newText isValidTikz])
+ return;
+
GtkTreeIter iter;
GtkTreePath *path = gtk_tree_path_new_from_string (pathStr);
@@ -420,6 +437,41 @@ static void remove_clicked_cb (GtkButton *button,
[pool drain];
}
+static void text_editing_started (GtkCellRenderer *cell,
+ GtkCellEditable *editable,
+ const gchar *path,
+ PropertyListEditor *editor)
+{
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+ if (GTK_IS_EDITABLE (editable) && GTK_IS_WIDGET (editable)) {
+ g_signal_handlers_disconnect_by_func (G_OBJECT (editable),
+ G_CALLBACK (text_changed_cb),
+ editor);
+ widget_clear_error (GTK_WIDGET (editable));
+ g_signal_connect (G_OBJECT (editable),
+ "changed",
+ G_CALLBACK (text_changed_cb),
+ editor);
+ }
+
+ [pool drain];
+}
+
+static void text_changed_cb (GtkEditable *editable, PropertyListEditor *pane)
+{
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+ NSString *newValue = gtk_editable_get_string (editable, 0, -1);
+ if (![newValue isValidTikz]) {
+ widget_set_error (GTK_WIDGET (editable));
+ } else {
+ widget_clear_error (GTK_WIDGET (editable));
+ }
+
+ [pool drain];
+}
+
// }}}
// vim:ft=objc:ts=8:et:sts=4:sw=4:foldmethod=marker