Пример #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
 public void selectionChanged(int start, int end) {
   selMin = Math.min(start, end);
   selMax = Math.max(start, end);
   DocDiff diff = user.cursorDiff(selMin, selMax, editor.getShadow().getText());
   cdoc.getShared().applyDiff(diff, editor.getCollaboratorId());
   checkMarkers();
 }
Пример #3
0
 @Override
 public void attach() {
   super.attach();
   project.getTeam().setUserFileOpen(file, user, editor.getCollaboratorId());
   getWindow().addListener(this);
   showUsers();
   editor.addListener(this);
   project.addListenerWeakRef(this);
   project.getTeam().addListener(this);
 }
Пример #4
0
 @Override
 public void detach() {
   super.detach();
   editor.removeListener(this);
   project.removeListenerWeakRef(this);
   project.getTeam().removeListener(this);
   project.getTeam().setUserFileClosed(file, user, editor.getCollaboratorId());
   if (popup != null) {
     getWindow().removeWindow(popup);
   }
 }
Пример #5
0
 private SuggestibleCollabAceEditor createEditor(ProjectFile file, Project project) {
   SuggestibleCollabAceEditor ed = EditorUtil.createEditorFor(cdoc.getShared(), file);
   if (file.getName().endsWith(".java") && project instanceof VaadinProject) {
     InMemoryCompiler compiler = ((VaadinProject) project).getCompiler();
     String className =
         ((VaadinProject) project).getPackageName()
             + "."
             + file.getName().substring(0, file.getName().length() - 5);
     ed.setSuggester(new VaadinSuggester(compiler, className), VaadinSuggester.DEFAULT_SHORTCUT);
   }
   return ed;
 }
Пример #6
0
  public EditorView(ProjectFile file, Project project, User user, boolean inIde, int line) {
    super();
    this.file = file;
    this.project = project;
    this.user = user;
    layout.setSizeFull();

    HorizontalLayout ho = new HorizontalLayout();
    if (!inIde) {
      String url = "#" + project.getName() + "/" + file.getName() + "!";
      Link link = new Link("<<< " + file.getName(), new ExternalResource(url));
      link.setDescription("View project");
      layout.addComponent(link);
    }
    if (inIde) {
      String url = "#" + project.getName() + "/" + file.getName();
      Link link = new Link(file.getName() + " >>>", new ExternalResource(url));
      link.setDescription("View in standalone window");
      layout.addComponent(link);
    }

    layout.addComponent(ho);

    layout.setExpandRatio(ho, 1);
    ho.setSizeFull();

    cdoc = project.getDoc(file);

    editor = createEditor(file, project);
    editor.setSizeFull();
    editor.setEnabled(user != null);
    editor.setUser(user.getUserId(), user.getStyle());

    final int pos =
        org.vaadin.aceeditor.gwt.shared.Util.cursorPosFromLineCol(
            cdoc.getShared().getValue().getText(), line, 0, 1);
    editor.scrollToPosition(pos);
    ho.addComponent(editor);
    ho.setExpandRatio(editor, 1);

    VerticalLayout rightBar = new VerticalLayout();
    rightBar.setWidth("64px");
    rightBar.addComponent(userLayout);
    rightBar.addComponent(markerLayout);

    ho.addComponent(rightBar);

    setSizeFull();
    setCompositionRoot(layout);
  }
Пример #7
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;
    }
  }
Пример #8
0
 private void showAddMarkerPopup(boolean notingEnabled, boolean lockingEnabled) {
   AddMarkerComponent am = new AddMarkerComponent(this, notingEnabled, lockingEnabled);
   String title = editor.getShadow().getText().substring(selMin, selMax);
   showPopup(title, am, editor.getCursorCoords()[1]);
 }
Пример #9
0
 private void removeMarkerById(String markerId) {
   cdoc.getShared().applyDiff(DocDiff.removeMarker(markerId), editor.getCollaboratorId());
 }
Пример #10
0
 private void showMarkerPopup() {
   int[] coords = editor.getCursorCoords();
   showMarkerPopup(coords[1]);
 }
Пример #11
0
 public void windowClose(CloseEvent e) {
   project.getTeam().setUserFileClosed(file, user, editor.getCollaboratorId());
 }