summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/gnome-plist-editor.c114
-rw-r--r--src/gnome-plist-editor.ui14
2 files changed, 124 insertions, 4 deletions
diff --git a/src/gnome-plist-editor.c b/src/gnome-plist-editor.c
index 32a9418..eb79a2a 100644
--- a/src/gnome-plist-editor.c
+++ b/src/gnome-plist-editor.c
@@ -194,6 +194,38 @@ void new_plist_cb(GtkWidget* item, gpointer user_data) {
gtk_tree_view_expand_all(app.document_tree_view);
}
+void add_child_cb(GtkWidget* item, gpointer user_data) {
+
+ GtkTreeSelection *selection;
+ GtkTreeModel *model;
+ GtkTreeView *view = GTK_TREE_VIEW(app.document_tree_view);
+ GtkTreeIter iter;
+ GtkTreePath *path = NULL;
+
+ selection = gtk_tree_view_get_selection(view);
+ if (gtk_tree_selection_get_selected(selection, &model, &iter)) {
+ plist_t node = NULL;
+ gtk_tree_model_get (model, &iter, 0, &node, -1);
+ path = gtk_tree_model_get_path(model, &iter);
+
+ //check that node is a structured node
+ plist_type type = plist_get_node_type(node);
+
+ if (type == PLIST_ARRAY) {
+ plist_array_append_item(node, plist_new_bool(0));
+ gtk_tree_view_expand_row(view, path, FALSE);
+ }
+ else if (type == PLIST_DICT) {
+ uint32_t n = plist_dict_get_size(node);
+ gchar* key = g_strdup_printf("Item %i", n);
+ plist_dict_insert_item(node, key, plist_new_bool(0));
+ g_free(key);
+ gtk_tree_view_expand_row(view, path, FALSE);
+ }
+ gtk_tree_path_free(path);
+ }
+}
+
void type_edited_cb(GtkCellRendererText *cell, gchar *path_string, gchar *new_text, gpointer user_data)
{
plist_t node;
@@ -234,6 +266,88 @@ void type_edited_cb(GtkCellRendererText *cell, gchar *path_string, gchar *new_te
gtk_tree_model_row_changed(model, path, &iter);
}
+void key_edited_cb(GtkCellRendererText *cell, gchar *path_string, gchar *new_text, gpointer user_data)
+{
+ plist_t node;
+ plist_t father;
+ GtkTreeIter iter;
+ GtkTreePath *path = NULL;
+ plist_type type = PLIST_NONE;
+ GtkTreeModel *model = GTK_TREE_MODEL(app.document_tree_store);
+
+ gtk_tree_model_get_iter_from_string(model, &iter, path_string);
+ path = gtk_tree_path_new_from_string(path_string);
+ gtk_tree_model_get(model, &iter, 0, &node, -1);
+
+ father = plist_get_parent(node);
+ if (father){
+ type = plist_get_node_type(father);
+ if (PLIST_DICT == type){
+ char* old_key = NULL;
+ plist_t backup = plist_copy(node);
+ plist_dict_get_item_key(node, &old_key);
+ plist_dict_remove_item(father, old_key);
+ free(old_key);
+ plist_dict_insert_item(father, new_text, backup);
+ gtk_tree_store_set(app.document_tree_store,
+ &iter,
+ 0,
+ (gpointer)backup,
+ -1);
+ }
+ }
+ gtk_tree_model_row_changed(model, path, &iter);
+}
+
+void value_edited_cb(GtkCellRendererText *cell, gchar *path_string, gchar *new_text, gpointer user_data)
+{
+ plist_t node;
+ GtkTreeIter iter;
+ GtkTreePath *path = NULL;
+ plist_type type = PLIST_NONE;
+ GtkTreeModel *model = GTK_TREE_MODEL(app.document_tree_store);
+
+ double d;
+ uint8_t b;
+ uint64_t u;
+
+ gtk_tree_model_get_iter_from_string(model, &iter, path_string);
+ path = gtk_tree_path_new_from_string(path_string);
+ gtk_tree_model_get(model, &iter, 0, &node, -1);
+
+ type = plist_get_node_type(node);
+ switch (type){
+ case PLIST_BOOLEAN:
+ b = !strcmp(new_text, "true") ? 1 : 0;
+ plist_set_bool_val(node, b);
+ break;
+ case PLIST_UINT:
+ u = g_ascii_strtoull(new_text, NULL, 0);
+ plist_set_uint_val(node, u);
+ break;
+ case PLIST_REAL:
+ d = g_ascii_strtod(new_text, NULL);
+ plist_set_real_val(node, d);
+ break;
+ case PLIST_STRING:
+ plist_set_string_val(node, new_text);
+ break;
+ case PLIST_DATA:
+ //TODO
+ break;
+ case PLIST_DATE:
+ //TODO
+ break;
+ case PLIST_ARRAY:
+ case PLIST_DICT:
+ break;
+ default:
+ break;
+ }
+ gtk_tree_model_row_changed(model, path, &iter);
+}
+
+
void about_menu_item_activate_cb(GtkMenuItem* item, gpointer user_data) {
gtk_show_about_dialog(app.main_window,
"program-name", "GNOME Property List Editor",
diff --git a/src/gnome-plist-editor.ui b/src/gnome-plist-editor.ui
index e1a7931..92cea0b 100644
--- a/src/gnome-plist-editor.ui
+++ b/src/gnome-plist-editor.ui
@@ -249,12 +249,12 @@
</packing>
</child>
<child>
- <object class="GtkToolButton" id="add_sibling_button">
+ <object class="GtkToolButton" id="add_child_button">
<property name="visible">True</property>
- <property name="sensitive">False</property>
<property name="label" translatable="yes">Add Item</property>
<property name="use_underline">True</property>
<property name="icon_name">list-add</property>
+ <signal name="clicked" handler="add_child_cb"/>
</object>
<packing>
<property name="expand">False</property>
@@ -304,7 +304,10 @@
<property name="min_width">150</property>
<property name="title">Key</property>
<child>
- <object class="GtkCellRendererText" id="cellrenderertext1"/>
+ <object class="GtkCellRendererText" id="cellrenderertext1">
+ <property name="editable">True</property>
+ <signal name="edited" handler="key_edited_cb"/>
+ </object>
</child>
</object>
</child>
@@ -328,7 +331,10 @@
<property name="title">Value</property>
<property name="expand">True</property>
<child>
- <object class="GtkCellRendererText" id="cellrenderertext2"/>
+ <object class="GtkCellRendererText" id="cellrenderertext2">
+ <property name="editable">True</property>
+ <signal name="edited" handler="value_edited_cb"/>
+ </object>
</child>
</object>
</child>