Merged revision(s) 51059 #42e68fd86d, 51080 #2a49eb46bc, 51084 #0a7cc81dde, 51105 #476bc7e244 from trunk:

IDE: Save Application Bundle and resource XPManifest to default project configuration. Issue #22286.
........
LazBuild: Fix compilation after r51059 #42e68fd86d. Issue #29274.
........
IDE: Enable "Make Resource String" command also when cursor is behind an end-quote. Issue #28829.
........
IDE: Remove explicit update of Messages window from TMainIDE.StartIDE. It deserves no special treatment layout-wise.
........

git-svn-id: branches/fixes_1_6@51148 -
This commit is contained in:
maxim 2016-01-03 12:28:36 +00:00
parent 6e20c18b2d
commit a47a2dffda
10 changed files with 139 additions and 91 deletions

View File

@ -18,10 +18,13 @@ type
{ TAbstractProjectResource }
TAbstractProjectResource = class
protected
private
FModified: boolean;
FOnModified: TNotifyEvent;
procedure SetModified(const AValue: boolean);
protected
// This resource is used when reading project default options.
FIsDefaultOption: Boolean;
public
constructor Create; virtual;
@ -33,6 +36,7 @@ type
property Modified: boolean read FModified write SetModified;
property OnModified: TNotifyEvent read FOnModified write FOnModified;
property IsDefaultOption: Boolean read FIsDefaultOption;
end;
TAbstractProjectResourceClass = class of TAbstractProjectResource;

View File

@ -974,6 +974,7 @@ type
function GetHighlighterAttriAtRowColEx(XY: TPoint; out Token: string;
out TokenType, Start: Integer;
out Attri: TSynHighlighterAttributes): boolean; //L505
procedure CaretAtIdentOrString(XY: TPoint; out AtIdent, NearString: Boolean);
procedure GetWordBoundsAtRowCol(const XY: TPoint; out StartX, EndX: integer);
function GetWordAtRowCol(XY: TPoint): string;
function NextTokenPos: TPoint; virtual; deprecated; // use next word pos instead
@ -8830,8 +8831,7 @@ begin
if (PosX >= Start) and (PosX < Start + Length(Token)) then begin
Attri := Highlighter.GetTokenAttribute;
TokenType := Highlighter.GetTokenKind;
Result := TRUE;
exit;
exit(True);
end;
Highlighter.Next;
end;
@ -8840,7 +8840,53 @@ begin
Token := '';
Attri := nil;
TokenType := -1;
Result := FALSE;
Result := False;
end;
procedure TCustomSynEdit.CaretAtIdentOrString(XY: TPoint; out AtIdent, NearString: Boolean);
// This is optimized to check if cursor is on identifier or string.
var
PosX, PosY: integer;
Line, Token: string;
Start: Integer;
Attri, PrevAttri: TSynHighlighterAttributes;
begin
PosY := XY.Y -1;
PrevAttri := nil;
AtIdent := False;
NearString := False;
//DebugLn('');
//DebugLn('TCustomSynEdit.CaretAtIdentOrString: Enter');
if Assigned(Highlighter) and (PosY >= 0) and (PosY < FTheLinesView.Count) then
begin
Line := FTheLinesView[PosY];
fHighlighter.CurrentLines := FTheLinesView;
Highlighter.StartAtLineIndex(PosY);
PosX := XY.X;
//DebugLn([' TCustomSynEdit.CaretAtIdentOrString: Line="', Line, '", PosX=', PosX, ', PosY=', PosY]);
if (PosX > 0) and (PosX <= Length(Line)) then
begin
while not Highlighter.GetEol do
begin
Start := Highlighter.GetTokenPos + 1;
Token := Highlighter.GetToken;
//TokenType := Highlighter.GetTokenKind;
Attri := Highlighter.GetTokenAttribute;
//DebugLn([' TCustomSynEdit.CaretAtIdentOrString: Start=', Start, ', Token=', Token]);
if (PosX >= Start) and (PosX < Start + Length(Token)) then
begin
AtIdent := Attri = Highlighter.IdentifierAttribute;
NearString := (Attri = Highlighter.StringAttribute)
or (PrevAttri = Highlighter.StringAttribute); // If cursor is on end-quote.
//DebugLn([' TCustomSynEdit.CaretAtIdentOrString: Success! Attri=', Attri,
// ', AtIdent=', AtIdent, ', AtString=', AtString]);
exit;
end;
PrevAttri := Attri;
Highlighter.Next;
end;
end;
end;
end;
function TCustomSynEdit.IdentChars: TSynIdentChars;

View File

@ -255,10 +255,13 @@ begin
begin
TitleEdit.Text := Title;
UseAppBundleCheckBox.Checked := UseAppBundle;
UseXPManifestCheckBox.Checked := TProjectXPManifest(ProjResources[TProjectXPManifest]).UseManifest;
DpiAwareCheckBox.Checked := TProjectXPManifest(ProjResources[TProjectXPManifest]).DpiAware;
ExecutionLevelComboBox.ItemIndex := Ord(TProjectXPManifest(ProjResources[TProjectXPManifest]).ExecutionLevel);
UIAccessCheckBox.Checked := TProjectXPManifest(ProjResources[TProjectXPManifest]).UIAccess;
with ProjResources.XPManifest do
begin
UseXPManifestCheckBox.Checked := UseManifest;
DpiAwareCheckBox.Checked := DpiAware;
ExecutionLevelComboBox.ItemIndex := Ord(ExecutionLevel);
UIAccessCheckBox.Checked := UIAccess;
end;
DpiAwareCheckBox.Enabled := UseXPManifestCheckBox.Checked;
ExecutionLevelLabel.Enabled := UseXPManifestCheckBox.Checked;
ExecutionLevelComboBox.Enabled := UseXPManifestCheckBox.Checked;

View File

@ -1585,7 +1585,6 @@ begin
Application.Terminate;
exit;
end;
DoShowMessagesView(false); // reopen extra windows
fUserInputSinceLastIdle:=true; // Idle work gets done initially before user action.
MainIDEBar.ApplicationIsActivate:=true;
IDECommandList.AddCustomUpdateEvent(@UpdateMainIDECommands);
@ -3625,10 +3624,9 @@ var
Editable: Boolean;
SelAvail: Boolean;
SelEditable: Boolean;
SrcEditorActive, DsgEditorActive, StringFound, IdentFound: Boolean;
SrcEditorActive, DsgEditorActive, IdentFound, StringFound: Boolean;
ActiveDesigner: TComponentEditorDesigner;
xAttr: TSynHighlighterAttributes;
xToken, CurWordAtCursor: string;
CurWordAtCursor: string;
begin
GetCurrentUnit(ASrcEdit, AnUnitInfo);
if not UpdateEditorCommandsStamp.Changed(ASrcEdit, DisplayState) then
@ -3641,18 +3639,16 @@ begin
DsgEditorActive := DisplayState = dsForm;
ActiveDesigner := GetActiveDesignerSkipMainBar;
StringFound := False;
IdentFound := False;
CurWordAtCursor := '';
if ASrcEdit<>nil then
begin
CurWordAtCursor := ASrcEdit.GetWordAtCurrentCaret;
//it is faster to get information from SynEdit than from CodeTools
if ASrcEdit.EditorComponent.GetHighlighterAttriAtRowCol(ASrcEdit.EditorComponent.CaretXY, xToken, xAttr) then
begin
StringFound := xAttr = ASrcEdit.EditorComponent.Highlighter.StringAttribute;
IdentFound := xAttr = ASrcEdit.EditorComponent.Highlighter.IdentifierAttribute;
end;
ASrcEdit.EditorComponent.CaretAtIdentOrString(ASrcEdit.EditorComponent.CaretXY, IdentFound, StringFound);
end
else begin
CurWordAtCursor := '';
IdentFound := False;
StringFound := False;
end;
if Assigned(ActiveDesigner) then

View File

@ -817,19 +817,9 @@ begin
AFilename:=AppendPathDelim(GetPrimaryConfigPath)+DefaultProjectOptionsFilename;
if not FileExistsUTF8(AFilename) then
CopySecondaryConfigFile(DefaultProjectOptionsFilename);
if FileExistsUTF8(AFilename) then begin
if AProject.ReadProject(AFilename,nil,True)<>mrOk then
if FileExistsUTF8(AFilename) then
if AProject.ReadProject(AFilename,nil,False)<>mrOk then
DebugLn(['TMainIDEBase.DoLoadDefaultCompilerOptions failed']);
end else begin
// old way (<0.9.31)
// load default compiler options if exists
AFilename:=AppendPathDelim(GetPrimaryConfigPath)+DefaultProjectCompilerOptionsFilename;
if not FileExistsUTF8(AFilename) then
CopySecondaryConfigFile(DefaultProjectCompilerOptionsFilename);
if not FileExistsUTF8(AFilename) then exit;
if AProject.CompilerOptions.LoadFromFile(AFilename)<>mrOk then
DebugLn(['TMainIDEBase.DoLoadDefaultCompilerOptions failed']);
end;
// change target file name
AFilename:=ExtractFileName(AProject.CompilerOptions.TargetFilename);

View File

@ -655,7 +655,7 @@ type
// load, save
procedure LoadProjOptsFromXMLConfig(XMLConfig: TXMLConfig; const Path: string);
procedure LoadSessionFromXMLConfig(XMLConfig: TXMLConfig; const Path: string;
LoadParts: boolean);
LoadAllOptions: boolean);
procedure SaveProjOptsToXMLConfig(XMLConfig: TXMLConfig; const Path: string;
SaveSession: boolean);
procedure SaveSessionOptsToXMLConfig(XMLConfig: TXMLConfig; const Path: string;
@ -762,7 +762,7 @@ type
FUseAsDefault: Boolean;
// Variables used by ReadProject / WriteProject
FXMLConfig: TXMLConfig;
FLoadParts: Boolean;
FLoadAllOptions: Boolean; // All options / just options used as default for new projects
FFileVersion: Integer;
FNewMainUnitID: LongInt;
FProjectWriteFlags: TProjectWriteFlags;
@ -888,10 +888,10 @@ type
procedure IgnoreProjectInfoFileOnDisk;
function ReadProject(const NewProjectInfoFile: string;
GlobalMatrixOptions: TBuildMatrixOptions;
LoadParts: Boolean = False): TModalResult;
LoadAllOptions: Boolean = True): TModalResult;
function WriteProject(ProjectWriteFlags: TProjectWriteFlags;
const OverrideProjectInfoFile: string;
GlobalMatrixOptions: TBuildMatrixOptions): TModalResult;
GlobalMatrixOptions: TBuildMatrixOptions): TModalResult;
procedure UpdateExecutableType; override;
procedure BackupSession;
procedure RestoreSession;
@ -2853,7 +2853,6 @@ begin
// automatically fixes broken lpi files.
FNewMainUnitID := FXMLConfig.GetValue(Path+'General/MainUnit/Value', 0);
Title := FXMLConfig.GetValue(Path+'General/Title/Value', '');
UseAppBundle := FXMLConfig.GetValue(Path+'General/UseAppBundle/Value', True);
AutoCreateForms := FXMLConfig.GetValue(Path+'General/AutoCreateForms/Value', true);
// fpdoc
@ -2873,9 +2872,6 @@ begin
end;
{$IFDEF IDE_MEM_CHECK}CheckHeapWrtMemCnt('TProject.ReadProject E reading comp sets');{$ENDIF}
// Resources
ProjResources.ReadFromProjectFile(FXMLConfig, Path);
// load custom data
LoadStringToStringTree(FXMLConfig,CustomData,Path+'CustomData/');
{$IFDEF IDE_MEM_CHECK}CheckHeapWrtMemCnt('TProject.ReadProject update ct boss');{$ENDIF}
@ -2911,7 +2907,7 @@ begin
FFileVersion:=FXMLConfig.GetValue(Path+'Version/Value',0);
// load MacroValues and compiler options
BuildModes.LoadSessionFromXMLConfig(FXMLConfig, Path, FLoadParts);
BuildModes.LoadSessionFromXMLConfig(FXMLConfig, Path, FLoadAllOptions);
// load defines used for custom options
LoadOtherDefines(Path);
@ -2928,21 +2924,8 @@ var
PIFile: String;
begin
Result:=mrOk;
if FLoadParts then begin
// read only parts of the lpi, keep other values
try
FXMLConfig := TCodeBufXMLConfig.CreateWithCache(Filename,true)
except
on E: Exception do begin
IDEMessageDialog(lisUnableToReadLpi,
Format(lisUnableToReadTheProjectInfoFile,[LineEnding,Filename])+LineEnding+E.Message,
mtError, [mbOk]);
Result:=mrCancel;
exit;
end;
end;
end
else begin
if FLoadAllOptions then
begin
// read the whole lpi, clear any old values
Clear;
ProjectInfoFile:=Filename;
@ -2972,6 +2955,20 @@ begin
fLastReadLPIFilename:=PIFile;
fLastReadLPIFileDate:=Now;
FNewMainUnitID:=-1;
end
else begin
// read only parts of the lpi, keep other values
try
FXMLConfig := TCodeBufXMLConfig.CreateWithCache(Filename,true)
except
on E: Exception do begin
IDEMessageDialog(lisUnableToReadLpi,
Format(lisUnableToReadTheProjectInfoFile,[LineEnding,Filename])+LineEnding+E.Message,
mtError, [mbOk]);
Result:=mrCancel;
exit;
end;
end;
end;
try
@ -2981,8 +2978,11 @@ begin
fCurStorePathDelim:=StorePathDelim;
{$IFDEF IDE_MEM_CHECK}CheckHeapWrtMemCnt('TProject.ReadProject C reading values');{$ENDIF}
FFileVersion:= FXMLConfig.GetValue(ProjOptionsPath+'Version/Value',0);
if not FLoadParts then
UseAppBundle := FXMLConfig.GetValue(ProjOptionsPath+'General/UseAppBundle/Value', True);
if FLoadAllOptions then
LoadFromLPI;
// Resources
ProjResources.ReadFromProjectFile(FXMLConfig, ProjOptionsPath, FLoadAllOptions);
// load MacroValues and compiler options
ClearBuildModes;
BuildModes.LoadProjOptsFromXMLConfig(FXMLConfig, ProjOptionsPath);
@ -3033,13 +3033,13 @@ end;
// Method ReadProject itself
function TProject.ReadProject(const NewProjectInfoFile: string;
GlobalMatrixOptions: TBuildMatrixOptions; LoadParts: Boolean): TModalResult;
GlobalMatrixOptions: TBuildMatrixOptions; LoadAllOptions: Boolean): TModalResult;
begin
Result := mrCancel;
BeginUpdate(true);
try
BuildModes.FGlobalMatrixOptions := GlobalMatrixOptions;
FLoadParts := LoadParts;
FLoadAllOptions := LoadAllOptions;
// load project lpi file
Result:=DoLoadLPI(NewProjectInfoFile);
@ -3048,7 +3048,7 @@ begin
// load session file (if available)
if (SessionStorage in pssHasSeparateSession)
and (CompareFilenames(ProjectInfoFile,ProjectSessionFile)<>0)
and not FLoadParts then
and FLoadAllOptions then
begin
Result:=DoLoadSession(ProjectSessionFile);
if Result<>mrOK then Exit;
@ -3195,7 +3195,8 @@ begin
// save lpi to disk
//debugln(['TProject.WriteProject ',DbgSName(FXMLConfig),' FCfgFilename=',FCfgFilename]);
FXMLConfig.Flush;
Modified:=false;
if not (pwfIgnoreModified in FProjectWriteFlags) then
Modified:=false;
if FSaveSessionInLPI then
SessionModified:=false;
end;
@ -3310,8 +3311,12 @@ begin
FSaveSessionInLPI:=(SessFilename='') or (CompareFilenames(SessFilename,CfgFilename)=0);
// check if modified
if not (pwfIgnoreModified in ProjectWriteFlags) then
if pwfIgnoreModified in ProjectWriteFlags then
begin
WriteLPI:=true;
WriteLPS:=true;
end
else begin
WriteLPI:=SomeDataModified or (not FileExistsUTF8(CfgFilename));
if (CompareFilenames(ProjectInfoFile,CfgFilename)=0) then
// save to default lpi
@ -3325,10 +3330,7 @@ begin
end else begin
WriteLPS:=WriteLPI or SomeSessionModified or (not FileExistsUTF8(SessFilename));
end;
if (not WriteLPI) and (not WriteLPS) then exit(mrOk);
end else begin
WriteLPI:=true;
WriteLPS:=true;
if not (WriteLPI or WriteLPS) then exit(mrOk);
end;
//debugln(['TProject.WriteProject WriteLPI=',WriteLPI,' WriteLPS=',WriteLPS,' Modifed=',Modified,' SessionModified=',SessionModified]);
@ -3783,12 +3785,12 @@ end;
function TProject.GetUseManifest: boolean;
begin
Result:=TProjectXPManifest(ProjResources[TProjectXPManifest]).UseManifest;
Result:=ProjResources.XPManifest.UseManifest;
end;
procedure TProject.SetUseManifest(AValue: boolean);
begin
TProjectXPManifest(ProjResources[TProjectXPManifest]).UseManifest:=AValue;
ProjResources.XPManifest.UseManifest:=AValue;
end;
function TProject.UnitCount:integer;
@ -7108,14 +7110,14 @@ begin
end;
procedure TProjectBuildModes.LoadSessionFromXMLConfig(XMLConfig: TXMLConfig;
const Path: string; LoadParts: boolean);
const Path: string; LoadAllOptions: boolean);
// Load for session
var
Cnt: Integer;
begin
FXMLConfig := XMLConfig;
if not LoadParts then
if LoadAllOptions then
// load matrix options
SessionMatrixOptions.LoadFromXMLConfig(FXMLConfig, Path+'BuildModes/SessionMatrixOptions/');
@ -7126,7 +7128,7 @@ begin
LoadAllMacroValues(Path+'MacroValues/', Cnt);
end;
if not LoadParts then
if LoadAllOptions then
// load what matrix options are enabled in session build modes
LoadSessionEnabledNonSessionMatrixOptions(Path+'BuildModes/SessionEnabledMatrixOptions/');

View File

@ -1260,8 +1260,7 @@ begin
Result := GetLocalizedName + LineEnding+LineEnding + lisApplicationProgramDescriptor;
end;
function TProjectApplicationDescriptor.InitProject(
AProject: TLazProject): TModalResult;
function TProjectApplicationDescriptor.InitProject(AProject: TLazProject): TModalResult;
var
NewSource: String;
MainFile: TLazProjectFile;

View File

@ -37,14 +37,22 @@ unit ProjectResources;
interface
uses
Classes, SysUtils, Contnrs, Controls, LCLProc, LResources, LazFileUtils,
Dialogs, AvgLvlTree, Laz2_XMLCfg, resource, reswriter,
// RTL + LCL
Classes, SysUtils, Contnrs, resource, reswriter, fgl,
Controls, LCLProc, LResources, Dialogs,
// LazUtils
LazFileUtils, AvgLvlTree, Laz2_XMLCfg,
// Codetools
KeywordFuncLists, BasicCodeTools, CodeToolManager, CodeCache,
// IdeIntf
ProjectIntf, ProjectResourcesIntf, CompOptsIntf,
// IDE
LazarusIDEStrConsts, IDEProcs, DialogProcs,
W32Manifest, W32VersionInfo, ProjectIcon, ProjectUserResources;
type
TResourceList = specialize TFPGObjectList<TAbstractProjectResource>;
{ TProjectResources }
TProjectResources = class(TAbstractProjectResources)
@ -54,7 +62,7 @@ type
FInModified: Boolean;
FLrsIncludeAllowed: Boolean;
FResources: TObjectList;
FResources: TResourceList;
FSystemResources: TResources;
FLazarusResources: TStringList;
@ -100,7 +108,7 @@ type
function HasLazarusResources: Boolean;
procedure WriteToProjectFile(AConfig: TXMLConfig; Path: String);
procedure ReadFromProjectFile(AConfig: TXMLConfig; Path: String);
procedure ReadFromProjectFile(AConfig: TXMLConfig; Path: String; ReadAll: Boolean);
property Modified: Boolean read FModified write SetModified;
property OnModified: TNotifyEvent read FOnModified write FOnModified;
@ -377,7 +385,7 @@ begin
if not FModified then
begin
for i := 0 to FResources.Count - 1 do
TAbstractProjectResource(FResources[i]).Modified := False;
FResources[i].Modified := False;
end;
if Assigned(FOnModified) then
OnModified(Self);
@ -388,16 +396,14 @@ end;
function TProjectResources.Update: Boolean;
var
i: integer;
Res: TAbstractProjectResource;
begin
Result:=true;
Clear;
for i := 0 to FResources.Count - 1 do
begin
Res:=TAbstractProjectResource(FResources[i]);
Result := Res.UpdateResources(Self, resFileName);
Result := FResources[i].UpdateResources(Self, resFileName);
if not Result then begin
debugln(['TProjectResources.Update UpdateResources of ',DbgSName(Res),' failed']);
debugln(['TProjectResources.Update UpdateResources of ',DbgSName(FResources[i]),' failed']);
Exit;
end;
end;
@ -423,7 +429,7 @@ begin
FSystemResources := TResources.Create;
FLazarusResources := TStringList.Create;
FResources := TObjectList.Create;
FResources := TResourceList.Create;
L := GetRegisteredResources;
for i := 0 to L.Count - 1 do
begin
@ -470,7 +476,7 @@ var
begin
for i := 0 to FResources.Count - 1 do
begin
Result := TAbstractProjectResource(FResources[i]);
Result := FResources[i];
if Result.InheritsFrom(AIndex) then
Exit;
end;
@ -482,7 +488,7 @@ var
i: integer;
begin
for i := 0 to FResources.Count - 1 do
TAbstractProjectResource(FResources[i]).DoAfterBuild(Self, AReason, SaveToTestDir);
FResources[i].DoAfterBuild(Self, AReason, SaveToTestDir);
end;
procedure TProjectResources.DoBeforeBuild(AReason: TCompileReason; SaveToTestDir: boolean);
@ -490,7 +496,7 @@ var
i: integer;
begin
for i := 0 to FResources.Count - 1 do
TAbstractProjectResource(FResources[i]).DoBeforeBuild(Self, AReason, SaveToTestDir);
FResources[i].DoBeforeBuild(Self, AReason, SaveToTestDir);
end;
procedure TProjectResources.Clear;
@ -558,16 +564,17 @@ var
begin
AConfig.SetDeleteValue(Path+'General/ResourceType/Value', ResourceTypeNames[ResourceType], ResourceTypeNames[rtLRS]);
for i := 0 to FResources.Count - 1 do
TAbstractProjectResource(FResources[i]).WriteToProjectFile(AConfig, Path);
FResources[i].WriteToProjectFile(AConfig, Path);
end;
procedure TProjectResources.ReadFromProjectFile(AConfig: TXMLConfig; Path: String);
procedure TProjectResources.ReadFromProjectFile(AConfig: TXMLConfig; Path: String; ReadAll: Boolean);
var
i: integer;
begin
ResourceType := StrToResourceType(AConfig.GetValue(Path+'General/ResourceType/Value', ResourceTypeNames[rtLRS]));
for i := 0 to FResources.Count - 1 do
TAbstractProjectResource(FResources[i]).ReadFromProjectFile(AConfig, Path);
if ReadAll or FResources[i].IsDefaultOption then
FResources[i].ReadFromProjectFile(AConfig, Path);
end;
function TProjectResources.UpdateMainSourceFile(const AFileName: string): Boolean;

View File

@ -3601,7 +3601,7 @@ begin
// read project info file
{$IFDEF IDE_MEM_CHECK}CheckHeapWrtMemCnt('TLazSourceFileManager.InitOpenedProjectFile B3');{$ENDIF}
Project1.ReadProject(AFilename,EnvironmentOptions.BuildMatrixOptions);
Project1.ReadProject(AFilename, EnvironmentOptions.BuildMatrixOptions, True);
{$IFDEF IDE_MEM_CHECK}CheckHeapWrtMemCnt('TLazSourceFileManager.InitOpenedProjectFile B4');{$ENDIF}
Result:=CompleteLoadingProjectInfo;
finally
@ -3626,7 +3626,7 @@ begin
// restore files
while EditorInfoIndex < Project1.AllEditorsInfoCount do begin
// TProject.ReadProject sorts alle UnitEditorInfos
// TProject.ReadProject sorts all UnitEditorInfos
AnEditorInfo := Project1.AllEditorsInfo[EditorInfoIndex];
AnUnitInfo := AnEditorInfo.UnitInfo;
if (not AnUnitInfo.Loaded) or (AnEditorInfo.PageIndex < 0) then begin

View File

@ -152,6 +152,7 @@ end;
constructor TProjectXPManifest.Create;
begin
inherited Create;
FIsDefaultOption := True;
UseManifest := False;
DpiAware := False;
ExecutionLevel := xmelAsInvoker;