Search in sources :

Example 1 with ViewFileRevisionEvent

use of org.rstudio.studio.client.workbench.views.vcs.common.events.ViewFileRevisionEvent in project rstudio by rstudio.

the class CommitDetail method setDetails.

@Override
public void setDetails(final DiffParser unifiedParser, final boolean suppressViewLink) {
    setProgressVisible(false);
    invalidation_.invalidate();
    final Token token = invalidation_.getInvalidationToken();
    Scheduler.get().scheduleIncremental(new RepeatingCommand() {

        @Override
        public boolean execute() {
            if (token.isInvalid())
                return false;
            final DiffFileHeader fileHeader = unifiedParser.nextFilePair();
            if (fileHeader == null)
                return false;
            int filesCompared = 2;
            ArrayList<ChunkOrLine> lines = new ArrayList<ChunkOrLine>();
            DiffChunk chunk;
            while (null != (chunk = unifiedParser.nextChunk())) {
                if (!chunk.shouldIgnore())
                    filesCompared = chunk.getRanges().length;
                lines.addAll(ChunkOrLine.fromChunk(chunk));
            }
            LineTableView view = new LineTableView(filesCompared);
            view.setUseStartBorder(true);
            view.setUseEndBorder(false);
            view.setShowActions(false);
            view.setData(lines, PatchMode.Stage);
            view.setWidth("100%");
            final DiffFrame diffFrame = new DiffFrame(null, fileHeader.getDescription(), null, commit_.getId(), view, new ClickHandler() {

                @Override
                public void onClick(ClickEvent event) {
                    fireEvent(new ViewFileRevisionEvent(commit_.getId(), fileHeader.getDescription().trim()));
                }
            }, suppressViewLink);
            diffFrame.setWidth("100%");
            detailPanel_.add(diffFrame);
            CommitTocRow tocAnchor = new CommitTocRow(fileHeader.getDescription());
            tocAnchor.addClickHandler(new ClickHandler() {

                @Override
                public void onClick(ClickEvent event) {
                    Point relativePosition = DomUtils.getRelativePosition(container_.getElement(), diffFrame.getElement());
                    container_.setVerticalScrollPosition(relativePosition.getY());
                }
            });
            tocPanel_.add(tocAnchor);
            return true;
        }
    });
}
Also used : ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) Token(org.rstudio.core.client.Invalidation.Token) Point(org.rstudio.core.client.Point) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) RepeatingCommand(com.google.gwt.core.client.Scheduler.RepeatingCommand) ViewFileRevisionEvent(org.rstudio.studio.client.workbench.views.vcs.common.events.ViewFileRevisionEvent)

Aggregations

RepeatingCommand (com.google.gwt.core.client.Scheduler.RepeatingCommand)1 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)1 ArrayList (java.util.ArrayList)1 Token (org.rstudio.core.client.Invalidation.Token)1 Point (org.rstudio.core.client.Point)1 ViewFileRevisionEvent (org.rstudio.studio.client.workbench.views.vcs.common.events.ViewFileRevisionEvent)1