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

  1. //--------------------------------------------------------------------------
  2. // Object Scripting
  3. // Copyright (c) 1996, 1997 by Borland International, All Rights Reserved
  4. //
  5. // FILEINSR.SPP: File Insert. Inserts a file into the current buffer.
  6. //
  7. // USE: Run script. The inserted text will replace any current block if the
  8. //   "Overwrite blocks" editor option is set.
  9. //
  10. // FILES: MSG.SPP
  11. //
  12. // NOTE: This functionality is already available under Brief emulation.
  13. //--------------------------------------------------------------------------
  14. print typeid(module());
  15.  
  16. //
  17. // IDE imports.
  18. //
  19. import IDE;
  20. import scriptEngine;
  21. import editor;
  22.  
  23. //
  24. // Load support module(s).
  25. //
  26. if (!scriptEngine.IsLoaded("msg")) scriptEngine.Load("msg");
  27.  
  28. fileinsr()
  29. {
  30.   declare msg = new TMsg();
  31.  
  32.   // Validate current buffer.
  33.   //
  34.   if (!initialized(editor.TopView)) {
  35.     msg.Info("There is no valid current buffer.");
  36.     return;
  37.   }
  38.   declare curView = editor.TopView;
  39.  
  40.   // Get a filename.
  41.   //
  42.   declare fileName = IDE.FileDialog("Enter the file to insert.", NULL);
  43.   if (fileName == "") {
  44.     return;
  45.   }
  46.  
  47.   // Check the file.
  48.   //
  49.   if (!FileExists(fileName)) {
  50.     msg.Error("Can't find file " + fileName);
  51.     return;
  52.   }
  53.  
  54.   // Insert the contents into the current buffer.
  55.   //
  56.   curView.Position.InsertFile(fileName);
  57. }
  58.  
  59.