Esempio n. 1
0
static int fs_cd_file(const char *filename)
{
    struct directory d;

    if (is_cwd_zip()) {
        return fs_cd_file_zip(sf_list_tail(&fs.directories), filename);
    }

    if (strcmp(filename, "..") == 0) {
        if (sf_list_cnt(&fs.directories)) {
            sf_list_pop(&fs.directories);
        }
        return chdir("..");
    } else {
        if (directory_init(&d, filename) != SF_OK) {
            return SF_ERR;
        }
        sf_list_push(&fs.directories, &d);
        if (!d.iszip) {
            return chdir(filename);
        }
    }

    return SF_OK;
}
Esempio n. 2
0
static int is_cwd_zip(void)
{
    if (sf_list_cnt(&fs.directories)) {
        struct directory *d;

        d = sf_list_tail(&fs.directories);
        if (d->iszip) {
            return 1;
        }
    }

    return 0;
}
Esempio n. 3
0
static void ui_toolbox_update_buttons(struct ui_toolbox *tb) {
    sf_list_iter_t iter;
    float xstep;
    float x;

    /*
     * 假设每个 buttons 的宽度相同,高度和 toolbox 一样。
     * 后期改进可以使用权重来计算每个 button 的位置。
     */
    xstep = tb->ui.area.w * 1.0f / (sf_list_cnt(&tb->buttons) + 1);

    x = xstep;

    if (sf_list_begin(&tb->buttons, &iter)) do {
        struct ui *button = *(struct ui**) sf_list_iter_elt(&iter);
        ui_move(button, x - button->area.w / 2, 0);
        x += xstep;
    } while (sf_list_iter_next(&iter));
}
Esempio n. 4
0
int fs_file_walker(int (*func)(int type, const char *filename, void *arg),
                   void *arg)
{
    int ret = SF_OK;
    struct directory *d;

    if (sf_list_cnt(&fs.directories) == 0) {
        return SF_OK;
    }

    d = sf_list_tail(&fs.directories);
    if (!d->isopened) {
        if ((ret = directory_open(d)) != SF_OK) {
            return ret;
        }
    }

    if (!d->iszip) {
        return fs_file_walker_dir(d, func, arg);
    } else {
        return fs_file_walker_zip(d, func, arg);
    }
}