]> uap-core.de Git - note.git/commitdiff
switch notes on selection events and change activate event to maximize the note editor
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Fri, 28 Feb 2025 20:34:02 +0000 (21:34 +0100)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Fri, 28 Feb 2025 20:34:02 +0000 (21:34 +0100)
application/application.h
application/menu.c
application/window.c
application/window.h
ui/gtk/container.c
ui/gtk/container.h
ui/ui/container.h

index 8fbe46a3e3a8056a995a42347e30826c54ed4ec3..e91cb3f2fa00a2456c316516ec74f36cae359b9a 100644 (file)
@@ -46,6 +46,9 @@ extern "C" {
 typedef struct MainWindow {
     UiObject *obj;
     
+    UIWIDGET splitpane;
+    UIWIDGET document_tabview;
+    
     UiList *notebooks;
     
     NotebookModel *current_notebook;
index ee5dcba35170af234987ccea81fe4e219e313f3c..be0b5fae1fcfecdf4e376a1fe82436690f380dba 100644 (file)
@@ -35,6 +35,5 @@ void menu_init() {
 void toolbar_init() {
     ui_toolbar_item("AddNote", .icon = UI_ICON_ADD, .onclick = action_note_new, .groups = UI_GROUPS(APP_STATE_NOTEBOOK_SELECTED));
     
-    
     ui_toolbar_add_default("AddNote", UI_TOOLBAR_LEFT);
 }
index 84e3230879ecf7abbebbb2bcdeea8455255681c0..a50aa734908a2235c3450df9ffe5e12c2fb9a399 100644 (file)
@@ -52,15 +52,15 @@ void window_create() {
         }
     }
     
-    ui_hsplitpane(obj, .initial_position = 200) {
+    ui_hsplitpane_w(obj, wdata->splitpane, .initial_position = 200) {
         // splitpane left: table
         UiModel* model = ui_model(obj->ctx, UI_STRING, "Name", UI_STRING_FREE, "Last Modified", -1);
         model->columnsize[0] = -1;
         model->getvalue = window_notelist_getvalue;
-        ui_table(obj, .model = model, .varname = "notes", .onactivate = action_note_selected);
+        ui_table(obj, .model = model, .varname = "notes", .multiselection = TRUE, .onselection = action_note_selected, .onactivate = action_note_activated);
         
         // splitpane right: content
-        ui_tabview(obj, .tabview = UI_TABVIEW_INVISIBLE, .varname = "note_type") {
+        ui_tabview_w(obj, wdata->document_tabview, .tabview = UI_TABVIEW_INVISIBLE, .varname = "note_type") {
             ui_tab(obj, "empty") {
                 
             }
@@ -186,6 +186,9 @@ void action_notebook_selected(UiEvent *event, void *userdata) {
         return; // notebook already selected
     }
     
+    // reset splitpane visibility
+    ui_splitpane_set_visible(window->splitpane, 0, TRUE);
+    
     CxHashKey key = cx_hash_key(&collection->collection_id, sizeof(collection->collection_id));
     NotebookModel *notebook = cxMapGet(window->notebook_cache, key);
     if(!notebook) {
@@ -200,19 +203,33 @@ void action_notebook_selected(UiEvent *event, void *userdata) {
     notebookmodel_attach(window, notebook);
 }
 
-void action_note_selected(UiEvent *event, void *userdata) {
+static int select_note(UiEvent *event) {
     UiListSelection *sel = event->eventdata;
     MainWindow *window = event->window;
     NotebookModel *notebook = window->current_notebook;
     
     if(!notebook) {
-        return; // should not happen
+        return 0; // should not happen
     }
     
-    if(sel->count == 0) {
-        return; // should not happen
+    if(sel->count != 1) {
+        notebookmodel_detach_current_note(notebook);
+        return 0;
     }
     
     Note *note = ui_list_get(notebook->notes, sel->rows[0]);
     notebookmodel_attach_note(notebook, note);
+    
+    return 1;
+}
+
+void action_note_selected(UiEvent *event, void *userdata) {
+    select_note(event);
+}
+
+void action_note_activated(UiEvent *event, void *userdata) {
+    MainWindow *window = event->window;
+    if(select_note(event)) {
+        ui_splitpane_set_visible(window->splitpane, 0, FALSE);
+    }
 }
index bf9b2155e0fe5fb6d13ee7a78510f86ee5b56055..8644f54a8387f7726b0e5608d845ac467cb00d19 100644 (file)
@@ -48,6 +48,7 @@ void* window_notelist_getvalue(void *data, int col);
 
 void action_notebook_selected(UiEvent *event, void *userdata);
 void action_note_selected(UiEvent *event, void *userdata);
+void action_note_activated(UiEvent *event, void *userdata);
 
 
 #ifdef __cplusplus
index 8a1697732bf9b7b06432c87c9172915ea9edbc72..aeee6f7a73386dfae3d3ef65262a3e17fdaa7ec6 100644 (file)
@@ -37,6 +37,8 @@
 #include "../common/context.h"
 #include "../common/object.h"
 
+#include <cx/array_list.h>
+
 
 void ui_container_begin_close(UiObject *obj) {
     UiContainer *ct = uic_get_current_container(obj);
@@ -1034,7 +1036,7 @@ static UIWIDGET splitpane_create(UiObject *obj, UiOrientation orientation, UiSpl
     UiObject* current = uic_current_obj(obj);
     
     GtkWidget *pane0 = create_paned(orientation);
-    
+      
     UI_APPLY_LAYOUT1(current, args);
     current->container->add(current->container, pane0, TRUE);
     
@@ -1044,6 +1046,8 @@ static UIWIDGET splitpane_create(UiObject *obj, UiOrientation orientation, UiSpl
     newobj->container = ui_splitpane_container(obj, pane0, orientation, max);
     uic_obj_add(obj, newobj);
     
+    g_object_set_data(G_OBJECT(pane0), "ui_splitpane", newobj->container);
+    
     return pane0;
 }
 
@@ -1062,6 +1066,7 @@ UiContainer* ui_splitpane_container(UiObject *obj, GtkWidget *pane, UiOrientatio
     ct->current_pane = pane;
     ct->orientation = orientation;
     ct->max = max;
+    ct->children = cxArrayListCreateSimple(CX_STORE_POINTERS, 4);
     return (UiContainer*)ct;
 }
 
@@ -1073,6 +1078,8 @@ void ui_splitpane_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill)
         return;
     }
     
+    cxListAdd(s->children, widget);
+       
     if(s->pos == 0) {
         gtk_paned_set_start_child(GTK_PANED(s->current_pane), widget);
         s->pos++;
@@ -1092,6 +1099,19 @@ void ui_splitpane_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill)
     }
 }
 
+UIEXPORT void ui_splitpane_set_visible(UIWIDGET splitpane, int child_index, UiBool visible) {
+    UiSplitPaneContainer *ct = g_object_get_data(G_OBJECT(splitpane), "ui_splitpane");
+    if(!ct) {
+        fprintf(stderr, "UI Error: not a splitpane\n");
+        return;
+    }
+    
+    GtkWidget *w = cxListAt(ct->children, child_index);
+    if(w) {
+        gtk_widget_set_visible(w, visible);
+    }
+}
+
 /* -------------------- ItemList Container -------------------- */
 
 static void remove_item(void *data, void *item) {
index 421451da04f82aa233c1e08366734fe43547ea79..26c0bc14637ed5d6cdccd45a2121733771b77a77 100644 (file)
@@ -36,6 +36,7 @@
 
 #include <cx/allocator.h>
 #include <cx/hash_map.h>
+#include <cx/list.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -123,10 +124,10 @@ typedef struct UiGtkTabView {
     int rowspacing;
 } UiGtkTabView;
 
-
 typedef struct UiSplitPaneContainer {
     UiContainer container;
     GtkWidget *current_pane;
+    CxList *children;
     UiOrientation orientation;
     int pos;
     int max;
index c7d6523431d8e7ee23f86d1af5e918ded3b30047..5649c41e0edb5745a2753434124f0f2b81148976 100644 (file)
@@ -274,6 +274,9 @@ struct UiContainerX {
 #define ui_hsplitpane0(obj) for(ui_hsplitpane_create(obj, (UiSplitPaneArgs){ 0 });ui_container_finish(obj);ui_container_begin_close(obj))
 #define ui_vsplitpane0(obj) for(ui_vsplitpane_create(obj, (UiSplitPaneArgs){ 0 });ui_container_finish(obj);ui_container_begin_close(obj))
 
+#define ui_hsplitpane_w(obj, w, ...) for(w = ui_hsplitpane_create(obj, (UiSplitPaneArgs){ __VA_ARGS__ });ui_container_finish(obj);ui_container_begin_close(obj))
+#define ui_vsplitpane_w(obj, w, ...) for(w = ui_vsplitpane_create(obj, (UiSplitPaneArgs){ __VA_ARGS__ });ui_container_finish(obj);ui_container_begin_close(obj))
+
 #define ui_tab(obj, label) for(ui_tab_create(obj, label);ui_container_finish(obj);ui_container_begin_close(obj))
 
 #define ui_headerbar_start(obj) for(ui_headerbar_start_create(obj);ui_container_finish(obj);ui_container_begin_close(obj))
@@ -311,6 +314,9 @@ UIEXPORT UIWIDGET ui_hsplitpane_create(UiObject *obj, UiSplitPaneArgs args);
 UIEXPORT UIWIDGET ui_vsplitpane_create(UiObject *obj, UiSplitPaneArgs args);
 
 
+UIEXPORT void ui_splitpane_set_visible(UIWIDGET splitpane, int child_index, UiBool visible);
+
+
 // box container layout functions
 UIEXPORT void ui_layout_fill(UiObject *obj, UiBool fill);
 // grid container layout functions