IDE: Improve the behavior of ViewUnit dialog. Support initial selection etc.

This commit is contained in:
Juha 2025-03-06 22:57:32 +02:00
parent ca8aa3f8c6
commit 7a6a7a85c8
4 changed files with 62 additions and 30 deletions

View File

@ -5993,7 +5993,7 @@ begin
AnUnitInfo := nil; AnUnitInfo := nil;
for UEntry in UnitList do for UEntry in UnitList do
begin begin
if not UEntry.Selected then continue; if not (vufSelected in UEntry.Flags) then continue;
AnUnitInfo := Project1.Units[UEntry.ID]; AnUnitInfo := Project1.Units[UEntry.ID];
if AnUnitInfo.OpenEditorInfoCount > 0 then if AnUnitInfo.OpenEditorInfoCount > 0 then
begin begin

View File

@ -188,6 +188,7 @@ type
fViewUnitEntries: TViewUnitEntries; fViewUnitEntries: TViewUnitEntries;
fSelectCaption: String; fSelectCaption: String;
protected protected
function InitialSelection(aFilename: string): Boolean; virtual;
function Select: TModalResult; //virtual; // Select with a dialog. function Select: TModalResult; //virtual; // Select with a dialog.
function ActionForFiles: TModalResult; virtual; abstract; function ActionForFiles: TModalResult; virtual; abstract;
public public
@ -210,6 +211,7 @@ type
TRenameFilesSelector = class(TProjectUnitFileSelector) TRenameFilesSelector = class(TProjectUnitFileSelector)
protected protected
function InitialSelection(aFilename: string): Boolean; override;
function ActionForFiles: TModalResult; override; function ActionForFiles: TModalResult; override;
public public
constructor Create; constructor Create;
@ -1753,12 +1755,16 @@ begin
inherited Destroy; inherited Destroy;
end; end;
function TProjectUnitFileSelector.InitialSelection(aFilename: string): Boolean;
begin
Result:=False;
end;
function TProjectUnitFileSelector.Select: TModalResult; function TProjectUnitFileSelector.Select: TModalResult;
var var
i:integer; i: integer;
AName: string; AName: string;
AnUnitInfo: TUnitInfo; AnUnitInfo: TUnitInfo;
UnitInfos: TFPList;
UEntry: TViewUnitsEntry; UEntry: TViewUnitsEntry;
Begin Begin
Result:=mrOK; Result:=mrOK;
@ -1770,7 +1776,8 @@ Begin
if (AnUnitInfo.IsPartOfProject) and (i<>Project1.MainUnitID) then if (AnUnitInfo.IsPartOfProject) and (i<>Project1.MainUnitID) then
begin begin
AName:=Project1.RemoveProjectPathFromFilename(AnUnitInfo.FileName); AName:=Project1.RemoveProjectPathFromFilename(AnUnitInfo.FileName);
fViewUnitEntries.Add(AName,AnUnitInfo.FileName,i,false,false); fViewUnitEntries.Add(AName, AnUnitInfo.FileName, i,
InitialSelection(AName), AnUnitInfo.OpenEditorInfoCount>0);
end; end;
end; end;
if ShowViewUnitsDlg(fViewUnitEntries,true,fSelectCaption,piUnit) <> mrOk then if ShowViewUnitsDlg(fViewUnitEntries,true,fSelectCaption,piUnit) <> mrOk then
@ -1779,7 +1786,7 @@ Begin
fUnitInfos:=TFPList.Create; fUnitInfos:=TFPList.Create;
for UEntry in fViewUnitEntries do for UEntry in fViewUnitEntries do
begin begin
if UEntry.Selected then if vufSelected in UEntry.Flags then
begin begin
if UEntry.ID<0 then continue; if UEntry.ID<0 then continue;
AnUnitInfo:=Project1.Units[UEntry.ID]; AnUnitInfo:=Project1.Units[UEntry.ID];
@ -1914,6 +1921,11 @@ begin
inherited; inherited;
end; end;
function TRenameFilesSelector.InitialSelection(aFilename: string): Boolean;
begin // Select only units having mixed case filename.
Result:=aFilename<>LowerCase(aFilename);
end;
function TRenameFilesSelector.ActionForFiles: TModalResult; function TRenameFilesSelector.ActionForFiles: TModalResult;
var var
i: Integer; i: Integer;
@ -1928,8 +1940,7 @@ begin
+ AnUnitInfo.Unit_Name + ' is not part of project'); + AnUnitInfo.Unit_Name + ' is not part of project');
if AnUnitInfo.Source=nil then if AnUnitInfo.Source=nil then
AnUnitInfo.ReadUnitSource(false,false); AnUnitInfo.ReadUnitSource(false,false);
// Marked here means to remove old files silently. Result:=RenameUnitLowerCase(AnUnitInfo,false,true);
Result:=RenameUnitLowerCase(AnUnitInfo, false,True);
if Result<>mrOK then exit; if Result<>mrOK then exit;
end; end;
InvalidateFileStateCache; InvalidateFileStateCache;
@ -3896,7 +3907,7 @@ begin
DlgCaption, ItemType, ActiveUnitInfo.Filename); DlgCaption, ItemType, ActiveUnitInfo.Filename);
// create list of selected files // create list of selected files
for Entry in UnitList do for Entry in UnitList do
if Entry.Selected then if vufSelected in Entry.Flags then
Files.Add(Entry.Filename); Files.Add(Entry.Filename);
finally finally

View File

@ -12,6 +12,8 @@ object ViewUnitDialog: TViewUnitDialog
Caption = 'View Project Units' Caption = 'View Project Units'
ClientHeight = 386 ClientHeight = 386
ClientWidth = 378 ClientWidth = 378
Position = poScreenCenter
LCLVersion = '4.99.0.0'
OnClose = FormClose OnClose = FormClose
OnCreate = FormCreate OnCreate = FormCreate
OnDestroy = FormDestroy OnDestroy = FormDestroy

View File

@ -65,14 +65,19 @@ type
piFrame piFrame
); );
TViewUnitFlag = (
vufSelected,
vufOpen
);
TViewUnitFlags = set of TViewUnitFlag;
{ TViewUnitsEntry } { TViewUnitsEntry }
TViewUnitsEntry = class TViewUnitsEntry = class
public public
Name: string; Name: string;
ID: integer; ID: integer;
Selected: boolean; Flags: TViewUnitFlags;
Open: boolean;
Filename: string; Filename: string;
constructor Create(const AName, AFilename: string; AnID: integer; ASelected, AOpen: boolean); constructor Create(const AName, AFilename: string; AnID: integer; ASelected, AOpen: boolean);
end; end;
@ -139,6 +144,7 @@ type
procedure CancelButtonClick(Sender :TObject); procedure CancelButtonClick(Sender :TObject);
procedure MultiselectCheckBoxClick(Sender :TObject); procedure MultiselectCheckBoxClick(Sender :TObject);
private private
FFirstDraw: boolean;
FIdleConnected: boolean; FIdleConnected: boolean;
FItemType: TIDEProjectItem; FItemType: TIDEProjectItem;
FSortAlphabetically: boolean; FSortAlphabetically: boolean;
@ -304,8 +310,10 @@ begin
inherited Create; inherited Create;
Name := AName; Name := AName;
ID := AnID; ID := AnID;
Selected := ASelected; if ASelected then
Open := AOpen; Include(Flags, vufSelected);
if AOpen then
Include(Flags, vufOpen);
Filename := AFilename; Filename := AFilename;
end; end;
@ -371,13 +379,14 @@ begin
fEntries:=TheEntries; fEntries:=TheEntries;
mniMultiselect.Enabled := EnableMultiSelect; mniMultiselect.Enabled := EnableMultiSelect;
mniMultiselect.Checked := EnableMultiSelect; mniMultiselect.Checked := EnableMultiSelect;
ListBox.MultiSelect := mniMultiselect.Enabled; ListBox.MultiSelect := mniMultiselect.Checked;
FFirstDraw := True;
ShowEntries; ShowEntries;
FilterEdit.SimpleSelection := true; FilterEdit.SimpleSelection := true;
if aStartFilename<>'' then begin if aStartFilename<>'' then begin
// init search for units // init search for units -> get unit search path and fill fSearchDirectories
// -> get unit search path and fill fSearchDirectories // The entries should not have "Selected" flag set because the list gets updated.
fStartFilename:=TrimFilename(aStartFilename); fStartFilename:=TrimFilename(aStartFilename);
SearchPath:=CodeToolBoss.GetCompleteSrcPathForDirectory(ExtractFilePath(fStartFilename)); SearchPath:=CodeToolBoss.GetCompleteSrcPathForDirectory(ExtractFilePath(fStartFilename));
p:=1; p:=1;
@ -399,17 +408,27 @@ procedure TViewUnitDialog.ListboxDrawItem(Control: TWinControl; Index: Integer;
ARect: TRect; State: TOwnerDrawState); ARect: TRect; State: TOwnerDrawState);
var var
aTop: Integer; aTop: Integer;
UEntry: TViewUnitsEntry;
begin begin
if Index < 0 then Exit; if Index < 0 then Exit;
with ListBox do with ListBox do begin
begin
Canvas.FillRect(ARect); Canvas.FillRect(ARect);
aTop := (ARect.Bottom + ARect.Top - IDEImages.Images_16.Height) div 2; aTop := (ARect.Bottom + ARect.Top - IDEImages.Images_16.Height) div 2;
IDEImages.Images_16.Draw(Canvas, 1, aTop, FImageIndex); IDEImages.Images_16.Draw(Canvas, 1, aTop, FImageIndex);
aTop := (ARect.Bottom + ARect.Top - Canvas.TextHeight('Šj9')) div 2; aTop := (ARect.Bottom + ARect.Top - Canvas.TextHeight('Šj9')) div 2;
Canvas.TextRect(ARect, ARect.Left + IDEImages.Images_16.Width + Scale96ToFont(4), aTop, Items[Index]); Canvas.TextRect(ARect, ARect.Left + IDEImages.Images_16.Width + Scale96ToFont(4),
if Items.Objects[Index] <> nil then // already open indicator aTop, Items[Index]);
Canvas.TextRect(ARect, ARect.Right - Scale96ToFont(8), aTop, '•'); UEntry := TViewUnitsEntry(Items.Objects[Index]);
if vufOpen in UEntry.Flags then // already open indicator
Canvas.TextRect(ARect, ARect.Right - Scale96ToFont(18), aTop, '🟢'); // 🟢
// Update the initial Selected state here.
if FFirstDraw then begin
if vufSelected in UEntry.Flags then
ListBox.Selected[Index] := True;
// Assume the items are drawn in order. After the last one reset FFirstDraw.
if Index = ListBox.Items.Count-1 then
FFirstDraw := False;;
end;
end; end;
end; end;
@ -419,7 +438,7 @@ procedure TViewUnitDialog.OnIdle(Sender: TObject; var Done: Boolean);
var var
CompClass: TPFComponentBaseClass; CompClass: TPFComponentBaseClass;
begin begin
//debugln(['CheckFile ',aFilename]); //DebugLn(['CheckFile ',aFilename]);
case ItemType of case ItemType of
piUnit: piUnit:
begin begin
@ -497,12 +516,17 @@ procedure TViewUnitDialog.OKButtonClick(Sender: TObject);
var var
S2PItem: PStringToPointerTreeItem; S2PItem: PStringToPointerTreeItem;
Entry: TViewUnitsEntry; Entry: TViewUnitsEntry;
Selected: Boolean;
Begin Begin
FilterEdit.StoreSelection; FilterEdit.StoreSelection;
for S2PItem in fEntries.fItems do begin for S2PItem in fEntries.fItems do begin
Entry:=TViewUnitsEntry(S2PItem^.Value); Entry:=TViewUnitsEntry(S2PItem^.Value);
Entry.Selected:=FilterEdit.SelectionList.IndexOf(Entry.Name)>-1; Selected:=FilterEdit.SelectionList.IndexOf(Entry.Name)>-1;
if Entry.Selected then if Selected then
Include(Entry.Flags, vufSelected)
else
Exclude(Entry.Flags, vufSelected);
if Selected then
ModalResult := mrOK; ModalResult := mrOK;
end; end;
End; End;
@ -539,18 +563,13 @@ end;
procedure TViewUnitDialog.ShowEntries; procedure TViewUnitDialog.ShowEntries;
var var
UEntry: TViewUnitsEntry; UEntry: TViewUnitsEntry;
flags: PtrInt;
begin begin
DisableAutoSizing{$IFDEF DebugDisableAutoSizing}('TViewUnitDialog.ShowEntries'){$ENDIF}; DisableAutoSizing{$IFDEF DebugDisableAutoSizing}('TViewUnitDialog.ShowEntries'){$ENDIF};
try try
// Data items // Data items
FilterEdit.Items.Clear; FilterEdit.Items.Clear;
for UEntry in fEntries do begin for UEntry in fEntries do
flags := PtrInt(UEntry.Selected); FilterEdit.Items.AddObject(UEntry.Name, UEntry);
if UEntry.Open then
flags := flags or 2;
FilterEdit.Items.AddObject(UEntry.Name, TObject(flags));
end;
FilterEdit.InvalidateFilter; FilterEdit.InvalidateFilter;
finally finally
EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('TViewUnitDialog.ShowEntries'){$ENDIF}; EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('TViewUnitDialog.ShowEntries'){$ENDIF};