Skip to content

Commit

Permalink
Merge pull request #4 from thierryH91200/master
Browse files Browse the repository at this point in the history
update to swift 4
  • Loading branch information
dehlen authored Oct 2, 2017
2 parents 6c67bcc + 60aceeb commit 4c27b1f
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 29 deletions.
22 changes: 18 additions & 4 deletions TRexAboutWindowController.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@
63FB01BC1B63AAB3001AE3EF /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0810;
LastUpgradeCheck = 0910;
ORGANIZATIONNAME = "David Ehlen";
TargetAttributes = {
63FB01C31B63AAB3001AE3EF = {
CreatedOnToolsVersion = 7.0;
LastSwiftMigration = 0820;
LastSwiftMigration = 0910;
};
};
};
Expand Down Expand Up @@ -174,14 +174,20 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -221,14 +227,20 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -262,7 +274,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.david-ehlen.TRexAboutWindowController";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -275,7 +288,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.david-ehlen.TRexAboutWindowController";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand Down
20 changes: 15 additions & 5 deletions TRexAboutWindowController/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
var aboutWindowController:TRexAboutWindowController

override init() {
self.aboutWindowController = TRexAboutWindowController(windowNibName: "PFAboutWindow")
self.aboutWindowController = TRexAboutWindowController(windowNibName: NSNib.Name(rawValue: "PFAboutWindow"))
super.init()
}

Expand All @@ -26,19 +26,29 @@ class AppDelegate: NSObject, NSApplicationDelegate {
// Insert code here to tear down your application
}

func applicationShouldTerminateAfterLastWindowClosed (_ sender: NSApplication) -> Bool
{
return true
}

@IBAction func showAboutWindow(_ sender:AnyObject) {
aboutWindowController = TRexAboutWindowController(windowNibName: NSNib.Name(rawValue: "PFAboutWindow"))
self.aboutWindowController.appURL = URL(string:"https://github.com/T-Rex-Editor/")
self.aboutWindowController.appName = "TRex-Editor"
let font = NSFont(name: "HelveticaNeue", size: 11.0) ?? NSFont.systemFont(ofSize: 11.0)
let color = NSColor.tertiaryLabelColor
let attribs:[String:AnyObject] = [NSForegroundColorAttributeName:color,
NSFontAttributeName:font]
let attribs:[NSAttributedStringKey : AnyObject] = [.foregroundColor : color,
.font : font]


self.aboutWindowController.appCopyright = NSAttributedString(string: "Copyright (c) 2015 David Ehlen", attributes: attribs)
let attributText = NSMutableAttributedString(string: "Copyright (c) 2015 David Ehlen")
attributText.setAttributes(attribs, range: NSMakeRange(0, attributText.length))

self.aboutWindowController.appCopyright = attributText

self.aboutWindowController.windowShouldHaveShadow = true
self.aboutWindowController.showWindow(nil)
aboutWindowController.delegate = self
self.aboutWindowController.showWindow(self)
}
}

17 changes: 9 additions & 8 deletions TRexAboutWindowController/PFAboutWindow.xib
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="11762" systemVersion="16C67" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="13526" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11762"/>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="13526"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
Expand All @@ -19,14 +20,14 @@
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<window allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" hasShadow="NO" oneShot="NO" showsToolbarButton="NO" visibleAtLaunch="NO" animationBehavior="default" id="1">
<windowStyleMask key="styleMask" titled="YES" closable="YES" texturedBackground="YES" unifiedTitleAndToolbar="YES"/>
<windowStyleMask key="styleMask" titled="YES" closable="YES" texturedBackground="YES"/>
<rect key="contentRect" x="196" y="240" width="510" height="199"/>
<rect key="screenRect" x="0.0" y="0.0" width="1440" height="877"/>
<rect key="screenRect" x="0.0" y="0.0" width="2560" height="1417"/>
<view key="contentView" id="2">
<rect key="frame" x="0.0" y="0.0" width="510" height="199"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="EGl-r9-3F1">
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" allowsCharacterPickerTouchBarItem="YES" translatesAutoresizingMaskIntoConstraints="NO" id="EGl-r9-3F1">
<rect key="frame" x="168" y="157" width="324" height="42"/>
<constraints>
<constraint firstAttribute="height" constant="42" id="eO9-ag-w29"/>
Expand All @@ -50,7 +51,7 @@
<action selector="showCredits:" target="-2" id="YDT-Xc-ugF"/>
</connections>
</button>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="ipZ-Gg-r2C">
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" allowsCharacterPickerTouchBarItem="YES" translatesAutoresizingMaskIntoConstraints="NO" id="ipZ-Gg-r2C">
<rect key="frame" x="168" y="136" width="324" height="21"/>
<constraints>
<constraint firstAttribute="height" constant="21" id="Uw8-GT-EfZ"/>
Expand Down Expand Up @@ -94,7 +95,7 @@
<rect key="frame" x="0.0" y="0.0" width="320" height="77"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textView editable="NO" drawsBackground="NO" importsGraphics="NO" findStyle="panel" id="zPN-eo-Xhd">
<textView editable="NO" drawsBackground="NO" importsGraphics="NO" verticallyResizable="YES" findStyle="panel" id="zPN-eo-Xhd">
<rect key="frame" x="0.0" y="0.0" width="320" height="77"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
Expand Down Expand Up @@ -135,7 +136,7 @@
</constraints>
</view>
<connections>
<outlet property="delegate" destination="-2" id="4"/>
<outlet property="delegate" destination="-2" id="ZGE-dL-Pkq"/>
</connections>
<point key="canvasLocation" x="244.5" y="199"/>
</window>
Expand Down
28 changes: 16 additions & 12 deletions TRexAboutWindowController/TRexAboutWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ public enum WindowState {
case Expanded
}

@objc(TRexAboutWindowController)
open class TRexAboutWindowController : NSWindowController {
open var appName = ""

var delegate: AppDelegate?

@objc open var appName = ""
open var appVersion = ""
open var appCopyright = NSAttributedString()
open var appCredits = NSAttributedString()
Expand Down Expand Up @@ -56,9 +60,9 @@ open class TRexAboutWindowController : NSWindowController {

if self.appCopyright.string.isEmpty {
let font = NSFont(name: "HelveticaNeue", size: 11.0) ?? NSFont.systemFont(ofSize: 11.0)
let color = floor(NSAppKitVersionNumber) <= Double(NSAppKitVersionNumber10_9) ? NSColor.lightGray : NSColor.tertiaryLabelColor
let attribs:[String:AnyObject] = [NSForegroundColorAttributeName:color,
NSFontAttributeName:font]
let color = floor(NSAppKitVersion.current.rawValue) <= Double((NSAppKitVersion.macOS10_9).rawValue) ? NSColor.lightGray : NSColor.tertiaryLabelColor
let attribs:[ NSAttributedStringKey : Any] = [.foregroundColor : color,
.font : font]
self.appCopyright = NSAttributedString(string: valueFromInfoDict("NSHumanReadableCopyright") ?? "", attributes:attribs)
}

Expand Down Expand Up @@ -115,19 +119,19 @@ open class TRexAboutWindowController : NSWindowController {
self.windowState = windowState == .Collapsed ? .Expanded : .Collapsed
}

open func windowShouldClose(_ sender: AnyObject) -> Bool {
self.showCopyright(sender)
return true
}
// @objc open func windowShouldClose(_ sender: AnyObject) -> Bool {
// self.showCopyright(sender)
// return true
// }

override open func showWindow(_ sender: Any?) {
super.showWindow(sender)
}
// override open func showWindow(_ sender: Any?) {
// self.showWindow(sender)
// }

//Button Actions
@IBAction func visitWebsite(_ sender: AnyObject) {
guard let url = self.appURL else { return }
NSWorkspace.shared().open(url)
NSWorkspace.shared.open(url)
}

@IBAction func showCredits(_ sender: AnyObject) {
Expand Down

0 comments on commit 4c27b1f

Please sign in to comment.