From: Olaf Wintermann Date: Sun, 6 Apr 2025 06:48:36 +0000 (+0200) Subject: fix image attachments not shown in gtk3 X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=c9579abfec6e327284855c68c2dc7be9127fd7f4;p=note.git fix image attachments not shown in gtk3 --- diff --git a/application/attachment.c b/application/attachment.c index dbd17ef..a64c6fc 100644 --- a/application/attachment.c +++ b/application/attachment.c @@ -84,7 +84,7 @@ void attachment_set_image(Attachment *attachment, void *img) { */ void attachment_item(UiObject *obj, int index, void *elm, void *userdata) { Attachment *attachment = elm; - + if(attachment->type == NOTE_ATTACHMENT_IMAGE) { UIWIDGET imgviewer = ui_imageviewer(obj, .value = attachment->ui->img, diff --git a/application/gtk-text.c b/application/gtk-text.c index ab238bf..0711800 100644 --- a/application/gtk-text.c +++ b/application/gtk-text.c @@ -316,6 +316,9 @@ static void editor_attach_image(NoteEditor *editor, GdkPixbuf *pixbuf, char *att GtkTextChildAnchor *anchor = gtk_text_buffer_create_child_anchor(buffer, &iter); GtkWidget *image = embedded_image_create(pixbuf); gtk_text_view_add_child_at_anchor(textview, image, anchor); +#if GTK_MAJOR_VERSION < 4 + gtk_widget_show_all(image); +#endif // remember widget and store a reference in the textbuffer // TODO: we need a cleanup strategy diff --git a/application/notebook.c b/application/notebook.c index 295aed6..2342415 100644 --- a/application/notebook.c +++ b/application/notebook.c @@ -142,6 +142,8 @@ void notebookmodel_attach_note(NotebookModel *model, Resource *note) { ui_set_group(model->window->obj->ctx, APP_STATE_NOTE_SELECTED); model->current_note = note; + ui_list_update(note->model->attachments); + if(!note->content_loaded) { note_load_content(model->window->obj, model, note); } diff --git a/application/window.c b/application/window.c index da70f24..bfc9b8d 100644 --- a/application/window.c +++ b/application/window.c @@ -89,12 +89,13 @@ void window_create() { ui_button(obj, .icon = "insert-link"); } ui_hbox_w(obj, wdata->attachments, .margin = 10, .fill = UI_OFF) { - void *sw; - ui_scrolledwindow_w(obj, sw, .name = "note_attachments_sw") { + //UIWIDGET sw; + //ui_scrolledwindow_w(obj, sw, .name = "note_attachments_sw") { ui_itemlist(obj, .varname = "note_attachments", .container = UI_CONTAINER_HBOX, .create_ui = attachment_item, .userdata = wdata); - } - ui_widget_set_size(sw, -1, 120); + //} + //ui_widget_set_size(sw, -1, 120); } + ui_widget_set_size(wdata->attachments, -1, 120); //ui_set_visible(wdata->attachments, FALSE); //ui_widget_set_groups(obj->ctx, wdata->attachments, (ui_enablefunc)ui_set_visible, APP_STATE_NOTE_HAS_ATTACHMENTS, -1); wdata->textview = ui_textarea(obj, .varname = "note_text", .vfill = TRUE, .hfill = TRUE, .hexpand = TRUE, .vexpand = TRUE, .colspan = 2, .groups = UI_GROUPS(APP_STATE_NOTE_SELECTED), .fill = UI_ON); diff --git a/ui/gtk/container.c b/ui/gtk/container.c index 1508bc0..054a7ce 100644 --- a/ui/gtk/container.c +++ b/ui/gtk/container.c @@ -1116,7 +1116,7 @@ static void remove_item(void *data, void *item) { static void update_itemlist(UiList *list, int c) { UiGtkItemListContainer *ct = list->obj; - + CxMap *new_items = cxHashMapCreateSimple(CX_STORE_POINTERS); new_items->collection.advanced_destructor = remove_item; new_items->collection.destructor_data = ct; @@ -1146,7 +1146,7 @@ static void update_itemlist(UiList *list, int c) { // add all items int index = 0; elm = list->first(list); - while(elm) { + while(elm) { CxHashKey key = cx_hash_key(&elm, sizeof(void*)); UiObject *item_obj = cxMapGet(ct->current_items, key); if(item_obj) { @@ -1175,6 +1175,10 @@ static void update_itemlist(UiList *list, int c) { elm = list->next(list); index++; } + +#if GTK_MAJOR_VERSION < 4 + gtk_widget_show_all(ct->widget); +#endif } static void destroy_itemlist_container(GtkWidget *w, UiGtkItemListContainer *container) { @@ -1221,7 +1225,7 @@ UIWIDGET ui_itemlist_create(UiObject *obj, UiItemListContainerArgs args) { "destroy", G_CALLBACK(destroy_itemlist_container), container); - + return box; }