-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
32 changed files
with
2,734 additions
and
0 deletions.
There are no files selected for viewing
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,23 @@ | ||
// | ||
// AppDelegate.swift | ||
// SoulverTextKit | ||
// | ||
// Created by Zac Cohan on 9/1/21. | ||
// | ||
|
||
import Cocoa | ||
|
||
@main | ||
class AppDelegate: NSObject, NSApplicationDelegate { | ||
|
||
func applicationDidFinishLaunching(_ aNotification: Notification) { | ||
// Insert code here to initialize your application | ||
} | ||
|
||
func applicationWillTerminate(_ aNotification: Notification) { | ||
// Insert code here to tear down your application | ||
} | ||
|
||
|
||
} | ||
|
11 changes: 11 additions & 0 deletions
11
Examples/Mac/Assets.xcassets/AccentColor.colorset/Contents.json
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,11 @@ | ||
{ | ||
"colors" : [ | ||
{ | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
Examples/Mac/Assets.xcassets/AppIcon.appiconset/Contents.json
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,58 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "1x", | ||
"size" : "16x16" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "2x", | ||
"size" : "16x16" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "1x", | ||
"size" : "32x32" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "2x", | ||
"size" : "32x32" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "1x", | ||
"size" : "128x128" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "2x", | ||
"size" : "128x128" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "1x", | ||
"size" : "256x256" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "2x", | ||
"size" : "256x256" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "1x", | ||
"size" : "512x512" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "2x", | ||
"size" : "512x512" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
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,6 @@ | ||
{ | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
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,30 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>CFBundleDevelopmentRegion</key> | ||
<string>$(DEVELOPMENT_LANGUAGE)</string> | ||
<key>CFBundleExecutable</key> | ||
<string>$(EXECUTABLE_NAME)</string> | ||
<key>CFBundleIconFile</key> | ||
<string></string> | ||
<key>CFBundleIdentifier</key> | ||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> | ||
<key>CFBundleInfoDictionaryVersion</key> | ||
<string>6.0</string> | ||
<key>CFBundleName</key> | ||
<string>$(PRODUCT_NAME)</string> | ||
<key>CFBundlePackageType</key> | ||
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string> | ||
<key>CFBundleShortVersionString</key> | ||
<string>1.0</string> | ||
<key>CFBundleVersion</key> | ||
<string>1</string> | ||
<key>LSMinimumSystemVersion</key> | ||
<string>$(MACOSX_DEPLOYMENT_TARGET)</string> | ||
<key>NSMainStoryboardFile</key> | ||
<string>Main</string> | ||
<key>NSPrincipalClass</key> | ||
<string>NSApplication</string> | ||
</dict> | ||
</plist> |
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,89 @@ | ||
// | ||
// ViewController.swift | ||
// SoulverTextKit | ||
// | ||
// Created by Zac Cohan on 9/1/21. | ||
// | ||
|
||
import Cocoa | ||
import SoulverTextKit | ||
|
||
class ViewController: NSViewController { | ||
|
||
/// Grab a standard text view | ||
@IBOutlet var textView: NSTextView! | ||
|
||
/// Create one of these things | ||
var paragraphCalculator: SoulverTextKit.ParagraphCalculator! | ||
|
||
/// Choose what character distinguishes a calculating paragraph | ||
let style = AnswerPosition.afterTab | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
self.setupSoulverTextKit() | ||
|
||
// Looks better | ||
self.textView.textContainerInset = NSSize(width: 10.0, height: 15.0) | ||
|
||
} | ||
|
||
func setupSoulverTextKit() { | ||
|
||
paragraphCalculator = ParagraphCalculator(answerPosition: self.style, textStorage: self.textView.textStorage!, textContainer: self.textView.textContainer!) | ||
|
||
// Setup the text view to send us relevant delegate messages | ||
self.textView.delegate = self | ||
self.textView.layoutManager!.delegate = self | ||
|
||
// Set some default expressions | ||
self.textView.string = [ | ||
"123 + 456", | ||
"10 USD in EUR", | ||
"today + 3 weeks" | ||
].expressionStringFor(style: self.style) | ||
|
||
// let soulverTextKit know we changed the textView's text | ||
paragraphCalculator.textDidChange() | ||
|
||
|
||
} | ||
|
||
} | ||
|
||
extension ViewController : NSLayoutManagerDelegate, NSTextViewDelegate { | ||
|
||
func textDidChange(_ notification: Notification) { | ||
|
||
// Let us know when the text changes, so we can evaluate any changed paragraph if necessary | ||
paragraphCalculator.textDidChange() | ||
} | ||
|
||
func layoutManager(_ layoutManager: NSLayoutManager, textContainer: NSTextContainer, didChangeGeometryFrom oldSize: NSSize) { | ||
|
||
// Let us know when the text view changes size, so we can change update the formatting if necessary | ||
paragraphCalculator.layoutDidChange() | ||
} | ||
|
||
func textView(_ textView: NSTextView, shouldChangeTextIn affectedCharRange: NSRange, replacementString: String?) -> Bool { | ||
|
||
// Check with us to see if the user should be able to edit parts of the paragraph. For example, we don't allow the user to edit results on Soulver lines themselves | ||
|
||
switch paragraphCalculator.shouldAllowReplacementFor(affectedCharRange: affectedCharRange, replacementString: replacementString) { | ||
case .allow: | ||
return true | ||
case .deny: | ||
NSSound.beep() | ||
return false | ||
case .setIntertionPoint(range: let range): | ||
textView.setSelectedRange(range) | ||
return false | ||
} | ||
|
||
} | ||
|
||
|
||
} | ||
|
||
|
Oops, something went wrong.