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

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