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

  1. !!Script 
  2. // Copyright ⌐ 2001 - Miguel Angel Rojas G.
  3. // @Modified build 497 cm20010225
  4.  
  5. /**
  6. @Tool: deleteCurrentBookmark~removes current bookmarks.
  7. */
  8.  
  9. var gOutput = getOutput();
  10.  
  11. function DoCommand()
  12.     var bookmarkMap = getMapFile( "Bookmarks" );
  13.     
  14.     if ( bookmarkMap.count == 0 )
  15.     {
  16.         return;
  17.     }
  18.     
  19.     // See if there is a bookmark on the current line and if so delete it
  20.     var found = false;
  21.     var editor = getActiveEditor();
  22.     if (editor)
  23.     {
  24.         var position = bookmarkMap.getHeadPosition();
  25.         var editorpath = editor.path;
  26.         var currentLineIndex = editor.getSelection().startLineIndex;
  27.         
  28.         while ( position && position.valid )
  29.         {
  30.             var next = bookmarkMap.getNext( position );
  31.             if (next.value.valid())
  32.             {
  33.                 var bookmark = next.value;
  34.                 if (bookmark.path == editorpath &&
  35.                     bookmark.startLineIndex == currentLineIndex)
  36.                 {
  37.                     bookmarkMap.remove(bookmark.hashKey);
  38.                     bookmark.remove();
  39.                     found = true;
  40.                 }
  41.             }
  42.             else
  43.             {
  44.                 bookmarkMap.remove(next.value.hashKey);
  45.             }
  46.         }
  47.         
  48.         if (found)
  49.         {
  50.             return;
  51.         }
  52.     }
  53.  
  54.     /*
  55.     var currentBookmark = getGlobal( "currentBookmark", -1);
  56.     if (currentBookmark != -1)
  57.     {
  58.         var list = getBookmarksAsList( bookmarkMap );
  59.         
  60.         var position = list.getPosition( currentBookmark );
  61.         
  62.         if ( position && position.valid )
  63.         {
  64.             var current = currentBookmark;
  65.             
  66.             if ( list.count == 1 ) 
  67.             {
  68.                 setGlobal( "currentBookmark", 0 );
  69.             }
  70.             else
  71.             {
  72.                 if ( current != 0 )
  73.                 {
  74.                     current = current-1;
  75.                 }
  76.                 setGlobal( "currentBookmark", current );
  77.             }
  78.             
  79.             var item = list.getAt( position );
  80.             bookmarkMap.remove( item.value.hashKey );
  81.             item.value.remove();
  82.         }
  83.     }
  84.     */
  85. }
  86.  
  87. function getBookmarksAsList( bookmarkMap )
  88.     var list = newList();
  89.     var position = bookmarkMap.getHeadPosition();
  90.     
  91.     while ( position && position.valid )
  92.     {
  93.         var next = bookmarkMap.getNext( position );
  94.         if (next.value.valid())
  95.         {
  96.             list.addTail(next);
  97.         }
  98.         else
  99.         {
  100.             bookmarkMap.remove(next.value.hashKey);
  101.         }
  102.     }
  103.     
  104.     list.sort(); // sort in order of creation
  105.     
  106.     return list;
  107. }
  108.  
  109. !!/Script
  110.