unit cde_SettingsForm;
{$mode delphi}
{$codepage UTF8}
interface
uses Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls, StdCtrls, ExtCtrls, Buttons, EditBtn,
     cde_dir, cde_lang, VersionControl, cde_types, LazFileUtils, cde_kernel, ANBFormatString, windows;
type
  { Tcde_Settings }
  Tcde_Settings = class(TForm)
    BrowseProgramEdt: TFileNameEdit;
    BrowseParamHlp: TSpeedButton;
    FlagsList: TImageList;
    BrowseProgramLbl: TLabel;
    BrowseParamEdt: TLabeledEdit;
    LanguageStateList: TImageList;
    LanguageBox: TListView;
    OkBtn: TBitBtn;
    CancelBtn: TBitBtn;
    ButtonsSep: TBevel;
    ButtonsPanel: TPanel;
    SettingsPages: TPageControl;
    LanguageSht: TTabSheet;
    BrowseSht: TTabSheet;
    BrowseProgramHlp: TSpeedButton;
    TabsImages: TImageList;
    SettingsTree: TTreeView;
    procedure BrowseParamHlpClick(Sender: TObject);
    procedure BrowseProgramHlpClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure SettingsTreeChange(Sender: TObject; Node: TTreeNode);
  private
    procedure FillLanguageList;
  public
  end;
var
  cde_Settings: Tcde_Settings;
implementation
{$R *.lfm}
{ Tcde_Settings }
procedure Tcde_Settings.FillLanguageList;
var SR: TSearchRec;
    LI: TListItem;
    Indx: Integer;
    FLanguage: String;
    LangInfo: TCDELanguageInfo;
    Image: TIcon;
begin
Indx:= -1;
LanguageBox.Items.Clear;
FlagsList.Clear;
if FindFirstUTF8(IncludeTrailingBackslash(GetCDEPath) + 'languages\*.json', faAnyFile, SR) = 0 then
 repeat
  if (not ((SR.Name = '.') or (SR.Name = '..'))) and FileExistsUTF8(IncludeTrailingBackslash(GetCDEPath) + 'languages\' + SR.Name) then
   begin
   LI:= LanguageBox.Items.Add;
   FLanguage:= ExtractFileNameWithoutExt(SR.Name);
   LangInfo:= GetLanguageInfo(FLanguage);
   LI.Caption:= LangInfo.liName;
   LI.SubItems.Add(FLanguage);
   Li.SubItems.Add(LangInfo.liAuthor);
   LI.SubItems.Add(VersionInfoToStr(LangInfo.liVersion));
   LI.SubItems.Add(VersionInfoToStr(LangInfo.liCDEVersion));
   if FLanguage = GetLanguage then
    begin
    Indx:= LI.Index;
    LI.StateIndex:= 0;
    end
    else
    LI.StateIndex:= -1;
   Image:= TIcon.Create;
   Image.LoadFromFile(IncludeTrailingBackslash(GetCDEPath) + 'languages\flags\' + FLanguage + '.ico');
   LI.ImageIndex:= FlagsList.AddIcon(Image);
   Image.Free;
   end;
  until FindNextUTF8(SR) <> 0;
FindCloseUTF8(SR);
LanguageBox.Items.Item[Indx].Selected:= True;
end;
procedure Tcde_Settings.SettingsTreeChange(Sender: TObject; Node: TTreeNode);
begin
SettingsPages.ActivePageIndex:= Node.StateIndex;
end;
procedure Tcde_Settings.FormCreate(Sender: TObject);
begin
FillLanguageList;
end;
procedure Tcde_Settings.BrowseProgramHlpClick(Sender: TObject);
var HlpText: String;
begin
HlpText:= FormatStr(GetLocalizedString(cdeg_messages_settingsbrowseprogramhelp), ['$newline$'], [#13#10]);
ShowMessageBox(HlpText, MB_ICONASTERISK);
end;
procedure Tcde_Settings.BrowseParamHlpClick(Sender: TObject);
var HlpText: String;
begin
HlpText:= FormatStr(GetLocalizedString(cdeg_messages_settingsbrowseparamhelp), ['$newline$'], [#13#10]);
ShowMessageBox(HlpText, MB_ICONASTERISK);
end;
end.
