mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-10 03:35:58 +02:00
extended MakeResourceString function to auto adjust at string constants boundaries
git-svn-id: trunk@7359 -
This commit is contained in:
parent
772ebf4265
commit
52b0862c32
@ -133,6 +133,8 @@ function StringToPascalConst(const s: string): string;
|
||||
function SplitStringConstant(const StringConstant: string;
|
||||
FirstLineLength, OtherLineLengths, Indent: integer;
|
||||
const NewLine: string): string;
|
||||
procedure ImproveStringConstantStart(const ACode: string; var StartPos: integer);
|
||||
procedure ImproveStringConstantEnd(const ACode: string; var EndPos: integer);
|
||||
|
||||
// other useful stuff
|
||||
procedure RaiseCatchableException(const Msg: string);
|
||||
@ -224,7 +226,7 @@ function SearchCodeInSource(const Source, Find: string; StartPos:integer;
|
||||
function ReadNextPascalAtom(const Source: string;
|
||||
var Position, AtomStart: integer): string;
|
||||
procedure ReadRawNextPascalAtom(const Source: string;
|
||||
var Position, AtomStart: integer);
|
||||
var Position: integer; out AtomStart: integer);
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -1391,8 +1393,8 @@ begin
|
||||
until false;
|
||||
end;
|
||||
|
||||
procedure ReadRawNextPascalAtom(const Source:string;
|
||||
var Position,AtomStart:integer);
|
||||
procedure ReadRawNextPascalAtom(const Source: string;
|
||||
var Position: integer; out AtomStart: integer);
|
||||
var Len:integer;
|
||||
c1,c2:char;
|
||||
begin
|
||||
@ -3007,6 +3009,119 @@ begin
|
||||
//DebugLn('SplitStringConstant END---------------------------------');
|
||||
end;
|
||||
|
||||
procedure ImproveStringConstantStart(const ACode: string; var StartPos: integer
|
||||
);
|
||||
// if StartPos is on the first character of a string constant it will be moved
|
||||
// one in front, that means on the start of the string constant.
|
||||
// Example: 'A' StartPos=2 -> StartPos:=1
|
||||
var
|
||||
AtomStartPos, AtomEndPos: Integer;
|
||||
Len: Integer;
|
||||
SubTokenStart: LongInt;
|
||||
begin
|
||||
AtomEndPos:=1;
|
||||
repeat
|
||||
AtomStartPos:=AtomEndPos;
|
||||
ReadRawNextPascalAtom(ACode,AtomEndPos,AtomStartPos);
|
||||
if (AtomEndPos>StartPos) then begin
|
||||
// token found
|
||||
Len:=length(ACode);
|
||||
while (AtomStartPos<=Len) do begin
|
||||
case (ACode[AtomStartPos]) of
|
||||
'#':
|
||||
begin
|
||||
SubTokenStart:=AtomStartPos;
|
||||
inc(AtomStartPos);
|
||||
while (AtomStartPos<=Len)
|
||||
and (ACode[AtomStartPos] in ['0'..'9']) do
|
||||
inc(AtomStartPos);
|
||||
if StartPos<AtomStartPos then begin
|
||||
StartPos:=SubTokenStart;
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
'''':
|
||||
begin
|
||||
inc(AtomStartPos);
|
||||
if StartPos=AtomStartPos then begin
|
||||
StartPos:=AtomStartPos-1;
|
||||
exit;
|
||||
end;
|
||||
while (AtomStartPos<=Len) do begin
|
||||
if (ACode[AtomStartPos]<>'''') then
|
||||
inc(AtomStartPos)
|
||||
else begin
|
||||
if (AtomStartPos<Len) and (ACode[AtomStartPos+1]='''') then
|
||||
inc(AtomStartPos)
|
||||
else
|
||||
break;
|
||||
end;
|
||||
end;
|
||||
inc(AtomStartPos);
|
||||
end;
|
||||
else
|
||||
break;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
until AtomEndPos>StartPos;
|
||||
end;
|
||||
|
||||
procedure ImproveStringConstantEnd(const ACode: string; var EndPos: integer);
|
||||
// if EndPos is on the last character of a string constant it will be moved
|
||||
// to the end, that means on the end of the string constant.
|
||||
// Example: 'A' EndPos=3 -> EndPos:=4
|
||||
var
|
||||
AtomStartPos, AtomEndPos: Integer;
|
||||
Len: Integer;
|
||||
begin
|
||||
AtomEndPos:=1;
|
||||
repeat
|
||||
AtomStartPos:=AtomEndPos;
|
||||
ReadRawNextPascalAtom(ACode,AtomEndPos,AtomStartPos);
|
||||
if (AtomEndPos>=EndPos) then begin
|
||||
// token found
|
||||
Len:=length(ACode);
|
||||
while (AtomStartPos<=Len) do begin
|
||||
case (ACode[AtomStartPos]) of
|
||||
'#':
|
||||
begin
|
||||
inc(AtomStartPos);
|
||||
while (AtomStartPos<=Len)
|
||||
and (ACode[AtomStartPos] in ['0'..'9']) do
|
||||
inc(AtomStartPos);
|
||||
if EndPos<AtomStartPos then begin
|
||||
EndPos:=AtomStartPos;
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
'''':
|
||||
begin
|
||||
inc(AtomStartPos);
|
||||
while (AtomStartPos<=Len) do begin
|
||||
if (ACode[AtomStartPos]<>'''') then
|
||||
inc(AtomStartPos)
|
||||
else begin
|
||||
if (AtomStartPos<Len) and (ACode[AtomStartPos+1]='''') then
|
||||
inc(AtomStartPos)
|
||||
else
|
||||
break;
|
||||
end;
|
||||
end;
|
||||
inc(AtomStartPos);
|
||||
if EndPos=AtomStartPos-1 then begin
|
||||
EndPos:=AtomStartPos;
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
else
|
||||
break;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
until AtomEndPos>=EndPos;
|
||||
end;
|
||||
|
||||
procedure RaiseCatchableException(const Msg: string);
|
||||
begin
|
||||
{ Raises an exception.
|
||||
|
@ -337,6 +337,10 @@ type
|
||||
SectionCode: TCodeBuffer; SectionX, SectionY: integer;
|
||||
const NewIdentifier, NewValue: string;
|
||||
InsertPolicy: TResourcestringInsertPolicy): boolean;
|
||||
procedure ImproveStringConstantStart(const ACode: string;
|
||||
var StartPos: integer);
|
||||
procedure ImproveStringConstantEnd(const ACode: string;
|
||||
var EndPos: integer);
|
||||
|
||||
// expressions
|
||||
function GetStringConstBounds(Code: TCodeBuffer; X,Y: integer;
|
||||
@ -1742,6 +1746,18 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TCodeToolManager.ImproveStringConstantStart(const ACode: string;
|
||||
var StartPos: integer);
|
||||
begin
|
||||
BasicCodeTools.ImproveStringConstantStart(ACode,StartPos);
|
||||
end;
|
||||
|
||||
procedure TCodeToolManager.ImproveStringConstantEnd(const ACode: string;
|
||||
var EndPos: integer);
|
||||
begin
|
||||
BasicCodeTools.ImproveStringConstantEnd(ACode,EndPos);
|
||||
end;
|
||||
|
||||
function TCodeToolManager.GetStringConstBounds(Code: TCodeBuffer; X, Y: integer;
|
||||
var StartCode: TCodeBuffer; var StartX, StartY: integer;
|
||||
var EndCode: TCodeBuffer; var EndX, EndY: integer;
|
||||
|
@ -3458,9 +3458,9 @@ begin
|
||||
try
|
||||
try
|
||||
InputHistories.ApplyFileDialogSettings(SaveDialog);
|
||||
SaveDialog.Filter:='Lazarus Desktop Settings (*.lds)|*.lds'
|
||||
+'|XML files (*.xml)|*.xml'
|
||||
+'|All files (*.*)|*.*';
|
||||
SaveDialog.Filter:=lisLazarusDesktopSettings+' (*.lds)|*.lds'
|
||||
+'|'+lisXMLFiles+' (*.xml)|*.xml'
|
||||
+'|'+dlgAllFiles+' (*.*)|*.*';
|
||||
if SaveDialog.Execute then begin
|
||||
AnEnvironmentOptions:=TEnvironmentOptions.Create;
|
||||
try
|
||||
@ -3493,9 +3493,9 @@ begin
|
||||
try
|
||||
try
|
||||
InputHistories.ApplyFileDialogSettings(OpenDialog);
|
||||
OpenDialog.Filter:='Lazarus Desktop Settings (*.lds)|*.lds'
|
||||
+'|XML files (*.xml)|*.xml'
|
||||
+'|All files (*.*)|*.*';
|
||||
OpenDialog.Filter:=lisLazarusDesktopSettings+' (*.lds)|*.lds'
|
||||
+'|'+lisXMLFiles+' (*.xml)|*.xml'
|
||||
+'|'+dlgAllFiles+' (*.*)|*.*';
|
||||
if OpenDialog.Execute then begin
|
||||
AnEnvironmentOptions:=TEnvironmentOptions.Create;
|
||||
try
|
||||
|
@ -285,6 +285,7 @@ resourcestring
|
||||
lisCompilerOptionsForProject = 'Compiler Options for Project: %s';
|
||||
lisChooseDelphiUnit = 'Choose Delphi unit (*.pas)';
|
||||
lisChooseDelphiProject = 'Choose Delphi project (*.dpr)';
|
||||
lisDelphiProject = 'Delphi project';
|
||||
lisUnableToReadFileError = 'Unable to read file %s%s%s%sError: %s';
|
||||
lisFormatError = 'Format error';
|
||||
lisLFMFileCorrupt = 'LFM file corrupt';
|
||||
@ -531,9 +532,15 @@ resourcestring
|
||||
|
||||
// file dialogs
|
||||
lisOpenFile = 'Open file';
|
||||
lisLazarusFile = 'Lazarus File';
|
||||
lisPascalUnit = 'Pascal unit';
|
||||
lisPascalSourceFile = 'Pascal source file';
|
||||
lisFreePascalSourceFile = 'FreePascal source file';
|
||||
lisDebugUnableToLoadFile = 'Unable to load file';
|
||||
lisDebugUnableToLoadFile2 = 'Unable to load file %s%s%s.';
|
||||
lisOpenProjectFile = 'Open Project File';
|
||||
lisLazarusProjectInfoFile = 'Lazarus Project Info file';
|
||||
lisAllFiles = 'All Files';
|
||||
lisOpenPackageFile = 'Open Package File';
|
||||
lisSaveSpace = 'Save ';
|
||||
lisSelectDFMFiles = 'Select Delphi form files (*.dfm)';
|
||||
@ -544,6 +551,8 @@ resourcestring
|
||||
lisChooseMakePath = 'Choose make path';
|
||||
lisChooseDebuggerPath = 'Choose debugger filename';
|
||||
lisChooseTestBuildDir = 'Choose the directory for tests';
|
||||
lisLazarusDesktopSettings = 'Lazarus Desktop Settings';
|
||||
lisXMLFiles = 'XML files';
|
||||
|
||||
// dialogs
|
||||
lisSaveChangesToProject = 'Save changes to project %s?';
|
||||
@ -768,6 +777,11 @@ resourcestring
|
||||
dlgDelTemplate = 'Delete template ';
|
||||
dlgChsCodeTempl = 'Choose code template file (*.dci)';
|
||||
dlgAllFiles = 'All files';
|
||||
lisLazarusUnit = 'Lazarus unit';
|
||||
lisLazarusProject = 'Lazarus project';
|
||||
lisLazarusForm = 'Lazarus form';
|
||||
lisLazarusPackage = 'Lazarus package';
|
||||
lisLazarusProjectSource = 'Lazarus project source';
|
||||
dlgAltSetClMode = 'Alt-Key sets column mode';
|
||||
dlgAutoIdent = 'Auto indent';
|
||||
dlgBracHighlight = 'Bracket highlighting';
|
||||
|
28
ide/main.pp
28
ide/main.pp
@ -1974,12 +1974,12 @@ begin
|
||||
InputHistories.ApplyFileDialogSettings(OpenDialog);
|
||||
OpenDialog.Title:=lisOpenFile;
|
||||
OpenDialog.Options:=OpenDialog.Options+[ofAllowMultiSelect];
|
||||
OpenDialog.Filter:='All files ('+GetAllFilesMask+')|'+GetAllFilesMask
|
||||
+'|Lazarus unit (*.pas;*.pp)|*.pas;*.pp'
|
||||
+'|Lazarus project (*.lpi)|*.lpi'
|
||||
+'|Lazarus form (*.lfm)|*.lfm'
|
||||
+'|Lazarus package (*.lpk)|*.lpk'
|
||||
+'|Lazarus project source (*.lpr)|*.lpr';
|
||||
OpenDialog.Filter:=dlgAllFiles+' ('+GetAllFilesMask+')|'+GetAllFilesMask
|
||||
+'|'+lisLazarusUnit+' (*.pas;*.pp)|*.pas;*.pp'
|
||||
+'|'+lisLazarusProject+' (*.lpi)|*.lpi'
|
||||
+'|'+lisLazarusForm+' (*.lfm)|*.lfm'
|
||||
+'|'+lisLazarusPackage+' (*.lpk)|*.lpk'
|
||||
+'|'+lisLazarusProjectSource+' (*.lpr)|*.lpr';
|
||||
if OpenDialog.Execute and (OpenDialog.Files.Count>0) then begin
|
||||
OpenFlags:=[ofAddToRecent];
|
||||
//debugln('TMainIDE.mnuOpenClicked OpenDialog.Files.Count=',dbgs(OpenDialog.Files.Count));
|
||||
@ -2699,8 +2699,8 @@ begin
|
||||
try
|
||||
InputHistories.ApplyFileDialogSettings(OpenDialog);
|
||||
OpenDialog.Title:=lisOpenProjectFile+' (*.lpi)';
|
||||
OpenDialog.Filter := 'Lazarus Project Info (*.lpi)|*.lpi|'
|
||||
+'All Files|'+GetAllFilesMask;
|
||||
OpenDialog.Filter := lisLazarusProjectInfoFile+' (*.lpi)|*.lpi|'
|
||||
+lisAllFiles+'|'+GetAllFilesMask;
|
||||
if OpenDialog.Execute then begin
|
||||
AFilename:=ExpandFilename(OpenDialog.Filename);
|
||||
DoOpenProjectFile(AFilename,[ofAddToRecent]);
|
||||
@ -3013,7 +3013,8 @@ begin
|
||||
InputHistories.ApplyFileDialogSettings(OpenDialog);
|
||||
OpenDialog.Title:=lisChooseDelphiProject;
|
||||
OpenDialog.Options:=OpenDialog.Options;
|
||||
OpenDialog.Filter:='Delphi project (*.dpr)|*.dpr|All files (*.*)|*.*';
|
||||
OpenDialog.Filter:=lisDelphiProject+' (*.dpr)|*.dpr|'+dlgAllFiles+' (*.*)|*'
|
||||
+'.*';
|
||||
if OpenDialog.Execute then begin
|
||||
AFilename:=CleanAndExpandFilename(OpenDialog.Filename);
|
||||
//debugln('TMainIDE.mnuToolConvertDelphiProjectClicked A ',AFilename);
|
||||
@ -10502,6 +10503,12 @@ begin
|
||||
// -> check if the selection is only part of the maximum bounds
|
||||
SelectedStartPos:=ActiveSrcEdit.EditorComponent.BlockBegin;
|
||||
SelectedEndPos:=ActiveSrcEdit.EditorComponent.BlockEnd;
|
||||
CodeToolBoss.ImproveStringConstantStart(
|
||||
ActiveSrcEdit.EditorComponent.Lines[SelectedStartPos.Y-1],
|
||||
SelectedStartPos.X);
|
||||
CodeToolBoss.ImproveStringConstantEnd(
|
||||
ActiveSrcEdit.EditorComponent.Lines[SelectedEndPos.Y-1],
|
||||
SelectedEndPos.X);
|
||||
//debugln('TMainIDE.DoMakeResourceString user has selected text: Selected=',dbgs(SelectedStartPos),'-',dbgs(SelectedEndPos),' Maximum=',dbgs(StartPos),'-',dbgs(EndPos));
|
||||
if (CompareCaret(SelectedStartPos,StartPos)>0)
|
||||
or (CompareCaret(SelectedEndPos,EndPos)<0)
|
||||
@ -11813,6 +11820,9 @@ end.
|
||||
|
||||
{ =============================================================================
|
||||
$Log$
|
||||
Revision 1.886 2005/07/15 17:42:45 mattias
|
||||
extended MakeResourceString function to auto adjust at string constants boundaries
|
||||
|
||||
Revision 1.885 2005/07/15 16:25:39 mattias
|
||||
extended MakeResourceString function to convert parts of string constants
|
||||
|
||||
|
@ -535,11 +535,12 @@ begin
|
||||
LazPackage.GetFileDialogInitialDir(OpenDialog.InitialDir);
|
||||
OpenDialog.Title:=lisOpenFile;
|
||||
OpenDialog.Options:=OpenDialog.Options+[ofFileMustExist,ofPathMustExist];
|
||||
OpenDialog.Filter:='Lazarus File (*.pas;*.pp;*.inc;*.lfm;*.lrs)|*.pas;*.pp;*.inc;*.lfm;*.lrs'
|
||||
+'|Pascal unit (*.pp;*.pas)|*.pp;*.pas'
|
||||
+'|Pascal source file (*.pas)|*.pas'
|
||||
+'|FreePascal source file (*.pp)|*.pp'
|
||||
+'|All files ('+GetAllFilesMask+')|'+GetAllFilesMask;
|
||||
OpenDialog.Filter:=lisLazarusFile+' (*.pas;*.pp;*.inc;*.lfm;*.lrs)|*.'
|
||||
+'pas;*.pp;*.inc;*.lfm;*.lrs'
|
||||
+'|'+lisPascalUnit+' (*.pp;*.pas)|*.pp;*.pas'
|
||||
+'|'+lisPascalSourceFile+' (*.pas)|*.pas'
|
||||
+'|'+lisFreePascalSourceFile+' (*.pp)|*.pp'
|
||||
+'|'+dlgAllFiles+' ('+GetAllFilesMask+')|'+GetAllFilesMask;
|
||||
if OpenDialog.Execute then begin
|
||||
AFilename:=CleanAndExpandFilename(OpenDialog.Filename);
|
||||
if FileExists(AFilename) then begin
|
||||
@ -611,10 +612,10 @@ begin
|
||||
LazPackage.GetFileDialogInitialDir(OpenDialog.InitialDir);
|
||||
OpenDialog.Title:=lisOpenFile;
|
||||
OpenDialog.Options:=OpenDialog.Options+[ofFileMustExist,ofPathMustExist];
|
||||
OpenDialog.Filter:='Pascal unit (*.pp;*.pas)|*.pp;*.pas'
|
||||
+'|Pascal source file (*.pas)|*.pas'
|
||||
+'|FreePascal source file (*.pp)|*.pp'
|
||||
+'|All files ('+GetAllFilesMask+')|'+GetAllFilesMask;
|
||||
OpenDialog.Filter:=lisPascalUnit+' (*.pp;*.pas)|*.pp;*.pas'
|
||||
+'|'+lisPascalSourceFile+' (*.pas)|*.pas'
|
||||
+'|'+lisFreePascalSourceFile+' (*.pp)|*.pp'
|
||||
+'|'+dlgAllFiles+' ('+GetAllFilesMask+')|'+GetAllFilesMask;
|
||||
if OpenDialog.Execute then begin
|
||||
AFilename:=CleanAndExpandFilename(OpenDialog.Filename);
|
||||
if FileExists(AFilename) then begin
|
||||
|
@ -329,8 +329,8 @@ begin
|
||||
InputHistories.ApplyFileDialogSettings(OpenDialog);
|
||||
OpenDialog.Title:=lisOpenPackageFile;
|
||||
OpenDialog.Options:=OpenDialog.Options+[ofAllowMultiSelect];
|
||||
OpenDialog.Filter:='Lazarus package (*.lpk)|*.lpk'
|
||||
+'|All files ('+GetAllFilesMask+')|'+GetAllFilesMask;
|
||||
OpenDialog.Filter:=lisLazarusPackage+' (*.lpk)|*.lpk'
|
||||
+'|'+dlgAllFiles+' ('+GetAllFilesMask+')|'+GetAllFilesMask;
|
||||
if OpenDialog.Execute and (OpenDialog.Files.Count>0) then begin
|
||||
OpenFlags:=[pofAddToRecent];
|
||||
For I := 0 to OpenDialog.Files.Count-1 do
|
||||
|
Loading…
Reference in New Issue
Block a user