From: Olaf Wintermann Date: Mon, 24 Mar 2025 20:02:45 +0000 (+0100) Subject: add first bits of attachment ui X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=091818cb808de4b2b5371057a2e83d261647c146;p=note.git add first bits of attachment ui --- diff --git a/application/application.h b/application/application.h index 6269728..43d4e1f 100644 --- a/application/application.h +++ b/application/application.h @@ -38,11 +38,12 @@ extern "C" { #endif -#define APP_STATE_NOTEBOOK_SELECTED 100 -#define APP_STATE_NOTE_SELECTED 110 +#define APP_STATE_NOTEBOOK_SELECTED 100 +#define APP_STATE_NOTE_SELECTED 110 +#define APP_STATE_NOTE_HAS_ATTACHMENTS 201 -#define VIEW_FLAGS_NO_BROWSER 1 +#define VIEW_FLAGS_NO_BROWSER 1 // typedefs for NotebookModel and NoteModel are in types.h @@ -61,6 +62,7 @@ typedef struct MainWindow { UIWIDGET splitpane; UIWIDGET document_tabview; UIWIDGET textview; + UIWIDGET attachments; /* * is the note list visible (splitpane child 0) @@ -139,7 +141,13 @@ struct NoteModel { UiGeneric *html; /* - * text note paragraph types + * List elements: AttachmentObj* + */ + UiList *attachments; + + /* + * Text note paragraph types + * List elements: char* */ UiList *textnote_para; @@ -151,6 +159,9 @@ struct NoteModel { bool modified; }; +typedef struct AttachmentObj { + int a; +} AttachmentObj; void application_init(); diff --git a/application/gtk-text.c b/application/gtk-text.c index fba2344..2f6a935 100644 --- a/application/gtk-text.c +++ b/application/gtk-text.c @@ -302,6 +302,15 @@ static void editor_attach_image(NoteEditor *editor, GdkPixbuf *pixbuf, char *att BufferEmbeddedObjects *embedded_objects = g_object_get_data(G_OBJECT(buffer), "embedded"); cxListAdd(embedded_objects->objects, em); + + // add attachment to note + MainWindow *wdata = editor->obj->window; + Note *note = wdata->current_notebook->current_note; + NoteModel *model = note->model; + + // TODO: this is just a test + ui_list_append(model->attachments, em); + ui_list_update(model->attachments); } #if GTK_CHECK_VERSION(4, 0, 0) diff --git a/application/note.c b/application/note.c index b965fb3..ae02248 100644 --- a/application/note.c +++ b/application/note.c @@ -64,6 +64,8 @@ NoteModel* notemodel_create(const CxAllocator *note_allocator) { model->text = ui_text_new(model->ctx, "note_text"); model->html = ui_generic_new(model->ctx, "note_html"); + model->attachments = ui_list_new(model->ctx, "note_attachments"); + ui_set(model->type, 1); //ui_set_group(model->ctx, APP_STATE_NOTE_SELECTED); diff --git a/application/window.c b/application/window.c index 144b1c9..0f94585 100644 --- a/application/window.c +++ b/application/window.c @@ -87,6 +87,13 @@ void window_create() { ui_button(obj, .icon = "insert-image"); ui_button(obj, .icon = "insert-link"); } + ui_hbox_w(obj, wdata->attachments, .margin = 10, .fill = UI_OFF) { + ui_scrolledwindow(obj, .name = "note_attachments_sw") { + ui_itemlist(obj, .varname = "note_attachments", .container = UI_CONTAINER_HBOX, .create_ui = attachment_item, .userdata = wdata); + } + } + //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); editor_init_textview(obj, ui_textarea_gettextwidget(wdata->textview)); } @@ -97,6 +104,10 @@ void window_create() { ui_show(obj); } +void attachment_item(UiObject *obj, int index, void *elm, void *userdata) { + ui_button(obj, .label = "Attachment Dummy"); +} + MainWindow* window_init_data(UiObject *obj) { MainWindow *wdata = ui_calloc(obj->ctx, 1, sizeof(MainWindow)); obj->window = wdata; diff --git a/application/window.h b/application/window.h index 5823316..7959b5b 100644 --- a/application/window.h +++ b/application/window.h @@ -52,6 +52,8 @@ void update_sublists(UiContext *ctx, UiList *sublists); void* window_notelist_getvalue(void *data, int col); +void attachment_item(UiObject *obj, int index, void *elm, void *userdata); + void action_notebook_selected(UiEvent *event, void *userdata); void action_note_selected(UiEvent *event, void *userdata); void action_note_activated(UiEvent *event, void *userdata); diff --git a/ui/common/context.c b/ui/common/context.c index 5857194..626f149 100644 --- a/ui/common/context.c +++ b/ui/common/context.c @@ -292,6 +292,8 @@ void uic_copy_binding(UiVar *from, UiVar *to, UiBool copytodoc) { to->from_ctx = from->from_ctx; } + ui_setop_enable(TRUE); + // copy binding // we don't copy the observer, because the from var has never one switch(from->type) { @@ -373,6 +375,8 @@ void uic_copy_binding(UiVar *from, UiVar *to, UiBool copytodoc) { break; } } + + ui_setop_enable(FALSE); } void uic_save_var2(UiVar *var) { diff --git a/ui/gtk/text.c b/ui/gtk/text.c index 3e863e5..475543c 100644 --- a/ui/gtk/text.c +++ b/ui/gtk/text.c @@ -74,12 +74,6 @@ static void textarea_set_undomgr(GtkWidget *text_area, UiText *value) { value->data2 = ui_create_undomgr(); } - g_signal_connect( - buf, - "changed", - G_CALLBACK(ui_textbuf_changed), - uitext); - // register undo manager g_signal_connect( buf, @@ -99,6 +93,20 @@ static void textarea_set_undomgr(GtkWidget *text_area, UiText *value) { } #endif +static GtkTextBuffer* create_textbuffer(UiTextArea *textarea) { + GtkTextBuffer *buf = gtk_text_buffer_new(NULL); + if(textarea) { + g_signal_connect( + buf, + "changed", + G_CALLBACK(ui_textbuf_changed), + textarea); + } else { + fprintf(stderr, "Error: create_textbuffer: textarea == NULL\n"); + } + return buf; +} + UIWIDGET ui_textarea_create(UiObject *obj, UiTextAreaArgs args) { UiObject* current = uic_current_obj(obj); UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.value, args.varname, UI_VAR_TEXT); @@ -122,6 +130,8 @@ UIWIDGET ui_textarea_create(UiObject *obj, UiTextAreaArgs args) { uitext->onchange = args.onchange; uitext->onchangedata = args.onchangedata; + g_object_set_data(G_OBJECT(text_area), "ui_textarea", uitext); + g_signal_connect( text_area, "destroy", @@ -155,7 +165,7 @@ UIWIDGET ui_textarea_create(UiObject *obj, UiTextAreaArgs args) { if(value->data1 && value->datatype == UI_TEXT_TYPE_BUFFER) { buf = value->data1; } else { - buf = gtk_text_buffer_new(NULL); + buf = create_textbuffer(uitext); if(value->value.ptr) { gtk_text_buffer_set_text(buf, value->value.ptr, -1); value->value.free(value->value.ptr); @@ -207,7 +217,7 @@ void ui_textarea_save(UiText *text) { void ui_textarea_restore(UiText *text) { GtkWidget *textarea = text->obj; if(!text->data1) { - text->data1 = gtk_text_buffer_new(NULL); + text->data1 = create_textbuffer(g_object_get_data(G_OBJECT(textarea), "ui_textarea")); text->datatype = UI_TEXT_TYPE_BUFFER; } gtk_text_view_set_buffer(GTK_TEXT_VIEW(textarea), text->data1); @@ -321,6 +331,7 @@ void ui_textbuf_changed(GtkTextBuffer *textbuffer, UiTextArea *textarea) { e.document = textarea->ctx->document; e.eventdata = value; e.intval = 0; + e.set = ui_get_setop(); if(textarea->onchange) { textarea->onchange(&e, textarea->onchangedata); @@ -681,6 +692,7 @@ void ui_textfield_changed(GtkEditable *editable, UiTextField *textfield) { e.document = textfield->obj->ctx->document; e.eventdata = value; e.intval = 0; + e.set = ui_get_setop(); if(textfield->onchange) { textfield->onchange(&e, textfield->onchangedata); @@ -699,6 +711,7 @@ void ui_textfield_activate(GtkEntry* self, UiTextField *textfield) { e.document = textfield->obj->ctx->document; e.eventdata = NULL; e.intval = 0; + e.set = ui_get_setop(); textfield->onactivate(&e, textfield->onactivatedata); } } @@ -795,6 +808,7 @@ void ui_path_button_clicked(GtkWidget *widget, UiEventDataExt *event) { evt.document = evt.obj->ctx->document; evt.eventdata = elm->path; evt.intval = event->value0; + evt.set = ui_get_setop(); event->callback(&evt, event->userdata); free(path.ptr); } diff --git a/ui/gtk/toolkit.c b/ui/gtk/toolkit.c index 2f28c2b..7e8e3a5 100644 --- a/ui/gtk/toolkit.c +++ b/ui/gtk/toolkit.c @@ -248,8 +248,9 @@ void ui_set_show_all(UIWIDGET widget, int value) { } void ui_set_visible(UIWIDGET widget, int visible) { - // TODO: gtk4 -#if GTK_MAJOR_VERSION <= 3 +#if GTK_MAJOR_VERSION >= 4 + gtk_widget_set_visible(widget, visible); +#else if(visible) { gtk_widget_set_no_show_all(widget, FALSE); gtk_widget_show_all(widget); diff --git a/ui/ui/container.h b/ui/ui/container.h index dbaa3ca..faa91e7 100644 --- a/ui/ui/container.h +++ b/ui/ui/container.h @@ -255,6 +255,9 @@ struct UiContainerX { #define ui_headerbar0(obj) for(ui_headerbar_create(obj, (UiHeaderbarArgs){ 0 });ui_container_finish(obj);ui_container_begin_close(obj)) #define ui_sidebar0(obj) for(ui_sidebar_create(obj, (UiSidebarArgs){ 0 });ui_container_finish(obj);ui_container_begin_close(obj)) +#define ui_vbox_w(obj, w, ...) for(w = ui_vbox_create(obj, (UiContainerArgs){ __VA_ARGS__ });ui_container_finish(obj);ui_container_begin_close(obj)) +#define ui_hbox_w(obj, w, ...) for(w = ui_hbox_create(obj, (UiContainerArgs){ __VA_ARGS__ });ui_container_finish(obj);ui_container_begin_close(obj)) +#define ui_grid_w(obj, w, ...) for(w = ui_grid_create(obj, (UiContainerArgs){ __VA_ARGS__ });ui_container_finish(obj);ui_container_begin_close(obj)) #define ui_tabview_w(obj, w, ...) for(w = ui_tabview_create(obj, (UiTabViewArgs){ __VA_ARGS__ });ui_container_finish(obj);ui_container_begin_close(obj)) #define ui_hsplitpane(obj, ...) for(ui_hsplitpane_create(obj, (UiSplitPaneArgs){ __VA_ARGS__ });ui_container_finish(obj);ui_container_begin_close(obj))