Bug 537131 - Preference to hide Quick Access field per default

This change adds a new preference in the org.eclipse.ui.workbench
plug-in. Setting this preference to true will hide the quick access
search field, if the field state was not restored explicitly by the
user.

I.e. if the preference is used, starting in a new workspace will result
in hidden quick access field. If the field is restored at least once,
the preference is no longer used.

The preference can be set with the following entry:

org.eclipse.ui/hideQuickAccessPerDefault=true

Change-Id: I9d0d628e00503bab10f9823177164d28e2eda5f7
Signed-off-by: Simeon Andreev <simeon.danailov.andreev@gmail.com>
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/IWorkbenchPreferenceConstants.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/IWorkbenchPreferenceConstants.java
index 7cf9753..90f3a26 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/IWorkbenchPreferenceConstants.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/IWorkbenchPreferenceConstants.java
@@ -605,4 +605,14 @@
 	 * @since 3.7
 	 */
 	String RECENTLY_USED_WORKINGSETS_SIZE = "RECENTLY_USED_WORKINGSETS_SIZE"; //$NON-NLS-1$
+
+	/**
+	 * Workbench preference id for hiding the quick access search field per default.
+	 * <p>
+	 * Boolean-valued. The default value for this preference is: <code>false</code>.
+	 * </p>
+	 *
+	 * @since 3.112
+	 */
+	String HIDE_QUICK_ACCESS_PER_DEFAULT = "hideQuickAccessPerDefault"; //$NON-NLS-1$
 }
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchWindow.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchWindow.java
index d23cc10..68a3168 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchWindow.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchWindow.java
@@ -968,6 +968,9 @@
 								IPresentationEngine.HIDDEN_EXPLICITLY)) {
 							quickAccessElement.getTags().add(IPresentationEngine.HIDDEN_EXPLICITLY);
 						}
+					} else if (!model.getTags().contains(QUICK_ACCESS_DEFAULT_VISIBILITY_CHANGED)
+							&& hidesQuickAccessPerDefault()) {
+						quickAccessElement.getTags().add(IPresentationEngine.HIDDEN_EXPLICITLY);
 					}
 				}
 			}
@@ -977,6 +980,12 @@
 
 	private static final String QUICK_ACCESS_ID = "SearchField"; //$NON-NLS-1$
 	private static final String QUICK_ACCESS_HIDDEN = "QUICK_ACCESS_HIDDEN"; //$NON-NLS-1$
+	private static final String QUICK_ACCESS_DEFAULT_VISIBILITY_CHANGED = "QUICK_ACCESS_DEFAULT_VISIBILITY_CHANGED"; //$NON-NLS-1$
+
+	private static boolean hidesQuickAccessPerDefault() {
+		IPreferenceStore preferenceStore = PlatformUI.getPreferenceStore();
+		return preferenceStore.getBoolean(IWorkbenchPreferenceConstants.HIDE_QUICK_ACCESS_PER_DEFAULT);
+	}
 
 	@Inject
 	private void hideQuickAccess(
@@ -1001,16 +1010,23 @@
 					IPresentationEngine.HIDDEN_EXPLICITLY)) {
 				if (!model.getTags().contains(QUICK_ACCESS_HIDDEN)) {
 					model.getTags().add(QUICK_ACCESS_HIDDEN);
+					quickAccessDefaultVisibilityChanged();
 				}
 			}
 		} else if (UIEvents.isREMOVE(event)) {
 			if (UIEvents.contains(event, UIEvents.EventTags.OLD_VALUE,
 					IPresentationEngine.HIDDEN_EXPLICITLY)) {
 				model.getTags().remove(QUICK_ACCESS_HIDDEN);
+				quickAccessDefaultVisibilityChanged();
 			}
 		}
 	}
 
+	private void quickAccessDefaultVisibilityChanged() {
+		model.getTags().add(QUICK_ACCESS_DEFAULT_VISIBILITY_CHANGED);
+	}
+
+
 	/**
 	 * Moves the given element from its current position to the position
 	 * mentioned in one of its tags.