mirror of
https://github.com/kennethreitz-archive/gitx.git
synced 2026-06-05 23:40:18 +00:00
CommitView: Use the status bar to update on status
This commit is contained in:
+11
-3
@@ -17,16 +17,24 @@
|
||||
IBOutlet NSTextView *commitMessageView;
|
||||
IBOutlet NSArrayController *unstagedFilesController;
|
||||
IBOutlet NSArrayController *cachedFilesController;
|
||||
NSString *status;
|
||||
|
||||
// We use busy as a count of active processes.
|
||||
// You can increase it when your process start
|
||||
// And decrease it after you have finished.
|
||||
int busy;
|
||||
|
||||
IBOutlet PBIconAndTextCell* unstagedButtonCell;
|
||||
IBOutlet PBIconAndTextCell* cachedButtonCell;
|
||||
}
|
||||
|
||||
@property (retain) NSMutableArray *files;
|
||||
@property (copy) NSString *status;
|
||||
@property (assign) int busy;
|
||||
|
||||
- (void) readCachedFiles;
|
||||
- (void) readOtherFiles;
|
||||
- (void) readUnstagedFiles;
|
||||
- (void) readCachedFiles:(NSNotification *)notification;
|
||||
- (void) readOtherFiles:(NSNotification *)notification;
|
||||
- (void) readUnstagedFiles:(NSNotification *)notification;
|
||||
|
||||
- (IBAction) refresh:(id) sender;
|
||||
- (IBAction) commit:(id) sender;
|
||||
|
||||
+76
-43
@@ -12,10 +12,12 @@
|
||||
|
||||
@implementation PBGitCommitController
|
||||
|
||||
@synthesize files;
|
||||
@synthesize files, status, busy;
|
||||
|
||||
- (void)awakeFromNib
|
||||
{
|
||||
self.busy = 0;
|
||||
|
||||
[unstagedButtonCell setAction:@selector(cellClicked:)];
|
||||
[cachedButtonCell setAction:@selector(cellClicked:)];
|
||||
|
||||
@@ -44,6 +46,45 @@
|
||||
return lines;
|
||||
}
|
||||
|
||||
- (void) refresh:(id) sender
|
||||
{
|
||||
self.status = @"Refreshing index…";
|
||||
self.busy++;
|
||||
files = [NSMutableArray array];
|
||||
[repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"update-index", @"-q", @"--unmerged", @"--ignore-missing", @"--refresh", nil]];
|
||||
self.busy--;
|
||||
|
||||
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
|
||||
[nc removeObserver:self];
|
||||
|
||||
// Other files
|
||||
NSArray *arguments = [NSArray arrayWithObjects:@"ls-files", @"--others", @"--exclude-standard", nil];
|
||||
NSFileHandle *handle = [repository handleInWorkDirForArguments:arguments];
|
||||
[nc addObserver:self selector:@selector(readOtherFiles:) name:NSFileHandleReadCompletionNotification object:handle];
|
||||
self.busy++;
|
||||
[handle readInBackgroundAndNotify];
|
||||
|
||||
// Unstaged files
|
||||
handle = [repository handleInWorkDirForArguments:[NSArray arrayWithObject:@"diff-files"]];
|
||||
[nc addObserver:self selector:@selector(readUnstagedFiles:) name:NSFileHandleReadCompletionNotification object:handle];
|
||||
self.busy++;
|
||||
[handle readInBackgroundAndNotify];
|
||||
|
||||
// Cached files
|
||||
handle = [repository handleInWorkDirForArguments:[NSArray arrayWithObjects:@"diff-index", @"--cached", @"HEAD", nil]];
|
||||
[nc addObserver:self selector:@selector(readCachedFiles:) name:NSFileHandleReadCompletionNotification object:handle];
|
||||
self.busy++;
|
||||
[handle readInBackgroundAndNotify];
|
||||
|
||||
self.files = files;
|
||||
}
|
||||
|
||||
- (void) doneProcessingIndex
|
||||
{
|
||||
if (!--self.busy)
|
||||
self.status = @"Ready";
|
||||
}
|
||||
|
||||
- (void) readOtherFiles:(NSNotification *)notification;
|
||||
{
|
||||
NSArray *lines = [self linesFromNotification:notification];
|
||||
@@ -56,34 +97,7 @@
|
||||
[files addObject: file];
|
||||
}
|
||||
self.files = files;
|
||||
}
|
||||
|
||||
- (void) refresh:(id) sender
|
||||
{
|
||||
files = [NSMutableArray array];
|
||||
[repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"update-index", @"-q", @"--unmerged", @"--ignore-missing", @"--refresh", nil]];
|
||||
|
||||
|
||||
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
|
||||
[nc removeObserver:self];
|
||||
|
||||
// Other files
|
||||
NSArray *arguments = [NSArray arrayWithObjects:@"ls-files", @"--others", @"--exclude-standard", nil];
|
||||
NSFileHandle *handle = [repository handleInWorkDirForArguments:arguments];
|
||||
[nc addObserver:self selector:@selector(readOtherFiles:) name:NSFileHandleReadCompletionNotification object:handle];
|
||||
[handle readInBackgroundAndNotify];
|
||||
|
||||
// Unstaged files
|
||||
handle = [repository handleInWorkDirForArguments:[NSArray arrayWithObject:@"diff-files"]];
|
||||
[nc addObserver:self selector:@selector(readUnstagedFiles:) name:NSFileHandleReadCompletionNotification object:handle];
|
||||
[handle readInBackgroundAndNotify];
|
||||
|
||||
// Cached files
|
||||
handle = [repository handleInWorkDirForArguments:[NSArray arrayWithObjects:@"diff-index", @"--cached", @"HEAD", nil]];
|
||||
[nc addObserver:self selector:@selector(readCachedFiles:) name:NSFileHandleReadCompletionNotification object:handle];
|
||||
[handle readInBackgroundAndNotify];
|
||||
|
||||
self.files = files;
|
||||
[self doneProcessingIndex];
|
||||
}
|
||||
|
||||
- (void) readUnstagedFiles:(NSNotification *)notification
|
||||
@@ -100,6 +114,7 @@
|
||||
[files addObject: file];
|
||||
}
|
||||
self.files = files;
|
||||
[self doneProcessingIndex];
|
||||
}
|
||||
|
||||
- (void) readCachedFiles:(NSNotification *)notification
|
||||
@@ -117,10 +132,24 @@
|
||||
[files addObject: file];
|
||||
}
|
||||
self.files = files;
|
||||
[self doneProcessingIndex];
|
||||
}
|
||||
|
||||
- (void) commitFailedBecause:(NSString *)reason
|
||||
{
|
||||
self.busy--;
|
||||
self.status = [@"Commit failed: " stringByAppendingString:reason];
|
||||
[[NSAlert alertWithMessageText:@"Commit failed"
|
||||
defaultButton:nil
|
||||
alternateButton:nil
|
||||
otherButton:nil
|
||||
informativeTextWithFormat:reason] runModal];
|
||||
return;
|
||||
}
|
||||
|
||||
- (IBAction) commit:(id) sender
|
||||
{
|
||||
|
||||
NSString *commitMessage = [commitMessageView string];
|
||||
if ([commitMessage length] < 3) {
|
||||
[[NSAlert alertWithMessageText:@"Commitmessage missing"
|
||||
@@ -130,29 +159,33 @@
|
||||
informativeTextWithFormat:@"Please enter a commit message before committing"] runModal];
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
self.busy++;
|
||||
self.status = @"Creating tree..";
|
||||
NSString *tree = [repository outputForCommand:@"write-tree"];
|
||||
if ([tree length] != 40) {
|
||||
NSLog(@"Tree: %@", tree);
|
||||
return;
|
||||
}
|
||||
if ([tree length] != 40)
|
||||
return [self commitFailedBecause:@"Could not create a tree"];
|
||||
|
||||
int ret;
|
||||
NSString *commit = [repository outputForArguments:[NSArray arrayWithObjects:@"commit-tree", tree, @"-p", @"HEAD", nil]
|
||||
inputString:commitMessage
|
||||
retValue: &ret];
|
||||
if (ret || [commit length] != 40) {
|
||||
NSLog(@"Commit failed");
|
||||
return;
|
||||
}
|
||||
|
||||
if (ret || [commit length] != 40)
|
||||
return [self commitFailedBecause:@"Could not create a commit object"];
|
||||
|
||||
[repository outputForArguments:[NSArray arrayWithObjects:@"update-ref", @"-m", @"Commit from GitX", @"HEAD", commit, nil]
|
||||
retValue: &ret];
|
||||
if (ret) {
|
||||
NSLog(@"Commit failed(2)");
|
||||
return;
|
||||
}
|
||||
if (ret)
|
||||
return [self commitFailedBecause:@"Could not update HEAD"];
|
||||
|
||||
NSLog(@"Success! New commit: %@", commit);
|
||||
[[NSAlert alertWithMessageText:@"Commit succesful"
|
||||
defaultButton:nil
|
||||
alternateButton:nil
|
||||
otherButton:nil
|
||||
informativeTextWithFormat:@"Successfully created commit %@", commit] runModal];
|
||||
|
||||
self.busy--;
|
||||
[commitMessageView setString:@""];
|
||||
[self refresh:self];
|
||||
}
|
||||
|
||||
+55
-5
@@ -8,7 +8,7 @@
|
||||
<string key="IBDocument.HIToolboxVersion">352.00</string>
|
||||
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<integer value="130"/>
|
||||
<integer value="1" id="9"/>
|
||||
</object>
|
||||
<object class="NSArray" key="IBDocument.PluginDependencies">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
@@ -35,7 +35,7 @@
|
||||
<object class="NSTextField" id="1073221655">
|
||||
<reference key="NSNextResponder" ref="750704519"/>
|
||||
<int key="NSvFlags">292</int>
|
||||
<string key="NSFrame">{{17, 7}, {305, 17}}</string>
|
||||
<string key="NSFrame">{{27, 7}, {305, 17}}</string>
|
||||
<reference key="NSSuperview" ref="750704519"/>
|
||||
<bool key="NSEnabled">YES</bool>
|
||||
<object class="NSTextFieldCell" key="NSCell" id="1003368966">
|
||||
@@ -114,7 +114,7 @@
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<integer value="12" id="777559147"/>
|
||||
<reference ref="777559147"/>
|
||||
<integer value="1" id="9"/>
|
||||
<reference ref="9"/>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
@@ -869,6 +869,16 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
|
||||
<string key="NSFrame">{{0, 35}, {852, 397}}</string>
|
||||
<reference key="NSSuperview" ref="750704519"/>
|
||||
</object>
|
||||
<object class="NSProgressIndicator" id="221814497">
|
||||
<reference key="NSNextResponder" ref="750704519"/>
|
||||
<int key="NSvFlags">1316</int>
|
||||
<object class="NSPSMatrix" key="NSDrawMatrix"/>
|
||||
<string key="NSFrame">{{6, 7}, {16, 16}}</string>
|
||||
<reference key="NSSuperview" ref="750704519"/>
|
||||
<int key="NSpiFlags">28938</int>
|
||||
<double key="NSMinValue">1.600000e+01</double>
|
||||
<double key="NSMaxValue">1.000000e+02</double>
|
||||
</object>
|
||||
</object>
|
||||
<string key="NSFrameSize">{852, 432}</string>
|
||||
<reference key="NSSuperview"/>
|
||||
@@ -1090,6 +1100,38 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
|
||||
</object>
|
||||
<int key="connectionID">213</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBBindingConnection" key="connection">
|
||||
<string key="label">value: status</string>
|
||||
<reference key="source" ref="1073221655"/>
|
||||
<reference key="destination" ref="1001"/>
|
||||
<object class="NSNibBindingConnector" key="connector">
|
||||
<reference key="NSSource" ref="1073221655"/>
|
||||
<reference key="NSDestination" ref="1001"/>
|
||||
<string key="NSLabel">value: status</string>
|
||||
<string key="NSBinding">value</string>
|
||||
<string key="NSKeyPath">status</string>
|
||||
<int key="NSNibBindingConnectorVersion">2</int>
|
||||
</object>
|
||||
</object>
|
||||
<int key="connectionID">216</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBBindingConnection" key="connection">
|
||||
<string key="label">animate: busy</string>
|
||||
<reference key="source" ref="221814497"/>
|
||||
<reference key="destination" ref="1001"/>
|
||||
<object class="NSNibBindingConnector" key="connector">
|
||||
<reference key="NSSource" ref="221814497"/>
|
||||
<reference key="NSDestination" ref="1001"/>
|
||||
<string key="NSLabel">animate: busy</string>
|
||||
<string key="NSBinding">animate</string>
|
||||
<string key="NSKeyPath">busy</string>
|
||||
<int key="NSNibBindingConnectorVersion">2</int>
|
||||
</object>
|
||||
</object>
|
||||
<int key="connectionID">222</int>
|
||||
</object>
|
||||
</object>
|
||||
<object class="IBMutableOrderedSet" key="objectRecords">
|
||||
<object class="NSArray" key="orderedObjects">
|
||||
@@ -1125,8 +1167,9 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
|
||||
<reference key="object" ref="750704519"/>
|
||||
<object class="NSMutableArray" key="children">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<reference ref="1073221655"/>
|
||||
<reference ref="812432808"/>
|
||||
<reference ref="221814497"/>
|
||||
<reference ref="1073221655"/>
|
||||
</object>
|
||||
<reference key="parent" ref="1002"/>
|
||||
</object>
|
||||
@@ -1377,6 +1420,11 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
|
||||
<reference key="object" ref="39450212"/>
|
||||
<reference key="parent" ref="79177434"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">217</int>
|
||||
<reference key="object" ref="221814497"/>
|
||||
<reference key="parent" ref="750704519"/>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
<object class="NSMutableDictionary" key="flattenedProperties">
|
||||
@@ -1403,6 +1451,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
|
||||
<string>163.IBPluginDependency</string>
|
||||
<string>164.IBPluginDependency</string>
|
||||
<string>2.IBPluginDependency</string>
|
||||
<string>217.IBPluginDependency</string>
|
||||
<string>42.IBPluginDependency</string>
|
||||
<string>45.IBPluginDependency</string>
|
||||
<string>46.IBPluginDependency</string>
|
||||
@@ -1450,6 +1499,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
</object>
|
||||
</object>
|
||||
<object class="NSMutableDictionary" key="unlocalizedProperties">
|
||||
@@ -1472,7 +1522,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
|
||||
</object>
|
||||
</object>
|
||||
<nil key="sourceID"/>
|
||||
<int key="maxID">213</int>
|
||||
<int key="maxID">222</int>
|
||||
</object>
|
||||
<object class="IBClassDescriber" key="IBDocument.Classes">
|
||||
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
|
||||
|
||||
Reference in New Issue
Block a user