mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-22 14:40:24 +02:00
IDE: open project: check if file is program and ask to create a lpi, bug #15329
git-svn-id: trunk@23188 -
This commit is contained in:
parent
d63e8ffbd3
commit
c632b48e5e
@ -123,6 +123,10 @@ resourcestring
|
||||
lisPathOfTheMakeUtility = 'Path of the make utility';
|
||||
lisProjectMacroProperties = 'Project macro properties';
|
||||
lisOpenProject2 = 'Open project';
|
||||
lisFileHasNoProject = 'File has no project';
|
||||
lisTheFileIsNotALazarusProjectCreateANewProjectForThi = 'The file %s%s%s is '
|
||||
+'not a lazarus project.%sCreate a new project for this %s?';
|
||||
lisCreateProject = 'Create project';
|
||||
lisKMSaveProject = 'Save project';
|
||||
lisKMCloseProject = 'Close project';
|
||||
lisKMSaveProjectAs = 'Save project as';
|
||||
|
42
ide/main.pp
42
ide/main.pp
@ -3498,6 +3498,10 @@ Procedure TMainIDE.mnuOpenProjectClicked(Sender: TObject);
|
||||
var
|
||||
OpenDialog:TOpenDialog;
|
||||
AFileName: string;
|
||||
LoadFlags: TLoadBufferFlags;
|
||||
PreReadBuf: TCodeBuffer;
|
||||
SourceType: String;
|
||||
LPIFilename: String;
|
||||
begin
|
||||
if (Sender is TIDEMenuItem)
|
||||
and (TIDEMenuItem(Sender).Section=itmProjectRecentOpen) then begin
|
||||
@ -3521,6 +3525,44 @@ begin
|
||||
+lisAllFiles+'|'+GetAllFilesMask;
|
||||
if OpenDialog.Execute then begin
|
||||
AFilename:=ExpandFileNameUTF8(OpenDialog.Filename);
|
||||
if CompareFileExt(AFilename,'.lpi')<>0 then begin
|
||||
// not a lpi file
|
||||
// check if it is a program source
|
||||
|
||||
// load the source
|
||||
LoadFlags := [lbfCheckIfText,lbfUpdateFromDisk,lbfRevert];
|
||||
if LoadCodeBuffer(PreReadBuf,AFileName,LoadFlags,true)<>mrOk then exit;
|
||||
|
||||
// check if unit is a program
|
||||
SourceType:=CodeToolBoss.GetSourceType(PreReadBuf,false);
|
||||
if (SysUtils.CompareText(SourceType,'PROGRAM')=0)
|
||||
or (SysUtils.CompareText(SourceType,'LIBRARY')=0)
|
||||
then begin
|
||||
// source is a program
|
||||
// either this is a lazarus project
|
||||
// or it is not yet a lazarus project ;)
|
||||
LPIFilename:=ChangeFileExt(AFilename,'.lpi');
|
||||
if FileExistsUTF8(LPIFilename) then begin
|
||||
if QuestionDlg(lisProjectInfoFileDetected,
|
||||
Format(lisTheFileSeemsToBeTheProgramFileOfAnExistingLazarusP, [
|
||||
AFilename]), mtConfirmation,
|
||||
[mrOk, lisOpenProject2, mrCancel], 0)
|
||||
<>mrOk
|
||||
then
|
||||
exit;
|
||||
AFilename:=LPIFilename;
|
||||
end else begin
|
||||
if QuestionDlg(lisFileHasNoProject,
|
||||
Format(lisTheFileIsNotALazarusProjectCreateANewProjectForThi, [
|
||||
'"', AFilename, '"', #13, '"'+lowercase(SourceType)+'"']),
|
||||
mtConfirmation, [mrYes, lisCreateProject, mrCancel], 0)<>mrYes
|
||||
then
|
||||
exit;
|
||||
DoCreateProjectForProgram(PreReadBuf);
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
DoOpenProjectFile(AFilename,[ofAddToRecent]);
|
||||
end;
|
||||
InputHistories.StoreFileDialogSettings(OpenDialog);
|
||||
|
Loading…
Reference in New Issue
Block a user