mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-03 22:20:17 +02:00
IDE: implemented code macro ofall
git-svn-id: trunk@19654 -
This commit is contained in:
parent
2e228a8d7f
commit
46cf4464ea
@ -401,6 +401,8 @@ type
|
|||||||
function FindAbstractMethods(Code: TCodeBuffer; X,Y: integer;
|
function FindAbstractMethods(Code: TCodeBuffer; X,Y: integer;
|
||||||
out ListOfPCodeXYPosition: TFPList;
|
out ListOfPCodeXYPosition: TFPList;
|
||||||
SkipAbstractsInStartClass: boolean = false): boolean;
|
SkipAbstractsInStartClass: boolean = false): boolean;
|
||||||
|
function GetValuesOfCaseVariable(Code: TCodeBuffer; X,Y: integer;
|
||||||
|
List: TStrings): boolean;
|
||||||
|
|
||||||
// rename identifier
|
// rename identifier
|
||||||
function FindReferences(IdentifierCode: TCodeBuffer;
|
function FindReferences(IdentifierCode: TCodeBuffer;
|
||||||
@ -2089,6 +2091,26 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TCodeToolManager.GetValuesOfCaseVariable(Code: TCodeBuffer; X,
|
||||||
|
Y: integer; List: TStrings): boolean;
|
||||||
|
var
|
||||||
|
CursorPos: TCodeXYPosition;
|
||||||
|
begin
|
||||||
|
{$IFDEF CTDEBUG}
|
||||||
|
DebugLn('TCodeToolManager.GetValuesOfCaseVariable A ',Code.Filename);
|
||||||
|
{$ENDIF}
|
||||||
|
Result:=false;
|
||||||
|
if not InitCurCodeTool(Code) then exit;
|
||||||
|
CursorPos.X:=X;
|
||||||
|
CursorPos.Y:=Y;
|
||||||
|
CursorPos.Code:=Code;
|
||||||
|
try
|
||||||
|
Result:=FCurCodeTool.GetValuesOfCaseVariable(CursorPos,List);
|
||||||
|
except
|
||||||
|
on e: Exception do Result:=HandleException(e);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
function TCodeToolManager.FindReferences(IdentifierCode: TCodeBuffer;
|
function TCodeToolManager.FindReferences(IdentifierCode: TCodeBuffer;
|
||||||
X, Y: integer; TargetCode: TCodeBuffer; SkipComments: boolean;
|
X, Y: integer; TargetCode: TCodeBuffer; SkipComments: boolean;
|
||||||
var ListOfPCodeXYPosition: TFPList): boolean;
|
var ListOfPCodeXYPosition: TFPList): boolean;
|
||||||
|
@ -981,7 +981,7 @@ function ExprTypeToString(const ExprType: TExpressionType): string;
|
|||||||
begin
|
begin
|
||||||
Result:='Desc='+ExpressionTypeDescNames[ExprType.Desc]
|
Result:='Desc='+ExpressionTypeDescNames[ExprType.Desc]
|
||||||
+' SubDesc='+ExpressionTypeDescNames[ExprType.SubDesc]
|
+' SubDesc='+ExpressionTypeDescNames[ExprType.SubDesc]
|
||||||
+FindContextToString(ExprType.Context);
|
+' '+FindContextToString(ExprType.Context);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function CreateExpressionType(const Desc, SubDesc: TExpressionTypeDesc;
|
function CreateExpressionType(const Desc, SubDesc: TExpressionTypeDesc;
|
||||||
|
@ -332,6 +332,8 @@ type
|
|||||||
function FindAbstractMethods(const CursorPos: TCodeXYPosition;
|
function FindAbstractMethods(const CursorPos: TCodeXYPosition;
|
||||||
out ListOfPCodeXYPosition: TFPList;
|
out ListOfPCodeXYPosition: TFPList;
|
||||||
SkipAbstractsInStartClass: boolean = false): boolean;
|
SkipAbstractsInStartClass: boolean = false): boolean;
|
||||||
|
function GetValuesOfCaseVariable(const CursorPos: TCodeXYPosition;
|
||||||
|
List: TStrings): boolean;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
const
|
const
|
||||||
@ -1936,6 +1938,89 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TIdentCompletionTool.GetValuesOfCaseVariable(
|
||||||
|
const CursorPos: TCodeXYPosition; List: TStrings): boolean;
|
||||||
|
var
|
||||||
|
CleanCursorPos: integer;
|
||||||
|
CursorNode: TCodeTreeNode;
|
||||||
|
CaseAtom: TAtomPosition;
|
||||||
|
Params: TFindDeclarationParams;
|
||||||
|
EndPos: LongInt;
|
||||||
|
ExprType: TExpressionType;
|
||||||
|
Node: TCodeTreeNode;
|
||||||
|
Tool: TFindDeclarationTool;
|
||||||
|
begin
|
||||||
|
Result:=false;
|
||||||
|
ActivateGlobalWriteLock;
|
||||||
|
Params:=nil;
|
||||||
|
try
|
||||||
|
BuildTreeAndGetCleanPos(trTillCursor,CursorPos,CleanCursorPos,
|
||||||
|
[{$IFNDEF DisableIgnoreErrorAfter}btSetIgnoreErrorPos{$ENDIF}]);
|
||||||
|
|
||||||
|
// find node at position
|
||||||
|
CursorNode:=BuildSubTreeAndFindDeepestNodeAtPos(CleanCursorPos,true);
|
||||||
|
|
||||||
|
// find keyword case
|
||||||
|
MoveCursorToNodeStart(CursorNode);
|
||||||
|
CaseAtom:=CleanAtomPosition;
|
||||||
|
repeat
|
||||||
|
ReadNextAtom;
|
||||||
|
if UpAtomIs('CASE') then
|
||||||
|
CaseAtom:=CurPos
|
||||||
|
until (CurPos.EndPos>SrcLen) or (CurPos.EndPos>CleanCursorPos);
|
||||||
|
if CaseAtom.StartPos<1 then exit;
|
||||||
|
|
||||||
|
// find case variable
|
||||||
|
EndPos:=FindEndOfExpression(CaseAtom.EndPos);
|
||||||
|
if EndPos>CleanCursorPos then
|
||||||
|
EndPos:=CleanCursorPos;
|
||||||
|
//DebugLn(['TIdentCompletionTool.GetValuesOfCaseVariable Expr=',dbgstr(copy(Src,CaseAtom.EndPos,EndPos-CaseAtom.EndPos))]);
|
||||||
|
|
||||||
|
Params:=TFindDeclarationParams.Create;
|
||||||
|
Params.ContextNode:=CursorNode;
|
||||||
|
Params.Flags:=fdfGlobals+fdfDefaultForExpressions;
|
||||||
|
ExprType:=FindExpressionTypeOfVariable(CaseAtom.EndPos,EndPos,Params,true);
|
||||||
|
//DebugLn(['TIdentCompletionTool.GetValuesOfCaseVariable Type=',ExprTypeToString(ExprType)]);
|
||||||
|
|
||||||
|
case ExprType.Desc of
|
||||||
|
|
||||||
|
xtBoolean,xtByteBool,xtLongBool:
|
||||||
|
begin
|
||||||
|
List.Add('True');
|
||||||
|
List.Add('False');
|
||||||
|
end;
|
||||||
|
|
||||||
|
xtContext:
|
||||||
|
begin
|
||||||
|
Node:=ExprType.Context.Node;
|
||||||
|
Tool:=ExprType.Context.Tool;
|
||||||
|
if Node=nil then exit;
|
||||||
|
case Node.Desc of
|
||||||
|
|
||||||
|
ctnEnumerationType:
|
||||||
|
begin
|
||||||
|
Node:=Node.FirstChild;
|
||||||
|
while Node<>nil do begin
|
||||||
|
List.Add(GetIdentifier(@Tool.Src[Node.StartPos]));
|
||||||
|
Node:=Node.NextBrother;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
else
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
else
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
|
||||||
|
Result:=true;
|
||||||
|
finally
|
||||||
|
Params.Free;
|
||||||
|
DeactivateGlobalWriteLock;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
{ TIdentifierListItem }
|
{ TIdentifierListItem }
|
||||||
|
|
||||||
function TIdentifierListItem.GetParamList: string;
|
function TIdentifierListItem.GetParamList: string;
|
||||||
|
@ -174,14 +174,16 @@ function CodeMacroDate(const Parameter: string; InteractiveValue: TPersistent;
|
|||||||
function CodeMacroTime(const Parameter: string; InteractiveValue: TPersistent;
|
function CodeMacroTime(const Parameter: string; InteractiveValue: TPersistent;
|
||||||
SrcEdit: TSourceEditorInterface;
|
SrcEdit: TSourceEditorInterface;
|
||||||
var Value, ErrorMsg: string): boolean;
|
var Value, ErrorMsg: string): boolean;
|
||||||
function CodeMacroDateTime(const Parameter: string;
|
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;
|
function CodeMacroAddMissingEnd(const Parameter: string;
|
||||||
InteractiveValue: TPersistent;
|
InteractiveValue: TPersistent;
|
||||||
SrcEdit: TSourceEditorInterface;
|
SrcEdit: TSourceEditorInterface;
|
||||||
var Value, ErrorMsg: string): boolean;
|
var Value, ErrorMsg: string): boolean;
|
||||||
|
function CodeMacroOfAll(const Parameter: string; InteractiveValue: TPersistent;
|
||||||
|
SrcEdit: TSourceEditorInterface;
|
||||||
|
var Value, ErrorMsg: string): boolean;
|
||||||
|
|
||||||
|
|
||||||
const
|
const
|
||||||
@ -465,6 +467,55 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function CodeMacroOfAll(const Parameter: string; InteractiveValue: TPersistent;
|
||||||
|
SrcEdit: TSourceEditorInterface; var Value, ErrorMsg: string): boolean;
|
||||||
|
// completes
|
||||||
|
// case SomeEnum of
|
||||||
|
// <list of enums>
|
||||||
|
// end;
|
||||||
|
var
|
||||||
|
List: TStrings;
|
||||||
|
Code: TCodeBuffer;
|
||||||
|
CaretXY: TPoint;
|
||||||
|
p: integer;
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
List:=TStringList.Create;
|
||||||
|
try
|
||||||
|
CaretXY:=SrcEdit.CursorTextXY;
|
||||||
|
Code:=SrcEdit.CodeToolsBuffer as TCodeBuffer;
|
||||||
|
Code.LineColToPosition(CaretXY.Y,CaretXY.X,p);
|
||||||
|
if p<1 then begin
|
||||||
|
ErrorMsg:='outside of code';
|
||||||
|
exit(false);
|
||||||
|
end;
|
||||||
|
while (p>1) and (IsIdentChar[Code.Source[p-1]]) do
|
||||||
|
begin
|
||||||
|
dec(p);
|
||||||
|
dec(CaretXY.X);
|
||||||
|
end;
|
||||||
|
if not CodeToolBoss.GetValuesOfCaseVariable(
|
||||||
|
SrcEdit.CodeToolsBuffer as TCodeBuffer,
|
||||||
|
CaretXY.X,CaretXY.Y,List) then
|
||||||
|
begin
|
||||||
|
Result:=false;
|
||||||
|
ErrorMsg:=CodeToolBoss.ErrorMessage;
|
||||||
|
if ErrorMsg='' then
|
||||||
|
ErrorMsg:='missing case variable';
|
||||||
|
LazarusIDE.DoJumpToCodeToolBossError;
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
|
||||||
|
Value:='';
|
||||||
|
for i:=0 to List.Count-1 do
|
||||||
|
Value:=Value+List[i]+': ;'+LineEnding;
|
||||||
|
finally
|
||||||
|
List.Free;
|
||||||
|
end;
|
||||||
|
|
||||||
|
Result:=true;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure RegisterStandardCodeTemplatesMenuItems;
|
procedure RegisterStandardCodeTemplatesMenuItems;
|
||||||
var
|
var
|
||||||
Path: string;
|
Path: string;
|
||||||
@ -533,6 +584,9 @@ begin
|
|||||||
'check if the next token in source'
|
'check if the next token in source'
|
||||||
+' is an end and if not returns lineend + end; + lineend',
|
+' is an end and if not returns lineend + end; + lineend',
|
||||||
@CodeMacroAddMissingEnd,nil);
|
@CodeMacroAddMissingEnd,nil);
|
||||||
|
RegisterCodeMacro('OfAll','list of all case values',
|
||||||
|
'returns list of all values of case variable in front of variable',
|
||||||
|
@CodeMacroOfAll,nil);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TCodeTemplateEditForm }
|
{ TCodeTemplateEditForm }
|
||||||
|
@ -16,18 +16,19 @@ LazarusResources.Add('lazarus_dci_file','DCI',[
|
|||||||
+'[ife | if then (no begin/end) else (no begin/end)]'#10'if | then'#10#10'els'
|
+'[ife | if then (no begin/end) else (no begin/end)]'#10'if | then'#10#10'els'
|
||||||
+'e'#10'[ifeb | if then else]'#10'if | then begin'#10#10'end'#10'else begin'
|
+'e'#10'[ifeb | if then else]'#10'if | then begin'#10#10'end'#10'else begin'
|
||||||
+#10#10'end;'#10'[procedure | procedure declaration]'#10'procedure |();'#10'b'
|
+#10#10'end;'#10'[procedure | procedure declaration]'#10'procedure |();'#10'b'
|
||||||
+'egin'#10#10'end;'#10'[trye | try except]'#10'try'#10' | '#10'except'#10#10
|
+'egin'#10#10'end;'#10'[ofall | case of all enums]'#10'$(AttributesStart)'#10
|
||||||
+'end;'#10'[tryf | try finally]'#10'try'#10' | '#10'finally'#10#10'end;'#10
|
+'EnableMakros=true'#10'$(AttributesEnd)'#10'of'#10'|$OfAll()end;'#10'[trye |'
|
||||||
+'[trycf | try finally (with Create/Free)]'#10'|variable := typename.Create; '
|
+' try except]'#10'try'#10' | '#10'except'#10#10'end;'#10'[tryf | try finall'
|
||||||
+#10'try'#10#10'finally'#10' variable.Free;'#10'end;'#10'[whileb | while sta'
|
+'y]'#10'try'#10' | '#10'finally'#10#10'end;'#10'[trycf | try finally (with '
|
||||||
+'tement]'#10'while | do begin'#10#10'end;'#10'[whiles | while (no begin)]'#10
|
+'Create/Free)]'#10'|variable := typename.Create; '#10'try'#10#10'finally'#10
|
||||||
+'while | do'#10'[withb | with statement]'#10'with | do begin'#10#10'end;'#10
|
+' variable.Free;'#10'end;'#10'[whileb | while statement]'#10'while | do beg'
|
||||||
+'[b | begin end]'#10'begin'#10' |'#10'end;'#10'[withs | with (no begin)]'#10
|
+'in'#10#10'end;'#10'[whiles | while (no begin)]'#10'while | do'#10'[withb | '
|
||||||
+'with | do'#10'[hexc | HexStr(Cardinal(),8)]'#10'HexStr(Cardinal(|),8)'#10'['
|
+'with statement]'#10'with | do begin'#10#10'end;'#10'[b | begin end]'#10'beg'
|
||||||
+'be | begin end else begin end]'#10'begin'#10' |'#10'end else begin'#10#10
|
+'in'#10' |'#10'end;'#10'[withs | with (no begin)]'#10'with | do'#10'[hexc |'
|
||||||
+'end;'#10'[withc | with for components]'#10'with | do begin'#10' Name:='''''
|
+' HexStr(Cardinal(),8)]'#10'HexStr(Cardinal(|),8)'#10'[be | begin end else b'
|
||||||
+';'#10' Parent:=;'#10' Left:=;'#10' Top:=;'#10' Width:=;'#10' Height:=;'
|
+'egin end]'#10'begin'#10' |'#10'end else begin'#10#10'end;'#10'[withc | wit'
|
||||||
+#10' Caption:='''';'#10'end;'#10'[d | debugln]'#10'$(AttributesStart)'#10'E'
|
+'h for components]'#10'with | do begin'#10' Name:='''';'#10' Parent:=;'#10
|
||||||
+'nableMakros=true'#10'$(AttributesEnd)'#10'debugln([''$ProcedureName() ''|])'
|
+' Left:=;'#10' Top:=;'#10' Width:=;'#10' Height:=;'#10' Caption:='''';'
|
||||||
+';'#10
|
+#10'end;'#10'[d | debugln]'#10'$(AttributesStart)'#10'EnableMakros=true'#10
|
||||||
|
+'$(AttributesEnd)'#10'debugln([''$ProcedureName() ''|]);'#10
|
||||||
]);
|
]);
|
||||||
|
@ -71,6 +71,12 @@ procedure |();
|
|||||||
begin
|
begin
|
||||||
|
|
||||||
end;
|
end;
|
||||||
|
[ofall | case of all enums]
|
||||||
|
$(AttributesStart)
|
||||||
|
EnableMakros=true
|
||||||
|
$(AttributesEnd)
|
||||||
|
of
|
||||||
|
|$OfAll()end;
|
||||||
[trye | try except]
|
[trye | try except]
|
||||||
try
|
try
|
||||||
|
|
|
|
||||||
|
Loading…
Reference in New Issue
Block a user