IDE: Minor optimization, cleanup and formatting.

git-svn-id: trunk@64047 -
This commit is contained in:
juha 2020-10-22 13:35:04 +00:00
parent fc27da0bce
commit 78d5022afa
6 changed files with 74 additions and 116 deletions

View File

@ -1411,8 +1411,8 @@ begin
FCodeCache.IncreaseChangeStamp;
end;
procedure TCodeBuffer.DecodeLoaded(const AFilename: string; var ASource,
ADiskEncoding, AMemEncoding: string);
procedure TCodeBuffer.DecodeLoaded(const AFilename: string;
var ASource, ADiskEncoding, AMemEncoding: string);
begin
inherited DecodeLoaded(AFilename,ASource,ADiskEncoding,AMemEncoding);
if CodeCache<>nil then
@ -1487,20 +1487,13 @@ end;
function TCodeBuffer.FileOnDiskHasChanged(IgnoreModifiedFlag: Boolean): boolean;
// file on disk has changed since last load/save
begin
if IsVirtual then exit(false);
if IgnoreModifiedFlag then
begin
if FileExistsCached(Filename) then
Result:=(FileDateOnDisk<>LoadDate) // ignore LoadDateValid because it is set to false after edit
else
Result:=false;
end else
begin
if LoadDateValid and FileExistsCached(Filename) then
Result:=(FileDateOnDisk<>LoadDate)
else
Result:=false;
end;
Result:=false;
if IsVirtual then exit;
// LoadDateValid is set to false after edit
if (IgnoreModifiedFlag or LoadDateValid) and FileExistsCached(Filename) then
Result:=(FileDateOnDisk<>LoadDate);
if Result then
DebugLn(['TCodeBuffer.FileOnDiskHasChanged ',Filename,' LoadDate=',LoadDate]);
end;
function TCodeBuffer.FileOnDiskIsEqual: boolean;

View File

@ -31,9 +31,10 @@ unit FormEditor;
interface
uses
Classes, LCLProc, Controls, Forms, Buttons, SysUtils, Graphics,
// register IDE base packages
LazarusPackageIntf, RegisterLCL, PkgRegisterBase, allsynedit, LazControls,
Classes, SysUtils,
// LCL
LCLProc, Controls, Forms,
RegisterLCL, // register IDE base packages
// IDE
ObjectInspector, Designer, IDECommands, FormEditingIntf, CustomFormEditor;

View File

@ -713,7 +713,7 @@ begin
NewLen:=length(Result);
while (NewLen>0) and (Result[NewLen] in ['0'..'9']) do
dec(NewLen);
Result:=copy(Result,1,NewLen);
SetLength(Result,NewLen);
end;
function FindFirstFileWithExt(const Directory, Ext: string): string;

View File

@ -679,7 +679,7 @@ type
procedure DoShowSourceOfActiveDesignerForm;
procedure SetDesigning(AComponent: TComponent; Value: Boolean);
procedure SetDesignInstance(AComponent: TComponent; Value: Boolean);
procedure InvalidateAllDesignerForms;
procedure UpdateAndInvalidateDesigners;
procedure ShowDesignerForm(AForm: TCustomForm);
procedure DoViewAnchorEditor(State: TIWGetFormState = iwgfShowOnTop);
procedure DoViewTabOrderEditor(State: TIWGetFormState = iwgfShowOnTop);
@ -3810,19 +3810,30 @@ begin
AnUnitInfo.LoadedDesigner:=true;
end;
procedure TMainIDE.InvalidateAllDesignerForms;
// Calls 'Invalidate' in all designer forms.
procedure TMainIDE.UpdateAndInvalidateDesigners;
// Update some options in designer and 'Invalidate' all designer forms.
var
AnUnitInfo: TUnitInfo;
CurDesignerForm: TCustomForm;
ADesigner: TDesigner;
begin
if Project1=nil then exit;
AnUnitInfo:=Project1.FirstUnitWithComponent;
while AnUnitInfo<>nil do begin
if AnUnitInfo.Component<>nil then begin
while AnUnitInfo<>nil do
begin
if AnUnitInfo.Component<>nil then
begin
CurDesignerForm:=FormEditor1.GetDesignerForm(AnUnitInfo.Component);
if CurDesignerForm<>nil then
begin
ADesigner:=TDesigner(CurDesignerForm.Designer);
if ADesigner<>nil then
begin
ADesigner.ShowEditorHints:=EnvironmentOptions.ShowEditorHints;
ADesigner.ShowComponentCaptions:=EnvironmentOptions.ShowComponentCaptions;
end;
CurDesignerForm.Invalidate;
end;
end;
AnUnitInfo:=AnUnitInfo.NextUnitWithComponent;
end;
@ -5092,45 +5103,6 @@ var
MacroValueChanged:=true;
end;
procedure UpdateDesigners;
var
AForm: TCustomForm;
AnUnitInfo: TUnitInfo;
ADesigner: TDesigner;
begin
if Project1=nil then exit;
AnUnitInfo := Project1.FirstUnitWithComponent;
while AnUnitInfo <> nil do
begin
if (AnUnitInfo.Component<>nil) then
begin
AForm := FormEditor1.GetDesignerForm(AnUnitInfo.Component);
if AForm <> nil then
begin
ADesigner := TDesigner(AForm.Designer);
if ADesigner <> nil then
begin
ADesigner.ShowEditorHints := EnvironmentOptions.ShowEditorHints;
ADesigner.ShowComponentCaptions := EnvironmentOptions.ShowComponentCaptions;
end;
end;
end;
AnUnitInfo := AnUnitInfo.NextUnitWithComponent;
end;
InvalidateAllDesignerForms;
end;
procedure UpdateObjectInspector;
begin
if ObjectInspector1<>nil then
EnvironmentOptions.ObjectInspectorOptions.AssignTo(ObjectInspector1);
end;
procedure UpdateMessagesView;
begin
MessagesView.ApplyIDEOptions;
end;
begin
if Restore then exit;
// invalidate cached substituted macros
@ -5158,9 +5130,10 @@ begin
MainBuildBoss.SetBuildTargetProject1(false);
// update environment
UpdateDesigners;
UpdateObjectInspector;
UpdateMessagesView;
UpdateAndInvalidateDesigners;
if ObjectInspector1<>nil then
EnvironmentOptions.ObjectInspectorOptions.AssignTo(ObjectInspector1);
MessagesView.ApplyIDEOptions;
MainIDEBar.SetupHints;
Application.ShowButtonGlyphs := EnvironmentOptions.ShowButtonGlyphs;
Application.ShowMenuGlyphs := EnvironmentOptions.ShowMenuGlyphs;

View File

@ -266,8 +266,7 @@ type
FResourceBaseClass: TPFComponentBaseClass;
fComponentName: string; { classname is always T<ComponentName>
this attribute contains the component name,
even if the unit is not loaded,
or the designer form is not created.
even if the unit is not loaded, or the designer form is not created.
A component can be for example a TForm or a TDataModule }
fComponentResourceName: string;
FComponentLastBinStreamSize: TStreamSeekType;
@ -296,7 +295,7 @@ type
FSessionModified: boolean;
fSource: TCodeBuffer;
fUsageCount: extended;
fUserReadOnly: Boolean;
fUserReadOnly: Boolean;
fSourceChangeStep: LongInt;
FSourceDirectoryReferenced: boolean;
FSourceDirNeedReference: boolean;
@ -400,8 +399,7 @@ type
function FindUsedByComponentDependency(MinTypes: TUnitCompDependencyTypes
): TUnitComponentDependency;
function FindAncestorUnit: TUnitInfo;
procedure ClearUnitComponentDependencies(
ClearTypes: TUnitCompDependencyTypes);
procedure ClearUnitComponentDependencies(ClearTypes: TUnitCompDependencyTypes);
// Bookmarks
function AddBookmark(X, Y, ID: integer):integer;
procedure DeleteBookmark(ID: integer);
@ -1690,13 +1688,15 @@ end;
function TUnitInfo.GetUsesUnitName: string;
begin
if not FilenameIsPascalUnit(Filename) then
Result:=''
else begin
Result:=FUnitName;
if (Result='') or (CompareText(Result,ExtractFileNameOnly(Filename))<>0) then
if FilenameIsPascalUnit(Filename) then
begin
if FUnitName<>'' then
Result:=FUnitName
else
Result:=ExtractFileNameOnly(Filename);
end;
end
else
Result:='';
end;
function TUnitInfo.CreateUnitName: string;
@ -1802,8 +1802,7 @@ begin
XMLConfig.SetDeleteValue(Path+'DisableI18NForLFM/Value',FDisableI18NForLFM,false);
// context data (project/session)
if (IsPartOfProject and SaveData)
or ((not IsPartOfProject) and SaveSession)
if (IsPartOfProject and SaveData) or ((not IsPartOfProject) and SaveSession)
then begin
XMLConfig.SetDeleteValue(Path+'ComponentName/Value',fComponentName,'');
XMLConfig.SetDeleteValue(Path+'HasResources/Value',fHasResources,false);
@ -2112,9 +2111,9 @@ end;
procedure TUnitInfo.IncreaseAutoRevertLock;
begin
inc(fAutoRevertLockCount);
if (fAutoRevertLockCount=1) then begin
if fAutoRevertLockCount=1 then begin
// activate lock
if (Source<>nil) then
if Source<>nil then
Source.LockAutoDiskRevert;
if Project<>nil then
Project.AddToOrRemoveFromAutoRevertLockedList(Self);
@ -2124,9 +2123,9 @@ end;
procedure TUnitInfo.DecreaseAutoRevertLock;
begin
dec(fAutoRevertLockCount);
if (fAutoRevertLockCount=0) then begin
if fAutoRevertLockCount=0 then begin
// deactivate lock
if (Source<>nil) then
if Source<>nil then
Source.LockAutoDiskRevert;
if Project<>nil then
Project.AddToOrRemoveFromAutoRevertLockedList(Self);
@ -2192,8 +2191,7 @@ begin
if fUsageCount<Min then fUsageCount:=Min;
end;
procedure TUnitInfo.UpdateUsageCount(TheUsage: TUnitUsage;
const Factor: TDateTime);
procedure TUnitInfo.UpdateUsageCount(TheUsage: TUnitUsage; const Factor: TDateTime);
begin
case TheUsage of
uuIsPartOfProject: UpdateUsageCount(20,200,2*Factor);
@ -2644,10 +2642,14 @@ begin
FProject:=AValue;
if FProject<>nil then begin
UpdatePageIndex;
if Component<>nil then Project.AddToList(Self,uilWithComponent);
if Loaded then Project.AddToList(Self,uilLoaded);
if IsAutoRevertLocked then Project.AddToList(Self,uilAutoRevertLocked);
if IsPartOfProject then Project.AddToList(Self,uilPartOfProject);
if Component<>nil then
Project.AddToList(Self,uilWithComponent);
if Loaded then
Project.AddToList(Self,uilLoaded);
if IsAutoRevertLocked then
Project.AddToList(Self,uilAutoRevertLocked);
if IsPartOfProject then
Project.AddToList(Self,uilPartOfProject);
for i := 0 to FEditorInfoList.Count - 1 do
FProject.EditorInfoAdd(FEditorInfoList[i]);
end;
@ -4490,7 +4492,8 @@ begin
end;
function TProject.RemoveProjectPathFromFilename(const AFilename: string): string;
var ProjectPath:string;
var
ProjectPath:string;
begin
ProjectPath:=Directory;
if ProjectPath='' then ProjectPath:=GetCurrentDirUTF8;
@ -4498,8 +4501,7 @@ begin
ForcePathDelims(Result);
// try making filename relative to project file
if FilenameIsAbsolute(Result)
and (CompareFileNames(copy(Result,1,length(ProjectPath)),ProjectPath)=0)
then
and (CompareFileNames(copy(Result,1,length(ProjectPath)),ProjectPath)=0) then
Result:=copy(Result,length(ProjectPath)+1,
length(Result)-length(ProjectPath));
end;

View File

@ -1309,10 +1309,7 @@ begin
if (FNewEditorInfo <> nil) and (FFlags * [ofProjectLoading, ofRevert] = [])
and (FNewEditorInfo.EditorComponent <> nil) then
begin
Result := ChangeEditorPage;
exit;
end;
exit(ChangeEditorPage);
Reverting:=ofRevert in FFlags;
if Reverting then
@ -1968,7 +1965,7 @@ function FileExistsInIDE(const Filename: string;
SearchFlags: TProjectFileSearchFlags): boolean;
begin
Result:=FileExistsCached(Filename)
or ((Project1<>nil) and (Project1.UnitInfoWithFilename(Filename,SearchFlags)<>nil));
or ((Project1<>nil) and (Project1.UnitInfoWithFilename(Filename,SearchFlags)<>nil));
end;
function BeautifySrc(const s: string): string;
@ -5903,28 +5900,23 @@ function LoadLFM(AnUnitInfo: TUnitInfo; OpenFlags: TOpenFlags;
CloseFlags: TCloseFlags): TModalResult;
// if there is a .lfm file, open the resource
var
UnitResourceFilename: string;
UnitResourceFileformat: TUnitResourcefileFormatClass;
ResFilename: string;
LFMBuf: TCodeBuffer;
CanAbort: boolean;
begin
CanAbort:=[ofProjectLoading,ofMultiOpen]*OpenFlags<>[];
UnitResourceFileformat:=AnUnitInfo.UnitResourceFileformat;
// Note: think about virtual and normal .lfm files.
UnitResourceFilename:=UnitResourceFileformat.GetUnitResourceFilename(AnUnitInfo.Filename,true);
with AnUnitInfo.UnitResourceFileformat do
ResFilename:=GetUnitResourceFilename(AnUnitInfo.Filename,true);
LFMBuf:=nil;
if not FileExistsInIDE(UnitResourceFilename,[pfsfOnlyEditorFiles]) then begin
// there is no LFM file -> ok
if not FileExistsInIDE(ResFilename,[pfsfOnlyEditorFiles]) then begin
{$IFDEF IDE_DEBUG}
debugln('LoadLFM there is no LFM file for "',AnUnitInfo.Filename,'"');
{$ENDIF}
Result:=mrOk;
exit;
exit(mrOk); // there is no LFM file -> ok
end;
// there is a lazarus form text file -> load it
Result:=LoadIDECodeBuffer(LFMBuf,UnitResourceFilename,[lbfUpdateFromDisk],CanAbort);
Result:=LoadIDECodeBuffer(LFMBuf,ResFilename,[lbfUpdateFromDisk],CanAbort);
if Result<>mrOk then begin
DebugLn(['LoadLFM LoadIDECodeBuffer failed']);
exit;
@ -6290,15 +6282,13 @@ function OpenComponent(const UnitFilename: string;
OpenFlags: TOpenFlags; CloseFlags: TCloseFlags; out Component: TComponent): TModalResult;
var
AnUnitInfo: TUnitInfo;
LFMFilename: String;
UnitCode: TCodeBuffer;
LFMCode: TCodeBuffer;
AFilename: String;
AFilename, LFMFilename: String;
UnitCode, LFMCode: TCodeBuffer;
begin
if Project1=nil then exit(mrCancel);
// try to find a unit name without expaning the path. this is required if unit is virtual
// in other case file name will be expanded with the wrong path
AFilename := UnitFilename;
AFilename:=UnitFilename;
AnUnitInfo:=Project1.UnitInfoWithFilename(AFilename);
if AnUnitInfo = nil then
begin
@ -6313,8 +6303,7 @@ begin
and (AnUnitInfo<>nil) and (AnUnitInfo.Component<>nil) then begin
// already open
Component:=AnUnitInfo.Component;
Result:=mrOk;
exit;
exit(mrOk);
end;
// ToDo: use UnitResources