IDE: Store defines added by user to compiler options. Works also for packages. Issue .

git-svn-id: trunk@50184 -
This commit is contained in:
juha 2015-10-27 17:30:48 +00:00
parent e16565eebb
commit e92ffb6dc2
6 changed files with 94 additions and 41 deletions

View File

@ -173,6 +173,7 @@ type
procedure SetTrashVariables(const AValue: Boolean);
procedure SetUncertainOpt(const AValue: Boolean);
procedure SetUseAnsiStr(const AValue: Boolean);
procedure SetUseCommentsInCustomOptions(AValue: Boolean);
procedure SetUseExternalDbgSyms(const AValue: Boolean);
procedure SetUseHeaptrc(const AValue: Boolean);
procedure SetUseLineInfoUnit(const AValue: Boolean);
@ -434,7 +435,8 @@ type
property CustomConfigFile: Boolean read fCustomConfigFile write SetCustomConfigFile;
property ConfigFilePath: String read fConfigFilePath write SetConfigFilePath;
property CustomOptions: string read GetCustomOptions write SetCustomOptions;
property UseCommentsInCustomOptions: Boolean read fUseCommentsInCustomOptions write fUseCommentsInCustomOptions;
property UseCommentsInCustomOptions: Boolean read fUseCommentsInCustomOptions
write SetUseCommentsInCustomOptions;
// execute other
procedure SetAlternativeCompile(const Command: string; ScanFPCMsgs: boolean); virtual; abstract; // disable normal compile and call this instead
@ -815,6 +817,13 @@ begin
IncreaseChangeStamp;
end;
procedure TLazCompilerOptions.SetUseCommentsInCustomOptions(AValue: Boolean);
begin
if fUseCommentsInCustomOptions=AValue then Exit;
fUseCommentsInCustomOptions:=AValue;
IncreaseChangeStamp;
end;
procedure TLazCompilerOptions.SetUseExternalDbgSyms(const AValue: Boolean);
begin
if FUseExternalDbgSyms=AValue then exit;

View File

@ -307,12 +307,11 @@ type
class function GetPrimaryConfigPath: String; virtual; abstract;
class function GetSecondaryConfigPath: String; virtual; abstract;
procedure CopySecondaryConfigFile(const AFilename: String); virtual; abstract;
procedure DoOpenIDEOptions(AEditor: TAbstractIDEOptionsEditorClass = nil;
ACaption: String = ''); overload;
procedure DoOpenIDEOptions(AEditor: TAbstractIDEOptionsEditorClass;
ACaption: String;
AOptionsFilter: array of TAbstractIDEOptionsClass;
ASettings: TIDEOptionsEditorSettings); overload; virtual; abstract;
function DoOpenIDEOptions(AEditor: TAbstractIDEOptionsEditorClass = nil;
ACaption: String = ''): Boolean; overload;
function DoOpenIDEOptions(AEditor: TAbstractIDEOptionsEditorClass;
ACaption: String; AOptionsFilter: array of TAbstractIDEOptionsClass;
ASettings: TIDEOptionsEditorSettings): Boolean; overload; virtual; abstract;
// filenames, paths
function CreateNewUniqueFilename(const Prefix, Ext: string;
@ -654,9 +653,10 @@ begin
Result:=DoNewFile(NewFileDescriptor,NewFilename,NewSource,NewFlags,nil);
end;
procedure TLazIDEInterface.DoOpenIDEOptions(AEditor: TAbstractIDEOptionsEditorClass; ACaption: String);
function TLazIDEInterface.DoOpenIDEOptions(AEditor: TAbstractIDEOptionsEditorClass;
ACaption: String): Boolean;
begin
DoOpenIDEOptions(AEditor, ACaption, [], []);
Result := DoOpenIDEOptions(AEditor, ACaption, [], []);
end;
procedure TLazIDEInterface.DoShowSearchResultsView(Show: boolean;

View File

@ -423,6 +423,7 @@ type
fInheritedOptParseStamps: integer;
FParsedOpts: TParsedCompilerOptions;
FStorePathDelim: TPathDelimSwitch;
FOtherDefines: TStrings; // list of user selectable defines for custom options
FFPCMsgFile: TFPCMsgFilePoolItem;
// other tools
@ -560,6 +561,7 @@ type
// stored properties
property StorePathDelim: TPathDelimSwitch read FStorePathDelim write FStorePathDelim;
property OtherDefines: TStrings read FOtherDefines;
// compilation
property CompilerPath: String read GetCompilerPath write SetCompilerPath;
@ -1093,6 +1095,7 @@ constructor TBaseCompilerOptions.Create(const AOwner: TObject;
begin
inherited Create(AOwner);
FParsedOpts := TParsedCompilerOptions.Create(Self);
FOtherDefines := TStringList.Create;
FExecuteBefore := AToolClass.Create(Self);
FExecuteBefore.OnChanged := @OnItemChanged;
FExecuteAfter := AToolClass.Create(Self);
@ -1118,6 +1121,7 @@ begin
FreeAndNil(fBuildMacros);
FreeThenNil(fExecuteBefore);
FreeThenNil(fExecuteAfter);
FreeThenNil(FOtherDefines);
FreeThenNil(FParsedOpts);
inherited Destroy;
end;
@ -1507,7 +1511,8 @@ var
var
b: boolean;
dit: TCompilerDbgSymbolType;
i: Integer;
i, Cnt: Integer;
s: String;
begin
{ Load the compiler options from the XML file }
p:=Path;
@ -1671,6 +1676,15 @@ begin
CustomOptions := LineBreaksToSystemLineBreaks(aXMLConfig.GetValue(p+'CustomOptions/Value', ''));
UseCommentsInCustomOptions := aXMLConfig.GetValue(p+'ConfigFile/UseCommentsInCustomOptions/Value', false);
FOtherDefines.Clear;
Cnt := aXMLConfig.GetValue(p+'OtherDefines/Count', 0);
for i := 0 to Cnt-1 do
begin
s := aXMLConfig.GetValue(p+'OtherDefines/Define'+IntToStr(i)+'/Value', '');
if s <> '' then
FOtherDefines.Add(s);
end;
{ Compilation }
CompilerPath := f(aXMLConfig.GetValue(p+'CompilerPath/Value',DefaultCompilerPath));
@ -1729,6 +1743,7 @@ var
var
P, s: string;
i: Integer;
begin
{ Save the compiler options to the XML file }
p:=Path;
@ -1852,6 +1867,11 @@ begin
LineBreaksToSystemLineBreaks(CustomOptions),''); // do not touch / \ characters
aXMLConfig.SetDeleteValue(p+'ConfigFile/UseCommentsInCustomOptions/Value', UseCommentsInCustomOptions,false);
for i:=0 to FOtherDefines.Count-1 do
aXMLConfig.SetDeleteValue(p+'OtherDefines/Define'+IntToStr(i)+'/Value',
FOtherDefines[i],'');
aXMLConfig.SetDeleteValue(p+'OtherDefines/Count',FOtherDefines.Count,0);
{ Compilation }
aXMLConfig.SetDeleteValue(p+'CompilerPath/Value', f(CompilerPath),DefaultCompilerPath);
ExecuteBefore.SaveToXMLConfig(aXMLConfig,p+'ExecuteBefore/',UsePathDelim);
@ -3396,6 +3416,7 @@ begin
ClearInheritedOptions;
ParsedOpts.Assign(CompOpts.ParsedOpts);
FStorePathDelim := CompOpts.FStorePathDelim;
FOtherDefines.Assign(CompOpts.FOtherDefines);
// compilation
CompilerPath := CompOpts.CompilerPath;
@ -3541,6 +3562,7 @@ begin
if Done(Tool.AddDiff('ConfigFilePath',fConfigFilePath,CompOpts.fConfigFilePath)) then exit;
if Done(Tool.AddDiff('StopAfterErrCount',fStopAfterErrCount,CompOpts.fStopAfterErrCount)) then exit;
if Done(Tool.AddDiff('CustomOptions',CustomOptions,CompOpts.CustomOptions)) then exit;
if Done(Tool.AddDiff('OtherDefines',OtherDefines.Text,CompOpts.OtherDefines.Text)) then exit;
// compilation
if Tool<>nil then Tool.Path:='Compilation';

View File

@ -31,7 +31,7 @@ uses
Classes, SysUtils, math, AVL_Tree, LazLogger, Forms, Controls, Graphics,
Dialogs, StdCtrls, ComCtrls, ExtCtrls, Buttons, LCLType, LazUTF8,
CodeToolsCfgScript, KeywordFuncLists, LazarusIDEStrConsts,
IDEOptionsIntf, CompOptsIntf, IDECommands, LazIDEIntf, Project, PackageDefs,
IDEOptionsIntf, CompOptsIntf, IDECommands, PackageDefs,
CompilerOptions, Compiler, AllCompilerOptions, DefinesGui,
EditorOptions, SynEdit, SynEditKeyCmds, SynCompletion, SourceSynEditor;
@ -62,6 +62,7 @@ type
FCompOptions: TBaseCompilerOptions;
FIdleConnected: Boolean;
FIsPackage: boolean;
FLocalOtherDefines: TStrings;
FCompletionHistory: TStrings;
FCompletionValues: TStrings;
FDefaultVariables: TCTCfgScriptVariables;
@ -157,11 +158,11 @@ begin
EditForm.OptionsReader := FOptionsReader;
EditForm.OptionsThread := FOptionsThread;
EditForm.CustomOptions := memoCustomOptions.Lines;
EditForm.DefinesCheckList.Items.Assign(Project1.OtherDefines);
EditForm.DefinesCheckList.Items.Assign(FLocalOtherDefines);
EditForm.UseComments := FUseComments;
if EditForm.ShowModal = mrOK then
begin
Project1.OtherDefines.Assign(EditForm.DefinesCheckList.Items);
FLocalOtherDefines.Assign(EditForm.DefinesCheckList.Items);
// Synchronize with custom options memo
EditForm.ToCustomOptions(memoCustomOptions.Lines);
memoCustomOptions.Invalidate;
@ -673,6 +674,7 @@ end;
constructor TCompilerOtherOptionsFrame.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
FLocalOtherDefines:=TStringList.Create;
FCompletionValues:=TStringList.Create;
FCompletionHistory:=TStringList.Create;
fDefaultVariables:=TCTCfgScriptVariables.Create;
@ -702,10 +704,11 @@ begin
IdleConnected:=false;
FreeAndNil(fOptionsThread);
FreeAndNil(FOptionsReader);
FreeAndNil(fEngine);
FreeAndNil(fDefaultVariables);
FreeAndNil(FCompletionHistory);
FreeAndNil(FCompletionValues);
FreeAndNil(fDefaultVariables);
FreeAndNil(fEngine);
FreeAndNil(FLocalOtherDefines);
inherited Destroy;
end;
@ -757,6 +760,7 @@ begin
memoCustomOptions.Text := FCompOptions.CustomOptions;
memoCustomOptions.OnChange(Nil);
FUseComments := FCompOptions.UseCommentsInCustomOptions;
FLocalOtherDefines.Assign(FCompOptions.OtherDefines);
UpdateStatusBar;
end;
@ -767,11 +771,13 @@ var
begin
//debugln(['TCompilerOtherOptionsFrame.WriteSettings ',DbgSName(AOptions)]);
CurOptions := AOptions as TBaseCompilerOptions;
with CurOptions do
CurOptions.Conditionals := CondSynEdit.Lines.Text;
CurOptions.CustomOptions := memoCustomOptions.Text;
CurOptions.UseCommentsInCustomOptions := FUseComments;
if not CurOptions.OtherDefines.Equals(FLocalOtherDefines) then
begin
Conditionals := CondSynEdit.Lines.Text;
CustomOptions := memoCustomOptions.Text;
UseCommentsInCustomOptions := FUseComments;
CurOptions.OtherDefines.Assign(FLocalOtherDefines);
CurOptions.IncreaseChangeStamp;
end;
end;

View File

@ -450,6 +450,7 @@ type
private
fBuilder: TLazarusBuilder;
function DoBuildLazarusSub(Flags: TBuildLazarusFlags): TModalResult;
procedure ProjectOptionsHelper(AFilter: array of TAbstractIDEOptionsClass);
// Global IDE events
procedure HandleProcessIDECommand(Sender: TObject; Command: word;
var Handled: boolean);
@ -471,9 +472,9 @@ type
// Environment options dialog events
procedure DoLoadIDEOptions(Sender: TObject; AOptions: TAbstractIDEOptions);
procedure DoSaveIDEOptions(Sender: TObject; AOptions: TAbstractIDEOptions);
procedure DoOpenIDEOptions(AEditor: TAbstractIDEOptionsEditorClass;
function DoOpenIDEOptions(AEditor: TAbstractIDEOptionsEditorClass;
ACaption: String; AOptionsFilter: array of TAbstractIDEOptionsClass;
ASettings: TIDEOptionsEditorSettings); override;
ASettings: TIDEOptionsEditorSettings): Boolean; override;
procedure DoEnvironmentOptionsBeforeRead(Sender: TObject);
procedure DoEnvironmentOptionsBeforeWrite(Sender: TObject; Restore: boolean);
@ -3509,11 +3510,6 @@ end;
{------------------------------------------------------------------------------}
procedure TMainIDE.mnuChgBuildModeClicked(Sender: TObject);
begin
DoOpenIDEOptions(TCompilerPathOptionsFrame, '', [TProjectCompilerOptions], []);
end;
function TMainIDE.CreateDesignerForComponent(AnUnitInfo: TUnitInfo;
AComponent: TComponent): TCustomForm;
var
@ -4097,16 +4093,38 @@ begin
OpenMainUnit(-1,-1,[]);
end;
procedure TMainIDE.mnuProjectOptionsClicked(Sender: TObject);
procedure TMainIDE.ProjectOptionsHelper(AFilter: array of TAbstractIDEOptionsClass);
var
Capt: String;
begin
if Project1=nil then exit;
DoOpenIDEOptions(nil, Format(dlgProjectOptionsFor, [Project1.GetTitleOrName]),
[TProjectIDEOptions, TProjectCompilerOptions], []);
// This is kind of a hack. Copy OtherDefines from project to current
// buildmode's compiler options and then back after they are modified.
// Only needed for projects, packages don't have buildmodes.
Project1.CompilerOptions.OtherDefines.Assign(Project1.OtherDefines);
Capt := Format(dlgProjectOptionsFor, [Project1.GetTitleOrName]);
if DoOpenIDEOptions(nil, Capt, AFilter, [])
and not Project1.OtherDefines.Equals(Project1.CompilerOptions.OtherDefines) then
begin
Project1.OtherDefines.Assign(Project1.CompilerOptions.OtherDefines);
Project1.Modified:=True;
end;
end;
procedure TMainIDE.mnuProjectOptionsClicked(Sender: TObject);
begin
ProjectOptionsHelper([TProjectIDEOptions, TProjectCompilerOptions]);
end;
procedure TMainIDE.mnuChgBuildModeClicked(Sender: TObject);
begin
ProjectOptionsHelper([TProjectCompilerOptions]);
end;
procedure TMainIDE.mnuBuildModeClicked(Sender: TObject);
begin
DoOpenIDEOptions(TCompilerPathOptionsFrame, '', [TProjectCompilerOptions], []);
ProjectOptionsHelper([TProjectCompilerOptions]);
end;
function TMainIDE.UpdateProjectPOFile(AProject: TProject): TModalResult;
@ -4648,9 +4666,9 @@ begin
SaveDesktopSettings(AOptions as TEnvironmentOptions);
end;
procedure TMainIDE.DoOpenIDEOptions(AEditor: TAbstractIDEOptionsEditorClass;
function TMainIDE.DoOpenIDEOptions(AEditor: TAbstractIDEOptionsEditorClass;
ACaption: String; AOptionsFilter: array of TAbstractIDEOptionsClass;
ASettings: TIDEOptionsEditorSettings);
ASettings: TIDEOptionsEditorSettings): Boolean;
var
IDEOptionsDialog: TIDEOptionsDialog;
OptionsFilter: TIDEOptionsEditorFilter;
@ -4668,8 +4686,7 @@ begin
else
OptionsFilter[0] := TAbstractIDEEnvironmentOptions;
end
else
begin
else begin
SetLength(OptionsFilter, Length(AOptionsFilter));
for i := 0 to Length(AOptionsFilter) - 1 do
OptionsFilter[i] := AOptionsFilter[i];
@ -4680,17 +4697,16 @@ begin
IDEOptionsDialog.OnLoadIDEOptionsHook:=@DoLoadIDEOptions;
IDEOptionsDialog.OnSaveIDEOptionsHook:=@DoSaveIDEOptions;
IDEOptionsDialog.ReadAll;
if IDEOptionsDialog.ShowModal = mrOk then begin
IDEOptionsDialog.WriteAll(false);
DebugLn(['TMainIDE.DoOpenIDEOptions: Options saved, updating Palette and TaskBar.']);
Result := IDEOptionsDialog.ShowModal = mrOk;
IDEOptionsDialog.WriteAll(not Result); // Restore if user cancelled.
if Result then
begin
DebugLn(['TMainIDE.DoOpenIDEOptions: Options saved, updating TaskBar.']);
// Update TaskBarBehavior immediately.
if EnvironmentOptions.Desktop.SingleTaskBarButton then
Application.TaskBarBehavior := tbSingleButton
else
Application.TaskBarBehavior := tbDefault;
end else begin
// restore
IDEOptionsDialog.WriteAll(true);
end;
finally
IDEOptionsDialog.Free;

View File

@ -2782,7 +2782,7 @@ begin
begin
s := FXMLConfig.GetValue(Path+SubPath+'Define'+IntToStr(i)+'/Value', '');
if s <> '' then
OtherDefines.Add(s);
FOtherDefines.Add(s);
end;
end;