Codecompletion changes.

Added code to Uniteditor for code completion.

Also, added code to gtkobject.inc so forms now get keypress events.
Shane

git-svn-id: trunk@166 -
This commit is contained in:
lazarus 2001-02-02 20:13:39 +00:00
parent a60f0a22ae
commit bf2acd12f4
6 changed files with 184 additions and 17 deletions

View File

@ -269,6 +269,7 @@ begin
TStringList(FItemList).OnChange := {$IFDEF FPC}@{$ENDIF}StringListChange;
bitmap := TBitmap.Create;
NbLinesInWindow := 6;
end;
procedure TSynBaseCompletionForm.Deactivate;
@ -289,6 +290,7 @@ procedure TSynBaseCompletionForm.KeyDown(var Key: Word;
var
i: integer;
begin
Writeln('[TSynBaseCompletionForm] KeyDown');
case Key of
// added the VK_XXX codes to make it more readable / maintainable
VK_RETURN:
@ -351,6 +353,8 @@ end;
procedure TSynBaseCompletionForm.Paint;
var
i: integer;
S1,S2 : String;
function Min(a, b: integer): integer;
begin
if a < b then
@ -389,14 +393,27 @@ Writeln('[TSynBaseCompletionForm.Paint]');
Canvas.Pen.Color := clSelect;
Canvas.Rectangle(0, FFontHeight * i, width, FFontHeight * (i + 1));
Canvas.Pen.Color := clBlack;
end else
Canvas.Font.Color := clWhite;
end
else
Begin
Canvas.Brush.Color := Color;
Canvas.Font.Color := clBlack;
end;
if not Assigned(OnPaintItem)
or not OnPaintItem(ItemList[Scroll.Position + i], Canvas, 0, FFontHeight * i)
then
Begin
Writeln('Drawing to canvas');
// Canvas.Font.Color := clBlack;
{ S1 := Copy(ItemList[Scroll.Position + i],pos('.',ItemList[Scroll.Position + i])+1,pos(':',ItemList[Scroll.Position + i])-1);
Canvas.TextOut(2, FFontHeight * i, S1);
Canvas.Font.Color := clLtGray;
Canvas.TextOut(2+(9*length(S1)), FFontHeight * i, Copy(ItemList[Scroll.Position + i],pos(':',ItemList[Scroll.Position + i]),255));
}
Canvas.TextOut(2, FFontHeight * i, ItemList[Scroll.Position + i]);
end;
end;

View File

@ -48,6 +48,8 @@ or use TPropertyType
Function GetPropName(Index : Integer) : String; virtual; abstract;
Function GetPropTypebyName(Name : String) : TTypeKind; virtual; abstract;
// Function GetPropTypebyName(Name : String) : TPropertyType; virtual; abstract;
Function GetPropTypeName(Index : Integer) : String; virtual; abstract;
Function GetPropValue(Index : Integer; var Value) : Boolean; virtual; abstract;
Function GetPropValuebyName(Name: String; var Value) : Boolean; virtual; abstract;

View File

@ -59,7 +59,9 @@ each control that's dropped onto the form
Function IsTControl : Boolean; override;
Function GetPropCount : Integer; override;
Function GetPropType(Index : Integer) : TTypeKind; override;
Function GetPropTypeInfo(Index : Integer) : PTypeInfo;
Function GetPropName(Index : Integer) : String; override;
Function GetPropTypeName(Index : Integer) : String; override;
Function GetPropTypebyName(Name : String) : TTypeKind; override;
Function GetPropValue(Index : Integer; var Value) : Boolean; override;
@ -67,6 +69,7 @@ each control that's dropped onto the form
Function SetProp(Index : Integer; const Value) : Boolean; override;
Function SetPropbyName(Name : String; const Value) : Boolean; override;
Function GetControlCount: Integer; override;
Function GetControl(Index : Integer): TIComponentInterface; override;
@ -322,7 +325,27 @@ Begin
freemem(PP);
end;
Function TComponentInterface.GetPropName(Index : Integer) : String;
Function TComponentInterface.GetPropTypeInfo(Index : Integer) : PTypeInfo;
var
PT : PTypeData;
PP : PPropList;
PI : PTypeInfo;
Num : Integer;
Begin
PI:=FControl.ClassInfo;
PT:=GetTypeData(PI);
GetMem (PP,PT^.PropCount*SizeOf(Pointer));
GetPropInfos(PI,PP);
if Index < PT^.PropCount then
Result := PP^[Index]^.PropType
else
Result := nil;
freemem(PP);
end;
{This returns "Integer" or "Boolean"}
Function TComponentInterface.GetPropTypeName(Index : Integer) : String;
var
PT : PTypeData;
PP : PPropList;
@ -340,6 +363,27 @@ Begin
freemem(PP);
end;
{This returns "Left" "Align" "Visible"}
Function TComponentInterface.GetPropName(Index : Integer) : String;
var
PT : PTypeData;
PP : PPropList;
PI : PTypeInfo;
Num : Integer;
Begin
PI:=FControl.ClassInfo;
PT:=GetTypeData(PI);
GetMem (PP,PT^.PropCount*SizeOf(Pointer));
GetPropInfos(PI,PP);
if Index < PT^.PropCount then
// Result := PP^[Index]^.PropType^.Name
Result := PP^[Index]^.Name
else
Result := '';
freemem(PP);
end;
Function TComponentInterface.GetPropTypebyName(Name : String) : TTypeKind;
var
PT : PTypeData;

View File

@ -839,13 +839,27 @@ Begin
end;
Procedure TSourceEditor.ccExecute(Sender : TObject);
type
TMethodRec = record
Flags : TParamFlags;
ParamName : ShortString;
TypeName : ShortString;
end;
var
scompl : TSynBaseCompletion;
S : TStrings;
CompInt : TComponentInterface;
CompName : String;
I : Integer;
I,X : Integer;
propKind : TTypeKind;
TypeInfo : PTypeInfo;
TypeData : PTypeData;
NewStr : String;
aName : String;
Count : Integer;
MethodRec : TMethodRec;
Temp : String;
Begin
CompInt := nil;
Writeln('[ccExecute]');
@ -856,8 +870,9 @@ Begin
CompName := Copy(CompName,1,pos('.',Compname)-1);
CompInt := TComponentInterface(FormEditor1.FindComponentByName(CompName));
if CompInt = nil then Exit;
aName := CompName+'.';
//get all methods
NewStr := '';
for I := 0 to CompInt.GetPropCount-1 do
Begin
Writeln('I = '+Inttostr(i));
@ -865,18 +880,88 @@ Begin
PropKind := CompInt.GetPropType(i);
case PropKind of
tkMethod : Begin
Writeln('Property type is TKMETHOD');
// Writeln('
end;
tkObject : Writeln('Property type is TKObject');
tkInteger : Writeln('Property type is TKINTEGER');
tkBool : Writeln('Property type is TKBool');
end;
end;
{
S.Add('constructor Create(aOwner : TComponent);');
S.Add('OnActivate');
TypeInfo := CompInt.GetPropTypeInfo(I);
TypeData := GetTypeData(TypeInfo);
NewStr := CompInt.GetPropName(I);
case TypeData^.MethodKind of
mkProcedure : NewStr := 'property '+CompInt.GetPropName(I)+' :'+CompInt.GetPropTypeName(I);
mkFunction : NewStr := 'property '+CompInt.GetPropName(I)+' :'+CompInt.GetPropTypeName(I);
mkClassFunction : NewStr := CompInt.GetPropName(I) + ' '+'Function ';
mkClassPRocedure : NewStr := CompInt.GetPropName(I) + ' '+'Procedure ';
mkConstructor : NewStr := 'constructor '+CompInt.GetPropName(I) + ' '+'procedure ';
mkDestructor : NewStr := 'destructor '+CompInt.GetPropName(I) + ' '+'procedure ';
end;
//check for parameters
Writeln('ParamCount = '+inttostr(TypeData^.ParamCount));
if TypeData^.ParamCount > 0 then
Begin
Writeln('----');
for Count := 0 to sizeof(TypeData^.ParamList)-1 do
if TypeData^.ParamList[4+Count] in ['a'..'z','A'..'Z','0'..'9'] then
Write(TypeData^.ParamList[Count])
else
Begin
Writeln('----');
break;
end;
{ NewStr := NewStr+'(';
for Count := 0 to TypeData^.ParamCount-1 do
begin
MethodRec.Flags := [];
Temp := '';
For X := 0 to Sizeof(MethodRec.Flags)-1 do
begin
Writeln('-->'+TypeData^.ParamList[Sizeof(MethodRec)*Count]);
Temp := Temp +TypeData^.ParamList[X+((Sizeof(MethodRec)-1)*Count)];
end;
Writeln('TEMP is <'+temp+'>');
MethodRec.ParamName := '';
For X := 0 to Sizeof(MethodRec.ParamName)-1 do
if TypeData^.ParamList[(Sizeof(MethodRec.Flags)-1)+((Sizeof(MethodRec)-1)*Count)+x] in ['a'..'z','A'..'Z','0'..'9'] then
MethodRec.ParamName := MethodRec.ParamName+TypeData^.ParamList[(Sizeof(MethodRec.Flags)-1)+((Sizeof(MethodRec)-1)*Count)+x]
else
break;
Writeln('ParamName is '+MethodRec.ParamName);
MethodRec.TypeName := '';
For X := 0 to Sizeof(MethodRec.TypeName)-1 do
if TypeData^.ParamList[(Sizeof(MethodRec.Paramname)-1)+Sizeof(MethodRec.Flags)+((Sizeof(MethodRec)-1)*Count)+x] in ['a'..'z','A'..'Z','0'..'9'] then
MethodRec.TypeName := MethodRec.TypeName+TypeData^.ParamList[Sizeof(MethodRec.Paramname)+Sizeof(MethodRec.Flags)+((Sizeof(MethodRec)-1)*Count)+x]
else
break;
Writeln('TypeName is '+MethodRec.TypeName);
// TParamFlags = set of (pfVar,pfConst,pfArray,pfAddress,pfReference,pfOut);
if (pfVar in MethodRec.Flags) then NewStr := NewStr+'var ';
if (pfConst in MethodRec.Flags) then NewStr := NewStr+'const ';
if (pfOut in MethodRec.Flags) then NewStr := NewStr+'out ';
if MethodRec.Typename <> 'void' then
NewStr := NewStr+MethodRec.ParamName+' :'+MethodRec.TypeName;
end;
}
end;
end;
tkObject : NewStr := 'tkobject '+CompInt.GetPropName(I) +' :'+CompInt.GetPropTypeName(I);
tkInteger,tkChar,tkEnumeration,tkWChar : NewStr := 'property ' +CompInt.GetPropName(I) +' :'+CompInt.GetPropTypeName(I);
tkBool : NewStr := 'property '+CompInt.GetPropName(I) +' :'+CompInt.GetPropTypeName(I);
tkClass : NewStr := 'property '+CompInt.GetPropName(I) +' :'+CompInt.GetPropTypeName(I);
tkFloat : NewStr := 'property '+CompInt.GetPropName(I) +' :'+CompInt.GetPropTypeName(I);
tkSString : NewStr := 'property '+CompInt.GetPropName(I) +' :'+CompInt.GetPropTypeName(I);
tkUnKnown,tkLString,tkWString,tkAString,tkVariant : NewStr := 'property '+CompInt.GetPropName(I) +' :'+CompInt.GetPropTypeName(I);
end;
if NewStr <> '' then
S.Add(NewStr);
NewStr := '';
end;
sCompl.ItemList := S;
End;

View File

@ -362,7 +362,6 @@ var
begin
// Assert(False, 'Trace:-----------------IN TCUSTOMFORM WNDPROC-------------------');
with Message do
case Msg of
LM_ACTIVATE, LM_SETFOCUS, LM_KILLFOCUS:
@ -838,6 +837,13 @@ end;
{ =============================================================================
$Log$
Revision 1.11 2001/02/02 20:13:39 lazarus
Codecompletion changes.
Added code to Uniteditor for code completion.
Also, added code to gtkobject.inc so forms now get keypress events.
Shane
Revision 1.10 2001/02/01 16:45:20 lazarus
Started the code completion.
Shane

View File

@ -1294,7 +1294,13 @@ begin
ConnectSignal(PgtkObject(PgtkCombo(TComboBox(sender).handle)^.entry), 'key-press-event', @GTKKeyUpDown, GDK_KEY_PRESS_MASK);
ConnectSignal(PgtkObject(PgtkCombo(TComboBox(sender).handle)^.entry), 'key-release-event', @GTKKeyUpDown, GDK_KEY_RELEASE_MASK);
end;
end
else
if (sender is TCustomForm) then
Begin
ConnectSignal(PgtkObject(TCustomForm(sender).handle), 'key-press-event', @GTKKeyUpDown, GDK_KEY_PRESS_MASK);
ConnectSignal(PgtkObject(TCustomForm(sender).handle), 'key-release-event', @GTKKeyUpDown, GDK_KEY_RELEASE_MASK);
end;
ConnectSignal(gFixed, 'key-press-event', @GTKKeyUpDown, GDK_KEY_PRESS_MASK);
ConnectSignal(gFixed, 'key-release-event', @GTKKeyUpDown, GDK_KEY_RELEASE_MASK);
end;
@ -2661,6 +2667,13 @@ end;
{ =============================================================================
$Log$
Revision 1.26 2001/02/02 20:13:39 lazarus
Codecompletion changes.
Added code to Uniteditor for code completion.
Also, added code to gtkobject.inc so forms now get keypress events.
Shane
Revision 1.25 2001/02/01 19:34:50 lazarus
TScrollbar created and a lot of code added.