diff --git a/bsp/stm32_radio/filelist.c b/bsp/stm32_radio/filelist.c index 6836475b73..b938796a26 100644 --- a/bsp/stm32_radio/filelist.c +++ b/bsp/stm32_radio/filelist.c @@ -454,19 +454,19 @@ rt_bool_t filelist_view_event_handler(struct rtgui_widget* widget, struct rtgui_ strncpy(new_path, view->current_directory, ptr - view->current_directory + 1); new_path[ptr - view->current_directory] = '\0'; } - rt_kprintf("new path: %s\n", new_path); } else if (view->current_item == 0 && (view->current_directory[0] == '/') && (view->current_directory[1] == '\0')) { - /* exit, close this view */ - rtgui_workbench_t* workbench; + if (RTGUI_VIEW(view)->modal_show == RT_TRUE) + { + rtgui_view_end_modal(RTGUI_VIEW(view), RTGUI_MODAL_CANCEL); + } + else + { + filelist_view_destroy(view); + } - workbench = RTGUI_WORKBENCH(RTGUI_WIDGET(view)->parent); - rtgui_workbench_remove_view(workbench, RTGUI_VIEW(view)); - filelist_view_destroy(view); - - filelist_view = RT_NULL; return RT_FALSE; } else @@ -482,20 +482,9 @@ rt_bool_t filelist_view_event_handler(struct rtgui_widget* widget, struct rtgui_ } else { - if (strstr(view->items[view->current_item].name, ".HDC") != RT_NULL || - strstr(view->items[view->current_item].name, ".hdc") != RT_NULL) + if (RTGUI_VIEW(view)->modal_show == RT_TRUE) { - char new_path[64]; - rtgui_workbench_t* workbench; - - workbench = RTGUI_WORKBENCH(RTGUI_WIDGET(view)->parent); - - if (view->current_directory[strlen(view->current_directory) - 1] != PATH_SEPARATOR) - sprintf(new_path, "%s%c%s",view->current_directory, PATH_SEPARATOR, - view->items[view->current_item].name); - else - sprintf(new_path, "%s%s",view->current_directory, - view->items[view->current_item].name); + rtgui_view_end_modal(RTGUI_VIEW(view), RTGUI_MODAL_OK); } } return RT_FALSE; diff --git a/rtgui/include/rtgui/widgets/view.h b/rtgui/include/rtgui/widgets/view.h index c1ebfa6913..6d8311fc61 100644 --- a/rtgui/include/rtgui/widgets/view.h +++ b/rtgui/include/rtgui/widgets/view.h @@ -38,6 +38,7 @@ struct rtgui_view /* private field */ char* title; + rt_bool_t modal_show; }; typedef struct rtgui_view rtgui_view_t; diff --git a/rtgui/widgets/view.c b/rtgui/widgets/view.c index 59e1b3043d..4c2b5293da 100644 --- a/rtgui/widgets/view.c +++ b/rtgui/widgets/view.c @@ -22,11 +22,24 @@ static void _rtgui_view_constructor(rtgui_view_t *view) rtgui_widget_set_event_handler(RTGUI_WIDGET(view), rtgui_view_event_handler); + view->modal_show = RT_FALSE; view->title = RT_NULL; } static void _rtgui_view_destructor(rtgui_view_t *view) { + /* remove view from workbench */ + if (RTGUI_WIDGET(view)->parent != RT_NULL) + { + rtgui_workbench_t *workbench; + + if (view->modal_show == RT_TRUE) + rtgui_view_end_modal(view, RTGUI_MODAL_CANCEL); + + workbench = RTGUI_WORKBENCH(RTGUI_WIDGET(view)->parent); + rtgui_workbench_remove_view(workbench, view); + } + if (view->title != RT_NULL) { rt_free(view->title);