#include "store.h"
#include "editor.h"
+#include "notebook.h"
static TextNoteParagraphStyles paragraph_styles[] = {
{ "Paragraph", EDITOR_STYLE_PARAGRAPH },
// new note
note_store_new_note_async(obj, note, NULL, NULL);
notebook->disable_selection_events = TRUE;
+ int index = notebook->notes->count(notebook->notes);
ui_list_append(notebook->notes, note);
- ui_list_update(notebook->notes);
+ notebook->notes->update(notebook->notes, index);
notebook->disable_selection_events = FALSE;
} else {
note_store_save_note_async(obj, note, NULL, NULL);
}
+
+void note_update_title(NotebookModel *notebook, Note *note) {
+ int index = notebookmode_get_note_index(notebook, note);
+ if(index < 0) {
+ return;
+ }
+ NoteModel *m = note->model;
+ m->modified = TRUE;
+
+ char *title = ui_get(m->title);
+ cxFree(m->note_allocator, note->title);
+ note->title = cx_strdup_a(m->note_allocator, cx_str(title)).ptr;
+
+ notebook->notes->update(notebook->notes, index);
+}
+
const char* note_get_title(Note *note) {
return note->title ? note->title : note->name;
}
void ui_listview_update2(UiList *list, int i) {
UiListView *view = list->obj;
- ui_update_liststore(view->liststore, list);
+ if(i < 0) {
+ ui_update_liststore(view->liststore, list);
+ } else {
+ void *value = list->get(list, i);
+ if(value) {
+ ObjWrapper *obj = obj_wrapper_new(value);
+ // TODO: if index i is selected, the selection is lost
+ // is it possible to update the item without removing it?
+ g_list_store_splice(view->liststore, i, 1, (void **)&obj, 1);
+ }
+ }
}
UiListSelection ui_listview_getselection2(UiList *list) {
#else
+static void update_list_row(GtkListStore *store, GtkTreeIter *iter, UiModel *model, void *elm) {
+ // set column values
+ int c = 0;
+ for(int i=0;i<model->columns;i++,c++) {
+ void *data = model->getvalue(elm, c);
+
+ GValue value = G_VALUE_INIT;
+ switch(model->types[i]) {
+ case UI_STRING:
+ case UI_STRING_FREE: {
+ g_value_init(&value, G_TYPE_STRING);
+ g_value_set_string(&value, data);
+ if(model->types[i] == UI_STRING_FREE) {
+ free(data);
+ }
+ break;
+ }
+ case UI_INTEGER: {
+ g_value_init(&value, G_TYPE_INT);
+ intptr_t intptr = (intptr_t)data;
+ g_value_set_int(&value, (int)intptr);
+ break;
+ }
+ case UI_ICON: {
+ g_value_init(&value, G_TYPE_OBJECT);
+ UiIcon *icon = data;
+#if GTK_MAJOR_VERSION >= 4
+ g_value_set_object(&value, icon->info); // TODO: does this work?
+#else
+ if(!icon->pixbuf && icon->info) {
+ GError *error = NULL;
+ GdkPixbuf *pixbuf = gtk_icon_info_load_icon(icon->info, &error);
+ icon->pixbuf = pixbuf;
+ }
+
+ if(icon->pixbuf) {
+ g_value_set_object(&value, icon->pixbuf);
+ }
+#endif
+ break;
+ }
+ case UI_ICON_TEXT:
+ case UI_ICON_TEXT_FREE: {
+ UiIcon *icon = data;
+#if GTK_MAJOR_VERSION >= 4
+ if(icon) {
+ GValue iconvalue = G_VALUE_INIT;
+ g_value_init(&iconvalue, G_TYPE_OBJECT);
+ g_value_set_object(&iconvalue, ui_icon_pixbuf(icon));
+ gtk_list_store_set_value(store, &iter, c, &iconvalue);
+ }
+#else
+ GValue pixbufvalue = G_VALUE_INIT;
+ if(icon) {
+ if(!icon->pixbuf && icon->info) {
+ GError *error = NULL;
+ GdkPixbuf *pixbuf = gtk_icon_info_load_icon(icon->info, &error);
+ icon->pixbuf = pixbuf;
+ }
+ g_value_init(&pixbufvalue, G_TYPE_OBJECT);
+ g_value_set_object(&pixbufvalue, icon->pixbuf);
+ gtk_list_store_set_value(store, iter, c, &pixbufvalue);
+ }
+#endif
+ c++;
+
+ char *str = model->getvalue(elm, c);
+ g_value_init(&value, G_TYPE_STRING);
+ g_value_set_string(&value, str);
+ if(model->types[i] == UI_ICON_TEXT_FREE) {
+ free(str);
+ }
+ break;
+ }
+ }
+
+ gtk_list_store_set_value(store, iter, c, &value);
+ }
+}
+
static GtkListStore* create_list_store(UiList *list, UiModel *model) {
int columns = model->columns;
GType types[2*columns];
GtkTreeIter iter;
gtk_list_store_insert (store, &iter, -1);
- // set column values
- int c = 0;
- for(int i=0;i<columns;i++,c++) {
- void *data = model->getvalue(elm, c);
-
- GValue value = G_VALUE_INIT;
- switch(model->types[i]) {
- case UI_STRING:
- case UI_STRING_FREE: {
- g_value_init(&value, G_TYPE_STRING);
- g_value_set_string(&value, data);
- if(model->types[i] == UI_STRING_FREE) {
- free(data);
- }
- break;
- }
- case UI_INTEGER: {
- g_value_init(&value, G_TYPE_INT);
- intptr_t intptr = (intptr_t)data;
- g_value_set_int(&value, (int)intptr);
- break;
- }
- case UI_ICON: {
- g_value_init(&value, G_TYPE_OBJECT);
- UiIcon *icon = data;
-#if GTK_MAJOR_VERSION >= 4
- g_value_set_object(&value, icon->info); // TODO: does this work?
-#else
- if(!icon->pixbuf && icon->info) {
- GError *error = NULL;
- GdkPixbuf *pixbuf = gtk_icon_info_load_icon(icon->info, &error);
- icon->pixbuf = pixbuf;
- }
-
- if(icon->pixbuf) {
- g_value_set_object(&value, icon->pixbuf);
- }
-#endif
- break;
- }
- case UI_ICON_TEXT:
- case UI_ICON_TEXT_FREE: {
- UiIcon *icon = data;
-#if GTK_MAJOR_VERSION >= 4
- if(icon) {
- GValue iconvalue = G_VALUE_INIT;
- g_value_init(&iconvalue, G_TYPE_OBJECT);
- g_value_set_object(&iconvalue, ui_icon_pixbuf(icon));
- gtk_list_store_set_value(store, &iter, c, &iconvalue);
- }
-#else
- GValue pixbufvalue = G_VALUE_INIT;
- if(icon) {
- if(!icon->pixbuf && icon->info) {
- GError *error = NULL;
- GdkPixbuf *pixbuf = gtk_icon_info_load_icon(icon->info, &error);
- icon->pixbuf = pixbuf;
- }
- g_value_init(&pixbufvalue, G_TYPE_OBJECT);
- g_value_set_object(&pixbufvalue, icon->pixbuf);
- gtk_list_store_set_value(store, &iter, c, &pixbufvalue);
- }
-#endif
- c++;
-
- char *str = model->getvalue(elm, c);
- g_value_init(&value, G_TYPE_STRING);
- g_value_set_string(&value, str);
- if(model->types[i] == UI_ICON_TEXT_FREE) {
- free(str);
- }
- break;
- }
- }
-
- gtk_list_store_set_value(store, &iter, c, &value);
- }
+ update_list_row(store, &iter, model, elm);
// next row
elm = list->next(list);
void ui_listview_update(UiList *list, int i) {
UiListView *view = list->obj;
- GtkListStore *store = create_list_store(list, view->model);
- gtk_tree_view_set_model(GTK_TREE_VIEW(view->widget), GTK_TREE_MODEL(store));
- g_object_unref(G_OBJECT(store));
+ if(i < 0) {
+ GtkListStore *store = create_list_store(list, view->model);
+ gtk_tree_view_set_model(GTK_TREE_VIEW(view->widget), GTK_TREE_MODEL(store));
+ g_object_unref(G_OBJECT(store));
+ } else {
+ void *elm = list->get(list, i);
+ GtkTreeModel *store = gtk_tree_view_get_model(GTK_TREE_VIEW(view->widget));
+ GtkTreeIter iter;
+ if(gtk_tree_model_iter_nth_child(store, &iter, NULL, i)) {
+ update_list_row(GTK_LIST_STORE(store), &iter, view->model, elm);
+ }
+ }
}
UiListSelection ui_listview_getselection(UiList *list) {