Enlightenment CVS committal

Author  : dj2
Project : e17
Module  : libs/ewl

Dir     : e17/libs/ewl/src/lib


Modified Files:
        ewl_filedialog.c ewl_filedialog.h ewl_fileselector.c 
        ewl_fileselector.h 


Log Message:
- make the filedialog work with a multiselect option. You should be able to
  enable/disable this at runtime, otherwise there is an
  ewl_filedialog_multiselect_new() to use it from scratch.

- there is no on-screen display of the mutiple selections (there isn't
  onscreen display of a single selection either)

- only does open dialogs, not save

===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_filedialog.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -3 -r1.2 -r1.3
--- ewl_filedialog.c    28 Mar 2005 07:04:28 -0000      1.2
+++ ewl_filedialog.c    28 May 2005 19:01:41 -0000      1.3
@@ -9,6 +9,25 @@
 #include <string.h>
 
 /**
+ * @return Returns a new open filedialog if successful, NULL on failure.
+ * @brief Create a new open filedialog
+ */
+Ewl_Widget *ewl_filedialog_multiselect_new(void)
+{
+       Ewl_Widget *fd;
+
+       DENTER_FUNCTION(DLEVEL_STABLE);
+
+       fd = ewl_filedialog_new(EWL_FILEDIALOG_TYPE_OPEN);
+       if (!fd) {
+               DRETURN_PTR(NULL, DLEVEL_STABLE);
+       }
+       ewl_filedialog_multiselect_set(EWL_FILEDIALOG(fd), TRUE);
+
+       DRETURN_PTR(EWL_WIDGET(fd), DLEVEL_STABLE);
+}
+
+/**
  * @param type: type of dialog to display
  * @return Returns a new filedialog in success, NULL on failure.
  * @brief Create a new filedialog
@@ -142,6 +161,56 @@
        DLEAVE_FUNCTION(DLEVEL_STABLE);
 }
 
+/**
+ * @param fd: the filedialog
+ * @param val: 1 to set multiselect, 0 otherwise
+ * @return Returns no value.
+ * @brief Sets the dialog to multiselect or single select
+ */
+void ewl_filedialog_multiselect_set(Ewl_Filedialog *fd, unsigned int val)
+{
+       DENTER_FUNCTION(DLEVEL_STABLE);
+       DCHECK_PARAM_PTR("fd", fd);
+
+       ewl_fileselector_multiselect_set(EWL_FILESELECTOR(fd->fs), val);
+
+       DLEAVE_FUNCTION(DLEVEL_STABLE);
+}
+
+/**
+ * @param fd: the filedialog
+ * @return Returns the multi select setting (0|1)
+ * @brief gets the multiselect setting of the filedialog
+ */
+unsigned int ewl_filedialog_multiselect_get(Ewl_Filedialog *fd)
+{
+       unsigned int val;
+
+       DENTER_FUNCTION(DLEVEL_STABLE);
+       DCHECK_PARAM_PTR_RET("fd", fd, 0);
+
+       val = ewl_fileselector_multiselect_get(EWL_FILESELECTOR(fd->fs));
+
+       DRETURN_INT(val, DLEVEL_STABLE);        
+}
+
+/**
+ * @param fd: The filedialog
+ * @return Returns an Ecore_List of selected items
+ * @brief returns all the elements selected by the user
+ */
+Ecore_List *ewl_filedialog_select_list_get(Ewl_Filedialog *fd)
+{
+       Ecore_List *list;
+
+       DENTER_FUNCTION(DLEVEL_STABLE);
+       DCHECK_PARAM_PTR_RET("fd", fd, NULL);
+
+       list = ewl_fileselector_select_list_get(EWL_FILESELECTOR(fd->fs));
+
+       DRETURN_PTR(list, DLEVEL_STABLE);
+}
+
 /*
  * Internally used callback, override at your own risk.
  */
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_filedialog.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -3 -r1.2 -r1.3
--- ewl_filedialog.h    9 Feb 2005 20:44:12 -0000       1.2
+++ ewl_filedialog.h    28 May 2005 19:01:41 -0000      1.3
@@ -42,19 +42,25 @@
  */
 struct Ewl_Filedialog
 {
-       Ewl_Box     box; /**< the overlay containing the fileselector */
-       Ewl_Widget    *fs;     /**< Ewl_Fileselector */
+       Ewl_Box        box; /**< the overlay containing the fileselector */
+       Ewl_Widget    *fs; /**< Ewl_Fileselector */
 };
 
 
-Ewl_Widget *ewl_filedialog_new      (Ewl_Filedialog_Type type);
+Ewl_Widget *ewl_filedialog_multiselect_new(void);
+Ewl_Widget *ewl_filedialog_new(Ewl_Filedialog_Type type);
 
-int         ewl_filedialog_init     (Ewl_Filedialog *fd, 
-                                           Ewl_Filedialog_Type type);
-char       *ewl_filedialog_path_get (Ewl_Filedialog *fd);
-char       *ewl_filedialog_file_get (Ewl_Filedialog *fd);
-void        ewl_filedialog_path_set (Ewl_Filedialog *fd,
-                                            char   *path);
+int         ewl_filedialog_init(Ewl_Filedialog *fd, 
+                                            Ewl_Filedialog_Type type);
+char       *ewl_filedialog_path_get(Ewl_Filedialog *fd);
+char       *ewl_filedialog_file_get(Ewl_Filedialog *fd);
+void        ewl_filedialog_path_set(Ewl_Filedialog *fd, char *path);
+
+void        ewl_filedialog_multiselect_set(Ewl_Filedialog *fd, 
+                                            unsigned int val);
+unsigned int ewl_filedialog_multiselect_get(Ewl_Filedialog *fd);
+
+Ecore_List *ewl_filedialog_select_list_get(Ewl_Filedialog *fd);
 
 /*
  * Internally used callbacks, override at your own risk.
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_fileselector.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -3 -r1.12 -r1.13
--- ewl_fileselector.c  27 Apr 2005 14:01:27 -0000      1.12
+++ ewl_fileselector.c  28 May 2005 19:01:41 -0000      1.13
@@ -33,6 +33,8 @@
 static void ewl_fileselector_file_data_cleanup_cb(Ewl_Widget *entry, 
                                        void *ev_data, void *user_data);
 
+static void ewl_fileselector_files_free_cb(void *data);
+
 /**
  * @return Returns NULL on failure, or the new fileselector on success.
  * @brief Create a new fileselector
@@ -44,8 +46,9 @@
        DENTER_FUNCTION(DLEVEL_STABLE);
 
        fs = NEW(Ewl_Fileselector, 1);
-       if (!fs)
+       if (!fs) {
                DRETURN_PTR(NULL, DLEVEL_STABLE);
+       }
 
        if (!ewl_fileselector_init(fs)) {
                FREE(fs);
@@ -109,7 +112,6 @@
                ewl_container_child_prepend(EWL_CONTAINER(hbox),
                                            fs->entry_dir);
                ewl_widget_show(fs->entry_dir);
-               // ewl_object_custom_w_set(EWL_OBJECT(fs->entry_dir), 200);
 
                misc = ewl_spacer_new();
                ewl_container_child_append(EWL_CONTAINER(hbox), misc);
@@ -213,6 +215,9 @@
        tmp = getenv("HOME");
        fs->path = strdup((tmp ? tmp : "/"));
 
+       fs->files = ecore_list_new();
+       ecore_list_set_free_cb(fs->files, ewl_fileselector_files_free_cb);
+
        DRETURN_INT(TRUE, DLEVEL_STABLE);
 }
 
@@ -240,21 +245,27 @@
  */
 char *ewl_fileselector_file_get(Ewl_Fileselector * fs)
 {
-       char *entry_file;
-
        DENTER_FUNCTION(DLEVEL_STABLE);
        DCHECK_PARAM_PTR_RET("fs", fs, NULL);
 
-       entry_file = ewl_entry_text_get(EWL_ENTRY(fs->entry_file));
-       IF_FREE(fs->file);
-       fs->file = entry_file;
+       if (ecore_list_is_empty(fs->files)) {
+               char *entry_file;
+
+               entry_file = ewl_entry_text_get(EWL_ENTRY(fs->entry_file));
+               if (entry_file && fs->path) {
+                       char *f2;
+
+                       f2 = ewl_fileselector_str_append(fs->path, entry_file);
+                       ecore_list_append(fs->files, f2);
+                       FREE(entry_file);
+               }
+       }
 
-       if (!fs->file || !fs->path) {
+       if (ecore_list_is_empty(fs->files)) {
                DRETURN_PTR(NULL, DLEVEL_STABLE);
        }
-       entry_file = ewl_fileselector_str_append(fs->path, fs->file);
 
-       DRETURN_PTR(entry_file, DLEVEL_STABLE);
+       DRETURN_PTR(ecore_list_goto_first(fs->files), DLEVEL_STABLE);
 }
 
 /**
@@ -277,6 +288,50 @@
        DLEAVE_FUNCTION(DLEVEL_STABLE);
 }
 
+/**
+ * @param fs: The fileselector
+ * @param val: Set selector multiselect (0|1)
+ * @return Returns no value
+ * @brief Sets the selector multi or single select
+ */
+void ewl_fileselector_multiselect_set(Ewl_Fileselector *fs, 
+                                               unsigned int val)
+{
+       DENTER_FUNCTION(DLEVEL_STABLE);
+       DCHECK_PARAM_PTR("fs", fs);
+
+       if (val > 1) val = 1;
+       fs->multi_select = val;
+               
+       DLEAVE_FUNCTION(DLEVEL_STABLE);
+}
+
+/**
+ * @param fs: The fileselector
+ * @return Returns the multiselect status of the selector
+ * @brief Gets the multiselect status of the selector
+ */
+unsigned int ewl_fileselector_multiselect_get(Ewl_Fileselector *fs)
+{
+       DENTER_FUNCTION(DLEVEL_STABLE);
+       DCHECK_PARAM_PTR_RET("fs", fs, 0);
+
+       DRETURN_INT(fs->multi_select, DLEVEL_STABLE);
+}
+
+/**
+ * @param fs: The fileselector
+ * @return Returns the selections
+ * @brief Returns the files selected in the selector
+ */
+Ecore_List *ewl_fileselector_select_list_get(Ewl_Fileselector *fs)
+{
+       DENTER_FUNCTION(DLEVEL_STABLE);
+       DCHECK_PARAM_PTR_RET("fs", fs, NULL);
+
+       DRETURN_PTR(fs->files, DLEVEL_STABLE);
+}
+
 /*
  * Internally used functions
  */
@@ -530,7 +585,7 @@
 {
        Ewl_Fileselector *fs = EWL_FILESELECTOR(w);
        IF_FREE(fs->path);
-       IF_FREE(fs->file);
+       ecore_list_destroy(fs->files);
        IF_FREE(fs->dfilter);
 }
 
@@ -546,15 +601,49 @@
 void ewl_fileselector_select_file_cb(Ewl_Widget *w,
                                        void *ev_data __UNUSED__, void *data)
 {
+       Ewl_Event_Mouse_Up *ev;
        Ewl_Fileselector *fs;
        char *name = NULL;
+       char *full_name = NULL;
 
+       ev = ev_data;
        fs = data;
        name = ewl_widget_data_get(w, "FILESELECTOR_FILE");
 
-       IF_FREE(fs->file);
-       fs->file = strdup(name);
-       ewl_entry_text_set(EWL_ENTRY(fs->entry_file), name);
+       full_name = ewl_fileselector_str_append(fs->path, name);
+       if (!full_name) {
+               DLEAVE_FUNCTION(DLEVEL_STABLE);
+       }
+
+       if ((fs->multi_select) && (ev->modifiers & EWL_KEY_MODIFIER_CTRL)) {
+               int i, found = 0;
+
+               for (i = 0; i < ecore_list_nodes(fs->files); i++) {
+                       char *cur;
+
+                       /* see if this selection is already in the list and
+                        * remove if so */
+                       cur = ecore_list_goto_index(fs->files, i);
+                       if (!strcmp(cur, full_name))
+                       {
+                               ecore_list_remove(fs->files);
+                               found = 1;
+                               break;
+                       }
+               }
+               if (!found) ecore_list_append(fs->files, full_name);
+       } else {
+               ecore_list_clear(fs->files);
+               ecore_list_append(fs->files, full_name);
+       }
+
+       /* only set the name if there is a single selection */
+       if (ecore_list_nodes(fs->files) == 1)
+               ewl_entry_text_set(EWL_ENTRY(fs->entry_file), name);
+       else
+               ewl_entry_text_set(EWL_ENTRY(fs->entry_file), "");
+
+       DLEAVE_FUNCTION(DLEVEL_STABLE);
 }
 
 void ewl_fileselector_select_dir_cb(Ewl_Widget *w, void *ev_data __UNUSED__,
@@ -619,6 +708,9 @@
        ewl_container_reset(EWL_CONTAINER(fs->list_files));
        ewl_entry_text_set(EWL_ENTRY(fs->entry_file), "");
 
+       /* clear the selection list */
+       ecore_list_clear(fs->files);
+
        /*
         * Setup a regex for matching files.
         */
@@ -634,7 +726,6 @@
        }
 
        fs->path = path2;
-       fs->file = NULL;
        ewl_entry_text_set(EWL_ENTRY(fs->entry_dir), path2);
 
        files = ecore_list_new();
@@ -800,3 +891,15 @@
        v = ewl_widget_data_get(w, "FILESELECTOR_DIR");
        IF_FREE(v);
 }
+
+static void
+ewl_fileselector_files_free_cb(void *data)
+{
+       char *v;
+
+       v = data;
+       IF_FREE(v);
+}
+
+
+
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/lib/ewl_fileselector.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -3 -r1.7 -r1.8
--- ewl_fileselector.h  27 Apr 2005 14:01:28 -0000      1.7
+++ ewl_fileselector.h  28 May 2005 19:01:41 -0000      1.8
@@ -46,11 +46,11 @@
        Ewl_Widget    *entry_filter;
   
        char          *path;    /* current fileselector path */
-       char          *file;    /* current selected item in the fileselector */
+       Ecore_List    *files;   /* current selected items in the fileselector */
        char          *dfilter; /* current filter to apply to directories */
+       unsigned int   multi_select; /* is the selector multi select or not */
 };
 
-
 Ewl_Widget     *ewl_fileselector_new();
 int             ewl_fileselector_init(Ewl_Fileselector *fs);
 
@@ -59,6 +59,12 @@
 
 void            ewl_fileselector_path_set(Ewl_Fileselector *fs, char *path);
 
+void            ewl_fileselector_multiselect_set(Ewl_Fileselector *fs, 
+                                                       unsigned int val);
+unsigned int    ewl_fileselector_multiselect_get(Ewl_Fileselector *fs);
+
+Ecore_List     *ewl_fileselector_select_list_get(Ewl_Fileselector *fs);
+
 /*
  * Internally used callbacks, override at your own risk.
  */




-------------------------------------------------------
This SF.Net email is sponsored by Yahoo.
Introducing Yahoo! Search Developer Network - Create apps using Yahoo!
Search APIs Find out how you can build Yahoo! directly into your own
Applications - visit http://developer.yahoo.net/?fr=offad-ysdn-ostg-q22005
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to