Skip to content

Commit

Permalink
Better Open experience
Browse files Browse the repository at this point in the history
  • Loading branch information
yongkangchen committed Jul 8, 2014
1 parent 0793f29 commit ddfe1dc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/browser/atom-application.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@ class AtomApplication
for atomWindow in @windows
return atomWindow if atomWindow.containsPath(pathToOpen)

for atomWindow in @windows
if not atomWindow.getInitialPath(pathToOpen)
atomWindow.setInitiaPath(pathToOpen)
return atomWindow

# Public: Returns the currently focused {AtomWindow} or undefined if none.
focusedWindow: ->
_.find @windows, (atomWindow) -> atomWindow.isFocused()
Expand Down
12 changes: 8 additions & 4 deletions src/browser/atom-window.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,9 @@ class AtomWindow
@constructor.includeShellLoadTime = false
loadSettings.shellLoadTime ?= Date.now() - global.shellStartTime

loadSettings.initialPath = pathToOpen
if fs.statSyncNoException(pathToOpen).isFile?()
loadSettings.initialPath = path.dirname(pathToOpen)

@browserWindow.loadSettings = loadSettings
@setInitiaPath(pathToOpen)

@browserWindow.once 'window:loaded', =>
@emit 'window:loaded'
@loaded = true
Expand All @@ -69,6 +67,12 @@ class AtomWindow
getInitialPath: ->
@browserWindow.loadSettings.initialPath

setInitiaPath: (pathToOpen) ->
loadSettings = @browserWindow.loadSettings
loadSettings.initialPath = pathToOpen
if fs.statSyncNoException(pathToOpen).isFile?()
loadSettings.initialPath = path.dirname(pathToOpen)

containsPath: (pathToCheck) ->
initialPath = @getInitialPath()
if not initialPath
Expand Down
5 changes: 4 additions & 1 deletion src/window-event-handler.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ class WindowEventHandler
@subscribe $(window), 'blur', -> $("body").addClass('is-blurred')

@subscribe $(window), 'window:open-path', (event, {pathToOpen, initialLine, initialColumn}) ->
unless fs.isDirectorySync(pathToOpen)
if not fs.isDirectorySync(pathToOpen)

This comment has been minimized.

Copy link
@thomasjo

thomasjo Aug 4, 2014

Why did you change it from unless to if not? The former is idiomatic CoffeeScript, the latter less so.

This comment has been minimized.

Copy link
@yongkangchen

yongkangchen Aug 4, 2014

Author Owner

Indeed, I just know unless can work with else. I'm quite new to CoffeeScript.

This comment has been minimized.

Copy link
@philipgiuliani

philipgiuliani Aug 5, 2014

Some style guides also say that you should never use unless with a else. Its easier to understand if you have a if not

This comment has been minimized.

Copy link
@yongkangchen

yongkangchen Aug 5, 2014

Author Owner

👍 I indeed feel more comfortable of if not else than odd unless else

atom.workspace?.open(pathToOpen, {initialLine, initialColumn})
else
atom.project?.setPath(pathToOpen)
atom.workspaceView?.trigger "tree-view:show"

@subscribe $(window), 'beforeunload', =>
confirmed = atom.workspaceView?.confirmClose()
Expand Down

0 comments on commit ddfe1dc

Please sign in to comment.