Changeset 2f910b7 in mainline
- Timestamp:
- 2021-09-27T12:42:37Z (3 years ago)
- Branches:
- master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a330f2e
- Parents:
- b4b5f6a4
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/edit/edit.c
rb4b5f6a4 r2f910b7 126 126 int ideal_column; 127 127 128 bool search_reverse; 128 129 char *previous_search; 129 130 bool previous_search_reverse; … … 183 184 static char *range_get_str(spt_t const *spos, spt_t const *epos); 184 185 185 static char *prompt(char const *prompt, char const *init_value);186 187 186 static errno_t pane_init(ui_window_t *, pane_t *); 188 187 static void pane_fini(pane_t *); … … 277 276 .bcancel = go_to_line_dialog_bcancel, 278 277 .close = go_to_line_dialog_close 278 }; 279 280 static void search_dialog_bok(ui_prompt_dialog_t *, void *, const char *); 281 static void search_dialog_bcancel(ui_prompt_dialog_t *, void *); 282 static void search_dialog_close(ui_prompt_dialog_t *, void *); 283 284 static ui_prompt_dialog_cb_t search_dialog_cb = { 285 .bok = search_dialog_bok, 286 .bcancel = search_dialog_bcancel, 287 .close = search_dialog_close 279 288 }; 280 289 … … 823 832 824 833 ui_file_dialog_set_cb(dialog, &save_as_dialog_cb, &edit); 825 }826 827 /** Ask for a string. */828 static char *prompt(char const *prompt, char const *init_value)829 {830 return str_dup("42");831 834 } 832 835 … … 1689 1692 static void search_prompt(bool reverse) 1690 1693 { 1691 char *pattern; 1692 1693 const char *prompt_text = "Find next"; 1694 if (reverse) 1695 prompt_text = "Find previous"; 1696 1697 const char *default_value = ""; 1698 if (pane.previous_search) 1699 default_value = pane.previous_search; 1700 1701 pattern = prompt(prompt_text, default_value); 1702 if (pattern == NULL) { 1703 status_display("Search cancelled."); 1694 ui_prompt_dialog_params_t pdparams; 1695 ui_prompt_dialog_t *dialog; 1696 errno_t rc; 1697 1698 ui_prompt_dialog_params_init(&pdparams); 1699 pdparams.caption = reverse ? "Reverse Search" : "Search"; 1700 pdparams.prompt = "Search text"; 1701 1702 // const char *default_value = ""; 1703 // if (pane.previous_search) 1704 // default_value = pane.previous_search; 1705 1706 rc = ui_prompt_dialog_create(edit.ui, &pdparams, &dialog); 1707 if (rc != EOK) { 1708 printf("Error creating prompt dialog.\n"); 1704 1709 return; 1705 1710 } 1706 1711 1707 if (pane.previous_search) 1708 free(pane.previous_search); 1709 pane.previous_search = pattern; 1710 pane.previous_search_reverse = reverse; 1711 1712 search(pattern, reverse); 1712 ui_prompt_dialog_set_cb(dialog, &search_dialog_cb, &edit); 1713 pane.search_reverse = reverse; 1713 1714 } 1714 1715 … … 2260 2261 } 2261 2262 2263 /** Search dialog OK button press. 2264 * 2265 * @param dialog Search dialog 2266 * @param arg Argument (ui_demo_t *) 2267 * @param text Submitted text 2268 */ 2269 static void search_dialog_bok(ui_prompt_dialog_t *dialog, void *arg, 2270 const char *text) 2271 { 2272 edit_t *edit = (edit_t *) arg; 2273 gfx_context_t *gc = ui_window_get_gc(edit->window); 2274 char *pattern; 2275 bool reverse; 2276 2277 ui_prompt_dialog_destroy(dialog); 2278 2279 /* Abort if search phrase is empty */ 2280 if (text[0] == '\0') 2281 return; 2282 2283 pattern = str_dup(text); 2284 reverse = pane.search_reverse; 2285 2286 if (pane.previous_search) 2287 free(pane.previous_search); 2288 pane.previous_search = pattern; 2289 pane.previous_search_reverse = reverse; 2290 2291 search(pattern, reverse); 2292 2293 // TODO Smarter cursor management 2294 (void) pane_update(&pane); 2295 gfx_cursor_set_visible(gc, true); 2296 (void) gfx_update(gc); 2297 } 2298 2299 /** Search dialog cancel button press. 2300 * 2301 * @param dialog File dialog 2302 * @param arg Argument (ui_demo_t *) 2303 */ 2304 static void search_dialog_bcancel(ui_prompt_dialog_t *dialog, void *arg) 2305 { 2306 edit_t *edit = (edit_t *) arg; 2307 gfx_context_t *gc = ui_window_get_gc(edit->window); 2308 2309 ui_prompt_dialog_destroy(dialog); 2310 // TODO Smarter cursor management 2311 pane.rflags |= REDRAW_CARET; 2312 (void) pane_update(&pane); 2313 gfx_cursor_set_visible(gc, true); 2314 } 2315 2316 /** Search dialog close request. 2317 * 2318 * @param dialog File dialog 2319 * @param arg Argument (ui_demo_t *) 2320 */ 2321 static void search_dialog_close(ui_prompt_dialog_t *dialog, void *arg) 2322 { 2323 edit_t *edit = (edit_t *) arg; 2324 gfx_context_t *gc = ui_window_get_gc(edit->window); 2325 2326 ui_prompt_dialog_destroy(dialog); 2327 // TODO Smarter cursor management 2328 pane.rflags |= REDRAW_CARET; 2329 (void) pane_update(&pane); 2330 gfx_cursor_set_visible(gc, true); 2331 } 2332 2262 2333 /** @} 2263 2334 */
Note:
See TracChangeset
for help on using the changeset viewer.