home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / SCRPTEXM.PAK / MODLIST.SPP < prev    next >
Encoding:
Text File  |  1997-05-06  |  2.5 KB  |  114 lines

  1. //--------------------------------------------------------------------------
  2. // Object Scripting
  3. // Copyright (c) 1996, 1997 by Borland International, All Rights Reserved
  4. //
  5. // MODLIST.SPP: Module List. Demonstrates how to handle events from
  6. //   other objects to maintain the contents of a list. Implements some
  7. //   of the functionality provided by the Script | Modules dialog.
  8. //--------------------------------------------------------------------------
  9. print typeid(module());
  10.  
  11. //
  12. // IDE imports.
  13. //
  14. import scriptEngine;
  15. import IDE;
  16.  
  17. //
  18. // Unloads this module.
  19. //
  20. UnloadOurself()
  21. {
  22.   scriptEngine.Unload(typeid(module()));
  23. }
  24.  
  25. IDE.StartWaitCursor();
  26.  
  27. declare LoadedModules = scriptEngine.Modules();
  28.  
  29. ModList = new ListWindow(50, 5, 300, 300, "Module List", TRUE, FALSE,
  30.                          LoadedModules);
  31.  
  32. on ModList:>Delete()
  33. {
  34.   declare i = 0;
  35.   declare foundSomething = FALSE;
  36.  
  37.   do {
  38.     declare name = ModList.Data[i++];
  39.  
  40.     declare String fName(name);
  41.     fName = fName.Lower();
  42.     if (fName.Index("modlist.sp")) {  // Check for .spx or .spp.
  43.       UnloadOurself();
  44.       break;
  45.     }
  46.  
  47.     declare String tmp(name);
  48.     foundSomething = tmp.Length;
  49.  
  50.     if (foundSomething) {
  51.       if (!scriptEngine.Unload(name)) {
  52.         IDE.Message("The unload failed!", INFORMATION);
  53.         print "scriptEngine.Unload failed.";
  54.       }
  55.     }
  56.   } while (foundSomething);
  57. }
  58.  
  59. on ModList:>Insert()
  60. {
  61.   declare name = IDE.FileDialog();
  62.   if (name != "") {
  63.     scriptEngine.Load(name);
  64.   }
  65. }
  66.  
  67. //
  68. // Hook the Accept event in order to do nothing. The default behavior
  69. // puts the list away.
  70. //
  71. on ModList:>Accept()
  72. {
  73.   declare name = ModList.Data[.CurrentIndex];
  74.   .Delete();
  75.   scriptEngine.Load(name);
  76. }
  77.  
  78. declare isInitialized = 0;
  79. on scriptEngine:>Loaded(arg)
  80. {
  81.   //
  82.   // The first time this entry is called is when it is being notified
  83.   // of its own load. Since it is already in the module list, don't
  84.   // add it again.
  85.   //
  86.   if (!isInitialized) {
  87.     isInitialized += 1;
  88.     return;
  89.   }
  90.  
  91.   //
  92.   // The first two modules in the chain are always Console Variables
  93.   // followed by the CLIENT object.  New modules are added after them
  94.   // so we'll always insert at position 2.
  95.   //
  96.   ModList.Add(arg, 2);
  97. }
  98.  
  99. on scriptEngine:>Unloaded(arg)
  100. {
  101.   declare idx = ModList.FindString(arg);
  102.   ModList.Remove(idx);
  103. }
  104.  
  105. on ModList:>Closed()
  106. {
  107.   UnloadOurself();
  108. }
  109.  
  110. IDE.EndWaitCursor();
  111.  
  112. ModList.Execute();
  113.  
  114.