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

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