NSToolbarItem的不稳定动作

时间:2016-05-09 00:30:13

标签: cocoa nsbutton nstask nstoolbar nstoolbaritem

我正在使用工具栏按钮来控制简单的NSTask。当IBAction由常规按钮给出时,下面的代码按预期工作,但是当由NSToolbarItem给出时产生伪像。更准确地说,运行按钮不会被禁用。任何想法都将不胜感激。

import Cocoa

class Document: NSDocument {

    override var windowNibName: String? {
        return "Document"
    }

    @IBOutlet var runButtonOutlet: NSToolbarItem! // works for NSButton 

    @IBAction func runButtonAction(sender: AnyObject) {
        runTask()
        runButtonOutlet.enabled = false
    }
    @IBAction func quitButtonAction(sender: AnyObject) {
        bigTask.terminate()
        runButtonOutlet.enabled = true
    }

    var bigTask = NSTask()

    func runTask () {
        let task = NSTask()
        bigTask = task
        task.launchPath = "/usr/bin/say"
        task.arguments = ["say something"]
        task.terminationHandler = {
            task in
            self.runButtonOutlet.enabled = true
        }
        task.launch()
    }
}

0 个答案:

没有答案