IDE: moved macros save/saveall to source editor

git-svn-id: trunk@36514 -
This commit is contained in:
mattias 2012-04-02 08:06:52 +00:00
parent 6f76486093
commit 87d9c6bb13
4 changed files with 62 additions and 54 deletions

View File

@ -62,6 +62,10 @@ type
private
CurrentParsedCompilerOption: TParsedCompilerOptions;
FUnitSetCache: TFPCUnitSetCache;
procedure OnMacroSubstitution(TheMacro: TTransferMacro;
const MacroName: string; var s: string;
const Data: PtrInt; var Handled, Abort: boolean;
Depth: integer);
function OnSubstituteCompilerOption(Options: TParsedCompilerOptions;
const UnparsedValue: string;
PlatformIndependent: boolean): string;
@ -240,6 +244,22 @@ end;
{ TBuildManager }
procedure TBuildManager.OnMacroSubstitution(TheMacro: TTransferMacro;
const MacroName: string; var s: string; const Data: PtrInt; var Handled,
Abort: boolean; Depth: integer);
begin
if TheMacro=nil then begin
DebugLn('WARNING: Macro not defined: "'+MacroName+'".');
{$IFDEF VerboseMacroNotDefined}
DumpStack;
{$ENDIF}
s:='';
//IDEMessageDlg('Unknown Macro','Macro not defined: "'+s+'".',mtError,[mbAbort],0);
Handled:=true;
exit;
end;
end;
function TBuildManager.OnSubstituteCompilerOption(
Options: TParsedCompilerOptions; const UnparsedValue: string;
PlatformIndependent: boolean): string;
@ -288,6 +308,7 @@ procedure TBuildManager.SetupTransferMacros;
begin
LazConfMacroFunc:=@BMLazConfMacroFunction;
GlobalMacroList:=TTransferMacroList.Create;
GlobalMacroList.OnSubstitution:=@OnMacroSubstitution;
IDEMacros:=TLazIDEMacros.Create;
CompilerOptions.OnParseString:=@OnSubstituteCompilerOption;

View File

@ -695,7 +695,6 @@ type
procedure SetupObjectInspector;
procedure SetupFormEditor;
procedure SetupSourceNotebook;
procedure SetupTransferMacros;
procedure SetupCodeMacros;
procedure SetupControlSelection;
procedure SetupIDECommands;
@ -862,7 +861,7 @@ type
OpenFlags: TOpenFlags): TModalResult; override;
procedure BeginFixupComponentReferences;
procedure EndFixupComponentReferences;
function DoSaveAll(Flags: TSaveFlags): TModalResult;
function DoSaveAll(Flags: TSaveFlags): TModalResult; override;
procedure DoRestart;
procedure DoExecuteRemoteControl;
function DoOpenMainUnit(PageIndex, WindowIndex: integer; Flags: TOpenFlags): TModalResult;
@ -1080,10 +1079,6 @@ type
// methods for debugging, compiling and external tools
function GetTestBuildDirectory: string; override;
procedure OnMacroSubstitution(TheMacro: TTransferMacro;
const MacroName: string; var s: string;
const Data: PtrInt; var Handled, Abort: boolean;
Depth: integer);
procedure GetIDEFileState(Sender: TObject; const AFilename: string;
NeededFlags: TIDEFileStateFlags; out ResultFlags: TIDEFileStateFlags); override;
@ -1391,7 +1386,7 @@ begin
MainBuildBoss.HasGUI:=true;
{$IFDEF IDE_MEM_CHECK}CheckHeapWrtMemCnt('TMainIDE.Create BUILD MANAGER');{$ENDIF}
// setup macros before loading options
SetupTransferMacros;
MainBuildBoss.SetupTransferMacros;
// load options
CreatePrimaryConfigPath;
@ -1403,7 +1398,7 @@ begin
// set the IDE mode to none (= editing mode)
ToolStatus:=itNone;
// setup macros
// setup code templates
SetupCodeMacros;
// setup the code tools
@ -2129,18 +2124,6 @@ begin
SourceEditorManager.InitMacros(GlobalMacroList);
end;
procedure TMainIDE.SetupTransferMacros;
begin
MainBuildBoss.SetupTransferMacros;
GlobalMacroList.OnSubstitution:=@OnMacroSubstitution;
// source editor
GlobalMacroList.Add(TTransferMacro.Create('Save','',
lisSaveCurrentEditorFile,nil,[tmfInteractive]));
GlobalMacroList.Add(TTransferMacro.Create('SaveAll','',
lisSaveAllModified,nil,[tmfInteractive]));
end;
procedure TMainIDE.SetupCodeMacros;
begin
CreateStandardCodeMacros;
@ -13808,35 +13791,6 @@ begin
FDisplayState:= dsSource;
end;
procedure TMainIDE.OnMacroSubstitution(TheMacro: TTransferMacro;
const MacroName: string; var s:string;
const Data: PtrInt; var Handled, Abort: boolean; Depth: integer);
var MacroLName:string;
begin
if TheMacro=nil then begin
DebugLn('WARNING: Macro not defined: "'+MacroName+'".');
{$IFDEF VerboseMacroNotDefined}
DumpStack;
{$ENDIF}
s:='';
//MessageDlg('Unknown Macro','Macro not defined: "'+s+'".',mtError,[mbAbort],0);
Handled:=true;
exit;
end;
MacroLName:=lowercase(MacroName);
Handled:=true;
if MacroLName='save' then begin
if (SourceEditorManager<>nil) and (SourceEditorManager.SourceEditorCount > 0) then
Abort:=(DoSaveEditorFile(SourceEditorManager.ActiveEditor,
[sfCheckAmbiguousFiles]) <> mrOk);
s:='';
end else if MacroLName='saveall' then begin
Abort:=(DoSaveAll([sfCheckAmbiguousFiles])<>mrOk);
s:='';
end else
Handled:=false;
end;
procedure TMainIDE.GetIDEFileState(Sender: TObject; const AFilename: string;
NeededFlags: TIDEFileStateFlags; out ResultFlags: TIDEFileStateFlags);
var
@ -14826,19 +14780,28 @@ begin
if InteractiveSetup then
begin
if (not ShowSetupDialog)
and ((CheckLazarusDirectoryQuality(EnvironmentOptions.GetParsedLazarusDirectory,Note)<>sddqCompatible)
or (CheckCompilerQuality(EnvironmentOptions.GetParsedCompilerFilename,Note,
CodeToolBoss.FPCDefinesCache.TestFilename)=sddqInvalid))
then
and (CheckLazarusDirectoryQuality(EnvironmentOptions.GetParsedLazarusDirectory,Note)<>sddqCompatible)
then begin
debugln(['Warning: incompatible Lazarus directory: ',EnvironmentOptions.GetParsedLazarusDirectory]);
ShowSetupDialog:=true;
end;
if (not ShowSetupDialog)
and (CheckCompilerQuality(EnvironmentOptions.GetParsedCompilerFilename,Note,
CodeToolBoss.FPCDefinesCache.TestFilename)=sddqInvalid)
then begin
debugln(['Warning: invalid compiler: ',EnvironmentOptions.GetParsedCompilerFilename]);
ShowSetupDialog:=true;
end;
if (not ShowSetupDialog) then
begin
CfgCache:=CodeToolBoss.FPCDefinesCache.ConfigCaches.Find(
EnvironmentOptions.GetParsedCompilerFilename,'','','',true);
if CheckFPCSrcDirQuality(EnvironmentOptions.GetParsedFPCSourceDirectory,Note,
CfgCache.GetFPCVer)=sddqInvalid
then
then begin
debugln(['Warning: invalid fpc source directory: ',EnvironmentOptions.GetParsedFPCSourceDirectory]);
ShowSetupDialog:=true;
end;
end;
if ShowSetupDialog then
if ShowInitialSetupDialog<>mrOk then

View File

@ -1017,6 +1017,10 @@ type
var Abort: boolean): string;
function MacroFuncPrompt(const s:string; const Data: PtrInt;
var Abort: boolean): string;
function MacroFuncSave(const s:string; const Data: PtrInt;
var Abort: boolean): string;
function MacroFuncSaveAll(const s:string; const Data: PtrInt;
var Abort: boolean): string;
public
procedure InitMacros(AMacroList: TTransferMacroList);
procedure SetupShortCuts;
@ -8943,6 +8947,21 @@ begin
Abort:=(ShowMacroPromptDialog(Result)<>mrOk);
end;
function TSourceEditorManager.MacroFuncSave(const s: string;
const Data: PtrInt; var Abort: boolean): string;
begin
Result:='';
if SourceEditorCount > 0 then
Abort:=LazarusIDE.DoSaveEditorFile(ActiveEditor,[sfCheckAmbiguousFiles]) <> mrOk;
end;
function TSourceEditorManager.MacroFuncSaveAll(const s: string;
const Data: PtrInt; var Abort: boolean): string;
begin
Result:='';
Abort:=LazarusIDE.DoSaveAll([sfCheckAmbiguousFiles])<>mrOk;
end;
procedure TSourceEditorManager.InitMacros(AMacroList: TTransferMacroList);
begin
AMacroList.Add(TTransferMacro.Create('Col','',
@ -8955,6 +8974,10 @@ begin
lisExpandedFilenameOfCurrentEditor,@MacroFuncEdFile,[]));
AMacroList.Add(TTransferMacro.Create('Prompt','',
lisPromptForValue,@MacroFuncPrompt,[tmfInteractive]));
AMacroList.Add(TTransferMacro.Create('Save','',
lisSaveCurrentEditorFile,@MacroFuncSave,[tmfInteractive]));
AMacroList.Add(TTransferMacro.Create('SaveAll','',
lisSaveAllModified,@MacroFuncSaveAll,[tmfInteractive]));
end;
procedure TSourceEditorManager.SetupShortCuts;

View File

@ -201,6 +201,7 @@ type
deprecated {$IFDEF VER2_5}'use method with EditorObject'{$ENDIF}; // deprecated in 0.9.29 March 2010
function DoSaveEditorFile(AEditor: TSourceEditorInterface;
Flags: TSaveFlags): TModalResult; virtual; abstract;
function DoSaveAll(Flags: TSaveFlags): TModalResult; virtual; abstract;
function DoCloseEditorFile(PageIndex:integer;
Flags: TCloseFlags):TModalResult; virtual; abstract;
deprecated {$IFDEF VER2_5}'use method with EditorObject'{$ENDIF}; // deprecated in 0.9.29 March 2010