* get units code complete to also work if browser disabled

This commit is contained in:
pierre 2002-09-05 05:59:47 +00:00
parent 3ab5492c52
commit c12f883d18

View File

@ -45,15 +45,16 @@ procedure RegisterCodeComplete;
implementation implementation
uses Views,MsgBox,Validate, uses App,Views,MsgBox,Validate,
{$ifdef FVISION} {$ifdef FVISION}
FVConsts, FVConsts,
{$else} {$else}
Commands, Commands,
{$endif} {$endif}
systems, BrowCol, systems, BrowCol,
WEditor, FPCompil, FPVars, FPSymbol, WEditor, FPSwitch,
App,FPConst,FPString,FPViews; FPCompil, FPVars, FPSymbol,
FPConst,FPString,FPViews;
{$ifndef NOOBJREG} {$ifndef NOOBJREG}
const const
@ -82,19 +83,19 @@ begin
St:=PString(CodeCompleteWords^.At(CIndex+1))^; St:=PString(CodeCompleteWords^.At(CIndex+1))^;
if (UpCaseStr(Copy(St,1,length(WordS)))=UpWordS) then if (UpCaseStr(Copy(St,1,length(WordS)))=UpWordS) then
begin begin
if UpCase(st[Length(UpWordS)+1])<>Upcase(Text[Length(UpWordS)+1]) then {if UpCase(st[Length(UpWordS)+1])<>Upcase(Text[Length(UpWordS)+1]) then}
begin begin
Text:=''; Text:='';
FPCompleteCodeWord:=false; FPCompleteCodeWord:=false;
exit; exit;
end (* end
else else
{ only give the common part } { only give the common part }
begin begin
i:=Length(UpWordS)+1; i:=Length(UpWordS)+1;
while (i<=length(st)) and (i<=length(text)) and (UpCase(st[i])=Upcase(Text[i])) do while (i<=length(st)) and (i<=length(text)) and (UpCase(st[i])=Upcase(Text[i])) do
inc(i); inc(i);
SetLength(Text,i-1); SetLength(Text,i-1); *)
end; end;
end; end;
end; end;
@ -108,19 +109,19 @@ begin
St:=PString(UnitsCodeCompleteWords^.At(Index+1))^; St:=PString(UnitsCodeCompleteWords^.At(Index+1))^;
if UpCaseStr(Copy(St,1,length(WordS)))=UpWordS then if UpCaseStr(Copy(St,1,length(WordS)))=UpWordS then
begin begin
if UpCase(st[Length(UpWordS)+1])<>Upcase(Text[Length(UpWordS)+1]) then {if UpCase(st[Length(UpWordS)+1])<>Upcase(Text[Length(UpWordS)+1]) then}
begin begin
Text:=''; Text:='';
FPCompleteCodeWord:=false; FPCompleteCodeWord:=false;
exit; exit;
end (* end
else else
{ only give the common part } { only give the common part }
begin begin
i:=Length(UpWordS)+1; i:=Length(UpWordS)+1;
while (i<=length(st)) and (i<=length(text)) and (UpCase(st[i])=Upcase(Text[i])) do while (i<=length(st)) and (i<=length(text)) and (UpCase(st[i])=Upcase(Text[i])) do
inc(i); inc(i);
SetLength(Text,i-1); SetLength(Text,i-1); *)
end; end;
end; end;
end; end;
@ -129,19 +130,19 @@ begin
if ShowOnlyUnique and (Index<>-1) and (CIndex<>-1) then if ShowOnlyUnique and (Index<>-1) and (CIndex<>-1) then
begin begin
St:=PString(CodeCompleteWords^.At(CIndex+1))^; St:=PString(CodeCompleteWords^.At(CIndex+1))^;
if UpCase(st[Length(UpWordS)+1])<>Upcase(Text[Length(UpWordS)+1]) then {if UpCase(st[Length(UpWordS)+1])<>Upcase(Text[Length(UpWordS)+1]) then}
begin begin
Text:=''; Text:='';
FPCompleteCodeWord:=false; FPCompleteCodeWord:=false;
exit; exit;
end (* end
else else
{ only give the common part } { only give the common part }
begin begin
i:=Length(UpWordS)+1; i:=Length(UpWordS)+1;
while (i<=length(st)) and (i<=length(text)) and (UpCase(st[i])=Upcase(Text[i])) do while (i<=length(st)) and (i<=length(text)) and (UpCase(st[i])=Upcase(Text[i])) do
inc(i); inc(i);
SetLength(Text,i-1); SetLength(Text,i-1); *)
end; end;
end; end;
if OK=false then Text:='' if OK=false then Text:=''
@ -157,8 +158,8 @@ procedure InitCodeComplete;
var I:integer; var I:integer;
S: string; S: string;
begin begin
if Assigned(CodeCompleteWords) then Exit; if Assigned(CodeCompleteWords) then
Dispose(CodeCompleteWords, Done);
New(CodeCompleteWords, Init(10,10)); New(CodeCompleteWords, Init(10,10));
for I:=0 to GetReservedWordCount-1 do for I:=0 to GetReservedWordCount-1 do
begin begin
@ -189,18 +190,22 @@ var
for I:=0 to P^.Count-1 do for I:=0 to P^.Count-1 do
InsertInS(P^.At(I)); InsertInS(P^.At(I));
end; end;
Var
st : string;
begin begin
Inc(level); Inc(level);
if UnitsCodeCompleteWords^.Count=MaxCollectionSize then if UnitsCodeCompleteWords^.Count=MaxCollectionSize then
begin Overflow:=true; Exit; end; begin Overflow:=true; Exit; end;
UnitsCodeCompleteWords^.Insert(NewStr(P^.GetName)); st:=P^.GetName;
if Length(st)>=CodeCompleteMinLen then
UnitsCodeCompleteWords^.Insert(NewStr(Lowcasestr(st)));
{ this is wrong because it inserted args or locals of proc { this is wrong because it inserted args or locals of proc
in the globals list !! PM} in the globals list !! PM}
if (P^.Items<>nil) and (level=1) and if (P^.Items<>nil) and (level=1) and
(not OnlyStandard or (Pos(P^.GetName+',',UpStandardUnits)>0) or ((not OnlyStandard or (Pos(P^.GetName+',',UpStandardUnits)>0) or
{ don't exclude system unit ... } { don't exclude system unit ... }
(Pos('SYS',P^.GetName)>0)) then (Pos('SYS',P^.GetName)>0))) then
InsertItemsInS(P^.Items); InsertItemsInS(P^.Items);
Dec(level); Dec(level);
end; end;
@ -229,9 +234,13 @@ procedure AddStandardUnitsToCodeComplete;
var var
HiddenSource : PSourceWindow; HiddenSource : PSourceWindow;
R : TRect; R : TRect;
StoreBrowserSwitchesConfig : string;
begin begin
Desktop^.GetExtent(R); Desktop^.GetExtent(R);
New(HiddenSource,init(R,'')); New(HiddenSource,init(R,'*'));
HiddenSource^.NoNameCount:=0;
HiddenSource^.UpdateTitle;
HiddenSource^.Hide;
CompilingHiddenFile:=HiddenSource; CompilingHiddenFile:=HiddenSource;
{ compile a dummy file to get symbol info } { compile a dummy file to get symbol info }
with HiddenSource^.Editor^ do with HiddenSource^.Editor^ do
@ -240,13 +249,17 @@ begin
if StandardUnits<>'' then if StandardUnits<>'' then
begin begin
AddLine('uses'); AddLine('uses');
Addline(StandardUnits+';'); Addline(StandardUnits);
Addline(' ;');
end; end;
Addline('begin'); Addline('begin');
Addline('end.'); Addline('end.');
SaveFile; SaveFile;
end; end;
StoreBrowserSwitchesConfig:=BrowserSwitches^.GetCurrSelParam;
BrowserSwitches^.ReadItemsCfg('+');
DoCompile(cCompile); DoCompile(cCompile);
BrowserSwitches^.SetCurrSelParam(StoreBrowserSwitchesConfig);
AddAvailableUnitsToCodeComplete(true); AddAvailableUnitsToCodeComplete(true);
{ Now add the interface declarations to the Code Complete list } { Now add the interface declarations to the Code Complete list }
CompilingHiddenFile:=nil; CompilingHiddenFile:=nil;
@ -300,8 +313,11 @@ end;
procedure DoneCodeComplete; procedure DoneCodeComplete;
begin begin
if Assigned(CodeCompleteWords) then Dispose(CodeCompleteWords, Done); if Assigned(CodeCompleteWords) then
CodeCompleteWords:=nil; begin
Dispose(CodeCompleteWords, Done);
CodeCompleteWords:=nil;
end;
if Assigned(UnitsCodeCompleteWords) then if Assigned(UnitsCodeCompleteWords) then
begin begin
Dispose(UnitsCodeCompleteWords,done); Dispose(UnitsCodeCompleteWords,done);
@ -444,6 +460,13 @@ begin
if Assigned(CodeCompleteWords) then Dispose(CodeCompleteWords, Done); if Assigned(CodeCompleteWords) then Dispose(CodeCompleteWords, Done);
CodeCompleteWords:=C; CodeCompleteWords:=C;
CodeCompleteCase:=TCodeCompleteCase(RB^.Value); CodeCompleteCase:=TCodeCompleteCase(RB^.Value);
MinInputL^.GetData(NewValStr);
NewVal:=StrToInt(NewValStr);
if (NewVal>0) and (NewVal<>CodeCompleteMinLen) then
begin
CodeCompleteMinLen:=NewVal;
InitCodeComplete;
end;
ShowOnlyUnique:=CB^.Mark(0); ShowOnlyUnique:=CB^.Mark(0);
UseAllUnitsInCodeComplete:=CB^.Mark(1); UseAllUnitsInCodeComplete:=CB^.Mark(1);
UseStandardUnitsInCodeComplete:=CB^.Mark(2); UseStandardUnitsInCodeComplete:=CB^.Mark(2);
@ -455,10 +478,6 @@ begin
end end
else else
InputL^.GetData(StandardUnits); InputL^.GetData(StandardUnits);
MinInputL^.GetData(NewValStr);
NewVal:=StrToInt(NewValStr);
if NewVal>0 then
CodeCompleteMinLen:=NewVal;
end end
else else
Dispose(C, Done); Dispose(C, Done);