/***************************************************************************************/ /* */ /* SCS editor Version 2 */ /* File : EditorsManager.pkg */ /* Version : 29 juin 2000 */ /* Basic functions to run module editors */ /* */ /***************************************************************************************/ /* NOTE IMPORTANTE (pour la mise à jour des données dans l'éditeur): les modifications faites dans le SCS2 ne sont répercutées dans l'éditeur que lors d'une modification du nom du module. Ceci afin de limiter les transferts de données vers l'éditeur et parce que la mise à jour des données de l'éditeur vers le SCS 2 se fait en plusieurs fois (ce qui provoquerait l'update de l'éditeur plusieurs fois) Il est donc important lors des mises à jours des modules de terminer celles-ci par une mise à jour de son nom si ces modifs doivent être répercutées dans l'éditeur. ou Forcer le reflex de modification de module avec le flag REFLEX_OTHER */ /* This structure stores the modifications on a module which are done by several functions in order to apply all in only one function */ struct EMmodifBuffer = [ EMMBdefinitions : [ [S [[S r1] r1] ] r1] , /* definitions buffer */ EMMBbitmapFile : S , /* module bitmap file name */ EMMBname : S /* module name */ ] mkEMmodifBuffer ;; struct EditorsManager = [ EDTSport : I , /* Port for Editors machine communications */ EDTSportRange : I , /* An available port will be searched from port to port+portRange when the machine is connected the port is set to its real value */ EDTSconnecting : I , /* is true when a new machine is connecting */ EDTSchannel : Chn , /* Channel for editors machine com */ EDTSserver : Srv , /* Server */ EDTScmdBuffer : [[Site Module] r1], /* cmd to launch editor when the server is ready */ EDTSlaunchedEditors : [[Site Module] r1], /* list of the module editors launched */ EDTSmodifBuffer : EMmodifBuffer , /* buffer of modifications on a modules */ EDTSbuffer : S /* Buffer for definition blocks transmission */ ] mkEditorsManager ;; typeof CURRENT_EDITORS_MANAGER = EditorsManager;; var EDITOR_CLOSE = 0b00000001;; var EDITOR_MINIMIZE = 0b00000010;; var EDITOR_RESTORE = 0b00000100;; var EDITOR_MAXIMIZE = 0b00001000;; var EDITOR_SAVE = 0b00010000;; var EDITOR_HIDE = 0b00100000;; var EDITOR_UNHIDE = 0b01000000;; var EDITOR_TOP = 0b10000000;; var DEFCOM_BLOCK_SIZE = 1024;; var EXCLUSION_DEFBLOCKS = "scs"::"link"::"zone"::nil;;/*::MOD_BLOCK_SCS::MOD_BLOCK_LINK::"zone"::nil;;*/ defcom CiniEditor = IniEditor I;; /* create a new instance for an editor */ defcom CresetEditor = ResetEditor I;; /* reset an existing instance for an editor (for update)*/ defcom CloadDefBlock = LoadDefBlock I S S;; /* load definition blocks */ defcom CrunEditor = RunEditor I S S S S S S;; /* start the module editor */ defcom CeditorControlWindow = EDITOR_ControlWindow I I;; /* change the editor window state */ defcom CeditorMoveWindow = EDITOR_MoveWindow I I I;; /* move the editor window to the new position x y */ /**************************************************************************************** * * To get a module structure in a list using its key * ****************************************************************************************/ fun _GetModuleByKey (list, key) = let list -> [first next] in if first == nil then nil else let first -> [site module] in if module.MODkey == key then first else _GetModuleByKey next key;; fun _RemoveModuleByKey (list, key) = let list -> [first next] in if first==nil then nil else let first -> [site module] in if module.MODkey==key then next else first::(_RemoveModuleByKey next key);; /**************************************************************************************** * * function called to run a new editor * ****************************************************************************************/ fun _SendDef (edma, key, defName, defString) = let strlen defString -> ll in if ll > DEFCOM_BLOCK_SIZE then let substr defString 0 DEFCOM_BLOCK_SIZE -> sdef in let substr defString DEFCOM_BLOCK_SIZE ll-DEFCOM_BLOCK_SIZE -> ndef in ( _on edma.EDTSchannel CloadDefBlock [nil nil sdef]; _SendDef edma key defName ndef; 0 ) else ( _on edma.EDTSchannel CloadDefBlock [key defName defString]; 0 ) ;; fun _LoadDefinitionsBlock (edma, key, definitions) = let definitions -> [first next] in if first==nil then nil else let first -> [defName defBlock] in ( if str_and_list_cmp defName EXCLUSION_DEFBLOCKS then nil /* some blocks can not be transmitted to the module editor */ else _SendDef edma key defName (strbuild defBlock); _LoadDefinitionsBlock edma key next; 0 ) ;; fun _LaunchEditor (cmd, edma) = let cmd -> [site module] in let MODULECLASS_GetScript module.MODclass -> script in if script==nil then ( SCSGUI_CloseLoadingDialogBox; let MODULE_GetDefBlock module "dmi" -> dmiBlock in if dmiBlock == nil then (MODULE_Destroy site module::nil; 0) else 0 ) else ( _on edma.EDTSchannel CiniEditor [module.MODkey]; _LoadDefinitionsBlock edma module.MODkey module.MODdefinitions; let if MODULE_IsBlackBox module then SCSDATA_GetBlackBoxClassRef else SCSDATA_SearchClassByClass module.MODclass -> classRef in let _checkpack (MODULE_GetBitmapFilename module) -> pp in let if pp==nil then module.MODclass.MODCbitmapFile else MODULE_GetBitmapFilename module -> bitmapFile in _on edma.EDTSchannel CrunEditor [ module.MODkey module.MODname script MODULECLASS_GetVersionName module.MODclass classRef.RMCfilename bitmapFile module.MODclass.MODChelpFile ] ) ;; /**************************************************************************************** * * The only function called from other packages * * fun EDITORSMANAGER_RunEditor(module) = * ****************************************************************************************/ /* The following variable definitions are required by the _setserver function ***********/ var packsusers = ["dms/scs2/Gui/Editors/Loader.pkg" "" ""]::nil;; var scriptserver = "";; var scriptuser = "_load \"dms/scs2/Gui/Editors/EditorsMachine.pkg\"\nmain \":1300\"";; var versionuser = 0;; /* try to run a server testing different ports from port to port+range */ fun _RunServer (port,range) = if range<0 then { ERRORS_AddError 2 7 (_locSCS "errorlabel-7" nil) ; logScsError "_RunServer" (itoa port)::nil "Can not run a new server (port already used?)" nil } else let _setserver _envchannel _channel port nil -> server in if server!=nil then [port server] else _RunServer (port+1) (range-1) ;; /**************************************************************************************** * * Function called when a module is modified * ****************************************************************************************/ fun _UpdateModuleEditor (moduleList, flag, edma) = if (flag==REFLEX_NAME || flag==REFLEX_OTHER) then /* voir la NOTE au début du fichier */ let moduleList -> [module next] in if module==nil then nil else ( _on edma.EDTSchannel CresetEditor [module.MODkey]; _LoadDefinitionsBlock edma module.MODkey module.MODdefinitions; let SCSDATA_SearchClassByClass module.MODclass -> classRef in _on edma.EDTSchannel CrunEditor [ module.MODkey module.MODname MODULECLASS_GetScript module.MODclass MODULECLASS_GetVersionName module.MODclass classRef.RMCfilename MODULE_GetBitmapFilename module module.MODclass.MODChelpFile ]; _UpdateModuleEditor next flag edma; 0 ) else nil;; /**************************************************************************************** * * This function set the state of an editors to the 'stateIn' if its site == 'site', * to the 'stateOut' otherwise. * ****************************************************************************************/ fun _SetEditorsStateBySite (channel, list, site, stateIn, stateOut) = let list -> [first next] in if first == nil then 0 else let first -> [s m] in ( _on channel CeditorControlWindow [m.MODkey (if s==site then stateIn else stateOut)]; _SetEditorsStateBySite channel next site stateIn stateOut ) ;; fun _SiteSelection (site, code, edma) = if code&REFLEX_SELECTION then ( _SetEditorsStateBySite edma.EDTSchannel edma.EDTSlaunchedEditors site EDITOR_RESTORE EDITOR_MINIMIZE; 0 ) else 0 ;; fun _RemoveSite (site, flag, edma) = _SetEditorsStateBySite edma.EDTSchannel edma.EDTSlaunchedEditors site EDITOR_CLOSE 0;; fun EM_CloseEditors (moduleList,code,edma) = if moduleList==nil then 0 else let moduleList -> [module next] in ( _on edma.EDTSchannel CeditorControlWindow [module.MODkey EDITOR_CLOSE]; EM_CloseEditors next code edma );; fun EM_DisplayInfo (edma,module) = { /* time consuming process */ SCSGUI_OpenLoadingDialogBox (_locSCS "editors-LOADINGMODULE" (MODULE_GetName module)::nil); 0 ; };; /**************************************************************************************** * * Main function to create an editors manager * ****************************************************************************************/ fun EDITORSMANAGER_Create () = let PARAMS_GetI SCSparameters "EDITORSMACHINE_PORT" -> port in let PARAMS_GetI SCSparameters "EDITORSMACHINE_PORT_RANGE" -> range in let mkEditorsManager [port range 0 nil nil nil nil nil nil] -> edma in let mkfun3 @_UpdateModuleEditor edma -> upModFun in let mkfun3 @_RemoveSite edma -> removeSiteFun in let mkfun3 @_SiteSelection edma -> selectSiteFun in let mkfun3 @EM_CloseEditors edma -> closeEditors in ( REFLEX_CBsiteSelected selectSiteFun; REFLEX_CBsiteRemoved removeSiteFun; REFLEX_CBmoduleModified upModFun; REFLEX_CBmoduleRemoved closeEditors; set CURRENT_EDITORS_MANAGER = edma; edma ) ;; /**************************************************************************************** * * Main function to run an editor window * ****************************************************************************************/ fun EDITORSMANAGER_RunEditor (edma, site, module) = if edma==nil then nil else let MODULE_GetKey module -> key in if edma.EDTSconnecting then ( set edma.EDTScmdBuffer = [site module]::edma.EDTScmdBuffer; EM_DisplayInfo edma module; 0 ) else if edma.EDTSchannel!=nil then ( let _GetModuleByKey edma.EDTSlaunchedEditors key -> startedEditor in if startedEditor!=nil then ( /*_on edma.EDTSchannel CeditorControlWindow [key EDITOR_HIDE|EDITOR_MINIMIZE]; _on edma.EDTSchannel CeditorControlWindow [key EDITOR_RESTORE];*/ _on edma.EDTSchannel CeditorControlWindow [key EDITOR_RESTORE|EDITOR_TOP]; 0 ) else ( EM_DisplayInfo edma module; _LaunchEditor [site module] edma; set edma.EDTScmdBuffer =[site module]::edma.EDTScmdBuffer; 0 ) ) else if edma.EDTSserver!=nil then nil else let _RunServer edma.EDTSport edma.EDTSportRange -> [port server] in let strcatn "_load \"dms/scs2/Gui/editors/Loader.pkg\"\n":: "load\nmain \":"::(itoa port)::"\""::nil -> script in ( EM_DisplayInfo edma module; set edma.EDTSconnecting = 1; set edma.EDTSserver = server; set edma.EDTSport = port; _newmachine "SCSmoduleEditors" script nil nil ; set edma.EDTScmdBuffer = [site module]::edma.EDTScmdBuffer; set edma.EDTSlaunchedEditors = nil; 0 ) ;; fun EDITORSMANAGER_ControlEditors (edma, modList, state) = let modList -> [module next] in if module == nil then 0 else ( _on edma.EDTSchannel CeditorControlWindow [module.MODkey state]; EDITORSMANAGER_ControlEditors edma next state ) ;; fun EDITORSMANAGER_MoveEditor (edma, module, posx, posy) = _on edma.EDTSchannel CeditorMoveWindow [module.MODkey posx posy] ;; fun EDITORSMANAGER_ControlEditorsBySite (edma, site, stateIn, stateOut) = _SetEditorsStateBySite edma.EDTSchannel edma.EDTSlaunchedEditors site stateIn stateOut;; /**************************************************************************************** * * function called to close the editors machine * ****************************************************************************************/ fun EDITORSMANAGER_DestroyEditors () = 0 /* need to beimplemented */ ;; /**************************************************************************************** * * Communication functions * ****************************************************************************************/ fun filter()= let _fooS _channelIP _channel -> ip in (strcmp ip "127.0.0.1") && (strcmp ip _hostIP) && (strcmp ip "unplugged");; fun _connected () = if filter then ( _closechannel; 0 ) else 0 ;; fun _closed () = let CURRENT_EDITORS_MANAGER -> edma in ( _killchannel edma.EDTSchannel; _closeserver edma.EDTSserver; set edma.EDTSchannel = nil; set edma.EDTSserver = nil; SCSGUI_CloseLoadingDialogBox; /********* to relaunch editors after a crash ****** set edma.EDTScmdBuffer = tl edma.EDTSlaunchedEditors; EDITORSMANAGER_RunEditor hd edma.EDTSlaunchedEditors ***************************************************/ set edma.EDTScmdBuffer = nil ) ;; /**************************************************************************************** * * This function is called by the EditorsMachine when it is ready to receive requests * ****************************************************************************************/ fun __EditorsMachineStarted () = let CURRENT_EDITORS_MANAGER -> edma in ( set edma.EDTSconnecting = 0; set edma.EDTSchannel = _channel; apply_on_list edma.EDTScmdBuffer @_LaunchEditor edma /* set edma.EDTScmdBuffer = nil */ ) ;; /**************************************************************************************** * * This function is called by the EditorsMachine when an Editor has been * successfully started * ****************************************************************************************/ fun __EditorStarted (key) = let CURRENT_EDITORS_MANAGER -> edma in let _GetModuleByKey edma.EDTScmdBuffer key -> [site module] in if site == nil then nil else ( set edma.EDTSlaunchedEditors = [site module]::edma.EDTSlaunchedEditors; set edma.EDTScmdBuffer = _RemoveModuleByKey edma.EDTScmdBuffer key; SCSGUI_CloseLoadingDialogBox; 0 );; fun __EditorClosed (key, posx, posy) = let CURRENT_EDITORS_MANAGER -> edma in let _GetModuleByKey edma.EDTSlaunchedEditors key -> [site module] in set edma.EDTSlaunchedEditors = _RemoveModuleByKey edma.EDTSlaunchedEditors key ;; /**************************************************************************************** * * Reset the all the definitions but the EXCLUSION_DEFBLOCKS ones * ****************************************************************************************/ fun __ResetDefinitions (key) = let CURRENT_EDITORS_MANAGER -> edma in set edma.EDTSmodifBuffer = mkEMmodifBuffer [nil nil nil];; /**************************************************************************************** * * Write a definition block in the module * ****************************************************************************************/ fun __SetDefBlock (key, defName, defBlockPacket) = let CURRENT_EDITORS_MANAGER -> edma in if key!=nil && defName!=nil then let _GetModuleByKey edma.EDTSlaunchedEditors key -> [_ module] in let strextr (strcat edma.EDTSbuffer defBlockPacket) -> defBlock in let edma.EDTSmodifBuffer.EMMBdefinitions -> defsBuffer in ( set edma.EDTSmodifBuffer.EMMBdefinitions = _SetDefBlock edma.EDTSmodifBuffer.EMMBdefinitions defName defBlock; set edma.EDTSbuffer = nil; 0 ) else ( set edma.EDTSbuffer = strcat edma.EDTSbuffer defBlockPacket; 0 ) ;; /**************************************************************************************** * * Write the module bitmap file name * ****************************************************************************************/ fun __SetModuleBitmap (key, fileName) = set CURRENT_EDITORS_MANAGER.EDTSmodifBuffer.EMMBbitmapFile = fileName; 0 ;; /**************************************************************************************** * * Apply all the modifications on the definitions and * Write the module name * ****************************************************************************************/ /* JOOL ICI -> todo: mettre cette fonction dans l'interface du module ? */ fun EM_GetCustomDefsWithoutExcludedDefBlocks (definitions) = if definitions == nil then nil else let definitions -> [firstDef nextDefs] in let firstDef -> [defName _] in if str_and_list_cmp defName EXCLUSION_DEFBLOCKS then EM_GetCustomDefsWithoutExcludedDefBlocks nextDefs else firstDef::(EM_GetCustomDefsWithoutExcludedDefBlocks nextDefs);; fun EM_UndoRename (list) = if list == nil then nil else let list -> [first next] in let first -> [io [old [new _]]] in (io::new::old::nil)::(EM_UndoRename next) ;; fun EM_CreateModifsRecord (site, module, newState) = if MODULE_IsBlackBox module then MODULE_SetCustomDefinition site module MOD_BLOCK_REN EM_UndoRename (_GetDefBlock newState.EMMBdefinitions MOD_BLOCK_REN) else nil; mkEMmodifBuffer [ (EM_GetCustomDefsWithoutExcludedDefBlocks module.MODdefinitions) /* JOOL ICI voir remarque ci-dessus */ (getInfo (MODULE_GetCustomDefinition module "dmi") "bitmap") (MODULE_GetName module) ] ;; fun EM_ApplyModifs (site, module, modifs) = let _GetDefBlocks module EXCLUSION_DEFBLOCKS -> scsDefs in let _GetDefBlock modifs.EMMBdefinitions "dmi" -> dmiBlock in if dmiBlock == nil then nil else ( /* reinit the definitions */ set module.MODdefinitions = scsDefs; /* and set the new ones from the editor */ MODULE_SetCustomDefinitions site module modifs.EMMBdefinitions; /* set the bitmap file */ if (strlen modifs.EMMBbitmapFile)>0 then MODULE_SetDefLine module MOD_BLOCK_DMI "bitmap" modifs.EMMBbitmapFile::nil else nil; MODULE_SetBitmap module modifs.EMMBbitmapFile; /* finally set the name */ if (strlen modifs.EMMBname)>0 then MODULE_SetDefLine module MOD_BLOCK_DMI "name" modifs.EMMBname::nil else nil; if module == SITE_GetModuleRoot site then SITE_SetName site modifs.EMMBname 0 else MODULE_SetName site module modifs.EMMBname 1; 0 ) ;; /* function called when a module is created (ok button clicked in an editor ) */ proto CREATIONTREE_RunModuleEditor = fun [Site Module EditorsManager] I;; proto EM_CreatedModule = fun [Site Module Module] I;; fun EM_CreatedModule (site, newmodule, father) = let CURRENT_EDITORS_MANAGER -> edma in let MODULE_GetName newmodule -> name in let MODULE_GetClass newmodule -> class in let MODULE_GetPosition newmodule -> position in let mkfun3 @CREATIONTREE_RunModuleEditor edma -> creationReflex in ( HISTORY_AddCurrentSite _locSCS "undo-MODULECREATED" name::nil mkfun1 mkfun2 @MODULE_DestroySingleElt site newmodule mkfun1 mkfun2 mkfun3 @EM_CreatedModule father newmodule site; if father != nil then /* insert module as father child */ SITE_InsertNewModule site father newmodule else /* insert module as root child */ SITE_InsertNewModule site (SITE_GetModuleRoot site) newmodule; REFLEX_ModuleAdded newmodule::nil nil; SELECT_NewModule newmodule::nil REFLEX_PRIORITY_ONE ) ;; fun __SetModuleNameAndApply (key, moduleName) = let CURRENT_EDITORS_MANAGER -> edma in let _GetModuleByKey edma.EDTSlaunchedEditors key -> [site module] in ( /* complete the modif record */ set edma.EDTSmodifBuffer.EMMBname = moduleName; /* Undo/Redo */ let edma.EDTSmodifBuffer -> newState in let EM_CreateModifsRecord site module newState -> oldState in if (_GetDefBlock oldState.EMMBdefinitions "dmi") == nil then ( /* apply modifs this is a new module */ if (_GetDefBlock newState.EMMBdefinitions "dmi") == nil then nil else ( let SITE_GetModuleCurrentBlackBox site -> father in EM_CreatedModule site module father; EM_ApplyModifs site module edma.EDTSmodifBuffer ); 0 ) else ( /* apply modif on an existing module */ EM_ApplyModifs site module edma.EDTSmodifBuffer; HISTORY_AddCurrentSite _locSCS "undo-MODULE-DEFINITIONS" moduleName::nil mkfun1 mkfun2 mkfun3 @EM_ApplyModifs oldState module site mkfun1 mkfun2 mkfun3 @EM_ApplyModifs newState module site; 0 ) ) ;; /**************************************************************************************** * * to the mainwin Keyboard reflexes * ****************************************************************************************/ fun __SendKeyboardEvent (down,scancode,asciicode)= if down then KEYBOARD_ProcessKeyDownCode scancode asciicode else KEYBOARD_ProcessKeyUpCode scancode asciicode ;;