// Created by Jaime O. Rios import AppKit var sharedPlugin: XcodePerforcePlugin? class XcodePerforcePlugin: NSObject { var bundle: NSBundle var p4Functionatlity: P4Functionality = P4Functionality() class func pluginDidLoad(bundle: NSBundle) { let appName = NSBundle.mainBundle().infoDictionary?["CFBundleName"] as? NSString if appName == "Xcode" { sharedPlugin = XcodePerforcePlugin(bundle: bundle) } } init(bundle: NSBundle) { self.bundle = bundle super.init() createMenuItems() } deinit { NSNotificationCenter.defaultCenter().removeObserver(self) } func createMenuItems() { var item = NSApp.mainMenu!!.itemWithTitle("Source Control") if item != nil { p4SettingsSetUpMenu(item) p4InfoSetUpMenu(item) p4CheckOutSetUpMenu(item) p4AddSetUpMenu(item) p4vcRevGraphSetUpMenu(item) p4vcTimeLapseSetUpMenu(item) } } // MARK: - func p4SettingsSetUpMenu(let item : NSMenuItem?) { var menuItem = NSMenuItem(title:"p4plugin settings", action:"p4Settings", keyEquivalent:"") menuItem.target = self item!.submenu!.addItem(NSMenuItem.separatorItem()) item!.submenu!.addItem(menuItem) } func p4Settings() { p4Functionatlity.checkSettings() var attr = p4Functionatlity.p4Installed let p4Installed = String("p4 installed: \t" + (attr ? "YES": "NO") + "\n") var value = p4Functionatlity.p4Path var valueStr = (value != nil ? value : "Unknown") let p4Path = String("p4 path: \t\t" + valueStr + "\n") attr = p4Functionatlity.p4vcInstalled let p4vcInstalled = String("p4vc installed: \t" + (attr ? "YES": "NO") + "\n") value = p4Functionatlity.p4vcPath valueStr = (value != nil ? value : "Unknown") let p4vcPath = String("p4vc path: \t" + valueStr + "\n") attr = p4Functionatlity.P4CONFIG_Set let p4ConfigSet = String("P4CONFIG set: " + (attr ? "YES": "NO") + "\n") value = p4Functionatlity.p4ClientName let p4ClientName = String("P4CLIENT name: " + value + "\n") var settingsAlertBox = NSAlert() settingsAlertBox.messageText = "plugin settings" settingsAlertBox.informativeText = p4Installed + p4Path + p4vcInstalled + p4vcPath + p4ConfigSet + p4ClientName settingsAlertBox.runModal() } func displayDefaultP4NotSetError() { let error = NSError(domain: "Either P4CONFIG not set or a p4 config file is not available in the project root", code:1, userInfo:nil) NSAlert(error: error).runModal() } func p4CheckOutSetUpMenu(let item : NSMenuItem?) { var menuItem = NSMenuItem(title:"p4 - edit", action:"p4CheckOut", keyEquivalent:"") menuItem.target = self item!.submenu!.addItem(menuItem) } func p4CheckOut() { if (p4Functionatlity.p4ClientSet()) { let msg = p4Functionatlity.p4CheckOutCurrentFile() var settingsAlertBox = NSAlert() settingsAlertBox.messageText = "p4 edit" settingsAlertBox.informativeText = msg settingsAlertBox.runModal() } else { displayDefaultP4NotSetError() } } func p4AddSetUpMenu(let item : NSMenuItem?) { var menuItem = NSMenuItem(title:"p4 - add", action:"p4Add", keyEquivalent:"") menuItem.target = self item!.submenu!.addItem(menuItem) } func p4Add() { if (p4Functionatlity.p4ClientSet()) { let msg = p4Functionatlity.p4Add() var settingsAlertBox = NSAlert() settingsAlertBox.messageText = "p4 add" settingsAlertBox.informativeText = msg settingsAlertBox.runModal() } else { displayDefaultP4NotSetError() } } func p4InfoSetUpMenu(let item : NSMenuItem?) { var menuItem = NSMenuItem(title:"p4 - info", action:"p4Info", keyEquivalent:"") menuItem.target = self item!.submenu!.addItem(menuItem) } func p4Info() { let msg = p4Functionatlity.p4Info() var settingsAlertBox = NSAlert() settingsAlertBox.messageText = "p4 info" settingsAlertBox.informativeText = msg settingsAlertBox.runModal() } // MARK: - func p4vcRevGraphSetUpMenu(let item : NSMenuItem?) { var menuItem = NSMenuItem(title:"p4vc - revgraph", action:"p4vcRevGraph", keyEquivalent:"") menuItem.target = self item!.submenu!.addItem(menuItem) } func p4vcRevGraph() { if (p4Functionatlity.p4ClientSet()) { p4Functionatlity.p4vcRevGraph(); } else { displayDefaultP4NotSetError() } } func p4vcTimeLapseSetUpMenu(let item : NSMenuItem?) { var menuItem = NSMenuItem(title:"p4vc - timelapse", action:"p4vcTimeLapse", keyEquivalent:"") menuItem.target = self item!.submenu!.addItem(menuItem) } func p4vcTimeLapse() { if (p4Functionatlity.p4ClientSet()) { p4Functionatlity.p4vcRevGraph(); } else { displayDefaultP4NotSetError() } } }