mirror of
https://github.com/ypresto/SwiftLintXcode.git
synced 2026-03-25 08:55:51 +00:00
49 lines
1.2 KiB
Swift
Executable file
49 lines
1.2 KiB
Swift
Executable file
//
|
|
// SwiftLintAutoCorrect.swift
|
|
//
|
|
// Created by yuya.tanaka on 2016/04/04.
|
|
// Copyright © 2016年 Yuya Tanaka. All rights reserved.
|
|
//
|
|
|
|
import AppKit
|
|
|
|
var sharedPlugin: SwiftLintAutoCorrect?
|
|
|
|
class SwiftLintAutoCorrect: NSObject {
|
|
|
|
var bundle: NSBundle
|
|
lazy var center = NSNotificationCenter.defaultCenter()
|
|
|
|
init(bundle: NSBundle) {
|
|
self.bundle = bundle
|
|
|
|
super.init()
|
|
center.addObserver(self, selector: Selector("createMenuItems"), name: NSApplicationDidFinishLaunchingNotification, object: nil)
|
|
}
|
|
|
|
deinit {
|
|
removeObserver()
|
|
}
|
|
|
|
func removeObserver() {
|
|
center.removeObserver(self)
|
|
}
|
|
|
|
func createMenuItems() {
|
|
removeObserver()
|
|
|
|
var item = NSApp.mainMenu!.itemWithTitle("Edit")
|
|
if item != nil {
|
|
var actionMenuItem = NSMenuItem(title:"Do Action", action:"doMenuAction", keyEquivalent:"")
|
|
actionMenuItem.target = self
|
|
item!.submenu!.addItem(NSMenuItem.separatorItem())
|
|
item!.submenu!.addItem(actionMenuItem)
|
|
}
|
|
}
|
|
|
|
func doMenuAction() {
|
|
let error = NSError(domain: "Hello World!", code:42, userInfo:nil)
|
|
NSAlert(error: error).runModal()
|
|
}
|
|
}
|
|
|