1 | unit UFormSource;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ActnList, Menus,
|
---|
7 | StdCtrls, SynEdit, SynHighlighterAny, UVCardHighlighter, UCommon;
|
---|
8 |
|
---|
9 | type
|
---|
10 |
|
---|
11 | { TFormSource }
|
---|
12 |
|
---|
13 | TFormSource = class(TForm)
|
---|
14 | APaste: TAction;
|
---|
15 | ACopy: TAction;
|
---|
16 | ACut: TAction;
|
---|
17 | ASelectAll: TAction;
|
---|
18 | ActionList1: TActionList;
|
---|
19 | ButtonOk: TButton;
|
---|
20 | ButtonCancel: TButton;
|
---|
21 | MenuItem1: TMenuItem;
|
---|
22 | MenuItem2: TMenuItem;
|
---|
23 | MenuItem3: TMenuItem;
|
---|
24 | MenuItem4: TMenuItem;
|
---|
25 | PopupMenu1: TPopupMenu;
|
---|
26 | SynEditSource: TSynEdit;
|
---|
27 | procedure ACopyExecute(Sender: TObject);
|
---|
28 | procedure ACutExecute(Sender: TObject);
|
---|
29 | procedure APasteExecute(Sender: TObject);
|
---|
30 | procedure ASelectAllExecute(Sender: TObject);
|
---|
31 | procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
|
---|
32 | procedure FormCreate(Sender: TObject);
|
---|
33 | procedure FormDestroy(Sender: TObject);
|
---|
34 | procedure FormShow(Sender: TObject);
|
---|
35 | private
|
---|
36 | VCardHighlighter: TSynVCardHighlighter;
|
---|
37 | function GetSource: string;
|
---|
38 | procedure SetSource(AValue: string);
|
---|
39 | procedure UpdateTheme;
|
---|
40 | public
|
---|
41 | property Source: string read GetSource write SetSource;
|
---|
42 | end;
|
---|
43 |
|
---|
44 | var
|
---|
45 | FormSource: TFormSource;
|
---|
46 |
|
---|
47 |
|
---|
48 | implementation
|
---|
49 |
|
---|
50 | {$R *.lfm}
|
---|
51 |
|
---|
52 | uses
|
---|
53 | UCore, UTheme, UVCard;
|
---|
54 |
|
---|
55 | { TFormSource }
|
---|
56 |
|
---|
57 | procedure TFormSource.FormClose(Sender: TObject; var CloseAction: TCloseAction);
|
---|
58 | begin
|
---|
59 | Core.PersistentForm1.Save(Self);
|
---|
60 | end;
|
---|
61 |
|
---|
62 | procedure TFormSource.ASelectAllExecute(Sender: TObject);
|
---|
63 | begin
|
---|
64 | SynEditSource.SelectAll;
|
---|
65 | end;
|
---|
66 |
|
---|
67 | procedure TFormSource.APasteExecute(Sender: TObject);
|
---|
68 | begin
|
---|
69 | SynEditSource.PasteFromClipboard;
|
---|
70 | end;
|
---|
71 |
|
---|
72 | procedure TFormSource.ACopyExecute(Sender: TObject);
|
---|
73 | begin
|
---|
74 | SynEditSource.CopyToClipboard;
|
---|
75 | end;
|
---|
76 |
|
---|
77 | procedure TFormSource.ACutExecute(Sender: TObject);
|
---|
78 | begin
|
---|
79 | SynEditSource.CutToClipboard;
|
---|
80 | end;
|
---|
81 |
|
---|
82 | procedure TFormSource.FormCreate(Sender: TObject);
|
---|
83 | var
|
---|
84 | ContactFields: TContactFields;
|
---|
85 | I: Integer;
|
---|
86 | begin
|
---|
87 | Core.Translator.TranslateComponentRecursive(Self);
|
---|
88 | Core.ThemeManager1.UseTheme(Self);
|
---|
89 |
|
---|
90 | VCardHighlighter := TSynVCardHighlighter.Create(nil);
|
---|
91 | ContactFields := TContact.GetFields;
|
---|
92 | SetLength(VCardHighlighter.Properties, ContactFields.Count);
|
---|
93 | for I := 0 to ContactFields.Count - 1 do
|
---|
94 | VCardHighlighter.Properties[I] := LowerCase(ContactFields[I].SysName);
|
---|
95 | SynEditSource.Highlighter := VCardHighlighter;
|
---|
96 | end;
|
---|
97 |
|
---|
98 | procedure TFormSource.FormDestroy(Sender: TObject);
|
---|
99 | begin
|
---|
100 | SynEditSource.Highlighter := nil;
|
---|
101 | FreeAndNil(VCardHighlighter);
|
---|
102 | end;
|
---|
103 |
|
---|
104 | procedure TFormSource.FormShow(Sender: TObject);
|
---|
105 | begin
|
---|
106 | Core.PersistentForm1.Load(Self);
|
---|
107 | UpdateTheme;
|
---|
108 | end;
|
---|
109 |
|
---|
110 | function TFormSource.GetSource: string;
|
---|
111 | begin
|
---|
112 | Result := SynEditSource.Lines.Text;
|
---|
113 | end;
|
---|
114 |
|
---|
115 | procedure TFormSource.SetSource(AValue: string);
|
---|
116 | begin
|
---|
117 | SynEditSource.Lines.Text := AValue;
|
---|
118 | end;
|
---|
119 |
|
---|
120 | procedure TFormSource.UpdateTheme;
|
---|
121 | var
|
---|
122 | C: TColor;
|
---|
123 | begin
|
---|
124 | if Core.ThemeManager1.Theme.Name = ThemeNameDark then begin
|
---|
125 | SynEditSource.Color := clBlack;
|
---|
126 | VCardHighlighter.IdentAttri.Foreground := clWhite;
|
---|
127 | VCardHighlighter.KeywordAttri.Foreground := clLightBlue;
|
---|
128 | VCardHighlighter.NumberAttri.Foreground := clLightGreen;
|
---|
129 | VCardHighlighter.PropertyAttri.Foreground := clLightRed;
|
---|
130 | end else
|
---|
131 | if Core.ThemeManager1.Theme.Name = ThemeNameLight then begin
|
---|
132 | SynEditSource.Color := clWhite;
|
---|
133 | VCardHighlighter.IdentAttri.Foreground := clBlack;
|
---|
134 | VCardHighlighter.KeywordAttri.Foreground := clBlue;
|
---|
135 | VCardHighlighter.NumberAttri.Foreground := clGreen;
|
---|
136 | VCardHighlighter.PropertyAttri.Foreground := clRed;
|
---|
137 | end else begin
|
---|
138 | SynEditSource.Color := clWindow;
|
---|
139 | VCardHighlighter.IdentAttri.Foreground := clWindowText;
|
---|
140 | C := ColorToRGB(clWindow);
|
---|
141 | if (((C and $ff) + ((C shr 8) and $ff) + ((C shr 16) and $ff)) div 3) > $7f then begin
|
---|
142 | VCardHighlighter.KeywordAttri.Foreground := clBlue;
|
---|
143 | VCardHighlighter.NumberAttri.Foreground := clGreen;
|
---|
144 | VCardHighlighter.PropertyAttri.Foreground := clRed;
|
---|
145 | end else begin
|
---|
146 | VCardHighlighter.KeywordAttri.Foreground := clLightBlue;
|
---|
147 | VCardHighlighter.NumberAttri.Foreground := clLightGreen;
|
---|
148 | VCardHighlighter.PropertyAttri.Foreground := clLightRed;
|
---|
149 | end;
|
---|
150 | end;
|
---|
151 | end;
|
---|
152 |
|
---|
153 | end.
|
---|
154 |
|
---|