diff --git a/SwitchKey.xcodeproj/project.pbxproj b/SwitchKey.xcodeproj/project.pbxproj index e2e991d..8cfd9b1 100644 --- a/SwitchKey.xcodeproj/project.pbxproj +++ b/SwitchKey.xcodeproj/project.pbxproj @@ -100,7 +100,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 1020; - LastUpgradeCheck = 1130; + LastUpgradeCheck = 1300; ORGANIZATIONNAME = "Jinyu Li"; TargetAttributes = { 71FECF2922610BE600C51FD7 = { @@ -196,6 +196,7 @@ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; @@ -257,6 +258,7 @@ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; diff --git a/SwitchKey.xcodeproj/xcshareddata/xcschemes/SwitchKey.xcscheme b/SwitchKey.xcodeproj/xcshareddata/xcschemes/SwitchKey.xcscheme index 80fd0cb..2e079ce 100644 --- a/SwitchKey.xcodeproj/xcshareddata/xcschemes/SwitchKey.xcscheme +++ b/SwitchKey.xcodeproj/xcshareddata/xcschemes/SwitchKey.xcscheme @@ -1,6 +1,6 @@ 0 { - conditionItems.remove(at: row - 1) + if row > 2 { + conditionItems.remove(at: row - 3) conditionTableView.reloadData() saveConditions() } } func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? { - if row > 0 { - let item = conditionItems[row - 1] + if row == 0 { + return conditionTableView.makeView(withIdentifier: editCellIdentifier, owner: nil) + } else if row == 1 { + return conditionTableView.makeView(withIdentifier: defaultCellIdentifier, owner: nil) + } else if row == 2 { + let itemCell = conditionTableView.makeView(withIdentifier: itemCellIdentifier, owner: nil) as! ConditionCell + + let icon = defaultCondition.inputSourceIcon + itemCell.appName.stringValue = "Default" + itemCell.appIcon.image = NSImage() + + itemCell.inputSourceButton.image = icon + itemCell.inputSourceButton.image?.isTemplate = icon.canTemplate() + + itemCell.conditionEnabled.state = defaultCondition.enabled ? .on : .off + return itemCell + } else { + let item = conditionItems[row - 3] let itemCell = conditionTableView.makeView(withIdentifier: itemCellIdentifier, owner: nil) as! ConditionCell itemCell.appIcon.image = item.applicationIcon itemCell.appName.stringValue = item.applicationName @@ -279,21 +335,21 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSTableViewDataSource, NSTab itemCell.conditionEnabled.state = item.enabled ? .on : .off return itemCell - } else { - return conditionTableView.makeView(withIdentifier: editCellIdentifier, owner: nil) } } func tableView(_ tableView: NSTableView, objectValueFor tableColumn: NSTableColumn?, row: Int) -> Any? { - if row > 0 { - return conditionItems[row - 1] + if row == 2 { + return defaultCondition + } else if row > 2 { + return conditionItems[row - 3] } else { return self } } func tableView(_ tableView: NSTableView, heightOfRow row: Int) -> CGFloat { - if row > 0 { + if row > 1 { return 64 } else { return 24 @@ -302,12 +358,12 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSTableViewDataSource, NSTab func tableView(_ tableView: NSTableView, rowViewForRow row: Int) -> NSTableRowView? { let view = TableRowView() - view.highlight = row > 0 + view.highlight = row > 1 return view } func numberOfRows(in tableView: NSTableView) -> Int { - return conditionItems.count + 1 + return conditionItems.count + 3 } } @@ -373,3 +429,17 @@ class EditCell: NSTableCellView { app.addCondition() } } + +class DefaultCell: NSTableCellView { + @IBAction func addItemClicked(_ sender: Any) { + let app = objectValue as! AppDelegate + app.setDefaultCondition() + } +} + +extension String { +subscript(to: Int) -> String { + let index = self.index(self.startIndex, offsetBy: to) + return String(self[.. - + - + @@ -23,23 +23,22 @@ - - + + - - + + - - + + - + - @@ -55,18 +54,17 @@ - + - + - @@ -76,9 +74,9 @@ - - - + + + @@ -118,7 +116,7 @@ - + @@ -127,20 +125,20 @@ - + - - + + + + + + + + + +