IDE.GotoFileForm.pas 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. unit IDE.GotoFileForm;
  2. {
  3. Inno Setup
  4. Copyright (C) 1997-2025 Jordan Russell
  5. Portions by Martijn Laan
  6. For conditions of distribution and use, see LICENSE.TXT.
  7. Compiler IDE Goto File form
  8. }
  9. interface
  10. uses
  11. Classes, Controls, StdCtrls, UIStateForm;
  12. type
  13. TGotoFileForm = class(TUIStateForm)
  14. OKButton: TButton;
  15. CancelButton: TButton;
  16. GotoFileListBox: TListBox;
  17. GotoFileEdit: TEdit;
  18. procedure FormCreate(Sender: TObject);
  19. procedure GotoFileListBoxDblClick(Sender: TObject);
  20. procedure GotoFileEditOrListBoxKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
  21. procedure GotoFileEditChange(Sender: TObject);
  22. procedure OKButtonClick(Sender: TObject);
  23. private
  24. FFiles: TStrings;
  25. FFileIndex: Integer;
  26. procedure SetFiles(Value: TStrings);
  27. procedure UpdateGotoFileListBox;
  28. protected
  29. procedure CreateWnd; override;
  30. procedure CreateParams(var Params: TCreateParams); override;
  31. public
  32. property Files: TStrings write SetFiles;
  33. property FileIndex: Integer read FFileIndex;
  34. end;
  35. implementation
  36. uses
  37. Windows, Messages,
  38. PathFunc,
  39. IDE.HelperFunc;
  40. {$R *.DFM}
  41. procedure TGotoFileForm.SetFiles(Value: TStrings);
  42. begin
  43. FFiles := Value;
  44. UpdateGotoFileListBox;
  45. end;
  46. procedure TGotoFileForm.UpdateGotoFileListBox;
  47. function Match(const Name, Value: String): Boolean;
  48. begin
  49. Result := (Value = '') or (PathStrFind(PChar(Name), Length(Name), PChar(Value), Length(Value)) >= 0);
  50. end;
  51. begin
  52. GotoFileListBox.Items.BeginUpdate;
  53. try
  54. GotoFileListBox.Items.Clear;
  55. for var I := 0 to FFiles.Count-1 do begin
  56. const Name = PathExtractName(FFiles[I]);
  57. if Match(Name, GotoFileEdit.Text) then
  58. GotoFileListBox.Items.AddObject(Name, TObject(I));
  59. end;
  60. finally
  61. GotoFileListBox.Items.EndUpdate;
  62. end;
  63. if GotoFileListBox.Items.Count > 0 then
  64. GotoFileListBox.ItemIndex := 0;
  65. OKButton.Enabled := GotoFileListBox.ItemIndex >= 0;
  66. end;
  67. procedure TGotoFileForm.FormCreate(Sender: TObject);
  68. begin
  69. InitFormFont(Self);
  70. InitFormTheme(Self);
  71. end;
  72. { This and CreateParams make bsSizeable (which has an unwanted icon) look like bsDialog, see:
  73. https://stackoverflow.com/questions/32096482/delphi-resizable-bsdialog-form/32098633 }
  74. procedure TGotoFileForm.CreateWnd;
  75. begin
  76. inherited;
  77. SendMessage(Handle, WM_SETICON, ICON_BIG, 0);
  78. end;
  79. procedure TGotoFileForm.CreateParams(var Params: TCreateParams);
  80. begin
  81. inherited CreateParams(Params);
  82. Params.ExStyle := Params.ExStyle or WS_EX_DLGMODALFRAME or WS_EX_WINDOWEDGE;
  83. end;
  84. procedure TGotoFileForm.GotoFileEditChange(Sender: TObject);
  85. begin
  86. UpdateGotoFileListBox;
  87. end;
  88. procedure TGotoFileForm.GotoFileEditOrListBoxKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
  89. begin
  90. if Shift = [] then begin
  91. if (Key = VK_DOWN) and (Sender = GotoFileEdit) then begin
  92. if GotoFileListBox.Items.Count > 0 then
  93. GotoFileListBox.ItemIndex := 0;
  94. ActiveControl := GotoFileListBox;
  95. Key := 0;
  96. end else if (Key = VK_UP) and (GotoFileListBox.ItemIndex <= 0) then begin
  97. ActiveControl := GotoFileEdit;
  98. Key := 0;
  99. end;
  100. end;
  101. end;
  102. procedure TGotoFileForm.GotoFileListBoxDblClick(Sender: TObject);
  103. begin
  104. if OKButton.Enabled then
  105. OKButton.Click;
  106. end;
  107. procedure TGotoFileForm.OKButtonClick(Sender: TObject);
  108. begin
  109. FFileIndex := Integer(GotoFileListBox.Items.Objects[GotoFileListBox.ItemIndex]);
  110. end;
  111. end.