DirViewColProperties.pas 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. unit DirViewColProperties;
  2. interface
  3. uses
  4. Classes, ComCtrls, ListViewColProperties;
  5. type
  6. TCustomDirViewColProperties = class(TCustomListViewColProperties)
  7. private
  8. function GetSortAscending: Boolean;
  9. function GetSortByExtension: Boolean;
  10. procedure SetSortColumn(Value: Integer);
  11. function GetSortColumn: Integer;
  12. function GetSortStr: string;
  13. procedure SetSortAscending(Value: Boolean);
  14. procedure SetSortByExtension(Value: Boolean);
  15. procedure SetSortStr(Value: string);
  16. public
  17. property SortAscending: Boolean read GetSortAscending write SetSortAscending default True;
  18. property SortByExtension: Boolean read GetSortByExtension write SetSortByExtension default False;
  19. property SortColumn: Integer read GetSortColumn write SetSortColumn;
  20. property SortStr: string read GetSortStr write SetSortStr stored False;
  21. protected
  22. function GetParamsStr: string; override;
  23. procedure SetParamsStr(Value: string); override;
  24. end;
  25. resourcestring
  26. SDirViewNameCol = 'Name';
  27. SDirViewSizeCol = 'Size';
  28. SDirViewTypeCol = 'Type';
  29. SDirViewChangedCol = 'Changed';
  30. SDirViewAttrCol = 'Attr';
  31. SDirViewExtCol = 'Ext';
  32. const
  33. DirViewColumns = 6;
  34. DefaultDirViewCaptions: array[0..DirViewColumns-1] of Pointer =
  35. (@SDirViewNameCol, @SDirViewSizeCol, @SDirViewTypeCol, @SDirViewChangedCol,
  36. @SDirViewAttrCol, @SDirViewExtCol);
  37. DefaultDirViewWidths: array[0..DirViewColumns-1] of Integer =
  38. (150, 80, 125, 130, 45, 20);
  39. DefaultDirViewAlignments: array[0..DirViewColumns-1] of TAlignment =
  40. (taLeftJustify, taRightJustify, taLeftJustify, taLeftJustify,
  41. taLeftJustify, taLeftJustify);
  42. DefaultDirViewVisible: array[0..DirViewColumns-1] of Boolean =
  43. (True, True, True, True, True, False);
  44. type
  45. TDirViewCol = (dvName, dvSize, dvType, dvChanged, dvAttr, dvExt);
  46. TDirViewColProperties = class(TCustomDirViewColProperties)
  47. private
  48. function StoreAlignment(Index: Integer): Boolean;
  49. function StoreCaption(Index: Integer): Boolean;
  50. function StoreWidth(Index: Integer): Boolean;
  51. function GetDirOrder(Index: Integer): TDirViewCol;
  52. function GetSortDirColumn: TDirViewCol;
  53. procedure SetDirOrder(Index: Integer; Value: TDirViewCol);
  54. procedure SetSortDirColumn(Value: TDirViewCol);
  55. public
  56. constructor Create(DirView: TCustomListView);
  57. published
  58. property MaxWidth;
  59. property MinWidth;
  60. property SortAscending;
  61. property SortByExtension;
  62. property SortDirColumn: TDirViewCol read GetSortDirColumn write SetSortDirColumn default dvName;
  63. property NameCaption: string index dvName read GetCaptions write SetCaptions stored StoreCaption;
  64. property NameWidth: Integer index dvName read GetWidths write SetWidths stored StoreWidth;
  65. property NameVisible: Boolean index dvName read GetVisible write SetVisible default True;
  66. property NameAlignment: TAlignment index dvName read GetAlignments write SetAlignments stored StoreAlignment;
  67. property SizeCaption: string index dvSize read GetCaptions write SetCaptions stored StoreCaption;
  68. property SizeWidth: Integer index dvSize read GetWidths write SetWidths stored StoreWidth;
  69. property SizeVisible: Boolean index dvSize read GetVisible write SetVisible default True;
  70. property SizeAlignment: TAlignment index dvSize read GetAlignments write SetAlignments stored StoreAlignment;
  71. property TypeCaption: string index dvType read GetCaptions write SetCaptions stored StoreCaption;
  72. property TypeWidth: Integer index dvType read GetWidths write SetWidths stored StoreWidth;
  73. property TypeVisible: Boolean index dvType read GetVisible write SetVisible default True;
  74. property TypeAlignment: TAlignment index dvType read GetAlignments write SetAlignments stored StoreAlignment;
  75. property ChangedCaption: string index dvChanged read GetCaptions write SetCaptions stored StoreCaption;
  76. property ChangedWidth: Integer index dvChanged read GetWidths write SetWidths stored StoreWidth;
  77. property ChangedVisible: Boolean index dvChanged read GetVisible write SetVisible default True;
  78. property ChangedAlignment: TAlignment index dvChanged read GetAlignments write SetAlignments stored StoreAlignment;
  79. property AttrCaption: string index dvAttr read GetCaptions write SetCaptions stored StoreCaption;
  80. property AttrWidth: Integer index dvAttr read GetWidths write SetWidths stored StoreWidth;
  81. property AttrVisible: Boolean index dvAttr read GetVisible write SetVisible default True;
  82. property AttrAlignment: TAlignment index dvAttr read GetAlignments write SetAlignments stored StoreAlignment;
  83. property ExtCaption: string index dvExt read GetCaptions write SetCaptions stored StoreCaption;
  84. property ExtWidth: Integer index dvExt read GetWidths write SetWidths stored StoreWidth;
  85. property ExtVisible: Boolean index dvExt read GetVisible write SetVisible default True;
  86. property ExtAlignment: TAlignment index dvExt read GetAlignments write SetAlignments stored StoreAlignment;
  87. property Column1: TDirViewCol index 0 read GetDirOrder write SetDirOrder default dvName;
  88. property Column2: TDirViewCol index 1 read GetDirOrder write SetDirOrder default dvSize;
  89. property Column3: TDirViewCol index 2 read GetDirOrder write SetDirOrder default dvType;
  90. property Column4: TDirViewCol index 3 read GetDirOrder write SetDirOrder default dvChanged;
  91. property Column5: TDirViewCol index 4 read GetDirOrder write SetDirOrder default dvAttr;
  92. property Column6: TDirViewCol index 5 read GetDirOrder write SetDirOrder default dvExt;
  93. end; { TDirViewColProperties }
  94. implementation
  95. uses
  96. SysUtils, CommCtrl, IEListView, CustomDirView;
  97. { TCustomDirViewColProperties }
  98. procedure TCustomDirViewColProperties.SetParamsStr(Value: string);
  99. begin
  100. SortStr := CutToChar(Value, '|', True);
  101. inherited SetParamsStr(Value);
  102. end;
  103. procedure TCustomDirViewColProperties.SetSortAscending(Value: Boolean);
  104. begin
  105. TIEListView(FListView).SortAscending := Value;
  106. end;
  107. procedure TCustomDirViewColProperties.SetSortByExtension(Value: Boolean);
  108. begin
  109. TCustomDirView(FListView).SortByExtension := Value;
  110. end;
  111. procedure TCustomDirViewColProperties.SetSortColumn(Value: Integer);
  112. begin
  113. if SortColumn <> Value then
  114. begin
  115. TIEListView(FListView).SortColumn := Value;
  116. Changed;
  117. end;
  118. end;
  119. function TCustomDirViewColProperties.GetParamsStr: string;
  120. begin
  121. Result := Format('%s|%s', [SortStr, inherited GetParamsStr]);
  122. end;
  123. function TCustomDirViewColProperties.GetSortAscending: Boolean;
  124. begin
  125. Result := TIEListView(FListView).SortAscending;
  126. end;
  127. function TCustomDirViewColProperties.GetSortByExtension: Boolean;
  128. begin
  129. Result := TCustomDirView(FListView).SortByExtension;
  130. end;
  131. function TCustomDirViewColProperties.GetSortColumn: Integer;
  132. begin
  133. Result := TIEListView(FListView).SortColumn;
  134. end;
  135. procedure TCustomDirViewColProperties.SetSortStr(Value: string);
  136. begin
  137. SortColumn := StrToIntDef(CutToChar(Value, ';', True), SortColumn);
  138. SortAscending := Boolean(StrToIntDef(CutToChar(Value, ';', True), Integer(SortAscending)));
  139. SortByExtension := Boolean(StrToIntDef(CutToChar(Value, ';', True), Integer(SortByExtension)));
  140. end;
  141. function TCustomDirViewColProperties.GetSortStr: string;
  142. begin
  143. Result := Format('%d;%d;%d', [SortColumn, Integer(SortAscending), Integer(SortByExtension)]);
  144. end;
  145. { TDirViewColProperties }
  146. constructor TDirViewColProperties.Create(DirView: TCustomListView);
  147. var
  148. Index: Integer;
  149. begin
  150. inherited Create(DirView, DirViewColumns);
  151. for Index := 0 to Count-1 do
  152. begin
  153. Captions[Index] := LoadResString(DefaultDirViewCaptions[Index]);
  154. Visible[Index] := DefaultDirViewVisible[Index];
  155. Widths[Index] := DefaultDirViewWidths[Index];
  156. Alignments[Index] := DefaultDirViewAlignments[Index];
  157. end;
  158. end;
  159. function TDirViewColProperties.GetDirOrder(Index: Integer): TDirViewCol;
  160. begin
  161. Result := TDirViewCol(GetOrder(Index));
  162. end;
  163. procedure TDirViewColProperties.SetDirOrder(Index: Integer;
  164. Value: TDirViewCol);
  165. begin
  166. SetOrder(Index, Integer(Value));
  167. end;
  168. procedure TDirViewColProperties.SetSortDirColumn(Value: TDirViewCol);
  169. begin
  170. SortColumn := Integer(Value);
  171. end;
  172. function TDirViewColProperties.GetSortDirColumn: TDirViewCol;
  173. begin
  174. Result := TDirViewCol(SortColumn);
  175. end;
  176. function TDirViewColProperties.StoreAlignment(Index: Integer): Boolean;
  177. begin
  178. Result := (Alignments[Index] <> DefaultDirViewAlignments[Index]);
  179. end;
  180. function TDirViewColProperties.StoreCaption(Index: Integer): Boolean;
  181. begin
  182. Result := (Captions[Index] <> LoadResString(DefaultDirViewCaptions[Index]));
  183. end;
  184. function TDirViewColProperties.StoreWidth(Index: Integer): Boolean;
  185. begin
  186. Result := (Widths[Index] <> DefaultDirViewWidths[Index]);
  187. end;
  188. end.