ges-ui: add new command, remove quit command (closing last window quits app)

This commit is contained in:
Brandon Lewis 2010-10-08 12:32:15 +01:00 committed by Edward Hervey
parent e557592074
commit a4f315274c
2 changed files with 16 additions and 19 deletions

View file

@ -87,13 +87,16 @@ typedef struct App
GtkSpinButton *frequency; GtkSpinButton *frequency;
} App; } App;
static int n_instances = 0;
/* Prototypes for auto-connected signal handlers ***************************/ /* Prototypes for auto-connected signal handlers ***************************/
/** /**
* These are declared non-static for signal auto-connection * These are declared non-static for signal auto-connection
*/ */
gboolean window_delete_event_cb (GtkObject * window, App * app); gboolean window_delete_event_cb (GtkObject * window, GdkEvent * event,
App * app);
void quit_item_activate_cb (GtkMenuItem * item, App * app); void quit_item_activate_cb (GtkMenuItem * item, App * app);
void delete_activate_cb (GtkAction * item, App * app); void delete_activate_cb (GtkAction * item, App * app);
void play_activate_cb (GtkAction * item, App * app); void play_activate_cb (GtkAction * item, App * app);
@ -999,6 +1002,12 @@ app_dispose (App * app)
g_free (app); g_free (app);
} }
n_instances--;
if (n_instances == 0) {
gtk_main_quit ();
}
} }
static App * static App *
@ -1006,6 +1015,7 @@ app_new (void)
{ {
App *ret; App *ret;
ret = g_new0 (App, 1); ret = g_new0 (App, 1);
n_instances++;
ret->selected_type = G_TYPE_NONE; ret->selected_type = G_TYPE_NONE;
@ -1040,10 +1050,10 @@ fail:
/* UI callbacks ************************************************************/ /* UI callbacks ************************************************************/
gboolean gboolean
window_delete_event_cb (GtkObject * window, App * app) window_delete_event_cb (GtkObject * window, GdkEvent * event, App * app)
{ {
gtk_main_quit (); app_dispose (app);
return TRUE; return FALSE;
} }
void void
@ -1283,7 +1293,6 @@ main (int argc, char *argv[])
if ((app = app_new ())) { if ((app = app_new ())) {
gtk_main (); gtk_main ();
app_dispose (app);
} }
return 0; return 0;

View file

@ -60,7 +60,9 @@
<object class="GtkImageMenuItem" id="new_item"> <object class="GtkImageMenuItem" id="new_item">
<property name="label">gtk-new</property> <property name="label">gtk-new</property>
<property name="use_underline">True</property> <property name="use_underline">True</property>
<property name="visible">True</property>
<property name="use_stock">True</property> <property name="use_stock">True</property>
<signal name="activate" handler="new_activate_cb"/>
</object> </object>
</child> </child>
<child> <child>
@ -84,20 +86,6 @@
<property name="use_stock">True</property> <property name="use_stock">True</property>
</object> </object>
</child> </child>
<child>
<object class="GtkSeparatorMenuItem" id="separatormenuitem1">
<property name="visible">True</property>
</object>
</child>
<child>
<object class="GtkImageMenuItem" id="quit_item">
<property name="label">gtk-quit</property>
<property name="visible">True</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
<signal name="activate" handler="quit_item_activate_cb"/>
</object>
</child>
</object> </object>
</child> </child>
</object> </object>