diff options
author | Søren Sandmann Pedersen <ssp@dhcp-100-2-40.bos.redhat.com> | 2009-04-12 19:15:41 -0400 |
---|---|---|
committer | Søren Sandmann Pedersen <ssp@dhcp-100-2-40.bos.redhat.com> | 2009-04-12 19:15:41 -0400 |
commit | fd8d07a294a2edb502e79e3e32019e424b72c659 (patch) | |
tree | 3e833151cae64228801dafe02320daa3f3bf2b50 | |
parent | 21e1aecdc3fcb5e674b12d394f6066e898ce1cdf (diff) |
Deal better with the blank window case
-rw-r--r-- | siv.c | 75 | ||||
-rw-r--r-- | window.c | 7 |
2 files changed, 51 insertions, 31 deletions
@@ -368,23 +368,23 @@ process_options (int argc, char **argv) static gboolean open_file (App *app, const char *filename, GPtrArray *err_files) { - SivWindow *window; + SivWindow *window = NULL; GError *err = NULL; + gboolean new_window = FALSE; int i; - window = NULL; - for (i = 0; i < app->windows->len; ++i) { const char *f; - - window = app->windows->pdata[i]; + SivWindow *w; - f = window_get_filename (window); + w = app->windows->pdata[i]; + f = window_get_filename (w); if (!f) { /* empty window */ + window = w; break; } @@ -394,32 +394,55 @@ open_file (App *app, const char *filename, GPtrArray *err_files) return TRUE; } } - + if (!window) + { window = window_new (app); - + + new_window = TRUE; + } + if (!window_load_file (window, filename, &err)) { if (err_files) g_ptr_array_add (err_files, g_strdup (filename)); - g_error_free (err); + if (new_window) + window_free (window); - window_free (window); - return FALSE; } - else - { - window_show (window, GDK_CURRENT_TIME); + + window_show (window, GDK_CURRENT_TIME); + + return TRUE; +} - return TRUE; - } +static void +app_begin_load (App *app) +{ + /* When a window is created, it increases the app->n_windows counter; + * when it is destroyed it decreases it. The problem is if the first + * window fails to load the file, it will cause the counter to reach + * zero, which will cause the application to exit. + * + * So set it to 1 here and decrement it after loading all the files to + * prevent that from happening. + */ + app->n_windows++; +} + +static void +app_end_load (App *app) +{ + app->n_windows--; } static void on_open (App *app, const char *filename) { + app_begin_load (app); + if (!open_file (app, filename, NULL)) { /* FIXME: show error @@ -429,6 +452,8 @@ on_open (App *app, const char *filename) * asking to load many files at once */ } + + app_end_load (app); } static App * @@ -444,17 +469,9 @@ app_new (int argc, char **argv) app = g_new0 (App, 1); app->windows = g_ptr_array_new (); - - /* When a window is created, it increases the app->n_windows counter; - * when it is destroyed it decreases it. The problem is if the first - * window fails to load the file, it will cause the counter to reach - * zero, which will cause the application to exit. - * - * So set it to 1 here and decrement it after loading all the files to - * prevent that from happening. - */ - app->n_windows = 1; + app_begin_load (app); + if (filenames[0]) { for (i = 0; filenames[i] != NULL; ++i) @@ -472,10 +489,10 @@ app_new (int argc, char **argv) g_ptr_array_foreach (err_files, (GFunc)g_free, NULL); g_ptr_array_free (err_files, TRUE); - if (app->n_windows == 1) + app_end_load (app); + + if (app->n_windows == 0) exit (1); - else - --app->n_windows; return app; } @@ -1214,13 +1214,16 @@ window_show (SivWindow *window, guint32 time) /* We have to do this after the window is shown */ - hadj = gtk_scrolled_window_get_hadjustment (get_widget (window, "scrolled_window")); - vadj = gtk_scrolled_window_get_vadjustment (get_widget (window, "scrolled_window")); + hadj = gtk_scrolled_window_get_hadjustment ( + get_widget (window, "scrolled_window")); + vadj = gtk_scrolled_window_get_vadjustment ( + get_widget (window, "scrolled_window")); gtk_adjustment_set_value (vadj, window->vadj); gtk_adjustment_set_value (hadj, window->hadj); gtk_window_present_with_time (get_widget (window, "main_window"), time); + gtk_window_present (get_widget (window, "main_window")); } const char * |