Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
404 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// | ||
// AppData.swift | ||
// ⌘英かな | ||
// | ||
// MIT License | ||
// Copyright (c) 2016 iMasanari | ||
// | ||
|
||
import Cocoa | ||
|
||
class AppData : NSObject { | ||
var name: String | ||
var id: String | ||
|
||
init(name: String, id: String) { | ||
self.name = name | ||
self.id = id | ||
|
||
super.init() | ||
} | ||
|
||
override init() { | ||
self.name = "" | ||
self.id = "" | ||
|
||
super.init() | ||
} | ||
|
||
init?(dictionary : [AnyHashable: Any]) { | ||
if let name = dictionary["name"] as? String, let id = dictionary["id"] as? String { | ||
self.name = name | ||
self.id = id | ||
|
||
super.init() | ||
} | ||
else { | ||
return nil | ||
} | ||
} | ||
|
||
func toDictionary() -> [AnyHashable: Any] { | ||
return [ | ||
"name": self.name, | ||
"id": self.id | ||
] | ||
} | ||
} | ||
|
||
|
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
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,83 @@ | ||
// | ||
// ExclusionAppsController.swift | ||
// ⌘英かな | ||
// | ||
// MIT License | ||
// Copyright (c) 2016 iMasanari | ||
// | ||
|
||
import Cocoa | ||
|
||
|
||
class ExclusionAppsController: NSViewController, NSTableViewDataSource, NSTableViewDelegate { | ||
@IBOutlet weak var tableView: NSTableView! | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
// Do any additional setup after loading the view. | ||
|
||
NotificationCenter.default.addObserver(self, | ||
selector: #selector(ExclusionAppsController.tableReload), | ||
name: NSNotification.Name.NSApplicationDidBecomeActive, | ||
object: nil) | ||
} | ||
|
||
func numberOfRows(in tableView: NSTableView) -> Int { | ||
return exclusionAppsList.count + activeAppsList.count | ||
} | ||
|
||
func tableView(_ tableView: NSTableView, objectValueFor tableColumn: NSTableColumn?, row: Int) -> Any? { | ||
let id = tableColumn!.identifier | ||
|
||
let isExclusion = row < exclusionAppsList.count | ||
|
||
if id == "checkbox" { | ||
return isExclusion | ||
} | ||
|
||
let value = isExclusion ? exclusionAppsList[row] : activeAppsList[row - exclusionAppsList.count] | ||
|
||
if id == "appName" { | ||
return value.name | ||
} | ||
if id == "appId" { | ||
return value.id | ||
} | ||
|
||
return nil | ||
} | ||
func tableView(_ tableView: NSTableView, setObjectValue object: Any?, for tableColumn: NSTableColumn?, row: Int) { | ||
let id = tableColumn!.identifier | ||
let isExclusion = row < exclusionAppsList.count | ||
|
||
if id != "checkbox" { | ||
return | ||
} | ||
|
||
if isExclusion { | ||
let item = exclusionAppsList.remove(at: row) | ||
activeAppsList.insert(item, at: 0) | ||
} | ||
else { | ||
let item = activeAppsList.remove(at: row - exclusionAppsList.count) | ||
exclusionAppsList.append(item) | ||
} | ||
|
||
exclusionAppsDict = [:] | ||
|
||
for val in exclusionAppsList { | ||
exclusionAppsDict[val.id] = val.name | ||
} | ||
|
||
tableReload() | ||
saveExclusionApps() | ||
} | ||
|
||
func tableReload() { | ||
tableView.reloadData() | ||
} | ||
|
||
func saveExclusionApps() { | ||
UserDefaults.standard.set(exclusionAppsList.map {$0.toDictionary()} , forKey: "exclusionApps") | ||
} | ||
} |
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
Oops, something went wrong.