mirror of
https://github.com/kennethreitz-archive/gitx.git
synced 2026-06-05 23:40:18 +00:00
Add drop down menus to the push and pull toolbar items.
TODO: need small disclosure triangles in the bottom right corner of the icons.
This commit is contained in:
@@ -52,6 +52,7 @@
|
||||
93CB42C20EAB7B2200530609 /* PBGitDefaults.m in Sources */ = {isa = PBXBuildFile; fileRef = 93CB42C10EAB7B2200530609 /* PBGitDefaults.m */; };
|
||||
93F7857F0EA3ABF100C1F443 /* PBCommitMessageView.m in Sources */ = {isa = PBXBuildFile; fileRef = 93F7857E0EA3ABF100C1F443 /* PBCommitMessageView.m */; };
|
||||
D26DC6450E782C9000C777B2 /* gitx.icns in Resources */ = {isa = PBXBuildFile; fileRef = D26DC6440E782C9000C777B2 /* gitx.icns */; };
|
||||
D8E41F1410A7B023007BB8FC /* KBPopUpToolbarItem.m in Sources */ = {isa = PBXBuildFile; fileRef = D8E41F1310A7B023007BB8FC /* KBPopUpToolbarItem.m */; };
|
||||
EB2A734A0FEE3F09006601CF /* PBCollapsibleSplitView.m in Sources */ = {isa = PBXBuildFile; fileRef = EB2A73490FEE3F09006601CF /* PBCollapsibleSplitView.m */; };
|
||||
F50A411F0EBB874C00208746 /* mainSplitterBar.tiff in Resources */ = {isa = PBXBuildFile; fileRef = F50A411D0EBB874C00208746 /* mainSplitterBar.tiff */; };
|
||||
F50A41200EBB874C00208746 /* mainSplitterDimple.tiff in Resources */ = {isa = PBXBuildFile; fileRef = F50A411E0EBB874C00208746 /* mainSplitterDimple.tiff */; };
|
||||
@@ -224,6 +225,8 @@
|
||||
93F7857E0EA3ABF100C1F443 /* PBCommitMessageView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBCommitMessageView.m; sourceTree = "<group>"; };
|
||||
93FCCBA80EA8AF450061B02B /* PBGitConfig.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBGitConfig.m; sourceTree = "<group>"; };
|
||||
D26DC6440E782C9000C777B2 /* gitx.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = gitx.icns; sourceTree = "<group>"; };
|
||||
D8E41F1210A7B019007BB8FC /* KBPopUpToolbarItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KBPopUpToolbarItem.h; sourceTree = "<group>"; };
|
||||
D8E41F1310A7B023007BB8FC /* KBPopUpToolbarItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KBPopUpToolbarItem.m; sourceTree = "<group>"; };
|
||||
EB2A73480FEE3F09006601CF /* PBCollapsibleSplitView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBCollapsibleSplitView.h; sourceTree = "<group>"; };
|
||||
EB2A73490FEE3F09006601CF /* PBCollapsibleSplitView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBCollapsibleSplitView.m; sourceTree = "<group>"; };
|
||||
F50A411D0EBB874C00208746 /* mainSplitterBar.tiff */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; name = mainSplitterBar.tiff; path = Images/mainSplitterBar.tiff; sourceTree = "<group>"; };
|
||||
@@ -609,6 +612,8 @@
|
||||
F5FC41F30EBCBD4300191D80 /* PBGitXProtocol.m */,
|
||||
653D9308109BEAFE00B26705 /* PBGitXErrors.h */,
|
||||
653D9309109BEAFE00B26705 /* PBGitXErrors.m */,
|
||||
D8E41F1210A7B019007BB8FC /* KBPopUpToolbarItem.h */,
|
||||
D8E41F1310A7B023007BB8FC /* KBPopUpToolbarItem.m */,
|
||||
);
|
||||
name = Aux;
|
||||
sourceTree = "<group>";
|
||||
@@ -998,6 +1003,7 @@
|
||||
F59F1DD5105C4FF300115F88 /* PBGitIndex.m in Sources */,
|
||||
654D16E8108C6CA6008D960C /* PBQLOutlineView.m in Sources */,
|
||||
653D930A109BEAFE00B26705 /* PBGitXErrors.m in Sources */,
|
||||
D8E41F1410A7B023007BB8FC /* KBPopUpToolbarItem.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
//
|
||||
// KBPopUpToolbarItem.h
|
||||
// --------------------
|
||||
//
|
||||
// Created by Keith Blount on 14/05/2006.
|
||||
// Copyright 2006 Keith Blount. All rights reserved.
|
||||
//
|
||||
// Provides a toolbar item that performs its given action if clicked, or displays a pop-up menu
|
||||
// (if it has one) if held down for over half a second.
|
||||
//
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
@class KBDelayedPopUpButton;
|
||||
|
||||
|
||||
@interface KBPopUpToolbarItem : NSToolbarItem
|
||||
{
|
||||
KBDelayedPopUpButton *button;
|
||||
NSImage *smallImage;
|
||||
NSImage *regularImage;
|
||||
}
|
||||
- (void)setMenu:(NSMenu *)menu;
|
||||
- (NSMenu *)menu;
|
||||
@end
|
||||
@@ -0,0 +1,280 @@
|
||||
//
|
||||
// KBPopUpToolbarItem.m
|
||||
// --------------------
|
||||
//
|
||||
// Created by Keith Blount on 14/05/2006.
|
||||
// Copyright 2006 Keith Blount. All rights reserved.
|
||||
//
|
||||
|
||||
#import "KBPopUpToolbarItem.h"
|
||||
|
||||
@interface KBDelayedPopUpButtonCell : NSButtonCell
|
||||
@end
|
||||
|
||||
@implementation KBDelayedPopUpButtonCell
|
||||
|
||||
- (NSPoint)menuPositionForFrame:(NSRect)cellFrame inView:(NSView *)controlView
|
||||
{
|
||||
NSPoint result = [controlView convertPoint:cellFrame.origin toView:nil];
|
||||
result.x += 1.0;
|
||||
result.y -= cellFrame.size.height + 5.5;
|
||||
return result;
|
||||
}
|
||||
|
||||
- (void)showMenuForEvent:(NSEvent *)theEvent controlView:(NSView *)controlView cellFrame:(NSRect)cellFrame
|
||||
{
|
||||
NSPoint menuPosition = [self menuPositionForFrame:cellFrame inView:controlView];
|
||||
|
||||
// Create event for pop up menu with adjusted mouse position
|
||||
NSEvent *menuEvent = [NSEvent mouseEventWithType:[theEvent type]
|
||||
location:menuPosition
|
||||
modifierFlags:[theEvent modifierFlags]
|
||||
timestamp:[theEvent timestamp]
|
||||
windowNumber:[theEvent windowNumber]
|
||||
context:[theEvent context]
|
||||
eventNumber:[theEvent eventNumber]
|
||||
clickCount:[theEvent clickCount]
|
||||
pressure:[theEvent pressure]];
|
||||
|
||||
[NSMenu popUpContextMenu:[self menu] withEvent:menuEvent forView:controlView];
|
||||
}
|
||||
|
||||
- (BOOL)trackMouse:(NSEvent *)theEvent inRect:(NSRect)cellFrame ofView:(NSView *)controlView untilMouseUp:(BOOL)untilMouseUp
|
||||
{
|
||||
|
||||
BOOL result = NO;
|
||||
NSDate *endDate;
|
||||
NSPoint currentPoint = [theEvent locationInWindow];
|
||||
BOOL done = NO;
|
||||
BOOL trackContinously = [self startTrackingAt:currentPoint inView:controlView];
|
||||
|
||||
// Catch next mouse-dragged or mouse-up event until timeout
|
||||
BOOL mouseIsUp = NO;
|
||||
NSEvent *event;
|
||||
while (!done)
|
||||
{
|
||||
NSPoint lastPoint = currentPoint;
|
||||
|
||||
// Set up timer for pop-up menu if we have one
|
||||
if ([self menu])
|
||||
endDate = [NSDate dateWithTimeIntervalSinceNow:0.6];
|
||||
else
|
||||
endDate = [NSDate distantFuture];
|
||||
|
||||
event = [NSApp nextEventMatchingMask:(NSLeftMouseUpMask|NSLeftMouseDraggedMask)
|
||||
untilDate:endDate
|
||||
inMode:NSEventTrackingRunLoopMode
|
||||
dequeue:YES];
|
||||
|
||||
if (event) // Mouse event
|
||||
{
|
||||
currentPoint = [event locationInWindow];
|
||||
|
||||
// Send continueTracking.../stopTracking...
|
||||
if (trackContinously)
|
||||
{
|
||||
if (![self continueTracking:lastPoint at:currentPoint inView:controlView])
|
||||
{
|
||||
done = YES;
|
||||
[self stopTracking:lastPoint at:currentPoint inView:controlView mouseIsUp:mouseIsUp];
|
||||
}
|
||||
if ([self isContinuous])
|
||||
{
|
||||
[NSApp sendAction:[self action] to:[self target] from:controlView];
|
||||
}
|
||||
}
|
||||
|
||||
mouseIsUp = ([event type] == NSLeftMouseUp);
|
||||
done = done || mouseIsUp;
|
||||
|
||||
if (untilMouseUp)
|
||||
{
|
||||
result = mouseIsUp;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Check if the mouse left our cell rect
|
||||
result = NSPointInRect([controlView convertPoint:currentPoint fromView:nil], cellFrame);
|
||||
if (!result)
|
||||
done = YES;
|
||||
}
|
||||
|
||||
if (done && result && ![self isContinuous])
|
||||
[NSApp sendAction:[self action] to:[self target] from:controlView];
|
||||
|
||||
}
|
||||
else // Show menu
|
||||
{
|
||||
done = YES;
|
||||
result = YES;
|
||||
[self showMenuForEvent:theEvent controlView:controlView cellFrame:cellFrame];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@interface KBDelayedPopUpButton : NSButton
|
||||
@end
|
||||
|
||||
@implementation KBDelayedPopUpButton
|
||||
|
||||
- (id)initWithFrame:(NSRect)frameRect
|
||||
{
|
||||
if (self = [super initWithFrame:frameRect])
|
||||
{
|
||||
if (![[self cell] isKindOfClass:[KBDelayedPopUpButtonCell class]])
|
||||
{
|
||||
NSString *title = [self title];
|
||||
if (title == nil) title = @"";
|
||||
[self setCell:[[[KBDelayedPopUpButtonCell alloc] initTextCell:title] autorelease]];
|
||||
[[self cell] setControlSize:NSRegularControlSize];
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation KBPopUpToolbarItem
|
||||
|
||||
- (id)initWithItemIdentifier:(NSString *)ident
|
||||
{
|
||||
if (self = [super initWithItemIdentifier:ident])
|
||||
{
|
||||
button = [[KBDelayedPopUpButton alloc] initWithFrame:NSMakeRect(0,0,32,32)];
|
||||
[button setButtonType:NSMomentaryChangeButton];
|
||||
[button setBordered:NO];
|
||||
[self setView:button];
|
||||
[self setMinSize:NSMakeSize(32,32)];
|
||||
[self setMaxSize:NSMakeSize(32,32)];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
// Note that we make no assumptions about the retain/release of the toolbar item's view, just to be sure -
|
||||
// we therefore retain our button view until we are dealloc'd.
|
||||
- (void)dealloc
|
||||
{
|
||||
[button release];
|
||||
[regularImage release];
|
||||
[smallImage release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (KBDelayedPopUpButtonCell *)popupCell
|
||||
{
|
||||
return [(KBDelayedPopUpButton *)[self view] cell];
|
||||
}
|
||||
|
||||
- (void)setMenu:(NSMenu *)menu
|
||||
{
|
||||
[[self popupCell] setMenu:menu];
|
||||
|
||||
// Also set menu form representation - this is used in the toolbar overflow menu but also, more importantly, to display
|
||||
// a menu in text-only mode.
|
||||
NSMenuItem *menuFormRep = [[NSMenuItem alloc] initWithTitle:[self label] action:nil keyEquivalent:@""];
|
||||
[menuFormRep setSubmenu:menu];
|
||||
[self setMenuFormRepresentation:menuFormRep];
|
||||
[menuFormRep release];
|
||||
}
|
||||
|
||||
- (NSMenu *)menu
|
||||
{
|
||||
return [[self popupCell] menu];
|
||||
}
|
||||
|
||||
- (void)setAction:(SEL)aSelector
|
||||
{
|
||||
[[self popupCell] setAction:aSelector];
|
||||
}
|
||||
|
||||
- (SEL)action
|
||||
{
|
||||
return [[self popupCell] action];
|
||||
}
|
||||
|
||||
- (void)setTarget:(id)anObject
|
||||
{
|
||||
[[self popupCell] setTarget:anObject];
|
||||
}
|
||||
|
||||
- (id)target
|
||||
{
|
||||
return [[self popupCell] target];
|
||||
}
|
||||
|
||||
- (void)setImage:(NSImage *)anImage
|
||||
{
|
||||
[regularImage autorelease];
|
||||
[smallImage autorelease];
|
||||
|
||||
regularImage = [anImage retain];
|
||||
smallImage = [anImage copy];
|
||||
[smallImage setScalesWhenResized:YES];
|
||||
[smallImage setSize:NSMakeSize(24,24)];
|
||||
|
||||
if ([[self toolbar] sizeMode] == NSToolbarSizeModeSmall) anImage = smallImage;
|
||||
|
||||
[[self popupCell] setImage:anImage];
|
||||
}
|
||||
|
||||
- (NSImage *)image
|
||||
{
|
||||
return [[self popupCell] image];
|
||||
}
|
||||
|
||||
- (void)setToolTip:(NSString *)theToolTip
|
||||
{
|
||||
[[self view] setToolTip:theToolTip];
|
||||
}
|
||||
|
||||
- (NSString *)toolTip
|
||||
{
|
||||
return [[self view] toolTip];
|
||||
}
|
||||
|
||||
- (void)validate
|
||||
{
|
||||
// First, make sure the toolbar image size fits the toolbar size mode; there must be a better place to do this!
|
||||
NSToolbarSizeMode sizeMode = [[self toolbar] sizeMode];
|
||||
float imgWidth = [[self image] size].width;
|
||||
|
||||
if (sizeMode == NSToolbarSizeModeSmall && imgWidth != 24)
|
||||
{
|
||||
[[self popupCell] setImage:smallImage];
|
||||
}
|
||||
else if (sizeMode == NSToolbarSizeModeRegular && imgWidth == 24)
|
||||
{
|
||||
[[self popupCell] setImage:regularImage];
|
||||
}
|
||||
|
||||
if ([[self toolbar] delegate])
|
||||
{
|
||||
BOOL enabled = YES;
|
||||
|
||||
if ([[[self toolbar] delegate] respondsToSelector:@selector(validateToolbarItem:)])
|
||||
enabled = [[[self toolbar] delegate] validateToolbarItem:self];
|
||||
|
||||
else if ([[[self toolbar] delegate] respondsToSelector:@selector(validateUserInterfaceItem:)])
|
||||
enabled = [[[self toolbar] delegate] validateUserInterfaceItem:self];
|
||||
|
||||
[self setEnabled:enabled];
|
||||
}
|
||||
|
||||
else if ([self action])
|
||||
{
|
||||
if (![self target])
|
||||
[self setEnabled:[[[[self view] window] firstResponder] respondsToSelector:[self action]]];
|
||||
|
||||
else
|
||||
[self setEnabled:[[self target] respondsToSelector:[self action]]];
|
||||
}
|
||||
|
||||
else
|
||||
[super validate];
|
||||
}
|
||||
|
||||
@end
|
||||
+56
-9
@@ -21,12 +21,11 @@
|
||||
</object>
|
||||
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<integer value="236"/>
|
||||
<integer value="4"/>
|
||||
<integer value="427"/>
|
||||
<integer value="459"/>
|
||||
<integer value="354"/>
|
||||
<integer value="237"/>
|
||||
<integer value="459"/>
|
||||
<integer value="478"/>
|
||||
</object>
|
||||
<object class="NSArray" key="IBDocument.PluginDependencies">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
@@ -376,7 +375,6 @@
|
||||
<int key="NSvFlags">-2147483392</int>
|
||||
<string key="NSFrame">{{0, 310}, {852, 15}}</string>
|
||||
<reference key="NSSuperview" ref="663765878"/>
|
||||
<bool key="NSEnabled">YES</bool>
|
||||
<int key="NSsFlags">1</int>
|
||||
<reference key="NSTarget" ref="663765878"/>
|
||||
<string key="NSAction">_doScroller:</string>
|
||||
@@ -401,7 +399,7 @@
|
||||
<string key="NSFrameSize">{852, 325}</string>
|
||||
<reference key="NSSuperview" ref="202620420"/>
|
||||
<reference key="NSNextKeyView" ref="546023969"/>
|
||||
<int key="NSsFlags">688</int>
|
||||
<int key="NSsFlags">560</int>
|
||||
<reference key="NSVScroller" ref="152625445"/>
|
||||
<reference key="NSHScroller" ref="452331733"/>
|
||||
<reference key="NSContentView" ref="546023969"/>
|
||||
@@ -2011,7 +2009,7 @@ TG9jYWwgYnJhbmNoZXMnIHdpbGwgbm90IHdvcmsuA</string>
|
||||
<string>public.url</string>
|
||||
</object>
|
||||
</object>
|
||||
<string key="NSFrameSize">{311, 66}</string>
|
||||
<string key="NSFrameSize">{311, 14}</string>
|
||||
<reference key="NSSuperview" ref="410453893"/>
|
||||
<object class="NSTextContainer" key="NSTextContainer" id="894245073">
|
||||
<object class="NSLayoutManager" key="NSLayoutManager">
|
||||
@@ -2072,8 +2070,8 @@ TG9jYWwgYnJhbmNoZXMnIHdpbGwgbm90IHdvcmsuA</string>
|
||||
<nil key="NSDefaultParagraphStyle"/>
|
||||
</object>
|
||||
<int key="NSTVFlags">6</int>
|
||||
<string key="NSMaxSize">{463, 1e+07}</string>
|
||||
<string key="NSMinize">{223, 66}</string>
|
||||
<string key="NSMaxSize">{624, 1e+07}</string>
|
||||
<string key="NSMinize">{223, 0}</string>
|
||||
<nil key="NSDelegate"/>
|
||||
</object>
|
||||
</object>
|
||||
@@ -2973,6 +2971,22 @@ TG9jYWwgYnJhbmNoZXMnIHdpbGwgbm90IHdvcmsuA</string>
|
||||
</object>
|
||||
<int key="connectionID">510</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBOutletConnection" key="connection">
|
||||
<string key="label">pushItem</string>
|
||||
<reference key="source" ref="892732705"/>
|
||||
<reference key="destination" ref="425122427"/>
|
||||
</object>
|
||||
<int key="connectionID">511</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBOutletConnection" key="connection">
|
||||
<string key="label">pullItem</string>
|
||||
<reference key="source" ref="892732705"/>
|
||||
<reference key="destination" ref="412717087"/>
|
||||
</object>
|
||||
<int key="connectionID">512</int>
|
||||
</object>
|
||||
</object>
|
||||
<object class="IBMutableOrderedSet" key="objectRecords">
|
||||
<object class="NSArray" key="orderedObjects">
|
||||
@@ -4113,7 +4127,9 @@ TG9jYWwgYnJhbmNoZXMnIHdpbGwgbm90IHdvcmsuA</string>
|
||||
<string>354.IBPluginDependency</string>
|
||||
<string>354.editorWindowContentRectSynchronizationRect</string>
|
||||
<string>355.IBPluginDependency</string>
|
||||
<string>356.CustomClassName</string>
|
||||
<string>356.IBPluginDependency</string>
|
||||
<string>357.CustomClassName</string>
|
||||
<string>357.IBPluginDependency</string>
|
||||
<string>358.IBPluginDependency</string>
|
||||
<string>36.IBPluginDependency</string>
|
||||
@@ -4140,10 +4156,14 @@ TG9jYWwgYnJhbmNoZXMnIHdpbGwgbm90IHdvcmsuA</string>
|
||||
<string>376.IBPluginDependency</string>
|
||||
<string>377.IBPluginDependency</string>
|
||||
<string>378.IBPluginDependency</string>
|
||||
<string>379.CustomClassName</string>
|
||||
<string>379.IBPluginDependency</string>
|
||||
<string>38.IBPluginDependency</string>
|
||||
<string>380.CustomClassName</string>
|
||||
<string>380.IBPluginDependency</string>
|
||||
<string>381.CustomClassName</string>
|
||||
<string>381.IBPluginDependency</string>
|
||||
<string>382.CustomClassName</string>
|
||||
<string>382.IBPluginDependency</string>
|
||||
<string>383.IBPluginDependency</string>
|
||||
<string>384.IBPluginDependency</string>
|
||||
@@ -4308,7 +4328,9 @@ TG9jYWwgYnJhbmNoZXMnIHdpbGwgbm90IHdvcmsuA</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>{{132, 614}, {616, 0}}</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>KBPopUpToolbarItem</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>KBPopUpToolbarItem</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
@@ -4342,10 +4364,14 @@ TG9jYWwgYnJhbmNoZXMnIHdpbGwgbm90IHdvcmsuA</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>KBDelayedPopUpButton</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>KBDelayedPopUpButtonCell</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>KBDelayedPopUpButton</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>KBDelayedPopUpButtonCell</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
@@ -4468,11 +4494,24 @@ TG9jYWwgYnJhbmNoZXMnIHdpbGwgbm90IHdvcmsuA</string>
|
||||
</object>
|
||||
</object>
|
||||
<nil key="sourceID"/>
|
||||
<int key="maxID">510</int>
|
||||
<int key="maxID">512</int>
|
||||
</object>
|
||||
<object class="IBClassDescriber" key="IBDocument.Classes">
|
||||
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="IBPartialClassDescription">
|
||||
<string key="className">KBDelayedPopUpButtonCell</string>
|
||||
<string key="superclassName">NSButtonCell</string>
|
||||
<object class="IBClassDescriptionSource" key="sourceIdentifier" id="369721441">
|
||||
<string key="majorKey">IBProjectSource</string>
|
||||
<string key="minorKey">KBPopUpToolbarItem.h</string>
|
||||
</object>
|
||||
</object>
|
||||
<object class="IBPartialClassDescription">
|
||||
<string key="className">KBPopUpToolbarItem</string>
|
||||
<string key="superclassName">NSToolbarItem</string>
|
||||
<reference key="sourceIdentifier" ref="369721441"/>
|
||||
</object>
|
||||
<object class="IBPartialClassDescription">
|
||||
<string key="className">NSToolbarItem</string>
|
||||
<string key="superclassName">NSObject</string>
|
||||
@@ -4637,7 +4676,9 @@ TG9jYWwgYnJhbmNoZXMnIHdpbGwgbm90IHdvcmsuA</string>
|
||||
<string>newTagButton:</string>
|
||||
<string>newTagSheet:</string>
|
||||
<string>pullButton:</string>
|
||||
<string>pullMenuAction:</string>
|
||||
<string>pushButton:</string>
|
||||
<string>pushMenuAction:</string>
|
||||
<string>rebaseButton:</string>
|
||||
<string>saveSheet:</string>
|
||||
</object>
|
||||
@@ -4654,7 +4695,9 @@ TG9jYWwgYnJhbmNoZXMnIHdpbGwgbm90IHdvcmsuA</string>
|
||||
<string>id</string>
|
||||
<string>id</string>
|
||||
<string>id</string>
|
||||
<string>NSMenuItem</string>
|
||||
<string>id</string>
|
||||
<string>NSMenuItem</string>
|
||||
<string>id</string>
|
||||
<string>id</string>
|
||||
</object>
|
||||
@@ -4681,6 +4724,8 @@ TG9jYWwgYnJhbmNoZXMnIHdpbGwgbm90IHdvcmsuA</string>
|
||||
<string>newTagSHA</string>
|
||||
<string>newTagSHALabel</string>
|
||||
<string>newTagSheet</string>
|
||||
<string>pullItem</string>
|
||||
<string>pushItem</string>
|
||||
</object>
|
||||
<object class="NSMutableArray" key="dict.values">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
@@ -4702,6 +4747,8 @@ TG9jYWwgYnJhbmNoZXMnIHdpbGwgbm90IHdvcmsuA</string>
|
||||
<string>NSTextField</string>
|
||||
<string>NSTextField</string>
|
||||
<string>NSWindow</string>
|
||||
<string>KBPopUpToolbarItem</string>
|
||||
<string>KBPopUpToolbarItem</string>
|
||||
</object>
|
||||
</object>
|
||||
<object class="IBClassDescriptionSource" key="sourceIdentifier">
|
||||
|
||||
+9
-1
@@ -13,6 +13,8 @@
|
||||
#import "PBGitCommit.h"
|
||||
#import "PBRefContextDelegate.h"
|
||||
|
||||
@class KBPopUpToolbarItem;
|
||||
|
||||
@interface PBRefController : NSObject <PBRefContextDelegate> {
|
||||
IBOutlet __weak PBGitHistoryController *historyController;
|
||||
IBOutlet NSArrayController *commitController;
|
||||
@@ -36,6 +38,8 @@
|
||||
IBOutlet NSTextField *newTagSHALabel;
|
||||
|
||||
IBOutlet NSPopUpButton *branchPopUp;
|
||||
IBOutlet KBPopUpToolbarItem *pullItem;
|
||||
IBOutlet KBPopUpToolbarItem *pushItem;
|
||||
}
|
||||
|
||||
- (IBAction)addRef:(id)sender;
|
||||
@@ -59,7 +63,11 @@
|
||||
|
||||
- (void) changeBranch:(NSMenuItem *)sender;
|
||||
- (void) selectCurrentBranch;
|
||||
- (void) updateBranchMenu;
|
||||
- (void) updateBranchMenus;
|
||||
- (void) updateAllBranchesMenuWithLocal:(NSMutableArray *)localBranches remote:(NSMutableArray *)remoteBranches tag:(NSMutableArray *)tags other:(NSMutableArray *)other;
|
||||
|
||||
- (void) pullMenuAction:(NSMenuItem *)sender;
|
||||
- (void) pushMenuAction:(NSMenuItem *)sender;
|
||||
|
||||
- (BOOL) pullImpl:(NSString *)refName;
|
||||
- (BOOL) pushImpl:(NSString *)refName;
|
||||
|
||||
+150
-39
@@ -9,6 +9,7 @@
|
||||
#import "PBRefController.h"
|
||||
#import "PBGitRevisionCell.h"
|
||||
#import "PBRefMenuItem.h"
|
||||
#import "KBPopUpToolbarItem.h"
|
||||
|
||||
@implementation PBRefController
|
||||
|
||||
@@ -17,14 +18,14 @@
|
||||
[commitList registerForDraggedTypes:[NSArray arrayWithObject:@"PBGitRef"]];
|
||||
[historyController addObserver:self forKeyPath:@"repository.branches" options:0 context:@"branchChange"];
|
||||
[historyController addObserver:self forKeyPath:@"repository.currentBranch" options:0 context:@"currentBranchChange"];
|
||||
[self updateBranchMenu];
|
||||
[self updateBranchMenus];
|
||||
[self selectCurrentBranch];
|
||||
}
|
||||
|
||||
- (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
|
||||
{
|
||||
if ([(NSString *)context isEqualToString: @"branchChange"]) {
|
||||
[self updateBranchMenu];
|
||||
[self updateBranchMenus];
|
||||
}
|
||||
else if ([(NSString *)context isEqualToString:@"currentBranchChange"]) {
|
||||
[self selectCurrentBranch];
|
||||
@@ -47,7 +48,7 @@
|
||||
[historyController.repository removeBranch:[[PBGitRevSpecifier alloc] initWithRef:[refMenuItem ref]]];
|
||||
[[refMenuItem commit] removeRef:[refMenuItem ref]];
|
||||
[commitController rearrangeObjects];
|
||||
[self updateBranchMenu];
|
||||
[self updateBranchMenus];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,11 +106,10 @@
|
||||
return [PBRefMenuItem defaultMenuItemsForRef:ref commit:commit target:self];
|
||||
}
|
||||
|
||||
- (BOOL) pushImpl:(NSString *)refName
|
||||
- (BOOL) pushRef:(NSString *)refName toRemote:(NSString *)remote
|
||||
{
|
||||
int ret = 1;
|
||||
BOOL success = NO;
|
||||
NSString *remote = [[historyController.repository config] valueForKeyPath:[NSString stringWithFormat:@"branch.%@.remote", refName]];
|
||||
BOOL success = NO;
|
||||
NSString *rval = [historyController.repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"push", remote, refName, nil] retValue: &ret];
|
||||
if (!remote) {
|
||||
[self showMessageSheet:@"Push to Remote" message:PBMissingRemoteErrorMessage];
|
||||
@@ -126,15 +126,20 @@
|
||||
return success;
|
||||
}
|
||||
|
||||
- (BOOL) pullImpl:(NSString *)refName
|
||||
- (BOOL) pushImpl:(NSString *)refName
|
||||
{
|
||||
NSString *remote = [[historyController.repository config] valueForKeyPath:[NSString stringWithFormat:@"branch.%@.remote", refName]];
|
||||
if (!remote) {
|
||||
[self showMessageSheet:@"Push to Remote" message:PBMissingRemoteErrorMessage];
|
||||
return NO;
|
||||
}
|
||||
return [self pushRef:refName toRemote:remote];
|
||||
}
|
||||
|
||||
- (BOOL) pullRef:(NSString *)refName fromRemote:(NSString *)remote
|
||||
{
|
||||
int ret = 1;
|
||||
BOOL success = NO;
|
||||
NSString *remote = [[historyController.repository config] valueForKeyPath:[NSString stringWithFormat:@"branch.%@.remote", refName]];
|
||||
if (!remote) {
|
||||
[self showMessageSheet:@"Pull from Remote" message:PBMissingRemoteErrorMessage];
|
||||
return success;
|
||||
}
|
||||
NSArray * args = [NSArray arrayWithObjects:@"pull", remote, refName, nil];
|
||||
NSString *rval = [historyController.repository outputInWorkdirForArguments:args retValue: &ret];
|
||||
if (ret) {
|
||||
@@ -148,6 +153,16 @@
|
||||
return success;
|
||||
}
|
||||
|
||||
- (BOOL) pullImpl:(NSString *)refName
|
||||
{
|
||||
NSString *remote = [[historyController.repository config] valueForKeyPath:[NSString stringWithFormat:@"branch.%@.remote", refName]];
|
||||
if (!remote) {
|
||||
[self showMessageSheet:@"Pull from Remote" message:PBMissingRemoteErrorMessage];
|
||||
return NO;
|
||||
}
|
||||
return [self pullRef:refName fromRemote:remote];
|
||||
}
|
||||
|
||||
- (BOOL) rebaseImpl:(NSString *)refName
|
||||
{
|
||||
int ret = 1;
|
||||
@@ -550,37 +565,16 @@
|
||||
[newTagSheet orderOut:self];
|
||||
}
|
||||
|
||||
# pragma mark Branches menu
|
||||
# pragma mark Branch menus
|
||||
|
||||
- (void) updateBranchMenu
|
||||
- (void) updateAllBranchesMenuWithLocal:(NSMutableArray *)localBranches remote:(NSMutableArray *)remoteBranches tag:(NSMutableArray *)tags other:(NSMutableArray *)other
|
||||
{
|
||||
if (!branchPopUp)
|
||||
return;
|
||||
|
||||
NSMutableArray *localBranches = [NSMutableArray array];
|
||||
NSMutableArray *remoteBranches = [NSMutableArray array];
|
||||
NSMutableArray *tags = [NSMutableArray array];
|
||||
NSMutableArray *other = [NSMutableArray array];
|
||||
return;
|
||||
|
||||
NSMenu *menu = [[NSMenu alloc] initWithTitle:@"Branch menu"];
|
||||
for (PBGitRevSpecifier *rev in historyController.repository.branches)
|
||||
{
|
||||
if (![rev isSimpleRef])
|
||||
{
|
||||
[other addObject:rev];
|
||||
continue;
|
||||
}
|
||||
|
||||
NSString *ref = [rev simpleRef];
|
||||
|
||||
if ([ref hasPrefix:@"refs/heads"])
|
||||
[localBranches addObject:rev];
|
||||
else if ([ref hasPrefix:@"refs/tags"])
|
||||
[tags addObject:rev];
|
||||
else if ([ref hasPrefix:@"refs/remote"])
|
||||
[remoteBranches addObject:rev];
|
||||
}
|
||||
|
||||
// Local
|
||||
for (PBGitRevSpecifier *rev in localBranches)
|
||||
{
|
||||
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:[rev description] action:@selector(changeBranch:) keyEquivalent:@""];
|
||||
@@ -593,7 +587,7 @@
|
||||
|
||||
// Remotes
|
||||
NSMenu *remoteMenu = [[NSMenu alloc] initWithTitle:@"Remotes"];
|
||||
NSMenu *currentMenu = NULL;
|
||||
NSMenu *currentMenu = nil;
|
||||
for (PBGitRevSpecifier *rev in remoteBranches)
|
||||
{
|
||||
NSString *ref = [rev simpleRef];
|
||||
@@ -634,7 +628,6 @@
|
||||
[tagItem setSubmenu:tagMenu];
|
||||
[menu addItem:tagItem];
|
||||
|
||||
|
||||
// Others
|
||||
[menu addItem:[NSMenuItem separatorItem]];
|
||||
|
||||
@@ -649,6 +642,106 @@
|
||||
[[branchPopUp cell] setMenu: menu];
|
||||
}
|
||||
|
||||
- (void) updatePullMenuWithRemotes:(NSMutableArray *)remoteBranches
|
||||
{
|
||||
if (!pullItem)
|
||||
return;
|
||||
|
||||
NSMenu *remoteMenu = [[NSMenu alloc] initWithTitle:@"Pull menu"];
|
||||
|
||||
// Remotes
|
||||
NSMenu *currentMenu = nil;
|
||||
for (PBGitRevSpecifier *rev in remoteBranches)
|
||||
{
|
||||
NSString *ref = [rev simpleRef];
|
||||
NSArray *components = [ref componentsSeparatedByString:@"/"];
|
||||
|
||||
NSString *remoteName = [components objectAtIndex:2];
|
||||
NSString *branchName = [[components subarrayWithRange:NSMakeRange(3, [components count] - 3)] componentsJoinedByString:@"/"];
|
||||
|
||||
if (![[currentMenu title] isEqualToString:remoteName])
|
||||
{
|
||||
currentMenu = [[NSMenu alloc] initWithTitle:remoteName];
|
||||
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:remoteName action:NULL keyEquivalent:@""];
|
||||
[item setSubmenu:currentMenu];
|
||||
[remoteMenu addItem:item];
|
||||
}
|
||||
|
||||
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:branchName action:@selector(pullMenuAction:) keyEquivalent:@""];
|
||||
[item setTarget:self];
|
||||
[item setRepresentedObject:rev];
|
||||
[currentMenu addItem:item];
|
||||
}
|
||||
|
||||
[pullItem setMenu: remoteMenu];
|
||||
}
|
||||
|
||||
- (void) updatePushMenuWithRemotes:(NSMutableArray *)remoteBranches
|
||||
{
|
||||
if (!pushItem)
|
||||
return;
|
||||
|
||||
NSMenu *remoteMenu = [[NSMenu alloc] initWithTitle:@"Push menu"];
|
||||
|
||||
// Remotes
|
||||
NSMenu *currentMenu = nil;
|
||||
for (PBGitRevSpecifier *rev in remoteBranches)
|
||||
{
|
||||
NSString *ref = [rev simpleRef];
|
||||
NSArray *components = [ref componentsSeparatedByString:@"/"];
|
||||
|
||||
NSString *remoteName = [components objectAtIndex:2];
|
||||
NSString *branchName = [[components subarrayWithRange:NSMakeRange(3, [components count] - 3)] componentsJoinedByString:@"/"];
|
||||
|
||||
if (![[currentMenu title] isEqualToString:remoteName])
|
||||
{
|
||||
currentMenu = [[NSMenu alloc] initWithTitle:remoteName];
|
||||
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:remoteName action:NULL keyEquivalent:@""];
|
||||
[item setSubmenu:currentMenu];
|
||||
[remoteMenu addItem:item];
|
||||
}
|
||||
|
||||
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:branchName action:@selector(pushMenuAction:) keyEquivalent:@""];
|
||||
[item setTarget:self];
|
||||
[item setRepresentedObject:rev];
|
||||
[currentMenu addItem:item];
|
||||
}
|
||||
|
||||
[pushItem setMenu: remoteMenu];
|
||||
}
|
||||
|
||||
- (void) updateBranchMenus
|
||||
{
|
||||
NSMutableArray *localBranches = [NSMutableArray array];
|
||||
NSMutableArray *remoteBranches = [NSMutableArray array];
|
||||
NSMutableArray *tags = [NSMutableArray array];
|
||||
NSMutableArray *other = [NSMutableArray array];
|
||||
|
||||
for (PBGitRevSpecifier *rev in historyController.repository.branches)
|
||||
{
|
||||
if (![rev isSimpleRef])
|
||||
{
|
||||
[other addObject:rev];
|
||||
continue;
|
||||
}
|
||||
|
||||
NSString *ref = [rev simpleRef];
|
||||
|
||||
if ([ref hasPrefix:@"refs/heads"])
|
||||
[localBranches addObject:rev];
|
||||
else if ([ref hasPrefix:@"refs/tags"])
|
||||
[tags addObject:rev];
|
||||
else if ([ref hasPrefix:@"refs/remote"])
|
||||
[remoteBranches addObject:rev];
|
||||
}
|
||||
|
||||
[self updateAllBranchesMenuWithLocal:localBranches remote:remoteBranches tag:tags other:other];
|
||||
|
||||
[self updatePullMenuWithRemotes:remoteBranches];
|
||||
|
||||
[self updatePushMenuWithRemotes:remoteBranches];
|
||||
}
|
||||
|
||||
- (void) changeBranch:(NSMenuItem *)sender
|
||||
{
|
||||
PBGitRevSpecifier *rev = [sender representedObject];
|
||||
@@ -677,6 +770,24 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void) pullMenuAction:(NSMenuItem *)sender
|
||||
{
|
||||
NSString *ref = [(PBGitRevSpecifier *)[sender representedObject] description];
|
||||
NSArray *refComponents = [ref componentsSeparatedByString:@"/"];
|
||||
if ([refComponents count] != 2)
|
||||
return;
|
||||
[self pullRef:[refComponents objectAtIndex:1] fromRemote:[refComponents objectAtIndex:0]];
|
||||
}
|
||||
|
||||
- (void) pushMenuAction:(NSMenuItem *)sender
|
||||
{
|
||||
NSString *ref = [(PBGitRevSpecifier *)[sender representedObject] description];
|
||||
NSArray *refComponents = [ref componentsSeparatedByString:@"/"];
|
||||
if ([refComponents count] != 2)
|
||||
return;
|
||||
[self pushRef:[refComponents objectAtIndex:1] toRemote:[refComponents objectAtIndex:0]];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation NSString (PBRefSpecAdditions)
|
||||
|
||||
Reference in New Issue
Block a user