]> uap-core.de Git - note.git/commitdiff
hide attachment bar when there are no attachments
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Mon, 21 Apr 2025 15:28:41 +0000 (17:28 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Mon, 21 Apr 2025 15:28:41 +0000 (17:28 +0200)
application/gtk-image.c
application/gtk-text.c
application/note.c
application/notebook.c
application/window.c

index 983bea2ec9d0d0938d12baf06f886fd793991c72..3b0959974f9b9ad1d82dc18657c19f02cc66196b 100644 (file)
@@ -38,7 +38,6 @@ static void embedded_image_adjust_size(EmbeddedWidget *em, int max_width) {
     double width = gdk_texture_get_width(texture);
     double height = gdk_texture_get_height(texture);
     
-    printf("max width: %d\n", max_width);
     if(width > max_width) {
         height = height * (max_width / width);
         width = max_width;
index 41b7fb126176de8ba68deeaf7f535073fde5485d..8a648484b25aa6f1cf52909bb460b8a1b0628347 100644 (file)
@@ -389,6 +389,9 @@ static void editor_attach_image(NoteEditor *editor, GdkPixbuf *pixbuf, char *att
     note_add_attachment(note, attachment);
     ui_list_append(model->attachments, attachment);
     ui_list_update(model->attachments);
+    
+    // TODO: can we move this to note_add_attachment or somewhere else?
+    ui_set_group(wdata->obj->ctx, APP_STATE_NOTE_HAS_ATTACHMENTS);
 }
 
 static gboolean editor_dnd_add_file(NoteEditor *editor, GFile *file) {
index 91902345ca82d27fc82373f8a7244eec19c3b827..6bae7f07172ca29a4608b1034a6b056a767bf5e4 100644 (file)
@@ -123,6 +123,10 @@ static void note_loading_completed(UiObject *obj, LoadNoteContent *op) {
         }
         ui_list_update(note->model->attachments);
         
+        if(ui_list_count(note->model->attachments) > 0) {
+            ui_set_group(obj->ctx, APP_STATE_NOTE_HAS_ATTACHMENTS);
+        }
+        
         editor_load_markdown(note, wdata->textview, note->content);
     }
     note->content_loaded = TRUE;
index e2487cd283b25cdc26c211b43233b9eb9b8b8932..a3f47e9992d9ce09d437b259285b2afaeb503f81 100644 (file)
@@ -144,6 +144,13 @@ void notebookmodel_attach_note(NotebookModel *model, Resource *note) {
     
     ui_list_update(note->model->attachments);
     
+    // TODO: replace when getting groups from sub-ctx works
+    if(ui_list_count(note->model->attachments) == 0) {
+        ui_unset_group(model->window->obj->ctx, APP_STATE_NOTE_HAS_ATTACHMENTS);
+    } else {
+        ui_set_group(model->window->obj->ctx, APP_STATE_NOTE_HAS_ATTACHMENTS);
+    }
+    
     if(!note->content_loaded) {
         note_load_content(model->window->obj, model, note);
     }
@@ -166,6 +173,7 @@ void notebookmodel_detach_current_note(NotebookModel *model) {
         }
         model->current_note = NULL;
     }
+    ui_unset_group(model->window->obj->ctx, APP_STATE_NOTE_HAS_ATTACHMENTS);
 }
 
 /*
index 3fa1bd3c50bf3a3c72422e738850bfd886e5476c..757e412bb89304cebb1a92eaee995b592d8363c5 100644 (file)
@@ -95,12 +95,13 @@ void window_create() {
                         //}
                         //ui_widget_set_size(sw, -1, 120);
                     }
+                    
                     ui_widget_set_size(wdata->attachments, -1, 120);
 #if GTK_MAJOR_VERSION >= 4
                     ui_customwidget(obj, editor_gtk4_workaround, wdata, .hfill = TRUE);
 #endif
-                    //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);
+                    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));
                 }