home *** CD-ROM | disk | FTP | other *** search
/ PC User 2001 August / APC_Aug2001_CD2.iso / features / web_dev / files / mwjpp516.exe / %MAINDIR% / Tools / Library / textUtilities.script < prev   
Encoding:
Text File  |  2001-06-19  |  1.5 KB  |  74 lines

  1. !!Script
  2. // Copyright ⌐ 1997-1998 - Modelworks Software
  3.  
  4.  
  5. //
  6. // Text Utilities
  7. // 
  8. //
  9.  
  10.  
  11. function DoCommand()
  12. {
  13.     alert("The textUtilities script only contains funtions\nthat can be used by other scripts");
  14. }
  15.  
  16. // Use this method to insert text that
  17. // needs to be reformatted
  18. function InsertStringAndReformat(editor, string) 
  19. {
  20.     if (editor)
  21.     {
  22.         var selection = editor.getSelection();
  23.         
  24.         var range = editor.insert(selection.endLineIndex, selection.endCharIndex, string);
  25.         for (var i = range.startLineIndex; i <= range.endLineIndex; i++)
  26.         {
  27.             var indent = editor.getSmartIndentLevel(i);
  28.             editor.setIndentLevel(i, indent);
  29.         }
  30.         return selection.endLineIndex;
  31.     }
  32.     return 0;
  33. }
  34.  
  35. // Use this method to insert preformated text that
  36. // only needs to be tabbed to the correct indent level
  37. function InsertString(editor, string) 
  38. {
  39.     if (editor)
  40.     {
  41.         var selection = editor.getSelection();
  42.         
  43.         var indent = editor.getIndentLevel(selection.startLineIndex);
  44.         var range = editor.insert(selection.endLineIndex, selection.endCharIndex, string);
  45.         IndentRange(editor, indent, range);
  46.         return selection.endLineIndex;
  47.     }
  48.     return 0;
  49. }
  50.  
  51. // Indent a range of text by count tabs
  52. function IndentRange(editor, count, range)
  53. {
  54.     if (count < 1)
  55.     {
  56.         return;
  57.     }
  58.     
  59.     var tabs = "";
  60.     for (var j = 1; j <= count; j++)
  61.     {
  62.         tabs += "\t";
  63.     }
  64.     
  65.     for (var i = range.startLineIndex + 1; i <= range.endLineIndex; i++)
  66.     {
  67.         editor.insert(i, 0, tabs);
  68.     }
  69. }
  70.  
  71.  
  72. !!/Script
  73.  
  74.