Ignore:
Timestamp:
Aug 6, 2012, 3:16:26 PM (12 years ago)
Author:
chronos
Message:
  • Modified: Definition of text source file moved to new package Basic.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/StudioPackage/UDataModule.pas

    r15 r16  
    1111
    1212type
    13 
    14   { TTextTemplate }
    15 
    16   TTextTemplate = class(TFileTemplate)
    17     constructor Create; override;
    18   end;
    19 
    20   { TTextFileType }
    21 
    22   TTextFileType = class(TSourceType)
    23     constructor Create; override;
    24   end;
    25 
    2613  { TOpenedFiles }
    2714
     
    3522    procedure OpenFileName(FileName: string);
    3623    procedure OpenFile(Source: TSource);
    37     procedure NewFile;
    3824    property OnChange: TNotifyEvent read FOnChange write FOnChange;
    3925  end;
     
    6551    procedure DataModuleDestroy(Sender: TObject);
    6652  private
    67     TextFileType: TSourceType;
    68     TextFileTemplate: TTextTemplate;
    6953    procedure AutoOpen;
    7054    procedure DockToPageControl(PageControl: TPageControl; Form: TForm);
     
    8872
    8973uses
    90   UFormSourceCode, UFormMain, UFormSettings, UFormModuleList, UFormNewFile;
     74  UFormMain, UFormSettings, UFormModuleList, UFormNewFile, ULDModuleBasic;
    9175
    9276resourcestring
    9377  SNewFile = 'New file';
    94   STextFile = 'Text file';
    95 
    96 { TTextFileType }
    97 
    98 constructor TTextFileType.Create;
    99 begin
    100   inherited Create;
    101   Extension := '.txt';
    102   Title := 'Text file';;
    103 end;
    104 
    105 { TTextTemplate }
    106 
    107 constructor TTextTemplate.Create;
    108 begin
    109   inherited Create;
    110   Name := STextFile;
    111 end;
    112 
    11378
    11479{ TOpenedFiles }
     
    13398procedure TOpenedFiles.OpenFileName(FileName: string);
    13499var
    135   NewFile: TSourceText;
    136 begin
    137   NewFile := TSourceText.Create;
    138   NewFile.Name := FileName;
    139   OpenFile(NewFile);
     100  NewFile: TSource;
     101  FileType: TSourceType;
     102begin
     103  FileType := DataModule1.FileTypes.FindByExt(ExtractFileExt(FileName));
     104  if Assigned(FileType) then begin
     105    NewFile := FileType.SourceClass.Create;
     106    NewFile.Name := FileName;
     107    OpenFile(NewFile);
     108  end;
    140109end;
    141110
     
    143112begin
    144113  AddNew(Source);
    145   Source.Form := TFormSourceCode.Create(nil);
     114  Source.Form := Source.FileType.Form.Create(nil);
    146115  Source.Form.Caption := ExtractFileName(Source.Name);
    147116  Source.Form.Visible := True;
    148117  Selected := Source;
    149   if Assigned(FOnChange) then FOnChange(Self);
    150 end;
    151 
    152 procedure TOpenedFiles.NewFile;
    153 var
    154   NewFile: TSource;
    155 begin
    156   NewFile := TSourceText(AddNew(TSource.Create));
    157   NewFile.Name := SNewFile;
    158   NewFile.Form := TFormSourceCode.Create(nil);
    159   NewFile.Form.Caption := ExtractFileName(NewFile.Name);
    160   NewFile.Form.Visible := True;
    161   Selected := NewFile;
    162118  if Assigned(FOnChange) then FOnChange(Self);
    163119end;
     
    175131  ModuleManager.API := API;
    176132
    177   TextFileType := TTextFileType.Create;
    178   API.RegisterFileType(TextFileType);
    179   TextFileTemplate := TTextTemplate.Create;
    180   API.RegisterFileTemplate(TextFileTemplate);
    181 
    182133  FormMain := TFormMain.Create(nil);
    183134  Application.UpdateMainForm(FormMain);
    184135  OpenedFiles.OnChange := FormMain.OpenedFileChange;
    185   FormSourceCode := TFormSourceCode.Create(nil);
    186136  FormSettings := TFormSettings.Create(nil);
    187137  FormModuleList := TFormModuleList.Create(nil);
     
    301251procedure TDataModule1.DataModuleDestroy(Sender: TObject);
    302252begin
    303   API.UnregisterFileType(TextFileType);
    304   FreeAndNil(TextFileType);
    305   API.UnregisterFileTemplate(TextFileTemplate);
    306   FreeAndNil(TextFileTemplate);
    307 
    308253  SaveToRegistry(RegContext(HKEY(ApplicationInfo1.RegistryRoot), ApplicationInfo1.RegistryKey));
    309254  FreeAndNil(ModuleManager);
    310255  FreeAndNil(FormNewFile);
    311256  FreeAndNil(FormMain);
    312   FreeAndNil(FormSourceCode);
    313257  FreeAndNil(FormSettings);
    314258  FreeAndNil(FormModuleList);
Note: See TracChangeset for help on using the changeset viewer.