mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-13 10:49:16 +02:00
IDE: fixed result of SaveSourceEditorChangesToCodeCache, codetools: started complete block
git-svn-id: trunk@20107 -
This commit is contained in:
parent
d9c7fdad82
commit
f8012d194e
@ -354,6 +354,9 @@ type
|
|||||||
function GuessUnclosedBlock(Code: TCodeBuffer; X,Y: integer;
|
function GuessUnclosedBlock(Code: TCodeBuffer; X,Y: integer;
|
||||||
out NewCode: TCodeBuffer;
|
out NewCode: TCodeBuffer;
|
||||||
out NewX, NewY, NewTopLine: integer): boolean;
|
out NewX, NewY, NewTopLine: integer): boolean;
|
||||||
|
function CompleteBlock(Code: TCodeBuffer; X,Y: integer;
|
||||||
|
out NewCode: TCodeBuffer;
|
||||||
|
out NewX, NewY, NewTopLine: integer): boolean;
|
||||||
|
|
||||||
// method jumping
|
// method jumping
|
||||||
function JumpToMethod(Code: TCodeBuffer; X,Y: integer;
|
function JumpToMethod(Code: TCodeBuffer; X,Y: integer;
|
||||||
@ -3036,6 +3039,36 @@ begin
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TCodeToolManager.CompleteBlock(Code: TCodeBuffer; X, Y: integer; out
|
||||||
|
NewCode: TCodeBuffer; out NewX, NewY, NewTopLine: integer): boolean;
|
||||||
|
var
|
||||||
|
CursorPos, NewPos: TCodeXYPosition;
|
||||||
|
begin
|
||||||
|
Result:=false;
|
||||||
|
NewCode:=Code;
|
||||||
|
NewX:=X;
|
||||||
|
NewY:=Y;
|
||||||
|
NewTopLine:=-1;
|
||||||
|
{$IFDEF CTDEBUG}
|
||||||
|
DebugLn('TCodeToolManager.CompleteBlock A ',Code.Filename,' x=',dbgs(X),' y=',dbgs(Y));
|
||||||
|
{$ENDIF}
|
||||||
|
if not InitCurCodeTool(Code) then exit;
|
||||||
|
CursorPos.X:=X;
|
||||||
|
CursorPos.Y:=Y;
|
||||||
|
CursorPos.Code:=Code;
|
||||||
|
try
|
||||||
|
Result:=FCurCodeTool.CompleteBlock(CursorPos,SourceChangeCache,
|
||||||
|
NewPos,NewTopLine);
|
||||||
|
if Result then begin
|
||||||
|
NewCode:=NewPos.Code;
|
||||||
|
NewX:=NewPos.X;
|
||||||
|
NewY:=NewPos.Y;
|
||||||
|
end;
|
||||||
|
except
|
||||||
|
on e: Exception do HandleException(e);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
function TCodeToolManager.GetCompatiblePublishedMethods(Code: TCodeBuffer;
|
function TCodeToolManager.GetCompatiblePublishedMethods(Code: TCodeBuffer;
|
||||||
const AClassName: string; TypeData: PTypeData; Proc: TGetStringProc): boolean;
|
const AClassName: string; TypeData: PTypeData; Proc: TGetStringProc): boolean;
|
||||||
begin
|
begin
|
||||||
|
@ -200,6 +200,9 @@ type
|
|||||||
out NewPos: TCodeXYPosition; out NewTopLine: integer): boolean;
|
out NewPos: TCodeXYPosition; out NewTopLine: integer): boolean;
|
||||||
function FindBlockCleanBounds(const CursorPos: TCodeXYPosition;
|
function FindBlockCleanBounds(const CursorPos: TCodeXYPosition;
|
||||||
out BlockCleanStart, BlockCleanEnd: integer): boolean;
|
out BlockCleanStart, BlockCleanEnd: integer): boolean;
|
||||||
|
function CompleteBlock(const CursorPos: TCodeXYPosition;
|
||||||
|
SourceChangeCache: TSourceChangeCache;
|
||||||
|
out NewPos: TCodeXYPosition; out NewTopLine: integer): boolean;
|
||||||
|
|
||||||
// compiler directives
|
// compiler directives
|
||||||
function GuessMisplacedIfdefEndif(const CursorPos: TCodeXYPosition;
|
function GuessMisplacedIfdefEndif(const CursorPos: TCodeXYPosition;
|
||||||
@ -5080,6 +5083,37 @@ begin
|
|||||||
Result:=true;
|
Result:=true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TStandardCodeTool.CompleteBlock(const CursorPos: TCodeXYPosition;
|
||||||
|
SourceChangeCache: TSourceChangeCache;
|
||||||
|
out NewPos: TCodeXYPosition; out NewTopLine: integer): boolean;
|
||||||
|
{ begin: end;
|
||||||
|
asm: end;
|
||||||
|
try: finally end;
|
||||||
|
finally: end;
|
||||||
|
except: end;
|
||||||
|
repeat: until ;
|
||||||
|
case of: end;
|
||||||
|
case :: ;
|
||||||
|
case else: end;
|
||||||
|
(: )
|
||||||
|
[: ]
|
||||||
|
record: end;
|
||||||
|
class: end;
|
||||||
|
object: end;
|
||||||
|
interface: end;
|
||||||
|
}
|
||||||
|
var
|
||||||
|
CleanCursorPos: integer;
|
||||||
|
Node: TCodeTreeNode;
|
||||||
|
begin
|
||||||
|
Result:=false;
|
||||||
|
BuildTreeAndGetCleanPos(trTillCursor,CursorPos,CleanCursorPos,
|
||||||
|
[{$IFNDEF DisableIgnoreErrorAfter}btSetIgnoreErrorPos{$ENDIF}]);
|
||||||
|
Node:=FindDeepestNodeAtPos(CleanCursorPos,true);
|
||||||
|
|
||||||
|
DebugLn(['TStandardCodeTool.CompleteBlock ',Node.DescAsString]);
|
||||||
|
end;
|
||||||
|
|
||||||
function TStandardCodeTool.GuessMisplacedIfdefEndif(
|
function TStandardCodeTool.GuessMisplacedIfdefEndif(
|
||||||
const CursorPos: TCodeXYPosition;
|
const CursorPos: TCodeXYPosition;
|
||||||
out NewPos: TCodeXYPosition; out NewTopLine: integer): boolean;
|
out NewPos: TCodeXYPosition; out NewTopLine: integer): boolean;
|
||||||
|
@ -640,14 +640,15 @@ type
|
|||||||
FMarkupCurWordNoTimer: Boolean;
|
FMarkupCurWordNoTimer: Boolean;
|
||||||
|
|
||||||
// Code tools options (MG: these will move to an unit of their own)
|
// Code tools options (MG: these will move to an unit of their own)
|
||||||
fAutoIdentifierCompletion: Boolean;
|
fAutoBlockCompletion: Boolean;
|
||||||
fAutoCodeParameters: Boolean;
|
fAutoCodeParameters: Boolean;
|
||||||
|
fAutoDelayInMSec: Integer;
|
||||||
|
fAutoIdentifierCompletion: Boolean;
|
||||||
|
FAutoRemoveEmptyMethods: Boolean;
|
||||||
fAutoToolTipExprEval: Boolean;
|
fAutoToolTipExprEval: Boolean;
|
||||||
fAutoToolTipSymbTools: Boolean;
|
fAutoToolTipSymbTools: Boolean;
|
||||||
fAutoDelayInMSec: Integer;
|
|
||||||
fCodeTemplateFileName: String;
|
fCodeTemplateFileName: String;
|
||||||
fCTemplIndentToTokenStart: Boolean;
|
fCTemplIndentToTokenStart: Boolean;
|
||||||
FAutoRemoveEmptyMethods: Boolean;
|
|
||||||
|
|
||||||
// Code Folding
|
// Code Folding
|
||||||
FUseCodeFolding: Boolean;
|
FUseCodeFolding: Boolean;
|
||||||
@ -791,6 +792,8 @@ type
|
|||||||
// Code Tools options
|
// Code Tools options
|
||||||
property AutoIdentifierCompletion: Boolean
|
property AutoIdentifierCompletion: Boolean
|
||||||
read fAutoIdentifierCompletion write fAutoIdentifierCompletion default True;
|
read fAutoIdentifierCompletion write fAutoIdentifierCompletion default True;
|
||||||
|
property AutoBlockCompletion: Boolean
|
||||||
|
read fAutoBlockCompletion write FAutoBlockCompletion default True;
|
||||||
property AutoCodeParameters: Boolean
|
property AutoCodeParameters: Boolean
|
||||||
read fAutoCodeParameters write fAutoCodeParameters default True;
|
read fAutoCodeParameters write fAutoCodeParameters default True;
|
||||||
property AutoToolTipExprEval: Boolean
|
property AutoToolTipExprEval: Boolean
|
||||||
@ -1825,6 +1828,9 @@ begin
|
|||||||
fAutoIdentifierCompletion :=
|
fAutoIdentifierCompletion :=
|
||||||
XMLConfig.GetValue(
|
XMLConfig.GetValue(
|
||||||
'EditorOptions/CodeTools/AutoIdentifierCompletion', True);
|
'EditorOptions/CodeTools/AutoIdentifierCompletion', True);
|
||||||
|
fAutoBlockCompletion :=
|
||||||
|
XMLConfig.GetValue(
|
||||||
|
'EditorOptions/CodeTools/AutoBlockCompletion', True);
|
||||||
fAutoCodeParameters :=
|
fAutoCodeParameters :=
|
||||||
XMLConfig.GetValue('EditorOptions/CodeTools/AutoCodeParameters', True);
|
XMLConfig.GetValue('EditorOptions/CodeTools/AutoCodeParameters', True);
|
||||||
fAutoToolTipExprEval :=
|
fAutoToolTipExprEval :=
|
||||||
@ -2055,6 +2061,8 @@ begin
|
|||||||
// Code Tools options
|
// Code Tools options
|
||||||
XMLConfig.SetDeleteValue('EditorOptions/CodeTools/AutoIdentifierCompletion'
|
XMLConfig.SetDeleteValue('EditorOptions/CodeTools/AutoIdentifierCompletion'
|
||||||
, fAutoIdentifierCompletion, True);
|
, fAutoIdentifierCompletion, True);
|
||||||
|
XMLConfig.SetDeleteValue('EditorOptions/CodeTools/AutoBlockCompletion'
|
||||||
|
, fAutoBlockCompletion, True);
|
||||||
XMLConfig.SetDeleteValue('EditorOptions/CodeTools/AutoCodeParameters'
|
XMLConfig.SetDeleteValue('EditorOptions/CodeTools/AutoCodeParameters'
|
||||||
, fAutoCodeParameters, True);
|
, fAutoCodeParameters, True);
|
||||||
XMLConfig.SetDeleteValue('EditorOptions/CodeTools/AutoToolTipExprEval'
|
XMLConfig.SetDeleteValue('EditorOptions/CodeTools/AutoToolTipExprEval'
|
||||||
|
@ -12274,11 +12274,14 @@ var i: integer;
|
|||||||
AnUnitInfo: TUnitInfo;
|
AnUnitInfo: TUnitInfo;
|
||||||
begin
|
begin
|
||||||
GetUnitWithPageIndex(APageIndex,SrcEdit,AnUnitInfo);
|
GetUnitWithPageIndex(APageIndex,SrcEdit,AnUnitInfo);
|
||||||
if (SrcEdit<>nil) and (AnUnitInfo<>nil) and SrcEdit.NeedsUpdateCodeBuffer then
|
if (SrcEdit<>nil) and (AnUnitInfo<>nil) then
|
||||||
begin
|
begin
|
||||||
SrcEdit.UpdateCodeBuffer;
|
|
||||||
AnUnitInfo.Modified:=true;
|
|
||||||
SaveSourceEditorChangesToCodeCache:=true;
|
SaveSourceEditorChangesToCodeCache:=true;
|
||||||
|
if SrcEdit.NeedsUpdateCodeBuffer then
|
||||||
|
begin
|
||||||
|
SrcEdit.UpdateCodeBuffer;
|
||||||
|
AnUnitInfo.Modified:=true;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -43,8 +43,8 @@ uses
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
Classes, SysUtils, Math, Controls, LCLProc, LCLType, LResources, LCLIntf,
|
Classes, SysUtils, Math, Controls, LCLProc, LCLType, LResources, LCLIntf,
|
||||||
FileUtil, Forms, Buttons, ComCtrls, Dialogs, StdCtrls, GraphType, Graphics,
|
FileUtil, Forms, Buttons, ComCtrls, Dialogs, StdCtrls, GraphType, Graphics,
|
||||||
Translations, ClipBrd, TypInfo, Extctrls, Menus, HelpIntfs, LazHelpIntf,
|
Translations, ClipBrd, TypInfo, types, Extctrls, Menus, HelpIntfs,
|
||||||
LConvEncoding, LDockCtrl,
|
LazHelpIntf, LConvEncoding, LDockCtrl,
|
||||||
// codetools
|
// codetools
|
||||||
CodeToolManager, CodeCache, SourceLog,
|
CodeToolManager, CodeCache, SourceLog,
|
||||||
// synedit
|
// synedit
|
||||||
@ -192,6 +192,7 @@ type
|
|||||||
procedure ccAddMessage(Texts: String);
|
procedure ccAddMessage(Texts: String);
|
||||||
function AutoCompleteChar(Char: TUTF8Char; var AddChar: boolean;
|
function AutoCompleteChar(Char: TUTF8Char; var AddChar: boolean;
|
||||||
Category: TAutoCompleteOption): boolean;
|
Category: TAutoCompleteOption): boolean;
|
||||||
|
procedure AutoCompleteBlock;
|
||||||
|
|
||||||
procedure FocusEditor;// called by TSourceNotebook when the Notebook page
|
procedure FocusEditor;// called by TSourceNotebook when the Notebook page
|
||||||
// changes so the editor is focused
|
// changes so the editor is focused
|
||||||
@ -1549,6 +1550,10 @@ begin
|
|||||||
if AutoCompleteChar(aChar,AddChar,acoLineBreak) then ;
|
if AutoCompleteChar(aChar,AddChar,acoLineBreak) then ;
|
||||||
//DebugLn(['TSourceEditor.ProcessCommand ecLineBreak AddChar=',AddChar]);
|
//DebugLn(['TSourceEditor.ProcessCommand ecLineBreak AddChar=',AddChar]);
|
||||||
if not AddChar then Command:=ecNone;
|
if not AddChar then Command:=ecNone;
|
||||||
|
{$IFDEF EnableCompleteBlock}
|
||||||
|
if EditorOpts.AutoBlockCompletion then
|
||||||
|
AutoCompleteBlock;
|
||||||
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
ecPrevBookmark: // Note: book mark commands lower than ecUserFirst must be handled here
|
ecPrevBookmark: // Note: book mark commands lower than ecUserFirst must be handled here
|
||||||
@ -2329,6 +2334,20 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TSourceEditor.AutoCompleteBlock;
|
||||||
|
var
|
||||||
|
XY: TPoint;
|
||||||
|
NewCode: TCodeBuffer;
|
||||||
|
NewX, NewY, NewTopLine: integer;
|
||||||
|
begin
|
||||||
|
if not LazarusIDE.SaveSourceEditorChangesToCodeCache(PageIndex) then exit;
|
||||||
|
XY:=FEditor.LogicalCaretXY;
|
||||||
|
if not CodeToolBoss.CompleteBlock(CodeBuffer,XY.X,XY.Y,
|
||||||
|
NewCode,NewX,NewY,NewTopLine) then exit;
|
||||||
|
if (NewCode<>CodeBuffer) or (NewX<>XY.X) or (NewY<>XY.Y) or (NewTopLine>0)
|
||||||
|
then ;
|
||||||
|
end;
|
||||||
|
|
||||||
Procedure TSourceEditor.CreateEditor(AOwner: TComponent; AParent: TWinControl);
|
Procedure TSourceEditor.CreateEditor(AOwner: TComponent; AParent: TWinControl);
|
||||||
var
|
var
|
||||||
NewName: string;
|
NewName: string;
|
||||||
|
Loading…
Reference in New Issue
Block a user