file selection filtering in filesel.
- From: Todd Dukes <tdukes ibmoto com>
- To: gtk <gtk-list redhat com>
- Subject: file selection filtering in filesel.
- Date: Fri, 15 Jan 1999 13:07:38 -0600
I would like to apply the following patch to the cvs repository
if no-one has any problmes with it.
It is the gtk-rbock-981208-0.patch with a little extra patch
I put on top of it. I also changed the testgtk filesel test
to just update the file list if there are any '*' or '?'
characters in the filename when the ok button is clicked.
Let me know if there is any problem with this.
thanks,
Todd.
--
==============================================================
| Todd Dukes E-MAIL: tdukes@ibmoto.com |
| Motorola Somerset Phone: (512) 424-8008 |
| MS OE70 |
| 6300 Bridgepoint Parkway Building #3 |
| Austin, Texas 78730 |
==============================================================
*** gtkfilesel.c.990114 Fri Jan 15 12:01:39 1999
--- gtkfilesel.c Fri Jan 15 12:02:18 1999
***************
*** 304,309 ****
--- 304,311 ----
GdkEventButton *bevent,
gpointer data);
+ static gboolean gtk_file_selection_filtered (GtkFileSelection *fs,
+ gchar *filename);
static void gtk_file_selection_populate (GtkFileSelection *fs,
gchar *rel_path,
gint try_complete);
***************
*** 493,498 ****
--- 495,503 ----
gtk_box_pack_start (GTK_BOX (entry_vbox), filesel->selection_entry, TRUE, TRUE, 0);
gtk_widget_show (filesel->selection_entry);
+ filesel->filter=NULL;
+ filesel->numfilter=0;
+
if (!cmpl_state_okay (filesel->cmpl_state))
{
gchar err_buf[256];
***************
*** 1070,1082 ****
}
static gint
gtk_file_selection_key_press (GtkWidget *widget,
GdkEventKey *event,
gpointer user_data)
{
GtkFileSelection *fs;
- char *text;
g_return_val_if_fail (widget != NULL, FALSE);
g_return_val_if_fail (event != NULL, FALSE);
--- 1075,1096 ----
}
+ void
+ gtk_file_selection_update_filter( GtkFileSelection *filesel)
+ {
+ char *text;
+ text = gtk_entry_get_text (GTK_ENTRY (filesel->selection_entry));
+ text = g_strdup (text);
+ gtk_file_selection_populate (filesel, text, TRUE);
+ g_free (text);
+ }
+
static gint
gtk_file_selection_key_press (GtkWidget *widget,
GdkEventKey *event,
gpointer user_data)
{
GtkFileSelection *fs;
g_return_val_if_fail (widget != NULL, FALSE);
g_return_val_if_fail (event != NULL, FALSE);
***************
*** 1084,1097 ****
if (event->keyval == GDK_Tab)
{
fs = GTK_FILE_SELECTION (user_data);
! text = gtk_entry_get_text (GTK_ENTRY (fs->selection_entry));
!
! text = g_strdup (text);
!
! gtk_file_selection_populate (fs, text, TRUE);
!
! g_free (text);
!
gtk_signal_emit_stop_by_name (GTK_OBJECT (widget), "key_press_event");
return TRUE;
--- 1098,1104 ----
if (event->keyval == GDK_Tab)
{
fs = GTK_FILE_SELECTION (user_data);
! gtk_file_selection_update_filter(fs);
gtk_signal_emit_stop_by_name (GTK_OBJECT (widget), "key_press_event");
return TRUE;
***************
*** 1279,1284 ****
--- 1286,1321 ----
}
}
+ void gtk_file_selection_set_filter (GtkFileSelection *filesel,
+ gchar **filter,
+ gint numfilter)
+ {
+ gint i;
+
+ if (filesel->numfilter) {
+ for (i=0; i<filesel->numfilter; i++) g_free(filesel->filter[i]);
+ }
+ g_free(filesel->filter);
+ filesel->filter=(gchar **) g_malloc(numfilter*sizeof(gchar *));
+ for (i=0; i<numfilter; i++) {
+ filesel->filter[i]=g_strdup(filter[i]);
+ }
+ filesel->numfilter=numfilter;
+ gtk_file_selection_populate (filesel, "", FALSE);
+ }
+
+ static gboolean
+ gtk_file_selection_filtered(GtkFileSelection *fs, gchar *filename)
+ {
+ gint i=0;
+
+ for (i=0; i<fs->numfilter; i++)
+ if (!fnmatch(fs->filter[i], filename, 0))
+ return TRUE;
+
+ return FALSE;
+ }
+
static void
gtk_file_selection_populate (GtkFileSelection *fs,
gchar *rel_path,
***************
*** 1357,1363 ****
}
}
}
! else
{
int width = gdk_string_width(fs->file_list->style->font,
filename);
--- 1394,1401 ----
}
}
}
! else
! if (!fs->filter || gtk_file_selection_filtered(fs, filename))
{
int width = gdk_string_width(fs->file_list->style->font,
filename);
*** gtkfilesel.h.990114 Fri Jan 15 12:01:49 1999
--- gtkfilesel.h Fri Jan 15 12:02:27 1999
***************
*** 65,70 ****
--- 65,72 ----
GtkWidget *button_area;
GtkWidget *action_area;
+ gchar **filter;
+ gint numfilter;
};
***************
*** 83,90 ****
const gchar *pattern);
void gtk_file_selection_show_fileop_buttons (GtkFileSelection *filesel);
void gtk_file_selection_hide_fileop_buttons (GtkFileSelection *filesel);
!
!
#ifdef __cplusplus
}
#endif /* __cplusplus */
--- 85,95 ----
const gchar *pattern);
void gtk_file_selection_show_fileop_buttons (GtkFileSelection *filesel);
void gtk_file_selection_hide_fileop_buttons (GtkFileSelection *filesel);
! void gtk_file_selection_set_filter (GtkFileSelection *filesel,
! gchar **filter,
! gint numfilter);
! /* this updates the file list */
! void gtk_file_selection_update_filter (GtkFileSelection *filesel);
#ifdef __cplusplus
}
#endif /* __cplusplus */
*** testgtk.c.990114 Fri Jan 15 12:02:04 1999
--- testgtk.c Fri Jan 15 12:02:37 1999
***************
*** 5206,5211 ****
--- 5206,5217 ----
file_selection_ok (GtkWidget *w,
GtkFileSelection *fs)
{
+ char * text;
+ text = gtk_file_selection_get_filename(fs);
+ if (strchr(text, '*') || strchr(text, '?')) {
+ gtk_file_selection_update_filter(fs);
+ return;
+ }
g_print ("%s\n", gtk_file_selection_get_filename (fs));
gtk_widget_destroy (GTK_WIDGET (fs));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]