source: mainline/uspace/app/nav/menu.c@ adfa8b6

Last change on this file since adfa8b6 was 1ec732a, checked in by Jiri Svoboda <jiri@…>, 3 weeks ago

Verify file - navigator operation and command-line utility.

  • Property mode set to 100644
File size: 5.7 KB
Line 
1/*
2 * Copyright (c) 2025 Jiri Svoboda
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup nav
30 * @{
31 */
32/** @file Navigator.
33 *
34 * HelenOS file manager.
35 */
36
37#include <errno.h>
38#include <stdlib.h>
39#include <ui/menu.h>
40#include <ui/menubar.h>
41#include <ui/menudd.h>
42#include <ui/menuentry.h>
43#include "menu.h"
44#include "nav.h"
45
46/** Create navigator menu.
47 *
48 * @param window Navigator window
49 * @param rmenu Place to store pointer to new menu
50 * @return EOK on success or an error code
51 */
52errno_t nav_menu_create(ui_window_t *window, nav_menu_t **rmenu)
53{
54 nav_menu_t *menu;
55 ui_menu_t *mfile;
56 ui_menu_entry_t *mnew;
57 ui_menu_entry_t *mopen;
58 ui_menu_entry_t *medit;
59 ui_menu_entry_t *mverify;
60 ui_menu_entry_t *mfsep;
61 ui_menu_entry_t *mexit;
62 gfx_rect_t arect;
63 gfx_rect_t rect;
64 errno_t rc;
65
66 menu = calloc(1, sizeof(nav_menu_t));
67 if (menu == NULL)
68 return ENOMEM;
69
70 menu->window = window;
71 menu->ui = ui_window_get_ui(window);
72
73 rc = ui_menu_bar_create(menu->ui, menu->window,
74 &menu->menubar);
75 if (rc != EOK)
76 goto error;
77
78 rc = ui_menu_dd_create(menu->menubar, "~F~ile", NULL, &mfile);
79 if (rc != EOK)
80 goto error;
81
82 rc = ui_menu_entry_create(mfile, "~N~ew File", "Ctrl-M", &mnew);
83 if (rc != EOK)
84 goto error;
85
86 ui_menu_entry_set_cb(mnew, nav_menu_file_new_file, (void *) menu);
87
88 rc = ui_menu_entry_create(mfile, "~O~pen", "Enter", &mopen);
89 if (rc != EOK)
90 goto error;
91
92 ui_menu_entry_set_cb(mopen, nav_menu_file_open, (void *) menu);
93
94 rc = ui_menu_entry_create(mfile, "~E~dit", "Ctrl-E", &medit);
95 if (rc != EOK)
96 goto error;
97
98 ui_menu_entry_set_cb(medit, nav_menu_file_edit, (void *) menu);
99
100 rc = ui_menu_entry_create(mfile, "~V~erify", "Ctrl-V", &mverify);
101 if (rc != EOK)
102 goto error;
103
104 ui_menu_entry_set_cb(mverify, nav_menu_file_verify, (void *) menu);
105
106 rc = ui_menu_entry_sep_create(mfile, &mfsep);
107 if (rc != EOK)
108 goto error;
109
110 rc = ui_menu_entry_create(mfile, "E~x~it", "Ctrl-Q", &mexit);
111 if (rc != EOK)
112 goto error;
113
114 ui_menu_entry_set_cb(mexit, nav_menu_file_exit, (void *) menu);
115
116 ui_window_get_app_rect(menu->window, &arect);
117
118 rect.p0 = arect.p0;
119 rect.p1.x = arect.p1.x;
120 rect.p1.y = arect.p0.y + 1;
121 ui_menu_bar_set_rect(menu->menubar, &rect);
122
123 *rmenu = menu;
124 return EOK;
125error:
126 nav_menu_destroy(menu);
127 return rc;
128}
129
130/** Set navigator menu callbacks.
131 *
132 * @param menu Menu
133 * @param cb Callbacks
134 * @param arg Argument to callback functions
135 */
136void nav_menu_set_cb(nav_menu_t *menu, nav_menu_cb_t *cb, void *arg)
137{
138 menu->cb = cb;
139 menu->cb_arg = arg;
140}
141
142/** Destroy navigator menu.
143 *
144 * @param menu Menu
145 */
146void nav_menu_destroy(nav_menu_t *menu)
147{
148 if (menu->menubar != NULL)
149 ui_menu_bar_destroy(menu->menubar);
150
151 free(menu);
152}
153
154/** Return base UI control for the menu bar.
155 *
156 * @param menu Navigator menu
157 * @return UI control
158 */
159ui_control_t *nav_menu_ctl(nav_menu_t *menu)
160{
161 return ui_menu_bar_ctl(menu->menubar);
162}
163
164/** File / New File menu entry selected.
165 *
166 * @param mentry Menu entry
167 * @param arg Argument (navigator_t *)
168 */
169void nav_menu_file_new_file(ui_menu_entry_t *mentry, void *arg)
170{
171 nav_menu_t *menu = (nav_menu_t *)arg;
172
173 if (menu->cb != NULL && menu->cb->file_new_file != NULL)
174 menu->cb->file_new_file(menu->cb_arg);
175}
176
177/** File / Open menu entry selected.
178 *
179 * @param mentry Menu entry
180 * @param arg Argument (navigator_t *)
181 */
182void nav_menu_file_open(ui_menu_entry_t *mentry, void *arg)
183{
184 nav_menu_t *menu = (nav_menu_t *)arg;
185
186 if (menu->cb != NULL && menu->cb->file_open != NULL)
187 menu->cb->file_open(menu->cb_arg);
188}
189
190/** File / Edit menu entry selected.
191 *
192 * @param mentry Menu entry
193 * @param arg Argument (navigator_t *)
194 */
195void nav_menu_file_edit(ui_menu_entry_t *mentry, void *arg)
196{
197 nav_menu_t *menu = (nav_menu_t *)arg;
198
199 if (menu->cb != NULL && menu->cb->file_edit != NULL)
200 menu->cb->file_edit(menu->cb_arg);
201}
202
203/** File / Verify menu entry selected.
204 *
205 * @param mentry Menu entry
206 * @param arg Argument (navigator_t *)
207 */
208void nav_menu_file_verify(ui_menu_entry_t *mentry, void *arg)
209{
210 nav_menu_t *menu = (nav_menu_t *)arg;
211
212 if (menu->cb != NULL && menu->cb->file_verify != NULL)
213 menu->cb->file_verify(menu->cb_arg);
214}
215
216/** File / Exit menu entry selected.
217 *
218 * @param mentry Menu entry
219 * @param arg Argument (navigator_t *)
220 */
221void nav_menu_file_exit(ui_menu_entry_t *mentry, void *arg)
222{
223 nav_menu_t *menu = (nav_menu_t *)arg;
224
225 if (menu->cb != NULL && menu->cb->file_exit != NULL)
226 menu->cb->file_exit(menu->cb_arg);
227}
228
229/** @}
230 */
Note: See TracBrowser for help on using the repository browser.