Skip to content

Commit c87478f

Browse files
committed
Revert to a simpler version of the code without the helper
1 parent 5a75067 commit c87478f

File tree

1 file changed

+8
-76
lines changed

1 file changed

+8
-76
lines changed

Source/NSAlert.m

Lines changed: 8 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1770,62 +1770,6 @@ void NSBeginInformationalAlertSheet(NSString *title,
17701770
NSReleaseAlertPanel(panel);
17711771
}
17721772

1773-
// Helper to run a sheet on the main thread and capture the result.
1774-
@interface _GSRunSheetHelper : NSObject
1775-
{
1776-
GSAlertPanel *_panel;
1777-
NSWindow *_docWindow;
1778-
NSInteger _result;
1779-
}
1780-
- (id)initWithPanel:(GSAlertPanel *)panel docWindow:(NSWindow *)docWindow;
1781-
- (void)runSheetOnMainThread;
1782-
- (NSInteger)result;
1783-
@end
1784-
1785-
@implementation _GSRunSheetHelper
1786-
- (id)initWithPanel:(GSAlertPanel *)panel docWindow:(NSWindow *)docWindow
1787-
{
1788-
if ((self = [super init]) != nil)
1789-
{
1790-
_panel = RETAIN(panel);
1791-
_docWindow = docWindow; // not retaining window to avoid cycles
1792-
_result = NSAlertErrorReturn;
1793-
}
1794-
return self;
1795-
}
1796-
1797-
- (void)dealloc
1798-
{
1799-
RELEASE(_panel);
1800-
[super dealloc];
1801-
}
1802-
1803-
- (void)runSheetOnMainThread
1804-
{
1805-
if (_docWindow)
1806-
{
1807-
// Ensure the document window is in front so the sheet appears on top
1808-
if ([_docWindow respondsToSelector: @selector(makeKeyAndOrderFront:)])
1809-
{
1810-
[_docWindow makeKeyAndOrderFront: nil];
1811-
}
1812-
else if ([_docWindow respondsToSelector: @selector(orderFront:)])
1813-
{
1814-
[_docWindow orderFront: nil];
1815-
}
1816-
}
1817-
[NSApp beginSheet: _panel
1818-
modalForWindow: _docWindow
1819-
modalDelegate: nil
1820-
didEndSelector: NULL
1821-
contextInfo: NULL];
1822-
_result = [_panel result];
1823-
}
1824-
1825-
- (NSInteger)result { return _result; }
1826-
1827-
@end
1828-
18291773
// Synchronous sheet-aware alert. If docWindow is nil, fall back to
18301774
// NSRunAlertPanel which shows a modal alert. Otherwise display a sheet
18311775
// attached to docWindow and run a modal loop until it completes.
@@ -1862,26 +1806,14 @@ - (NSInteger)result { return _result; }
18621806

18631807
panel = getSomeSheet(&standardAlertPanel, defaultTitle, title, message,
18641808
defaultButton, alternateButton, otherButton);
1865-
/* Run the sheet on the main thread to ensure it is presented. */
1866-
if (GSCurrentThread() != GSAppKitThread)
1867-
{
1868-
_GSRunSheetHelper *h = [[_GSRunSheetHelper alloc] initWithPanel: panel
1869-
docWindow: docWindow];
1870-
[h performSelectorOnMainThread: @selector(runSheetOnMainThread)
1871-
withObject: nil
1872-
waitUntilDone: YES];
1873-
result = [h result];
1874-
RELEASE(h);
1875-
}
1876-
else
1877-
{
1878-
[NSApp beginSheet: panel
1879-
modalForWindow: docWindow
1880-
modalDelegate: nil
1881-
didEndSelector: NULL
1882-
contextInfo: NULL];
1883-
result = [panel result];
1884-
}
1809+
1810+
[panel makeKeyAndOrderFront: nil];
1811+
[NSApp beginSheet: panel
1812+
modalForWindow: docWindow
1813+
modalDelegate: nil
1814+
didEndSelector: NULL
1815+
contextInfo: NULL];
1816+
result = [panel result];
18851817

18861818
NSReleaseAlertPanel(panel);
18871819
return result;

0 commit comments

Comments
 (0)