-- ExampleTool.mesa
--  last edit                 June 22, 1984 9:51:20 am PDT  Sturgis

DIRECTORY
   Commander USING[CommandProc, Register],
   EasyTool USING[DefineItemsProc, DefineTool],
   IO USING[STREAM],
   Rope USING[ROPE];
  

ExampleTool: PROGRAM IMPORTS EasyTool, Commander =

BEGIN OPEN EasyTool;

ToolData: TYPE = REF ToolDataBody;
ToolDataBody: TYPE = RECORD[
	out: IO.STREAM,
	v1: REF LONG CARDINAL,
	v2: REF LONG CARDINAL,
	v3: REF LONG CARDINAL,
	v4: REF BOOLEAN,
	v5: REF BOOLEAN,
	v6: REF Rope.ROPE,
	v7: REF Rope.ROPE,
	v8: REF Rope.ROPE,
	v9: REF Rope.ROPE,
	v10: REF Rope.ROPE,
	v11: REF Rope.ROPE
	];
	
recentTool: ToolData ← NIL;

BuildExampleTool: Commander.CommandProc = TRUSTED
	BEGIN
	data: ToolData ← (recentTool ← NEW[ToolDataBody]);
	
	DefineItems: DefineItemsProc =
		BEGIN
		RETURN[defineColumn[ LIST[
			
			defineMatrix[LIST[
				LIST[
					defineButton["action1", Action1],
					defineButton["action2", Action2],
					defineButton["action3", Action3]
					],
				LIST[
					defineItem[, "d1", , data.v1 ← NEW[LONG CARDINAL ← 1], "for size of 1", TRUE],
					defineItem[, "d2", , data.v2 ← NEW[LONG CARDINAL ← 2], "for size of 2", TRUE],
					defineItem[, "d3", , data.v3 ← NEW[LONG CARDINAL ← 3], "for size of 3"]
					]
				]],
			
			defineFiller[0, 10],
					
			defineRow[LIST[
				defineButton["action4", Action4],
				defineFiller[5, 0],
				defineItem[, "d4", , data.v4 ← NEW[BOOLEAN ← FALSE], "FALSE", TRUE],
				defineItem[, "d5", , data.v5 ← NEW[BOOLEAN ← FALSE], "FALSE"]
				], 10],
				
			defineMatrix[LIST[
				LIST[
					defineButton["action6", Action6],
					defineItem[, "d6", , data.v6 ← NEW[Rope.ROPE ← "hi"], "ttttttttt", TRUE],
					defineItem[, "d7", , data.v7 ← NEW[Rope.ROPE ← "hi"], "ttttttttt"]
					],
				LIST[
					defineButton["action8", Action8],
					defineItem[, "d8", , data.v8 ← NEW[Rope.ROPE ← "hello"], "xxxttttttttttttt", TRUE],
					defineItem[, "d9", , data.v9 ← NEW[Rope.ROPE ← "hello"], "ttttttttt"]
					],
				LIST[
					defineButton["action10", Action10],
					defineItem[, "d10", , data.v10 ← NEW[Rope.ROPE ← "good bye"], "ttttttttttttt", TRUE],
					defineItem[, "d11", , data.v11 ← NEW[Rope.ROPE ← "good bye"], "ttttttttttttt"]
					]], 5, 10]
			]]];
		END;
			
	[] ← DefineTool["exampleTool", data, DefineItems];
	data.out ← cmd.out;
	END;
	
BuildSimpleExampleTool: Commander.CommandProc = TRUSTED
	BEGIN
	data: ToolData ← NEW[ToolDataBody];
	
	DefineItems: DefineItemsProc =
			BEGIN
			RETURN[defineColumn[ LIST[
				defineButton["action1", Action1],
	            defineItem[, "d1", , data.v1 ← NEW[LONG CARDINAL ← 1], "for size of 1", TRUE]
				]]];
			END;
			
	[] ← DefineTool["simpleExampleTool", data, DefineItems];
	data.out ← cmd.out;
	END;


Action1: PROCEDURE[d: REF ANY] =
	BEGIN
	data: ToolData ← NARROW[d];
	data.v1↑ ← data.v1↑ + 1;
	END;

Action2: PROCEDURE[d: REF ANY] =
	BEGIN
	data: ToolData ← NARROW[d];
	data.v2↑ ← data.v2↑ + 1;
	END;
	
Action3: PROCEDURE[d: REF ANY] =
	BEGIN
	data: ToolData ← NARROW[d];
	data.v3↑ ← data.v1↑ + data.v2↑;
	END;
	
Action4: PROCEDURE[d: REF ANY] =
	BEGIN
	data: ToolData ← NARROW[d];
	data.v5↑ ← data.v4↑;
	END;
	
Action6: PROCEDURE[d: REF ANY] =
	BEGIN
	data: ToolData ← NARROW[d];
	data.v7↑ ← data.v6↑;
	END;	
	
Action8: PROCEDURE[d: REF ANY] =
	BEGIN
	data: ToolData ← NARROW[d];
	data.v9↑ ← data.v8↑;
	END;	
	
Action10: PROCEDURE[d: REF ANY] =
	BEGIN
	data: ToolData ← NARROW[d];
	data.v11↑ ← data.v10↑;
	END;


-- main code

Commander.Register[key: "ExampleTool", proc: BuildExampleTool, doc: ""];
Commander.Register[key: "SimpleExampleTool", proc: BuildSimpleExampleTool, doc: ""];

END..


--  September 3, 1982 12:14 pm: Sturgis, started ExampleTool.mesa
-- September 5, 1982 4:34 pm: Sturgis: use unsigned and boolean items.
-- September 6, 1982 6:58 pm: Sturgis: convert to simpler interface.
-- September 6, 1982 8:29 pm: try out tabs and skipOver.
-- RTE: September 6, 1982 8:42 pm: did not skip over enough space.
-- September 18, 1982 12:16 pm: convert to new form using Matrices, Rows, and Columns.
-- September 18, 1982 2:23 pm: add some fill.
-- RTE: September 18, 1982 2:28 pm: got width and heigth reversed in one of the fillers.
-- change: September 18, 1982 3:18 pm: add a different direction matrix to look for right justification., test ropes.
-- CTE: February 11, 1983 12:06 pm: convert to 4.0.  BUildExampleTOol is a CommandProc, and now wants a new param.  Give it NIL.  Obtain exec.out now by GetStreams[exec].out.
-- Change: June 22, 1984 9:51:10 am PDT: convert to Cedar 5.2