Search in sources :

Example 41 with JsArrayString

use of com.google.gwt.core.client.JsArrayString in project gerrit by GerritCodeReview.

the class SideBySideChunkManager method render.

private void render(Region region, String diffColor) {
    int startA = lineMapper.getLineA();
    int startB = lineMapper.getLineB();
    JsArrayString a = region.a();
    JsArrayString b = region.b();
    int aLen = a != null ? a.length() : 0;
    int bLen = b != null ? b.length() : 0;
    String color = a == null || b == null ? diffColor : SideBySideTable.style.intralineBg();
    colorLines(cmA, color, startA, aLen);
    colorLines(cmB, color, startB, bLen);
    markEdit(cmA, startA, a, region.editA());
    markEdit(cmB, startB, b, region.editB());
    addPadding(cmA, startA + aLen - 1, bLen - aLen);
    addPadding(cmB, startB + bLen - 1, aLen - bLen);
    addGutterTag(region, startA, startB);
    lineMapper.appendReplace(aLen, bLen);
    int endA = lineMapper.getLineA() - 1;
    int endB = lineMapper.getLineB() - 1;
    if (aLen > 0) {
        addDiffChunk(cmB, endA, aLen, bLen > 0);
    }
    if (bLen > 0) {
        addDiffChunk(cmA, endB, bLen, aLen > 0);
    }
}
Also used : JsArrayString(com.google.gwt.core.client.JsArrayString) JsArrayString(com.google.gwt.core.client.JsArrayString)

Example 42 with JsArrayString

use of com.google.gwt.core.client.JsArrayString in project gerrit by GerritCodeReview.

the class DiffTable method set.

void set(DiffPreferences prefs, JsArray<RevisionInfo> list, int parents, DiffInfo info, boolean editExists, boolean current, boolean open, boolean binary) {
    this.changeType = info.changeType();
    patchSetSelectBoxA.setUpPatchSetNav(list, parents, info.metaA(), editExists, current, open, binary);
    patchSetSelectBoxB.setUpPatchSetNav(list, parents, info.metaB(), editExists, current, open, binary);
    JsArrayString hdr = info.diffHeader();
    if (hdr != null) {
        StringBuilder b = new StringBuilder();
        for (int i = 1; i < hdr.length(); i++) {
            String s = hdr.get(i);
            if (!info.binary() && (s.startsWith("diff --git ") || s.startsWith("index ") || s.startsWith("+++ ") || s.startsWith("--- "))) {
                continue;
            }
            b.append(s).append('\n');
        }
        String hdrTxt = b.toString().trim();
        header = !hdrTxt.isEmpty();
        diffHeaderText.setInnerText(hdrTxt);
        UIObject.setVisible(diffHeaderRow, header);
    } else {
        header = false;
        UIObject.setVisible(diffHeaderRow, false);
    }
    setHideEmptyPane(prefs.hideEmptyPane());
}
Also used : JsArrayString(com.google.gwt.core.client.JsArrayString) JsArrayString(com.google.gwt.core.client.JsArrayString)

Example 43 with JsArrayString

use of com.google.gwt.core.client.JsArrayString in project gerrit by GerritCodeReview.

the class PathSuggestOracle method onRequestSuggestions.

@Override
protected void onRequestSuggestions(final Request req, final Callback cb) {
    RestApi api = ChangeApi.revision(changeId.get(), revision.name()).view("files");
    if (req.getQuery() != null) {
        api.addParameter("q", req.getQuery() == null ? "" : req.getQuery());
    }
    api.background().get(new AsyncCallback<JsArrayString>() {

        @Override
        public void onSuccess(JsArrayString result) {
            List<Suggestion> r = new ArrayList<>();
            for (String path : Natives.asList(result)) {
                r.add(new PathSuggestion(path));
            }
            cb.onSuggestionsReady(req, new Response(r));
        }

        @Override
        public void onFailure(Throwable caught) {
            List<Suggestion> none = Collections.emptyList();
            cb.onSuggestionsReady(req, new Response(none));
        }
    });
}
Also used : RestApi(com.google.gerrit.client.rpc.RestApi) List(java.util.List) ArrayList(java.util.ArrayList) JsArrayString(com.google.gwt.core.client.JsArrayString) JsArrayString(com.google.gwt.core.client.JsArrayString)

Example 44 with JsArrayString

use of com.google.gwt.core.client.JsArrayString in project gerrit by GerritCodeReview.

the class QuickApprove method set.

void set(ChangeInfo info, String commit, ReplyAction action) {
    if (!info.hasPermittedLabels() || !info.status().isOpen()) {
        // Quick approve needs at least one label on an open change.
        setVisible(false);
        return;
    }
    if (info.revision(commit).isEdit() || info.revision(commit).draft()) {
        setVisible(false);
        return;
    }
    String qName = null;
    String qValueStr = null;
    short qValue = 0;
    int index = info.getMissingLabelIndex();
    if (index != -1) {
        LabelInfo label = Natives.asList(info.allLabels().values()).get(index);
        JsArrayString values = info.permittedValues(label.name());
        String s = values.get(values.length() - 1);
        short v = LabelInfo.parseValue(s);
        if (v > 0 && s.equals(label.maxValue())) {
            qName = label.name();
            qValueStr = s;
            qValue = v;
        }
    }
    if (qName != null) {
        changeId = info.legacyId();
        revision = commit;
        input = ReviewInput.create();
        input.drafts(DraftHandling.PUBLISH_ALL_REVISIONS);
        input.label(qName, qValue);
        replyAction = action;
        setText(qName + qValueStr);
        setVisible(true);
    } else {
        setVisible(false);
    }
}
Also used : LabelInfo(com.google.gerrit.client.info.ChangeInfo.LabelInfo) JsArrayString(com.google.gwt.core.client.JsArrayString) JsArrayString(com.google.gwt.core.client.JsArrayString)

Example 45 with JsArrayString

use of com.google.gwt.core.client.JsArrayString in project gerrit by GerritCodeReview.

the class Hashtags method formatHashtags.

private SafeHtmlBuilder formatHashtags(JsArrayString hashtags) {
    SafeHtmlBuilder html = new SafeHtmlBuilder();
    Iterator<String> itr = Natives.asList(hashtags).iterator();
    while (itr.hasNext()) {
        String hashtagName = itr.next();
        html.openSpan().setAttribute(DATA_ID, hashtagName).setStyleName(style.hashtagName()).openAnchor().setAttribute("href", "#" + PageLinks.toChangeQuery("hashtag:\"" + hashtagName + "\"")).setAttribute("role", "listitem").openSpan().setStyleName(style.hashtagIcon()).append(new ImageResourceRenderer().render(Gerrit.RESOURCES.hashtag())).closeSpan().append(" ").append(hashtagName).closeAnchor();
        if (canEdit) {
            html.openElement("button").setAttribute("title", "Remove hashtag").setAttribute("onclick", REMOVE + "(event)").append("×").closeElement("button");
        }
        html.closeSpan();
        if (itr.hasNext()) {
            html.append(' ');
        }
    }
    return html;
}
Also used : JsArrayString(com.google.gwt.core.client.JsArrayString) SafeHtmlBuilder(com.google.gwtexpui.safehtml.client.SafeHtmlBuilder) ImageResourceRenderer(com.google.gwt.user.client.ui.ImageResourceRenderer)

Aggregations

JsArrayString (com.google.gwt.core.client.JsArrayString)86 ArrayList (java.util.ArrayList)15 JSONString (com.google.gwt.json.client.JSONString)5 Position (org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position)5 ServerError (org.rstudio.studio.client.server.ServerError)4 JsArrayInteger (com.google.gwt.core.client.JsArrayInteger)3 Command (com.google.gwt.user.client.Command)3 List (java.util.List)3 KeySequence (org.rstudio.core.client.command.KeyboardShortcut.KeySequence)3 JsObject (org.rstudio.core.client.js.JsObject)3 RmdTemplateFormatOption (org.rstudio.studio.client.rmarkdown.model.RmdTemplateFormatOption)3 JsArrayBoolean (com.google.gwt.core.client.JsArrayBoolean)2 FlowPanel (com.google.gwt.user.client.ui.FlowPanel)2 Label (com.google.gwt.user.client.ui.Label)2 OperationException (org.eclipse.che.api.promises.client.OperationException)2 Handler (org.rstudio.core.client.command.Handler)2 EnsureHeightHandler (org.rstudio.core.client.events.EnsureHeightHandler)2 EnsureVisibleHandler (org.rstudio.core.client.events.EnsureVisibleHandler)2 ChangeFontSizeHandler (org.rstudio.studio.client.application.events.ChangeFontSizeHandler)2 RmdFrontMatterOutputOptions (org.rstudio.studio.client.rmarkdown.model.RmdFrontMatterOutputOptions)2