+ /* Do not allow standalone editors or standalone viewers */
+ if (!current_top &&
+ (MODEST_IS_MSG_VIEW_WINDOW (window) ||
+ MODEST_IS_MSG_EDIT_WINDOW (window)))
+ modest_window_mgr_show_initial_window (self);
+
+ if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
+ gchar *uid;
+ TnyHeader *header;
+
+ uid = g_strdup (modest_msg_view_window_get_message_uid (MODEST_MSG_VIEW_WINDOW (window)));
+
+ header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (window));
+
+ if (uid == NULL)
+ uid = modest_tny_folder_get_header_unique_id (header);
+ /* Embedded messages do not have uid */
+ if (uid) {
+ if (g_list_find_custom (priv->window_list, uid, (GCompareFunc) compare_msguids)) {
+ g_debug ("%s found another view window showing the same header", __FUNCTION__);
+ g_free (uid);
+ g_object_unref (header);
+ return FALSE;
+ }
+ g_free (uid);
+ } else if (header) {
+ if (g_list_find_custom (priv->window_list, header, (GCompareFunc) compare_headers)) {
+ g_debug ("%s found another view window showing the same header", __FUNCTION__);
+ g_object_unref (header);
+ return FALSE;
+ }
+ }
+ if (header)
+ g_object_unref (header);
+ }
+
+ /* Rules
+ * * toplevel = msg edit -> if not modified, close, if modified, stay
+ * * same account -> no action
+ * * window = accounts -> no action
+ * * window = folders, mailboxes, headers: close all up to accounts window
+ */
+
+ if (MODEST_IS_MSG_EDIT_WINDOW (current_top) &&
+ !modest_msg_edit_window_is_modified (MODEST_MSG_EDIT_WINDOW (current_top))) {
+ gboolean retval;
+
+ g_signal_emit_by_name (G_OBJECT (current_top), "delete-event", NULL, &retval);
+ current_top = (ModestWindow *) hildon_window_stack_peek (stack);
+ }
+
+ if (MODEST_IS_MSG_EDIT_WINDOW (current_top) ||
+ (current_top && MODEST_IS_ACCOUNTS_WINDOW (window))) {