Enlightenment CVS committal Author : dj2 Project : e17 Module : libs/ewl
Dir : e17/libs/ewl/src/lib Modified Files: ewl_filelist.c ewl_filelist.h ewl_filelist_icon.c ewl_filelist_icon.h ewl_filelist_list.c ewl_filelist_list.h ewl_widget.c ewl_widget.h Log Message: - highlight selected items in the filedialog - handle CTRL multiselection. SHIFT isn't done yet - abstract more stuff out to the filelist from the implementations - minor formatting to a .edc file =================================================================== RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_filelist.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- ewl_filelist.c 11 Apr 2006 21:22:46 -0000 1.2 +++ ewl_filelist.c 14 Apr 2006 19:31:46 -0000 1.3 @@ -185,22 +185,16 @@ void ewl_filelist_selected_file_set(Ewl_Filelist *fl, const char *file) { - Ewl_Filelist_Event ev_data; - DENTER_FUNCTION(DLEVEL_STABLE); DCHECK_PARAM_PTR("fl", fl); DCHECK_TYPE("fl", fl, EWL_FILELIST_TYPE); /* clean out the old set of selected files */ + if (fl->selected_unselect) fl->selected_unselect(fl); ecore_list_clear(fl->selected); + if (fl->selected_file_add) fl->selected_file_add(fl, file); - if (file) ecore_list_append(fl->selected, strdup(file)); - if (fl->selected_files_change) fl->selected_files_change(fl); - - ev_data.type = EWL_FILELIST_EVENT_TYPE_SELECTION_CHANGE; - - ewl_callback_call_with_event_data(EWL_WIDGET(fl), - EWL_CALLBACK_VALUE_CHANGED, &ev_data); + ewl_filelist_selected_files_change_notify(fl); DLEAVE_FUNCTION(DLEVEL_STABLE); } @@ -213,14 +207,16 @@ char * ewl_filelist_selected_file_get(Ewl_Filelist *fl) { - char *file; + void *widget; + const char *file = NULL; DENTER_FUNCTION(DLEVEL_STABLE); DCHECK_PARAM_PTR_RET("fl", fl, NULL); DCHECK_TYPE_RET("fl", fl, EWL_FILELIST_TYPE, 0); ecore_list_goto_first(fl->selected); - file = ecore_list_current(fl->selected); + widget = ecore_list_current(fl->selected); + if (fl->file_name_get) file = fl->file_name_get(fl, widget); DRETURN_PTR((file ? strdup(file) : NULL), DLEVEL_STABLE); } @@ -238,16 +234,18 @@ DENTER_FUNCTION(DLEVEL_STABLE); DCHECK_PARAM_PTR("fl", fl); + DCHECK_PARAM_PTR("files", files); DCHECK_TYPE("fl", fl, EWL_FILELIST_TYPE); /* clean out the old set of selected files */ + if (fl->selected_unselect) fl->selected_unselect(fl); ecore_list_clear(fl->selected); ecore_list_goto_first(files); while ((file = ecore_list_next(files))) - ecore_list_append(fl->selected, file); + if (fl->selected_file_add) fl->selected_file_add(fl, file); - if (fl->selected_files_change) fl->selected_files_change(fl); + ewl_filelist_selected_files_change_notify(fl); DLEAVE_FUNCTION(DLEVEL_STABLE); } @@ -260,11 +258,68 @@ Ecore_List * ewl_filelist_selected_files_get(Ewl_Filelist *fl) { + Ecore_List *selected; + void *item; + DENTER_FUNCTION(DLEVEL_STABLE); DCHECK_PARAM_PTR_RET("fl", fl, NULL); DCHECK_TYPE_RET("fl", fl, EWL_FILELIST_TYPE, NULL); - DRETURN_INT(fl->selected, DLEVEL_STABLE); + selected = ecore_list_new(); + ecore_list_goto_first(fl->selected); + while ((item = ecore_list_next(fl->selected))) + { + const char *file; + file = fl->file_name_get(fl, item); + ecore_list_append(selected, strdup(file)); + } + + DRETURN_INT(selected, DLEVEL_STABLE); +} + +/** + * @param fl: The filelist to work with + * @return Returns no value. + * @brief Notifies interested consumers that the filelist has changed + * selected values + */ +void +ewl_filelist_selected_files_change_notify(Ewl_Filelist *fl) +{ + Ewl_Filelist_Event ev_data; + + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR("fl", fl); + DCHECK_TYPE("fl", fl, EWL_FILELIST_TYPE); + + ev_data.type = EWL_FILELIST_EVENT_TYPE_SELECTION_CHANGE; + ewl_callback_call_with_event_data(EWL_WIDGET(fl), + EWL_CALLBACK_VALUE_CHANGED, &ev_data); + + DLEAVE_FUNCTION(DLEVEL_STABLE); +} + +/** + * @param fl: The filelist to work with + * @param signal: The signal to send + * @return Returns no value + * @brief Signals all of the selected widgets with the given signal + */ +void +ewl_filelist_selected_signal_all(Ewl_Filelist *fl, const char *signal) +{ + Ewl_Widget *item; + + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR("fl", fl); + DCHECK_PARAM_PTR("signal", signal); + DCHECK_TYPE("fl", fl, EWL_FILELIST_TYPE); + + ecore_list_goto_first(fl->selected); + while ((item = ecore_list_next(fl->selected))) + ewl_widget_state_set(item, signal); + + DLEAVE_FUNCTION(DLEVEL_STABLE); } /** @@ -394,6 +449,90 @@ DLEAVE_FUNCTION(DLEVEL_STABLE); } +/** + * @param fl: The filelist to work with + * @param w: The widget that was clicked + * @param select_state: Signal to send to goto select state + * @param unselect_state: Signal to send to goto unselect state + * @return Returns no value. + * @brief Adds or removes the given widget from the select list as needed + */ +void +ewl_filelist_handle_click(Ewl_Filelist *fl, Ewl_Widget *w, + Ewl_Event_Mouse_Up *ev, + const char *select_state, + const char *unselect_state) +{ + Ewl_Widget *last; + int multi = FALSE; + + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR("fl", fl); + DCHECK_PARAM_PTR("w", w); + DCHECK_PARAM_PTR("ev", ev); + DCHECK_TYPE("fl", fl, EWL_FILELIST_TYPE); + DCHECK_TYPE("w", w, EWL_WIDGET_TYPE); + + /* only trigger on lmb */ + if (ev->button != 1) + DRETURN(DLEVEL_STABLE); + + /* are the multiselect keys pressed? */ + if ((ev->modifiers & EWL_KEY_MODIFIER_SHIFT) + || (ev->modifiers & EWL_KEY_MODIFIER_CTRL)) + multi = TRUE; + + /* store and update the last selected widget */ + last = fl->last_selected; + fl->last_selected = w; + + /* we are not in multiselect mode, or the multiselect keys aren't + * pressed */ + if (!ewl_filelist_multiselect_get(fl) || (!multi)) + { + if (fl->selected_unselect) fl->selected_unselect(fl); + ecore_list_clear(fl->selected); + + if (select_state) + ewl_widget_state_set(w, select_state); + + ecore_list_append(fl->selected, w); + ewl_filelist_selected_files_change_notify(fl); + + DRETURN(DLEVEL_STABLE); + } + + /* ok, we're in multiselect mode and either shift or ctrl are + * pressed */ + + if (ev->modifiers & EWL_KEY_MODIFIER_SHIFT) + { + /* XXX Write me .. */ + } + else + { + void *item; + + item = ecore_list_goto(fl->selected, w); + if (item) + { + if (unselect_state) + ewl_widget_state_set(w, unselect_state); + + ecore_list_remove(fl->selected); + } + else + { + if (select_state) + ewl_widget_state_set(w, select_state); + + ecore_list_append(fl->selected, w); + } + } + + DLEAVE_FUNCTION(DLEVEL_STABLE); +} + void ewl_filelist_cb_destroy(Ewl_Widget *w, void *ev, void *data) { @@ -413,7 +552,9 @@ fl->filter_change = NULL; fl->multiselect_change = NULL; fl->show_dot_change = NULL; - fl->selected_files_change = NULL; + fl->selected_file_add = NULL; + fl->file_name_get = NULL; + fl->selected_unselect = NULL; DLEAVE_FUNCTION(DLEVEL_STABLE); } =================================================================== RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_filelist.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- ewl_filelist.h 10 Apr 2006 04:48:21 -0000 1.2 +++ ewl_filelist.h 14 Apr 2006 19:31:46 -0000 1.3 @@ -39,6 +39,9 @@ unsigned char multiselect:1; /**< Allow multiple file selctions */ unsigned char show_dot_files:1; /**< Show . files */ + Ewl_Widget *last_selected; /**< The last selected icon */ + Ewl_Widget *base_selected; /**< First select in SHIFT select */ + void (*dir_change)(Ewl_Filelist *fl); /**< Callback to notify of directory change */ void (*filter_change)(Ewl_Filelist *fl); /**< Callback to notify @@ -49,10 +52,16 @@ void (*show_dot_change)(Ewl_Filelist *fl); /**< Callback to notify of show dot file setting change */ - void (*selected_files_change)(Ewl_Filelist *fl); /**< Callback to + void (*selected_unselect)(Ewl_Filelist *fl); /**< Callback to + unselect all files */ + void (*selected_file_add)(Ewl_Filelist *fl, const char *file); /**< + Callback to notify of a change to the selected files */ + const char *(*file_name_get)(Ewl_Filelist *fl, void *file); /**< + Callback to get the + selected filename */ }; int ewl_filelist_init(Ewl_Filelist *fl); @@ -80,12 +89,20 @@ void ewl_filelist_selected_files_set(Ewl_Filelist *fl, Ecore_List *files); Ecore_List *ewl_filelist_selected_files_get(Ewl_Filelist *fl); +void ewl_filelist_selected_files_change_notify(Ewl_Filelist *fl); + +void ewl_filelist_selected_signal_all(Ewl_Filelist *fl, + const char *signal); char *ewl_filelist_expand_path(Ewl_Filelist *fl, const char *dir); void ewl_filelist_directory_read(Ewl_Filelist *fl, void (*func)(Ewl_Filelist *fl, const char *dir, char *file)); +void ewl_filelist_handle_click(Ewl_Filelist *fl, Ewl_Widget *w, + Ewl_Event_Mouse_Up *ev, + const char *select_state, + const char *unselect_state); /* * Internally used functions, override at your own risk =================================================================== RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_filelist_icon.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- ewl_filelist_icon.c 11 Apr 2006 16:15:56 -0000 1.2 +++ ewl_filelist_icon.c 14 Apr 2006 19:31:46 -0000 1.3 @@ -78,7 +78,9 @@ list->dir_change = ewl_filelist_icon_dir_change; list->filter_change = ewl_filelist_icon_dir_change; list->show_dot_change = ewl_filelist_icon_dir_change; - list->selected_files_change = ewl_filelist_icon_selected_files_change; + list->selected_file_add = ewl_filelist_icon_selected_file_add; + list->file_name_get = ewl_filelist_icon_filename_get; + list->selected_unselect = ewl_filelist_icon_selected_unselect; fl->freebox = ewl_vfreebox_new(); ewl_container_child_append(EWL_CONTAINER(fl), fl->freebox); @@ -113,10 +115,50 @@ * @brief The callback to notify of selected files changing */ void -ewl_filelist_icon_selected_files_change(Ewl_Filelist *fl) +ewl_filelist_icon_selected_file_add(Ewl_Filelist *fl, const char *file) { DENTER_FUNCTION(DLEVEL_STABLE); DCHECK_PARAM_PTR("fl", fl); + DCHECK_PARAM_PTR("file", file); + DCHECK_TYPE("fl", fl, EWL_FILELIST_TYPE); + + DLEAVE_FUNCTION(DLEVEL_STABLE); +} + +/** + * @param fl: The filelist to work with + * @param item: The item to get the name from + * @return Returns the filename for the given item + * @brief Retrieves the filename for the given item + */ +const char * +ewl_filelist_icon_filename_get(Ewl_Filelist *fl, void *item) +{ + Ewl_Icon *icon; + + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR_RET("fl", fl, NULL); + DCHECK_PARAM_PTR_RET("item", item, NULL); + DCHECK_TYPE_RET("fl", fl, EWL_FILELIST_TYPE, NULL); + + icon = EWL_ICON(item); + + DRETURN_PTR(ewl_icon_label_get(icon), DLEVEL_STABLE); +} + +/** + * @param fl: The filelist to work with + * @return Returns no value. + * @brief This will set all of the icons back to their unselected state + */ +void +ewl_filelist_icon_selected_unselect(Ewl_Filelist *fl) +{ + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR("fl", fl); + DCHECK_TYPE("fl", fl, EWL_FILELIST_TYPE); + + ewl_filelist_selected_signal_all(fl, "icon,unselect"); DLEAVE_FUNCTION(DLEVEL_STABLE); } @@ -152,23 +194,14 @@ static void ewl_filelist_icon_cb_icon_clicked(Ewl_Widget *w, void *ev, void *data) { - Ewl_Filelist_Icon *fl; - Ewl_Icon *icon; - Ewl_Event_Mouse_Up *event; - DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR("w", w); + DCHECK_PARAM_PTR("ev", ev); + DCHECK_PARAM_PTR("data", data); + DCHECK_TYPE("w", w, EWL_WIDGET_TYPE); - icon = EWL_ICON(w); - fl = data; - event = ev; - - /* only trigger on lmb */ - if (event->button != 1) - DRETURN(DLEVEL_STABLE); - - /* XXX need to deal with SHIFT modifier and multiselect here */ - ewl_filelist_selected_file_set(EWL_FILELIST(fl), - ewl_icon_label_get(icon)); + ewl_filelist_handle_click(EWL_FILELIST(data), w, ev, + "icon,select", "icon,unselect"); DLEAVE_FUNCTION(DLEVEL_STABLE); } =================================================================== RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_filelist_icon.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- ewl_filelist_icon.h 10 Apr 2006 04:48:21 -0000 1.2 +++ ewl_filelist_icon.h 14 Apr 2006 19:31:46 -0000 1.3 @@ -40,7 +40,11 @@ int ewl_filelist_icon_init(Ewl_Filelist_Icon *fl); void ewl_filelist_icon_dir_change(Ewl_Filelist *fl); -void ewl_filelist_icon_selected_files_change(Ewl_Filelist *fl); +void ewl_filelist_icon_selected_file_add(Ewl_Filelist *fl, + const char *file); +const char *ewl_filelist_icon_filename_get(Ewl_Filelist *fl, + void *item); +void ewl_filelist_icon_selected_unselect(Ewl_Filelist *fl); /** * @} =================================================================== RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_filelist_list.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -3 -r1.1 -r1.2 --- ewl_filelist_list.c 10 Apr 2006 04:43:17 -0000 1.1 +++ ewl_filelist_list.c 14 Apr 2006 19:31:46 -0000 1.2 @@ -82,7 +82,9 @@ list->dir_change = ewl_filelist_list_dir_change; list->filter_change = ewl_filelist_list_dir_change; list->show_dot_change = ewl_filelist_list_dir_change; - list->selected_files_change = ewl_filelist_list_selected_files_change; + list->selected_file_add = ewl_filelist_list_selected_file_add; + list->file_name_get = ewl_filelist_list_filename_get; + list->selected_unselect = ewl_filelist_list_selected_unselect; fl->tree = ewl_tree_new(6); ewl_tree_headers_set(EWL_TREE(fl->tree), headers); @@ -118,11 +120,51 @@ * @brief Callback when the selected files are changed */ void -ewl_filelist_list_selected_files_change(Ewl_Filelist *fl) +ewl_filelist_list_selected_file_add(Ewl_Filelist *fl, const char *file) { DENTER_FUNCTION(DLEVEL_STABLE); DCHECK_PARAM_PTR("fl", fl); + /* XXX Write me ... */ + + DLEAVE_FUNCTION(DLEVEL_STABLE); +} + +/** + * @param fl: The filelist to work with + * @param item: The item to get the name from + * @return Returns the filename for the given item + * @brief Retrieves the filename for the given item + */ +const char * +ewl_filelist_list_filename_get(Ewl_Filelist *fl, void *item) +{ + Ewl_Widget *o; + + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR_RET("fl", fl, NULL); + DCHECK_PARAM_PTR_RET("item", item, NULL); + DCHECK_TYPE_RET("fl", fl, EWL_FILELIST_TYPE, NULL); + + o = ewl_tree_row_column_get(EWL_ROW(item), 0); + + DRETURN_PTR(ewl_label_text_get(EWL_LABEL(o)), DLEVEL_STABLE); +} + +/** + * @param fl: The filelist to work with + * @return Returns no value. + * @brief This will set all of the rows back to their unselected state + */ +void +ewl_filelist_list_selected_unselect(Ewl_Filelist *fl) +{ + DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR("fl", fl); + DCHECK_TYPE("fl", fl, EWL_FILELIST_TYPE); + + ewl_filelist_selected_signal_all(fl, "row,unselect"); + DLEAVE_FUNCTION(DLEVEL_STABLE); } @@ -290,24 +332,14 @@ static void ewl_filelist_list_cb_icon_clicked(Ewl_Widget *w, void *ev, void *data) { - Ewl_Widget *o; - Ewl_Filelist_List *fl; - Ewl_Event_Mouse_Up *event; - DENTER_FUNCTION(DLEVEL_STABLE); + DCHECK_PARAM_PTR("w", w); + DCHECK_PARAM_PTR("ev", ev); + DCHECK_PARAM_PTR("data", data); + DCHECK_TYPE("w", w, EWL_WIDGET_TYPE); - o = ewl_tree_row_column_get(EWL_ROW(w), 0); - fl = data; - event = ev; - - /* only trigger on lmb */ - if (event->button != 1) - DRETURN(DLEVEL_STABLE); - - /* XXX need to deal with SHIFT modifier and multiselect here - or push up to ewl_filelist? */ - ewl_filelist_selected_file_set(EWL_FILELIST(fl), - ewl_label_text_get(EWL_LABEL(o))); + ewl_filelist_handle_click(EWL_FILELIST(data), w, ev, + "row,select", "row,unselect"); DLEAVE_FUNCTION(DLEVEL_STABLE); } =================================================================== RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_filelist_list.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- ewl_filelist_list.h 10 Apr 2006 04:48:21 -0000 1.2 +++ ewl_filelist_list.h 14 Apr 2006 19:31:47 -0000 1.3 @@ -40,7 +40,11 @@ int ewl_filelist_list_init(Ewl_Filelist_List *fl); void ewl_filelist_list_dir_change(Ewl_Filelist *fl); -void ewl_filelist_list_selected_files_change(Ewl_Filelist *fl); +void ewl_filelist_list_selected_file_add(Ewl_Filelist *fl, + const char *file); +const char *ewl_filelist_list_filename_get(Ewl_Filelist *fl, + void *item); +void ewl_filelist_list_selected_unselect(Ewl_Filelist *fl); /** * @} =================================================================== RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_widget.c,v retrieving revision 1.71 retrieving revision 1.72 diff -u -3 -r1.71 -r1.72 --- ewl_widget.c 12 Apr 2006 05:07:14 -0000 1.71 +++ ewl_widget.c 14 Apr 2006 19:31:47 -0000 1.72 @@ -677,7 +677,7 @@ * the state parameter. */ void -ewl_widget_state_set(Ewl_Widget *w, char *state) +ewl_widget_state_set(Ewl_Widget *w, const char *state) { DENTER_FUNCTION(DLEVEL_STABLE); DCHECK_PARAM_PTR("w", w); =================================================================== RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_widget.h,v retrieving revision 1.39 retrieving revision 1.40 diff -u -3 -r1.39 -r1.40 --- ewl_widget.h 12 Apr 2006 05:07:14 -0000 1.39 +++ ewl_widget.h 14 Apr 2006 19:31:47 -0000 1.40 @@ -167,7 +167,7 @@ void *ewl_widget_data_del(Ewl_Widget * w, void *k); void *ewl_widget_data_get(Ewl_Widget * w, void *k); -void ewl_widget_state_set(Ewl_Widget * w, char *state); +void ewl_widget_state_set(Ewl_Widget * w, const char *state); void ewl_widget_appearance_set(Ewl_Widget * w, char *appearance); char *ewl_widget_appearance_get(Ewl_Widget * w); ------------------------------------------------------- This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory! http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642 _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs