Skip to content

Commit

Permalink
NXTAlert: fixed message view initializationl; added `representedObjec…
Browse files Browse the repository at this point in the history
…t` property.
  • Loading branch information
trunkmaster committed Sep 18, 2024
1 parent 409c047 commit b7529cd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
2 changes: 2 additions & 0 deletions Frameworks/DesktopKit/NXTAlert.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
NSUInteger minButtonWidth;
}

@property (assign) id representedObject;

- (id)initWithTitle:(NSString *)titleText
message:(NSString *)messageText
defaultButton:(NSString *)defaultText
Expand Down
45 changes: 23 additions & 22 deletions Frameworks/DesktopKit/NXTAlert.m
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ - (id)initWithTitle:(NSString *)titleText
- (void)awakeFromNib
{
NSDictionary *selectedAttrs;
// NSText *fieldEditor;

maxButtonWidth = ([panel frame].size.width - 16 - 10) / 3;
minButtonWidth = [defaultButton frame].size.width;
Expand All @@ -224,12 +223,8 @@ - (void)awakeFromNib
[messageView setSelectable:YES];
[messageView setAlignment:NSCenterTextAlignment];
[messageView setTextContainerInset:NSMakeSize(0,0)];
[[panel contentView] addSubview:messageView];
[messageView release];

selectedAttrs = @{NSBackgroundColorAttributeName:[NSColor controlLightHighlightColor]};
// fieldEditor = [panel fieldEditor:YES forObject:messageView];
// [(NSTextView *)fieldEditor setSelectedTextAttributes:selectedAttrs];
[messageView setSelectedTextAttributes:selectedAttrs];
}

Expand Down Expand Up @@ -271,9 +266,14 @@ - (NSRect)rectForView:(NSTextView *)view
withinSelectedCharacterRange:textRange
inTextContainer:[view textContainer]
rectCount:&rectCount];
for (int i = 0; i < rectCount; i++) {
textRect.size.height += rectArray[i].size.height;
}
// if (rectArray) {
for (int i = 0; i < rectCount; i++) {
textRect.size.height += rectArray[i].size.height;
}
// } else {
// textRect = [view frame];
// }

return textRect;
}

Expand Down Expand Up @@ -418,38 +418,39 @@ - (NSInteger)runModalForWindow:(NSWindow *)theWindow

theSession = [NSApp beginModalSessionForWindow:theWindow];
limit = [NSDate distantPast];
// limit = [NSDate dateWithTimeIntervalSinceNow:0.5];
srv = GSCurrentServer();

while (code == NSRunContinuesResponse) {
// limit = [NSDate dateWithTimeIntervalSinceNow:0.1];
// Try to handle events for this session, discarding others.
code = [NSApp runModalSession:theSession];
if (code == NSRunContinuesResponse) {
// code = [NSApp runModalSession:theSession];
// if (code == NSRunContinuesResponse) {
// Wait until there are more events to handle.
event = DPSPeekEvent(srv, NSAnyEventMask, limit, NSModalPanelRunLoopMode);
event = DPSGetEvent(srv, NSAnyEventMask, limit, NSModalPanelRunLoopMode);
if (event != nil) {
NSWindow *eventWindow = [event window];

if (eventWindow == theWindow || [eventWindow worksWhenModal] == YES ||
[event type] == NSAppKitDefined) {
if (eventWindow == theWindow || [eventWindow worksWhenModal] == YES /*||
[event type] != NSPeriodic*/) {
// [NSApp sendEvent:event];
// [NSApp updateWindows];
[eventWindow sendEvent:event];
[eventWindow setViewsNeedDisplay:YES];
// [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.5]];
NSLog(@"NSSendEvent: %@", event);
// if ([[NSApp windows] indexOfObjectIdenticalTo:theWindow] == NSNotFound ||
// ![theWindow isVisible]) {
// [NSApp stopModal];
// code = 0;
// }
}
}
}
// if ([theWindow isVisible] == NO) {
// [NSApp stopModal];
// }

// }
}

[NSApp endModalSession:theSession];
} @catch (NSException *localException) {
if (theSession != 0) {
// NSWindow *win_to_close = theSession->window;

[NSApp endModalSession:theSession];
[theWindow close];
}
Expand Down Expand Up @@ -501,7 +502,7 @@ - (void)buttonPressed:(id)sender
NSLog(@"NXAalert panel button pressed when not in modal loop.");
return;
}

[NSApp stopModalWithCode:[sender tag]];
}

Expand Down

0 comments on commit b7529cd

Please sign in to comment.