Class ToggleSelectionBookmarkHandler

java.lang.Object
org.eclipse.core.commands.common.EventManager
org.eclipse.core.commands.AbstractHandler
All Implemented Interfaces:
org.eclipse.core.commands.IHandler, org.eclipse.core.commands.IHandler2

public class ToggleSelectionBookmarkHandler extends AbstractToggleBookmarkHandler
Toggles bookmarks from selection and caret line.
  • If current line (selection end) contains bookmarks then those bookmarks are deleted.
  • Otherwise, a new bookmark is created for the current (selection end) line.
    • If something is selected, then this is used as bookmark content.
    • If nothing is selected, then current line (trimmed content+location) is used for bookmark. Current line is not the caret line but rather is the first line of selection. When nothing is selected then there is still a selection object that points to the caret line in coordinates of the document rather than view that could be folded.
    • If multiple lines are selected, then the first line of the selection is used to determine which bookmarks are to be deleted and what should be the location of the bookmarks. This is a bit different from "jump to bookmark" behaviour in bookmarks view that puts caret to the last line of multiline bookmark. However, standard text editors display bookmark marker on the left rule on the first rather than last line of multiline bookmark.
  • The handler ignores invocations when current view part is not a ITextEditor (and cannot be adapted to it), selection is not a ITextSelection or editor's input is not a IResource (and cannot be adapted to it). This should support EDT's granular editors (like ConfigurationEditor and FormEditor) consisting of multiple tabs some of which are not text editors as well as regular Eclipse text editors.
  • Constructor Details

    • ToggleSelectionBookmarkHandler

      public ToggleSelectionBookmarkHandler()
  • Method Details

    • calculateActiveLine

      protected OptionalInt calculateActiveLine(org.eclipse.ui.texteditor.ITextEditor editor)
      Description copied from class: AbstractToggleBookmarkHandler
      Calculates document line where bookmark us supposed to be added or deleted.
      Specified by:
      calculateActiveLine in class AbstractToggleBookmarkHandler
      Parameters:
      editor - Editor where bookmark is to be added or deleted. Must not be null.
      Returns:
      0-based document line number where bookmarks has to be added or deleted or an empty value if active line cannot be determined. Never null.
    • createBookmark

      protected void createBookmark(org.eclipse.ui.texteditor.ITextEditor editor, org.eclipse.core.resources.IResource resource, int activeLine)
      Description copied from class: AbstractToggleBookmarkHandler
      Creates a bookmark.
      Specified by:
      createBookmark in class AbstractToggleBookmarkHandler
      Parameters:
      editor - Editor where bookmark is to be created. Must not be null.
      resource - Resource that is being edited. Must not be null.
      activeLine - 0-based document line where bookmark is to be created.