Skip to content

Commit

Permalink
• Deselect external items by default.
Browse files Browse the repository at this point in the history
• 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
Chris Thomas committed May 15, 2006
1 parent 503098a commit 8833b88
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CommitWindow.xcodeproj/project.pbxproj
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion CommitWindowController.h
Expand Up @@ -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;

Expand Down
155 changes: 149 additions & 6 deletions CommitWindowController.m
Expand Up @@ -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
Expand Down Expand Up @@ -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");
Expand All @@ -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];
}
}
Expand All @@ -99,6 +114,11 @@ - (void) awakeFromNib

[fFilesController objectDidEndEditing:nil];


//
// Populate previous summary menu
//
[self populatePreviousSummaryMenu];

//
// Map the enter key to the OK button
Expand Down Expand Up @@ -160,20 +180,141 @@ - (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];
int i;
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.
Expand Down Expand Up @@ -227,6 +368,8 @@ - (IBAction) commit:(id) sender

- (IBAction) cancel:(id) sender
{
[self saveSummary];

fprintf(stdout, "commit window: cancel\n");
exit(-128);
}
Expand Down
2 changes: 2 additions & 0 deletions CommitWindow_Prefix.pch
Expand Up @@ -2,3 +2,5 @@
#ifdef __OBJC__
#import <Cocoa/Cocoa.h>
#endif

#import <ApplicationServices/ApplicationServices.h>
1 change: 1 addition & 0 deletions English.lproj/MainMenu.nib/classes.nib

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions English.lproj/MainMenu.nib/info.nib

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified English.lproj/MainMenu.nib/keyedobjects.nib
Binary file not shown.

0 comments on commit 8833b88

Please sign in to comment.