add the ICELifetimeManager service and use it to close #310

This commit is contained in:
Basile Burg 2018-04-26 15:37:32 +02:00
parent a6b630f090
commit 80c81cce1e
4 changed files with 113 additions and 32 deletions

View File

@ -236,6 +236,20 @@ type
amcAutoCompile // same as amcAutoEdit or amcAutoProj but set by the ICEMessagesDisplay according to what's being compiled.
);
TLifetimeStatus = (
lfsLoading, // IDE is not ready yet, other services might be nil
lfsLoaded, // IDE is 100% working
lfsExiting // IDE is quiting, other services will be nil
);
(**
* Single service providing information about the IDE liftetime
*)
ICELifetimeManager = interface(ICESingleService)
function getLifetimeStatus: TLifetimeStatus;
function asObject: TObject;
end;
(**
* Single service provided by the messages widget.
*)
@ -453,6 +467,7 @@ type
function getCompilerSelector: ICECompilerSelector; inline;
function getMainMenu: ICEMainMenu; inline;
function getCodeFormatting: ICECodeFormatting; inline;
function getLifeTimeManager: ICELifetimeManager; inline;
implementation
@ -612,6 +627,11 @@ function getCodeFormatting: ICECodeFormatting; inline;
begin
exit(EntitiesConnector.getSingleService('ICECodeFormatting') as ICECodeFormatting);
end;
function getLifeTimeManager: ICELifetimeManager; inline;
begin
exit(EntitiesConnector.getSingleService('ICELifetimeManager') as ICELifetimeManager);
end;
{$ENDREGION}
function usingCompilerInfo(value: DCompiler): string;

View File

@ -1472,7 +1472,6 @@ object CEMainForm: TCEMainForm
OnResize = FormResize
OnWindowStateChange = FormWindowStateChange
ShowHint = True
LCLVersion = '1.8.2.0'
Visible = False
object mainMenu: TMainMenu
top = 1

View File

@ -22,6 +22,17 @@ type
TCEApplicationOptions = class;
TCELifetimeProvider = class(ICELifetimeManager)
strict private
fStatus: TLifetimeStatus;
function singleServiceName: string;
function getLifetimeStatus: TLifetimeStatus;
function asObject: TObject;
public
constructor create;
property lifetimeStatus: TLifetimeStatus read fStatus write fStatus;
end;
TAsyncWait = (awNo, awYes, awCustom);
TRunnableToFolderCondition = (
@ -415,6 +426,7 @@ type
fAppliOpts: TCEApplicationOptions;
fProjActionsLock: boolean;
fCompilerSelector: ICECompilerSelector;
fLifeTimeStatusProvider: TCELifetimeProvider;
procedure updateFloatingWidgetOnTop(onTop: boolean);
procedure widgetDockingChanged(sender: TCEWidget; newState: TWidgetDockingState);
procedure mnuOptsItemClick(sender: TObject);
@ -1105,6 +1117,28 @@ begin
end;
{$ENDREGION}
{$REGION Lifetime}
constructor TCELifetimeProvider.create;
begin
EntitiesConnector.addSingleService(self);
end;
function TCELifetimeProvider.singleServiceName: string;
begin
result := 'ICELifetimeManager';
end;
function TCELifetimeProvider.getLifetimeStatus: TLifetimeStatus;
begin
result := fStatus;
end;
function TCELifetimeProvider.asObject: TObject;
begin
result := self;
end;
{$ENDREGION}
{$REGION Actions shortcuts -----------------------------------------------------}
constructor TCEPersistentMainShortcuts.create(aOwner: TComponent);
begin
@ -1194,6 +1228,10 @@ end;
{$REGION Standard Comp/Obj------------------------------------------------------}
constructor TCEMainForm.create(aOwner: TComponent);
begin
fLifeTimeStatusProvider := TCELifetimeProvider.create;
fLifeTimeStatusProvider.lifetimeStatus:=lfsLoading;
inherited create(aOwner);
// provide defaults, necessary because not handled by docking.xml
@ -2025,6 +2063,8 @@ begin
OpenURL(url);
end;
end;
fLifeTimeStatusProvider.lifetimeStatus := lfsLoaded;
end;
procedure TCEMainForm.FormClose(Sender: TObject; var CloseAction: TCloseAction);
@ -2081,6 +2121,7 @@ begin
fOptionCategories.Free;
EntitiesConnector.removeObserver(self);
inherited;
fLifeTimeStatusProvider.free;
end;
procedure TCEMainForm.UpdateDockCaption(Exclude: TControl = nil);
@ -2208,7 +2249,7 @@ begin
free;
end;
end;
fLifeTimeStatusProvider.lifetimeStatus:=lfsExiting;
SaveLastDocsAndProj;
CanClose:= true;
fProjectGroup.closeGroup;

View File

@ -166,9 +166,13 @@ type
procedure goToLine(value: integer);
end;
{ TCESynMemo }
TCESynMemo = class(TSynEdit, ICEDebugObserver)
private
//fIndentGuideMarkup: TSynEditMarkupFoldColors;
fLifeTimeManager: TObject;
fIdentDialShown: boolean;
fScrollMemo: TCEScrollMemo;
fFilename: string;
fDastWorxExename: string;
@ -288,6 +292,7 @@ type
procedure debugQueryBreakPoint(const line: integer; out fname: string; out kind: TBreakPointKind);
procedure debugBreak(const fname: string; line: integer; reason: TCEDebugBreakReason);
function breakPointsCount: integer;
procedure tryToPatchMixedIndentation;
protected
procedure DoEnter; override;
procedure DoExit; override;
@ -899,11 +904,16 @@ end;
constructor TCESynMemo.Create(aOwner: TComponent);
var
z: TIconScaledSize;
i: ICELifetimeManager;
begin
inherited;
fScrollMemo := TCEScrollMemo.construct(self);
i := getLifeTimeManager();
if (i <> nil) then
fLifeTimeManager := i.asObject;
OnShowHint:= @showHintEvent;
OnStatusChange:= @handleStatusChanged;
fDefaultFontSize := 10;
@ -1120,9 +1130,9 @@ end;
procedure TCESynMemo.setFocus;
begin
inherited;
//checkFileDate;
highlightCurrentIdentifier;
subjDocFocused(TCEMultiDocSubject(fMultiDocSubject), self);
tryToPatchMixedIndentation;
end;
procedure TCESynMemo.showPage;
@ -2997,35 +3007,7 @@ begin
loadCache;
fCacheLoaded := true;
end;
case indentationMode() of
imTabs:
if detectIndentMode then
Options:= Options - [eoTabsToSpaces];
imSpaces:
if detectIndentMode then
Options:= Options + [eoTabsToSpaces];
imMixed:
if (isDSource or alwaysAdvancedFeatures) and
(dlgYesNo('Mixed indentation style detected, ' +
'do you wish to convert to a single mode ?') = mrYes) then
with TMixedIndetationDialog.construct() do
try
case ShowModal of
10:
begin
forceIndentation(imTabs, TMixedIndetationDialog.fSpacesPerTab);
Options:= Options - [eoTabsToSpaces];
end;
11:
begin
forceIndentation(imSpaces, TMixedIndetationDialog.fSpacesPerTab);
Options:= Options + [eoTabsToSpaces];
end;
end;
finally
free;
end;
end;
subjDocChanged(TCEMultiDocSubject(fMultiDocSubject), self);
fCanDscan := true;
end;
@ -3494,6 +3476,45 @@ begin
result += byte(marks[i].ImageIndex = integer(giBreakSet));
end;
procedure TCESynMemo.tryToPatchMixedIndentation;
begin
if fLifeTimeManager.isNotNil and not fIdentDialShown and
((fLifeTimeManager as ICELifetimeManager).getLifetimeStatus = lfsLoaded)
then
begin
fIdentDialShown := true;
case indentationMode() of
imTabs:
if detectIndentMode then
Options:= Options - [eoTabsToSpaces];
imSpaces:
if detectIndentMode then
Options:= Options + [eoTabsToSpaces];
imMixed:
if (isDSource or alwaysAdvancedFeatures) and
(dlgYesNo('Mixed indentation style detected, ' +
'do you wish to convert to a single mode ?') = mrYes) then
with TMixedIndetationDialog.construct() do
try
case ShowModal of
10:
begin
forceIndentation(imTabs, TMixedIndetationDialog.fSpacesPerTab);
Options:= Options - [eoTabsToSpaces];
end;
11:
begin
forceIndentation(imSpaces, TMixedIndetationDialog.fSpacesPerTab);
Options:= Options + [eoTabsToSpaces];
end;
end;
finally
free;
end;
end;
end;
end;
procedure TCESynMemo.addBreakPoint(line: integer);
begin
if findBreakPoint(line) then