All pastes #33121 Raw Edit

Unnamed

public text v1 · immutable
#33121 ·published 2005-12-09 20:53 UTC
rendered paste body
Index: gedit-session.c
===================================================================
RCS file: /cvs/gnome/gedit/gedit/gedit-session.c,v
retrieving revision 1.9.8.14
diff -u -p -r1.9.8.14 gedit-session.c
--- gedit-session.c	9 Dec 2005 10:10:43 -0000	1.9.8.14
+++ gedit-session.c	9 Dec 2005 20:52:39 -0000
@@ -68,6 +68,9 @@ static gint interaction_key;
 static GSList *window_dirty_list;
 
 static void	ask_next_confirmation	(void);
+static void	window_state_change (GeditWindow *window,
+				     GParamSpec  *pspec,
+				     gpointer     data);
 
 #define GEDIT_SESSION_LIST_OF_DOCS_TO_SAVE "gedit-session-list-of-docs-to-save-key"
 
@@ -319,49 +322,88 @@ window_handled (GeditWindow *window)
 }
 
 static void
+abort_shutdown (GeditWindow *window)
+{
+	GSList *l;
+
+	gedit_debug (DEBUG_SESSION);
+
+	/* disconnect window_state_changed where needed */
+	for (l = window_dirty_list; l != NULL; l = l->next)
+		g_signal_handlers_disconnect_by_func (l->data,
+				window_state_change, NULL);
+
+	g_slist_free (window_dirty_list);
+	window_dirty_list = NULL;
+
+	/* cancel shutdown */
+	finish_interaction (TRUE);
+}
+
+static void
 window_state_change (GeditWindow *window,
 		     GParamSpec  *pspec,
 		     gpointer     data)
 {
 	GeditWindowState state;
-	GList *unsaved_docs;
-	GList *docs_to_save;
-	GList *l;
 	gboolean done = TRUE;
 
 	state = gedit_window_get_state (window);
 
-	/* we are still saving */
 	if (state & GEDIT_WINDOW_STATE_SAVING)
+	{
+		/* we are still saving */
+		return;
+	}
+	else if (state & GEDIT_WINDOW_STATE_ERROR)
+	{
+		/* an error occurred, abort save session */
+		abort_shutdown (window);
 		return;
+	}
+	else
+	{
+		/* if there are still unsaved docs, it means we
+		 * pressed cancel when asked "save as" for an 
+		 * untitled document: abort session save. Otherwise
+		 * this window is good to go.
+		 */
+		GList *unsaved_docs;
+		GList *docs_to_save;
+		GList *l;
 
-	unsaved_docs = gedit_window_get_unsaved_documents (window);
+		unsaved_docs = gedit_window_get_unsaved_documents (window);
 
-	docs_to_save =	g_object_get_data (G_OBJECT (window),
-					   GEDIT_SESSION_LIST_OF_DOCS_TO_SAVE);
+		docs_to_save =	g_object_get_data (G_OBJECT (window),
+						   GEDIT_SESSION_LIST_OF_DOCS_TO_SAVE);
 
 
-	for (l = docs_to_save; l != NULL; l = l->next)
-	{
-		if (g_list_find (unsaved_docs, l->data))
+		for (l = docs_to_save; l != NULL; l = l->next)
 		{
-			done = FALSE;
-			break;
+			if (g_list_find (unsaved_docs, l->data))
+			{
+				done = FALSE;
+				break;
+			}
 		}
-	}
 
-	if (done)
-	{
-		g_signal_handlers_disconnect_by_func (window, window_state_change, data);
-		g_list_free (docs_to_save);
-		g_object_set_data (G_OBJECT (window),
-				   GEDIT_SESSION_LIST_OF_DOCS_TO_SAVE,
-				   NULL);
+		g_list_free (unsaved_docs);
 
-		window_handled (window);
-	}
+		if (done)
+		{
+			g_signal_handlers_disconnect_by_func (window, window_state_change, data);
+			g_list_free (docs_to_save);
+			g_object_set_data (G_OBJECT (window),
+					   GEDIT_SESSION_LIST_OF_DOCS_TO_SAVE,
+					   NULL);
 
-	g_list_free (unsaved_docs);
+			window_handled (window);
+		}
+		else
+		{
+			abort_shutdown (window);
+		}
+	}
 }
 
 static void
@@ -370,9 +412,8 @@ close_confirmation_dialog_response_handl
 					    GeditWindow                  *window)
 {
 	const GList *selected_documents;
-	GSList *l;
 
-	gedit_debug (DEBUG_COMMANDS);
+	gedit_debug (DEBUG_SESSION);
 
 	switch (response_id)
 	{
@@ -395,8 +436,6 @@ close_confirmation_dialog_response_handl
 
 			_gedit_cmd_file_save_documents_list (window, selected_documents);
 
-			// FIXME: also need to lock the window to prevent further changes..
-
 			break;
 
 		case GTK_RESPONSE_NO:
@@ -405,16 +444,8 @@ close_confirmation_dialog_response_handl
 			break;
 
 		default:
-			/* disconnect window_state_changed where needed */
-			for (l = window_dirty_list; l != NULL; l = l->next)
-				g_signal_handlers_disconnect_by_func (window,
-						window_state_change, NULL);
-			g_slist_free (window_dirty_list);
-			window_dirty_list = NULL;
-
-			/* cancel shutdown */
-			finish_interaction (TRUE);
-
+			/* cancel session save */
+			abort_shutdown (window);
 			break;
 	}