-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Your name
committed
May 24, 2019
0 parents
commit 6f82ca1
Showing
71 changed files
with
9,857 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
// | ||
// MLAlert.swift | ||
// ModernLookOSXSampleSwift | ||
// | ||
// Created by thierry hentic on 22/05/2019. | ||
// Copyright © 2019 thierry hentic. All rights reserved. | ||
// | ||
|
||
import Cocoa | ||
|
||
enum MLAlertResponse : Int { | ||
case yes | ||
case no | ||
case cancel | ||
} | ||
|
||
final class MLAlert: NSWindowController { | ||
|
||
@IBOutlet weak var title: NSTextField! | ||
@IBOutlet weak var message: NSTextField! | ||
@IBOutlet weak var cancel: NSButton! | ||
@IBOutlet weak var yes: NSButton! | ||
@IBOutlet weak var no: NSButton! | ||
@IBOutlet weak var toolbar: MLToolbar! | ||
|
||
|
||
override func windowDidLoad() { | ||
super.windowDidLoad() | ||
|
||
window?.styleMask = .borderless | ||
|
||
|
||
// Implement this method to handle any initialization after your window controller's window has been loaded from its nib file. | ||
} | ||
|
||
func showQuestion(_ question: String?, title: String?, withCancel: Bool, buttonsTitle titles: [String]) -> MLAlertResponse { | ||
// let alert = MLAlert() | ||
if !withCancel { | ||
cancel.isHidden = true | ||
} | ||
self.title.stringValue = title ?? "" | ||
message.stringValue = question ?? "" | ||
if titles.count == 3 { | ||
cancel.title = titles[0] | ||
yes.title = titles[1] | ||
no.title = titles[2] | ||
} else { | ||
yes.title = titles[0] | ||
no.title = titles[1] | ||
} | ||
resizeButtons() | ||
let res = runAlert() | ||
window?.close() | ||
return res | ||
} | ||
|
||
func showQuestion(_ question: String, title: String, withCancel: Bool) -> MLAlertResponse { | ||
return showQuestion(question, title: title, withCancel: withCancel, buttonsTitle: ["Cancel", "Yes", "No"]) | ||
} | ||
|
||
func showError(_ question: String, title: String, buttonsTitle butonTitle: String) -> MLAlertResponse { | ||
|
||
toolbar.backgroundColor = NSColor.red | ||
cancel.isHidden = true | ||
yes.isHidden = true | ||
self.title.stringValue = title | ||
message.stringValue = question | ||
no.title = butonTitle | ||
resizeButtons() | ||
let res: MLAlertResponse = runAlert() | ||
window?.close() | ||
return res | ||
|
||
} | ||
|
||
func showError(_ question: String, title: String) -> MLAlertResponse { | ||
return showError(question, title: title, buttonsTitle: "Back") | ||
} | ||
|
||
override var windowNibName: NSNib.Name? { | ||
return "MLAlertYesNoCancel" | ||
} | ||
|
||
// required init?(coder: NSCoder) { | ||
// fatalError("init(coder:) has not been implemented") | ||
// } | ||
|
||
func resizeButtons() { | ||
// [self.no sizeToFit]; | ||
// [self.yes sizeToFit]; | ||
// [self.cancel sizeToFit]; | ||
|
||
var cr = cancel.bounds | ||
var yr = yes.bounds | ||
var nr = no.bounds | ||
|
||
cr.size.width = cancel.frame.size.width + 10 | ||
yr.size.width = yes.frame.size.width + 10 | ||
nr.size.width = no.frame.size.width + 10 | ||
|
||
if cr.size.width < 85 { | ||
cr.size.width = 85 | ||
} | ||
if yr.size.width < 85 { | ||
yr.size.width = 85 | ||
} | ||
if nr.size.width < 85 { | ||
nr.size.width = 85 | ||
} | ||
|
||
no.bounds = nr | ||
yes.bounds = yr | ||
cancel.bounds = cr | ||
|
||
no.needsDisplay = true | ||
yes.needsDisplay = true | ||
cancel.needsDisplay = true | ||
} | ||
|
||
func runAlert() -> MLAlertResponse { | ||
MLMainWindow.shared.relativeCenter(window) | ||
let runSessionRes = NSApplication.shared.runModal(for: window!) | ||
window?.close() | ||
|
||
return (MLAlertResponse(rawValue: runSessionRes.rawValue)!) | ||
} | ||
|
||
func windowWillClose(_ notification: Notification) { | ||
// [[NSApplication sharedApplication] stopModal]; | ||
} | ||
|
||
@IBAction func doCancel(_ sender: Any) { | ||
NSApp.stopModal(withCode: .cancel) | ||
} | ||
|
||
@IBAction func doYes(_ sender: Any) { | ||
NSApp.stopModal(withCode: .OK) | ||
} | ||
|
||
@IBAction func doNo(_ sender: Any) { | ||
NSApp.stopModal(withCode: .alertSecondButtonReturn) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// | ||
// MLAlertWindow.swift | ||
// ModernLookOSXSampleSwift | ||
// | ||
// Created by thierry hentic on 22/05/2019. | ||
// Copyright © 2019 thierry hentic. All rights reserved. | ||
// | ||
|
||
import Cocoa | ||
|
||
class MLAlertWindow: MLCenteredWindow { | ||
|
||
let MLALERT_YES = 0 | ||
let MLALERT_NO = 1 | ||
let MLALERT_CANCEL = 2 | ||
|
||
|
||
override func cancelOperation(_ sender: Any?) { | ||
NSApp.stopModal( withCode: .cancel) | ||
} | ||
|
||
override var canBecomeMain: Bool { | ||
return false | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES"> | ||
<dependencies> | ||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14490.70"/> | ||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> | ||
</dependencies> | ||
<objects> | ||
<customObject id="-2" userLabel="File's Owner" customClass="MLAlert"> | ||
<connections> | ||
<outlet property="cancel" destination="1VS-YW-anM" id="OQt-DA-yzb"/> | ||
<outlet property="message" destination="WVl-N5-6Px" id="0V6-a5-Wpn"/> | ||
<outlet property="no" destination="X5U-LN-WrO" id="rkB-jM-oo8"/> | ||
<outlet property="title" destination="OEn-fO-laH" id="zoU-vm-4dR"/> | ||
<outlet property="toolbar" destination="D4K-MO-rYw" id="goD-Hr-a2S"/> | ||
<outlet property="window" destination="F0z-JX-Cv5" id="gIp-Ho-8D9"/> | ||
<outlet property="yes" destination="Vcr-UG-FoQ" id="q29-wZ-bl1"/> | ||
</connections> | ||
</customObject> | ||
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/> | ||
<customObject id="-3" userLabel="Application" customClass="NSObject"/> | ||
<window title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" visibleAtLaunch="NO" animationBehavior="default" id="F0z-JX-Cv5" customClass="MLAlertWindow" customModule="ModernLookOSXSampleSwift" customModuleProvider="target"> | ||
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/> | ||
<rect key="contentRect" x="196" y="240" width="480" height="166"/> | ||
<rect key="screenRect" x="0.0" y="0.0" width="2560" height="1417"/> | ||
<view key="contentView" id="se5-gp-TjO" customClass="MLWindowContent" customModule="ModernLookOSXSampleSwift" customModuleProvider="target"> | ||
<rect key="frame" x="0.0" y="0.0" width="480" height="166"/> | ||
<autoresizingMask key="autoresizingMask"/> | ||
<subviews> | ||
<button translatesAutoresizingMaskIntoConstraints="NO" id="X5U-LN-WrO" customClass="MLColoredButton" customModule="ModernLookOSXSampleSwift" customModuleProvider="target"> | ||
<rect key="frame" x="377" y="11" width="85" height="33"/> | ||
<constraints> | ||
<constraint firstAttribute="height" constant="28" id="fmm-TV-Cg4"/> | ||
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="81" id="hyg-9o-zaF"/> | ||
</constraints> | ||
<buttonCell key="cell" type="bevel" title="N" bezelStyle="regularSquare" alignment="center" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="nQp-jq-bLi"> | ||
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/> | ||
<font key="font" size="14" name="HelveticaNeue-Light"/> | ||
</buttonCell> | ||
<connections> | ||
<action selector="doNo:" target="-2" id="HLJ-ct-gSd"/> | ||
</connections> | ||
</button> | ||
<button translatesAutoresizingMaskIntoConstraints="NO" id="Vcr-UG-FoQ" customClass="MLColoredButton" customModule="ModernLookOSXSampleSwift" customModuleProvider="target"> | ||
<rect key="frame" x="288" y="11" width="85" height="33"/> | ||
<constraints> | ||
<constraint firstAttribute="height" constant="28" id="GO8-AA-uvk"/> | ||
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="81" id="ijK-NT-qK1"/> | ||
</constraints> | ||
<buttonCell key="cell" type="bevel" title="Y" bezelStyle="regularSquare" image="BuyTemplate" alignment="center" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="Woz-7a-Olc"> | ||
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/> | ||
<font key="font" size="14" name="HelveticaNeue-Light"/> | ||
<string key="keyEquivalent" base64-UTF8="YES"> | ||
DQ | ||
</string> | ||
</buttonCell> | ||
<userDefinedRuntimeAttributes> | ||
<userDefinedRuntimeAttribute type="color" keyPath="backgroundColor"> | ||
<color key="value" red="0.20392157137393951" green="0.59607845544815063" blue="0.85882353782653809" alpha="1" colorSpace="calibratedRGB"/> | ||
</userDefinedRuntimeAttribute> | ||
</userDefinedRuntimeAttributes> | ||
<connections> | ||
<action selector="doYes:" target="-2" id="WRO-bk-FwV"/> | ||
</connections> | ||
</button> | ||
<button translatesAutoresizingMaskIntoConstraints="NO" id="1VS-YW-anM" customClass="MLColoredButton" customModule="ModernLookOSXSampleSwift" customModuleProvider="target"> | ||
<rect key="frame" x="24" y="11" width="85" height="33"/> | ||
<constraints> | ||
<constraint firstAttribute="height" constant="28" id="6Rg-7O-thZ"/> | ||
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="81" id="Ogc-3L-wHF"/> | ||
</constraints> | ||
<buttonCell key="cell" type="bevel" title="C" bezelStyle="regularSquare" alignment="center" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="ZI8-Ii-Jgc"> | ||
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/> | ||
<font key="font" size="14" name="HelveticaNeue-Light"/> | ||
<string key="keyEquivalent" base64-UTF8="YES"> | ||
Gw | ||
</string> | ||
</buttonCell> | ||
<connections> | ||
<action selector="doCancel:" target="-2" id="WaF-dZ-tmW"/> | ||
</connections> | ||
</button> | ||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="WVl-N5-6Px"> | ||
<rect key="frame" x="24" y="77" width="438" height="22"/> | ||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/> | ||
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Message" id="z0i-dh-1WT"> | ||
<font key="font" size="18" name="HelveticaNeue-Thin"/> | ||
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/> | ||
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/> | ||
</textFieldCell> | ||
</textField> | ||
<customView fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="D4K-MO-rYw" customClass="MLToolbar" customModule="ModernLookOSXSampleSwift" customModuleProvider="target"> | ||
<rect key="frame" x="0.0" y="117" width="480" height="49"/> | ||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/> | ||
<subviews> | ||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="OEn-fO-laH"> | ||
<rect key="frame" x="18" y="10" width="476" height="28"/> | ||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/> | ||
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Title" id="NV9-di-mLu"> | ||
<font key="font" size="23" name="HelveticaNeue-Light"/> | ||
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/> | ||
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/> | ||
</textFieldCell> | ||
</textField> | ||
</subviews> | ||
<userDefinedRuntimeAttributes> | ||
<userDefinedRuntimeAttribute type="color" keyPath="backgroundColor"> | ||
<color key="value" red="0.9529411792755127" green="0.61176472902297974" blue="0.070588238537311554" alpha="1" colorSpace="calibratedRGB"/> | ||
</userDefinedRuntimeAttribute> | ||
<userDefinedRuntimeAttribute type="boolean" keyPath="hiddenButtons" value="YES"/> | ||
</userDefinedRuntimeAttributes> | ||
</customView> | ||
<box verticalHuggingPriority="750" fixedFrame="YES" boxType="separator" translatesAutoresizingMaskIntoConstraints="NO" id="Yq5-8L-hsM"> | ||
<rect key="frame" x="26" y="54" width="434" height="4"/> | ||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/> | ||
</box> | ||
</subviews> | ||
<constraints> | ||
<constraint firstAttribute="bottom" secondItem="X5U-LN-WrO" secondAttribute="bottom" constant="14" id="4Zg-G8-c0A"/> | ||
<constraint firstAttribute="trailing" secondItem="X5U-LN-WrO" secondAttribute="trailing" constant="20" id="KOw-V3-YvZ"/> | ||
<constraint firstItem="X5U-LN-WrO" firstAttribute="leading" secondItem="Vcr-UG-FoQ" secondAttribute="trailing" constant="8" id="aF2-Sx-v90"/> | ||
<constraint firstAttribute="bottom" secondItem="Vcr-UG-FoQ" secondAttribute="bottom" constant="14" id="cLh-43-4cs"/> | ||
<constraint firstAttribute="bottom" secondItem="1VS-YW-anM" secondAttribute="bottom" constant="14" id="gcA-bB-F44"/> | ||
<constraint firstItem="1VS-YW-anM" firstAttribute="leading" secondItem="se5-gp-TjO" secondAttribute="leading" constant="26" id="pvB-fn-Q5v"/> | ||
</constraints> | ||
<userDefinedRuntimeAttributes> | ||
<userDefinedRuntimeAttribute type="color" keyPath="backgroundColor"> | ||
<color key="value" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/> | ||
</userDefinedRuntimeAttribute> | ||
</userDefinedRuntimeAttributes> | ||
</view> | ||
<connections> | ||
<outlet property="delegate" destination="-2" id="0bl-1N-AYu"/> | ||
</connections> | ||
<point key="canvasLocation" x="-259" y="89"/> | ||
</window> | ||
</objects> | ||
<resources> | ||
<image name="BuyTemplate" width="512" height="512"/> | ||
</resources> | ||
</document> |
Oops, something went wrong.