Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the window UI to look a bit more like Open Quickly #14

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 52 additions & 33 deletions PGXcodeActionBrowser/Controllers/XCActionBarWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ @interface XCActionBarWindowController () <XCActionBarCommandProcessor, NSTableV
@property (weak) IBOutlet NSLayoutConstraint *searchFieldBottomConstraint;
@property (weak) IBOutlet NSLayoutConstraint *searchResultsTableHeightConstraint;
@property (weak) IBOutlet NSLayoutConstraint *searchResultsTableBottomConstraint;
@property (strong) XCSearchResultCell *prototypeResultCell;

@property (nonatomic) NSArray *searchResults;

Expand Down Expand Up @@ -78,14 +79,17 @@ - (void)windowDidLoad

self.commandHandlers = @{XCSearchInputHandlerKey: [[XCActionBarSearchStateCommandHandler alloc] initWithCommandProcessor:self],
XCArgumentInputHandlerKey: [[XCActionBarArgumentInputStateCommandHandler alloc] initWithCommandProcessor:self]};


self.searchField.focusRingType = NSFocusRingTypeNone;
self.searchField.delegate = self;
self.searchField.nextResponder = self;

self.searchField.layer.borderColor = [[NSColor controlColor] CGColor];
self.searchResultsTable.rowSizeStyle = NSTableViewRowSizeStyleCustom;
self.searchResultsTable.selectionHighlightStyle = NSTableViewSelectionHighlightStyleRegular;
self.searchResultsTable.rowHeight = 50.0;
self.searchField.layer.borderWidth = 1.0;
self.searchField.layer.backgroundColor = [[NSColor whiteColor] CGColor];
self.searchField.layer.cornerRadius = 3.0;
self.searchField.layer.masksToBounds = YES;

self.searchResultsTable.target = self;
self.searchResultsTable.doubleAction = @selector(processDoubleClickOnSearchResult:);
Expand Down Expand Up @@ -195,46 +199,53 @@ - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColu
- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
XCSearchResultCell *cell = [tableView makeViewWithIdentifier:NSStringFromClass([XCSearchResultCell class]) owner:self];

[self configureCell:cell forRow:row];
return cell;
}

- (void)configureCell:(XCSearchResultCell *)cell forRow:(NSUInteger)row
{
id<XCActionInterface> action = self.searchResults[row];

NSMutableAttributedString *title = [[NSMutableAttributedString alloc] initWithString:TRSafeString(action.title)];

[title addAttribute:NSForegroundColorAttributeName
value:(action.enabled ? [NSColor blackColor] : [NSColor darkGrayColor])
range:NSMakeRange(0, title.length)];

for(NSValue *rangeValue in action.searchQueryMatchRanges) {
[title addAttributes:@{NSBackgroundColorAttributeName:[NSColor colorWithCalibratedRed:1.000 green:1.000 blue:0.519 alpha:0.250],
NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle),
NSUnderlineColorAttributeName: [NSColor yellowColor]}
range:rangeValue.rangeValue];
}

cell.textField.allowsEditingTextAttributes = YES;

cell.textField.attributedStringValue = title;
cell.hintTextField.stringValue = TRSafeString(action.hint);

if([action acceptsArguments] == YES) {
// NSString *summaryWithMarker = [NSString stringWithFormat:@"%@ %@", @"\uf11c", TRSafeString(action.subtitle)];
// NSMutableAttributedString *summary = [[NSMutableAttributedString alloc] initWithString:summaryWithMarker];
// [summary addAttributes:@{NSFontAttributeName: XCFontAwesomeWithSize(12.0)}
// range:NSMakeRange(0, 1)];
// cell.subtitleTextField.allowsEditingTextAttributes = YES;
// cell.subtitleTextField.attributedStringValue = summary;

cell.subtitleTextField.stringValue = [NSString stringWithFormat:@"%@ %@", @"\u21e5", TRSafeString(action.subtitle)];
cell.subtitleTextField.stringValue = TRSafeString(action.subtitle);
cell.iconImageView.image = action.icon;
}
else cell.subtitleTextField.stringValue = TRSafeString(action.subtitle);

}

- (CGFloat)tableView:(NSTableView *)tableView heightOfRow:(NSInteger)row
{
if (self.prototypeResultCell == nil)
{
self.prototypeResultCell = [self.searchResultsTable makeViewWithIdentifier:NSStringFromClass([XCSearchResultCell class]) owner:self];
}

[self configureCell:self.prototypeResultCell forRow:row];
[self.prototypeResultCell layoutSubtreeIfNeeded];

return cell;
return self.prototypeResultCell.fittingSize.height;
}

#pragma mark - Public Methods


////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
- (void)updateSearchResults:(NSArray *)results
Expand Down Expand Up @@ -420,13 +431,16 @@ - (void)selectSearchResultAtIndex:(NSInteger)indexToSelect
- (void)resizeWindowToAccomodateSearchResults
{
if(TRCheckIsEmpty(self.searchResults) == NO) {
[[self.searchResultsTable animator] setAlphaValue:1.0];

self.searchResultsTable.hidden = NO;
self.searchResultsTableBottomConstraint.constant = 10.0;
self.searchResultsTableHeightConstraint.constant = 250.0;

[self.searchField layoutSubtreeIfNeeded];
self.searchResultsTableBottomConstraint.constant = 0.0;

[NSAnimationContext runAnimationGroup:^(NSAnimationContext *context) {
context.duration = 0.26;
self.searchResultsTable.animator.alphaValue = 1.0;
self.searchResultsTableHeightConstraint.animator.constant = MIN(self.searchResultsTable.rowHeight * self.searchResults.count, self.searchResultsTable.rowHeight * 6);

[self.searchField layoutSubtreeIfNeeded];
} completionHandler:nil];
}
else [self restoreWindowSize];
}
Expand All @@ -435,13 +449,18 @@ - (void)resizeWindowToAccomodateSearchResults
////////////////////////////////////////////////////////////////////////////////
- (void)restoreWindowSize
{
[[self.searchResultsTable animator] setAlphaValue:0.0];

self.searchResultsTable.hidden = YES;
self.searchResultsTableBottomConstraint.constant = 0.0;
self.searchResultsTableHeightConstraint.constant = 0.0;

[self.window.contentView layoutSubtreeIfNeeded];
[NSAnimationContext runAnimationGroup:^(NSAnimationContext *context) {
context.duration = 0.16;
self.searchResultsTable.animator.alphaValue = 0.0;
self.searchResultsTableHeightConstraint.constant = 0.0;
[self.window.contentView layoutSubtreeIfNeeded];

} completionHandler:^{
self.searchResultsTableBottomConstraint.constant = 0.0;
self.searchResultsTable.hidden = YES;

[self.window.contentView layoutSubtreeIfNeeded];
}];
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
Loading