Skip to content

Commit 075088a

Browse files
author
angelozerr
committed
Implement del + rd command interpreter to refresh the Project Explorer.
1 parent 0a26fc4 commit 075088a

File tree

7 files changed

+208
-1
lines changed

7 files changed

+208
-1
lines changed

eclipse/terminal/ts.eclipse.ide.terminal.interpreter/plugin.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ providerName=Angelo ZERR
1414
# Extension point
1515
commandInterpreterFactories.name=Command Interpreter factories
1616
interpreter.cd.name=Interpret 'cd', 'chdir' commands to select the well container of the Project Explorer.
17+
interpreter.del.name=Interpret 'del' commands to refresh the Project Explorer.
18+
interpreter.rd.name=Interpret 'rd' commands to refresh the Project Explorer.
1719

1820
# Local Terminal - Interpreter
1921
terminal.interpreter.name=Local Terminal (Interpreter)

eclipse/terminal/ts.eclipse.ide.terminal.interpreter/plugin.xml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,29 @@
3131
<factory
3232
id="ts.eclipse.ide.terminal.interpreter.commands.CdCommandInterpreterFactory"
3333
name="%interpreter.cd.name"
34-
commands="#"
34+
commands="cd"
3535
class="ts.eclipse.ide.terminal.interpreter.internal.commands.CdCommandInterpreterFactory">
3636
</factory>
3737
</extension>
3838
-->
39+
40+
<extension
41+
point="ts.eclipse.ide.terminal.interpreter.commandInterpreterFactories">
42+
<factory
43+
id="ts.eclipse.ide.terminal.interpreter.commands.DelCommandInterpreterFactory"
44+
name="%interpreter.del.name"
45+
commands="del"
46+
class="ts.eclipse.ide.terminal.interpreter.internal.commands.DelCommandInterpreterFactory">
47+
</factory>
48+
</extension>
3949

50+
<extension
51+
point="ts.eclipse.ide.terminal.interpreter.commandInterpreterFactories">
52+
<factory
53+
id="ts.eclipse.ide.terminal.interpreter.commands.RdCommandInterpreterFactory"
54+
name="%interpreter.rd.name"
55+
commands="rd,rmdir"
56+
class="ts.eclipse.ide.terminal.interpreter.internal.commands.RdCommandInterpreterFactory">
57+
</factory>
58+
</extension>
4059
</plugin>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package ts.eclipse.ide.terminal.interpreter.internal.commands;
2+
3+
import java.util.List;
4+
5+
import org.eclipse.core.resources.IContainer;
6+
import org.eclipse.core.resources.ResourcesPlugin;
7+
import org.eclipse.core.runtime.Path;
8+
import org.eclipse.ui.progress.UIJob;
9+
10+
import ts.eclipse.ide.terminal.interpreter.AbstractCommandInterpreter;
11+
import ts.eclipse.ide.terminal.interpreter.internal.jobs.RefreshContainerJob;
12+
13+
public class DelCommandInterpreter extends AbstractCommandInterpreter {
14+
15+
public DelCommandInterpreter(List<String> parameters, String workingDir) {
16+
super(parameters, workingDir);
17+
}
18+
19+
@Override
20+
public void execute(List<String> parameters, String workingDir) {
21+
String path = parameters.get(0);
22+
final IContainer[] c = ResourcesPlugin.getWorkspace().getRoot()
23+
.findContainersForLocation(new Path(workingDir + "/" + path));
24+
if (c != null && c.length > 0) {
25+
for (int i = 0; i < c.length; i++) {
26+
UIJob job = new RefreshContainerJob(c[i]);
27+
job.schedule();
28+
}
29+
}
30+
}
31+
32+
@Override
33+
public void onTrace(String line) {
34+
// Do nothing
35+
}
36+
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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.terminal.interpreter.internal.commands;
12+
13+
import java.util.List;
14+
15+
import ts.eclipse.ide.terminal.interpreter.ICommandInterpreter;
16+
import ts.eclipse.ide.terminal.interpreter.ICommandInterpreterFactory;
17+
18+
/**
19+
* After a "del" command, this interpreter refresh the Project Explorer.
20+
*
21+
*/
22+
public class DelCommandInterpreterFactory implements ICommandInterpreterFactory {
23+
24+
@Override
25+
public ICommandInterpreter create(List<String> parameters, String workingDir) {
26+
if (parameters.size() < 1) {
27+
return null;
28+
}
29+
return new DelCommandInterpreter(parameters, workingDir);
30+
}
31+
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package ts.eclipse.ide.terminal.interpreter.internal.commands;
2+
3+
import java.util.List;
4+
5+
import org.eclipse.core.resources.IContainer;
6+
import org.eclipse.core.resources.ResourcesPlugin;
7+
import org.eclipse.core.runtime.Path;
8+
import org.eclipse.ui.progress.UIJob;
9+
10+
import ts.eclipse.ide.terminal.interpreter.AbstractCommandInterpreter;
11+
import ts.eclipse.ide.terminal.interpreter.internal.jobs.RefreshContainerJob;
12+
13+
public class RdCommandInterpreter extends AbstractCommandInterpreter {
14+
15+
public RdCommandInterpreter(List<String> parameters, String workingDir) {
16+
super(parameters, workingDir);
17+
}
18+
19+
@Override
20+
public void execute(List<String> parameters, String workingDir) {
21+
String path = getPath(parameters);
22+
final IContainer[] c = ResourcesPlugin.getWorkspace().getRoot()
23+
.findContainersForLocation(new Path(workingDir + "/" + path));
24+
if (c != null && c.length > 0) {
25+
for (int i = 0; i < c.length; i++) {
26+
UIJob job = new RefreshContainerJob(c[i].getParent());
27+
job.schedule();
28+
}
29+
}
30+
}
31+
32+
private String getPath(List<String> parameters) {
33+
// RD [/S] [/Q] [drive:]path
34+
// path is the last token
35+
return parameters.get(parameters.size() - 1);
36+
}
37+
38+
@Override
39+
public void onTrace(String line) {
40+
// Do nothing
41+
}
42+
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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.terminal.interpreter.internal.commands;
12+
13+
import java.util.List;
14+
15+
import ts.eclipse.ide.terminal.interpreter.ICommandInterpreter;
16+
import ts.eclipse.ide.terminal.interpreter.ICommandInterpreterFactory;
17+
18+
/**
19+
* After a "rd" command, this interpreter refresh the Project Explorer.
20+
*
21+
*/
22+
public class RdCommandInterpreterFactory implements ICommandInterpreterFactory {
23+
24+
@Override
25+
public ICommandInterpreter create(List<String> parameters, String workingDir) {
26+
if (parameters.size() < 1) {
27+
return null;
28+
}
29+
return new RdCommandInterpreter(parameters, workingDir);
30+
}
31+
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package ts.eclipse.ide.terminal.interpreter.internal.jobs;
2+
3+
import org.eclipse.core.resources.IContainer;
4+
import org.eclipse.core.resources.IResource;
5+
import org.eclipse.core.runtime.CoreException;
6+
import org.eclipse.core.runtime.IProgressMonitor;
7+
import org.eclipse.core.runtime.IStatus;
8+
import org.eclipse.core.runtime.Status;
9+
import org.eclipse.jface.viewers.StructuredSelection;
10+
import org.eclipse.ui.IPageLayout;
11+
import org.eclipse.ui.IViewPart;
12+
import org.eclipse.ui.IWorkbenchPage;
13+
import org.eclipse.ui.PlatformUI;
14+
import org.eclipse.ui.part.ISetSelectionTarget;
15+
import org.eclipse.ui.progress.UIJob;
16+
17+
import ts.eclipse.ide.terminal.interpreter.internal.TerminalInterpreterPlugin;
18+
19+
public class RefreshContainerJob extends UIJob {
20+
21+
private final IContainer container;
22+
23+
public RefreshContainerJob(IContainer container) {
24+
super("Refresh container job");
25+
this.container = container;
26+
}
27+
28+
@Override
29+
public IStatus runInUIThread(IProgressMonitor monitor) {
30+
try {
31+
container.refreshLocal(IResource.DEPTH_INFINITE, monitor);
32+
} catch (CoreException e) {
33+
return new Status(IStatus.ERROR, TerminalInterpreterPlugin.PLUGIN_ID, "Error while refreshing container",
34+
e);
35+
}
36+
37+
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
38+
final IViewPart view = page.findView(IPageLayout.ID_PROJECT_EXPLORER);
39+
((ISetSelectionTarget) view).selectReveal(new StructuredSelection(container));
40+
return Status.OK_STATUS;
41+
}
42+
}

0 commit comments

Comments
 (0)