From: Olaf Wintermann Date: Fri, 28 Feb 2025 20:34:02 +0000 (+0100) Subject: switch notes on selection events and change activate event to maximize the note editor X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=b86c56c156fd23228e8b464ddb947ed1edbc9154;p=note.git switch notes on selection events and change activate event to maximize the note editor --- diff --git a/application/application.h b/application/application.h index 8fbe46a..e91cb3f 100644 --- a/application/application.h +++ b/application/application.h @@ -46,6 +46,9 @@ extern "C" { typedef struct MainWindow { UiObject *obj; + UIWIDGET splitpane; + UIWIDGET document_tabview; + UiList *notebooks; NotebookModel *current_notebook; diff --git a/application/menu.c b/application/menu.c index ee5dcba..be0b5fa 100644 --- a/application/menu.c +++ b/application/menu.c @@ -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); } diff --git a/application/window.c b/application/window.c index 84e3230..a50aa73 100644 --- a/application/window.c +++ b/application/window.c @@ -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); + } } diff --git a/application/window.h b/application/window.h index bf9b215..8644f54 100644 --- a/application/window.h +++ b/application/window.h @@ -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 diff --git a/ui/gtk/container.c b/ui/gtk/container.c index 8a16977..aeee6f7 100644 --- a/ui/gtk/container.c +++ b/ui/gtk/container.c @@ -37,6 +37,8 @@ #include "../common/context.h" #include "../common/object.h" +#include + 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) { diff --git a/ui/gtk/container.h b/ui/gtk/container.h index 421451d..26c0bc1 100644 --- a/ui/gtk/container.h +++ b/ui/gtk/container.h @@ -36,6 +36,7 @@ #include #include +#include #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; diff --git a/ui/ui/container.h b/ui/ui/container.h index c7d6523..5649c41 100644 --- a/ui/ui/container.h +++ b/ui/ui/container.h @@ -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