typedef struct MainWindow {
UiObject *obj;
+ UIWIDGET splitpane;
+ UIWIDGET document_tabview;
+
UiList *notebooks;
NotebookModel *current_notebook;
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);
}
}
}
- 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") {
}
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) {
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);
+ }
}
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
#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);
UiObject* current = uic_current_obj(obj);
GtkWidget *pane0 = create_paned(orientation);
-
+
UI_APPLY_LAYOUT1(current, args);
current->container->add(current->container, pane0, TRUE);
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;
}
ct->current_pane = pane;
ct->orientation = orientation;
ct->max = max;
+ ct->children = cxArrayListCreateSimple(CX_STORE_POINTERS, 4);
return (UiContainer*)ct;
}
return;
}
+ cxListAdd(s->children, widget);
+
if(s->pos == 0) {
gtk_paned_set_start_child(GTK_PANED(s->current_pane), widget);
s->pos++;
}
}
+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) {
#include <cx/allocator.h>
#include <cx/hash_map.h>
+#include <cx/list.h>
#ifdef __cplusplus
extern "C" {
int rowspacing;
} UiGtkTabView;
-
typedef struct UiSplitPaneContainer {
UiContainer container;
GtkWidget *current_pane;
+ CxList *children;
UiOrientation orientation;
int pos;
int max;
#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))
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