]> uap-core.de Git - note.git/commitdiff
add first bits of attachment ui
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Mon, 24 Mar 2025 20:02:45 +0000 (21:02 +0100)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Mon, 24 Mar 2025 20:02:45 +0000 (21:02 +0100)
application/application.h
application/gtk-text.c
application/note.c
application/window.c
application/window.h
ui/common/context.c
ui/gtk/text.c
ui/gtk/toolkit.c
ui/ui/container.h

index 6269728afa1cfde7811e99c4fe4b66e26066d24f..43d4e1f75a8edef8804bcfe0b4e99f70df4773f8 100644 (file)
 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();
 
index fba23444945d97a3cb44bb1fd2b36c5f8415cff9..2f6a93500e78ac37403380f7a051acd9bb53add3 100644 (file)
@@ -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)
index b965fb3fb4de678b162dc2c2e9b6cedcd5c007c3..ae022485f63aaeb0e0fcbaa736a5cbdfaee395a2 100644 (file)
@@ -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);
     
index 144b1c91965e78aa4b29f2f6fa5a3aec7cce3c02..0f9458594ecaf2c7f5c2258315367a3305af0faf 100644 (file)
@@ -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;
index 58233166f8c181c1ad2701fa3ed18f02b9806662..7959b5b082c9f35bf75a2cbd30b34641ee7e95e8 100644 (file)
@@ -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);
index 585719440a876aff444f73c600815f475547bfb4..626f149f2e2a0b4cd0bf1d4b995498a2aea89ea6 100644 (file)
@@ -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) {
index 3e863e52e366dc241a0cf0a44d9ae057dfd72ea2..475543c765bb96281d903212e22dab81185cc04f 100644 (file)
@@ -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);
 }
index 2f28c2b256de482f8398042b53e9d955c86fd51e..7e8e3a5864999417dd8bfa3975fca814be62557d 100644 (file)
@@ -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);
index dbaa3cad562fe56e94e9880e7e5635cc2e5a616c..faa91e76873e8d5fd3d34c6a703ea98a04427c89 100644 (file)
@@ -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))