diff --git a/Frameworks/OakFileBrowser/src/OakFileBrowser.mm b/Frameworks/OakFileBrowser/src/OakFileBrowser.mm index da6ff182..1fe016b2 100644 --- a/Frameworks/OakFileBrowser/src/OakFileBrowser.mm +++ b/Frameworks/OakFileBrowser/src/OakFileBrowser.mm @@ -3,6 +3,7 @@ #import "ui/OFBHeaderView.h" #import "ui/OFBOutlineView.h" #import "ui/OFBPathInfoCell.h" +#import "ui/OFBActionsView.h" #import "io/FSDataSource.h" #import "io/FSSCMDataSource.h" #import "io/FSItem.h" @@ -39,6 +40,7 @@ OAK_DEBUG_VAR(FileBrowser_Controller); @property (nonatomic, readwrite) NSView* view; @property (nonatomic) OFBHeaderView* headerView; @property (nonatomic) OFBOutlineView* outlineView; +@property (nonatomic) OFBActionsView* actionsView; @property (nonatomic) FSOutlineViewDelegate* outlineViewDelegate; @property (nonatomic) NSUInteger dataSourceOptions; @@ -141,6 +143,16 @@ static NSMutableSet* SymmetricDifference (NSMutableSet* aSet, NSMutableSet* anot _headerView.goForwardButton.target = self; _headerView.goForwardButton.action = @selector(goForward:); + _actionsView = [[OFBActionsView alloc] initWithFrame:NSZeroRect]; + _actionsView.createButton.action = @selector(newDocumentInTab:); + _actionsView.reloadButton.target = self; + _actionsView.reloadButton.action = @selector(reload:); + _actionsView.searchButton.action = @selector(orderFrontFindPanelForFileBrowser:); + _actionsView.favoritesButton.target = self; + _actionsView.favoritesButton.action = @selector(goToFavorites:); + _actionsView.scmButton.target = self; + _actionsView.scmButton.action = @selector(goToSCMDataSource:); + _view = [NSView new]; NSCell* cell = [OFBPathInfoCell new]; @@ -160,6 +172,8 @@ static NSMutableSet* SymmetricDifference (NSMutableSet* aSet, NSMutableSet* anot @"header" : _headerView, @"headerDivider" : OakCreateHorizontalLine([NSColor colorWithCalibratedWhite:0.500 alpha:1], [NSColor colorWithCalibratedWhite:0.750 alpha:1]), @"browser" : scrollView, + @"actionsDivider" : OakCreateHorizontalLine([NSColor colorWithCalibratedWhite:0.500 alpha:1], [NSColor colorWithCalibratedWhite:0.750 alpha:1]), + @"actions" : _actionsView, }; for(NSView* view in [views allValues]) @@ -168,8 +182,8 @@ static NSMutableSet* SymmetricDifference (NSMutableSet* aSet, NSMutableSet* anot [_view addSubview:view]; } - [_view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[browser(==header,==headerDivider)]|" options:0 metrics:nil views:views]]; - [_view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[header][headerDivider][browser]|" options:NSLayoutFormatAlignAllLeft metrics:nil views:views]]; + [_view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[browser(==header,==headerDivider,==actionsDivider,==actions)]|" options:0 metrics:nil views:views]]; + [_view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[header][headerDivider][browser][actionsDivider][actions]|" options:NSLayoutFormatAlignAllLeft metrics:nil views:views]]; } - (void)setupViewWithState:(NSDictionary*)fileBrowserState diff --git a/Frameworks/OakFileBrowser/src/ui/OFBActionsView.h b/Frameworks/OakFileBrowser/src/ui/OFBActionsView.h new file mode 100644 index 00000000..846a7bd1 --- /dev/null +++ b/Frameworks/OakFileBrowser/src/ui/OFBActionsView.h @@ -0,0 +1,10 @@ +#import + +@interface OFBActionsView : OakGradientView +@property (nonatomic) NSButton* createButton; +@property (nonatomic) NSPopUpButton* actionsPopUpButton; +@property (nonatomic) NSButton* reloadButton; +@property (nonatomic) NSButton* searchButton; +@property (nonatomic) NSButton* favoritesButton; +@property (nonatomic) NSButton* scmButton; +@end diff --git a/Frameworks/OakFileBrowser/src/ui/OFBActionsView.mm b/Frameworks/OakFileBrowser/src/ui/OFBActionsView.mm new file mode 100644 index 00000000..e42e2ebe --- /dev/null +++ b/Frameworks/OakFileBrowser/src/ui/OFBActionsView.mm @@ -0,0 +1,105 @@ +#import "OFBActionsView.h" +#import +#import + +static NSButton* OakCreateImageButton (NSImage* image, NSSize imageSize = NSMakeSize(16, 16)) +{ + NSButton* res = [NSButton new]; + + // [[res cell] setBackgroundStyle:NSBackgroundStyleRaised]; + [res setButtonType:NSMomentaryChangeButton]; + [res setBezelStyle:NSSmallSquareBezelStyle]; + [res setBordered:NO]; + + // image = [image copy]; + // [image setSize:imageSize]; + [res setImage:image]; + [res setImagePosition:NSImageOnly]; + + [res setContentHuggingPriority:NSLayoutPriorityDefaultLow forOrientation:NSLayoutConstraintOrientationHorizontal]; + [res setContentHuggingPriority:NSLayoutPriorityDefaultLow forOrientation:NSLayoutConstraintOrientationVertical]; + + return res; +} + +static NSPopUpButton* OakCreatePopUpButton () +{ + NSPopUpButton* res = [NSPopUpButton new]; + res.bordered = NO; + res.pullsDown = YES; + + NSMenuItem* item = [NSMenuItem new]; + item.title = @""; + item.image = [NSImage imageNamed:NSImageNameActionTemplate]; + [item.image setSize:NSMakeSize(12, 12)]; + + [[res cell] setUsesItemFromMenu:NO]; + [[res cell] setMenuItem:item]; + + return res; +} + +@implementation OFBActionsView +- (id)initWithFrame:(NSRect)aRect +{ + if(self = [super initWithGradient:[[NSGradient alloc] initWithColorsAndLocations: [NSColor colorWithCalibratedWhite:1.000 alpha:0.68], 0.0, [NSColor colorWithCalibratedWhite:1.000 alpha:0.5], 0.0416, [NSColor colorWithCalibratedWhite:1.000 alpha:0.0], 1.0, nil] inactiveGradient:[[NSGradient alloc] initWithColorsAndLocations: [NSColor colorWithCalibratedWhite:1.000 alpha:0.68], 0.0, [NSColor colorWithCalibratedWhite:1.000 alpha:0.5], 0.0416, [NSColor colorWithCalibratedWhite:1.000 alpha:0.0], 1.0, nil]]) + { + self.createButton = OakCreateImageButton([NSImage imageNamed:NSImageNameAddTemplate]); + self.actionsPopUpButton = OakCreatePopUpButton(); + self.reloadButton = OakCreateImageButton([NSImage imageNamed:NSImageNameRefreshTemplate]); + self.searchButton = OakCreateImageButton([NSImage imageNamed:NSImageNameRevealFreestandingTemplate]); + self.favoritesButton = OakCreateImageButton([NSImage imageNamed:@"Favorites" inSameBundleAsClass:[self class]]); + self.scmButton = OakCreateImageButton([NSImage imageNamed:@"SmartFolder" inSameBundleAsClass:[self class]]); + + self.createButton.toolTip = @"Create new file"; + self.reloadButton.toolTip = @"Reload "; + self.searchButton.toolTip = @""; + self.favoritesButton.toolTip = @"Show favorites"; + self.scmButton.toolTip = @"Show source control management status"; + + NSMenu* menu = [NSMenu new]; + [menu addItemWithTitle:@"Unused" action:@selector(nop:) keyEquivalent:@""]; + [menu addItemWithTitle:@"Create Folder" action:@selector(nop:) keyEquivalent:@""]; + self.actionsPopUpButton.menu = menu; + + NSView* wrappedActionsPopUpButton = [NSView new]; + [wrappedActionsPopUpButton addSubview:self.actionsPopUpButton]; + [self.actionsPopUpButton setTranslatesAutoresizingMaskIntoConstraints:NO]; + [wrappedActionsPopUpButton addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[popup]|" options:0 metrics:nil views:@{ @"popup" : self.actionsPopUpButton }]]; + [wrappedActionsPopUpButton addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[popup]|" options:0 metrics:nil views:@{ @"popup" : self.actionsPopUpButton }]]; + + NSDictionary* views = @{ + @"create" : self.createButton, + @"leftDivider" : OakCreateVerticalLine([NSColor colorWithCalibratedWhite:0.551 alpha:1], [NSColor colorWithCalibratedWhite:0.801 alpha:1]), + @"leftShading" : OakCreateVerticalLine([NSColor colorWithCalibratedWhite:0.869 alpha:1], [NSColor colorWithCalibratedWhite:0.869 alpha:0]), + @"actions" : wrappedActionsPopUpButton, + @"reload" : self.reloadButton, + @"search" : self.searchButton, + @"favorites" : self.favoritesButton, + @"scm" : self.scmButton, + }; + + for(NSView* view in [views allValues]) + { + [view setTranslatesAutoresizingMaskIntoConstraints:NO]; + [self addSubview:view]; + } + + [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-(24)-[create(==22)][leftDivider][leftShading][actions(==30)]-(>=8)-[reload(==22,==search,==favorites,==scm)][search][favorites][scm]-(24)-|" options:0 metrics:nil views:views]]; + [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[create(==leftDivider,==leftShading,==actions,==reload,==search,==favorites,==scm)]|" options:0 metrics:nil views:views]]; + } + return self; +} + +- (NSSize)intrinsicContentSize +{ + return NSMakeSize(NSViewNoInstrinsicMetric, 24); +} + +- (void)drawRect:(NSRect)aRect +{ + [[NSColor windowBackgroundColor] set]; NSRectFill(aRect); + + [super drawRect:aRect]; +} +@end