mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-09 10:47:58 +02:00
added make resourcestring dialog, not finished
git-svn-id: trunk@3888 -
This commit is contained in:
parent
57d8d3c6a9
commit
1c346b3b87
@ -18,7 +18,7 @@ implicitunits=codetoolsstrconsts avl_tree basiccodetools codecache sourcelog \
|
||||
customcodetool multikeywordlisttool pascalparsertool finddeclarationtool \
|
||||
identcompletiontool stdcodetools resourcecodetool methodjumptool \
|
||||
eventcodetool codecompletiontool codeatom codetree definetemplates expreval \
|
||||
keywordfunclists linkscanner sourcechanger fileprocs \
|
||||
keywordfunclists linkscanner sourcechanger fileprocs codetoolsstructs \
|
||||
memcheck
|
||||
|
||||
[clean]
|
||||
|
@ -20,7 +20,7 @@ uses
|
||||
FindDeclarationCache, BasicCodeTools, CodeTree, CodeAtom, SourceChanger,
|
||||
CodeToolMemManager, CodeCache, KeywordFuncLists, SourceLog, ExprEval,
|
||||
DefineTemplates, FileProcs, AVL_Tree, CodeToolsStrConsts,
|
||||
MultiKeyWordListTool, ResourceCodeTool;
|
||||
MultiKeyWordListTool, ResourceCodeTool, CodeToolsStructs;
|
||||
|
||||
|
||||
implementation
|
||||
@ -30,6 +30,9 @@ end.
|
||||
{ =============================================================================
|
||||
|
||||
$Log$
|
||||
Revision 1.13 2003/03/02 09:04:02 mattias
|
||||
added make resourcestring dialog, not finished
|
||||
|
||||
Revision 1.12 2002/12/24 12:52:53 mattias
|
||||
fixed ReAllocmem of memcheck and added memcheck for fpc 1.1
|
||||
|
||||
|
@ -46,11 +46,13 @@ type
|
||||
P: integer;
|
||||
Code: TCodeBuffer;
|
||||
end;
|
||||
PCodePosition = ^TCodePosition;
|
||||
|
||||
TCodeXYPosition = record
|
||||
X, Y: integer;
|
||||
Code: TCodeBuffer;
|
||||
end;
|
||||
PCodeXYPosition = ^TCodeXYPosition;
|
||||
|
||||
TCommonAtomFlag = (
|
||||
cafNone,
|
||||
|
@ -42,7 +42,7 @@ uses
|
||||
Classes, SysUtils, CodeToolsStrConsts, EventCodeTool, CodeTree, CodeAtom,
|
||||
SourceChanger, DefineTemplates, CodeCache, ExprEval, LinkScanner,
|
||||
KeywordFuncLists, TypInfo, AVL_Tree, CustomCodeTool, FindDeclarationTool,
|
||||
IdentCompletionTool, ResourceCodeTool;
|
||||
IdentCompletionTool, ResourceCodeTool, CodeToolsStructs;
|
||||
|
||||
type
|
||||
TCodeToolManager = class;
|
||||
@ -98,6 +98,7 @@ type
|
||||
procedure CreateScanner(Code: TCodeBuffer);
|
||||
function InitCurCodeTool(Code: TCodeBuffer): boolean;
|
||||
function InitResourceTool: boolean;
|
||||
procedure ClearPositions;
|
||||
function FindCodeToolForSource(Code: TCodeBuffer): TCustomCodeTool;
|
||||
function GetCodeToolForSource(Code: TCodeBuffer;
|
||||
ExceptionOnError: boolean): TCustomCodeTool;
|
||||
@ -129,6 +130,7 @@ type
|
||||
GlobalValues: TExpressionEvaluator;
|
||||
IdentifierList: TIdentifierList;
|
||||
IdentifierHistory: TIdentifierHistoryList;
|
||||
Positions: TCodeXYPositions;
|
||||
|
||||
procedure ActivateWriteLock;
|
||||
procedure DeactivateWriteLock;
|
||||
@ -233,9 +235,13 @@ type
|
||||
var NewX, NewY, NewTopLine: integer): boolean;
|
||||
function FindSmartHint(Code: TCodeBuffer; X,Y: integer): string;
|
||||
|
||||
// gather identifiers
|
||||
// gather identifiers (i.e. all visible)
|
||||
function GatherIdentifiers(Code: TCodeBuffer; X,Y: integer): boolean;
|
||||
|
||||
// resource string sections
|
||||
function GatherResourceStringSections(
|
||||
Code: TCodeBuffer; X,Y: integer): boolean;
|
||||
|
||||
// expressions
|
||||
function GetStringConstBounds(Code: TCodeBuffer; X,Y: integer;
|
||||
var StartCode: TCodeBuffer; var StartX, StartY: integer;
|
||||
@ -411,6 +417,7 @@ begin
|
||||
{$IFDEF CTDEBUG}
|
||||
writeln('[TCodeToolManager.Destroy] B');
|
||||
{$ENDIF}
|
||||
Positions.Free;
|
||||
IdentifierHistory.Free;
|
||||
IdentifierList.Free;
|
||||
FSourceTools.FreeAndClear;
|
||||
@ -607,6 +614,14 @@ begin
|
||||
Result:=true;
|
||||
end;
|
||||
|
||||
procedure TCodeToolManager.ClearPositions;
|
||||
begin
|
||||
if Positions=nil then
|
||||
Positions:=TCodeXYPositions.Create
|
||||
else
|
||||
Positions.Clear;
|
||||
end;
|
||||
|
||||
function TCodeToolManager.HandleException(AnException: Exception): boolean;
|
||||
var ErrorSrcTool: TCustomCodeTool;
|
||||
begin
|
||||
@ -799,6 +814,27 @@ begin
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
function TCodeToolManager.GatherResourceStringSections(Code: TCodeBuffer; X,
|
||||
Y: integer): boolean;
|
||||
var
|
||||
CursorPos: TCodeXYPosition;
|
||||
begin
|
||||
Result:=false;
|
||||
{$IFDEF CTDEBUG}
|
||||
writeln('TCodeToolManager.GatherResourceStringSections A ',Code.Filename,' x=',x,' y=',y);
|
||||
{$ENDIF}
|
||||
if not InitCurCodeTool(Code) then exit;
|
||||
CursorPos.X:=X;
|
||||
CursorPos.Y:=Y;
|
||||
CursorPos.Code:=Code;
|
||||
ClearPositions;
|
||||
try
|
||||
Result:=FCurCodeTool.GatherResourceStringSections(CursorPos,Positions);
|
||||
except
|
||||
on e: Exception do HandleException(e);
|
||||
end;
|
||||
end;
|
||||
|
||||
function TCodeToolManager.GetStringConstBounds(Code: TCodeBuffer; X, Y: integer;
|
||||
var StartCode: TCodeBuffer; var StartX, StartY: integer;
|
||||
var EndCode: TCodeBuffer; var EndX, EndY: integer;
|
||||
|
@ -588,6 +588,9 @@ type
|
||||
Params: TFindDeclarationParams): TTypeCompatibility;
|
||||
function IsBaseCompatible(const TargetType, ExpressionType: TExpressionType;
|
||||
Params: TFindDeclarationParams): TTypeCompatibility;
|
||||
protected
|
||||
function OpenCodeToolForUnit(UnitNameAtom, UnitInFileAtom: TAtomPosition;
|
||||
ExceptionOnNotFound: boolean): TFindDeclarationTool;
|
||||
public
|
||||
procedure BuildTree(OnlyInterfaceNeeded: boolean); override;
|
||||
destructor Destroy; override;
|
||||
@ -3043,18 +3046,8 @@ begin
|
||||
// identifier not found
|
||||
end;
|
||||
end else begin
|
||||
// open the unit and search the identifier in the interface
|
||||
NewCodeTool:=FindCodeToolForUsedUnit(UnitNameAtom,InAtom,false);
|
||||
if NewCodeTool=nil then begin
|
||||
MoveCursorToCleanPos(UnitNameAtom.StartPos);
|
||||
RaiseExceptionInstance(
|
||||
ECodeToolUnitNotFound.Create(Self,
|
||||
Format(ctsUnitNotFound,[GetAtom(UnitNameAtom)]),
|
||||
GetAtom(UnitNameAtom)));
|
||||
end else if NewCodeTool=Self then begin
|
||||
MoveCursorToCleanPos(UnitNameAtom.StartPos);
|
||||
RaiseExceptionFmt(ctsIllegalCircleInUsedUnits,[GetAtom(UnitNameAtom)]);
|
||||
end;
|
||||
// open the unit
|
||||
NewCodeTool:=OpenCodeToolForUnit(UnitNameAtom,InAtom,false);
|
||||
// search the identifier in the interface of the used unit
|
||||
Params.Save(OldInput);
|
||||
Params.Flags:=[fdfIgnoreUsedUnits]+(fdfGlobalsSameIdent*Params.Flags)
|
||||
@ -5127,6 +5120,25 @@ begin
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
function TFindDeclarationTool.OpenCodeToolForUnit(UnitNameAtom,
|
||||
UnitInFileAtom: TAtomPosition;
|
||||
ExceptionOnNotFound: boolean): TFindDeclarationTool;
|
||||
begin
|
||||
// open the unit
|
||||
Result:=FindCodeToolForUsedUnit(UnitNameAtom,UnitInFileAtom,
|
||||
ExceptionOnNotFound);
|
||||
if Result=nil then begin
|
||||
MoveCursorToCleanPos(UnitNameAtom.StartPos);
|
||||
RaiseExceptionInstance(
|
||||
ECodeToolUnitNotFound.Create(Self,
|
||||
Format(ctsUnitNotFound,[GetAtom(UnitNameAtom)]),
|
||||
GetAtom(UnitNameAtom)));
|
||||
end else if Result=Self then begin
|
||||
MoveCursorToCleanPos(UnitNameAtom.StartPos);
|
||||
RaiseExceptionFmt(ctsIllegalCircleInUsedUnits,[GetAtom(UnitNameAtom)]);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TFindDeclarationTool.DoDeleteNodes;
|
||||
begin
|
||||
ClearNodeCaches(true);
|
||||
|
@ -136,6 +136,7 @@ type
|
||||
procedure Move(Pos, Len, MoveTo: integer);
|
||||
function LoadFromFile(const Filename: string): boolean; virtual;
|
||||
function SaveToFile(const Filename: string): boolean; virtual;
|
||||
function GetLines(StartLine, EndLine: integer): string;
|
||||
function IsEqual(sl: TStrings): boolean;
|
||||
procedure Assign(sl: TStrings);
|
||||
procedure AssignTo(sl: TStrings);
|
||||
@ -673,6 +674,26 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
function TSourceLog.GetLines(StartLine, EndLine: integer): string;
|
||||
var
|
||||
StartPos: Integer;
|
||||
EndPos: Integer;
|
||||
begin
|
||||
BuildLineRanges;
|
||||
if StartLine<1 then StartLine:=1;
|
||||
if EndLine>LineCount then EndLine:=LineCount;
|
||||
if StartLine<=EndLine then begin
|
||||
StartPos:=FLineRanges[StartLine-1].StartPos;
|
||||
if EndLine<LineCount then
|
||||
EndPos:=FLineRanges[EndLine].StartPos
|
||||
else
|
||||
EndPos:=FLineRanges[EndLine-1].EndPos;
|
||||
SetLength(Result,EndPos-StartPos);
|
||||
System.Move(FSource[StartPos],Result[1],length(Result));
|
||||
end else
|
||||
Result:='';
|
||||
end;
|
||||
|
||||
function TSourceLog.IsEqual(sl: TStrings): boolean;
|
||||
var x,y,p,LineLen: integer;
|
||||
Line: string;
|
||||
|
@ -28,6 +28,7 @@
|
||||
- lazarus resources
|
||||
- Application.CreateForm statements
|
||||
- published variables
|
||||
- resource strings
|
||||
|
||||
}
|
||||
unit StdCodeTools;
|
||||
@ -47,7 +48,7 @@ uses
|
||||
Classes, SysUtils, CodeToolsStrConsts, CodeTree, CodeAtom,
|
||||
IdentCompletionTool, PascalParserTool, SourceLog, KeywordFuncLists,
|
||||
BasicCodeTools, LinkScanner, CodeCache, AVL_Tree, TypInfo, SourceChanger,
|
||||
CustomCodeTool;
|
||||
CustomCodeTool, CodeToolsStructs;
|
||||
|
||||
type
|
||||
TStandardCodeTool = class(TIdentCompletionTool)
|
||||
@ -162,8 +163,8 @@ type
|
||||
ResolveComments: boolean): boolean;
|
||||
|
||||
// resource strings
|
||||
function FindNextResourceStringSection(CursorPos: TCodeXYPosition;
|
||||
var ResStrPos: TCodeXYPosition; IgnoreUsedUnits: boolean): boolean;
|
||||
function GatherResourceStringSections(CursorPos: TCodeXYPosition;
|
||||
PositionList: TCodeXYPositions): boolean;
|
||||
end;
|
||||
|
||||
|
||||
@ -1198,12 +1199,12 @@ type
|
||||
scatInherited, scatPoint, scatUp,
|
||||
scatEdgedBracketOpen, scatEdgedBracketClose,
|
||||
scatRoundBracketOpen, scatRoundBracketClose);
|
||||
{const
|
||||
const
|
||||
StrConstTokenTypeName: array[TStrConstTokenType] of string = (
|
||||
'scatNone', 'scatStrConst', 'scatPlus', 'scatIdent',
|
||||
'scatInherited', 'scatPoint', 'scatUp',
|
||||
'scatEdgedBracketOpen', 'scatEdgedBracketClose',
|
||||
'scatRoundBracketOpen', 'scatRoundBracketClose');}
|
||||
'scatRoundBracketOpen', 'scatRoundBracketClose');
|
||||
|
||||
function GetCurrentTokenType: TStrConstTokenType;
|
||||
begin
|
||||
@ -1241,15 +1242,15 @@ begin
|
||||
EndPos:=CursorPos;
|
||||
Result:=true;
|
||||
BuildTreeAndGetCleanPos(trAll,CursorPos,CleanCursorPos,[]);
|
||||
//writeln('TStandardCodeTool.GetStringConstBounds A ',CleanCursorPos,' "',copy(Src,CleanCursorPos-5,5),'" | "',copy(Src,CleanCursorPos,5),'"');
|
||||
writeln('TStandardCodeTool.GetStringConstBounds A ',CleanCursorPos,' "',copy(Src,CleanCursorPos-5,5),'" | "',copy(Src,CleanCursorPos,5),'"');
|
||||
GetCleanPosInfo(-1,CleanCursorPos,ResolveComments,SameArea);
|
||||
//writeln('TStandardCodeTool.GetStringConstBounds B ',SameArea.StartPos,'-',SameArea.EndPos,' "',copy(Src,SameArea.StartPos,SameArea.EndPos-SameArea.StartPos),'"');
|
||||
writeln('TStandardCodeTool.GetStringConstBounds B ',SameArea.StartPos,'-',SameArea.EndPos,' "',copy(Src,SameArea.StartPos,SameArea.EndPos-SameArea.StartPos),'"');
|
||||
if (SameArea.EndPos=SameArea.StartPos) or (SameArea.StartPos>SrcLen) then
|
||||
exit;
|
||||
// read til end of string constant
|
||||
MoveCursorToCleanPos(SameArea.StartPos);
|
||||
ReadNextAtom;
|
||||
//writeln('TStandardCodeTool.GetStringConstBounds F ',GetAtom);
|
||||
writeln('TStandardCodeTool.GetStringConstBounds read til end of string ',GetAtom);
|
||||
CurrentToken:=GetCurrentTokenType;
|
||||
if (CurrentToken=scatNone) then exit;
|
||||
repeat
|
||||
@ -1257,10 +1258,10 @@ begin
|
||||
ReadNextAtom;
|
||||
LastToken:=CurrentToken;
|
||||
CurrentToken:=GetCurrentTokenType;
|
||||
//writeln('TStandardCodeTool.GetStringConstBounds G ',GetAtom,' EndCleanPos=',EndCleanPos,
|
||||
//' LastToken=',StrConstTokenTypeName[LastToken],
|
||||
//' CurrentToken=',StrConstTokenTypeName[CurrentToken],
|
||||
//' ',StrConstTokenTypeName[GetCurrentTokenType]);
|
||||
writeln('TStandardCodeTool.GetStringConstBounds Read Forward: ',GetAtom,' EndCleanPos=',EndCleanPos,
|
||||
' LastToken=',StrConstTokenTypeName[LastToken],
|
||||
' CurrentToken=',StrConstTokenTypeName[CurrentToken],
|
||||
' ',StrConstTokenTypeName[GetCurrentTokenType]);
|
||||
case CurrentToken of
|
||||
scatNone, scatEdgedBracketClose, scatRoundBracketClose:
|
||||
if not (LastToken in [scatStrConst,scatIdent,scatUp,
|
||||
@ -1297,20 +1298,20 @@ begin
|
||||
end;
|
||||
until false;
|
||||
|
||||
// read til end of string constant
|
||||
// read til start of string constant
|
||||
MoveCursorToCleanPos(SameArea.StartPos);
|
||||
ReadNextAtom;
|
||||
//writeln('TStandardCodeTool.GetStringConstBounds H ',GetAtom);
|
||||
writeln('TStandardCodeTool.GetStringConstBounds Read til start of string ',GetAtom);
|
||||
CurrentToken:=GetCurrentTokenType;
|
||||
repeat
|
||||
StartCleanPos:=CurPos.StartPos;
|
||||
ReadPriorAtom;
|
||||
//writeln('TStandardCodeTool.GetStringConstBounds I ',GetAtom,' StartCleanPos=',StartCleanPos);
|
||||
writeln('TStandardCodeTool.GetStringConstBounds Read backward: ',GetAtom,' StartCleanPos=',StartCleanPos);
|
||||
LastToken:=CurrentToken;
|
||||
CurrentToken:=GetCurrentTokenType;
|
||||
case CurrentToken of
|
||||
scatNone, scatEdgedBracketOpen, scatRoundBracketOpen:
|
||||
if not (LastToken in [scatStrConst,scatIdent]) then
|
||||
if not (LastToken in [scatStrConst,scatIdent,scatPlus]) then
|
||||
exit
|
||||
else
|
||||
break;
|
||||
@ -1351,20 +1352,82 @@ begin
|
||||
Result:=true;
|
||||
end;
|
||||
|
||||
function TStandardCodeTool.FindNextResourceStringSection(
|
||||
CursorPos: TCodeXYPosition; var ResStrPos: TCodeXYPosition;
|
||||
IgnoreUsedUnits: boolean): boolean;
|
||||
function TStandardCodeTool.GatherResourceStringSections(
|
||||
CursorPos: TCodeXYPosition; PositionList: TCodeXYPositions): boolean;
|
||||
|
||||
function SearchInUsesSection(UsesNode: TCodeTreeNode): boolean;
|
||||
var
|
||||
InAtom, UnitNameAtom: TAtomPosition;
|
||||
NewCodeTool: TPascalParserTool;
|
||||
ANode: TCodeTreeNode;
|
||||
NewCaret: TCodeXYPosition;
|
||||
begin
|
||||
Result:=false;
|
||||
MoveCursorToUsesEnd(UsesNode);
|
||||
repeat
|
||||
ReadPriorUsedUnit(UnitNameAtom, InAtom);
|
||||
//writeln('TStandardCodeTool.GatherResourceStringSections Uses ',GetAtom(UnitNameAtom));
|
||||
// open the unit
|
||||
NewCodeTool:=OpenCodeToolForUnit(UnitNameAtom,InAtom,false);
|
||||
NewCodeTool.BuildTree(true);
|
||||
// search all resource string sections in the interface
|
||||
ANode:=NewCodeTool.FindInterfaceNode;
|
||||
if (ANode<>nil) and (ANode.LastChild<>nil) then begin
|
||||
ANode:=ANode.LastChild;
|
||||
while ANode<>nil do begin
|
||||
if ANode.Desc=ctnResStrSection then begin
|
||||
if not NewCodeTool.CleanPosToCaret(ANode.StartPos,NewCaret) then
|
||||
break;
|
||||
writeln('TStandardCodeTool.GatherResourceStringSections Found Other ',NewCodeTool.MainFilename,' Y=',NewCaret.Y);
|
||||
PositionList.Add(NewCaret);
|
||||
end;
|
||||
ANode:=ANode.PriorBrother;
|
||||
end;
|
||||
end;
|
||||
// restore the cursor
|
||||
MoveCursorToCleanPos(UnitNameAtom.StartPos);
|
||||
ReadPriorAtom; // read keyword 'uses' or comma
|
||||
//writeln('TStandardCodeTool.GatherResourceStringSections Uses B ',GetAtom);
|
||||
until not AtomIsChar(',');
|
||||
Result:=true;
|
||||
end;
|
||||
|
||||
var
|
||||
CleanCursorPos: integer;
|
||||
//CursorNode: TCodeTreeNode;
|
||||
CursorNode: TCodeTreeNode;
|
||||
NewCaret: TCodeXYPosition;
|
||||
ANode: TCodeTreeNode;
|
||||
begin
|
||||
Result:=false;
|
||||
writeln('TStandardCodeTool.GatherResourceStringSections A ');
|
||||
BuildTreeAndGetCleanPos(trAll,CursorPos,CleanCursorPos,[]);
|
||||
//CursorNode:=FindDeepestNodeAtPos(CleanCursorPos,true);
|
||||
// ToDo
|
||||
|
||||
exit;
|
||||
|
||||
CursorNode:=FindDeepestNodeAtPos(CleanCursorPos,true);
|
||||
PositionList.Clear;
|
||||
ANode:=CursorNode;
|
||||
while ANode<>nil do begin
|
||||
case ANode.Desc of
|
||||
|
||||
ctnResStrSection:
|
||||
begin
|
||||
if not CleanPosToCaret(ANode.StartPos,NewCaret) then exit;
|
||||
writeln('TStandardCodeTool.GatherResourceStringSections Found Same Y=',NewCaret.Y);
|
||||
PositionList.Add(NewCaret);
|
||||
end;
|
||||
|
||||
ctnUsesSection:
|
||||
if not SearchInUsesSection(ANode) then break;
|
||||
|
||||
end;
|
||||
|
||||
// go to next node
|
||||
if ANode.PriorBrother<>nil then begin
|
||||
ANode:=ANode.PriorBrother;
|
||||
if (ANode.Desc=ctnInterface) and (ANode.LastChild<>nil) then
|
||||
ANode:=ANode.LastChild;
|
||||
end else begin
|
||||
ANode:=ANode.Parent;
|
||||
end;
|
||||
end;
|
||||
Result:=true;
|
||||
end;
|
||||
|
||||
|
@ -1037,7 +1037,6 @@ begin
|
||||
itmToolMakeResourceString := TMenuItem.Create(Self);
|
||||
itmToolMakeResourceString.Name:='itmToolMakeResourceString';
|
||||
itmToolMakeResourceString.Caption := lisMenuMakeResourceString;
|
||||
itmToolMakeResourceString.Enabled:=false;
|
||||
mnuTools.Add(itmToolMakeResourceString);
|
||||
|
||||
mnuTools.Add(CreateMenuSeparator);
|
||||
|
@ -27,6 +27,10 @@
|
||||
***************************************************************************
|
||||
|
||||
Author: Mattias Gaertner
|
||||
|
||||
Abstract:
|
||||
TNewOtherDialog is the dialog, which is shown, when the user selects the
|
||||
File->New... menuitem and lets the user choose what to create.
|
||||
|
||||
}
|
||||
unit NewDialog;
|
||||
@ -189,6 +193,7 @@ begin
|
||||
if Result=mrOk then begin
|
||||
ItemType:=NewOtherDialog.ItemType.CreateCopy;
|
||||
end;
|
||||
IDEDialogLayoutList.SaveLayout(NewOtherDialog);
|
||||
NewOtherDialog.Free;
|
||||
end;
|
||||
|
||||
|
@ -463,7 +463,7 @@ const
|
||||
'b c #000080',
|
||||
'a c #008000',
|
||||
'# c #00ff00',
|
||||
'. c none',
|
||||
'. c None',
|
||||
'...................',
|
||||
'......######.......',
|
||||
'....##aaaaaa##..#..',
|
||||
|
Loading…
Reference in New Issue
Block a user