<<>> <> <> <> <<>> DIRECTORY IO, Menus USING [AppendMenuEntry, ClickProc, CreateEntry, FindEntry, MenuEntry, ReplaceMenuEntry], MessageWindow, Rope, <> TEditInput, <> TextNode, TiogaMenuOps USING [tiogaMenu], TiogaMesaOps, TiogaExecCommands, TiogaIO, TiogaIOExtras, TiogaOps, <> ViewerOps, ViewerTools; TiogaPlainImpl: CEDAR PROGRAM IMPORTS IO, Menus, MessageWindow, Rope, TEditInput, <> TextNode, TiogaExecCommands, TiogaIO, TiogaIOExtras, TiogaMenuOps, TiogaMesaOps, TiogaOps, ViewerOps, ViewerTools ~ BEGIN ROPE: TYPE = Rope.ROPE; Node: TYPE ~ TextNode.Ref; InstallMenuButton: PROC [name: ROPE, proc: Menus.ClickProc] = { old: Menus.MenuEntry = Menus.FindEntry[menu: TiogaMenuOps.tiogaMenu, entryName: name]; new: Menus.MenuEntry = Menus.CreateEntry[name: name, proc: proc, fork: FALSE]; IF old = NIL THEN Menus.AppendMenuEntry[TiogaMenuOps.tiogaMenu, new] ELSE Menus.ReplaceMenuEntry[TiogaMenuOps.tiogaMenu, old, new]; }; PlainClick: Menus.ClickProc ~ { TEditInput.InterpretAtom[parent, $MakePlain]; }; CedarClick: Menus.ClickProc ~ { TEditInput.InterpretAtom[parent, $MakeCedar]; }; <> <> < {>> <> <0 THEN RETURN [lt[0].pos.where];>> <<};>> < {}>> <<};>> defaultNestIndent: Rope.ROPE ¬ " "; MakePlain: TEditInput.CommandProc ~ { <<--This causes ugly repositioning; can that be fixed?>> root: Node ~ TiogaOps.ViewerDoc[viewer]; Inner: PROC [root: Node] ~ { r: ROPE ¬ TiogaIO.RopeFromSimpleDoc[root]; SELECT TRUE FROM NOT Rope.IsEmpty[r] => MessageWindow.Append["Document is already plain", TRUE]; viewer.link#NIL => MessageWindow.Append["Can't do this with split views", TRUE]; ENDCASE => { s: IO.STREAM ~ IO.ROS[]; TiogaIOExtras.WritePlain[s, root, TRUE, defaultNestIndent]; r ¬ IO.RopeFromROS[s]; ViewerTools.SetTiogaContents[viewer, NEW[ViewerTools.TiogaContentsRec ¬ [contents: r, formatting: NIL]], TRUE]; ViewerOps.SetNewVersion[viewer]; }; }; TiogaOps.CallWithLocks[Inner, root]; RETURN [recordAtom: TRUE, quit: TRUE]; }; defaultTabIndent: INT ¬ 8; MakeCedar: TEditInput.CommandProc ~ { <<--This causes ugly repositioning; can that be fixed?>> root: Node ~ TiogaOps.ViewerDoc[viewer]; Inner: PROC [root: Node] ~ { r: ROPE ~ TiogaIO.RopeFromSimpleDoc[root]; SELECT TRUE FROM Rope.IsEmpty[r] => MessageWindow.Append["Document is not plain", TRUE]; viewer.link#NIL => MessageWindow.Append["Can't do this with split views", TRUE]; ENDCASE => { <> node: Node ¬ TiogaExecCommands.ReadIndent[r, defaultTabIndent]; ViewerOps.SetViewer[viewer: viewer, data: node, op: $TiogaDocument]; node ¬ TiogaOps.ViewerDoc[viewer]; [] ¬ TiogaMesaOps.SpanMesaLooks[ span: TextNode.MakeNodeSpan[node, TextNode.LastWithin[node]], root: node ]; <> }; }; TiogaOps.CallWithLocks[Inner, root]; RETURN [recordAtom: TRUE, quit: TRUE]; }; TEditInput.Register[$MakePlain, MakePlain]; TEditInput.Register[$MakeCedar, MakeCedar]; InstallMenuButton["Plain", PlainClick]; InstallMenuButton["Cedar", CedarClick]; END.