Skip to content

Commit

Permalink
remove branch filter from toolbar
Browse files Browse the repository at this point in the history
 - branch filter already exists in the search options section
 - having two branch filters can be confusing
 - jgit allows currently to only mark 24 revs during rev walk. This
   means that the branch filter could only work with branch
   information for 23 branches max. This would cause it to incorrectly
   filter out commits in repos with many branches and can lead to no or
   wrong results. The branch filter of the search options section is
   applied during the git command and doesn't have this issue.
  • Loading branch information
mbien committed Mar 19, 2024
1 parent 3cb5ad4 commit 4fb8227
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 142 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,6 @@
<Properties>
<Property name="rollover" type="boolean" value="true"/>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_InitCodePre" type="java.lang.String" value="jToolBar1.setLayout(new BoxLayout(jToolBar1, BoxLayout.X_AXIS));"/>
</AuxValues>

<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBoxLayout"/>
<SubComponents>
Expand Down Expand Up @@ -215,37 +212,15 @@
<AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="16"/>
</AuxValues>
</Component>
<Component class="javax.swing.JToolBar$Separator" name="jSeparator4">
</Component>
<Component class="javax.swing.JLabel" name="lblBranch">
<Component class="javax.swing.Box$Filler" name="fillerX">
<Properties>
<Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
<ComponentRef name="cmbBranch"/>
</Property>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/netbeans/modules/git/ui/history/Bundle.properties" key="branchLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
<Property name="toolTipText" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/netbeans/modules/git/ui/history/Bundle.properties" key="branchLabel.TTtext" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.EmptyBorderInfo">
<EmptyBorder bottom="0" left="5" right="5" top="0"/>
</Border>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JComboBox" name="cmbBranch">
<Properties>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="0"/>
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[32767, 0]"/>
</Property>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cmbBranchActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JToolBar$Separator" name="jSeparator1">
<AuxValues>
<AuxValue name="classDetails" type="java.lang.String" value="Box.Filler.HorizontalGlue"/>
</AuxValues>
</Component>
<Component class="javax.swing.JLabel" name="lblFilter">
<Properties>
Expand All @@ -264,6 +239,9 @@
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="0"/>
</Property>
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[300, 32767]"/>
</Property>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cmbFilterKindActionPerformed"/>
Expand All @@ -283,11 +261,11 @@
</Component>
<Component class="javax.swing.JTextField" name="txtFilter">
<Properties>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[30, 18]"/>
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[350, 100]"/>
</Property>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[50, 18]"/>
<Dimension value="[350, 23]"/>
</Property>
</Properties>
</Component>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package org.netbeans.modules.git.ui.history;

import java.awt.Color;
import java.awt.Component;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import org.openide.util.NbBundle;
Expand Down Expand Up @@ -50,13 +49,8 @@
import java.util.stream.Collectors;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.BoxLayout;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListCellRenderer;
import javax.swing.Icon;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.KeyStroke;
import javax.swing.SwingUtilities;
import javax.swing.Timer;
Expand All @@ -83,9 +77,6 @@
*
* @author Maros Sandor
*/
@NbBundle.Messages({
"SearchHistoryPanel.filter.allbranches=All Branches"
})
class SearchHistoryPanel extends javax.swing.JPanel implements ExplorerManager.Provider, PropertyChangeListener, DocumentListener, ActionListener {

private final File[] roots;
Expand Down Expand Up @@ -115,9 +106,7 @@ class SearchHistoryPanel extends javax.swing.JPanel implements ExplorerManager.P
private DiffResultsViewFactory diffViewFactory;
private boolean searchStarted;
private String currentBranch;
private Object currentBranchFilter = ALL_BRANCHES_FILTER;
private final RepositoryInfo info;
private static final String ALL_BRANCHES_FILTER = Bundle.SearchHistoryPanel_filter_allbranches();
private final PropertyChangeListener list;

enum FilterKind {
Expand Down Expand Up @@ -252,18 +241,6 @@ public void actionPerformed(ActionEvent e) {
fileInfoCheckBox.setSelected(GitModuleConfig.getDefault().getShowFileInfo());

criteria.btnSelectBranch.addActionListener(this);
cmbBranch.setRenderer(new DefaultListCellRenderer() {

@Override
public Component getListCellRendererComponent (JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
if (value instanceof GitBranch) {
value = ((GitBranch) value).getName();
}
return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
}

});
refreshBranchFilterModel();
}


Expand All @@ -273,8 +250,6 @@ public void propertyChange(PropertyChangeEvent evt) {
TopComponent tc = (TopComponent) SwingUtilities.getAncestorOfClass(TopComponent.class, this);
if (tc == null) return;
tc.setActivatedNodes((Node[]) evt.getNewValue());
} else if (RepositoryInfo.PROPERTY_BRANCHES.equals(evt.getPropertyName())) {
refreshBranchFilterModel();
}
}

Expand Down Expand Up @@ -395,7 +370,6 @@ void executeSearch() {
// did user change this setting and cleared the branch field?
GitModuleConfig.getDefault().setSearchOnlyCurrentBranchEnabled(criteria.getBranch() != null);
}
updateBranchFilter(criteria.getBranch());
try {
currentSearch = new SearchExecutor(this);
currentSearch.start(Git.getInstance().getRequestProcessor(repository), repository, NbBundle.getMessage(SearchExecutor.class, "MSG_Search_Progress", repository)); //NOI18N
Expand Down Expand Up @@ -458,10 +432,7 @@ private void initComponents() {
jSeparator2 = new javax.swing.JSeparator();
jSeparator3 = new javax.swing.JToolBar.Separator();
layoutButton = new javax.swing.JToggleButton();
jSeparator4 = new javax.swing.JToolBar.Separator();
lblBranch = new javax.swing.JLabel();
cmbBranch = new javax.swing.JComboBox();
jSeparator1 = new javax.swing.JToolBar.Separator();
fillerX = new javax.swing.Box.Filler(new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 0), new java.awt.Dimension(32767, 0));
lblFilter = new javax.swing.JLabel();
cmbFilterKind = new javax.swing.JComboBox();
lblFilterContains = new javax.swing.JLabel();
Expand All @@ -476,7 +447,6 @@ private void initComponents() {

searchCriteriaPanel.setLayout(new java.awt.BorderLayout());

jToolBar1.setLayout(new BoxLayout(jToolBar1, BoxLayout.X_AXIS));
jToolBar1.setRollover(true);

buttonGroup1.add(tbSummary);
Expand Down Expand Up @@ -521,31 +491,22 @@ private void initComponents() {
fileInfoCheckBox.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
fileInfoCheckBox.addActionListener(this::fileInfoCheckBoxActionPerformed);
jToolBar1.add(fileInfoCheckBox);
jToolBar1.add(jSeparator4);

lblBranch.setLabelFor(cmbBranch);
org.openide.awt.Mnemonics.setLocalizedText(lblBranch, org.openide.util.NbBundle.getMessage(SearchHistoryPanel.class, "branchLabel.text")); // NOI18N
lblBranch.setToolTipText(org.openide.util.NbBundle.getMessage(SearchHistoryPanel.class, "branchLabel.TTtext")); // NOI18N
lblBranch.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 5, 0, 5));
jToolBar1.add(lblBranch);

cmbBranch.addActionListener(this::cmbBranchActionPerformed);
jToolBar1.add(cmbBranch);
jToolBar1.add(jSeparator1);
jToolBar1.add(fillerX);

org.openide.awt.Mnemonics.setLocalizedText(lblFilter, org.openide.util.NbBundle.getMessage(SearchHistoryPanel.class, "filterLabel.text")); // NOI18N
lblFilter.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 5, 0, 5));
jToolBar1.add(lblFilter);

cmbFilterKind.setMaximumSize(new java.awt.Dimension(300, 32767));
cmbFilterKind.addActionListener(this::cmbFilterKindActionPerformed);
jToolBar1.add(cmbFilterKind);

org.openide.awt.Mnemonics.setLocalizedText(lblFilterContains, org.openide.util.NbBundle.getMessage(SearchHistoryPanel.class, "containsLabel")); // NOI18N
lblFilterContains.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 5, 0, 5));
jToolBar1.add(lblFilterContains);

txtFilter.setMinimumSize(new java.awt.Dimension(30, 18));
txtFilter.setPreferredSize(new java.awt.Dimension(50, 18));
txtFilter.setMaximumSize(new java.awt.Dimension(350, 100));
txtFilter.setPreferredSize(new java.awt.Dimension(350, 23));
jToolBar1.add(txtFilter);

resultsPanel.setLayout(new java.awt.BorderLayout());
Expand Down Expand Up @@ -612,31 +573,6 @@ private void cmbFilterKindActionPerformed (java.awt.event.ActionEvent evt) {//GE
}
}//GEN-LAST:event_cmbFilterKindActionPerformed

@NbBundle.Messages({
"LBL_SearchHistoryPanel.searchAllBranches.title=Search Restart Required",
"# {0} - branch name", "MSG_SearchHistoryPanel.searchAllBranches.text=Changing the branch filter to this value will have no effect \n"
+ "because you are currently searching the branch \"{0}\" only.\n\n"
+ "Do you want to restart the search to view all branches?"
})
private void cmbBranchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbBranchActionPerformed
Object filter = cmbBranch.getSelectedItem();
boolean refresh = filter != currentBranchFilter;
if (refresh) {
currentBranchFilter = filter;
if (currentBranchFilter == ALL_BRANCHES_FILTER && criteria.getBranch() != null && criteria.tfBranch.isEnabled()) {
if (JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(this,
Bundle.MSG_SearchHistoryPanel_searchAllBranches_text(criteria.getBranch()),
Bundle.LBL_SearchHistoryPanel_searchAllBranches_title(),
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE)) {
criteria.setBranch("");
executeSearch();
return;
}
}
filterTimer.restart();
}
}//GEN-LAST:event_cmbBranchActionPerformed

private void layoutButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_layoutButtonActionPerformed
diffView.switchLayout();
}//GEN-LAST:event_layoutButtonActionPerformed
Expand Down Expand Up @@ -694,17 +630,14 @@ public void actionPerformed (ActionEvent e) {
final javax.swing.JButton bPrev = new javax.swing.JButton();
private javax.swing.JButton bSearch;
private javax.swing.ButtonGroup buttonGroup1;
private javax.swing.JComboBox cmbBranch;
private javax.swing.JComboBox cmbFilterKind;
private org.netbeans.modules.versioning.history.LinkButton expandCriteriaButton;
final javax.swing.JCheckBox fileInfoCheckBox = new javax.swing.JCheckBox();
private javax.swing.JToolBar.Separator jSeparator1;
private javax.swing.Box.Filler fillerX;
private javax.swing.JSeparator jSeparator2;
private javax.swing.JToolBar.Separator jSeparator3;
private javax.swing.JToolBar.Separator jSeparator4;
private javax.swing.JToolBar jToolBar1;
private javax.swing.JToggleButton layoutButton;
private javax.swing.JLabel lblBranch;
private javax.swing.JLabel lblFilter;
private javax.swing.JLabel lblFilterContains;
private javax.swing.JPanel resultsPanel;
Expand Down Expand Up @@ -827,15 +760,11 @@ private boolean applyFilter(RepositoryRevision rev, FilterKind kind, String text

private boolean applyFilterImpl(RepositoryRevision rev, FilterKind kind, String text) {
GitRevisionInfo log = rev.getLog();
boolean visible = text.isEmpty()
return text.isEmpty()
|| (allOrEquals(kind, FilterKind.MESSAGE) && log.getFullMessage().toLowerCase(ROOT).contains(text))
|| (allOrEquals(kind, FilterKind.USER) && log.getAuthor().toString().toLowerCase(ROOT).contains(text))
|| (allOrEquals(kind, FilterKind.ID) && (log.getRevision().contains(text) || contains(rev.getBranches(), text) || contains(rev.getTags(), text)))
|| (allOrEquals(kind, FilterKind.FILE) && containsFiles(log, text));
if (visible && currentBranchFilter instanceof GitBranch) {
visible = log.getBranches().containsKey(((GitBranch) currentBranchFilter).getName());
}
return visible;
}

private static boolean allOrEquals(FilterKind toCheck, FilterKind required) {
Expand Down Expand Up @@ -952,34 +881,4 @@ void setDiffResultsViewFactory(SearchHistoryTopComponent.DiffResultsViewFactory
}
}

private void refreshBranchFilterModel () {
DefaultComboBoxModel model = new DefaultComboBoxModel();
model.addElement(ALL_BRANCHES_FILTER);
for (Map.Entry<String, GitBranch> e : info.getBranches().entrySet()) {
GitBranch b = e.getValue();
if (b.getName() != GitBranch.NO_BRANCH) {
model.addElement(b);
if (currentBranchFilter instanceof GitBranch && b.getName().equals(((GitBranch) currentBranchFilter).getName())) {
currentBranchFilter = b;
}
}
}
cmbBranch.setModel(model);
cmbBranch.setSelectedItem(currentBranchFilter);
}

private void updateBranchFilter (String branch) {
currentBranchFilter = ALL_BRANCHES_FILTER;
if (branch != null && criteria.getMode() != SearchExecutor.Mode.REMOTE_IN) {
ComboBoxModel model = cmbBranch.getModel();
for (int i = 0; i < model.getSize(); ++i) {
Object filter = model.getElementAt(i);
if (filter instanceof GitBranch && branch.equals(((GitBranch) filter).getName())) {
currentBranchFilter = filter;
break;
}
}
}
cmbBranch.setSelectedItem(currentBranchFilter);
}
}

0 comments on commit 4fb8227

Please sign in to comment.