Changeset b4b5f6a4 in mainline


Ignore:
Timestamp:
2021-09-26T07:15:58Z (3 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
2f910b7
Parents:
8e253ac
Message:

Go To Line dialog

Need to restore cursor after closing dialog. This is not how it should
be done. Either the cursor should be restored by pane activation
handler (so we still treat cursor as a global resource and the
individual controls need to responsibly manage it), or, the UI library
should somehow virtualize it, e.g. each window would remember its
cursor state and cursor would be automatically updated when a different
window is activated.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/edit/edit.c

    r8e253ac rb4b5f6a4  
    6161#include <ui/menubar.h>
    6262#include <ui/menuentry.h>
     63#include <ui/promptdialog.h>
    6364#include <ui/resource.h>
    6465#include <ui/ui.h>
     
    268269};
    269270
     271static void go_to_line_dialog_bok(ui_prompt_dialog_t *, void *, const char *);
     272static void go_to_line_dialog_bcancel(ui_prompt_dialog_t *, void *);
     273static void go_to_line_dialog_close(ui_prompt_dialog_t *, void *);
     274
     275static ui_prompt_dialog_cb_t go_to_line_dialog_cb = {
     276        .bok = go_to_line_dialog_bok,
     277        .bcancel = go_to_line_dialog_bcancel,
     278        .close =  go_to_line_dialog_close
     279};
    270280
    271281int main(int argc, char *argv[])
     
    10451055        return EOK;
    10461056}
    1047 
    10481057
    10491058/** Display pane text.
     
    16091618static void caret_go_to_line_ask(void)
    16101619{
    1611         char *sline;
    1612 
    1613         sline = prompt("Go to line", "");
    1614         if (sline == NULL) {
    1615                 status_display("Go to line cancelled.");
     1620        ui_prompt_dialog_params_t pdparams;
     1621        ui_prompt_dialog_t *dialog;
     1622        errno_t rc;
     1623
     1624        ui_prompt_dialog_params_init(&pdparams);
     1625        pdparams.caption = "Go To Line";
     1626        pdparams.prompt = "Line Number";
     1627
     1628        rc = ui_prompt_dialog_create(edit.ui, &pdparams, &dialog);
     1629        if (rc != EOK) {
     1630                printf("Error creating prompt dialog.\n");
    16161631                return;
    16171632        }
    16181633
    1619         char *endptr;
    1620         int line = strtol(sline, &endptr, 10);
    1621         if (*endptr != '\0') {
    1622                 free(sline);
    1623                 status_display("Invalid number entered.");
    1624                 return;
    1625         }
    1626         free(sline);
    1627 
    1628         caret_move_absolute(line, pane.ideal_column, dir_before, false);
     1634        ui_prompt_dialog_set_cb(dialog, &go_to_line_dialog_cb, &edit);
    16291635}
    16301636
     
    21312137    const char *fname)
    21322138{
     2139        edit_t *edit = (edit_t *)arg;
     2140        gfx_context_t *gc = ui_window_get_gc(edit->window);
    21332141        char *cname;
    21342142        errno_t rc;
    21352143
    21362144        ui_file_dialog_destroy(dialog);
     2145        // TODO Smarter cursor management
     2146        pane.rflags |= REDRAW_CARET;
     2147        (void) pane_update(&pane);
     2148        gfx_cursor_set_visible(gc, true);
    21372149
    21382150        cname = str_dup(fname);
     
    21602172{
    21612173        edit_t *edit = (edit_t *)arg;
    2162 
    2163         (void)edit;
     2174        gfx_context_t *gc = ui_window_get_gc(edit->window);
     2175
    21642176        ui_file_dialog_destroy(dialog);
     2177        // TODO Smarter cursor management
     2178        pane.rflags |= REDRAW_CARET;
     2179        (void) pane_update(&pane);
     2180        gfx_cursor_set_visible(gc, true);
    21652181}
    21662182
     
    21732189{
    21742190        edit_t *edit = (edit_t *)arg;
    2175 
    2176         (void)edit;
     2191        gfx_context_t *gc = ui_window_get_gc(edit->window);
     2192
    21772193        ui_file_dialog_destroy(dialog);
     2194        // TODO Smarter cursor management
     2195        pane.rflags |= REDRAW_CARET;
     2196        (void) pane_update(&pane);
     2197        gfx_cursor_set_visible(gc, true);
     2198}
     2199
     2200/** Go To Line dialog OK button press.
     2201 *
     2202 * @param dialog Go To Line dialog
     2203 * @param arg Argument (ui_demo_t *)
     2204 * @param text Submitted text
     2205 */
     2206static void go_to_line_dialog_bok(ui_prompt_dialog_t *dialog, void *arg,
     2207    const char *text)
     2208{
     2209        edit_t *edit = (edit_t *) arg;
     2210        gfx_context_t *gc = ui_window_get_gc(edit->window);
     2211        char *endptr;
     2212        int line;
     2213
     2214        ui_prompt_dialog_destroy(dialog);
     2215        line = strtol(text, &endptr, 10);
     2216        if (*endptr != '\0') {
     2217                status_display("Invalid number entered.");
     2218                return;
     2219        }
     2220
     2221        caret_move_absolute(line, pane.ideal_column, dir_before, false);
     2222        // TODO Smarter cursor management
     2223        (void) pane_update(&pane);
     2224        gfx_cursor_set_visible(gc, true);
     2225        (void) gfx_update(gc);
     2226}
     2227
     2228/** Go To Line dialog cancel button press.
     2229 *
     2230 * @param dialog File dialog
     2231 * @param arg Argument (ui_demo_t *)
     2232 */
     2233static void go_to_line_dialog_bcancel(ui_prompt_dialog_t *dialog, void *arg)
     2234{
     2235        edit_t *edit = (edit_t *) arg;
     2236        gfx_context_t *gc = ui_window_get_gc(edit->window);
     2237
     2238        ui_prompt_dialog_destroy(dialog);
     2239        // TODO Smarter cursor management
     2240        pane.rflags |= REDRAW_CARET;
     2241        (void) pane_update(&pane);
     2242        gfx_cursor_set_visible(gc, true);
     2243}
     2244
     2245/** Go To Line dialog close request.
     2246 *
     2247 * @param dialog File dialog
     2248 * @param arg Argument (ui_demo_t *)
     2249 */
     2250static void go_to_line_dialog_close(ui_prompt_dialog_t *dialog, void *arg)
     2251{
     2252        edit_t *edit = (edit_t *) arg;
     2253        gfx_context_t *gc = ui_window_get_gc(edit->window);
     2254
     2255        ui_prompt_dialog_destroy(dialog);
     2256        // TODO Smarter cursor management
     2257        pane.rflags |= REDRAW_CARET;
     2258        (void) pane_update(&pane);
     2259        gfx_cursor_set_visible(gc, true);
    21782260}
    21792261
Note: See TracChangeset for help on using the changeset viewer.