I'm studying eclipse cdt plug-in development use gnuarmeclipse.
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).
But I want, it execute on project explorer context menu.
See below.
1) Select LD(folder for only one linkerscript file) on Project Explorer.
2) Right click and select "Set Linker Script File" on context menu.
3) Select a file to set or replace on Open window.
This is 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.
Any API or method is there? or recommend documents.
I can't attach jpg for figure.. need more reputation point. Sorry!
Thanks in advance.
Oh finally, I did it myself. This is my answer.
Thanks stackoverflow and 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;
}
}