📄 argumentstab.java
字号:
/*
* Author: atotic
* Author: fabioz
* Created: Aug 20, 2003
* License: Common Public License v1.0
*/
package org.python.pydev.debug.ui;
import java.io.File;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
import org.eclipse.debug.ui.ILaunchConfigurationDialog;
import org.eclipse.debug.ui.ILaunchConfigurationTab;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.python.pydev.core.IInterpreterManager;
import org.python.pydev.core.docutils.WordUtils;
import org.python.pydev.debug.core.Constants;
import org.python.pydev.debug.ui.launching.PythonRunnerConfig;
import org.python.pydev.plugin.PydevPlugin;
/**
* The main Python debug setup tab.
*
* <p>Interesting functionality: InterpreterEditor will try the verify the choice of an interpreter.
* <p>Getting the ModifyListener to display the proper error message was tricky
*/
public class ArgumentsTab extends AbstractLaunchConfigurationTab {
// Widgets
Text baseDirectoryField;
Text programArgumentField;
Combo interpreterComboField;
Text vmArgumentsField;
// View constant
public static final String DEFAULT_INTERPRETER_NAME = "Default Interpreter";
protected ModifyListener modifyListener = new ModifyListener() {
public void modifyText(ModifyEvent e) {
if(e.getSource() == baseDirectoryField){
File file = new File(baseDirectoryField.getText());
if(!file.exists()){
setErrorMessage("The directory in the Base Directory does not exist.");
}
if(!file.isDirectory()){
setErrorMessage("The directory in the location is not actually a directory.");
}
}else if(e.getSource() == programArgumentField){
}
updateLaunchConfigurationDialog();
}
};
private IInterpreterManager interpreterManager;
private Button buttonSeeResultingCommandLine;
private ILaunchConfigurationWorkingCopy workingCopyForCommandLineGeneration;
private Text text;
private MainModuleTab mainModuleTab;
private SelectionListener listener = new SelectionListener(){
public void widgetSelected(SelectionEvent e) {
if(e.getSource() == buttonSeeResultingCommandLine){
try {
//ok, show the command-line to the user
ILaunchConfigurationDialog launchConfigurationDialog = getLaunchConfigurationDialog();
ILaunchConfigurationTab[] tabs = launchConfigurationDialog.getTabs();
for (int i = 0; i < tabs.length; i++) {
tabs[i].performApply(workingCopyForCommandLineGeneration);
}
PythonRunnerConfig config = getConfig(workingCopyForCommandLineGeneration, launchConfigurationDialog);
String commandLineAsString = config.getCommandLineAsString();
commandLineAsString = WordUtils.wrap(commandLineAsString, 80);
commandLineAsString += "\n\nThe PYTHONPATH that will be used is:\n\n";
commandLineAsString += config.pythonpathUsed;
text.setText(commandLineAsString);
} catch (Exception e1) {
text.setText("Unable to make the command-line. \n\nReason:\n\n"+e1.getMessage());
}
}
}
public void widgetDefaultSelected(SelectionEvent e) {
}
};
/**
* @param conf the launch configuration to be used
* @param launchConfigurationDialog the dialog for the launch configuration
* @return a PythonRunnerConfig configured with the given launch configuration
* @throws CoreException
*/
private PythonRunnerConfig getConfig(ILaunchConfiguration conf, ILaunchConfigurationDialog launchConfigurationDialog) throws CoreException {
String run;
if(interpreterManager.isJython()){
run = PythonRunnerConfig.RUN_JYTHON;
}else if(interpreterManager.isPython()){
run = PythonRunnerConfig.RUN_REGULAR;
}else{
throw new RuntimeException("Should be python or jython interpreter (found unknown).");
}
PythonRunnerConfig config = new PythonRunnerConfig(conf, launchConfigurationDialog.getMode(), run);
return config;
}
public ArgumentsTab(IInterpreterManager interpreterManager, MainModuleTab mainModuleTab) {
this.interpreterManager = interpreterManager;
this.mainModuleTab = mainModuleTab;
}
public void createControl(Composite parent) {
Composite comp = new Composite(parent, SWT.NONE);
setControl(comp);
GridLayout gridLayout = new GridLayout ();
comp.setLayout (gridLayout);
GridData data = new GridData (GridData.FILL_HORIZONTAL);
Label label2 = new Label (comp, SWT.NONE);
label2.setText ("Base directory:");
label2.setLayoutData (data);
baseDirectoryField = new Text (comp, SWT.BORDER);
data = new GridData ();
data.horizontalAlignment = GridData.FILL;
data.verticalAlignment = GridData.FILL;
data.horizontalSpan = 1;
data.verticalSpan = 2;
baseDirectoryField.setLayoutData (data);
baseDirectoryField.addModifyListener(modifyListener);
baseDirectoryField.setLayoutData(data);
Label label4 = new Label (comp, SWT.NONE);
data = new GridData (GridData.FILL_HORIZONTAL);
label4.setText ("Program Arguments:");
label4.setLayoutData (data);
programArgumentField = new Text (comp, SWT.BORDER | SWT.MULTI);
data = new GridData ();
data.horizontalAlignment = GridData.FILL;
data.verticalAlignment = GridData.FILL;
data.horizontalSpan = 1;
data.verticalSpan = 2;
programArgumentField.setLayoutData (data);
programArgumentField.addModifyListener(modifyListener);
Label label6 = new Label (comp, SWT.NONE);
label6.setText ("Interpreter:");
data = new GridData (GridData.FILL_HORIZONTAL);
data.horizontalSpan = 2;
label6.setLayoutData (data);
interpreterComboField = new Combo (comp, SWT.DROP_DOWN);
String[] interpreters = this.interpreterManager.getInterpreters();
if (interpreters.length > 0){
// There is at least one interpreter defined, add the default interpreter option at the beginning.
String[] interpreterNames = interpreters;
interpreters = new String[interpreterNames.length+1];
interpreters[0] = ArgumentsTab.DEFAULT_INTERPRETER_NAME;
for (int i = 0; i < interpreterNames.length; i ++){
interpreters[i+1] = interpreterNames[i];
}
}
interpreterComboField.setItems (interpreters);
interpreterComboField.select(0);
data = new GridData ();
data.horizontalAlignment = GridData.FILL;
data.horizontalSpan = 2;
interpreterComboField.setLayoutData (data);
interpreterComboField.addModifyListener(modifyListener);
//label
Label l3 = new Label(comp,SWT.None);
l3.setText("VM arguments (for python.exe or java.exe): ");
data = new GridData(GridData.FILL_HORIZONTAL);
data.horizontalSpan = 2;
l3.setLayoutData(data);
//Text of the Arguments
vmArgumentsField = new Text(comp, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.WRAP);
data = new GridData();
data.grabExcessHorizontalSpace = true;
data.grabExcessVerticalSpace = true;
data.horizontalAlignment = SWT.FILL;
data.verticalAlignment = SWT.FILL;
data.horizontalSpan = 2;
data.verticalSpan = 5;
vmArgumentsField.setLayoutData(data);
vmArgumentsField.addModifyListener(modifyListener);
buttonSeeResultingCommandLine = new Button (comp, SWT.NONE);
buttonSeeResultingCommandLine.setText ("See resulting command-line for the given parameters");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -