Home » Developing U++ » U++ TheIDE and Library: Releases and ChangeLogs » Some macro enhancements for TheIde
Some macro enhancements for TheIde [message #10404] |
Fri, 06 July 2007 16:03  |
Zardos
Messages: 62 Registered: April 2007
|
Member |
|
|
Hello,
I needed some enhancements for Macros in TheIde, so I made some small changes in the upp source. May be you can consider introducing them into the repository, again...
1.) I wanted to run some external programs on a source file. For example a source beautifier like AStyle. This kind of macro should be always available and independent of the selected package.
To accomplis this I changed:
In Ide.cpp the function void Ide::SyncUsc() to this code:
void Ide::SyncUsc()
{
CleanUsc();
::Workspace wspc;
static String scan[] = { main, ConfigFile("ide.aux") };
for(int t = 0; t < (sizeof scan / sizeof scan[0]); t++) {
wspc.Scan(scan[t]);
int i;
for(i = 0; i < wspc.GetCount(); i++) {
const Package& p = wspc.GetPackage(i);
for(int j = 0; j < p.file.GetCount(); j++) {
String file = SourcePath(wspc[i], p.file[j]);
if(ToLower(GetFileExt(file)) == ".usc")
UscFile(file);
}
}
}
UscProcessDir(GetCommonDir());
UscProcessDir(GetLocalDir());
UscProcessDir(GetFileFolder(ConfigFile("x")));
}
Now, not only the current package is searched for macros - in addition the files in <ide-aux> are searched for macros, too.
The next step was to add 3 functions to "Ide::MacroEditor()":
SaveCurrentFile() : Save the current source file
ProjectDir() : Get the package directory. I need this for some other stufff... OOps PackageDir or PackagePath would be better I gues 
FileName() : Get the current Name of the current file.
I changed Ide.h and added the following lines to:
struct Ide : public TopWindow, public WorkspaceWork, public IdeContext {
void MacroSaveCurrentFile(EscEscape& e);
void MacroProjectDir(EscEscape& e);
void MacroFileName(EscEscape& e);
and in Macro.cpp I added the following lines to:
EscValue Ide::MacroEditor()
out.Escape("SaveCurrentFile()", THISBACK(MacroSaveCurrentFile));
out.Escape("ProjectDir()", THISBACK(MacroProjectDir));
out.Escape("FileName()", THISBACK(MacroFileName));
and these functions to Macro.cpp:
void Ide::MacroSaveCurrentFile(EscEscape& e)
{
SaveFile();
}
void Ide::MacroProjectDir(EscEscape& e)
{
e = GetFileFolder(PackagePathA(GetActivePackage()));
}
void Ide::MacroFileName(EscEscape& e)
{
e = editfile;
}
As an example you can now add a macro file to <ide-aux> and call a beautifier like this from the macro menu:
macro "Beautify" Ctrl+Shift+B {
ClearConsole();
cout("Beautifying...");
SaveCurrentFile();
Execute("astyle.exe --style=java --indent=tab=4 --indent-cases --one-line=keep-blocks --unpad=paren --pad=oper --break-blocks " + FileName());
}
- Ralf
|
|
|
Goto Forum:
Current Time: Thu Jun 26 11:30:58 CEST 2025
Total time taken to generate the page: 0.04484 seconds
|