From 7425aec186b5d580382d85be5989e04ec45e2eaf Mon Sep 17 00:00:00 2001 From: Chris Wanstrath Date: Wed, 9 Nov 2011 12:16:15 -0800 Subject: [PATCH] atom.native --- src/editor.coffee | 9 ++++----- src/native.coffee | 12 ++++++------ src/startup.coffee | 2 ++ 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/editor.coffee b/src/editor.coffee index ebe6f96ec..cb1a68c6d 100644 --- a/src/editor.coffee +++ b/src/editor.coffee @@ -5,7 +5,6 @@ ace = require 'ace/ace' Event = require 'event' KeyBinder = require 'key-binder' -Native = require 'native' Storage = require 'storage' Pane = require 'pane' @@ -133,7 +132,7 @@ class Editor extends Pane else "An untitled file has changes." - canceled = Native.alert "Do you want to save the changes you made?", detailedMessage, + canceled = atom.native.alert "Do you want to save the changes you made?", detailedMessage, "Save": => path = @save() not path # if save modal fails/cancels, consider it canceled @@ -180,7 +179,7 @@ class Editor extends Pane path saveAs: -> - path = Native.savePanel()?.toString() + path = atom.native.savePanel()?.toString() if path @save path @addBuffer path @@ -213,11 +212,11 @@ class Editor extends Pane copy: -> text = @ace.getSession().doc.getTextRange @ace.getSelectionRange() - Native.writeToPasteboard text + atom.native.writeToPasteboard text cut: -> text = @ace.getSession().doc.getTextRange @ace.getSelectionRange() - Native.writeToPasteboard text + atom.native.writeToPasteboard text @ace.session.remove @ace.getSelectionRange() eval: -> eval @code() diff --git a/src/native.coffee b/src/native.coffee index 8a9765694..567e354ac 100644 --- a/src/native.coffee +++ b/src/native.coffee @@ -1,6 +1,6 @@ module.exports = class Native - @alert: (message, detailedMessage, buttons) -> + alert: (message, detailedMessage, buttons) -> alert = OSX.NSAlert.alloc.init alert.setMessageText message alert.setInformativeText detailedMessage @@ -13,13 +13,13 @@ class Native return callbacks[buttonTag]() # path - Optional. The String path to the file to base it on. - @newWindow: (path) -> + newWindow: (path) -> controller = OSX.NSApp.createController path controller.window controller.window.makeKeyAndOrderFront null # Returns null or a file path. - @openPanel: -> + openPanel: -> panel = OSX.NSOpenPanel.openPanel panel.setCanChooseDirectories true if panel.runModal isnt OSX.NSFileHandlingPanelOKButton @@ -28,18 +28,18 @@ class Native localStorage.lastOpenedPath = filename filename.toString() - @openURL: (url) -> + openURL: (url) -> window.location = url atom.app.activeWindow.setTitle _.last url.replace(/\/$/,'').split '/' # Returns null or a file path. - @savePanel: -> + savePanel: -> panel = OSX.NSSavePanel.savePanel if panel.runModal isnt OSX.NSFileHandlingPanelOKButton return null panel.filenames.lastObject - @writeToPasteboard: (text) -> + writeToPasteboard: (text) -> pb = OSX.NSPasteboard.generalPasteboard pb.declareTypes_owner [OSX.NSStringPboardType], null pb.setString_forType text, OSX.NSStringPboardType diff --git a/src/startup.coffee b/src/startup.coffee index 928d68935..4f54d8a76 100644 --- a/src/startup.coffee +++ b/src/startup.coffee @@ -1,6 +1,8 @@ # Like sands through the hourglass, so are the days of our lives. App = require 'app' +Native = require 'native' window.atom = {} window.atom.app = new App +window.atom.native = new Native \ No newline at end of file