Commit f88dd96e authored by Andrey Filippov's avatar Andrey Filippov

Implemented multiple-choice launch actions

parent 216443b3
...@@ -145,5 +145,6 @@ public class VDT { ...@@ -145,5 +145,6 @@ public class VDT {
public static final String GENERATOR_ID_CURRENT_FILE = "CurrentFile"; public static final String GENERATOR_ID_CURRENT_FILE = "CurrentFile";
public static final String GENERATOR_ID_SELECTED_FILE = "SelectedFile"; public static final String GENERATOR_ID_SELECTED_FILE = "SelectedFile";
public static final String GENERATOR_ID_CURRENT_BASE = "CurrentFileBase"; public static final String GENERATOR_ID_CURRENT_BASE = "CurrentFileBase";
public static final String GENERATOR_ID_CHOSEN_ACTION = "ChosenActionIndex";
public static final String GENERATOR_ID_OS_NAME = "OS"; public static final String GENERATOR_ID_OS_NAME = "OS";
} // class VDT } // class VDT
...@@ -100,8 +100,8 @@ public class VerilogUtils { ...@@ -100,8 +100,8 @@ public class VerilogUtils {
* Returns the top module(s) for given verilog file. * Returns the top module(s) for given verilog file.
*/ */
public static String[] getTopModuleNames(IFile file) { public static String[] getTopModuleNames(IFile file) { //L/x353/data/vdt/workspace_11-runtime/x353/x353_1.tf
OutlineElement[] outlineElements= getTopModulesVeditor(file); OutlineElement[] outlineElements= getTopModulesVeditor(file); // empty inside
if (outlineElements==null) return null; if (outlineElements==null) return null;
String [] list = new String[outlineElements.length]; String [] list = new String[outlineElements.length];
for (int i=0;i<list.length;i++) { for (int i=0;i<list.length;i++) {
......
...@@ -73,7 +73,13 @@ public class ParamBasedOption extends Option { ...@@ -73,7 +73,13 @@ public class ParamBasedOption extends Option {
} }
public String doLoadDefault() { public String doLoadDefault() {
String value = param.getDefaultValue().get(0); String value = param.getDefaultValue(true).get(0); // Andrey: ignore faults in TopModuleName generator
doClear();
return value;
}
public String doLoadDefault(boolean menuMode) {
String value = param.getDefaultValue(menuMode).get(0);
doClear(); doClear();
return value; return value;
} }
......
...@@ -990,28 +990,29 @@ public class XMLConfig extends Config { ...@@ -990,28 +990,29 @@ public class XMLConfig extends Config {
for(Iterator<Node> n = runForNodes.iterator(); n.hasNext();) { for(Iterator<Node> n = runForNodes.iterator(); n.hasNext();) {
Node node = (Node)n.next(); Node node = (Node)n.next();
boolean checkExtension=false; // for empty resource field - do not check file or extensions
boolean checkExistence=false;
String label = getAttributeValue(node, CONTEXT_TOOL_ACTION_LABEL); String label = getAttributeValue(node, CONTEXT_TOOL_ACTION_LABEL);
if (label == null) if (label == null)
label=CONTEXT_TOOL_DFLT_ACTION_LABEL; label=CONTEXT_TOOL_DFLT_ACTION_LABEL;
String resource = getAttributeValue(node, CONTEXT_TOOL_ACTION_RESOURCE); String resource = getAttributeValue(node, CONTEXT_TOOL_ACTION_RESOURCE);
if (resource == null) if ((resource == null) || (resource.length()==0)) {
resource= CONTEXT_TOOL_DFLT_ACTION_RESOURCE; // resource= CONTEXT_TOOL_DFLT_ACTION_RESOURCE;
resource = "";
String checkExtensionAttr=getAttributeValue(node, CONTEXT_TOOL_ACTION_CHECK_EXTENSION); } else {
if (checkExtensionAttr==null){ String checkExtensionAttr=getAttributeValue(node, CONTEXT_TOOL_ACTION_CHECK_EXTENSION);
checkExtensionAttr=CONTEXT_TOOL_DFLT_ACTION_CHECK_EXTENSION; if (checkExtensionAttr==null){
} checkExtensionAttr=CONTEXT_TOOL_DFLT_ACTION_CHECK_EXTENSION;
checkBoolAttr(checkExtensionAttr, CONTEXT_TOOL_ACTION_CHECK_EXTENSION); }
boolean checkExtension=getBoolAttrValue(checkExtensionAttr); checkBoolAttr(checkExtensionAttr, CONTEXT_TOOL_ACTION_CHECK_EXTENSION);
checkExtension=getBoolAttrValue(checkExtensionAttr);
String checkExistenceAttr=getAttributeValue(node, CONTEXT_TOOL_ACTION_CHECK_EXISTENCE);
String checkExistenceAttr=getAttributeValue(node, CONTEXT_TOOL_ACTION_CHECK_EXISTENCE); if (checkExistenceAttr==null){
if (checkExistenceAttr==null){ checkExistenceAttr=CONTEXT_TOOL_DFLT_ACTION_CHECK_EXISTENCE;
checkExistenceAttr=CONTEXT_TOOL_DFLT_ACTION_CHECK_EXISTENCE; }
checkBoolAttr(checkExistenceAttr, CONTEXT_TOOL_ACTION_CHECK_EXISTENCE);
checkExistence=getBoolAttrValue(checkExistenceAttr);
} }
checkBoolAttr(checkExistenceAttr, CONTEXT_TOOL_ACTION_CHECK_EXISTENCE);
boolean checkExistence=getBoolAttrValue(checkExistenceAttr);
runForList.add(new RunFor(label, resource, checkExtension, checkExistence)); runForList.add(new RunFor(label, resource, checkExtension, checkExistence));
} }
} }
......
...@@ -31,7 +31,7 @@ public abstract class AbstractGenerator { ...@@ -31,7 +31,7 @@ public abstract class AbstractGenerator {
protected final String prefix, suffix; protected final String prefix, suffix;
protected String separator; protected String separator;
private final boolean forcedMultiline; private final boolean forcedMultiline;
private boolean menuMode=false; // managing menu items, not running tool private boolean menuMode=false; // managing menu items, not running tool. Ignore Generator errors
public AbstractGenerator() { public AbstractGenerator() {
this(false); this(false);
...@@ -119,8 +119,11 @@ public abstract class AbstractGenerator { ...@@ -119,8 +119,11 @@ public abstract class AbstractGenerator {
return output; return output;
} }
protected void fault(String message) { protected String fault(String message) {
if (menuMode)
return "";
MessageUI.error("Generator '" + getName() + "' fault: " + message); MessageUI.error("Generator '" + getName() + "' fault: " + message);
return null;
} }
protected abstract String[] getStringValues(); protected abstract String[] getStringValues();
......
...@@ -17,8 +17,9 @@ ...@@ -17,8 +17,9 @@
*******************************************************************************/ *******************************************************************************/
package com.elphel.vdt.core.tools.generators; package com.elphel.vdt.core.tools.generators;
import org.eclipse.core.resources.IFile; //import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource; //import org.eclipse.core.resources.IResource;
//import org.eclipse.ui.IPageLayout;
import com.elphel.vdt.VDT; import com.elphel.vdt.VDT;
import com.elphel.vdt.ui.variables.SelectedResourceManager; import com.elphel.vdt.ui.variables.SelectedResourceManager;
...@@ -31,13 +32,17 @@ public class CurrentFileBaseGenerator extends AbstractGenerator { ...@@ -31,13 +32,17 @@ public class CurrentFileBaseGenerator extends AbstractGenerator {
} }
protected String[] getStringValues() { protected String[] getStringValues() {
IResource resource = SelectedResourceManager.getDefault().getSelectedResource(); // IResource resource = SelectedResourceManager.getDefault().getSelectedResource();
String fullName=SelectedResourceManager.getDefault().getChosenTarget();
if((resource != null) && (resource.getType() == IResource.FILE)) { // if((resource != null) && (resource.getType() == IResource.FILE)) {
String fullName=((IFile)resource).getLocation().toOSString(); // String fullName=((IFile)resource).getLocation().toOSString();
if (fullName!=null){
int dot = fullName.lastIndexOf('.'); int dot = fullName.lastIndexOf('.');
return new String[] { (dot <0) ? fullName : fullName.substring(0, dot) }; return new String[] { (dot <0) ? fullName : fullName.substring(0, dot) };
} }
return new String[] { "" }; return new String[] { "" };
} }
} }
...@@ -44,12 +44,13 @@ public class CurrentFileGenerator extends AbstractGenerator { ...@@ -44,12 +44,13 @@ public class CurrentFileGenerator extends AbstractGenerator {
*/ */
protected String[] getStringValues() { protected String[] getStringValues() {
IResource resource; IResource resource;
if (getMenuMode()) resource = SelectedResourceManager.getDefault().getViewSelectedResource(IPageLayout.ID_RES_NAV); if (getMenuMode()) {
else resource = SelectedResourceManager.getDefault().getSelectedResource(); resource = SelectedResourceManager.getDefault().getViewSelectedResource(IPageLayout.ID_RES_NAV);
if((resource != null) && (resource.getType() == IResource.FILE))
if((resource != null) && (resource.getType() == IResource.FILE)) return new String[] { ((IFile)resource).getLocation().toOSString() };
return new String[] { ((IFile)resource).getLocation().toOSString() }; } else {
return new String[] { SelectedResourceManager.getDefault().getChosenTarget()};
}
return new String[] { "" }; return new String[] { "" };
} }
} }
...@@ -52,9 +52,10 @@ public class SourceListGenerator extends AbstractGenerator { ...@@ -52,9 +52,10 @@ public class SourceListGenerator extends AbstractGenerator {
protected String[] getStringValues() { protected String[] getStringValues() {
String[] file_names = null; String[] file_names = null;
IResource resource = SelectedResourceManager.getDefault().getSelectedVerilogFile(); // IResource resource = SelectedResourceManager.getDefault().getSelectedVerilogFile();
IResource resource = SelectedResourceManager.getDefault().getChosenVerilogFile();
if (resource != null && resource.getType() == IResource.FILE) { if (resource != null && resource.getType() == IResource.FILE) {
IFile[] files = VerilogUtils.getDependencies((IFile)resource); IFile[] files = VerilogUtils.getDependencies((IFile)resource); // returned just the same x353_1.tf
file_names = new String[files.length]; file_names = new String[files.length];
for (int i=0; i < files.length; i++) for (int i=0; i < files.length; i++)
file_names[i] = files[i].getProjectRelativePath().toOSString(); //.getName(); file_names[i] = files[i].getProjectRelativePath().toOSString(); //.getName();
......
...@@ -37,7 +37,8 @@ public class TopModuleNameGenerator extends AbstractGenerator { ...@@ -37,7 +37,8 @@ public class TopModuleNameGenerator extends AbstractGenerator {
return NAME; return NAME;
} }
protected String[] getStringValues() { protected String[] getStringValues() {
IResource resource = SelectedResourceManager.getDefault().getSelectedVerilogFile(); // IResource resource = SelectedResourceManager.getDefault().getSelectedVerilogFile();
IResource resource = SelectedResourceManager.getDefault().getChosenVerilogFile();
if ((resource != null) && (resource.getType() == IResource.FILE)) { if ((resource != null) && (resource.getType() == IResource.FILE)) {
String[] outlineElementsNames= VerilogUtils.getTopModuleNames((IFile)resource); String[] outlineElementsNames= VerilogUtils.getTopModuleNames((IFile)resource);
if ((outlineElementsNames!=null) && (outlineElementsNames.length>0)) return new String[] {outlineElementsNames[0]}; if ((outlineElementsNames!=null) && (outlineElementsNames.length>0)) return new String[] {outlineElementsNames[0]};
......
...@@ -45,7 +45,8 @@ public class TopModulesNameGenerator extends AbstractGenerator { ...@@ -45,7 +45,8 @@ public class TopModulesNameGenerator extends AbstractGenerator {
return NAME; return NAME;
} }
protected String[] getStringValues() { protected String[] getStringValues() {
IResource resource = SelectedResourceManager.getDefault().getSelectedVerilogFile(); // IResource resource = SelectedResourceManager.getDefault().getSelectedVerilogFile();
IResource resource = SelectedResourceManager.getDefault().getChosenVerilogFile();
if ((resource != null) && (resource.getType() == IResource.FILE)) { if ((resource != null) && (resource.getType() == IResource.FILE)) {
String[] outlineElementsNames= VerilogUtils.getTopModuleNames((IFile)resource); String[] outlineElementsNames= VerilogUtils.getTopModuleNames((IFile)resource);
if ((outlineElementsNames!=null) && (outlineElementsNames.length>0)) return outlineElementsNames; if ((outlineElementsNames!=null) && (outlineElementsNames.length>0)) return outlineElementsNames;
......
...@@ -122,9 +122,11 @@ public class Parameter implements Cloneable, Updateable { ...@@ -122,9 +122,11 @@ public class Parameter implements Cloneable, Updateable {
this.relevant = relevant; this.relevant = relevant;
this.hasDependentParameters = false; this.hasDependentParameters = false;
this.sourceXML=sourceXML; this.sourceXML=sourceXML;
/*
if (id.equals("SimulationTopFile")){ // Andrey if (id.equals("SimulationTopFile")){ // Andrey
System.out.println("Creating parameter SimulationTopFile, defaultValue="+defaultValue); System.out.println("Creating parameter SimulationTopFile, defaultValue="+defaultValue);
} }
*/
} }
protected Parameter(Parameter param) { protected Parameter(Parameter param) {
this(param.id, this(param.id,
...@@ -167,10 +169,11 @@ public class Parameter implements Cloneable, Updateable { ...@@ -167,10 +169,11 @@ public class Parameter implements Cloneable, Updateable {
this.context = context; this.context = context;
*/ */
/*
if (id.equals("SimulationTopFile")){ // Andrey if (id.equals("SimulationTopFile")){ // Andrey
System.out.println("Initializing parameter SimulationTopFile, defaultValue="+defaultValue); System.out.println("Initializing parameter SimulationTopFile, defaultValue="+defaultValue);
} }
*/
// Andrey: replacing with // Andrey: replacing with
if(this.context == context) { if(this.context == context) {
...@@ -312,9 +315,9 @@ public class Parameter implements Cloneable, Updateable { ...@@ -312,9 +315,9 @@ public class Parameter implements Cloneable, Updateable {
// //
public void setCurrentValue(String value) throws ToolException { public void setCurrentValue(String value) throws ToolException {
if (id.equals("SimulationTopFile")){ // Andrey // if (id.equals("SimulationTopFile")){ // Andrey
System.out.println("setCurrentValue() SimulationTopFile, value="+value); // System.out.println("setCurrentValue() SimulationTopFile, value="+value);
} // }
if(type.isList()) if(type.isList())
throw new ToolException("Assigning a non-list value to list parameter"); throw new ToolException("Assigning a non-list value to list parameter");
...@@ -328,9 +331,9 @@ public class Parameter implements Cloneable, Updateable { ...@@ -328,9 +331,9 @@ public class Parameter implements Cloneable, Updateable {
} }
public void setCurrentValue(List<String> value) throws ToolException { public void setCurrentValue(List<String> value) throws ToolException {
if (id.equals("SimulationTopFile")){ // Andrey // if (id.equals("SimulationTopFile")){ // Andrey
System.out.println("setCurrentValue() SimulationTopFile a list value"); // System.out.println("setCurrentValue() SimulationTopFile a list value");
} // }
if(!type.isList()) if(!type.isList())
throw new ToolException("Assigning a list value to non-list parameter"); throw new ToolException("Assigning a list value to non-list parameter");
...@@ -352,8 +355,11 @@ public class Parameter implements Cloneable, Updateable { ...@@ -352,8 +355,11 @@ public class Parameter implements Cloneable, Updateable {
return currentValue; return currentValue;
} }
public List<String> getDefaultValue() { public List<String> getDefaultValue() {
return getDefaultValue(false);
}
public List<String> getDefaultValue(boolean menuMode) {
String resolvedDefaultValue = ConditionUtils.resolveContextCondition(context, defaultValue); String resolvedDefaultValue = ConditionUtils.resolveContextCondition(context, defaultValue);
String errmsg = "Parameter '" + id + String errmsg = "Parameter '" + id +
"' of context '" + context.getName() + "' of context '" + context.getName() +
...@@ -363,7 +369,7 @@ public class Parameter implements Cloneable, Updateable { ...@@ -363,7 +369,7 @@ public class Parameter implements Cloneable, Updateable {
FormatProcessor processor = new FormatProcessor(new Recognizer[] { FormatProcessor processor = new FormatProcessor(new Recognizer[] {
//new RepeaterRecognizer(), //new RepeaterRecognizer(),
new SimpleGeneratorRecognizer(), new SimpleGeneratorRecognizer(menuMode),
new ContextParamRecognizer(context) new ContextParamRecognizer(context)
}); });
...@@ -386,10 +392,11 @@ public class Parameter implements Cloneable, Updateable { ...@@ -386,10 +392,11 @@ public class Parameter implements Cloneable, Updateable {
// returns current value if it is set // returns current value if it is set
// otherwise returns default value // otherwise returns default value
public List<String> getValue() { public List<String> getValue() {
/*
if (id.equals("SimulationTopFile")){ // Andrey if (id.equals("SimulationTopFile")){ // Andrey
System.out.println("getValue() SimulationTopFile"); System.out.println("getValue() SimulationTopFile");
} }
*/
if(!currentValue.isEmpty()) if(!currentValue.isEmpty())
return currentValue; return currentValue;
...@@ -399,10 +406,11 @@ public class Parameter implements Cloneable, Updateable { ...@@ -399,10 +406,11 @@ public class Parameter implements Cloneable, Updateable {
// returns external form of the current value unless it equals null; // returns external form of the current value unless it equals null;
// otherwise returns external form of the default value // otherwise returns external form of the default value
public List<String> getExternalValueForm() { public List<String> getExternalValueForm() {
/*
if (id.equals("SimulationTopFile")){ // Andrey if (id.equals("SimulationTopFile")){ // Andrey
System.out.println("getExternalValueForm() SimulationTopFile"); System.out.println("getExternalValueForm() SimulationTopFile");
} }
*/
List<String> externalFormValue = new ArrayList<String>(); List<String> externalFormValue = new ArrayList<String>();
for(Iterator<String> i = getValue().iterator(); i.hasNext();) { for(Iterator<String> i = getValue().iterator(); i.hasNext();) {
......
...@@ -44,6 +44,7 @@ public class Tool extends Context implements Cloneable, Inheritable { ...@@ -44,6 +44,7 @@ public class Tool extends Context implements Cloneable, Inheritable {
private List<String> extensions; private List<String> extensions;
private List<RunFor> runfor; private List<RunFor> runfor;
private int choice; // selected variant for runfor
private Tool baseTool; private Tool baseTool;
...@@ -94,11 +95,19 @@ public class Tool extends Context implements Cloneable, Inheritable { ...@@ -94,11 +95,19 @@ public class Tool extends Context implements Cloneable, Inheritable {
this.toolErrors = toolErrors; this.toolErrors = toolErrors;
this.toolWarnings = toolWarnings; this.toolWarnings = toolWarnings;
this.toolInfo = toolInfo; this.toolInfo = toolInfo;
this.choice=0;
} }
public List<RunFor> getRunFor(){ public List<RunFor> getRunFor(){
return runfor; return runfor;
} }
public int getChoice(){
return choice;
}
public void setChoice(int choice){
this.choice=choice;
}
public void init(Config config) throws ConfigException { public void init(Config config) throws ConfigException {
if(initialized) if(initialized)
...@@ -231,7 +240,7 @@ public class Tool extends Context implements Cloneable, Inheritable { ...@@ -231,7 +240,7 @@ public class Tool extends Context implements Cloneable, Inheritable {
public RunFor[] getMenuActions(IProject project) { public RunFor[] getMenuActions(IProject project) {
if(runfor == null) if(runfor == null)
return null; return null;
updateContextOptions (project); // Fill in parameters updateContextOptions(project); // Fill in parameters - it parses here too - at least some parameters? (not in menu mode)
// Can be two different processors for labels and resources // Can be two different processors for labels and resources
//SimpleGeneratorRecognizer(true) may be not needed, as current file is already set here //SimpleGeneratorRecognizer(true) may be not needed, as current file is already set here
...@@ -277,27 +286,46 @@ public class Tool extends Context implements Cloneable, Inheritable { ...@@ -277,27 +286,46 @@ public class Tool extends Context implements Cloneable, Inheritable {
PackageContext packageContext = getParentPackage(); PackageContext packageContext = getParentPackage();
if (packageContext != null) { if (packageContext != null) {
OptionsCore.doLoadContextOptions(packageContext); OptionsCore.doLoadContextOptions(packageContext);
/*
try { try {
packageContext.buildParams(); packageContext.buildParams();
} catch (ToolException e) { // Do nothing here } catch (ToolException e) { // Do nothing here
System.out.println("updateContextOptions ToolException for Package Context="+e.getMessage()); System.out.println("updateContextOptions ToolException for Package Context="+e.getMessage());
} catch (NullPointerException e) { // Do nothing here Or make it "finally" to ignore all parameters parsing here?
System.out.println("updateContextOptions NullPointerException for Package Context="+e.getMessage());
} finally {
System.out.println("updateContextOptions for Package Context - other error");
} }
*/
} }
Context context = getParentProject(); Context context = getParentProject();
if (context != null) { if (context != null) {
OptionsCore.doLoadContextOptions(context, project); OptionsCore.doLoadContextOptions(context, project);
/*
try { try {
context.buildParams(); context.buildParams();
} catch (ToolException e) { // Do nothing here } catch (ToolException e) { // Do nothing here Or make it "finally" to ignore all parameters parsing here?
System.out.println("updateContextOptions ToolException for Project Context="+e.getMessage()); System.out.println("updateContextOptions ToolException for Project Context="+e.getMessage());
} catch (NullPointerException e) { // Do nothing here Or make it "finally" to ignore all parameters parsing here?
System.out.println("updateContextOptions NullPointerException for Project Context="+e.getMessage());
} finally {
System.out.println("updateContextOptions for Project Context - other error");
} }
*/
} }
//NullPointerException
OptionsCore.doLoadContextOptions(this, project); OptionsCore.doLoadContextOptions(this, project);
/*
try { try {
buildParams(); buildParams();
} catch (ToolException e) { // Do nothing here } catch (ToolException e) { // Do nothing here
System.out.println("updateContextOptions ToolException for Tool Context="+e.getMessage()); System.out.println("updateContextOptions ToolException for Tool Context="+e.getMessage());
} catch (NullPointerException e) { // Do nothing here Or make it "finally" to ignore all parameters parsing here?
System.out.println("updateContextOptions NullPointerException for Tool Context="+e.getMessage());
} finally {
System.out.println("updateContextOptions for Tool Context - other error");
} }
*/
} }
...@@ -321,10 +349,11 @@ public class Tool extends Context implements Cloneable, Inheritable { ...@@ -321,10 +349,11 @@ public class Tool extends Context implements Cloneable, Inheritable {
* processing that inheritance is ignored * processing that inheritance is ignored
*/ */
// if(param != null) // Was before the change described above // if(param != null) // Was before the change described above
/*
if ((param != null) &&(param.getID().equals("SimulationTopFile"))){ // Andrey if ((param != null) &&(param.getID().equals("SimulationTopFile"))){ // Andrey
System.out.println("Initializing parameter SimulationTopFile, isChild="+param.getIsChild()); System.out.println("Initializing parameter SimulationTopFile, isChild="+param.getIsChild());
} }
*/
if ((param != null) && !param.getIsChild()) if ((param != null) && !param.getIsChild())
return param; return param;
......
...@@ -30,9 +30,10 @@ public class SimpleGeneratorRecognizer implements Recognizer { ...@@ -30,9 +30,10 @@ public class SimpleGeneratorRecognizer implements Recognizer {
new ProjectNameGenerator(), new ProjectNameGenerator(),
new ProjectPathGenerator(), new ProjectPathGenerator(),
new TopModuleNameGenerator(), new TopModuleNameGenerator(),
new SelectedFileGenerator(),
new CurrentFileGenerator(), new CurrentFileGenerator(),
// new ViewSelectedFileGenerator(), new CurrentFileBaseGenerator(),
new CurrentFileBaseGenerator() new ChosenActionGenerator()
}; };
public SimpleGeneratorRecognizer(){ public SimpleGeneratorRecognizer(){
......
...@@ -44,6 +44,7 @@ public class RunFor implements Cloneable{ ...@@ -44,6 +44,7 @@ public class RunFor implements Cloneable{
public String getResource(){ public String getResource(){
return resource; return resource;
} }
public boolean getCheckExtension(){ public boolean getCheckExtension(){
return checkExtension; return checkExtension;
} }
......
...@@ -21,10 +21,14 @@ import java.util.Stack; ...@@ -21,10 +21,14 @@ import java.util.Stack;
import com.elphel.vdt.VerilogUtils; import com.elphel.vdt.VerilogUtils;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.text.ITextSelection; import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.IStructuredSelection;
...@@ -58,6 +62,10 @@ public class SelectedResourceManager implements IWindowListener, ISelectionListe ...@@ -58,6 +62,10 @@ public class SelectedResourceManager implements IWindowListener, ISelectionListe
private ITextSelection fSelectedText = null; private ITextSelection fSelectedText = null;
private Stack<IWorkbenchWindow> fWindowStack = new Stack<IWorkbenchWindow>(); private Stack<IWorkbenchWindow> fWindowStack = new Stack<IWorkbenchWindow>();
//Andrey
private String fChosenTarget=null; // full path of the chosen (for action) resource or any string. Used to calculate CurrentFile, verilog file, ...
private IResource fChosenVerilogFile = null; // to keep fSelectedVerilogFile
private int fChosenAction=0; // Chosen variant of running the tool
private SelectedResourceManager() { private SelectedResourceManager() {
IWorkbench workbench = PlatformUI.getWorkbench(); IWorkbench workbench = PlatformUI.getWorkbench();
...@@ -204,6 +212,7 @@ public class SelectedResourceManager implements IWindowListener, ISelectionListe ...@@ -204,6 +212,7 @@ public class SelectedResourceManager implements IWindowListener, ISelectionListe
* @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection) * @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
*/ */
public void selectionChanged(IWorkbenchPart part, ISelection selection) { public void selectionChanged(IWorkbenchPart part, ISelection selection) {
// System.out.println("SelectedResourceManager.selectionChanged()");
IWorkbenchWindow window = part.getSite().getWorkbenchWindow(); IWorkbenchWindow window = part.getSite().getWorkbenchWindow();
if (fWindowStack.isEmpty() || !fWindowStack.peek().equals(window)) { if (fWindowStack.isEmpty() || !fWindowStack.peek().equals(window)) {
// selection is not in the active window // selection is not in the active window
...@@ -212,15 +221,54 @@ public class SelectedResourceManager implements IWindowListener, ISelectionListe ...@@ -212,15 +221,54 @@ public class SelectedResourceManager implements IWindowListener, ISelectionListe
IResource selectedResource = getSelectedResource(part, selection); IResource selectedResource = getSelectedResource(part, selection);
if (selectedResource != null) { if (selectedResource != null) {
fSelectedResource = selectedResource; fSelectedResource = selectedResource;
if ((selectedResource.getType()==IResource.FILE) && (VerilogUtils.isHhdlFile((IFile)fSelectedResource))) // System.out.println("SelectedResourceManager.selectionChanged(): fSelectedResource changed to "+fSelectedResource.getName());
// if (selectedResource.getName().endsWith(".v"))
if ((selectedResource.getType()==IResource.FILE) && (VerilogUtils.isHhdlFile((IFile)fSelectedResource))){
fSelectedVerilogFile = selectedResource; /* Maybe same will work for vhdl too? */ fSelectedVerilogFile = selectedResource; /* Maybe same will work for vhdl too? */
// System.out.println("SelectedResourceManager.selectionChanged(): fSelectedVerilogFile changed to "+fSelectedVerilogFile.getName());
}
} }
if (selection instanceof ITextSelection) { if (selection instanceof ITextSelection) {
fSelectedText = (ITextSelection)selection; fSelectedText = (ITextSelection)selection;
} }
} // selectionChanged() } // selectionChanged()
//TODO: Make them project-relative
public String tryRelativePath(String path){
if (path==null)
return null;
if (getSelectedProject()==null) return path;
IProject project=getSelectedProject();
if (path.startsWith(project.getLocation().toString()))
return path.substring(project.getLocation().toString().length()+1);
return path;
}
public void updateActionChoice(String chosenTarget, int choice){
fChosenAction=choice;
fChosenTarget=tryRelativePath(chosenTarget);
IProject project=getSelectedProject();
if (project==null) return;
IPath path = new Path(fChosenTarget);
IFile file = (path==null)?null:project.getFile(path);
if ((file != null) && (VerilogUtils.isHhdlFile(file)))
fChosenVerilogFile=file;
else if (fChosenVerilogFile==null)
fChosenVerilogFile=fSelectedVerilogFile;
}
public String getChosenTarget() {
return fChosenTarget;
}
public IResource getChosenVerilogFile() {
return (fChosenVerilogFile!=null)?fChosenVerilogFile:fSelectedVerilogFile;
}
public int getChosenAction() {
return fChosenAction;
}
/** /**
......
...@@ -88,7 +88,8 @@ public class VerilogResolver implements IDynamicVariableResolver { ...@@ -88,7 +88,8 @@ public class VerilogResolver implements IDynamicVariableResolver {
* @throws CoreException if there is no selection * @throws CoreException if there is no selection
*/ */
protected IResource getSelectedResource(IDynamicVariable variable) throws CoreException { protected IResource getSelectedResource(IDynamicVariable variable) throws CoreException {
IResource resource = SelectedResourceManager.getDefault().getSelectedVerilogFile(); // IResource resource = SelectedResourceManager.getDefault().getSelectedVerilogFile();
IResource resource = SelectedResourceManager.getDefault().getChosenVerilogFile();
if (resource == null) { if (resource == null) {
abort(Txt.s("Error.Variable.Verilog.NoSelection", new String[]{getReferenceExpression(variable, null)}), null); abort(Txt.s("Error.Variable.Verilog.NoSelection", new String[]{getReferenceExpression(variable, null)}), null);
} }
......
...@@ -81,6 +81,9 @@ public class DesignMenuModel { ...@@ -81,6 +81,9 @@ public class DesignMenuModel {
public boolean isEnabled(IResource resource) { public boolean isEnabled(IResource resource) {
return false; return false;
} }
public boolean isEnabled(String path) {
return false;
}
public Object getParent() { public Object getParent() {
return parent; return parent;
...@@ -138,7 +141,6 @@ public class DesignMenuModel { ...@@ -138,7 +141,6 @@ public class DesignMenuModel {
String extensions[] = tool.getExtensions(); String extensions[] = tool.getExtensions();
if (extensions == null) if (extensions == null)
return true; return true;
String resourceExt = resource.getFileExtension(); String resourceExt = resource.getFileExtension();
if (resourceExt == null) if (resourceExt == null)
return false; return false;
...@@ -148,8 +150,25 @@ public class DesignMenuModel { ...@@ -148,8 +150,25 @@ public class DesignMenuModel {
return true; return true;
} }
return false; return false;
} // isEnabled() } // isEnabled(IResource)
public boolean isEnabled(String path) {
if (path == null)
return false;
String extensions[] = tool.getExtensions();
if (extensions == null)
return true;
int index=path.indexOf(".");
if (index<0) return false;
String resourceExt = path.substring(index+1);
for (int i=0; i < extensions.length; i++) {
if (resourceExt.equalsIgnoreCase(extensions[i]))
return true;
}
return false;
} // isEnabled(String)
public Tool getTool() { public Tool getTool() {
return tool; return tool;
} }
......
...@@ -55,28 +55,21 @@ ...@@ -55,28 +55,21 @@
<!-- Actually used --> <!-- Actually used -->
<syntax name = "JustValueSyntax" <syntax name="JustValueSyntax" format="%%ParamValue"></syntax>
format = "%%ParamValue"></syntax> <syntax name="TopModuleSyntax" format="-s%%TopModule" />
<syntax name = "TopModuleSyntax" <syntax name="TopModulesOtherSyntax" format="%(-s%%ParamValue%| %)" />
format = "-s%%TopModule"/> <syntax name="ModuleLibrarySyntax" format="%(-y%%ParamValue%| %)" />
<syntax name = "TopModulesOtherSyntax" <syntax name="SourceListSyntax" format="%(%%SourceList%| %)" />
format = "%(-s%%ParamValue%| %)"/> <syntax name="ExtraFilesSyntax" format="%(%%ParamValue%| %)" />
<syntax name = "ModuleLibrarySyntax" <syntax name="exeFileSyntax" format="%%ParamValue" />
format = "%(-y%%ParamValue%| %)"/> <syntax name="SwitchSyntax" format="-%%ParamName" />
<syntax name = "SourceListSyntax"
format = "%(%%SourceList%| %)"/>
<syntax name = "ExtraFilesSyntax" <syntax name="DbgCurrentFileSyntax" format="echo &quot;%%CurrentFile&quot; ;" />
format = "%(%%ParamValue%| %)"/> <syntax name="DbgChosenActionIndexSyntax" format="echo &quot;index=%%ChosenActionIndex&quot; ;" />
<syntax name = "exeFileSyntax"
format = "%%ParamValue"/>
<syntax name = "SwitchSyntax"
format = "-%%ParamName"/>
ChosenActionIndex
<!-- typedef --> <!-- typedef -->
...@@ -178,7 +171,7 @@ ...@@ -178,7 +171,7 @@
<action-menu> <action-menu>
<action label="Simulate" resource="%SimulationTopFile" check-extension="false" check-existence="true" /> <action label="Simulate" resource="%SimulationTopFile" check-extension="false" check-existence="true" />
<action label="Simulate for" resource="%%CurrentFile" check-extension="true"/> <action label="Simulate for" resource="%%SelectedFile" check-extension="true" check-existence="true"/>
<action label="Empty" resource="" /> <action label="Empty" resource="" />
<action label="Just try for" resource="%%OS" /> <action label="Just try for" resource="%%OS" />
</action-menu> </action-menu>
...@@ -293,6 +286,25 @@ ...@@ -293,6 +286,25 @@
default = "2&gt;&amp;1 | tee iverilog.log | grep --line-buffered -E 'error|warning' | grep --line-buffered -v &quot;(null):0&quot;" default = "2&gt;&amp;1 | tee iverilog.log | grep --line-buffered -E 'error|warning' | grep --line-buffered -v &quot;(null):0&quot;"
readonly = "false" readonly = "false"
visible = "true"/> visible = "true"/>
<parameter id = "DbgCurrentFile"
label = "DbgCurrentFile"
type = "StringType"
format = "DbgCurrentFileSyntax"
default = ""
readonly = "false"
visible = "true"/>
<parameter id = "ChosenActionIndex"
label = "ChosenActionIndex"
type = "StringType"
format = "DbgChosenActionIndexSyntax"
default = ""
readonly = "false"
visible = "true"/>
<!-- intentional error below - duplicate --> <!-- intentional error below - duplicate -->
<parameter id = "BuildDir" <parameter id = "BuildDir"
label = "project build directory" label = "project build directory"
...@@ -325,7 +337,10 @@ ...@@ -325,7 +337,10 @@
<output> <output>
<line name="command_line" sep=" "> <line name="command_line" sep=" ">
"%Param_Shell_Options" "%Param_Shell_Options"
"%DbgCurrentFile"
"%ChosenActionIndex"
"echo BuildDir=%BuildDir ;" "echo BuildDir=%BuildDir ;"
"echo CurrentFile=%%CurrentFile ;"
"echo SimulationTopFile=%SimulationTopFile ;" "echo SimulationTopFile=%SimulationTopFile ;"
"echo SimulationTopModule=%SimulationTopModule ;" "echo SimulationTopModule=%SimulationTopModule ;"
"%Param_PreExe" "%Param_PreExe"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment