Search in sources :

Example 1 with LocalComments

use of com.google.gerrit.client.change.LocalComments in project gerrit by GerritCodeReview.

the class DraftBox method save.

void save(CallbackGroup group) {
    if (pendingGroup != null) {
        pendingGroup.addListener(group);
        return;
    }
    String message = editArea.getValue().trim();
    if (message.length() == 0) {
        return;
    }
    CommentInfo input = CommentInfo.copy(comment);
    input.message(message);
    enableEdit(false);
    pendingGroup = group;
    final LocalComments lc = new LocalComments(psId);
    GerritCallback<CommentInfo> cb = new GerritCallback<CommentInfo>() {

        @Override
        public void onSuccess(CommentInfo result) {
            enableEdit(true);
            pendingGroup = null;
            set(result);
            setEdit(false);
            if (autoClosed) {
                setOpen(false);
            }
            getCommentManager().setUnsaved(DraftBox.this, false);
        }

        @Override
        public void onFailure(Throwable e) {
            enableEdit(true);
            pendingGroup = null;
            if (RestApi.isNotSignedIn(e)) {
                CommentInfo saved = CommentInfo.copy(comment);
                saved.message(editArea.getValue().trim());
                lc.setInlineComment(saved);
            }
            super.onFailure(e);
        }
    };
    if (input.id() == null) {
        CommentApi.createDraft(psId, input, group.add(cb));
    } else {
        CommentApi.updateDraft(psId, input.id(), input, group.add(cb));
    }
    CodeMirror cm = getCm();
    cm.vim().handleKey("<Esc>");
    cm.focus();
}
Also used : GerritCallback(com.google.gerrit.client.rpc.GerritCallback) CommentInfo(com.google.gerrit.client.changes.CommentInfo) LocalComments(com.google.gerrit.client.change.LocalComments) CodeMirror(net.codemirror.lib.CodeMirror)

Aggregations

LocalComments (com.google.gerrit.client.change.LocalComments)1 CommentInfo (com.google.gerrit.client.changes.CommentInfo)1 GerritCallback (com.google.gerrit.client.rpc.GerritCallback)1 CodeMirror (net.codemirror.lib.CodeMirror)1