Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

• Deselect external items by default.

• Make it build with latest Xcode and attendant tools.
• Preserve the last few commit summaries in a persistent pop-up menu. Summaries are saved even when canceling.

git-svn-id: http://svn.textmate.org/trunk/Tools/CommitWindowProject@3346 dfb7d73b-c2ec-0310-8fea-fb051d288c6d
  • Loading branch information...
commit 8833b88c13d39559d8cbf8c8eaadcf75aa21e261 1 parent 503098a
Chris Thomas authored
View
2  CommitWindow.xcodeproj/project.pbxproj
@@ -278,6 +278,7 @@
isa = XCBuildConfiguration;
buildSettings = {
COPY_PHASE_STRIP = NO;
+ FRAMEWORK_SEARCH_PATHS = "$(SDKROOT)/System/Library/Frameworks";
GCC_DYNAMIC_NO_PIC = NO;
GCC_ENABLE_FIX_AND_CONTINUE = YES;
GCC_GENERATE_DEBUGGING_SYMBOLS = YES;
@@ -300,6 +301,7 @@
buildSettings = {
COPY_PHASE_STRIP = YES;
DEAD_CODE_STRIPPING = YES;
+ FRAMEWORK_SEARCH_PATHS = "$(SDKROOT)/System/Library/Frameworks";
GCC_DYNAMIC_NO_PIC = YES;
GCC_ENABLE_CPP_EXCEPTIONS = NO;
GCC_ENABLE_CPP_RTTI = NO;
View
6 CommitWindowController.h
@@ -13,9 +13,13 @@
{
// NSMutableArray * fFiles; // {@"commit", @"path"}
IBOutlet NSArrayController * fFilesController;
+
+ IBOutlet NSWindow * fWindow;
+
IBOutlet NSTextField * fRequestText;
IBOutlet NSTextView * fCommitMessage;
- IBOutlet NSWindow * fWindow;
+ IBOutlet NSPopUpButton * fPreviousSummaryPopUp;
+
IBOutlet NSButton * fCancelButton;
IBOutlet NSButton * fOKButton;
View
155 CommitWindowController.m
@@ -7,11 +7,12 @@
//
#import "CommitWindowController.h"
-
-//FIX ME HIServices/Processes.h doesn't work -- is this a Tiger-specific problem?
-#import </System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/HIServices.framework/Versions/A/Headers/HIServices.h>
#import "VersionControlColors.h"
+@interface CommitWindowController (Private)
+- (void) populatePreviousSummaryMenu;
+@end
+
@implementation CommitWindowController
- (void) awakeFromNib
@@ -63,7 +64,7 @@ - (void) awakeFromNib
}
else if( [argument isEqualToString:@"--status"] )
{
- // Next argument should be a colon-seperated list of status strings, one for each path, in order
+ // Next argument should be a colon-seperated list of status strings, one for each path
if( i >= (argc - 1) )
{
fprintf(stderr, "commit window: missing text: --status \"A:D:M:M:M\"\n");
@@ -77,9 +78,23 @@ - (void) awakeFromNib
else
{
NSMutableDictionary * dictionary = [fFilesController newObject];
+ BOOL itemSelectedForCommit;
[dictionary setObject:[argument stringByAbbreviatingWithTildeInPath] forKey:@"path"];
- // [dictionary setObject:[NSNumber numberWithBool:YES] forKey:@"commit"]; not needed; the binding defaults to YES
+ if( fFileStatusStrings != nil )
+ {
+ // Deselect external commits by default
+ if([[fFileStatusStrings objectAtIndex:[[fFilesController content] count]] hasPrefix:@"X"])
+ {
+ itemSelectedForCommit = NO;
+ }
+ else
+ {
+ itemSelectedForCommit = YES;
+ }
+ [dictionary setObject:[NSNumber numberWithBool:itemSelectedForCommit] forKey:@"commit"];
+ }
+
[fFilesController addObject:dictionary];
}
}
@@ -99,6 +114,11 @@ - (void) awakeFromNib
[fFilesController objectDidEndEditing:nil];
+
+ //
+ // Populate previous summary menu
+ //
+ [self populatePreviousSummaryMenu];
//
// Map the enter key to the OK button
@@ -160,13 +180,132 @@ - (void) awakeFromNib
}
}
-
// center again after resize
[fWindow center];
[fWindow makeKeyAndOrderFront:self];
}
+#if 0
+#pragma mark -
+#pragma mark Summary save/restore
+#endif
+
+#define kMaxSavedSummariesCount 5
+#define kDisplayCharsOfSummaryInMenuItemCount 30
+#define kPreviousSummariesKey "prev-summaries"
+#define kPreviousSummariesItemTitle "Previous Summaries"
+
+- (void) populatePreviousSummaryMenu
+{
+ NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
+ NSArray * summaries = [defaults arrayForKey:@kPreviousSummariesKey];
+
+ if( summaries == nil )
+ {
+ // No previous summaries, no menu
+ [fPreviousSummaryPopUp setEnabled:NO];
+ }
+ else
+ {
+ NSMenu * menu = [[NSMenu alloc] initWithTitle:@kPreviousSummariesItemTitle];
+ NSMenuItem * item;
+
+ unsigned int summaryCount = [summaries count];
+ unsigned int index;
+
+ // PopUp title
+ [menu addItemWithTitle:@kPreviousSummariesItemTitle action:@selector(restoreSummary:) keyEquivalent:@""];
+
+ for(index = 0; index < summaryCount; index += 1)
+ {
+ NSString * summary = [summaries objectAtIndex:index];
+ NSString * itemName;
+
+ itemName = summary;
+
+ // Limit length of menu item names
+ if( [itemName length] > kDisplayCharsOfSummaryInMenuItemCount )
+ {
+ itemName = [itemName substringToIndex:kDisplayCharsOfSummaryInMenuItemCount];
+
+ // append ellipsis
+ itemName = [itemName stringByAppendingFormat: @"%C", 0x2026];
+ }
+
+ item = [menu addItemWithTitle:itemName action:@selector(restoreSummary:) keyEquivalent:@""];
+ [item setTarget:self];
+
+ [item setRepresentedObject:summary];
+ }
+
+ [fPreviousSummaryPopUp setMenu:menu];
+ }
+}
+
+- (void) restoreSummary:(id)sender
+{
+ NSString * summary = [sender representedObject];
+
+ [fCommitMessage setString:summary];
+}
+
+// Save, in an LRU list, the most recent commit summary
+- (void) saveSummary
+{
+ NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
+ NSString * latestSummary = [fCommitMessage string];
+
+ NSLog(@"%s%@", _cmd, latestSummary);
+
+ // avoid empty string
+ if( ! [latestSummary isEqualToString:@""] )
+ {
+ NSArray * oldSummaries = [defaults arrayForKey:@kPreviousSummariesKey];
+ NSMutableArray * newSummaries;
+
+ if( oldSummaries != nil )
+ {
+ unsigned int oldIndex;
+
+ newSummaries = [oldSummaries mutableCopy];
+
+ // Already in the array? Move it to latest position
+ oldIndex = [newSummaries indexOfObject:latestSummary];
+ if( oldIndex != NSNotFound )
+ {
+ [newSummaries exchangeObjectAtIndex:oldIndex withObjectAtIndex:[newSummaries count] - 1];
+ }
+ else
+ {
+ // Add object, remove oldest object
+ [newSummaries addObject:latestSummary];
+ if( [newSummaries count] > kMaxSavedSummariesCount )
+ {
+ [newSummaries removeObjectAtIndex:0];
+ }
+ }
+ }
+ else
+ {
+ // First time
+ newSummaries = [NSMutableArray arrayWithObject:latestSummary];
+ }
+
+ [defaults setObject:newSummaries forKey:@kPreviousSummariesKey];
+
+ // Write the defaults to disk
+ [defaults synchronize];
+ }
+}
+
+#if 0
+#pragma mark -
+#pragma mark Actions
+#endif
+
+
+
- (IBAction) commit:(id) sender
{
NSArray * objects = [fFilesController arrangedObjects];
@@ -174,6 +313,8 @@ - (IBAction) commit:(id) sender
int pathsToCommitCount = 0;
NSMutableString * commitString;
+ [self saveSummary];
+
//
// Quote any single-quotes in the commit message
// \' doesn't work with bash. We must use string concatenation.
@@ -227,6 +368,8 @@ - (IBAction) commit:(id) sender
- (IBAction) cancel:(id) sender
{
+ [self saveSummary];
+
fprintf(stdout, "commit window: cancel\n");
exit(-128);
}
View
2  CommitWindow_Prefix.pch
@@ -2,3 +2,5 @@
#ifdef __OBJC__
#import <Cocoa/Cocoa.h>
#endif
+
+#import <ApplicationServices/ApplicationServices.h>
View
1  English.lproj/MainMenu.nib/classes.nib
@@ -12,6 +12,7 @@
fFilesController = NSArrayController;
fOKButton = NSButton;
fPathColumn = NSTableColumn;
+ fPreviousSummaryPopUp = NSPopUpButton;
fRequestText = NSTextField;
fStatusColumn = NSTableColumn;
fWindow = NSWindow;
View
10 English.lproj/MainMenu.nib/info.nib
@@ -3,20 +3,20 @@
<plist version="1.0">
<dict>
<key>IBDocumentLocation</key>
- <string>94 233 356 240 0 0 1280 1002 </string>
+ <string>184 149 356 240 0 0 1440 878 </string>
<key>IBEditorPositions</key>
<dict>
<key>263</key>
- <string>94 478 125 44 0 0 1280 1002 </string>
+ <string>107 416 125 44 0 0 1440 878 </string>
</dict>
<key>IBFramework Version</key>
- <string>439.0</string>
+ <string>443.0</string>
<key>IBOpenObjects</key>
<array>
- <integer>263</integer>
<integer>21</integer>
+ <integer>263</integer>
</array>
<key>IBSystem Version</key>
- <string>8C46</string>
+ <string>8I1119</string>
</dict>
</plist>
View
BIN  English.lproj/MainMenu.nib/keyedobjects.nib
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.