Ignore:
Timestamp:
Feb 4, 2011, 9:45:01 AM (13 years ago)
Author:
chronos
Message:
  • Modified: Source selection separated to single form.
  • Added: Starting compiler and IDE with updated paths in configuration files.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UInstanceOptions.pas

    r5 r6  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
    9   ComCtrls, ExtCtrls, DOM, XMLWrite, XMLRead, HTTPSend, USource, UInstance;
     9  ComCtrls, ExtCtrls, DOM, XMLWrite, XMLRead, HTTPSend, USource, UInstance,
     10  USourceSelection;
    1011
    1112type
     
    1415
    1516  TInstanceOptionsForm = class(TForm)
    16     ButtonUpdateSource: TButton;
     17    Button1: TButton;
     18    Button2: TButton;
    1719    ButtonCancel: TButton;
    1820    ButtonOk: TButton;
    1921    Edit1: TEdit;
     22    Edit2: TEdit;
     23    Edit3: TEdit;
    2024    Label1: TLabel;
    2125    Label2: TLabel;
    2226    Label3: TLabel;
    23     ListView1: TListView;
    24     ListView2: TListView;
    25     Panel1: TPanel;
    26     Panel2: TPanel;
    27     Panel3: TPanel;
     27    procedure Button1Click(Sender: TObject);
     28    procedure Button2Click(Sender: TObject);
    2829    procedure ButtonCancelClick(Sender: TObject);
    2930    procedure ButtonOkClick(Sender: TObject);
    30     procedure ButtonUpdateSourceClick(Sender: TObject);
    3131    procedure FormCreate(Sender: TObject);
    3232    procedure FormDestroy(Sender: TObject);
    3333    procedure FormShow(Sender: TObject);
    34     procedure ListView1Data(Sender: TObject; Item: TListItem);
    35     procedure ListView2Data(Sender: TObject; Item: TListItem);
    3634  private
    37     procedure ReloadList;
     35    IsNew: Boolean;
    3836  public
    3937    Instance: TInstance;
    40     FPCSources: TSourceList;
    41     IDESources: TSourceList;
     38    FPCSource: TSource;
     39    IDESource: TSource;
    4240  end;
    4341
     
    5452{ TInstanceOptionsForm }
    5553
    56 procedure TInstanceOptionsForm.ButtonUpdateSourceClick(Sender: TObject);
    57 var
    58   fs: TFileStream;
    59 begin
    60   fs := TFileStream.Create(ExtractFileName(MainForm.SourceURL), fmOpenWrite or fmCreate);
    61   try
    62     HttpGetBinary(MainForm.SourceURL, fs);
    63   finally
    64     fs.Free;
    65   end;
    66   MainForm.Sources.UpdateFormFile(ExtractFileName(MainForm.SourceURL));
    67   ReloadList;
    68 end;
    69 
    7054procedure TInstanceOptionsForm.ButtonOkClick(Sender: TObject);
    7155begin
    7256  Instance.Name := Edit1.Text;
    73   if Assigned(ListView1.Selected) then
    74     Instance.FPCSource := TSource(ListView1.Selected.Data)
    75     else Instance.FPCSource := nil;
    76   if Assigned(ListView2.Selected) then
    77     Instance.IDESource := TSource(ListView2.Selected.Data)
    78     else Instance.IDESource := nil;
     57  Instance.FPCSource := FPCSource;
     58  Instance.IDESource := IDESource;
    7959end;
    8060
    8161procedure TInstanceOptionsForm.ButtonCancelClick(Sender: TObject);
    8262begin
    83   Instance.Free;
     63  if IsNew then Instance.Free;
     64end;
     65
     66procedure TInstanceOptionsForm.Button1Click(Sender: TObject);
     67begin
     68  SourceSelectionForm.ProjectType := 'Compiler';
     69  if SourceSelectionForm.ShowModal = mrOk then begin
     70    if Assigned(SourceSelectionForm.ListView1.Selected) then
     71      FPCSource := TSource(SourceSelectionForm.ListView1.Selected.Data)
     72      else FPCSource := nil;
     73    if Assigned(FPCSource) then
     74      Edit2.Text := FPCSource.GetName
     75      else Edit2.Text := '';
     76  end;
     77end;
     78
     79procedure TInstanceOptionsForm.Button2Click(Sender: TObject);
     80begin
     81  SourceSelectionForm.ProjectType := 'IDE';
     82  if SourceSelectionForm.ShowModal = mrOk then begin
     83    if Assigned(SourceSelectionForm.ListView1.Selected) then
     84      IDESource := TSource(SourceSelectionForm.ListView1.Selected.Data)
     85      else IDESource := nil;
     86    if Assigned(IDESource) then
     87      Edit3.Text := IDESource.GetName
     88      else Edit3.Text := '';
     89  end;
    8490end;
    8591
    8692procedure TInstanceOptionsForm.FormCreate(Sender: TObject);
    8793begin
    88   FPCSources := TSourceList.Create;
    89   FPCSources.OwnsObjects := False;
    90   IDESources := TSourceList.Create;
    91   IDESources.OwnsObjects := False;
    9294end;
    9395
    9496procedure TInstanceOptionsForm.FormDestroy(Sender: TObject);
    9597begin
    96   FPCSources.Free;
    97   IDESources.Free;
    9898end;
    9999
    100100procedure TInstanceOptionsForm.FormShow(Sender: TObject);
    101101begin
    102   ReloadList;
    103102  if not Assigned(Instance) then begin
    104103    Instance := TInstance.Create;
    105104    Instance.Id := MainForm.Instances.GetNewId;
    106105    Instance.Name := 'Instance ' + IntToStr(Instance.Id);
    107   end;
    108   //    ListView1.Items[;
     106    IsNew := True;
     107  end else IsNew := False;
     108
    109109  Edit1.Text := Instance.Name;
    110 end;
    111 
    112 procedure TInstanceOptionsForm.ListView1Data(Sender: TObject; Item: TListItem);
    113 begin
    114   if Item.Index < FPCSources.Count then
    115   with TSource(FPCSources[Item.Index]) do begin
    116     Item.Caption := ProjectName;
    117     Item.Data := FPCSources[Item.Index];
    118     Item.SubItems.Add(VersionType);
    119     Item.SubItems.Add(VersionNumber);
    120     Item.SubItems.Add('');
    121     Item.SubItems.Add('');
    122     Item.SubItems.Add(SubversionURL);
    123   end;
    124 end;
    125 
    126 procedure TInstanceOptionsForm.ListView2Data(Sender: TObject; Item: TListItem);
    127 begin
    128   if Item.Index < IDESources.Count then
    129   with TSource(IDESources[Item.Index]) do begin
    130     Item.Caption := ProjectName;
    131     Item.Data := IDESources[Item.Index];
    132     Item.SubItems.Add(VersionType);
    133     Item.SubItems.Add(VersionNumber);
    134     Item.SubItems.Add('');
    135     Item.SubItems.Add('');
    136     Item.SubItems.Add(SubversionURL);
    137   end;
    138 end;
    139 
    140 procedure TInstanceOptionsForm.ReloadList;
    141 var
    142   I: Integer;
    143 begin
    144   FPCSources.Clear;
    145   for I := 0 to MainForm.Sources.Count - 1 do
    146     if TSource(MainForm.Sources[I]).ProjectType = 'Compiler' then
    147       FPCSources.Add(MainForm.Sources[I]);
    148   if ListView1.Items.Count <> FPCSources.Count then
    149     ListView1.Items.Count := FPCSources.Count;
    150   ListView1.Items[-1]; // workaround
    151   ListView1.Refresh;
    152   IDESources.Clear;
    153   for I := 0 to MainForm.Sources.Count - 1 do
    154     if TSource(MainForm.Sources[I]).ProjectType = 'IDE' then
    155       IDESources.Add(MainForm.Sources[I]);
    156   if ListView2.Items.Count <> IDESources.Count then
    157     ListView2.Items.Count := IDESources.Count;
    158   ListView2.Items[-1]; // workaround
    159   ListView2.Refresh;
     110  if Assigned(Instance.FPCSource) then
     111    Edit2.Text := Instance.FPCSource.GetName
     112    else Edit2.Text := '';
     113  if Assigned(Instance.IDESource) then
     114    Edit3.Text := Instance.IDESource.GetName
     115    else Edit3.Text := '';
    160116end;
    161117
Note: See TracChangeset for help on using the changeset viewer.