Changeset 75 for trunk/Packages/Common/LastOpenedList.pas
- Timestamp:
- Jun 4, 2024, 12:22:49 AM (5 months ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/LastOpenedList.pas
r74 r75 1 unit ULastOpenedList; 2 3 {$mode delphi} 1 unit LastOpenedList; 4 2 5 3 interface 6 4 7 5 uses 8 Classes, SysUtils, Registry, URegistry, Menus;6 Classes, SysUtils, Registry, RegistryEx, Menus, XMLConf, DOM; 9 7 10 8 type … … 27 25 procedure LoadFromRegistry(Context: TRegistryContext); 28 26 procedure SaveToRegistry(Context: TRegistryContext); 27 procedure LoadFromXMLConfig(XMLConfig: TXMLConfig; Path: string); 28 procedure SaveToXMLConfig(XMLConfig: TXMLConfig; Path: string); 29 29 procedure AddItem(FileName: string); 30 function GetFirstFileName: string; 30 31 published 31 32 property MaxCount: Integer read FMaxCount write SetMaxCount; … … 81 82 destructor TLastOpenedList.Destroy; 82 83 begin 83 Items.Free;84 FreeAndNil(Items); 84 85 inherited; 85 86 end; … … 91 92 begin 92 93 if Assigned(MenuItem) then begin 93 MenuItem.Clear; 94 while MenuItem.Count > Items.Count do 95 MenuItem.Delete(MenuItem.Count - 1); 96 while MenuItem.Count < Items.Count do begin 97 NewMenuItem := TMenuItem.Create(MenuItem); 98 MenuItem.Add(NewMenuItem); 99 end; 94 100 for I := 0 to Items.Count - 1 do begin 95 NewMenuItem := TMenuItem.Create(MenuItem); 96 NewMenuItem.Caption := Items[I]; 97 NewMenuItem.OnClick := ClickAction; 98 MenuItem.Add(NewMenuItem); 101 MenuItem.Items[I].Caption := Items[I]; 102 MenuItem.Items[I].OnClick := ClickAction; 99 103 end; 100 104 end; … … 137 141 OpenKey(Context.Key, True); 138 142 for I := 0 to Items.Count - 1 do 139 WriteString('File' + IntToStr(I), UTF8Decode(Items[I]));143 WriteString('File' + IntToStr(I), Items[I]); 140 144 finally 141 145 Free; 146 end; 147 end; 148 149 procedure TLastOpenedList.LoadFromXMLConfig(XMLConfig: TXMLConfig; Path: string 150 ); 151 var 152 I: Integer; 153 Value: string; 154 Count: Integer; 155 begin 156 with XMLConfig do begin 157 Count := GetValue(DOMString(Path + '/Count'), 0); 158 if Count > MaxCount then Count := MaxCount; 159 Items.Clear; 160 for I := 0 to Count - 1 do begin 161 Value := string(GetValue(DOMString(Path + '/File' + IntToStr(I)), '')); 162 if Trim(Value) <> '' then Items.Add(Value); 163 end; 164 if Assigned(FOnChange) then 165 FOnChange(Self); 166 end; 167 end; 168 169 procedure TLastOpenedList.SaveToXMLConfig(XMLConfig: TXMLConfig; Path: string); 170 var 171 I: Integer; 172 begin 173 with XMLConfig do begin 174 SetValue(DOMString(Path + '/Count'), Items.Count); 175 for I := 0 to Items.Count - 1 do 176 SetValue(DOMString(Path + '/File' + IntToStr(I)), DOMString(Items[I])); 177 Flush; 142 178 end; 143 179 end; … … 151 187 end; 152 188 189 function TLastOpenedList.GetFirstFileName: string; 190 begin 191 if Items.Count > 0 then Result := Items[0] 192 else Result := ''; 193 end; 194 153 195 end. 154
Note:
See TracChangeset
for help on using the changeset viewer.