Skip to content

Commit

Permalink
Merge branch 'swift-3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelhanneken committed Jul 29, 2016
2 parents 2bbd754 + e40a2c6 commit 54a9a91
Show file tree
Hide file tree
Showing 20 changed files with 263 additions and 297 deletions.
5 changes: 5 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
line_length: 115
cyclomatic_complexity: 12

excluded:
- Carthage
10 changes: 9 additions & 1 deletion Icns Composer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
20FA7A861B14E9FE00E7B8E7 /* MainWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 20FA7A801B14E9FE00E7B8E7 /* MainWindow.xib */; };
20FA7A871B14E9FE00E7B8E7 /* MainWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20FA7A811B14E9FE00E7B8E7 /* MainWindowController.swift */; };
20FA7A8B1B14EA2500E7B8E7 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 20FA7A8A1B14EA2500E7B8E7 /* MainMenu.xib */; };
8E1825C51D49F45E001259F1 /* IconImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E1825C41D49F45E001259F1 /* IconImage.swift */; };
8E4E684F1BDAACEF004980A0 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 8E4E684E1BDAACEF004980A0 /* Assets.xcassets */; };
8E72A1011B583FBC00F6BCFB /* Sparkle.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8E72A1001B583FBC00F6BCFB /* Sparkle.framework */; };
8E72A1041B5843BE00F6BCFB /* Sparkle.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 8E72A1001B583FBC00F6BCFB /* Sparkle.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
Expand Down Expand Up @@ -42,6 +43,7 @@
20FA7A801B14E9FE00E7B8E7 /* MainWindow.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MainWindow.xib; sourceTree = "<group>"; };
20FA7A811B14E9FE00E7B8E7 /* MainWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MainWindowController.swift; sourceTree = "<group>"; };
20FA7A8A1B14EA2500E7B8E7 /* MainMenu.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MainMenu.xib; sourceTree = "<group>"; };
8E1825C41D49F45E001259F1 /* IconImage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IconImage.swift; sourceTree = "<group>"; };
8E4E684E1BDAACEF004980A0 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
8E72A1001B583FBC00F6BCFB /* Sparkle.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Sparkle.framework; path = "Icns Composer/Sparkle.framework"; sourceTree = "<group>"; };
8E7A659B1B5BB935003FC529 /* NSImageExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSImageExtensions.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -83,6 +85,7 @@
20FA7A7D1B14E9FE00E7B8E7 /* AppDelegate.swift */,
20FA7A811B14E9FE00E7B8E7 /* MainWindowController.swift */,
20FA7A7F1B14E9FE00E7B8E7 /* Iconset.swift */,
8E1825C41D49F45E001259F1 /* IconImage.swift */,
20FA7A7E1B14E9FE00E7B8E7 /* DragDropImageView.swift */,
8E7A659B1B5BB935003FC529 /* NSImageExtensions.swift */,
20FA7A891B14EA0400E7B8E7 /* UI */,
Expand Down Expand Up @@ -148,11 +151,12 @@
attributes = {
LastSwiftMigration = 0700;
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0700;
LastUpgradeCheck = 0800;
ORGANIZATIONNAME = "Raphael Hanneken";
TargetAttributes = {
20FA7A5C1B14E9D900E7B8E7 = {
CreatedOnToolsVersion = 6.3.2;
LastSwiftMigration = 0800;
};
};
};
Expand Down Expand Up @@ -209,6 +213,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
8E1825C51D49F45E001259F1 /* IconImage.swift in Sources */,
20FA7A851B14E9FE00E7B8E7 /* Iconset.swift in Sources */,
8E7A659C1B5BB935003FC529 /* NSImageExtensions.swift in Sources */,
20FA7A831B14E9FE00E7B8E7 /* AppDelegate.swift in Sources */,
Expand Down Expand Up @@ -315,6 +320,7 @@
OTHER_LDFLAGS = "-Wl,-rpath,@loader_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = io.raphaelhanneken.icnscomposer;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -332,6 +338,8 @@
OTHER_LDFLAGS = "-Wl,-rpath,@loader_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = io.raphaelhanneken.icnscomposer;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand Down
9 changes: 3 additions & 6 deletions Icns Composer/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,25 @@ class AppDelegate: NSObject, NSApplicationDelegate {
/// Handle the window via MainWindowController.
var mainWindowController: MainWindowController?


func applicationDidFinishLaunching(aNotification: NSNotification) {
func applicationDidFinishLaunching(_ aNotification: Notification) {
// Create a new WindowController instance.
let mainWindowController = MainWindowController()

// Display the associated window on screen.
mainWindowController.showWindow(self)

// Point the instance variable to the WindowController object.
self.mainWindowController = mainWindowController
}

// Reopen mainWindow, when the user clicks on the dock icon.
func applicationShouldHandleReopen(sender: NSApplication,
func applicationShouldHandleReopen(_ sender: NSApplication,
hasVisibleWindows flag: Bool) -> Bool {
if let mainWindowController = self.mainWindowController {
mainWindowController.showWindow(self)
}
return true
}

func applicationWillTerminate(aNotification: NSNotification) {
func applicationWillTerminate(_ aNotification: Notification) {
// Insert code here to tear down your application
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 13 additions & 15 deletions Icns Composer/DragDropImageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,52 +34,50 @@ class DragDropImageView: NSImageView, NSDraggingSource {
var mouseDownEvent: NSEvent?



override init(frame frameRect: NSRect) {
super.init(frame: frameRect)

// Assure editable is set to true, to enable drop capabilities.
self.editable = true
self.isEditable = true
}

required init?(coder: NSCoder) {
super.init(coder: coder)

// Assure editable is set to true, to enable drop capabilities.
self.editable = true
self.isEditable = true
}

override func drawRect(dirtyRect: NSRect) {
super.drawRect(dirtyRect)
override func draw(_ dirtyRect: NSRect) {
super.draw(dirtyRect)
}



// MARK: - NSDraggingSource

// Since we only want to copy/delete the current image we register ourselfes
// for .Copy and .Delete operations.
func draggingSession(session: NSDraggingSession, sourceOperationMaskForDraggingContext
context: NSDraggingContext) -> NSDragOperation {
return NSDragOperation.Copy.union(.Delete)
func draggingSession(_ session: NSDraggingSession,
sourceOperationMaskFor context: NSDraggingContext) -> NSDragOperation {
return NSDragOperation.copy.union(.delete)
}

// Clear the ImageView on delete operation; e.g. the image gets
// dropped on the trash can in the dock.
func draggingSession(session: NSDraggingSession, endedAtPoint screenPoint: NSPoint,
func draggingSession(_ session: NSDraggingSession, endedAt screenPoint: NSPoint,
operation: NSDragOperation) {
if operation == .Delete {
if operation == .delete {
self.image = nil
}
}

// Track mouse down events and safe the to the poperty.
override func mouseDown(theEvent: NSEvent) {
override func mouseDown(_ theEvent: NSEvent) {
self.mouseDownEvent = theEvent
}

// Track mouse dragged events to handle dragging sessions.
override func mouseDragged(theEvent: NSEvent) {
override func mouseDragged(_ theEvent: NSEvent) {
// Calculate the drag distance...
let mouseDown = self.mouseDownEvent!.locationInWindow
let dragPoint = theEvent.locationInWindow
Expand All @@ -101,7 +99,7 @@ class DragDropImageView: NSImageView, NSDraggingSource {
let draggingItem = NSDraggingItem(pasteboardWriter: image)
// Calculate the mouseDown location from the window's coordinate system to the
// ImageView's coordinate system, to use it as origin for the dragging frame.
let draggingFrameOrigin = convertPoint(mouseDown, fromView: nil)
let draggingFrameOrigin = convert(mouseDown, from: nil)
// Build the dragging frame and offset it by half the image size on each axis
// to center the mouse cursor within the dragging frame.
let draggingFrame = NSRect(origin: draggingFrameOrigin, size: img.size)
Expand All @@ -120,7 +118,7 @@ class DragDropImageView: NSImageView, NSDraggingSource {
}

// Begin actual dragging session. Woohow!
beginDraggingSessionWithItems([draggingItem], event: mouseDownEvent!, source: self)
beginDraggingSession(with: [draggingItem], event: mouseDownEvent!, source: self)
}
}
}
81 changes: 81 additions & 0 deletions Icns Composer/IconImage.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
//
// IconImage.swift
// Icns Composer
// https://github.com/raphaelhanneken/icnscomposer
//
// The MIT License (MIT)
//
// Copyright (c) 2015 Raphael Hanneken
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import Cocoa

/// Defines the scale of an image.
///
/// - at1x: A Scale of @1x
/// - at2x: A Scale of @2x
/// - at3x: A Scale of @3x
enum ImageScale: String {
case x1 = "@1x"
case x2 = "@2x"
}

/// Represents a single image of an iconset.
struct IconImage {
/// Holds the image it represents.
let image: NSImage?
/// The image scale.
let scale: ImageScale
/// The images size.
let size: NSSize

var filename: String {
switch scale {
case .x1:
return "icon_\(Int(size.width))x\(Int(size.height))\(scale.rawValue).png"
case .x2:
return "icon_\(Int(size.width / 2))x\(Int(size.height / 2))\(scale.rawValue).png"
}
}

/// Initialize a new iconset image.
init?(_ image: NSImage?, withSize size: NSSize, andScale scale: ImageScale) {
guard let image = image else {
return nil
}
// Resize the supplied image.
self.image = image.copyWithSize(size)
self.scale = scale
self.size = size
}

/// Write the iconset image to the supplied url.
///
/// - parameter url: The url where to save the image.
func writeToURL(_ url: URL) throws {
// Define the image name.
let imgURL = try url.appendingPathComponent(filename, isDirectory: false)

// Get the png representation of the image and write it to the supplied url.
if let png = image?.PNGRepresentation() {
try png.write(to: imgURL, options: .atomic)
}
}
}
Loading

0 comments on commit 54a9a91

Please sign in to comment.