Commit b6bfc326 authored by Andrey Filippov's avatar Andrey Filippov
Browse files

converted paths to project-relative when possible

parent 2e5900c7
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -433,9 +433,9 @@ public class Parameter implements Cloneable, Updateable {
        
        if(defaultValue == null) {
            defaultValue = param.defaultValue;
            if (id.equals("SimulationTopFile")){ // Andrey
            	System.out.println("Updating parameter SimulationTopFile, defaultValue="+defaultValue);
            }
//            if (id.equals("SimulationTopFile")){ // Andrey
//            	System.out.println("Updating parameter SimulationTopFile, defaultValue="+defaultValue);
//            }
        }            
        
        if(label == null)
+28 −0
Original line number Diff line number Diff line
@@ -17,8 +17,13 @@
 *******************************************************************************/
package com.elphel.vdt.core.tools.params.types;

import org.eclipse.core.resources.IProject;

import com.elphel.vdt.core.tools.config.ConfigException;
import com.elphel.vdt.core.tools.params.ControlInterface;
import com.elphel.vdt.ui.variables.SelectedResourceManager;
import com.elphel.vdt.veditor.VerilogPlugin;
import com.elphel.vdt.veditor.preference.PreferenceStrings;


public class ParamTypeString extends ParamType {
@@ -137,7 +142,30 @@ public class ParamTypeString extends ParamType {
        }
    }
    
    public String tryProjectRelativePath(String path){
    	if (path==null)
    		return null;
        IProject project = SelectedResourceManager.getDefault().getSelectedProject();
    	if (project==null) return path;
        String projectPath=project.getLocation().toString();
    	if (path.startsWith(projectPath)) {
        	if (path.equals(projectPath)){
        		System.out.println("Path equals to project path = \""+path+"\", returning \".\"");
        		return ".";
        	}
    		return path.substring(projectPath.length()+1);
    	}
    	return path;
    }

    public String canonicalizeValue(String value) {
// Try to convert file/dir parameters to project-relative
    	if ((kind == KIND.FILE) || (kind == KIND.FILE)) {
    		if (VerilogPlugin.getPreferenceBoolean(PreferenceStrings.DEBUG_OTHER)) System.out.print("Converting \""+value+"\"to ");
    		value=tryProjectRelativePath(value);
    		if (VerilogPlugin.getPreferenceBoolean(PreferenceStrings.DEBUG_OTHER)) System.out.println("\""+value+"\"");
    	}
    	
        switch(caseSensitive) {
            case UPPERCASE: 
                return value.toUpperCase();
+39 −16
Original line number Diff line number Diff line
@@ -17,9 +17,13 @@
 *******************************************************************************/
package com.elphel.vdt.ui.dialogs;

import org.eclipse.core.resources.IProject;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Shell;

import com.elphel.vdt.ui.variables.SelectedResourceManager;


/**
 * Dialog to promt list of files. 
 * 
@@ -27,15 +31,24 @@ import org.eclipse.swt.widgets.Shell;
 * @author  Lvov Konstantin
 */
public class FileListPromptDialog extends ListPromptDialog {

/*
	public FileListPromptDialog( final Shell parentShell, String title) {
		this(parentShell, title, null);
		this(parentShell, title, null,null);
	}
	public FileListPromptDialog( final Shell parentShell,
			String title,
			final String[] extensions
			)
	{
		this(parentShell, title, extensions,null);

	
	public FileListPromptDialog( final Shell parentShell
			                   , String title
			                   , final String[] extensions)
	}
*/
	public FileListPromptDialog( final Shell parentShell,
			String title,
			final String[] extensions,
			final String projectPath
			)
	{
		super( parentShell
				, title
@@ -43,11 +56,21 @@ public class FileListPromptDialog extends ListPromptDialog {
			public String getNewValue() {
				FileDialog dialog = new FileDialog(parentShell);
				dialog.setFilterExtensions(extensions);
				if (projectPath!=null){
					dialog.setFileName(projectPath);
				}
				String selectedFile = dialog.open();
// try to convert to project-relative
		    	if ((selectedFile!=null) && selectedFile.startsWith(projectPath)) {
		        	if (selectedFile.equals(projectPath)){
		        		System.out.println("FileListPromptDialog(): Path equals to project path = \""+selectedFile+"\", returning \".\"");
		        		return ".";
		        	}
		    		return selectedFile.substring(projectPath.length()+1);
		    	}
		    	return selectedFile;
			}
		}
				);
	}
	
} // class FileListPromptDialog
+5 −1
Original line number Diff line number Diff line
@@ -50,7 +50,11 @@ public class ContextOptionsDialog extends Dialog {
            , context
            , OptionsCore.getPreferenceStore(context, project)
            );
        location = project.getLocation().toOSString();
        location = project.getLocation().toOSString(); // project location
//        System.out.println("ContextOptionsDialog: location was "+location);
//        location = project.getProjectRelativePath().toOSString();
//        System.out.println("ContextOptionsDialog: location changed to "+location);
        		
    }

    public ContextOptionsDialog(Shell parent, Context context) {
+17 −5
Original line number Diff line number Diff line
@@ -17,10 +17,13 @@
 *******************************************************************************/
package com.elphel.vdt.ui.options.component;

import org.eclipse.core.resources.IProject;

import com.elphel.vdt.core.tools.params.Parameter;
import com.elphel.vdt.core.tools.params.types.ParamTypeString;
import com.elphel.vdt.ui.dialogs.FileListPromptDialog;
import com.elphel.vdt.ui.dialogs.ListPromptDialog;
import com.elphel.vdt.ui.variables.SelectedResourceManager;

public class FileListComponent extends ListComponent {

@@ -31,10 +34,19 @@ public class FileListComponent extends ListComponent {
    protected ListPromptDialog createDialog() {
    	String filemask = ((ParamTypeString)param.getType()).getFilemask();
    	final String[] extensions = (filemask != null? new String[] { filemask } : null);
    	IProject project = SelectedResourceManager.getDefault().getSelectedProject();
    	String projectPath=null;
    	if (project!=null) {
    		projectPath=project.getLocation().toString();
    	}
    	final String fProjectPath=projectPath;

        return new FileListPromptDialog( promptField.getVisibleNameField().getShell()
                                       , "File list prompt"
                                       , extensions );

    	return new FileListPromptDialog( promptField.getVisibleNameField().getShell(),
    			"File list prompt",
    			extensions,
    			fProjectPath);
    }
    

}
Loading