Rev 47 | Rev 56 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 47 | Rev 49 | ||
---|---|---|---|
Line 11... | Line 11... | ||
11 | You can obtain SynEdit via Embarcadero GetIt |
11 | You can obtain SynEdit via Embarcadero GetIt |
12 | *) |
12 | *) |
13 | 13 | ||
14 | // TODO: localize |
14 | // TODO: localize |
15 | // TODO: wieso geht copy paste im twebbrowser nicht??? |
15 | // TODO: wieso geht copy paste im twebbrowser nicht??? |
16 | // Wieso dauert webbrowser1 erste kompilierung so lange??? |
16 | // TODO: Wieso dauert webbrowser1 erste kompilierung so lange??? |
17 | // TODO: wieso kommt syntax fehler zweimal? einmal stderr einmal stdout? |
17 | // TODO: wieso kommt syntax fehler zweimal? einmal stderr einmal stdout? |
18 | // TODO: Browser titlebar (link preview) |
18 | // TODO: Browser titlebar (link preview) |
19 | // TODO: todo liste |
19 | // TODO: "jump to next/prev todo" buttons/shortcuts |
- | 20 | // TODO: "increase/decrease indent" buttons/shortcuts |
|
20 | 21 | ||
21 | // Future ideas |
22 | // Future ideas |
22 | // - code insight |
23 | // - code insight |
23 | // - verschiedene php versionen? |
24 | // - verschiedene php versionen? |
24 | // - webbrowser1 nur laden, wenn man den tab anwählt? |
25 | // - webbrowser1 nur laden, wenn man den tab anwählt? |
Line 172... | Line 173... | ||
172 | 173 | ||
173 | {$R Cursors.res} |
174 | {$R Cursors.res} |
174 | 175 | ||
175 | uses |
176 | uses |
176 | Functions, StrUtils, WebBrowserUtils, FastPHPUtils, Math, ShellAPI, RichEdit, |
177 | Functions, StrUtils, WebBrowserUtils, FastPHPUtils, Math, ShellAPI, RichEdit, |
177 | FastPHPTreeView, ImageListEx; |
178 | FastPHPTreeView, ImageListEx, FastPHPConfig; |
178 | 179 | ||
179 | const |
180 | const |
180 | crMouseGutter = 1; |
181 | crMouseGutter = 1; |
181 | 182 | ||
182 | procedure TForm1.RefreshModifySign; |
183 | procedure TForm1.RefreshModifySign; |
Line 341... | Line 342... | ||
341 | begin |
342 | begin |
342 | // TODO: if something is selected, only process the selected part |
343 | // TODO: if something is selected, only process the selected part |
343 | 344 | ||
344 | if not SpacesAvailable(SynEdit1.Lines) then |
345 | if not SpacesAvailable(SynEdit1.Lines) then |
345 | begin |
346 | begin |
346 | ShowMessage(SNoLinesAvailable); |
347 | MessageDlg(SNoLinesAvailable, mtInformation, [mbOk], 0); |
347 | exit; |
348 | exit; |
348 | end; |
349 | end; |
349 | 350 | ||
350 | ind := GuessIndent(SynEdit1.Lines); |
351 | ind := GuessIndent(SynEdit1.Lines); |
351 | if ind <> -1 then val := IntToStr(ind); |
352 | if ind <> -1 then val := IntToStr(ind); |
Line 716... | Line 717... | ||
716 | {$ENDREGION} |
717 | {$ENDREGION} |
717 | end; |
718 | end; |
718 | 719 | ||
719 | procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); |
720 | procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); |
720 | begin |
721 | begin |
721 | FastPHPConfig.WriteInteger('User', 'FontSize', SynEdit1.Font.Size); |
722 | TFastPHPConfig.FontSize := SynEdit1.Font.Size; |
722 | end; |
723 | end; |
723 | 724 | ||
724 | procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean); |
725 | procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean); |
725 | var |
726 | var |
726 | r: integer; |
727 | r: integer; |
Line 784... | Line 785... | ||
784 | end; |
785 | end; |
785 | 786 | ||
786 | procedure TForm1.FormShow(Sender: TObject); |
787 | procedure TForm1.FormShow(Sender: TObject); |
787 | var |
788 | var |
788 | ScrapFile: string; |
789 | ScrapFile: string; |
- | 790 | tmpFontSize: integer; |
|
789 | begin |
791 | begin |
790 | ScrapFile := GetScrapFile; |
792 | ScrapFile := GetScrapFile; |
791 | if ScrapFile = '' then |
793 | if ScrapFile = '' then |
792 | begin |
794 | begin |
793 | Application.Terminate; // Close; |
795 | Application.Terminate; // Close; |
Line 801... | Line 803... | ||
801 | PageControl1.ActivePage := PlaintextTabSheet; |
803 | PageControl1.ActivePage := PlaintextTabSheet; |
802 | 804 | ||
803 | PageControl2.ActivePage := CodeTabsheet; |
805 | PageControl2.ActivePage := CodeTabsheet; |
804 | HelpTabsheet.TabVisible := false; |
806 | HelpTabsheet.TabVisible := false; |
805 | 807 | ||
- | 808 | tmpFontSize := TFastPHPConfig.FontSize; |
|
806 | SynEdit1.Font.Size := FastPHPConfig.ReadInteger('User', 'FontSize', SynEdit1.Font.Size); |
809 | if tmpFontSize <> -1 then SynEdit1.Font.Size := tmpFontSize; |
807 | SynEdit1.SetFocus; |
810 | SynEdit1.SetFocus; |
808 | 811 | ||
809 | DoubleBuffered := true; |
812 | DoubleBuffered := true; |
810 | StartCodeExplorer; |
813 | StartCodeExplorer; |
811 | end; |
814 | end; |
Line 820... | Line 823... | ||
820 | codeExplorer.WorkDir := ExtractFileDir(Application.ExeName); |
823 | codeExplorer.WorkDir := ExtractFileDir(Application.ExeName); |
821 | codeExplorer.Resume; |
824 | codeExplorer.Resume; |
822 | end; |
825 | end; |
823 | 826 | ||
824 | function TForm1.GetScrapFile: string; |
827 | function TForm1.GetScrapFile: string; |
- | 828 | var |
|
- | 829 | tmpPath: string; |
|
825 | begin |
830 | begin |
826 | if FScrapFile <> '' then |
831 | if FScrapFile <> '' then |
827 | begin |
832 | begin |
828 | result := FScrapFile; |
833 | result := FScrapFile; |
829 | exit; |
834 | exit; |
830 | end; |
835 | end; |
831 | 836 | ||
832 | if ParamStr(1) <> '' then |
837 | if ParamStr(1) <> '' then |
- | 838 | begin |
|
- | 839 | // Program was started with a filename |
|
- | 840 | ||
833 | result := ParamStr(1) |
841 | result := ParamStr(1); |
- | 842 | ||
- | 843 | if not FileExists(result) then |
|
- | 844 | begin |
|
- | 845 | case MessageDlg(Format('File %s does not exist. Create it?', [result]), mtConfirmation, mbYesNoCancel, 0) of |
|
- | 846 | mrYes: |
|
- | 847 | try |
|
- | 848 | SynEdit1.Lines.SaveToFile(result); |
|
- | 849 | except |
|
- | 850 | on E: Exception do |
|
- | 851 | begin |
|
- | 852 | MessageDlg(E.Message, mtError, [mbOk], 0); |
|
- | 853 | Application.Terminate; |
|
- | 854 | result := ''; |
|
- | 855 | exit; |
|
- | 856 | end; |
|
- | 857 | end; |
|
- | 858 | mrNo: |
|
- | 859 | begin |
|
- | 860 | Application.Terminate; |
|
- | 861 | result := ''; |
|
- | 862 | exit; |
|
- | 863 | end; |
|
- | 864 | mrCancel: |
|
- | 865 | begin |
|
- | 866 | Application.Terminate; |
|
- | 867 | result := ''; |
|
- | 868 | exit; |
|
- | 869 | end; |
|
- | 870 | end; |
|
- | 871 | end; |
|
- | 872 | end |
|
834 | else |
873 | else |
- | 874 | begin |
|
- | 875 | // Program is started without filename -> use scrap file |
|
- | 876 | ||
835 | result := FastPHPConfig.ReadString('Paths', 'ScrapFile', ''); |
877 | result := TFastPHPConfig.ScrapFile; |
- | 878 | ||
836 | if not FileExists(result) then |
879 | if not FileExists(result) then |
837 | begin |
880 | begin |
838 | repeat |
881 | repeat |
- | 882 | {$REGION 'Determinate opendialog initial directory'} |
|
- | 883 | if result <> '' then |
|
- | 884 | begin |
|
- | 885 | tmpPath := ExtractFilePath(result); |
|
- | 886 | if DirectoryExists(tmpPath) then |
|
- | 887 | begin |
|
- | 888 | OpenDialog3.InitialDir := tmpPath; |
|
- | 889 | OpenDialog3.FileName := Result; |
|
- | 890 | end |
|
- | 891 | else |
|
- | 892 | begin |
|
- | 893 | OpenDialog3.InitialDir := GetMyDocumentsFolder; |
|
- | 894 | end; |
|
- | 895 | end |
|
- | 896 | else |
|
- | 897 | begin |
|
- | 898 | OpenDialog3.InitialDir := GetMyDocumentsFolder; |
|
- | 899 | end; |
|
- | 900 | {$ENDREGION} |
|
- | 901 | ||
839 | if not OpenDialog3.Execute then |
902 | if not OpenDialog3.Execute then |
840 | begin |
903 | begin |
841 | Application.Terminate; |
904 | Application.Terminate; |
842 | result := ''; |
905 | result := ''; |
843 | exit; |
906 | exit; |
844 | end; |
907 | end; |
845 | 908 | ||
846 | if not DirectoryExists(ExtractFilePath(OpenDialog3.FileName)) then |
909 | if not DirectoryExists(ExtractFilePath(OpenDialog3.FileName)) then |
847 | begin |
910 | begin |
848 | ShowMessage('Path does not exist! Please try again.'); |
911 | MessageDlg('Path does not exist! Please try again.', mtWarning, [mbOk], 0); |
849 | end |
912 | end |
850 | else |
913 | else |
851 | begin |
914 | begin |
852 | result := OpenDialog3.FileName; |
915 | result := OpenDialog3.FileName; |
853 | end; |
916 | end; |
854 | until result <> ''; |
917 | until result <> ''; |
855 | 918 | ||
- | 919 | if not FileExists(result) then |
|
- | 920 | begin |
|
- | 921 | try |
|
- | 922 | // Try saving the file; check if we have permissions |
|
856 | //SynEdit1.Lines.Clear; |
923 | //SynEdit1.Lines.Clear; |
857 | //SynEdit1.Lines.SaveToFile(result); |
924 | SynEdit1.Lines.SaveToFile(result); |
- | 925 | except |
|
- | 926 | on E: Exception do |
|
- | 927 | begin |
|
- | 928 | MessageDlg(E.Message, mtError, [mbOk], 0); |
|
- | 929 | Application.Terminate; |
|
- | 930 | result := ''; |
|
- | 931 | exit; |
|
- | 932 | end; |
|
- | 933 | end; |
|
- | 934 | end; |
|
858 | 935 | ||
859 | FastPHPConfig.WriteString('Paths', 'ScrapFile', result); |
936 | TFastPHPConfig.ScrapFile := result; |
860 | FScrapFile := result; |
937 | FScrapFile := result; |
861 | end; |
938 | end; |
862 | end; |
939 | end; |
- | 940 | end; |
|
863 | 941 | ||
864 | procedure TForm1.Help; |
942 | procedure TForm1.Help; |
865 | var |
943 | var |
866 | IndexFile, chmFile, w, OriginalWord, url: string; |
944 | IndexFile, chmFile, w, OriginalWord, url: string; |
867 | internalHtmlFile: string; |
945 | internalHtmlFile: string; |
868 | begin |
946 | begin |
869 | if not Assigned(ChmIndex) then |
947 | if not Assigned(ChmIndex) then |
870 | begin |
948 | begin |
871 | IndexFile := FastPHPConfig.ReadString('Paths', 'HelpIndex', ''); |
949 | IndexFile := TFastPHPConfig.HelpIndex; |
872 | IndexFile := ChangeFileExt(IndexFile, '.ini'); // Just to be sure. Maybe someone wrote manually the ".chm" file in there |
950 | IndexFile := ChangeFileExt(IndexFile, '.ini'); // Just to be sure. Maybe someone wrote manually the ".chm" file in there |
873 | if FileExists(IndexFile) then |
951 | if FileExists(IndexFile) then |
874 | begin |
952 | begin |
875 | ChmIndex := TMemIniFile.Create(IndexFile); |
953 | ChmIndex := TMemIniFile.Create(IndexFile); |
876 | end; |
954 | end; |
877 | end; |
955 | end; |
878 | 956 | ||
879 | if Assigned(ChmIndex) then |
957 | if Assigned(ChmIndex) then |
880 | begin |
958 | begin |
881 | IndexFile := FastPHPConfig.ReadString('Paths', 'HelpIndex', ''); |
959 | IndexFile := TFastPHPConfig.HelpIndex; |
882 | // We don't check if IndexFile still exists. It is not important since we have ChmIndex pre-loaded in memory |
960 | // We don't check if IndexFile still exists. It is not important since we have ChmIndex pre-loaded in memory |
883 | 961 | ||
884 | chmFile := ChangeFileExt(IndexFile, '.chm'); |
962 | chmFile := ChangeFileExt(IndexFile, '.chm'); |
885 | if not FileExists(chmFile) then |
963 | if not FileExists(chmFile) then |
886 | begin |
964 | begin |
Line 905... | Line 983... | ||
905 | Screen.Cursor := crHourGlass; |
983 | Screen.Cursor := crHourGlass; |
906 | Application.ProcessMessages; |
984 | Application.ProcessMessages; |
907 | try |
985 | try |
908 | if not ParseCHM(chmFile) then |
986 | if not ParseCHM(chmFile) then |
909 | begin |
987 | begin |
910 | ShowMessage('The CHM file is not a valid PHP documentation. Cannot use help.'); |
988 | MessageDlg('The CHM file is not a valid PHP documentation. Cannot use help.', mtError, [mbOk], 0); |
911 | exit; |
989 | exit; |
912 | end; |
990 | end; |
913 | finally |
991 | finally |
914 | Screen.Cursor := crDefault; |
992 | Screen.Cursor := crDefault; |
915 | Panel1.Visible := false; |
993 | Panel1.Visible := false; |
916 | end; |
994 | end; |
917 | 995 | ||
918 | if not FileExists(IndexFile) then |
996 | if not FileExists(IndexFile) then |
919 | begin |
997 | begin |
920 | ShowMessage('Unknown error. Cannot use help.'); |
998 | MessageDlg('Unknown error. Cannot use help.', mtError, [mbOk], 0); |
921 | exit; |
999 | exit; |
922 | end; |
1000 | end; |
923 | end; |
1001 | end; |
924 | 1002 | ||
925 | FastPHPConfig.WriteString('Paths', 'HelpIndex', IndexFile); |
- | |
926 | FastPHPConfig.UpdateFile; |
1003 | TFastPHPConfig.HelpIndex := IndexFile; |
927 | 1004 | ||
928 | ChmIndex := TMemIniFile.Create(IndexFile); |
1005 | ChmIndex := TMemIniFile.Create(IndexFile); |
929 | end; |
1006 | end; |
930 | 1007 | ||
931 | w := GetWordUnderCaret(SynEdit1); |
1008 | w := GetWordUnderCaret(SynEdit1); |