Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在gnu arm eclipse或cdt上的project explorer上设置或替换文件?_Eclipse_Eclipse Plugin_Eclipse Cdt_Gnu Arm - Fatal编程技术网

如何在gnu arm eclipse或cdt上的project explorer上设置或替换文件?

如何在gnu arm eclipse或cdt上的project explorer上设置或替换文件?,eclipse,eclipse-plugin,eclipse-cdt,gnu-arm,Eclipse,Eclipse Plugin,Eclipse Cdt,Gnu Arm,我正在研究EclipseCDT插件的开发使用 我需要在project explorer中设置或替换文件(如linkerscript) 我知道它在项目属性->C/C++构建->设置->工具设置->GCC链接器->常规->脚本文件-T上发生了变化 但我想,它在ProjectExplorer上下文菜单上执行 见下文 1在Project Explorer上仅为一个linkerscript文件选择LDfolder 2右键单击并在关联菜单上选择设置链接器脚本文件 3在打开的窗口中选择要设置或替换的文件 这是

我正在研究EclipseCDT插件的开发使用

我需要在project explorer中设置或替换文件(如linkerscript)

我知道它在项目属性->C/C++构建->设置->工具设置->GCC链接器->常规->脚本文件-T上发生了变化

但我想,它在ProjectExplorer上下文菜单上执行

见下文

1在Project Explorer上仅为一个linkerscript文件选择LDfolder

2右键单击并在关联菜单上选择设置链接器脚本文件

3在打开的窗口中选择要设置或替换的文件

这是setlinkerscript.java

public class setlinkerscript extends AbstractHandler {

public Object execute(ExecutionEvent event) throws ExecutionException {
    // TODO Auto-generated method stub

    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);

    Shell shell = new Shell();
    FileDialog dialog = new FileDialog(shell, SWT.OPEN);
    dialog.setFilterExtensions(new String[] {"*.x"});
    String linkerscript = dialog.open();
    System.out.println(linkerscript);

    return null;
}}
我有一个文件位置,但我不知道我在eclipse上设置的位置

有什么API或方法吗?或推荐文件

我无法为图附加jpg。。需要更多的信誉点。对不起


提前谢谢。

哦,最后,我自己做了。这是我的答案。 谢谢stackoverflow和google。 但是另一个问题来了。。。ㅜㅜ

public class setlinkerscript extends AbstractHandler {

    public Object execute(ExecutionEvent event) throws ExecutionException {
        // TODO Auto-generated method stub

        IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);

        Shell shell = new Shell();
        FileDialog dialog = new FileDialog(shell, SWT.OPEN);
        dialog.setFilterExtensions(new String[] {"*.x"});       
        String linkerscript = dialog.open();    // get new linkerscript with path       

        IEditorPart  editorPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
        String activeProjectName = null;

        if(editorPart  != null)
        {
            IFileEditorInput input = (FileEditorInput)editorPart.getEditorInput();
            IFile file = input.getFile();
            IProject activeProject = file.getProject();
            activeProjectName = activeProject.getName();
        }

        // ===========================================================================================================
        // CProject

        ICProject cproject = CoreModel.getDefault().getCModel().getCProject(activeProjectName);
        IManagedBuildInfo buildInfo = ManagedBuildManager.getBuildInfo(cproject.getResource());

        // ===========================================================================================================
        // config

        IConfiguration configs[] = buildInfo.getManagedProject().getConfigurations();

        int i;
        for(i=0; i<2; i++)
        {
            // configs[0] : Debug
            ITool[] tool = configs[i].getTools();

            // configs[1] : Release

            // ===========================================================================================================
            // tool
            //  GCC Assembler,  GCC C Compiler, GCC C++ Compiler,       GCC C Linker,
            //  GCC C++ Linker, GCC Archiver,   Windows Create Flash Image, Windows Create Listing,
            //  Windows Print Size

            // tool[3] : EISC GCC C Linker
            IOption[] option = tool[3].getOptions();

            // option[0] : linkerscript
            Object value = option[0].getValue();

            try {
                option[0].setValue(linkerscript);
            } catch (BuildException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        // ===========================================================================================================

        return null;
    }
}