The Meta-Environment API

sdf-actions.tb

Go to the documentation of this file.
00001 #ifndef __SDF_ACTIONS__
00002 #define __SDF_ACTIONS__
00003 
00004 #include <config-utils.tb>
00005 #include <sdf-namespace.h>
00006 #include <gui-utils.tb>
00007 #include <module-utils.tb>
00008 
00009 process ChangeWorkspaceAction is
00010 let
00011   Cancel: bool,
00012   Path: str
00013 in
00014   PromptForDirectory("Workspace", [], Cancel?, Path?)
00015   .
00016   if equal(Cancel, true) then
00017     tau
00018   else
00019     snd-msg(cm-change-workspace(Path))
00020   fi
00021 endlet
00022 
00023 process CloseAllAction is
00024 let
00025   Id: term,
00026   ModuleId: module-id,
00027   Modules: list
00028 in
00029   Id := process-id
00030   . MM-GetAllModules(Modules?)
00031   . CloseModules(Modules)
00032 endlet
00033 
00034 process NewModuleAction is
00035 let
00036   Cancel: bool,
00037   Extension : str,
00038   Directory : str,
00039   Pid: int,
00040   FileName : str,
00041   Path : str,
00042   Paths: list
00043 in
00044   GetSearchPaths(Paths?)
00045   . PromptForFileWithExtension("New Module", Paths, SDF_EXTENSION, Cancel?, Path?)
00046   .
00047   if equal(Cancel, true) then
00048     tau
00049   else
00050     SplitFilename(Path, FileName?, Directory?, Extension?)
00051     . create(NewModuleContentHandler(), Pid?)
00052     . CreateNewModule(Pid, Directory, FileName)
00053   fi
00054 endlet
00055 
00056 process DefaultPrettyPrintAction(EditorId : session-id) is
00057 let
00058   Tree : term,
00059   RTree : term,
00060   ModuleId: module-id,
00061   Path: str
00062 in
00063   GetModuleId(EditorId, ModuleId?)
00064   . GetPath(EditorId, Path?)
00065   . GetTermParsetree(ModuleId, Path, Tree?)
00066   .
00067   if not-equal(Tree, UNDEFINED) then
00068     PrettyPrint(Path, Tree, RTree?)
00069     . 
00070     if not-equal(RTree, UNDEFINED) then
00071       ReplaceFocus(EditorId, RTree)
00072     else 
00073       tau
00074     fi
00075   else tau
00076   fi
00077 endlet
00078 
00079 process OpenModuleAction is
00080 let
00081   Cancel: bool,
00082   Event: attribute-changed-event,
00083   Extension : str,
00084   Directory : str,
00085   Path : str,
00086   Idle: term,
00087   Filename : str,
00088   RelativeFilename : str,
00089   ModuleId : module-id,
00090   Paths: list,
00091   FoundPath: str,
00092   Prefix: str,
00093   HasAttribute: bool
00094 in
00095   GetSearchPaths(Paths?)
00096   . PromptForFileWithExtension("Open Module", Paths, SDF_EXTENSION, Cancel?, Path?)
00097   .
00098   if equal(Cancel, true) then
00099     tau
00100   else
00101     if equal(Path, "") then
00102       tau
00103     else
00104       SplitFilename(Path, Filename?, Directory?, Extension?)
00105       . snd-msg(io-get-relative-filename(Paths, Path, Extension))
00106       . rec-msg(io-filename(Paths, Path, Extension, Prefix?, RelativeFilename?))
00107       . BuildPath(Prefix, RelativeFilename, Extension, FoundPath?)
00108       .
00109       if equal(FoundPath, Path) then
00110     snd-msg(tm-request-transaction(module-manager))
00111         . OpenModule(RelativeFilename, ModuleId?)
00112     . MM-Subscribe-Attribute-Changed(ModuleId,META_NAMESPACE,"idle",<term>,yes)
00113     . MM-HasAttribute(ModuleId, META_NAMESPACE, "idle", HasAttribute?) 
00114     .
00115     if equal(HasAttribute, true) then
00116       MM-GetAttribute(ModuleId, META_NAMESPACE, "idle", Idle?)
00117     else
00118       tau
00119     fi
00120         .
00121     if or(not-equal(Idle, yes), equal(HasAttribute, false)) then
00122           rec-note(mm-attribute-changed(Event?))
00123     else
00124       tau
00125     fi
00126     . snd-msg(tm-end-transaction(module-manager))
00127         . SelectModule(ModuleId)
00128       else
00129         printf("warning: The chosen Module is shadowed by another module in the search path: %s\n", FoundPath)
00130       fi
00131     fi
00132   fi
00133 endlet
00134 
00135 
00136 process DumpParseTableAction(ModuleId : module-id) is
00137 let
00138   Cancel: bool,
00139   Path : str
00140 in
00141   PromptForFileWithExtension("Export Term ParseTable", [], ".trm.tbl", Cancel?, Path?)
00142   .
00143   if equal(Cancel, true) then
00144     tau
00145   else
00146     DumpParseTable(ModuleId, SDF_NAMESPACE, Path, trm)
00147   fi
00148 endlet
00149 
00150 process EditorDumpParseTableAction(EditorId : session-id) is
00151 let
00152   Cancel: bool,
00153   Path : str,
00154   ModuleId : module-id
00155 in
00156   GetModuleId(EditorId, ModuleId?)
00157   . PromptForFileWithExtension("Export Term ParseTable", [], ".trm.tbl", Cancel?, Path?)
00158   .
00159   if equal(Cancel, true) then
00160     tau
00161   else
00162     DumpParseTable(ModuleId, SDF_NAMESPACE, Path, trm)
00163   fi
00164 endlet
00165 
00166 process DumpSdfDefinitionAction(ModuleId : module-id) is
00167 let
00168   Cancel: bool,
00169   Path : str
00170 in
00171   PromptForFileWithExtension("Export SDF Definition", [], ".def", Cancel?, Path?)
00172   .
00173   if equal(Cancel, true) then
00174     tau
00175   else
00176     snd-msg(tm-request-transaction(syntax-definition))
00177     . DumpSdfDefinition(ModuleId, Path)
00178     . snd-msg(tm-end-transaction(syntax-definition))
00179   fi
00180 endlet
00181 
00182 process CloseModuleAction(ModuleId : module-id) is
00183 let
00184   Answer     : term,
00185   Recursive  : bool
00186 in
00187   AskQuestion("Do you want to recursively close the imported modules?", Answer?)
00188   . 
00189   if equal(Answer, cancel) then
00190     tau
00191   else
00192     if equal(Answer, yes) then
00193       Recursive := true
00194     else
00195       Recursive := false
00196     fi 
00197     . CloseModule(ModuleId, Recursive)
00198   fi
00199 endlet
00200 
00201 process CloseOtherModulesAction(ModuleId : module-id) is
00202   CloseOtherModules(ModuleId) 
00203 
00204 process ExtractSDFAction(ModuleId : module-id) is
00205   SDFExtraction(ModuleId)
00206 
00207 #ifdef DEAD
00208 process RenameModuleAction(Modulename : str) is
00209 let
00210   Cancel: bool,
00211   Directory : str,
00212   Filename : str,
00213   Extension : str,
00214   Path : str,
00215   Paths : list
00216 in
00217   GetSearchPaths(Paths?)
00218   . PromptForFileWithExtension("Rename module to", Paths, SDF_EXTENSION, Cancel?, Path?)
00219   . 
00220   if equal(Cancel, true) then
00221     tau
00222   else
00223     SplitFilename(Path, Filename?, Directory?, Extension?)
00224     . RenameModule(Modulename, Directory, Filename)
00225   fi
00226 endlet
00227 
00228 process CopyModuleAction(Modulename : str) is
00229 let
00230   Cancel: bool,
00231   Path : str,
00232   Directory : str,
00233   Filename : str,
00234   Extension : str,
00235   Paths : list
00236 in
00237   GetSearchPaths(Paths?)
00238   . PromptForFileWithExtension("Copy module to", Paths, SDF_EXTENSION, Cancel?, Path?)
00239   .
00240   if equal(Cancel, true) then
00241     tau
00242   else
00243     SplitFilename(Path, Filename?, Directory?, Extension?)
00244     . CopySdfModule(Modulename, Directory, Filename)
00245     . CopyAsfModule(Modulename, Directory, Filename)
00246   fi
00247 endlet
00248 
00249 process DeleteModuleAction(Modulename : str) is
00250 let
00251   Answer : term
00252 in
00253   AskQuestion("Are you sure you want delete this module (from disk)?", Answer?)
00254   . if equal(Answer, cancel) then
00255       tau
00256     else
00257       if equal(Answer, yes) then
00258         DeleteModule(Modulename)
00259       else
00260         tau
00261       fi 
00262     fi
00263 endlet
00264 
00265 
00266 process AddImportAction(Modulename: str) is
00267 let
00268   Id: int,
00269   Import: str,
00270   Options: list
00271 in
00272   Id := process-id
00273   . snd-msg(get-all-module-names)
00274   . rec-msg(all-module-names(Options?))
00275   . snd-msg(show-list-choice(Modulename, "Choose a module to import", Options))
00276   .
00277   (
00278     rec-msg(list-choice(Modulename, Import?))
00279     . snd-note(ui-status(statf(Id, "Adding import %s to %s",
00280                                [Import, Modulename])))
00281     . AddImport(Modulename, Import)
00282     . snd-note(ui-status(endstat(Id)))
00283   +
00284     rec-msg(cancel-list-choice(Modulename))
00285   )
00286 endlet
00287 
00288 process RemoveImportAction(Modulename: str) is
00289 let
00290   Id: int,
00291   Import: str,
00292   Options: list
00293 in
00294   Id := process-id
00295   . snd-msg(get-imported-modules(Modulename))
00296   . rec-msg(imported-modules(Options?))
00297   . snd-msg(show-list-choice(Modulename, "Choose an import to remove", Options))
00298   .
00299   (
00300     rec-msg(list-choice(Modulename, Import?))
00301     . snd-note(ui-status(statf(Id, "Removing import %s from %s",
00302                                [Import, Modulename])))
00303     . RemoveImport(Modulename, Import)
00304     . snd-note(ui-status(endstat(Id)))
00305   +
00306     rec-msg(cancel-list-choice(Modulename))
00307   )
00308 endlet
00309 
00310 #endif
00311 #endif /*__SDF_ACTIONS__*/

Generated on Fri Sep 12 13:09:47 2008 for sdf-meta by  doxygen 1.4.6