DocWinList.pas 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. unit DocWinList;
  2. interface
  3. uses
  4. FormDocument,
  5. System.Generics.Collections, FMX.Forms, System.SysUtils, System.Types,
  6. System.UITypes, System.Classes;
  7. type
  8. TDocumentWindowList = class(TObjectList<TfmDocument>)
  9. private
  10. function GetNumOfVisible: Integer;
  11. function GetActiveWindow: TfmDocument;
  12. function GetLastActive: TfmDocument;
  13. public
  14. property NumOfVisible: Integer read GetNumOfVisible;
  15. property ActiveWindow: TfmDocument read GetActiveWindow;
  16. property LastActive: TfmDocument read GetLastActive;
  17. public
  18. function Add(const Value: TfmDocument): NativeInt;
  19. function Remove(const Value: TfmDocument): NativeInt;
  20. procedure ShowAll;
  21. function HasActiveWindow: Boolean;
  22. function GetWindowByFilename(const AFilename: string): TfmDocument;
  23. end;
  24. implementation
  25. function TDocumentWindowList.Add(const Value: TfmDocument): NativeInt;
  26. begin
  27. Result := inherited;
  28. end;
  29. function TDocumentWindowList.Remove(const Value: TfmDocument): NativeInt;
  30. begin
  31. Result := inherited;
  32. if Count <= 0 then
  33. Application.MainForm.Close;
  34. end;
  35. procedure TDocumentWindowList.ShowAll;
  36. begin
  37. for var item in self do
  38. begin
  39. if not item.Visible then
  40. begin
  41. item.Show;
  42. end;
  43. end;
  44. end;
  45. function TDocumentWindowList.GetNumOfVisible: Integer;
  46. begin
  47. Result := 0;
  48. for var item in self do
  49. begin
  50. if item.Visible then
  51. begin
  52. Inc(Result);
  53. end;
  54. end;
  55. end;
  56. function TDocumentWindowList.GetActiveWindow: TfmDocument;
  57. begin
  58. for var item in self do
  59. if item.Active then
  60. Exit(item);
  61. Exit(nil);
  62. end;
  63. function TDocumentWindowList.GetLastActive: TfmDocument;
  64. begin
  65. if Count > 0 then
  66. Result := First
  67. else
  68. Result := nil;
  69. end;
  70. function TDocumentWindowList.GetWindowByFilename(const AFilename: string): TfmDocument;
  71. begin
  72. for var item in self do
  73. if item.lblFilename.Text.ToLower = AFilename.ToLower then
  74. Exit(item);
  75. Result := nil;
  76. end;
  77. function TDocumentWindowList.HasActiveWindow: Boolean;
  78. begin
  79. Result := GetActiveWindow <> nil;
  80. end;
  81. end.