Skip to content
This repository has been archived by the owner on Feb 2, 2022. It is now read-only.

Commit

Permalink
Merge pull request #5 from nodes-ios/RealmSupport
Browse files Browse the repository at this point in the history
Realm support
  • Loading branch information
kasperwelner committed Mar 29, 2016
2 parents b917864 + ec686ef commit 1d794e9
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 30 deletions.
12 changes: 12 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[submodule "Carthage/Checkouts/CommandLine"]
path = Carthage/Checkouts/CommandLine
url = https://github.com/jatoben/CommandLine.git
[submodule "Carthage/Checkouts/MASShortcut"]
path = Carthage/Checkouts/MASShortcut
url = https://github.com/shpakovski/MASShortcut.git
[submodule "Carthage/Checkouts/model-generator"]
path = Carthage/Checkouts/model-generator
url = https://github.com/nodes-ios/model-generator.git
[submodule "Carthage/Checkouts/ZipArchive"]
path = Carthage/Checkouts/ZipArchive
url = https://github.com/ZipArchive/ZipArchive.git
2 changes: 1 addition & 1 deletion Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
github "jatoben/CommandLine" "v2.0.0"
github "shpakovski/MASShortcut" "2.3.3"
github "ZipArchive/ZipArchive" "e9313bf5c14a74518ca995824a2cf2b7e512858c"
github "ZipArchive/ZipArchive" "8c51a6838fe12b53482b6b2e744af6a655d96d5b"
github "nodes-ios/model-generator" "0.6.1"
1 change: 1 addition & 0 deletions Carthage/Checkouts/CommandLine
Submodule CommandLine added at 96df5d
1 change: 1 addition & 0 deletions Carthage/Checkouts/MASShortcut
Submodule MASShortcut added at d00631
1 change: 1 addition & 0 deletions Carthage/Checkouts/ZipArchive
Submodule ZipArchive added at 8c51a6
1 change: 1 addition & 0 deletions Carthage/Checkouts/model-generator
Submodule model-generator added at 25756d
2 changes: 1 addition & 1 deletion Model Boiler/Classes/Helpers/KeyCommandManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct KeyCommandManager {
static func updateKeyCommand(command: String, modifierMask: NSEventModifierFlags) throws {
let bundle = NSBundle.mainBundle()

guard let appServices = bundle.infoDictionary?["NSServices"]?[0] as? [String: AnyObject],
guard let appServices = bundle.infoDictionary?["NSServices"]?.firstItem as? [String: AnyObject],
bundleIdentifier = bundle.bundleIdentifier,
serviceName = appServices["NSMenuItem"]?["default"] as? String,
methodName = appServices["NSMessage"] as? String else {
Expand Down
1 change: 1 addition & 0 deletions Model Boiler/Classes/Helpers/SettingsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ enum Setting: String {
case SoundEnabled = "SoundEnabled"
case NoCamelCaseConversion = "NoCamelCaseConversion"
case UseNativeDictionaries = "UseNativeDictionaries"
case OnlyCreateInitializer = "OnlyCreateInitializer"
}

struct SettingsManager {
Expand Down
2 changes: 1 addition & 1 deletion Model Boiler/Classes/Helpers/UpdateManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class UpdateManager: NSObject {
public func start() {
// Schedule update timer for every hour
checkForUpdates()
updateTimer = NSTimer.scheduledTimerWithTimeInterval(3600, target: self, selector: "autoUpdateTimerFired", userInfo: nil, repeats: true)
updateTimer = NSTimer.scheduledTimerWithTimeInterval(3600, target: self, selector: #selector(UpdateManager.autoUpdateTimerFired), userInfo: nil, repeats: true)
}

public static func stop() {
Expand Down
3 changes: 2 additions & 1 deletion Model Boiler/Classes/Service/Service.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ struct Service {
generatorSettings.moduleName = nil
generatorSettings.noConvertCamelCase = SettingsManager.isSettingEnabled(.NoCamelCaseConversion)
generatorSettings.useNativeDictionaries = SettingsManager.isSettingEnabled(.UseNativeDictionaries)

generatorSettings.onlyCreateInitializer = SettingsManager.isSettingEnabled(.OnlyCreateInitializer)

do {
// Try to generate the code
let code = try ModelGenerator.modelCodeFromSourceCode(source, withSettings: generatorSettings)
Expand Down
62 changes: 41 additions & 21 deletions Model Boiler/Classes/User Interface/StatusBarController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ enum MenuItem: Int {
case Generate
case SoundEnabled
case CamelCaseConversion
case OnlyCreateInitializer
case Preferences
case Restart
case Quit
}

class StatusBarController: NSObject, NSMenuDelegate {

let statusMenu = NSMenu()
let statusMenu = NSMenu()
let optionsMenu = NSMenu()
let statusItem = NSStatusBar.systemStatusBar().statusItemWithLength(NSVariableStatusItemLength)

var preferencesController: PreferencesController?
Expand All @@ -47,47 +49,56 @@ class StatusBarController: NSObject, NSMenuDelegate {
let build = infoDict["CFBundleVersion"]!
let name = infoDict["CFBundleName"]!

let versionItem = NSMenuItem(title: "\(name) v\(version) (\(build))", action: "", keyEquivalent: "")
let versionItem = NSMenuItem(title: "\(name) v\(version) (\(build))", action: nil, keyEquivalent: "")
versionItem.tag = MenuItem.Title.rawValue
statusMenu.addItem(versionItem)
}

// Menu item for generation
let generateItem = NSMenuItem(title: "Current hotkey: ", action: "", keyEquivalent: "")
let generateItem = NSMenuItem(title: "Current hotkey: ", action: nil, keyEquivalent: "")
generateItem.tag = MenuItem.Generate.rawValue
statusMenu.addItem(generateItem)

// Separator
statusMenu.addItem(NSMenuItem.separatorItemWithTag(MenuItem.Separator.rawValue))

// Add section title
statusMenu.addItem(NSMenuItem(title: "Options:", action: "", keyEquivalent: ""))

// Add options menu
let optionsItem = NSMenuItem( title: "Options", action: nil, keyEquivalent: "")
statusMenu.addItem(optionsItem)
statusMenu.setSubmenu(optionsMenu, forItem: optionsItem)

// Camel case conversion item
let camelCaseItem = NSMenuItem(title: "camelCase -> underscore_notation", action: "toggleCamelCaseConversion", keyEquivalent: "")
let camelCaseItem = NSMenuItem(title: "Map camelCase -> underscore_notation", action: #selector(toggleCamelCaseConversion), keyEquivalent: "")
camelCaseItem.state = SettingsManager.isSettingEnabled(.NoCamelCaseConversion) ? NSOffState : NSOnState
camelCaseItem.target = self
camelCaseItem.tag = MenuItem.CamelCaseConversion.rawValue
statusMenu.addItem(camelCaseItem)

// Separator
statusMenu.addItem(NSMenuItem.separatorItemWithTag(MenuItem.Separator.rawValue))
optionsMenu.addItem(camelCaseItem)

// Sound enabled item
let soundItem = NSMenuItem(title: "Audio enabled", action: "toggleSoundEnabled", keyEquivalent: "")
let soundItem = NSMenuItem(title: "Audio enabled", action: #selector(StatusBarController.toggleSoundEnabled), keyEquivalent: "")
soundItem.state = SettingsManager.isSettingEnabled(.SoundEnabled) ? NSOnState : NSOffState
soundItem.target = self
soundItem.tag = MenuItem.SoundEnabled.rawValue
statusMenu.addItem(soundItem)

optionsMenu.addItem(soundItem)

// Generate Initializer only
let initializerOnlyItem = NSMenuItem(title: "Only generate initializer (useful for use with Realm/CoreData)", action: #selector(toggleOnlyCreateInitializers), keyEquivalent: "")
initializerOnlyItem.state = SettingsManager.isSettingEnabled(.OnlyCreateInitializer) ? NSOnState : NSOffState
initializerOnlyItem.target = self
initializerOnlyItem.tag = MenuItem.OnlyCreateInitializer.rawValue
optionsMenu.addItem(initializerOnlyItem)

// Separator
statusMenu.addItem(NSMenuItem.separatorItemWithTag(MenuItem.Separator.rawValue))

// Preferences item
let preferencesItem = NSMenuItem(title: "Settings", action: "showSettings", keyEquivalent: "")
let preferencesItem = NSMenuItem(title: "Settings", action: #selector(StatusBarController.showSettings), keyEquivalent: "")
preferencesItem.target = self
preferencesItem.tag = MenuItem.Preferences.rawValue
statusMenu.addItem(preferencesItem)

// Check for updates item
let updateItem = NSMenuItem(title: "Check for updates", action: "updatePressed", keyEquivalent: "")
let updateItem = NSMenuItem(title: "Check for updates", action: #selector(StatusBarController.updatePressed), keyEquivalent: "")
updateItem.target = self
updateItem.tag = MenuItem.Update.rawValue
statusMenu.addItem(updateItem)
Expand All @@ -96,13 +107,13 @@ class StatusBarController: NSObject, NSMenuDelegate {
statusMenu.addItem(NSMenuItem.separatorItemWithTag(MenuItem.Separator.rawValue))

// Restart item
let restartItem = NSMenuItem(title: "Restart", action: "restartPressed", keyEquivalent: "")
let restartItem = NSMenuItem(title: "Restart", action: #selector(StatusBarController.restartPressed), keyEquivalent: "")
restartItem.tag = MenuItem.Restart.rawValue
restartItem.target = self
statusMenu.addItem(restartItem)

// Quit item
let quitItem = NSMenuItem(title: "Quit", action: "quitPressed", keyEquivalent: "")
let quitItem = NSMenuItem(title: "Quit", action: #selector(StatusBarController.quitPressed), keyEquivalent: "")
quitItem.tag = MenuItem.Quit.rawValue
quitItem.target = self
statusMenu.addItem(quitItem)
Expand Down Expand Up @@ -140,7 +151,7 @@ class StatusBarController: NSObject, NSMenuDelegate {
let newState = !SettingsManager.isSettingEnabled(.SoundEnabled)
SettingsManager.setSetting(.SoundEnabled, enabled: newState)

if let soundItem = statusMenu.itemWithTag(MenuItem.SoundEnabled.rawValue) {
if let soundItem = optionsMenu.itemWithTag(MenuItem.SoundEnabled.rawValue) {
soundItem.state = newState == true ? NSOnState : NSOffState
}
}
Expand All @@ -149,11 +160,20 @@ class StatusBarController: NSObject, NSMenuDelegate {
let newState = !SettingsManager.isSettingEnabled(.NoCamelCaseConversion)
SettingsManager.setSetting(.NoCamelCaseConversion, enabled: newState)

if let camelCaseItem = statusMenu.itemWithTag(MenuItem.CamelCaseConversion.rawValue) {
if let camelCaseItem = optionsMenu.itemWithTag(MenuItem.CamelCaseConversion.rawValue) {
camelCaseItem.state = newState == true ? NSOffState : NSOnState
}
}


func toggleOnlyCreateInitializers() {
let newState = !SettingsManager.isSettingEnabled(.OnlyCreateInitializer)
SettingsManager.setSetting(.OnlyCreateInitializer, enabled: newState)

if let camelCaseItem = optionsMenu.itemWithTag(MenuItem.OnlyCreateInitializer.rawValue) {
camelCaseItem.state = newState == true ? NSOffState : NSOnState
}
}

func showSettings() {
preferencesController = PreferencesController.newFromNib()
preferencesController?.window?.makeKeyFrontAndCenter(self)
Expand Down
6 changes: 3 additions & 3 deletions Model Boiler/Resources/Preferences.xib
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="9531" systemVersion="15C50" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="10116" systemVersion="15D21" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="9531"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="10116"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="PreferencesController" customModule="Model_Boiler" customModuleProvider="target">
Expand All @@ -18,7 +18,7 @@
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="163" y="199" width="369" height="129"/>
<rect key="screenRect" x="0.0" y="0.0" width="1920" height="1177"/>
<rect key="screenRect" x="0.0" y="0.0" width="2560" height="1417"/>
<view key="contentView" id="2Sk-wY-H3O">
<rect key="frame" x="0.0" y="0.0" width="369" height="129"/>
<autoresizingMask key="autoresizingMask"/>
Expand Down
4 changes: 2 additions & 2 deletions Model Boiler/Supporting Files/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>2.1.2</string>
<string>2.1.3</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>12</string>
<string>13</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key>
Expand Down

0 comments on commit 1d794e9

Please sign in to comment.