Commit 4f131502 authored by Juha Manninen's avatar Juha Manninen
Browse files

IDE: Reload also .lfm file in designer when a unit was changed on disk....

IDE: Reload also .lfm file in designer when a unit was changed on disk. Improve DiskDiffsDialog. Issue #21587.

git-svn-id: trunk@64048 -
parent 78d5022a
object DiskDiffsDlg: TDiskDiffsDlg
Left = 314
Height = 353
Top = 351
Left = 396
Height = 361
Top = 348
Width = 600
ActiveControl = FilesListBox
Caption = 'DiskDiffsDlg'
ClientHeight = 353
ClientHeight = 361
ClientWidth = 600
KeyPreview = True
OnClose = FormClose
Position = poScreenCenter
LCLVersion = '1.7'
LCLVersion = '2.1.0.0'
object FilesListBox: TCheckListBox
Left = 6
Height = 86
......@@ -23,16 +23,15 @@ object DiskDiffsDlg: TDiskDiffsDlg
ItemHeight = 0
OnClick = FilesListBoxClick
TabOrder = 0
TopIndex = -1
end
inline DiffSynEdit: TSynEdit
AnchorSideBottom.Control = CheckDiskChangesWithLoadingCheckBox
AnchorSideBottom.Control = WarnSpeedButton
Left = 6
Height = 167
Height = 145
Top = 97
Width = 588
Align = alTop
BorderSpacing.Left = 6
BorderSpacing.Right = 6
BorderSpacing.Around = 6
Anchors = [akTop, akLeft, akRight, akBottom]
Font.Height = -12
Font.Name = 'courier'
......@@ -43,7 +42,7 @@ object DiskDiffsDlg: TDiskDiffsDlg
TabOrder = 2
BookMarkOptions.Xoffset = -18
Gutter.Visible = False
Gutter.Width = 59
Gutter.Width = 55
Gutter.MouseActions = <
item
ClickCount = ccAny
......@@ -468,6 +467,10 @@ object DiskDiffsDlg: TDiskDiffsDlg
SelectedColor.ItalicPriority = 50
SelectedColor.UnderlinePriority = 50
SelectedColor.StrikeOutPriority = 50
ScrollOnEditLeftOptions.ScrollExtraPercent = 20
ScrollOnEditLeftOptions.ScrollExtraMax = 10
ScrollOnEditRightOptions.ScrollExtraPercent = 30
ScrollOnEditRightOptions.ScrollExtraMax = 25
BracketHighlightStyle = sbhsBoth
BracketMatchColor.Background = clNone
BracketMatchColor.Foreground = clNone
......@@ -486,7 +489,7 @@ object DiskDiffsDlg: TDiskDiffsDlg
MouseActions = <>
end
object SynGutterLineNumber1: TSynGutterLineNumber
Width = 19
Width = 15
MouseActions = <>
MarkupInfo.Background = clBtnFace
MarkupInfo.Foreground = clNone
......@@ -573,68 +576,143 @@ object DiskDiffsDlg: TDiskDiffsDlg
AnchorSideLeft.Control = Owner
AnchorSideBottom.Control = BtnPanel
Left = 6
Height = 19
Top = 270
Width = 241
Anchors = [akLeft]
Height = 21
Top = 286
Width = 278
Anchors = [akLeft, akBottom]
BorderSpacing.Around = 6
Caption = 'CheckDiskChangesWithLoadingCheckBox'
TabOrder = 3
end
object BtnPanel: TPanel
Left = 0
Height = 37
Top = 316
Width = 600
Align = alBottom
AutoSize = True
BevelOuter = bvNone
ClientHeight = 37
ClientWidth = 600
TabOrder = 5
object RevertButton: TButton
Left = 499
Height = 25
Top = 6
Width = 95
Align = alRight
AutoSize = True
BorderSpacing.Around = 6
Caption = 'RevertButton'
Default = True
ModalResult = 6
TabOrder = 1
end
object IgnoreDiskChangesButton: TButton
Left = 329
Height = 25
Top = 6
Width = 164
Align = alRight
AutoSize = True
BorderSpacing.Around = 6
Caption = 'IgnoreDiskChangesButton'
ModalResult = 5
TabOrder = 0
end
end
object AutoCheckModifiedFilesCheckBox: TCheckBox
AnchorSideLeft.Control = Owner
AnchorSideTop.Control = CheckDiskChangesWithLoadingCheckBox
AnchorSideTop.Side = asrBottom
AnchorSideBottom.Control = BtnPanel
object BtnPanel: TButtonPanel
Left = 6
Height = 15
Top = 295
Width = 202
Anchors = [akTop, akLeft, akBottom]
BorderSpacing.Around = 6
Caption = 'AutoCheckModifiedFilesCheckBox'
Height = 42
Top = 313
Width = 588
OKButton.Name = 'OKButton'
OKButton.DefaultCaption = True
HelpButton.Name = 'HelpButton'
HelpButton.DefaultCaption = True
CloseButton.Name = 'CloseButton'
CloseButton.DefaultCaption = True
CancelButton.Name = 'CancelButton'
CancelButton.DefaultCaption = True
TabOrder = 4
ShowButtons = [pbOK, pbCancel, pbHelp]
end
object WarnLabel: TLabel
AnchorSideLeft.Control = WarnSpeedButton
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = WarnSpeedButton
AnchorSideTop.Side = asrCenter
Left = 45
Height = 19
Top = 255
Width = 66
BorderSpacing.Around = 6
Caption = 'WarnLabel'
Font.Color = clMaroon
ParentColor = False
ParentFont = False
end
object WarnSpeedButton: TSpeedButton
AnchorSideLeft.Control = CheckDiskChangesWithLoadingCheckBox
AnchorSideBottom.Control = CheckDiskChangesWithLoadingCheckBox
Left = 6
Height = 32
Top = 248
Width = 33
Anchors = [akLeft, akBottom]
Flat = True
Transparent = False
end
object SynDiffSyn1: TSynDiffSyn
Enabled = False
left = 135
top = 138
UnknownAttri.BackPriority = 0
UnknownAttri.ForePriority = 0
UnknownAttri.FramePriority = 0
UnknownAttri.BoldPriority = 0
UnknownAttri.ItalicPriority = 0
UnknownAttri.UnderlinePriority = 0
UnknownAttri.StrikeOutPriority = 0
SpaceAttri.BackPriority = 0
SpaceAttri.ForePriority = 0
SpaceAttri.FramePriority = 0
SpaceAttri.BoldPriority = 0
SpaceAttri.ItalicPriority = 0
SpaceAttri.UnderlinePriority = 0
SpaceAttri.StrikeOutPriority = 0
OrigFileAttri.BackPriority = 0
OrigFileAttri.ForePriority = 0
OrigFileAttri.FramePriority = 0
OrigFileAttri.BoldPriority = 0
OrigFileAttri.ItalicPriority = 0
OrigFileAttri.UnderlinePriority = 0
OrigFileAttri.StrikeOutPriority = 0
NewFileAttri.BackPriority = 0
NewFileAttri.ForePriority = 0
NewFileAttri.FramePriority = 0
NewFileAttri.BoldPriority = 0
NewFileAttri.ItalicPriority = 0
NewFileAttri.UnderlinePriority = 0
NewFileAttri.StrikeOutPriority = 0
ChunkMarkerAttri.BackPriority = 0
ChunkMarkerAttri.ForePriority = 0
ChunkMarkerAttri.FramePriority = 0
ChunkMarkerAttri.BoldPriority = 0
ChunkMarkerAttri.ItalicPriority = 0
ChunkMarkerAttri.UnderlinePriority = 0
ChunkMarkerAttri.StrikeOutPriority = 0
ChunkNewAttri.BackPriority = 0
ChunkNewAttri.ForePriority = 0
ChunkNewAttri.FramePriority = 0
ChunkNewAttri.BoldPriority = 0
ChunkNewAttri.ItalicPriority = 0
ChunkNewAttri.UnderlinePriority = 0
ChunkNewAttri.StrikeOutPriority = 0
ChunkOldAttri.BackPriority = 0
ChunkOldAttri.ForePriority = 0
ChunkOldAttri.FramePriority = 0
ChunkOldAttri.BoldPriority = 0
ChunkOldAttri.ItalicPriority = 0
ChunkOldAttri.UnderlinePriority = 0
ChunkOldAttri.StrikeOutPriority = 0
ChunkMixedAttri.BackPriority = 0
ChunkMixedAttri.ForePriority = 0
ChunkMixedAttri.FramePriority = 0
ChunkMixedAttri.BoldPriority = 0
ChunkMixedAttri.ItalicPriority = 0
ChunkMixedAttri.UnderlinePriority = 0
ChunkMixedAttri.StrikeOutPriority = 0
LineAddedAttri.BackPriority = 0
LineAddedAttri.ForePriority = 0
LineAddedAttri.FramePriority = 0
LineAddedAttri.BoldPriority = 0
LineAddedAttri.ItalicPriority = 0
LineAddedAttri.UnderlinePriority = 0
LineAddedAttri.StrikeOutPriority = 0
LineRemovedAttri.BackPriority = 0
LineRemovedAttri.ForePriority = 0
LineRemovedAttri.FramePriority = 0
LineRemovedAttri.BoldPriority = 0
LineRemovedAttri.ItalicPriority = 0
LineRemovedAttri.UnderlinePriority = 0
LineRemovedAttri.StrikeOutPriority = 0
LineChangedAttri.BackPriority = 0
LineChangedAttri.ForePriority = 0
LineChangedAttri.FramePriority = 0
LineChangedAttri.BoldPriority = 0
LineChangedAttri.ItalicPriority = 0
LineChangedAttri.UnderlinePriority = 0
LineChangedAttri.StrikeOutPriority = 0
LineContextAttri.BackPriority = 0
LineContextAttri.ForePriority = 0
LineContextAttri.FramePriority = 0
LineContextAttri.BoldPriority = 0
LineContextAttri.ItalicPriority = 0
LineContextAttri.UnderlinePriority = 0
LineContextAttri.StrikeOutPriority = 0
Left = 135
Top = 138
end
end
{
/***************************************************************************
diskdiffsdialog.pas
- form for showing the diffs of editor files changed on disk
***************************************************************************/
***************************************************************************
* *
* This source is free software; you can redistribute it and/or modify *
......@@ -24,6 +18,8 @@
* *
***************************************************************************
Abstract:
form for showing the diffs of editor files changed on disk
}
unit DiskDiffsDialog;
......@@ -35,11 +31,13 @@ uses
// RTL + FCL
Classes, SysUtils,
// LCL
LCLProc, LCLType, Forms, Controls, StdCtrls, ExtCtrls, CheckLst,
LCLProc, LCLType, Forms, StdCtrls, ExtCtrls, CheckLst, ButtonPanel, Buttons,
// CodeTools
FileProcs, CodeCache,
// LazUtils
LazUTF8Classes, LazFileUtils,
LazUTF8Classes, LazFileUtils, UITypes,
// IdeIntf
IDEImagesIntf,
// SynEdit
SynEdit, SynHighlighterDiff,
// IDE
......@@ -58,13 +56,12 @@ type
{ TDiskDiffsDlg }
TDiskDiffsDlg = class(TForm)
BtnPanel: TPanel;
BtnPanel: TButtonPanel;
CheckDiskChangesWithLoadingCheckBox: TCheckBox;
AutoCheckModifiedFilesCheckBox: TCheckBox;
DiffSynEdit: TSynEdit;
FilesListBox: TCheckListBox;
RevertButton: TButton;
IgnoreDiskChangesButton: TButton;
WarnLabel: TLabel;
WarnSpeedButton: TSpeedButton;
Splitter: TSplitter;
SynDiffSyn1: TSynDiffSyn;
procedure FilesListBoxClick(Sender: TObject);
......@@ -73,7 +70,9 @@ type
FIgnoreList: TFPList;
FPackageList: TStringList;
FUnitList: TFPList;
FHasLocalModifications: Boolean;
FCachedDiffs: TFPList; // List of PDiffItem
procedure AddFile2Box(AInfo: TObject; AFileName: string; AModified: Boolean);
procedure FillFilesListBox;
procedure ApplyChecks;
procedure ShowDiff;
......@@ -97,112 +96,113 @@ implementation
var
DiskDiffsDlg: TDiskDiffsDlg = nil;
function ShowDiskDiffsDialog(AnUnitList: TFPList; APackageList: TStringList;
AnIgnoreList: TFPList): TModalResult;
// Procedures used by ShowDiskDiffsDialog
function ListsAreEmpty: boolean;
begin
Result:=((AnUnitList=nil) or (AnUnitList.Count=0))
and ((APackageList=nil) or (APackageList.Count=0));
end;
procedure CheckUnitsWithLoading;
var
i: Integer;
CurUnit: TUnitInfo;
Changed: Boolean;
MemCode: TCodeBuffer;
s, DiskEncoding, MemEncoding: String;
fs: TFileStreamUTF8;
procedure CheckUnitsWithLoading(AnUnitList: TFPList);
var
i: Integer;
CurUnit: TUnitInfo;
CodeOk: Boolean;
MemCode: TCodeBuffer;
s, DiskEncoding, MemEncoding: String;
fs: TFileStreamUTF8;
begin
for i:=AnUnitList.Count-1 downto 0 do
begin
if AnUnitList=nil then exit;
for i:=AnUnitList.Count-1 downto 0 do begin
CurUnit:=TUnitInfo(AnUnitList[i]);
MemCode:=CurUnit.Source;
Changed:=true;
CurUnit:=TUnitInfo(AnUnitList[i]);
MemCode:=CurUnit.Source;
CodeOk:=false;
try
fs := TFileStreamUTF8.Create(MemCode.Filename, fmOpenRead or fmShareDenyNone);
try
fs := TFileStreamUTF8.Create(MemCode.Filename, fmOpenRead or fmShareDenyNone);
try
SetLength(s, fs.Size);
if s <> '' then
fs.Read(s[1], length(s));
DiskEncoding := '';
MemEncoding := '';
MemCode.CodeCache.OnDecodeLoaded(MemCode,MemCode.Filename,
s,DiskEncoding,MemEncoding);
//debugln(['CheckUnitsWithLoading ',MemCode.Filename,
// ' ',length(s),'=',MemCode.SourceLength]);
if (MemEncoding=MemCode.MemEncoding)
and (DiskEncoding=MemCode.DiskEncoding)
and (length(s)=MemCode.SourceLength)
and (s=MemCode.Source) then begin
Changed:=false;
end;
finally
fs.Free;
SetLength(s, fs.Size);
if s <> '' then
fs.Read(s[1], length(s));
DiskEncoding := '';
MemEncoding := '';
MemCode.CodeCache.OnDecodeLoaded(MemCode,MemCode.Filename,
s,DiskEncoding,MemEncoding);
//debugln(['CheckUnitsWithLoading ',MemCode.Filename,
// ' ',length(s),'=',MemCode.SourceLength]);
if (MemEncoding=MemCode.MemEncoding)
and (DiskEncoding=MemCode.DiskEncoding)
and (length(s)=MemCode.SourceLength)
and (s=MemCode.Source) then begin
CodeOk:=true;
end;
except
// unable to load
end;
if not Changed then begin
if (CurUnit.Source<>nil) then CurUnit.Source.MakeFileDateValid;
AnUnitList.Delete(i);
finally
fs.Free;
end;
except
// unable to load
end;
if CodeOk then begin
if CurUnit.Source<>nil then
CurUnit.Source.MakeFileDateValid;
AnUnitList.Delete(i);
end;
end;
procedure CheckPackagesWithLoading;
var
i: Integer;
CurPackage: TLazPackage;
PackageDidNotChange: Boolean;
fs: TFileStreamUTF8;
CurSource, DiskSource: string;
AltFilename: String;
end;
procedure CheckPackagesWithLoading(APackageList: TStringList);
var
i: Integer;
CurPackage: TLazPackage;
PackageOk: Boolean;
fs: TFileStreamUTF8;
CurSource, DiskSource: string;
AltFilename: String;
begin
for i:=APackageList.Count-1 downto 0 do
begin
if APackageList=nil then exit;
for i:=APackageList.Count-1 downto 0 do begin
AltFilename:=APackageList[i];
CurPackage:=TLazPackage(APackageList.Objects[i]);
PackageDidNotChange:=false;
if CurPackage.LPKSource=nil then
continue;// this package was not loaded/saved
if CompareFilenames(CurPackage.Filename,AltFilename)<>0 then
continue; // lpk has vanished, an alternative lpk was found => show
AltFilename:=APackageList[i];
CurPackage:=TLazPackage(APackageList.Objects[i]);
PackageOk:=false;
if CurPackage.LPKSource=nil then
continue; // this package was not loaded/saved
if CompareFilenames(CurPackage.Filename,AltFilename)<>0 then
continue; // lpk has vanished, an alternative lpk was found => show
try
CurPackage.SaveToString(CurSource);
fs:=TFileStreamUTF8.Create(CurPackage.Filename,fmOpenRead);
try
CurPackage.SaveToString(CurSource);
fs:=TFileStreamUTF8.Create(CurPackage.Filename,fmOpenRead);
try
if fs.Size=length(CurSource) then begin
// size has not changed => load to see difference
SetLength(DiskSource,fs.Size);
fs.Read(DiskSource[1],length(DiskSource));
if DiskSource=CurSource then
PackageDidNotChange:=true;
end;
finally
fs.Free;
end;
except
// unable to load
on E: Exception do begin
DebugLn(['CheckPackagesWithLoading Filename=',CurPackage.Filename,' Error=',E.Message]);
if fs.Size=length(CurSource) then begin
// size has not changed => load to see difference
SetLength(DiskSource,fs.Size);
fs.Read(DiskSource[1],length(DiskSource));
if DiskSource=CurSource then
PackageOk:=true;
end;
finally
fs.Free;
end;
if PackageDidNotChange then begin
APackageList.Delete(i);
end;
except
// unable to load
on E: Exception do
DebugLn(['CheckPackagesWithLoading Filename=',CurPackage.Filename,' Error=',E.Message]);
end;
if PackageOk then
APackageList.Delete(i);
end;
begin
if (DiskDiffsDlg<>nil) or ListsAreEmpty then begin
Result:=mrIgnore;
exit;
end;
function ShowDiskDiffsDialog(AnUnitList: TFPList; APackageList: TStringList;
AnIgnoreList: TFPList): TModalResult;
function ListsAreEmpty: boolean;
begin
Result:=((AnUnitList=nil) or (AnUnitList.Count=0))
and ((APackageList=nil) or (APackageList.Count=0));
end;
begin
if (DiskDiffsDlg<>nil) or ListsAreEmpty then
exit(mrIgnore);
if EnvironmentOptions.CheckDiskChangesWithLoading then begin
CheckUnitsWithLoading;
CheckPackagesWithLoading;
if Assigned(AnUnitList) then
CheckUnitsWithLoading(AnUnitList);
if Assigned(APackageList) then
CheckPackagesWithLoading(APackageList);
if ListsAreEmpty then exit(mrIgnore);
end;
DiskDiffsDlg:=TDiskDiffsDlg.Create(nil);
......@@ -211,10 +211,13 @@ begin
DiskDiffsDlg.IgnoreList:=AnIgnoreList;
DiskDiffsDlg.FillFilesListBox;
Result:=DiskDiffsDlg.ShowModal;
if Result=mrYes then
DiskDiffsDlg.ApplyChecks;
case Result of
mrOK : DiskDiffsDlg.ApplyChecks;
mrCancel : Result:=mrIgnore;
end;
DiskDiffsDlg.Free;
DiskDiffsDlg:=nil;
Assert(Result in [mrOK,mrIgnore], 'ShowDiskDiffsDialog: Invalid result '+IntToStr(Result));
end;
{ TDiskDiffsDlg }
......@@ -227,42 +230,47 @@ end;
procedure TDiskDiffsDlg.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
EnvironmentOptions.CheckDiskChangesWithLoading:=CheckDiskChangesWithLoadingCheckBox.Checked;
EnvironmentOptions.DiskChangesAutoCheckModified:=AutoCheckModifiedFilesCheckBox.Checked;
end;
procedure TDiskDiffsDlg.AddFile2Box(AInfo: TObject; AFileName: string; AModified: Boolean);
var
i: Integer;
begin
if AModified then
AFileName:='*'+AFileName;
i:=FilesListBox.Items.AddObject(AFileName,AInfo);
if AModified then
FHasLocalModifications:=True
else
FilesListBox.Checked[i]:=True;
end;
procedure TDiskDiffsDlg.FillFilesListBox;
var i, ii: integer;
AnUnitInfo: TUnitInfo;
var
i: integer;
UInfo: TUnitInfo;
APackage: TLazPackage;
AFileName: string;
begin
FHasLocalModifications:=False;
FilesListBox.Items.BeginUpdate;
FilesListBox.Items.Clear;
if UnitList<>nil then
begin
for i:=0 to UnitList.Count-1 do begin
AnUnitInfo:=TUnitInfo(UnitList[i]);
AFileName:=AnUnitInfo.ShortFilename;
if AnUnitInfo.Modified then
AFileName:='*'+AFileName;
ii := FilesListBox.Items.AddObject(AFileName,AnUnitInfo);
if AutoCheckModifiedFilesCheckBox.Checked or not AnUnitInfo.Modified then
FilesListBox.Checked[ii] := True;
UInfo:=TUnitInfo(UnitList[i]);
AddFile2Box(UInfo, UInfo.ShortFilename, UInfo.Modified);
end;
end;
if PackageList<>nil then
begin
for i:=0 to PackageList.Count-1 do begin
APackage:=TLazPackage(PackageList.Objects[i]);
AFileName:=APackage.Filename;
if APackage.Modified then
AFileName:='*'+AFileName;
ii := FilesListBox.Items.AddObject(AFileName,APackage);
if AutoCheckModifiedFilesCheckBox.Checked or not APackage.Modified then
FilesListBox.Checked[ii] := True;
AddFile2Box(APackage, APackage.Filename, APackage.Modified);
end;
end;
FilesListBox.Items.EndUpdate;
WarnSpeedButton.Visible:=FHasLocalModifications;
WarnLabel.Visible:=FHasLocalModifications;
end;
procedure TDiskDiffsDlg.ShowDiff;
......@@ -375,15 +383,19 @@ begin
Caption:=lisDiskDiffSomeFilesHaveChangedOnDisk;
EditorOpts.GetSynEditSettings(DiffSynEdit);
DiffSynEdit.Lines.Text:=lisDiskDiffClickOnOneOfTheAboveItemsToSeeTheDiff;
RevertButton.Caption:=lisDiskDiffReloadCheckedFilesFromDisk;
IgnoreDiskChangesButton.Caption:=lisDiskDiffIgnoreAllDiskChanges;
BtnPanel.OkButton.Caption:=lisDiskDiffReloadCheckedFilesFromDisk;
Assert(BtnPanel.OKButton.ModalResult=mrOK, 'OKButton.ModalResult<>mrOK');
// Cancel button now means Ignore All Disk Changes
BtnPanel.CancelButton.Caption:=lisDiskDiffIgnoreAllDiskChanges;
IDEImages.AssignImage(WarnSpeedButton, 'state_warning');
WarnLabel.Caption:=lisDiskDiffSomeFilesChangedLocally;
WarnLabel.Visible:=False;
WarnSpeedButton.Visible:=False;
CheckDiskChangesWithLoadingCheckBox.Caption:=lisCheckForDiskFileChangesViaContent;