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

Last change on this file since 2309891 was 2309891, checked in by Jiri Svoboda <jiri@…>, 3 days ago

Copy files (Navigator and command line).

TODO Overwrite query, new I/O error types.

  • Property mode set to 100644
File size: 6.2 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 *mcopy;
61 ui_menu_entry_t *mfsep;
62 ui_menu_entry_t *mexit;
63 gfx_rect_t arect;
64 gfx_rect_t rect;
65 errno_t rc;
66
67 menu = calloc(1, sizeof(nav_menu_t));
68 if (menu == NULL)
69 return ENOMEM;
70
71 menu->window = window;
72 menu->ui = ui_window_get_ui(window);
73
74 rc = ui_menu_bar_create(menu->ui, menu->window,
75 &menu->menubar);
76 if (rc != EOK)
77 goto error;
78
79 rc = ui_menu_dd_create(menu->menubar, "~F~ile", NULL, &mfile);
80 if (rc != EOK)
81 goto error;
82
83 rc = ui_menu_entry_create(mfile, "~N~ew File", "Ctrl-M", &mnew);
84 if (rc != EOK)
85 goto error;
86
87 ui_menu_entry_set_cb(mnew, nav_menu_file_new_file, (void *) menu);
88
89 rc = ui_menu_entry_create(mfile, "~O~pen", "Enter", &mopen);
90 if (rc != EOK)
91 goto error;
92
93 ui_menu_entry_set_cb(mopen, nav_menu_file_open, (void *) menu);
94
95 rc = ui_menu_entry_create(mfile, "~E~dit", "Ctrl-E", &medit);
96 if (rc != EOK)
97 goto error;
98
99 ui_menu_entry_set_cb(medit, nav_menu_file_edit, (void *) menu);
100
101 rc = ui_menu_entry_create(mfile, "~V~erify", "Ctrl-V", &mverify);
102 if (rc != EOK)
103 goto error;
104
105 ui_menu_entry_set_cb(mverify, nav_menu_file_verify, (void *) menu);
106
107 rc = ui_menu_entry_create(mfile, "~C~opy", "Ctrl-C", &mcopy);
108 if (rc != EOK)
109 goto error;
110
111 ui_menu_entry_set_cb(mcopy, nav_menu_file_copy, (void *) menu);
112
113 rc = ui_menu_entry_sep_create(mfile, &mfsep);
114 if (rc != EOK)
115 goto error;
116
117 rc = ui_menu_entry_create(mfile, "E~x~it", "Ctrl-Q", &mexit);
118 if (rc != EOK)
119 goto error;
120
121 ui_menu_entry_set_cb(mexit, nav_menu_file_exit, (void *) menu);
122
123 ui_window_get_app_rect(menu->window, &arect);
124
125 rect.p0 = arect.p0;
126 rect.p1.x = arect.p1.x;
127 rect.p1.y = arect.p0.y + 1;
128 ui_menu_bar_set_rect(menu->menubar, &rect);
129
130 *rmenu = menu;
131 return EOK;
132error:
133 nav_menu_destroy(menu);
134 return rc;
135}
136
137/** Set navigator menu callbacks.
138 *
139 * @param menu Menu
140 * @param cb Callbacks
141 * @param arg Argument to callback functions
142 */
143void nav_menu_set_cb(nav_menu_t *menu, nav_menu_cb_t *cb, void *arg)
144{
145 menu->cb = cb;
146 menu->cb_arg = arg;
147}
148
149/** Destroy navigator menu.
150 *
151 * @param menu Menu
152 */
153void nav_menu_destroy(nav_menu_t *menu)
154{
155 if (menu->menubar != NULL)
156 ui_menu_bar_destroy(menu->menubar);
157
158 free(menu);
159}
160
161/** Return base UI control for the menu bar.
162 *
163 * @param menu Navigator menu
164 * @return UI control
165 */
166ui_control_t *nav_menu_ctl(nav_menu_t *menu)
167{
168 return ui_menu_bar_ctl(menu->menubar);
169}
170
171/** File / New File menu entry selected.
172 *
173 * @param mentry Menu entry
174 * @param arg Argument (navigator_t *)
175 */
176void nav_menu_file_new_file(ui_menu_entry_t *mentry, void *arg)
177{
178 nav_menu_t *menu = (nav_menu_t *)arg;
179
180 if (menu->cb != NULL && menu->cb->file_new_file != NULL)
181 menu->cb->file_new_file(menu->cb_arg);
182}
183
184/** File / Open menu entry selected.
185 *
186 * @param mentry Menu entry
187 * @param arg Argument (navigator_t *)
188 */
189void nav_menu_file_open(ui_menu_entry_t *mentry, void *arg)
190{
191 nav_menu_t *menu = (nav_menu_t *)arg;
192
193 if (menu->cb != NULL && menu->cb->file_open != NULL)
194 menu->cb->file_open(menu->cb_arg);
195}
196
197/** File / Edit menu entry selected.
198 *
199 * @param mentry Menu entry
200 * @param arg Argument (navigator_t *)
201 */
202void nav_menu_file_edit(ui_menu_entry_t *mentry, void *arg)
203{
204 nav_menu_t *menu = (nav_menu_t *)arg;
205
206 if (menu->cb != NULL && menu->cb->file_edit != NULL)
207 menu->cb->file_edit(menu->cb_arg);
208}
209
210/** File / Verify menu entry selected.
211 *
212 * @param mentry Menu entry
213 * @param arg Argument (navigator_t *)
214 */
215void nav_menu_file_verify(ui_menu_entry_t *mentry, void *arg)
216{
217 nav_menu_t *menu = (nav_menu_t *)arg;
218
219 if (menu->cb != NULL && menu->cb->file_verify != NULL)
220 menu->cb->file_verify(menu->cb_arg);
221}
222
223/** File / Copy menu entry selected.
224 *
225 * @param mentry Menu entry
226 * @param arg Argument (navigator_t *)
227 */
228void nav_menu_file_copy(ui_menu_entry_t *mentry, void *arg)
229{
230 nav_menu_t *menu = (nav_menu_t *)arg;
231
232 if (menu->cb != NULL && menu->cb->file_copy != NULL)
233 menu->cb->file_copy(menu->cb_arg);
234}
235
236/** File / Exit menu entry selected.
237 *
238 * @param mentry Menu entry
239 * @param arg Argument (navigator_t *)
240 */
241void nav_menu_file_exit(ui_menu_entry_t *mentry, void *arg)
242{
243 nav_menu_t *menu = (nav_menu_t *)arg;
244
245 if (menu->cb != NULL && menu->cb->file_exit != NULL)
246 menu->cb->file_exit(menu->cb_arg);
247}
248
249/** @}
250 */
Note: See TracBrowser for help on using the repository browser.