Skip to content

Commit

Permalink
Merge pull request #7128 from mbien/git-diff-history-improvements
Browse files Browse the repository at this point in the history
Git history and diff view improvements
  • Loading branch information
mbien authored Mar 27, 2024
2 parents 39e4b5f + d5d6ab8 commit e074d9d
Show file tree
Hide file tree
Showing 18 changed files with 628 additions and 612 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ public void removeNotify () {
jSplitPane1.setResizeWeight(0.5);
jSplitPane1.setDividerSize(INITIAL_DIVIDER_SIZE);
jSplitPane1.putClientProperty("PersistenceType", "Never"); // NOI18N
jSplitPane1.putClientProperty("diff-view-mode-splitter", true);
jSplitPane1.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(EditableDiffView.class, "ACS_DiffPanelA11yName")); // NOI18N
jSplitPane1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(EditableDiffView.class, "ACS_DiffPanelA11yDesc")); // NOI18N
view.setName(org.openide.util.NbBundle.getMessage(EditableDiffView.class, "DiffComponent.title", ss1.getName(), ss2.getName())); // NOI18N
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ TT_Limit=Show at most this number of commits
LBL_SearchHistoryPanel_AllInfo=Show &All Files
LBL_TT_SearchHistoryPanel_AllInfo=Shows all files affected in found revisions

CTL_DiffPanel_Next_Tooltip=Next Difference
CTL_DiffPanel_Prev_Tooltip=Previous Difference
CTL_DiffPanel_Next_Tooltip=Next Difference - {0}
CTL_DiffPanel_Prev_Tooltip=Previous Difference - {0}
ACSN_NextDifference=Go To Next Difference
ACSN_PrevDifference=Go To Previous Difference
ACSD_NextDifference=Go To Next Difference
Expand All @@ -67,6 +67,8 @@ ACSN_PrevRevision=Go To Previous ChangePath
ACSD_NextRevision=Go To Next ChangePath
ACSD_PrevRevision=Go To Previous ChangePath

TT_SwitchLayout=Switch between horizontal and vertical Layouts

LBL_SearchHistory_Searching = <No Results Yet - Search in Progress...>
LBL_SearchHistory_NoResults = <No Results - End of Search>
LBL_SearchHistory_Diffing = Retrieving files...
Expand Down Expand Up @@ -116,7 +118,7 @@ MSG_RevisionNodeChildren.Loading=Loading...
MSG_SearchHistoryPanel.GettingMoreRevisions=Getting more revisions
filterLabel.text=Fi&lter:
containsLabel=&contains
Filter.All=No Filter
Filter.All=All
Filter.Message=Message
Filter.User=Author
Filter.Commit=Revision
Expand Down
131 changes: 72 additions & 59 deletions ide/git/src/org/netbeans/modules/git/ui/history/DiffResultsView.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.util.logging.Logger;
import javax.swing.JComponent;
import javax.swing.JSplitPane;
import javax.swing.JTabbedPane;
import org.netbeans.api.diff.DiffController;
import org.netbeans.modules.git.client.GitProgressSupport;
import org.netbeans.modules.git.ui.diff.DiffStreamSource;
Expand Down Expand Up @@ -67,7 +68,7 @@ class DiffResultsView implements AncestorListener, PropertyChangeListener {
protected static final Logger LOG = Logger.getLogger(DiffResultsView.class.getName());
private final PropertyChangeListener list;
private Node[] selectedNodes;
private final Set<RepositoryRevision> revisionsToRefresh = new HashSet<RepositoryRevision>(2);
private final Set<RepositoryRevision> revisionsToRefresh = new HashSet<>(2);
private int lastDividerLoc;

public DiffResultsView (SearchHistoryPanel parent, List<RepositoryRevision> results) {
Expand All @@ -83,26 +84,27 @@ public DiffResultsView (SearchHistoryPanel parent, List<RepositoryRevision> resu
list = WeakListeners.propertyChange(this, null);
}

void switchLayout() {
diffView.setOrientation(
diffView.getOrientation() == JSplitPane.VERTICAL_SPLIT ? JSplitPane.HORIZONTAL_SPLIT : JSplitPane.VERTICAL_SPLIT
);
diffView.setDividerLocation(0.33);
}

@Override
public void ancestorAdded(AncestorEvent event) {
ExplorerManager em = ExplorerManager.find(treeView);
em.addPropertyChangeListener(this);
if (dividerSet) {
if (lastDividerLoc != 0) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run () {
diffView.setDividerLocation(lastDividerLoc);
}
EventQueue.invokeLater(() -> {
diffView.setDividerLocation(lastDividerLoc);
});
}
} else {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
dividerSet = true;
diffView.setDividerLocation(0.33);
}
EventQueue.invokeLater(() -> {
dividerSet = true;
diffView.setDividerLocation(0.33);
});
}
}
Expand Down Expand Up @@ -139,13 +141,7 @@ else if (selectedNodes.length > 2) {
revisionsToRefresh.clear();

// invoked asynchronously becase treeView.getSelection() may not be ready yet
Runnable runnable = new Runnable() {
@Override
public void run() {
showDiff();
}
};
EventQueue.invokeLater(runnable);
EventQueue.invokeLater(this::showDiff);
} else if (RepositoryRevision.PROP_EVENTS_CHANGED.equals(evt.getPropertyName())) {
if (evt.getSource() instanceof RepositoryRevision) {
RepositoryRevision revision = (RepositoryRevision) evt.getSource();
Expand Down Expand Up @@ -223,7 +219,6 @@ private void showDiff () {
}

if (loading) {
showDiffError(NbBundle.getMessage(DiffResultsView.class, "MSG_DiffPanel_LoadingDiff")); //NOI18N
parent.refreshComponents(false);
} else if (error) {
showDiffError(NbBundle.getMessage(DiffResultsView.class, "MSG_DiffPanel_IllegalSelection")); // NOI18N
Expand All @@ -233,17 +228,12 @@ private void showDiff () {
}
}

protected void showDiffError (final String s) {
Runnable inAWT = new Runnable() {
@Override
public void run() {
setBottomComponent(new NoContentPanel(s));
}
};
protected void showDiffError(final String s) {
Runnable inEDT = () -> setBottomComponent(new NoContentPanel(s));
if (EventQueue.isDispatchThread()) {
inAWT.run();
inEDT.run();
} else {
EventQueue.invokeLater(inAWT);
EventQueue.invokeLater(inEDT);
}
}

Expand Down Expand Up @@ -408,7 +398,7 @@ private class ShowDiffTask extends GitProgressSupport {
private File file1;
private File baseFile1;
private String revision1;
private boolean showLastDifference;
private final boolean showLastDifference;
private final RepositoryRevision.Event event2;
private DiffStreamSource s1;
private DiffStreamSource s2;
Expand All @@ -425,7 +415,6 @@ public ShowDiffTask(RepositoryRevision.Event event1, RepositoryRevision.Event ev

@Override
public void perform () {
showDiffError(NbBundle.getMessage(DiffResultsView.class, "MSG_DiffPanel_LoadingDiff")); //NOI18N
if (revision1 == null) {
try {
revision1 = event2.getLogInfoHeader().getAncestorCommit(event2.getOriginalFile(), getClient(), GitUtils.NULL_PROGRESS_MONITOR);
Expand Down Expand Up @@ -462,44 +451,68 @@ public void perform () {

if (currentTask != this) return;

EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
try {
if (isCanceled()) {
showDiffError(NbBundle.getMessage(DiffResultsView.class, "MSG_DiffPanel_NoRevisions")); // NOI18N
return;
EventQueue.invokeLater(() -> {
try {
if (isCanceled()) {
showDiffError(NbBundle.getMessage(DiffResultsView.class, "MSG_DiffPanel_NoRevisions")); // NOI18N
return;
}
final DiffController newDiff = DiffController.createEnhanced(s1, s2);

if (currentTask == ShowDiffTask.this) {
if (currentDiff != null) {
copyUIState(currentDiff, newDiff);
}
final DiffController view = DiffController.createEnhanced(s1, s2);
if (currentTask == ShowDiffTask.this) {
currentDiff = view;
setBottomComponent(currentDiff.getJComponent());
final int dl = diffView.getDividerLocation();
if (!setLocation(view)) {
view.addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
view.removePropertyChangeListener(this);
setLocation(view);
parent.updateActions();
}
});
}
parent.refreshComponents(false);
EventQueue.invokeLater(new Runnable () {
currentDiff = newDiff;
setBottomComponent(currentDiff.getJComponent());
if (!setLocation(newDiff)) {
newDiff.addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void run() {
diffView.setDividerLocation(dl);
public void propertyChange(PropertyChangeEvent evt) {
newDiff.removePropertyChangeListener(this);
setLocation(newDiff);
parent.updateActions();
}
});
}
} catch (IOException e) {
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
parent.refreshComponents(false);
}
} catch (IOException e) {
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
}
});
}

private void copyUIState(DiffController oldView, DiffController newView) {
JTabbedPane oldTP = findComponent(oldView.getJComponent(), JTabbedPane.class, "diff-view-mode-switcher");
JTabbedPane newTP = findComponent(newView.getJComponent(), JTabbedPane.class, "diff-view-mode-switcher");
if (newTP != null && oldTP != null) {
newTP.setSelectedIndex(oldTP.getSelectedIndex());
}
JSplitPane oldSP = findComponent(oldView.getJComponent(), JSplitPane.class, "diff-view-mode-splitter");
JSplitPane newSP = findComponent(newView.getJComponent(), JSplitPane.class, "diff-view-mode-splitter");
if (newSP != null && oldSP != null) {
newSP.setDividerLocation(oldSP.getDividerLocation());
}
}

@SuppressWarnings("unchecked")
private <T extends JComponent> T findComponent(JComponent parent, Class<T> ofType, String withProp) {
if (ofType.isInstance(parent) && Boolean.TRUE.equals(parent.getClientProperty(withProp))) {
return (T) parent;
} else {
for (Component child : parent.getComponents()) {
if (child instanceof JComponent) {
T comp = findComponent((JComponent) child, ofType, withProp);
if (comp != null) {
return comp;
}
}
}
}
return null;
}

@Override
public boolean cancel () {
if (s1 != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ public ShowDiffTask (File file, String revision, boolean showLastDifference) {

@Override
public void perform () {
showDiffError(NbBundle.getMessage(DiffResultsView.class, "MSG_DiffPanel_LoadingDiff")); //NOI18N
final DiffStreamSource leftSource = new DiffStreamSource(file, file, revision, revision);
final LocalFileDiffStreamSource rightSource = new LocalFileDiffStreamSource(file, true);

Expand Down
Loading

0 comments on commit e074d9d

Please sign in to comment.