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

  1. !!Script 
  2. // Copyright ⌐ 1997-1998 - Modelworks Software
  3. // @Modified build 497 cm20010225
  4. // @Modified build 507 cm20010403
  5.  
  6. /**
  7. @Tool: addBookmark~displays a dialog to let you add a bookmark for the line containing the 
  8. current selection in the active editor. The default name of the bookmark is copied from 
  9. the current selection. 
  10. @Image: Add Bookmark Dialog@addBookmark_Dialog.gif
  11. @EndTool: 
  12. @Summary: addBookmark~adds a bookmark for the current selection
  13. */
  14.  
  15. function DoCommand()
  16.     var bookmarkMap = getMapFile("Bookmarks");
  17.     
  18.     var editor = getActiveEditor();
  19.     if (editor && editor.path.length == 0)
  20.     {
  21.         editor.save(); // Cannot set a bookmark in an unsaved file
  22.     }
  23.     
  24.     if (editor && editor.path.length > 0)
  25.     {
  26.         var selection = editor.getSelection();
  27.         
  28.         var initialValue = editor.copy(selection);
  29.         var result = prompt("Enter a name for this bookmark", initialValue);
  30.         
  31.         if (result && result.length > 0)
  32.         {
  33.             var bookmark = GetBookmark(result, bookmarkMap);
  34.             
  35.             if (bookmark)
  36.             {
  37.                 bookmarkMap.remove(bookmark.hashKey);
  38.                 bookmark.remove()
  39.             }
  40.             
  41.             bookmark = editor.newBookmark(selection.startLineIndex);
  42.             bookmark.description = result;
  43.             bookmarkMap.add(bookmark.hashKey, bookmark);
  44.         }
  45.     }
  46. }
  47.  
  48. function GetBookmark(result, bookmarkMap)
  49. {
  50.     var position = bookmarkMap.getHeadPosition();
  51.     while (position && position.valid)
  52.     {
  53.         var bookmark = bookmarkMap.getNext(position).value;
  54.         if (bookmark && bookmark.description == result)
  55.         {
  56.             return bookmark;
  57.         }
  58.     }
  59.     return null;
  60.     
  61. }
  62.  
  63. !!/Script
  64.