OK, here is a basic script:
local pm = GetProjectManager();
if (IsNull(pm))
{
ShowError(_T("Could not query the project manager. Cannot continue."));
return 0;
}
local p = pm.GetActiveProject();
// File with the source files separated by \n
// for example:
// '''''''''''''''''''
// a.cpp
// b.cpp
// '''''''''''''''''''
local filecontent = IO.ReadFileContents (_T("D:\\ddddd\\fileList.txt"));
// Split the files in lines
local fileList = GetArrayFromString(filecontent, _T("\n"), true);
print(_T("Files to load:"));
for(local i = 0; i < fileList.GetCount(); i++)
{
print(fileList.Item(i) + _T("\n")); // Print the files in the list, as a check
}
// Base path, the files in the text files are relative in my case. If they are absolute you can remove this
local basePath = _T("D:\\ddddd\\src\\");
for(local i = 0; i < fileList.GetCount(); i++)
{
// Create file path
local filePath = basePath + fileList.Item(i);
// Add to all build targets
for(local a = 0; a <= p.GetBuildTargetsCount(); a++)
pm.AddFileToProject(filePath, p, a);
}
// Save the project. This triggers also an update of the project UI
pm.SaveAllProjects();
This works on windows, you have to replace the paths accordingly on linux...
the example file D:\ddddd\fileList.txt
the two source files are in D:\ddddd\src\
To use the scirpt:
1) Create a text document and C&P the top script
2) Replace the paths in the script with the paths and files on your system
3) Save the text document, and rename it to "myImportScript.script"
4) Start codeblocks
5) Create or open the project, where the files should be imported
6) View->Scripting console
7) In the opening window select "Load from file" the second button near the command input field
8) Enjoy
[edit:] fix spelling
[edit2:] References for all this:
http://wiki.codeblocks.org/index.php/Scripting_Code::Blocks
http://wiki.codeblocks.org/index.php/Some_examples
http://wiki.codeblocks.org/index.php/Scripting_commands
http://www.squirrel-lang.org/