Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf2019-11-19 02:51:58 -0500
committerMichael Keppler2019-11-20 02:10:39 -0500
commitd27d58caf90e24ed4361fdf91a837cadba723d7f (patch)
treefe2e6fcd9d6c836dd0b130fb1a50f05b7d7a9135
parent94b62dc4edf826b3cc001c45230e7c800a4381f5 (diff)
downloadegit-d27d58caf90e24ed4361fdf91a837cadba723d7f.tar.gz
egit-d27d58caf90e24ed4361fdf91a837cadba723d7f.tar.xz
egit-d27d58caf90e24ed4361fdf91a837cadba723d7f.zip
[history] Don't allow empty ref filters
Give the text cell editor in the ref filter dialog a validator and add a label where we can display a validation error message. Use an ICellEditorListener to update the message and the buttons. Disable the OK button when the cell editor value is invalid. Also prevent pasting multi-line text into the single-line control of the cell editor. (See bug 273470.) Bug: 553070 Change-Id: I660428ad1306d8fdfea1918a13ba040cc2b68f27 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java6
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryRefFilterConfigurationDialog.java64
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties2
3 files changed, 64 insertions, 8 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java
index 36eea91c3..36d9a1cda 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java
@@ -674,6 +674,9 @@ public class UIText extends NLS {
public static String GitHistoryPage_configureFilters;
/** */
+ public static String GitHistoryPage_filterRefDialog_dialogMessage;
+
+ /** */
public static String GitHistoryPage_filterRefDialog_dialogTitle;
/** */
@@ -707,6 +710,9 @@ public class UIText extends NLS {
public static String GitHistoryPage_filterRefDialog_preconfiguredText;
/** */
+ public static String GitHistoryPage_filterRefDialog_refEmptyError;
+
+ /** */
public static String GitHistoryPage_filterRefDialog_selectRefDialog_dialogTitle;
/** */
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryRefFilterConfigurationDialog.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryRefFilterConfigurationDialog.java
index e8fbe66a1..4176a1aa5 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryRefFilterConfigurationDialog.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryRefFilterConfigurationDialog.java
@@ -13,14 +13,17 @@ package org.eclipse.egit.ui.internal.history;
import java.util.List;
import java.util.Set;
+import org.eclipse.egit.core.internal.Utils;
import org.eclipse.egit.ui.internal.UIText;
import org.eclipse.egit.ui.internal.dialogs.AbstractBranchSelectionDialog;
import org.eclipse.egit.ui.internal.history.RefFilterHelper.RefFilter;
+import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.CheckStateChangedEvent;
import org.eclipse.jface.viewers.CheckboxTableViewer;
import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.ICellEditorListener;
import org.eclipse.jface.viewers.ICellModifier;
import org.eclipse.jface.viewers.ICheckStateListener;
import org.eclipse.jface.viewers.ICheckStateProvider;
@@ -34,6 +37,7 @@ import org.eclipse.jface.viewers.ViewerComparator;
import org.eclipse.jface.window.Window;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.ShellAdapter;
@@ -49,6 +53,7 @@ import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.preferences.ViewSettingsDialog;
@@ -73,6 +78,8 @@ public class GitHistoryRefFilterConfigurationDialog
private Button editButton;
private TextCellEditor editor;
+ private CLabel message;
+
private volatile boolean editingMode = false;
private boolean defaultsPerformed = false;
@@ -134,6 +141,10 @@ public class GitHistoryRefFilterConfigurationDialog
composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
composite.setBackground(container.getBackground());
+ message = new CLabel(composite, SWT.WRAP);
+ message.setText(UIText.GitHistoryPage_filterRefDialog_dialogMessage);
+ GridDataFactory.fillDefaults().grab(true, false).applyTo(message);
+
Group filtersComposite = new Group(composite, SWT.NONE);
filtersComposite
.setText(
@@ -241,19 +252,56 @@ public class GitHistoryRefFilterConfigurationDialog
});
editor = new TextCellEditor(configsTable.getTable()) {
+
@Override
- public void deactivate() {
- super.deactivate();
- if (editingMode) {
- editingMode = false;
- updateButtonEnablement();
+ protected Control createControl(Composite containing) {
+ Control result = super.createControl(containing);
+ if ((text.getStyle() & SWT.SINGLE) != 0) {
+ // See bug 273470
+ text.addVerifyListener(
+ event -> event.text = Utils.firstLine(event.text));
}
+ return result;
}
};
- CellEditor[] editors = new CellEditor[1];
- editors[0] = editor;
+ editor.setValidator(value -> {
+ String currentText = value.toString().trim();
+ if (currentText.isEmpty()) {
+ return UIText.GitHistoryPage_filterRefDialog_refEmptyError;
+ }
+ return null;
+ });
+ editor.addListener(new ICellEditorListener() {
+
+ @Override
+ public void editorValueChanged(boolean oldValidState,
+ boolean newValidState) {
+ if (newValidState) {
+ message.setImage(null);
+ message.setText(
+ UIText.GitHistoryPage_filterRefDialog_dialogMessage);
+ } else {
+ message.setImage(PlatformUI.getWorkbench().getSharedImages()
+ .getImage(ISharedImages.IMG_OBJS_ERROR_TSK));
+ message.setText(editor.getErrorMessage());
+ }
+ getButton(OK).setEnabled(newValidState);
+ }
+
+ @Override
+ public void cancelEditor() {
+ editingMode = false;
+ editorValueChanged(false, true);
+ updateButtonEnablement();
+ }
+
+ @Override
+ public void applyEditorValue() {
+ cancelEditor();
+ }
+ });
configsTable.setColumnProperties(new String[] { FILTER_COLUMN_NAME });
- configsTable.setCellEditors(editors);
+ configsTable.setCellEditors(new CellEditor[] { editor });
configsTable.setCellModifier(new ICellModifier() {
@Override
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties
index 67fd434c7..47497c6f0 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties
@@ -244,6 +244,7 @@ GitHistoryPage_ShowSubMenuLabel=&Show
GitHistoryPage_ColumnsSubMenuLabel=&Columns
GitHistoryPage_toggleEmailAddresses=&E-mail Addresses
GitHistoryPage_configureFilters=Ref F&ilters...
+GitHistoryPage_filterRefDialog_dialogMessage=Define which refs to include in the git history.
GitHistoryPage_filterRefDialog_dialogTitle=Configure Ref Filters
GitHistoryPage_filterRefDialog_filtersCompositeLabel=Filters
GitHistoryPage_filterRefDialog_patternExplanation=Filters are treated as path filters ('?', '*' and '**' are valid wildcards). Valid macros are "[CURRENT-BRANCH]", which will be replaced by the current branch name.
@@ -255,6 +256,7 @@ GitHistoryPage_filterRefDialog_button_headOnly=HEAD Only
GitHistoryPage_filterRefDialog_button_currentBranchOnly=Current Branch (Local and Remote)
GitHistoryPage_filterRefDialog_button_allBranchesAndTags=All Branches and Tags
GitHistoryPage_filterRefDialog_preconfiguredText=\ - (preconfigured)
+GitHistoryPage_filterRefDialog_refEmptyError=Ref filter must not be empty.
GitHistoryPage_filterRefDialog_selectRefDialog_dialogTitle=Select Ref
GitHistoryPage_filterRefDialog_selectRefDialog_dialogMessage=Select ref for branch filter
GitLightweightDecorator_name=Git resource decorations

Back to the top