unit DeviceSel;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ComCtrls, ImgList,inifiles, ToolWin, Placemnt, Menus;

type
  TfmDevSel = class(TForm)
    ListView1: TListView;
    ToolBar1: TToolBar;
    tbnLarge: TToolButton;
    tbnList: TToolButton;
    sbProperties: TToolButton;
    FormStorage: TFormStorage;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    procedure FormCreate(Sender: TObject);
    procedure tbnLargeClick(Sender: TObject);
    procedure sbPropertiesClick(Sender: TObject);
    procedure ListView1Change(Sender: TObject; Item: TListItem;
      Change: TItemChange);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure N1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  fmDevSel: TfmDevSel;

implementation

uses Data, DevEdit, LoadConst;

{$R *.DFM}

procedure TfmDevSel.FormCreate(Sender: TObject);
var
 iDir : string;
 Found : integer;
 SR    : TSearchRec;
 fDev  : TIniFile;
 iDev  : TDeviceEl;
 Itm   : TListItem;
begin
  iDir := ExtractFileDir(ParamStr(0))+'\devices';
  Found:=FindFirst(idir+'\*.idev',faAnyFile,SR);
  while Found=0 do
  begin
    //Item := ListView1.Items.Add;
    fDev := TIniFile.Create(idir+'\'+SR.Name);
    with FDev do
    try
     iDev := TDeviceEl.Create(FDev);
     Itm := iDev.CreateListItem(ListView1);
     Itm.SubItems.Objects[0]:=iDev;
    finally
      FDev.Free;
    end;
    Found:=FindNext(SR);
  end;
  FindClose(SR);
end;

procedure TfmDevSel.tbnLargeClick(Sender: TObject);
begin
  ListView1.ViewStyle  := TViewStyle(TToolButton(Sender).Tag);;
end;

procedure TfmDevSel.sbPropertiesClick(Sender: TObject);
var
 ADev : TDeviceEl;
begin
  if Assigned(ListView1.Selected) then
  begin
    ADev := TDeviceEl(ListView1.Selected.data);
    if ADev<>Nil then
    with TfmDevEdit.Create(ADev) do
    try
     ShowModal;
    finally
     Free;
    end;
  end;
end;

procedure TfmDevSel.ListView1Change(Sender: TObject; Item: TListItem;
  Change: TItemChange);
begin
  sbProperties.Enabled := ListView1.Selected<>nil;
end;

procedure TfmDevSel.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  if Owner is TFmLoadConstr then
  with TfmLoadConstr(Owner) do
    sbDevicesToogle.Down := False;
end;

procedure TfmDevSel.N1Click(Sender: TObject);
begin
  ListView1.Arrange(arAlignTop);
end;

end.
