|
@@ -209,6 +209,7 @@ type
|
|
FPrint: TMenuItem;
|
|
FPrint: TMenuItem;
|
|
N22: TMenuItem;
|
|
N22: TMenuItem;
|
|
PrintDialog: TPrintDialog;
|
|
PrintDialog: TPrintDialog;
|
|
|
|
+ FSaveEncodingUTF8NoPreamble: TMenuItem;
|
|
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
|
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
|
procedure FExitClick(Sender: TObject);
|
|
procedure FExitClick(Sender: TObject);
|
|
procedure FOpenMainFileClick(Sender: TObject);
|
|
procedure FOpenMainFileClick(Sender: TObject);
|
|
@@ -513,7 +514,7 @@ var
|
|
implementation
|
|
implementation
|
|
|
|
|
|
uses
|
|
uses
|
|
- ActiveX, Clipbrd, ShellApi, ShlObj, IniFiles, Registry, Consts, Types, UITypes, Math,
|
|
|
|
|
|
+ ActiveX, Clipbrd, ShellApi, ShlObj, IniFiles, Registry, Consts, Types, UITypes, Math, WideStrUtils,
|
|
PathFunc, CmnFunc, CmnFunc2, FileClass, CompMsgs, TmSchema, BrowseFunc,
|
|
PathFunc, CmnFunc, CmnFunc2, FileClass, CompMsgs, TmSchema, BrowseFunc,
|
|
HtmlHelpFunc, TaskbarProgressFunc,
|
|
HtmlHelpFunc, TaskbarProgressFunc,
|
|
{$IFDEF STATICCOMPILER} Compile, {$ENDIF}
|
|
{$IFDEF STATICCOMPILER} Compile, {$ENDIF}
|
|
@@ -1015,7 +1016,7 @@ begin
|
|
|
|
|
|
FMainMemo.Filename := '';
|
|
FMainMemo.Filename := '';
|
|
UpdateCaption;
|
|
UpdateCaption;
|
|
- FMainMemo.SaveInUTF8Encoding := False;
|
|
|
|
|
|
+ FMainMemo.SaveEncoding := seUTF8;
|
|
FMainMemo.Lines.Clear;
|
|
FMainMemo.Lines.Clear;
|
|
FModifiedAnySinceLastCompile := True;
|
|
FModifiedAnySinceLastCompile := True;
|
|
FPreprocessorOutput := '';
|
|
FPreprocessorOutput := '';
|
|
@@ -1106,7 +1107,7 @@ begin
|
|
end;
|
|
end;
|
|
|
|
|
|
if CommandLineWizard then begin
|
|
if CommandLineWizard then begin
|
|
- SaveTextToFile(CommandLineFileName, WizardForm.ResultScript, False);
|
|
|
|
|
|
+ SaveTextToFile(CommandLineFileName, WizardForm.ResultScript, seUtf8);
|
|
end else begin
|
|
end else begin
|
|
NewMainFile;
|
|
NewMainFile;
|
|
FMainMemo.Lines.Text := WizardForm.ResultScript;
|
|
FMainMemo.Lines.Text := WizardForm.ResultScript;
|
|
@@ -1125,14 +1126,31 @@ end;
|
|
procedure TCompileForm.OpenFile(AMemo: TCompScintFileEdit; AFilename: String;
|
|
procedure TCompileForm.OpenFile(AMemo: TCompScintFileEdit; AFilename: String;
|
|
const MainMemoAddToRecentDocs: Boolean);
|
|
const MainMemoAddToRecentDocs: Boolean);
|
|
|
|
|
|
- function IsStreamUTF8Encoded(const Stream: TStream): Boolean;
|
|
|
|
|
|
+ function GetStreamSaveEncoding(const Stream: TStream): TSaveEncoding;
|
|
var
|
|
var
|
|
Buf: array[0..2] of Byte;
|
|
Buf: array[0..2] of Byte;
|
|
begin
|
|
begin
|
|
- Result := False;
|
|
|
|
- if Stream.Read(Buf, SizeOf(Buf)) = SizeOf(Buf) then
|
|
|
|
- if (Buf[0] = $EF) and (Buf[1] = $BB) and (Buf[2] = $BF) then
|
|
|
|
- Result := True;
|
|
|
|
|
|
+ Result := seAuto;
|
|
|
|
+ var Size: Integer := Stream.Size;
|
|
|
|
+ if (Size >= SizeOf(Buf)) and (Stream.Read(Buf, SizeOf(Buf)) = SizeOf(Buf)) and
|
|
|
|
+ (Buf[0] = $EF) and (Buf[1] = $BB) and (Buf[2] = $BF) then
|
|
|
|
+ Result := seUTF8
|
|
|
|
+ else begin
|
|
|
|
+ Stream.Seek(0, soFromBeginning);
|
|
|
|
+ var S: AnsiString;
|
|
|
|
+ SetLength(S, Size);
|
|
|
|
+ SetLength(S, Stream.Read(S[1], Size));
|
|
|
|
+ if IsUTF8String(S) then
|
|
|
|
+ Result := seUTF8NoPreamble;
|
|
|
|
+ end;
|
|
|
|
+ end;
|
|
|
|
+
|
|
|
|
+ function GetEncoding(const SaveEncoding: TSaveEncoding): TEncoding;
|
|
|
|
+ begin
|
|
|
|
+ if SaveEncoding in [seUTF8, seUTF8NoPreamble] then
|
|
|
|
+ Result := TEncoding.UTF8
|
|
|
|
+ else
|
|
|
|
+ Result := nil;
|
|
end;
|
|
end;
|
|
|
|
|
|
var
|
|
var
|
|
@@ -1145,9 +1163,9 @@ begin
|
|
if AMemo = FMainMemo then
|
|
if AMemo = FMainMemo then
|
|
NewMainFile;
|
|
NewMainFile;
|
|
GetFileTime(Stream.Handle, nil, nil, @AMemo.FileLastWriteTime);
|
|
GetFileTime(Stream.Handle, nil, nil, @AMemo.FileLastWriteTime);
|
|
- AMemo.SaveInUTF8Encoding := IsStreamUTF8Encoded(Stream);
|
|
|
|
|
|
+ AMemo.SaveEncoding := GetStreamSaveEncoding(Stream);
|
|
Stream.Seek(0, soFromBeginning);
|
|
Stream.Seek(0, soFromBeginning);
|
|
- AMemo.Lines.LoadFromStream(Stream);
|
|
|
|
|
|
+ AMemo.Lines.LoadFromStream(Stream, GetEncoding(AMemo.SaveEncoding));
|
|
finally
|
|
finally
|
|
Stream.Free;
|
|
Stream.Free;
|
|
end;
|
|
end;
|
|
@@ -1193,7 +1211,7 @@ function TCompileForm.SaveFile(const AMemo: TCompScintFileEdit; const SaveAs: Bo
|
|
[GetLastError]);
|
|
[GetLastError]);
|
|
TempFN := Buf;
|
|
TempFN := Buf;
|
|
try
|
|
try
|
|
- SaveTextToFile(TempFN, AMemo.Lines.Text, AMemo.SaveInUTF8Encoding);
|
|
|
|
|
|
+ SaveTextToFile(TempFN, AMemo.Lines.Text, AMemo.SaveEncoding);
|
|
|
|
|
|
{ Back up existing file if needed }
|
|
{ Back up existing file if needed }
|
|
if FOptions.MakeBackups and NewFileExists(FN) then begin
|
|
if FOptions.MakeBackups and NewFileExists(FN) then begin
|
|
@@ -1728,8 +1746,9 @@ var
|
|
begin
|
|
begin
|
|
FSaveMainFileAs.Enabled := FActiveMemo = FMainMemo;
|
|
FSaveMainFileAs.Enabled := FActiveMemo = FMainMemo;
|
|
FSaveEncoding.Enabled := FSave.Enabled; { FSave.Enabled is kept up-to-date by UpdateSaveMenuItemAndButton }
|
|
FSaveEncoding.Enabled := FSave.Enabled; { FSave.Enabled is kept up-to-date by UpdateSaveMenuItemAndButton }
|
|
- FSaveEncodingAuto.Checked := FSaveEncoding.Enabled and not (FActiveMemo as TCompScintFileEdit).SaveInUTF8Encoding;
|
|
|
|
- FSaveEncodingUTF8.Checked := FSaveEncoding.Enabled and (FActiveMemo as TCompScintFileEdit).SaveInUTF8Encoding;
|
|
|
|
|
|
+ FSaveEncodingAuto.Checked := FSaveEncoding.Enabled and ((FActiveMemo as TCompScintFileEdit).SaveEncoding = seAuto);
|
|
|
|
+ FSaveEncodingUTF8.Checked := FSaveEncoding.Enabled and ((FActiveMemo as TCompScintFileEdit).SaveEncoding = seUTF8);
|
|
|
|
+ FSaveEncodingUTF8NoPreamble.Checked := FSaveEncoding.Enabled and ((FActiveMemo as TCompScintFileEdit).SaveEncoding = seUTF8NoPreamble);
|
|
FSaveAll.Visible := FOptions.OpenIncludedFiles;
|
|
FSaveAll.Visible := FOptions.OpenIncludedFiles;
|
|
ReadMRUMainFilesList;
|
|
ReadMRUMainFilesList;
|
|
FMRUMainFilesSep.Visible := FMRUMainFilesList.Count <> 0;
|
|
FMRUMainFilesSep.Visible := FMRUMainFilesList.Count <> 0;
|
|
@@ -1785,7 +1804,12 @@ end;
|
|
|
|
|
|
procedure TCompileForm.FSaveEncodingItemClick(Sender: TObject);
|
|
procedure TCompileForm.FSaveEncodingItemClick(Sender: TObject);
|
|
begin
|
|
begin
|
|
- (FActiveMemo as TCompScintFileEdit).SaveInUTF8Encoding := (Sender = FSaveEncodingUTF8);
|
|
|
|
|
|
+ if Sender = FSaveEncodingUTF8 then
|
|
|
|
+ (FActiveMemo as TCompScintFileEdit).SaveEncoding := seUTF8
|
|
|
|
+ else if Sender = FSaveEncodingUTF8NoPreamble then
|
|
|
|
+ (FActiveMemo as TCompScintFileEdit).SaveEncoding := seUTF8NoPreamble
|
|
|
|
+ else
|
|
|
|
+ (FActiveMemo as TCompScintFileEdit).SaveEncoding := seAuto;
|
|
end;
|
|
end;
|
|
|
|
|
|
procedure TCompileForm.FSaveAllClick(Sender: TObject);
|
|
procedure TCompileForm.FSaveAllClick(Sender: TObject);
|