mirror of
https://github.com/kennethreitz-archive/gitx.git
synced 2026-06-05 23:40:18 +00:00
CommitView: Add context menu to revert changes
This commit is contained in:
@@ -52,6 +52,7 @@
|
||||
F58A8F280E043698007E3FC0 /* commits.css in Resources */ = {isa = PBXBuildFile; fileRef = F58A8F270E043698007E3FC0 /* commits.css */; };
|
||||
F59116E60E843BB50072CCB1 /* PBGitCommitView.xib in Resources */ = {isa = PBXBuildFile; fileRef = F59116E50E843BB50072CCB1 /* PBGitCommitView.xib */; };
|
||||
F59116E90E843BCB0072CCB1 /* PBGitCommitController.m in Sources */ = {isa = PBXBuildFile; fileRef = F59116E80E843BCB0072CCB1 /* PBGitCommitController.m */; };
|
||||
F593DF780E9E636C003A8559 /* PBFileChangesTableView.m in Sources */ = {isa = PBXBuildFile; fileRef = F593DF770E9E636C003A8559 /* PBFileChangesTableView.m */; };
|
||||
F5945E170E02B0C200706420 /* PBGitRepository.m in Sources */ = {isa = PBXBuildFile; fileRef = F5945E160E02B0C200706420 /* PBGitRepository.m */; };
|
||||
F5AD56790E79B78100EDAAFE /* PBCommitList.m in Sources */ = {isa = PBXBuildFile; fileRef = F5AD56780E79B78100EDAAFE /* PBCommitList.m */; };
|
||||
F5B721C40E05CF7E00AF29DC /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = F5B721C20E05CF7E00AF29DC /* MainMenu.xib */; };
|
||||
@@ -164,6 +165,8 @@
|
||||
F59116E50E843BB50072CCB1 /* PBGitCommitView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = PBGitCommitView.xib; sourceTree = "<group>"; };
|
||||
F59116E70E843BCB0072CCB1 /* PBGitCommitController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBGitCommitController.h; sourceTree = "<group>"; };
|
||||
F59116E80E843BCB0072CCB1 /* PBGitCommitController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBGitCommitController.m; sourceTree = "<group>"; };
|
||||
F593DF760E9E636C003A8559 /* PBFileChangesTableView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBFileChangesTableView.h; sourceTree = "<group>"; };
|
||||
F593DF770E9E636C003A8559 /* PBFileChangesTableView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBFileChangesTableView.m; sourceTree = "<group>"; };
|
||||
F5945E150E02B0C200706420 /* PBGitRepository.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBGitRepository.h; sourceTree = "<group>"; };
|
||||
F5945E160E02B0C200706420 /* PBGitRepository.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBGitRepository.m; sourceTree = "<group>"; };
|
||||
F5AD56770E79B78100EDAAFE /* PBCommitList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBCommitList.h; sourceTree = "<group>"; };
|
||||
@@ -438,6 +441,8 @@
|
||||
children = (
|
||||
F5E927F60E883E7200056E75 /* PBChangedFile.h */,
|
||||
F5E927F70E883E7200056E75 /* PBChangedFile.m */,
|
||||
F593DF760E9E636C003A8559 /* PBFileChangesTableView.h */,
|
||||
F593DF770E9E636C003A8559 /* PBFileChangesTableView.m */,
|
||||
);
|
||||
name = Commit;
|
||||
sourceTree = "<group>";
|
||||
@@ -590,6 +595,7 @@
|
||||
F5140DC90E8A8EB20091E9F3 /* RoundedRectangle.m in Sources */,
|
||||
F56244090E9684B0002B6C44 /* PBUnsortableTableHeader.m in Sources */,
|
||||
F53C4DF70E97FC630022AD59 /* PBGitBinary.m in Sources */,
|
||||
F593DF780E9E636C003A8559 /* PBFileChangesTableView.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
||||
@@ -76,6 +76,24 @@
|
||||
self.hasUnstagedChanges = YES;
|
||||
}
|
||||
|
||||
- (void) forceRevertChanges
|
||||
{
|
||||
[repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"checkout", @"--", path, nil]];
|
||||
self.hasUnstagedChanges = NO;
|
||||
}
|
||||
|
||||
- (void) revertChanges
|
||||
{
|
||||
int ret = [[NSAlert alertWithMessageText:@"Revert changes"
|
||||
defaultButton:nil
|
||||
alternateButton:@"Cancel"
|
||||
otherButton:nil
|
||||
informativeTextWithFormat:@"Are you sure you wish to revert the changes in '%@'?\n\n You cannot undo this operation.", path] runModal];
|
||||
|
||||
if (ret == NSAlertDefaultReturn)
|
||||
[self forceRevertChanges];
|
||||
}
|
||||
|
||||
+ (BOOL)isSelectorExcludedFromWebScript:(SEL)aSelector
|
||||
{
|
||||
return NO;
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
//
|
||||
// PBFileChangesTableView.h
|
||||
// GitX
|
||||
//
|
||||
// Created by Pieter de Bie on 09-10-08.
|
||||
// Copyright 2008 Pieter de Bie. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
|
||||
@interface PBFileChangesTableView : NSTableView {
|
||||
id controller;
|
||||
}
|
||||
|
||||
@property (retain) id controller;
|
||||
@end
|
||||
@@ -0,0 +1,24 @@
|
||||
//
|
||||
// PBFileChangesTableView.m
|
||||
// GitX
|
||||
//
|
||||
// Created by Pieter de Bie on 09-10-08.
|
||||
// Copyright 2008 Pieter de Bie. All rights reserved.
|
||||
//
|
||||
|
||||
#import "PBFileChangesTableView.h"
|
||||
#import "PBGitCommitController.h"
|
||||
|
||||
@implementation PBFileChangesTableView
|
||||
|
||||
@synthesize controller;
|
||||
|
||||
#pragma mark NSTableView overrides
|
||||
- (NSMenu *)menuForEvent:(NSEvent *)theEvent
|
||||
{
|
||||
if (controller)
|
||||
return [(PBGitCommitController *)controller menuForTable: self];
|
||||
|
||||
return nil;
|
||||
}
|
||||
@end
|
||||
@@ -41,6 +41,8 @@
|
||||
- (void) readOtherFiles:(NSNotification *)notification;
|
||||
- (void) readUnstagedFiles:(NSNotification *)notification;
|
||||
|
||||
- (NSMenu *) menuForTable:(NSTableView *)table;
|
||||
|
||||
- (IBAction) refresh:(id) sender;
|
||||
- (IBAction) commit:(id) sender;
|
||||
@end
|
||||
|
||||
+45
-25
@@ -27,6 +27,8 @@
|
||||
[unstagedTable setDoubleAction:@selector(tableClicked:)];
|
||||
[cachedTable setDoubleAction:@selector(tableClicked:)];
|
||||
|
||||
[unstagedTable setController: self];
|
||||
|
||||
[self refresh:self];
|
||||
|
||||
[commitMessageView setTypingAttributes:[NSDictionary dictionaryWithObject:[NSFont fontWithName:@"Monaco" size:12.0] forKey:NSFontAttributeName]];
|
||||
@@ -158,18 +160,23 @@
|
||||
}
|
||||
even = 0;
|
||||
|
||||
BOOL isNew = YES;
|
||||
// If the file is already added, we shouldn't add it again
|
||||
// but rather update it to incorporate our changes
|
||||
NSArray *existingFiles = [files filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"path == '%@'", line]];
|
||||
if ([existingFiles count] != 0) {
|
||||
PBChangedFile *file = [existingFiles objectAtIndex:0];
|
||||
if (cached)
|
||||
file.hasCachedChanges = YES;
|
||||
else
|
||||
file.hasUnstagedChanges = YES;
|
||||
return;
|
||||
for (PBChangedFile *file in files) {
|
||||
if ([file.path isEqualToString:line]) {
|
||||
if (cached)
|
||||
file.hasCachedChanges = YES;
|
||||
else
|
||||
file.hasUnstagedChanges = YES;
|
||||
isNew = NO;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isNew)
|
||||
continue;
|
||||
|
||||
PBChangedFile *file = [[PBChangedFile alloc] initWithPath:line andRepository:repository];
|
||||
if ([[fileStatus objectAtIndex:4] isEqualToString:@"D"])
|
||||
file.status = DELETED;
|
||||
@@ -284,29 +291,14 @@
|
||||
- (void) tableClicked:(NSTableView *) tableView
|
||||
{
|
||||
NSUInteger selectionIndex = [[tableView selectedRowIndexes] firstIndex];
|
||||
NSArrayController *controller, *otherController;
|
||||
if ([tableView tag] == 0) {
|
||||
controller = unstagedFilesController;
|
||||
otherController = cachedFilesController;
|
||||
}
|
||||
else {
|
||||
controller = cachedFilesController;
|
||||
otherController = unstagedFilesController;
|
||||
}
|
||||
|
||||
NSArrayController *controller = [tableView tag] == 0 ? unstagedFilesController : cachedFilesController;
|
||||
PBChangedFile *selectedItem = [[controller arrangedObjects] objectAtIndex:selectionIndex];
|
||||
[controller removeObject:selectedItem];
|
||||
|
||||
if ([tableView tag] == 0)
|
||||
[selectedItem stageChanges];
|
||||
else
|
||||
[selectedItem unstageChangesAmend:amend];
|
||||
|
||||
// Add the file to the other controller if it's not there yet
|
||||
for (PBChangedFile *object in [otherController arrangedObjects])
|
||||
if ([[object path] isEqualToString:[selectedItem path]])
|
||||
return;
|
||||
|
||||
[otherController addObject:selectedItem];
|
||||
}
|
||||
|
||||
- (void) rowClicked:(NSCell *)sender
|
||||
@@ -321,4 +313,32 @@
|
||||
{
|
||||
[[tableColumn dataCell] setImage:[[[(([tableView tag] == 0) ? unstagedFilesController : cachedFilesController) arrangedObjects] objectAtIndex:rowIndex] icon]];
|
||||
}
|
||||
|
||||
- (NSMenu *) menuForTable:(NSTableView *)table
|
||||
{
|
||||
NSUInteger selectionIndex = [[table selectedRowIndexes] firstIndex];
|
||||
PBChangedFile *selectedItem = [[unstagedFilesController arrangedObjects] objectAtIndex:selectionIndex];
|
||||
|
||||
NSMenu *a = [[NSMenu alloc] init];
|
||||
NSMenuItem *stageItem = [[NSMenuItem alloc] initWithTitle:@"Stage Changes" action:@selector(stageChanges) keyEquivalent:@""];
|
||||
[stageItem setTarget:selectedItem];
|
||||
[a addItem:stageItem];
|
||||
|
||||
// Do not add "revert" options for untracked files
|
||||
if (selectedItem.status == NEW)
|
||||
return a;
|
||||
|
||||
NSMenuItem *revertItem = [[NSMenuItem alloc] initWithTitle:@"Revert Changes…" action:@selector(revertChanges) keyEquivalent:@""];
|
||||
[revertItem setTarget:selectedItem];
|
||||
[revertItem setAlternate:NO];
|
||||
[a addItem:revertItem];
|
||||
|
||||
NSMenuItem *revertForceItem = [[NSMenuItem alloc] initWithTitle:@"Revert Changes" action:@selector(forceRevertChanges) keyEquivalent:@""];
|
||||
[revertForceItem setTarget:selectedItem];
|
||||
[revertForceItem setAlternate:YES];
|
||||
[revertForceItem setKeyEquivalentModifierMask:NSAlternateKeyMask];
|
||||
[a addItem:revertForceItem];
|
||||
|
||||
return a;
|
||||
}
|
||||
@end
|
||||
|
||||
+16
-2
@@ -8,7 +8,7 @@
|
||||
<string key="IBDocument.HIToolboxVersion">352.00</string>
|
||||
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<integer value="207"/>
|
||||
<integer value="45"/>
|
||||
</object>
|
||||
<object class="NSArray" key="IBDocument.PluginDependencies">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
@@ -359,7 +359,7 @@
|
||||
<string>WebURLsWithTitlesPboardType</string>
|
||||
</object>
|
||||
</object>
|
||||
<string key="NSFrameSize">{427, 32}</string>
|
||||
<string key="NSFrameSize">{427, 14}</string>
|
||||
<reference key="NSSuperview" ref="245211955"/>
|
||||
<object class="NSTextContainer" key="NSTextContainer" id="311869542">
|
||||
<object class="NSLayoutManager" key="NSLayoutManager">
|
||||
@@ -1438,6 +1438,7 @@
|
||||
<string>45.IBPluginDependency</string>
|
||||
<string>46.IBPluginDependency</string>
|
||||
<string>47.IBPluginDependency</string>
|
||||
<string>48.CustomClassName</string>
|
||||
<string>48.IBPluginDependency</string>
|
||||
<string>54.IBPluginDependency</string>
|
||||
<string>55.IBPluginDependency</string>
|
||||
@@ -1479,6 +1480,7 @@
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>PBFileChangesTableView</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
@@ -1514,6 +1516,18 @@
|
||||
<object class="IBClassDescriber" key="IBDocument.Classes">
|
||||
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="IBPartialClassDescription">
|
||||
<string key="className">PBFileChangesTableView</string>
|
||||
<string key="superclassName">NSTableView</string>
|
||||
<object class="NSMutableDictionary" key="outlets">
|
||||
<string key="NS.key.0">controller</string>
|
||||
<string key="NS.object.0">id</string>
|
||||
</object>
|
||||
<object class="IBClassDescriptionSource" key="sourceIdentifier">
|
||||
<string key="majorKey">IBProjectSource</string>
|
||||
<string key="minorKey">PBFileChangesTableView.h</string>
|
||||
</object>
|
||||
</object>
|
||||
<object class="IBPartialClassDescription">
|
||||
<string key="className">PBGitCommitController</string>
|
||||
<string key="superclassName">PBViewController</string>
|
||||
|
||||
Reference in New Issue
Block a user