This repository has been archived by the owner on Nov 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 417
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for editing tweaks on OS X.
- When targeting OS X, use FBTweakOSX build target
- Loading branch information
Showing
15 changed files
with
1,799 additions
and
13 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// FBTweaksEditorViewController.h | ||
// FBTweak | ||
// | ||
// Created by Paulo Andrade on 13/12/14. | ||
// Copyright (c) 2014 Facebook. All rights reserved. | ||
// | ||
|
||
#import <Cocoa/Cocoa.h> | ||
|
||
@interface FBTweakEditorViewController : NSViewController | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
// | ||
// FBTweaksEditorViewController.m | ||
// FBTweak | ||
// | ||
// Created by Paulo Andrade on 13/12/14. | ||
// Copyright (c) 2014 Facebook. All rights reserved. | ||
// | ||
|
||
#import "FBTweakEditorViewController.h" | ||
#import "_FBTweakCategoriesViewController.h" | ||
#import "_FBTweakListViewController.h" | ||
|
||
@interface FBTweakEditorViewController () <_FBTweakCategoriesViewControllerDelegate> | ||
|
||
@property (nonatomic, strong) NSSplitViewController *splitViewController; | ||
|
||
@property (nonatomic, strong) NSSplitViewItem *categoriesSplitViewItem; | ||
@property (nonatomic, strong) _FBTweakCategoriesViewController *categoriesViewController; | ||
|
||
@property (nonatomic, strong) NSSplitViewItem *listSplitViewItem; | ||
@property (nonatomic, strong) _FBTweakListViewController *listViewController; | ||
|
||
|
||
|
||
@end | ||
|
||
@implementation FBTweakEditorViewController | ||
|
||
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil | ||
{ | ||
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; | ||
if (self) { | ||
self.title = @"Tweaks"; | ||
} | ||
return self; | ||
} | ||
|
||
- (void)loadView | ||
{ | ||
NSView *view = [[NSView alloc] initWithFrame:CGRectMake(0, 0, 640, 480)]; | ||
|
||
_FBTweakCategoriesViewController *categories = [[_FBTweakCategoriesViewController alloc] initWithStore:[FBTweakStore sharedInstance]]; | ||
categories.delegate = self; | ||
_FBTweakListViewController *list = [[_FBTweakListViewController alloc] init]; | ||
|
||
NSSplitViewController *splitViewController = [[NSSplitViewController alloc] init]; | ||
|
||
// Categories | ||
NSSplitViewItem *splitItem = [NSSplitViewItem splitViewItemWithViewController:categories]; | ||
NSView *splitItemView = [categories view]; | ||
splitItemView.translatesAutoresizingMaskIntoConstraints = NO; | ||
NSLayoutConstraint *width = [NSLayoutConstraint constraintWithItem:splitItemView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:150]; | ||
width.priority = NSLayoutPriorityDefaultLow; | ||
width.active = YES; | ||
splitItem.holdingPriority = NSLayoutPriorityDefaultLow+1; | ||
splitItem.collapsed = NO; | ||
splitItem.canCollapse = NO; | ||
[splitViewController addSplitViewItem:splitItem]; | ||
self.categoriesSplitViewItem = splitItem; | ||
|
||
// Collections | ||
splitItem = [NSSplitViewItem splitViewItemWithViewController:list]; | ||
splitItemView = [list view]; | ||
splitItemView.translatesAutoresizingMaskIntoConstraints = NO; | ||
width = [NSLayoutConstraint constraintWithItem:splitItemView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:330]; | ||
width.priority = NSLayoutPriorityDefaultLow; | ||
width.active = YES; | ||
splitItem.holdingPriority = NSLayoutPriorityDefaultLow; | ||
splitItem.collapsed = NO; | ||
splitItem.canCollapse = NO; | ||
|
||
[splitViewController addSplitViewItem:splitItem]; | ||
self.listSplitViewItem = splitItem; | ||
|
||
NSView *splitView = [splitViewController view]; | ||
splitView.frame = view.bounds; | ||
splitView.autoresizingMask = NSViewWidthSizable|NSViewHeightSizable; | ||
[view addSubview:splitView]; | ||
|
||
self.categoriesViewController = categories; | ||
self.listViewController = list; | ||
self.splitViewController = splitViewController; | ||
|
||
[self addChildViewController:self.splitViewController]; | ||
|
||
self.view = view; | ||
} | ||
|
||
- (void)viewWillAppear | ||
{ | ||
[super viewWillAppear]; | ||
self.listViewController.tweakCategory = [self.categoriesViewController selectedCategory]; | ||
} | ||
|
||
#pragma mark - Delegates | ||
|
||
#pragma mark _FBTweakCategoriesViewControllerDelegate | ||
|
||
- (void)categoriesViewController:(_FBTweakCategoriesViewController *)controller didChangeSelection:(FBTweakCategory *)category | ||
{ | ||
self.listViewController.tweakCategory = category; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// _FBTweakCategoriesViewController.h | ||
// FBTweak | ||
// | ||
// Created by Paulo Andrade on 13/12/14. | ||
// Copyright (c) 2014 Facebook. All rights reserved. | ||
// | ||
|
||
#import <AppKit/AppKit.h> | ||
#import "FBTweakStore.h" | ||
#import "FBTweakCategory.h" | ||
|
||
@protocol _FBTweakCategoriesViewControllerDelegate; | ||
|
||
|
||
|
||
@interface _FBTweakCategoriesViewController : NSViewController | ||
|
||
- (instancetype)initWithStore:(FBTweakStore *)store; | ||
|
||
@property (nonatomic, weak) id<_FBTweakCategoriesViewControllerDelegate> delegate; | ||
|
||
- (FBTweakCategory *)selectedCategory; | ||
|
||
@end | ||
|
||
|
||
|
||
|
||
@protocol _FBTweakCategoriesViewControllerDelegate <NSObject> | ||
|
||
- (void)categoriesViewController:(_FBTweakCategoriesViewController *)controller didChangeSelection:(FBTweakCategory *)category; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
// | ||
// _FBTweakCategoriesViewController.m | ||
// FBTweak | ||
// | ||
// Created by Paulo Andrade on 13/12/14. | ||
// Copyright (c) 2014 Facebook. All rights reserved. | ||
// | ||
|
||
#import "_FBTweakCategoriesViewController.h" | ||
#import "FBTweakStore.h" | ||
#import "FBTweakCategory.h" | ||
|
||
@interface _FBTweakCategoriesViewController () <NSOutlineViewDataSource, NSOutlineViewDelegate> | ||
|
||
|
||
@property (nonatomic, weak) NSOutlineView *outlineView; | ||
|
||
@end | ||
|
||
@implementation _FBTweakCategoriesViewController { | ||
NSArray *_sortedCategories; | ||
} | ||
|
||
- (instancetype)initWithStore:(FBTweakStore *)store | ||
{ | ||
self = [super initWithNibName:@"" bundle:nil]; | ||
if (self) { | ||
_sortedCategories = [store.tweakCategories sortedArrayUsingComparator:^(FBTweakCategory *a, FBTweakCategory *b) { | ||
return [a.name localizedStandardCompare:b.name]; | ||
}]; | ||
} | ||
return self; | ||
} | ||
|
||
- (void)loadView | ||
{ | ||
NSView *view = [[NSView alloc] initWithFrame:CGRectMake(0, 0, 300, 500)]; | ||
|
||
NSScrollView *scrollView = [[NSScrollView alloc] initWithFrame:view.bounds]; | ||
scrollView.autoresizingMask = NSViewWidthSizable|NSViewHeightSizable; | ||
|
||
NSOutlineView *outlineView = [[NSOutlineView alloc] initWithFrame:scrollView.bounds]; | ||
outlineView.autoresizingMask = NSViewWidthSizable|NSViewHeightSizable; | ||
outlineView.translatesAutoresizingMaskIntoConstraints = NO; | ||
outlineView.dataSource = self; | ||
outlineView.delegate = self; | ||
outlineView.allowsEmptySelection = NO; | ||
outlineView.allowsMultipleSelection = NO; | ||
outlineView.selectionHighlightStyle = NSTableViewSelectionHighlightStyleSourceList; | ||
|
||
NSTableColumn *column = [[NSTableColumn alloc] initWithIdentifier:@"Categories"]; | ||
column.title = @"Categories"; | ||
column.width = CGRectGetWidth(view.frame); | ||
column.editable = NO; | ||
[outlineView addTableColumn:column]; | ||
|
||
scrollView.documentView = outlineView; | ||
scrollView.autoresizesSubviews = YES; | ||
|
||
[view addSubview:scrollView]; | ||
|
||
[view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[outlineView]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(outlineView)]]; | ||
[view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[outlineView]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(outlineView)]]; | ||
|
||
self.outlineView = outlineView; | ||
|
||
self.view = view; | ||
} | ||
|
||
|
||
- (FBTweakCategory *)selectedCategory | ||
{ | ||
return _sortedCategories[[self.outlineView selectedRow]]; | ||
} | ||
|
||
- (void)viewDidAppear | ||
{ | ||
[super viewDidAppear]; | ||
[self.outlineView reloadData]; | ||
} | ||
|
||
#pragma mark - NSOutlineView | ||
|
||
#pragma mark datasource | ||
|
||
- (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item | ||
{ | ||
return (item == nil) ? [_sortedCategories count] : 0; | ||
} | ||
|
||
- (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item | ||
{ | ||
return _sortedCategories[index]; | ||
} | ||
|
||
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item | ||
{ | ||
return NO; | ||
} | ||
|
||
|
||
#pragma mark delegate | ||
|
||
- (NSView *)outlineView:(NSOutlineView *)outlineView viewForTableColumn:(NSTableColumn *)tableColumn item:(FBTweakCategory *)category | ||
{ | ||
NSTableCellView *cellView = [[NSTableCellView alloc] initWithFrame:CGRectMake(0, 0, 100, 50)]; | ||
NSTextField *textField = [[NSTextField alloc] initWithFrame:cellView.bounds]; | ||
textField.autoresizingMask = NSViewWidthSizable|NSViewHeightSizable; | ||
textField.stringValue = category.name; | ||
textField.bordered = NO; | ||
textField.drawsBackground = NO; | ||
textField.focusRingType = NSFocusRingTypeNone; | ||
[cellView addSubview:textField]; | ||
cellView.textField = textField; | ||
return cellView; | ||
} | ||
|
||
- (void)outlineViewSelectionDidChange:(NSNotification *)notification | ||
{ | ||
[self.delegate categoriesViewController:self didChangeSelection:[self selectedCategory]]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// _FBTweakListViewController.h | ||
// FBTweak | ||
// | ||
// Created by Paulo Andrade on 14/12/14. | ||
// Copyright (c) 2014 Facebook. All rights reserved. | ||
// | ||
|
||
#import <Cocoa/Cocoa.h> | ||
#import "FBTweakCategory.h" | ||
|
||
@interface _FBTweakListViewController : NSViewController | ||
|
||
@property (nonatomic, strong) FBTweakCategory *tweakCategory; | ||
|
||
@end |
Oops, something went wrong.