ColorTrixGalleryImpl.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Bloomenthal, January 29, 1987 2:32:53 pm PST
DIRECTORY Buttons, ColorTrixDispatch, Commander, CommandTool, Containers, FileNames, FS, IO, MessageWindow, Process, Rope, ViewerClasses, ViewerOps;
ColorTrixGalleryImpl: CEDAR PROGRAM
IMPORTS Buttons, ColorTrixDispatch, CommandTool, Containers, FileNames, FS, IO, MessageWindow, Process, Rope, ViewerOps
~ BEGIN
ROPE: TYPE ~ Rope.ROPE;
GalleryData: TYPE ~ RECORD [
cmd: Commander.Handle ← NIL,
ctView: Commander.CommandProc ← NIL,
viewer, printButton: ViewerClasses.Viewer ← NIL,
filenames: LIST OF ROPENIL,
currentName: LIST OF ROPENIL
];
CtGallery: PUBLIC Commander.CommandProc ~ {
FirstChar: PUBLIC PROC [rope: ROPE, char: CHAR] RETURNS [BOOL] ~ {
RETURN[rope.Length[] > 0 AND rope.Fetch[0] = char];
};
LastChar: PUBLIC PROC [rope: ROPE, char: CHAR] RETURNS [BOOL] ~ {
ropeLength: INT ← rope.Length[];
RETURN[ropeLength > 0 AND rope.Fetch[ropeLength-1] = char];
};
RopeShorten: PUBLIC PROC [rope: ROPE, n: INT] RETURNS [ROPE] ~ {
ropeLength: INT ← rope.Length[];
IF ropeLength >= n THEN rope ← rope.Substr[0, ropeLength-n];
RETURN [rope];
};
args: CommandTool.ArgumentVector ← CommandTool.Parse[cmd];
gd: REF GalleryData ← NEW[GalleryData ← [cmd: cmd]];
FOR i: INT IN [1..args.argc) DO
IF NOT FirstChar[args[i], '-] THEN {
EachName: FS.NameProc ~ {
Process.CheckForAbort[];
gd.filenames ← CONS[FileNames.ConvertToSlashFormat[fullFName], gd.filenames];
RETURN[TRUE];
};
Pattern: PROC [arg: ROPE] RETURNS [ROPE] ~ {
star: BOOL ← LastChar[arg, '*];
errorMsg ← NIL;
WHILE LastChar[arg, '*] DO arg ← RopeShorten[arg, 1]; ENDLOOP;
IF Rope.IsEmpty[arg] OR LastChar[arg, '/] OR LastChar[arg, '>] THEN RETURN[NIL];
arg ← FileNames.ResolveRelativePath[arg];     -- handle .> or ..>
arg ← Rope.Concat[arg, "*"];         -- ensure FName
arg ← FS.ExpandName[arg ! FS.Error => {
errorMsg ← error.explanation; CONTINUE}].fullFName;
IF errorMsg # NIL THEN RETURN[NIL];
IF NOT star THEN arg ← RopeShorten[arg, 1];    -- remove '*
RETURN[Rope.Concat[arg, "!H"]];
};
errorMsg: ROPENIL;
pattern: ROPE ~ Pattern[args[i]];
IF pattern = NIL
THEN IO.PutRope[cmd.err, errorMsg]
ELSE FS.EnumerateForNames[pattern, EachName ! FS.Error => CONTINUE];
};
ENDLOOP;
IF gd.filenames = NIL THEN {Blink["No such files"]; RETURN};
gd.viewer ← Containers.Create[
info: [name: "Ct Gallery", openHeight: 33, iconic: TRUE, column: right, scrollable: FALSE],
paint: FALSE];
gd.currentName ← gd.filenames;
[] ← Buttons.Create[info: [parent: gd.viewer, name: "Next Picture", wx: 7, wy: 2],
proc: Next, clientData: gd, paint: TRUE];
ViewerOps.OpenIcon[gd.viewer];
gd.ctView ← ColorTrixDispatch.GetCtOp["View"].proc;
Show[gd];
};
Blink: PROC [rope: ROPE] ~ {
MessageWindow.Append[rope, TRUE];
MessageWindow.Blink[];
};
Show: PROC [gd: REF GalleryData] ~ {
result: ROPE;
IF gd.currentName = NIL THEN RETURN;
gd.cmd.commandLine ← Rope.Concat[gd.currentName.first, "\n"];
MessageWindow.Append[gd.currentName.first, TRUE];
IF (result ← gd.ctView[gd.cmd].msg) # NIL THEN Blink[result];
IF gd.currentName = gd.filenames THEN MessageWindow.Append[" (. . . first)"];
IF (gd.currentName ← gd.currentName.rest) = NIL THEN {
gd.currentName ← gd.filenames;
MessageWindow.Append[" (. . . last)"];
};
};
Next: Buttons.ButtonProc ~ {Show[NARROW[clientData]]};
Start Code
ColorTrixDispatch.RegisterCtOp[
"Gallery", CtGallery, "Ct Gallery {pattern and/or list of filenames}."];
END.