Rev 60 | Rev 63 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 60 | Rev 62 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | unit EditorMain; |
1 | unit EditorMain; |
2 | 2 | ||
3 | {$Include 'FastPHP.inc'} |
3 | {$Include 'FastPHP.inc'} |
4 | 4 | ||
- | 5 | // TODO 70423 * <fastphp> bug beheben, bei dem php.exe im hintergrund geöffnet bleibt, wenn man den editor schließt !!!!!!!!! |
|
- | 6 | ||
5 | (* |
7 | (* |
6 | This program requires |
8 | This program requires |
7 | - Microsoft Internet Controls (TWebBrowser) |
9 | - Microsoft Internet Controls (TWebBrowser) |
8 | If you are using Delphi 10.1 Starter Edition, please import the ActiveX TLB |
10 | If you are using Delphi 10.1 Starter Edition, please import the ActiveX TLB |
9 | "Microsoft Internet Controls" |
11 | "Microsoft Internet Controls" |
Line 34... | Line 36... | ||
34 | // TODO: "{$IFDEF USE_SHDOCVW_TLB}_TLB{$ENDIF}" does not work with Delphi 10.2 |
36 | // TODO: "{$IFDEF USE_SHDOCVW_TLB}_TLB{$ENDIF}" does not work with Delphi 10.2 |
35 | Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, |
37 | Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, |
36 | Dialogs, StdCtrls, OleCtrls, ComCtrls, ExtCtrls, ToolWin, IniFiles, |
38 | Dialogs, StdCtrls, OleCtrls, ComCtrls, ExtCtrls, ToolWin, IniFiles, |
37 | SynEditHighlighter, SynHighlighterPHP, SynEdit, ShDocVw_TLB, FindReplace, |
39 | SynEditHighlighter, SynHighlighterPHP, SynEdit, ShDocVw_TLB, FindReplace, |
38 | ActnList, SynEditMiscClasses, SynEditSearch, RunPHP, ImgList, SynUnicode, |
40 | ActnList, SynEditMiscClasses, SynEditSearch, RunPHP, ImgList, SynUnicode, |
39 | System.ImageList, System.Actions, Vcl.Menus, SHDocVw; |
41 | System.ImageList, System.Actions, Vcl.Menus, SHDocVw, Vcl.Themes; |
40 | 42 | ||
41 | {.$DEFINE OnlineHelp} |
43 | {.$DEFINE OnlineHelp} |
42 | 44 | ||
43 | type |
45 | type |
44 | TForm1 = class(TForm) |
46 | TForm1 = class(TForm) |
Line 97... | Line 99... | ||
97 | Save1: TMenuItem; |
99 | Save1: TMenuItem; |
98 | SaveDialog1: TSaveDialog; |
100 | SaveDialog1: TSaveDialog; |
99 | BtnSpecialChars: TImage; |
101 | BtnSpecialChars: TImage; |
100 | BtnSpecialCharsOff: TImage; |
102 | BtnSpecialCharsOff: TImage; |
101 | BtnSpecialCharsOn: TImage; |
103 | BtnSpecialCharsOn: TImage; |
- | 104 | BtnLightOn: TImage; |
|
- | 105 | BtnLightOff: TImage; |
|
- | 106 | BtnLight: TImage; |
|
- | 107 | StartUpTimer: TTimer; |
|
102 | procedure Run(Sender: TObject); |
108 | procedure Run(Sender: TObject); |
103 | procedure RunConsole(Sender: TObject); |
109 | procedure RunConsole(Sender: TObject); |
104 | procedure FormShow(Sender: TObject); |
110 | procedure FormShow(Sender: TObject); |
105 | procedure FormCreate(Sender: TObject); |
111 | procedure FormCreate(Sender: TObject); |
106 | procedure FormDestroy(Sender: TObject); |
112 | procedure FormDestroy(Sender: TObject); |
Line 153... | Line 159... | ||
153 | procedure Saveas1Click(Sender: TObject); |
159 | procedure Saveas1Click(Sender: TObject); |
154 | procedure Save1Click(Sender: TObject); |
160 | procedure Save1Click(Sender: TObject); |
155 | procedure BtnSpecialCharsClick(Sender: TObject); |
161 | procedure BtnSpecialCharsClick(Sender: TObject); |
156 | procedure WebBrowser1WindowClosing(ASender: TObject; |
162 | procedure WebBrowser1WindowClosing(ASender: TObject; |
157 | IsChildWindow: WordBool; var Cancel: WordBool); |
163 | IsChildWindow: WordBool; var Cancel: WordBool); |
- | 164 | procedure BtnLightClick(Sender: TObject); |
|
- | 165 | procedure StartUpTimerTimer(Sender: TObject); |
|
158 | private |
166 | private |
159 | CurSearchTerm: string; |
167 | CurSearchTerm: string; |
160 | HlpPrevPageIndex: integer; |
168 | HlpPrevPageIndex: integer; |
161 | SrcRep: TSynEditFindReplace; |
169 | SrcRep: TSynEditFindReplace; |
162 | {$IFDEF OnlineHelp} |
170 | {$IFDEF OnlineHelp} |
Line 173... | Line 181... | ||
173 | codeExplorer: TRunCodeExplorer; |
181 | codeExplorer: TRunCodeExplorer; |
174 | procedure GotoLineNo(LineNo: integer); |
182 | procedure GotoLineNo(LineNo: integer); |
175 | function GetScrapFile: string; |
183 | function GetScrapFile: string; |
176 | procedure StartCodeExplorer; |
184 | procedure StartCodeExplorer; |
177 | procedure RefreshModifySign; |
185 | procedure RefreshModifySign; |
- | 186 | procedure Theme_Light; |
|
- | 187 | procedure Theme_Dark; |
|
- | 188 | function IsThemeDark: boolean; |
|
178 | end; |
189 | end; |
179 | 190 | ||
180 | var |
191 | var |
181 | Form1: TForm1; |
192 | Form1: TForm1; |
182 | 193 | ||
Line 249... | Line 260... | ||
249 | 260 | ||
250 | procedure TForm1.ActionOpenExecute(Sender: TObject); |
261 | procedure TForm1.ActionOpenExecute(Sender: TObject); |
251 | begin |
262 | begin |
252 | If OpenDialog3.Execute then |
263 | If OpenDialog3.Execute then |
253 | begin |
264 | begin |
254 | ShellExecute(0, 'open', PChar(ParamStr(0)), PChar(OpenDialog3.FileName), '', SW_NORMAL); |
265 | ShellExecute(0, 'open', PChar(ParamStr(0)), PChar('"' + OpenDialog3.FileName + '"'), '', SW_NORMAL); |
255 | end; |
266 | end; |
256 | end; |
267 | end; |
257 | 268 | ||
258 | procedure TForm1.ActionReplaceExecute(Sender: TObject); |
269 | procedure TForm1.ActionReplaceExecute(Sender: TObject); |
259 | begin |
270 | begin |
Line 395... | Line 406... | ||
395 | var |
406 | var |
396 | firstTimeBrowserLoad: boolean = true; |
407 | firstTimeBrowserLoad: boolean = true; |
397 | procedure TForm1.Run(Sender: TObject); |
408 | procedure TForm1.Run(Sender: TObject); |
398 | var |
409 | var |
399 | bakTS: TTabSheet; |
410 | bakTS: TTabSheet; |
- | 411 | ss: TStringStream; |
|
- | 412 | bakPos: Int64; |
|
400 | begin |
413 | begin |
401 | memo2.Lines.Text := ''; |
414 | memo2.Lines.Text := ''; |
402 | 415 | ||
403 | if firstTimeBrowserLoad then |
416 | if firstTimeBrowserLoad then |
404 | begin |
417 | begin |
Line 418... | Line 431... | ||
418 | Application.ProcessMessages; |
431 | Application.ProcessMessages; |
419 | 432 | ||
420 | try |
433 | try |
421 | ActionSave.Execute; // TODO: if it is not the scrap file: do not save the file, since the user did not intended to save... better create a temporary file and run it instead. |
434 | ActionSave.Execute; // TODO: if it is not the scrap file: do not save the file, since the user did not intended to save... better create a temporary file and run it instead. |
422 | 435 | ||
- | 436 | // TODO 70421 * <fastphp> flush() mittels ContentCallBack implementieren... ich möchte bei langen scripts statusanzeigen realisieren können mit javascript das stück für stück geladen wird !!!!!!!! |
|
- | 437 | // TODO 70422 * <fastphp> wenn ein script hängt, soll man es abwürgen dürfen!!!!!! |
|
423 | memo2.Lines.Text := RunPHPScript(GetScrapFile, Sender=ActionLint, False); |
438 | memo2.Lines.Text := RunPHPScript(GetScrapFile, Sender=ActionLint, False); |
424 | 439 | ||
- | 440 | ||
425 | Webbrowser1.LoadHTML(MarkUpLineReference(memo2.Lines.Text), GetScrapFile); |
441 | // Webbrowser1.LoadHTML(MarkUpLineReference(memo2.Lines.Text), GetScrapFile); |
- | 442 | ||
- | 443 | // Alternatively: |
|
- | 444 | (* |
|
- | 445 | ss := TstringStream.Create; |
|
- | 446 | ss.WriteString(MarkUpLineReference(memo2.Lines.Text)); |
|
- | 447 | ss.Position := 0; |
|
- | 448 | Webbrowser1.LoadStream(ss, GetScrapFile); |
|
- | 449 | Webbrowser1.Wait; |
|
- | 450 | ss.Free; |
|
- | 451 | *) |
|
426 | 452 | ||
427 | if IsTextHTML(memo2.lines.text) then |
453 | if IsTextHTML(memo2.lines.text) then |
428 | PageControl1.ActivePage := HtmlTabSheet |
454 | PageControl1.ActivePage := HtmlTabSheet |
429 | else |
455 | else |
430 | PageControl1.ActivePage := PlaintextTabSheet; |
456 | PageControl1.ActivePage := PlaintextTabSheet; |
Line 646... | Line 672... | ||
646 | SynEditFocusTimer.Enabled := false; |
672 | SynEditFocusTimer.Enabled := false; |
647 | Button1.SetFocus; // Workaround for weird bug... This (and the timer) is necessary to get the focus to SynEdit1 |
673 | Button1.SetFocus; // Workaround for weird bug... This (and the timer) is necessary to get the focus to SynEdit1 |
648 | SynEdit1.SetFocus; |
674 | SynEdit1.SetFocus; |
649 | end; |
675 | end; |
650 | 676 | ||
- | 677 | procedure TForm1.Theme_Dark; |
|
- | 678 | begin |
|
- | 679 | if IsThemeDark then exit; |
|
- | 680 | TStyleManager.TrySetStyle('Windows10 SlateGray'); |
|
- | 681 | Color := 1316887; |
|
- | 682 | Font.Color := clCream; |
|
- | 683 | //Memo2.Font.Color := clCream; |
|
- | 684 | //Memo2.ParentColor := true; |
|
- | 685 | SynEdit1.ActiveLineColor := 2238502; |
|
- | 686 | SynEdit1.Color := 1316887; |
|
- | 687 | SynEdit1.Font.Color := clCream; |
|
- | 688 | SynEdit1.Gutter.Color := 1316887; |
|
- | 689 | SynEdit1.Gutter.Font.Color := clCream; |
|
- | 690 | SynEdit1.Gutter.GradientStartColor := 2238502; |
|
- | 691 | SynEdit1.Gutter.GradientEndColor := 1316887; |
|
- | 692 | SynPHPSyn1.CommentAttri.Foreground := 6314591; |
|
- | 693 | SynPHPSyn1.IdentifierAttri.Foreground := 9627120; |
|
- | 694 | SynPHPSyn1.KeyAttri.Foreground := 4157595; |
|
- | 695 | SynPHPSyn1.NumberAttri.Foreground := 5008079; |
|
- | 696 | SynPHPSyn1.StringAttri.Foreground := 6987151; |
|
- | 697 | SynPHPSyn1.SymbolAttri.Foreground := 8769754; |
|
- | 698 | SynPHPSyn1.VariableAttri.Foreground := 6924493; |
|
- | 699 | end; |
|
- | 700 | ||
- | 701 | procedure TForm1.Theme_Light; |
|
- | 702 | begin |
|
- | 703 | if not IsThemeDark then exit; |
|
- | 704 | TStyleManager.TrySetStyle('Windows'); |
|
- | 705 | Color := clBtnFace; |
|
- | 706 | Font.Color := clWindowText; |
|
- | 707 | //Memo2.Font.Color := clWindowText; |
|
- | 708 | SynEdit1.ActiveLineColor := 14680010; |
|
- | 709 | SynEdit1.Color := clWindow; |
|
- | 710 | SynEdit1.Font.Color := clWindowText; |
|
- | 711 | SynEdit1.Gutter.Color := clBtnFace; |
|
- | 712 | SynEdit1.Gutter.Font.Color := clWindowText; |
|
- | 713 | SynEdit1.Gutter.GradientStartcolor := cl3dLight; |
|
- | 714 | SynEdit1.Gutter.GradientEndColor := clBtnFace;; |
|
- | 715 | SynPHPSyn1.CommentAttri.Foreground := 33023; |
|
- | 716 | SynPHPSyn1.IdentifierAttri.Foreground := 4194304; |
|
- | 717 | SynPHPSyn1.KeyAttri.Foreground := 4227072; |
|
- | 718 | SynPHPSyn1.NumberAttri.Foreground := 213; |
|
- | 719 | SynPHPSyn1.StringAttri.Foreground := 13762560; |
|
- | 720 | SynPHPSyn1.SymbolAttri.Foreground := 4227072; |
|
- | 721 | SynPHPSyn1.VariableAttri.Foreground := 213; |
|
- | 722 | end; |
|
- | 723 | ||
651 | procedure TForm1.Timer1Timer(Sender: TObject); |
724 | procedure TForm1.Timer1Timer(Sender: TObject); |
652 | begin |
725 | begin |
653 | {$IFDEF OnlineHelp} |
726 | {$IFDEF OnlineHelp} |
654 | Timer1.Enabled := false; |
727 | Timer1.Enabled := false; |
655 | 728 | ||
Line 718... | Line 791... | ||
718 | end; |
791 | end; |
719 | Exit; |
792 | Exit; |
720 | end; |
793 | end; |
721 | {$ENDREGION} |
794 | {$ENDREGION} |
722 | 795 | ||
723 | {$REGION 'Intelligent browser (executes PHP scripts)'} |
796 | {$REGION 'Intelligent browser (executes PHP scripts which are clicked in a hyperlink)'} |
724 | if URL <> 'about:blank' then |
797 | if URL <> 'about:blank' then |
725 | begin |
798 | begin |
726 | myUrl := URL; |
799 | myUrl := URL; |
727 | 800 | ||
728 | p := Pos('?', myUrl); |
801 | p := Pos('?', myUrl); |
729 | if p >= 1 then myURL := copy(myURL, 1, p-1); |
802 | if p >= 1 then myURL := copy(myURL, 1, p-1); |
730 | 803 | ||
731 | // TODO: myURL urldecode |
804 | // TODO: myURL urldecode |
732 | // TODO: maybe we could even open that file in the editor! |
805 | // TODO: maybe we could even open that file in the editor! |
- | 806 | // TODO: ?parameter=.... |
|
733 | 807 | ||
734 | if FileExists(myURL) and (EndsText('.php', myURL) or EndsText('.php3', myURL) or EndsText('.php4', myURL) or EndsText('.php5', myURL) or EndsText('.phps', myURL)) then |
808 | if FileExists(myURL) and (EndsText('.php', myURL) or EndsText('.php3', myURL) or EndsText('.php4', myURL) or EndsText('.php5', myURL) or EndsText('.phps', myURL)) then |
735 | begin |
809 | begin |
736 | WebBrowser1.LoadHTML(RunPHPScript(myURL), myUrl); |
810 | WebBrowser1.LoadHTML(RunPHPScript(myURL), myUrl); |
737 | Cancel := true; |
811 | Cancel := true; |
738 | end; |
812 | end; |
739 | end; |
813 | end; |
740 | {$ENDREGION} |
814 | {$ENDREGION} |
741 | end; |
815 | end; |
742 | 816 | ||
- | 817 | procedure TForm1.BtnLightClick(Sender: TObject); |
|
- | 818 | begin |
|
- | 819 | if IsThemeDark then |
|
- | 820 | begin |
|
- | 821 | BtnLight.Picture.Assign(BtnLightOn.Picture); |
|
- | 822 | Theme_Light; |
|
- | 823 | TFastPHPConfig.DarkTheme := false; |
|
- | 824 | end |
|
- | 825 | else |
|
- | 826 | begin |
|
- | 827 | BtnLight.Picture.Assign(BtnLightOff.Picture); |
|
- | 828 | Theme_Dark; |
|
- | 829 | TFastPHPConfig.DarkTheme := true; |
|
- | 830 | end; |
|
- | 831 | end; |
|
- | 832 | ||
743 | procedure TForm1.BtnSpecialCharsClick(Sender: TObject); |
833 | procedure TForm1.BtnSpecialCharsClick(Sender: TObject); |
744 | var |
834 | var |
745 | opts: TSynEditorOptions; |
835 | opts: TSynEditorOptions; |
746 | begin |
836 | begin |
747 | opts := SynEdit1.Options; |
837 | opts := SynEdit1.Options; |
Line 867... | Line 957... | ||
867 | if tmpFontSize <> -1 then SynEdit1.Font.Size := tmpFontSize; |
957 | if tmpFontSize <> -1 then SynEdit1.Font.Size := tmpFontSize; |
868 | SynEdit1.SetFocus; |
958 | SynEdit1.SetFocus; |
869 | 959 | ||
870 | DoubleBuffered := true; |
960 | DoubleBuffered := true; |
871 | StartCodeExplorer; |
961 | StartCodeExplorer; |
- | 962 | ||
- | 963 | StartupTimer.Enabled := true; |
|
872 | end; |
964 | end; |
873 | 965 | ||
874 | procedure TForm1.Save1Click(Sender: TObject); |
966 | procedure TForm1.Save1Click(Sender: TObject); |
875 | begin |
967 | begin |
876 | Button7.Click; |
968 | Button7.Click; |
Line 895... | Line 987... | ||
895 | codeExplorer.PhpFile := IncludeTrailingPathDelimiter(ExtractFileDir(Application.ExeName)) + 'codeexplorer.php'; // GetScrapFile; |
987 | codeExplorer.PhpFile := IncludeTrailingPathDelimiter(ExtractFileDir(Application.ExeName)) + 'codeexplorer.php'; // GetScrapFile; |
896 | codeExplorer.WorkDir := ExtractFileDir(Application.ExeName); |
988 | codeExplorer.WorkDir := ExtractFileDir(Application.ExeName); |
897 | codeExplorer.Resume; |
989 | codeExplorer.Resume; |
898 | end; |
990 | end; |
899 | 991 | ||
- | 992 | procedure TForm1.StartUpTimerTimer(Sender: TObject); |
|
- | 993 | begin |
|
- | 994 | StartupTimer.Enabled := false; |
|
- | 995 | ||
- | 996 | // We need this timer because we cannot change the Theme during OnShow, |
|
- | 997 | // because the Delphi VCL Theme is buggy! |
|
- | 998 | ||
- | 999 | if TFastPHPConfig.DarkTheme then |
|
- | 1000 | begin |
|
- | 1001 | BtnLight.Picture.Assign(BtnLightOff.Picture); |
|
- | 1002 | Theme_Dark; |
|
- | 1003 | end |
|
- | 1004 | else |
|
- | 1005 | begin |
|
- | 1006 | BtnLight.Picture.Assign(BtnLightOn.Picture); |
|
- | 1007 | Theme_Light; |
|
- | 1008 | end; |
|
- | 1009 | end; |
|
- | 1010 | ||
900 | function TForm1.GetScrapFile: string; |
1011 | function TForm1.GetScrapFile: string; |
901 | var |
1012 | var |
902 | tmpPath: string; |
1013 | tmpPath: string; |
903 | begin |
1014 | begin |
904 | if FSaveAsFilename <> '' then |
1015 | if FSaveAsFilename <> '' then |
Line 1245... | Line 1356... | ||
1245 | begin |
1356 | begin |
1246 | data := UTF8Encode(SynEdit1.Text); |
1357 | data := UTF8Encode(SynEdit1.Text); |
1247 | result := true; |
1358 | result := true; |
1248 | end; |
1359 | end; |
1249 | 1360 | ||
- | 1361 | function TForm1.IsThemeDark: boolean; |
|
- | 1362 | begin |
|
- | 1363 | result := Assigned(TStyleManager.ActiveStyle) and (TStyleManager.ActiveStyle.Name<>'Windows'); |
|
- | 1364 | end; |
|
- | 1365 | ||
1250 | function TForm1.OutputNotifyCallback(const data: AnsiString): boolean; |
1366 | function TForm1.OutputNotifyCallback(const data: AnsiString): boolean; |
1251 | begin |
1367 | begin |
1252 | result := TreeView1.FillWithFastPHPData(data); |
1368 | result := TreeView1.FillWithFastPHPData(data); |
1253 | end; |
1369 | end; |
1254 | 1370 |