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

  1. //--------------------------------------------------------------------------
  2. // Object Scripting
  3. // Copyright (c) 1996, 1997 by Borland International, All Rights Reserved
  4. //
  5. // AUTOSAVE.SPP: Autosave. Saves files, environment, desktop, project,
  6. //   and/or messages at the specified interval.
  7. //
  8. // USE: Set values in autosave.cfg and run script.
  9. //
  10. // FILES: AUTOSAVE.CFG, MSG.SPP, FILE.SPP, MISC.SPP   
  11. //
  12. // NOTES: All autosave.* files must reside in the same directory. 
  13. //--------------------------------------------------------------------------
  14. print typeid(module());
  15.  
  16. //
  17. // IDE imports.
  18. //
  19. import IDE;
  20. import scriptEngine;
  21.  
  22. //
  23. // Load support module(s).
  24. //
  25. if (!scriptEngine.IsLoaded("msg")) scriptEngine.Load("msg");
  26. if (!scriptEngine.IsLoaded("file")) scriptEngine.Load("file");
  27. if (!scriptEngine.IsLoaded("misc")) scriptEngine.Load("misc");
  28.  
  29. //
  30. // Configuration values.
  31. //
  32. SaveIntervalSec;
  33. bSaveFiles;
  34. bSaveEnvironment;
  35. bSaveDesktop;
  36. bSaveProject;
  37. bSaveMessages;
  38.  
  39. Msg = new TMsg();          // Message object.
  40. Seconds = 0;               // Seconds counter.
  41. bAutosaveComplete = TRUE;  // Reentry flag.
  42.  
  43. //
  44. // Fully-qualified configuration file.
  45. //
  46. CFGFile = GetModuleDir(typeid(module())) + "\\autosave.cfg";
  47.  
  48. autosave()
  49. {
  50.   //
  51.   // Load configuration values.
  52.   //
  53.   declare file = new TConfigFile(CFGFile);
  54.  
  55.   SaveIntervalSec  = file.GetValue("SaveIntervalSec", "600");
  56.   bSaveFiles       = file.GetValue("SaveFiles", "1");
  57.   bSaveEnvironment = file.GetValue("SaveEnvironment", "0");
  58.   bSaveDesktop     = file.GetValue("SaveDesktop", "0");
  59.   bSaveProject     = file.GetValue("SaveProject", "0");
  60.   bSaveMessages    = file.GetValue("SaveMessages", "0");
  61.  
  62.   file.Close();
  63. }
  64.  
  65. //
  66. // Saves the specified items.
  67. //
  68. SaveItems()
  69. {
  70.   bAutosaveComplete = FALSE;  // Set flag to prevent reentry.
  71.  
  72.   //
  73.   // If any of the items saved through the Save Options dialog are to be
  74.   // saved, raise a confirmation dialog first. This is necessary since that
  75.   // dialog is controlled with the use of SendKeys(), and the keys can go to
  76.   // another task if BCW is not active.
  77.   //
  78.   if (bSaveEnvironment || bSaveDesktop || bSaveProject || bSaveMessages) {
  79.     declare choice = IDE.YesNoDialog("Autosave?");
  80.     if (choice == "No" || choice == "") {
  81.       bAutosaveComplete = TRUE;
  82.       return;
  83.     }
  84.   }
  85.  
  86.   // Save open buffers.
  87.   //
  88.   if (bSaveFiles) {
  89.     if (!IDE.FileSaveAll()) Msg.Error("Save All failed.");
  90.   }
  91.  
  92.   //  
  93.   // Save the items available via the Options Save dialog. This must be done
  94.   // with keystrokes, so we tell the IDE Application object to raise events
  95.   // when dialogs are created and we later trap those events.
  96.   //
  97.   if (bSaveEnvironment || bSaveDesktop || bSaveProject || bSaveMessages) {
  98.     IDE.RaiseDialogCreatedEvent = TRUE;
  99.     if (!IDE.OptionsSave()) Msg.Error("Could not open Save Options dialog.");
  100.     IDE.RaiseDialogCreatedEvent = FALSE;
  101.   }
  102.  
  103.   bAutosaveComplete = TRUE;
  104. }
  105.  
  106. //
  107. // Handle the second timer events, and save if we hit the save interval.
  108. //
  109. on IDE:>SecondElapsed()
  110. {
  111.   pass();
  112.  
  113.   Seconds++;
  114.   if (Seconds == SaveIntervalSec) {
  115.     Seconds = 0;
  116.     if (bAutosaveComplete) SaveItems();  // Save if not still saving.
  117.   }
  118. }
  119.  
  120. //
  121. // Handle the dialog created events, and throw keys if it's the Save Options
  122. // dialog.
  123. //
  124. on IDE:>DialogCreated(dlgName, hDlg)
  125. {
  126.   if (dlgName == "Save Options") {
  127.      declare keys = "e" + (bSaveEnvironment ? "{VK_ADD}" : "-") +
  128.                     "d" + (bSaveDesktop ? "{VK_ADD}" : "-") +
  129.                     "p" + (bSaveProject ? "{VK_ADD}" : "-") +
  130.                     "m" + (bSaveMessages ? "{VK_ADD}" : "-") +
  131.                     "{VK_RETURN}";
  132.      .KeyboardManager.SendKeys(keys, TRUE);
  133.   }
  134.  
  135.   pass(dlgName, hDlg);
  136. }
  137.