~ubuntu-branches/ubuntu/saucy/epiphany-browser/saucy

« back to all changes in this revision

Viewing changes to src/ephy-window.c

  • Committer: Package Import Robot
  • Author(s): Sebastien Bacher
  • Date: 2012-12-03 17:43:05 UTC
  • mfrom: (129.1.1 quantal-proposed)
  • Revision ID: package-import@ubuntu.com-20121203174305-k0ri214j3x0tb7k1
Tags: 3.6.1-0ubuntu2
Upload to raring

Show diffs side-by-side

added added

removed removed

Lines of Context:
98
98
 
99
99
        /* File actions. */
100
100
 
 
101
        { "FileNewWindow", NULL, N_("_New Window"), "<control>N", NULL,
 
102
          G_CALLBACK (window_cmd_file_new_window) },
101
103
        { "FileOpen", NULL, N_("_Open…"), "<control>O", NULL,
102
104
          G_CALLBACK (window_cmd_file_open) },
103
105
        { "FileSaveAs", NULL, N_("Save _As…"), "<shift><control>S", NULL,
110
112
          G_CALLBACK (window_cmd_file_send_to) },
111
113
        { "FileCloseTab", NULL, N_("_Close"), "<control>W", NULL,
112
114
          G_CALLBACK (window_cmd_file_close_window) },
 
115
        { "FileQuit", NULL, N_("_Quit"), "<control>Q", NULL,
 
116
          G_CALLBACK (window_cmd_file_quit) },
113
117
 
114
118
        /* Edit actions. */
115
119
 
133
137
          G_CALLBACK (window_cmd_edit_find_next) },
134
138
        { "EditFindPrev", NULL, N_("Find Pre_vious"), "<shift><control>G", NULL,
135
139
          G_CALLBACK (window_cmd_edit_find_prev) },
 
140
        { "EditBookmarks", NULL, N_("_Bookmarks"), "<control>B", NULL,
 
141
          G_CALLBACK (window_cmd_edit_bookmarks) },
 
142
        { "EditHistory", NULL, N_("_History"), "<control>H", NULL,
 
143
          G_CALLBACK (window_cmd_edit_history) },
 
144
        { "EditPreferences", NULL, N_("Preferences"), "<control>e", NULL,
 
145
          G_CALLBACK (window_cmd_edit_preferences) },
 
146
        { "EditPersonalData", NULL, N_("Personal Data"), "<control>m", NULL,
 
147
          G_CALLBACK (window_cmd_edit_personal_data) },
136
148
 
137
149
        /* View actions. */
138
150
 
174
186
          G_CALLBACK (window_cmd_tabs_move_right) },
175
187
        { "TabsDetach", NULL, N_("_Detach Tab"), NULL, NULL,
176
188
          G_CALLBACK (window_cmd_tabs_detach) },
 
189
 
 
190
        /* Help. */
 
191
 
 
192
        { "HelpAbout", NULL, N_("_About"), NULL, NULL,
 
193
          G_CALLBACK (window_cmd_help_about) }
177
194
};
178
195
 
179
196
static const GtkToggleActionEntry ephy_menu_toggle_entries [] =
261
278
        /* FIXME: PageMenu should have its accel without being in the
262
279
         * extra keybindings, but does not seem to work for some
263
280
         * reason. */
264
 
        { GDK_KEY_e,            GDK_MOD1_MASK,          "PageMenu",              TRUE },
 
281
        { GDK_KEY_F10,          0,                      "PageMenu",              TRUE },
265
282
        { GDK_KEY_Home,         GDK_MOD1_MASK,          "FileHome",              TRUE },
266
283
        /* FIXME: these are not in any menu for now, so add them here. */
267
284
        { GDK_KEY_F11,          0,                      "ViewFullscreen",        FALSE },
354
371
        EphyLocationController *location_controller;
355
372
 
356
373
        gulong set_focus_handler;
 
374
        gulong app_menu_visibility_handler;
357
375
 
358
376
        guint closing : 1;
359
377
        guint has_size : 1;
970
988
ephy_window_delete_event (GtkWidget *widget,
971
989
                          GdkEventAny *event)
972
990
{
973
 
        EphyWindow *window = EPHY_WINDOW (widget);
974
 
        EphySession *session;
975
 
        EphyEmbed *modified_embed = NULL;
976
 
        GList *tabs, *l, *windows;
977
 
        guint number_windows;
978
 
        gboolean modified = FALSE;
979
 
 
980
 
        /* We ignore the delete_event if the disable_quit lockdown has been set
981
 
         */
982
 
        if (g_settings_get_boolean (EPHY_SETTINGS_LOCKDOWN,
983
 
                                    EPHY_PREFS_LOCKDOWN_QUIT)) return TRUE;
984
 
 
985
 
        tabs = impl_get_children (EPHY_EMBED_CONTAINER (window));
986
 
        for (l = tabs; l != NULL; l = l->next)
987
 
        {
988
 
                EphyEmbed *embed = (EphyEmbed *) l->data;
989
 
 
990
 
                g_return_val_if_fail (EPHY_IS_EMBED (embed), FALSE);
991
 
 
992
 
                if (ephy_web_view_has_modified_forms (ephy_embed_get_web_view (embed)))
993
 
                {
994
 
                        modified = TRUE;
995
 
                        modified_embed = embed;
996
 
                        break;
997
 
                }
998
 
        }
999
 
        g_list_free (tabs);
1000
 
 
1001
 
        if (modified)
1002
 
        {
1003
 
                /* jump to the first tab with modified forms */
1004
 
                impl_set_active_child (EPHY_EMBED_CONTAINER (window),
1005
 
                                       modified_embed);
1006
 
 
1007
 
                if (confirm_close_with_modified_forms (window) == FALSE)
1008
 
                {
1009
 
                        /* stop window close */
1010
 
                        return TRUE;
1011
 
                }
1012
 
        }
1013
 
 
1014
 
 
1015
 
        if (window_has_ongoing_downloads (window) && confirm_close_with_downloads (window) == FALSE)
1016
 
        {
1017
 
                /* stop window close */
1018
 
                return TRUE;
1019
 
        }
1020
 
 
1021
 
        /* If this is the last window, save its state in the session. */
1022
 
        session = EPHY_SESSION (ephy_shell_get_session (ephy_shell));
1023
 
        windows = ephy_session_get_windows (session);
1024
 
        number_windows = g_list_length (windows);
1025
 
        g_list_free (windows);
1026
 
 
1027
 
        if (number_windows == 1)
1028
 
        {
1029
 
                ephy_session_close (session);
1030
 
        }
1031
 
 
1032
 
        /* See bug #114689 */
1033
 
        gtk_widget_hide (widget);
 
991
        if (!ephy_window_close (EPHY_WINDOW (widget)))
 
992
            return TRUE;
1034
993
 
1035
994
        /* proceed with window close */
1036
995
        if (GTK_WIDGET_CLASS (ephy_window_parent_class)->delete_event)
3414
3373
                g_signal_handler_disconnect (window,
3415
3374
                                             priv->set_focus_handler);
3416
3375
 
 
3376
        if (priv->app_menu_visibility_handler != 0)
 
3377
                g_signal_handler_disconnect (gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (window))),
 
3378
                                             priv->app_menu_visibility_handler);
 
3379
 
3417
3380
        G_OBJECT_CLASS (ephy_window_parent_class)->finalize (object);
3418
3381
 
3419
3382
        LOG ("EphyWindow finalised %p", object);
3590
3553
        return res;
3591
3554
}
3592
3555
 
 
3556
static const gchar* app_actions[] = {
 
3557
        "FileNewWindow",
 
3558
        "EditPreferences",
 
3559
        "EditPersonalData",
 
3560
        "EditBookmarks",
 
3561
        "EditHistory",
 
3562
        "FileQuit",
 
3563
        "HelpAbout"
 
3564
};
 
3565
 
 
3566
static void
 
3567
ephy_window_toggle_visibility_for_app_menu (EphyWindow *window)
 
3568
{
 
3569
        const gchar *action_name;
 
3570
        gboolean shows_app_menu;
 
3571
        GtkSettings *settings;
 
3572
        GtkAction *action;
 
3573
        gint idx;
 
3574
 
 
3575
        settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (window)));
 
3576
        g_object_get (settings,
 
3577
                      "gtk-shell-shows-app-menu", &shows_app_menu,
 
3578
                      NULL);
 
3579
 
 
3580
        for (idx = 0; idx < G_N_ELEMENTS (app_actions); idx++) {
 
3581
                action_name = app_actions[idx];
 
3582
                action = gtk_action_group_get_action (window->priv->action_group, action_name);
 
3583
 
 
3584
                gtk_action_set_visible (action, !shows_app_menu);
 
3585
        }
 
3586
}
 
3587
 
3593
3588
static GObject *
3594
3589
ephy_window_constructor (GType type,
3595
3590
                         guint n_construct_properties,
3771
3766
                }
3772
3767
        }
3773
3768
 
 
3769
        /* We never want the menubar shown, we merge the app menu into
 
3770
         * our super menu manually when running outside the Shell. */
 
3771
        gtk_application_window_set_show_menubar (GTK_APPLICATION_WINDOW (window), FALSE);
 
3772
 
 
3773
        ephy_window_toggle_visibility_for_app_menu (window);
 
3774
        priv->app_menu_visibility_handler =  g_signal_connect_swapped (gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (window))),
 
3775
                                                                       "notify::gtk-shell-shows-app-menu",
 
3776
                                                                       G_CALLBACK (ephy_window_toggle_visibility_for_app_menu), window);
 
3777
 
3774
3778
        /* ensure the UI is updated */
3775
3779
        gtk_ui_manager_ensure_update (priv->manager);
3776
3780
 
4165
4169
 
4166
4170
        return window->priv->location_controller;
4167
4171
}
 
4172
 
 
4173
/**
 
4174
 * ephy_window_close:
 
4175
 * @window: an #EphyWindow
 
4176
 *
 
4177
 * Try to close the window. The window might refuse to close
 
4178
 * if there are ongoing download operations or unsubmitted
 
4179
 * modifed forms.
 
4180
 *
 
4181
 * Returns: %TRUE if the window is closed, or %FALSE otherwise
 
4182
 **/
 
4183
gboolean
 
4184
ephy_window_close (EphyWindow *window)
 
4185
{
 
4186
        EphySession *session;
 
4187
        EphyEmbed *modified_embed = NULL;
 
4188
        GList *tabs, *l, *windows;
 
4189
        guint number_windows;
 
4190
        gboolean modified = FALSE;
 
4191
 
 
4192
        /* We ignore the delete_event if the disable_quit lockdown has been set
 
4193
         */
 
4194
        if (g_settings_get_boolean (EPHY_SETTINGS_LOCKDOWN,
 
4195
                                    EPHY_PREFS_LOCKDOWN_QUIT)) return FALSE;
 
4196
 
 
4197
        tabs = impl_get_children (EPHY_EMBED_CONTAINER (window));
 
4198
        for (l = tabs; l != NULL; l = l->next)
 
4199
        {
 
4200
                EphyEmbed *embed = (EphyEmbed *) l->data;
 
4201
 
 
4202
                g_return_val_if_fail (EPHY_IS_EMBED (embed), FALSE);
 
4203
 
 
4204
                if (ephy_web_view_has_modified_forms (ephy_embed_get_web_view (embed)))
 
4205
                {
 
4206
                        modified = TRUE;
 
4207
                        modified_embed = embed;
 
4208
                        break;
 
4209
                }
 
4210
        }
 
4211
        g_list_free (tabs);
 
4212
 
 
4213
        if (modified)
 
4214
        {
 
4215
                /* jump to the first tab with modified forms */
 
4216
                impl_set_active_child (EPHY_EMBED_CONTAINER (window),
 
4217
                                       modified_embed);
 
4218
 
 
4219
                if (confirm_close_with_modified_forms (window) == FALSE)
 
4220
                {
 
4221
                        /* stop window close */
 
4222
                        return FALSE;
 
4223
                }
 
4224
        }
 
4225
 
 
4226
 
 
4227
        if (window_has_ongoing_downloads (window) && confirm_close_with_downloads (window) == FALSE)
 
4228
        {
 
4229
                /* stop window close */
 
4230
                return FALSE;
 
4231
        }
 
4232
 
 
4233
        /* If this is the last window, save its state in the session. */
 
4234
        session = EPHY_SESSION (ephy_shell_get_session (ephy_shell));
 
4235
        windows = ephy_session_get_windows (session);
 
4236
        number_windows = g_list_length (windows);
 
4237
        g_list_free (windows);
 
4238
 
 
4239
        if (number_windows == 1)
 
4240
        {
 
4241
                ephy_session_close (session);
 
4242
        }
 
4243
 
 
4244
        /* See bug #114689 */
 
4245
        gtk_widget_hide (GTK_WIDGET (window));
 
4246
 
 
4247
        return TRUE;
 
4248
}