messages rewrite using internal observer system 4

This commit is contained in:
Basile Burg 2014-11-08 19:21:29 +01:00
parent de0022a61f
commit e7c9cfac4d
10 changed files with 127 additions and 68 deletions

View File

@ -55,7 +55,10 @@ begin
inherited; inherited;
Enabled := exeInSysPath('cdb'); Enabled := exeInSysPath('cdb');
if Enabled then if Enabled then
begin
EntitiesConnector.addObserver(self); EntitiesConnector.addObserver(self);
EntitiesConnector.endUpdate;
end;
end; end;
destructor TCECdbWidget.destroy; destructor TCECdbWidget.destroy;

View File

@ -101,6 +101,7 @@ begin
end; end;
// //
EntitiesConnector.addObserver(self); EntitiesConnector.addObserver(self);
EntitiesConnector.endUpdate;
end; end;
destructor TCEEditorWidget.destroy; destructor TCEEditorWidget.destroy;

View File

@ -316,6 +316,8 @@ begin
newProj; newProj;
checkCompilo; checkCompilo;
getCMdParams; getCMdParams;
//
EntitiesConnector.endUpdate;
end; end;
procedure TCEMainForm.checkCompilo; procedure TCEMainForm.checkCompilo;
@ -723,9 +725,10 @@ end;
procedure TCEMainForm.ApplicationProperties1Exception(Sender: TObject;E: Exception); procedure TCEMainForm.ApplicationProperties1Exception(Sender: TObject;E: Exception);
begin begin
//if fMesgWidg = nil then if fMesgWidg = nil then
//ce_common.dlgOkError(E.Message) ce_common.dlgOkError(E.Message)
//else fMesgWidg.addCeErr(E.Message); else
fMesgWidg.lmStandard(E.Message, nil, amcApp, amkErr);
end; end;
procedure TCEMainForm.FormCloseQuery(Sender: TObject; var CanClose: boolean); procedure TCEMainForm.FormCloseQuery(Sender: TObject; var CanClose: boolean);

View File

@ -148,6 +148,7 @@ begin
btnSelAll.OnClick := @selCtxtClick; btnSelAll.OnClick := @selCtxtClick;
// //
EntitiesConnector.addObserver(self); EntitiesConnector.addObserver(self);
EntitiesConnector.endUpdate;
end; end;
destructor TCEMessagesWidget.destroy; destructor TCEMessagesWidget.destroy;
@ -317,8 +318,10 @@ end;
procedure TCEMessagesWidget.projClosing(const aProject: TCEProject); procedure TCEMessagesWidget.projClosing(const aProject: TCEProject);
begin begin
if fProj = aProject then if fProj <> aProject then
lmClearByData(@fProj); exit;
//
lmClearByData(aProject);
fProj := nil; fProj := nil;
filterMessages(fCtxt); filterMessages(fCtxt);
end; end;
@ -388,17 +391,17 @@ begin
if not (poUsePipes in aValue.Options) then if not (poUsePipes in aValue.Options) then
exit; exit;
// //
aValue.Tag := (Byte(aCtxt) << 8) + Byte(aKind); aValue.Tag := (Byte(aCtxt) shl 8) + Byte(aKind);
// //
if (aValue is TAsyncProcess) then if (aValue is TAsyncProcess) then
begin begin
TAsyncProcess(aValue).OnReadData := @processOutput; TAsyncProcess(aValue).OnReadData := @processOutput;
TAsyncProcess(aValue).OnTerminate := @processTerminate; TAsyncProcess(aValue).OnTerminate := @processTerminate;
end; end;
// always process message: a TAsyncProcess may be already terminated. if aValue.Output = nil then
exit;
// always process messages: a TAsyncProcess may be already terminated.
logProcessOutput(aValue); logProcessOutput(aValue);
//
Application.ProcessMessages;
end; end;
procedure TCEMessagesWidget.processOutput(Sender: TObject); procedure TCEMessagesWidget.processOutput(Sender: TObject);
@ -425,6 +428,7 @@ begin
finally finally
lst.Free; lst.Free;
Application.ProcessMessages; Application.ProcessMessages;
filterMessages(fCtxt);
end; end;
end; end;
@ -456,7 +460,7 @@ begin
for i := List.Items.Count-1 downto 0 do for i := List.Items.Count-1 downto 0 do
begin begin
msgdt := PMessageData(List.Items[i].Data); msgdt := PMessageData(List.Items[i].Data);
if (msgdt^.data = aData) or (msgdt^.data = Pointer(aData^)) then if (msgdt^.data = aData) then
List.Items.Delete(List.Items[i]); List.Items.Delete(List.Items[i]);
end; end;
end; end;
@ -520,11 +524,8 @@ begin
continue; continue;
end end
else case msgdt^.ctxt of else case msgdt^.ctxt of
// PMessageData.data can be either a reference or a pointer amcEdit: itm.Visible := (fDoc = TCESynMemo(msgdt^.data)) and (aCtxt = amcEdit);
amcEdit: itm.Visible := ((fDoc = TCESynMemo(msgdt^.data)) or (fDoc = TCESynMemo(msgdt^.data^))) amcProj: itm.Visible := (fProj = TCEProject(msgdt^.data)) and (aCtxt = amcProj);
and (aCtxt = amcEdit);
amcProj: itm.Visible := ((fProj = TCEProject(msgdt^.data)) or (fProj = TCEProject(msgdt^.data^)))
and (aCtxt = amcProj);
amcApp: itm.Visible := aCtxt = amcApp; amcApp: itm.Visible := aCtxt = amcApp;
amcMisc: itm.Visible := aCtxt = amcMisc; amcMisc: itm.Visible := aCtxt = amcMisc;
end; end;

View File

@ -52,6 +52,7 @@ begin
Grid.OnEditorFilter := @GridFilter; Grid.OnEditorFilter := @GridFilter;
// //
EntitiesConnector.addObserver(self); EntitiesConnector.addObserver(self);
EntitiesConnector.endUpdate;
end; end;
destructor TCEProjectConfigurationWidget.destroy; destructor TCEProjectConfigurationWidget.destroy;

View File

@ -47,6 +47,10 @@ type
function getCurrConf: TCompilerConfiguration; function getCurrConf: TCompilerConfiguration;
function runPrePostProcess(const processInfo: TCompileProcOptions): Boolean; function runPrePostProcess(const processInfo: TCompileProcOptions): Boolean;
function getCanBeRun: boolean; function getCanBeRun: boolean;
// passes pre/post/executed project/ outputs as bubles.
procedure runProcOutput(sender: TObject);
// passes compilation message as "to be guessed"
procedure compProcOutput(proc: TProcess);
protected protected
procedure afterSave; override; procedure afterSave; override;
procedure afterLoad; override; procedure afterLoad; override;
@ -91,6 +95,7 @@ uses
constructor TCEProject.create(aOwner: TComponent); constructor TCEProject.create(aOwner: TComponent);
begin begin
inherited create(aOwner); inherited create(aOwner);
//
fLogMessager := TCELogMessageSubject.create; fLogMessager := TCELogMessageSubject.create;
fProjectSubject := TCEProjectSubject.create; fProjectSubject := TCEProjectSubject.create;
// //
@ -102,6 +107,7 @@ begin
// //
reset; reset;
addDefaults; addDefaults;
subjProjNew(TCEProjectSubject(fProjectSubject), self);
subjProjChanged(TCEProjectSubject(fProjectSubject), self); subjProjChanged(TCEProjectSubject(fProjectSubject), self);
// //
fModified := false; fModified := false;
@ -118,6 +124,7 @@ begin
fSrcs.free; fSrcs.free;
fSrcsCop.Free; fSrcsCop.Free;
fOptsColl.free; fOptsColl.free;
killProcess(fRunner);
inherited; inherited;
end; end;
@ -476,13 +483,73 @@ begin
while process.Running do while process.Running do
if not (poWaitOnExit in process.Options) then if not (poWaitOnExit in process.Options) then
if poUsePipes in process.Options then if poUsePipes in process.Options then
subjLmProcess(TCELogMessageSubject(fLogMessager), process, @Self, amcProj, amkBub); runProcOutput(process);
finally finally
result := process.ExitStatus = 0; result := process.ExitStatus = 0;
process.Free; process.Free;
end; end;
end; end;
function TCEProject.compileProject: Boolean;
var
config: TCompilerConfiguration;
compilproc: TProcess;
olddir, prjpath: string;
prjname: string;
begin
result := false;
config := currentConfiguration;
if config = nil then
begin
subjLmStandard(TCELogMessageSubject(fLogMessager),
'unexpected project error: no active configuration', Self, amcProj, amkErr);
exit;
end;
//
subjLmClearByData(TCELogMessageSubject(fLogMessager), Self);
//
if not runPrePostProcess(config.preBuildProcess) then
subjLmStandard(TCELogMessageSubject(fLogMessager),
'project warning: the pre-compilation process has not been properly executed', Self, amcProj, amkWarn);
//
prjname := shortenPath(filename, 25);
compilproc := TProcess.Create(nil);
olddir := '';
getDir(0, olddir);
try
subjLmStandard(TCELogMessageSubject(fLogMessager),
'compiling ' + prjname, Self, amcProj, amkInf);
prjpath := extractFilePath(fileName);
if directoryExists(prjpath) then
begin
chDir(prjpath);
compilproc.CurrentDirectory := prjpath;
end;
compilproc.Executable := DCompiler;
compilproc.Options := compilproc.Options + [poStderrToOutPut, poUsePipes];
compilproc.ShowWindow := swoHIDE;
getOpts(compilproc.Parameters);
compilproc.Execute;
while compilProc.Running do
compProcOutput(compilproc);
if compilproc.ExitStatus = 0 then begin
subjLmStandard(TCELogMessageSubject(fLogMessager),
prjname + ' has been successfully compiled', Self, amcProj, amkInf);
result := true;
end else
subjLmStandard(TCELogMessageSubject(fLogMessager),
prjname + ' has not been compiled', Self, amcProj, amkWarn);
if not runPrePostProcess(config.PostBuildProcess) then
subjLmStandard(TCELogMessageSubject(fLogMessager),
'project warning: the post-compilation process has not been properly executed', Self, amcProj, amkWarn);
finally
compilproc.Free;
chDir(olddir);
end;
end;
function TCEProject.runProject(const runArgs: string = ''): Boolean; function TCEProject.runProject(const runArgs: string = ''): Boolean;
var var
prm: string; prm: string;
@ -506,74 +573,53 @@ begin
if not fileExists(outputFilename) then if not fileExists(outputFilename) then
begin begin
subjLmStandard(TCELogMessageSubject(fLogMessager), subjLmStandard(TCELogMessageSubject(fLogMessager),
'output executable missing: ' + shortenPath(outputFilename,25), @Self, amcProj, amkErr); 'output executable missing: ' + shortenPath(outputFilename, 25), Self, amcProj, amkErr);
exit; exit;
end; end;
// //
fRunner.Executable := outputFilename; fRunner.Executable := outputFilename;
if fRunner.CurrentDirectory = '' then if fRunner.CurrentDirectory = '' then
fRunner.CurrentDirectory := extractFilePath(fRunner.Executable); fRunner.CurrentDirectory := extractFilePath(fRunner.Executable);
subjLmProcess(TCELogMessageSubject(fLogMessager), fRunner, @Self, amcProj, amkBub); if poUsePipes in fRunner.Options then begin
fRunner.OnReadData := @runProcOutput;
fRunner.OnTerminate := @runProcOutput;
end;
fRunner.Execute; fRunner.Execute;
// //
result := true; result := true;
end; end;
function TCEProject.compileProject: Boolean; procedure TCEProject.runProcOutput(sender: TObject);
var var
config: TCompilerConfiguration; proc: TProcess;
compilproc: TProcess; lst: TStringList;
olddir, prjpath: string; str: string;
prjname: string;
begin begin
result := false; proc := TProcess(sender);
config := currentConfiguration; lst := TStringList.Create;
if config = nil then
begin
subjLmStandard(TCELogMessageSubject(fLogMessager),
'unexpected project error: no active configuration', @Self, amcProj, amkErr);
exit;
end;
//
if not runPrePostProcess(config.preBuildProcess) then
subjLmStandard(TCELogMessageSubject(fLogMessager),
'project warning: the pre-compilation process has not been executed', @Self, amcProj, amkWarn);
//
prjname := shortenPath(filename, 25);
compilproc := TProcess.Create(nil);
olddir := '';
getDir(0, olddir);
try try
subjLmStandard(TCELogMessageSubject(fLogMessager), processOutputToStrings(proc, lst);
'compiling ' + prjname, @Self, amcProj, amkInf); for str in lst do
prjpath := extractFilePath(fileName);
if directoryExists(prjpath) then
begin
chDir(prjpath);
compilproc.CurrentDirectory := prjpath;
end;
compilproc.Executable := DCompiler;
compilproc.Options := compilproc.Options + [poStderrToOutPut, poUsePipes];
compilproc.ShowWindow := swoHIDE;
getOpts(compilproc.Parameters);
compilproc.Execute;
while compilProc.Running do
subjLmProcess(TCELogMessageSubject(fLogMessager), compilproc, @Self, amcProj, amkBub);
if compilproc.ExitStatus = 0 then begin
subjLmStandard(TCELogMessageSubject(fLogMessager), subjLmStandard(TCELogMessageSubject(fLogMessager),
prjname + ' has been successfully compiled', @Self, amcProj, amkInf); str, Self, amcProj, amkBub);
result := true;
end else
subjLmStandard(TCELogMessageSubject(fLogMessager),
prjname + ' has not been compiled', @Self, amcProj, amkWarn);
if not runPrePostProcess(config.PostBuildProcess) then
subjLmStandard(TCELogMessageSubject(fLogMessager),
'project warning: the post-compilation process has not been executed', @Self, amcProj, amkWarn);
finally finally
compilproc.Free; lst.Free;
chDir(olddir); end;
end;
procedure TCEProject.compProcOutput(proc: TProcess);
var
lst: TStringList;
str: string;
begin
lst := TStringList.Create;
try
processOutputToStrings(proc, lst);
for str in lst do
subjLmStandard(TCELogMessageSubject(fLogMessager),
str, Self, amcProj, amkAuto);
finally
lst.Free;
end; end;
end; end;

View File

@ -83,6 +83,7 @@ begin
Tree.PopupMenu := contextMenu; Tree.PopupMenu := contextMenu;
// //
EntitiesConnector.addObserver(self); EntitiesConnector.addObserver(self);
EntitiesConnector.endUpdate;
end; end;
destructor TCEProjectInspectWidget.destroy; destructor TCEProjectInspectWidget.destroy;

View File

@ -92,6 +92,7 @@ begin
fReplaceMru:= TMruList.Create; fReplaceMru:= TMruList.Create;
// //
EntitiesConnector.addObserver(self); EntitiesConnector.addObserver(self);
EntitiesConnector.endUpdate;
end; end;
destructor TCESearchWidget.Destroy; destructor TCESearchWidget.Destroy;

View File

@ -129,6 +129,7 @@ begin
Tree.PopupMenu := contextMenu; Tree.PopupMenu := contextMenu;
// //
EntitiesConnector.addObserver(self); EntitiesConnector.addObserver(self);
EntitiesConnector.endUpdate;
end; end;
destructor TCEStaticExplorerWidget.destroy; destructor TCEStaticExplorerWidget.destroy;

View File

@ -128,6 +128,7 @@ begin
PopupMenu := contextMenu; PopupMenu := contextMenu;
EntitiesConnector.addObserver(self); EntitiesConnector.addObserver(self);
EntitiesConnector.endUpdate;
end; end;
destructor TCEWidget.destroy; destructor TCEWidget.destroy;