Skip to content

Commit 95e0503

Browse files
committed
Add a string truncation category because on a very large commit the showMessage sheet just exploded out of my monitor.
1 parent a3ede54 commit 95e0503

File tree

5 files changed

+119
-4
lines changed

5 files changed

+119
-4
lines changed

GitX.xcodeproj/project.pbxproj

+9-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
551BF176112F3F4B00265053 /* gitx_askpasswd in Resources */ = {isa = PBXBuildFile; fileRef = 551BF111112F371800265053 /* gitx_askpasswd */; };
3333
653D930A109BEAFE00B26705 /* PBGitXErrors.m in Sources */ = {isa = PBXBuildFile; fileRef = 653D9309109BEAFE00B26705 /* PBGitXErrors.m */; };
3434
654D16E8108C6CA6008D960C /* PBQLOutlineView.m in Sources */ = {isa = PBXBuildFile; fileRef = F513085A0E0740F2000C8BCD /* PBQLOutlineView.m */; };
35+
654FEFA0115A2684004C8721 /* NSString_Truncate.m in Sources */ = {isa = PBXBuildFile; fileRef = 654FEF9F115A2684004C8721 /* NSString_Truncate.m */; };
3536
6552BA27109C4CA8003B4892 /* Preferences.xib in Resources */ = {isa = PBXBuildFile; fileRef = 47DBDB690E94EF6500671A1E /* Preferences.xib */; };
3637
65C77FA0108BF560003BD3B5 /* Quartz.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 65C77F9F108BF560003BD3B5 /* Quartz.framework */; };
3738
65F3544011599F3100235D5B /* AddRemoteBranchTemplate.png in Resources */ = {isa = PBXBuildFile; fileRef = 65A102F110A7D9FE0033C593 /* AddRemoteBranchTemplate.png */; };
@@ -247,6 +248,8 @@
247248
654D17E7108C90E8008D960C /* html */ = {isa = PBXFileReference; lastKnownFileType = folder; path = html; sourceTree = "<group>"; };
248249
654D18EF108C9597008D960C /* Install.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Install.xcconfig; sourceTree = "<group>"; };
249250
654D18F6108C96CB008D960C /* install.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = install.sh; sourceTree = "<group>"; };
251+
654FEF9F115A2684004C8721 /* NSString_Truncate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NSString_Truncate.m; sourceTree = "<group>"; };
252+
654FEFAF115A2747004C8721 /* NSString_Truncate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSString_Truncate.h; sourceTree = "<group>"; };
250253
65A102F110A7D9FE0033C593 /* AddRemoteBranchTemplate.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = AddRemoteBranchTemplate.png; path = Images/AddRemoteBranchTemplate.png; sourceTree = "<group>"; };
251254
65C77F9F108BF560003BD3B5 /* Quartz.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Quartz.framework; path = System/Library/Frameworks/Quartz.framework; sourceTree = SDKROOT; };
252255
770B37EC0679A11B001EADE2 /* GitTest_DataModel.xcdatamodel */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = wrapper.xcdatamodel; path = GitTest_DataModel.xcdatamodel; sourceTree = "<group>"; };
@@ -791,6 +794,8 @@
791794
F56524BA0E02D22D00F03B52 /* NSFileHandleExt.h */,
792795
F562C8850FE1766C000EC528 /* NSString_RegEx.h */,
793796
F562C8860FE1766C000EC528 /* NSString_RegEx.m */,
797+
654FEFAF115A2747004C8721 /* NSString_Truncate.h */,
798+
654FEF9F115A2684004C8721 /* NSString_Truncate.m */,
794799
F57CC38F0E05DDF2000472E2 /* PBEasyPipe.h */,
795800
F57CC3900E05DDF2000472E2 /* PBEasyPipe.m */,
796801
F5DFFA6A0E075D8800617813 /* PBEasyFS.h */,
@@ -1292,6 +1297,7 @@
12921297
D8295D2A1130A1DC00C838E8 /* PBGitHistoryList.m in Sources */,
12931298
D8295DE01130E43900C838E8 /* PBGitHistoryGrapher.m in Sources */,
12941299
D8E105471157C18200FC28A4 /* PBQLTextView.m in Sources */,
1300+
654FEFA0115A2684004C8721 /* NSString_Truncate.m in Sources */,
12951301
);
12961302
runOnlyForDeploymentPostprocessing = 0;
12971303
};
@@ -1632,11 +1638,13 @@
16321638
"$(inherited)",
16331639
"\"$(SRCROOT)\"",
16341640
);
1641+
GCC_C_LANGUAGE_STANDARD = gnu99;
16351642
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
16361643
GCC_MODEL_TUNING = G5;
16371644
GCC_PRECOMPILE_PREFIX_HEADER = YES;
16381645
GCC_PREFIX_HEADER = GitX_Prefix.pch;
1639-
GCC_PREPROCESSOR_DEFINITIONS_NOT_USED_IN_PRECOMPS = "";
1646+
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
1647+
GCC_WARN_CHECK_SWITCH_STATEMENTS = YES;
16401648
HEADER_SEARCH_PATHS = libgit2/src;
16411649
INFOPLIST_FILE = Info.plist;
16421650
INFOPLIST_OTHER_PREPROCESSOR_FLAGS = "-traditional";

NSString_Truncate.h

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//
2+
// NSString_Truncate.h
3+
// GitX
4+
//
5+
// Created by Andre Berg on 24.03.10.
6+
// Copyright 2010 Berg Media. All rights reserved.
7+
//
8+
// Licensed under the Apache License, Version 2.0 (the "License");
9+
// you may not use this file except in compliance with the License.
10+
// You may obtain a copy of the License at
11+
//
12+
// http://www.apache.org/licenses/LICENSE-2.0
13+
//
14+
// Unless required by applicable law or agreed to in writing, software
15+
// distributed under the License is distributed on an "AS IS" BASIS,
16+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
// See the License for the specific language governing permissions and
18+
// limitations under the License.
19+
20+
#import <Cocoa/Cocoa.h>
21+
22+
typedef enum {
23+
PBNSStringTruncateModeCenter = 0,
24+
PBNSStringTruncateModeStart = 1,
25+
PBNSStringTruncateModeEnd = 2
26+
} PBNSStringTruncateMode;
27+
28+
@interface NSString (PBGitXTruncateExtensions)
29+
30+
- (NSString *) truncateToLength:(NSUInteger)length mode:(PBNSStringTruncateMode)mode indicator:(NSString *)indicatorString;
31+
32+
@end

NSString_Truncate.m

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
//
2+
// NSString_Truncate.m
3+
// GitX
4+
//
5+
// Created by Andre Berg on 24.03.10.
6+
// Copyright 2010 Berg Media. All rights reserved.
7+
//
8+
// Licensed under the Apache License, Version 2.0 (the "License");
9+
// you may not use this file except in compliance with the License.
10+
// You may obtain a copy of the License at
11+
//
12+
// http://www.apache.org/licenses/LICENSE-2.0
13+
//
14+
// Unless required by applicable law or agreed to in writing, software
15+
// distributed under the License is distributed on an "AS IS" BASIS,
16+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
// See the License for the specific language governing permissions and
18+
// limitations under the License.
19+
20+
#import "NSString_Truncate.h"
21+
22+
@implementation NSString (PBGitXTruncateExtensions)
23+
24+
- (NSString *) truncateToLength:(NSUInteger)targetLength mode:(PBNSStringTruncateMode)mode indicator:(NSString *)indicatorString {
25+
26+
NSString * res = nil;
27+
NSString * firstPart;
28+
NSString * lastPart;
29+
30+
if (!indicatorString) {
31+
indicatorString = @"...";
32+
}
33+
34+
NSUInteger stringLength = [self length];
35+
NSUInteger ilength = [indicatorString length];
36+
37+
if (stringLength <= targetLength) {
38+
return self;
39+
} else if (stringLength <= 0 || (!self)) {
40+
return nil;
41+
} else {
42+
switch (mode) {
43+
case PBNSStringTruncateModeCenter:
44+
firstPart = [self substringToIndex:(targetLength/2)];
45+
lastPart = [self substringFromIndex:(stringLength-((targetLength/2))+ilength)];
46+
res = [NSString stringWithFormat:@"%@%@%@", firstPart, indicatorString, lastPart];
47+
break;
48+
case PBNSStringTruncateModeStart:
49+
res = [NSString stringWithFormat:@"%@%@", indicatorString, [self substringFromIndex:((stringLength-targetLength)+ilength)]];
50+
break;
51+
case PBNSStringTruncateModeEnd:
52+
res = [NSString stringWithFormat:@"%@%@", [self substringToIndex:(targetLength-ilength)], indicatorString];
53+
break;
54+
default:
55+
;
56+
NSException * myException = [NSException exceptionWithName:NSInvalidArgumentException
57+
reason:[NSString stringWithFormat:
58+
@"[%@ %s] called with nonsensical value for 'mode' (mode = %d) ***",
59+
[self class], _cmd, mode]
60+
userInfo:nil];
61+
@throw myException;
62+
return res;
63+
break;
64+
};
65+
}
66+
return res;
67+
}
68+
69+
@end

PBGitWindowController.m

+6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
#import "Terminal.h"
1414
#import "PBCloneRepsitoryToSheet.h"
1515
#import "PBGitSidebarController.h"
16+
#import "NSString_Truncate.h"
17+
18+
#define SHEET_INFOTEXT_CHAR_LIMIT 2000 // character size limit for the message sheet's info text
1619

1720
@implementation PBGitWindowController
1821

@@ -108,6 +111,9 @@ - (void) showHistoryView:(id)sender
108111

109112
- (void)showMessageSheet:(NSString *)messageText infoText:(NSString *)infoText
110113
{
114+
if ([infoText length] > SHEET_INFOTEXT_CHAR_LIMIT) {
115+
infoText = [infoText truncateToLength:SHEET_INFOTEXT_CHAR_LIMIT mode:PBNSStringTruncateModeCenter indicator:@" ... "];
116+
}
111117
[[NSAlert alertWithMessageText:messageText
112118
defaultButton:nil
113119
alternateButton:nil

PBRemoteProgressSheet.m

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
@interface PBRemoteProgressSheet ()
2626

27-
- (void) beginRemoteProgressSheetForArguments:(NSArray *)args title:(NSString *)theTitle description:(NSString *)theDescription inDir:(NSString *)dir windowController:(PBGitWindowController *)controller;
27+
- (void) beginRemoteProgressSheetForArguments:(NSArray *)args title:(NSString *)theTitle description:(NSString *)theDescription inDirectory:(NSString *)dir windowController:(PBGitWindowController *)controller;
2828
- (void) showSuccessMessage;
2929
- (void) showErrorMessage;
3030

@@ -55,7 +55,7 @@ @implementation PBRemoteProgressSheet
5555
+ (void) beginRemoteProgressSheetForArguments:(NSArray *)args title:(NSString *)theTitle description:(NSString *)theDescription inDir:(NSString *)dir windowController:(PBGitWindowController *)windowController
5656
{
5757
PBRemoteProgressSheet *sheet = [[self alloc] initWithWindowNibName:@"PBRemoteProgressSheet"];
58-
[sheet beginRemoteProgressSheetForArguments:args title:theTitle description:theDescription inDir:dir windowController:windowController];
58+
[sheet beginRemoteProgressSheetForArguments:args title:theTitle description:theDescription inDirectory:dir windowController:windowController];
5959
}
6060

6161

@@ -65,7 +65,7 @@ + (void) beginRemoteProgressSheetForArguments:(NSArray *)args title:(NSString *)
6565
}
6666

6767

68-
- (void) beginRemoteProgressSheetForArguments:(NSArray *)args title:(NSString *)theTitle description:(NSString *)theDescription inDir:(NSString *)dir windowController:(PBGitWindowController *)windowController
68+
- (void) beginRemoteProgressSheetForArguments:(NSArray *)args title:(NSString *)theTitle description:(NSString *)theDescription inDirectory:(NSString *)dir windowController:(PBGitWindowController *)windowController
6969
{
7070
controller = windowController;
7171
arguments = args;

0 commit comments

Comments
 (0)