mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-25 15:19:14 +02:00
cody: dictionary: load before save
git-svn-id: trunk@33842 -
This commit is contained in:
parent
346e83eccf
commit
535af9b027
@ -41,7 +41,7 @@ interface
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, FileProcs, LResources, LCLProc, avl_tree, Forms, Controls,
|
Classes, SysUtils, FileProcs, LResources, LCLProc, avl_tree, Forms, Controls,
|
||||||
Graphics, Dialogs, ButtonPanel, StdCtrls, ExtCtrls, LCLType,
|
Graphics, Dialogs, ButtonPanel, StdCtrls, ExtCtrls, LCLType, Buttons,
|
||||||
PackageIntf, LazIDEIntf, SrcEditorIntf, ProjectIntf, CompOptsIntf, IDEDialogs,
|
PackageIntf, LazIDEIntf, SrcEditorIntf, ProjectIntf, CompOptsIntf, IDEDialogs,
|
||||||
CodeCache, BasicCodeTools, CustomCodeTool, CodeToolManager, UnitDictionary,
|
CodeCache, BasicCodeTools, CustomCodeTool, CodeToolManager, UnitDictionary,
|
||||||
CodeTree, LinkScanner, DefineTemplates,
|
CodeTree, LinkScanner, DefineTemplates,
|
||||||
@ -104,6 +104,11 @@ type
|
|||||||
property LoadSaveError: string read FLoadSaveError write SetLoadSaveError;
|
property LoadSaveError: string read FLoadSaveError write SetLoadSaveError;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
TCodyIdentifierDlgAction = (
|
||||||
|
cidaUseIdentifier,
|
||||||
|
cidaJumpToIdentifier
|
||||||
|
);
|
||||||
|
|
||||||
{ TCodyIdentifiersDlg }
|
{ TCodyIdentifiersDlg }
|
||||||
|
|
||||||
TCodyIdentifiersDlg = class(TForm)
|
TCodyIdentifiersDlg = class(TForm)
|
||||||
@ -120,6 +125,7 @@ type
|
|||||||
procedure FilterEditExit(Sender: TObject);
|
procedure FilterEditExit(Sender: TObject);
|
||||||
procedure FilterEditKeyDown(Sender: TObject; var Key: Word;
|
procedure FilterEditKeyDown(Sender: TObject; var Key: Word;
|
||||||
{%H-}Shift: TShiftState);
|
{%H-}Shift: TShiftState);
|
||||||
|
procedure JumpButtonClick(Sender: TObject);
|
||||||
procedure FormClose(Sender: TObject; var {%H-}CloseAction: TCloseAction);
|
procedure FormClose(Sender: TObject; var {%H-}CloseAction: TCloseAction);
|
||||||
procedure FormCreate(Sender: TObject);
|
procedure FormCreate(Sender: TObject);
|
||||||
procedure HideOtherProjectsCheckBoxChange(Sender: TObject);
|
procedure HideOtherProjectsCheckBoxChange(Sender: TObject);
|
||||||
@ -127,12 +133,15 @@ type
|
|||||||
procedure ItemsListBoxSelectionChange(Sender: TObject; {%H-}User: boolean);
|
procedure ItemsListBoxSelectionChange(Sender: TObject; {%H-}User: boolean);
|
||||||
procedure OnIdle(Sender: TObject; var {%H-}Done: Boolean);
|
procedure OnIdle(Sender: TObject; var {%H-}Done: Boolean);
|
||||||
private
|
private
|
||||||
|
FDlgAction: TCodyIdentifierDlgAction;
|
||||||
|
FJumpButton: TBitBtn;
|
||||||
FLastFilter: string;
|
FLastFilter: string;
|
||||||
FLastHideOtherProjects: boolean;
|
FLastHideOtherProjects: boolean;
|
||||||
FIdleConnected: boolean;
|
FIdleConnected: boolean;
|
||||||
FMaxItems: integer;
|
FMaxItems: integer;
|
||||||
FNoFilterText: string;
|
FNoFilterText: string;
|
||||||
FItems: TStringList;
|
FItems: TStringList;
|
||||||
|
procedure SetDlgAction(NewAction: TCodyIdentifierDlgAction);
|
||||||
procedure SetIdleConnected(AValue: boolean);
|
procedure SetIdleConnected(AValue: boolean);
|
||||||
procedure SetMaxItems(AValue: integer);
|
procedure SetMaxItems(AValue: integer);
|
||||||
procedure UpdateGeneralInfo;
|
procedure UpdateGeneralInfo;
|
||||||
@ -144,6 +153,7 @@ type
|
|||||||
procedure UpdateCurOwnerOfUnit;
|
procedure UpdateCurOwnerOfUnit;
|
||||||
procedure AddToUsesSection;
|
procedure AddToUsesSection;
|
||||||
procedure UpdateTool;
|
procedure UpdateTool;
|
||||||
|
function AddButton: TBitBtn;
|
||||||
function GetCurOwnerCompilerOptions: TLazCompilerOptions;
|
function GetCurOwnerCompilerOptions: TLazCompilerOptions;
|
||||||
public
|
public
|
||||||
CurIdentifier: string;
|
CurIdentifier: string;
|
||||||
@ -168,9 +178,11 @@ type
|
|||||||
|
|
||||||
function Init: boolean;
|
function Init: boolean;
|
||||||
procedure UseIdentifier;
|
procedure UseIdentifier;
|
||||||
|
procedure JumpToIdentifier;
|
||||||
property IdleConnected: boolean read FIdleConnected write SetIdleConnected;
|
property IdleConnected: boolean read FIdleConnected write SetIdleConnected;
|
||||||
property MaxItems: integer read FMaxItems write SetMaxItems;
|
property MaxItems: integer read FMaxItems write SetMaxItems;
|
||||||
function OwnerToString(AnOwner: TObject): string;
|
function OwnerToString(AnOwner: TObject): string;
|
||||||
|
property DlgAction: TCodyIdentifierDlgAction read FDlgAction;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
var
|
var
|
||||||
@ -190,8 +202,12 @@ begin
|
|||||||
CodyIdentifiersDlg:=TCodyIdentifiersDlg.Create(nil);
|
CodyIdentifiersDlg:=TCodyIdentifiersDlg.Create(nil);
|
||||||
try
|
try
|
||||||
if not CodyIdentifiersDlg.Init then exit;
|
if not CodyIdentifiersDlg.Init then exit;
|
||||||
if CodyIdentifiersDlg.ShowModal=mrOk then
|
if CodyIdentifiersDlg.ShowModal=mrOk then begin
|
||||||
CodyIdentifiersDlg.UseIdentifier;
|
case CodyIdentifiersDlg.DlgAction of
|
||||||
|
cidaUseIdentifier: CodyIdentifiersDlg.UseIdentifier;
|
||||||
|
cidaJumpToIdentifier: CodyIdentifiersDlg.JumpToIdentifier;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
finally
|
finally
|
||||||
CodyIdentifiersDlg.Free;
|
CodyIdentifiersDlg.Free;
|
||||||
end;
|
end;
|
||||||
@ -532,10 +548,7 @@ end;
|
|||||||
|
|
||||||
procedure TCodyIdentifiersDlg.ButtonPanel1OKButtonClick(Sender: TObject);
|
procedure TCodyIdentifiersDlg.ButtonPanel1OKButtonClick(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
if FindSelectedItem(NewIdentifier, NewUnitFilename, NewGroupName, NewGroupFilename) then
|
SetDlgAction(cidaUseIdentifier);
|
||||||
ModalResult:=mrOk
|
|
||||||
else
|
|
||||||
ModalResult:=mrNone;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCodyIdentifiersDlg.FilterEditExit(Sender: TObject);
|
procedure TCodyIdentifiersDlg.FilterEditExit(Sender: TObject);
|
||||||
@ -565,6 +578,11 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCodyIdentifiersDlg.JumpButtonClick(Sender: TObject);
|
||||||
|
begin
|
||||||
|
SetDlgAction(cidaJumpToIdentifier);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TCodyIdentifiersDlg.FormClose(Sender: TObject;
|
procedure TCodyIdentifiersDlg.FormClose(Sender: TObject;
|
||||||
var CloseAction: TCloseAction);
|
var CloseAction: TCloseAction);
|
||||||
begin
|
begin
|
||||||
@ -581,6 +599,11 @@ begin
|
|||||||
FItems:=TStringList.Create;
|
FItems:=TStringList.Create;
|
||||||
HideOtherProjectsCheckBox.Checked:=true;
|
HideOtherProjectsCheckBox.Checked:=true;
|
||||||
HideOtherProjectsCheckBox.Caption:=crsHideUnitsOfOtherProjects;
|
HideOtherProjectsCheckBox.Caption:=crsHideUnitsOfOtherProjects;
|
||||||
|
|
||||||
|
FJumpButton:=AddButton;
|
||||||
|
FJumpButton.Name:='JumpButton';
|
||||||
|
FJumpButton.OnClick:=@JumpButtonClick;
|
||||||
|
FJumpButton.Caption:='Jump to';
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCodyIdentifiersDlg.HideOtherProjectsCheckBoxChange(Sender: TObject);
|
procedure TCodyIdentifiersDlg.HideOtherProjectsCheckBoxChange(Sender: TObject);
|
||||||
@ -625,6 +648,17 @@ begin
|
|||||||
Application.RemoveOnIdleHandler(@OnIdle);
|
Application.RemoveOnIdleHandler(@OnIdle);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCodyIdentifiersDlg.SetDlgAction(NewAction: TCodyIdentifierDlgAction);
|
||||||
|
begin
|
||||||
|
FDlgAction:=NewAction;
|
||||||
|
if FindSelectedItem(NewIdentifier, NewUnitFilename, NewGroupName,
|
||||||
|
NewGroupFilename)
|
||||||
|
then
|
||||||
|
ModalResult:=mrOk
|
||||||
|
else
|
||||||
|
ModalResult:=mrNone;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TCodyIdentifiersDlg.SetMaxItems(AValue: integer);
|
procedure TCodyIdentifiersDlg.SetMaxItems(AValue: integer);
|
||||||
begin
|
begin
|
||||||
if FMaxItems=AValue then Exit;
|
if FMaxItems=AValue then Exit;
|
||||||
@ -1027,6 +1061,41 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCodyIdentifiersDlg.JumpToIdentifier;
|
||||||
|
var
|
||||||
|
NewUnitCode: TCodeBuffer;
|
||||||
|
NewCode: TCodeBuffer;
|
||||||
|
NewX: integer;
|
||||||
|
NewY: integer;
|
||||||
|
NewTopLine: integer;
|
||||||
|
begin
|
||||||
|
if not FileExistsUTF8(NewUnitFilename) then begin
|
||||||
|
IDEMessageDialog('File not found',
|
||||||
|
'File "'+NewUnitFilename+'" does not exist anymore.',
|
||||||
|
mtError,[mbCancel]);
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
NewUnitCode:=CodeToolBoss.LoadFile(NewUnitFilename,true,false);
|
||||||
|
if NewUnitCode=nil then begin
|
||||||
|
IDEMessageDialog('File read error',
|
||||||
|
'Unable to read file "'+NewUnitFilename+'".',
|
||||||
|
mtError,[mbCancel]);
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
|
||||||
|
if not CodeToolBoss.FindDeclarationOfPropertyPath(NewUnitCode,NewIdentifier,
|
||||||
|
NewCode, NewX, NewY, NewTopLine)
|
||||||
|
then begin
|
||||||
|
IDEMessageDialog('Identifir not found',
|
||||||
|
'Identifier "'+NewIdentifier+'" not found in unit "'+NewUnitFilename+'"',
|
||||||
|
mtError,[mbCancel]);
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
|
||||||
|
LazarusIDE.DoOpenFileAndJumpToPos(NewCode.Filename,Point(NewX,NewY),NewTopLine,
|
||||||
|
-1,-1,[ofDoNotLoadResource]);
|
||||||
|
end;
|
||||||
|
|
||||||
function TCodyIdentifiersDlg.OwnerToString(AnOwner: TObject): string;
|
function TCodyIdentifiersDlg.OwnerToString(AnOwner: TObject): string;
|
||||||
begin
|
begin
|
||||||
Result:='nil';
|
Result:='nil';
|
||||||
@ -1109,6 +1178,16 @@ begin
|
|||||||
CurNode:=CurTool.FindDeepestNodeAtPos(CurCleanPos,false);
|
CurNode:=CurTool.FindDeepestNodeAtPos(CurCleanPos,false);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TCodyIdentifiersDlg.AddButton: TBitBtn;
|
||||||
|
begin
|
||||||
|
Result := TBitBtn.Create(Self);
|
||||||
|
Result.Align := alCustom;
|
||||||
|
Result.Default := false;
|
||||||
|
Result.Constraints.MinWidth:=25;
|
||||||
|
Result.AutoSize := true;
|
||||||
|
Result.Parent := ButtonPanel1;
|
||||||
|
end;
|
||||||
|
|
||||||
function TCodyIdentifiersDlg.GetCurOwnerCompilerOptions: TLazCompilerOptions;
|
function TCodyIdentifiersDlg.GetCurOwnerCompilerOptions: TLazCompilerOptions;
|
||||||
begin
|
begin
|
||||||
if CurOwner is TLazProject then
|
if CurOwner is TLazProject then
|
||||||
|
Loading…
Reference in New Issue
Block a user