Skip to content

Commit ab63c28

Browse files
committed
Add CodeLens preferences page. See See
#181
1 parent f2982c9 commit ab63c28

File tree

6 files changed

+247
-0
lines changed

6 files changed

+247
-0
lines changed

eclipse/ts.eclipse.ide.ui/plugin.properties

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ EditorPreferencePage.name=Editor
3030
FormatterPreferencePage.name=Formatter
3131
ValidationPreferencePage.name=Validation
3232
TextMatePreferencePage.name=TextMate
33+
CodeLensPreferencePage.name=CodeLens
3334
SaveActionsPreferencePage.name=Save Actions
3435

3536
# Menu/Commands

eclipse/ts.eclipse.ide.ui/plugin.xml

+6
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,12 @@
240240
id="ts.eclipse.ide.ui.preference.TextMatePreferencePage"
241241
category="ts.eclipse.ide.ui.preference.EditorPreferencePage">
242242
</page>
243+
<page
244+
name="%CodeLensPreferencePage.name"
245+
class="ts.eclipse.ide.internal.ui.preferences.CodeLensPreferencePage"
246+
id="ts.eclipse.ide.ui.preference.CodeLensPreferencePage"
247+
category="ts.eclipse.ide.ui.preference.EditorPreferencePage">
248+
</page>
243249
<page
244250
category="ts.eclipse.ide.ui.preference.EditorPreferencePage"
245251
class="ts.eclipse.ide.internal.ui.preferences.SaveActionsPreferencePage"

eclipse/ts.eclipse.ide.ui/src/ts/eclipse/ide/internal/ui/TypeScriptUIMessages.java

+4
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ public class TypeScriptUIMessages extends NLS {
137137
public static String TextMateConfigurationBlock_textmate_group_label;
138138
public static String TextMateConfigurationBlock_textmate_SyntaxColoring;
139139

140+
// CodeLens
141+
public static String CodeLensConfigurationBlock_CodeLens_group_label;
142+
public static String CodeLensConfigurationBlock_CodeLens_activate;
143+
140144
// Search
141145
public static String TypeScriptSearchQuery_label;
142146
public static String TypeScriptSearchQuery_result;

eclipse/ts.eclipse.ide.ui/src/ts/eclipse/ide/internal/ui/TypeScriptUIMessages.properties

+4
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ ValidationConfigurationBlock_installed_checkbox_label=Installed tslint
120120
TextMateConfigurationBlock_textmate_group_label=TextMate options
121121
TextMateConfigurationBlock_textmate_SyntaxColoring=Use TextMate for syntax coloring
122122

123+
# CodeLens
124+
CodeLensConfigurationBlock_CodeLens_group_label=CodeLens options
125+
CodeLensConfigurationBlock_CodeLens_activate=Activate CodeLens?
126+
123127
# Search
124128
TypeScriptSearchQuery_label=TypeScript Search
125129
TypeScriptSearchQuery_result= {0} matches - done in {1} ms.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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+
*/
11+
package ts.eclipse.ide.internal.ui.preferences;
12+
13+
import org.eclipse.core.resources.IProject;
14+
import org.eclipse.swt.widgets.Composite;
15+
import org.eclipse.swt.widgets.Control;
16+
import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer;
17+
18+
import ts.eclipse.ide.ui.preferences.PropertyAndPreferencePage;
19+
20+
/**
21+
* CodeLens preferences page
22+
*
23+
*/
24+
public class CodeLensPreferencePage extends PropertyAndPreferencePage {
25+
26+
public static final String PREF_ID = "ts.eclipse.ide.ui.preference.CodeLensPreferencePage"; //$NON-NLS-1$
27+
public static final String PROP_ID = "ts.eclipse.ide.ui.property.CodeLensPreferencePage"; //$NON-NLS-1$
28+
29+
private CodeLensConfigurationBlock configurationBlock;
30+
31+
public CodeLensPreferencePage() {
32+
}
33+
34+
@Override
35+
public void createControl(Composite parent) {
36+
IWorkbenchPreferenceContainer container = (IWorkbenchPreferenceContainer) getContainer();
37+
configurationBlock = new CodeLensConfigurationBlock(getNewStatusChangedListener(), getProject(), container);
38+
super.createControl(parent);
39+
}
40+
41+
@Override
42+
protected Control createPreferenceBodyContent(Composite composite) {
43+
return configurationBlock.createContents(composite);
44+
}
45+
46+
@Override
47+
protected boolean hasProjectSpecificOptions(IProject project) {
48+
return configurationBlock.hasProjectSpecificOptions(project);
49+
}
50+
51+
@Override
52+
protected String getPreferencePageID() {
53+
return PREF_ID;
54+
}
55+
56+
@Override
57+
protected String getPropertyPageID() {
58+
return PROP_ID;
59+
}
60+
61+
@Override
62+
protected void enablePreferenceContent(boolean enable) {
63+
if (configurationBlock != null) {
64+
configurationBlock.enablePreferenceContent(enable);
65+
}
66+
}
67+
68+
@Override
69+
protected void enableProjectSpecificSettings(boolean useProjectSpecificSettings) {
70+
super.enableProjectSpecificSettings(useProjectSpecificSettings);
71+
if (configurationBlock != null) {
72+
configurationBlock.useProjectSpecificSettings(useProjectSpecificSettings);
73+
}
74+
}
75+
76+
@Override
77+
public void dispose() {
78+
if (configurationBlock != null) {
79+
configurationBlock.dispose();
80+
}
81+
super.dispose();
82+
}
83+
84+
protected void performDefaults() {
85+
super.performDefaults();
86+
if (configurationBlock != null) {
87+
configurationBlock.performDefaults();
88+
}
89+
}
90+
91+
@Override
92+
public boolean performOk() {
93+
if (configurationBlock != null && !configurationBlock.performOk()) {
94+
return false;
95+
}
96+
return super.performOk();
97+
}
98+
99+
@Override
100+
public void performApply() {
101+
if (configurationBlock != null) {
102+
configurationBlock.performApply();
103+
}
104+
}
105+
106+
}

0 commit comments

Comments
 (0)