The Meta-Environment API
00001 #ifndef __RSCRIPT_ACTIONS__ 00002 #define __RSCRIPT_ACTIONS__ 00003 00004 #include <config-utils.tb> 00005 #include <rscript-namespace.h> 00006 #include <gui-utils.tb> 00007 #include <pretty-print-utils.tb> 00008 #include <rscriptcalculator.idef> 00009 #include <rscripttestsuite.idef> 00010 00011 process StopScriptAction is 00012 snd-note(interrupt-rscript) 00013 00014 process StopEditorScriptAction(EditorId : session-id) is 00015 snd-note(interrupt-rscript) 00016 00017 process ChangeWorkspaceAction is 00018 let 00019 Cancel: bool, 00020 Path: str 00021 in 00022 PromptForDirectory("Workspace", [], Cancel?, Path?) 00023 . 00024 if equal(Cancel, true) then 00025 tau 00026 else 00027 snd-msg(cm-change-workspace(Path)) 00028 fi 00029 endlet 00030 00031 process CloseAllAction is 00032 let 00033 Id: term, 00034 ModuleId: module-id, 00035 Modules: list 00036 in 00037 Id := process-id 00038 . MM-GetAllModules(Modules?) 00039 . CloseModules(Modules) 00040 endlet 00041 00042 process NewModuleAction is 00043 let 00044 Cancel: bool, 00045 Extension : str, 00046 Directory : str, 00047 Pid: int, 00048 FileName : str, 00049 Path : str, 00050 Paths: list 00051 in 00052 GetSearchPaths(Paths?) 00053 . PromptForFileWithExtension("New Module", Paths, RSCRIPT_EXTENSION, Cancel?, Path?) 00054 . 00055 if equal(Cancel, true) then 00056 tau 00057 else 00058 SplitFilename(Path, FileName?, Directory?, Extension?) 00059 . create(NewModuleContentHandler(), Pid?) 00060 . CreateNewModule(Pid, Directory, FileName) 00061 fi 00062 endlet 00063 00064 process DefaultPrettyPrintAction(EditorId : session-id) is 00065 let 00066 Tree : term, 00067 RTree : term, 00068 ModuleId: module-id, 00069 Path: str 00070 in 00071 GetModuleId(EditorId, ModuleId?) 00072 . GetRSCRIPTParsetree(ModuleId, Tree?) 00073 . 00074 if not-equal(Tree, UNDEFINED) then 00075 PrettyPrint(Path, Tree, RTree?) 00076 . 00077 if not-equal(RTree, UNDEFINED) then 00078 ReplaceFocus(EditorId, RTree) 00079 else 00080 tau 00081 fi 00082 else tau 00083 fi 00084 endlet 00085 00086 process OpenModuleAction is 00087 let 00088 Cancel: bool, 00089 Event: attribute-changed-event, 00090 Extension : str, 00091 Directory : str, 00092 Path : str, 00093 Idle: term, 00094 Filename : str, 00095 RelativeFilename : str, 00096 ModuleId : module-id, 00097 Paths: list, 00098 FoundPath: str, 00099 Prefix: str, 00100 HasAttribute: bool 00101 in 00102 GetSearchPaths(Paths?) 00103 . PromptForFileWithExtension("Open Module", Paths, RSCRIPT_EXTENSION, Cancel?, Path?) 00104 . 00105 if equal(Cancel, true) then 00106 tau 00107 else 00108 if equal(Path, "") then 00109 tau 00110 else 00111 SplitFilename(Path, Filename?, Directory?, Extension?) 00112 . snd-msg(io-get-relative-filename(Paths, Path, Extension)) 00113 . rec-msg(io-filename(Paths, Path, Extension, Prefix?, RelativeFilename?)) 00114 . BuildPath(Prefix, RelativeFilename, Extension, FoundPath?) 00115 . 00116 if equal(FoundPath, Path) then 00117 snd-msg(tm-request-transaction(module-manager)) 00118 . OpenModule(RelativeFilename, ModuleId?) 00119 . MM-Subscribe-Attribute-Changed(ModuleId,META_NAMESPACE,"idle",<term>,yes) 00120 . MM-HasAttribute(ModuleId, META_NAMESPACE, "idle", HasAttribute?) 00121 . 00122 if equal(HasAttribute, true) then 00123 MM-GetAttribute(ModuleId, META_NAMESPACE, "idle", Idle?) 00124 else 00125 tau 00126 fi 00127 . 00128 if or(not-equal(Idle, yes), equal(HasAttribute, false)) then 00129 rec-note(mm-attribute-changed(Event?)) 00130 else 00131 tau 00132 fi 00133 . snd-msg(tm-end-transaction(module-manager)) 00134 . SelectModule(ModuleId) 00135 else 00136 printf("warning: The chosen Module is shadowed by another module in the search path: %s\n", FoundPath) 00137 fi 00138 fi 00139 fi 00140 endlet 00141 00142 process DumpParseTableAction(ModuleId : module-id) is 00143 let 00144 Cancel: bool, 00145 Path : str 00146 in 00147 PromptForFileWithExtension("Export Term ParseTable", [], ".trm.tbl", Cancel?, Path?) 00148 . 00149 if equal(Cancel, true) then 00150 tau 00151 else 00152 DumpParseTable(ModuleId, RSCRIPT_NAMESPACE, Path, trm) 00153 fi 00154 endlet 00155 00156 process EditorDumpParseTableAction(EditorId : session-id) is 00157 let 00158 Cancel: bool, 00159 Path : str, 00160 ModuleId : module-id 00161 in 00162 GetModuleId(EditorId, ModuleId?) 00163 . PromptForFileWithExtension("Export Term ParseTable", [], ".trm.tbl", Cancel?, Path?) 00164 . 00165 if equal(Cancel, true) then 00166 tau 00167 else 00168 DumpParseTable(ModuleId, RSCRIPT_NAMESPACE, Path, trm) 00169 fi 00170 endlet 00171 00172 process DumpRScriptDefinitionAction(ModuleId : module-id) is 00173 let 00174 Cancel: bool, 00175 Path : str 00176 in 00177 PromptForFileWithExtension("Export RSCRIPT Definition", [], ".def", Cancel?, Path?) 00178 . 00179 if equal(Cancel, true) then 00180 tau 00181 else 00182 snd-msg(tm-request-transaction(syntax-definition)) 00183 . DumpRScriptDefinition(ModuleId, Path) 00184 . snd-msg(tm-end-transaction(syntax-definition)) 00185 fi 00186 endlet 00187 00188 process CloseModuleAction(ModuleId : module-id) is 00189 let 00190 Answer : term, 00191 Recursive : bool 00192 in 00193 /* 00194 AskQuestion("Do you want to recursively close the imported modules?", Answer?) 00195 . 00196 if equal(Answer, cancel) then 00197 tau 00198 else 00199 if equal(Answer, yes) then 00200 Recursive := true 00201 else 00202 Recursive := false 00203 fi 00204 . CloseModule(ModuleId, Recursive) 00205 fi 00206 */ 00207 CloseModule(ModuleId, false) 00208 endlet 00209 00210 process CloseOtherModulesAction(ModuleId : module-id) is 00211 CloseOtherModules(ModuleId) 00212 00213 process ExtractRSCRIPTAction(ModuleId : module-id) is 00214 let 00215 Syntax : term, 00216 Store : term, 00217 RStore : rstore, 00218 Modulename : str 00219 in 00220 GetSyntaxDefinition(ModuleId, Syntax?) 00221 . MM-GetAttribute(ModuleId, RSCRIPT_NAMESPACE, "name", Modulename?) 00222 . snd-msg(es-extract-rscript(Syntax)) 00223 . rec-msg(es-rscript-store(Store?)) 00224 . snd-msg(rs-lower-rstore(Store)) 00225 . rec-msg(rs-lowered-rstore(RStore?)) 00226 . snd-msg(rc-load-rstore(Modulename, RStore)) 00227 endlet 00228 00229 process RunRScriptAction(ModuleId : module-id) is 00230 RunRScript(ModuleId) 00231 00232 process RunRScriptWithRStoreAction(ModuleId : module-id) is 00233 RunRScriptWithRStore(ModuleId) 00234 00235 process TestRScriptAction(ModuleId : module-id) is 00236 TestRScript(ModuleId) 00237 00238 #endif /*__RSCRIPT_ACTIONS__*/