Enlightenment CVS committal
Author : jethomas
Project : e17
Module : libs/ewl
Dir : e17/libs/ewl/src/lib
Modified Files:
ewl_filedialog.c ewl_filedialog.h ewl_filepicker.c
ewl_filepicker.h
Log Message:
The filepicker can now act as an open or save as type. Includes a patch from
shragei to show the relative path for files.
===================================================================
RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_filedialog.c,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -3 -r1.43 -r1.44
--- ewl_filedialog.c 26 Feb 2008 04:35:58 -0000 1.43
+++ ewl_filedialog.c 13 Apr 2008 18:02:34 -0000 1.44
@@ -579,4 +579,86 @@
DLEAVE_FUNCTION(DLEVEL_STABLE);
}
+/**
+ * @param fd: The filedialog to work with
+ * @t: Non-zero to set the filedialog to a save type
+ * @return Returns no value
+ * @brief Sets the type of the filedialog
+ */
+void
+ewl_filedialog_save_as_set(Ewl_Filedialog *fd, unsigned int t)
+{
+ DENTER_FUNCTION(DLEVEL_STABLE);
+ DCHECK_PARAM_PTR(fd);
+ DCHECK_TYPE(fd, EWL_FILEDIALOG_TYPE);
+
+ ewl_filepicker_save_as_set(EWL_FILEPICKER(fd->fp), t);
+ DLEAVE_FUNCTION(DLEVEL_STABLE);
+}
+
+/**
+ * @param fd: The filedialog to work with
+ * @return Returns non-zero if the filedialog is currently a Save As type
+ * @brief Gets the current type fo the filedialog
+ */
+unsigned int
+ewl_filedialog_save_as_get(Ewl_Filedialog *fd)
+{
+ DENTER_FUNCTION(DLEVEL_STABLE);
+ DCHECK_PARAM_PTR_RET(fd, FALSE);
+ DCHECK_TYPE_RET(fd, EWL_FILEDIALOG_TYPE, FALSE);
+
+ DRETURN_INT(ewl_filepicker_save_as_get(EWL_FILEPICKER(fd->fp)),
+ DLEVEL_STABLE);
+}
+
+/**
+ * @param fd: The filedialog to work with
+ * @param t: Non-zero to allow the filedialog to open directories
+ * @return Returns no value
+ * @brief Sets the filedialog's policy on returning directories
+ */
+void
+ewl_filedialog_return_directories_set(Ewl_Filedialog *fd, unsigned int t)
+{
+ DENTER_FUNCTION(DLEVEL_STABLE);
+ DCHECK_PARAM_PTR(fd);
+ DCHECK_TYPE(fd, EWL_FILEDIALOG_TYPE);
+
+ ewl_filepicker_return_directories_set(EWL_FILEPICKER(fd->fp), t);
+ DLEAVE_FUNCTION(DLEVEL_STABLE);
+}
+
+/**
+ * @param fp: The filedialog to work with
+ * @return Returns non-zero if the filedialog can return directories
+ * @brief Gets the filedialog's policy on returning directories
+ */
+unsigned int
+ewl_filedialog_return_directories_get(Ewl_Filedialog *fd)
+{
+ DENTER_FUNCTION(DLEVEL_STABLE);
+ DCHECK_PARAM_PTR_RET(fd, FALSE);
+ DCHECK_TYPE_RET(fd, EWL_FILEDIALOG_TYPE, FALSE);
+
+ DRETURN_INT(ewl_filepicker_return_directories_get
+ (EWL_FILEPICKER(fd->fp)), DLEVEL_STABLE);
+}
+
+/**
+ * @return Returns a created Save As dialog widget or NULL on failure
+ * @brief A convenience function to create a Save As dialog widget
+ */
+Ewl_Widget *
+ewl_filedialog_save_as_new(void)
+{
+ Ewl_Widget *ret;
+
+ DENTER_FUNCTION(DLEVEL_STABLE);
+
+ ret = ewl_filedialog_new();
+ ewl_filedialog_save_as_set(EWL_FILEDIALOG(ret), TRUE);
+
+ DRETURN_PTR(ret, DLEVEL_STABLE);
+}
===================================================================
RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_filedialog.h,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -3 -r1.24 -r1.25
--- ewl_filedialog.h 9 Dec 2007 04:33:39 -0000 1.24
+++ ewl_filedialog.h 13 Apr 2008 18:02:34 -0000 1.25
@@ -91,6 +91,13 @@
const char *name,
const char *filter,
Ecore_List *mime_types);
+void ewl_filedialog_save_as_set(Ewl_Filedialog *fd,
+ unsigned int t);
+unsigned int ewl_filedialog_save_as_get(Ewl_Filedialog *fd);
+void ewl_filedialog_return_directories_set(Ewl_Filedialog *fd,
+ unsigned int t);
+unsigned int ewl_filedialog_return_directories_get(Ewl_Filedialog *fd);
+Ewl_Widget *ewl_filedialog_save_as_new(void);
/*
* Internally used callbacks, override at your own risk.
===================================================================
RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_filepicker.c,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -3 -r1.50 -r1.51
--- ewl_filepicker.c 12 Apr 2008 18:59:26 -0000 1.50
+++ ewl_filepicker.c 13 Apr 2008 18:02:34 -0000 1.51
@@ -65,6 +65,7 @@
unsigned int col);
static void ewl_filepicker_filter_free_cb(Ewl_Filelist_Filter *filter);
+static void ewl_filepicker_type_change(Ewl_Filepicker *fp);
/**
@@ -108,6 +109,7 @@
if (!ewl_box_init(EWL_BOX(fp)))
DRETURN_INT(FALSE, DLEVEL_STABLE);
+ fp->ret_dir = TRUE;
ewl_box_orientation_set(EWL_BOX(fp), EWL_ORIENTATION_VERTICAL);
ewl_widget_inherit(EWL_WIDGET(fp), EWL_FILEPICKER_TYPE);
ewl_widget_appearance_set(EWL_WIDGET(fp), EWL_FILEPICKER_TYPE);
@@ -197,7 +199,6 @@
fp->file_entry = ewl_entry_new();
ewl_container_child_append(EWL_CONTAINER(box), fp->file_entry);
-
ewl_widget_show(fp->file_entry);
fp->filters = ecore_list_new();
@@ -235,14 +236,14 @@
ewl_object_fill_policy_set(EWL_OBJECT(box), EWL_FLAG_FILL_SHRINK);
ewl_widget_show(box);
- o = ewl_button_new();
- ewl_container_child_append(EWL_CONTAINER(box), o);
- ewl_stock_type_set(EWL_STOCK(o), EWL_STOCK_OK);
- ewl_callback_append(o, EWL_CALLBACK_CLICKED,
+ fp->ret_button = ewl_button_new();
+ ewl_container_child_append(EWL_CONTAINER(box), fp->ret_button);
+ ewl_stock_type_set(EWL_STOCK(fp->ret_button), EWL_STOCK_OPEN);
+ ewl_callback_append(fp->ret_button, EWL_CALLBACK_CLICKED,
ewl_filepicker_cb_button_clicked, fp);
- ewl_object_fill_policy_set(EWL_OBJECT(o),
+ ewl_object_fill_policy_set(EWL_OBJECT(fp->ret_button),
EWL_FLAG_FILL_HFILL | EWL_FLAG_FILL_VSHRINK);
- ewl_widget_show(o);
+ ewl_widget_show(fp->ret_button);
o = ewl_button_new();
ewl_container_child_append(EWL_CONTAINER(box), o);
@@ -262,6 +263,120 @@
}
/**
+ * @return Returns a created Save As widget or NULL on failure
+ * @brief A convenience function to create a Save As widget
+ */
+Ewl_Widget *
+ewl_filepicker_save_as_new(void)
+{
+ Ewl_Widget *ret;
+
+ DENTER_FUNCTION(DLEVEL_STABLE);
+
+ ret = ewl_filepicker_new();
+ ewl_filepicker_save_as_set(EWL_FILEPICKER(ret), TRUE);
+
+ DRETURN_PTR(ret, DLEVEL_STABLE);
+}
+
+/**
+ * @internal
+ * @param fp: The filepicker to change the type of
+ * @return Returns no value
+ * @brief Changes the filepicker to either an open or save as type
+ */
+static void
+ewl_filepicker_type_change(Ewl_Filepicker *fp)
+{
+ DENTER_FUNCTION(DLEVEL_STABLE);
+ DCHECK_PARAM_PTR(fp);
+ DCHECK_TYPE(fp, EWL_FILEPICKER_TYPE);
+
+ if (fp->saveas_dialog)
+ {
+ ewl_widget_enable(fp->file_entry);
+ ewl_stock_type_set(EWL_STOCK(fp->ret_button), EWL_STOCK_SAVE);
+ }
+ else
+ {
+ if (ewl_filelist_multiselect_get(EWL_FILELIST(fp->file_list)))
+ ewl_widget_disable(fp->file_entry);
+ ewl_stock_type_set(EWL_STOCK(fp->ret_button), EWL_STOCK_OPEN);
+ }
+
+ DLEAVE_FUNCTION(DLEVEL_STABLE);
+}
+
+/**
+ * @param fp: The filepicker to work with
+ * @param t: Non-zero to set the filepicker to a save type
+ * @return Returns no value
+ * @brief Sets the type for the filepicker
+ */
+void
+ewl_filepicker_save_as_set(Ewl_Filepicker *fp, unsigned int t)
+{
+ DENTER_FUNCTION(DLEVEL_STABLE);
+ DCHECK_PARAM_PTR(fp);
+ DCHECK_TYPE(fp, EWL_FILEPICKER_TYPE);
+
+ if (fp->saveas_dialog == t)
+ DRETURN(DLEVEL_STABLE);
+
+ fp->saveas_dialog = !!t;
+ ewl_filepicker_type_change(fp);
+
+ DLEAVE_FUNCTION(DLEVEL_STABLE);
+}
+
+/**
+ * @param fp: The filepicker to work with
+ * @return Returns non-zero if the filepicker is currently a Save As type
+ * @brief Gets the current type of the filepicker
+ */
+unsigned int
+ewl_filepicker_save_as_get(Ewl_Filepicker *fp)
+{
+ DENTER_FUNCTION(DLEVEL_STABLE);
+ DCHECK_PARAM_PTR_RET(fp, FALSE);
+ DCHECK_TYPE_RET(fp, EWL_FILEPICKER_TYPE, FALSE);
+
+ DRETURN_INT(fp->saveas_dialog, DLEVEL_STABLE);
+}
+
+/**
+ * @param fp: The filepicker to work with
+ * @param t: Non-zero to allow the filepicker to open directories
+ * @return Returns no value
+ * @brief Sets the filepicker's policy on returning directories
+ */
+void
+ewl_filepicker_return_directories_set(Ewl_Filepicker *fp, unsigned int t)
+{
+ DENTER_FUNCTION(DLEVEL_STABLE);
+ DCHECK_PARAM_PTR(fp);
+ DCHECK_TYPE(fp, EWL_FILEPICKER_TYPE);
+
+ fp->ret_dir = !!t;
+ DLEAVE_FUNCTION(DLEVEL_STABLE);
+}
+
+/**
+ * @param fp: The filepicker to work with
+ * @return Returns non-zero if the filepicker can return directories
+ * @brief Gets the filepicker's policy on returning directories
+ */
+unsigned int
+ewl_filepicker_return_directories_get(Ewl_Filepicker *fp)
+{
+ DENTER_FUNCTION(DLEVEL_STABLE);
+ DCHECK_PARAM_PTR_RET(fp, FALSE);
+ DCHECK_TYPE_RET(fp, EWL_FILEPICKER_TYPE, FALSE);
+
+ DRETURN_INT(fp->ret_dir, DLEVEL_STABLE);
+}
+
+/**
* @param fp: The filepicker to change
* @param show: The show favorites setting to apply
* @return Returns no value
@@ -532,13 +647,15 @@
/**
* @param fp: The filepicker to get the selected file from
- * @return Returns the currently selected file in the filepicker
+ * @return Returns the full path of the currently selected file in the
filepicker
* @brief Retrieves the currently selected file from the filepicker
*/
char *
ewl_filepicker_selected_file_get(Ewl_Filepicker *fp)
{
- char *file;
+ char *file, *ret;
+ const char *dir;
+ size_t len, dir_len, file_len;
DENTER_FUNCTION(DLEVEL_STABLE);
DCHECK_PARAM_PTR_RET(fp, NULL);
@@ -549,9 +666,40 @@
* selected array from the file list */
file = ewl_text_text_get(EWL_TEXT(fp->file_entry));
if (!file)
- file =
ewl_filelist_selected_file_get(EWL_FILELIST(fp->file_list));
+ ret =
ewl_filelist_selected_file_get(EWL_FILELIST(fp->file_list));
+ else
+ {
+ dir = ewl_filelist_directory_get(EWL_FILELIST(fp->file_list));
+ file_len = strlen(file);
+ if (file_len)
+ {
+ if (file[0] != '/')
+ {
+ dir_len = strlen(dir);
+ if (dir_len == 1)
+ dir_len = 0;
+ len = dir_len + file_len + 2;
+ ret = NEW(char, len);
+ strcat(ret, dir);
+ if (dir_len > 1)
+ strcat(ret, "/");
+ strcat(ret, file);
+ }
+ else
+ {
+ ret = file;
+ file = NULL;
+ }
+ }
+ else
+ ret = NULL;
+ }
- DRETURN_PTR(file, DLEVEL_STABLE);
+ IF_FREE(file);
+ if ((!fp->ret_dir) && (ret) && (ecore_file_is_dir(ret)))
+ FREE(ret);
+
+ DRETURN_PTR(ret, DLEVEL_STABLE);
}
/**
@@ -642,7 +790,6 @@
e = ev;
/* clear the text and get the selected file */
- ewl_text_clear(EWL_TEXT(fp->file_entry));
file = ewl_filelist_selected_file_get(fl);
if (e->response == EWL_FILELIST_EVENT_DIR_CHANGE)
@@ -656,20 +803,47 @@
ewl_widget_disable(fp->dir_button);
else
ewl_widget_enable(fp->dir_button);
-
+ ewl_text_clear(EWL_TEXT(fp->file_entry));
FREE(dir);
}
- else if ((e->response == EWL_FILELIST_EVENT_SELECTION_CHANGE) &&
- (!fl->multiselect))
- ewl_text_text_set(EWL_TEXT(fp->file_entry), file);
+ else if (e->response == EWL_FILELIST_EVENT_SELECTION_CHANGE)
+ {
+ if (ecore_file_is_dir(file))
+ {
+ if ((!fp->saveas_dialog) && (!fl->multiselect) &&
+ (fp->ret_dir))
+ ewl_text_text_set(EWL_TEXT(fp->file_entry),
+ file);
+ }
+ else
+ {
+ if (!fl->multiselect)
+ ewl_text_text_set(EWL_TEXT(fp->file_entry),
+ ecore_file_file_get(file));
+ }
+ }
- else if (e->response == EWL_FILELIST_EVENT_MULTI_TRUE)
- ewl_widget_disable(EWL_WIDGET(fp->file_entry));
+ else if ((e->response == EWL_FILELIST_EVENT_MULTI_TRUE) &&
+ (!fp->saveas_dialog))
+ {
+ ewl_widget_disable(fp->file_entry);
+ ewl_text_clear(EWL_TEXT(fp->file_entry));
+ }
- else if (e->response == EWL_FILELIST_EVENT_MULTI_FALSE)
+ else if ((e->response == EWL_FILELIST_EVENT_MULTI_FALSE) &&
+ (!fp->saveas_dialog))
{
- ewl_widget_enable(EWL_WIDGET(fp->file_entry));
- ewl_text_text_set(EWL_TEXT(fp->file_entry), file);
+ if ((ecore_file_is_dir(file)) && (fp->ret_dir))
+ {
+ ewl_text_text_set(EWL_TEXT(fp->file_entry),
+ file);
+ }
+ else
+ {
+ ewl_text_text_set(EWL_TEXT(fp->file_entry),
+ ecore_file_file_get(file));
+ }
+ ewl_widget_enable(fp->file_entry);
}
FREE(file);
===================================================================
RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_filepicker.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -3 -r1.17 -r1.18
--- ewl_filepicker.h 12 Apr 2008 18:59:26 -0000 1.17
+++ ewl_filepicker.h 13 Apr 2008 18:02:34 -0000 1.18
@@ -56,6 +56,7 @@
Ewl_Widget *favorites_box; /**< Favoirte directory box */
Ewl_Widget *path_combo; /**< Path combo box */
Ewl_Widget *dir_button; /**< Button to create a directory */
+ Ewl_Widget *ret_button; /**< The save/open button */
Ecore_List *path; /**< The path components */
Ecore_List *filters; /**< The type filters */
@@ -68,6 +69,9 @@
} mvc_filters, mvc_path;
unsigned char show_favorites:1; /**< Show the favorite box */
+ unsigned char saveas_dialog:1; /**< Open or save dialog */
+ unsigned char ret_dir:1; /**< Allow directories to be returned */
+
};
Ewl_Widget *ewl_filepicker_new(void);
@@ -78,7 +82,7 @@
const char *ewl_filepicker_directory_get(Ewl_Filepicker *fp);
void ewl_filepicker_filter_set(Ewl_Filepicker *fp,
- Ewl_Filelist_Filter
*filter);
+ Ewl_Filelist_Filter *filter);
Ewl_Filelist_Filter *ewl_filepicker_filter_get(Ewl_Filepicker *fp);
void ewl_filepicker_multiselect_set(Ewl_Filepicker *fp,
@@ -109,6 +113,13 @@
const char *name,
const char *extension,
Ecore_List *mime_types);
+void ewl_filepicker_save_as_set(Ewl_Filepicker *fp,
+ unsigned int t);
+unsigned int ewl_filepicker_save_as_get(Ewl_Filepicker *fp);
+void ewl_filepicker_return_directories_set(Ewl_Filepicker *fp,
+ unsigned int t);
+unsigned int ewl_filepicker_return_directories_get(Ewl_Filepicker *fp);
+Ewl_Widget *ewl_filepicker_save_as_new(void);
/**
* @}
*/
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
enlightenment-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs