Search in sources :

Example 1 with PatchMode

use of org.rstudio.studio.client.common.vcs.GitServerOperations.PatchMode in project rstudio by rstudio.

the class GitReviewPresenter method updateDiff.

private void updateDiff(boolean allowModeSwitch) {
    view_.hideSizeWarning();
    final ArrayList<StatusAndPath> paths = view_.getChangelistTable().getSelectedItems();
    if (paths.size() != 1) {
        clearDiff();
        return;
    }
    final StatusAndPath item = paths.get(0);
    if (allowModeSwitch) {
        if (!softModeSwitch_) {
            boolean staged = item.getStatus().charAt(0) != ' ' && item.getStatus().charAt(1) == ' ';
            HasValue<Boolean> checkbox = staged ? view_.getStagedCheckBox() : view_.getUnstagedCheckBox();
            if (!checkbox.getValue()) {
                clearDiff();
                checkbox.setValue(true, true);
            }
        } else {
            if (view_.getStagedCheckBox().getValue() && (item.getStatus().charAt(0) == ' ' || item.getStatus().charAt(0) == '?')) {
                clearDiff();
                view_.getUnstagedCheckBox().setValue(true, true);
            } else if (view_.getUnstagedCheckBox().getValue() && item.getStatus().charAt(1) == ' ') {
                clearDiff();
                view_.getStagedCheckBox().setValue(true, true);
            }
        }
    }
    softModeSwitch_ = false;
    if (!item.getPath().equals(currentFilename_)) {
        clearDiff();
        currentFilename_ = item.getPath();
    }
    diffInvalidation_.invalidate();
    final Token token = diffInvalidation_.getInvalidationToken();
    final PatchMode patchMode = view_.getStagedCheckBox().getValue() ? PatchMode.Stage : PatchMode.Working;
    server_.gitDiffFile(item.getPath(), patchMode, view_.getContextLines().getValue(), overrideSizeWarning_, new SimpleRequestCallback<DiffResult>("Diff Error") {

        @Override
        public void onResponseReceived(DiffResult diffResult) {
            if (token.isInvalid())
                return;
            // Use lastResponse_ to prevent unnecessary flicker
            String response = diffResult.getDecodedValue();
            if (response.equals(currentResponse_))
                return;
            currentResponse_ = response;
            currentSourceEncoding_ = diffResult.getSourceEncoding();
            UnifiedParser parser = new UnifiedParser(response);
            parser.nextFilePair();
            ArrayList<ChunkOrLine> allLines = new ArrayList<ChunkOrLine>();
            activeChunks_.clear();
            for (DiffChunk chunk; null != (chunk = parser.nextChunk()); ) {
                activeChunks_.add(chunk);
                allLines.add(new ChunkOrLine(chunk));
                for (Line line : chunk.getLines()) allLines.add(new ChunkOrLine(line));
            }
            view_.setShowActions(!"??".equals(item.getStatus()) && !"UU".equals(item.getStatus()));
            view_.setData(allLines, patchMode);
        }

        @Override
        public void onError(ServerError error) {
            JSONNumber size = error.getClientInfo().isNumber();
            if (size != null)
                view_.showSizeWarning((long) size.doubleValue());
            else {
                if (error.getCode() != ServerError.TRANSMISSION)
                    super.onError(error);
            }
        }
    });
}
Also used : StatusAndPath(org.rstudio.studio.client.common.vcs.StatusAndPath) ServerError(org.rstudio.studio.client.server.ServerError) ArrayList(java.util.ArrayList) Token(org.rstudio.core.client.Invalidation.Token) JSONNumber(com.google.gwt.json.client.JSONNumber) DiffResult(org.rstudio.studio.client.common.vcs.DiffResult) PatchMode(org.rstudio.studio.client.common.vcs.GitServerOperations.PatchMode)

Aggregations

JSONNumber (com.google.gwt.json.client.JSONNumber)1 ArrayList (java.util.ArrayList)1 Token (org.rstudio.core.client.Invalidation.Token)1 DiffResult (org.rstudio.studio.client.common.vcs.DiffResult)1 PatchMode (org.rstudio.studio.client.common.vcs.GitServerOperations.PatchMode)1 StatusAndPath (org.rstudio.studio.client.common.vcs.StatusAndPath)1 ServerError (org.rstudio.studio.client.server.ServerError)1