application/menu.c

changeset 3
c04433993fbb
parent 2
ea89bbb0c4c8
child 4
d8e8f34e65ee
--- a/application/menu.c	Thu Dec 10 13:43:25 2020 +0100
+++ b/application/menu.c	Fri Dec 11 11:46:19 2020 +0100
@@ -27,6 +27,7 @@
  */
 
 #include "menu.h"
+#include "window.h"
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -34,8 +35,8 @@
 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
 
 static UiInteger *tb_sidebar;
-static UiInteger *tb_browser;
-static UiInteger *tb_editor;
+static UiInteger *tb_singleview;
+static UiInteger *tb_dualview;
 
 static void create_main_menu(void) {
     ui_menu("File");
@@ -50,19 +51,25 @@
 static void create_main_toolbar(void) {
     UiContext *ctx = ui_global_context();
     tb_sidebar = ui_int_new(ctx, NULL);
-    tb_browser = ui_int_new(ctx, NULL);
-    tb_editor = ui_int_new(ctx, NULL);
+    tb_singleview = ui_int_new(ctx, NULL);
+    tb_dualview = ui_int_new(ctx, NULL);
+    tb_sidebar->observers = ui_add_observer(tb_sidebar->observers, action_show_sidebar, NULL);
+    tb_singleview->observers = ui_add_observer(tb_singleview->observers, action_singleview, NULL);
+    tb_dualview->observers = ui_add_observer(tb_dualview->observers, action_dualview, NULL);
     
     ui_toolitem_toggle("show-sidebar", "Sidebar", NULL, tb_sidebar);
-    ui_toolitem_toggle("show-browser", "Browser", NULL, tb_browser);
-    ui_toolitem_toggle("show-editor", "Editor", NULL, tb_editor);
+    ui_toolitem_toggle("singleview", "S", NULL, tb_singleview);
+    ui_toolitem_toggle("dualview", "D", NULL, tb_dualview);
+    
     tb_sidebar->value = 1;
-    tb_browser->value = 1;
-    tb_editor->value = 1;
+    tb_singleview->value = 0;
+    tb_dualview->value = 1;
     
     ui_toolbar_add_default("show-sidebar");
-    ui_toolbar_add_default("show-browser");
-    ui_toolbar_add_default("show-editor");
+    ui_toolbar_add_default("@separator");
+    ui_toolbar_add_default("singleview");
+    ui_toolbar_add_default("dualview");
+    ui_toolbar_add_default("@separator");
 }
 
 void menu_init(void) {
@@ -71,13 +78,47 @@
 }
 
 void action_show_sidebar(UiEvent *event, void *udata) {
+    WindowData *w = event->window;
+    ui_set_visible(w->sidebar, event->intval);
+}
+
+static void change_view(WindowData *w, int dual) {
+    if(dual) {
+        ui_set_visible(w->browser, TRUE);
+        ui_set_visible(w->editor, TRUE);
+    } else {
+        UiBool e, b;
+        if(w->editorIsOpen) {
+            e = TRUE;
+            b = FALSE;
+        } else {
+            e = FALSE;
+            b = TRUE;
+        }
+        ui_set_visible(w->browser, b);
+        ui_set_visible(w->editor, e);
+    }
+}
+
+void action_dualview(UiEvent *event, void *udata) {
+    int s = event->intval == 1 ? 0 : 1;
+    tb_singleview->set(tb_singleview, s);
+    change_view(event->window, event->intval);
+}
+
+void action_singleview(UiEvent *event, void *udata) {
+    int s = event->intval == 1 ? 0 : 1;
+    tb_dualview->set(tb_dualview, s);
+    change_view(event->window, s);
+}
+
+
+
+
+void action_test1(UiEvent *event, void *udata) {
     
 }
 
-void action_show_browser(UiEvent *event, void *udata) {
+void action_test2(UiEvent *event, void *udata) {
     
 }
-
-void action_show_editor(UiEvent *event, void *udata) {
-    
-}

mercurial