Skip to content
This repository has been archived by the owner on Nov 3, 2020. It is now read-only.

Commit

Permalink
Merge pull request #286 from CocoaPods/repo_update_simple
Browse files Browse the repository at this point in the history
Add support for 'auto-update specs repo'
  • Loading branch information
orta committed Apr 19, 2016
2 parents dba5468 + 5d8c43c commit e9e1f73
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app/CocoaPods/Base.lproj/CPHomeWindowController.xib
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<window title="Welcome to CocoaPods" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" showsToolbarButton="NO" visibleAtLaunch="NO" animationBehavior="default" id="F0z-JX-Cv5" customClass="CPThickDecorationsWindow" customModule="CocoaPods" customModuleProvider="target">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" texturedBackground="YES" unifiedTitleAndToolbar="YES" fullSizeContentView="YES"/>
<rect key="contentRect" x="196" y="240" width="721" height="369"/>
<rect key="screenRect" x="0.0" y="0.0" width="1280" height="800"/>
<rect key="screenRect" x="0.0" y="0.0" width="2560" height="1440"/>
<view key="contentView" id="se5-gp-TjO">
<rect key="frame" x="0.0" y="0.0" width="721" height="369"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
Expand Down
6 changes: 6 additions & 0 deletions app/CocoaPods/Base.lproj/MainMenu.xib
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,12 @@
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="Lmb-6g-oqt"/>
<menuItem title="Auto-Update Specs Repos" id="bei-ab-BDq">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="toggleUpdateSpecsRepo:" target="-1" id="NBL-g1-bOd"/>
</connections>
</menuItem>
</items>
</menu>
</menuItem>
Expand Down
24 changes: 18 additions & 6 deletions app/CocoaPods/CPInstallAction.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
import Cocoa

enum InstallActionType {
case Install(verbose: Bool)
case Update(verbose: Bool)
case Install(options: InstallOptions)
case Update(options: InstallOptions)
}

struct InstallOptions {
let verbose: Bool
let repoUpdate: Bool

var commandOptions : String {
var string = ""
if verbose { string += "--verbose " }
if repoUpdate { string += "--repo-update " }
return string
}
}

class CPInstallAction: NSObject, CPCLITaskDelegate {
Expand All @@ -18,10 +30,10 @@ class CPInstallAction: NSObject, CPCLITaskDelegate {

func performAction(type: InstallActionType) {
switch type {
case .Install(let verbose):
executeTaskWithCommand(verbose ? "install --verbose" : "install")
case .Update(let verbose):
executeTaskWithCommand(verbose ? "update --verbose" : "update")
case .Install(let options):
executeTaskWithCommand("install \(options.commandOptions)")
case .Update(let options):
executeTaskWithCommand("update \(options.commandOptions)")
}
}

Expand Down
4 changes: 2 additions & 2 deletions app/CocoaPods/CPMenuVisiblityDirector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ class CPMenuVisiblityDirector: NSObject {
notificationCenter.addObserver(self, selector: #selector(windowsChanged(_:)), name: NSWindowDidBecomeKeyNotification, object: nil)
}

/// Set hidden on the menus when we don't need to show the submenus
/// Set hidden on the menus when we don't need to enable the submenus
func windowsChanged(notification: NSNotification) {
guard let window = notification.object as? NSWindow else { return print("Notification does not have a window") }
let docs = NSDocumentController.sharedDocumentController()
let windowHasDocument = docs.documentForWindow(window) != nil

for menu in podfileEditorMenuItems {
menu.enabled = !windowHasDocument
menu.enabled = windowHasDocument
}
}
}
31 changes: 27 additions & 4 deletions app/CocoaPods/CPPodfileViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,29 @@ class CPPodfileViewController: NSViewController, NSTabViewDelegate {

@IBAction func install(obj: AnyObject) {
userProject.saveDocument(self)
installAction.performAction(.Install(verbose: false))
let options = InstallOptions(verbose: false, repoUpdate: shouldUpdateSpecsRepo())
installAction.performAction(.Install(options: options))
showConsoleTab(self)
}

@IBAction func installVerbose(obj: AnyObject) {
userProject.saveDocument(self)
installAction.performAction(.Install(verbose: true))
let options = InstallOptions(verbose: true, repoUpdate: shouldUpdateSpecsRepo())
installAction.performAction(.Install(options: options))
showConsoleTab(self)
}

@IBAction func installUpdate(obj: AnyObject) {
userProject.saveDocument(self)
installAction.performAction(.Update(verbose: false))
let options = InstallOptions(verbose: false, repoUpdate: shouldUpdateSpecsRepo())
installAction.performAction(.Update(options: options))
showConsoleTab(self)
}

@IBAction func installUpdateVerbose(obj: AnyObject) {
userProject.saveDocument(self)
installAction.performAction(.Update(verbose: true))
let options = InstallOptions(verbose: true, repoUpdate: shouldUpdateSpecsRepo())
installAction.performAction(.Update(options: options))
showConsoleTab(self)
}

Expand All @@ -93,6 +97,25 @@ class CPPodfileViewController: NSViewController, NSTabViewDelegate {
NSMenu.popUpContextMenu(installMenu, withEvent: event, forView: button)
}

let UpdateSpecsKey = "CPUpdateSpecsRepos"
func shouldUpdateSpecsRepo() -> Bool {
return NSUserDefaults.standardUserDefaults().boolForKey(UpdateSpecsKey)
}

@IBAction func toggleUpdateSpecsRepo(obj: AnyObject) {
let defaults = NSUserDefaults.standardUserDefaults()
let current = defaults.boolForKey(UpdateSpecsKey)
defaults.setBool(!current, forKey: UpdateSpecsKey)
defaults.synchronize()
}

override func validateMenuItem(menuItem: NSMenuItem) -> Bool {
if menuItem.action == #selector(toggleUpdateSpecsRepo) {
let state = shouldUpdateSpecsRepo() ? 1 : 0
menuItem.state = state
}
return true
}

@IBAction func showEditorTab(sender: AnyObject) {
tabController.selectedTabViewItemIndex = 0
Expand Down
7 changes: 7 additions & 0 deletions app/CocoaPods/Podfile.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,13 @@
<action selector="installUpdateVerbose:" target="5gI-5U-AMq" id="dCA-77-Jc3"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="MfJ-p0-dcA"/>
<menuItem title="Auto-Update Specs Repos" id="7VJ-3T-Bex">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="toggleUpdateSpecsRepo:" target="5gI-5U-AMq" id="shm-m1-s3m"/>
</connections>
</menuItem>
</items>
</menu>
<userDefaultsController representsSharedInstance="YES" id="LcC-8e-1XM"/>
Expand Down

0 comments on commit e9e1f73

Please sign in to comment.