Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 13746a5

Browse files
committedJun 9, 2009
PBGitWindowController: Use beginSheetModalForWindow instead of runModal
Introduce a new showMessageSheet/showErrorSheet-method for PBGitWindowController which uses the beginSheetModalForWindow method of NSAlert whereever possible. This has the advantage over runModal as it doesn't block the other instances of GitX and is generally more unobstrusive for simple status-messages. Signed-off-by: Johannes Gilger <[email protected]>
1 parent 64b977e commit 13746a5

File tree

5 files changed

+25
-32
lines changed

5 files changed

+25
-32
lines changed
 

‎PBGitCommitController.m

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -272,32 +272,20 @@ - (void) commitFailedBecause:(NSString *)reason
272272
{
273273
self.busy--;
274274
self.status = [@"Commit failed: " stringByAppendingString:reason];
275-
[[NSAlert alertWithMessageText:@"Commit failed"
276-
defaultButton:nil
277-
alternateButton:nil
278-
otherButton:nil
279-
informativeTextWithFormat:reason] runModal];
275+
[[repository windowController] showMessageSheet:@"Commit failed" infoText:reason];
280276
return;
281277
}
282278

283279
- (IBAction) commit:(id) sender
284280
{
285281
if ([[cachedFilesController arrangedObjects] count] == 0) {
286-
[[NSAlert alertWithMessageText:@"No changes to commit"
287-
defaultButton:nil
288-
alternateButton:nil
289-
otherButton:nil
290-
informativeTextWithFormat:@"You must first stage some changes before committing"] runModal];
282+
[[repository windowController] showMessageSheet:@"No changes to commit" infoText:@"You must first stage some changes before committing"];
291283
return;
292284
}
293285

294286
NSString *commitMessage = [commitMessageView string];
295287
if ([commitMessage length] < 3) {
296-
[[NSAlert alertWithMessageText:@"Commitmessage missing"
297-
defaultButton:nil
298-
alternateButton:nil
299-
otherButton:nil
300-
informativeTextWithFormat:@"Please enter a commit message before committing"] runModal];
288+
[[repository windowController] showMessageSheet:@"Commitmessage missing" infoText:@"Please enter a commit message before committing"];
301289
return;
302290
}
303291

‎PBGitIndexController.m

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ - (void) ignoreFiles:(NSArray *)files
113113
} else {
114114
ignoreFile = [NSMutableString stringWithContentsOfFile:gitIgnoreName usedEncoding:&enc error:&error];
115115
if (error) {
116-
[[NSAlert alertWithError:error] runModal];
116+
[[commitController.repository windowController] showErrorSheet:error];
117117
return;
118118
}
119119
// Add a newline if not yet present
@@ -124,7 +124,7 @@ - (void) ignoreFiles:(NSArray *)files
124124

125125
[ignoreFile writeToFile:gitIgnoreName atomically:YES encoding:enc error:&error];
126126
if (error)
127-
[[NSAlert alertWithError:error] runModal];
127+
[[commitController.repository windowController] showErrorSheet:error];
128128
}
129129

130130
# pragma mark Displaying diffs
@@ -166,11 +166,7 @@ - (void) forceRevertChangesForFiles:(NSArray *)files
166166
int ret = 1;
167167
[commitController.repository outputForArguments:arguments inputString:input retValue:&ret];
168168
if (ret) {
169-
[[NSAlert alertWithMessageText:@"Reverting changes failed"
170-
defaultButton:nil
171-
alternateButton:nil
172-
otherButton:nil
173-
informativeTextWithFormat:@"Reverting changes failed with error code %i", ret] runModal];
169+
[[commitController.repository windowController] showMessageSheet:@"Reverting changes failed" infoText:[NSString stringWithFormat:@"Reverting changes failed with error code %i", ret]];
174170
return;
175171
}
176172

‎PBGitWindowController.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929

3030
- (void)changeViewController:(NSInteger)whichViewTag;
3131
- (void)useToolbar:(NSToolbar *)toolbar;
32+
- (void)showMessageSheet:(NSString *)messageText infoText:(NSString *)infoText;
33+
- (void)showErrorSheet:(NSError *)error;
3234

3335
- (IBAction) showCommitView:(id)sender;
3436
- (IBAction) showHistoryView:(id)sender;

‎PBGitWindowController.m

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,21 @@ - (void) showHistoryView:(id)sender
122122
self.selectedViewIndex = 0;
123123
}
124124

125+
- (void)showMessageSheet:(NSString *)messageText infoText:(NSString *)infoText
126+
{
127+
[[NSAlert alertWithMessageText:messageText
128+
defaultButton:nil
129+
alternateButton:nil
130+
otherButton:nil
131+
informativeTextWithFormat:infoText] beginSheetModalForWindow: [self window] modalDelegate:self didEndSelector:nil contextInfo:nil];
132+
}
133+
134+
- (void)showErrorSheet:(NSError *)error
135+
{
136+
[[NSAlert alertWithError:error] beginSheetModalForWindow: [self window] modalDelegate:self didEndSelector:nil contextInfo:nil];
137+
}
138+
139+
125140
#pragma mark -
126141
#pragma mark Toolbar Delegates
127142

‎PBRefController.m

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,7 @@ - (void) checkoutRef:(PBRefMenuItem *)sender
6060
int ret = 1;
6161
[historyController.repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"checkout", [[sender ref] shortName], nil] retValue: &ret];
6262
if (ret) {
63-
[[NSAlert alertWithMessageText:@"Checking out branch failed"
64-
defaultButton:@"OK"
65-
alternateButton:nil
66-
otherButton:nil
67-
informativeTextWithFormat:@"There was an error checking out the branch. Perhaps your working directory is not clean?"] runModal];
63+
[[historyController.repository windowController] showMessageSheet:@"Checking out branch failed" infoText:@"There was an error checking out the branch. Perhaps your working directory is not clean?"];
6864
return;
6965
}
7066
[historyController.repository reloadRefs];
@@ -79,11 +75,7 @@ - (void) tagInfo:(PBRefMenuItem *)sender
7975
NSString *info = [historyController.repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"tag", @"-n50", @"-l", [[sender ref] shortName], nil] retValue: &ret];
8076

8177
if (!ret) {
82-
[[NSAlert alertWithMessageText:message
83-
defaultButton:@"OK"
84-
alternateButton:nil
85-
otherButton:nil
86-
informativeTextWithFormat:info] runModal];
78+
[[historyController.repository windowController] showMessageSheet:message infoText:info];
8779
}
8880
return;
8981
}

0 commit comments

Comments
 (0)