mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-30 15:10:16 +02:00
fixed event assignment completion cursor pos
git-svn-id: trunk@8098 -
This commit is contained in:
parent
504f83432a
commit
cc1d35125b
@ -2475,7 +2475,7 @@ var CleanCursorPos, Indent, insertPos: integer;
|
|||||||
// read event name (optional)
|
// read event name (optional)
|
||||||
GetIdentStartEndAtPosition(Src,CleanCursorPos,
|
GetIdentStartEndAtPosition(Src,CleanCursorPos,
|
||||||
UserEventAtom.StartPos,UserEventAtom.EndPos);
|
UserEventAtom.StartPos,UserEventAtom.EndPos);
|
||||||
MoveCursorToCleanPos(UserEventAtom.StartPos);
|
MoveCursorToAtomPos(UserEventAtom);
|
||||||
if AtomIsKeyWord then exit;
|
if AtomIsKeyWord then exit;
|
||||||
ReadPriorAtom;
|
ReadPriorAtom;
|
||||||
// check @ operator (optional)
|
// check @ operator (optional)
|
||||||
@ -2695,13 +2695,13 @@ var CleanCursorPos, Indent, insertPos: integer;
|
|||||||
AMethodAttr: TProcHeadAttributes;
|
AMethodAttr: TProcHeadAttributes;
|
||||||
begin
|
begin
|
||||||
Result:=false;
|
Result:=false;
|
||||||
|
|
||||||
{$IFDEF CTDEBUG}
|
{$IFDEF CTDEBUG}
|
||||||
DebugLn(' CompleteEventAssignment: CheckEventAssignmentSyntax...');
|
DebugLn(' CompleteEventAssignment: CheckEventAssignmentSyntax...');
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
// check assigment syntax
|
// check assigment syntax
|
||||||
if not CheckEventAssignmentSyntax(PropertyAtom, AssignmentOperator,
|
if not CheckEventAssignmentSyntax(PropertyAtom, AssignmentOperator,
|
||||||
AddrOperatorPos, UserEventAtom, SemicolonPos)
|
AddrOperatorPos, UserEventAtom, SemicolonPos)
|
||||||
then
|
then
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
@ -2765,7 +2765,7 @@ begin
|
|||||||
while (CleanCursorPos>1) and (Src[CleanCursorPos] in [#10,#13]) do
|
while (CleanCursorPos>1) and (Src[CleanCursorPos] in [#10,#13]) do
|
||||||
dec(CleanCursorPos);
|
dec(CleanCursorPos);
|
||||||
// skip space (first try left)
|
// skip space (first try left)
|
||||||
while (CleanCursorPos>1) and (Src[CleanCursorPos] in [' ',#9,';']) do
|
while (CleanCursorPos>1) and (Src[CleanCursorPos-1] in [' ',#9,';']) do
|
||||||
dec(CleanCursorPos);
|
dec(CleanCursorPos);
|
||||||
if (CleanCursorPos>0) and (CleanCursorPos<SrcLen)
|
if (CleanCursorPos>0) and (CleanCursorPos<SrcLen)
|
||||||
and (Src[CleanCursorPos] in [#10,#13]) then begin
|
and (Src[CleanCursorPos] in [#10,#13]) then begin
|
||||||
@ -2796,7 +2796,7 @@ begin
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
|
||||||
// test if forward proc
|
// test if forward proc
|
||||||
debugln('TCodeCompletionCodeTool.CompleteCode ',CursorNode.DescAsString);
|
//debugln('TCodeCompletionCodeTool.CompleteCode ',CursorNode.DescAsString);
|
||||||
ProcNode:=CursorNode.GetNodeOfType(ctnProcedure);
|
ProcNode:=CursorNode.GetNodeOfType(ctnProcedure);
|
||||||
if (ProcNode=nil) and (CursorNode.Desc=ctnProcedure) then
|
if (ProcNode=nil) and (CursorNode.Desc=ctnProcedure) then
|
||||||
ProcNode:=CursorNode;
|
ProcNode:=CursorNode;
|
||||||
|
@ -1412,10 +1412,6 @@ begin
|
|||||||
|
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
case c2 of
|
|
||||||
'=': CurPos.Flag:=cafEqual;
|
|
||||||
'.': CurPos.Flag:=cafPoint;
|
|
||||||
end;
|
|
||||||
if CurPos.StartPos>1 then begin
|
if CurPos.StartPos>1 then begin
|
||||||
c1:=Src[CurPos.StartPos-1];
|
c1:=Src[CurPos.StartPos-1];
|
||||||
// test for double char operators :=, +=, -=, /=, *=, <>, <=, >=, **, ><
|
// test for double char operators :=, +=, -=, /=, *=, <>, <=, >=, **, ><
|
||||||
@ -1428,6 +1424,16 @@ begin
|
|||||||
then begin
|
then begin
|
||||||
dec(CurPos.StartPos);
|
dec(CurPos.StartPos);
|
||||||
CurPos.Flag:=cafNone;
|
CurPos.Flag:=cafNone;
|
||||||
|
end else begin
|
||||||
|
case c2 of
|
||||||
|
'=': CurPos.Flag:=cafEqual;
|
||||||
|
'.': CurPos.Flag:=cafPoint;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end else begin
|
||||||
|
case c2 of
|
||||||
|
'=': CurPos.Flag:=cafEqual;
|
||||||
|
'.': CurPos.Flag:=cafPoint;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
@ -210,7 +210,7 @@ const
|
|||||||
end else begin
|
end else begin
|
||||||
// normal macro -> substitute
|
// normal macro -> substitute
|
||||||
NewValue:='';
|
NewValue:='';
|
||||||
if not Macro.GetValue(MacroValue,nil,NewValue,ErrMsg) then exit;
|
if not Macro.GetValue(MacroValue,nil,SrcEdit,NewValue,ErrMsg) then exit;
|
||||||
MacroValue:=NewValue;
|
MacroValue:=NewValue;
|
||||||
end;
|
end;
|
||||||
end else begin
|
end else begin
|
||||||
|
@ -118,10 +118,13 @@ procedure CreateStandardCodeMacros;
|
|||||||
|
|
||||||
// standard code macros
|
// standard code macros
|
||||||
function CodeMakroUpper(const Parameter: string; InteractiveValue: TPersistent;
|
function CodeMakroUpper(const Parameter: string; InteractiveValue: TPersistent;
|
||||||
|
SrcEdit: TSourceEditorInterface;
|
||||||
var Value, ErrorMsg: string): boolean;
|
var Value, ErrorMsg: string): boolean;
|
||||||
function CodeMakroLower(const Parameter: string; InteractiveValue: TPersistent;
|
function CodeMakroLower(const Parameter: string; InteractiveValue: TPersistent;
|
||||||
|
SrcEdit: TSourceEditorInterface;
|
||||||
var Value, ErrorMsg: string): boolean;
|
var Value, ErrorMsg: string): boolean;
|
||||||
function CodeMakroPaste(const Parameter: string; InteractiveValue: TPersistent;
|
function CodeMakroPaste(const Parameter: string; InteractiveValue: TPersistent;
|
||||||
|
SrcEdit: TSourceEditorInterface;
|
||||||
var Value, ErrorMsg: string): boolean;
|
var Value, ErrorMsg: string): boolean;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
@ -188,6 +191,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function CodeMakroUpper(const Parameter: string; InteractiveValue: TPersistent;
|
function CodeMakroUpper(const Parameter: string; InteractiveValue: TPersistent;
|
||||||
|
SrcEdit: TSourceEditorInterface;
|
||||||
var Value, ErrorMsg: string): boolean;
|
var Value, ErrorMsg: string): boolean;
|
||||||
begin
|
begin
|
||||||
Value:=UpperCase(Parameter);
|
Value:=UpperCase(Parameter);
|
||||||
@ -195,6 +199,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function CodeMakroLower(const Parameter: string; InteractiveValue: TPersistent;
|
function CodeMakroLower(const Parameter: string; InteractiveValue: TPersistent;
|
||||||
|
SrcEdit: TSourceEditorInterface;
|
||||||
var Value, ErrorMsg: string): boolean;
|
var Value, ErrorMsg: string): boolean;
|
||||||
begin
|
begin
|
||||||
Value:=LowerCase(Parameter);
|
Value:=LowerCase(Parameter);
|
||||||
@ -202,6 +207,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function CodeMakroPaste(const Parameter: string; InteractiveValue: TPersistent;
|
function CodeMakroPaste(const Parameter: string; InteractiveValue: TPersistent;
|
||||||
|
SrcEdit: TSourceEditorInterface;
|
||||||
var Value, ErrorMsg: string): boolean;
|
var Value, ErrorMsg: string): boolean;
|
||||||
begin
|
begin
|
||||||
Value:=Clipboard.AsText;
|
Value:=Clipboard.AsText;
|
||||||
|
@ -41,83 +41,9 @@ type
|
|||||||
|
|
||||||
var
|
var
|
||||||
// the global IDE values
|
// the global IDE values
|
||||||
IDEMacros: TIDEMacros; // set by the IDE
|
IDEMacros: TIDEMacros = nil; // set by the IDE
|
||||||
|
|
||||||
|
|
||||||
type
|
|
||||||
|
|
||||||
{ TIDEInteractiveStringValue }
|
|
||||||
|
|
||||||
TIDEInteractiveStringValue = class(TPersistent)
|
|
||||||
private
|
|
||||||
FValue: string;
|
|
||||||
published
|
|
||||||
property Value: string read FValue write FValue;
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
TIDECodeMacroGetValueProc = function(const Parameter: string;
|
|
||||||
InteractiveValue: TPersistent;
|
|
||||||
var Value, ErrorMsg: string): boolean;
|
|
||||||
TIDECodeMacroGetValueMethod = function(const Parameter: string;
|
|
||||||
InteractiveValue: TPersistent;
|
|
||||||
var Value, ErrorMsg: string): boolean of object;
|
|
||||||
|
|
||||||
{ TIDECodeMacro }
|
|
||||||
|
|
||||||
TIDECodeMacro = class
|
|
||||||
private
|
|
||||||
FInteractive: boolean;
|
|
||||||
FInteractiveValueClass: TPersistentClass;
|
|
||||||
FLongDescription: string;
|
|
||||||
FName: string;
|
|
||||||
FOnGetValueMethod: TIDECodeMacroGetValueMethod;
|
|
||||||
FOnGetValueProc: TIDECodeMacroGetValueProc;
|
|
||||||
FShortDescription: string;
|
|
||||||
protected
|
|
||||||
procedure Init; virtual;
|
|
||||||
public
|
|
||||||
constructor Create(const TheName: string);
|
|
||||||
property Name: string read FName;
|
|
||||||
property ShortDescription: string read FShortDescription write FShortDescription;
|
|
||||||
property LongDescription: string read FLongDescription write FLongDescription;
|
|
||||||
property OnGetValueProc: TIDECodeMacroGetValueProc read FOnGetValueProc
|
|
||||||
write FOnGetValueProc;
|
|
||||||
property OnGetValueMethod: TIDECodeMacroGetValueMethod read FOnGetValueMethod
|
|
||||||
write FOnGetValueMethod;
|
|
||||||
function GetValue(const Parameter: string; InteractiveValue: TPersistent;
|
|
||||||
out Value, ErrorMsg: string): boolean; virtual;
|
|
||||||
property Interactive: boolean read FInteractive write FInteractive;
|
|
||||||
property InteractiveValueClass: TPersistentClass read FInteractiveValueClass
|
|
||||||
write FInteractiveValueClass;
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
{ TIDECodeMacros }
|
|
||||||
|
|
||||||
TIDECodeMacros = class
|
|
||||||
protected
|
|
||||||
function GetItems(Index: integer): TIDECodeMacro; virtual; abstract;
|
|
||||||
public
|
|
||||||
property Items[Index: integer]: TIDECodeMacro read GetItems; default;
|
|
||||||
function Count: integer; virtual; abstract;
|
|
||||||
function Add(Macro: TIDECodeMacro): integer; virtual; abstract;
|
|
||||||
function FindByName(const AName: string): TIDECodeMacro; virtual; abstract;
|
|
||||||
function CreateUniqueName(const AName: string): string; virtual; abstract;
|
|
||||||
end;
|
|
||||||
|
|
||||||
var
|
|
||||||
IDECodeMacros: TIDECodeMacros = nil; // set by the IDE
|
|
||||||
|
|
||||||
const
|
|
||||||
CodeTemplateMakroMagic = '$(EnableMakros)';
|
|
||||||
|
|
||||||
|
|
||||||
function RegisterCodeMacro(const Name: string;
|
|
||||||
const ShortDescription, LongDescription: string;
|
|
||||||
OnGetValueProc: TIDECodeMacroGetValueProc;
|
|
||||||
OnGetValueMethod: TIDECodeMacroGetValueMethod): TIDECodeMacro;
|
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
const
|
const
|
||||||
@ -125,21 +51,6 @@ const
|
|||||||
MinStamp = -$7fffffff;
|
MinStamp = -$7fffffff;
|
||||||
InvalidStamp = MinStamp-1;
|
InvalidStamp = MinStamp-1;
|
||||||
|
|
||||||
function RegisterCodeMacro(const Name: string; const ShortDescription,
|
|
||||||
LongDescription: string; OnGetValueProc: TIDECodeMacroGetValueProc;
|
|
||||||
OnGetValueMethod: TIDECodeMacroGetValueMethod): TIDECodeMacro;
|
|
||||||
var
|
|
||||||
NewName: String;
|
|
||||||
begin
|
|
||||||
NewName:=IDECodeMacros.CreateUniqueName(Name);
|
|
||||||
Result:=TIDECodeMacro.Create(NewName);
|
|
||||||
Result.ShortDescription:=ShortDescription;
|
|
||||||
Result.LongDescription:=LongDescription;
|
|
||||||
Result.OnGetValueProc:=OnGetValueProc;
|
|
||||||
Result.OnGetValueMethod:=OnGetValueMethod;
|
|
||||||
IDECodeMacros.Add(Result);
|
|
||||||
end;
|
|
||||||
|
|
||||||
{ TIDEMacros }
|
{ TIDEMacros }
|
||||||
|
|
||||||
procedure TIDEMacros.IncreaseBaseStamp;
|
procedure TIDEMacros.IncreaseBaseStamp;
|
||||||
@ -168,35 +79,5 @@ begin
|
|||||||
Result:=true;
|
Result:=true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TIDECodeMacro }
|
|
||||||
|
|
||||||
procedure TIDECodeMacro.Init;
|
|
||||||
begin
|
|
||||||
FInteractiveValueClass:=TIDEInteractiveStringValue;
|
|
||||||
end;
|
|
||||||
|
|
||||||
constructor TIDECodeMacro.Create(const TheName: string);
|
|
||||||
begin
|
|
||||||
FName:=TheName;
|
|
||||||
FShortDescription:=FName;
|
|
||||||
FLongDescription:=FName;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TIDECodeMacro.GetValue(const Parameter: string;
|
|
||||||
InteractiveValue: TPersistent; out Value, ErrorMsg: string): boolean;
|
|
||||||
begin
|
|
||||||
Value:=Parameter;
|
|
||||||
ErrorMsg:='';
|
|
||||||
if Assigned(OnGetValueProc) then
|
|
||||||
Result:=OnGetValueProc(Parameter,InteractiveValue,Value,ErrorMsg)
|
|
||||||
else if Assigned(OnGetValueMethod) then
|
|
||||||
Result:=OnGetValueMethod(Parameter,InteractiveValue,Value,ErrorMsg)
|
|
||||||
else
|
|
||||||
Result:=true;
|
|
||||||
end;
|
|
||||||
|
|
||||||
initialization
|
|
||||||
IDEMacros:=nil;
|
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@ -123,11 +123,106 @@ type
|
|||||||
write SetActiveEditor;
|
write SetActiveEditor;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
var
|
var
|
||||||
SourceEditorWindow: TSourceEditorWindowInterface = nil;// set by the IDE
|
SourceEditorWindow: TSourceEditorWindowInterface = nil;// set by the IDE
|
||||||
|
|
||||||
|
|
||||||
|
type
|
||||||
|
|
||||||
|
{ TIDEInteractiveStringValue }
|
||||||
|
|
||||||
|
TIDEInteractiveStringValue = class(TPersistent)
|
||||||
|
private
|
||||||
|
FValue: string;
|
||||||
|
published
|
||||||
|
property Value: string read FValue write FValue;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
TIDECodeMacroGetValueProc = function(const Parameter: string;
|
||||||
|
InteractiveValue: TPersistent;
|
||||||
|
SrcEdit: TSourceEditorInterface;
|
||||||
|
var Value, ErrorMsg: string): boolean;
|
||||||
|
TIDECodeMacroGetValueMethod = function(const Parameter: string;
|
||||||
|
InteractiveValue: TPersistent;
|
||||||
|
SrcEdit: TSourceEditorInterface;
|
||||||
|
var Value, ErrorMsg: string): boolean of object;
|
||||||
|
|
||||||
|
{ TIDECodeMacro }
|
||||||
|
|
||||||
|
TIDECodeMacro = class
|
||||||
|
private
|
||||||
|
FInteractive: boolean;
|
||||||
|
FInteractiveValueClass: TPersistentClass;
|
||||||
|
FLongDescription: string;
|
||||||
|
FName: string;
|
||||||
|
FOnGetValueMethod: TIDECodeMacroGetValueMethod;
|
||||||
|
FOnGetValueProc: TIDECodeMacroGetValueProc;
|
||||||
|
FShortDescription: string;
|
||||||
|
protected
|
||||||
|
procedure Init; virtual;
|
||||||
|
public
|
||||||
|
constructor Create(const TheName: string);
|
||||||
|
property Name: string read FName;
|
||||||
|
property ShortDescription: string read FShortDescription write FShortDescription;
|
||||||
|
property LongDescription: string read FLongDescription write FLongDescription;
|
||||||
|
property OnGetValueProc: TIDECodeMacroGetValueProc read FOnGetValueProc
|
||||||
|
write FOnGetValueProc;
|
||||||
|
property OnGetValueMethod: TIDECodeMacroGetValueMethod read FOnGetValueMethod
|
||||||
|
write FOnGetValueMethod;
|
||||||
|
function GetValue(const Parameter: string; InteractiveValue: TPersistent;
|
||||||
|
SrcEdit: TSourceEditorInterface;
|
||||||
|
out Value, ErrorMsg: string): boolean; virtual;
|
||||||
|
property Interactive: boolean read FInteractive write FInteractive;
|
||||||
|
property InteractiveValueClass: TPersistentClass read FInteractiveValueClass
|
||||||
|
write FInteractiveValueClass;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
{ TIDECodeMacros }
|
||||||
|
|
||||||
|
TIDECodeMacros = class
|
||||||
|
protected
|
||||||
|
function GetItems(Index: integer): TIDECodeMacro; virtual; abstract;
|
||||||
|
public
|
||||||
|
property Items[Index: integer]: TIDECodeMacro read GetItems; default;
|
||||||
|
function Count: integer; virtual; abstract;
|
||||||
|
function Add(Macro: TIDECodeMacro): integer; virtual; abstract;
|
||||||
|
function FindByName(const AName: string): TIDECodeMacro; virtual; abstract;
|
||||||
|
function CreateUniqueName(const AName: string): string; virtual; abstract;
|
||||||
|
end;
|
||||||
|
|
||||||
|
var
|
||||||
|
IDECodeMacros: TIDECodeMacros = nil; // set by the IDE
|
||||||
|
|
||||||
|
const
|
||||||
|
CodeTemplateMakroMagic = '$(EnableMakros)';
|
||||||
|
|
||||||
|
|
||||||
|
function RegisterCodeMacro(const Name: string;
|
||||||
|
const ShortDescription, LongDescription: string;
|
||||||
|
OnGetValueProc: TIDECodeMacroGetValueProc;
|
||||||
|
OnGetValueMethod: TIDECodeMacroGetValueMethod): TIDECodeMacro;
|
||||||
|
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
|
function RegisterCodeMacro(const Name: string; const ShortDescription,
|
||||||
|
LongDescription: string; OnGetValueProc: TIDECodeMacroGetValueProc;
|
||||||
|
OnGetValueMethod: TIDECodeMacroGetValueMethod): TIDECodeMacro;
|
||||||
|
var
|
||||||
|
NewName: String;
|
||||||
|
begin
|
||||||
|
NewName:=IDECodeMacros.CreateUniqueName(Name);
|
||||||
|
Result:=TIDECodeMacro.Create(NewName);
|
||||||
|
Result.ShortDescription:=ShortDescription;
|
||||||
|
Result.LongDescription:=LongDescription;
|
||||||
|
Result.OnGetValueProc:=OnGetValueProc;
|
||||||
|
Result.OnGetValueMethod:=OnGetValueMethod;
|
||||||
|
IDECodeMacros.Add(Result);
|
||||||
|
end;
|
||||||
|
|
||||||
{ TSourceEditorInterface }
|
{ TSourceEditorInterface }
|
||||||
|
|
||||||
procedure TSourceEditorInterface.SelectText(LineNum, CharStart, LineNum2,
|
procedure TSourceEditorInterface.SelectText(LineNum, CharStart, LineNum2,
|
||||||
@ -147,5 +242,33 @@ begin
|
|||||||
EndUpdate;
|
EndUpdate;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TIDECodeMacro }
|
||||||
|
|
||||||
|
procedure TIDECodeMacro.Init;
|
||||||
|
begin
|
||||||
|
FInteractiveValueClass:=TIDEInteractiveStringValue;
|
||||||
|
end;
|
||||||
|
|
||||||
|
constructor TIDECodeMacro.Create(const TheName: string);
|
||||||
|
begin
|
||||||
|
FName:=TheName;
|
||||||
|
FShortDescription:=FName;
|
||||||
|
FLongDescription:=FName;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TIDECodeMacro.GetValue(const Parameter: string;
|
||||||
|
InteractiveValue: TPersistent; SrcEdit: TSourceEditorInterface;
|
||||||
|
out Value, ErrorMsg: string): boolean;
|
||||||
|
begin
|
||||||
|
Value:=Parameter;
|
||||||
|
ErrorMsg:='';
|
||||||
|
if Assigned(OnGetValueProc) then
|
||||||
|
Result:=OnGetValueProc(Parameter,InteractiveValue,SrcEdit,Value,ErrorMsg)
|
||||||
|
else if Assigned(OnGetValueMethod) then
|
||||||
|
Result:=OnGetValueMethod(Parameter,InteractiveValue,SrcEdit,Value,ErrorMsg)
|
||||||
|
else
|
||||||
|
Result:=true;
|
||||||
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user