|
| 1 | +/** |
| 2 | + * Copyright (c) 2015-2016 Angelo ZERR. |
| 3 | + * All rights reserved. This program and the accompanying materials |
| 4 | + * are made available under the terms of the Eclipse Public License v1.0 |
| 5 | + * which accompanies this distribution, and is available at |
| 6 | + * http://www.eclipse.org/legal/epl-v10.html |
| 7 | + * |
| 8 | + * Contributors: |
| 9 | + * Angelo Zerr <[email protected]> - initial API and implementation |
| 10 | + * Lorenzo Dalla Vecchia <[email protected]> - added reconcileControls hook |
| 11 | + */ |
| 12 | +package ts.eclipse.ide.internal.ui.preferences; |
| 13 | + |
| 14 | +import org.eclipse.core.resources.IProject; |
| 15 | +import org.eclipse.jface.dialogs.ControlEnableState; |
| 16 | +import org.eclipse.swt.SWT; |
| 17 | +import org.eclipse.swt.layout.GridData; |
| 18 | +import org.eclipse.swt.layout.GridLayout; |
| 19 | +import org.eclipse.swt.widgets.Composite; |
| 20 | +import org.eclipse.swt.widgets.Group; |
| 21 | +import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer; |
| 22 | + |
| 23 | +import ts.eclipse.ide.internal.ui.TypeScriptUIMessages; |
| 24 | +import ts.eclipse.ide.ui.preferences.OptionsConfigurationBlock; |
| 25 | +import ts.eclipse.ide.ui.preferences.ScrolledPageContent; |
| 26 | +import ts.eclipse.ide.ui.preferences.TypeScriptUIPreferenceConstants; |
| 27 | +import ts.eclipse.ide.ui.widgets.IStatusChangeListener; |
| 28 | + |
| 29 | +/** |
| 30 | + * CodeLens configuration block. |
| 31 | + * |
| 32 | + */ |
| 33 | +public class CodeLensConfigurationBlock extends OptionsConfigurationBlock { |
| 34 | + |
| 35 | + // Editor Options |
| 36 | + private static final Key PREF_EDITOR_ACTIVATE_CODELENS = getTypeScriptUIKey( |
| 37 | + TypeScriptUIPreferenceConstants.EDITOR_ACTIVATE_CODELENS); |
| 38 | + |
| 39 | + private Composite controlsComposite; |
| 40 | + private ControlEnableState blockEnableState; |
| 41 | + |
| 42 | + public CodeLensConfigurationBlock(IStatusChangeListener context, IProject project, |
| 43 | + IWorkbenchPreferenceContainer container) { |
| 44 | + super(context, project, getKeys(), container); |
| 45 | + blockEnableState = null; |
| 46 | + } |
| 47 | + |
| 48 | + private static Key[] getKeys() { |
| 49 | + return new Key[] { PREF_EDITOR_ACTIVATE_CODELENS }; |
| 50 | + } |
| 51 | + |
| 52 | + public void enablePreferenceContent(boolean enable) { |
| 53 | + if (controlsComposite != null && !controlsComposite.isDisposed()) { |
| 54 | + if (enable) { |
| 55 | + if (blockEnableState != null) { |
| 56 | + blockEnableState.restore(); |
| 57 | + blockEnableState = null; |
| 58 | + } |
| 59 | + } else { |
| 60 | + if (blockEnableState == null) { |
| 61 | + blockEnableState = ControlEnableState.disable(controlsComposite); |
| 62 | + } |
| 63 | + } |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + @Override |
| 68 | + protected Composite createUI(Composite parent) { |
| 69 | + final ScrolledPageContent pageContent = new ScrolledPageContent(parent); |
| 70 | + Composite composite = pageContent.getBody(); |
| 71 | + GridLayout layout = new GridLayout(); |
| 72 | + layout.marginHeight = 0; |
| 73 | + layout.marginWidth = 0; |
| 74 | + composite.setLayout(layout); |
| 75 | + |
| 76 | + controlsComposite = new Composite(composite, SWT.NONE); |
| 77 | + controlsComposite.setFont(composite.getFont()); |
| 78 | + controlsComposite.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false)); |
| 79 | + |
| 80 | + layout = new GridLayout(); |
| 81 | + layout.marginHeight = 0; |
| 82 | + layout.marginWidth = 0; |
| 83 | + layout.numColumns = 1; |
| 84 | + controlsComposite.setLayout(layout); |
| 85 | + |
| 86 | + // CodeLens options |
| 87 | + createCodeLensOptions(controlsComposite); |
| 88 | + return pageContent; |
| 89 | + } |
| 90 | + |
| 91 | + /** |
| 92 | + * Create editor options. |
| 93 | + * |
| 94 | + * @param parent |
| 95 | + */ |
| 96 | + private void createCodeLensOptions(Composite parent) { |
| 97 | + |
| 98 | + Group group = new Group(parent, SWT.NONE); |
| 99 | + group.setText(TypeScriptUIMessages.CodeLensConfigurationBlock_CodeLens_group_label); |
| 100 | + |
| 101 | + GridLayout layout = new GridLayout(); |
| 102 | + layout.numColumns = 3; |
| 103 | + group.setLayout(layout); |
| 104 | + group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
| 105 | + |
| 106 | + // Activate CodeLens |
| 107 | + addCheckBox(group, TypeScriptUIMessages.CodeLensConfigurationBlock_CodeLens_activate, |
| 108 | + PREF_EDITOR_ACTIVATE_CODELENS, new String[] { "true", "false" }, 0); |
| 109 | + } |
| 110 | + |
| 111 | + @Override |
| 112 | + protected void validateSettings(Key changedKey, String oldValue, String newValue) { |
| 113 | + if (!areSettingsEnabled()) { |
| 114 | + return; |
| 115 | + } |
| 116 | + if (changedKey != null) { |
| 117 | + |
| 118 | + } |
| 119 | + } |
| 120 | + |
| 121 | + @Override |
| 122 | + protected String[] getFullBuildDialogStrings(boolean workspaceSettings) { |
| 123 | + return null; |
| 124 | + } |
| 125 | + |
| 126 | +} |
0 commit comments