Skip to content

Commit 758fdd2

Browse files
committed
Add tslint wizard page. See
#147
1 parent c85b895 commit 758fdd2

File tree

11 files changed

+364
-46
lines changed

11 files changed

+364
-46
lines changed

eclipse/terminal/ts.eclipse.ide.terminal.interpreter/src/ts/eclipse/ide/terminal/interpreter/CommandTerminalService.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package ts.eclipse.ide.terminal.interpreter;
22

33
import java.util.HashMap;
4+
import java.util.List;
45
import java.util.Map;
56

67
import org.eclipse.core.runtime.Assert;
@@ -24,6 +25,30 @@ public static CommandTerminalService getInstance() {
2425
return INSTANCE;
2526
}
2627

28+
public void executeCommand(List<String> commands, String terminalId, final Map<String, Object> properties,
29+
final ITerminalService.Done done) {
30+
if (commands.isEmpty()) {
31+
return;
32+
}
33+
Assert.isNotNull(terminalId);
34+
35+
properties.put(ICommandTerminalServiceConstants.TERMINAL_ID, terminalId);
36+
properties.put(ICommandTerminalServiceConstants.COMMAND_ID, commands);
37+
38+
TerminalConnectorWrapper connector = getConnector(terminalId, properties);
39+
if (connector != null) {
40+
String workingDir = (String) properties.get(ITerminalsConnectorConstants.PROP_PROCESS_WORKING_DIR);
41+
if (connector.hasWorkingDirChanged(workingDir)) {
42+
connector.executeCommand("cd " + workingDir, properties);
43+
}
44+
for (String cmd : commands) {
45+
connector.executeCommand(cmd, properties);
46+
}
47+
} else {
48+
this.openConsole(properties, done);
49+
}
50+
}
51+
2752
public void executeCommand(String command, String terminalId, final Map<String, Object> properties,
2853
final ITerminalService.Done done) {
2954
Assert.isNotNull(terminalId);

eclipse/terminal/ts.eclipse.ide.terminal.interpreter/src/ts/eclipse/ide/terminal/interpreter/internal/CommandInterpreterProcessor.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
package ts.eclipse.ide.terminal.interpreter.internal;
1212

1313
import java.util.ArrayList;
14+
import java.util.Collection;
1415
import java.util.Collections;
1516
import java.util.List;
1617
import java.util.Map;
@@ -55,7 +56,14 @@ private static String getInitialWorkingDir(Map<String, Object> properties) {
5556
* @return the initial command when terminal is opened.
5657
*/
5758
private static String getInitialCommand(Map<String, Object> properties) {
58-
return (String) properties.get(ICommandTerminalServiceConstants.COMMAND_ID);
59+
Object command = properties.get(ICommandTerminalServiceConstants.COMMAND_ID);
60+
if (command instanceof Collection) {
61+
Collection<String> commands = (Collection<String>) command;
62+
for (String cmd : commands) {
63+
return cmd;
64+
}
65+
}
66+
return (String) command;
5967
}
6068

6169
/**
@@ -74,7 +82,7 @@ protected void submitCommand(LineCommand lineCommand) {
7482
}
7583

7684
@Override
77-
protected void executingCommand(String line, LineCommand lineCommand) {
85+
protected void executingCommand(String line, LineCommand lineCommand) {
7886
if (interpreter != null) {
7987
interpreter.onTrace(line);
8088
}

eclipse/terminal/ts.eclipse.ide.terminal.interpreter/src/ts/eclipse/ide/terminal/interpreter/internal/ITerminalConnectorWrapper.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ public interface ITerminalConnectorWrapper extends ITerminalConnector {
2121

2222
boolean hasWorkingDirChanged(String workingDir);
2323

24-
String getCommand();
25-
2624
String getWorkingDir();
2725

2826
}

eclipse/terminal/ts.eclipse.ide.terminal.interpreter/src/ts/eclipse/ide/terminal/interpreter/internal/TerminalConnectorWrapper.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package ts.eclipse.ide.terminal.interpreter.internal;
22

33
import java.io.OutputStream;
4+
import java.util.Collection;
45
import java.util.Map;
56

67
import org.eclipse.core.runtime.Platform;
@@ -45,15 +46,24 @@ public boolean isDirty() {
4546
public void connect(ITerminalControl control) {
4647
delegate.connect(control);
4748
if (control instanceof ITerminalViewControl) {
48-
terminal = (ITerminalViewControl) control;
49+
terminal = (ITerminalViewControl) control;
4950
if (isConfigureShellPrompt()) {
5051
// Initialize Shell Prompt to display working dir in the
5152
// prompt
5253
// This command is required to track working directory by
5354
// CommandTerminalTracker
5455
executeCommand("PS1='\\w\\$ '", null); // //$NON-NLS-1$
5556
}
56-
executeCommand(getCommand(), null);
57+
Object command = properties.get(ICommandTerminalServiceConstants.COMMAND_ID);
58+
if (command instanceof Collection) {
59+
Collection<String> commands = (Collection<String>) command;
60+
for (String cmd : commands) {
61+
executeCommand(cmd, null);
62+
}
63+
} else {
64+
executeCommand((String) command, null);
65+
}
66+
5767
}
5868
}
5969

@@ -149,10 +159,6 @@ public boolean hasWorkingDirChanged(String workingDir) {
149159
return !wd.equals(workingDir);
150160
}
151161

152-
public String getCommand() {
153-
return (String) properties.get(ICommandTerminalServiceConstants.COMMAND_ID);
154-
}
155-
156162
@Override
157163
public String getWorkingDir() {
158164
return (String) properties.get(ITerminalsConnectorConstants.PROP_PROCESS_WORKING_DIR);

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,10 @@ public class TypeScriptUIMessages extends NLS {
193193

194194
public static String TypeScriptRuntimeAndNodejsWizardPage_title;
195195
public static String TypeScriptRuntimeAndNodejsWizardPage_description;
196-
public static String TypeScriptRuntimeAndNodejsWizardPage_nodejs_group_label;
197196
public static String TypeScriptRuntimeAndNodejsWizardPage_typescript_group_label;
198197
public static String TypeScriptRuntimeAndNodejsWizardPage_useEmbeddedTsRuntime_label;
199198
public static String TypeScriptRuntimeAndNodejsWizardPage_useInstallTsRuntime_label;
199+
public static String TypeScriptRuntimeAndNodejsWizardPage_nodejs_group_label;
200200
public static String TypeScriptRuntimeAndNodejsWizardPage_useEmbeddedNodeJs_label;
201201
public static String TypeScriptRuntimeAndNodejsWizardPage_useInstalledNodeJs_label;
202202

@@ -211,6 +211,14 @@ public class TypeScriptUIMessages extends NLS {
211211
public static String NPMInstallWidget_SearchingVersions_status;
212212
public static String NPMInstallWidget_InvalidVersion_status;
213213

214+
public static String TSLintWizardPage_enableTslint_text;
215+
public static String TSLintWizardPage_title;
216+
public static String TSLintWizardPage_description;
217+
public static String TSLintWizardPage_tslint_group_label;
218+
public static String TSLintWizardPage_useEmbeddedTslintRuntime_label;
219+
public static String TSLintWizardPage_useInstallTslintRuntime_label;
220+
221+
214222
public static ResourceBundle getResourceBundle() {
215223
try {
216224
if (fResourceBundle == null)

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,4 +184,11 @@ NPMModuleVersionsSelectionDialog_searchJob_taskName=Searching
184184
NPMInstallWidget_versionText_message=Fill version or use Ctrl+Space to open content assist.
185185
NPMInstallWidget_ValidateVersionJob_name=Validate NPM module version job.
186186
NPMInstallWidget_SearchingVersions_status=Searching available versions for ''{0}'' module with 'npm show'...
187-
NPMInstallWidget_InvalidVersion_status=Invalid version ''{0}'' for ''{1}'' module.
187+
NPMInstallWidget_InvalidVersion_status=Invalid version ''{0}'' for ''{1}'' module.
188+
189+
TSLintWizardPage_enableTslint_text=Enable tslint?
190+
TSLintWizardPage_title=Configure tslint
191+
TSLintWizardPage_description=Configure tslint
192+
TSLintWizardPage_tslint_group_label=tslint Runtime
193+
TSLintWizardPage_useEmbeddedTslintRuntime_label=Use embedded
194+
TSLintWizardPage_useInstallTslintRuntime_label=Install

eclipse/ts.eclipse.ide.ui/src/ts/eclipse/ide/internal/ui/wizards/NewTypeScriptProjectWizard.java

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414

1515
import java.lang.reflect.InvocationTargetException;
1616
import java.nio.charset.StandardCharsets;
17+
import java.util.ArrayList;
1718
import java.util.HashMap;
19+
import java.util.List;
1820
import java.util.Map;
1921

2022
import org.eclipse.core.commands.ExecutionException;
@@ -86,6 +88,7 @@ public class NewTypeScriptProjectWizard extends AbstractNewProjectWizard {
8688
private static final String WIZARD_NAME = "NewTypeScriptProjectWizard";
8789
private TSConfigWizardPage tsconfigPage;
8890
private TypeScriptRuntimeAndNodejsWizardPage tsRuntimeAndNodeJsPage;
91+
private TSLintWizardPage tslintPage;
8992

9093
public NewTypeScriptProjectWizard() {
9194
super(WIZARD_NAME, TypeScriptUIMessages.NewTypeScriptProjectWizard_newProjectTitle,
@@ -113,6 +116,8 @@ public void addPages() {
113116
addPage(tsconfigPage);
114117
tsRuntimeAndNodeJsPage = new TypeScriptRuntimeAndNodejsWizardPage();
115118
addPage(tsRuntimeAndNodeJsPage);
119+
tslintPage = new TSLintWizardPage();
120+
addPage(tslintPage);
116121
}
117122

118123
@Override
@@ -159,10 +164,21 @@ public void run(final IProgressMonitor monitor) throws InvocationTargetException
159164
throw new InvocationTargetException(e);
160165
}
161166

162-
// Install TypeScript if needed
167+
// Install TypeScript/tslint if needed
168+
List<String> commands = new ArrayList<>();
169+
boolean customTypeScript = false;
163170
String cmd = tsRuntimeAndNodeJsPage.getNpmInstallCommand();
164171
if (!StringUtils.isEmpty(cmd)) {
165-
172+
commands.add(cmd);
173+
customTypeScript = true;
174+
}
175+
boolean customTslint = false;
176+
cmd = tslintPage.getNpmInstallCommand();
177+
if (!StringUtils.isEmpty(cmd)) {
178+
commands.add(cmd);
179+
customTslint = true;
180+
}
181+
if (!commands.isEmpty()) {
166182
// Prepare terminal properties
167183
String terminalId = "TypeScript Projects";
168184
Map<String, Object> properties = new HashMap<String, Object>();
@@ -175,16 +191,21 @@ public void run(final IProgressMonitor monitor) throws InvocationTargetException
175191
properties.put(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID,
176192
"org.eclipse.tm.terminal.connector.local.LocalConnector");
177193

178-
CommandTerminalService.getInstance().executeCommand(cmd, terminalId, properties, null);
179-
180-
IEclipsePreferences node = new ProjectScope(newProjectHandle).getNode(TypeScriptCorePlugin.PLUGIN_ID);
181-
node.putBoolean(TypeScriptCorePreferenceConstants.USE_EMBEDDED_TYPESCRIPT, false);
182-
node.put(TypeScriptCorePreferenceConstants.INSTALLED_TYPESCRIPT_PATH, "${project_loc:node_modules/typescript}");
183-
try {
184-
node.flush();
185-
} catch (BackingStoreException e) {
186-
// TODO Auto-generated catch block
187-
e.printStackTrace();
194+
CommandTerminalService.getInstance().executeCommand(commands, terminalId, properties, null);
195+
196+
if (customTypeScript || customTslint) {
197+
IEclipsePreferences node = new ProjectScope(newProjectHandle)
198+
.getNode(TypeScriptCorePlugin.PLUGIN_ID);
199+
if (customTypeScript) {
200+
node.putBoolean(TypeScriptCorePreferenceConstants.USE_EMBEDDED_TYPESCRIPT, false);
201+
node.put(TypeScriptCorePreferenceConstants.INSTALLED_TYPESCRIPT_PATH,
202+
"${project_loc:node_modules/typescript}");
203+
}
204+
try {
205+
node.flush();
206+
} catch (BackingStoreException e) {
207+
e.printStackTrace();
208+
}
188209
}
189210
}
190211

0 commit comments

Comments
 (0)