fixed event assignment completion cursor pos

git-svn-id: trunk@8098 -
This commit is contained in:
mattias 2005-11-07 22:11:05 +00:00
parent 504f83432a
commit cc1d35125b
6 changed files with 146 additions and 130 deletions

View File

@ -2475,7 +2475,7 @@ var CleanCursorPos, Indent, insertPos: integer;
// read event name (optional)
GetIdentStartEndAtPosition(Src,CleanCursorPos,
UserEventAtom.StartPos,UserEventAtom.EndPos);
MoveCursorToCleanPos(UserEventAtom.StartPos);
MoveCursorToAtomPos(UserEventAtom);
if AtomIsKeyWord then exit;
ReadPriorAtom;
// check @ operator (optional)
@ -2695,13 +2695,13 @@ var CleanCursorPos, Indent, insertPos: integer;
AMethodAttr: TProcHeadAttributes;
begin
Result:=false;
{$IFDEF CTDEBUG}
DebugLn(' CompleteEventAssignment: CheckEventAssignmentSyntax...');
{$ENDIF}
// check assigment syntax
if not CheckEventAssignmentSyntax(PropertyAtom, AssignmentOperator,
AddrOperatorPos, UserEventAtom, SemicolonPos)
AddrOperatorPos, UserEventAtom, SemicolonPos)
then
exit;
@ -2765,7 +2765,7 @@ begin
while (CleanCursorPos>1) and (Src[CleanCursorPos] in [#10,#13]) do
dec(CleanCursorPos);
// 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);
if (CleanCursorPos>0) and (CleanCursorPos<SrcLen)
and (Src[CleanCursorPos] in [#10,#13]) then begin
@ -2796,7 +2796,7 @@ begin
{$ENDIF}
// test if forward proc
debugln('TCodeCompletionCodeTool.CompleteCode ',CursorNode.DescAsString);
//debugln('TCodeCompletionCodeTool.CompleteCode ',CursorNode.DescAsString);
ProcNode:=CursorNode.GetNodeOfType(ctnProcedure);
if (ProcNode=nil) and (CursorNode.Desc=ctnProcedure) then
ProcNode:=CursorNode;

View File

@ -1412,10 +1412,6 @@ begin
else
begin
case c2 of
'=': CurPos.Flag:=cafEqual;
'.': CurPos.Flag:=cafPoint;
end;
if CurPos.StartPos>1 then begin
c1:=Src[CurPos.StartPos-1];
// test for double char operators :=, +=, -=, /=, *=, <>, <=, >=, **, ><
@ -1428,6 +1424,16 @@ begin
then begin
dec(CurPos.StartPos);
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;

View File

@ -210,7 +210,7 @@ const
end else begin
// normal macro -> substitute
NewValue:='';
if not Macro.GetValue(MacroValue,nil,NewValue,ErrMsg) then exit;
if not Macro.GetValue(MacroValue,nil,SrcEdit,NewValue,ErrMsg) then exit;
MacroValue:=NewValue;
end;
end else begin

View File

@ -118,10 +118,13 @@ procedure CreateStandardCodeMacros;
// standard code macros
function CodeMakroUpper(const Parameter: string; InteractiveValue: TPersistent;
SrcEdit: TSourceEditorInterface;
var Value, ErrorMsg: string): boolean;
function CodeMakroLower(const Parameter: string; InteractiveValue: TPersistent;
SrcEdit: TSourceEditorInterface;
var Value, ErrorMsg: string): boolean;
function CodeMakroPaste(const Parameter: string; InteractiveValue: TPersistent;
SrcEdit: TSourceEditorInterface;
var Value, ErrorMsg: string): boolean;
implementation
@ -188,6 +191,7 @@ begin
end;
function CodeMakroUpper(const Parameter: string; InteractiveValue: TPersistent;
SrcEdit: TSourceEditorInterface;
var Value, ErrorMsg: string): boolean;
begin
Value:=UpperCase(Parameter);
@ -195,6 +199,7 @@ begin
end;
function CodeMakroLower(const Parameter: string; InteractiveValue: TPersistent;
SrcEdit: TSourceEditorInterface;
var Value, ErrorMsg: string): boolean;
begin
Value:=LowerCase(Parameter);
@ -202,6 +207,7 @@ begin
end;
function CodeMakroPaste(const Parameter: string; InteractiveValue: TPersistent;
SrcEdit: TSourceEditorInterface;
var Value, ErrorMsg: string): boolean;
begin
Value:=Clipboard.AsText;

View File

@ -41,83 +41,9 @@ type
var
// 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
const
@ -125,21 +51,6 @@ const
MinStamp = -$7fffffff;
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 }
procedure TIDEMacros.IncreaseBaseStamp;
@ -168,35 +79,5 @@ begin
Result:=true;
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.

View File

@ -123,11 +123,106 @@ type
write SetActiveEditor;
end;
var
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
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 }
procedure TSourceEditorInterface.SelectText(LineNum, CharStart, LineNum2,
@ -147,5 +242,33 @@ begin
EndUpdate;
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.