Fri, 11 Dec 2020 18:32:54 +0100
add sqlite dependency
2 | 1 | /* |
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
3 | * | |
4 | * Copyright 2020 Olaf Wintermann. All rights reserved. | |
5 | * | |
6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions are met: | |
8 | * | |
9 | * 1. Redistributions of source code must retain the above copyright | |
10 | * notice, this list of conditions and the following disclaimer. | |
11 | * | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | |
15 | * | |
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
26 | * POSSIBILITY OF SUCH DAMAGE. | |
27 | */ | |
28 | ||
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 | 31 | |
32 | #include <stdio.h> | |
33 | #include <stdlib.h> | |
34 | ||
35 | #pragma clang diagnostic ignored "-Wdeprecated-declarations" | |
36 | ||
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 | 40 | |
41 | static void create_main_menu(void) { | |
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 | 44 | ui_menuitem_st(UI_STOCK_OPEN, NULL, NULL); |
45 | ||
46 | ui_menu("Edit"); | |
47 | ui_menuitem_st(UI_STOCK_UNDO, NULL, NULL); | |
48 | ui_menuitem_st(UI_STOCK_REDO, NULL, NULL); | |
49 | ||
50 | } | |
51 | ||
52 | static void create_main_toolbar(void) { | |
53 | UiContext *ctx = ui_global_context(); | |
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 | 60 | |
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 | 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 | 70 | |
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 | 77 | } |
78 | ||
79 | void menu_init(void) { | |
80 | create_main_menu(); | |
81 | create_main_toolbar(); | |
82 | } | |
83 | ||
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 | 123 | |
124 | } | |
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 | 127 | |
128 | } |