2020-01-12 20:48:41 +08:00
|
|
|
/**
|
|
|
|
* File: demo_file_browser.c
|
|
|
|
* Author: AWTK Develop Team
|
|
|
|
* Brief: basic demo
|
|
|
|
*
|
|
|
|
* Copyright (c) 2020 - 2020 Guangzhou ZHIYUAN Electronics Co.,Ltd.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* License file for more details.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* History:
|
|
|
|
* ================================================================
|
|
|
|
* 2020-01-12 Li XianJing <xianjimli@hotmail.com> created
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "awtk.h"
|
|
|
|
#include "ext_widgets/file_browser/file_chooser.h"
|
|
|
|
|
|
|
|
static ret_t on_quit(void* ctx, event_t* e) {
|
|
|
|
tk_quit();
|
|
|
|
return RET_OK;
|
|
|
|
}
|
|
|
|
|
2020-01-15 14:19:33 +08:00
|
|
|
static ret_t tk_on_choose_file_result(void* ctx, event_t* e) {
|
|
|
|
widget_t* win = WIDGET(ctx);
|
|
|
|
file_chooser_t* chooser = (file_chooser_t*)(e->target);
|
2020-01-12 20:48:41 +08:00
|
|
|
widget_t* cwd = widget_lookup(win, "cwd", TRUE);
|
|
|
|
widget_t* filename = widget_lookup(win, "filename", TRUE);
|
2020-01-15 10:20:03 +08:00
|
|
|
|
|
|
|
if (file_chooser_is_aborted(chooser)) {
|
2020-01-12 20:48:41 +08:00
|
|
|
widget_set_text_utf8(cwd, "aborted");
|
|
|
|
widget_set_text_utf8(filename, "aborted");
|
|
|
|
} else {
|
2020-01-15 10:20:03 +08:00
|
|
|
widget_set_text_utf8(cwd, file_chooser_get_dir(chooser));
|
2020-01-14 10:07:12 +08:00
|
|
|
if (chooser->filename.str) {
|
2020-01-15 10:20:03 +08:00
|
|
|
widget_set_text_utf8(filename, file_chooser_get_filename(chooser));
|
2020-01-12 21:35:49 +08:00
|
|
|
} else {
|
|
|
|
widget_set_text_utf8(filename, "");
|
|
|
|
}
|
2020-01-12 20:48:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return RET_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ret_t on_file_save(void* ctx, event_t* e) {
|
2020-01-15 17:46:39 +08:00
|
|
|
file_chooser_t* chooser = file_chooser_create();
|
2020-01-15 14:19:33 +08:00
|
|
|
emitter_on(EMITTER(chooser), EVT_DONE, tk_on_choose_file_result, ctx);
|
2020-01-16 17:40:05 +08:00
|
|
|
|
2020-06-04 07:15:24 +08:00
|
|
|
file_chooser_set_init_dir(chooser, "../");
|
2021-04-15 17:11:09 +08:00
|
|
|
file_chooser_set_top_dir(chooser, "../");
|
2020-01-12 20:48:41 +08:00
|
|
|
|
|
|
|
return file_chooser_choose_file_for_save(chooser);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ret_t on_file_open(void* ctx, event_t* e) {
|
2020-01-15 17:46:39 +08:00
|
|
|
file_chooser_t* chooser = file_chooser_create();
|
2020-01-15 14:19:33 +08:00
|
|
|
emitter_on(EMITTER(chooser), EVT_DONE, tk_on_choose_file_result, ctx);
|
2020-01-16 17:40:05 +08:00
|
|
|
|
2020-06-04 07:15:24 +08:00
|
|
|
file_chooser_set_init_dir(chooser, "src");
|
|
|
|
file_chooser_set_filter(chooser, ".c.h.cpp.inc");
|
2020-01-12 20:48:41 +08:00
|
|
|
|
|
|
|
return file_chooser_choose_file_for_open(chooser);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ret_t on_choose_folder(void* ctx, event_t* e) {
|
2020-01-15 17:46:39 +08:00
|
|
|
file_chooser_t* chooser = file_chooser_create();
|
2020-01-12 20:48:41 +08:00
|
|
|
return_value_if_fail(chooser != NULL, RET_OOM);
|
2020-01-15 14:19:33 +08:00
|
|
|
emitter_on(EMITTER(chooser), EVT_DONE, tk_on_choose_file_result, ctx);
|
2020-01-12 20:48:41 +08:00
|
|
|
|
2020-01-15 17:46:39 +08:00
|
|
|
file_chooser_set_init_dir(chooser, "./");
|
|
|
|
|
2020-01-12 20:48:41 +08:00
|
|
|
return file_chooser_choose_folder(chooser);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ret_t on_manager(void* ctx, event_t* e) {
|
2020-01-15 17:46:39 +08:00
|
|
|
file_chooser_t* chooser = file_chooser_create();
|
2020-01-12 20:48:41 +08:00
|
|
|
return_value_if_fail(chooser != NULL, RET_OOM);
|
2020-01-15 14:19:33 +08:00
|
|
|
emitter_on(EMITTER(chooser), EVT_DONE, tk_on_choose_file_result, ctx);
|
2020-01-16 17:40:05 +08:00
|
|
|
|
2020-01-15 17:46:39 +08:00
|
|
|
file_chooser_set_init_dir(chooser, "./");
|
2020-01-12 20:48:41 +08:00
|
|
|
|
|
|
|
return file_chooser_choose_folder(chooser);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret_t application_init() {
|
|
|
|
widget_t* win = NULL;
|
2020-01-15 15:37:12 +08:00
|
|
|
window_open("system_bar");
|
2020-01-12 20:48:41 +08:00
|
|
|
|
|
|
|
win = window_open("file_browser");
|
|
|
|
|
|
|
|
widget_child_on(win, "file_save", EVT_CLICK, on_file_save, win);
|
|
|
|
widget_child_on(win, "file_open", EVT_CLICK, on_file_open, win);
|
|
|
|
widget_child_on(win, "folder", EVT_CLICK, on_choose_folder, win);
|
|
|
|
widget_child_on(win, "manager", EVT_CLICK, on_manager, win);
|
|
|
|
widget_child_on(win, "quit", EVT_CLICK, on_quit, win);
|
|
|
|
|
|
|
|
return RET_OK;
|
|
|
|
}
|
2020-03-19 11:11:32 +08:00
|
|
|
|
|
|
|
ret_t application_exit() {
|
|
|
|
log_debug("application_exit\n");
|
|
|
|
return RET_OK;
|
|
|
|
}
|
|
|
|
|
2020-05-22 18:30:13 +08:00
|
|
|
#ifdef WITH_FS_RES
|
|
|
|
#define APP_DEFAULT_FONT "default_full"
|
2020-05-24 19:23:42 +08:00
|
|
|
#endif /*WITH_FS_RES*/
|
2020-05-22 18:30:13 +08:00
|
|
|
|
2020-03-19 11:11:32 +08:00
|
|
|
#include "awtk_main.inc"
|