[uim-commit] r2956 - trunk/helper
ekato at freedesktop.org
ekato at freedesktop.org
Fri Jan 20 18:57:53 PST 2006
Author: ekato
Date: 2006-01-20 18:57:49 -0800 (Fri, 20 Jan 2006)
New Revision: 2956
Modified:
trunk/helper/pref-gtk-custom-widgets.c
trunk/helper/pref-gtk-custom-widgets.h
Log:
* helper/pref-gtk-custom-widgets.h : Create UimPrefFileEntry
custom widget, which has GtkEntry and filetype attribute.
* helper/pref-gtk-custom-widgets.c : Follow the changes in
uim-custom's pathname structure.
(uimpref_file_entry_get_type) : New for UimPrefFileEntry widget.
(uimpref_file_entry_class_init) : Ditto.
(uimpref_file_entry_init) : Ditto.
(uimpref_file_entry_new) : Ditto.
(custom_entry_changed_cb) : Follow the change in custom pathname
structure.
(sync_value_string) : Ditto.
(custom_pathname_button_clicked_cb) : Ditto. Now distinguish
regular file and directory when opening a dialog.
(add_custom_type_pathname) : Create UimPrefFileEntry instead of
GtkEntry.
(uim_pref_gtk_set_default_value) : Follow the change in custom
pathname structure.
Modified: trunk/helper/pref-gtk-custom-widgets.c
===================================================================
--- trunk/helper/pref-gtk-custom-widgets.c 2006-01-21 01:49:04 UTC (rev 2955)
+++ trunk/helper/pref-gtk-custom-widgets.c 2006-01-21 02:57:49 UTC (rev 2956)
@@ -76,9 +76,55 @@
NULL, NULL, NULL, NULL, NULL, 0, 0,
};
+static void uimpref_file_entry_class_init(UimPrefFileEntryClass *klass);
+static void uimpref_file_entry_init(UimPrefFileEntry *entry);
+GType
+uimpref_file_entry_get_type(void)
+{
+ static GType uimpref_file_entry_type = 0;
+ if (!uimpref_file_entry_type)
+ {
+ static const GTypeInfo uimpref_file_entry_info =
+ {
+ sizeof(UimPrefFileEntryClass),
+ NULL,
+ NULL,
+ (GClassInitFunc)uimpref_file_entry_class_init,
+ NULL,
+ NULL,
+ sizeof(UimPrefFileEntry),
+ 0,
+ (GInstanceInitFunc)uimpref_file_entry_init,
+ };
+
+ uimpref_file_entry_type = g_type_register_static(GTK_TYPE_ENTRY,
+ "UimPrefFileEntry", &uimpref_file_entry_info, 0);
+ }
+
+ return uimpref_file_entry_type;
+}
+
static void
+uimpref_file_entry_class_init(UimPrefFileEntryClass *klass)
+{
+}
+
+static void
+uimpref_file_entry_init(UimPrefFileEntry *entry)
+{
+ entry->type = UCustomPathnameType_RegularFile;
+}
+
+GtkWidget *
+uimpref_file_entry_new()
+{
+ return GTK_WIDGET(g_object_new(uimpref_file_entry_get_type(), NULL));
+}
+
+
+static void
custom_check_button_toggled_cb(GtkToggleButton *button, gpointer user_data)
{
const char *custom_sym;
@@ -295,8 +341,8 @@
custom->value->as_str = strdup(str);
rv = uim_custom_set(custom);
} else if (custom->type == UCustom_Pathname) {
- free(custom->value->as_pathname);
- custom->value->as_pathname = strdup(str);
+ free(custom->value->as_pathname->str);
+ custom->value->as_pathname->str = strdup(str);
rv = uim_custom_set(custom);
} else {
rv = UIM_FALSE;
@@ -334,7 +380,7 @@
if (custom->type == UCustom_Str) {
gtk_entry_set_text(GTK_ENTRY(entry), custom->value->as_str);
} else if (custom->type == UCustom_Pathname) {
- gtk_entry_set_text(GTK_ENTRY(entry), custom->value->as_pathname);
+ gtk_entry_set_text(GTK_ENTRY(entry), custom->value->as_pathname->str);
}
uim_custom_free(custom);
@@ -383,9 +429,20 @@
custom_pathname_button_clicked_cb(GtkWidget *button, GtkWidget *entry)
{
GtkWidget *dialog;
+ GtkFileChooserAction action;
+
+ switch (UIMPREF_FILE_ENTRY(entry)->type) {
+ case UCustomPathnameType_Directory:
+ action = GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER;
+ break;
+ case UCustomPathnameType_RegularFile:
+ default:
+ action = GTK_FILE_CHOOSER_ACTION_OPEN;
+ break;
+ }
dialog = gtk_file_chooser_dialog_new (_("Specify file"),
NULL,
- GTK_FILE_CHOOSER_ACTION_OPEN,
+ action,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
NULL);
@@ -417,7 +474,8 @@
gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
- entry = gtk_entry_new();
+ entry = uimpref_file_entry_new();
+ UIMPREF_FILE_ENTRY(entry)->type = custom->value->as_pathname->type;
gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0);
button = gtk_button_new_with_label(_("File..."));
@@ -1972,8 +2030,9 @@
value->as_str = strdup(defval->as_str);
break;
case UCustom_Pathname:
- free(value->as_pathname);
- value->as_pathname = strdup(defval->as_pathname);
+ free(value->as_pathname->str);
+ value->as_pathname->str = strdup(defval->as_pathname->str);
+ value->as_pathname->type = defval->as_pathname->type;
break;
case UCustom_Choice:
free(value->as_choice->symbol);
Modified: trunk/helper/pref-gtk-custom-widgets.h
===================================================================
--- trunk/helper/pref-gtk-custom-widgets.h 2006-01-21 01:49:04 UTC (rev 2955)
+++ trunk/helper/pref-gtk-custom-widgets.h 2006-01-21 02:57:49 UTC (rev 2956)
@@ -34,5 +34,33 @@
#include <glib.h>
#include <gtk/gtk.h>
+G_BEGIN_DECLS
+
+#define UIMPREF_FILE_ENTRY_TYPE (uimpref_file_entry_get_type())
+#define UIMPREF_FILE_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), UIMPREF_FILE_ENTRY_TYPE, UimPrefFileEntry))
+#define UIMPREF_FILE_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), UIMPREF_FILE_ENTRY_TYPE, UimPrefFileEntryClass))
+#define IS_UIMPREF_FILE_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), UIMPREF_FILE_ENTRY_TYPE))
+#define IS_UIMPREF_FILE_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), UIMPREF_FILE_ENTRY_TYPE))
+
+typedef struct _UimPrefFileEntry UimPrefFileEntry;
+typedef struct _UimPrefFileEntryClass UimPrefFileEntryClass;
+
+struct _UimPrefFileEntryClass
+{
+ GtkEntryClass parent_class;
+};
+
+struct _UimPrefFileEntry
+{
+ GtkEntry entry;
+ int type;
+};
+
+GType uimpref_file_entry_get_type(void);
+GtkWidget *uimpref_file_entry_new(void);
+
+G_END_DECLS
+
+
void uim_pref_gtk_add_custom(GtkWidget *vbox, const char *custom_sym);
void uim_pref_gtk_set_default_value(GtkWidget *widget);
More information about the uim-commit
mailing list