mirror of https://gitlab.com/basile.b/dexed.git
improved symbolic strings
- lazy update happen only when needed - new symbol `<CPCD>`, which expands to the project sources common directory - updated demo
This commit is contained in:
parent
9c6256df57
commit
3ef1d25c43
|
@ -6,12 +6,12 @@ import std.getopt;
|
||||||
/*
|
/*
|
||||||
pass:
|
pass:
|
||||||
|
|
||||||
"--a=<CAF>" "--b=<CAP>" "--c=<CFF>" "--d=<CFP>" "--e=<CI>" "--f=<CPF>" "--g=<CPP>" "--h=<CPR>" "--i=<CPN>" "--j=<CPO>" "--k=<CPFS>"
|
"--a=<CAF>" "--b=<CAP>" "--c=<CFF>" "--d=<CFP>" "--e=<CI>" "--f=<CPF>" "--g=<CPP>" "--h=<CPR>" "--i=<CPN>" "--j=<CPO>" "--k=<CPFS>" "--l=<CPCD>"
|
||||||
|
|
||||||
as parameters in "Run, Compile and Run file..."
|
as parameters in "Run, Compile and Run file..."
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void main(string args[])
|
void main(string[] args)
|
||||||
{
|
{
|
||||||
auto opt2symbol = [
|
auto opt2symbol = [
|
||||||
// coedit
|
// coedit
|
||||||
|
@ -27,7 +27,8 @@ void main(string args[])
|
||||||
'h' : "CurrentProjectRoot.....: ",
|
'h' : "CurrentProjectRoot.....: ",
|
||||||
'i' : "CurrentProjectName.....: ",
|
'i' : "CurrentProjectName.....: ",
|
||||||
'j' : "CurrentProjectOutput...: ",
|
'j' : "CurrentProjectOutput...: ",
|
||||||
'k' : "CurrentProjectFiles....: "
|
'k' : "CurrentProjectFiles....: ",
|
||||||
|
'l' : "CurrentProjectCommonSourceDirectory....: "
|
||||||
];
|
];
|
||||||
|
|
||||||
string expanded;
|
string expanded;
|
||||||
|
|
|
@ -12,7 +12,7 @@ type
|
||||||
(**
|
(**
|
||||||
* Enumerates the symbol kinds, used to index an associative array.
|
* Enumerates the symbol kinds, used to index an associative array.
|
||||||
*)
|
*)
|
||||||
TCESymbol = (CAF, CAP, CFF, CFP, CI, CPF, CPP, CPO, CPR, CPN, CPFS);
|
TCESymbol = (CAF, CAP, CFF, CFP, CI, CPF, CPP, CPO, CPR, CPN, CPFS, CPCD);
|
||||||
|
|
||||||
(**
|
(**
|
||||||
* TCESymbolExpander is designed to expand Coedit symbolic strings,
|
* TCESymbolExpander is designed to expand Coedit symbolic strings,
|
||||||
|
@ -22,6 +22,7 @@ type
|
||||||
private
|
private
|
||||||
fProj: TCEProject;
|
fProj: TCEProject;
|
||||||
fDoc: TCESynMemo;
|
fDoc: TCESynMemo;
|
||||||
|
fNeedUpdate: boolean;
|
||||||
fSymbols: array[TCESymbol] of string;
|
fSymbols: array[TCESymbol] of string;
|
||||||
procedure updateSymbols;
|
procedure updateSymbols;
|
||||||
//
|
//
|
||||||
|
@ -54,10 +55,12 @@ uses
|
||||||
constructor TCESymbolExpander.Create;
|
constructor TCESymbolExpander.Create;
|
||||||
begin
|
begin
|
||||||
EntitiesConnector.addObserver(self);
|
EntitiesConnector.addObserver(self);
|
||||||
|
fNeedUpdate := true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TCESymbolExpander.Destroy;
|
destructor TCESymbolExpander.Destroy;
|
||||||
begin
|
begin
|
||||||
|
fNeedUpdate := false;
|
||||||
EntitiesConnector.removeObserver(self);
|
EntitiesConnector.removeObserver(self);
|
||||||
inherited;
|
inherited;
|
||||||
end;
|
end;
|
||||||
|
@ -68,6 +71,7 @@ end;
|
||||||
procedure TCESymbolExpander.projNew(aProject: TCEProject);
|
procedure TCESymbolExpander.projNew(aProject: TCEProject);
|
||||||
begin
|
begin
|
||||||
fProj := aProject;
|
fProj := aProject;
|
||||||
|
fNeedUpdate := true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCESymbolExpander.projClosing(aProject: TCEProject);
|
procedure TCESymbolExpander.projClosing(aProject: TCEProject);
|
||||||
|
@ -75,17 +79,20 @@ begin
|
||||||
if fProj <> aProject then
|
if fProj <> aProject then
|
||||||
exit;
|
exit;
|
||||||
fProj := nil;
|
fProj := nil;
|
||||||
|
fNeedUpdate := true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCESymbolExpander.projFocused(aProject: TCEProject);
|
procedure TCESymbolExpander.projFocused(aProject: TCEProject);
|
||||||
begin
|
begin
|
||||||
fProj := aProject;
|
fProj := aProject;
|
||||||
|
fNeedUpdate := true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCESymbolExpander.projChanged(aProject: TCEProject);
|
procedure TCESymbolExpander.projChanged(aProject: TCEProject);
|
||||||
begin
|
begin
|
||||||
if fProj <> aProject then
|
if fProj <> aProject then
|
||||||
exit;
|
exit;
|
||||||
|
fNeedUpdate := true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCESymbolExpander.projCompiling(aProject: TCEProject);
|
procedure TCESymbolExpander.projCompiling(aProject: TCEProject);
|
||||||
|
@ -98,6 +105,7 @@ end;
|
||||||
procedure TCESymbolExpander.docNew(aDoc: TCESynMemo);
|
procedure TCESymbolExpander.docNew(aDoc: TCESynMemo);
|
||||||
begin
|
begin
|
||||||
fDoc := aDoc;
|
fDoc := aDoc;
|
||||||
|
fNeedUpdate := true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCESymbolExpander.docClosing(aDoc: TCESynMemo);
|
procedure TCESymbolExpander.docClosing(aDoc: TCESynMemo);
|
||||||
|
@ -105,17 +113,22 @@ begin
|
||||||
if aDoc <> fDoc then
|
if aDoc <> fDoc then
|
||||||
exit;
|
exit;
|
||||||
fDoc := nil;
|
fDoc := nil;
|
||||||
|
fNeedUpdate := true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCESymbolExpander.docFocused(aDoc: TCESynMemo);
|
procedure TCESymbolExpander.docFocused(aDoc: TCESynMemo);
|
||||||
begin
|
begin
|
||||||
|
if (aDoc <> nil) and (fDoc = aDoc) then
|
||||||
|
exit;
|
||||||
fDoc := aDoc;
|
fDoc := aDoc;
|
||||||
|
fNeedUpdate := true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCESymbolExpander.docChanged(aDoc: TCESynMemo);
|
procedure TCESymbolExpander.docChanged(aDoc: TCESynMemo);
|
||||||
begin
|
begin
|
||||||
if aDoc <> fDoc then
|
if aDoc <> fDoc then
|
||||||
exit;
|
exit;
|
||||||
|
fNeedUpdate := true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{$ENDREGION}
|
{$ENDREGION}
|
||||||
|
@ -127,9 +140,12 @@ var
|
||||||
hasDoc: boolean;
|
hasDoc: boolean;
|
||||||
fname: string;
|
fname: string;
|
||||||
i: Integer;
|
i: Integer;
|
||||||
|
str: TStringList;
|
||||||
const
|
const
|
||||||
na = '``';
|
na = '``';
|
||||||
begin
|
begin
|
||||||
|
if not fNeedUpdate then exit;
|
||||||
|
fNeedUpdate := false;
|
||||||
hasProj := fProj <> nil;
|
hasProj := fProj <> nil;
|
||||||
hasDoc := fDoc <> nil;
|
hasDoc := fDoc <> nil;
|
||||||
// application
|
// application
|
||||||
|
@ -180,19 +196,28 @@ begin
|
||||||
fSymbols[CPN] := na;
|
fSymbols[CPN] := na;
|
||||||
fSymbols[CPO] := na;
|
fSymbols[CPO] := na;
|
||||||
end;
|
end;
|
||||||
fSymbols[CPFS] := '';
|
|
||||||
for i := 0 to fProj.Sources.Count - 1 do
|
|
||||||
begin
|
|
||||||
fname := fProj.getAbsoluteSourceName(i);
|
|
||||||
if dExtList.IndexOf(ExtractFileExt(fname)) = -1 then
|
|
||||||
continue;
|
|
||||||
fSymbols[CPFS] += fname;
|
|
||||||
if fProj.Sources.Count > 1 then
|
|
||||||
if i <> fProj.Sources.Count - 1 then
|
|
||||||
fSymbols[CPFS] += LineEnding;
|
|
||||||
end;
|
|
||||||
if fProj.Sources.Count = 0 then
|
if fProj.Sources.Count = 0 then
|
||||||
|
begin
|
||||||
fSymbols[CPFS] := na;
|
fSymbols[CPFS] := na;
|
||||||
|
fSymbols[CPCD] := na;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
str := TStringList.Create;
|
||||||
|
try
|
||||||
|
for i := 0 to fProj.Sources.Count-1 do
|
||||||
|
begin
|
||||||
|
fname := fProj.getAbsoluteSourceName(i);
|
||||||
|
if dExtList.IndexOf(ExtractFileExt(fname)) = -1 then
|
||||||
|
continue;
|
||||||
|
str.Add(fname);
|
||||||
|
end;
|
||||||
|
fSymbols[CPFS] := str.Text;
|
||||||
|
fSymbols[CPCD] := commonFolder(str);
|
||||||
|
finally
|
||||||
|
str.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
|
@ -202,6 +227,7 @@ begin
|
||||||
fSymbols[CPN] := na;
|
fSymbols[CPN] := na;
|
||||||
fSymbols[CPO] := na;
|
fSymbols[CPO] := na;
|
||||||
fSymbols[CPFS] := na;
|
fSymbols[CPFS] := na;
|
||||||
|
fSymbols[CPCD] := na;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -215,8 +241,8 @@ begin
|
||||||
Result := '';
|
Result := '';
|
||||||
if symString = '' then
|
if symString = '' then
|
||||||
exit;
|
exit;
|
||||||
updateSymbols;
|
|
||||||
//
|
//
|
||||||
|
updateSymbols;
|
||||||
elems := TStringList.Create;
|
elems := TStringList.Create;
|
||||||
try
|
try
|
||||||
i := 0;
|
i := 0;
|
||||||
|
@ -236,7 +262,7 @@ begin
|
||||||
begin
|
begin
|
||||||
begs := False;
|
begs := False;
|
||||||
ends := False;
|
ends := False;
|
||||||
// elem.obj is a flag to diferenciate symbols from elements
|
// elem.obj is a flag to differenciate symbols from elements
|
||||||
elems.Objects[elems.Count - 1] := Self;
|
elems.Objects[elems.Count - 1] := Self;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
@ -264,6 +290,7 @@ begin
|
||||||
'CPO', 'CurrentProjectOutput': Result += fSymbols[CPO];
|
'CPO', 'CurrentProjectOutput': Result += fSymbols[CPO];
|
||||||
'CPP', 'CurrentProjectPath': Result += fSymbols[CPP];
|
'CPP', 'CurrentProjectPath': Result += fSymbols[CPP];
|
||||||
'CPR', 'CurrentProjectRoot': Result += fSymbols[CPR];
|
'CPR', 'CurrentProjectRoot': Result += fSymbols[CPR];
|
||||||
|
'CPCD','CurrentProjectCommonDirectory': Result += fSymbols[CPCD];
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
finally
|
finally
|
||||||
|
|
Loading…
Reference in New Issue