Search in sources :

Example 1 with BlameInfo

use of com.google.gerrit.client.blame.BlameInfo in project gerrit by GerritCodeReview.

the class PatchSetSelectBox method setUpBlame.

void setUpBlame(final CodeMirror cm, final boolean isBase, final PatchSet.Id rev, final String path) {
    if (!Patch.isMagic(path) && Gerrit.isSignedIn() && Gerrit.info().change().allowBlame()) {
        Anchor blameIcon = createBlameIcon();
        blameIcon.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent clickEvent) {
                if (cm.extras().getBlameInfo() != null) {
                    cm.extras().toggleAnnotation();
                } else {
                    ChangeApi.blame(rev, path, isBase).get(new GerritCallback<JsArray<BlameInfo>>() {

                        @Override
                        public void onSuccess(JsArray<BlameInfo> lines) {
                            cm.extras().toggleAnnotation(lines);
                        }
                    });
                }
            }
        });
        linkPanel.add(blameIcon);
    }
}
Also used : GerritCallback(com.google.gerrit.client.rpc.GerritCallback) Anchor(com.google.gwt.user.client.ui.Anchor) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JsArray(com.google.gwt.core.client.JsArray) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) BlameInfo(com.google.gerrit.client.blame.BlameInfo)

Example 2 with BlameInfo

use of com.google.gerrit.client.blame.BlameInfo in project gerrit by GerritCodeReview.

the class Extras method setAnnotations.

public final void setAnnotations(JsArray<BlameInfo> blameInfos) {
    if (blameInfos.length() > 0) {
        setBlameInfo(blameInfos);
        JsArrayString gutters = ((JsArrayString) JsArrayString.createArray());
        gutters.push(ANNOTATION_GUTTER_ID);
        cm.setOption("gutters", gutters);
        annotated = true;
        DateTimeFormat format = DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.DATE_SHORT);
        JsArray<LintLine> annotations = JsArray.createArray().cast();
        for (BlameInfo blameInfo : Natives.asList(blameInfos)) {
            for (RangeInfo range : Natives.asList(blameInfo.ranges())) {
                Date commitTime = new Date(blameInfo.time() * 1000L);
                String shortId = blameInfo.id().substring(0, 8);
                String shortBlame = C.shortBlameMsg(shortId, format.format(commitTime), blameInfo.author());
                String detailedBlame = C.detailedBlameMsg(blameInfo.id(), blameInfo.author(), FormatUtil.mediumFormat(commitTime), blameInfo.commitMsg());
                annotations.push(LintLine.create(shortBlame, detailedBlame, shortId, Pos.create(range.start() - 1)));
            }
        }
        cm.setOption("lint", getAnnotation(annotations));
    }
}
Also used : JsArrayString(com.google.gwt.core.client.JsArrayString) RangeInfo(com.google.gerrit.client.RangeInfo) JsArrayString(com.google.gwt.core.client.JsArrayString) Date(java.util.Date) DateTimeFormat(com.google.gwt.i18n.client.DateTimeFormat) BlameInfo(com.google.gerrit.client.blame.BlameInfo)

Aggregations

BlameInfo (com.google.gerrit.client.blame.BlameInfo)2 RangeInfo (com.google.gerrit.client.RangeInfo)1 GerritCallback (com.google.gerrit.client.rpc.GerritCallback)1 JsArray (com.google.gwt.core.client.JsArray)1 JsArrayString (com.google.gwt.core.client.JsArrayString)1 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)1 DateTimeFormat (com.google.gwt.i18n.client.DateTimeFormat)1 Anchor (com.google.gwt.user.client.ui.Anchor)1 Date (java.util.Date)1