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

  1. !!Script 
  2. // Copyright ⌐ 2001 - Modelworks Software
  3.  
  4. /**
  5. @Tool: goDown~displays the bookmark just above the current
  6. line.
  7. @EndTool: 
  8. @Summary: goDown~displays the bookmark just above
  9. */
  10.  
  11. var gOutput = getOutput();
  12.  
  13. function DoCommand()
  14.     var editor = getActiveEditor();
  15.     if (editor)
  16.     {
  17.         var bookmarkList = GetBookmarks(editor);
  18.         if (bookmarkList)
  19.         {
  20.             var lineIndex = editor.getSelection().startLineIndex;
  21.             
  22.             var position = bookmarkList.getHeadPosition();
  23.             while (position && position.valid)
  24.             {
  25.                 var bookmark = bookmarkList.getNext(position);
  26.                 if (bookmark.sortValue > lineIndex)
  27.                 {
  28.                     bookmark.go();
  29.                     return;
  30.                 }
  31.             }
  32.         }
  33.     }
  34. }
  35.  
  36. function GetBookmarks(editor) // Get sorted list of bookmarks in this editor
  37. {
  38.     var path = editor.path;
  39.     var bookmarkMap = getMapFile("Bookmarks");
  40.     var list = newList();
  41.     
  42.     var position = bookmarkMap.getHeadPosition();
  43.     while (position && position.valid)
  44.     {
  45.         var association = bookmarkMap.getNext(position);
  46.         var bookmark = association.value;
  47.         if (bookmark.valid() && bookmark.path == path)
  48.         {
  49.             list.addTail(bookmark);
  50.         }
  51.     }
  52.  
  53.     var position = list.getHeadPosition();
  54.     while (position && position.valid)
  55.     {
  56.         var bookmark = list.getNext(position);
  57.         bookmark.sortValue = bookmark.startLineIndex;
  58.     }
  59.     list.sort(compareItems);
  60.     return list;
  61. }
  62.  
  63. function compareItems(itemA, itemB)
  64. {
  65.     // Assumes itemA and itemB are Bookmarks
  66.     if ( itemA.sortValue < itemB.sortValue) return -1;
  67.     if (itemA.sortValue == itemB.sortValue) return 0;
  68.     
  69.     return 1;
  70. }
  71. !!/Script
  72.