| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- unit IDE.GotoFileForm;
- {
- Inno Setup
- Copyright (C) 1997-2025 Jordan Russell
- Portions by Martijn Laan
- For conditions of distribution and use, see LICENSE.TXT.
- Compiler IDE Goto File form
- }
- interface
- uses
- Classes, Controls, StdCtrls, UIStateForm;
- type
- TGotoFileForm = class(TUIStateForm)
- OKButton: TButton;
- CancelButton: TButton;
- GotoFileListBox: TListBox;
- GotoFileEdit: TEdit;
- procedure FormCreate(Sender: TObject);
- procedure GotoFileListBoxDblClick(Sender: TObject);
- procedure GotoFileEditOrListBoxKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
- procedure GotoFileEditChange(Sender: TObject);
- procedure OKButtonClick(Sender: TObject);
- private
- FFiles: TStrings;
- FFileIndex: Integer;
- procedure SetFiles(Value: TStrings);
- procedure UpdateGotoFileListBox;
- protected
- procedure CreateWnd; override;
- procedure CreateParams(var Params: TCreateParams); override;
- public
- property Files: TStrings write SetFiles;
- property FileIndex: Integer read FFileIndex;
- end;
- implementation
- uses
- Windows, Messages,
- PathFunc,
- IDE.HelperFunc;
- {$R *.DFM}
- procedure TGotoFileForm.SetFiles(Value: TStrings);
- begin
- FFiles := Value;
- UpdateGotoFileListBox;
- end;
- procedure TGotoFileForm.UpdateGotoFileListBox;
- function Match(const Name, Value: String): Boolean;
- begin
- Result := (Value = '') or (PathStrFind(PChar(Name), Length(Name), PChar(Value), Length(Value)) >= 0);
- end;
- begin
- GotoFileListBox.Items.BeginUpdate;
- try
- GotoFileListBox.Items.Clear;
- for var I := 0 to FFiles.Count-1 do begin
- const Name = PathExtractName(FFiles[I]);
- if Match(Name, GotoFileEdit.Text) then
- GotoFileListBox.Items.AddObject(Name, TObject(I));
- end;
- finally
- GotoFileListBox.Items.EndUpdate;
- end;
- if GotoFileListBox.Items.Count > 0 then
- GotoFileListBox.ItemIndex := 0;
- OKButton.Enabled := GotoFileListBox.ItemIndex >= 0;
- end;
- procedure TGotoFileForm.FormCreate(Sender: TObject);
- begin
- InitFormFont(Self);
- InitFormTheme(Self);
- end;
- { This and CreateParams make bsSizeable (which has an unwanted icon) look like bsDialog, see:
- https://stackoverflow.com/questions/32096482/delphi-resizable-bsdialog-form/32098633 }
- procedure TGotoFileForm.CreateWnd;
- begin
- inherited;
- SendMessage(Handle, WM_SETICON, ICON_BIG, 0);
- end;
- procedure TGotoFileForm.CreateParams(var Params: TCreateParams);
- begin
- inherited CreateParams(Params);
- Params.ExStyle := Params.ExStyle or WS_EX_DLGMODALFRAME or WS_EX_WINDOWEDGE;
- end;
- procedure TGotoFileForm.GotoFileEditChange(Sender: TObject);
- begin
- UpdateGotoFileListBox;
- end;
- procedure TGotoFileForm.GotoFileEditOrListBoxKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
- begin
- if Shift = [] then begin
- if (Key = VK_DOWN) and (Sender = GotoFileEdit) then begin
- if GotoFileListBox.Items.Count > 0 then
- GotoFileListBox.ItemIndex := 0;
- ActiveControl := GotoFileListBox;
- Key := 0;
- end else if (Key = VK_UP) and (GotoFileListBox.ItemIndex <= 0) then begin
- ActiveControl := GotoFileEdit;
- Key := 0;
- end;
- end;
- end;
- procedure TGotoFileForm.GotoFileListBoxDblClick(Sender: TObject);
- begin
- if OKButton.Enabled then
- OKButton.Click;
- end;
- procedure TGotoFileForm.OKButtonClick(Sender: TObject);
- begin
- FFileIndex := Integer(GotoFileListBox.Items.Objects[GotoFileListBox.ItemIndex]);
- end;
- end.
|