# Script to test custom UI functionality

# For custom dialogs which are large and/or it is desirable to retain values between executions (e.g. for filters)
# use the 'defaultDialog()' function to get the current scope's permanent dialog, and use/set the 'created' property
# as shown here.

void createDefaultDialog(Dialog ui)
{
	Widget w, group, w2, tabs, page;

	# Set title and vertical automatic filling of main dialog layout
	ui.title = "UI Test";

	# Create a Tabs widget to store everything in
	tabs = ui.addTabs("tabwidget");
	# -- Page 1
	page = tabs.addPage("page1", "Demo 1");
	page.verticalFill = TRUE;
	
	# Create a combo box to display various items - we will attack it with various signals
	page.addCombo("combo", "Combo Box", "One,Two,Three,Four,Five", 1, 1, 1);

	# Create some checkboxes (in a group) which can be used to disable/hide the combo box
	group = page.addGroup("group1", "Disable / Hide");
	w = group.addCheck("check1", "Disable Combo Box?", FALSE);
	w.onInteger(0, 1, "sendinteger", "combo", "disabled");
	w = group.addCheck("check2", "Hide Combo Box?", FALSE);
	w.onInteger(0, 1, "sendinteger", "combo", "invisible");

	# Create some controls to allow the combobox contents to be changed
	group = page.addGroup("group2", "Combo Contents");
	page.addRadioGroup("contentsgroup");
	w = group.addRadioButton("radio1", "Numbers", "contentsgroup", 1);
	w.onInteger(1, 1, "set", "combo", "items", "One,Two,Three,Four,Five");
	w = group.addRadioButton("radio2", "Letters", "contentsgroup", 0);
	w.onInteger(1, 1, "set", "combo", "items", "Aay,Bee,Cee,Dee,Eee,Eff");
	w = group.addRadioButton("radio3", "Weights", "contentsgroup", 0);
	w.onInteger(1, 1, "set", "combo", "items", "Grams,Ounces,HundredWeight,Stones,Cups");
	w2 = group.addRadioButton("radio4", "Music", "contentsgroup", 0);

	# Create another group here, allowing selection of Misc items list
	# We will then link the final radio button created to activate this radiogroup and select the new combo items
	group = page.addGroup("group3", "Misc Choices");
	group.enabled = FALSE;
	ui.addRadioGroup("musicgroup");
	w = group.addRadioButton("radio5", "Modern", "musicgroup", 1);
	w.onInteger(1, 1, "set", "combo", "items", "'Foo Fighters',Muse,'Ukelele Orchestra','Black Sabbath'");
	w = group.addRadioButton("radio6", "Classic", "musicgroup", 0);
	w.onInteger(1, 1, "set", "combo", "items", "Bach,Chopin,Rachmaninov");
	ui.widget("contentsgroup").onInteger(1, 3, "sendbool", "group3", "disabled");
	ui.widget("contentsgroup").onInteger(4, 4, "activate", "musicgroup", "value");
}

# Show (execute) the dialog to allow user interaction. The show() function returns 0 for 'canceled' or '1' for 'ok'
if (!showDefaultDialog()) error("Dialog canceled.\n");
else
{
        Dialog ui = defaultDialog();

	# Print out status of the widgets
	printf("Widget Status:\n\n");

	printf("Combo box current item  : '%s'\n", ui.asString("combo"));
	printf("Combo box current index : %i\n", ui.asInteger("combo"));
	printf("Contents group index    : %i\n", ui.asInteger("contentsgroup"));
	printf("Music group index       : %i\n", ui.asInteger("musicgroup"));
}
