mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-20 12:19:31 +02:00
jcf: sync with r764:
- Fix to 2130798 - Indentation strange on procedure local type/var declarations - Notepad UI has save and save as for input files, and remembers the file name - Fix to SF bug ID: 2490118 Parser exception with empty var section in a class - Fixed an issue in handling utf-8 encoded files git-svn-id: trunk@18246 -
This commit is contained in:
parent
841e7c90e9
commit
ce19796997
@ -230,6 +230,10 @@ object fmJCFNotepad: TfmJCFNotepad
|
||||
Caption = 'Save &Input'
|
||||
OnClick = mnuFileSaveInClick
|
||||
end
|
||||
object mnuFileSaveInAs: TMenuItem
|
||||
Caption = 'Save Input &as...'
|
||||
OnClick = mnuFileSaveInAsClick
|
||||
end
|
||||
object N1: TMenuItem
|
||||
Caption = '-'
|
||||
end
|
||||
|
@ -37,7 +37,7 @@ uses
|
||||
{ JEDI }
|
||||
JvMRUManager, JvMemo, JvComponent, JvExStdCtrls, JvFormPlacement, JvComponentBase,
|
||||
{ local }
|
||||
JcfRegistrySettings, Converter, ConvertTypes;
|
||||
JcfRegistrySettings, Converter, ConvertTypes, JcfUnicodeFiles;
|
||||
|
||||
{ have to do file pos display *after* various processing }
|
||||
const
|
||||
@ -85,7 +85,7 @@ type
|
||||
mnuEditSelectAll: TMenuItem;
|
||||
mnuEditCopyMessages: TMenuItem;
|
||||
mnuFormat: TMenuItem;
|
||||
mnuFileSaveIn: TMenuItem;
|
||||
mnuFileSaveInAs: TMenuItem;
|
||||
mnuHelp: TMenuItem;
|
||||
mnuHelpAbout: TMenuItem;
|
||||
mnuShowRegSetting: TMenuItem;
|
||||
@ -93,6 +93,7 @@ type
|
||||
ActCut: TAction;
|
||||
Contents1: TMenuItem;
|
||||
JvFormStorage1: TJvFormStorage;
|
||||
mnuFileSaveIn: TMenuItem;
|
||||
procedure FormResize(Sender: TObject);
|
||||
procedure pcPagesChange(Sender: TObject);
|
||||
procedure actGoExecute(Sender: TObject);
|
||||
@ -111,7 +112,7 @@ type
|
||||
procedure mnuEditCopyOutputClick(Sender: TObject);
|
||||
procedure mnuEditSelectAllClick(Sender: TObject);
|
||||
procedure mnuEditCopyMessagesClick(Sender: TObject);
|
||||
procedure mnuFileSaveInClick(Sender: TObject);
|
||||
procedure mnuFileSaveInAsClick(Sender: TObject);
|
||||
procedure mnuHelpAboutClick(Sender: TObject);
|
||||
procedure mnuShowRegSettingClick(Sender: TObject);
|
||||
procedure mnuFormatSettingsClick(Sender: TObject);
|
||||
@ -127,8 +128,11 @@ type
|
||||
procedure mInputClick(Sender: TObject);
|
||||
procedure mOutputClick(Sender: TObject);
|
||||
procedure mInputKeyPress(Sender: TObject; var Key: char);
|
||||
procedure mnuFileSaveInClick(Sender: TObject);
|
||||
private
|
||||
fcConvert: TConverter;
|
||||
fsLastInputFileName: string;
|
||||
feLastInputContentType: TFileContentType;
|
||||
|
||||
procedure OnConvertStatusMessage(const psUnit, psMessage: string;
|
||||
const peMessageType: TStatusMessageType;
|
||||
@ -137,6 +141,10 @@ type
|
||||
procedure CheckInputState;
|
||||
procedure CheckCutPasteState;
|
||||
procedure DoFileOpen(const psFileName: string);
|
||||
procedure SaveInputToFile(const psFileName: string);
|
||||
|
||||
procedure CheckSaveEnabled;
|
||||
|
||||
procedure AddCheckMRU(const psFile: string);
|
||||
|
||||
procedure ShowFilePos;
|
||||
@ -157,7 +165,7 @@ uses
|
||||
{ jcl }
|
||||
JclStrings,
|
||||
{ local }
|
||||
JcfUnicodeFiles, JcfStringUtils,
|
||||
JcfStringUtils,
|
||||
JCFHelp, fAbout, fRegistrySettings, fAllSettings, JcfFontSetFunctions;
|
||||
|
||||
{$ifdef FPC}
|
||||
@ -172,6 +180,11 @@ begin
|
||||
actClear.Enabled := (mInput.Text <> '');
|
||||
end;
|
||||
|
||||
procedure TfmJCFNotepad.CheckSaveEnabled;
|
||||
begin
|
||||
mnuFileSaveIn.Enabled := (fsLastInputFileName <> '');
|
||||
end;
|
||||
|
||||
procedure TfmJCFNotepad.CheckCutPasteState;
|
||||
var
|
||||
lbHasOutput: boolean;
|
||||
@ -192,7 +205,6 @@ end;
|
||||
procedure TfmJCFNotepad.DoFileOpen(const psFileName: string);
|
||||
var
|
||||
lsFileContents: WideString;
|
||||
leContentType: TFileContentType;
|
||||
begin
|
||||
if psFileName = '' then
|
||||
exit;
|
||||
@ -201,7 +213,7 @@ begin
|
||||
|
||||
GetRegSettings.InputDir := ExtractFilePath(psFileName);
|
||||
|
||||
ReadTextFile(psFileName, lsFileContents, leContentType);
|
||||
ReadTextFile(psFileName, lsFileContents, feLastInputContentType);
|
||||
|
||||
// use standard line breaks - temp
|
||||
//lsFileContents := WideStringReplace(lsFileContents, NativeLineFeed, NativeCrLf, [rfReplaceAll]);
|
||||
@ -212,6 +224,28 @@ begin
|
||||
|
||||
CheckInputState;
|
||||
SendShowFilePos;
|
||||
CheckSaveEnabled;
|
||||
end;
|
||||
|
||||
procedure TfmJCFNotepad.SaveInputToFile(const psFileName: string);
|
||||
begin
|
||||
if psFileName = '' then
|
||||
exit;
|
||||
|
||||
// default the file type to utf-8 if it's not known
|
||||
if feLastInputContentType = eUnknown then
|
||||
begin
|
||||
feLastInputContentType := eUtf8;
|
||||
end;
|
||||
|
||||
WriteTextFile(psFileName, mInput.Text, feLastInputContentType);
|
||||
|
||||
|
||||
sb1.Panels[1].Text := 'Saved input as ' + psFileName;
|
||||
AddCheckMRU(psFileName);
|
||||
|
||||
fsLastInputFileName := psFileName;
|
||||
CheckSaveEnabled;
|
||||
end;
|
||||
|
||||
procedure TfmJCFNotepad.AddCheckMRU(const psFile: string);
|
||||
@ -355,6 +389,11 @@ begin
|
||||
mruFiles.RemoveInvalid;
|
||||
|
||||
pcPages.ActivePage := tsInput;
|
||||
|
||||
feLastInputContentType := eUnknown;
|
||||
fsLastInputFileName := '';
|
||||
|
||||
CheckSaveEnabled;
|
||||
end;
|
||||
|
||||
procedure TfmJCFNotepad.FormDestroy(Sender: TObject);
|
||||
@ -423,6 +462,16 @@ begin
|
||||
end;
|
||||
|
||||
procedure TfmJCFNotepad.mnuFileSaveInClick(Sender: TObject);
|
||||
begin
|
||||
if fsLastInputFileName <> '' then
|
||||
begin
|
||||
SaveInputToFile(fsLastInputFileName);
|
||||
end;
|
||||
|
||||
end;
|
||||
|
||||
|
||||
procedure TfmJCFNotepad.mnuFileSaveInAsClick(Sender: TObject);
|
||||
begin
|
||||
SaveDialog1.InitialDir := GetRegSettings.OutputDir;
|
||||
SaveDialog1.Title := 'Save input file';
|
||||
@ -431,9 +480,8 @@ begin
|
||||
if SaveDialog1.Execute then
|
||||
begin
|
||||
GetRegSettings.OutputDir := ExtractFilePath(SaveDialog1.FileName);
|
||||
StringToFile(SaveDialog1.FileName, AnsiString(mInput.Text));
|
||||
sb1.Panels[1].Text := 'Saved input as ' + SaveDialog1.FileName;
|
||||
AddCheckMRU(SaveDialog1.FileName);
|
||||
|
||||
SaveInputToFile(SaveDialog1.FileName);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
@ -2198,10 +2198,12 @@ begin
|
||||
// VarSection -> VAR (VarDecl ';')...
|
||||
Recognise([ttVar, ttThreadvar]);
|
||||
|
||||
repeat
|
||||
// can be enpty
|
||||
while not (fcTokenList.FirstSolidTokenType in leEndVarSection) do
|
||||
begin
|
||||
RecogniseVarDecl;
|
||||
Recognise(ttSemicolon);
|
||||
until (fcTokenList.FirstSolidTokenType in leEndVarSection);
|
||||
end;
|
||||
|
||||
PopNode;
|
||||
end;
|
||||
|
@ -110,6 +110,23 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
function InGlobalTypeOrVarSection(const pt: TSourceToken): Boolean;
|
||||
begin
|
||||
// are we in a type or var section?
|
||||
if not pt.HasParentNode([nTypeSection, nVarSection]) then
|
||||
begin
|
||||
Result := False;
|
||||
exit;
|
||||
end;
|
||||
|
||||
if pt.HasParentNode([nProcedureDecl, nFunctionDecl, nConstructorDecl, nDestructorDecl]) then
|
||||
begin
|
||||
Result := False;
|
||||
exit;
|
||||
end;
|
||||
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
function IsIndented(const pt: TSourceToken): Boolean;
|
||||
begin
|
||||
@ -573,7 +590,7 @@ begin
|
||||
begin
|
||||
if pt.HasParentNode([nLibrary, nProgram]) and (liIndentCount >= 1) then
|
||||
begin
|
||||
if not pt.HasParentNode([nExports, nUses, nTypeSection, nVarSection]) then
|
||||
if not pt.HasParentNode([nExports, nUses]) and (not InGlobalTypeOrVarSection(pt)) then
|
||||
begin
|
||||
if pt.HasParentNode([nCompoundStatement]) and not pt.HasParentNode([nDeclSection]) then
|
||||
begin
|
||||
|
@ -172,6 +172,29 @@ begin
|
||||
Result := WideString(lsContents8bit);
|
||||
end;
|
||||
|
||||
|
||||
function ReadUtf8File(const pcFileStream: TFileStream): WideString;
|
||||
var
|
||||
liBytesRemaining: integer;
|
||||
lsContents: AnsiString;
|
||||
begin
|
||||
liBytesRemaining := pcFileStream.Size - pcFileStream.Position;
|
||||
// read the bytes into a string
|
||||
SetLength(lsContents, liBytesRemaining);
|
||||
if pcFileStream.Size > 0 then
|
||||
begin
|
||||
pcFileStream.ReadBuffer(lsContents[1], liBytesRemaining);
|
||||
end;
|
||||
|
||||
// convert to wide string
|
||||
{$IFDEF DELPHI12}
|
||||
Result := UTF8ToWideString(lsContents);
|
||||
{$ELSE}
|
||||
Result := UTF8Decode(lsContents);
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
|
||||
function Read16BitFile(const pcFileStream: TFileStream; const pbBigEndian: boolean): WideString;
|
||||
var
|
||||
liBytesRemaining: integer;
|
||||
@ -258,10 +281,15 @@ begin
|
||||
ReadPastFileHeader(fs, peContentType);
|
||||
|
||||
case peContentType of
|
||||
e8Bit, eUtf8:
|
||||
e8Bit:
|
||||
psContents := Read8BitFile(fs);
|
||||
|
||||
eUtf8:
|
||||
psContents := ReadUtf8File(fs);
|
||||
|
||||
eUtf16LittleEndian, eUtf16BigEndian:
|
||||
psContents := Read16BitFile(fs, peContentType = eUtf16BigEndian);
|
||||
|
||||
eUtf32LittleEndian, eUtf32BigEndian:
|
||||
psContents := Read32BitFile(fs, peContentType = eUtf32BigEndian);
|
||||
else
|
||||
@ -275,24 +303,37 @@ begin
|
||||
end;
|
||||
|
||||
{ this is one of the few cases when "AnsiString" must be used }
|
||||
procedure Write8BitFile(const pcFileStream: TFileStream;
|
||||
const psContents: WideString; const pbUtf8Header: boolean);
|
||||
procedure Write8BitFile(const pcFileStream: TFileStream; const psContents: WideString);
|
||||
var
|
||||
Len: integer;
|
||||
lsContents: AnsiString;
|
||||
begin
|
||||
lsContents := AnsiString(psContents);
|
||||
|
||||
Len := Length(lsContents);
|
||||
|
||||
if Len > 0 then
|
||||
begin
|
||||
pcFileStream.WriteBuffer(lsContents[1], Len);
|
||||
end;
|
||||
end;
|
||||
|
||||
{ this is one of the few cases when "AnsiString" must be used }
|
||||
procedure WriteUtf8File(const pcFileStream: TFileStream; const psContents: WideString);
|
||||
var
|
||||
Len: integer;
|
||||
lsContents: AnsiString;
|
||||
utf8Header: array [0..2] of byte;
|
||||
begin
|
||||
lsContents := AnsiString(psContents);
|
||||
lsContents := UTF8Encode(psContents);
|
||||
|
||||
Len := Length(lsContents);
|
||||
|
||||
if pbUtf8Header then
|
||||
begin
|
||||
// write the BOM
|
||||
utf8Header[0] := Utf8Marker1;
|
||||
utf8Header[1] := Utf8Marker2;
|
||||
utf8Header[2] := Utf8Marker3;
|
||||
pcFileStream.WriteBuffer(utf8Header[0], 3);
|
||||
end;
|
||||
// write the BOM
|
||||
utf8Header[0] := Utf8Marker1;
|
||||
utf8Header[1] := Utf8Marker2;
|
||||
utf8Header[2] := Utf8Marker3;
|
||||
pcFileStream.WriteBuffer(utf8Header[0], 3);
|
||||
|
||||
if Len > 0 then
|
||||
begin
|
||||
@ -386,9 +427,14 @@ var
|
||||
try
|
||||
|
||||
case peContentType of
|
||||
e8Bit, eUtf8:
|
||||
e8Bit:
|
||||
begin
|
||||
Write8BitFile(fs, psContents, peContentType = eUtf8);
|
||||
Write8BitFile(fs, psContents);
|
||||
end;
|
||||
|
||||
eUtf8:
|
||||
begin
|
||||
WriteUtf8File(fs, psContents);
|
||||
end;
|
||||
|
||||
eUtf16LittleEndian, eUtf16BigEndian:
|
||||
|
@ -1,3 +1,3 @@
|
||||
This directory contains a copy (sometimes modified) of r746 jcf2 svn tree: https://jedicodeformat.svn.sourceforge.net/svnroot/jedicodeformat/trunk/CodeFormat/Jcf2
|
||||
This directory contains a copy (sometimes modified) of r764 jcf2 svn tree: https://jedicodeformat.svn.sourceforge.net/svnroot/jedicodeformat/trunk/CodeFormat/Jcf2
|
||||
|
||||
Only command line utility works currently.
|
Loading…
Reference in New Issue
Block a user