From 2b1e04264c30fd69b0384e6335b4051139e5f34d Mon Sep 17 00:00:00 2001 From: Chris Wanstrath Date: Sat, 3 Sep 2011 23:18:52 -0700 Subject: [PATCH] kill Process, split into fs module and system module --- plugins/project/project.coffee | 6 +++--- plugins/tabs/tabs.coffee | 2 +- src/editor.coffee | 4 ++-- src/fs.coffee | 8 ++++++++ src/osx.coffee | 10 ---------- src/system.coffee | 7 +++++++ 6 files changed, 21 insertions(+), 16 deletions(-) create mode 100644 src/system.coffee diff --git a/plugins/project/project.coffee b/plugins/project/project.coffee index 6d26fdac5..b62b82248 100644 --- a/plugins/project/project.coffee +++ b/plugins/project/project.coffee @@ -1,7 +1,7 @@ $ = require 'jquery' _ = require 'underscore' -{Chrome, Process} = require 'osx' +{Chrome} = require 'osx' File = require 'fs' Editor = require 'editor' @@ -14,7 +14,7 @@ exports.init = -> @toggle() Editor.ace.on 'open', => - @reload() if @dir? and Process.cwd() isnt @dir + @reload() if @dir? and File.workingDirectory() isnt @dir $('#project .cwd').live 'click', (event) => Editor.open @dir.replace _.last(@dir.split '/'), '' @@ -36,7 +36,7 @@ exports.toggle = -> @showing = not @showing exports.reload = -> - @dir = dir = Process.cwd() + @dir = dir = File.workingDirectory() $('#project .cwd').text _.last dir.split '/' $('#project li').remove() diff --git a/plugins/tabs/tabs.coffee b/plugins/tabs/tabs.coffee index f9d036fad..e62bee973 100644 --- a/plugins/tabs/tabs.coffee +++ b/plugins/tabs/tabs.coffee @@ -1,7 +1,7 @@ $ = require 'jquery' _ = require 'underscore' -{Chrome, Process} = require 'osx' +{Chrome} = require 'osx' File = require 'fs' {bindKey} = require 'editor' diff --git a/src/editor.coffee b/src/editor.coffee index acf445971..71cdff1cd 100644 --- a/src/editor.coffee +++ b/src/editor.coffee @@ -3,7 +3,7 @@ $ = require 'jquery' _ = require 'underscore' -{Chrome, Process} = require 'osx' +{Chrome} = require 'osx' File = require 'fs' ace = require 'ace/ace' @@ -25,7 +25,7 @@ exports.open = open = (path) -> filename = path if File.isDir filename - Process.cwd filename + File.changeWorkingDirectory filename Chrome.title _.last filename.split '/' editor.getSession().setValue "" Chrome.setDirty false diff --git a/src/fs.coffee b/src/fs.coffee index 60fa2e426..68b19a8bb 100644 --- a/src/fs.coffee +++ b/src/fs.coffee @@ -12,6 +12,10 @@ module.exports = else path + # Set the current working directory to `path`. + changeWorkingDirectory: (path) -> + OSX.NSFileManager.defaultManager.changeCurrentDirectoryPath path + # Returns true if the file specified by path exists and is a # directory. isDirectory: (path) -> @@ -54,3 +58,7 @@ module.exports = write: (path, content) -> str = OSX.NSString.stringWithString content str.writeToFile_atomically @absolute(path), true + + # Return the path name of the current working directory. + workingDirectory: -> + OSX.NSFileManager.defaultManager.currentDirectoryPath.toString() \ No newline at end of file diff --git a/src/osx.coffee b/src/osx.coffee index 92785a89b..95acf0046 100644 --- a/src/osx.coffee +++ b/src/osx.coffee @@ -87,16 +87,6 @@ Chrome = appRoot: -> OSX.NSBundle.mainBundle.resourcePath -Process = - cwd: (path) -> - if path? - OSX.NSFileManager.defaultManager.changeCurrentDirectoryPath path - else - OSX.NSFileManager.defaultManager.currentDirectoryPath.toString() - - env: -> - OSX.NSProcess.processInfo.environment - exports.Chrome = Chrome exports.File = File exports.Dir = Dir diff --git a/src/system.coffee b/src/system.coffee new file mode 100644 index 000000000..bf1707baf --- /dev/null +++ b/src/system.coffee @@ -0,0 +1,7 @@ +# commonjs system module +# http://ringojs.org/api/v0.8/system/ + +module.exports = -> + # An object containing our environment variables. + env: -> + OSX.NSProcess.processInfo.environment