Пример #1
0
  private void addMarker(Marker m, ChatLine chatLine) {
    String markerId = editor.newItemId();
    Doc v = cdoc.getShared().getValue();
    // Adding the marker to the selection marker position, a bit of a hack.
    Marker sema = v.getMarkers().get(user.getSelectionMarkerId());
    if (sema == null) {
      getWindow().showNotification("Something went wrong marker-wise :( Please try again.");
      return;
    }
    String text = v.getText();
    int start = sema.getStart();
    int end = sema.getEnd();
    m = m.withNewPos(start, end);

    DocDiff d = DocDiff.addMarker(markerId, m, text);
    cdoc.getShared().applyDiff(d, editor.getCollaboratorId());

    if (chatLine != null) {
      List<ChatLine> lines = Collections.singletonList(chatLine);
      project.getDoc(file).getMarkerChatCreateIfNotExist(markerId, lines);
    }

    latestMarkers.put(markerId, m);
    activeMarker = markerId;

    updateMarkers(latestMarkers);
    showMarkerPopup();
    editor.requestRepaint();
  }
Пример #2
0
  private void checkMarkers() {

    int touchesLocks = 0;
    int touchesNotes = 0;
    LinkedList<String> touchingMarkers = new LinkedList<String>();
    Map<String, Marker> markers = editor.getShared().getValue().getMarkers();
    boolean redraw = false;
    for (Entry<String, Marker> e : markers.entrySet()) {
      final Marker m = e.getValue();
      if (!isTabWorthyMarker(m)) {
        continue;
      }
      if (!latestMarkers.containsKey(e.getKey())) {
        redraw = true;
      }
      if (m.touches(selMin, selMax)) {
        touchingMarkers.add(e.getKey());
        if (m.getType() == Marker.Type.LOCK) touchesLocks++;
        if (m.getType() == Marker.Type.COMMENT) touchesNotes++;
      }
    }

    if (!redraw) {
      for (String mid : latestMarkers.keySet()) {
        if (!markers.containsKey(mid)) {
          redraw = true;
          break;
        }
      }
    }

    if (redraw) {
      updateMarkers(markers);
    }

    boolean selected = (selMin != selMax);
    boolean notingEnabled = selected && touchesNotes == 0;
    boolean lockingEnabled = selected && touchesLocks == 0;

    if (touchingMarkers.size() > 0) {
      if (!touchingMarkers.contains(activeMarker)) {
        activeMarker = touchingMarkers.getFirst();
        showMarkerPopup();
      }
    } else if (notingEnabled || lockingEnabled) {
      showAddMarkerPopup(notingEnabled, lockingEnabled);
    } else {
      if (popup != null) {
        popup.setVisible(false);
      }
      activeMarker = null;
    }
  }
Пример #3
0
 public void addNote(String note) {
   ChatLine line = new ChatLine(note, user.getUserId(), user.getName(), user.getStyle());
   Marker m = Marker.newCommentMarker(0, 0, note);
   addMarker(m, line);
 }
Пример #4
0
 public void addLock() {
   Marker m =
       Marker.newLockMarker(selMin, selMax, user.getUserId(), "Locked for " + user.getName());
   ChatLine line = new ChatLine(user.getName() + " locked this part.");
   addMarker(m, line);
 }
Пример #5
0
 private boolean isTabWorthyMarker(Marker m) {
   return m.getType() == Marker.Type.COMMENT
       || (m.getType() == Marker.Type.LOCK && (m.getData() != null));
 }