source: trunk/StudioCommon/USource.pas

Last change on this file was 16, checked in by chronos, 12 years ago
  • Modified: Definition of text source file moved to new package Basic.
File size: 3.4 KB
Line 
1unit USource;
2
3{$mode delphi}{$H+}
4
5interface
6
7uses
8 Classes, SysUtils, SpecializedList, Forms;
9
10type
11 TSourceType = class;
12
13 { TSource }
14
15 TSource = class
16 private
17 FName: string;
18 procedure SetName(AValue: string);
19 public
20 Modified: Boolean;
21 Form: TForm;
22 FileType: TSourceType;
23 property Name: string read FName write SetName;
24 end;
25
26 TSourceClass = class of TSource;
27
28 TSourceList = class
29 Items: TListObject; // TListObject<TSource>
30 Main: TSource;
31 end;
32
33
34 { TSourceType }
35
36 TSourceType = class
37 Extension: string;
38 Title: string;
39 Form: TFormClass;
40 SourceClass: TSourceClass;
41 constructor Create; virtual;
42 end;
43
44 TFileTypeClass = class of TSourceType;
45
46 { TFileTypes }
47
48 TFileTypes = class(TListObject)
49 function GetDialogFilter: string;
50 function FindByExt(Extension: string): TSourceType;
51 end;
52
53 { TFileTemplate }
54
55 TFileTemplate = class
56 public
57 Name: string;
58 Description: TStringList;
59 FileTypeClass: TSourceType;
60 constructor Create; virtual;
61 destructor Destroy; override;
62 function Execute: TSource; virtual;
63 end;
64
65 TFileTemplates = class(TListObject)
66 end;
67
68 TDebugLogEvent = procedure(Text: string) of object;
69 TDebugPositionEvent = procedure (Position: Integer) of object;
70
71 { TConvertor }
72
73 TConvertor = class
74 private
75 FOnDebugLog: TDebugLogEvent;
76 FOnDebugPosition: TDebugPositionEvent;
77 public
78 Name: string;
79 InputType: TSourceClass;
80 OutputType: TSourceClass;
81 procedure Convert(Input, Output: TSourceList); virtual;
82 constructor Create; virtual;
83 procedure Log(Text: string);
84 property OnDebugLog: TDebugLogEvent read FOnDebugLog write FOnDebugLog;
85 property OnDebugPosition: TDebugPositionEvent read FOnDebugPosition
86 write FOnDebugPosition;
87 end;
88
89 TConvertorClass = class of TConvertor;
90
91
92implementation
93
94resourcestring
95 SAllFiles = 'All files';
96
97{ TSourceType }
98
99constructor TSourceType.Create;
100begin
101 inherited;
102 SourceClass := TSource;
103end;
104
105procedure TSource.SetName(AValue: string);
106begin
107 if FName = AValue then Exit;
108 FName := AValue;
109 if Assigned(Form) then
110 Form.Caption := ExtractFileName(FName);
111end;
112
113
114{ TFileTemplate }
115
116constructor TFileTemplate.Create;
117begin
118 Description := TStringList.Create;
119end;
120
121destructor TFileTemplate.Destroy;
122begin
123 Description.Free;
124 inherited Destroy;
125end;
126
127function TFileTemplate.Execute: TSource;
128begin
129
130end;
131
132
133{ TFileTypes }
134
135function TFileTypes.GetDialogFilter: string;
136var
137 I: Integer;
138begin
139 Result := '';
140 for I := 0 to Count - 1 do
141 Result := Result + TSourceType(Items[I]).Title + ' (*' +
142 TSourceType(Items[I]).Extension + ')|' +
143 TSourceType(Items[I]).Extension + '|';
144 Result := Result + SAllFiles + ' (*.*)|*.*';
145end;
146
147function TFileTypes.FindByExt(Extension: string): TSourceType;
148var
149 I: Integer;
150begin
151 I := 0;
152 while (I < count) and (TSourceType(Items[I]).Extension <> Extension) do Inc(I);
153 if I < Count then Result := TSourceType(Items[I])
154 else Result := nil;
155end;
156
157{ TConvertor }
158
159procedure TConvertor.Convert(Input, Output: TSourceList);
160begin
161
162end;
163
164constructor TConvertor.Create;
165begin
166
167end;
168
169procedure TConvertor.Log(Text: string);
170begin
171 if Assigned(FOnDebugLog) then
172 FOnDebugLog(Text);
173end;
174
175end.
176
Note: See TracBrowser for help on using the repository browser.