mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-11-23 14:19:32 +01:00
extended MakeResourceString function to convert parts of string constants
git-svn-id: trunk@7358 -
This commit is contained in:
parent
42f6cd4d0e
commit
772ebf4265
@ -324,11 +324,12 @@ type
|
|||||||
function CreateIdentifierFromStringConst(
|
function CreateIdentifierFromStringConst(
|
||||||
StartCode: TCodeBuffer; StartX, StartY: integer;
|
StartCode: TCodeBuffer; StartX, StartY: integer;
|
||||||
EndCode: TCodeBuffer; EndX, EndY: integer;
|
EndCode: TCodeBuffer; EndX, EndY: integer;
|
||||||
var Identifier: string; MaxLen: integer): boolean;
|
out Identifier: string; MaxLen: integer): boolean;
|
||||||
function StringConstToFormatString(
|
function StringConstToFormatString(
|
||||||
StartCode: TCodeBuffer; StartX, StartY: integer;
|
StartCode: TCodeBuffer; StartX, StartY: integer;
|
||||||
EndCode: TCodeBuffer; EndX, EndY: integer;
|
EndCode: TCodeBuffer; EndX, EndY: integer;
|
||||||
var FormatStringConstant, FormatParameters: string): boolean;
|
out FormatStringConstant, FormatParameters: string;
|
||||||
|
out StartInStringConst, EndInStringConst: boolean): boolean;
|
||||||
function GatherResourceStringsWithValue(SectionCode: TCodeBuffer;
|
function GatherResourceStringsWithValue(SectionCode: TCodeBuffer;
|
||||||
SectionX, SectionY: integer; const StringValue: string;
|
SectionX, SectionY: integer; const StringValue: string;
|
||||||
CodePositions: TCodeXYPositions): boolean;
|
CodePositions: TCodeXYPositions): boolean;
|
||||||
@ -1630,7 +1631,7 @@ end;
|
|||||||
function TCodeToolManager.CreateIdentifierFromStringConst(
|
function TCodeToolManager.CreateIdentifierFromStringConst(
|
||||||
StartCode: TCodeBuffer; StartX, StartY: integer;
|
StartCode: TCodeBuffer; StartX, StartY: integer;
|
||||||
EndCode: TCodeBuffer; EndX, EndY: integer;
|
EndCode: TCodeBuffer; EndX, EndY: integer;
|
||||||
var Identifier: string; MaxLen: integer): boolean;
|
out Identifier: string; MaxLen: integer): boolean;
|
||||||
var
|
var
|
||||||
StartCursorPos, EndCursorPos: TCodeXYPosition;
|
StartCursorPos, EndCursorPos: TCodeXYPosition;
|
||||||
begin
|
begin
|
||||||
@ -1657,7 +1658,8 @@ end;
|
|||||||
function TCodeToolManager.StringConstToFormatString(
|
function TCodeToolManager.StringConstToFormatString(
|
||||||
StartCode: TCodeBuffer; StartX, StartY: integer;
|
StartCode: TCodeBuffer; StartX, StartY: integer;
|
||||||
EndCode: TCodeBuffer; EndX, EndY: integer;
|
EndCode: TCodeBuffer; EndX, EndY: integer;
|
||||||
var FormatStringConstant, FormatParameters: string): boolean;
|
out FormatStringConstant, FormatParameters: string;
|
||||||
|
out StartInStringConst, EndInStringConst: boolean): boolean;
|
||||||
var
|
var
|
||||||
StartCursorPos, EndCursorPos: TCodeXYPosition;
|
StartCursorPos, EndCursorPos: TCodeXYPosition;
|
||||||
begin
|
begin
|
||||||
@ -1674,7 +1676,8 @@ begin
|
|||||||
EndCursorPos.Code:=EndCode;
|
EndCursorPos.Code:=EndCode;
|
||||||
try
|
try
|
||||||
Result:=FCurCodeTool.StringConstToFormatString(
|
Result:=FCurCodeTool.StringConstToFormatString(
|
||||||
StartCursorPos,EndCursorPos,FormatStringConstant,FormatParameters);
|
StartCursorPos,EndCursorPos,FormatStringConstant,FormatParameters,
|
||||||
|
StartInStringConst,EndInStringConst);
|
||||||
except
|
except
|
||||||
on e: Exception do HandleException(e);
|
on e: Exception do HandleException(e);
|
||||||
end;
|
end;
|
||||||
|
|||||||
@ -57,7 +57,7 @@ type
|
|||||||
function ExtractCode(StartPos, EndPos: integer;
|
function ExtractCode(StartPos, EndPos: integer;
|
||||||
Attr: TProcHeadAttributes): string;
|
Attr: TProcHeadAttributes): string;
|
||||||
function ExtractIdentCharsFromStringConstant(
|
function ExtractIdentCharsFromStringConstant(
|
||||||
StartPos, MaxLen: integer): string;
|
StartPos, MinPos, MaxPos, MaxLen: integer): string;
|
||||||
function ReadStringConstantValue(StartPos: integer): string;
|
function ReadStringConstantValue(StartPos: integer): string;
|
||||||
|
|
||||||
// properties
|
// properties
|
||||||
@ -864,11 +864,12 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function TPascalReaderTool.ExtractIdentCharsFromStringConstant(StartPos,
|
function TPascalReaderTool.ExtractIdentCharsFromStringConstant(StartPos,
|
||||||
MaxLen: integer): string;
|
MinPos, MaxPos, MaxLen: integer): string;
|
||||||
var
|
var
|
||||||
APos: Integer;
|
APos: Integer;
|
||||||
IdentStartPos: Integer;
|
IdentStartPos: Integer;
|
||||||
IdentStr: String;
|
IdentStr: String;
|
||||||
|
IdentEndPos: LongInt;
|
||||||
begin
|
begin
|
||||||
Result:='';
|
Result:='';
|
||||||
APos:=StartPos;
|
APos:=StartPos;
|
||||||
@ -888,17 +889,20 @@ begin
|
|||||||
repeat
|
repeat
|
||||||
// read identifier chars
|
// read identifier chars
|
||||||
IdentStartPos:=APos;
|
IdentStartPos:=APos;
|
||||||
while (IdentStartPos<SrcLen) and (IsIdentChar[Src[IdentStartPos]]) do
|
while (APos<SrcLen) and (IsIdentChar[Src[APos]]) do
|
||||||
inc(IdentStartPos);
|
inc(APos);
|
||||||
if IdentStartPos>APos then begin
|
IdentEndPos:=APos;
|
||||||
if IdentStartPos-APos+length(Result)>MaxLen then
|
if IdentStartPos<MinPos then IdentStartPos:=MinPos;
|
||||||
IdentStartPos:=APos+MaxLen-length(Result);
|
if IdentEndPos>MaxPos then IdentEndPos:=MaxPos;
|
||||||
IdentStr:=copy(Src,APos,IdentStartPos-APos);
|
if (IdentEndPos>IdentStartPos) then begin
|
||||||
if (Result<>'') and (IdentStr<>'') then
|
if IdentEndPos-IdentStartPos+length(Result)>MaxLen then
|
||||||
|
IdentEndPos:=IdentStartPos+MaxLen-length(Result);
|
||||||
|
IdentStr:=copy(Src,IdentStartPos,IdentEndPos-IdentStartPos);
|
||||||
|
if (IdentStr<>'') then begin
|
||||||
IdentStr[1]:=UpChars[IdentStr[1]];
|
IdentStr[1]:=UpChars[IdentStr[1]];
|
||||||
Result:=Result+IdentStr;
|
Result:=Result+IdentStr;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
APos:=IdentStartPos;
|
|
||||||
// skip non identifier chars
|
// skip non identifier chars
|
||||||
while (APos<SrcLen) and (Src[APos]<>'''')
|
while (APos<SrcLen) and (Src[APos]<>'''')
|
||||||
and (not IsIdentChar[Src[APos]])
|
and (not IsIdentChar[Src[APos]])
|
||||||
|
|||||||
@ -215,7 +215,10 @@ type
|
|||||||
const NewCode: string;
|
const NewCode: string;
|
||||||
SourceChangeCache: TSourceChangeCache): boolean;
|
SourceChangeCache: TSourceChangeCache): boolean;
|
||||||
function GetStringConstAsFormatString(StartPos, EndPos: integer;
|
function GetStringConstAsFormatString(StartPos, EndPos: integer;
|
||||||
var FormatStringConstant,FormatParameters: string): boolean;
|
out FormatStringConstant, FormatParameters: string;
|
||||||
|
out StartInStringConst, EndInStringConst: boolean): boolean;
|
||||||
|
function GetStringConstAsFormatString(StartPos, EndPos: integer;
|
||||||
|
out FormatStringConstant, FormatParameters: string): boolean;
|
||||||
|
|
||||||
// resource strings
|
// resource strings
|
||||||
function GatherResourceStringSections(const CursorPos: TCodeXYPosition;
|
function GatherResourceStringSections(const CursorPos: TCodeXYPosition;
|
||||||
@ -238,10 +241,11 @@ type
|
|||||||
SourceChangeCache: TSourceChangeCache): boolean;
|
SourceChangeCache: TSourceChangeCache): boolean;
|
||||||
function CreateIdentifierFromStringConst(
|
function CreateIdentifierFromStringConst(
|
||||||
const StartCursorPos, EndCursorPos: TCodeXYPosition;
|
const StartCursorPos, EndCursorPos: TCodeXYPosition;
|
||||||
var Identifier: string; MaxLen: integer): boolean;
|
out Identifier: string; MaxLen: integer): boolean;
|
||||||
function StringConstToFormatString(
|
function StringConstToFormatString(
|
||||||
const StartCursorPos, EndCursorPos: TCodeXYPosition;
|
const StartCursorPos, EndCursorPos: TCodeXYPosition;
|
||||||
var FormatStringConstant,FormatParameters: string): boolean;
|
out FormatStringConstant,FormatParameters: string;
|
||||||
|
out StartInStringConst, EndInStringConst: boolean): boolean;
|
||||||
|
|
||||||
// register procedure
|
// register procedure
|
||||||
function HasInterfaceRegisterProc(var HasRegisterProc: boolean): boolean;
|
function HasInterfaceRegisterProc(var HasRegisterProc: boolean): boolean;
|
||||||
@ -2339,7 +2343,8 @@ begin
|
|||||||
ReadNextAtom;
|
ReadNextAtom;
|
||||||
if AtomIsIdentifier(false) then begin
|
if AtomIsIdentifier(false) then begin
|
||||||
CurIdentNode:=
|
CurIdentNode:=
|
||||||
IdentTree.FindKey(@Src[CurPos.StartPos], TListSortCompare(@CompareIdentifiers));
|
IdentTree.FindKey(@Src[CurPos.StartPos],
|
||||||
|
TListSortCompare(@CompareIdentifiers));
|
||||||
if CurIdentNode<>nil then begin
|
if CurIdentNode<>nil then begin
|
||||||
CurDiff:=CurPos.StartPos-CleanCursorPos;
|
CurDiff:=CurPos.StartPos-CleanCursorPos;
|
||||||
if CurDiff<0 then CurDiff:=-CurDiff;
|
if CurDiff<0 then CurDiff:=-CurDiff;
|
||||||
@ -2349,7 +2354,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
until CurPos.EndPos>SrcLen
|
until CurPos.EndPos>SrcLen;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TStandardCodeTool.GetStringConstBounds(
|
function TStandardCodeTool.GetStringConstBounds(
|
||||||
@ -2552,8 +2557,8 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function TStandardCodeTool.GetStringConstAsFormatString(StartPos,
|
function TStandardCodeTool.GetStringConstAsFormatString(StartPos,
|
||||||
EndPos: integer; var FormatStringConstant, FormatParameters: string
|
EndPos: integer; out FormatStringConstant, FormatParameters: string;
|
||||||
): boolean;
|
out StartInStringConst, EndInStringConst: boolean): boolean;
|
||||||
{ Converts a string constant into the parameters for a Format call of the
|
{ Converts a string constant into the parameters for a Format call of the
|
||||||
system unit.
|
system unit.
|
||||||
|
|
||||||
@ -2585,19 +2590,30 @@ function TStandardCodeTool.GetStringConstAsFormatString(StartPos,
|
|||||||
var
|
var
|
||||||
APos: Integer;
|
APos: Integer;
|
||||||
CharConstStart: Integer;
|
CharConstStart: Integer;
|
||||||
|
InRange: Boolean;
|
||||||
begin
|
begin
|
||||||
|
if (CurPos.StartPos<StartPos) and (CurPos.EndPos>StartPos) then
|
||||||
|
StartInStringConst:=true;
|
||||||
|
if (CurPos.StartPos<EndPos) and (CurPos.EndPos>EndPos) then
|
||||||
|
EndInStringConst:=true;
|
||||||
|
|
||||||
APos:=CurPos.StartPos;
|
APos:=CurPos.StartPos;
|
||||||
while APos<EndPos do begin
|
while APos<EndPos do begin
|
||||||
|
InRange:=(APos>=StartPos);
|
||||||
|
//debugln('ConvertStringConstant InRange=',dbgs(InRange),' Src[APos]=',Src[APos]);
|
||||||
if Src[APos]='''' then begin
|
if Src[APos]='''' then begin
|
||||||
// read string constant
|
// read string constant
|
||||||
inc(APos);
|
inc(APos);
|
||||||
while APos<EndPos do begin
|
while APos<EndPos do begin
|
||||||
|
InRange:=(APos>=StartPos);
|
||||||
case Src[APos] of
|
case Src[APos] of
|
||||||
'''':
|
'''':
|
||||||
if (APos<EndPos-1) and (Src[APos+1]='''') then begin
|
if (APos<EndPos-1) and (Src[APos+1]='''') then begin
|
||||||
// a double ' means a single '
|
// a double ' means a single '
|
||||||
AddChar('''');
|
if InRange then begin
|
||||||
AddChar('''');
|
AddChar('''');
|
||||||
|
AddChar('''');
|
||||||
|
end;
|
||||||
inc(APos,2);
|
inc(APos,2);
|
||||||
end else begin
|
end else begin
|
||||||
// a single ' means end of string constant
|
// a single ' means end of string constant
|
||||||
@ -2606,19 +2622,22 @@ function TStandardCodeTool.GetStringConstAsFormatString(StartPos,
|
|||||||
end;
|
end;
|
||||||
'"':
|
'"':
|
||||||
begin
|
begin
|
||||||
AddParameter('''"''');
|
if InRange then
|
||||||
|
AddParameter('''"''');
|
||||||
inc(APos);
|
inc(APos);
|
||||||
end;
|
end;
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
// normal char
|
// normal char
|
||||||
AddChar(Src[APos]);
|
if InRange then
|
||||||
|
AddChar(Src[APos]);
|
||||||
inc(APos);
|
inc(APos);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end else if Src[APos]='#' then begin
|
end else if Src[APos]='#' then begin
|
||||||
CharConstStart:=APos;
|
CharConstStart:=APos;
|
||||||
|
InRange:=(APos+1>=StartPos);
|
||||||
repeat
|
repeat
|
||||||
// read char constant
|
// read char constant
|
||||||
inc(APos);
|
inc(APos);
|
||||||
@ -2634,7 +2653,8 @@ function TStandardCodeTool.GetStringConstAsFormatString(StartPos,
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
until (APos>=EndPos) or (Src[APos]<>'#');
|
until (APos>=EndPos) or (Src[APos]<>'#');
|
||||||
AddParameter(CharConstStart,APos);
|
if InRange then
|
||||||
|
AddParameter(CharConstStart,APos);
|
||||||
end else
|
end else
|
||||||
break;
|
break;
|
||||||
end;
|
end;
|
||||||
@ -2659,32 +2679,53 @@ function TStandardCodeTool.GetStringConstAsFormatString(StartPos,
|
|||||||
if AtomIsStringConstant then UndoReadNextAtom;
|
if AtomIsStringConstant then UndoReadNextAtom;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
var
|
||||||
|
ANode: TCodeTreeNode;
|
||||||
|
CodePosInFront: LongInt;
|
||||||
begin
|
begin
|
||||||
Result:=false;
|
Result:=false;
|
||||||
// read string constants and convert it
|
// read string constants and convert it
|
||||||
FormatStringConstant:='';
|
FormatStringConstant:='';
|
||||||
FormatParameters:='';
|
FormatParameters:='';
|
||||||
MoveCursorToCleanPos(StartPos);
|
StartInStringConst:=false;
|
||||||
|
EndInStringConst:=false;
|
||||||
|
ANode:=FindDeepestNodeAtPos(StartPos,True);
|
||||||
|
CodePosInFront:=ANode.StartPos;
|
||||||
|
MoveCursorToCleanPos(CodePosInFront);
|
||||||
if EndPos>SrcLen then EndPos:=SrcLen+1;
|
if EndPos>SrcLen then EndPos:=SrcLen+1;
|
||||||
repeat
|
repeat
|
||||||
ReadNextAtom;
|
ReadNextAtom;
|
||||||
if (CurPos.EndPos>EndPos) then break;
|
//debugln('GetStringConstAsFormatString Atom=',GetAtom);
|
||||||
if AtomIsStringConstant then begin
|
if (CurPos.StartPos>=EndPos) then break;
|
||||||
// a string constant
|
if CurPos.EndPos>StartPos then begin
|
||||||
ConvertStringConstant;
|
//debugln('GetStringConstAsFormatString Parsing...');
|
||||||
end else if AtomIsChar('+') then begin
|
if AtomIsStringConstant then begin
|
||||||
// simply ignore
|
// a string constant
|
||||||
end else if (CurPos.Flag=cafRoundBracketOpen) or AtomIsIdentifier(false)
|
ConvertStringConstant;
|
||||||
then begin
|
end else if AtomIsChar('+') then begin
|
||||||
// add as parameter
|
// simply ignore
|
||||||
ConvertOther;
|
end else if (CurPos.Flag=cafRoundBracketOpen) or AtomIsIdentifier(false)
|
||||||
end else
|
then begin
|
||||||
// string constant end
|
// add as parameter
|
||||||
break;
|
ConvertOther;
|
||||||
|
end else
|
||||||
|
// string constant end
|
||||||
|
break;
|
||||||
|
end;
|
||||||
until false;
|
until false;
|
||||||
Result:=FormatStringConstant<>'';
|
Result:=FormatStringConstant<>'';
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TStandardCodeTool.GetStringConstAsFormatString(StartPos,
|
||||||
|
EndPos: integer; out FormatStringConstant, FormatParameters: string
|
||||||
|
): boolean;
|
||||||
|
var
|
||||||
|
StartInStringConst, EndInStringConstant: boolean;
|
||||||
|
begin
|
||||||
|
Result:=GetStringConstAsFormatString(StartPos,EndPos,FormatStringConstant,
|
||||||
|
FormatParameters,StartInStringConst,EndInStringConstant);
|
||||||
|
end;
|
||||||
|
|
||||||
function TStandardCodeTool.GatherResourceStringSections(
|
function TStandardCodeTool.GatherResourceStringSections(
|
||||||
const CursorPos: TCodeXYPosition; PositionList: TCodeXYPositions): boolean;
|
const CursorPos: TCodeXYPosition; PositionList: TCodeXYPositions): boolean;
|
||||||
|
|
||||||
@ -2792,12 +2833,14 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function TStandardCodeTool.CreateIdentifierFromStringConst(const StartCursorPos,
|
function TStandardCodeTool.CreateIdentifierFromStringConst(const StartCursorPos,
|
||||||
EndCursorPos: TCodeXYPosition; var Identifier: string;
|
EndCursorPos: TCodeXYPosition; out Identifier: string;
|
||||||
MaxLen: integer): boolean;
|
MaxLen: integer): boolean;
|
||||||
var
|
var
|
||||||
StartPos, EndPos: integer;
|
StartPos, EndPos: integer;
|
||||||
Dummy: Integer;
|
Dummy: Integer;
|
||||||
IdentStr: String;
|
IdentStr: String;
|
||||||
|
ANode: TCodeTreeNode;
|
||||||
|
CodePosInFront: LongInt;
|
||||||
begin
|
begin
|
||||||
Result:=false;
|
Result:=false;
|
||||||
if MaxLen<=0 then exit;
|
if MaxLen<=0 then exit;
|
||||||
@ -2805,26 +2848,32 @@ begin
|
|||||||
BuildTreeAndGetCleanPos(trAll,StartCursorPos,StartPos,[]);
|
BuildTreeAndGetCleanPos(trAll,StartCursorPos,StartPos,[]);
|
||||||
Dummy:=CaretToCleanPos(EndCursorPos, EndPos);
|
Dummy:=CaretToCleanPos(EndCursorPos, EndPos);
|
||||||
if (Dummy<>0) and (Dummy<>-1) then exit;
|
if (Dummy<>0) and (Dummy<>-1) then exit;
|
||||||
|
ANode:=FindDeepestNodeAtPos(StartPos,True);
|
||||||
|
CodePosInFront:=ANode.StartPos;
|
||||||
// read string constants and extract identifier characters
|
// read string constants and extract identifier characters
|
||||||
Identifier:='';
|
Identifier:='';
|
||||||
MoveCursorToCleanPos(StartPos);
|
MoveCursorToCleanPos(CodePosInFront);
|
||||||
repeat
|
repeat
|
||||||
ReadNextAtom;
|
ReadNextAtom;
|
||||||
if CurPos.EndPos>EndPos then break;
|
//debugln('TStandardCodeTool.CreateIdentifierFromStringConst Atom=',GetAtom);
|
||||||
|
if (CurPos.StartPos>=EndPos) then break;
|
||||||
if AtomIsStringConstant then begin
|
if AtomIsStringConstant then begin
|
||||||
IdentStr:=ExtractIdentCharsFromStringConstant(CurPos.StartPos,
|
IdentStr:=ExtractIdentCharsFromStringConstant(CurPos.StartPos,
|
||||||
MaxLen-length(Identifier));
|
StartPos,EndPos,MaxLen-length(Identifier));
|
||||||
if (Identifier<>'') and (IdentStr<>'') then
|
//debugln('TStandardCodeTool.CreateIdentifierFromStringConst IdentStr=',IdentStr);
|
||||||
|
if (IdentStr<>'') then begin
|
||||||
IdentStr[1]:=UpChars[IdentStr[1]];
|
IdentStr[1]:=UpChars[IdentStr[1]];
|
||||||
Identifier:=Identifier+IdentStr;
|
Identifier:=Identifier+IdentStr;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
until length(Identifier)>=MaxLen;
|
until length(Identifier)>=MaxLen;
|
||||||
Result:=Identifier<>'';
|
Result:=Identifier<>'';
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TStandardCodeTool.StringConstToFormatString(const StartCursorPos,
|
function TStandardCodeTool.StringConstToFormatString(const StartCursorPos,
|
||||||
EndCursorPos: TCodeXYPosition; var FormatStringConstant,
|
EndCursorPos: TCodeXYPosition;
|
||||||
FormatParameters: string): boolean;
|
out FormatStringConstant, FormatParameters: string;
|
||||||
|
out StartInStringConst, EndInStringConst: boolean): boolean;
|
||||||
var
|
var
|
||||||
StartPos,EndPos,Dummy: Integer;
|
StartPos,EndPos,Dummy: Integer;
|
||||||
begin
|
begin
|
||||||
@ -2834,7 +2883,7 @@ begin
|
|||||||
Dummy:=CaretToCleanPos(EndCursorPos, EndPos);
|
Dummy:=CaretToCleanPos(EndCursorPos, EndPos);
|
||||||
if (Dummy<>0) and (Dummy<>-1) then exit;
|
if (Dummy<>0) and (Dummy<>-1) then exit;
|
||||||
Result:=GetStringConstAsFormatString(StartPos,EndPos,FormatStringConstant,
|
Result:=GetStringConstAsFormatString(StartPos,EndPos,FormatStringConstant,
|
||||||
FormatParameters);
|
FormatParameters,StartInStringConst,EndInStringConst);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TStandardCodeTool.HasInterfaceRegisterProc(var HasRegisterProc: boolean
|
function TStandardCodeTool.HasInterfaceRegisterProc(var HasRegisterProc: boolean
|
||||||
|
|||||||
86
ide/main.pp
86
ide/main.pp
@ -10460,60 +10460,63 @@ begin
|
|||||||
Result:=mrCancel;
|
Result:=mrCancel;
|
||||||
if not BeginCodeTool(ActiveSrcEdit,ActiveUnitInfo,[]) then exit;
|
if not BeginCodeTool(ActiveSrcEdit,ActiveUnitInfo,[]) then exit;
|
||||||
{$IFDEF IDE_DEBUG}
|
{$IFDEF IDE_DEBUG}
|
||||||
writeln('');
|
debugln('');
|
||||||
writeln('[TMainIDE.DoMakeResourceString] ************');
|
debugln('[TMainIDE.DoMakeResourceString] ************');
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
// calculate start and end of expression in source
|
// calculate start and end of expression in source
|
||||||
CursorCode:=ActiveUnitInfo.Source;
|
CursorCode:=ActiveUnitInfo.Source;
|
||||||
CursorXY:=ActiveSrcEdit.EditorComponent.LogicalCaretXY;
|
CursorXY:=ActiveSrcEdit.EditorComponent.LogicalCaretXY;
|
||||||
if CodeToolBoss.GetStringConstBounds(
|
if not CodeToolBoss.GetStringConstBounds(
|
||||||
CursorCode,CursorXY.X,CursorXY.Y,
|
CursorCode,CursorXY.X,CursorXY.Y,
|
||||||
StartCode,StartPos.X,StartPos.Y,
|
StartCode,StartPos.X,StartPos.Y,
|
||||||
EndCode,EndPos.X,EndPos.Y,
|
EndCode,EndPos.X,EndPos.Y,
|
||||||
true) then
|
true) then
|
||||||
begin
|
begin
|
||||||
// the codetools have calculated the maximum bounds
|
|
||||||
if (StartCode=EndCode) and (CompareCaret(StartPos,EndPos)=0) then begin
|
|
||||||
MessageDlg(lisNoStringConstantFound,
|
|
||||||
Format(lisHintTheMakeResourcestringFunctionExpectsAStringCon, [#13]),
|
|
||||||
mtError,[mbCancel],0);
|
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
// the user can shorten this range by selecting text
|
|
||||||
if (Trim(ActiveSrcEdit.EditorComponent.SelText)='') then begin
|
|
||||||
// the user has not selected text
|
|
||||||
// -> check if the string constant is in single file
|
|
||||||
// (replacing code that contains an $include directive is ambiguous)
|
|
||||||
if (StartCode<>ActiveUnitInfo.Source)
|
|
||||||
or (EndCode<>ActiveUnitInfo.Source)
|
|
||||||
then begin
|
|
||||||
MessageDlg(lisNoStringConstantFound, Format(
|
|
||||||
lisInvalidExpressionHintTheMakeResourcestringFunction, [#13]),
|
|
||||||
mtError,[mbCancel],0);
|
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
end else begin
|
|
||||||
// the user has selected text
|
|
||||||
// -> check if the selection is only part of the maximum bounds
|
|
||||||
SelectedStartPos:=ActiveSrcEdit.EditorComponent.BlockBegin;
|
|
||||||
SelectedEndPos:=ActiveSrcEdit.EditorComponent.BlockEnd;
|
|
||||||
if (CompareCaret(SelectedStartPos,StartPos)>0)
|
|
||||||
or (CompareCaret(SelectedEndPos,EndPos)<0)
|
|
||||||
then begin
|
|
||||||
MessageDlg(lisSelectionExceedsStringConstant,
|
|
||||||
Format(lisHintTheMakeResourcestringFunctionExpectsAStringCon2, [#13]),
|
|
||||||
mtError,[mbCancel],0);
|
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
StartPos:=SelectedStartPos;
|
|
||||||
EndPos:=SelectedEndPos;
|
|
||||||
end;
|
|
||||||
end else begin
|
|
||||||
DoJumpToCodeToolBossError;
|
DoJumpToCodeToolBossError;
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
// the codetools have calculated the maximum bounds
|
||||||
|
if (StartCode=EndCode) and (CompareCaret(StartPos,EndPos)=0) then begin
|
||||||
|
MessageDlg(lisNoStringConstantFound,
|
||||||
|
Format(lisHintTheMakeResourcestringFunctionExpectsAStringCon, [#13]),
|
||||||
|
mtError,[mbCancel],0);
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
// the user can shorten this range by selecting text
|
||||||
|
if (ActiveSrcEdit.EditorComponent.SelText='') then begin
|
||||||
|
// the user has not selected text
|
||||||
|
// -> check if the string constant is in single file
|
||||||
|
// (replacing code that contains an $include directive is ambiguous)
|
||||||
|
//debugln('TMainIDE.DoMakeResourceString user has not selected text');
|
||||||
|
if (StartCode<>ActiveUnitInfo.Source)
|
||||||
|
or (EndCode<>ActiveUnitInfo.Source)
|
||||||
|
then begin
|
||||||
|
MessageDlg(lisNoStringConstantFound, Format(
|
||||||
|
lisInvalidExpressionHintTheMakeResourcestringFunction, [#13]),
|
||||||
|
mtError,[mbCancel],0);
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
end else begin
|
||||||
|
// the user has selected text
|
||||||
|
// -> check if the selection is only part of the maximum bounds
|
||||||
|
SelectedStartPos:=ActiveSrcEdit.EditorComponent.BlockBegin;
|
||||||
|
SelectedEndPos:=ActiveSrcEdit.EditorComponent.BlockEnd;
|
||||||
|
//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)
|
||||||
|
then begin
|
||||||
|
MessageDlg(lisSelectionExceedsStringConstant,
|
||||||
|
Format(lisHintTheMakeResourcestringFunctionExpectsAStringCon2, [#13]),
|
||||||
|
mtError,[mbCancel],0);
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
StartPos:=SelectedStartPos;
|
||||||
|
EndPos:=SelectedEndPos;
|
||||||
|
end;
|
||||||
|
|
||||||
// gather all reachable resourcestring sections
|
// gather all reachable resourcestring sections
|
||||||
|
//debugln('TMainIDE.DoMakeResourceString gather all reachable resourcestring sections ...');
|
||||||
if not CodeToolBoss.GatherResourceStringSections(
|
if not CodeToolBoss.GatherResourceStringSections(
|
||||||
CursorCode,CursorXY.X,CursorXY.Y,nil)
|
CursorCode,CursorXY.X,CursorXY.Y,nil)
|
||||||
then begin
|
then begin
|
||||||
@ -11810,6 +11813,9 @@ end.
|
|||||||
|
|
||||||
{ =============================================================================
|
{ =============================================================================
|
||||||
$Log$
|
$Log$
|
||||||
|
Revision 1.885 2005/07/15 16:25:39 mattias
|
||||||
|
extended MakeResourceString function to convert parts of string constants
|
||||||
|
|
||||||
Revision 1.884 2005/07/15 15:00:01 mattias
|
Revision 1.884 2005/07/15 15:00:01 mattias
|
||||||
added resourcestrings for search progress form
|
added resourcestrings for search progress form
|
||||||
|
|
||||||
|
|||||||
@ -40,8 +40,8 @@ unit MakeResStrDlg;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, Forms, Controls, Buttons, ComCtrls, StdCtrls, Dialogs,
|
Classes, SysUtils, LCLProc, Forms, Controls, Buttons, ComCtrls, StdCtrls,
|
||||||
LResources, LazarusIDEStrConsts, IDEOptionDefs, CodeToolManager,
|
Dialogs, LResources, LazarusIDEStrConsts, IDEOptionDefs, CodeToolManager,
|
||||||
CodeAtom, CodeToolsStructs, CodeCache, SynHighlighterPas, SynEdit,
|
CodeAtom, CodeToolsStructs, CodeCache, SynHighlighterPas, SynEdit,
|
||||||
EditorOptions, InputHistory, MiscOptions;
|
EditorOptions, InputHistory, MiscOptions;
|
||||||
|
|
||||||
@ -152,6 +152,7 @@ var
|
|||||||
Section: PCodeXYPosition;
|
Section: PCodeXYPosition;
|
||||||
ResourcestringSectionID: Integer;
|
ResourcestringSectionID: Integer;
|
||||||
begin
|
begin
|
||||||
|
//debugln('ShowMakeResStrDialog StartPos=',dbgs(StartPos),' EndPos=',dbgs(EndPos),' ');
|
||||||
MakeResStrDialog:=TMakeResStrDialog.Create(nil);
|
MakeResStrDialog:=TMakeResStrDialog.Create(nil);
|
||||||
MakeResStrDialog.Positions:=CodeToolBoss.Positions.CreateCopy;
|
MakeResStrDialog.Positions:=CodeToolBoss.Positions.CreateCopy;
|
||||||
MakeResStrDialog.SetSource(Code,StartPos,EndPos);
|
MakeResStrDialog.SetSource(Code,StartPos,EndPos);
|
||||||
@ -601,7 +602,7 @@ var
|
|||||||
begin
|
begin
|
||||||
// get the Prefixes history list
|
// get the Prefixes history list
|
||||||
HistoryList:=
|
HistoryList:=
|
||||||
InputHistories.HistoryLists.GetList(hlMakeResourceStringPrefixes,true);
|
InputHistories.HistoryLists.GetList(hlMakeResourceStringPrefixes,true);
|
||||||
IdentPrefixComboBox.Items.Assign(HistoryList);
|
IdentPrefixComboBox.Items.Assign(HistoryList);
|
||||||
if IdentPrefixComboBox.Items.Count>0 then
|
if IdentPrefixComboBox.Items.Count>0 then
|
||||||
IdentPrefixComboBox.Text:=IdentPrefixComboBox.Items[0]
|
IdentPrefixComboBox.Text:=IdentPrefixComboBox.Items[0]
|
||||||
@ -786,9 +787,11 @@ var
|
|||||||
LastLine: string;
|
LastLine: string;
|
||||||
NewString: String;
|
NewString: String;
|
||||||
RightSide: String;
|
RightSide: String;
|
||||||
|
StartInStringConst, EndInStringConst: boolean;
|
||||||
begin
|
begin
|
||||||
if not CodeToolBoss.StringConstToFormatString(Code,StartPos.X,StartPos.Y,
|
if not CodeToolBoss.StringConstToFormatString(Code,StartPos.X,StartPos.Y,
|
||||||
Code,EndPos.X,EndPos.Y,FormatStringConstant,FormatParameters)
|
Code,EndPos.X,EndPos.Y,FormatStringConstant,FormatParameters,
|
||||||
|
StartInStringConst,EndInStringConst)
|
||||||
then begin
|
then begin
|
||||||
SrcPreviewSynEdit.Text:='Error:'#13+CodeToolBoss.ErrorMessage;
|
SrcPreviewSynEdit.Text:='Error:'#13+CodeToolBoss.ErrorMessage;
|
||||||
exit;
|
exit;
|
||||||
@ -797,6 +800,10 @@ begin
|
|||||||
NewString:=GetIdentifier
|
NewString:=GetIdentifier
|
||||||
else
|
else
|
||||||
NewString:='Format('+GetIdentifier+',['+FormatParameters+'])';
|
NewString:='Format('+GetIdentifier+',['+FormatParameters+'])';
|
||||||
|
if StartInStringConst then
|
||||||
|
NewString:='''+'+NewString;
|
||||||
|
if EndInStringConst then
|
||||||
|
NewString:=NewString+'+''';
|
||||||
LeftSide:=copy(StringConstSynEdit.Lines[0],1,StartPos.X-1);
|
LeftSide:=copy(StringConstSynEdit.Lines[0],1,StartPos.X-1);
|
||||||
LastLine:=StringConstSynEdit.Lines[EndPos.Y-StartPos.Y];
|
LastLine:=StringConstSynEdit.Lines[EndPos.Y-StartPos.Y];
|
||||||
RightSide:=copy(LastLine,EndPos.X,length(LastLine)-EndPos.X+1);
|
RightSide:=copy(LastLine,EndPos.X,length(LastLine)-EndPos.X+1);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user