Skip to content

Commit

Permalink
rename pasteboard with clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
jdev7 committed Jun 14, 2020
1 parent d0e8736 commit f718c0f
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 23 deletions.
4 changes: 2 additions & 2 deletions nef-plugin/AppScheme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ struct AppScheme {
enum Action {
case preferences
case carbon(selection: String)
case pasteboardCarbon(selection: String)
case clipboardCarbon(selection: String)
case markdownPage(playground: String)
case playgroundBook(package: String)

var item: URLQueryItem {
switch self {
case .preferences: return URLQueryItem(name: "preferences", value: nil)
case let .carbon(selection): return URLQueryItem(name: "carbon", value: selection)
case let .pasteboardCarbon(selection): return URLQueryItem(name: "pasteboardCarbon", value: selection)
case let .clipboardCarbon(selection): return URLQueryItem(name: "clipboardCarbon", value: selection)
case let .markdownPage(playground): return URLQueryItem(name: "markdownPage", value: playground)
case let .playgroundBook(package): return URLQueryItem(name: "playgroundBook", value: package)
}
Expand Down
8 changes: 4 additions & 4 deletions nef-plugin/SourceEditorCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class SourceEditorCommand: NSObject, XCSourceEditorCommand {
preferences(completion: completion)
case .exportSnippet:
carbon(editor: editor, completion: completion)
case .exportSnippetToPasteboard:
pasteboardCarbon(editor: editor, completion: completion)
case .exportSnippetToClipboard:
clipboardCarbon(editor: editor, completion: completion)
case .markdownPage:
markdownPage(editor: editor, completion: completion)
case .playgroundBook:
Expand All @@ -41,11 +41,11 @@ class SourceEditorCommand: NSObject, XCSourceEditorCommand {
terminate(deadline: .now() + .seconds(5), completion)
}

private func pasteboardCarbon(editor: Editor, completion: @escaping (Error?) -> Void) {
private func clipboardCarbon(editor: Editor, completion: @escaping (Error?) -> Void) {
guard Reachability.isConnected else { completion(EditorError.internetConnection); return }
guard let selection = editor.selection else { completion(EditorError.selection); return }

AppScheme(action: .pasteboardCarbon(selection: selection)).run()
AppScheme(action: .clipboardCarbon(selection: selection)).run()
terminate(deadline: .now() + .seconds(5), completion)
}

Expand Down
2 changes: 1 addition & 1 deletion nef-plugin/SourceEditorExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class SourceEditorExtension: NSObject, XCSourceEditorExtension {
enum Command: String {
case preferences
case exportSnippet
case exportSnippetToPasteboard
case exportSnippetToClipboard
case markdownPage
case playgroundBook
}
Expand Down
2 changes: 1 addition & 1 deletion nef-plugin/Support Files/Info-appstore.plist
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<key>XCSourceEditorCommandClassName</key>
<string>$(PRODUCT_MODULE_NAME).SourceEditorCommand</string>
<key>XCSourceEditorCommandIdentifier</key>
<string>exportSnippetToPasteboard</string>
<string>exportSnippetToClipboard</string>
<key>XCSourceEditorCommandName</key>
<string>Code selection → Image (Clipboard)</string>
</dict>
Expand Down
2 changes: 1 addition & 1 deletion nef-plugin/Support Files/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<key>XCSourceEditorCommandClassName</key>
<string>$(PRODUCT_MODULE_NAME).SourceEditorCommand</string>
<key>XCSourceEditorCommandIdentifier</key>
<string>exportSnippetToPasteboard</string>
<string>exportSnippetToClipboard</string>
<key>XCSourceEditorCommandName</key>
<string>Code selection → Image (Clipboard)</string>
</dict>
Expand Down
12 changes: 6 additions & 6 deletions nef/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ class AppDelegate: NSObject, NSApplicationDelegate {
preferencesDidFinishLaunching()
case .carbon(let code):
carbonDidFinishLaunching(code: code)
case .pasteboardCarbon(let code):
pasteboardCarbonDidFinishLaunching(code: code)
case .clipboardCarbon(let code):
clipboardCarbonDidFinishLaunching(code: code)
case .markdownPage(let playground):
markdownPageDidFinishLaunching(playground: playground)
case .playgroundBook(let package):
Expand Down Expand Up @@ -104,14 +104,14 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}
}

private func pasteboardCarbonDidFinishLaunching(code: String) {
private func clipboardCarbonDidFinishLaunching(code: String) {
guard !code.isEmpty else { terminate(); return }
emptyDidFinishLaunching()

let config = Clipboard.Config(clipboard: .general, notificationCenter: .current())

assembler.resolveCarbon(code: code).env()^.mapError { _ in .carbon }
.flatMap(pasteboardCarbonIO)^
.flatMap(clipboardCarbonIO)^
.provide(config)
.unsafeRunAsync(on: .global(qos: .userInitiated)) { output in
_ = output.map { _ in
Expand Down Expand Up @@ -231,8 +231,8 @@ class AppDelegate: NSObject, NSApplicationDelegate {
return .preferences
case let ("carbon", value):
return .carbon(code: value)
case let ("pasteboardCarbon", value):
return .pasteboardCarbon(code: value)
case let ("clipboardCarbon", value):
return .clipboardCarbon(code: value)
case let ("markdownPage", value):
return .markdownPage(playground: value)
case let ("playgroundBook", value):
Expand Down
10 changes: 5 additions & 5 deletions nef/Extensions/AppDelegate+Notifications.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Bow
import BowEffects

extension AppDelegate {
func pasteboardCarbonIO(data: Data) -> EnvIO<Clipboard.Config, Clipboard.Error, NSImage> {
func clipboardCarbonIO(data: Data) -> EnvIO<Clipboard.Config, Clipboard.Error, NSImage> {
func makeImage(_ data: Data) -> IO<Clipboard.Error, NSImage> {
data.makeImage().mapError { _ in .invalidData }
}
Expand All @@ -15,16 +15,16 @@ extension AppDelegate {

return binding(
image <- makeImage(data).env(),
|<-self.writeToPasteboard(image.get),
|<-self.writeToClipboard(image.get),
|<-self.removeOldNotifications(),
|<-self.showNotification(title: "nef",
body: "Image copied to pasteboard!",
body: "Image copied to clipboard!",
imageData: data,
actions: [.cancel, .saveImage]),
yield:image.get)^
}

private func writeToPasteboard(_ image: NSImage) -> EnvIO<Clipboard.Config, Clipboard.Error, Void> {
private func writeToClipboard(_ image: NSImage) -> EnvIO<Clipboard.Config, Clipboard.Error, Void> {
EnvIO.invoke { config in
config.clipboard.clearContents()
if !config.clipboard.writeObjects([image]) {
Expand Down Expand Up @@ -96,7 +96,7 @@ extension AppDelegate: UNUserNotificationCenterDelegate {
switch action {
case NefNotification.Action.saveImage.identifier:
return image
.persist (command: .pasteboardCarbon())
.persist (command: .clipboardCarbon())
.mapError { _ in .persistImage }
.contramap(\.openPanel)
.map { .saveImage($0) }^
Expand Down
2 changes: 1 addition & 1 deletion nef/Extensions/URL+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ extension URL {
func appendingCommandExtensionComponent(command: Command) -> URL {
let ext: String
switch command {
case .carbon, .pasteboardCarbon: ext = "jpg"
case .carbon, .clipboardCarbon: ext = "jpg"
case .markdownPage: ext = "md"
default: ext = ""
}
Expand Down
4 changes: 2 additions & 2 deletions nef/Utils/Command.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ enum Command: CustomStringConvertible {
case about
case preferences
case carbon(code: String)
case pasteboardCarbon(code: String = "")
case clipboardCarbon(code: String = "")
case markdownPage(playground: String)
case playgroundBook(package: String)
case notification(userInfo: [String: Any], action: String)
Expand All @@ -14,7 +14,7 @@ enum Command: CustomStringConvertible {
case .about: return "about"
case .preferences: return "preferences"
case .carbon: return "carbon"
case .pasteboardCarbon: return "pasteboardCarbon"
case .clipboardCarbon: return "clipboardCarbon"
case .markdownPage: return "markdown"
case .playgroundBook: return "playground-book"
case .notification: return "notification"
Expand Down

0 comments on commit f718c0f

Please sign in to comment.