mirror of
https://github.com/atom/atom.git
synced 2026-01-24 06:18:03 -05:00
atom.native
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user