home *** CD-ROM | disk | FTP | other *** search
- !!Script
- // Copyright ⌐ 1997-1998 - Modelworks Software
-
- //
- // Smartkey script to complete a if-else
- //
- /**
- @Tool: completeIfElse~completes an if-else statement and places
- the caret between the opening and closing parenthesis of the if statement.
- Defined for all file types.
- Typing <code>ife<tab></code> results in:
- <pre>
- if (<caret>)
- {
- }
- else
- {
- }
- </pre>
- @EndTool:
- @Summary: completeIfElse~complets an if-else statement
- */
-
- function DoCommand()
- {
- var path = File.getToolsPath() + "\\Smartkeys\\completeIfElse.script";
- Application.registerSmartKeyHandler("*", "ife\t", path,
- "Complete: ife<tab> with if(){}else{}");
- }
-
- function OnEvent(editor,lineBuffer)
- {
- var selection = editor.getSelection();
- selection.startCharIndex -= 3;
- editor.replace("if()", selection);
-
- var indentLevel = editor.getIndentLevel(selection.startLineIndex);
- var lineIndex = selection.startLineIndex;
-
- editor.insert(++lineIndex, 0, "{\n");
- editor.setIndentLevel(lineIndex, indentLevel);
-
- editor.insert(++lineIndex, 0, "}\n");
- editor.setIndentLevel(lineIndex, indentLevel);
-
- editor.insert(++lineIndex, 0, "else\n");
- editor.setIndentLevel(lineIndex, indentLevel);
-
- editor.insert(++lineIndex, 0, "{\n");
- editor.setIndentLevel(lineIndex, indentLevel);
-
- editor.insert(++lineIndex, 0, "}\n");
- editor.setIndentLevel(lineIndex, indentLevel);
-
- editor.select(selection.startLineIndex, selection.endCharIndex,
- selection.startLineIndex, selection.endCharIndex);
-
- editor.setActive("Complete if-else");
- return true;
- }
-
- !!/Script
-
-
-