Skip to content

Commit

Permalink
improve file dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
xianjimli committed Jan 2, 2024
1 parent c29391c commit f895def
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
3 changes: 2 additions & 1 deletion docs/changes.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# 最新动态

2024/01/02
* 更新软件版权日期。
* 增加函数 tokenizer\_next\_str\_until
* widget 增加 widget->vt 的空指针检查。
* 修复tk\_is\_pointer\_pressed接口在处理鼠标抬起事件过程中返回值错误的问题(感谢雨欣提供补丁)
* 修复文档拼写错误(感谢雨欣提供补丁)
* 更新软件版权日期。
* 修复NFD关闭后误触发awtk窗口内的其他事件(感谢兆坤提供补丁)

2024/01/01
* 文件浏览支持变量。
Expand Down
33 changes: 33 additions & 0 deletions src/ext_widgets/file_browser/file_dialog.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,31 @@
#ifdef WITH_NATIVE_FILE_DIALOG
#include "../3rd/nativefiledialog/src/include/nfd.h"

static ret_t tk_choose_restore_window_manager_ignore_input_events(const idle_info_t* idle) {
window_manager_set_ignore_input_events(window_manager(), FALSE);
return RET_REMOVE;
}

/* 忽略本帧内的输入事件,避免出现关闭nfd后误触发awtk窗口内的其他事件(如在nfd里双击选择文件) */
static ret_t tk_choose_window_manager_ignore_input_events(void) {
ret_t ret = RET_OK;
window_manager_t* wm = WINDOW_MANAGER(window_manager());
return_value_if_fail(wm != NULL, RET_FAIL);

if (!wm->ignore_input_events) {
ret = window_manager_set_ignore_input_events(wm, TRUE);
if (RET_OK == ret) {
uint32_t id = idle_add(tk_choose_restore_window_manager_ignore_input_events, wm);
ret = (id != TK_INVALID_ID) ? RET_OK : RET_FAIL;
if (RET_OK != ret) {
window_manager_set_ignore_input_events(wm, FALSE);
}
}
}

return ret;
}

static const char* filters_to_nfd(const char* filters, str_t* str) {
str_set(str, filters);
str_replace(str, ".", ",");
Expand All @@ -48,6 +73,8 @@ static darray_t* tk_choose_files_native(const char* filters, const char* init_di
result = NFD_OpenDialogMultiple(filters_to_nfd(filters, &str), init_dir, &pathSet);
str_reset(&str);

tk_choose_window_manager_ignore_input_events();

if (result == NFD_OKAY) {
size_t i = 0;
size_t n = NFD_PathSet_GetCount(&pathSet);
Expand Down Expand Up @@ -75,6 +102,8 @@ static char* tk_choose_file_native(const char* filters, const char* init_dir) {
nfdresult_t result = NFD_OpenDialog(filters_to_nfd(filters, &str), init_dir, &outPath);
str_reset(&str);

tk_choose_window_manager_ignore_input_events();

if (result == NFD_OKAY) {
char* ret = tk_strdup(outPath);
log_debug("%s\n", outPath);
Expand All @@ -93,6 +122,8 @@ static char* tk_choose_folder_native(const char* init_dir) {
nfdchar_t* outPath = NULL;
nfdresult_t result = NFD_PickFolder(init_dir, &outPath);

tk_choose_window_manager_ignore_input_events();

if (result == NFD_OKAY) {
char* ret = tk_strdup(outPath);
log_debug("%s\n", outPath);
Expand All @@ -116,6 +147,8 @@ static char* tk_choose_file_for_save_native(const char* filters, const char* ini
result = NFD_SaveDialog(filters_to_nfd(filters, &str), init_dir, &outPath);
str_reset(&str);

tk_choose_window_manager_ignore_input_events();

if (result == NFD_OKAY) {
char* ret = tk_strdup(outPath);
log_debug("%s\n", outPath);
Expand Down

0 comments on commit f895def

Please sign in to comment.