From 66cb0a6a77848327d6020477aa5886c1f9363ba3 Mon Sep 17 00:00:00 2001 From: Ben Gotow Date: Wed, 4 May 2016 14:27:46 -0700 Subject: [PATCH] rm(*): deprecated/unused Atom code, user stylesheet support --- .../mode-switch/lib/mode-switch.cjsx | 79 ---------- menus/darwin.json | 5 +- spec/clipboard-spec.coffee | 12 -- .../theme-with-syntax-variables/package.json | 4 - .../styles/editor.less | 0 spec/styles-element-spec.coffee | 36 ----- spec/theme-manager-spec.coffee | 137 +----------------- src/browser/context-menu.coffee | 24 --- src/browser/nylas-window.coffee | 9 -- src/clipboard.coffee | 57 -------- src/nylas-env.coffee | 5 - src/package-manager.coffee | 21 --- src/package.coffee | 11 -- src/react-remote/selection-listeners.js | 78 ---------- src/space-pen-utils.js | 117 --------------- src/style-manager.coffee | 14 -- src/styles-element.coffee | 34 ----- src/theme-manager.coffee | 134 +---------------- src/window-event-handler.coffee | 8 - 19 files changed, 6 insertions(+), 779 deletions(-) delete mode 100644 internal_packages/mode-switch/lib/mode-switch.cjsx delete mode 100644 spec/clipboard-spec.coffee delete mode 100755 spec/fixtures/packages/theme-with-syntax-variables/package.json delete mode 100755 spec/fixtures/packages/theme-with-syntax-variables/styles/editor.less delete mode 100644 src/browser/context-menu.coffee delete mode 100644 src/clipboard.coffee delete mode 100644 src/react-remote/selection-listeners.js delete mode 100644 src/space-pen-utils.js diff --git a/internal_packages/mode-switch/lib/mode-switch.cjsx b/internal_packages/mode-switch/lib/mode-switch.cjsx deleted file mode 100644 index 496b97b4f..000000000 --- a/internal_packages/mode-switch/lib/mode-switch.cjsx +++ /dev/null @@ -1,79 +0,0 @@ -{ComponentRegistry, - WorkspaceStore, - Actions} = require "nylas-exports" -{RetinaImg} = require 'nylas-component-kit' -React = require "react" -_ = require "underscore" - - -## -## THIS FILE IS NOT IN USE! DEPRECATED IN FAVOR OF ModeToggle -## - -class ModeSwitch extends React.Component - @displayName: 'ModeSwitch' - - constructor: (@props) -> - @state = @_getStateFromStores() - - componentDidMount: => - @unsubscribe = WorkspaceStore.listen @_onStateChanged - - componentWillUnmount: => - @unsubscribe?() - - render: => - return
unless @state.visible - - knobX = if @state.mode is 'list' then 25 else 41 - - # Currently ModeSwitch is an opaque control that is not intended - # to be styled, hence the fixed margins and positions. If we - # turn this into a standard component one day, change! -
- - - - -
- - _onStateChanged: => - @setState(@_getStateFromStores()) - - _getStateFromStores: => - rootModes = WorkspaceStore.rootSheet().supportedModes - rootVisible = WorkspaceStore.rootSheet() is WorkspaceStore.topSheet() - - mode: WorkspaceStore.layoutMode() - visible: rootVisible and rootModes and rootModes.length > 1 - - _onToggleMode: => - if @state.mode is 'list' - Actions.selectLayoutMode('split') - else - Actions.selectLayoutMode('list') - - _onSetMode: (event) => - Actions.selectLayoutMode(event.target.dataset.mode) - event.stopPropagation() - - -module.exports = ModeSwitch diff --git a/menus/darwin.json b/menus/darwin.json index 72610b56c..0494f349b 100644 --- a/menus/darwin.json +++ b/menus/darwin.json @@ -123,8 +123,5 @@ { "label": "Nylas N1 Help", "command": "application:view-help" } ] } -], - -"context-menu": [ -] + ] } diff --git a/spec/clipboard-spec.coffee b/spec/clipboard-spec.coffee deleted file mode 100644 index ffa73cd06..000000000 --- a/spec/clipboard-spec.coffee +++ /dev/null @@ -1,12 +0,0 @@ -describe "Clipboard", -> - describe "write(text, metadata) and read()", -> - it "writes and reads text to/from the native clipboard", -> - expect(NylasEnv.clipboard.read()).toBe 'initial clipboard content' - NylasEnv.clipboard.write('next') - expect(NylasEnv.clipboard.read()).toBe 'next' - - it "returns metadata if the item on the native clipboard matches the last written item", -> - NylasEnv.clipboard.write('next', {meta: 'data'}) - expect(NylasEnv.clipboard.read()).toBe 'next' - expect(NylasEnv.clipboard.readWithMetadata().text).toBe 'next' - expect(NylasEnv.clipboard.readWithMetadata().metadata).toEqual {meta: 'data'} diff --git a/spec/fixtures/packages/theme-with-syntax-variables/package.json b/spec/fixtures/packages/theme-with-syntax-variables/package.json deleted file mode 100755 index 7f8bafacb..000000000 --- a/spec/fixtures/packages/theme-with-syntax-variables/package.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "theme": "syntax", - "styleSheets": ["editor.less"] -} diff --git a/spec/fixtures/packages/theme-with-syntax-variables/styles/editor.less b/spec/fixtures/packages/theme-with-syntax-variables/styles/editor.less deleted file mode 100755 index e69de29bb..000000000 diff --git a/spec/styles-element-spec.coffee b/spec/styles-element-spec.coffee index 5f1f666cf..25e05d313 100644 --- a/spec/styles-element-spec.coffee +++ b/spec/styles-element-spec.coffee @@ -76,39 +76,3 @@ describe "StylesElement", -> expect(element.children.length).toBe 2 expect(element.children[0].textContent).toBe "a {color: red;}" expect(element.children[1].textContent).toBe "a {color: blue;}" - - describe "nylas-theme-wrap shadow DOM selector upgrades", -> - beforeEach -> - element.setAttribute('context', 'nylas-theme-wrap') - spyOn(console, 'warn') - - it "upgrades selectors containing .editor-colors", -> - NylasEnv.styles.addStyleSheet(".editor-colors {background: black;}", context: 'nylas-theme-wrap') - expect(element.firstChild.sheet.cssRules[0].selectorText).toBe ':host' - - it "upgrades selectors containing .editor", -> - NylasEnv.styles.addStyleSheet """ - .editor {background: black;} - .editor.mini {background: black;} - .editor:focus {background: black;} - """, context: 'nylas-theme-wrap' - - expect(element.firstChild.sheet.cssRules[0].selectorText).toBe ':host' - expect(element.firstChild.sheet.cssRules[1].selectorText).toBe ':host(.mini)' - expect(element.firstChild.sheet.cssRules[2].selectorText).toBe ':host(:focus)' - - it "defers selector upgrade until the element is attached", -> - element = new StylesElement - element.setAttribute('context', 'nylas-theme-wrap') - element.initialize() - - NylasEnv.styles.addStyleSheet ".editor {background: black;}", context: 'nylas-theme-wrap' - expect(element.firstChild.sheet).toBeNull() - - document.querySelector('#jasmine-content').appendChild(element) - expect(element.firstChild.sheet.cssRules[0].selectorText).toBe ':host' - - it "does not throw exceptions on rules with no selectors", -> - NylasEnv.styles.addStyleSheet """ - @media screen {font-size: 10px;} - """, context: 'nylas-theme-wrap' diff --git a/spec/theme-manager-spec.coffee b/spec/theme-manager-spec.coffee index e203f861d..31b935671 100644 --- a/spec/theme-manager-spec.coffee +++ b/spec/theme-manager-spec.coffee @@ -88,7 +88,6 @@ describe "ThemeManager", -> describe "when the core.themes config value changes", -> it "add/removes stylesheets to reflect the new config value", -> themeManager.onDidChangeActiveThemes didChangeActiveThemesHandler = jasmine.createSpy() - spyOn(NylasEnv.styles, 'getUserStyleSheetPath').andCallFake -> null waitsForPromise -> themeManager.activateThemes() @@ -147,17 +146,13 @@ describe "ThemeManager", -> expect(importPaths[0]).toContain 'ui-light' it 'adds theme-* classes to the workspace for each active theme', -> - workspaceElement = document.createElement('nylas-workspace') - jasmine.attachToDOM(workspaceElement) - themeManager.onDidChangeActiveThemes didChangeActiveThemesHandler = jasmine.createSpy() waitsForPromise -> themeManager.activateThemes() runs -> - expect(workspaceElement.classList.contains('theme-ui-light')).toBe(true) - + expect(document.body.classList.contains('theme-ui-light')).toBe(true) themeManager.onDidChangeActiveThemes didChangeActiveThemesHandler = jasmine.createSpy() NylasEnv.config.set('core.themes', ['theme-with-ui-variables']) @@ -166,8 +161,8 @@ describe "ThemeManager", -> runs -> # `theme-` twice as it prefixes the name with `theme-` - expect(workspaceElement.classList.contains('theme-theme-with-ui-variables')).toBe(true) - expect(workspaceElement.classList.contains('theme-ui-dark')).toBe(false) + expect(document.body.classList.contains('theme-theme-with-ui-variables')).toBe(true) + expect(document.body.classList.contains('theme-ui-dark')).toBe(false) describe "when a theme fails to load", -> it "logs a warning", -> @@ -184,8 +179,6 @@ describe "ThemeManager", -> it "synchronously loads css at the given path and installs a style tag for it in the head", -> NylasEnv.styles.onDidAddStyleElement styleElementAddedHandler = jasmine.createSpy("styleElementAddedHandler") - themeManager.onDidChangeStylesheets stylesheetsChangedHandler = jasmine.createSpy("stylesheetsChangedHandler") - themeManager.onDidAddStylesheet stylesheetAddedHandler = jasmine.createSpy("stylesheetAddedHandler") cssPath = path.join(__dirname, 'fixtures', 'css.css') lengthBefore = document.querySelectorAll('head style').length @@ -194,8 +187,6 @@ describe "ThemeManager", -> expect(document.querySelectorAll('head style').length).toBe lengthBefore + 1 expect(styleElementAddedHandler).toHaveBeenCalled() - expect(stylesheetAddedHandler).toHaveBeenCalled() - expect(stylesheetsChangedHandler).toHaveBeenCalled() element = document.querySelector('head style[source-path*="css.css"]') expect(element.getAttribute('source-path')).toBe themeManager.stringToId(cssPath) @@ -250,20 +241,10 @@ describe "ThemeManager", -> expect(window.getComputedStyle(document.body)['font-weight']).toBe("bold") NylasEnv.styles.onDidRemoveStyleElement styleElementRemovedHandler = jasmine.createSpy("styleElementRemovedHandler") - themeManager.onDidRemoveStylesheet stylesheetRemovedHandler = jasmine.createSpy("stylesheetRemovedHandler") - themeManager.onDidChangeStylesheets stylesheetsChangedHandler = jasmine.createSpy("stylesheetsChangedHandler") - disposable.dispose() expect(window.getComputedStyle(document.body)['font-weight']).not.toBe("bold") - expect(styleElementRemovedHandler).toHaveBeenCalled() - expect(stylesheetRemovedHandler).toHaveBeenCalled() - stylesheet = stylesheetRemovedHandler.argsForCall[0][0] - expect(stylesheet instanceof CSSStyleSheet).toBe true - expect(stylesheet.cssRules[0].selectorText).toBe 'body' - - expect(stylesheetsChangedHandler).toHaveBeenCalled() describe "base style sheet loading", -> workspaceElement = null @@ -316,118 +297,6 @@ describe "ThemeManager", -> nodeStyle = window.getComputedStyle(node) expect(nodeStyle['background-color']).toBe "rgb(152, 123, 0)" - describe "user stylesheet", -> - userStylesheetPath = null - beforeEach -> - userStylesheetPath = path.join(temp.mkdirSync("nylas-spec"), 'styles.less') - fs.writeFileSync(userStylesheetPath, 'body {border-style: dotted !important;}') - spyOn(NylasEnv.styles, 'getUserStyleSheetPath').andReturn userStylesheetPath - - describe "when the user stylesheet changes", -> - beforeEach -> - jasmine.snapshotDeprecations() - - afterEach -> - jasmine.restoreDeprecationsSnapshot() - - it "reloads it", -> - [styleElementAddedHandler, styleElementRemovedHandler] = [] - [stylesheetRemovedHandler, stylesheetAddedHandler, stylesheetsChangedHandler] = [] - - waitsForPromise -> - themeManager.activateThemes().then -> - - runs -> - NylasEnv.styles.onDidRemoveStyleElement styleElementRemovedHandler = jasmine.createSpy("styleElementRemovedHandler") - NylasEnv.styles.onDidAddStyleElement styleElementAddedHandler = jasmine.createSpy("styleElementAddedHandler") - - themeManager.onDidChangeStylesheets stylesheetsChangedHandler = jasmine.createSpy("stylesheetsChangedHandler") - themeManager.onDidRemoveStylesheet stylesheetRemovedHandler = jasmine.createSpy("stylesheetRemovedHandler") - themeManager.onDidAddStylesheet stylesheetAddedHandler = jasmine.createSpy("stylesheetAddedHandler") - spyOn(themeManager, 'loadUserStylesheet').andCallThrough() - - bodyStyle = window.getComputedStyle(document.body) - expect(bodyStyle['border-style']).toBe "dotted" - fs.writeFileSync(userStylesheetPath, 'body {border-style: dashed}') - - waitsFor -> - themeManager.loadUserStylesheet.callCount is 1 - - runs -> - bodyStyle = window.getComputedStyle(document.body) - expect(bodyStyle['border-style']).toBe "dashed" - - expect(styleElementRemovedHandler).toHaveBeenCalled() - expect(styleElementRemovedHandler.argsForCall[0][0].textContent).toContain 'dotted' - expect(stylesheetRemovedHandler).toHaveBeenCalled() - - match = null - for rule in stylesheetRemovedHandler.argsForCall[0][0].cssRules - match = rule if rule.selectorText is 'body' - expect(match.style.border).toBe 'dotted' - - expect(styleElementAddedHandler).toHaveBeenCalled() - expect(styleElementAddedHandler.argsForCall[0][0].textContent).toContain 'dashed' - expect(stylesheetAddedHandler).toHaveBeenCalled() - match = null - for rule in stylesheetAddedHandler.argsForCall[0][0].cssRules - match = rule if rule.selectorText is 'body' - expect(match.style.border).toBe 'dashed' - - expect(stylesheetsChangedHandler).toHaveBeenCalled() - - styleElementRemovedHandler.reset() - stylesheetRemovedHandler.reset() - stylesheetsChangedHandler.reset() - fs.removeSync(userStylesheetPath) - - waitsFor -> - themeManager.loadUserStylesheet.callCount is 2 - - runs -> - expect(styleElementRemovedHandler).toHaveBeenCalled() - expect(styleElementRemovedHandler.argsForCall[0][0].textContent).toContain 'dashed' - expect(stylesheetRemovedHandler).toHaveBeenCalled() - - waitsFor -> - match = null - for rule in stylesheetRemovedHandler.argsForCall[0][0].cssRules - match = rule if rule.selectorText is 'body' - - bodyStyle = window.getComputedStyle(document.body) - match.style.border is 'dashed' and bodyStyle['border-style'] is 'none' - - runs -> - expect(stylesheetsChangedHandler).toHaveBeenCalled() - - describe "when there is an error reading the stylesheet", -> - addErrorHandler = null - beforeEach -> - themeManager.loadUserStylesheet() - spyOn(themeManager.lessCache, 'cssForFile').andCallFake -> - throw new Error('EACCES permission denied "styles.less"') - - it "creates an error notification and does not add the stylesheet", -> - themeManager.loadUserStylesheet() - expect(console.error).toHaveBeenCalled() - note = console.error.mostRecentCall.args[0] - expect(note).toEqual 'EACCES permission denied "styles.less"' - expect(NylasEnv.styles.styleElementsBySourcePath[NylasEnv.styles.getUserStyleSheetPath()]).toBeUndefined() - - describe "when there is an error watching the user stylesheet", -> - addErrorHandler = null - beforeEach -> - {File} = require 'pathwatcher' - spyOn(File::, 'onDidChange').andCallFake (event) -> - throw new Error('Unable to watch path') - spyOn(themeManager, 'loadStylesheet').andReturn '' - - it "creates an error notification", -> - themeManager.loadUserStylesheet() - expect(console.error).toHaveBeenCalled() - note = console.error.mostRecentCall.args[0] - expect(note).toEqual 'Error: Unable to watch path' - describe "when a non-existent theme is present in the config", -> beforeEach -> NylasEnv.config.set('core.themes', ['non-existent-dark-ui']) diff --git a/src/browser/context-menu.coffee b/src/browser/context-menu.coffee deleted file mode 100644 index 8ddc79a7a..000000000 --- a/src/browser/context-menu.coffee +++ /dev/null @@ -1,24 +0,0 @@ -{Menu} = require 'electron' - -module.exports = -class ContextMenu - constructor: (template, @nylasWindow) -> - template = @createClickHandlers(template) - menu = Menu.buildFromTemplate(template) - menu.popup(@nylasWindow.browserWindow) - - # It's necessary to build the event handlers in this process, otherwise - # closures are dragged across processes and failed to be garbage collected - # appropriately. - createClickHandlers: (template) -> - for item in template - if item.command - item.commandDetail ?= {} - item.commandDetail.contextCommand = true - item.commandDetail.nylasWindow = @nylasWindow - do (item) => - item.click = => - global.application.sendCommandToWindow(item.command, @nylasWindow, item.commandDetail) - else if item.submenu - @createClickHandlers(item.submenu) - item diff --git a/src/browser/nylas-window.coffee b/src/browser/nylas-window.coffee index e25d92bf0..6d2d23e6a 100644 --- a/src/browser/nylas-window.coffee +++ b/src/browser/nylas-window.coffee @@ -140,13 +140,6 @@ class NylasWindow slashes: true query: {loadSettings: JSON.stringify(loadSettings)} - setupContextMenu: -> - ContextMenu = null - - @browserWindow.on 'context-menu', (menuTemplate) => - ContextMenu ?= require './context-menu' - new ContextMenu(menuTemplate, this) - handleEvents: -> # Also see logic in `NylasEnv::onBeforeUnload` and # `WindowEventHandler::AddUnloadCallback`. Classes like the DraftStore @@ -217,8 +210,6 @@ class NylasWindow when 0 then @browserWindow.destroy() when 1 then @browserWindow.reload() - @setupContextMenu() - if @isSpec # Workaround for https://github.com/atom/electron/issues/380 # Don't focus the window when it is being blurred during close or diff --git a/src/clipboard.coffee b/src/clipboard.coffee deleted file mode 100644 index 2145a0396..000000000 --- a/src/clipboard.coffee +++ /dev/null @@ -1,57 +0,0 @@ -{clipboard} = require 'electron' -crypto = require 'crypto' - -# Extended: Represents the clipboard used for copying and pasting in Nylas N1. -# -# An instance of this class is always available as the `NylasEnv.clipboard` global. -# -# ## Examples -# -# ```coffee -# NylasEnv.clipboard.write('hello') -# -# console.log(NylasEnv.clipboard.read()) # 'hello' -# ``` -module.exports = -class Clipboard - metadata: null - signatureForMetadata: null - - # Creates an `md5` hash of some text. - # - # * `text` A {String} to hash. - # - # Returns a hashed {String}. - md5: (text) -> - crypto.createHash('md5').update(text, 'utf8').digest('hex') - - # Public: Write the given text to the clipboard. - # - # The metadata associated with the text is available by calling - # {::readWithMetadata}. - # - # * `text` The {String} to store. - # * `metadata` The additional info to associate with the text. - write: (text, metadata) -> - @signatureForMetadata = @md5(text) - @metadata = metadata - clipboard.writeText(text) - - # Public: Read the text from the clipboard. - # - # Returns a {String}. - read: -> - clipboard.readText() - - # Public: Read the text from the clipboard and return both the text and the - # associated metadata. - # - # Returns an {Object} with the following keys: - # * `text` The {String} clipboard text. - # * `metadata` The metadata stored by an earlier call to {::write}. - readWithMetadata: -> - text = @read() - if @signatureForMetadata is @md5(text) - {text, @metadata} - else - {text} diff --git a/src/nylas-env.coffee b/src/nylas-env.coffee index be2ef35af..4c8aab152 100644 --- a/src/nylas-env.coffee +++ b/src/nylas-env.coffee @@ -103,9 +103,6 @@ class NylasEnvConstructor # Public: A {Config} instance config: null - # Public: A {Clipboard} instance - clipboard: null - # Public: A {MenuManager} instance menu: null @@ -151,7 +148,6 @@ class NylasEnvConstructor KeymapManager = require './keymap-manager' CommandRegistry = require './command-registry' PackageManager = require './package-manager' - Clipboard = require './clipboard' ThemeManager = require './theme-manager' StyleManager = require './style-manager' ActionBridge = require './flux/action-bridge' @@ -187,7 +183,6 @@ class NylasEnvConstructor @styles = new StyleManager document.head.appendChild(new StylesElement) @themes = new ThemeManager({packageManager: @packages, configDirPath, resourcePath, safeMode}) - @clipboard = new Clipboard() @menu = new MenuManager({resourcePath}) if process.platform is 'win32' @getCurrentWindow().setMenuBarVisibility(false) diff --git a/src/package-manager.coffee b/src/package-manager.coffee index 1c3d6abd6..5e12e9ac7 100644 --- a/src/package-manager.coffee +++ b/src/package-manager.coffee @@ -6,7 +6,6 @@ EmitterMixin = require('emissary').Emitter {Emitter} = require 'event-kit' fs = require 'fs-plus' Q = require 'q' -Grim = require 'grim' Package = require './package' ThemePackage = require './theme-package' @@ -67,11 +66,6 @@ class PackageManager # Returns a {Disposable} on which `.dispose()` can be called to unsubscribe. onDidLoadInitialPackages: (callback) -> @emitter.on 'did-load-initial-packages', callback - @emitter.on 'did-load-all', callback # TODO: Remove once deprecated pre-1.0 APIs are gone - - onDidLoadAll: (callback) -> - Grim.deprecate("Use `::onDidLoadInitialPackages` instead.") - @onDidLoadInitialPackages(callback) # Public: Invoke the given callback when all packages have been activated. # @@ -80,11 +74,6 @@ class PackageManager # Returns a {Disposable} on which `.dispose()` can be called to unsubscribe. onDidActivateInitialPackages: (callback) -> @emitter.on 'did-activate-initial-packages', callback - @emitter.on 'did-activate-all', callback # TODO: Remove once deprecated pre-1.0 APIs are gone - - onDidActivateAll: (callback) -> - Grim.deprecate("Use `::onDidActivateInitialPackages` instead.") - @onDidActivateInitialPackages(callback) # Public: Invoke the given callback when a package is activated. # @@ -122,16 +111,6 @@ class PackageManager onDidUnloadPackage: (callback) -> @emitter.on 'did-unload-package', callback - on: (eventName) -> - switch eventName - when 'loaded' - Grim.deprecate 'Use PackageManager::onDidLoadInitialPackages instead' - when 'activated' - Grim.deprecate 'Use PackageManager::onDidActivateInitialPackages instead' - else - Grim.deprecate 'PackageManager::on is deprecated. Use event subscription methods instead.' - EmitterMixin::on.apply(this, arguments) - ### Section: Package system data ### diff --git a/src/package.coffee b/src/package.coffee index fc94d4f94..4d8a73353 100644 --- a/src/package.coffee +++ b/src/package.coffee @@ -100,14 +100,6 @@ class Package onDidDeactivate: (callback) -> @emitter.on 'did-deactivate', callback - on: (eventName) -> - switch eventName - when 'deactivated' - deprecate 'Use Package::onDidDeactivate instead' - else - deprecate 'Package::on is deprecated. Use event subscription methods instead.' - EmitterMixin::on.apply(this, arguments) - ### Section: Instance Methods ### @@ -212,8 +204,6 @@ class Package for [sourcePath, source] in @stylesheets if match = path.basename(sourcePath).match(/[^.]*\.([^.]*)\./) context = match[1] - else if @metadata.theme is 'syntax' - context = 'nylas-theme-wrap' else context = undefined @@ -290,7 +280,6 @@ class Package deactivate: -> @activationDeferred?.reject() @activationDeferred = null - @activationCommandSubscriptions?.dispose() @deactivateResources() @deactivateConfig() if @mainActivated diff --git a/src/react-remote/selection-listeners.js b/src/react-remote/selection-listeners.js deleted file mode 100644 index 16212b5a8..000000000 --- a/src/react-remote/selection-listeners.js +++ /dev/null @@ -1,78 +0,0 @@ -pathRelativeToReactNode = function (node, stack) { - if (!node || !node.parentNode) { - return stack; - } - if (node.dataset && node.dataset.reactid) { - return stack - } else { - index = -1; - if (node.parentNode && node.parentNode.childNodes) { - for (var i=0; i < node.parentNode.childNodes.length; i++) { - if (node.parentNode.childNodes[i] == node) { - index = i; - } - } - stack.unshift(index) - } - return pathRelativeToReactNode(node.parentNode, stack) - } -} - -restoreSelection = function(selectionData) { - anchorNode = document.querySelector(["[data-reactid='"+selectionData.anchorReactId+"']"]); - focusNode = document.querySelector(["[data-reactid='"+selectionData.focusReactId+"']"]); - if (anchorNode && focusNode) { - for (var i=0; i < selectionData.anchorStack.length; i++) { - childIndex = selectionData.anchorStack[i] - if (anchorNode.childNodes) { - anchorNode = anchorNode.childNodes[childIndex]; - } - } - for (var i=0; i < selectionData.focusStack.length; i++) { - childIndex = selectionData.focusStack[i] - if (focusNode.childNodes) { - focusNode = focusNode.childNodes[childIndex] - } - } - selection = document.getSelection(); - console.log("Setting selection", anchorNode, selectionData.anchorOffset, focusNode, selectionData.focusOffset) - selection.setBaseAndExtent(anchorNode, - selectionData.anchorOffset, - focusNode, - selectionData.focusOffset) - } -} - -getSelectionData = function(){ - selection = document.getSelection(); - selectionData = { - anchorReactId: null, - focusReactId: null, - anchorOffset: selection.anchorOffset, - focusOffset: selection.focusOffset, - }; - if (selection.anchorNode) { - anchorStack = pathRelativeToReactNode(selection.anchorNode, []); - reactNode = selection.anchorNode; - for (var i=0; i < anchorStack.length; i++) { - reactNode = reactNode.parentNode; - } - selectionData.anchorReactId = reactNode.dataset.reactid - selectionData.anchorStack = anchorStack - } - if (selection.focusNode) { - focusStack = pathRelativeToReactNode(selection.focusNode, []); - reactNode = selection.focusNode; - for (var i=0; i < focusStack.length; i++) { - reactNode = reactNode.parentNode; - } - selectionData.focusReactId = reactNode.dataset.reactid - selectionData.focusStack = focusStack - } - return selectionData -} - -module.exports = { - restoreSelection: restoreSelection, - getSelectionData: getSelectionData -}; diff --git a/src/space-pen-utils.js b/src/space-pen-utils.js deleted file mode 100644 index 071176949..000000000 --- a/src/space-pen-utils.js +++ /dev/null @@ -1,117 +0,0 @@ -(function() { - var macModifierKeyMap, nonMacModifierKeyMap, plus, shiftKeyMap - - macModifierKeyMap = { - cmd: '\u2318', - ctrl: '\u2303', - alt: '\u2325', - option: '\u2325', - shift: '\u21e7', - enter: '\u23ce', - left: '\u2190', - right: '\u2192', - up: '\u2191', - down: '\u2193' - }; - - nonMacModifierKeyMap = { - cmd: 'Cmd', - ctrl: 'Ctrl', - alt: 'Alt', - option: 'Alt', - shift: 'Shift', - enter: 'Enter', - left: 'Left', - right: 'Right', - up: 'Up', - down: 'Down' - }; - - shiftKeyMap = { - '~': '`', - '_': '-', - '+': '=', - '|': '\\', - '{': '[', - '}': ']', - ':': ';', - '"': '\'', - '<': ',', - '>': '.', - '?': '/' - }; - - plus = { - capitalize: function(word) { - if (!word) { - return ''; - } - if (word.toLowerCase() === 'github') { - return 'GitHub'; - } else { - return word[0].toUpperCase() + word.slice(1); - } - }, - humanizeKey: function(key, platform) { - var modifierKeyMap; - if (platform == null) { - platform = process.platform; - } - if (!key) { - return key; - } - modifierKeyMap = platform === 'darwin' ? macModifierKeyMap : nonMacModifierKeyMap; - if (modifierKeyMap[key]) { - return modifierKeyMap[key]; - } else if (key.length === 1 && (shiftKeyMap[key] != null)) { - return [modifierKeyMap.shift, shiftKeyMap[key]]; - } else if (key.length === 1 && key === key.toUpperCase() && key.toUpperCase() !== key.toLowerCase()) { - return [modifierKeyMap.shift, key.toUpperCase()]; - } else if (key.length === 1 || /f[0-9]{1,2}/.test(key)) { - return key.toUpperCase(); - } else { - if (platform === 'darwin') { - return key; - } else { - return plus.capitalize(key); - } - } - }, - humanizeKeystroke: function(keystroke, platform) { - var humanizedKeystrokes, index, key, keys, keystrokes, splitKeystroke, _i, _j, _len, _len1; - if (platform == null) { - platform = process.platform; - } - if (!keystroke) { - return keystroke; - } - keystrokes = keystroke.split(' '); - humanizedKeystrokes = []; - for (_i = 0, _len = keystrokes.length; _i < _len; _i++) { - keystroke = keystrokes[_i]; - keys = []; - splitKeystroke = keystroke.split('-'); - for (index = _j = 0, _len1 = splitKeystroke.length; _j < _len1; index = ++_j) { - key = splitKeystroke[index]; - if (key === '' && splitKeystroke[index - 1] === '') { - key = '-'; - } - if (key) { - keys.push(plus.humanizeKey(key, platform)); - } - } - keys = _.uniq(_.flatten(keys)); - if (platform === 'darwin') { - keys = keys.join(''); - } else { - keys = keys.join('+'); - } - humanizedKeystrokes.push(keys); - } - return humanizedKeystrokes.join(' '); - } - } - - module.exports = plus - -}).call(this) diff --git a/src/style-manager.coffee b/src/style-manager.coffee index 7496dadf2..e8fd2eb0e 100644 --- a/src/style-manager.coffee +++ b/src/style-manager.coffee @@ -151,17 +151,3 @@ class StyleManager existingStyleElements = @getStyleElements() for styleElement in styleElementsToRestore @addStyleElement(styleElement) unless styleElement in existingStyleElements - - ### - Section: Paths - ### - - # Extended: Get the path of the user style sheet in `~/.nylas`. - # - # Returns a {String}. - getUserStyleSheetPath: -> - stylesheetPath = fs.resolve(path.join(NylasEnv.getConfigDirPath(), 'styles'), ['css', 'less']) - if fs.isFileSync(stylesheetPath) - stylesheetPath - else - path.join(NylasEnv.getConfigDirPath(), 'styles.less') diff --git a/src/styles-element.coffee b/src/styles-element.coffee index 8d1d751b7..d2e61a2a2 100644 --- a/src/styles-element.coffee +++ b/src/styles-element.coffee @@ -18,9 +18,6 @@ class StylesElement extends HTMLElement @styleElementClonesByOriginalElement = new WeakMap attachedCallback: -> - if @context is 'nylas-theme-wrap' - for styleElement in @children - @upgradeDeprecatedSelectors(styleElement) @initialize() detachedCallback: -> @@ -64,10 +61,6 @@ class StylesElement extends HTMLElement break @insertBefore(styleElementClone, insertBefore) - - if @context is 'nylas-theme-wrap' - @upgradeDeprecatedSelectors(styleElementClone) - @emitter.emit 'did-add-style-element', styleElementClone styleElementRemoved: (styleElement) -> @@ -87,31 +80,4 @@ class StylesElement extends HTMLElement styleElementMatchesContext: (styleElement) -> not @context? or styleElement.context is @context - upgradeDeprecatedSelectors: (styleElement) -> - return unless styleElement.sheet? - - upgradedSelectors = [] - - for rule in styleElement.sheet.cssRules - continue unless rule.selectorText? - continue if /\:host/.test(rule.selectorText) - - inputSelector = rule.selectorText - outputSelector = rule.selectorText - .replace(/\.editor-colors($|[ >])/g, ':host$1') - .replace(/\.editor([:.][^ ,>]+)/g, ':host($1)') - .replace(/\.editor($|[ ,>])/g, ':host$1') - - unless inputSelector is outputSelector - rule.selectorText = outputSelector - upgradedSelectors.push({inputSelector, outputSelector}) - - if upgradedSelectors.length > 0 - warning = "Upgraded the following syntax theme selectors in `#{styleElement.sourcePath}` for shadow DOM compatibility:\n\n" - for {inputSelector, outputSelector} in upgradedSelectors - warning += "`#{inputSelector}` => `#{outputSelector}`\n" - - warning += "\nSee the upgrade guide for information on removing this warning." - console.warn(warning) - module.exports = StylesElement = document.registerElement 'nylas-styles', prototype: StylesElement.prototype diff --git a/src/theme-manager.coffee b/src/theme-manager.coffee index e3de75d6b..c83e8579b 100644 --- a/src/theme-manager.coffee +++ b/src/theme-manager.coffee @@ -6,7 +6,6 @@ EmitterMixin = require('emissary').Emitter {File} = require 'pathwatcher' fs = require 'fs-plus' Q = require 'q' -Grim = require 'grim' Package = require './package' @@ -47,24 +46,17 @@ class ThemeManager styleElementAdded: (styleElement) -> {sheet} = styleElement @sheetsByStyleElement.set(styleElement, sheet) - @emit 'stylesheet-added', sheet @emitter.emit 'did-add-stylesheet', sheet - @emit 'stylesheets-changed' @emitter.emit 'did-change-stylesheets' styleElementRemoved: (styleElement) -> sheet = @sheetsByStyleElement.get(styleElement) - @emit 'stylesheet-removed', sheet @emitter.emit 'did-remove-stylesheet', sheet - @emit 'stylesheets-changed' @emitter.emit 'did-change-stylesheets' styleElementUpdated: ({sheet}) -> - @emit 'stylesheet-removed', sheet @emitter.emit 'did-remove-stylesheet', sheet - @emit 'stylesheet-added', sheet @emitter.emit 'did-add-stylesheet', sheet - @emit 'stylesheets-changed' @emitter.emit 'did-change-stylesheets' ### @@ -78,65 +70,6 @@ class ThemeManager onDidChangeActiveThemes: (callback) -> @emitter.on 'did-change-active-themes', callback - onDidReloadAll: (callback) -> - Grim.deprecate("Use `::onDidChangeActiveThemes` instead.") - @onDidChangeActiveThemes(callback) - - # Deprecated: Invoke `callback` when a stylesheet has been added to the dom. - # - # * `callback` {Function} - # * `stylesheet` {StyleSheet} the style node - # - # Returns a {Disposable} on which `.dispose()` can be called to unsubscribe. - onDidAddStylesheet: (callback) -> - Grim.deprecate("Use NylasEnv.styles.onDidAddStyleElement instead") - @emitter.on 'did-add-stylesheet', callback - - # Deprecated: Invoke `callback` when a stylesheet has been removed from the dom. - # - # * `callback` {Function} - # * `stylesheet` {StyleSheet} the style node - # - # Returns a {Disposable} on which `.dispose()` can be called to unsubscribe. - onDidRemoveStylesheet: (callback) -> - Grim.deprecate("Use NylasEnv.styles.onDidRemoveStyleElement instead") - @emitter.on 'did-remove-stylesheet', callback - - # Deprecated: Invoke `callback` when a stylesheet has been updated. - # - # * `callback` {Function} - # * `stylesheet` {StyleSheet} the style node - # - # Returns a {Disposable} on which `.dispose()` can be called to unsubscribe. - onDidUpdateStylesheet: (callback) -> - Grim.deprecate("Use NylasEnv.styles.onDidUpdateStyleElement instead") - @emitter.on 'did-update-stylesheet', callback - - # Deprecated: Invoke `callback` when any stylesheet has been updated, added, or removed. - # - # * `callback` {Function} - # - # Returns a {Disposable} on which `.dispose()` can be called to unsubscribe. - onDidChangeStylesheets: (callback) -> - Grim.deprecate("Use NylasEnv.styles.onDidAdd/RemoveStyleElement instead") - @emitter.on 'did-change-stylesheets', callback - - on: (eventName) -> - switch eventName - when 'reloaded' - Grim.deprecate 'Use ThemeManager::onDidChangeActiveThemes instead' - when 'stylesheet-added' - Grim.deprecate 'Use ThemeManager::onDidAddStylesheet instead' - when 'stylesheet-removed' - Grim.deprecate 'Use ThemeManager::onDidRemoveStylesheet instead' - when 'stylesheet-updated' - Grim.deprecate 'Use ThemeManager::onDidUpdateStylesheet instead' - when 'stylesheets-changed' - Grim.deprecate 'Use ThemeManager::onDidChangeStylesheets instead' - else - Grim.deprecate 'ThemeManager::on is deprecated. Use event subscription methods instead.' - EmitterMixin::on.apply(this, arguments) - ### Section: Accessing Available Themes ### @@ -153,10 +86,6 @@ class ThemeManager getLoadedThemeNames: -> theme.name for theme in @getLoadedThemes() - getLoadedNames: -> - Grim.deprecate("Use `::getLoadedThemeNames` instead.") - @getLoadedThemeNames() - # Public: Get an array of all the loaded themes. getLoadedThemes: -> pack for pack in @packageManager.getLoadedPackages() when pack.isTheme() @@ -169,10 +98,6 @@ class ThemeManager getActiveThemeNames: -> theme.name for theme in @getActiveThemes() - getActiveNames: -> - Grim.deprecate("Use `::getActiveThemeNames` instead.") - @getActiveThemeNames() - # Public: Get an array of all the active themes. getActiveThemes: -> pack for pack in @packageManager.getActivePackages() when pack.isTheme() @@ -219,13 +144,6 @@ class ThemeManager # the first/top theme to override later themes in the stack. themeNames.reverse() - # Set the list of enabled themes. - # - # * `enabledThemeNames` An {Array} of {String} theme names. - setEnabledThemes: (enabledThemeNames) -> - Grim.deprecate("Use `NylasEnv.config.set('core.themes', arrayOfThemeNames)` instead") - NylasEnv.config.set('core.themes', enabledThemeNames) - # Set the active theme. # Because of how theme-manager works, we always need to set the # base theme first, and the newly activated theme after it to override the @@ -241,11 +159,6 @@ class ThemeManager Section: Private ### - # Returns the {String} path to the user's stylesheet under ~/.nylas - getUserStylesheetPath: -> - Grim.deprecate("Call NylasEnv.styles.getUserStyleSheetPath() instead") - NylasEnv.styles.getUserStyleSheetPath() - # Resolve and apply the stylesheet specified by the path. # # This supports both CSS and Less stylsheets. @@ -262,42 +175,6 @@ class ThemeManager else throw new Error("Could not find a file at path '#{stylesheetPath}'") - unwatchUserStylesheet: -> - @userStylsheetSubscriptions?.dispose() - @userStylsheetSubscriptions = null - @userStylesheetFile = null - @userStyleSheetDisposable?.dispose() - @userStyleSheetDisposable = null - - loadUserStylesheet: -> - @unwatchUserStylesheet() - - userStylesheetPath = NylasEnv.styles.getUserStyleSheetPath() - return unless fs.isFileSync(userStylesheetPath) - try - @userStylesheetFile = new File(userStylesheetPath) - @userStylsheetSubscriptions = new CompositeDisposable() - reloadStylesheet = => @loadUserStylesheet() - @userStylsheetSubscriptions.add(@userStylesheetFile.onDidChange(reloadStylesheet)) - @userStylsheetSubscriptions.add(@userStylesheetFile.onDidRename(reloadStylesheet)) - @userStylsheetSubscriptions.add(@userStylesheetFile.onDidDelete(reloadStylesheet)) - catch error - message = """ - Unable to watch path: `#{path.basename(userStylesheetPath)}`. Make sure - you have permissions to `#{userStylesheetPath}`. - - On linux there are currently problems with watch sizes. - """ - console.error(message, dismissable: true) - console.error(error.toString()) - - try - userStylesheetContents = @loadStylesheet(userStylesheetPath, true) - catch - return - - @userStyleSheetDisposable = NylasEnv.styles.addStyleSheet(userStylesheetContents, sourcePath: userStylesheetPath, priority: 2) - loadBaseStylesheets: -> @reloadBaseStylesheets() @@ -381,10 +258,8 @@ class ThemeManager Q.all(promises).then => @addActiveThemeClasses() @refreshLessCache() # Update cache again now that @getActiveThemes() is populated - @loadUserStylesheet() @reloadBaseStylesheets() @initialLoadComplete = true - @emit 'reloaded' @emitter.emit 'did-change-active-themes' deferred.resolve() @@ -392,24 +267,19 @@ class ThemeManager deactivateThemes: -> @removeActiveThemeClasses() - @unwatchUserStylesheet() @packageManager.deactivatePackage(pack.name) for pack in @getActiveThemes() null isInitialLoadComplete: -> @initialLoadComplete addActiveThemeClasses: -> - workspaceElement = document.getElementsByTagName('nylas-workspace')[0] - return unless workspaceElement for pack in @getActiveThemes() - workspaceElement.classList.add("theme-#{pack.name}") + document.body.classList.add("theme-#{pack.name}") return removeActiveThemeClasses: -> - workspaceElement = document.getElementsByTagName('nylas-workspace')[0] - return unless workspaceElement for pack in @getActiveThemes() - workspaceElement.classList.remove("theme-#{pack.name}") + document.body.classList.remove("theme-#{pack.name}") return refreshLessCache: -> diff --git a/src/window-event-handler.coffee b/src/window-event-handler.coffee index b5700f6a1..05fa02de6 100644 --- a/src/window-event-handler.coffee +++ b/src/window-event-handler.coffee @@ -14,14 +14,6 @@ class WindowEventHandler _.defer => @showDevModeMessages() - ipcRenderer.on 'open-path', (event, pathToOpen) -> - unless NylasEnv.project?.getPaths().length - if fs.existsSync(pathToOpen) or fs.existsSync(path.dirname(pathToOpen)) - NylasEnv.project?.setPaths([pathToOpen]) - - unless fs.isDirectorySync(pathToOpen) - NylasEnv.workspace?.open(pathToOpen, {}) - ipcRenderer.on 'update-available', (event, detail) -> NylasEnv.updateAvailable(detail)