Ignore:
Timestamp:
Aug 3, 2012, 4:03:59 PM (12 years ago)
Author:
chronos
Message:
  • Modified: Implementing base tabbed opened file list.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/StudioPackage/UDataModule.pas

    r11 r13  
    2323  end;
    2424
    25   TOpenFileEvent = procedure (OpenedFile: TOpenedFile) of object;
    26 
    2725  { TOpenedFiles }
    2826
    2927  TOpenedFiles = class(TListObject)
    3028  private
    31     FOnOpenFile: TOpenFileEvent;
     29    FOnChange: TNotifyEvent;
    3230  public
    3331    Selected: TOpenedFile;
    34     procedure CloseFile(OpenedFile: TOpenedFile);
     32    function FindByFileName(Value: string): TOpenedFile;
     33    procedure CloseFile(FileName: string);
    3534    procedure OpenFile(FileName: string);
    3635    procedure NewFile;
    37     property OnOpenFile: TOpenFileEvent read FOnOpenFile write FOnOpenFile;
     36    property OnChange: TNotifyEvent read FOnChange write FOnChange;
    3837  end;
    3938
     
    6261  UFormSourceCode, UFormMain, UFormSettings, UFormModuleList;
    6362
     63resourcestring
     64  SNewFile = 'New file';
     65
    6466procedure TOpenedFile.SetFileName(AValue: string);
    6567begin
     
    7274{ TOpenedFiles }
    7375
    74 procedure TOpenedFiles.CloseFile(OpenedFile: TOpenedFile);
     76function TOpenedFiles.FindByFileName(Value: string): TOpenedFile;
     77var
     78  I: Integer;
    7579begin
     80  I := 0;
     81  while (I < Count) and (TOpenedFile(Items[I]).FileName <> Value) do Inc(I);
     82  if I < Count then Result := TOpenedFile(Items[I])
     83    else Result := nil;
     84end;
     85
     86procedure TOpenedFiles.CloseFile(FileName: string);
     87var
     88  OpenedFile: TOpenedFile;
     89begin
     90  OpenedFile := FindByFileName(FileName);
    7691  FreeAndNil(OpenedFile.Form);
     92  Remove(OpenedFile);
     93  if Assigned(FOnChange) then FOnChange(Self);
    7794end;
    7895
     
    87104  NewFile.Form.Visible := True;
    88105  Selected := NewFile;
    89   if Assigned(FOnOpenFile) then
    90     FOnOpenFile(NewFile);
     106  if Assigned(FOnChange) then FOnChange(Self);
    91107end;
    92108
    93109procedure TOpenedFiles.NewFile;
     110var
     111  NewFile: TOpenedFile;
    94112begin
    95 
     113  NewFile := TOpenedFile(AddNew(TOpenedFile.Create));
     114  NewFile.FileName := SNewFile;
     115  NewFile.Form := TFormSourceCode.Create(nil);
     116  NewFile.Form.Caption := ExtractFileName(NewFile.FileName);
     117  NewFile.Form.Visible := True;
     118  Selected := NewFile;
     119  if Assigned(FOnChange) then FOnChange(Self);
    96120end;
    97121
     
    109133  FormMain := TFormMain.Create(nil);
    110134  Application.UpdateMainForm(FormMain);
    111   OpenedFiles.OnOpenFile := FormMain.OpenFileExecute;
     135  OpenedFiles.OnChange := FormMain.OpenedFileChange;
    112136  FormSourceCode := TFormSourceCode.Create(nil);
    113137  FormSettings := TFormSettings.Create(nil);
Note: See TracChangeset for help on using the changeset viewer.