GNOME File Selector Developer Documentation | ||
---|---|---|
<<< Previous | Next >>> |
To actually do anything with your new GNOME File Selector, you will need to get its event source. This is done via the standard Bonobo::Unknown::queryInterface() method.
Example 2. Querying for the Bonobo::EventSource
Bonobo_EventSource es; Bonobo_Unknown corba_control; corba_control = bonobo_widget_get_objref (BONOBO_WIDGET (control)); es = Bonobo_Unknown_queryInterface (corba_control, "IDL:Bonobo/EventSource:1.0", ev); |
When the user clicks either the Ok or Cancel button, the GNOME File Selector emits a ButtonClicked event. To get notified of these events, you need to create a Bonobo::Listener and connect it to the previous EventSource.
Example 3. Listening to ButtonClicked Events
BonoboListener *listener; Bonobo_Listener corba_listener; Bonobo_EventSource es; Bonobo_EventSource_ListenerId id; listener = bonobo_listener_new (listener_cb, data); corba_listener = BONOBO_OBJREF (listener); id = Bonobo_EventSource_addListenerWithMask (es, corba_listener, "GNOME/FileSelector:ButtonClicked", ev); |
The subtype for this event is either Action or Cancel, depending on which button was clicked. If the action button was clicked, the data for this event is a CORBA_sequence_CORBA_string (basically a char **) listing the files which were selected by the user when the action button was clicked.
Example 4. Handling ButtonClicked Events
static void listener_cb (BonoboListener *listener, const char *event_name, const CORBA_any *any, CORBA_Environment *ev, gpointer data) { const CORBA_sequence_CORBA_string *seq; const char *subtype; int i; subtype = bonobo_event_subtype (event_name); if (!strcmp (subtype, "Action")) { seq = any->_value; for (i = 0; i < seq->_length; i++) { g_print ("user selected: %s\n", seq->_buffer[i]); /* code to open file */ } } else { /* code to close/hide the window */ } g_free (subtype); } |
It is pretty easy - no appending files onto directories or interacting with GtkCLists.
<<< Previous | Home | Next >>> |
Creating a GNOME File Selector | Properties |