Commit d5b5f9ab authored by Gaël Bonithon's avatar Gaël Bonithon Committed by Matthew Brush

Do not open an empty document when encoding failed

parent 509c03ba
......@@ -57,6 +57,7 @@ main (gint argc, gchar **argv)
MousepadApplication *application;
GError *error = NULL;
gchar *working_directory;
gboolean succeed;
/* bind the text domain to the locale directory */
bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
......@@ -179,14 +180,14 @@ main (gint argc, gchar **argv)
application = mousepad_application_get ();
/* open an empty window (with an empty document or the files) */
mousepad_application_new_window_with_files (application, NULL, working_directory, filenames);
succeed = mousepad_application_new_window_with_files (application, NULL, working_directory, filenames);
/* cleanup */
g_free (working_directory);
g_strfreev (filenames);
/* do not enter the main loop, unless we have atleast one window */
if (G_LIKELY (mousepad_application_has_windows (application)))
if (G_LIKELY (mousepad_application_has_windows (application)) && succeed == TRUE)
{
#ifdef HAVE_DBUS
/* register with dbus */
......@@ -203,5 +204,5 @@ main (gint argc, gchar **argv)
/* release application reference */
g_object_unref (G_OBJECT (application));
return EXIT_SUCCESS;
return succeed ? EXIT_SUCCESS : EXIT_FAILURE;
}
......@@ -270,7 +270,7 @@ mousepad_application_new_window (MousepadWindow *existing,
void
gboolean
mousepad_application_new_window_with_files (MousepadApplication *application,
GdkScreen *screen,
const gchar *working_directory,
......@@ -281,8 +281,8 @@ mousepad_application_new_window_with_files (MousepadApplication *application,
MousepadDocument *document;
GtkWindowGroup *window_group;
g_return_if_fail (MOUSEPAD_IS_APPLICATION (application));
g_return_if_fail (screen == NULL || GDK_IS_SCREEN (screen));
g_return_val_if_fail (MOUSEPAD_IS_APPLICATION (application), succeed);
g_return_val_if_fail (screen == NULL || GDK_IS_SCREEN (screen), succeed);
/* create a new window (signals added and already hooked up) */
window = mousepad_application_create_window (application);
......@@ -295,22 +295,24 @@ mousepad_application_new_window_with_files (MousepadApplication *application,
/* place the window on the right screen */
gtk_window_set_screen (GTK_WINDOW (window), screen ? screen : gdk_screen_get_default ());
/* try to open the files */
/* try to open the files if any, or open an empty document */
if (working_directory && filenames && g_strv_length (filenames))
succeed = mousepad_window_open_files (MOUSEPAD_WINDOW (window), working_directory, filenames);
/* open an empty document */
if (succeed == FALSE)
else
{
/* create a new document */
document = mousepad_document_new ();
/* add the document to the new window */
mousepad_window_add (MOUSEPAD_WINDOW (window), document);
succeed = TRUE;
}
/* show the window */
gtk_widget_show (window);
if (succeed == TRUE)
gtk_widget_show (window);
return succeed;
}
......
......@@ -40,7 +40,7 @@ gboolean mousepad_application_has_windows (MousepadApplic
void mousepad_application_take_window (MousepadApplication *application,
GtkWindow *window);
void mousepad_application_new_window_with_files (MousepadApplication *application,
gboolean mousepad_application_new_window_with_files (MousepadApplication *application,
GdkScreen *screen,
const gchar *working_directory,
gchar **filenames);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment