⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 abstractlaunchshortcut.java

📁 Python Development Environment (Python IDE plugin for Eclipse). Features editor, code completion, re
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            reportError("Unexpected error", e);
        }
        return validConfigs;
    }

    /**
     * @param file
     * @return default string for the location field
     */
    public static String getDefaultLocation(IResource[] file) {
        StringBuffer buffer = new StringBuffer();

        for (IResource r : file) {
            if (buffer.length() > 0) {
                buffer.append("|");
            }
            buffer.append(r.getRawLocation().toString());
        }
        return buffer.toString();
        // E3		IStringVariableManager varManager = VariablesPlugin.getDefault().getStringVariableManager();
        // E3		return varManager.generateVariableExpression("workspace_loc", file.getFullPath().toString());
    }

    /**
     * @return a string with the launch configuration type that should be used for the run.
     */
    protected abstract String getLaunchConfigurationType();

    protected ILaunchConfiguration createDefaultLaunchConfiguration(IResource[] resource) {
        IInterpreterManager pythonInterpreterManager = getInterpreterManager();
        String projName = resource[0].getProject().getName();
        return createDefaultLaunchConfiguration(resource, getLaunchConfigurationType(), getDefaultLocation(resource),
                pythonInterpreterManager, projName);
    }

    public static ILaunchConfiguration createDefaultLaunchConfiguration(IResource[] resource, String launchConfigurationType,
            String location, IInterpreterManager pythonInterpreterManager, String projName) {
        return createDefaultLaunchConfiguration(resource, launchConfigurationType, location, pythonInterpreterManager, projName, null);
    }

    /**
     * COPIED/MODIFIED from AntLaunchShortcut
     * @param location 
     * @param pythonInterpreterManager 
     */
    public static ILaunchConfiguration createDefaultLaunchConfiguration(IResource[] resource, String launchConfigurationType,
            String location, IInterpreterManager pythonInterpreterManager, String projName, String vmargs) {

        ILaunchManager manager = org.eclipse.debug.core.DebugPlugin.getDefault().getLaunchManager();
        ILaunchConfigurationType type = manager.getLaunchConfigurationType(launchConfigurationType);
        if (type == null) {
            reportError("Python launch configuration not found", null);
            return null;
        }

        StringBuffer buffer = new StringBuffer(projName);
        buffer.append(" ");
        StringBuffer resourceNames = new StringBuffer();
        for(IResource r:resource){
            if(resourceNames.length() > 0){
                resourceNames.append(" - ");
            }
            resourceNames.append(r.getName());
        }
        buffer.append(resourceNames);
        String name = buffer.toString().trim();
        name = manager.generateUniqueLaunchConfigurationNameFrom(name);

        try {

            ILaunchConfigurationWorkingCopy workingCopy = type.newInstance(null, name);
            // Python Main Tab Arguments

            //IStringVariableManager varManager = VariablesPlugin.getDefault().getStringVariableManager();
            //String baseDirectory = varManager.generateVariableExpression("workspace_loc",resource.getRawLocation().removeLastSegments(1).toString());
            String baseDirectory = resource[0].getRawLocation().removeLastSegments(1).toString();
            String arguments = "";

            workingCopy.setAttribute(Constants.ATTR_PROJECT, projName);
            workingCopy.setAttribute(Constants.ATTR_RESOURCE_TYPE, resource[0].getType());
            workingCopy.setAttribute(Constants.ATTR_INTERPRETER, Constants.ATTR_INTERPRETER_DEFAULT);

            workingCopy.setAttribute(IDebugUIConstants.ATTR_LAUNCH_IN_BACKGROUND, false);
            workingCopy.setAttribute(Constants.ATTR_LOCATION, location);
            workingCopy.setAttribute(Constants.ATTR_WORKING_DIRECTORY, baseDirectory);
            workingCopy.setAttribute(Constants.ATTR_PROGRAM_ARGUMENTS, arguments);
            workingCopy.setAttribute(Constants.ATTR_VM_ARGUMENTS, vmargs);

            // Common Tab Arguments
            CommonTab tab = new CommonTab();
            tab.setDefaults(workingCopy);
            tab.dispose();
            return workingCopy.doSave();
        } catch (NotConfiguredInterpreterException e) {
            reportError(e.getMessage(), e);
            throw e;
        } catch (CoreException e) {
            reportError(null, e);
            return null;
        }
    }

    /**
     * @return the interpreter manager associated with this shortcut (may be overridden if it is not python)
     */
    protected IInterpreterManager getInterpreterManager() {
        return PydevPlugin.getPythonInterpreterManager();
    }

    /**
     * COPIED/MODIFIED from AntLaunchShortcut
     */
    protected ILaunchConfiguration chooseConfig(List configs) {
        if (configs.isEmpty()) {
            return null;
        }
        ILabelProvider labelProvider = DebugUITools.newDebugModelPresentation();
        ElementListSelectionDialog dialog = new ElementListSelectionDialog(Display.getDefault().getActiveShell(), labelProvider);
        dialog.setElements(configs.toArray(new ILaunchConfiguration[configs.size()]));
        dialog.setTitle("Pick a Python configuration");
        dialog.setMessage("Choose a python configuration to run");
        dialog.setMultipleSelection(false);
        int result = dialog.open();
        labelProvider.dispose();
        if (result == Window.OK)
            return (ILaunchConfiguration) dialog.getFirstResult();
        else
            return null;
    }

    protected void launch(IResource file, String mode, String targetAttribute) {
        launch(new IResource[] { file }, mode, targetAttribute);
    }

    /**
     * Launch the given targets in the given build file. The targets are
     * launched in the given mode.
     * 
     * @param file the build file to launch
     * @param mode the mode in which the build file should be executed
     * @param targetAttribute the targets to launch, in the form of the launch
     * configuration targets attribute.
     */
    protected void launch(IResource[] file, String mode, String targetAttribute) {
        if (!verifyMode(mode)) {
            reportError("Invalid mode " + mode, null);
            return;
        }

        ILaunchConfiguration conf = null;
        List configurations = findExistingLaunchConfigurations(file);
        if (configurations.isEmpty())
            conf = createDefaultLaunchConfiguration(file);
        else {
            if (configurations.size() == 1) {
                conf = (ILaunchConfiguration) configurations.get(0);
            } else {
                conf = chooseConfig(configurations);
                if (conf == null)
                    // User cancelled selection
                    return;
            }
        }

        if (conf != null) {
            if (fShowDialog) {
                String groupID = "";

                if (mode.equals("run")) {
                    groupID = Constants.PYTHON_RUN_LAUNCH_GROUP;
                } else if (mode.equals("debug")) {
                    groupID = Constants.PYTHON_DEBUG_LAUNCH_GROUP;
                }

                DebugUITools.openLaunchConfigurationDialog(PydevDebugPlugin.getActiveWorkbenchWindow().getShell(), conf, groupID, null);
            } else {
                DebugUITools.launch(conf, mode);
            }
            return;
        }
        fileNotFound();
    }

    public void setShowDialog(boolean showDialog) {
        fShowDialog = showDialog;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -