Changeset 97c3c59 in mainline for uspace/app/nav/panel.c


Ignore:
Timestamp:
2021-10-25T00:32:45Z (2 years ago)
Author:
jxsvoboda <5887334+jxsvoboda@…>
Branches:
master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5bbb4453
Parents:
01e9991
git-author:
Jiri Svoboda <jiri@…> (2021-10-19 19:48:40)
git-committer:
jxsvoboda <5887334+jxsvoboda@…> (2021-10-25 00:32:45)
Message:

When moving up a dir, seek to the directory just exited

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/nav/panel.c

    r01e9991 r97c3c59  
    519519        char *ndir = NULL;
    520520        panel_entry_attr_t attr;
     521        panel_entry_t *next;
     522        panel_entry_t *prev;
     523        char *olddn;
     524        size_t pg_size;
     525        size_t i;
    521526        errno_t rc;
    522527
     
    582587        panel->page = panel_first(panel);
    583588        panel->page_idx = 0;
     589
     590        /* Moving up? */
     591        if (str_cmp(dirname, "..") == 0) {
     592                /* Get the last component of old path */
     593                olddn = str_rchr(panel->dir, '/');
     594                if (olddn != NULL && *olddn != '\0') {
     595                        /* Find corresponding entry */
     596                        ++olddn;
     597                        next = panel_next(panel->cursor);
     598                        while (next != NULL && str_cmp(next->name, olddn) <= 0 &&
     599                            next->isdir) {
     600                                panel->cursor = next;
     601                                ++panel->cursor_idx;
     602                                next = panel_next(panel->cursor);
     603                        }
     604
     605                        /* Move page so that cursor is in the center */
     606                        panel->page = panel->cursor;
     607                        panel->page_idx = panel->cursor_idx;
     608
     609                        pg_size = panel_page_size(panel);
     610
     611                        for (i = 0; i < pg_size / 2; i++) {
     612                                prev = panel_prev(panel->page);
     613                                if (prev == NULL)
     614                                        break;
     615
     616                                panel->page = prev;
     617                                --panel->page_idx;
     618                        }
     619                }
     620        }
     621
    584622        free(panel->dir);
    585623        panel->dir = ndir;
     624
    586625        return EOK;
    587626error:
     
    9741013{
    9751014        gfx_context_t *gc = ui_window_get_gc(panel->window);
     1015        char *dirname;
    9761016        errno_t rc;
    9771017
    9781018        assert(entry->isdir);
    9791019
     1020        /*
     1021         * Need to copy out name before we free the entry below
     1022         * via panel_clear_entries().
     1023         */
     1024        dirname = str_dup(entry->name);
     1025        if (dirname == NULL)
     1026                return ENOMEM;
     1027
    9801028        panel_clear_entries(panel);
    9811029
    982         rc = panel_read_dir(panel, entry->name);
    983         if (rc != EOK)
    984                 return rc;
     1030        rc = panel_read_dir(panel, dirname);
     1031        if (rc != EOK) {
     1032                free(dirname);
     1033                return rc;
     1034        }
     1035
     1036        free(dirname);
    9851037
    9861038        rc = panel_paint(panel);
Note: See TracChangeset for help on using the changeset viewer.