1 | unit USource;
|
---|
2 |
|
---|
3 | {$mode delphi}{$H+}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | Classes, SysUtils, SpecializedList, Forms;
|
---|
9 |
|
---|
10 | type
|
---|
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 |
|
---|
92 | implementation
|
---|
93 |
|
---|
94 | resourcestring
|
---|
95 | SAllFiles = 'All files';
|
---|
96 |
|
---|
97 | { TSourceType }
|
---|
98 |
|
---|
99 | constructor TSourceType.Create;
|
---|
100 | begin
|
---|
101 | inherited;
|
---|
102 | SourceClass := TSource;
|
---|
103 | end;
|
---|
104 |
|
---|
105 | procedure TSource.SetName(AValue: string);
|
---|
106 | begin
|
---|
107 | if FName = AValue then Exit;
|
---|
108 | FName := AValue;
|
---|
109 | if Assigned(Form) then
|
---|
110 | Form.Caption := ExtractFileName(FName);
|
---|
111 | end;
|
---|
112 |
|
---|
113 |
|
---|
114 | { TFileTemplate }
|
---|
115 |
|
---|
116 | constructor TFileTemplate.Create;
|
---|
117 | begin
|
---|
118 | Description := TStringList.Create;
|
---|
119 | end;
|
---|
120 |
|
---|
121 | destructor TFileTemplate.Destroy;
|
---|
122 | begin
|
---|
123 | Description.Free;
|
---|
124 | inherited Destroy;
|
---|
125 | end;
|
---|
126 |
|
---|
127 | function TFileTemplate.Execute: TSource;
|
---|
128 | begin
|
---|
129 |
|
---|
130 | end;
|
---|
131 |
|
---|
132 |
|
---|
133 | { TFileTypes }
|
---|
134 |
|
---|
135 | function TFileTypes.GetDialogFilter: string;
|
---|
136 | var
|
---|
137 | I: Integer;
|
---|
138 | begin
|
---|
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 + ' (*.*)|*.*';
|
---|
145 | end;
|
---|
146 |
|
---|
147 | function TFileTypes.FindByExt(Extension: string): TSourceType;
|
---|
148 | var
|
---|
149 | I: Integer;
|
---|
150 | begin
|
---|
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;
|
---|
155 | end;
|
---|
156 |
|
---|
157 | { TConvertor }
|
---|
158 |
|
---|
159 | procedure TConvertor.Convert(Input, Output: TSourceList);
|
---|
160 | begin
|
---|
161 |
|
---|
162 | end;
|
---|
163 |
|
---|
164 | constructor TConvertor.Create;
|
---|
165 | begin
|
---|
166 |
|
---|
167 | end;
|
---|
168 |
|
---|
169 | procedure TConvertor.Log(Text: string);
|
---|
170 | begin
|
---|
171 | if Assigned(FOnDebugLog) then
|
---|
172 | FOnDebugLog(Text);
|
---|
173 | end;
|
---|
174 |
|
---|
175 | end.
|
---|
176 |
|
---|