-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #87 from zenangst/feature/list-mode
Feature list mode
- Loading branch information
Showing
23 changed files
with
680 additions
and
140 deletions.
There are no files selected for viewing
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
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
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,17 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "universal", | ||
"filename" : "Grid.pdf" | ||
} | ||
], | ||
"info" : { | ||
"version" : 1, | ||
"author" : "xcode" | ||
}, | ||
"properties" : { | ||
"template-rendering-intent" : "template", | ||
"preserves-vector-representation" : true, | ||
"auto-scaling" : "auto" | ||
} | ||
} |
Binary file not shown.
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,17 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "universal", | ||
"filename" : "List.pdf" | ||
} | ||
], | ||
"info" : { | ||
"version" : 1, | ||
"author" : "xcode" | ||
}, | ||
"properties" : { | ||
"template-rendering-intent" : "template", | ||
"preserves-vector-representation" : true, | ||
"auto-scaling" : "auto" | ||
} | ||
} |
Binary file not shown.
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
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
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
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
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,63 @@ | ||
import Cocoa | ||
|
||
protocol ViewToolbarItemDelegate: class { | ||
func viewToolbarItem(_ toolbarItem: ViewToolbarItem, didChange mode: String) | ||
} | ||
|
||
class ViewToolbarItem: NSToolbarItem { | ||
static var itemIdentifier: NSToolbarItem.Identifier = .init("View") | ||
|
||
weak var delegate: ViewToolbarItemDelegate? | ||
|
||
lazy var segmentedControl = NSSegmentedControl.init(images: ApplicationsFeatureViewController.Mode.allCases.compactMap({ $0.image }), | ||
trackingMode: .selectOne, | ||
target: self, | ||
action: #selector(didChangeView(_:))) | ||
lazy var customView = NSView() | ||
|
||
init() { | ||
super.init(itemIdentifier: ViewToolbarItem.itemIdentifier) | ||
view = customView | ||
view?.addSubview(segmentedControl) | ||
minSize = .init(width: 80, height: 25) | ||
maxSize = .init(width: 80, height: 25) | ||
segmentedControl.setToolTip("Grid", forSegment: 0) | ||
segmentedControl.setTag(0, forSegment: 0) | ||
segmentedControl.setToolTip("List", forSegment: 1) | ||
segmentedControl.setTag(1, forSegment: 1) | ||
configureSegmentControl() | ||
setupConstraints() | ||
|
||
NotificationCenter.default.addObserver(self, selector: #selector(configureSegmentControl), | ||
name: NSNotification.Name.init(rawValue: "featureViewControllerMode"), object: nil) | ||
} | ||
|
||
@objc func configureSegmentControl() { | ||
if let mode = UserDefaults.standard.featureViewControllerMode { | ||
switch mode { | ||
case .grid: | ||
segmentedControl.selectSegment(withTag: 0) | ||
case .list: | ||
segmentedControl.selectSegment(withTag: 1) | ||
} | ||
} else { | ||
segmentedControl.selectSegment(withTag: 0) | ||
} | ||
} | ||
|
||
func setupConstraints() { | ||
segmentedControl.translatesAutoresizingMaskIntoConstraints = false | ||
segmentedControl.centerXAnchor.constraint(equalTo: customView.centerXAnchor).isActive = true | ||
segmentedControl.centerYAnchor.constraint(equalTo: customView.centerYAnchor).isActive = true | ||
segmentedControl.widthAnchor.constraint(equalTo: customView.widthAnchor).isActive = true | ||
segmentedControl.heightAnchor.constraint(equalToConstant: 25).isActive = true | ||
} | ||
|
||
@objc func didChangeView(_ segmentControl: NSSegmentedControl) { | ||
guard let label = segmentedControl.toolTip(forSegment: segmentedControl.indexOfSelectedItem) else { | ||
return | ||
} | ||
|
||
delegate?.viewToolbarItem(self, didChange: label) | ||
} | ||
} |
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 @@ | ||
import Foundation | ||
|
||
extension UserDefaults { | ||
var featureViewControllerMode: ApplicationsFeatureViewController.Mode? { | ||
get { | ||
let rawValue = UserDefaults.standard.string(forKey: #function) ?? "" | ||
return ApplicationsFeatureViewController.Mode.init(rawValue: rawValue) | ||
} | ||
set { | ||
UserDefaults.standard.set(newValue?.rawValue, forKey: #function) | ||
} | ||
} | ||
} |
Oops, something went wrong.