{
********************************************************************************

YaPeTaVi - Yet another Periodic Table Viewer
Copyright (C) 2009-2010 Geoffray Levasseur <geoffray.levasseurbrandin@numericable.fr>.
All rights reserved.
http://www.geoffray-levasseur.org/

This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 3 of the License, or (at your option) any later
version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.  See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place - Suite 330, Boston, MA  02111-1307, USA.

********************************************************************************

Description:
   Discoverer list form and associated tools

}
unit frmDiscovererList;

{$mode objfpc}

interface

uses
  Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
  Buttons, StdCtrls;

type

  { TDiscovererListForm }

  TDiscovererListForm = class(TForm)
    btnWikipedia: TBitBtn;
    btnClose: TBitBtn;
    Label1: TLabel;
    lblDiscoName: TLabel;
    lbDiscoverer: TListBox;
    memElements: TMemo;
    procedure btnCloseClick(Sender: TObject);
    procedure btnWikipediaClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure lbDiscovererClick(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end; 

var
  DiscovererListForm: TDiscovererListForm;

implementation

uses
  uIconManager, uUtils, uElemListClass, uStrings, uConst, uCommon;

{ TDiscovererListForm }

procedure TDiscovererListForm.btnCloseClick(Sender: TObject);
begin
  Close;
end;

procedure TDiscovererListForm.btnWikipediaClick(Sender: TObject);
begin
  if not OpenURL(rsWikipediaAddr + lblDiscoName.Caption) then
    MessageDlg(rsError, erOpenUrl, mtError, [mbOK], '');
end;

procedure TDiscovererListForm.FormCreate(Sender: TObject);
var
  Str: TStrings;
begin
  lblDiscoName.Caption := '';
  memElements.Clear;
  InitBtnGlyphs(Self);
  lbDiscoverer.Sorted := False;
  lbDiscoverer.Items.Clear;
  Str := ElementsList.GetDiscovererList;
  lbDiscoverer.Items.Assign(Str);
  lbDiscoverer.Sorted := True;
end;

procedure TDiscovererListForm.lbDiscovererClick(Sender: TObject);
var
  I, J: integer;
begin
  memElements.Clear;
  lblDiscoName.Caption := lbDiscoverer.Items[lbDiscoverer.ItemIndex];
  for I := 1 to ElemNumber do
    for J := 1 to CountItemsInStr(ElementsList.Elements[I].Discoverer, ',') do
      if Trim(GetItemInStr(ElementsList.Elements[I].Discoverer, ',', J)) =
        lblDiscoName.Caption then
          memElements.Lines.Add(ElementsList.Elements[I].Name + ' (' +
            ElementsList.Elements[I].ShortName + ') in ' +
            IntToStr(ElementsList.Elements[I].DiscoYear));
end;

initialization
  {$I frmdiscovererlist.lrs}

end.

