SF.net SVN: geany: [930] trunk

eht16 at users.sourceforge.net eht16 at xxxxx
Wed Oct 25 14:39:02 UTC 2006


Revision: 930
          http://svn.sourceforge.net/geany/?rev=930&view=rev
Author:   eht16
Date:     2006-10-25 07:38:48 -0700 (Wed, 25 Oct 2006)

Log Message:
-----------
Added warning message dialog, united dialogs_show_info() and dialogs_show_error() to dialogs_show_msgbox().
Added warning message when opening files that cannot be handled correctly and set them to read-only mode.

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/src/build.c
    trunk/src/dialogs.c
    trunk/src/dialogs.h
    trunk/src/document.c
    trunk/src/prefs.c
    trunk/src/win32.c

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2006-10-24 23:50:50 UTC (rev 929)
+++ trunk/ChangeLog	2006-10-25 14:38:48 UTC (rev 930)
@@ -1,3 +1,13 @@
+2006-10-25  Enrico Tröger  <enrico.troeger at uvena.de>
+
+ * src/dialogs.c, src/dialogs.h, src/build.c, src/prefs.c, src/win32.c
+   src/document.c:
+   Added warning message dialog, united dialogs_show_info() and
+   dialogs_show_error() to dialogs_show_msgbox().
+ * src/document.c: Added warning message when opening files that cannot
+                   be handled correctly and set them to read-only mode.
+
+
 2006-10-24  Enrico Tröger  <enrico.troeger at uvena.de>
 
  * src/build.c, src/socket.c: Fixed compiler warnings under Windows.

Modified: trunk/src/build.c
===================================================================
--- trunk/src/build.c	2006-10-24 23:50:50 UTC (rev 929)
+++ trunk/src/build.c	2006-10-25 14:38:48 UTC (rev 930)
@@ -258,7 +258,8 @@
 		}
 		else
 		{
-			dialogs_show_error("Something very strange is occured, could not stat %s (%s)",
+			dialogs_show_msgbox(GTK_MESSAGE_ERROR,
+					_("Something very strange is occured, could not stat %s (%s)"),
 					doc_list[idx].file_name, strerror(errno));
 		}
 	}

Modified: trunk/src/dialogs.c
===================================================================
--- trunk/src/dialogs.c	2006-10-24 23:50:50 UTC (rev 929)
+++ trunk/src/dialogs.c	2006-10-25 14:38:48 UTC (rev 930)
@@ -120,7 +120,6 @@
 			gtk_combo_box_append_text(GTK_COMBO_BOX(encoding_combo), encoding_string);
 			g_free(encoding_string);
 		}
-		//gtk_combo_box_append_text(GTK_COMBO_BOX(encoding_combo), _("Do not any conversion"));
 		gtk_combo_box_append_text(GTK_COMBO_BOX(encoding_combo), _("Detect from file"));
 		gtk_combo_box_set_active(GTK_COMBO_BOX(encoding_combo), GEANY_ENCODINGS_MAX);
 
@@ -305,7 +304,7 @@
 }
 
 
-void dialogs_show_info(const gchar *text, ...)
+void dialogs_show_msgbox(gint type, const gchar *text, ...)
 {
 #ifndef G_OS_WIN32
 	GtkWidget *dialog;
@@ -318,11 +317,10 @@
 	va_end(args);
 
 #ifdef G_OS_WIN32
-	win32_message_dialog(GTK_MESSAGE_INFO, string);
+	win32_message_dialog(type, string);
 #else
-
 	dialog = gtk_message_dialog_new(GTK_WINDOW(app->window), GTK_DIALOG_DESTROY_WITH_PARENT,
-                                  GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "%s", string);
+                                  type, GTK_BUTTONS_OK, "%s", string);
 	gtk_dialog_run(GTK_DIALOG(dialog));
 	gtk_widget_destroy(dialog);
 #endif
@@ -330,30 +328,6 @@
 }
 
 
-void dialogs_show_error(const gchar *text, ...)
-{
-#ifndef G_OS_WIN32
-	GtkWidget *dialog;
-#endif
-	gchar *string = g_malloc(512);
-	va_list args;
-
-	va_start(args, text);
-	g_vsnprintf(string, 511, text, args);
-	va_end(args);
-
-#ifdef G_OS_WIN32
-	win32_message_dialog(GTK_MESSAGE_ERROR, string);
-#else
-	dialog = gtk_message_dialog_new(GTK_WINDOW(app->window), GTK_DIALOG_DESTROY_WITH_PARENT,
-                                  GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "%s", string);
-	gtk_dialog_run(GTK_DIALOG(dialog));
-	gtk_widget_destroy(dialog);
-#endif
-	g_free(string);
-}
-
-
 gboolean dialogs_show_unsaved_file(gint idx)
 {
 #ifndef G_OS_WIN32
@@ -860,8 +834,8 @@
 
 	if (idx == -1 || ! doc_list[idx].is_valid || doc_list[idx].file_name == NULL)
 	{
-		dialogs_show_error(
-	_("An error occurred or file information could not be retrieved (e.g. from a new file)."));
+		dialogs_show_msgbox(GTK_MESSAGE_ERROR,
+		_("An error occurred or file information could not be retrieved (e.g. from a new file)."));
 		return;
 	}
 

Modified: trunk/src/dialogs.h
===================================================================
--- trunk/src/dialogs.h	2006-10-24 23:50:50 UTC (rev 929)
+++ trunk/src/dialogs.h	2006-10-25 14:38:48 UTC (rev 930)
@@ -30,10 +30,6 @@
 /* This shows the file selection dialog to save a file. */
 void dialogs_show_save_as();
 
-void dialogs_show_info(const gchar *text, ...) G_GNUC_PRINTF (1, 2);
-
-void dialogs_show_error(const gchar *text, ...) G_GNUC_PRINTF (1, 2);
-
 gboolean dialogs_show_unsaved_file(gint idx);
 
 /* This shows the font selection dialog to choose a font. */
@@ -62,4 +58,6 @@
 
 void dialogs_show_keyboard_shortcuts();
 
+void dialogs_show_msgbox(gint type, const gchar *text, ...);
+
 #endif

Modified: trunk/src/document.c
===================================================================
--- trunk/src/document.c	2006-10-24 23:50:50 UTC (rev 929)
+++ trunk/src/document.c	2006-10-25 14:38:48 UTC (rev 930)
@@ -617,9 +617,9 @@
 	}
 
 #ifdef G_OS_WIN32
-	if (! g_file_get_contents(utf8_filename, &data, &size, &err))
+	if (! g_file_get_contents(utf8_filename, &data, NULL, &err))
 #else
-	if (! g_file_get_contents(locale_filename, &data, &size, &err))
+	if (! g_file_get_contents(locale_filename, &data, NULL, &err))
 #endif
 	{
 		msgwin_status_add(err->message);
@@ -629,6 +629,23 @@
 		return -1;
 	}
 
+	/* check whether the size of the loaded data is equal to the size of the file in the filesystem */
+	//size = strlen(data);
+	size = strlen(data);
+	if (size != st.st_size)
+	{
+		gchar *warn_msg = _("The file \"%s\" could not opened properly and probably was truncated. "
+				"Be aware that saving it can cause data lost.\nThe file was set to read-only.");
+
+		if (app->main_window_realized)
+			dialogs_show_msgbox(GTK_MESSAGE_WARNING, warn_msg, utf8_filename);
+		
+		msgwin_status_add(warn_msg, utf8_filename);
+			
+		// set the file to read-only mode because saving it is probably dangerous
+		readonly = TRUE;
+	}
+
 	/* Determine character encoding and convert to UTF-8 */
 	if (forced_enc != NULL)
 	{
@@ -810,7 +827,7 @@
 
 		if (conv_error != NULL)
 		{
-			dialogs_show_error(
+			dialogs_show_msgbox(GTK_MESSAGE_ERROR,
 	_("An error occurred while converting the file from UTF-8 in \"%s\". The file remains unsaved."
 	  "\nError message: %s\n"),
 			doc_list[idx].encoding, conv_error->message);
@@ -1444,7 +1461,7 @@
 		rc = system(cmdline);
 		if (rc != 0)
 		{
-			dialogs_show_error(_("Printing of \"%s\" failed (return code: %d)."),
+			dialogs_show_msgbox(GTK_MESSAGE_ERROR, _("Printing of \"%s\" failed (return code: %d)."),
 								doc_list[idx].file_name, rc);
 		}
 		else

Modified: trunk/src/prefs.c
===================================================================
--- trunk/src/prefs.c	2006-10-24 23:50:50 UTC (rev 929)
+++ trunk/src/prefs.c	2006-10-25 14:38:48 UTC (rev 930)
@@ -873,7 +873,7 @@
 		if (keys[i]->key == key && keys[i]->mods == mods
 			&& ! (keys[i]->key == keys[idx]->key && keys[i]->mods == keys[idx]->mods))
 		{
-			dialogs_show_error(
+			dialogs_show_msgbox(GTK_MESSAGE_ERROR,
 				_("The combination '%s' is already used for \"%s\". Please choose another one."),
 				action, keys[i]->label);
 			return TRUE;

Modified: trunk/src/win32.c
===================================================================
--- trunk/src/win32.c	2006-10-24 23:50:50 UTC (rev 929)
+++ trunk/src/win32.c	2006-10-25 14:38:48 UTC (rev 930)
@@ -337,6 +337,12 @@
 			title = _("Question");
 			break;
 		}
+		case GTK_MESSAGE_WARNING:
+		{
+			t = MB_OK | MB_ICONWARNING;
+			title = _("Warning");
+			break;
+		}
 		default:
 		{
 			t = MB_OK | MB_ICONINFORMATION;


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the Commits mailing list