diff options
Diffstat (limited to 'tikzit/src/gtk/PropertyListEditor.m')
-rw-r--r-- | tikzit/src/gtk/PropertyListEditor.m | 52 |
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 |