mirror of https://gitlab.com/basile.b/dexed.git
static macros, validated with a regex
This commit is contained in:
parent
83338db48c
commit
6b954e0fe5
|
@ -5,7 +5,7 @@ unit ce_staticmacro;
|
||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, Sysutils, SynEdit, SynCompletion,
|
Classes, Sysutils, SynEdit, SynCompletion, RegExpr,
|
||||||
ce_common, ce_interfaces, ce_writableComponent, ce_synmemo;
|
ce_common, ce_interfaces, ce_writableComponent, ce_synmemo;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
@ -48,6 +48,7 @@ type
|
||||||
*)
|
*)
|
||||||
TCEStaticEditorMacro = class(TWritableLfmTextComponent, ICEMultiDocObserver, ICEEditableOptions, ICEEditableShortCut)
|
TCEStaticEditorMacro = class(TWritableLfmTextComponent, ICEMultiDocObserver, ICEEditableOptions, ICEEditableShortCut)
|
||||||
private
|
private
|
||||||
|
fValidator: TRegExpr;
|
||||||
fCompletor: TSynAutoComplete;
|
fCompletor: TSynAutoComplete;
|
||||||
fMacros: TStringList;
|
fMacros: TStringList;
|
||||||
fDoc: TCESynMemo;
|
fDoc: TCESynMemo;
|
||||||
|
@ -201,8 +202,11 @@ var
|
||||||
begin
|
begin
|
||||||
inherited;
|
inherited;
|
||||||
fAutomatic := true;
|
fAutomatic := true;
|
||||||
|
fValidator := TRegExpr.Create('^\$\w*[a-zA-Z]$');
|
||||||
|
fValidator.Compile;
|
||||||
fCompletor := TSynAutoComplete.Create(self);
|
fCompletor := TSynAutoComplete.Create(self);
|
||||||
fCompletor.ShortCut := 8224; // SHIFT + SPACE
|
fCompletor.ShortCut := 8224; // SHIFT + SPACE
|
||||||
|
fCompletor.EndOfTokenChr:= '';
|
||||||
fMacros := TStringList.Create;
|
fMacros := TStringList.Create;
|
||||||
fMacros.Delimiter := '=';
|
fMacros.Delimiter := '=';
|
||||||
//
|
//
|
||||||
|
@ -236,6 +240,7 @@ begin
|
||||||
EntitiesConnector.removeObserver(Self);
|
EntitiesConnector.removeObserver(Self);
|
||||||
//
|
//
|
||||||
fMacros.Free;
|
fMacros.Free;
|
||||||
|
fValidator.Free;
|
||||||
inherited;
|
inherited;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -349,23 +354,11 @@ end;
|
||||||
procedure TCEStaticEditorMacro.sanitize;
|
procedure TCEStaticEditorMacro.sanitize;
|
||||||
var
|
var
|
||||||
i: Integer;
|
i: Integer;
|
||||||
text: string;
|
|
||||||
macro: string;
|
|
||||||
begin
|
begin
|
||||||
for i := fMacros.Count-1 downto 0 do
|
for i := fMacros.Count-1 downto 0 do
|
||||||
begin
|
if not fValidator.Exec(fMacros.Names[i]) then
|
||||||
text := fMacros[i];
|
|
||||||
if text.length >= 4 then
|
|
||||||
if text[1] = '$' then
|
|
||||||
if Pos('=', text) > 2 then
|
|
||||||
begin
|
|
||||||
macro := fMacros.Names[i];
|
|
||||||
if (macro[macro.length] in ['a'..'z', 'A'..'Z', '0'..'9']) then
|
|
||||||
continue;
|
|
||||||
end;
|
|
||||||
fMacros.Delete(i);
|
fMacros.Delete(i);
|
||||||
end;
|
end;
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TCEStaticEditorMacro.addDefaults;
|
procedure TCEStaticEditorMacro.addDefaults;
|
||||||
var
|
var
|
||||||
|
|
Loading…
Reference in New Issue