Implemented the ShouldQuit() stuff for the Quit menu item on the GTK+ backend.

This commit is contained in:
Pietro Gagliardi 2015-05-09 10:50:03 -04:00
parent c062d2d0b5
commit 5ef355f28f
2 changed files with 15 additions and 2 deletions

View File

@ -23,8 +23,11 @@ int onClosing(uiWindow *w, void *data)
int onShouldQuit(void *data)
{
printf("in onShouldQuit()\n");
uiControlDestroy(uiControl(data));
return uiMenuItemChecked(shouldQuitItem);
if (uiMenuItemChecked(shouldQuitItem)) {
uiControlDestroy(uiControl(data));
return 1;
}
return 0;
}
uiBox *mainBox;

View File

@ -81,6 +81,12 @@ static void defaultOnClicked(uiMenuItem *item, uiWindow *w, void *data)
// do nothing
}
static void onQuitClicked(uiMenuItem *item, uiWindow *w, void *data)
{
if (shouldQuit())
uiQuit();
}
static void menuItemEnableDisable(struct menuItem *item, gboolean enabled)
{
GHashTableIter iter;
@ -110,6 +116,8 @@ static void menuItemOnClicked(uiMenuItem *ii, void (*f)(uiMenuItem *, uiWindow *
{
struct menuItem *item = (struct menuItem *) ii;
if (item->type == typeQuit)
complain("attempt to call uiMenuItemOnClicked() on a Quit item; use uiOnShouldQuit() instead");
item->onClicked = f;
item->onClickedData = data;
}
@ -162,6 +170,8 @@ static uiMenuItem *newItem(struct menu *m, int type, const char *name)
}
item->onClicked = defaultOnClicked;
if (item->type == typeQuit)
item->onClicked = onQuitClicked;
switch (item->type) {
case typeCheckbox: