source: trunk/Forms/FormSource.pas

Last change on this file was 162, checked in by chronos, 11 months ago
  • Modified: Updated Common package.
File size: 3.7 KB
Line 
1unit FormSource;
2
3interface
4
5uses
6 Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ActnList, Menus,
7 StdCtrls, SynEdit, SynHighlighterAny, VCardHighlighter, Common, FormEx;
8
9type
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
44implementation
45
46{$R *.lfm}
47
48uses
49 Core, Theme, VCard;
50
51{ TFormSource }
52
53procedure TFormSource.ASelectAllExecute(Sender: TObject);
54begin
55 SynEditSource.SelectAll;
56end;
57
58procedure TFormSource.APasteExecute(Sender: TObject);
59begin
60 SynEditSource.PasteFromClipboard;
61end;
62
63procedure TFormSource.ACopyExecute(Sender: TObject);
64begin
65 SynEditSource.CopyToClipboard;
66end;
67
68procedure TFormSource.ACutExecute(Sender: TObject);
69begin
70 SynEditSource.CutToClipboard;
71end;
72
73procedure TFormSource.FormCreate(Sender: TObject);
74var
75 ContactFields: TContactFields;
76 I: Integer;
77begin
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;
85end;
86
87procedure TFormSource.FormDestroy(Sender: TObject);
88begin
89 SynEditSource.Highlighter := nil;
90 FreeAndNil(VCardHighlighter);
91end;
92
93procedure TFormSource.FormShow(Sender: TObject);
94begin
95 UpdateTheme;
96end;
97
98function TFormSource.GetSource: string;
99begin
100 Result := SynEditSource.Lines.Text;
101end;
102
103procedure TFormSource.SetSource(AValue: string);
104begin
105 SynEditSource.Lines.Text := AValue;
106end;
107
108procedure TFormSource.UpdateTheme;
109var
110 C: TColor;
111begin
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;
139end;
140
141end.
142
Note: See TracBrowser for help on using the repository browser.