XcodePerforcePlugin.swift #1

  • //
  • guest/
  • jaime_rios/
  • XcodePerforcePlugin/
  • XcodePerforcePlugin/
  • XcodePerforcePlugin.swift
  • View
  • Commits
  • Open Download .zip Download (5 KB)
// 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()
        }
    }
}

# Change User Description Committed
#12 20141 Jaime Rios Merging using M_robc_apple-to_jaime_rios_XcodePerforcePlugin
#11 19863 Jaime Rios Fixed warning generated by Xcode regarding deprecated selector call usage in Swift
#10 15948 Jaime Rios Added p4vc submit functionality; violated rule 0; updated plist for xcode 7 uuid; fixed errors encountered by xcode related to optionals and interoperability with Obj-C++ code.
#9 15115 Jaime Rios Modified plist for Xcode 6.4 and Xcode 7 Beta; updated code changes in Swift; added notes about UUID for self.
#8 13723 Jaime Rios Fixed problem with menu items not being created because mainMenu is not available at startup for Xcode 6.3.2.
#7 13687 Jaime Rios Added Xcode 6.3.2 support; minor editing changes; fixes for Swift compiler errors.
#6 12123 Jaime Rios Added compatibility for Xcode 6.2; modified the menu layout; added additional screenshot; updated URL for Alcatraz Package Manager.
#5 11740 Jaime Rios Updated readme text with additional known issues; refactored p4 revert function; added perforce icon to alert message.
#4 11739 Jaime Rios Merging

//guest/matt_attaway/XcodePerforcePlugin/...

to //guest/jaime_rios/XcodePerforcePlugin/...
#3 11734 Jaime Rios Modified p4vc functions in Swift code to only show a dialog box if there is an error.
#2 11733 Jaime Rios Refactored code to have more functionality within Swift code; fixed perforce connection bugs.
#1 11694 Jaime Rios Initial add of XcodePerforcePlugin project to guest depot.