improve top_dir of file browser

This commit is contained in:
lixianjing 2021-04-16 09:58:11 +08:00
parent 6186653d09
commit bdf0bdd61f
3 changed files with 20 additions and 0 deletions

View File

@ -63,6 +63,7 @@ static ret_t on_file_open(void* ctx, event_t* e) {
emitter_on(EMITTER(chooser), EVT_DONE, tk_on_choose_file_result, ctx);
file_chooser_set_init_dir(chooser, "src");
file_chooser_set_top_dir(chooser, "./");
file_chooser_set_filter(chooser, ".c.h.cpp.inc");
return file_chooser_choose_file_for_open(chooser);

View File

@ -107,6 +107,7 @@ ret_t file_browser_set_cwd(file_browser_t* fb, const char* cwd) {
return_value_if_fail(path_abs(cwd, path, MAX_PATH) == RET_OK, RET_BAD_PARAMS);
path_normalize(path, fb->cwd, MAX_PATH);
}
path_remove_last_slash(fb->cwd);
file_browser_refresh(fb);

View File

@ -367,3 +367,21 @@ TEST(FileBrowser, top_dir) {
file_browser_destroy(fb);
}
TEST(FileBrowser, top_dir1) {
char cwd[MAX_PATH + 1];
file_browser_t* fb = file_browser_create(os_fs());
fs_get_cwd(os_fs(), cwd);
ASSERT_EQ(file_browser_set_cwd(fb, "./"), RET_OK);
ASSERT_EQ(file_browser_set_top_dir(fb, "./"), RET_OK);
ASSERT_STREQ(fb->top_dir, cwd);
ASSERT_NE(file_browser_up(fb), RET_OK);
ASSERT_EQ(file_browser_enter(fb, "src"), RET_OK);
ASSERT_EQ(file_browser_up(fb), RET_OK);
ASSERT_NE(file_browser_up(fb), RET_OK);
file_browser_destroy(fb);
}