/** * Corrects the {@link IMarker#CHAR_START} and {@link IMarker#CHAR_END} values as needed * * @param document * @param marker * @param line * @throws BadLocationException */ void ensureRanges(IDocument document, IMarker marker, int line) throws BadLocationException { if (line < 0 || line > document.getNumberOfLines()) { return; } IRegion region = document.getLineInformation(line - 1); int charstart = region.getOffset(); int charend = charstart + region.getLength(); MarkerUtilities.setCharStart(marker, charstart); MarkerUtilities.setCharEnd(marker, charend); }
/** * Adds a new quickmark in the active editor. If the same quickmark number already exists (in the * workspace), the existing quickmark is replaced with the new (i.e. the quickmark is moved). If * the same quickmark already exists in the same location, the quickmark is removed. * * @param quickmarkNumber */ private void addBookmark(int quickmarkNumber) { ITextEditor editor = getActiveEditor(); if (editor != null) { Integer key = new Integer(quickmarkNumber); Map attributes = new HashMap(); ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection(); int charStart = selection.getOffset(); int charEnd = charStart; MarkerUtilities.setCharStart(attributes, charStart); MarkerUtilities.setCharEnd(attributes, charEnd); IFile file = getActiveFile(); String message = MessageFormat.format( Messages.getString("SetQuickmarkAction.quickmarkMessage"), new Object[] {key}); // $NON-NLS-1$ MarkerUtilities.setMessage(attributes, message); attributes.put(QuickmarksPlugin.NUMBER, key); attributes.put(QuickmarksPlugin.FILE, file); boolean OK = true; Map markers = getMarkers(); if (markers.containsKey(key)) { IMarker marker = (IMarker) markers.get(key); try { Integer markerCharStart = (Integer) marker.getAttribute(IMarker.CHAR_START); Integer markerCharEnd = (Integer) marker.getAttribute(IMarker.CHAR_END); if (markerCharStart != null && markerCharStart.intValue() == charStart && markerCharEnd != null && markerCharEnd.intValue() == charEnd) { OK = false; } marker.delete(); } catch (CoreException e) { QuickmarksPlugin.debug(e); } } if (OK) { try { MarkerUtilities.createMarker(file, attributes, getMarkerType()); } catch (Exception e) { QuickmarksPlugin.log(e); } } } }