From 827e944ea016a75c1d0d94965992b0523903cf9f Mon Sep 17 00:00:00 2001 From: Peter Williams Date: Tue, 14 Aug 2001 22:27:42 +0000 Subject: YESS! 2001-07-12 Peter Williams * e-msg-composer.c (map_default_cb): New function. Figure out which widget gets the default and assign it. Harder to do than it sounds. (e_msg_composer_construct): Hook map_default_cb up to the "map" signal. (set_focus_to_editor): Removed. (set_focus_to_editor_idle): Removed. svn path=/trunk/; revision=12037 --- composer/ChangeLog | 10 ++++++++ composer/e-msg-composer.c | 62 ++++++++++++++++++++++++++++++++--------------- 2 files changed, 53 insertions(+), 19 deletions(-) (limited to 'composer') diff --git a/composer/ChangeLog b/composer/ChangeLog index 5286653640..165219cf29 100644 --- a/composer/ChangeLog +++ b/composer/ChangeLog @@ -1,3 +1,13 @@ +2001-07-12 Peter Williams + + * e-msg-composer.c (map_default_cb): New function. Figure out + which widget gets the default and assign it. Harder to do than + it sounds. + (e_msg_composer_construct): Hook map_default_cb up to the "map" + signal. + (set_focus_to_editor): Removed. + (set_focus_to_editor_idle): Removed. + 2001-08-10 Jon Trowbridge * e-msg-composer-hdrs.c (set_recipients): Removed comment about diff --git a/composer/e-msg-composer.c b/composer/e-msg-composer.c index 622c18ecb4..9bc2390fd4 100644 --- a/composer/e-msg-composer.c +++ b/composer/e-msg-composer.c @@ -62,6 +62,7 @@ #include #include #include +#include #include #include "widgets/misc/e-charset-picker.h" @@ -239,24 +240,6 @@ e_msg_composer_clear_inlined_table (EMsgComposer *composer) g_hash_table_foreach_remove (composer->inline_images, clear_inline_images, NULL); } -static guint -set_focus_to_editor_idle (EMsgComposer *composer) -{ - CORBA_Environment ev; - - CORBA_exception_init (&ev); - GNOME_GtkHTML_Editor_Engine_runCommand (composer->editor_engine, "grab-focus", &ev); - CORBA_exception_free (&ev); - - return FALSE; -} - -static inline void -set_focus_to_editor (EMsgComposer *composer) -{ - gtk_idle_add (set_focus_to_editor_idle, composer); -} - static void add_inlined_image (gpointer key, gpointer value, gpointer data) { @@ -2271,6 +2254,47 @@ e_msg_composer_get_visible_flags (EMsgComposer *composer) return flags; } + +static void +map_default_cb (EMsgComposer *composer, gpointer user_data) +{ + GtkWidget *to; + BonoboControlFrame *cf; + Bonobo_PropertyBag pb = CORBA_OBJECT_NIL; + char *text; + CORBA_Environment ev; + + /* If the 'To:' field is empty, focus it (This is ridiculously complicated) */ + + to = e_msg_composer_hdrs_get_to_entry (E_MSG_COMPOSER_HDRS (composer->hdrs)); + cf = bonobo_widget_get_control_frame (BONOBO_WIDGET (to)); + pb = bonobo_control_frame_get_control_property_bag (cf, NULL); + text = bonobo_property_bag_client_get_value_string (pb, "text", NULL); + + if (!text || text[0] == '\0') { + bonobo_control_frame_focus_child (cf, GTK_DIR_TAB_FORWARD); + return; + } + + /* If not, check the subject field */ + + text = e_msg_composer_hdrs_get_subject (E_MSG_COMPOSER_HDRS (composer->hdrs)); + + if (!text || text[0] == '\0') { + GtkWidget *widget; + + widget = e_msg_composer_hdrs_get_subject_entry (E_MSG_COMPOSER_HDRS (composer->hdrs)); + gtk_widget_grab_focus (GTK_WIDGET (E_ENTRY (widget)->canvas)); + return; + } + + /* Jump to the editor as a last resort. */ + + CORBA_exception_init (&ev); + GNOME_GtkHTML_Editor_Engine_runCommand (composer->editor_engine, "grab-focus", &ev); + CORBA_exception_free (&ev); +} + /** * e_msg_composer_construct: * @composer: A message composer widget @@ -2369,7 +2393,7 @@ e_msg_composer_construct (EMsgComposer *composer) e_msg_composer_show_attachments (composer, FALSE); prepare_engine (composer); - set_focus_to_editor (composer); + gtk_signal_connect (GTK_OBJECT (composer), "map", map_default_cb, NULL); } static EMsgComposer * -- cgit v1.2.3