/*
**      Newton Developer Technical Support Sample Code
**
**      ListPicker,  This sample illistrates displaying soup entries and icons.
**
**      by Stephen Harris, Newton Developer Technical Support
**
**      Copyright  1993-1996 by Apple Computer, Inc.  All rights reserved.
**
**      You may incorporate this sample code into your applications without
**      restriction.  This sample code has been provided "AS IS" and the
**      responsibility for its operation is 100% yours.  You are not
**      permitted to modify and redistribute the source as "DTS Sample Code."
**      If you are going to re-distribute the source, we require that you
**      make it clear in the source that the code was descended from
**      Apple-provided sample code, but that you've made changes.
*/

//  This sample demonstates the use of the protoListPicker and a icon in the first column.

// the app stuff
constant kAppTitle := "The List Picker";

//--------------

// Soup stuff
constant kSoupName := kPackageName;
Constant kSoupIndexes := '[{structure: slot,path:first, type: string}];
constant kQuerySpec := '{type: index, indexpath: first};

// used by the regUnionSoup function for soup design
DefConst('kSoupDef, {
	name: kSoupName,
	username: kAppName,
	ownerApp: kAppSymbol,
	userDescr: "Data for the listPicker Icon sample",
	indexes: kSoupIndexes
}) ;

//--------------

//-------icon

rFile := OpenResFileX(home & "icons.rsrc");
defconst('kTreeIcon, GetPictAsBits("tree",nil)) ;
CloseResFileX(rFile);

//-----------


// Random  entry generator.
DefConst('kCanonicalEntry,
   {
		first: nil,
		second: nil,

	});


DefConst('kRandomDataGeneratorFunc, func()
	begin
		local item:= clone(kCanonicalEntry);

		item.first:= Capitalize(GetRandomWord(4, 12));
		item.second:= Capitalize(GetRandomWord(4, 12));
		item;
	end);
		
//--------------

// DeleteScript->  this only gets called when your app is deleted and not
// when the card is removed.
SetPartFrameSlot('DeletionScript, func()
begin
	//Remove the soup from the stores
	foreach store in GetStores() do 
	begin
		local theSoup := store:GetSoup(kSoupName);
		if theSoup then
		   theSoup:RemoveFromStore();
	end;
end
);

// Install/Remove Scripts

InstallScript := func(part)
begin	
	RegUnionSoup(kAppSymbol, kSoupDef) ;
end;

RemoveScript := func(part)
begin
	// unregister autocreation of soup
	UnRegUnionSoup(kSoupName, kAppSymbol);
end;