|
@@ -15,7 +15,7 @@ protocol KMPlanTableCellViewDelegate: AnyObject {
|
|
|
|
|
|
class KMPlanTableCellView: NSTableCellView{
|
|
|
var delegate: KMPlanTableCellViewDelegate?
|
|
|
- var language: Dictionary<String, Any>?
|
|
|
+ var language: String = ""
|
|
|
@IBOutlet var planTextField: NSTextField!
|
|
|
@IBOutlet var planButton: NSButton!
|
|
|
|
|
@@ -28,7 +28,10 @@ class KMPlanTableCellView: NSTableCellView{
|
|
|
class KMPlanViewController: NSViewController,KMPlanTableCellViewDelegate,NSOutlineViewDelegate,NSOutlineViewDataSource{
|
|
|
|
|
|
@IBOutlet var outlineView: NSOutlineView!
|
|
|
- var palns: Array<Any>?
|
|
|
+ lazy var palns: Array<String> = {
|
|
|
+ let palns = [KMLocalizedString("Plan 1 (Online)",nil), KMLocalizedString("Plan 2 (Offline)",nil)]
|
|
|
+ return palns
|
|
|
+ }()
|
|
|
|
|
|
override init(nibName nibNameOrNil: NSNib.Name?, bundle nibBundleOrNil: Bundle?) {
|
|
|
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
|
|
@@ -41,27 +44,63 @@ class KMPlanViewController: NSViewController,KMPlanTableCellViewDelegate,NSOutli
|
|
|
|
|
|
override func awakeFromNib() {
|
|
|
super.awakeFromNib()
|
|
|
- if(self.palns == nil){
|
|
|
- self.palns = [KMLocalizedString("Plan 1 (Online)",nil), KMLocalizedString("Plan 2 (Offline)",nil)]
|
|
|
- self.outlineView.reloadData()
|
|
|
+ self.outlineView.reloadData()
|
|
|
+ }
|
|
|
+ //MARK: NSOutlineViewDataSource
|
|
|
+ func outlineView(_ outlineView: NSOutlineView, numberOfChildrenOfItem item: Any?) -> Int {
|
|
|
+ return self.palns.count
|
|
|
+ }
|
|
|
+ func outlineView(_ outlineView: NSOutlineView, child index: Int, ofItem item: Any?) -> Any {
|
|
|
+ return self.palns[index]
|
|
|
+ }
|
|
|
+ func outlineView(_ outlineView: NSOutlineView, isItemExpandable item: Any) -> Bool {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ // NSOutlineViewDelegate
|
|
|
+ func outlineView(_ outlineView: NSOutlineView, viewFor tableColumn: NSTableColumn?, item: Any) -> NSView? {
|
|
|
+ let result = outlineView.makeView(withIdentifier: NSUserInterfaceItemIdentifier("PlanDataCell"), owner: self) as! KMPlanTableCellView
|
|
|
+ let plan = UserDefaults.standard.integer(forKey: "KMOCRCurrentPlanKey")
|
|
|
+ if plan == transformCellNum(cellContent: item as! String) {
|
|
|
+ result.planButton.state = .on
|
|
|
+ } else {
|
|
|
+ result.planButton.state = .off
|
|
|
}
|
|
|
+ result.planTextField.stringValue = item as! String
|
|
|
+ result.language = item as! String
|
|
|
+ result.delegate = self
|
|
|
+ return result
|
|
|
+ }
|
|
|
+ func outlineView(_ outlineView: NSOutlineView, shouldSelectItem item: Any) -> Bool {
|
|
|
+ return false
|
|
|
}
|
|
|
|
|
|
//MARK: KMPlanTableCellViewDelegate
|
|
|
func tableCellViewCheckButtonDidChange(_ cell: KMPlanTableCellView) {
|
|
|
-// NSUInteger plan = [self.palns indexOfObject:cell.planTextField.stringValue];
|
|
|
-// if (cell.planButton.state) {
|
|
|
-// [[NSUserDefaults standardUserDefaults] setInteger:plan forKey:@"KMOCRCurrentPlanKey"];
|
|
|
-// } else {
|
|
|
-// if(plan == 0) {
|
|
|
-// [[NSUserDefaults standardUserDefaults] setInteger:1 forKey:@"KMOCRCurrentPlanKey"];
|
|
|
-// } else {
|
|
|
-// [[NSUserDefaults standardUserDefaults] setInteger:0 forKey:@"KMOCRCurrentPlanKey"];
|
|
|
-// }
|
|
|
-// [[NSUserDefaults standardUserDefaults] synchronize];
|
|
|
-// }
|
|
|
-// [self.outlineView reloadData];
|
|
|
-// [[NSNotificationCenter defaultCenter] postNotificationName:@"KMOCRSelectedPlanChangeNotification" object:nil];
|
|
|
+ let plan = transformCellNum(cellContent: cell.planTextField.stringValue)
|
|
|
+ if cell.planButton.state == .on{
|
|
|
+ UserDefaults.standard.set(plan, forKey: "KMOCRCurrentPlanKey")
|
|
|
+ } else {
|
|
|
+ if plan == 0 {
|
|
|
+ UserDefaults.standard.set(1, forKey: "KMOCRCurrentPlanKey")
|
|
|
+ } else {
|
|
|
+ UserDefaults.standard.set(0, forKey: "KMOCRCurrentPlanKey")
|
|
|
+ }
|
|
|
+ UserDefaults.standard.synchronize()
|
|
|
+ }
|
|
|
+ self.outlineView.reloadData()
|
|
|
+ NotificationCenter.default.post(name: NSNotification.Name("KMOCRSelectedPlanChangeNotification"), object: nil)
|
|
|
+ }
|
|
|
+
|
|
|
+ func transformCellNum(cellContent:String) -> Int {
|
|
|
+ var index = 0
|
|
|
+ for i in 0..<(self.palns.count) {
|
|
|
+ let str: String = self.palns[i]
|
|
|
+ if cellContent == str {
|
|
|
+ index = i
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return index
|
|
|
}
|
|
|
|
|
|
}
|