ide: reload changed files dialog:

1) use TCheckListBox
2) allow to reload changed files too (unchecked by default, prefixed with *).

git-svn-id: trunk@51852 -
This commit is contained in:
ondrej 2016-03-07 20:36:45 +00:00
parent 06d19a8613
commit 3dd60b3899
9 changed files with 129 additions and 84 deletions

View File

@ -85,9 +85,9 @@ type
function SaveToFile(const AFilename: string): boolean; override;
function Save: boolean;
function FileDateOnDisk: longint;
function FileNeedsUpdate: boolean; // needs loading
function FileNeedsUpdate(IgnoreModifiedFlag: Boolean = False): boolean; // needs loading
function FileOnDiskNeedsUpdate: boolean;
function FileOnDiskHasChanged: boolean;
function FileOnDiskHasChanged(IgnoreModifiedFlag: Boolean = False): boolean;
function FileOnDiskIsEqual: boolean;
function AutoRevertFromDisk: boolean;
procedure LockAutoDiskRevert;
@ -1444,14 +1444,21 @@ begin
Result:=FileAgeCached(Filename);
end;
function TCodeBuffer.FileNeedsUpdate: boolean;
function TCodeBuffer.FileNeedsUpdate(IgnoreModifiedFlag: Boolean): boolean;
// file needs update (to be loaded), if file is not modified and file on disk has changed
begin
if Modified or IsVirtual then exit(false);
if LoadDateValid then
Result:=(FFileChangeStep=ChangeStep) and (FileDateOnDisk<>LoadDate)
else
Result:=true;
if IgnoreModifiedFlag then
begin
if IsVirtual then exit(false);
Result:=FileDateOnDisk<>LoadDate; // ignore LoadDateValid because it is set to false after edit
end else
begin
if Modified or IsVirtual then exit(false);
if LoadDateValid then
Result:=(FFileChangeStep=ChangeStep) and (FileDateOnDisk<>LoadDate)
else
Result:=true;
end;
end;
function TCodeBuffer.FileOnDiskNeedsUpdate: boolean;
@ -1464,13 +1471,19 @@ begin
or (not FileExistsCached(Filename));
end;
function TCodeBuffer.FileOnDiskHasChanged: boolean;
function TCodeBuffer.FileOnDiskHasChanged(IgnoreModifiedFlag: Boolean): boolean;
// file on disk has changed since last load/save
begin
if LoadDateValid and FileExistsCached(Filename) then
Result:=(FileDateOnDisk<>LoadDate)
else
Result:=false;
if IgnoreModifiedFlag then
begin
Result:=FileDateOnDisk<>LoadDate; // ignore LoadDateValid because it is set to false after edit
end else
begin
if LoadDateValid and FileExistsCached(Filename) then
Result:=(FileDateOnDisk<>LoadDate)
else
Result:=false;
end;
end;
function TCodeBuffer.FileOnDiskIsEqual: boolean;

View File

@ -9,25 +9,25 @@ object DiskDiffsDlg: TDiskDiffsDlg
ClientWidth = 600
KeyPreview = True
OnClose = FormClose
OnKeyDown = DiskDiffsDlgKeyDown
Position = poScreenCenter
LCLVersion = '1.5'
object FilesListBox: TListBox
LCLVersion = '1.7'
object FilesListBox: TCheckListBox
Left = 6
Height = 86
Top = 6
Width = 594
Width = 588
Align = alTop
BorderSpacing.Left = 6
BorderSpacing.Top = 6
BorderSpacing.Right = 6
ItemHeight = 0
OnSelectionChange = FilesListBoxSelectionChange
OnClick = FilesListBoxClick
TabOrder = 0
end
inline DiffSynEdit: TSynEdit
AnchorSideBottom.Control = CheckDiskChangesWithLoadingCheckBox
Left = 6
Height = 193
Height = 189
Top = 97
Width = 588
Align = alTop
@ -573,9 +573,9 @@ object DiskDiffsDlg: TDiskDiffsDlg
AnchorSideLeft.Control = Owner
AnchorSideBottom.Control = BtnPanel
Left = 6
Height = 17
Top = 296
Width = 216
Height = 19
Top = 292
Width = 241
Anchors = [akLeft, akBottom]
BorderSpacing.Around = 6
Caption = 'CheckDiskChangesWithLoadingCheckBox'
@ -583,33 +583,33 @@ object DiskDiffsDlg: TDiskDiffsDlg
end
object BtnPanel: TPanel
Left = 0
Height = 35
Top = 319
Height = 37
Top = 317
Width = 600
Align = alBottom
AutoSize = True
BevelOuter = bvNone
ClientHeight = 35
ClientHeight = 37
ClientWidth = 600
TabOrder = 4
object RevertAllButton: TButton
Left = 492
Height = 23
object RevertButton: TButton
Left = 499
Height = 25
Top = 6
Width = 102
Width = 95
Align = alRight
AutoSize = True
BorderSpacing.Around = 6
Caption = 'RevertAllButton'
Caption = 'RevertButton'
Default = True
ModalResult = 10
ModalResult = 6
TabOrder = 1
end
object IgnoreDiskChangesButton: TButton
Left = 335
Height = 23
Left = 329
Height = 25
Top = 6
Width = 151
Width = 164
Align = alRight
AutoSize = True
BorderSpacing.Around = 6

View File

@ -34,6 +34,7 @@ interface
uses
// RTL + FCL + LCL
Classes, SysUtils, LCLProc, Forms, Controls, StdCtrls, ExtCtrls, LCLType,
CheckLst,
// CodeTools
FileProcs, CodeCache,
// LazUtils
@ -60,32 +61,33 @@ type
BtnPanel: TPanel;
CheckDiskChangesWithLoadingCheckBox: TCheckBox;
DiffSynEdit: TSynEdit;
FilesListBox: TListBox;
RevertAllButton: TButton;
FilesListBox: TCheckListBox;
RevertButton: TButton;
IgnoreDiskChangesButton: TButton;
Splitter: TSplitter;
SynDiffSyn1: TSynDiffSyn;
procedure DiskDiffsDlgKeyDown(Sender: TObject; var Key: Word;
{%H-}Shift: TShiftState);
procedure FilesListBoxSelectionChange(Sender: TObject; User: boolean);
procedure FilesListBoxClick(Sender: TObject);
procedure FormClose(Sender: TObject; var {%H-}CloseAction: TCloseAction);
private
FIgnoreList: TFPList;
FPackageList: TStringList;
FUnitList: TFPList;
FCachedDiffs: TFPList; // List of PDiffItem
procedure FillFilesListBox;
procedure ApplyChecks;
procedure ShowDiff;
function GetCachedDiff(FileOwner: TObject; AltFilename: string): PDiffItem;
procedure ClearCache;
public
property UnitList: TFPList read FUnitList write FUnitList; // list of TUnitInfo
property PackageList: TStringList read FPackageList write FPackageList; // list of alternative filename and TLazPackage
property IgnoreList: TFPList read FIgnoreList write FIgnoreList;
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
end;
function ShowDiskDiffsDialog(AnUnitList: TFPList; APackageList: TStringList): TModalResult;
function ShowDiskDiffsDialog(AnUnitList: TFPList;
APackageList: TStringList; AnIgnoreList: TFPList): TModalResult;
implementation
@ -94,7 +96,8 @@ implementation
var
DiskDiffsDlg: TDiskDiffsDlg = nil;
function ShowDiskDiffsDialog(AnUnitList: TFPList; APackageList: TStringList): TModalResult;
function ShowDiskDiffsDialog(AnUnitList: TFPList; APackageList: TStringList;
AnIgnoreList: TFPList): TModalResult;
function ListsAreEmpty: boolean;
begin
@ -194,29 +197,20 @@ begin
DiskDiffsDlg:=TDiskDiffsDlg.Create(nil);
DiskDiffsDlg.UnitList:=AnUnitList;
DiskDiffsDlg.PackageList:=APackageList;
DiskDiffsDlg.IgnoreList:=AnIgnoreList;
DiskDiffsDlg.FillFilesListBox;
Result:=DiskDiffsDlg.ShowModal;
if Result=mrYes then
DiskDiffsDlg.ApplyChecks;
DiskDiffsDlg.Free;
DiskDiffsDlg:=nil;
end;
{ TDiskDiffsDlg }
procedure TDiskDiffsDlg.DiskDiffsDlgKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure TDiskDiffsDlg.FilesListBoxClick(Sender: TObject);
begin
if Key = VK_Escape then
ModalResult := mrIgnore
else
if Key = VK_Return then
ModalResult := mrYesToAll;
end;
procedure TDiskDiffsDlg.FilesListBoxSelectionChange(Sender: TObject;
User: boolean);
begin
if User then
ShowDiff;
ShowDiff;
end;
procedure TDiskDiffsDlg.FormClose(Sender: TObject; var CloseAction: TCloseAction);
@ -225,21 +219,32 @@ begin
end;
procedure TDiskDiffsDlg.FillFilesListBox;
var i: integer;
var i, ii: integer;
AnUnitInfo: TUnitInfo;
APackage: TLazPackage;
AFileName: string;
begin
FilesListBox.Items.BeginUpdate;
FilesListBox.Items.Clear;
if UnitList<>nil then
for i:=0 to UnitList.Count-1 do begin
AnUnitInfo:=TUnitInfo(UnitList[i]);
FilesListBox.Items.AddObject(AnUnitInfo.ShortFilename,AnUnitInfo);
AFileName:=AnUnitInfo.ShortFilename;
if AnUnitInfo.Modified then
AFileName:='*'+AFileName;
ii := FilesListBox.Items.AddObject(AFileName,AnUnitInfo);
if not AnUnitInfo.Modified then
FilesListBox.Checked[ii] := True;
end;
if PackageList<>nil then
for i:=0 to PackageList.Count-1 do begin
APackage:=TLazPackage(PackageList.Objects[i]);
FilesListBox.Items.AddObject(APackage.Filename,APackage);
AFileName:=APackage.Filename;
if APackage.Modified then
AFileName:='*'+AFileName;
ii := FilesListBox.Items.AddObject(AFileName,APackage);
if not APackage.Modified then
FilesListBox.Checked[ii] := True;
end;
FilesListBox.Items.EndUpdate;
end;
@ -354,10 +359,23 @@ begin
Caption:=lisDiskDiffSomeFilesHaveChangedOnDisk;
EditorOpts.GetSynEditSettings(DiffSynEdit);
DiffSynEdit.Lines.Text:=lisDiskDiffClickOnOneOfTheAboveItemsToSeeTheDiff;
RevertAllButton.Caption:=lisDiskDiffRevertAll;
IgnoreDiskChangesButton.Caption:=lisDiskDiffIgnoreDiskChanges;
RevertButton.Caption:=lisDiskDiffReloadCheckedFilesFromDisk;
IgnoreDiskChangesButton.Caption:=lisDiskDiffIgnoreAllDiskChanges;
CheckDiskChangesWithLoadingCheckBox.Caption:=lisCheckForDiskFileChangesViaContent;
CheckDiskChangesWithLoadingCheckBox.Checked:=EnvironmentOptions.CheckDiskChangesWithLoading;
DefaultControl:=RevertButton;
CancelControl:=IgnoreDiskChangesButton;
end;
procedure TDiskDiffsDlg.ApplyChecks;
var
i: Integer;
begin
FIgnoreList.Clear;
for i := 0 to FilesListBox.Count-1 do
if not FilesListBox.Checked[i] then
FIgnoreList.Add(FilesListBox.Items.Objects[i]);
end;
destructor TDiskDiffsDlg.Destroy;

View File

@ -3969,8 +3969,8 @@ resourcestring
lisDiskDiffSomeFilesHaveChangedOnDisk = 'Some files have changed on disk:';
lisDiskDiffClickOnOneOfTheAboveItemsToSeeTheDiff = 'Click on one of the '
+'above items to see the diff';
lisDiskDiffRevertAll = 'Reload from disk';
lisDiskDiffIgnoreDiskChanges = 'Ignore disk changes';
lisDiskDiffReloadCheckedFilesFromDisk = 'Reload checked files from disk';
lisDiskDiffIgnoreAllDiskChanges = 'Ignore all disk changes';
// edit define tree
lisEdtDefCurrentProject = 'Current Project';

View File

@ -345,7 +345,7 @@ type
function GetFileOwner: TObject; override;
function GetFileOwnerName: string; override;
function ChangedOnDisk(CompareOnlyLoadSaveTime: boolean): boolean;
function ChangedOnDisk(CompareOnlyLoadSaveTime: boolean; IgnoreModifiedFlag: boolean = False): boolean;
function IsAutoRevertLocked: boolean;
function IsReverting: boolean;
function IsMainUnit: boolean;
@ -885,7 +885,7 @@ type
function SomeDataModified(Verbose: boolean = false): boolean;
function SomeSessionModified(Verbose: boolean = false): boolean;
procedure MainSourceFilenameChanged;
procedure GetUnitsChangedOnDisk(var AnUnitList: TFPList);
procedure GetUnitsChangedOnDisk(var AnUnitList: TFPList; IgnoreModifiedFlag: boolean = False);
function HasProjectInfoFileChangedOnDisk: boolean;
procedure IgnoreProjectInfoFileOnDisk;
function ReadProject(const NewProjectInfoFile: string;
@ -2071,9 +2071,10 @@ begin
Result:=FRevertLockCount>0;
end;
function TUnitInfo.ChangedOnDisk(CompareOnlyLoadSaveTime: boolean): boolean;
function TUnitInfo.ChangedOnDisk(CompareOnlyLoadSaveTime: boolean;
IgnoreModifiedFlag: boolean): boolean;
begin
Result:=(Source<>nil) and Source.FileOnDiskHasChanged;
Result:=(Source<>nil) and Source.FileOnDiskHasChanged(IgnoreModifiedFlag);
//if Result then debugln(['TUnitInfo.ChangedOnDisk ',Filename,' FileAgeCached=',FileAgeCached(Source.Filename)]);
if Result
and (not CompareOnlyLoadSaveTime)
@ -4362,7 +4363,8 @@ begin
ExtendPath(SrcPathMacroName,CompilerOptions.SrcPath);
end;
procedure TProject.GetUnitsChangedOnDisk(var AnUnitList: TFPList);
procedure TProject.GetUnitsChangedOnDisk(var AnUnitList: TFPList;
IgnoreModifiedFlag: boolean);
var
AnUnitInfo: TUnitInfo;
begin
@ -4370,7 +4372,7 @@ begin
AnUnitInfo:=fFirst[uilAutoRevertLocked];
while (AnUnitInfo<>nil) do begin
if (AnUnitInfo.Source<>nil)
and AnUnitInfo.ChangedOnDisk(false) then begin
and AnUnitInfo.ChangedOnDisk(false, IgnoreModifiedFlag) then begin
if AnUnitList=nil then
AnUnitList:=TFPList.Create;
AnUnitList.Add(AnUnitInfo);

View File

@ -2986,7 +2986,7 @@ end;
function TLazSourceFileManager.CheckFilesOnDisk(Instantaneous: boolean): TModalResult;
var
AnUnitList: TFPList; // list of TUnitInfo
AnUnitList, AIgnoreList: TFPList; // list of TUnitInfo
APackageList: TStringList; // list of alternative lpkfilename and TLazPackage
i: integer;
CurUnit: TUnitInfo;
@ -3005,7 +3005,9 @@ begin
FCheckingFilesOnDisk:=true;
AnUnitList:=nil;
APackageList:=nil;
AIgnoreList:=nil;
try
AIgnoreList := TFPList.Create;
InvalidateFileStateCache;
if Project1.HasProjectInfoFileChangedOnDisk then begin
@ -3020,11 +3022,11 @@ begin
exit(mrOk);
end;
Project1.GetUnitsChangedOnDisk(AnUnitList);
PkgBoss.GetPackagesChangedOnDisk(APackageList);
Project1.GetUnitsChangedOnDisk(AnUnitList, True);
PkgBoss.GetPackagesChangedOnDisk(APackageList, True);
if (AnUnitList=nil) and (APackageList=nil) then exit;
Result:=ShowDiskDiffsDialog(AnUnitList,APackageList);
if Result in [mrYesToAll] then
Result:=ShowDiskDiffsDialog(AnUnitList,APackageList,AIgnoreList);
if Result in [mrYes,mrYesToAll] then
Result:=mrOk;
// reload units
@ -3032,7 +3034,9 @@ begin
for i:=0 to AnUnitList.Count-1 do begin
CurUnit:=TUnitInfo(AnUnitList[i]);
//DebugLn(['TLazSourceFileManager.CheckFilesOnDisk revert ',CurUnit.Filename,' EditorIndex=',CurUnit.EditorIndex]);
if Result=mrOk then begin
if (Result=mrOk)
and (AIgnoreList.IndexOf(CurUnit)<0) then // ignore current
begin
if CurUnit.OpenEditorInfoCount > 0 then begin
// Revert one Editor-View, the others follow
Result:=OpenEditorFile(CurUnit.Filename, CurUnit.OpenEditorInfo[0].PageIndex,
@ -3054,14 +3058,21 @@ begin
end;
// reload packages
Result:=PkgBoss.RevertPackages(APackageList);
if Result<>mrOk then exit;
if APackageList<>nil then
begin
for i:=APackageList.Count-1 downto 0 do
if AIgnoreList.IndexOf(APackageList.Objects[i])>=0 then
APackageList.Delete(i);
Result:=PkgBoss.RevertPackages(APackageList);
if Result<>mrOk then exit;
end;
Result:=mrOk;
finally
FCheckingFilesOnDisk:=false;
AnUnitList.Free;
APackageList.Free;
AIgnoreList.Free;
end;
end;

View File

@ -122,7 +122,7 @@ type
procedure OpenHiddenModifiedPackages; virtual; abstract;
// package graph
procedure GetPackagesChangedOnDisk(out ListOfPackages: TStringList); virtual; abstract;
procedure GetPackagesChangedOnDisk(out ListOfPackages: TStringList; IgnoreModifiedFlag: boolean = False); virtual; abstract;
function RevertPackages(APackageList: TStringList // list of TLazPackage and alternative lpk file name
): TModalResult; virtual; abstract;
function CheckUserSearchPaths(aCompilerOptions: TBaseCompilerOptions): TModalResult; virtual; abstract;

View File

@ -335,7 +335,7 @@ type
var PkgList: TFPList; var Tree: TPkgPairTree);
function GetBrokenDependenciesWhenChangingPkgID(APackage: TLazPackage;
const NewName: string; NewVersion: TPkgVersion): TFPList;
procedure GetPackagesChangedOnDisk(out ListOfPackages: TStringList); // returns list of new filename and TLazPackage
procedure GetPackagesChangedOnDisk(out ListOfPackages: TStringList; IgnoreModifiedFlag: boolean = False); // returns list of new filename and TLazPackage
procedure GetAllRequiredPackages(APackage: TLazPackage; // if not nil then ignore FirstDependency and do not add APackage to Result
FirstDependency: TPkgDependency;
out List: TFPList;
@ -5166,7 +5166,7 @@ begin
end;
procedure TLazPackageGraph.GetPackagesChangedOnDisk(out
ListOfPackages: TStringList);
ListOfPackages: TStringList; IgnoreModifiedFlag: boolean);
// if package source is changed in IDE (codetools)
// then changes on disk are ignored
var
@ -5198,7 +5198,7 @@ begin
NewFilename:=APackage.Filename;
if FileExistsCached(APackage.Filename) then begin
if (APackage.LPKSource<>nil)
and (not APackage.LPKSource.FileNeedsUpdate) then
and (not APackage.LPKSource.FileNeedsUpdate(IgnoreModifiedFlag)) then
continue;
// a lpk has changed, this might include dependencies => reload lpl files
UpdateGlobalLinks;

View File

@ -259,7 +259,7 @@ type
function AddDependencyToUnitOwners(const OwnedFilename,
RequiredUnitname: string): TModalResult; override;
function RedirectPackageDependency(APackage: TIDEPackage): TIDEPackage; override;
procedure GetPackagesChangedOnDisk(out ListOfPackages: TStringList); override;
procedure GetPackagesChangedOnDisk(out ListOfPackages: TStringList; IgnoreModifiedFlag: boolean = False); override;
function RevertPackages(APackageList: TStringList): TModalResult; override;
// project
@ -5003,10 +5003,11 @@ begin
end;
end;
procedure TPkgManager.GetPackagesChangedOnDisk(out ListOfPackages: TStringList);
procedure TPkgManager.GetPackagesChangedOnDisk(out ListOfPackages: TStringList;
IgnoreModifiedFlag: boolean);
begin
if PackageGraph=nil then exit;
PackageGraph.GetPackagesChangedOnDisk(ListOfPackages);
PackageGraph.GetPackagesChangedOnDisk(ListOfPackages, IgnoreModifiedFlag);
end;
function TPkgManager.RevertPackages(APackageList: TStringList): TModalResult;