Skip to content

Commit

Permalink
#72 [v2.0] add *_path eclipse variables
Browse files Browse the repository at this point in the history
added new variables:
${easyshell:resource_path}
${easyshell:container_name}
${easyshell:container_path}
${easyshell:project_loc}
${easyshell:project_path}

renamed ${easyshell:drive} to ${easyshell:windows_drive}

Signed-off-by: Andre Bossert <anb0s@anbos.de>
  • Loading branch information
anb0s committed Jul 31, 2016
1 parent 7e9d598 commit a7365a8
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,36 @@ public String resolveValue(IDynamicVariable variable, String argument)
}

private String handleOwnVariable(String argument) {
if (argument.equals("drive")) {
return resource.getWindowsDrive(); // {0} == ${easyshell:drive}
if (argument.equals("windows_drive")) {
return resource.getWindowsDrive(); // ${easyshell:windows_drive} == {0}
} else if (argument.equals("line_separator")) {
return resource.getLineSeparator(); // {5} == ${easyshell:line_separator}
return resource.getLineSeparator(); // ${easyshell:line_separator} == {5}
} else if (argument.equals("qualified_name")) {
return resource.getFullQualifiedName(); // ${easyshell:qualified_name}
}
// here we have eclipse variables embedded in easyshell variable as parameter
// here we have a eclipse variable embedded in easyshell variable as parameter
return handleEclipseVariable(argument, null);
}

private String handleEclipseVariable(String variable, String argument) {
if (variable.equals("container_loc")) {
return autoQuotes(resource.getParentPath()); // {1} == ${easyshell:container_loc}
return autoQuotes(resource.getContainerLocation()); // ${easyshell:container_loc} == {1}
} else if (variable.equals("container_name")) {
return autoQuotes(resource.getContainerName()); // ${easyshell:container_name}
} else if (variable.equals("container_path")) {
return autoQuotes(resource.getContainerPath()); // ${easyshell:container_path}
} else if (variable.equals("resource_loc")) {
return autoQuotes(resource.getFullPath()); // {2} == ${easyshell:resource_loc}
return autoQuotes(resource.getResourceLocation()); // ${easyshell:resource_loc} == {2}
} else if (variable.equals("resource_name")) {
return autoQuotes(resource.getFileName()); // {3} == ${easyshell:resource_name}
return autoQuotes(resource.getResourceName()); // ${easyshell:resource_name} == {3}
} else if (variable.equals("resource_path")) {
return autoQuotes(resource.getResourcePath()); // ${easyshell:resource_path}
} else if (variable.equals("project_loc")) {
return autoQuotes(resource.getProjectLocation()); // ${easyshell:project_loc_loc}
} else if (variable.equals("project_name")) {
return resource.getProjectName(); // {4} == ${easyshell:project_name}
} else if (variable.equals("qualified_name")) {
return resource.getFullQualifiedName(); // {6} == ${easyshell:qualified_name} == qualified name
return resource.getProjectName(); // ${easyshell:project_name} == {4}
} else if (variable.equals("project_path")) {
return autoQuotes(resource.getProjectPath()); // ${easyshell:project_path}
}
return null;
}
Expand Down
142 changes: 96 additions & 46 deletions plugin/src/de/anbos/eclipse/easyshell/plugin/Resource.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,22 @@
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaCore;
import org.osgi.framework.Bundle;

public class Resource {

// internal
private File file = null;
private IResource iRes = null;
private IResource resource = null;

// resolved
private String windowsDrive = null;
private String fullPath = null;
private String parentPath = null;
private String fileName = null;
private String projectName = null;
private String resourceLocation = null;
private String containerLocation = null;
private String resourceName = null;
private String projectName = Activator.getResourceString("easyshell.plugin.name");
static private String lineSeparator = null;

//Activator.logDebug("full_path : >" + fullPath + "<");
Expand All @@ -41,85 +42,130 @@ public class Resource {

public Resource(Resource myRes) {
file = myRes.getFile();
projectName = myRes.getProjectName();
}

public Resource(File file, IResource iRes, String projectName) {
public Resource(File file, IResource resource) {
this.file = file;
this.iRes = iRes;
this.projectName = projectName;
this.resource = resource;
}

public Resource(File file, String projectName) {
this(file, null, projectName);
public Resource(File file) {
this(file, null);
}

public Resource(IResource iRes) {
this(iRes.getLocation().toFile(), iRes, iRes.getProject().getName());
public Resource(IResource resource) {
this(resource.getLocation().toFile(), resource);
}

public File getFile() {
return file;
}

public IResource getIResource() {
return iRes;
public IResource getResource() {
return resource;
}

public String getWindowsDrive() {
if (windowsDrive == null) {
getFullPath();
getResourceLocation();
// Try to extract drive on Win32
if (fullPath.indexOf(":") != -1) {
windowsDrive = fullPath.substring(0, fullPath.indexOf(":"));
if (resourceLocation.indexOf(":") != -1) {
windowsDrive = resourceLocation.substring(0, resourceLocation.indexOf(":"));
} else {
windowsDrive = "";
}
}
return windowsDrive;
}

public String getFullPath() {
if (fullPath == null) {
fullPath = file.toString();
public String getContainerLocation() {
if (containerLocation == null) {
if (file.isDirectory()) {
containerLocation = file.getPath();
} else {
containerLocation = file.getParent();
}
}
return fullPath;
return containerLocation;
}

public String getParentPath() {
if (parentPath == null) {
if (file.isDirectory()) {
parentPath = getFile().getPath();
public String getContainerName() {
if (resource != null) {
if (resource.getType() == IResource.FILE) {
return resource.getParent().getName();
} else {
return resource.getName();
}
} else {
if (file.isFile()) {
return file.getParentFile().getName();
} else {
parentPath = file.getParent();
fileName = file.getName();
return file.getName();
}
}
}

public String getContainerPath() {
if (resource != null) {
if (resource.getType() == IResource.FILE) {
return resource.getParent().getFullPath().toString();
} else {
return resource.getFullPath().toString();
}
}
return parentPath;
return "";
}

public String getParentName() {
if (iRes != null) {
return iRes.getParent().getName();
public String getResourceLocation() {
if (resourceLocation == null) {
resourceLocation = file.getPath();
}
return file.getParentFile().getName();
return resourceLocation;
}

public String getFileName() {
if (fileName == null) {
if (file.isDirectory()) {
fileName = "";
public String getResourceName() {
if (resourceName == null) {
if (resource != null) {
resourceName = resource.getName();
} else {
fileName = file.getName();
}
/*if (file.isDirectory()) {
resourceName = "";
} else {*/
resourceName = file.getName();
//}
}
}
return resourceName;
}

public String getResourcePath() {
if (resource != null) {
return resource.getFullPath().toString();
}
return "";
}

public String getProjectLocation() {
if (resource != null) {
return resource.getProject().getLocation().toFile().toString();
}
return fileName;
return "";
}

public String getProjectName() {
if (resource != null) {
return resource.getProject().getName();
}
return projectName;
}

public String getProjectPath() {
if (resource != null) {
return resource.getProject().getFullPath().toString();
}
return "";
}

public String getLineSeparator() {
if (lineSeparator == null) {
lineSeparator = System.getProperty("line.separator");
Expand All @@ -128,14 +174,17 @@ public String getLineSeparator() {
}

public String getFullQualifiedName() {
if (iRes != null) {
if (resource != null) {
Bundle bundle = Platform.getBundle("org.eclipse.jdt.core");
if (bundle != null) {
IJavaElement element = JavaCore.create(iRes);
IJavaElement element = JavaCore.create(resource);
if (element instanceof IPackageFragment) {
return ((IPackageFragment)element).getElementName();
} else if (element instanceof ICompilationUnit) {
return ((ICompilationUnit)element).findPrimaryType().getFullyQualifiedName();
IType type = ((ICompilationUnit)element).findPrimaryType();
if (type != null) {
return type.getFullyQualifiedName();
}
}
}
}
Expand All @@ -144,8 +193,8 @@ public String getFullQualifiedName() {

public String getFullQualifiedPathName() {
String fqcn = "";
if (iRes != null) {
return iRes.getFullPath().toString();
if (resource != null) {
return resource.getFullPath().toString();
/*
String[] segments = iRes.getProjectRelativePath().segments();
for (int i=0;i<segments.length-1;i++) {
Expand All @@ -159,6 +208,7 @@ public String getFullQualifiedPathName() {
}

public boolean resolve() {
return getFullPath() != null ? true : false;
return getResourceLocation() != null ? true : false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static public ISelection getResourceSelection(IWorkbenchPart part) {
ISelection selection = null;
if (part != null) {
if (part instanceof IEditorPart) {
Resource file = getResource((IEditorPart)part, null);
Resource file = getResource((IEditorPart)part);
if (file != null) {
selection = new StructuredSelection(file);
}
Expand All @@ -49,7 +49,7 @@ static public ISelection getResourceSelection(IWorkbenchPart part) {
return selection;
}

static public Resource getResource(Object myObj, String projectName) {
static public Resource getResource(Object myObj) {
Object object = null;
if (myObj instanceof IEditorPart) {
IEditorPart editorPart = (IEditorPart)myObj;
Expand Down Expand Up @@ -77,7 +77,7 @@ static public Resource getResource(Object myObj, String projectName) {
return new Resource(((IFile) object));
}
if (object instanceof File) {
return new Resource((File) object, projectName);
return new Resource((File) object);
}
if (object instanceof IAdaptable) {
IAdaptable adaptable = (IAdaptable) object;
Expand Down Expand Up @@ -106,7 +106,7 @@ static public Resource getResource(Object myObj, String projectName) {
*/
File file = (File) adaptable.getAdapter(File.class);
if (file != null) {
return new Resource(file, projectName);
return new Resource(file);
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,12 @@ public boolean isEnabled()
boolean enabled = false;
if (currentSelection != null)
{
String projectName = Activator.getResourceString("easyshell.plugin.name");
Object[] selectedObjects = currentSelection.toArray();
if (selectedObjects.length >= 1)
{
resource = new Resource[selectedObjects.length];
for (int i=0;i<selectedObjects.length;i++) {
resource[i] = ResourceUtils.getResource(selectedObjects[i], projectName);
resource[i] = ResourceUtils.getResource(selectedObjects[i]);
if (resource[i] != null) {
enabled=true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ private void addAllOSCommands() {
// Clipboard - Qualified name
list.add(new CommandData("88989d78-cf17-4750-91fc-6260055743ae", PresetType.presetPlugin, Utils.getOS(), "Qualified Name", ResourceType.resourceTypeFileOrDirectory, Category.categoryClipboard, CommandType.commandTypeClipboard,
"${easyshell:qualified_name}${easyshell:line_separator}"));
// Clipboard - Variables Test
list.add(new CommandData("e6de32cc-342a-46a0-a766-ac74e7e4000d", PresetType.presetPlugin, Utils.getOS(), "Variables Test", ResourceType.resourceTypeFileOrDirectory, Category.categoryClipboard, CommandType.commandTypeClipboard,
"easyshell:windows_drive=${easyshell:windows_drive}${easyshell:line_separator}easyshell:resource_loc=${easyshell:resource_loc}${easyshell:line_separator}easyshell:resource_name=${easyshell:resource_name}${easyshell:line_separator}easyshell:resource_path=${easyshell:resource_path}${easyshell:line_separator}easyshell:container_loc=${easyshell:container_loc}${easyshell:line_separator}easyshell:container_name=${easyshell:container_name}${easyshell:line_separator}easyshell:container_path=${easyshell:container_path}${easyshell:line_separator}easyshell:project_loc=${easyshell:project_loc}${easyshell:line_separator}easyshell:project_name=${easyshell:project_name}${easyshell:line_separator}easyshell:project_path=${easyshell:project_path}${easyshell:line_separator}"));
}

public List<CommandData> getCommands() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,17 @@ public Control createDialogArea(Composite parent) {
pageGroup2.setLayoutData(data2);
pageGroup2.setFont(parent.getFont());

createVariableLabel(pageGroup2, "${easyshell:drive}", "is the drive letter on Win32");
createVariableLabel(pageGroup2, "${easyshell:container_loc}", "is the parent path*");
createVariableLabel(pageGroup2, "${easyshell:resource_loc}", "is the full path*");
createVariableLabel(pageGroup2, "${easyshell:resource_name}", "is the file name*");
createVariableLabel(pageGroup2, "${easyshell:project_name}", "is the project name");
createVariableLabel(pageGroup2, "${easyshell:line_separator}", "is the line separator");
createVariableLabel(pageGroup2, "${easyshell:resource_loc}", "absolute path of file or directory");
createVariableLabel(pageGroup2, "${easyshell:resource_name}", "name of file or directory");
createVariableLabel(pageGroup2, "${easyshell:resource_path}", "relative path to workspace of file or directory");
createVariableLabel(pageGroup2, "${easyshell:container_loc}", "absolute path of file directory or directory itself");
createVariableLabel(pageGroup2, "${easyshell:container_name}", "name of file directory or directory itself");
createVariableLabel(pageGroup2, "${easyshell:container_path}", "relative path to workspace of file directory or directory itself");
createVariableLabel(pageGroup2, "${easyshell:project_loc}", "absolute path of project");
createVariableLabel(pageGroup2, "${easyshell:project_name}", "name of project");
createVariableLabel(pageGroup2, "${easyshell:project_path}", "relative path to workspace of project");
createVariableLabel(pageGroup2, "${easyshell:line_separator}", "iline separator");
createVariableLabel(pageGroup2, "${easyshell:windows_drive}", "drive letter of file or directory on Windows");

// TODO: to be enabled again, see https://github.com/anb0s/EasyShell/issues/61
setHelpAvailable(false);
Expand Down
2 changes: 1 addition & 1 deletion uuids.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ f6bcdd71-4687-46d8-bf34-2780bafd762a
All
33043fe3-1a5f-46d7-b94e-9a02ef204e7d
88989d78-cf17-4750-91fc-6260055743ae
e6de32cc-342a-46a0-a766-ac74e7e4000d

Do not use
cd32fa5a-34d7-4551-8bd0-3aae0dc444d0 // was MAC OS X clipboard before

Free
e6de32cc-342a-46a0-a766-ac74e7e4000d
d2726c3f-6da3-46b5-8029-1c63d0ff6bd2
03e6678b-f67f-42ed-b65f-6b6f06ec0e8f
c57a5d9f-491a-4b21-8a8b-9941b01cc049
Expand Down

0 comments on commit a7365a8

Please sign in to comment.