Ignore:
Timestamp:
Jun 4, 2024, 12:22:49 AM (5 months ago)
Author:
chronos
Message:
  • Modified: Removed U prefix from unit names.
  • Modified: Updated Common package.
File:
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/Packages/Common/LastOpenedList.pas

    r74 r75  
    1 unit ULastOpenedList;
    2 
    3 {$mode delphi}
     1unit LastOpenedList;
    42
    53interface
    64
    75uses
    8   Classes, SysUtils, Registry, URegistry, Menus;
     6  Classes, SysUtils, Registry, RegistryEx, Menus, XMLConf, DOM;
    97
    108type
     
    2725    procedure LoadFromRegistry(Context: TRegistryContext);
    2826    procedure SaveToRegistry(Context: TRegistryContext);
     27    procedure LoadFromXMLConfig(XMLConfig: TXMLConfig; Path: string);
     28    procedure SaveToXMLConfig(XMLConfig: TXMLConfig; Path: string);
    2929    procedure AddItem(FileName: string);
     30    function GetFirstFileName: string;
    3031  published
    3132    property MaxCount: Integer read FMaxCount write SetMaxCount;
     
    8182destructor TLastOpenedList.Destroy;
    8283begin
    83   Items.Free;
     84  FreeAndNil(Items);
    8485  inherited;
    8586end;
     
    9192begin
    9293  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;
    94100    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;
    99103    end;
    100104  end;
     
    137141    OpenKey(Context.Key, True);
    138142    for I := 0 to Items.Count - 1 do
    139       WriteString('File' + IntToStr(I), UTF8Decode(Items[I]));
     143      WriteString('File' + IntToStr(I), Items[I]);
    140144  finally
    141145    Free;
     146  end;
     147end;
     148
     149procedure TLastOpenedList.LoadFromXMLConfig(XMLConfig: TXMLConfig; Path: string
     150  );
     151var
     152  I: Integer;
     153  Value: string;
     154  Count: Integer;
     155begin
     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;
     167end;
     168
     169procedure TLastOpenedList.SaveToXMLConfig(XMLConfig: TXMLConfig; Path: string);
     170var
     171  I: Integer;
     172begin
     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;
    142178  end;
    143179end;
     
    151187end;
    152188
     189function TLastOpenedList.GetFirstFileName: string;
     190begin
     191  if Items.Count > 0 then Result := Items[0]
     192    else Result := '';
     193end;
     194
    153195end.
    154 
Note: See TracChangeset for help on using the changeset viewer.