home *** CD-ROM | disk | FTP | other *** search
- !!Script
- // Copyright ⌐ 1997-1998 - Modelworks Software
- // @Modified build 497 cm20010225
- // @Modified build 507 cm20010403
-
- /**
- @Tool: addBookmark~displays a dialog to let you add a bookmark for the line containing the
- current selection in the active editor. The default name of the bookmark is copied from
- the current selection.
- @Image: Add Bookmark Dialog@addBookmark_Dialog.gif
- @EndTool:
- @Summary: addBookmark~adds a bookmark for the current selection
- */
-
- function DoCommand()
- {
- var bookmarkMap = getMapFile("Bookmarks");
-
- var editor = getActiveEditor();
- if (editor && editor.path.length == 0)
- {
- editor.save(); // Cannot set a bookmark in an unsaved file
- }
-
- if (editor && editor.path.length > 0)
- {
- var selection = editor.getSelection();
-
- var initialValue = editor.copy(selection);
- var result = prompt("Enter a name for this bookmark", initialValue);
-
- if (result && result.length > 0)
- {
- var bookmark = GetBookmark(result, bookmarkMap);
-
- if (bookmark)
- {
- bookmarkMap.remove(bookmark.hashKey);
- bookmark.remove()
- }
-
- bookmark = editor.newBookmark(selection.startLineIndex);
- bookmark.description = result;
- bookmarkMap.add(bookmark.hashKey, bookmark);
- }
- }
- }
-
- function GetBookmark(result, bookmarkMap)
- {
- var position = bookmarkMap.getHeadPosition();
- while (position && position.valid)
- {
- var bookmark = bookmarkMap.getNext(position).value;
- if (bookmark && bookmark.description == result)
- {
- return bookmark;
- }
- }
- return null;
-
- }
-
- !!/Script
-