Search in sources :

Example 1 with StatusAndPath

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

the class SVNReviewPresenter method updateDiff.

private void updateDiff() {
    view_.hideSizeWarning();
    final ArrayList<StatusAndPath> paths = view_.getChangelistTable().getSelectedItems();
    if (paths.size() != 1) {
        clearDiff();
        return;
    }
    final StatusAndPath item = paths.get(0);
    if (!item.getPath().equals(currentFilename_)) {
        clearDiff();
        currentFilename_ = item.getPath();
    }
    // bail if this is an undiffable status
    if (undiffableStatuses_.contains(item.getStatus()))
        return;
    diffInvalidation_.invalidate();
    final Token token = diffInvalidation_.getInvalidationToken();
    server_.svnDiffFile(item.getPath(), view_.getContextLines().getValue(), overrideSizeWarning_, new SimpleRequestCallback<DiffResult>("Diff Error") {

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

        @Override
        public void onError(ServerError error) {
            JSONNumber size = error.getClientInfo().isNumber();
            if (size != null)
                view_.showSizeWarning((long) size.doubleValue());
            else
                super.onError(error);
        }
    });
}
Also used : SVNDiffParser(org.rstudio.studio.client.workbench.views.vcs.svn.SVNDiffParser) 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)

Example 2 with StatusAndPath

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

the class ChangelistTable method getSelectedItems.

public ArrayList<StatusAndPath> getSelectedItems() {
    SelectionModel<? super StatusAndPath> selectionModel = table_.getSelectionModel();
    ArrayList<StatusAndPath> results = new ArrayList<StatusAndPath>();
    for (StatusAndPath item : dataProvider_.getList()) {
        if (selectionModel.isSelected(item))
            results.add(item);
    }
    return results;
}
Also used : StatusAndPath(org.rstudio.studio.client.common.vcs.StatusAndPath) ArrayList(java.util.ArrayList)

Example 3 with StatusAndPath

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

the class ChangelistTable method getSelectedPaths.

public ArrayList<String> getSelectedPaths() {
    SelectionModel<? super StatusAndPath> selectionModel = table_.getSelectionModel();
    ArrayList<String> results = new ArrayList<String>();
    for (StatusAndPath item : dataProvider_.getList()) {
        if (selectionModel.isSelected(item))
            results.add(item.getPath());
    }
    return results;
}
Also used : StatusAndPath(org.rstudio.studio.client.common.vcs.StatusAndPath) ArrayList(java.util.ArrayList)

Example 4 with StatusAndPath

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

the class GitChangelistTable method toggleStaged.

public void toggleStaged(boolean moveSelection) {
    ArrayList<StatusAndPath> items = getSelectedItems();
    if (items.size() > 0) {
        boolean unstage = items.get(0).getStatus().charAt(1) == ' ';
        fireEvent(new StageUnstageEvent(unstage, items));
        if (moveSelection) {
            moveSelectionDown();
        }
    }
}
Also used : StatusAndPath(org.rstudio.studio.client.common.vcs.StatusAndPath) StageUnstageEvent(org.rstudio.studio.client.workbench.views.vcs.common.events.StageUnstageEvent)

Example 5 with StatusAndPath

use of org.rstudio.studio.client.common.vcs.StatusAndPath 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

StatusAndPath (org.rstudio.studio.client.common.vcs.StatusAndPath)10 ArrayList (java.util.ArrayList)7 JSONNumber (com.google.gwt.json.client.JSONNumber)2 Token (org.rstudio.core.client.Invalidation.Token)2 DiffResult (org.rstudio.studio.client.common.vcs.DiffResult)2 ServerError (org.rstudio.studio.client.server.ServerError)2 Handler (org.rstudio.core.client.command.Handler)1 Operation (org.rstudio.core.client.widget.Operation)1 OperationWithInput (org.rstudio.core.client.widget.OperationWithInput)1 PatchMode (org.rstudio.studio.client.common.vcs.GitServerOperations.PatchMode)1 IgnoreList (org.rstudio.studio.client.common.vcs.ignore.IgnoreList)1 VCSApplicationParams (org.rstudio.studio.client.vcs.VCSApplicationParams)1 ProcessCallback (org.rstudio.studio.client.workbench.views.vcs.common.ProcessCallback)1 StageUnstageEvent (org.rstudio.studio.client.workbench.views.vcs.common.events.StageUnstageEvent)1 HistoryPresenter (org.rstudio.studio.client.workbench.views.vcs.dialog.HistoryPresenter)1 ReviewPresenter (org.rstudio.studio.client.workbench.views.vcs.dialog.ReviewPresenter)1 SVNDiffParser (org.rstudio.studio.client.workbench.views.vcs.svn.SVNDiffParser)1