简体   繁体   English

如何在gnu arm eclipse或cdt上的项目资源管理器中设置或替换文件?

[英]how to set or replace a file on project explorer on gnu arm eclipse or cdt?

I'm studying eclipse cdt plug-in development use gnuarmeclipse . 我正在研究使用gnuarmeclipse的 eclipse cdt插件开发。

previous question. 前一个问题。

I need to set or replace a file(such a linkerscript) in project explorer. 我需要在项目资源管理器中设置或替换文件(例如链接描述文件)。

I know it change on project properties -> C/C++ Build -> Settings -> Tool Settings -> GCC C Linker -> General -> Script file(-T). 我知道它会在项目属性-> C / C ++ Build->设置->工具设置-> GCC C链接器->常规->脚本文件(-T)上更改。

But I want, it execute on project explorer context menu. 但是我想要在项目资源管理器上下文菜单上执行。

See below. 见下文。

1) Select LD(folder for only one linkerscript file) on Project Explorer. 1)在项目资源管理器中选择LD(仅一个链接描述文件的文件夹)。

2) Right click and select "Set Linker Script File" on context menu. 2)右键单击并在上下文菜单上选择“设置链接器脚本文件”。

3) Select a file to set or replace on Open window. 3)在“打开”窗口中选择要设置或替换的文件。

This is setlinkerscript.java 这是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;
}}

I got a file location but I don't know where I set on eclipse. 我有文件位置,但不知道在eclipse上的设置位置。

Any API or method is there? 有任何API或方法吗? or recommend documents. 或推荐文件。

I can't attach jpg for figure.. need more reputation point. 我无法为图片附加jpg。需要更多信誉点。 Sorry! 抱歉!

Thanks in advance. 提前致谢。

Oh finally, I did it myself. 哦,终于,我自己做了。 This is my answer. 这是我的答案。

Thanks stackoverflow and google. 感谢stackoverflow和google。

But.. another problems coming... ㅜㅜ 但是..另一个问题来了...ㅜㅜ

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;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Eclipse CDT + GNU ARM中的奇怪包含路径 - Strange include path in Eclipse CDT + GNU ARM 如何在gnu arm eclipse项目模板上设置带有路径的默认链接描述文件? - how to set default linker script with path on gnu arm eclipse project template? 将现有的* .bin文件添加到gnu arm eclipse中的项目中 - Adding existing *.bin file to project in gnu arm eclipse Eclipse CDT-在项目资源管理器中缺少“归档”和“包含” - Eclipse CDT - missing “Archives” and “Includes” in Project Explorer 如何使用现有C ++源代码在Eclipse CDT中创建GNU Autotool项目? - How do i create a GNU Autotool Project in Eclipse CDT from existing C++ source code? 如何通过每个项目的脚本在Eclipse CDT中设置环境? - How to set up an environment in Eclipse CDT by script per project? 在Eclipse CDT gnu autotools项目中添加其他编译器选项 - Adding additional compiler option(s) in eclipse CDT gnu autotools project Eclipse Project Explorer在Fedora 20和Eclipse CDT上不起作用 - Eclipse Project Explorer not working on fedora 20 and eclipse cdt GNU ARM Eclipse:如何模拟引脚输入? - GNU ARM Eclipse: how to simulate pin input? Eclipse / CDT项目资源管理器中这个装饰文件夹图标的含义是什么? - What is the meaning of this decorated folder icon in Eclipse/CDT project explorer?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM