-
Notifications
You must be signed in to change notification settings - Fork 31
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
Rishiraj Sharma
authored and
Rishiraj Sharma
committed
Feb 8, 2018
1 parent
5bc555c
commit 6d553e8
Showing
53 changed files
with
2,710 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
Swiftness.xcodeproj/project.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,96 @@ | ||
import Cocoa | ||
|
||
@NSApplicationMain | ||
class AppDelegate: NSObject, NSApplicationDelegate { | ||
|
||
// MARK: - Properties | ||
let templateManager = TemplateManager() | ||
|
||
private lazy var statusItem: NSStatusItem = { | ||
let statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.squareLength) | ||
statusItem.button?.action = #selector(togglePopover) | ||
return statusItem | ||
}() | ||
|
||
private lazy var popover: NSPopover = { | ||
let popover = NSPopover() | ||
let statusBarViewController = NSStoryboard.statusBarViewController() | ||
statusBarViewController?.delegate = self | ||
popover.contentViewController = statusBarViewController | ||
popover.behavior = .transient | ||
return popover | ||
}() | ||
|
||
// When the popover is shown, click outside will close the popover | ||
private lazy var eventMonitor: EventMonitor = { | ||
let eventMonitor = EventMonitor(mask: [.leftMouseDown, .rightMouseDown] ) { [unowned self] event in | ||
guard event?.window != self.popover.contentViewController?.view.window else { return } | ||
if self.popover.isShown { | ||
self.closePopover() | ||
} | ||
} | ||
return eventMonitor | ||
}() | ||
|
||
// MARK: - Overrides | ||
func applicationDidFinishLaunching(_ aNotification: Notification) { | ||
hideMainWindow() | ||
statusItem.button?.image = NSImage(named: NSImage.Name(rawValue: "link")) | ||
} | ||
|
||
} | ||
|
||
// MARK: - MainWindowDelegate | ||
extension AppDelegate: MainWindowDelegate { | ||
|
||
func hideMainWindow() { | ||
NSApp.hide(nil) | ||
NSApp.setActivationPolicy(.accessory) | ||
} | ||
|
||
func showMainWindow() { | ||
if NSApp.isHidden { | ||
NSApp.setActivationPolicy(.regular) | ||
} | ||
closePopover() | ||
NSApp.activate(ignoringOtherApps: true) | ||
} | ||
|
||
} | ||
|
||
// MARK: - Public methods | ||
extension AppDelegate { | ||
|
||
@objc func togglePopover() { | ||
if popover.isShown { | ||
closePopover() | ||
} else { | ||
showPopover() | ||
} | ||
} | ||
|
||
} | ||
|
||
// MARK: - Private methods | ||
private extension AppDelegate { | ||
|
||
// MARK: Popover | ||
func showPopover() { | ||
guard let statusItemButton = statusItem.button else { return } | ||
|
||
(popover.contentViewController as? StatusBarViewController)?.templateManager = templateManager | ||
|
||
if !NSApp.isHidden { | ||
NSApp.activate(ignoringOtherApps: true) | ||
} | ||
|
||
popover.show(relativeTo: .zero, of: statusItemButton, preferredEdge: NSRectEdge.minY) | ||
eventMonitor.start() | ||
} | ||
|
||
func closePopover() { | ||
eventMonitor.stop() | ||
popover.performClose(self) | ||
} | ||
|
||
} |
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,13 @@ | ||
import Cocoa | ||
|
||
class EditorTableView: NSTableView { | ||
|
||
override func menu(for event: NSEvent) -> NSMenu? { | ||
let mouseLocation = event.locationInWindow | ||
|
||
let viewLocation = convert(mouseLocation, from: nil) | ||
let row = self.row(at: viewLocation) | ||
return row == -1 ? nil : super.menu(for: event) | ||
} | ||
|
||
} |
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,9 @@ | ||
import Cocoa | ||
|
||
class EditorTemplateCellView: NSTableCellView { | ||
|
||
static let identifier = NSUserInterfaceItemIdentifier("EditorTemplateCellView") | ||
@IBOutlet weak var titleTextField: NSTextField! | ||
|
||
} | ||
|
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,21 @@ | ||
import Cocoa | ||
|
||
class HoverButton: NSButton { | ||
|
||
private var trackingArea: NSTrackingArea? | ||
|
||
open override func cursorUpdate(with event: NSEvent) { | ||
NSCursor.pointingHand.set() | ||
} | ||
|
||
override open func updateTrackingAreas() { | ||
if let trackingArea = self.trackingArea { | ||
self.removeTrackingArea(trackingArea) | ||
} | ||
|
||
let trackingOptions: NSTrackingArea.Options = [.cursorUpdate, .activeAlways] | ||
trackingArea = NSTrackingArea(rect: bounds, options: trackingOptions, owner: self, userInfo: nil) | ||
addTrackingArea(trackingArea!) | ||
} | ||
|
||
} |
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,13 @@ | ||
import Cocoa | ||
|
||
class RowView: NSTableRowView { | ||
|
||
override func drawSelection(in dirtyRect: NSRect) { | ||
isEmphasized ? NSColor.white.set() : NSColor.white.set() | ||
dirtyRect.fill() | ||
} | ||
override var isEmphasized: Bool { | ||
set {} | ||
get { 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,13 @@ | ||
import Cocoa | ||
|
||
class StatusBarTemplateCellView: NSTableCellView { | ||
|
||
static let identifier = NSUserInterfaceItemIdentifier("StatusBarTemplateCellView") | ||
|
||
@IBOutlet weak var titleTextField: NSTextField! | ||
@IBOutlet weak var copyButton: NSButton! | ||
|
||
func setSelected(selected: Bool) { | ||
layer?.backgroundColor = selected ? CGColor.clear : CGColor.white | ||
} | ||
} |
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,29 @@ | ||
import Cocoa | ||
|
||
public class EventMonitor { | ||
|
||
private var monitor: AnyObject? | ||
private let mask: NSEvent.EventTypeMask | ||
private let handler: (NSEvent?) -> Void | ||
|
||
public init(mask: NSEvent.EventTypeMask, handler: @escaping (NSEvent?) -> Void) { | ||
self.mask = mask | ||
self.handler = handler | ||
} | ||
|
||
deinit { | ||
stop() | ||
} | ||
|
||
public func start() { | ||
monitor = NSEvent.addGlobalMonitorForEvents(matching: mask, handler: handler) as AnyObject? | ||
} | ||
|
||
public func stop() { | ||
if monitor != nil { | ||
NSEvent.removeMonitor(monitor!) | ||
monitor = nil | ||
} | ||
} | ||
} | ||
|
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,15 @@ | ||
import Cocoa | ||
|
||
protocol Copyable { | ||
func copyToPasteboard(_ string: NSAttributedString) | ||
} | ||
|
||
extension Copyable { | ||
func copyToPasteboard(_ string: NSAttributedString) { | ||
let pasteboard = NSPasteboard.general | ||
let documentAttributes: [NSAttributedString.DocumentAttributeKey: Any] = [.documentType: NSAttributedString.DocumentType.rtf] | ||
let data = try! string.data(from: NSRange(location: 0, length: string.length), documentAttributes: documentAttributes) | ||
pasteboard.clearContents() | ||
pasteboard.setData(data, forType: .rtf) | ||
} | ||
} |
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 @@ | ||
import Foundation | ||
|
||
protocol MainWindowDelegate: class { | ||
func showMainWindow() | ||
func hideMainWindow() | ||
} |
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,16 @@ | ||
import Cocoa | ||
|
||
extension NSButton { | ||
|
||
@IBInspectable open var textColor: NSColor? { | ||
get { | ||
return attributedTitle.attribute(.foregroundColor, at: 0, effectiveRange: nil) as? NSColor | ||
} | ||
set { | ||
var attributes = attributedTitle.attributes(at: 0, effectiveRange: nil) | ||
attributes[.foregroundColor] = newValue ?? NSColor.black | ||
attributedTitle = NSMutableAttributedString(string: self.title, attributes: attributes) | ||
} | ||
} | ||
|
||
} |
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,22 @@ | ||
import Cocoa | ||
|
||
extension NSStoryboard { | ||
|
||
class func statusBarViewController() -> StatusBarViewController? { | ||
return load(identifier: "StatusBarViewController") as? StatusBarViewController | ||
} | ||
|
||
class func editorWindowController() -> EditorWindowController? { | ||
return load(identifier: "EditorWindowController") as? EditorWindowController | ||
} | ||
|
||
} | ||
|
||
private extension NSStoryboard { | ||
|
||
static func load(identifier: String) -> Any { | ||
let storyboard = NSStoryboard(name: Name("Main"), bundle: nil) | ||
return storyboard.instantiateController(withIdentifier: SceneIdentifier(identifier)) | ||
} | ||
|
||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+60.4 KB
Swiftness/Resources/Assets.xcassets/AppIcon.appiconset/[email protected]
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.
Binary file added
BIN
+2.2 KB
Swiftness/Resources/Assets.xcassets/AppIcon.appiconset/[email protected]
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.
Binary file added
BIN
+205 KB
Swiftness/Resources/Assets.xcassets/AppIcon.appiconset/[email protected]
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.
Binary file added
BIN
+6.39 KB
Swiftness/Resources/Assets.xcassets/AppIcon.appiconset/[email protected]
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.
Binary file added
BIN
+752 KB
Swiftness/Resources/Assets.xcassets/AppIcon.appiconset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 68 additions & 0 deletions
68
Swiftness/Resources/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,68 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"size" : "16x16", | ||
"idiom" : "mac", | ||
"filename" : "16px.png", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"size" : "16x16", | ||
"idiom" : "mac", | ||
"filename" : "[email protected]", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"size" : "32x32", | ||
"idiom" : "mac", | ||
"filename" : "32px.png", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"size" : "32x32", | ||
"idiom" : "mac", | ||
"filename" : "[email protected]", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"size" : "128x128", | ||
"idiom" : "mac", | ||
"filename" : "128px.png", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"size" : "128x128", | ||
"idiom" : "mac", | ||
"filename" : "[email protected]", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"size" : "256x256", | ||
"idiom" : "mac", | ||
"filename" : "256px.png", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"size" : "256x256", | ||
"idiom" : "mac", | ||
"filename" : "[email protected]", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"size" : "512x512", | ||
"idiom" : "mac", | ||
"filename" : "512px-1.png", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"size" : "512x512", | ||
"idiom" : "mac", | ||
"filename" : "[email protected]", | ||
"scale" : "2x" | ||
} | ||
], | ||
"info" : { | ||
"version" : 1, | ||
"author" : "xcode" | ||
} | ||
} |
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" : { | ||
"version" : 1, | ||
"author" : "xcode" | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
Swiftness/Resources/Assets.xcassets/Copy Icon.imageset/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,22 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "universal", | ||
"filename" : "Copy Icon.png", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"idiom" : "universal", | ||
"filename" : "Copy [email protected]", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "universal", | ||
"scale" : "3x" | ||
} | ||
], | ||
"info" : { | ||
"version" : 1, | ||
"author" : "xcode" | ||
} | ||
} |
Binary file added
BIN
+641 Bytes
Swiftness/Resources/Assets.xcassets/Copy Icon.imageset/Copy Icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1017 Bytes
Swiftness/Resources/Assets.xcassets/Copy Icon.imageset/Copy [email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions
22
Swiftness/Resources/Assets.xcassets/Search.imageset/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,22 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "universal", | ||
"filename" : "Search.png", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"idiom" : "universal", | ||
"filename" : "[email protected]", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "universal", | ||
"scale" : "3x" | ||
} | ||
], | ||
"info" : { | ||
"version" : 1, | ||
"author" : "xcode" | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.56 KB
Swiftness/Resources/Assets.xcassets/Search.imageset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.