Rev 10 | Rev 14 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 10 | Rev 13 | ||
---|---|---|---|
Line 8... | Line 8... | ||
8 | - SynEdit |
8 | - SynEdit |
9 | You can obtain SynEdit via Embarcadero GetIt |
9 | You can obtain SynEdit via Embarcadero GetIt |
10 | *) |
10 | *) |
11 | 11 | ||
12 | // TODO: localize |
12 | // TODO: localize |
13 | - | ||
14 | // TODO: wieso geht copy paste im twebbrowser nicht??? |
13 | // TODO: wieso geht copy paste im twebbrowser nicht??? |
15 | // Wieso dauert webbrowser1 erste kompilierung so lange??? |
14 | // Wieso dauert webbrowser1 erste kompilierung so lange??? |
16 | // TODO: wieso kommt syntax fehler zweimal? einmal stderr einmal stdout? |
15 | // TODO: wieso kommt syntax fehler zweimal? einmal stderr einmal stdout? |
17 | // TODO: Browser titlebar (link preview) |
16 | // TODO: Browser titlebar (link preview) |
18 | 17 | ||
19 | // TODO: strg+f / h |
- | |
20 | // TODO: font bigger |
- | |
21 | // TODO: code in bildschirmmitte? |
- | |
22 | // TODO: regelmäßig scrap zwischenspeichern, oder bei strg+s |
- | |
23 | - | ||
24 | // Future ideas |
18 | // Future ideas |
25 | // - ToDo list |
19 | // - ToDo list |
26 | // - Open/Save real files |
- | |
27 | // - multiple scraps? |
- | |
28 | // - verschiedene php versionen? |
20 | // - verschiedene php versionen? |
29 | // - webbrowser1 nur laden, wenn man den tab anwählt? |
21 | // - webbrowser1 nur laden, wenn man den tab anwählt? |
30 | // - doppelklick auf tab soll diesen schließen |
22 | // - doppelklick auf tab soll diesen schließen |
31 | // - Onlinehelp (www) aufrufen |
23 | // - Onlinehelp (www) aufrufen |
- | 24 | // - Let all colors be adjustable |
|
- | 25 | // - code in bildschirmmitte? |
|
32 | 26 | ||
33 | interface |
27 | interface |
34 | 28 | ||
35 | uses |
29 | uses |
36 | Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, |
30 | Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, |
37 | Dialogs, StdCtrls, OleCtrls, ComCtrls, ExtCtrls, ToolWin, IniFiles, |
31 | Dialogs, StdCtrls, OleCtrls, ComCtrls, ExtCtrls, ToolWin, IniFiles, |
38 | SynEditHighlighter, SynHighlighterPHP, SynEdit, SHDocVw_TLB; |
32 | SynEditHighlighter, SynHighlighterPHP, SynEdit, SHDocVw_TLB, FindReplace, |
- | 33 | System.Actions, Vcl.ActnList; |
|
39 | 34 | ||
40 | type |
35 | type |
41 | TForm1 = class(TForm) |
36 | TForm1 = class(TForm) |
42 | PageControl1: TPageControl; |
37 | PageControl1: TPageControl; |
43 | PlaintextTabSheet: TTabSheet; |
38 | PlaintextTabSheet: TTabSheet; |
Line 57... | Line 52... | ||
57 | Panel2: TPanel; |
52 | Panel2: TPanel; |
58 | SynEditFocusTimer: TTimer; |
53 | SynEditFocusTimer: TTimer; |
59 | Button1: TButton; |
54 | Button1: TButton; |
60 | Button2: TButton; |
55 | Button2: TButton; |
61 | Button3: TButton; |
56 | Button3: TButton; |
- | 57 | Button4: TButton; |
|
- | 58 | Button5: TButton; |
|
- | 59 | Button6: TButton; |
|
- | 60 | ActionList: TActionList; |
|
- | 61 | ActionFind: TAction; |
|
- | 62 | ActionReplace: TAction; |
|
- | 63 | ActionFindNext: TAction; |
|
- | 64 | ActionGoto: TAction; |
|
- | 65 | ActionSave: TAction; |
|
- | 66 | ActionHelp: TAction; |
|
- | 67 | ActionRun: TAction; |
|
- | 68 | ActionESC: TAction; |
|
- | 69 | Button7: TButton; |
|
62 | procedure Run(Sender: TObject); |
70 | procedure Run(Sender: TObject); |
63 | procedure FormShow(Sender: TObject); |
71 | procedure FormShow(Sender: TObject); |
64 | procedure FormCreate(Sender: TObject); |
72 | procedure FormCreate(Sender: TObject); |
65 | procedure FormDestroy(Sender: TObject); |
73 | procedure FormDestroy(Sender: TObject); |
66 | procedure FormClose(Sender: TObject; var Action: TCloseAction); |
74 | procedure FormClose(Sender: TObject; var Action: TCloseAction); |
Line 68... | Line 76... | ||
68 | procedure Memo2DblClick(Sender: TObject); |
76 | procedure Memo2DblClick(Sender: TObject); |
69 | procedure WebBrowser1BeforeNavigate2(ASender: TObject; |
77 | procedure WebBrowser1BeforeNavigate2(ASender: TObject; |
70 | const pDisp: IDispatch; const URL, Flags, TargetFrameName, PostData, |
78 | const pDisp: IDispatch; const URL, Flags, TargetFrameName, PostData, |
71 | Headers: OleVariant; var Cancel: WordBool); |
79 | Headers: OleVariant; var Cancel: WordBool); |
72 | procedure SynEditFocusTimerTimer(Sender: TObject); |
80 | procedure SynEditFocusTimerTimer(Sender: TObject); |
- | 81 | procedure ActionFindExecute(Sender: TObject); |
|
- | 82 | procedure ActionReplaceExecute(Sender: TObject); |
|
- | 83 | procedure ActionFindNextExecute(Sender: TObject); |
|
- | 84 | procedure ActionGotoExecute(Sender: TObject); |
|
- | 85 | procedure ActionSaveExecute(Sender: TObject); |
|
73 | procedure Button1Click(Sender: TObject); |
86 | procedure ActionHelpExecute(Sender: TObject); |
74 | procedure Button2Click(Sender: TObject); |
87 | procedure ActionRunExecute(Sender: TObject); |
75 | procedure Button3Click(Sender: TObject); |
88 | procedure ActionESCExecute(Sender: TObject); |
- | 89 | procedure SynEdit1MouseWheelDown(Sender: TObject; Shift: TShiftState; |
|
- | 90 | MousePos: TPoint; var Handled: Boolean); |
|
- | 91 | procedure SynEdit1MouseWheelUp(Sender: TObject; Shift: TShiftState; |
|
- | 92 | MousePos: TPoint; var Handled: Boolean); |
|
76 | private |
93 | private |
77 | CurSearchTerm: string; |
94 | CurSearchTerm: string; |
78 | HlpPrevPageIndex: integer; |
95 | HlpPrevPageIndex: integer; |
- | 96 | SrcRep: TFindReplace; |
|
79 | procedure Help; |
97 | procedure Help; |
80 | procedure ApplicationOnMessage(var Msg: tagMSG; var Handled: Boolean); |
- | |
81 | function MarkUpLineReference(cont: string): string; |
98 | function MarkUpLineReference(cont: string): string; |
82 | protected |
99 | protected |
83 | ChmIndex: TMemIniFile; |
100 | ChmIndex: TMemIniFile; |
84 | procedure GotoLineNo(LineNo:integer); |
101 | procedure GotoLineNo(LineNo:integer); |
85 | function GetScrapFile: string; |
102 | function GetScrapFile: string; |
Line 91... | Line 108... | ||
91 | implementation |
108 | implementation |
92 | 109 | ||
93 | {$R *.dfm} |
110 | {$R *.dfm} |
94 | 111 | ||
95 | uses |
112 | uses |
96 | Functions, StrUtils, WebBrowserUtils, FastPHPUtils; |
113 | Functions, StrUtils, WebBrowserUtils, FastPHPUtils, Math; |
- | 114 | ||
- | 115 | // TODO: FindPrev ? |
|
- | 116 | procedure TForm1.ActionFindNextExecute(Sender: TObject); |
|
- | 117 | begin |
|
- | 118 | SrcRep.FindNext; |
|
- | 119 | end; |
|
97 | 120 | ||
98 | procedure TForm1.ApplicationOnMessage(var Msg: tagMSG; var Handled: Boolean); |
121 | procedure TForm1.ActionGotoExecute(Sender: TObject); |
99 | var |
122 | var |
100 | val: string; |
123 | val: string; |
101 | lineno: integer; |
124 | lineno: integer; |
102 | begin |
125 | begin |
103 | case Msg.message of |
- | |
104 | WM_KEYUP: |
- | |
105 | begin |
- | |
106 | case Msg.wParam of |
- | |
107 | {$REGION 'Esc'} |
- | |
108 | VK_ESCAPE: |
- | |
109 | begin |
- | |
110 | Handled := true; |
126 | // TODO: VK_LMENU does not work! only works with AltGr but not Alt |
111 | // It is necessary to use Application.OnMessage, because Form1.KeyPreview does not work when TWebBrowser has the focus |
127 | // http://stackoverflow.com/questions/16828250/delphi-xe2-how-to-prevent-the-alt-key-stealing-focus ? |
- | 128 | ||
112 | if (HlpPrevPageIndex <> -1) and (PageControl2.ActivePage = HelpTabSheet) and |
129 | InputQuery('Go to', 'Line number:', val); |
113 | (HelpTabsheet.TabVisible) then |
130 | if not TryStrToInt(val, lineno) then |
114 | begin |
131 | begin |
115 | PageControl2.ActivePageIndex := HlpPrevPageIndex; |
132 | if SynEdit1.CanFocus then SynEdit1.SetFocus; |
116 | HelpTabsheet.TabVisible := false; |
133 | exit; |
117 | end; |
134 | end; |
- | 135 | GotoLineNo(lineno); |
|
118 | end; |
136 | end; |
119 | {$ENDREGION} |
- | |
120 | 137 | ||
121 | {$REGION 'Ctrl+G (Go to line)'} |
- | |
122 | ord('G'): |
- | |
123 | begin |
- | |
124 | // TODO: VK_LMENU does not work! only works with AltGr but not Alt |
- | |
125 | // http://stackoverflow.com/questions/16828250/delphi-xe2-how-to-prevent-the-alt-key-stealing-focus ? |
- | |
126 | if (GetKeyState(VK_CONTROL) < 0) then |
138 | procedure TForm1.ActionHelpExecute(Sender: TObject); |
127 | begin |
139 | begin |
128 | Handled := true; |
140 | Help; |
129 | InputQuery('Go to', 'Line number:', val); |
141 | if PageControl2.ActivePage = HelpTabsheet then |
- | 142 | WebBrowser2.SetFocus |
|
130 | if not TryStrToInt(val, lineno) then exit; |
143 | else if PageControl2.ActivePage = TabSheet3{Scrap} then |
131 | GotoLineNo(lineno); |
144 | SynEdit1.SetFocus; |
132 | end; |
145 | end; |
- | 146 | ||
- | 147 | procedure TForm1.ActionReplaceExecute(Sender: TObject); |
|
- | 148 | begin |
|
- | 149 | SrcRep.ReplaceExecute; |
|
133 | end; |
150 | end; |
134 | {$ENDREGION} |
- | |
135 | 151 | ||
136 | {$REGION 'Ctrl+S (Save)'} |
152 | procedure TForm1.ActionRunExecute(Sender: TObject); |
137 | ord('S'): |
- | |
138 | begin |
153 | begin |
- | 154 | Run(Sender); |
|
- | 155 | SynEdit1.SetFocus; |
|
- | 156 | end; |
|
- | 157 | ||
139 | if (GetKeyState(VK_CONTROL) < 0) and (SynEdit1.Focused) then |
158 | procedure TForm1.ActionSaveExecute(Sender: TObject); |
140 | begin |
159 | begin |
141 | Handled := true; |
- | |
142 | SynEdit1.Lines.SaveToFile(GetScrapFile); |
160 | SynEdit1.Lines.SaveToFile(GetScrapFile); |
143 | end; |
161 | end; |
144 | end; |
- | |
145 | {$ENDREGION} |
- | |
146 | 162 | ||
147 | {$REGION 'F1 (Help)'} |
163 | procedure TForm1.ActionESCExecute(Sender: TObject); |
148 | VK_F1: |
- | |
149 | begin |
164 | begin |
- | 165 | if (HlpPrevPageIndex <> -1) and (PageControl2.ActivePage = HelpTabSheet) and |
|
150 | if SynEdit1.Focused then |
166 | (HelpTabsheet.TabVisible) then |
151 | begin |
167 | begin |
152 | Handled := true; |
168 | PageControl2.ActivePageIndex := HlpPrevPageIndex; |
153 | Help; |
169 | HelpTabsheet.TabVisible := false; |
154 | end; |
- | |
155 | end; |
170 | end; |
156 | {$ENDREGION} |
- | |
157 | 171 | ||
158 | {$REGION 'F5 (Run)'} |
- | |
159 | VK_F5: |
172 | // Dirty hack... |
160 | begin |
173 | SrcRep._FindDialog.CloseDialog; |
161 | Run(Self); |
174 | SrcRep._ReplaceDialog.CloseDialog; |
162 | end; |
175 | end; |
163 | {$ENDREGION} |
- | |
164 | 176 | ||
165 | {$REGION 'F9 (Run)'} |
177 | procedure TForm1.ActionFindExecute(Sender: TObject); |
166 | VK_F9: |
- | |
167 | begin |
178 | begin |
168 | Run(Self); |
179 | SrcRep.FindExecute; |
169 | end; |
- | |
170 | {$ENDREGION} |
- | |
171 | end; |
- | |
172 | end; |
- | |
173 | end; |
- | |
174 | end; |
180 | end; |
175 | 181 | ||
176 | procedure TForm1.Run(Sender: TObject); |
182 | procedure TForm1.Run(Sender: TObject); |
177 | begin |
183 | begin |
178 | memo2.Lines.Text := ''; |
184 | memo2.Lines.Text := ''; |
Line 194... | Line 200... | ||
194 | finally |
200 | finally |
195 | Screen.Cursor := crDefault; |
201 | Screen.Cursor := crDefault; |
196 | end; |
202 | end; |
197 | end; |
203 | end; |
198 | 204 | ||
- | 205 | procedure TForm1.SynEdit1MouseWheelDown(Sender: TObject; Shift: TShiftState; |
|
- | 206 | MousePos: TPoint; var Handled: Boolean); |
|
- | 207 | begin |
|
- | 208 | if ssCtrl in Shift then |
|
- | 209 | begin |
|
- | 210 | SynEdit1.Font.Size := Max(SynEdit1.Font.Size - 1, 5); |
|
- | 211 | end; |
|
- | 212 | end; |
|
- | 213 | ||
- | 214 | procedure TForm1.SynEdit1MouseWheelUp(Sender: TObject; Shift: TShiftState; |
|
- | 215 | MousePos: TPoint; var Handled: Boolean); |
|
- | 216 | begin |
|
- | 217 | if ssCtrl in Shift then |
|
- | 218 | begin |
|
- | 219 | SynEdit1.Font.Size := SynEdit1.Font.Size + 1; |
|
- | 220 | end; |
|
- | 221 | end; |
|
- | 222 | ||
199 | procedure TForm1.SynEditFocusTimerTimer(Sender: TObject); |
223 | procedure TForm1.SynEditFocusTimerTimer(Sender: TObject); |
200 | begin |
224 | begin |
201 | SynEditFocusTimer.Enabled := false; |
225 | SynEditFocusTimer.Enabled := false; |
202 | Button1.SetFocus; // Workaround for weird bug... This (and the timer) is necessary to get the focus to SynEdit1 |
226 | Button1.SetFocus; // Workaround for weird bug... This (and the timer) is necessary to get the focus to SynEdit1 |
203 | SynEdit1.SetFocus; |
227 | SynEdit1.SetFocus; |
Line 244... | Line 268... | ||
244 | end; |
268 | end; |
245 | end; |
269 | end; |
246 | {$ENDREGION} |
270 | {$ENDREGION} |
247 | end; |
271 | end; |
248 | 272 | ||
249 | procedure TForm1.Button1Click(Sender: TObject); |
- | |
250 | begin |
- | |
251 | Run(Sender); |
- | |
252 | SynEdit1.SetFocus; |
- | |
253 | end; |
- | |
254 | - | ||
255 | procedure TForm1.Button2Click(Sender: TObject); |
- | |
256 | begin |
- | |
257 | Help; |
- | |
258 | if PageControl2.ActivePage = HelpTabsheet then |
- | |
259 | WebBrowser2.SetFocus |
- | |
260 | else if PageControl2.ActivePage = TabSheet3{Scrap} then |
- | |
261 | SynEdit1.SetFocus; |
- | |
262 | end; |
- | |
263 | - | ||
264 | procedure TForm1.Button3Click(Sender: TObject); |
- | |
265 | var |
- | |
266 | val: string; |
- | |
267 | lineno: integer; |
- | |
268 | begin |
- | |
269 | InputQuery('Go to', 'Line number:', val); |
- | |
270 | if not TryStrToInt(val, lineno) then |
- | |
271 | begin |
- | |
272 | if SynEdit1.CanFocus then SynEdit1.SetFocus; |
- | |
273 | exit; |
- | |
274 | end; |
- | |
275 | GotoLineNo(lineno); |
- | |
276 | end; |
- | |
277 | - | ||
278 | procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); |
273 | procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); |
279 | begin |
274 | begin |
280 | SynEdit1.Lines.SaveToFile(GetScrapFile); |
275 | SynEdit1.Lines.SaveToFile(GetScrapFile); |
- | 276 | FastPHPConfig.WriteInteger('User', 'FontSize', SynEdit1.Font.Size); |
|
281 | end; |
277 | end; |
282 | 278 | ||
283 | procedure TForm1.FormCreate(Sender: TObject); |
279 | procedure TForm1.FormCreate(Sender: TObject); |
284 | begin |
280 | begin |
285 | HlpPrevPageIndex := -1; |
281 | HlpPrevPageIndex := -1; |
286 | CurSearchTerm := ''; |
282 | CurSearchTerm := ''; |
287 | Application.OnMessage := ApplicationOnMessage; |
283 | Caption := Caption + ' - ' + GetScrapFile; |
- | 284 | SrcRep := TFindReplace.Create(self); |
|
- | 285 | SrcRep.Editor := SynEdit1; |
|
288 | end; |
286 | end; |
289 | 287 | ||
290 | procedure TForm1.FormDestroy(Sender: TObject); |
288 | procedure TForm1.FormDestroy(Sender: TObject); |
291 | begin |
289 | begin |
292 | if Assigned(ChmIndex) then |
290 | if Assigned(ChmIndex) then |
293 | begin |
291 | begin |
294 | FreeAndNil(ChmIndex); |
292 | FreeAndNil(ChmIndex); |
295 | end; |
293 | end; |
- | 294 | FreeAndNil(SrcRep); |
|
296 | end; |
295 | end; |
297 | 296 | ||
298 | procedure TForm1.FormShow(Sender: TObject); |
297 | procedure TForm1.FormShow(Sender: TObject); |
299 | var |
298 | var |
300 | ScrapFile: string; |
299 | ScrapFile: string; |
Line 310... | Line 309... | ||
310 | PageControl1.ActivePage := PlaintextTabSheet; |
309 | PageControl1.ActivePage := PlaintextTabSheet; |
311 | 310 | ||
312 | PageControl2.ActivePageIndex := 0; // Scraps |
311 | PageControl2.ActivePageIndex := 0; // Scraps |
313 | HelpTabsheet.TabVisible := false; |
312 | HelpTabsheet.TabVisible := false; |
314 | 313 | ||
- | 314 | SynEdit1.Font.Size := FastPHPConfig.ReadInteger('User', 'FontSize', SynEdit1.Font.Size); |
|
315 | SynEdit1.SetFocus; |
315 | SynEdit1.SetFocus; |
316 | end; |
316 | end; |
317 | 317 | ||
318 | function TForm1.GetScrapFile: string; |
318 | function TForm1.GetScrapFile: string; |
319 | begin |
319 | begin |
- | 320 | if FileExists(ParamStr(1)) then |
|
- | 321 | result := ParamStr(1) |
|
- | 322 | else |
|
320 | result := FastPHPConfig.ReadString('Paths', 'ScrapFile', ''); |
323 | result := FastPHPConfig.ReadString('Paths', 'ScrapFile', ''); |
321 | if not FileExists(result) then |
324 | if not FileExists(result) then |
322 | begin |
325 | begin |
323 | if not OpenDialog3.Execute then |
326 | if not OpenDialog3.Execute then |
324 | begin |
327 | begin |