1 | unit FormSource;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ActnList, Menus,
|
---|
7 | StdCtrls, SynEdit, SynHighlighterAny, VCardHighlighter, Common, FormEx;
|
---|
8 |
|
---|
9 | type
|
---|
10 |
|
---|
11 | { TFormSource }
|
---|
12 |
|
---|
13 | TFormSource = class(TFormEx)
|
---|
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 FormCreate(Sender: TObject);
|
---|
32 | procedure FormDestroy(Sender: TObject);
|
---|
33 | procedure FormShow(Sender: TObject);
|
---|
34 | private
|
---|
35 | VCardHighlighter: TSynVCardHighlighter;
|
---|
36 | function GetSource: string;
|
---|
37 | procedure SetSource(AValue: string);
|
---|
38 | procedure UpdateTheme;
|
---|
39 | public
|
---|
40 | property Source: string read GetSource write SetSource;
|
---|
41 | end;
|
---|
42 |
|
---|
43 |
|
---|
44 | implementation
|
---|
45 |
|
---|
46 | {$R *.lfm}
|
---|
47 |
|
---|
48 | uses
|
---|
49 | Core, Theme, VCard;
|
---|
50 |
|
---|
51 | { TFormSource }
|
---|
52 |
|
---|
53 | procedure TFormSource.ASelectAllExecute(Sender: TObject);
|
---|
54 | begin
|
---|
55 | SynEditSource.SelectAll;
|
---|
56 | end;
|
---|
57 |
|
---|
58 | procedure TFormSource.APasteExecute(Sender: TObject);
|
---|
59 | begin
|
---|
60 | SynEditSource.PasteFromClipboard;
|
---|
61 | end;
|
---|
62 |
|
---|
63 | procedure TFormSource.ACopyExecute(Sender: TObject);
|
---|
64 | begin
|
---|
65 | SynEditSource.CopyToClipboard;
|
---|
66 | end;
|
---|
67 |
|
---|
68 | procedure TFormSource.ACutExecute(Sender: TObject);
|
---|
69 | begin
|
---|
70 | SynEditSource.CutToClipboard;
|
---|
71 | end;
|
---|
72 |
|
---|
73 | procedure TFormSource.FormCreate(Sender: TObject);
|
---|
74 | var
|
---|
75 | ContactFields: TContactFields;
|
---|
76 | I: Integer;
|
---|
77 | begin
|
---|
78 | VCardHighlighter := TSynVCardHighlighter.Create(nil);
|
---|
79 | ContactFields := TContact.GetFields;
|
---|
80 | SetLength(VCardHighlighter.Properties, ContactFields.Count);
|
---|
81 | for I := 0 to ContactFields.Count - 1 do
|
---|
82 | VCardHighlighter.Properties[I] := LowerCase(ContactFields[I].SysName);
|
---|
83 | SynEditSource.Highlighter := VCardHighlighter;
|
---|
84 | SynEditSource.Font.Height := Font.Height;
|
---|
85 | end;
|
---|
86 |
|
---|
87 | procedure TFormSource.FormDestroy(Sender: TObject);
|
---|
88 | begin
|
---|
89 | SynEditSource.Highlighter := nil;
|
---|
90 | FreeAndNil(VCardHighlighter);
|
---|
91 | end;
|
---|
92 |
|
---|
93 | procedure TFormSource.FormShow(Sender: TObject);
|
---|
94 | begin
|
---|
95 | UpdateTheme;
|
---|
96 | end;
|
---|
97 |
|
---|
98 | function TFormSource.GetSource: string;
|
---|
99 | begin
|
---|
100 | Result := SynEditSource.Lines.Text;
|
---|
101 | end;
|
---|
102 |
|
---|
103 | procedure TFormSource.SetSource(AValue: string);
|
---|
104 | begin
|
---|
105 | SynEditSource.Lines.Text := AValue;
|
---|
106 | end;
|
---|
107 |
|
---|
108 | procedure TFormSource.UpdateTheme;
|
---|
109 | var
|
---|
110 | C: TColor;
|
---|
111 | begin
|
---|
112 | if Core.Core.ThemeManager1.Theme.Name = ThemeNameDark then begin
|
---|
113 | SynEditSource.Color := clBlack;
|
---|
114 | VCardHighlighter.IdentAttri.Foreground := clWhite;
|
---|
115 | VCardHighlighter.KeywordAttri.Foreground := clLightBlue;
|
---|
116 | VCardHighlighter.NumberAttri.Foreground := clLightGreen;
|
---|
117 | VCardHighlighter.PropertyAttri.Foreground := clLightRed;
|
---|
118 | end else
|
---|
119 | if Core.Core.ThemeManager1.Theme.Name = ThemeNameLight then begin
|
---|
120 | SynEditSource.Color := clWhite;
|
---|
121 | VCardHighlighter.IdentAttri.Foreground := clBlack;
|
---|
122 | VCardHighlighter.KeywordAttri.Foreground := clBlue;
|
---|
123 | VCardHighlighter.NumberAttri.Foreground := clGreen;
|
---|
124 | VCardHighlighter.PropertyAttri.Foreground := clRed;
|
---|
125 | end else begin
|
---|
126 | SynEditSource.Color := clWindow;
|
---|
127 | VCardHighlighter.IdentAttri.Foreground := clWindowText;
|
---|
128 | C := ColorToRGB(clWindow);
|
---|
129 | if (((C and $ff) + ((C shr 8) and $ff) + ((C shr 16) and $ff)) div 3) > $7f then begin
|
---|
130 | VCardHighlighter.KeywordAttri.Foreground := clBlue;
|
---|
131 | VCardHighlighter.NumberAttri.Foreground := clGreen;
|
---|
132 | VCardHighlighter.PropertyAttri.Foreground := clRed;
|
---|
133 | end else begin
|
---|
134 | VCardHighlighter.KeywordAttri.Foreground := clLightBlue;
|
---|
135 | VCardHighlighter.NumberAttri.Foreground := clLightGreen;
|
---|
136 | VCardHighlighter.PropertyAttri.Foreground := clLightRed;
|
---|
137 | end;
|
---|
138 | end;
|
---|
139 | end;
|
---|
140 |
|
---|
141 | end.
|
---|
142 |
|
---|