Changeset 374
- Timestamp:
- Jun 13, 2012, 9:38:59 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Common/ULastOpenedList.pas
r369 r374 12 12 { TLastOpenedList } 13 13 14 TLastOpenedList = class(T StringList)14 TLastOpenedList = class(TComponent) 15 15 private 16 FMaxCount: Integer; 16 17 FOnChange: TNotifyEvent; 18 procedure SetMaxCount(AValue: Integer); 19 procedure LimitMaxCount; 17 20 public 18 MaxCount: Integer;21 Items: TStringList; 19 22 ClickAction: TNotifyEvent; 20 constructor Create ;23 constructor Create(AOwner: TComponent); override; 21 24 destructor Destroy; override; 22 25 procedure LoadToMenuItem(MenuItem: TMenuItem); … … 24 27 procedure SaveToRegistry(Root: HKEY; Key: string); 25 28 procedure AddItem(FileName: string); 29 property MaxCount: Integer read FMaxCount write SetMaxCount; 26 30 property OnChange: TNotifyEvent read FOnChange write FOnChange; 27 31 end; … … 31 35 { TLastOpenedList } 32 36 33 constructor TLastOpenedList.Create; 37 procedure TLastOpenedList.SetMaxCount(AValue: Integer); 38 begin 39 if FMaxCount = AValue then Exit; 40 FMaxCount := AValue; 41 if FMaxCount < 0 then FMaxCount := 0; 42 LimitMaxCount; 43 end; 44 45 procedure TLastOpenedList.LimitMaxCount; 46 begin 47 while Items.Count > MaxCount do 48 Items.Delete(Items.Count - 1); 49 end; 50 51 constructor TLastOpenedList.Create(AOwner: TComponent); 34 52 begin 35 53 inherited; 36 MaxCount := 5; 54 Items := TStringList.Create; 55 MaxCount := 10; 37 56 end; 38 57 39 58 destructor TLastOpenedList.Destroy; 40 59 begin 60 Items.Free; 41 61 inherited; 42 62 end; … … 49 69 if Assigned(MenuItem) then begin 50 70 MenuItem.Clear; 51 for I := 0 to Count - 1 do begin71 for I := 0 to Items.Count - 1 do begin 52 72 NewMenuItem := TMenuItem.Create(MenuItem); 53 NewMenuItem.Caption := Strings[I];73 NewMenuItem.Caption := Items[I]; 54 74 NewMenuItem.OnClick := ClickAction; 55 75 MenuItem.Add(NewMenuItem); … … 69 89 RootKey := Root; 70 90 OpenKey(Key, True); 71 Clear;91 Items.Clear; 72 92 I := 0; 73 93 while ValueExists('File' + IntToStr(I)) and (I < MaxCount) do begin 74 94 FileName := UTF8Encode(ReadStringWithDefault('File' + IntToStr(I), '')); 75 if Trim(FileName) <> '' then inheritedAdd(FileName);95 if Trim(FileName) <> '' then Items.Add(FileName); 76 96 Inc(I); 77 97 end; … … 93 113 RootKey := Root; 94 114 OpenKey(Key, True); 95 for I := 0 to Count - 1 do96 WriteString('File' + IntToStr(I), UTF8Decode( Strings[I]));115 for I := 0 to Items.Count - 1 do 116 WriteString('File' + IntToStr(I), UTF8Decode(Items[I])); 97 117 finally 98 118 Free; … … 102 122 procedure TLastOpenedList.AddItem(FileName:string); 103 123 begin 104 if IndexOf(FileName) <> -1 then Delete(IndexOf(FileName)); 105 Insert(0, FileName); 106 while Count > MaxCount do 107 Delete(Count - 1); 108 124 if Items.IndexOf(FileName) <> -1 then Items.Delete(Items.IndexOf(FileName)); 125 Items.Insert(0, FileName); 126 LimitMaxCount; 109 127 if Assigned(FOnChange) then 110 128 FOnChange(Self);
Note:
See TracChangeset
for help on using the changeset viewer.