mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-22 13:59:22 +02:00
ide: save file as: check for pascal keyword in unit name and suggest retry or ampersand
This commit is contained in:
parent
838a85bc8c
commit
87d27af233
@ -559,7 +559,7 @@ type
|
|||||||
function GatherOverloads(Code: TCodeBuffer; X,Y: integer;
|
function GatherOverloads(Code: TCodeBuffer; X,Y: integer;
|
||||||
out Graph: TDeclarationOverloadsGraph): boolean;
|
out Graph: TDeclarationOverloadsGraph): boolean;
|
||||||
|
|
||||||
// find references, rename identifier, remove identifier
|
// find references, rename identifier, remove identifier. For unit/program name see FindSourceNameReferences
|
||||||
function FindReferences(IdentifierCode: TCodeBuffer;
|
function FindReferences(IdentifierCode: TCodeBuffer;
|
||||||
X, Y: integer; SearchInCode: TCodeBuffer; SkipComments: boolean;
|
X, Y: integer; SearchInCode: TCodeBuffer; SkipComments: boolean;
|
||||||
var ListOfPCodeXYPosition: TFPList;
|
var ListOfPCodeXYPosition: TFPList;
|
||||||
|
@ -769,6 +769,8 @@ resourcestring
|
|||||||
lisisAnInvalidProjectNamePleaseChooseAnotherEGProject = '"%s" is an '
|
lisisAnInvalidProjectNamePleaseChooseAnotherEGProject = '"%s" is an '
|
||||||
+'invalid project name.%sPlease choose another (e.g. project1.lpi)';
|
+'invalid project name.%sPlease choose another (e.g. project1.lpi)';
|
||||||
lisChooseADifferentName = 'Choose a different name';
|
lisChooseADifferentName = 'Choose a different name';
|
||||||
|
lisUseInstead = 'Use "%s" instead';
|
||||||
|
lisUseAnyway = 'Use "%s" anyway';
|
||||||
lisTheProjectInfoFileIsEqualToTheProjectMainSource = 'The project info '
|
lisTheProjectInfoFileIsEqualToTheProjectMainSource = 'The project info '
|
||||||
+'file "%s"%sis equal to the project main source file!';
|
+'file "%s"%sis equal to the project main source file!';
|
||||||
lisUnitIdentifierExists = 'Unit identifier exists';
|
lisUnitIdentifierExists = 'Unit identifier exists';
|
||||||
@ -1076,6 +1078,7 @@ resourcestring
|
|||||||
lisForceRenaming = 'Force renaming';
|
lisForceRenaming = 'Force renaming';
|
||||||
lisCancelRenaming = 'Cancel renaming';
|
lisCancelRenaming = 'Cancel renaming';
|
||||||
lisInvalidPascalIdentifierCap = 'Invalid Pascal Identifier';
|
lisInvalidPascalIdentifierCap = 'Invalid Pascal Identifier';
|
||||||
|
lisTheNameContainsAPascalKeyword = 'The name "%s" contains a Pascal keyword.';
|
||||||
lisInvalidPascalIdentifierName = 'The name "%s" is not a valid Pascal identifier.'
|
lisInvalidPascalIdentifierName = 'The name "%s" is not a valid Pascal identifier.'
|
||||||
+'%sUse it anyway?';
|
+'%sUse it anyway?';
|
||||||
|
|
||||||
|
@ -4905,7 +4905,8 @@ var
|
|||||||
NewFilename, NewFileExt: string;
|
NewFilename, NewFileExt: string;
|
||||||
OldUnitName, NewUnitName: string;
|
OldUnitName, NewUnitName: string;
|
||||||
ACaption, AText, APath: string;
|
ACaption, AText, APath: string;
|
||||||
Filter, AllEditorExt, AllFilter: string;
|
Filter, AllEditorExt, AllFilter, AmpUnitname: string;
|
||||||
|
r: integer;
|
||||||
begin
|
begin
|
||||||
if (AnUnitInfo<>nil) and (AnUnitInfo.OpenEditorInfoCount>0) then
|
if (AnUnitInfo<>nil) and (AnUnitInfo.OpenEditorInfoCount>0) then
|
||||||
SrcEdit := TSourceEditor(AnUnitInfo.OpenEditorInfo[0].EditorComponent)
|
SrcEdit := TSourceEditor(AnUnitInfo.OpenEditorInfo[0].EditorComponent)
|
||||||
@ -5019,6 +5020,7 @@ begin
|
|||||||
// Is it a valid name? Ask user.
|
// Is it a valid name? Ask user.
|
||||||
if not IsValidUnitName(NewUnitName) then
|
if not IsValidUnitName(NewUnitName) then
|
||||||
begin
|
begin
|
||||||
|
// it is not valid name -> Ask user
|
||||||
Result:=IDEQuestionDialogAb(lisInvalidPascalIdentifierCap,
|
Result:=IDEQuestionDialogAb(lisInvalidPascalIdentifierCap,
|
||||||
Format(lisInvalidPascalIdentifierName,[NewUnitName,LineEnding]),
|
Format(lisInvalidPascalIdentifierName,[NewUnitName,LineEnding]),
|
||||||
mtConfirmation, [mrIgnore, lisSave,
|
mtConfirmation, [mrIgnore, lisSave,
|
||||||
@ -5029,7 +5031,27 @@ begin
|
|||||||
continue;
|
continue;
|
||||||
if Result in [mrCancel,mrAbort] then
|
if Result in [mrCancel,mrAbort] then
|
||||||
exit;
|
exit;
|
||||||
|
end else if CodeToolBoss.IdentifierHasKeywords(NewUnitName,
|
||||||
|
ExtractFilePath(NewFilename),AmpUnitname)
|
||||||
|
then begin
|
||||||
|
// contains keywords -> Suggest to ampersand it
|
||||||
|
Result:=TaskDlg(lisInvalidPascalIdentifierCap,
|
||||||
|
Format(lisTheNameContainsAPascalKeyword, [NewUnitName]), '',
|
||||||
|
tdiWarning,[mbOk,mbCancel],mbOk,
|
||||||
|
[lisChooseADifferentName,
|
||||||
|
Format(lisUseInstead, [StringReplace(AmpUnitname,'&','&&',[rfReplaceAll])]),
|
||||||
|
Format(lisUseAnyway, [NewUnitName])], r);
|
||||||
|
if Result<>mrOk then
|
||||||
|
exit(mrCancel);
|
||||||
|
case r of
|
||||||
|
1: NewUnitName:=AmpUnitname;
|
||||||
|
2: ;
|
||||||
|
else
|
||||||
|
Result:=mrRetry;
|
||||||
|
continue; // retry
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// Does the project already have such unit?
|
// Does the project already have such unit?
|
||||||
if Project1.IndexOfUnitWithName(NewUnitName,true,AnUnitInfo)>=0 then
|
if Project1.IndexOfUnitWithName(NewUnitName,true,AnUnitInfo)>=0 then
|
||||||
begin
|
begin
|
||||||
|
Loading…
Reference in New Issue
Block a user