Skip to content

Commit

Permalink
Explain why you're being prompted to confirm quitting behind a disclo…
Browse files Browse the repository at this point in the history
…sure triangle. Issue 5322
  • Loading branch information
gnachman committed Nov 30, 2016
1 parent 0c4b0a7 commit 0e29ebb
Show file tree
Hide file tree
Showing 15 changed files with 466 additions and 42 deletions.
16 changes: 16 additions & 0 deletions iTerm2.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1314,6 +1314,8 @@
A62C3B431BD40E7C00B5629D /* iTermImageMark.m in Sources */ = {isa = PBXBuildFile; fileRef = A62C3B411BD40E7C00B5629D /* iTermImageMark.m */; };
A6358646184BEA57009ED690 /* AATree.h in Headers */ = {isa = PBXBuildFile; fileRef = A6358642184BEA57009ED690 /* AATree.h */; };
A6358649184BEA57009ED690 /* AATreeNode.h in Headers */ = {isa = PBXBuildFile; fileRef = A6358644184BEA57009ED690 /* AATreeNode.h */; };
A6374A281DEE941F000A136F /* iTermPromptOnCloseReason.h in Headers */ = {isa = PBXBuildFile; fileRef = A6374A261DEE941F000A136F /* iTermPromptOnCloseReason.h */; };
A6374A291DEE941F000A136F /* iTermPromptOnCloseReason.m in Sources */ = {isa = PBXBuildFile; fileRef = A6374A271DEE941F000A136F /* iTermPromptOnCloseReason.m */; };
A63BA39518A9CB43002BE075 /* iTermSelection.h in Headers */ = {isa = PBXBuildFile; fileRef = A63BA39318A9CB43002BE075 /* iTermSelection.h */; };
A63BA39F18B27B92002BE075 /* iTermTextExtractor.h in Headers */ = {isa = PBXBuildFile; fileRef = A63BA39D18B27B92002BE075 /* iTermTextExtractor.h */; };
A63F4095183B398C003A6A6D /* PTYNoteViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = A63F4093183B398C003A6A6D /* PTYNoteViewController.h */; };
Expand Down Expand Up @@ -1380,6 +1382,8 @@
A663013019D0864C004AF81C /* SCEventListenerProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = A663012519D0864C004AF81C /* SCEventListenerProtocol.h */; };
A663013119D0864C004AF81C /* SCEvents.h in Headers */ = {isa = PBXBuildFile; fileRef = A663012619D0864C004AF81C /* SCEvents.h */; };
A663013219D0864C004AF81C /* SCEvents.h in Headers */ = {isa = PBXBuildFile; fileRef = A663012619D0864C004AF81C /* SCEvents.h */; };
A66444BA1DEEA534000AC615 /* iTermDisclosableView.h in Headers */ = {isa = PBXBuildFile; fileRef = A66444B81DEEA534000AC615 /* iTermDisclosableView.h */; };
A66444BB1DEEA534000AC615 /* iTermDisclosableView.m in Sources */ = {isa = PBXBuildFile; fileRef = A66444B91DEEA534000AC615 /* iTermDisclosableView.m */; };
A667F3871B48615900705186 /* iTermToolbeltTest.m in Sources */ = {isa = PBXBuildFile; fileRef = A667F3861B48615900705186 /* iTermToolbeltTest.m */; };
A667F3881B48671B00705186 /* libiTerm2Shared.a in Frameworks */ = {isa = PBXBuildFile; fileRef = A6C760501B45C4CF00E3C992 /* libiTerm2Shared.a */; };
A667F38B1B48AEF200705186 /* NSApplication+iTerm.h in Headers */ = {isa = PBXBuildFile; fileRef = A667F3891B48AEF200705186 /* NSApplication+iTerm.h */; };
Expand Down Expand Up @@ -2985,6 +2989,8 @@
A6358644184BEA57009ED690 /* AATreeNode.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.h; name = AATreeNode.h; path = "objc-aatree-master/AATreeNode.h"; sourceTree = "<group>"; tabWidth = 4; };
A6358645184BEA57009ED690 /* AATreeNode.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.objc; name = AATreeNode.m; path = "objc-aatree-master/AATreeNode.m"; sourceTree = "<group>"; tabWidth = 4; };
A635C4351AB38205008A2DEE /* iTermCursor.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.objc; path = iTermCursor.m; sourceTree = "<group>"; tabWidth = 4; };
A6374A261DEE941F000A136F /* iTermPromptOnCloseReason.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = iTermPromptOnCloseReason.h; sourceTree = "<group>"; };
A6374A271DEE941F000A136F /* iTermPromptOnCloseReason.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = iTermPromptOnCloseReason.m; sourceTree = "<group>"; };
A63BA39318A9CB43002BE075 /* iTermSelection.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = iTermSelection.h; sourceTree = "<group>"; tabWidth = 4; };
A63BA39418A9CB43002BE075 /* iTermSelection.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.objc; path = iTermSelection.m; sourceTree = "<group>"; tabWidth = 4; };
A63BA39D18B27B92002BE075 /* iTermTextExtractor.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = iTermTextExtractor.h; sourceTree = "<group>"; tabWidth = 4; };
Expand Down Expand Up @@ -3045,6 +3051,8 @@
A663012519D0864C004AF81C /* SCEventListenerProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SCEventListenerProtocol.h; path = SCEvents/Source/SCEventListenerProtocol.h; sourceTree = "<group>"; };
A663012619D0864C004AF81C /* SCEvents.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SCEvents.h; path = SCEvents/Source/SCEvents.h; sourceTree = "<group>"; };
A663012719D0864C004AF81C /* SCEvents.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SCEvents.m; path = SCEvents/Source/SCEvents.m; sourceTree = "<group>"; };
A66444B81DEEA534000AC615 /* iTermDisclosableView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = iTermDisclosableView.h; sourceTree = "<group>"; };
A66444B91DEEA534000AC615 /* iTermDisclosableView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = iTermDisclosableView.m; sourceTree = "<group>"; };
A667F3861B48615900705186 /* iTermToolbeltTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = iTermToolbeltTest.m; sourceTree = "<group>"; };
A667F3891B48AEF200705186 /* NSApplication+iTerm.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSApplication+iTerm.h"; sourceTree = "<group>"; };
A667F38A1B48AEF200705186 /* NSApplication+iTerm.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSApplication+iTerm.m"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -4358,6 +4366,8 @@
A667F3961B4F71AE00705186 /* iTermSavePanel.m */,
1D72A4D31BE9707A0042174A /* iTermWebViewWrapperViewController.h */,
1D72A4D41BE9707A0042174A /* iTermWebViewWrapperViewController.m */,
A66444B81DEEA534000AC615 /* iTermDisclosableView.h */,
A66444B91DEEA534000AC615 /* iTermDisclosableView.m */,
);
name = "Misc. Views";
sourceTree = "<group>";
Expand Down Expand Up @@ -5143,6 +5153,8 @@
A6755F421D728FFA00F3726C /* iTermImage.m */,
A6ECA5981D76907400D19511 /* iTermImageDecoderDriver.h */,
A6ECA5991D76907400D19511 /* iTermImageDecoderDriver.m */,
A6374A261DEE941F000A136F /* iTermPromptOnCloseReason.h */,
A6374A271DEE941F000A136F /* iTermPromptOnCloseReason.m */,
);
name = Helpers;
sourceTree = "<group>";
Expand Down Expand Up @@ -6115,6 +6127,7 @@
A62C3B2D1BCC24AB00B5629D /* iTermCommandHistoryCommandUseMO.h in Headers */,
A66DB83A1C9142C900233E88 /* iTermAltScreenMouseScrollInferer.h in Headers */,
A6755F431D728FFA00F3726C /* iTermImage.h in Headers */,
A66444BA1DEEA534000AC615 /* iTermDisclosableView.h in Headers */,
A66DB8421CA24E8800233E88 /* iTermAutoMasterParser.h in Headers */,
A60251681CCD3E5E009BABF1 /* NSURL+iTerm.h in Headers */,
1D300BAA1BD9A8BB002043F7 /* NSDate+iTerm.h in Headers */,
Expand All @@ -6127,6 +6140,7 @@
A62C3B2B1BCC24AB00B5629D /* iTermCommandHistoryCommandUseMO+CoreDataProperties.h in Headers */,
A62C3B251BCC24AB00B5629D /* iTermCommandHistoryEntryMO.h in Headers */,
1DE0C8451BF17397008ACBA9 /* SetHostnameTrigger.h in Headers */,
A6374A281DEE941F000A136F /* iTermPromptOnCloseReason.h in Headers */,
A62C3B231BCC24AB00B5629D /* iTermCommandHistoryEntryMO+CoreDataProperties.h in Headers */,
A62C3A911BCAE0ED00B5629D /* iTermRecentDirectoryMO+Additions.h in Headers */,
1DDC093F1B4DB97500B1A910 /* iTermRoundedCornerScrollView.h in Headers */,
Expand Down Expand Up @@ -7516,6 +7530,7 @@
A6C763B51B45C52B00E3C992 /* SendTextTrigger.m in Sources */,
A6C762C41B45C52B00E3C992 /* NSWorkspace+iTerm.m in Sources */,
1D0EA5A21CA5DAA2005FCF8B /* PSMLightHighContrastTabStyle.m in Sources */,
A6374A291DEE941F000A136F /* iTermPromptOnCloseReason.m in Sources */,
A6C7639E1B45C52B00E3C992 /* TmuxStateParser.m in Sources */,
A6C763771B45C52B00E3C992 /* PointerPrefsController.m in Sources */,
A6C763481B45C52B00E3C992 /* iTermShortcutInputView.m in Sources */,
Expand Down Expand Up @@ -7733,6 +7748,7 @@
A6C762FB1B45C52B00E3C992 /* FileTransferManager.m in Sources */,
A658716B1D85E6750061CEEE /* PFMoveApplication.m in Sources */,
A6C762B81B45C52B00E3C992 /* NSImage+iTerm.m in Sources */,
A66444BB1DEEA534000AC615 /* iTermDisclosableView.m in Sources */,
1D300BAB1BD9A8BB002043F7 /* NSDate+iTerm.m in Sources */,
A6C762E61B45C52B00E3C992 /* VT100Grid.m in Sources */,
A6C763981B45C52B00E3C992 /* TmuxControllerRegistry.m in Sources */,
Expand Down
8 changes: 7 additions & 1 deletion iTerm2.xcodeproj/xcshareddata/xcschemes/iTerm2.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
enableAddressSanitizer = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
Expand All @@ -96,10 +97,15 @@
<EnvironmentVariable
key = "OS_ACTIVITY_MODE"
value = "disable"
isEnabled = "YES">
isEnabled = "NO">
</EnvironmentVariable>
</EnvironmentVariables>
<AdditionalOptions>
<AdditionalOption
key = "NSZombieEnabled"
value = "YES"
isEnabled = "YES">
</AdditionalOption>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
Expand Down
1 change: 1 addition & 0 deletions sources/NSArray+iTerm.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

// Returns an array where each object in self is replaced with block(object).
- (NSArray *)mapWithBlock:(id (^)(id anObject))block;
- (NSArray *)multimapWithBlock:(NSArray *(^)(id anObject))block;

// Returns those elements of the array for which block(element) returns YES.
// block is called on every element in order.
Expand Down
8 changes: 8 additions & 0 deletions sources/NSArray+iTerm.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ - (NSArray *)mapWithBlock:(id (^)(id anObject))block {
return temp;
}

- (NSArray *)multimapWithBlock:(NSArray *(^)(id))block {
NSMutableArray *temp = [NSMutableArray array];
for (id anObject in self) {
[temp addObjectsFromArray:block(anObject)];
}
return temp;
}

- (NSArray *)filteredArrayUsingBlock:(BOOL (^)(id anObject))block {
NSIndexSet *indexes = [self indexesOfObjectsPassingTest:^BOOL(id _Nonnull obj,
NSUInteger idx,
Expand Down
3 changes: 2 additions & 1 deletion sources/PTYSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ extern NSString *const kPTYSessionCapturedOutputDidChange;
@class iTermCommandHistoryCommandUseMO;
@class iTermController;
@class iTermGrowlDelegate;
@class iTermPromptOnCloseReason;
@class iTermQuickLookController;
@class SessionView;

Expand Down Expand Up @@ -216,7 +217,7 @@ typedef enum {
@property(nonatomic, assign) BOOL newOutput;

// Do we need to prompt on close for this session?
@property(nonatomic, readonly) BOOL promptOnClose;
@property(nonatomic, readonly) iTermPromptOnCloseReason *promptOnCloseReason;

// Array of subprocessess names.
@property(nonatomic, readonly) NSArray *childJobNames;
Expand Down
24 changes: 15 additions & 9 deletions sources/PTYSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#import "iTermPasteHelper.h"
#import "iTermPreferences.h"
#import "iTermProfilePreferences.h"
#import "iTermPromptOnCloseReason.h"
#import "iTermRecentDirectoryMO.h"
#import "iTermRestorableSession.h"
#import "iTermRule.h"
Expand Down Expand Up @@ -1248,32 +1249,37 @@ - (NSArray *)childJobNames {
return names;
}

- (BOOL)promptOnClose
{
- (iTermPromptOnCloseReason *)promptOnCloseReason {
if (_exited) {
return NO;
return [iTermPromptOnCloseReason noReason];
}
switch ([[_profile objectForKey:KEY_PROMPT_CLOSE] intValue]) {
case PROMPT_ALWAYS:
return YES;
return [iTermPromptOnCloseReason profileAlwaysPrompts:_profile];

case PROMPT_NEVER:
return NO;
return [iTermPromptOnCloseReason noReason];

case PROMPT_EX_JOBS: {
NSMutableArray<NSString *> *blockingJobs = [NSMutableArray array];
NSArray *jobsThatDontRequirePrompting = [_profile objectForKey:KEY_JOBS];
for (NSString *childName in [self childJobNames]) {
if ([jobsThatDontRequirePrompting indexOfObject:childName] == NSNotFound) {
// This job is not in the ignore list.
return YES;
[blockingJobs addObject:childName];
}
}
// All jobs were in the ignore list.
return NO;
if (blockingJobs.count > 0) {
return [iTermPromptOnCloseReason profile:_profile blockedByJobs:blockingJobs];
} else {
// All jobs were in the ignore list.
return [iTermPromptOnCloseReason noReason];
}
}
}

return YES;
// This shouldn't happen
return [iTermPromptOnCloseReason profileAlwaysPrompts:_profile];
}

- (NSString *)_autoLogFilenameForTermId:(NSString *)termid {
Expand Down
2 changes: 1 addition & 1 deletion sources/PTYTab.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
- (void)notifyWindowChanged;
- (void)maximize;
// Does any session in this tab require prompt on close?
- (BOOL)promptOnClose;
- (iTermPromptOnCloseReason *)promptOnCloseReason;

// Anyone changing the number of sessions must call this after the sessions
// are "well formed".
Expand Down
10 changes: 5 additions & 5 deletions sources/PTYTab.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#import "iTermController.h"
#import "iTermGrowlDelegate.h"
#import "iTermPreferences.h"
#import "iTermPromptOnCloseReason.h"
#import "iTermProfilePreferences.h"
#import "MovePaneController.h"
#import "NSColor+iTerm.h"
Expand Down Expand Up @@ -3506,13 +3507,12 @@ - (void)unmaximize {
}
}

- (BOOL)promptOnClose {
- (iTermPromptOnCloseReason *)promptOnCloseReason {
iTermPromptOnCloseReason *reason = [iTermPromptOnCloseReason noReason];
for (PTYSession *aSession in [self sessions]) {
if ([aSession promptOnClose]) {
return YES;
}
[reason addReason:[aSession promptOnCloseReason]];
}
return NO;
return reason;
}

- (BOOL)canMoveCurrentSessionDividerBy:(int)direction horizontally:(BOOL)horizontally {
Expand Down
3 changes: 2 additions & 1 deletion sources/PseudoTerminal.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

@class PTYSession;
@class PSMTabBarControl;
@class iTermPromptOnCloseReason;
@class iTermToolbeltView;
@class iTermController;
@class TmuxController;
Expand Down Expand Up @@ -181,7 +182,7 @@ extern NSString *const kPseudoTerminalStateRestorationWindowArrangementKey;
- (void)irAdvance:(int)dir;

// Does any session want to be prompted for closing?
- (BOOL)promptOnClose;
- (iTermPromptOnCloseReason *)promptOnCloseReason;

// Accessor for toolbelt view.
- (iTermToolbeltView *)toolbelt;
Expand Down
17 changes: 8 additions & 9 deletions sources/PseudoTerminal.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#import "iTermPreferences.h"
#import "iTermProfilePreferences.h"
#import "iTermProfilesWindowController.h"
#import "iTermPromptOnCloseReason.h"
#import "iTermQuickLookController.h"
#import "iTermRootTerminalView.h"
#import "iTermSelection.h"
Expand Down Expand Up @@ -1137,7 +1138,7 @@ - (BOOL)confirmCloseTab:(PTYTab *)aTab
}

BOOL mustAsk = NO;
if (numClosing > 0 && [aTab promptOnClose]) {
if (numClosing > 0 && [aTab promptOnCloseReason].hasReason) {
mustAsk = YES;
}
if (numClosing > 1 &&
Expand Down Expand Up @@ -1325,7 +1326,7 @@ - (void)closeSessionWithConfirmation:(PTYSession *)aSession
BOOL okToClose = NO;
if ([aSession exited]) {
okToClose = YES;
} else if (![aSession promptOnClose]) {
} else if (![aSession promptOnCloseReason].hasReason) {
okToClose = YES;
} else {
okToClose = [self confirmCloseForSessions:[NSArray arrayWithObject:aSession]
Expand Down Expand Up @@ -2118,14 +2119,12 @@ - (void)windowDidDeminiaturize:(NSNotification *)aNotification
userInfo:nil];
}

- (BOOL)promptOnClose
{
- (iTermPromptOnCloseReason *)promptOnCloseReason {
iTermPromptOnCloseReason *reason = [iTermPromptOnCloseReason noReason];
for (PTYSession *aSession in [self allSessions]) {
if ([aSession promptOnClose]) {
return YES;
}
[reason addReason:[aSession promptOnCloseReason]];
}
return NO;
return reason;
}

// TODO: Kill this
Expand Down Expand Up @@ -2157,7 +2156,7 @@ - (BOOL)windowShouldClose:(NSNotification *)aNotification
[appDelegate userDidInteractWithASession];

BOOL needPrompt = NO;
if ([self promptOnClose]) {
if ([self promptOnCloseReason].hasReason) {
needPrompt = YES;
}
if ([iTermPreferences boolForKey:kPreferenceKeyConfirmClosingMultipleTabs] &&
Expand Down
Loading

0 comments on commit 0e29ebb

Please sign in to comment.