home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 67 / IOPROG_67A.ISO / soft / Tools / mwsppv4.exe / FILECOMMANDS.JS < prev    next >
Encoding:
JavaScript  |  2000-07-26  |  3.2 KB  |  132 lines

  1. // Called by the IDE to initialize this editor
  2. function File_Reload(path) 
  3. {
  4.     gOutput.writeLine("Do_InsertObject(" + path + ") called");
  5.     
  6.     // Load your document
  7.     ReadData(path);
  8. }    
  9.  
  10. function Event_OnReadOnlyChange(readOnly) 
  11. {
  12.     gOutput.writeLine("Event_OnReadOnlyChange(" + readOnly + ") called");
  13. }
  14.  
  15. // Called by the IDE to setup the context menu
  16. function Application_SetupContextMenu(menu) 
  17. {
  18.     menu.appendSeparator();
  19.     menu.appendItem("Open As XML", gWebEdit.editorPath,
  20.         "Open this document with the XML editor", 
  21.         false, "OpenAsText");
  22. }    
  23.  
  24. // Called to update the state of the dynamic commands (menu, button)
  25. function DoUpdate(cmdUI) 
  26. {
  27.     gOutput.writeLine("DoUpdate(" + cmdUI.cookie + ") called");
  28.     if (cmdUI.cookie == "InsertObject") // Defined in onLoadMenu
  29.     {
  30.         cmdUI.enable(true);
  31.         return true;
  32.     }
  33.     
  34.     else if (cmdUI.cookie == "OpenAsText") // Defined in SetupContextMenu above
  35.     {
  36.         cmdUI.enable(gWebEdit.destinationPath.length > 0);
  37.         return true;
  38.     }
  39.     return false;
  40. }
  41.  
  42. function Do_InsertObject(data)
  43. {
  44.     gOutput.writeLine("Do_InsertObject(data) called");
  45.     DumpArrayParameter(data);
  46. }
  47.  
  48. function Undo_InsertObject(data) 
  49. {
  50.     gOutput.writeLine("Undo_InsertObject(data) called");
  51.     DumpArrayParameter(data);
  52. }
  53.  
  54. function DoCommand(id, cookie)
  55. {
  56.     gOutput.writeLine("DoCommand(" + id + "," + cookie + ") called");
  57.     if (cookie == "InsertObject") // Defined in onLoadMenu.script
  58.     {
  59.         // For all commands that modify the document use the following paradigm
  60.         // so that undo, redo, and repeat will automatically be supported
  61.         
  62.         // First create the data parameter for the command - it can be any JavaScript variable
  63.         // Here we use an Array object
  64.         var data = new Array("name", 1, 2, 3);
  65.         
  66.         // Second call pushUndoCommand
  67.         gWebEdit.pushUndoCommand("Insert Object", data, Do_InsertObject, Undo_InsertObject);
  68.         
  69.         // Third do the command
  70.         Do_InsertObject(data);
  71.     }
  72.     
  73.     else if (cookie == "OpenAsText") // Defined in SetupContextMenu above
  74.     {
  75.         File.openAs(gWebEdit.destinationPath, ".xml", true); 
  76.     }
  77. }
  78.  
  79. function ReadData(path)
  80. {
  81.     if (File.exists(path))
  82.     {
  83.         var file = gFileSystem.OpenTextFile(path, 1);
  84.         if (file)
  85.         {
  86.             gOutput.writeLine("Reading from " + path);
  87.             var s = file.ReadLine();
  88.             file.Close();
  89.         }
  90.     }
  91. }
  92.  
  93. function WriteData(path)
  94. {
  95.     if (File.exists(path))
  96.     {
  97.         gOutput.writeLine("File System Object created");
  98.         var file = gFileSystem.CreateTextFile(path, true);
  99.         if (file)
  100.         {
  101.             gOutput.writeLine("Writing to " + path);
  102.             file.WriteLine("<person>");
  103.             file.WriteLine("\t<name>");
  104.             file.WriteLine("\t</name>");
  105.             file.WriteLine("</person>");
  106.             file.Close();
  107.         }
  108.     }
  109.     return true;
  110. }
  111.  
  112. function File_Save(path, autoSave)
  113. {
  114.     // Do not use gWebEdit.destinationPath since File_Save(path)
  115.     // Can be called to do a SaveAs or SaveCopyAs
  116.     gOutput.writeLine("File_Save: " + path + " called");
  117.     return WriteData(path);
  118. }
  119.  
  120. function File_Close()   
  121. {
  122.     gOutput.writeLine("File_Close called");
  123.     // This is just a notification call telling you 
  124.     // that this editor is going away. The contents have
  125.     // already been saved so there is nothing to do unless
  126.     // you need to save configuration data. Even that
  127.     // is not necessary if you a MapFile to store configuration
  128.     // data.
  129. }
  130.  
  131.  
  132.