Fix focus in location if starting up with a Blank page

At the point of loading the first page the web view
hasn't loaded anything, so we need to manually focus
the Location if the page is blank.

Incidentally midori_browser_activate_action can activate
any action, so it will probably be much more useful
in the future.
This commit is contained in:
Christian Dywan 2008-04-25 21:31:57 +02:00
parent 62cbafe12a
commit a580cf281b
3 changed files with 38 additions and 4 deletions

View file

@ -456,7 +456,7 @@ int main(int argc, char** argv)
"signal::delete-event", midori_browser_delete_event_cb, browsers, "signal::delete-event", midori_browser_delete_event_cb, browsers,
"signal::quit", midori_browser_quit_cb, browsers, "signal::quit", midori_browser_quit_cb, browsers,
NULL); NULL);
browsers = g_list_prepend(browsers, browser); browsers = g_list_prepend (browsers, browser);
gtk_widget_show (GTK_WIDGET (browser)); gtk_widget_show (GTK_WIDGET (browser));
KatzeXbelItem* session = katze_xbel_folder_new (); KatzeXbelItem* session = katze_xbel_folder_new ();
@ -466,6 +466,10 @@ int main(int argc, char** argv)
KatzeXbelItem* item = katze_xbel_folder_get_nth_item (_session, i); KatzeXbelItem* item = katze_xbel_folder_get_nth_item (_session, i);
midori_browser_append_xbel_item (browser, item); midori_browser_append_xbel_item (browser, item);
} }
// FIXME: Switch to the last active page
KatzeXbelItem* item = katze_xbel_folder_get_nth_item (_session, 0);
if (!strcmp (katze_xbel_bookmark_get_href (item), ""))
midori_browser_activate_action (browser, "Location");
katze_xbel_item_unref (_session); katze_xbel_item_unref (_session);
gtk_main (); gtk_main ();

View file

@ -2797,7 +2797,7 @@ midori_browser_settings_notify (MidoriWebSettings* web_settings,
g_value_get_boolean (&value)); g_value_get_boolean (&value));
else if (!g_object_class_find_property (G_OBJECT_GET_CLASS (web_settings), else if (!g_object_class_find_property (G_OBJECT_GET_CLASS (web_settings),
name)) name))
g_warning("Unexpected setting '%s'", name); g_warning (_("Unexpected setting '%s'"), name);
g_value_unset (&value); g_value_unset (&value);
} }
@ -3070,6 +3070,26 @@ midori_browser_append_uri (MidoriBrowser* browser,
return midori_browser_append_tab (browser, web_view); return midori_browser_append_tab (browser, web_view);
} }
/**
* midori_browser_activate_action:
* @browser: a #MidoriBrowser
* @name: name of the action
*
* Activates the specified action.
**/
void
midori_browser_activate_action (MidoriBrowser* browser,
const gchar* name)
{
MidoriBrowserPrivate* priv = browser->priv;
GtkAction* action = _action_by_name (browser, name);
if (action)
gtk_action_activate (action);
else
g_warning (_("Unexpected action '%s'."), name);
}
/** /**
* midori_browser_set_current_page: * midori_browser_set_current_page:
* @browser: a #MidoriBrowser * @browser: a #MidoriBrowser
@ -3086,8 +3106,14 @@ midori_browser_set_current_page (MidoriBrowser* browser,
MidoriBrowserPrivate* priv = browser->priv; MidoriBrowserPrivate* priv = browser->priv;
gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook), n); gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook), n);
GtkWidget* widget = midori_browser_get_current_page (browser); GtkWidget* scrolled = gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook), n);
if (widget) GtkWidget* widget = _midori_browser_child_for_scrolled (browser, scrolled);
printf ("_nth_page: %s\n", G_OBJECT_CLASS_NAME (G_OBJECT_GET_CLASS (widget)));
if (widget && MIDORI_IS_WEB_VIEW (widget)
&& !strcmp (midori_web_view_get_display_uri (
MIDORI_WEB_VIEW (widget)), ""))
gtk_widget_grab_focus (priv->location);
else
gtk_widget_grab_focus (widget); gtk_widget_grab_focus (widget);
} }

View file

@ -76,6 +76,10 @@ gint
midori_browser_append_uri (MidoriBrowser* browser, midori_browser_append_uri (MidoriBrowser* browser,
const gchar* uri); const gchar* uri);
void
midori_browser_activate_action (MidoriBrowser* browser,
const gchar* name);
void void
midori_browser_set_current_page (MidoriBrowser* browser, midori_browser_set_current_page (MidoriBrowser* browser,
gint n); gint n);