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. 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. * Single service provided by the messages widget.
*) *)
@ -453,6 +467,7 @@ type
function getCompilerSelector: ICECompilerSelector; inline; function getCompilerSelector: ICECompilerSelector; inline;
function getMainMenu: ICEMainMenu; inline; function getMainMenu: ICEMainMenu; inline;
function getCodeFormatting: ICECodeFormatting; inline; function getCodeFormatting: ICECodeFormatting; inline;
function getLifeTimeManager: ICELifetimeManager; inline;
implementation implementation
@ -612,6 +627,11 @@ function getCodeFormatting: ICECodeFormatting; inline;
begin begin
exit(EntitiesConnector.getSingleService('ICECodeFormatting') as ICECodeFormatting); exit(EntitiesConnector.getSingleService('ICECodeFormatting') as ICECodeFormatting);
end; end;
function getLifeTimeManager: ICELifetimeManager; inline;
begin
exit(EntitiesConnector.getSingleService('ICELifetimeManager') as ICELifetimeManager);
end;
{$ENDREGION} {$ENDREGION}
function usingCompilerInfo(value: DCompiler): string; function usingCompilerInfo(value: DCompiler): string;

View File

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

View File

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

View File

@ -166,9 +166,13 @@ type
procedure goToLine(value: integer); procedure goToLine(value: integer);
end; end;
{ TCESynMemo }
TCESynMemo = class(TSynEdit, ICEDebugObserver) TCESynMemo = class(TSynEdit, ICEDebugObserver)
private private
//fIndentGuideMarkup: TSynEditMarkupFoldColors; //fIndentGuideMarkup: TSynEditMarkupFoldColors;
fLifeTimeManager: TObject;
fIdentDialShown: boolean;
fScrollMemo: TCEScrollMemo; fScrollMemo: TCEScrollMemo;
fFilename: string; fFilename: string;
fDastWorxExename: string; fDastWorxExename: string;
@ -288,6 +292,7 @@ type
procedure debugQueryBreakPoint(const line: integer; out fname: string; out kind: TBreakPointKind); procedure debugQueryBreakPoint(const line: integer; out fname: string; out kind: TBreakPointKind);
procedure debugBreak(const fname: string; line: integer; reason: TCEDebugBreakReason); procedure debugBreak(const fname: string; line: integer; reason: TCEDebugBreakReason);
function breakPointsCount: integer; function breakPointsCount: integer;
procedure tryToPatchMixedIndentation;
protected protected
procedure DoEnter; override; procedure DoEnter; override;
procedure DoExit; override; procedure DoExit; override;
@ -899,11 +904,16 @@ end;
constructor TCESynMemo.Create(aOwner: TComponent); constructor TCESynMemo.Create(aOwner: TComponent);
var var
z: TIconScaledSize; z: TIconScaledSize;
i: ICELifetimeManager;
begin begin
inherited; inherited;
fScrollMemo := TCEScrollMemo.construct(self); fScrollMemo := TCEScrollMemo.construct(self);
i := getLifeTimeManager();
if (i <> nil) then
fLifeTimeManager := i.asObject;
OnShowHint:= @showHintEvent; OnShowHint:= @showHintEvent;
OnStatusChange:= @handleStatusChanged; OnStatusChange:= @handleStatusChanged;
fDefaultFontSize := 10; fDefaultFontSize := 10;
@ -1120,9 +1130,9 @@ end;
procedure TCESynMemo.setFocus; procedure TCESynMemo.setFocus;
begin begin
inherited; inherited;
//checkFileDate;
highlightCurrentIdentifier; highlightCurrentIdentifier;
subjDocFocused(TCEMultiDocSubject(fMultiDocSubject), self); subjDocFocused(TCEMultiDocSubject(fMultiDocSubject), self);
tryToPatchMixedIndentation;
end; end;
procedure TCESynMemo.showPage; procedure TCESynMemo.showPage;
@ -2997,35 +3007,7 @@ begin
loadCache; loadCache;
fCacheLoaded := true; fCacheLoaded := true;
end; 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); subjDocChanged(TCEMultiDocSubject(fMultiDocSubject), self);
fCanDscan := true; fCanDscan := true;
end; end;
@ -3494,6 +3476,45 @@ begin
result += byte(marks[i].ImageIndex = integer(giBreakSet)); result += byte(marks[i].ImageIndex = integer(giBreakSet));
end; 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); procedure TCESynMemo.addBreakPoint(line: integer);
begin begin
if findBreakPoint(line) then if findBreakPoint(line) then