IDE: mode matrix: save enabled options in session modes

git-svn-id: trunk@41461 -
This commit is contained in:
mattias 2013-05-30 14:29:43 +00:00
parent 20f62dfb26
commit 422e68c742
5 changed files with 141 additions and 17 deletions

View File

@ -19,14 +19,9 @@
***************************************************************************
ToDo:
- save session modes in session
- project
- IDE
- load session modes
- project
- IDE
- save matrix options for old build macro values
- load old build macro values into matrix
- when rename build mode, update option modes
- ifdef old frame
- ifdef old macro value classes
- wiki

View File

@ -416,7 +416,7 @@ begin
if not FileExistsUTF8(AFilename) then
CopySecondaryConfigFile(DefaultProjectOptionsFilename);
if FileExistsUTF8(AFilename) then begin
if AProject.ReadProject(AFilename,[prfLoadParts,prfLoadPartBuildModes])<>mrOk then
if AProject.ReadProject(AFilename,nil,[prfLoadParts,prfLoadPartBuildModes])<>mrOk then
DebugLn(['TMainIDEBase.DoLoadDefaultCompilerOptions failed']);
end else begin
// old way (<0.9.31)

View File

@ -57,6 +57,8 @@ const
bmgtAll = [low(TBuildMatrixGroupType)..high(TBuildMatrixGroupType)];
type
TIsModeEvent = function(const ModeIdentifier: string): boolean of object;
TBuildMatrixOptions = class;
TBMModesType = (
@ -98,10 +100,13 @@ type
function Equals(Obj: TObject): boolean; override;
function GetModesSeparatedByComma(aTyp: TBMModesType): string;
procedure SetModesFromCommaSeparatedList(aList: string; aTyp: TBMModesType);
procedure DisableModes(const DisableModeEvent: TIsModeEvent; aTyp: TBMModesType);
procedure EnableMode(const aMode: string; aTyp: TBMModesType);
procedure LoadFromConfig(Cfg: TConfigStorage);
procedure SaveToConfig(Cfg: TConfigStorage);
procedure LoadFromXMLConfig(Cfg: TXMLConfig; const aPath: string);
procedure SaveToXMLConfig(Cfg: TXMLConfig; const aPath: string);
function AsString: string;
end;
{ TBuildMatrixOptions }
@ -122,6 +127,7 @@ type
constructor Create;
destructor Destroy; override;
procedure Clear;
procedure DisableModes(const IsModeEvent: TIsModeEvent; aTyp: TBMModesType);
function Count: integer;
property Items[Index: integer]: TBuildMatrixOption read GetItems; default;
function IndexOf(Option: TBuildMatrixOption): integer;
@ -144,6 +150,7 @@ type
// queries
procedure AppendCustomOptions(Target, ActiveMode: string; var Options: string);
procedure GetOutputDirectory(Target, ActiveMode: string; var OutDir: string);
function FindOption(const ID: string): TBuildMatrixOption;
end;
EMMMacroSyntaxException = class(Exception)
@ -458,6 +465,15 @@ begin
IncreaseChangeStep;
end;
procedure TBuildMatrixOptions.DisableModes(const IsModeEvent: TIsModeEvent;
aTyp: TBMModesType);
var
i: Integer;
begin
for i:=0 to Count-1 do
Items[i].DisableModes(IsModeEvent,aTyp);
end;
function TBuildMatrixOptions.Count: integer;
begin
Result:=fItems.Count;
@ -539,11 +555,13 @@ var
Option: TBuildMatrixOption;
begin
Clear;
Cnt:=Cfg.GetValue('Count',0);
Cnt:=Cfg.GetValue(aPath+'Count',0);
//debugln(['TBuildMatrixOptions.LoadFromXMLConfig Cnt=',Cnt]);
for i:=1 to Cnt do begin
Option:=TBuildMatrixOption.Create(Self);
Option.LoadFromXMLConfig(Cfg,aPath+'item'+IntToStr(i)+'/');
end;
//debugln(['TBuildMatrixOptions.LoadFromXMLConfig Count=',Count]);
end;
procedure TBuildMatrixOptions.SaveToXMLConfig(Cfg: TXMLConfig;
@ -551,6 +569,7 @@ procedure TBuildMatrixOptions.SaveToXMLConfig(Cfg: TXMLConfig;
var
i: Integer;
begin
//debugln(['TBuildMatrixOptions.SaveToXMLConfig ',aPath]);
Cfg.SetDeleteValue(aPath+'Count',Count,0);
for i:=0 to Count-1 do
Items[i].SaveToXMLConfig(Cfg,aPath+'item'+IntToStr(i+1)+'/');
@ -590,6 +609,17 @@ begin
end;
end;
function TBuildMatrixOptions.FindOption(const ID: string): TBuildMatrixOption;
var
i: Integer;
begin
for i:=0 to Count-1 do begin
Result:=Items[i];
if Result.ID=ID then exit;
end;
Result:=nil;
end;
{ TBuildMatrixOption }
procedure TBuildMatrixOption.SetMacroName(AValue: string);
@ -740,6 +770,38 @@ begin
Modes[aTyp]:=aList;
end;
procedure TBuildMatrixOption.DisableModes(const DisableModeEvent: TIsModeEvent;
aTyp: TBMModesType);
var
CurModes: String;
p: PChar;
StartP: PChar;
CurMode: String;
StartPos: integer;
begin
CurModes:=Modes[aTyp];
p:=PChar(CurModes);
while p^<>#0 do begin
StartP:=p;
while not (p^ in [#0,#10,#13]) do inc(p);
StartPos:=StartP-PChar(CurModes)+1;
CurMode:=copy(CurModes,StartPos,p-StartP);
while p^ in [#10,#13] do inc(p);
if DisableModeEvent(CurMode) then begin
System.Delete(CurModes,StartPos,p-StartP);
p:=Pointer(CurModes)+StartPos-1;
end;
end;
Modes[aTyp]:=CurModes;
end;
procedure TBuildMatrixOption.EnableMode(const aMode: string; aTyp: TBMModesType
);
begin
if FitsMode(aMode,aTyp) then exit;
Modes[aTyp]:=Modes[aTyp]+aMode+LineEnding;
end;
procedure TBuildMatrixOption.LoadFromConfig(Cfg: TConfigStorage);
begin
ID:=Cfg.GetValue('ID','');
@ -766,6 +828,7 @@ begin
ID:=Cfg.GetValue(aPath+'ID','');
Targets:=Cfg.GetValue(aPath+'Targets','*');
SetModesFromCommaSeparatedList(Cfg.GetValue(aPath+'Modes','*'),bmmtStored);
Modes[bmmtActive]:=Modes[bmmtStored];
Typ:=Str2BuildMatrixOptionType(Cfg.GetValue(aPath+'Type',''));
MacroName:=Cfg.GetValue(aPath+'MacroName','');
Value:=Cfg.GetValue(aPath+'Value','');
@ -782,5 +845,10 @@ begin
Cfg.SetDeleteValue(aPath+'Value',Value,'');
end;
function TBuildMatrixOption.AsString: string;
begin
Result:='ID="'+ID+'" '+BuildMatrixOptionTypeNames[Typ]+' Value="'+Value+'" ActiveModes="'+dbgstr(Modes[bmmtActive])+'"';
end;
end.

View File

@ -736,6 +736,7 @@ type
procedure RemoveOnChangedHandler(const Handler: TNotifyEvent);
function IsModified(InSession: boolean): boolean;
function GetSessionModes: TStringList;
function IsSessionMode(const ModeIdentifier: string): boolean;
public
property Items[Index: integer]: TProjectBuildMode read GetItems; default;
property ChangeStamp: integer read FChangeStamp;
@ -912,6 +913,7 @@ type
function HasProjectInfoFileChangedOnDisk: boolean;
procedure IgnoreProjectInfoFileOnDisk;
function ReadProject(const NewProjectInfoFile: string;
GlobalMatrixOptions: TBuildMatrixOptions;
ReadFlags: TProjectReadFlags = []): TModalResult;
function WriteProject(ProjectWriteFlags: TProjectWriteFlags;
const OverrideProjectInfoFile: string;
@ -2723,6 +2725,7 @@ function TProject.WriteProject(ProjectWriteFlags: TProjectWriteFlags;
if not MatrixOption.FitsMode(CurMode.Identifier,bmmtActive) then continue;
inc(Cnt);
SubPath:=Path+'Item'+IntToStr(Cnt)+'/';
//debugln(['SaveSessionEnabledNonSessionMatrixOptions ModeID="',CurMode.Identifier,'" OptionID="',MatrixOption.ID,'"']);
XMLConfig.SetDeleteValue(SubPath+'Mode',CurMode.Identifier,'');
XMLConfig.SetDeleteValue(SubPath+'Option',MatrixOption.ID,'');
end;
@ -3183,7 +3186,8 @@ end;
TProject ReadProject
------------------------------------------------------------------------------}
function TProject.ReadProject(const NewProjectInfoFile: string;
ReadFlags: TProjectReadFlags): TModalResult;
GlobalMatrixOptions: TBuildMatrixOptions; ReadFlags: TProjectReadFlags
): TModalResult;
type
TOldProjectType = (ptApplication, ptProgram, ptCustomProgram);
const
@ -3195,6 +3199,50 @@ var
FileVersion: Integer;
NewMainUnitID: LongInt;
procedure EnableMatrixMode(MatrixOptions: TBuildMatrixOptions;
OptionID, ModeID: string);
var
MatrixOption: TBuildMatrixOption;
begin
if MatrixOptions=nil then exit;
MatrixOption:=MatrixOptions.FindOption(OptionID);
if MatrixOption=nil then exit;
//debugln(['EnableMatrixMode OptionID=',OptionID,' ModeID=',ModeID]);
MatrixOption.EnableMode(ModeID,bmmtActive);
end;
procedure LoadSessionEnabledNonSessionMatrixOptions(XMLConfig: TXMLConfig;
const Path: string);
var
Cnt: integer;
i: Integer;
SubPath: String;
ModeID: String;
OptionID: String;
begin
// disable all matrix options in session modes
if GlobalMatrixOptions<>nil then
GlobalMatrixOptions.DisableModes(@BuildModes.IsSessionMode,bmmtActive);
BuildModes.SharedMatrixOptions.DisableModes(@BuildModes.IsSessionMode,bmmtActive);
// load
Cnt:=XMLConfig.GetValue(Path+'Count',0);
for i:=1 to Cnt do begin
SubPath:=Path+'Item'+IntToStr(i)+'/';
ModeID:=XMLConfig.GetValue(SubPath+'Mode','');
if (ModeID='') or (not BuildModes.IsSessionMode(ModeID)) then begin
debugln(['LoadSessionEnabledNonSessionMatrixOptions not a session Mode="',dbgstr(ModeID),'" at ',SubPath]);
continue;
end;
OptionID:=XMLConfig.GetValue(SubPath+'Option','');
if OptionID='' then begin
debugln(['LoadSessionEnabledNonSessionMatrixOptions invalid option at ',SubPath]);
continue;
end;
EnableMatrixMode(GlobalMatrixOptions,OptionID,ModeID);
EnableMatrixMode(BuildModes.SharedMatrixOptions,OptionID,ModeID);
end;
end;
procedure LoadBuildModes(XMLConfig: TXMLConfig; const Path: string;
LoadData: boolean);
var
@ -3249,7 +3297,7 @@ var
end else if LoadData then begin
// no build modes => an old file format
CompOptsPath:='CompilerOptions/';
// due to an old bug, the XML path can be 'CompilerOptions/' or ''
// due to a bug in an old version, the XML path can be 'CompilerOptions/' or ''
if (FileVersion<3)
and (XMLConfig.GetValue('SearchPaths/CompilerPath/Value','')<>'') then
CompOptsPath:='';
@ -3262,18 +3310,17 @@ var
if LoadData then begin
// load matrix options of project (not session)
BuildModes.SharedMatrixOptions.LoadFromXMLConfig(XMLConfig,Path+'BuildModes/SharedMatrixOptions/');
//debugln(['LoadBuildModes BuildModes.SharedMatrixOptions.Count=',BuildModes.SharedMatrixOptions.Count]);
//for i:=0 to BuildModes.SharedMatrixOptions.Count-1 do
// debugln([' ',BuildModes.SharedMatrixOptions[i].AsString]);
end;
if (not LoadData) and (not LoadParts) then begin
// load matrix options of session
BuildModes.SessionMatrixOptions.LoadFromXMLConfig(XMLConfig,Path+'BuildModes/SessionMatrixOptions/');
// disable matrix options in session build modes
// ToDo:
// load what matrix options are enabled in session build modes
// ToDo:
//Cnt:=0;
//SubPath:=Path+'BuildModes/SessionMatrixOptions/';
SubPath:=Path+'BuildModes/SessionMatrixOptions/';
LoadSessionEnabledNonSessionMatrixOptions(XMLConfig,SubPath);
end;
// set active mode
@ -7324,6 +7371,20 @@ begin
end;
end;
function TProjectBuildModes.IsSessionMode(const ModeIdentifier: string
): boolean;
var
i: Integer;
BuildMode: TProjectBuildMode;
begin
for i:=0 to Count-1 do begin
BuildMode:=Items[i];
if SysUtils.CompareText(BuildMode.Identifier,ModeIdentifier)=0 then
exit(BuildMode.InSession);
end;
Result:=false;
end;
initialization
RegisterIDEOptionsGroup(GroupProject, TProject);
RegisterIDEOptionsGroup(GroupCompiler, TProjectCompilerOptions);

View File

@ -1935,7 +1935,7 @@ begin
// read project info file
{$IFDEF IDE_MEM_CHECK}CheckHeapWrtMemCnt('TLazSourceFileManager.OpenProjectFile B3');{$ENDIF}
Project1.ReadProject(AFilename);
Project1.ReadProject(AFilename,EnvironmentOptions.BuildMatrixOptions);
{$IFDEF IDE_MEM_CHECK}CheckHeapWrtMemCnt('TLazSourceFileManager.OpenProjectFile B4');{$ENDIF}
Result:=CompleteLoadingProjectInfo;
finally