application/menu.c

Fri, 11 Dec 2020 18:32:54 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Fri, 11 Dec 2020 18:32:54 +0100
changeset 4
d8e8f34e65ee
parent 3
c04433993fbb
permissions
-rw-r--r--

add sqlite dependency

2
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2020 Olaf Wintermann. All rights reserved.
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include "menu.h"
3
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
30 #include "window.h"
2
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32 #include <stdio.h>
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 #include <stdlib.h>
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37 static UiInteger *tb_sidebar;
3
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
38 static UiInteger *tb_singleview;
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
39 static UiInteger *tb_dualview;
2
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 static void create_main_menu(void) {
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 ui_menu("File");
4
d8e8f34e65ee add sqlite dependency
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
43 ui_menuitem_st(UI_STOCK_NEW, NULL, NULL);
2
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 ui_menuitem_st(UI_STOCK_OPEN, NULL, NULL);
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 ui_menu("Edit");
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 ui_menuitem_st(UI_STOCK_UNDO, NULL, NULL);
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48 ui_menuitem_st(UI_STOCK_REDO, NULL, NULL);
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 }
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 static void create_main_toolbar(void) {
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 UiContext *ctx = ui_global_context();
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 tb_sidebar = ui_int_new(ctx, NULL);
3
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
55 tb_singleview = ui_int_new(ctx, NULL);
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
56 tb_dualview = ui_int_new(ctx, NULL);
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
57 tb_sidebar->observers = ui_add_observer(tb_sidebar->observers, action_show_sidebar, NULL);
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
58 tb_singleview->observers = ui_add_observer(tb_singleview->observers, action_singleview, NULL);
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
59 tb_dualview->observers = ui_add_observer(tb_dualview->observers, action_dualview, NULL);
2
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 ui_toolitem_toggle("show-sidebar", "Sidebar", NULL, tb_sidebar);
3
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
62 ui_toolitem_toggle("singleview", "S", NULL, tb_singleview);
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
63 ui_toolitem_toggle("dualview", "D", NULL, tb_dualview);
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
64
4
d8e8f34e65ee add sqlite dependency
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
65 ui_toolitem_st("new-note", UI_STOCK_NEW, NULL, NULL);
d8e8f34e65ee add sqlite dependency
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
66
2
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 tb_sidebar->value = 1;
3
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
68 tb_singleview->value = 0;
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
69 tb_dualview->value = 1;
2
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71 ui_toolbar_add_default("show-sidebar");
3
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
72 ui_toolbar_add_default("@separator");
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
73 ui_toolbar_add_default("singleview");
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
74 ui_toolbar_add_default("dualview");
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
75 ui_toolbar_add_default("@separator");
4
d8e8f34e65ee add sqlite dependency
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
76 ui_toolbar_add_default("new-note");
2
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 }
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 void menu_init(void) {
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80 create_main_menu();
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 create_main_toolbar();
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82 }
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84 void action_show_sidebar(UiEvent *event, void *udata) {
3
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
85 WindowData *w = event->window;
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
86 ui_set_visible(w->sidebar, event->intval);
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
87 }
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
88
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
89 static void change_view(WindowData *w, int dual) {
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
90 if(dual) {
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
91 ui_set_visible(w->browser, TRUE);
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
92 ui_set_visible(w->editor, TRUE);
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
93 } else {
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
94 UiBool e, b;
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
95 if(w->editorIsOpen) {
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
96 e = TRUE;
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
97 b = FALSE;
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
98 } else {
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
99 e = FALSE;
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
100 b = TRUE;
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
101 }
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
102 ui_set_visible(w->browser, b);
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
103 ui_set_visible(w->editor, e);
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
104 }
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
105 }
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
106
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
107 void action_dualview(UiEvent *event, void *udata) {
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
108 int s = event->intval == 1 ? 0 : 1;
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
109 tb_singleview->set(tb_singleview, s);
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
110 change_view(event->window, event->intval);
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
111 }
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
112
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
113 void action_singleview(UiEvent *event, void *udata) {
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
114 int s = event->intval == 1 ? 0 : 1;
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
115 tb_dualview->set(tb_dualview, s);
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
116 change_view(event->window, s);
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
117 }
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
118
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
119
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
120
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
121
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
122 void action_test1(UiEvent *event, void *udata) {
2
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124 }
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
125
3
c04433993fbb add drawingarea and textarea group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
126 void action_test2(UiEvent *event, void *udata) {
2
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
127
ea89bbb0c4c8 toolkit update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
128 }

mercurial