source: tags/1.4.0/Forms/UFormSource.pas

Last change on this file was 129, checked in by chronos, 2 years ago
  • Added: TVCard as TComponent descendant.
  • Modified: TContactsFile renamed to TVCardFile and moved into separate file.
File size: 4.0 KB
Line 
1unit UFormSource;
2
3interface
4
5uses
6 Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ActnList, Menus,
7 StdCtrls, SynEdit, SynHighlighterAny, UVCardHighlighter, UCommon;
8
9type
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
44var
45 FormSource: TFormSource;
46
47
48implementation
49
50{$R *.lfm}
51
52uses
53 UCore, UTheme, UVCard;
54
55{ TFormSource }
56
57procedure TFormSource.FormClose(Sender: TObject; var CloseAction: TCloseAction);
58begin
59 Core.PersistentForm1.Save(Self);
60end;
61
62procedure TFormSource.ASelectAllExecute(Sender: TObject);
63begin
64 SynEditSource.SelectAll;
65end;
66
67procedure TFormSource.APasteExecute(Sender: TObject);
68begin
69 SynEditSource.PasteFromClipboard;
70end;
71
72procedure TFormSource.ACopyExecute(Sender: TObject);
73begin
74 SynEditSource.CopyToClipboard;
75end;
76
77procedure TFormSource.ACutExecute(Sender: TObject);
78begin
79 SynEditSource.CutToClipboard;
80end;
81
82procedure TFormSource.FormCreate(Sender: TObject);
83var
84 ContactFields: TContactFields;
85 I: Integer;
86begin
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;
96end;
97
98procedure TFormSource.FormDestroy(Sender: TObject);
99begin
100 SynEditSource.Highlighter := nil;
101 FreeAndNil(VCardHighlighter);
102end;
103
104procedure TFormSource.FormShow(Sender: TObject);
105begin
106 Core.PersistentForm1.Load(Self);
107 UpdateTheme;
108end;
109
110function TFormSource.GetSource: string;
111begin
112 Result := SynEditSource.Lines.Text;
113end;
114
115procedure TFormSource.SetSource(AValue: string);
116begin
117 SynEditSource.Lines.Text := AValue;
118end;
119
120procedure TFormSource.UpdateTheme;
121var
122 C: TColor;
123begin
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;
151end;
152
153end.
154
Note: See TracBrowser for help on using the repository browser.