Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[Dltk-dev] A very helpful AddScriptInterpreterDialog feature request

Hi,

Could you make a generateInterpreterName() protected method in
org.eclipse.dltk.internal.debug.ui.interpreters.AddScriptInterpreterDialog.java
that contains the code a fragment below which is extracted form the
validateInterpreterLocation() method.

This would help in decoupling the name of the executable and the
effective name of the executable. For example, I have an interpreter
"interpreter.exe" and I want to name automatically it "My Interpreter
v1.2.3" (similar with how java names the JRE's installations). And
this without reimplementing the whole validateInterpreterLocation()
method (which is not possible btw. because it has a default modifier.)

// A setter for the text in fInterpreterName is also needed.
protected void setInterpreterName(String name) {
	fInterpreterName.setText(pName);
}

// The new method
protected void generateInterpreterName() {

	String name = fInterpreterName.getText();
			if ((name == null || name.trim().length() == 0) && file != null) {
				// auto-generate interpreter name
				String genName = null;
				IPath path = new Path(file.getCanonicalPath());
				int segs = path.segmentCount();
				if (segs == 1) {
					genName = path.segment(0);
				} else if (segs >= 2) {
					String last = path.lastSegment();
					genName = last;
				}
				// Add number if interpreter with such name already exists.
				String pName = genName;
				int index = 0;
				while (true) {
					boolean found = false;
					for (int i = 0; i < this.fInterpreterTypes.length; i++) {
						IInterpreterInstallType type = this.fInterpreterTypes[i];
						IInterpreterInstall inst = type
								.findInterpreterInstallByName(pName);
						if (inst != null) {
							pName = genName + "(" + String.valueOf(++index) //$NON-NLS-1$
									+ ")"; //$NON-NLS-1$
							found = true;
							break;
						}
					}
					if (!found) {
						break;
					}
				}
				if (pName != null) {
					setInterpreterName(pName);
				}
			}
}

Thanks!
Gabriel

-- 
MSc Gabriel Petrovay
MCSA, MCDBA, MCAD
Mobile: +41(0)787978034


Back to the top