mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-12 20:21:04 +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';
|
lisPathOfTheMakeUtility = 'Path of the make utility';
|
||||||
lisProjectMacroProperties = 'Project macro properties';
|
lisProjectMacroProperties = 'Project macro properties';
|
||||||
lisOpenProject2 = 'Open project';
|
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';
|
lisKMSaveProject = 'Save project';
|
||||||
lisKMCloseProject = 'Close project';
|
lisKMCloseProject = 'Close project';
|
||||||
lisKMSaveProjectAs = 'Save project as';
|
lisKMSaveProjectAs = 'Save project as';
|
||||||
|
42
ide/main.pp
42
ide/main.pp
@ -3498,6 +3498,10 @@ Procedure TMainIDE.mnuOpenProjectClicked(Sender: TObject);
|
|||||||
var
|
var
|
||||||
OpenDialog:TOpenDialog;
|
OpenDialog:TOpenDialog;
|
||||||
AFileName: string;
|
AFileName: string;
|
||||||
|
LoadFlags: TLoadBufferFlags;
|
||||||
|
PreReadBuf: TCodeBuffer;
|
||||||
|
SourceType: String;
|
||||||
|
LPIFilename: String;
|
||||||
begin
|
begin
|
||||||
if (Sender is TIDEMenuItem)
|
if (Sender is TIDEMenuItem)
|
||||||
and (TIDEMenuItem(Sender).Section=itmProjectRecentOpen) then begin
|
and (TIDEMenuItem(Sender).Section=itmProjectRecentOpen) then begin
|
||||||
@ -3521,6 +3525,44 @@ begin
|
|||||||
+lisAllFiles+'|'+GetAllFilesMask;
|
+lisAllFiles+'|'+GetAllFilesMask;
|
||||||
if OpenDialog.Execute then begin
|
if OpenDialog.Execute then begin
|
||||||
AFilename:=ExpandFileNameUTF8(OpenDialog.Filename);
|
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]);
|
DoOpenProjectFile(AFilename,[ofAddToRecent]);
|
||||||
end;
|
end;
|
||||||
InputHistories.StoreFileDialogSettings(OpenDialog);
|
InputHistories.StoreFileDialogSettings(OpenDialog);
|
||||||
|
Loading…
Reference in New Issue
Block a user