Commit 762ef290 authored by Morten Welinder's avatar Morten Welinder

Use application properties instead of ugly dual-use global variable

parent 34dac1b3
......@@ -38,8 +38,10 @@
#define GNM_IS_APP(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), GNM_APP_TYPE))
enum {
APPLICATION_PROP_0,
APPLICATION_PROP_FILE_HISTORY_LIST
PROP_0,
PROP_HISTORY_LIST,
PROP_SHUTTING_DOWN,
PROP_INITIAL_OPEN_COMPLETE
};
/* Signals */
enum {
......@@ -71,6 +73,9 @@ struct _GnmApp {
GtkRecentManager *recent;
gulong recent_sig;
gboolean shutting_down;
gboolean initial_open_complete;
};
typedef struct {
......@@ -723,7 +728,7 @@ cb_recent_changed (G_GNUC_UNUSED GtkRecentManager *recent, GnmApp *app)
}
static void
gnumeric_application_finalize (GObject *obj)
gnm_app_finalize (GObject *obj)
{
GnmApp *application = GNM_APP (obj);
......@@ -739,34 +744,75 @@ gnumeric_application_finalize (GObject *obj)
}
static void
gnumeric_application_get_property (GObject *obj, guint param_id,
gnm_app_get_property (GObject *obj, guint param_id,
GValue *value, GParamSpec *pspec)
{
#if 0
GnmApp *application = GNM_APP (obj);
#endif
switch (param_id) {
case APPLICATION_PROP_FILE_HISTORY_LIST:
case PROP_HISTORY_LIST:
g_value_set_pointer (value, gnm_app_history_get_list (G_MAXINT));
break;
case PROP_SHUTTING_DOWN:
g_value_set_boolean (value, gnm_app_shutting_down ());
break;
case PROP_INITIAL_OPEN_COMPLETE:
g_value_set_boolean (value, gnm_app_initial_open_complete ());
break;
default: G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, param_id, pspec);
break;
}
}
static void
gnm_app_set_property (GObject *object, guint property_id,
GValue const *value, GParamSpec *pspec)
{
GnmApp *app = (GnmApp *)object;
switch (property_id) {
case PROP_SHUTTING_DOWN:
app->shutting_down = g_value_get_boolean (value);
break;
case PROP_INITIAL_OPEN_COMPLETE:
app->initial_open_complete = g_value_get_boolean (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gnm_app_class_init (GObjectClass *gobject_klass)
{
parent_klass = g_type_class_peek_parent (gobject_klass);
/* Object class method overrides */
gobject_klass->finalize = gnumeric_application_finalize;
gobject_klass->get_property = gnumeric_application_get_property;
g_object_class_install_property (gobject_klass, APPLICATION_PROP_FILE_HISTORY_LIST,
gobject_klass->finalize = gnm_app_finalize;
gobject_klass->get_property = gnm_app_get_property;
gobject_klass->set_property = gnm_app_set_property;
g_object_class_install_property (gobject_klass, PROP_HISTORY_LIST,
g_param_spec_pointer ("file-history-list",
P_("File History List"),
P_("A list of filenames that have been read recently"),
GSF_PARAM_STATIC | G_PARAM_READABLE));
g_object_class_install_property (gobject_klass, PROP_SHUTTING_DOWN,
g_param_spec_boolean ("shutting-down",
P_("Shutting Down"),
P_("In the process of shutting down?"),
FALSE,
GSF_PARAM_STATIC | G_PARAM_READWRITE));
g_object_class_install_property (gobject_klass, PROP_INITIAL_OPEN_COMPLETE,
g_param_spec_boolean ("initial-open-complete",
P_("Initial Open Complete"),
P_("All command-line files open?"),
FALSE,
GSF_PARAM_STATIC | G_PARAM_READWRITE));
signals[WORKBOOK_ADDED] = g_signal_new ("workbook_added",
GNM_APP_TYPE,
......@@ -1074,3 +1120,15 @@ gnm_app_recalc_clear_caches (void)
{
g_signal_emit_by_name (gnm_app_get_app (), "recalc-clear-caches");
}
gboolean
gnm_app_shutting_down (void)
{
return app->shutting_down;
}
gboolean
gnm_app_initial_open_complete (void)
{
return app->initial_open_complete;
}
......@@ -13,6 +13,9 @@ typedef gboolean (*GnmWbIterFunc) (Workbook *wb, gpointer data);
GType gnm_app_get_type (void);
GObject *gnm_app_get_app (void);
gboolean gnm_app_shutting_down (void);
gboolean gnm_app_initial_open_complete (void);
/* List of active workbooks */
void gnm_app_workbook_list_add (Workbook *wb);
void gnm_app_workbook_list_remove (Workbook *wb);
......
......@@ -128,9 +128,6 @@ fake_gtk_icon_theme_add_resource_path (GtkIconTheme G_GNUC_UNUSED *theme,
#endif
/* TODO : get rid of this monstrosity */
gboolean initial_workbook_open_complete = FALSE;
static gboolean param_show_version = FALSE;
static char *param_lib_dir = NULL;
static char *param_data_dir = NULL;
......
......@@ -25,8 +25,6 @@ void gnm_shutdown (void);
GOptionGroup *gnm_get_option_group (void);
GNM_VAR_DECL gboolean initial_workbook_open_complete;
G_END_DECLS
#endif /* _GNM_LIBGNUMERIC_H_ */
......@@ -88,7 +88,7 @@ handle_paint_events (void)
{
/* FIXME: we need to mask input events correctly here */
/* Show something coherent */
while (gtk_events_pending () && !initial_workbook_open_complete)
while (gtk_events_pending () && !gnm_app_shutting_down ())
gtk_main_iteration_do (FALSE);
}
......@@ -261,7 +261,7 @@ main (int argc, char const **argv)
N = g_strv_length (startup_files);
go_io_context_set_num_files (ioc, N);
for (i = 0; i < N && !initial_workbook_open_complete; i++) {
for (i = 0; i < N && !gnm_app_shutting_down (); i++) {
char *uri = go_shell_arg_to_uri (startup_files[i]);
if (uri == NULL) {
......@@ -314,11 +314,13 @@ main (int argc, char const **argv)
any_error = FALSE;
// If we were intentionally short circuited exit now
if (any_error || initial_workbook_open_complete) {
if (any_error || gnm_app_shutting_down ()) {
g_object_unref (ioc);
g_slist_foreach (wbcgs_to_kill, (GFunc)cb_kill_wbcg, NULL);
} else {
initial_workbook_open_complete = TRUE;
g_object_set (gnm_app_get_app (),
"initial-open-complete", TRUE, NULL);
if (!opened_workbook) {
gint n_of_sheets = gnm_conf_get_core_workbook_n_sheet ();
wbc_gtk_new (NULL,
......@@ -343,6 +345,8 @@ main (int argc, char const **argv)
gtk_main ();
}
g_object_set (gnm_app_get_app (), "shutting-down", TRUE, NULL);
g_slist_free (wbcgs_to_kill);
gnumeric_arg_shutdown ();
store_plugin_state ();
......
......@@ -287,8 +287,8 @@ static GNM_ACTION_DEF (cb_file_close) { wbc_gtk_close (wbcg); }
static GNM_ACTION_DEF (cb_file_quit)
{
/* If we are still loading initial files, short circuit */
if (!initial_workbook_open_complete) {
initial_workbook_open_complete = TRUE;
if (!gnm_app_initial_open_complete ()) {
g_object_set (gnm_app_get_app (), "shutting-down", TRUE, NULL);
return;
}
......
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