home *** CD-ROM | disk | FTP | other *** search
/ PC User 2001 August / APC_Aug2001_CD2.iso / features / web_dev / files / mwjpp516.exe / %MAINDIR% / Tools / Smartkeys / completeIf.script < prev    next >
Encoding:
Text File  |  2001-06-19  |  1.2 KB  |  49 lines

  1. !!Script
  2. // Copyright ⌐ 1997-1998 - Modelworks Software
  3.  
  4. /**
  5. @Tool: completeIf~completes an if statement and places 
  6. the caret between the opening and closing parenthesis of the if statement. 
  7. Defined for all file types. 
  8. Typing <code>if<tab></code> results in:
  9. <pre> 
  10. if (<caret>)
  11. {
  12. }
  13. </pre>
  14. @EndTool: 
  15. @Summary: completeIf~complets an if statement
  16. */
  17.  
  18. function DoCommand()
  19. {
  20.   var path = File.getToolsPath() + "\\Smartkeys\\completeIf.script";
  21.   Application.registerSmartKeyHandler("*", "if\t", path, 
  22.     "Complete: if<tab> with if(){}");
  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 if");
  43.   return true;
  44. }
  45.  
  46. !!/Script
  47.  
  48.  
  49.