home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 67 / IOPROG_67A.ISO / soft / Tools / mwsppv4.exe / COMPLETEFOR.SCRIPT < prev    next >
Encoding:
Text File  |  2001-06-26  |  1.2 KB  |  49 lines

  1. !!Script
  2. // Copyright ⌐ 1997-1998 - Modelworks Software
  3.  
  4. /**
  5. @Tool: completeFor~completes a for structure and places 
  6. the caret between the opening and closing parenthesis of the for statement. 
  7. Defined for all file types. 
  8. Typing <code>for<tab></code> results in:
  9. <pre> 
  10. for(<caret>;;)
  11. {
  12. }
  13. </pre>
  14. @EndTool: 
  15. @Summary: completeFor~complets a for statement 
  16. */
  17.  
  18. function DoCommand()
  19. {
  20.   var path = File.getToolsPath() + "\\Smartkeys\\completeFor.script";
  21.   Application.registerSmartKeyHandler(".*", "for\t", path, 
  22.     "Complete: for<tab> with for(;;){}");
  23. }
  24.  
  25. function OnEvent(editor,lineBuffer)
  26. {
  27.   var selection = editor.getSelection();
  28.   editor.replace("(;;)", selection); 
  29.  
  30.   var indentLevel = editor.getIndentLevel(selection.startLineIndex);
  31.   var lineIndex = selection.startLineIndex;
  32.   
  33.   editor.insert(++lineIndex, 0, "{\n");
  34.   editor.setIndentLevel(lineIndex, indentLevel);
  35.   
  36.   editor.insert(++lineIndex, 0, "}\n");
  37.   editor.setIndentLevel(lineIndex, indentLevel);
  38.  
  39.   editor.select(selection.startLineIndex, selection.endCharIndex + 1, 
  40.     selection.startLineIndex, selection.endCharIndex + 1);
  41.  
  42.   editor.setActive("Complete for");
  43.   return true;
  44. }
  45.  
  46. !!/Script
  47.  
  48.  
  49.