Skip to content

Commit

Permalink
Merge pull request #2 from stihahi/sushi_changer
Browse files Browse the repository at this point in the history
Sushi changer
  • Loading branch information
mzp committed Jul 3, 2017
2 parents 50f5756 + 63f31d8 commit 54f9e4e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 18 deletions.
4 changes: 3 additions & 1 deletion sushibar.xcodeproj/project.pbxproj
Expand Up @@ -88,7 +88,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0810;
LastUpgradeCheck = 0810;
LastUpgradeCheck = 0830;
ORGANIZATIONNAME = mzp;
TargetAttributes = {
13E88E441DC4AEDC00AF08B0 = {
Expand Down Expand Up @@ -169,6 +169,7 @@
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_SUSPICIOUS_MOVES = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -218,6 +219,7 @@
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_SUSPICIOUS_MOVES = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down
45 changes: 31 additions & 14 deletions sushibar/AppDelegate.swift
Expand Up @@ -12,7 +12,10 @@ fileprivate extension NSTouchBarItemIdentifier {
static let kome = NSTouchBarItemIdentifier("jp.mzp.touchbar.kome")
static let fish = NSTouchBarItemIdentifier("jp.mzp.touchbar.fish")
static let sushi = NSTouchBarItemIdentifier("jp.mzp.touchbar.sushi")
static let lane = NSTouchBarItemIdentifier("jp.mzp.touchbar.lane")
// static let lane = NSTouchBarItemIdentifier("jp.mzp.touchbar.lane")
static let komelane = NSTouchBarItemIdentifier("jp.mzp.touchbar.lane.kome")
static let fishlane = NSTouchBarItemIdentifier("jp.mzp.touchbar.lane.fish")
static let sushilane = NSTouchBarItemIdentifier("jp.mzp.touchbar.lane.sushi")
}

@available(OSX 10.12.2, *)
Expand Down Expand Up @@ -46,32 +49,46 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSTouchBarProvider, NSTouchB
return mainBar
}

func makeSecondaryTouchBar() -> NSTouchBar {
func makeSecondaryTouchBar(tLane _tLane:NSTouchBarItemIdentifier) -> NSTouchBar {
let mainBar = NSTouchBar()
mainBar.delegate = self
mainBar.defaultItemIdentifiers = [.lane]
mainBar.defaultItemIdentifiers = [_tLane]
return mainBar
}

func touchBar(_ touchBar: NSTouchBar, makeItemForIdentifier identifier: NSTouchBarItemIdentifier) -> NSTouchBarItem? {
if identifier == .kome {
let item = NSCustomTouchBarItem(identifier: identifier)
let button = NSButton(title: "🍚", target: self, action: #selector(AppDelegate.tapped(_:)))
item.view = button
let item = NSPopoverTouchBarItem(identifier: identifier)
item.collapsedRepresentationLabel = "🍚"
item.popoverTouchBar = makeSecondaryTouchBar(tLane: .komelane)
return item
} else if identifier == .fish {
let item = NSPopoverTouchBarItem(identifier: identifier)
item.collapsedRepresentationLabel = "🐟"
item.popoverTouchBar = makeSecondaryTouchBar(tLane: .fishlane)
return item
}else if identifier == .sushi {
let item = NSPopoverTouchBarItem(identifier: identifier)
item.collapsedRepresentationLabel = "🍣"
item.popoverTouchBar = makeSecondaryTouchBar(tLane: .sushilane)
return item
} else if identifier == .sushilane {
let item = NSCustomTouchBarItem(identifier: identifier)
let button = NSButton(title: "🐟", target: self, action: #selector(AppDelegate.tapped(_:)))
item.view = button
let sushiLaneVC = SushiLaneController()
sushiLaneVC.setStr(str:"🍣")
item.viewController = sushiLaneVC
return item
} else if identifier == .lane {
} else if identifier == .fishlane {
let item = NSCustomTouchBarItem(identifier: identifier)
item.viewController = SushiLaneController()
let sushiLaneVC = SushiLaneController()
sushiLaneVC.setStr(str:"🐟")
item.viewController = sushiLaneVC
return item
} else if identifier == .sushi {
let item = NSPopoverTouchBarItem(identifier: identifier)
item.collapsedRepresentationLabel = "🍣"
item.popoverTouchBar = makeSecondaryTouchBar()
} else if identifier == .komelane {
let item = NSCustomTouchBarItem(identifier: identifier)
let sushiLaneVC = SushiLaneController()
sushiLaneVC.setStr(str:"🍚")
item.viewController = sushiLaneVC
return item
} else {
return nil
Expand Down
10 changes: 7 additions & 3 deletions sushibar/SushiLaneController.swift
Expand Up @@ -11,7 +11,8 @@ import AppKit

class SushiLaneController : NSViewController {
let lane = NSView()

var mvString="🍣"

override func loadView() {
self.view = NSView()
}
Expand All @@ -25,13 +26,16 @@ class SushiLaneController : NSViewController {
for x in 0...16 {
lane.addSubview(makeSushi(x: x * 100))
}

start()
}

func setStr(str: String){
mvString = str
}

func makeSushi(x : Int) -> NSView {
let sushi = NSTextView(frame: NSRect(x: x, y: 0, width: 30, height: 30))
sushi.string = "🍣"
sushi.string = mvString
sushi.drawsBackground = false
sushi.isEditable = false
sushi.isSelectable = false
Expand Down

0 comments on commit 54f9e4e

Please sign in to comment.