[Goodies-commits] r5759 - xfbib/branches/gobject/src
David Gustafsson
tssj at xfce.org
Wed Oct 22 23:30:56 CEST 2008
Author: tssj
Date: 2008-10-22 21:30:56 +0000 (Wed, 22 Oct 2008)
New Revision: 5759
Modified:
xfbib/branches/gobject/src/xfbib-bibtex.c
xfbib/branches/gobject/src/xfbib-bibtex.h
xfbib/branches/gobject/src/xfbib-list-store.c
xfbib/branches/gobject/src/xfbib-list-store.h
xfbib/branches/gobject/src/xfbib-menu-bar.c
xfbib/branches/gobject/src/xfbib-tree-view.c
Log:
Added initial functionality for saving existing entries
Modified: xfbib/branches/gobject/src/xfbib-bibtex.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-bibtex.c 2008-10-22 21:22:01 UTC (rev 5758)
+++ xfbib/branches/gobject/src/xfbib-bibtex.c 2008-10-22 21:30:56 UTC (rev 5759)
@@ -412,3 +412,46 @@
elements->n_entries++;
}
+/*
+ * Return the position of the new entry, counting from 0
+ */
+gint
+xfbib_bibtex_replace_entry(XfbibBibtex *elements, XfbibBibtexEntry *old_entry, XfbibBibtexEntry *new_entry)
+{
+ GObject *obj;
+ gint n = 0;
+ g_return_val_if_fail(XFBIB_IS_BIBTEX(elements), -1);
+ g_return_val_if_fail(XFBIB_IS_BIBTEX_ENTRY(old_entry) && XFBIB_IS_BIBTEX_ENTRY(new_entry), -1);
+
+#if G_SEQUENCE
+ GSequenceIter *iter;
+ for (iter = g_sequence_get_begin_iter(elements->seq);
+ !g_sequence_iter_is_end(iter); iter = g_sequence_iter_next(iter)) {
+ obj = g_sequence_get(iter);
+ if (XFBIB_IS_BIBTEX_ENTRY(obj))
+ n++;
+
+ if (obj == G_OBJECT(old_entry)) {
+ g_sequence_insert_before(iter, new_entry);
+ g_sequence_remove(iter);
+ return n;
+ }
+ }
+#else
+ gint i, len;
+ len = g_list_length(elements->list);
+ for (i = 0; i < len; i++) {
+ obj = g_list_nth(elements->list, i);
+ if (XFBIB_IS_BIBTEX_ENTRY(obj->data))
+ n++;
+
+ if (obj->data == G_OBJECT(old_entry)) {
+ elements->list = g_list_insert_before(elements->list, obj, new_entry);
+ elements->list = g_list_remove(elements->list, obj);
+ return n;
+ }
+ }
+#endif
+ return -1;
+}
+
Modified: xfbib/branches/gobject/src/xfbib-bibtex.h
===================================================================
--- xfbib/branches/gobject/src/xfbib-bibtex.h 2008-10-22 21:22:01 UTC (rev 5758)
+++ xfbib/branches/gobject/src/xfbib-bibtex.h 2008-10-22 21:30:56 UTC (rev 5759)
@@ -27,6 +27,7 @@
void xfbib_bibtex_remove(XfbibBibtex *, GObject *);
void xfbib_bibtex_remove_all(XfbibBibtex *);
void xfbib_bibtex_add_entry(XfbibBibtex *, XfbibBibtexEntry *);
+gint xfbib_bibtex_replace_entry(XfbibBibtex *, XfbibBibtexEntry *, XfbibBibtexEntry *);
G_END_DECLS
Modified: xfbib/branches/gobject/src/xfbib-list-store.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-list-store.c 2008-10-22 21:22:01 UTC (rev 5758)
+++ xfbib/branches/gobject/src/xfbib-list-store.c 2008-10-22 21:30:56 UTC (rev 5759)
@@ -579,6 +579,23 @@
gtk_tree_path_free(path);
}
+void
+xfbib_list_store_row_changed(XfbibListStore *list_store, gint pos)
+{
+ GtkTreePath *path;
+ GtkTreeIter iter;
+ g_return_if_fail(XFBIB_IS_LIST_STORE(list_store));
+
+ path = gtk_tree_path_new();
+ gtk_tree_path_append_index(path, pos);
+
+ gtk_tree_model_get_iter(GTK_TREE_MODEL(list_store), &iter, path);
+
+ gtk_tree_model_row_changed(GTK_TREE_MODEL(list_store), path, &iter);
+
+ gtk_tree_path_free(path);
+}
+
XfbibBibtexEntry *
xfbib_list_store_get_entry(XfbibListStore *list_store, GtkTreeIter *iter)
{
@@ -604,3 +621,20 @@
n = xfbib_bibtex_get_n_entries(elements);
xfbib_list_store_row_inserted(list_store, n-1);
}
+
+void
+xfbib_list_store_replace_entry(XfbibListStore *list_store, XfbibBibtexEntry *old_entry,
+ XfbibBibtexEntry *new_entry)
+{
+ XfbibBibtex *elements;
+ gint n;
+
+ g_return_if_fail(XFBIB_IS_LIST_STORE(list_store));
+ g_return_if_fail(XFBIB_BIBTEX_ENTRY(old_entry) && XFBIB_BIBTEX_ENTRY(new_entry));
+
+ elements = xfbib_state_get_bibtex_elements(list_store->state);
+
+ n = xfbib_bibtex_replace_entry(elements, old_entry, new_entry);
+
+ xfbib_list_store_row_changed(list_store, n);
+}
Modified: xfbib/branches/gobject/src/xfbib-list-store.h
===================================================================
--- xfbib/branches/gobject/src/xfbib-list-store.h 2008-10-22 21:22:01 UTC (rev 5758)
+++ xfbib/branches/gobject/src/xfbib-list-store.h 2008-10-22 21:30:56 UTC (rev 5759)
@@ -42,7 +42,9 @@
void xfbib_list_store_row_inserted(XfbibListStore *, gint);
XfbibBibtexEntry *xfbib_list_store_get_entry(XfbibListStore *, GtkTreeIter *);
void xfbib_list_store_add_entry(XfbibListStore *, XfbibBibtexEntry *);
+void xfbib_list_store_replace_entry(XfbibListStore *, XfbibBibtexEntry *, XfbibBibtexEntry *);
+
G_END_DECLS
#endif //__XFBIB_LIST_STORE_H
Modified: xfbib/branches/gobject/src/xfbib-menu-bar.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-menu-bar.c 2008-10-22 21:22:01 UTC (rev 5758)
+++ xfbib/branches/gobject/src/xfbib-menu-bar.c 2008-10-22 21:30:56 UTC (rev 5759)
@@ -168,9 +168,8 @@
dialog = xfbib_entry_edit_dialog_new(entry);
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) {
- /* TODO: Save the entry */
new_entry = xfbib_entry_edit_dialog_get_entry(XFBIB_ENTRY_EDIT_DIALOG(dialog));
- g_printf("TODO: Edit an existing entry\n");
+ xfbib_list_store_replace_entry(XFBIB_LIST_STORE(model), entry, new_entry);
}
gtk_widget_destroy(dialog);
} else {
Modified: xfbib/branches/gobject/src/xfbib-tree-view.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-tree-view.c 2008-10-22 21:22:01 UTC (rev 5758)
+++ xfbib/branches/gobject/src/xfbib-tree-view.c 2008-10-22 21:30:56 UTC (rev 5759)
@@ -95,9 +95,8 @@
entry = xfbib_list_store_get_entry(XFBIB_LIST_STORE(model), &iter);
dialog = xfbib_entry_edit_dialog_new(entry);
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) {
- /* TODO: Save the entry to an existing entry */
new_entry = xfbib_entry_edit_dialog_get_entry(XFBIB_ENTRY_EDIT_DIALOG(dialog));
- g_printf("TODO: Edit an existing entry\n");
+ xfbib_list_store_replace_entry(XFBIB_LIST_STORE(model), entry, new_entry);
}
gtk_widget_destroy(dialog);
}
More information about the Goodies-commits
mailing list