source: cprs/branches/tmg-cprs/TMG_Extra/tntUniCode/Design/TntStrEdit_Design.pas@ 1531

Last change on this file since 1531 was 672, checked in by Kevin Toppenberg, 15 years ago

Adding source to tntControls for compilation

File size: 11.3 KB
Line 
1
2{*****************************************************************************}
3{ }
4{ Tnt Delphi Unicode Controls }
5{ http://www.tntware.com/delphicontrols/unicode/ }
6{ Version: 2.3.0 }
7{ }
8{ Copyright (c) 2002-2007, Troy Wolbrink (troy.wolbrink@tntware.com) }
9{ }
10{*****************************************************************************}
11
12unit TntStrEdit_Design;
13
14{$INCLUDE ..\Source\TntCompilers.inc}
15
16// The following unit is adapted from StrEdit.pas.
17
18interface
19
20uses
21 Windows, Classes, Graphics, Controls, Buttons, Menus, StdCtrls,
22 TntStdCtrls, ExtCtrls, DesignEditors, DesignIntf,
23 TntForms, TntMenus, TntClasses, TntDialogs;
24
25type
26 TTntStrEditDlg = class(TTntForm)
27 CodeWndBtn: TTntButton;
28 OpenDialog: TTntOpenDialog;
29 SaveDialog: TTntSaveDialog;
30 HelpButton: TTntButton;
31 OKButton: TTntButton;
32 CancelButton: TTntButton;
33 StringEditorMenu: TTntPopupMenu;
34 LoadItem: TTntMenuItem;
35 SaveItem: TTntMenuItem;
36 CodeEditorItem: TTntMenuItem;
37 TntGroupBox1: TTntGroupBox;
38 UnicodeEnabledLbl: TTntLabel;
39 Memo: TTntMemo;
40 LineCount: TTntLabel;
41 procedure FileOpenClick(Sender: TObject);
42 procedure FileSaveClick(Sender: TObject);
43 procedure HelpButtonClick(Sender: TObject);
44 procedure CodeWndBtnClick(Sender: TObject);
45 procedure FormCreate(Sender: TObject);
46 procedure Memo1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
47 procedure UpdateStatus(Sender: TObject);
48 private
49 SingleLine: WideString;
50 MultipleLines: WideString;
51 protected
52 FModified: Boolean;
53 function GetLines: TTntStrings;
54 procedure SetLines(const Value: TTntStrings);
55 function GetLinesControl: TWinControl;
56 public
57 property Lines: TTntStrings read GetLines write SetLines;
58 procedure PrepareForWideStringEdit;
59 end;
60
61type
62 TWideStringListProperty = class(TClassProperty)
63 protected
64 function EditDialog: TTntStrEditDlg; virtual;
65 function GetStrings: TTntStrings; virtual;
66 procedure SetStrings(const Value: TTntStrings); virtual;
67 public
68 function GetAttributes: TPropertyAttributes; override;
69 procedure Edit; override;
70 end;
71
72procedure Register;
73
74implementation
75
76{$R *.dfm}
77
78uses
79 ActiveX, Forms, SysUtils, DesignConst, ToolsAPI, IStreams, LibHelp,
80 StFilSys, TypInfo, TntSystem, TntDesignEditors_Design;
81
82procedure Register;
83begin
84 RegisterPropertyEditor(TypeInfo(TTntStrings), nil, '', TWideStringListProperty);
85end;
86
87{$IFDEF COMPILER_10_UP}
88type
89 TStringsModuleCreator = class(TInterfacedObject, IOTACreator, IOTAModuleCreator)
90 private
91 FFileName: AnsiString;
92 FStream: TStringStream{TNT-ALLOW TStringStream};
93 FAge: TDateTime;
94 public
95 constructor Create(const FileName: AnsiString; Stream: TStringStream{TNT-ALLOW TStringStream}; Age: TDateTime);
96 destructor Destroy; override;
97 { IOTACreator }
98 function GetCreatorType: AnsiString;
99 function GetExisting: Boolean;
100 function GetFileSystem: AnsiString;
101 function GetOwner: IOTAModule;
102 function GetUnnamed: Boolean;
103 { IOTAModuleCreator }
104 function GetAncestorName: AnsiString;
105 function GetImplFileName: AnsiString;
106 function GetIntfFileName: AnsiString;
107 function GetFormName: AnsiString;
108 function GetMainForm: Boolean;
109 function GetShowForm: Boolean;
110 function GetShowSource: Boolean;
111 function NewFormFile(const FormIdent, AncestorIdent: AnsiString): IOTAFile;
112 function NewImplSource(const ModuleIdent, FormIdent, AncestorIdent: AnsiString): IOTAFile;
113 function NewIntfSource(const ModuleIdent, FormIdent, AncestorIdent: AnsiString): IOTAFile;
114 procedure FormCreated(const FormEditor: IOTAFormEditor);
115 end;
116
117 TOTAFile = class(TInterfacedObject, IOTAFile)
118 private
119 FSource: AnsiString;
120 FAge: TDateTime;
121 public
122 constructor Create(const ASource: AnsiString; AAge: TDateTime);
123 { IOTAFile }
124 function GetSource: AnsiString;
125 function GetAge: TDateTime;
126 end;
127
128{ TOTAFile }
129
130constructor TOTAFile.Create(const ASource: AnsiString; AAge: TDateTime);
131begin
132 inherited Create;
133 FSource := ASource;
134 FAge := AAge;
135end;
136
137function TOTAFile.GetAge: TDateTime;
138begin
139 Result := FAge;
140end;
141
142function TOTAFile.GetSource: AnsiString;
143begin
144 Result := FSource;
145end;
146
147{ TStringsModuleCreator }
148
149constructor TStringsModuleCreator.Create(const FileName: AnsiString; Stream: TStringStream{TNT-ALLOW TStringStream};
150 Age: TDateTime);
151begin
152 inherited Create;
153 FFileName := FileName;
154 FStream := Stream;
155 FAge := Age;
156end;
157
158destructor TStringsModuleCreator.Destroy;
159begin
160 FStream.Free;
161 inherited;
162end;
163
164procedure TStringsModuleCreator.FormCreated(const FormEditor: IOTAFormEditor);
165begin
166 { Nothing to do }
167end;
168
169function TStringsModuleCreator.GetAncestorName: AnsiString;
170begin
171 Result := '';
172end;
173
174function TStringsModuleCreator.GetCreatorType: AnsiString;
175begin
176 Result := sText;
177end;
178
179function TStringsModuleCreator.GetExisting: Boolean;
180begin
181 Result := True;
182end;
183
184function TStringsModuleCreator.GetFileSystem: AnsiString;
185begin
186 Result := sTStringsFileSystem;
187end;
188
189function TStringsModuleCreator.GetFormName: AnsiString;
190begin
191 Result := '';
192end;
193
194function TStringsModuleCreator.GetImplFileName: AnsiString;
195begin
196 Result := FFileName;
197end;
198
199function TStringsModuleCreator.GetIntfFileName: AnsiString;
200begin
201 Result := '';
202end;
203
204function TStringsModuleCreator.GetMainForm: Boolean;
205begin
206 Result := False;
207end;
208
209function TStringsModuleCreator.GetOwner: IOTAModule;
210begin
211 Result := nil;
212end;
213
214function TStringsModuleCreator.GetShowForm: Boolean;
215begin
216 Result := False;
217end;
218
219function TStringsModuleCreator.GetShowSource: Boolean;
220begin
221 Result := True;
222end;
223
224function TStringsModuleCreator.GetUnnamed: Boolean;
225begin
226 Result := False;
227end;
228
229function TStringsModuleCreator.NewFormFile(const FormIdent,
230 AncestorIdent: AnsiString): IOTAFile;
231begin
232 Result := nil;
233end;
234
235function TStringsModuleCreator.NewImplSource(const ModuleIdent, FormIdent,
236 AncestorIdent: AnsiString): IOTAFile;
237begin
238 Result := TOTAFile.Create(FStream.DataString, FAge);
239end;
240
241function TStringsModuleCreator.NewIntfSource(const ModuleIdent, FormIdent,
242 AncestorIdent: AnsiString): IOTAFile;
243begin
244 Result := nil;
245end;
246{$ENDIF}
247
248{ TTntStrEditDlg }
249
250procedure TTntStrEditDlg.FormCreate(Sender: TObject);
251begin
252 HelpContext := hcDStringListEditor;
253 OpenDialog.HelpContext := hcDStringListLoad;
254 SaveDialog.HelpContext := hcDStringListSave;
255 SingleLine := srLine;
256 MultipleLines := srLines;
257 UnicodeEnabledLbl.Visible := IsWindowUnicode(Memo.Handle);
258end;
259
260procedure TTntStrEditDlg.PrepareForWideStringEdit;
261begin
262 Caption := 'WideString Editor';
263 CodeWndBtn.Visible := False;
264 CodeEditorItem.Visible := False;
265end;
266
267procedure TTntStrEditDlg.FileOpenClick(Sender: TObject);
268begin
269 with OpenDialog do
270 if Execute then Lines.LoadFromFile(FileName);
271end;
272
273procedure TTntStrEditDlg.FileSaveClick(Sender: TObject);
274begin
275 SaveDialog.FileName := OpenDialog.FileName;
276 with SaveDialog do
277 if Execute then Lines.SaveToFile(FileName);
278end;
279
280procedure TTntStrEditDlg.HelpButtonClick(Sender: TObject);
281begin
282 Application.HelpContext(HelpContext);
283end;
284
285procedure TTntStrEditDlg.CodeWndBtnClick(Sender: TObject);
286begin
287 ModalResult := mrYes;
288end;
289
290function TTntStrEditDlg.GetLinesControl: TWinControl;
291begin
292 Result := Memo;
293end;
294
295procedure TTntStrEditDlg.Memo1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
296begin
297 if Key = VK_ESCAPE then CancelButton.Click;
298end;
299
300procedure TTntStrEditDlg.UpdateStatus(Sender: TObject);
301var
302 Count: Integer;
303 LineText: WideString;
304begin
305 if Sender = Memo then FModified := True;
306 Count := Lines.Count;
307 if Count = 1 then LineText := SingleLine
308 else LineText := MultipleLines;
309 LineCount.Caption := WideFormat('%d %s', [Count, LineText]);
310end;
311
312function TTntStrEditDlg.GetLines: TTntStrings;
313begin
314 Result := Memo.Lines;
315end;
316
317procedure TTntStrEditDlg.SetLines(const Value: TTntStrings);
318begin
319 Memo.Lines.Assign(Value);
320end;
321
322{ TWideStringListProperty }
323
324function TWideStringListProperty.EditDialog: TTntStrEditDlg;
325begin
326 Result := TTntStrEditDlg.Create(Application);
327end;
328
329function TWideStringListProperty.GetAttributes: TPropertyAttributes;
330begin
331 Result := inherited GetAttributes + [paDialog] - [paSubProperties];
332end;
333
334function TWideStringListProperty.GetStrings: TTntStrings;
335begin
336 Result := TTntStrings(GetOrdValue);
337end;
338
339procedure TWideStringListProperty.SetStrings(const Value: TTntStrings);
340begin
341 SetOrdValue(Longint(Value));
342end;
343
344procedure TWideStringListProperty.Edit;
345{$IFDEF COMPILER_10_UP}
346const
347 DotSep = '.'; // Temp fix for opening the strings in the editor.
348var
349 Ident: AnsiString;
350 Component: TComponent;
351 Module: IOTAModule;
352 Editor: IOTAEditor;
353 ModuleServices: IOTAModuleServices;
354 Stream: TStringStream{TNT-ALLOW TStringStream};
355 Age: TDateTime;
356{$ENDIF}
357begin
358 {$IFDEF COMPILER_10_UP}
359 Component := TComponent(GetComponent(0));
360 ModuleServices := BorlandIDEServices as IOTAModuleServices;
361 if (TObject(Component) is TComponent)
362 and (Component.Owner = Self.Designer.GetRoot)
363 and (Self.Designer.GetRoot.Name <> '')
364 then begin
365 Ident := Self.Designer.GetRoot.Name + DotSep +
366 Component.Name + DotSep + GetName;
367 Ident := Self.Designer.GetDesignerExtension + DotSep + Ident;
368 Module := ModuleServices.FindModule(Ident);
369 end else begin
370 Ident := '';
371 Module := nil;
372 end;
373 if (Module <> nil) and (Module.GetModuleFileCount > 0) then
374 Module.GetModuleFileEditor(0).Show
375 else
376 {$ENDIF}
377 with EditDialog do
378 try
379 if GetObjectInspectorForm <> nil then
380 Font.Assign(GetObjectInspectorForm.Font);
381 Lines := GetStrings;
382 UpdateStatus(nil);
383 FModified := False;
384 ActiveControl := GetLinesControl;
385 {$IFDEF COMPILER_10_UP}
386 CodeEditorItem.Enabled := Ident <> '';
387 CodeWndBtn.Enabled := Ident <> '';
388 {$ENDIF}
389 case ShowModal of
390 mrOk: SetStrings(Lines);
391 {$IFDEF COMPILER_10_UP}
392 mrYes:
393 begin
394 // this used to be done in LibMain's TLibrary.Create but now its done here
395 // the unregister is done over in ComponentDesigner's finalization
396 //StFilSys.Register;
397 Stream := TStringStream{TNT-ALLOW TStringStream}.Create(WideStringToUTF8(Lines.Text));
398 Stream.Position := 0;
399 Age := Now;
400 Module := ModuleServices.CreateModule(
401 TStringsModuleCreator.Create(Ident, Stream, Age));
402 if Module <> nil then
403 begin
404 with StringsFileSystem.GetTStringsProperty(Ident, Component, GetName) do
405 DiskAge := DateTimeToFileDate(Age);
406 Editor := Module.GetModuleFileEditor(0);
407 if FModified then
408 Editor.MarkModified;
409 Editor.Show;
410 end;
411 end;
412 {$ENDIF}
413 end;
414 finally
415 Free;
416 end;
417end;
418
419end.
Note: See TracBrowser for help on using the repository browser.