mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-08 14:38:12 +02:00
IDE: Improve the behavior of ViewUnit dialog. Support initial selection etc.
This commit is contained in:
parent
ca8aa3f8c6
commit
7a6a7a85c8
@ -5993,7 +5993,7 @@ begin
|
||||
AnUnitInfo := nil;
|
||||
for UEntry in UnitList do
|
||||
begin
|
||||
if not UEntry.Selected then continue;
|
||||
if not (vufSelected in UEntry.Flags) then continue;
|
||||
AnUnitInfo := Project1.Units[UEntry.ID];
|
||||
if AnUnitInfo.OpenEditorInfoCount > 0 then
|
||||
begin
|
||||
|
@ -188,6 +188,7 @@ type
|
||||
fViewUnitEntries: TViewUnitEntries;
|
||||
fSelectCaption: String;
|
||||
protected
|
||||
function InitialSelection(aFilename: string): Boolean; virtual;
|
||||
function Select: TModalResult; //virtual; // Select with a dialog.
|
||||
function ActionForFiles: TModalResult; virtual; abstract;
|
||||
public
|
||||
@ -210,6 +211,7 @@ type
|
||||
|
||||
TRenameFilesSelector = class(TProjectUnitFileSelector)
|
||||
protected
|
||||
function InitialSelection(aFilename: string): Boolean; override;
|
||||
function ActionForFiles: TModalResult; override;
|
||||
public
|
||||
constructor Create;
|
||||
@ -1753,12 +1755,16 @@ begin
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
function TProjectUnitFileSelector.InitialSelection(aFilename: string): Boolean;
|
||||
begin
|
||||
Result:=False;
|
||||
end;
|
||||
|
||||
function TProjectUnitFileSelector.Select: TModalResult;
|
||||
var
|
||||
i:integer;
|
||||
i: integer;
|
||||
AName: string;
|
||||
AnUnitInfo: TUnitInfo;
|
||||
UnitInfos: TFPList;
|
||||
UEntry: TViewUnitsEntry;
|
||||
Begin
|
||||
Result:=mrOK;
|
||||
@ -1770,7 +1776,8 @@ Begin
|
||||
if (AnUnitInfo.IsPartOfProject) and (i<>Project1.MainUnitID) then
|
||||
begin
|
||||
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;
|
||||
if ShowViewUnitsDlg(fViewUnitEntries,true,fSelectCaption,piUnit) <> mrOk then
|
||||
@ -1779,7 +1786,7 @@ Begin
|
||||
fUnitInfos:=TFPList.Create;
|
||||
for UEntry in fViewUnitEntries do
|
||||
begin
|
||||
if UEntry.Selected then
|
||||
if vufSelected in UEntry.Flags then
|
||||
begin
|
||||
if UEntry.ID<0 then continue;
|
||||
AnUnitInfo:=Project1.Units[UEntry.ID];
|
||||
@ -1914,6 +1921,11 @@ begin
|
||||
inherited;
|
||||
end;
|
||||
|
||||
function TRenameFilesSelector.InitialSelection(aFilename: string): Boolean;
|
||||
begin // Select only units having mixed case filename.
|
||||
Result:=aFilename<>LowerCase(aFilename);
|
||||
end;
|
||||
|
||||
function TRenameFilesSelector.ActionForFiles: TModalResult;
|
||||
var
|
||||
i: Integer;
|
||||
@ -1928,8 +1940,7 @@ begin
|
||||
+ AnUnitInfo.Unit_Name + ' is not part of project');
|
||||
if AnUnitInfo.Source=nil then
|
||||
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;
|
||||
end;
|
||||
InvalidateFileStateCache;
|
||||
@ -3896,7 +3907,7 @@ begin
|
||||
DlgCaption, ItemType, ActiveUnitInfo.Filename);
|
||||
// create list of selected files
|
||||
for Entry in UnitList do
|
||||
if Entry.Selected then
|
||||
if vufSelected in Entry.Flags then
|
||||
Files.Add(Entry.Filename);
|
||||
|
||||
finally
|
||||
|
@ -12,6 +12,8 @@ object ViewUnitDialog: TViewUnitDialog
|
||||
Caption = 'View Project Units'
|
||||
ClientHeight = 386
|
||||
ClientWidth = 378
|
||||
Position = poScreenCenter
|
||||
LCLVersion = '4.99.0.0'
|
||||
OnClose = FormClose
|
||||
OnCreate = FormCreate
|
||||
OnDestroy = FormDestroy
|
||||
|
@ -65,14 +65,19 @@ type
|
||||
piFrame
|
||||
);
|
||||
|
||||
TViewUnitFlag = (
|
||||
vufSelected,
|
||||
vufOpen
|
||||
);
|
||||
TViewUnitFlags = set of TViewUnitFlag;
|
||||
|
||||
{ TViewUnitsEntry }
|
||||
|
||||
TViewUnitsEntry = class
|
||||
public
|
||||
Name: string;
|
||||
ID: integer;
|
||||
Selected: boolean;
|
||||
Open: boolean;
|
||||
Flags: TViewUnitFlags;
|
||||
Filename: string;
|
||||
constructor Create(const AName, AFilename: string; AnID: integer; ASelected, AOpen: boolean);
|
||||
end;
|
||||
@ -139,6 +144,7 @@ type
|
||||
procedure CancelButtonClick(Sender :TObject);
|
||||
procedure MultiselectCheckBoxClick(Sender :TObject);
|
||||
private
|
||||
FFirstDraw: boolean;
|
||||
FIdleConnected: boolean;
|
||||
FItemType: TIDEProjectItem;
|
||||
FSortAlphabetically: boolean;
|
||||
@ -304,8 +310,10 @@ begin
|
||||
inherited Create;
|
||||
Name := AName;
|
||||
ID := AnID;
|
||||
Selected := ASelected;
|
||||
Open := AOpen;
|
||||
if ASelected then
|
||||
Include(Flags, vufSelected);
|
||||
if AOpen then
|
||||
Include(Flags, vufOpen);
|
||||
Filename := AFilename;
|
||||
end;
|
||||
|
||||
@ -371,13 +379,14 @@ begin
|
||||
fEntries:=TheEntries;
|
||||
mniMultiselect.Enabled := EnableMultiSelect;
|
||||
mniMultiselect.Checked := EnableMultiSelect;
|
||||
ListBox.MultiSelect := mniMultiselect.Enabled;
|
||||
ListBox.MultiSelect := mniMultiselect.Checked;
|
||||
FFirstDraw := True;
|
||||
ShowEntries;
|
||||
FilterEdit.SimpleSelection := true;
|
||||
|
||||
if aStartFilename<>'' then begin
|
||||
// init search for units
|
||||
// -> get unit search path and fill fSearchDirectories
|
||||
// init search for units -> get unit search path and fill fSearchDirectories
|
||||
// The entries should not have "Selected" flag set because the list gets updated.
|
||||
fStartFilename:=TrimFilename(aStartFilename);
|
||||
SearchPath:=CodeToolBoss.GetCompleteSrcPathForDirectory(ExtractFilePath(fStartFilename));
|
||||
p:=1;
|
||||
@ -399,17 +408,27 @@ procedure TViewUnitDialog.ListboxDrawItem(Control: TWinControl; Index: Integer;
|
||||
ARect: TRect; State: TOwnerDrawState);
|
||||
var
|
||||
aTop: Integer;
|
||||
UEntry: TViewUnitsEntry;
|
||||
begin
|
||||
if Index < 0 then Exit;
|
||||
with ListBox do
|
||||
begin
|
||||
with ListBox do begin
|
||||
Canvas.FillRect(ARect);
|
||||
aTop := (ARect.Bottom + ARect.Top - IDEImages.Images_16.Height) div 2;
|
||||
IDEImages.Images_16.Draw(Canvas, 1, aTop, FImageIndex);
|
||||
aTop := (ARect.Bottom + ARect.Top - Canvas.TextHeight('Šj9')) div 2;
|
||||
Canvas.TextRect(ARect, ARect.Left + IDEImages.Images_16.Width + Scale96ToFont(4), aTop, Items[Index]);
|
||||
if Items.Objects[Index] <> nil then // already open indicator
|
||||
Canvas.TextRect(ARect, ARect.Right - Scale96ToFont(8), aTop, '•');
|
||||
Canvas.TextRect(ARect, ARect.Left + IDEImages.Images_16.Width + Scale96ToFont(4),
|
||||
aTop, Items[Index]);
|
||||
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;
|
||||
|
||||
@ -419,7 +438,7 @@ procedure TViewUnitDialog.OnIdle(Sender: TObject; var Done: Boolean);
|
||||
var
|
||||
CompClass: TPFComponentBaseClass;
|
||||
begin
|
||||
//debugln(['CheckFile ',aFilename]);
|
||||
//DebugLn(['CheckFile ',aFilename]);
|
||||
case ItemType of
|
||||
piUnit:
|
||||
begin
|
||||
@ -497,12 +516,17 @@ procedure TViewUnitDialog.OKButtonClick(Sender: TObject);
|
||||
var
|
||||
S2PItem: PStringToPointerTreeItem;
|
||||
Entry: TViewUnitsEntry;
|
||||
Selected: Boolean;
|
||||
Begin
|
||||
FilterEdit.StoreSelection;
|
||||
for S2PItem in fEntries.fItems do begin
|
||||
Entry:=TViewUnitsEntry(S2PItem^.Value);
|
||||
Entry.Selected:=FilterEdit.SelectionList.IndexOf(Entry.Name)>-1;
|
||||
if Entry.Selected then
|
||||
Selected:=FilterEdit.SelectionList.IndexOf(Entry.Name)>-1;
|
||||
if Selected then
|
||||
Include(Entry.Flags, vufSelected)
|
||||
else
|
||||
Exclude(Entry.Flags, vufSelected);
|
||||
if Selected then
|
||||
ModalResult := mrOK;
|
||||
end;
|
||||
End;
|
||||
@ -539,18 +563,13 @@ end;
|
||||
procedure TViewUnitDialog.ShowEntries;
|
||||
var
|
||||
UEntry: TViewUnitsEntry;
|
||||
flags: PtrInt;
|
||||
begin
|
||||
DisableAutoSizing{$IFDEF DebugDisableAutoSizing}('TViewUnitDialog.ShowEntries'){$ENDIF};
|
||||
try
|
||||
// Data items
|
||||
FilterEdit.Items.Clear;
|
||||
for UEntry in fEntries do begin
|
||||
flags := PtrInt(UEntry.Selected);
|
||||
if UEntry.Open then
|
||||
flags := flags or 2;
|
||||
FilterEdit.Items.AddObject(UEntry.Name, TObject(flags));
|
||||
end;
|
||||
for UEntry in fEntries do
|
||||
FilterEdit.Items.AddObject(UEntry.Name, UEntry);
|
||||
FilterEdit.InvalidateFilter;
|
||||
finally
|
||||
EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('TViewUnitDialog.ShowEntries'){$ENDIF};
|
||||
|
Loading…
Reference in New Issue
Block a user