Changeset 9 for trunk/UCore.pas


Ignore:
Timestamp:
May 18, 2015, 11:49:39 PM (10 years ago)
Author:
chronos
Message:
  • Added: Simple Bazaar backend.\n* Added: Support for backends dynamic registration.\n* Added: Backend selection in checkout form.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UCore.pas

    r8 r9  
    77uses
    88  Classes, SysUtils, XMLConf, FileUtil, ActnList, Controls, UVCS, UProject,
    9   ULastOpenedList, Forms, Dialogs;
     9  ULastOpenedList, Forms, Dialogs, Contnrs, UBackend;
    1010
    1111type
     
    4747  private
    4848    procedure UpdateInterface;
     49    procedure RegisterBackends;
     50    procedure RegisterBackend(Backend: TBackend);
     51    function DetectBackend(Directory: string): TBackend;
    4952  public
     53    Backends: TObjectList; // TList<TBackend>
    5054    Project: TProject;
    5155    procedure LoadConfig;
     
    6468
    6569uses
    66   UFormMain, UFormBrowse, UFormSettings, UFormCommit, UFormCheckout;
     70  UFormMain, UFormBrowse, UFormSettings, UFormCommit, UFormCheckout,
     71  USubversion, UBazaar;
    6772
    6873{ TCore }
     
    8085procedure TCore.DataModuleCreate(Sender: TObject);
    8186begin
     87  Backends := TObjectList.Create;
    8288  UpdateInterface;
    8389end;
     
    8591procedure TCore.DataModuleDestroy(Sender: TObject);
    8692begin
    87   Project.Free;
     93  FreeAndNil(Project);
     94  FreeAndNil(Backends);
    8895end;
    8996
     
    97104  AProjectClose.Enabled := Assigned(Project);
    98105  FormMain.UpdateInterface;
     106end;
     107
     108procedure TCore.RegisterBackends;
     109begin
     110  RegisterBackend(TBackendSubversion.Create);
     111  RegisterBackend(TBackendBazaar.Create);
     112end;
     113
     114procedure TCore.RegisterBackend(Backend: TBackend);
     115begin
     116  Backends.Add(Backend);
     117end;
     118
     119function TCore.DetectBackend(Directory: string): TBackend;
     120var
     121  I: Integer;
     122begin
     123  I := 0;
     124  while (I < Backends.Count) and (not TBackend(Backends[I]).IsWorkingCopy(Directory)) do Inc(I);
     125  if I < Backends.Count then Result := TBackend(Backends[I])
     126    else Result := nil;
    99127end;
    100128
     
    115143procedure TCore.Init;
    116144begin
     145  RegisterBackends;
    117146  LoadConfig;
    118147  if (LastOpenedList1.Items.Count > 0) and DirectoryExistsUTF8(LastOpenedList1.Items[0]) then
     
    129158  AProjectClose.Execute;
    130159  Project := TProject.Create;
    131   Project.VCSType := vtSubversion;
    132   Project.Directory := Directory;
    133   UpdateInterface;
    134   FormBrowse.Directory := Project.Directory;
    135   FormBrowse.ReloadList;
    136   LastOpenedList1.AddItem(Project.Directory);
     160  Project.Backend := DetectBackend(Directory);
     161  if Assigned(Project.Backend) then begin
     162    Project.Directory := Directory;
     163    UpdateInterface;
     164    FormBrowse.Directory := Project.Directory;
     165    FormBrowse.ReloadList;
     166    LastOpenedList1.AddItem(Project.Directory);
     167  end else ShowMessage('Directory not recognized as working copy of any of supported VCS systems');
    137168end;
    138169
     
    175206    TempProject := TProject.Create;
    176207    try
    177       TempProject.VCSType := vtSubversion;
     208      TempProject.Backend := TBackend(FormCheckout.ComboBox1.Items.Objects[FormCheckout.ComboBox1.ItemIndex]);
    178209      TempProject.Directory := FormCheckout.EditDir.Text;
    179210      TempProject.RepositoryURL := FormCheckout.EditURL.Text;
Note: See TracChangeset for help on using the changeset viewer.