diff --git a/extensions-to-port/tabs/tabs.coffee b/extensions-to-port/tabs/tabs.coffee deleted file mode 100644 index d66cf58dd..000000000 --- a/extensions-to-port/tabs/tabs.coffee +++ /dev/null @@ -1,48 +0,0 @@ -$ = require 'jquery' - -Extension = require 'extension' -File = require 'fs' -TabsPane = require 'tabs/tabspane' - -module.exports = -class Tabs extends Extension - # The Editor pane we're managing. - editor: null - - keymap: -> - 'Command-W': 'closeActiveTab' - 'Command-Shift-[': 'prevTab' - 'Command-Shift-]': 'nextTab' - 'Command-1': -> @pane.switchToTab 1 - 'Command-2': -> @pane.switchToTab 2 - 'Command-3': -> @pane.switchToTab 3 - 'Command-4': -> @pane.switchToTab 4 - 'Command-5': -> @pane.switchToTab 5 - 'Command-6': -> @pane.switchToTab 6 - 'Command-7': -> @pane.switchToTab 7 - 'Command-8': -> @pane.switchToTab 8 - 'Command-9': -> @pane.switchToTab 9 - - constructor: (args...) -> - super args... - - @pane = new TabsPane @window, @ - @pane.toggle() - - @window.on 'open', ({filename}) => - return if File.isDirectory filename # Ignore directories - @pane.addTab filename - - @window.on 'close', ({filename}) => - @pane.removeTab filename - - # Move all of this methods below to pane? I think so - closeActiveTab: -> - activeTab = $('#tabs ul .active') - @window.close activeTab.data 'path' - - nextTab: -> - @pane.switchToTab $('#tabs ul .active').next() - - prevTab: -> - @switchToTab $('#tabs ul .active').prev() diff --git a/extensions-to-port/tabs/index.coffee b/extensions/tabs/index.coffee similarity index 100% rename from extensions-to-port/tabs/index.coffee rename to extensions/tabs/index.coffee diff --git a/extensions/tabs/key-bindings.coffee b/extensions/tabs/key-bindings.coffee new file mode 100644 index 000000000..e7baf290a --- /dev/null +++ b/extensions/tabs/key-bindings.coffee @@ -0,0 +1,14 @@ +tabs: + 'cmd-w': (tabs) -> tabs.pane.closeActiveTab() + 'cmd-shift-[': (tabs) -> tabs.pane.prevTab() + 'cmd-shift-]': (tabs) -> tabs.pane.nextTab() + 'cmd-1': (tabs) -> tabs.pane.switchToTab 1 + 'cmd-2': (tabs) -> tabs.pane.switchToTab 2 + 'cmd-3': (tabs) -> tabs.pane.switchToTab 3 + 'cmd-4': (tabs) -> tabs.pane.switchToTab 4 + 'cmd-5': (tabs) -> tabs.pane.switchToTab 5 + 'cmd-6': (tabs) -> tabs.pane.switchToTab 6 + 'cmd-7': (tabs) -> tabs.pane.switchToTab 7 + 'cmd-8': (tabs) -> tabs.pane.switchToTab 8 + 'cmd-9': (tabs) -> tabs.pane.switchToTab 9 + diff --git a/extensions/tabs/tabs.coffee b/extensions/tabs/tabs.coffee new file mode 100644 index 000000000..d5a020a4a --- /dev/null +++ b/extensions/tabs/tabs.coffee @@ -0,0 +1,28 @@ +$ = require 'jquery' + +Extension = require 'extension' +KeyBinder = require 'key-binder' +Event = require 'event' +TabsPane = require 'tabs/tabspane' + +fs = require 'fs' + +module.exports = +class Tabs extends Extension + constructor: () -> + KeyBinder.register "tabs", @ + KeyBinder.load require.resolve "tabs/key-bindings.coffee" + + @pane = new TabsPane @ + + Event.on 'window:open', (e) => + path = e.details + return if fs.isDirectory path # Ignore directories + @pane.addTab path + + Event.on 'editor:close', (e) => + path = e.details + @pane.removeTab path + + startup: -> + @pane.show() \ No newline at end of file diff --git a/extensions-to-port/tabs/tabs.css b/extensions/tabs/tabs.css similarity index 100% rename from extensions-to-port/tabs/tabs.css rename to extensions/tabs/tabs.css diff --git a/extensions-to-port/tabs/tabs.html b/extensions/tabs/tabs.html similarity index 100% rename from extensions-to-port/tabs/tabs.html rename to extensions/tabs/tabs.html diff --git a/extensions-to-port/tabs/tabsPane.coffee b/extensions/tabs/tabsPane.coffee similarity index 78% rename from extensions-to-port/tabs/tabsPane.coffee rename to extensions/tabs/tabsPane.coffee index 5eb9781e2..acf900d60 100644 --- a/extensions-to-port/tabs/tabsPane.coffee +++ b/extensions/tabs/tabsPane.coffee @@ -2,7 +2,6 @@ $ = require 'jquery' _ = require 'underscore' Pane = require 'pane' -File = require 'fs' module.exports = class TabsPane extends Pane @@ -10,9 +9,7 @@ class TabsPane extends Pane html: $ require 'tabs/tabs.html' - constructor: (@window, @tabs) -> - super @window - + constructor: -> # Style html @html.parents('.pane').css height: 'inherit' css = $('').html require 'tabs/tabs.css' @@ -20,17 +17,27 @@ class TabsPane extends Pane # click tab tabPane = this - $('#tabs ul li').live 'click', -> + $('#tabs ul li').live 'mousedown', -> tabPane.switchToTab this false + closeActiveTab: -> + activeTab = $('#tabs ul .active') + window.editor.close activeTab.data 'path' + + nextTab: -> + @switchToTab $('#tabs ul .active').next() + + prevTab: -> + @switchToTab $('#tabs ul .active').prev() + switchToTab: (tab) -> tab = $("#tabs ul li").get(tab - 1) if _.isNumber tab return if tab.length is 0 $("#tabs ul .active").removeClass("active") $(tab).addClass 'active' - @window.open $(tab).data 'path' + window.editor.open $(tab).data 'path' addTab: (path) -> existing = $("#tabs [data-path='#{path}']") diff --git a/src/editor.coffee b/src/editor.coffee index a3e28e814..5267e8b3e 100644 --- a/src/editor.coffee +++ b/src/editor.coffee @@ -64,7 +64,9 @@ class Editor @ace.getSession().setMode new mode open: (path) -> - if not path or fs.isDirectory path + return if fs.isDirectory path + + if not path @activePath = null @ace.setSession @newSession() else @@ -85,7 +87,7 @@ class Editor # ICK, clean this up... too many assumptions being made session = @sessions[path] - if not session or session.$atom_dirty + if session?.$atom_dirty or (not session and @code.length > 0) detailedMessage = if @activePath "#{@activePath} has changes." else diff --git a/src/event.coffee b/src/event.coffee index 7220c548c..5ce4e293b 100644 --- a/src/event.coffee +++ b/src/event.coffee @@ -13,6 +13,7 @@ class Event window.document.removeEventListener name, callback @trigger: (name, data, bubbleToApp=true) -> + console.log name if bubbleToApp and name.match /^app:/ OSX.NSApp.triggerGlobalEvent_data name, data return diff --git a/src/extension.coffee b/src/extension.coffee index ba5adbdfe..cb3bd0975 100644 --- a/src/extension.coffee +++ b/src/extension.coffee @@ -1,18 +1,12 @@ KeyBinder = require 'key-binder' -App = require 'app' fs = require 'fs' module.exports = class Extension constructor: -> - console.log "#{@.constructor.name}: Loaded" - register @identifier(), @ + console.log "#{@constructor.name}: Loaded" - # Unique key for the extension. Used in key bindings and settings. - identifier: -> - throw "#{@constructor.name}: You have to supply a unique identifier to extensions" - - storageNamespace: -> "storage-#{@identifier()}" + storageNamespace: -> @constructor.name startup: -> diff --git a/src/key-binder.coffee b/src/key-binder.coffee index beebd624c..040d617e5 100644 --- a/src/key-binder.coffee +++ b/src/key-binder.coffee @@ -57,7 +57,11 @@ class KeyBinder return false if not callbacks # Only use the most recently added binding - _.last(callbacks)() + try + _.last(callbacks)() + catch e + console.warn "Failed to run binding #{binding}. #{e}" + true @bindingParser: (binding) -> diff --git a/src/pane.coffee b/src/pane.coffee index e13f57549..ce9388cb0 100644 --- a/src/pane.coffee +++ b/src/pane.coffee @@ -30,10 +30,16 @@ class Pane else throw "I DON'T KNOW HOW TO DEAL WITH #{@position}" + show: -> + @add this + @showing = true + + hide: -> + @html.parent().detach() + @showing = false + toggle: -> if @showing - @html.parent().detach() + @hide() else - @add this - - @showing = not @showing + @show() diff --git a/src/require.coffee b/src/require.coffee index 21c50568b..9e92e2d68 100644 --- a/src/require.coffee +++ b/src/require.coffee @@ -1,4 +1,5 @@ -resourcePath = OSX.NSBundle.mainBundle.resourcePath +#resourcePath = OSX.NSBundle.mainBundle.resourcePath +resourcePath = "/Users/corey/code/mine/Atomicity" paths = [ "#{resourcePath}/src" diff --git a/src/window.coffee b/src/window.coffee index 43699b811..f3c9cae22 100644 --- a/src/window.coffee +++ b/src/window.coffee @@ -1,4 +1,5 @@ Editor = require 'editor' +Extension = require 'extension' Event = require 'event' KeyBinder = require 'key-binder' Native = require 'native' @@ -15,13 +16,13 @@ windowAdditions = appRoot: OSX.NSBundle.mainBundle.resourcePath startup: () -> + KeyBinder.register "window", window + if atomController.path @setRecentPath atomController.path else atomController.path = @recentPath() - KeyBinder.register "window", window - @editor = if atomController.path and fs.isFile atomController.path new Editor atomController.path else @@ -32,7 +33,6 @@ windowAdditions = Event.on "editor:open", (e) => path = e.details - console.log path basename = fs.base path @setTitle basename @@ -47,7 +47,7 @@ windowAdditions = for extensionPath in extensionPaths when fs.isDirectory extensionPath try extension = require extensionPath - extensions.push new Extension() + extensions.push new extension() catch error console.warn "window: Loading Extension #{fs.base extensionPath} failed." console.warn error @@ -100,8 +100,6 @@ windowAdditions = parent = atomController.path.replace(/([^\/])$/, "$1/") child = path.replace(/([^\/])$/, "$1/") - console.log parent - console.log child window.x = parent window.y = child