cocoa: preventing font or color dialog from being restored on Application restart (in case of a crash while they're shown on restart)

git-svn-id: trunk@62708 -
This commit is contained in:
dmitry 2020-03-08 05:15:59 +00:00
parent 64e40526df
commit 4bd9ac45a1
3 changed files with 27 additions and 0 deletions

View File

@ -174,6 +174,8 @@ type
// 10.7+
procedure toggleFullScreen(sender: id); message 'toggleFullScreen:';
function backingScaleFactor: CGFloat; message 'backingScaleFactor';
function isRestorable: LCLObjCBoolean; message 'isRestorable';
procedure setRestorable(ARestore: LCLObjCBoolean); message 'setRestorable:';
// 10.12
procedure setTabbingMode(amode: NSWindowTabbingMode); message 'setTabbingMode:';
function tabbingMode: NSWindowTabbingMode; message 'tabbingMode';

View File

@ -552,6 +552,27 @@ begin
// todo: this should be called for "Default" or "Modal" loops
NSApp.updateWindows;
// color panel has allocated at least once
if (NSColorPanel.sharedColorPanelExists)
// Color panel has been shown
and (NSColorPanel.sharedColorPanel.isVisible)
// LCL color panel will will assign accessoryView
and (NSColorPanel.sharedColorPanel.accessoryView = nil) then
begin
NSColorPanel.sharedColorPanel.close;
end;
// the same check for font panel
if (NSFontPanel.sharedFontPanelExists)
and (NSFontPanel.sharedFontPanel.sharedFontPanel.isVisible)
and (not Assigned(NSFontPanel.sharedFontPanel.accessoryView)
or (NSFontPanel.sharedFontPanel.accessoryView.subviews.count = 0))
then
begin
NSFontPanel.sharedFontPanel.close;
end;
finally
// Focus change notification used to be in makeFirstResponder method

View File

@ -482,6 +482,8 @@ begin
ACommonDialog.UserChoice := mrCancel;
colorPanel := NSColorPanel.sharedColorPanel();
if (colorPanel.respondsToSelector(ObjCSelector('setRestorable:'))) then
colorPanel.setRestorable(false);
colorPanel.setColor(ColorToNSColor(ColorDialog.Color));
colorDelegate := TColorPanelDelegate.alloc.init();
@ -557,6 +559,8 @@ begin
ACommonDialog.UserChoice := mrCancel;
fontPanel := NSFontPanel.sharedFontPanel();
if (fontPanel.respondsToSelector(ObjCSelector('setRestorable:'))) then
fontPanel.setRestorable(false);
inFont := TCocoaFont(FontDialog.Font.Handle);
fn := inFont.Font;
if (FontDialog.Font.PixelsPerInch<>72) and (FontDialog.Font.PixelsPerInch<>0) then