Skip to content

Commit

Permalink
Linked repeat button to Core Data / Sorted sounds
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Di Meco committed Mar 22, 2016
1 parent 06448f5 commit d398132
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 52 deletions.
8 changes: 4 additions & 4 deletions QuickSound.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
92BE1D891C9C506B004F13BB /* PopoverViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92BE1D871C9C506B004F13BB /* PopoverViewController.swift */; };
92BE1D8A1C9C506B004F13BB /* PopoverViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 92BE1D881C9C506B004F13BB /* PopoverViewController.xib */; };
92BE1D911C9C6E8F004F13BB /* TransformerIsNotEmpty.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92BE1D901C9C6E8F004F13BB /* TransformerIsNotEmpty.swift */; };
E96D54091C9CAE6E006286EB /* TransformerFilePathToName.swift in Sources */ = {isa = PBXBuildFile; fileRef = E96D54081C9CAE6E006286EB /* TransformerFilePathToName.swift */; };
E942CF291CA1FBF8004FBCD2 /* Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = E942CF281CA1FBF8004FBCD2 /* Utils.swift */; };
E9FC49131C9DD93B001C35B3 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = E9FC49121C9DD93B001C35B3 /* MainMenu.xib */; };
/* End PBXBuildFile section */

Expand All @@ -36,7 +36,7 @@
92BE1D871C9C506B004F13BB /* PopoverViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PopoverViewController.swift; sourceTree = "<group>"; };
92BE1D881C9C506B004F13BB /* PopoverViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = PopoverViewController.xib; sourceTree = "<group>"; };
92BE1D901C9C6E8F004F13BB /* TransformerIsNotEmpty.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransformerIsNotEmpty.swift; sourceTree = "<group>"; };
E96D54081C9CAE6E006286EB /* TransformerFilePathToName.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransformerFilePathToName.swift; sourceTree = "<group>"; };
E942CF281CA1FBF8004FBCD2 /* Utils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Utils.swift; sourceTree = "<group>"; };
E9FC49121C9DD93B001C35B3 /* MainMenu.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MainMenu.xib; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -118,8 +118,8 @@
92BE1D921C9C6E91004F13BB /* Utils */ = {
isa = PBXGroup;
children = (
E942CF281CA1FBF8004FBCD2 /* Utils.swift */,
92BE1D901C9C6E8F004F13BB /* TransformerIsNotEmpty.swift */,
E96D54081C9CAE6E006286EB /* TransformerFilePathToName.swift */,
2228E2FC1CA19DF30041056A /* TransformerIsChecked.swift */,
);
name = Utils;
Expand Down Expand Up @@ -221,8 +221,8 @@
92BE1D911C9C6E8F004F13BB /* TransformerIsNotEmpty.swift in Sources */,
2228E3001CA1B0D00041056A /* Model.xcdatamodeld in Sources */,
2228E2FD1CA19DF30041056A /* TransformerIsChecked.swift in Sources */,
E96D54091C9CAE6E006286EB /* TransformerFilePathToName.swift in Sources */,
2228E3051CA1B1CE0041056A /* Sound+CoreDataProperties.swift in Sources */,
E942CF291CA1FBF8004FBCD2 /* Utils.swift in Sources */,
92BE1D891C9C506B004F13BB /* PopoverViewController.swift in Sources */,
2228E3061CA1B1CE0041056A /* Sound.swift in Sources */,
92BE1D781C9C4B9B004F13BB /* AppDelegate.swift in Sources */,
Expand Down
5 changes: 3 additions & 2 deletions QuickSound/Model.xcdatamodeld/Model.xcdatamodel/contents
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model userDefinedModelVersionIdentifier="" type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="9525" systemVersion="15D21" minimumToolsVersion="Xcode 7.0">
<model userDefinedModelVersionIdentifier="" type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="10171" systemVersion="15E65" minimumToolsVersion="Xcode 7.0">
<entity name="Sound" representedClassName=".Sound" syncable="YES">
<attribute name="filePath" attributeType="String" syncable="YES"/>
<attribute name="name" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="repeatEnabled" attributeType="Boolean" defaultValueString="NO" syncable="YES"/>
</entity>
<elements>
<element name="Sound" positionX="-63" positionY="-18" width="128" height="75"/>
<element name="Sound" positionX="-63" positionY="-18" width="128" height="90"/>
</elements>
</model>
7 changes: 6 additions & 1 deletion QuickSound/PopoverViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class PopoverViewController: NSViewController {

// Init array controller
self.soundsArrayController.managedObjectContext = AppDelegate.dataManager.managedObjectContext
self.soundsArrayController.sortDescriptors = [Sound.alphabeticalSortDescriptor()]
self.soundsArrayController.prepareContent()
}

Expand Down Expand Up @@ -82,8 +83,12 @@ class PopoverViewController: NSViewController {
}
}

@IBAction func removeSoundAction(sender: AnyObject) {
self.soundsArrayController.remove(sender)
AppDelegate.dataManager.saveContext()
}

@IBAction func autoRepeatClicked(sender: AnyObject) {

AppDelegate.dataManager.saveContext()
}

Expand Down
31 changes: 16 additions & 15 deletions QuickSound/PopoverViewController.xib
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customView id="at7-VE-jKz">
<rect key="frame" x="0.0" y="0.0" width="240" height="240"/>
<rect key="frame" x="0.0" y="0.0" width="275" height="275"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<scrollView borderType="none" autohidesScrollers="YES" horizontalLineScroll="35" horizontalPageScroll="10" verticalLineScroll="35" verticalPageScroll="10" hasHorizontalScroller="NO" usesPredominantAxisScrolling="NO" horizontalScrollElasticity="none" verticalScrollElasticity="allowed" translatesAutoresizingMaskIntoConstraints="NO" id="B2T-wf-e0a">
<rect key="frame" x="0.0" y="29" width="240" height="211"/>
<rect key="frame" x="0.0" y="29" width="275" height="246"/>
<clipView key="contentView" drawsBackground="NO" copiesOnScroll="NO" id="rVb-bq-ZVp">
<rect key="frame" x="0.0" y="0.0" width="240" height="211"/>
<rect key="frame" x="0.0" y="0.0" width="275" height="246"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" columnSelection="YES" columnResizing="NO" autosaveColumns="NO" rowHeight="33" rowSizeStyle="automatic" viewBased="YES" id="Mmb-31-dOi">
<rect key="frame" x="0.0" y="0.0" width="240" height="0.0"/>
<rect key="frame" x="0.0" y="0.0" width="275" height="246"/>
<autoresizingMask key="autoresizingMask"/>
<size key="intercellSpacing" width="3" height="2"/>
<color key="backgroundColor" white="1" alpha="0.0" colorSpace="deviceWhite"/>
<color key="gridColor" name="gridColor" catalog="System" colorSpace="catalog"/>
<tableColumns>
<tableColumn width="237" minWidth="40" maxWidth="1000" id="nyi-cG-OrX">
<tableColumn width="272" minWidth="40" maxWidth="1000" id="nyi-cG-OrX">
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
Expand All @@ -44,20 +44,20 @@
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
<prototypeCellViews>
<tableCellView id="33t-ly-sub">
<rect key="frame" x="1" y="1" width="237" height="33"/>
<rect key="frame" x="1" y="1" width="272" height="33"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="Blr-KK-Txb">
<rect key="frame" x="29" y="7" width="183" height="19"/>
<rect key="frame" x="29" y="7" width="218" height="19"/>
<textFieldCell key="cell" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" title="Sound name" id="zgU-2Z-lTN">
<font key="font" metaFont="systemLight" size="16"/>
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
<connections>
<binding destination="33t-ly-sub" name="value" keyPath="objectValue.filePath" id="s62-eV-wam">
<binding destination="33t-ly-sub" name="value" keyPath="objectValue.name" id="Ona-Qe-XOe">
<dictionary key="options">
<string key="NSValueTransformerName">TransformerFilePathToName</string>
<string key="NSNullPlaceholder">&lt;No name&gt;</string>
</dictionary>
</binding>
</connections>
Expand All @@ -71,13 +71,13 @@
</textFieldCell>
</textField>
<button horizontalHuggingPriority="252" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="3UO-en-eQC">
<rect key="frame" x="218" y="9" width="11" height="16"/>
<rect key="frame" x="253" y="9" width="11" height="16"/>
<buttonCell key="cell" type="square" bezelStyle="shadowlessSquare" image="NSRefreshTemplate" imagePosition="overlaps" alignment="center" state="on" imageScaling="proportionallyDown" inset="2" id="m00-4s-AuG">
<behavior key="behavior" pushIn="YES" changeContents="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="autoRepeatClicked:" target="-2" id="RMF-EF-W7V"/>
<action selector="autoRepeatClicked:" target="-2" id="LXi-yl-sxd"/>
<binding destination="33t-ly-sub" name="value" keyPath="objectValue.repeatEnabled" id="VxC-2G-ACn"/>
</connections>
</button>
Expand All @@ -103,6 +103,7 @@
</tableColumns>
<connections>
<action trigger="doubleAction" selector="tableViewRowDoubleClicked:" target="-2" id="frw-0i-Hfw"/>
<outlet property="delegate" destination="-2" id="xoL-JS-aWR"/>
</connections>
</tableView>
</subviews>
Expand All @@ -118,7 +119,7 @@
</scroller>
</scrollView>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="MG5-Tr-YmP">
<rect key="frame" x="71" y="119" width="99" height="24"/>
<rect key="frame" x="88" y="136" width="99" height="24"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Aucun son" id="Eop-gp-PbZ">
<font key="font" metaFont="system" size="20"/>
<color key="textColor" name="headerColor" catalog="System" colorSpace="catalog"/>
Expand All @@ -133,7 +134,7 @@
</connections>
</textField>
<box verticalHuggingPriority="750" title="Box" boxType="separator" titlePosition="noTitle" translatesAutoresizingMaskIntoConstraints="NO" id="ch7-h8-dHD">
<rect key="frame" x="0.0" y="26" width="240" height="5"/>
<rect key="frame" x="0.0" y="26" width="275" height="5"/>
<color key="borderColor" white="0.0" alpha="0.41999999999999998" colorSpace="calibratedWhite"/>
<color key="fillColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<font key="titleFont" metaFont="system"/>
Expand All @@ -155,7 +156,7 @@
</connections>
</button>
<popUpButton toolTip="More..." translatesAutoresizingMaskIntoConstraints="NO" id="7oC-em-Yi8">
<rect key="frame" x="194" y="4" width="38" height="21"/>
<rect key="frame" x="229" y="4" width="38" height="21"/>
<constraints>
<constraint firstAttribute="height" constant="21" id="dWb-lU-mQc"/>
<constraint firstAttribute="width" constant="38" id="fKb-dc-8He"/>
Expand Down Expand Up @@ -197,7 +198,7 @@ CA
</string>
</buttonCell>
<connections>
<action selector="remove:" target="XaV-0I-8yP" id="Ma8-fT-DC9"/>
<action selector="removeSoundAction:" target="-2" id="dvV-rx-3wU"/>
<binding destination="XaV-0I-8yP" name="enabled" keyPath="canRemove" id="FNL-Yw-oVH"/>
</connections>
</button>
Expand Down
1 change: 1 addition & 0 deletions QuickSound/Sound+CoreDataProperties.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import CoreData
extension Sound {

@NSManaged var filePath: String?
@NSManaged var name: String?
@NSManaged var repeatEnabled: NSNumber?

}
7 changes: 7 additions & 0 deletions QuickSound/Sound.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,15 @@ class Sound: NSManagedObject {
if let entityDescription = NSEntityDescription.entityForName("Sound", inManagedObjectContext: moc) {
object = Sound(entity: entityDescription, insertIntoManagedObjectContext: moc)
object?.filePath = filepath
object?.name = Utils.filePathToFileNameWithoutExtension(filepath)
}
return object
}


// MARK: - Sort descriptors

static func alphabeticalSortDescriptor() -> NSSortDescriptor {
return NSSortDescriptor(key: "name", ascending: true)
}
}
30 changes: 0 additions & 30 deletions QuickSound/TransformerFilePathToName.swift

This file was deleted.

18 changes: 18 additions & 0 deletions QuickSound/Utils.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// Utils.swift
// QuickSound
//
// Created by Thomas Di Meco on 22/03/2016.
// Copyright © 2016 Thomas Di Meco. All rights reserved.
//

import Foundation


struct Utils {

static func filePathToFileNameWithoutExtension(filePath: String) -> String? {
guard let lastPathComponent = NSURL(string: filePath)?.lastPathComponent else { return nil }
return NSString(string: lastPathComponent).stringByDeletingPathExtension
}
}

0 comments on commit d398132

Please sign in to comment.