IDE: started code macro AddMissingEnd

git-svn-id: trunk@12000 -
This commit is contained in:
mattias 2007-09-11 23:57:27 +00:00
parent 144f93a6fe
commit 70c926401f

View File

@ -34,7 +34,7 @@ uses
Classes, SysUtils, LCLProc, LResources, Forms, Controls, Graphics, Dialogs, Classes, SysUtils, LCLProc, LResources, Forms, Controls, Graphics, Dialogs,
ClipBrd, StdCtrls, Buttons, ExtCtrls, Menus, FileUtil, ClipBrd, StdCtrls, Buttons, ExtCtrls, Menus, FileUtil,
SynEdit, SynHighlighterPas, SynEditAutoComplete, CodeToolManager, CodeCache, SynEdit, SynHighlighterPas, SynEditAutoComplete, CodeToolManager, CodeCache,
PascalParserTool, KeywordFuncLists, BasicCodeTools, PascalParserTool,
IDECommands, TextTools, SrcEditorIntf, MenuIntf, IDEWindowIntf, LazIDEIntf, IDECommands, TextTools, SrcEditorIntf, MenuIntf, IDEWindowIntf, LazIDEIntf,
IDEProcs, InputHistory, LazarusIDEStrConsts, EditorOptions, CodeMacroSelect; IDEProcs, InputHistory, LazarusIDEStrConsts, EditorOptions, CodeMacroSelect;
@ -161,6 +161,11 @@ function CodeMacroDateTime(const Parameter: string;
InteractiveValue: TPersistent; InteractiveValue: TPersistent;
SrcEdit: TSourceEditorInterface; SrcEdit: TSourceEditorInterface;
var Value, ErrorMsg: string): boolean; var Value, ErrorMsg: string): boolean;
function CodeMacroAddMissingEnd(const Parameter: string;
InteractiveValue: TPersistent;
SrcEdit: TSourceEditorInterface;
var Value, ErrorMsg: string): boolean;
const const
CodeTemplatesMenuRootName = 'CodeTemplates'; CodeTemplatesMenuRootName = 'CodeTemplates';
@ -278,45 +283,45 @@ begin
Attributes:=[]; Attributes:=[];
for i:=0 to Params.Count-1 do begin for i:=0 to Params.Count-1 do begin
Param:=Params[i]; Param:=Params[i];
if CompareText(Param,'WithStart')=0 then if SysUtils.CompareText(Param,'WithStart')=0 then
Include(Attributes,phpWithStart) Include(Attributes,phpWithStart)
else if CompareText(Param,'WithStart')=0 then else if SysUtils.CompareText(Param,'WithStart')=0 then
Include(Attributes,phpWithStart) Include(Attributes,phpWithStart)
else if CompareText(Param,'WithoutClassKeyword')=0 then else if SysUtils.CompareText(Param,'WithoutClassKeyword')=0 then
Include(Attributes,phpWithoutClassKeyword) Include(Attributes,phpWithoutClassKeyword)
else if CompareText(Param,'AddClassName')=0 then else if SysUtils.CompareText(Param,'AddClassName')=0 then
Include(Attributes,phpAddClassName) Include(Attributes,phpAddClassName)
else if CompareText(Param,'WithoutClassName')=0 then else if SysUtils.CompareText(Param,'WithoutClassName')=0 then
Include(Attributes,phpWithoutClassName) Include(Attributes,phpWithoutClassName)
else if CompareText(Param,'WithoutName')=0 then else if SysUtils.CompareText(Param,'WithoutName')=0 then
Include(Attributes,phpWithoutName) Include(Attributes,phpWithoutName)
else if CompareText(Param,'WithoutParamList')=0 then else if SysUtils.CompareText(Param,'WithoutParamList')=0 then
Include(Attributes,phpWithoutParamList) Include(Attributes,phpWithoutParamList)
else if CompareText(Param,'WithVarModifiers')=0 then else if SysUtils.CompareText(Param,'WithVarModifiers')=0 then
Include(Attributes,phpWithVarModifiers) Include(Attributes,phpWithVarModifiers)
else if CompareText(Param,'WithParameterNames')=0 then else if SysUtils.CompareText(Param,'WithParameterNames')=0 then
Include(Attributes,phpWithParameterNames) Include(Attributes,phpWithParameterNames)
else if CompareText(Param,'WithoutParamTypes')=0 then else if SysUtils.CompareText(Param,'WithoutParamTypes')=0 then
Include(Attributes,phpWithoutParamTypes) Include(Attributes,phpWithoutParamTypes)
else if CompareText(Param,'WithDefaultValues')=0 then else if SysUtils.CompareText(Param,'WithDefaultValues')=0 then
Include(Attributes,phpWithDefaultValues) Include(Attributes,phpWithDefaultValues)
else if CompareText(Param,'WithResultType')=0 then else if SysUtils.CompareText(Param,'WithResultType')=0 then
Include(Attributes,phpWithResultType) Include(Attributes,phpWithResultType)
else if CompareText(Param,'WithOfObject')=0 then else if SysUtils.CompareText(Param,'WithOfObject')=0 then
Include(Attributes,phpWithOfObject) Include(Attributes,phpWithOfObject)
else if CompareText(Param,'WithCallingSpecs')=0 then else if SysUtils.CompareText(Param,'WithCallingSpecs')=0 then
Include(Attributes,phpWithCallingSpecs) Include(Attributes,phpWithCallingSpecs)
else if CompareText(Param,'WithProcModifiers')=0 then else if SysUtils.CompareText(Param,'WithProcModifiers')=0 then
Include(Attributes,phpWithProcModifiers) Include(Attributes,phpWithProcModifiers)
else if CompareText(Param,'WithComments')=0 then else if SysUtils.CompareText(Param,'WithComments')=0 then
Include(Attributes,phpWithComments) Include(Attributes,phpWithComments)
else if CompareText(Param,'InUpperCase')=0 then else if SysUtils.CompareText(Param,'InUpperCase')=0 then
Include(Attributes,phpInUpperCase) Include(Attributes,phpInUpperCase)
else if CompareText(Param,'CommentsToSpace')=0 then else if SysUtils.CompareText(Param,'CommentsToSpace')=0 then
Include(Attributes,phpCommentsToSpace) Include(Attributes,phpCommentsToSpace)
else if CompareText(Param,'WithoutBrackets')=0 then else if SysUtils.CompareText(Param,'WithoutBrackets')=0 then
Include(Attributes,phpWithoutBrackets) Include(Attributes,phpWithoutBrackets)
else if CompareText(Param,'WithoutSemicolon')=0 then else if SysUtils.CompareText(Param,'WithoutSemicolon')=0 then
Include(Attributes,phpWithoutSemicolon) Include(Attributes,phpWithoutSemicolon)
else begin else begin
Result:=false; Result:=false;
@ -385,6 +390,38 @@ begin
Result:=true; Result:=true;
end; end;
function CodeMacroAddMissingEnd(const Parameter: string;
InteractiveValue: TPersistent; SrcEdit: TSourceEditorInterface; var Value,
ErrorMsg: string): boolean;
var
Line: String;
p: TPoint;
begin
Result:=true;
Value:='';
Line:=SrcEdit.CurrentLineText;
p:=SrcEdit.CursorTextXY;
if p.y<1 then exit;
while (p.y<=SrcEdit.LineCount) do begin
Line:=SrcEdit.Lines[p.y-1];
while (p.x<=length(Line)) do begin
if IsSpaceChar[Line[p.x]] then
inc(p.x)
else begin
if CompareIdentifiers(@Line[p.x],'end')=0 then begin
// has already an end
exit;
end else begin
// missing end
Value:=LineEnding+'end;'+LineEnding;
end;
end;
end;
inc(p.y);
p.x:=1;
end;
end;
procedure RegisterStandardCodeTemplatesMenuItems; procedure RegisterStandardCodeTemplatesMenuItems;
var var
Path: string; Path: string;
@ -449,6 +486,10 @@ begin
RegisterCodeMacro('DateTime','insert date and time', RegisterCodeMacro('DateTime','insert date and time',
'Insert date and time. Optional: format string', 'Insert date and time. Optional: format string',
@CodeMacroDateTime,nil); @CodeMacroDateTime,nil);
RegisterCodeMacro('AddMissingEnd','insert end if needed',
'check if the next token in source'
+' is an end and if not returns lineend + end; + lineend',
@CodeMacroAddMissingEnd,nil);
end; end;
{ TCodeTemplateEditForm } { TCodeTemplateEditForm }
@ -1009,7 +1050,7 @@ begin
i:=Count-1; i:=Count-1;
while (i>=0) do begin while (i>=0) do begin
Result:=Items[i]; Result:=Items[i];
if (CompareText(Result.Name,AName)=0) then exit; if (SysUtils.CompareText(Result.Name,AName)=0) then exit;
dec(i); dec(i);
end; end;
Result:=nil; Result:=nil;