mirror of
https://gitee.com/zlgopen/awtk.git
synced 2024-12-03 20:48:02 +08:00
refactor
This commit is contained in:
parent
222e5b2af5
commit
d1c9a291e6
@ -91,9 +91,6 @@ file_browser_t* file_browser_create(fs_t* fs) {
|
||||
tk_strcpy(fb->cwd, "/");
|
||||
fb->ignore_hidden_files = TRUE;
|
||||
fb->compare = fb_compare_by_name;
|
||||
wbuffer_init_extendable(&(fb->copy_items));
|
||||
|
||||
emitter_init(EMITTER(fb));
|
||||
|
||||
return fb;
|
||||
}
|
||||
@ -193,73 +190,6 @@ ret_t file_browser_remove(file_browser_t* fb, const char* name) {
|
||||
return file_browser_remove_item_recursive(fb, fullpath);
|
||||
}
|
||||
|
||||
ret_t file_browser_copy(file_browser_t* fb, darray_t* items) {
|
||||
uint32_t i = 0;
|
||||
wbuffer_t* wb = NULL;
|
||||
return_value_if_fail(fb != NULL && items != NULL, RET_BAD_PARAMS);
|
||||
|
||||
wb = &(fb->copy_items);
|
||||
wb->cursor = 0;
|
||||
tk_strncpy(fb->copy_src_dir, fb->cwd, MAX_PATH);
|
||||
|
||||
for (i = 0; i < items->size; i++) {
|
||||
fb_item_t* iter = (fb_item_t*)(items->elms[i]);
|
||||
|
||||
if (wbuffer_write_string(wb, iter->name) != RET_OK) {
|
||||
wb->cursor = 0;
|
||||
return RET_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
ret_t file_browser_cut(file_browser_t* fb, darray_t* items) {
|
||||
return_value_if_fail(fb != NULL && items != NULL, RET_BAD_PARAMS);
|
||||
|
||||
fb->cut = TRUE;
|
||||
return file_browser_copy(fb, items);
|
||||
}
|
||||
|
||||
bool_t file_browser_can_paste(file_browser_t* fb) {
|
||||
return_value_if_fail(fb != NULL, FALSE);
|
||||
|
||||
return fb->copy_items.cursor > 0;
|
||||
}
|
||||
|
||||
static ret_t file_browser_copy_item(file_browser_t* fb, const char* src, const char* dst,
|
||||
const char* name) {
|
||||
/*TODO*/
|
||||
return RET_NOT_IMPL;
|
||||
}
|
||||
|
||||
ret_t file_browser_paste(file_browser_t* fb) {
|
||||
rbuffer_t rb;
|
||||
wbuffer_t* wb = NULL;
|
||||
const char* src = NULL;
|
||||
const char* name = NULL;
|
||||
char fullpath[MAX_PATH + 1];
|
||||
return_value_if_fail(file_browser_can_paste(fb), RET_BAD_PARAMS);
|
||||
|
||||
wb = &(fb->copy_items);
|
||||
rbuffer_init(&rb, wb->data, wb->cursor);
|
||||
return_value_if_fail(rbuffer_read_string(&rb, &src) == RET_OK, RET_BAD_PARAMS);
|
||||
|
||||
memset(fullpath, 0x00, sizeof(fullpath));
|
||||
while (rbuffer_read_string(&rb, &name) == RET_OK) {
|
||||
if (file_browser_copy_item(fb, src, fb->cwd, name) != RET_OK) {
|
||||
return RET_FAIL;
|
||||
}
|
||||
|
||||
if (fb->cut) {
|
||||
return_value_if_fail(path_build(fullpath, MAX_PATH, src, name, NULL) == RET_OK, RET_FAIL);
|
||||
file_browser_remove_item_recursive(fb, fullpath);
|
||||
}
|
||||
}
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
ret_t file_browser_refresh(file_browser_t* fb) {
|
||||
fs_item_t info;
|
||||
fs_stat_info_t st;
|
||||
@ -555,8 +485,6 @@ ret_t file_browser_destroy(file_browser_t* fb) {
|
||||
TKMEM_FREE(fb->items);
|
||||
}
|
||||
|
||||
emitter_deinit(EMITTER(fb));
|
||||
wbuffer_deinit(&(fb->copy_items));
|
||||
TKMEM_FREE(fb);
|
||||
|
||||
return RET_OK;
|
||||
|
@ -86,7 +86,6 @@ typedef struct _fb_item_t {
|
||||
* 文件浏览器模型。
|
||||
*/
|
||||
typedef struct _file_browser_t {
|
||||
emitter_t emitter;
|
||||
/**
|
||||
* @property {char*} cwd
|
||||
* @annotation ["readable"]
|
||||
@ -104,23 +103,9 @@ typedef struct _file_browser_t {
|
||||
tk_filter_t filter;
|
||||
tk_compare_t compare;
|
||||
|
||||
bool_t cut;
|
||||
wbuffer_t copy_items;
|
||||
char copy_src_dir[MAX_PATH + 1];
|
||||
|
||||
bool_t ignore_hidden_files;
|
||||
} file_browser_t;
|
||||
|
||||
/**
|
||||
* @event {event_t} EVT_ITEMS_CHANGED
|
||||
* 文件项目改变
|
||||
*/
|
||||
|
||||
/**
|
||||
* @event {progress_event_t} EVT_PROGRESS
|
||||
* 进度改变。
|
||||
*/
|
||||
|
||||
/**
|
||||
* @method file_browser_create
|
||||
* 创建file_browser对象
|
||||
@ -178,48 +163,6 @@ ret_t file_browser_create_file(file_browser_t* fb, const char* name, const void*
|
||||
*/
|
||||
ret_t file_browser_remove(file_browser_t* fb, const char* name);
|
||||
|
||||
/**
|
||||
* @method file_browser_copy
|
||||
* 拷贝当前目录下的指定子目录。
|
||||
*
|
||||
* @param {file_browser_t*} fb file browser对象。
|
||||
* @param {darray_t*} items 当前目录下的子目录/文件项列表。
|
||||
*
|
||||
* @return {ret_t} 返回RET_OK表示成功,否则表示失败。
|
||||
*/
|
||||
ret_t file_browser_copy(file_browser_t* fb, darray_t* items);
|
||||
|
||||
/**
|
||||
* @method file_browser_cut
|
||||
* 剪切当前目录下的指定子目录。
|
||||
*
|
||||
* @param {file_browser_t*} fb file browser对象。
|
||||
* @param {darray_t*} items 当前目录下的子目录/文件项列表。
|
||||
*
|
||||
* @return {ret_t} 返回RET_OK表示成功,否则表示失败。
|
||||
*/
|
||||
ret_t file_browser_cut(file_browser_t* fb, darray_t* items);
|
||||
|
||||
/**
|
||||
* @method file_browser_can_paste
|
||||
* 判断是否可以粘贴。
|
||||
*
|
||||
* @param {file_browser_t*} fb file browser对象。
|
||||
*
|
||||
* @return {bool_t} 返回FALSE表示不可以,否则表示可以。
|
||||
*/
|
||||
bool_t file_browser_can_paste(file_browser_t* fb);
|
||||
|
||||
/**
|
||||
* @method file_browser_paste
|
||||
* 粘贴。
|
||||
*
|
||||
* @param {file_browser_t*} fb file browser对象。
|
||||
*
|
||||
* @return {ret_t} 返回RET_OK表示成功,否则表示失败。
|
||||
*/
|
||||
ret_t file_browser_paste(file_browser_t* fb);
|
||||
|
||||
/**
|
||||
* @method file_browser_enter
|
||||
* 进入当前目录下的指定子目录。
|
||||
|
@ -41,7 +41,6 @@ ret_t file_browser_view_set_init_dir(widget_t* widget, const char* init_dir) {
|
||||
|
||||
file_browser_view->init_dir = tk_str_copy(file_browser_view->init_dir, init_dir);
|
||||
file_browser_set_cwd(file_browser_view->fb, init_dir);
|
||||
str_set(&(file_browser_view->value), init_dir);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
@ -112,9 +111,6 @@ static ret_t file_browser_view_get_prop(widget_t* widget, const char* name, valu
|
||||
} else if (tk_str_eq(FILE_BROWSER_VIEW_PROP_SORT_BY, name)) {
|
||||
value_set_str(v, file_browser_view->sort_by);
|
||||
return RET_OK;
|
||||
} else if (tk_str_eq(WIDGET_PROP_VALUE, name)) {
|
||||
value_set_str(v, file_browser_view->value.str);
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
return RET_NOT_FOUND;
|
||||
@ -148,7 +144,6 @@ static ret_t file_browser_view_on_destroy(widget_t* widget) {
|
||||
TKMEM_FREE(file_browser_view->init_dir);
|
||||
file_browser_destroy(file_browser_view->fb);
|
||||
|
||||
str_reset(&(file_browser_view->value));
|
||||
widget_destroy(file_browser_view->file_template);
|
||||
widget_destroy(file_browser_view->folder_template);
|
||||
darray_deinit(&(file_browser_view->selected_items));
|
||||
@ -180,25 +175,17 @@ static ret_t file_browser_view_on_item_clicked(void* ctx, event_t* e) {
|
||||
|
||||
if (tk_str_eq(target->name, FILE_BROWSER_VIEW_RETURN_UP)) {
|
||||
file_browser_up(file_browser_view->fb);
|
||||
str_set(&(file_browser_view->value), file_browser_view->fb->cwd);
|
||||
|
||||
idle_add(file_browser_view_reload_in_idle, file_browser_view);
|
||||
} else if (tk_str_eq(target->name, FILE_BROWSER_VIEW_FOLDER)) {
|
||||
uint32_t index = widget_index_of(target);
|
||||
fb_item_t* info = file_browser_get_item(file_browser_view->fb, index - 1);
|
||||
|
||||
file_browser_enter(file_browser_view->fb, info->name);
|
||||
str_set(&(file_browser_view->value), file_browser_view->fb->cwd);
|
||||
|
||||
idle_add(file_browser_view_reload_in_idle, file_browser_view);
|
||||
} else {
|
||||
uint32_t index = widget_index_of(target);
|
||||
fb_item_t* info = file_browser_get_item(file_browser_view->fb, index - 1);
|
||||
|
||||
str_set(&(file_browser_view->value), file_browser_view->fb->cwd);
|
||||
str_append_char(&(file_browser_view->value), TK_PATH_SEP);
|
||||
str_append(&(file_browser_view->value), info->name);
|
||||
|
||||
if (file_browser_view->selected_file != NULL) {
|
||||
widget_set_text_utf8(file_browser_view->selected_file, info->name);
|
||||
}
|
||||
@ -399,7 +386,6 @@ widget_t* file_browser_view_create(widget_t* parent, xy_t x, xy_t y, wh_t w, wh_
|
||||
file_browser_view_t* file_browser_view = FILE_BROWSER_VIEW(widget);
|
||||
return_value_if_fail(file_browser_view != NULL, NULL);
|
||||
|
||||
str_init(&(file_browser_view->value), 0);
|
||||
file_browser_view->sort_ascending = TRUE;
|
||||
file_browser_view->ignore_hidden_files = TRUE;
|
||||
file_browser_view->fb = file_browser_create(os_fs());
|
||||
@ -453,50 +439,6 @@ const char* file_browser_view_get_cwd(widget_t* widget) {
|
||||
return file_browser_view->fb->cwd;
|
||||
}
|
||||
|
||||
ret_t file_browser_view_copy(widget_t* widget) {
|
||||
darray_t* selected_items = NULL;
|
||||
file_browser_view_t* file_browser_view = FILE_BROWSER_VIEW(widget);
|
||||
return_value_if_fail(file_browser_view != NULL, RET_BAD_PARAMS);
|
||||
|
||||
selected_items = file_browser_view_get_selected_items(widget);
|
||||
|
||||
return file_browser_copy(file_browser_view->fb, selected_items);
|
||||
}
|
||||
|
||||
ret_t file_browser_view_cut(widget_t* widget) {
|
||||
darray_t* selected_items = NULL;
|
||||
file_browser_view_t* file_browser_view = FILE_BROWSER_VIEW(widget);
|
||||
return_value_if_fail(file_browser_view != NULL, RET_BAD_PARAMS);
|
||||
|
||||
selected_items = file_browser_view_get_selected_items(widget);
|
||||
|
||||
return file_browser_cut(file_browser_view->fb, selected_items);
|
||||
}
|
||||
|
||||
ret_t file_browser_view_remove(widget_t* widget) {
|
||||
darray_t* selected_items = NULL;
|
||||
file_browser_view_t* file_browser_view = FILE_BROWSER_VIEW(widget);
|
||||
return_value_if_fail(file_browser_view != NULL, RET_BAD_PARAMS);
|
||||
|
||||
selected_items = file_browser_view_get_selected_items(widget);
|
||||
|
||||
return file_browser_cut(file_browser_view->fb, selected_items);
|
||||
}
|
||||
|
||||
ret_t file_browser_view_paste(widget_t* widget) {
|
||||
file_browser_view_t* file_browser_view = FILE_BROWSER_VIEW(widget);
|
||||
return_value_if_fail(file_browser_view != NULL, RET_BAD_PARAMS);
|
||||
|
||||
return file_browser_paste(file_browser_view->fb);
|
||||
}
|
||||
|
||||
bool_t file_browser_view_can_paste(widget_t* widget) {
|
||||
file_browser_view_t* file_browser_view = FILE_BROWSER_VIEW(widget);
|
||||
return_value_if_fail(file_browser_view != NULL, RET_BAD_PARAMS);
|
||||
|
||||
return file_browser_can_paste(file_browser_view->fb);
|
||||
}
|
||||
|
||||
ret_t file_browser_view_create_dir(widget_t* widget, const char* name) {
|
||||
file_browser_view_t* file_browser_view = FILE_BROWSER_VIEW(widget);
|
||||
return_value_if_fail(file_browser_view != NULL, RET_BAD_PARAMS);
|
||||
|
@ -62,14 +62,6 @@ typedef struct _file_browser_view_t {
|
||||
*/
|
||||
char* sort_by;
|
||||
|
||||
/**
|
||||
* @property {char*} value
|
||||
* @fake
|
||||
* @annotation ["set_prop","get_prop"]
|
||||
* 当前选中项的完整路径。
|
||||
*/
|
||||
str_t value;
|
||||
|
||||
/*private*/
|
||||
bool_t inited;
|
||||
file_browser_t* fb;
|
||||
|
Loading…
Reference in New Issue
Block a user