Skip to content

Commit

Permalink
Added initial commit button functionality.
Browse files Browse the repository at this point in the history
  • Loading branch information
iamamused committed Oct 28, 2010
1 parent 389e201 commit 027d27f
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 7 deletions.
57 changes: 50 additions & 7 deletions English.lproj/MyDocument.xib
Expand Up @@ -552,6 +552,14 @@
</object>
<int key="connectionID">100043</int>
</object>
<object class="IBConnectionRecord">
<object class="IBActionConnection" key="connection">
<string key="label">commitChanges:</string>
<reference key="source" ref="512844837"/>
<reference key="destination" ref="25746127"/>
</object>
<int key="connectionID">100044</int>
</object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
Expand Down Expand Up @@ -756,7 +764,7 @@
</object>
</object>
<nil key="sourceID"/>
<int key="maxID">100043</int>
<int key="maxID">100044</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
Expand All @@ -765,14 +773,35 @@
<string key="className">MyDocument</string>
<string key="superclassName">NSDocument</string>
<object class="NSMutableDictionary" key="actions">
<string key="NS.key.0">copyGeneratedHTMLAction:</string>
<string key="NS.object.0">id</string>
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>commitChanges:</string>
<string>copyGeneratedHTMLAction:</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>id</string>
<string>id</string>
</object>
</object>
<object class="NSMutableDictionary" key="actionInfosByName">
<string key="NS.key.0">copyGeneratedHTMLAction:</string>
<object class="IBActionInfo" key="NS.object.0">
<string key="name">copyGeneratedHTMLAction:</string>
<string key="candidateClassName">id</string>
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>commitChanges:</string>
<string>copyGeneratedHTMLAction:</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBActionInfo">
<string key="name">commitChanges:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo">
<string key="name">copyGeneratedHTMLAction:</string>
<string key="candidateClassName">id</string>
</object>
</object>
</object>
<object class="NSMutableDictionary" key="outlets">
Expand Down Expand Up @@ -1215,6 +1244,20 @@
<string key="minorKey">Foundation.framework/Headers/NSURLDownload.h</string>
</object>
</object>
<object class="IBPartialClassDescription">
<string key="className">NSObject</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBFrameworkSource</string>
<string key="minorKey">Sparkle.framework/Headers/SUAppcast.h</string>
</object>
</object>
<object class="IBPartialClassDescription">
<string key="className">NSObject</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBFrameworkSource</string>
<string key="minorKey">Sparkle.framework/Headers/SUUpdater.h</string>
</object>
</object>
<object class="IBPartialClassDescription">
<string key="className">NSObject</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
Expand Down
4 changes: 4 additions & 0 deletions MyDocument.h
Expand Up @@ -22,8 +22,12 @@
BOOL hasSavedOrigin;
NSPoint savedOrigin;
BOOL savedAtBottom;

NSTask *commit;
NSPipe *gitOut;
}

- (IBAction)copyGeneratedHTMLAction:(id)sender;
- (IBAction)commitChanges:(id)sender;

@end
45 changes: 45 additions & 0 deletions MyDocument.m
Expand Up @@ -58,6 +58,14 @@ - (id)init {
userInfo:nil
repeats:YES];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(finishedCommit:)
name:NSTaskDidTerminateNotification
object:nil];

commit = nil;
gitOut = [[NSPipe alloc] init];

}
return self;
}
Expand Down Expand Up @@ -157,4 +165,41 @@ - (IBAction)copyGeneratedHTMLAction:(id)sender {
[[NSPasteboard generalPasteboard] setString:[self markdown2html:[markdownSource string]] forType:NSStringPboardType];
}

- (IBAction)commitChanges:(id)sender;
{
//http://cocoadevcentral.com/articles/000025.php
//http://github.com/pieter/gitx/blob/master/PBGitBinary.m

NSLog(@"Commiting changes.");

commit=[[NSTask alloc] init];
[commit setLaunchPath:@"/usr/bin/git"];

NSMutableArray *components = [NSMutableArray arrayWithArray:[[self fileURL] pathComponents]];
[components removeLastObject];

NSLog(@"path: %@", [components componentsJoinedByString:@"/"]);

[commit setCurrentDirectoryPath: [[components componentsJoinedByString:@"/"] stringByExpandingTildeInPath]];

[commit setArguments:[NSArray arrayWithObjects:@"commit", [[[self fileURL] pathComponents] lastObject], @"-m",@"Commit Message",nil]];

[commit setStandardOutput:gitOut];

NSLog(@"Commit: %@", commit);

[commit launch];
}

- (void)finishedCommit:(NSNotification *)aNotification {

//NSData *output = [[gitOut fileHandleForReading] readDataToEndOfFile];
//NSString *string = [[[NSString alloc] initWithData: output encoding: NSUTF8StringEncoding] autorelease];
//NSLog(@"GITOUT:", string);

[commit release]; // Don't forget to clean up memory
commit=nil; // Just in case...

}

@end

0 comments on commit 027d27f

Please sign in to comment.