Skip to content

Commit

Permalink
Use different icon and arrow for moved code between files (issue #715)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsantalis committed May 30, 2024
1 parent c09832f commit 0db227b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 13 deletions.
7 changes: 7 additions & 0 deletions src/main/java/gui/webdiff/DirComparator.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public Set<String> getAddedFilesName() {
public List<Pair<String,String>> getModifiedFilesName() {
return modifiedFilesName;
}

public Pair<String,String> getFileContentsPair(int id)
{
return new Pair<>(
Expand Down Expand Up @@ -64,6 +65,12 @@ private void compare() {
removedFilesName.removeAll(addedFilesName);
addedFilesName.removeAll(removedBackup);
}

public boolean isMoveDiff(int id) {
ASTDiff diff = getASTDiff(id);
return projectASTDiff.getMoveDiffSet().contains(diff);
}

public ASTDiff getASTDiff(int id) {
return diffs.get(id);
}
Expand Down
46 changes: 33 additions & 13 deletions src/main/java/gui/webdiff/DirectoryDiffView.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,18 @@
import static org.rendersnake.HtmlAttributesFactory.*;

public class DirectoryDiffView implements Renderable {
private final DirComparator comperator;
private final DirComparator comparator;

public DirectoryDiffView(DirComparator comperator) {
this.comperator = comperator;
public DirectoryDiffView(DirComparator comparator) {
this.comparator = comparator;
}

private boolean isMovedCode(TreeNodeInfo info) {
return comparator.isMoveDiff(info.getId());
}

private boolean isModifiedFile(TreeNodeInfo info) {
ASTDiff astDiff = comperator.getASTDiff(info.getId());
ASTDiff astDiff = comparator.getASTDiff(info.getId());
if(astDiff != null && astDiff.getSrcPath() != null)
return astDiff.getSrcPath().equals(astDiff.getDstPath());
return false;
Expand All @@ -43,10 +47,10 @@ public void renderOn(HtmlCanvas html) throws IOException {
.div(class_("card-header"))
.h4(class_("card-title mb-0"))
.write("Modified files ")
.span(class_("badge badge-secondary").style("color:black")).content(comperator.getModifiedFilesName().size())
.span(class_("badge badge-secondary").style("color:black")).content(comparator.getModifiedFilesName().size())
._h4()
._div()
.render_if(new ModifiedFiles(comperator), !comperator.getModifiedFilesName().isEmpty())
.render_if(new ModifiedFiles(comparator), !comparator.getModifiedFilesName().isEmpty())
._div()
._div()
._div()
Expand All @@ -56,23 +60,23 @@ public void renderOn(HtmlCanvas html) throws IOException {
.div(class_("card-header bg-danger"))
.h4(class_("card-title mb-0"))
.write("Deleted files ")
.span(class_("badge badge-secondary").style("color:black")).content(comperator.getRemovedFilesName().size())
.span(class_("badge badge-secondary").style("color:black")).content(comparator.getRemovedFilesName().size())
._h4()
._div()
.render_if(new AddedOrDeletedFiles(comperator.getRemovedFilesName()),
comperator.getRemovedFilesName().size() > 0)
.render_if(new AddedOrDeletedFiles(comparator.getRemovedFilesName()),
comparator.getRemovedFilesName().size() > 0)
._div()
._div()
.div(class_("col"))
.div(class_("card"))
.div(class_("card-header bg-success"))
.h4(class_("card-title mb-0"))
.write("Added files ")
.span(class_("badge badge-secondary").style("color:black")).content(comperator.getAddedFilesName().size())
.span(class_("badge badge-secondary").style("color:black")).content(comparator.getAddedFilesName().size())
._h4()
._div()
.render_if(new AddedOrDeletedFiles(comperator.getAddedFilesName()),
comperator.getAddedFilesName().size() > 0)
.render_if(new AddedOrDeletedFiles(comparator.getAddedFilesName()),
comparator.getAddedFilesName().size() > 0)
._div()
._div()
._div()
Expand Down Expand Up @@ -109,11 +113,27 @@ private void renderNode(HtmlCanvas ul, DefaultMutableTreeNode node) throws IOExc
iconWidth = 15;
iconHeight = 17;
}
else if(isMovedCode(nodeInfo)) {
iconPath = "dist/file-transfer.svg";
iconWidth = 22;
iconHeight = 28;
ASTDiff astDiff = comparator.getASTDiff(nodeInfo.getId());
if(astDiff != null && astDiff.getSrcPath() != null) {
String srcName = astDiff.getSrcPath();
if(astDiff.getSrcPath().contains("/")) {
srcName = srcName.substring(srcName.lastIndexOf("/") + 1, srcName.length());
}
if(!srcName.equals(nodeInfo.getName())) {
//file is renamed
description = srcName + " ⇨ " + nodeInfo.getName();
}
}
}
else {
iconPath = "dist/icons8-file-move.svg";
iconWidth = 15;
iconHeight = 17;
ASTDiff astDiff = comperator.getASTDiff(nodeInfo.getId());
ASTDiff astDiff = comparator.getASTDiff(nodeInfo.getId());
if(astDiff != null && astDiff.getSrcPath() != null) {
String srcName = astDiff.getSrcPath();
if(astDiff.getSrcPath().contains("/")) {
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/web/dist/file-transfer.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0db227b

Please sign in to comment.