Skip to content

Commit

Permalink
Added short keys
Browse files Browse the repository at this point in the history
  • Loading branch information
Knut Inge Grosland committed Jun 14, 2015
1 parent 3870b68 commit aa6179e
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 43 deletions.
8 changes: 4 additions & 4 deletions AppReviews/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -750,18 +750,18 @@ If you like App Reviews, please consider making a donation. Feature requests, is
<popUpButton key="view" verticalHuggingPriority="750" id="86s-19-3Op">
<rect key="frame" x="0.0" y="14" width="38" height="28"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<popUpButtonCell key="cell" type="roundTextured" bezelStyle="texturedRounded" alignment="center" lineBreakMode="truncatingTail" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" pullsDown="YES" arrowPosition="arrowAtCenter" selectedItem="cFs-J6-JGM" id="QDp-ep-0Ia">
<popUpButtonCell key="cell" type="roundTextured" bezelStyle="texturedRounded" alignment="center" lineBreakMode="truncatingTail" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" pullsDown="YES" arrowPosition="arrowAtCenter" selectedItem="3if-UU-Y8u" id="QDp-ep-0Ia">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="menu"/>
<menu key="menu" id="hQD-RF-WYJ">
<items>
<menuItem state="on" image="NSActionTemplate" hidden="YES" id="n7W-XG-F69"/>
<menuItem title="Open in Appstore ..." id="cFs-J6-JGM">
<menuItem title="Open in Appstore ..." keyEquivalent="I" id="cFs-J6-JGM">
<connections>
<action selector="openInAppstore:" target="E8W-Gv-fjB" id="UXn-0T-f8W"/>
</connections>
</menuItem>
<menuItem title="Export reviews..." id="f1n-ML-MFv">
<menuItem title="Export reviews..." keyEquivalent="e" id="f1n-ML-MFv">
<connections>
<action selector="exportReviewsClicked:" target="E8W-Gv-fjB" id="Jup-9X-7qX"/>
</connections>
Expand All @@ -773,7 +773,7 @@ If you like App Reviews, please consider making a donation. Feature requests, is
<action selector="automaticUpdateDidChangeState:" target="E8W-Gv-fjB" id="4T1-HM-vPR"/>
</connections>
</menuItem>
<menuItem title="Refresh" id="3if-UU-Y8u">
<menuItem title="Refresh" keyEquivalent="r" id="3if-UU-Y8u">
<connections>
<action selector="refreshApplication:" target="E8W-Gv-fjB" id="FTS-dK-P88"/>
</connections>
Expand Down
22 changes: 0 additions & 22 deletions AppReviews/ReviewViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,28 +50,6 @@ class ReviewViewController: NSViewController {
NSAnimationContext.endGrouping()
}
}

// Register Keyboard shortcuts.
NSEvent.addLocalMonitorForEventsMatchingMask(NSEventMaskFromType(.KeyDown), handler: { [weak self] (event: NSEvent!) -> NSEvent! in

let cChar : UInt16 = 8
let sChar : UInt16 = 1
let fChar : UInt16 = 3
let iChar : UInt16 = 34

// Cmd-C -> Copy current selected review
if event.modifierFlags & NSEventModifierFlags.CommandKeyMask != nil && cChar == event.keyCode{
self?.copyToClipBoardSelectedReview(nil)
} else if event.modifierFlags & NSEventModifierFlags.CommandKeyMask != nil && sChar == event.keyCode{
self?.saveSelectedReview(nil)
} else if event.modifierFlags & NSEventModifierFlags.CommandKeyMask != nil && fChar == event.keyCode{
self?.shareSelectedReview(nil)
} else if event.modifierFlags & NSEventModifierFlags.CommandKeyMask != nil && iChar == event.keyCode{
self?.openInItunesSelectedReview(nil)
}

return event
})
}

}
Expand Down
68 changes: 61 additions & 7 deletions AppReviews/ReviewWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import AppKit

class ReviewWindowController: NSWindowController {

var reviewController : ReviewViewController?
var managedObjectContext: NSManagedObjectContext!
@IBOutlet weak var automaticUpdate: NSMenuItem?
@IBOutlet weak var shareButton: NSButton?
Expand All @@ -20,8 +20,8 @@ class ReviewWindowController: NSWindowController {
window?.title = application.trackName
automaticUpdate?.state = application.settings.automaticUpdate ? NSOnState: NSOffState

if let reviewController = contentViewController as? ReviewSplitViewController {
reviewController.application = application
if let reviewSplitViewController = contentViewController as? ReviewSplitViewController {
reviewSplitViewController.application = application
}
}
}
Expand Down Expand Up @@ -59,19 +59,73 @@ class ReviewWindowController: NSWindowController {
let frame = self.window!.frame
self.window?.setFrame(NSRect(x: frame.origin.x, y: frame.origin.y, width: 800, height: 700), display: true)

if let reviewController = contentViewController as? ReviewSplitViewController {
reviewController.application = application
if let reviewSplitViewController = contentViewController as? ReviewSplitViewController {
reviewSplitViewController.application = application
reviewController = reviewSplitViewController.reviewViewController
}

self.shareButton!.sendActionOn(Int(NSEventMask.LeftMouseDownMask.rawValue))

// Register Keyboard shortcuts.
NSEvent.addLocalMonitorForEventsMatchingMask(NSEventMaskFromType(.KeyDown), handler: { [weak self] (event: NSEvent!) -> NSEvent! in

let rChar: UInt16 = 15
let iChar: UInt16 = 34
let cChar: UInt16 = 8
let sChar: UInt16 = 1
let fChar: UInt16 = 3
let aChar: UInt16 = 0

if event.modifierFlags & NSEventModifierFlags.CommandKeyMask != nil {
switch event.keyCode {
case rChar:
self?.refreshApplication(nil)
case aChar:
self?.openApplications(nil)
case iChar:
if (event.modifierFlags & NSEventModifierFlags.ShiftKeyMask == nil) {
self?.reviewController?.openInItunesSelectedReview(nil)
}
case cChar:
self?.reviewController?.copyToClipBoardSelectedReview(nil)
case sChar:
self?.reviewController?.saveSelectedReview(nil)
case fChar:
self?.reviewController?.shareSelectedReview(nil)
case 18, 19 , 20, 21, 22, 23, 24, 25:
let key = Int(event.keyCode) - 18
let appdelegate = NSApplication.sharedApplication().delegate as! AppDelegate
let menuItems = appdelegate.statusMenuController.statusItem.menu?.itemArray
if menuItems?.count > key {
if let menuItem = menuItems![key] as? NSMenuItem {
if let application = menuItem.representedObject as? Application {
ReviewWindowController.show(application.objectID)
}
}
}
default:
break
}
}

return event
})

}
}

// MARK: - Actions

extension ReviewWindowController {

@IBAction func refreshApplication(sender: AnyObject) {
func openApplications(sender: AnyObject?) {
let appdelegate = NSApplication.sharedApplication().delegate as! AppDelegate
let windowController = appdelegate.applicationWindowController
windowController.showWindow(self)
NSApp.activateIgnoringOtherApps(true)
}

@IBAction func refreshApplication(sender: AnyObject?) {
if let application = application {
ReviewManager.appUpdater().fetchReviewsForApplication(application.objectID)
}
Expand Down Expand Up @@ -103,7 +157,7 @@ extension ReviewWindowController {
}
}

@IBAction func exportReviewsClicked(sender: AnyObject) {
@IBAction func exportReviewsClicked(sender: AnyObject?) {
if let application = application {

if let reviewController = contentViewController as? ReviewSplitViewController {
Expand Down
23 changes: 13 additions & 10 deletions AppReviews/StatusMenuController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class StatusMenuController: NSObject {

var newReviews = false

var idx = 1
for application in applications {

// application.addObserver(self, forKeyPath: "settings.newReviews", options: .New, context: &kvoContext)
Expand All @@ -65,23 +66,25 @@ class StatusMenuController: NSObject {
newReviews = true
title = title + " (" + String(application.settings.newReviews.integerValue) + ")"
}

var menuItem = NSMenuItem(title: title, action: Selector("openReviewsForApp:"), keyEquivalent: "")

let shortKey = idx < 10 ? String(idx) : ""
var menuItem = NSMenuItem(title: title, action: Selector("openReviewsForApp:"), keyEquivalent: shortKey)

menuItem.representedObject = application
menuItem.target = self
menu.addItem(menuItem)
idx++
}

if (applications.count > 0) {
menu.addItem(NSMenuItem.separatorItem())
}

var menuItemApplications = NSMenuItem(title: NSLocalizedString("Add / Remove Applications", comment: "statusbar.menu.applications"), action: Selector("openApplications:"), keyEquivalent: "")
var menuItemApplications = NSMenuItem(title: NSLocalizedString("Add / Remove Applications", comment: "statusbar.menu.applications"), action: Selector("openApplications:"), keyEquivalent: "a")
var menuItemAbout = NSMenuItem(title: NSLocalizedString("About Appstore Reviews", comment: "statusbar.menu.about"), action: Selector("openAbout:"), keyEquivalent: "")
var menuItemProvidFeedback = NSMenuItem(title: NSLocalizedString("Provide Feedback...", comment: "statusbar.menu.feedback"), action: Selector("openFeedback:"), keyEquivalent: "")

var menuItemQuit = NSMenuItem(title: NSLocalizedString("Quit", comment: "statusbar.menu.quit"), action: Selector("quit:"), keyEquivalent: "")
var menuItemQuit = NSMenuItem(title: NSLocalizedString("Quit", comment: "statusbar.menu.quit"), action: Selector("quit:"), keyEquivalent: "q")

var menuItemLaunchAtStartup = NSMenuItem(title: NSLocalizedString("Launch at startup", comment: "statusbar.menu.startup"), action: Selector("launchAtStartUpToggle:"), keyEquivalent: "")
menuItemLaunchAtStartup.state = NSApplication.shouldLaunchAtStartup() ? NSOnState : NSOffState
Expand Down Expand Up @@ -116,40 +119,40 @@ class StatusMenuController: NSObject {

extension StatusMenuController {

func openReviewsForApp(sender: AnyObject) {
func openReviewsForApp(sender: AnyObject?) {
if let menuItem = sender as? NSMenuItem {
if let application = menuItem.representedObject as? Application {
ReviewWindowController.show(application.objectID)
}
}
}

func openAbout(sender: AnyObject) {
func openAbout(sender: AnyObject?) {
let appdelegate = NSApplication.sharedApplication().delegate as! AppDelegate
let windowController = appdelegate.aboutWindowController
windowController.showWindow(self)
NSApp.activateIgnoringOtherApps(true)
}

func openApplications(sender: AnyObject) {
func openApplications(sender: AnyObject?) {
let appdelegate = NSApplication.sharedApplication().delegate as! AppDelegate
let windowController = appdelegate.applicationWindowController
windowController.showWindow(self)
NSApp.activateIgnoringOtherApps(true)
}

func openFeedback(sender: AnyObject) {
func openFeedback(sender: AnyObject?) {
NSWorkspace.sharedWorkspace().openURL(NSURL(string: "http://knutigro.github.io/apps/app-reviews/#Feedback")!)
}

func launchAtStartUpToggle(sender : AnyObject) {
func launchAtStartUpToggle(sender : AnyObject?) {
if let menu = sender as? NSMenuItem {
NSApplication.toggleShouldLaunchAtStartup()
menu.state = NSApplication.shouldLaunchAtStartup() ? NSOnState : NSOffState
}
}

func quit(sender: AnyObject) {
func quit(sender: AnyObject?) {
NSApplication.sharedApplication().terminate(sender)
}
}
Expand Down

0 comments on commit aa6179e

Please sign in to comment.