From ea5d931e1563ea8f4ff91ed3dbea6b674c7a3456 Mon Sep 17 00:00:00 2001 From: Ruben Daniels Date: Mon, 19 Oct 2015 10:57:28 -0700 Subject: [PATCH] Allow beautify to be called with a string. Other small supportive fixes --- package.json | 4 +++- plugins/c9.ide.editors/editors.js | 21 ++++++++++++++++++++- plugins/c9.ide.editors/tab.js | 3 ++- plugins/c9.ide.editors/tabmanager.js | 7 +------ plugins/c9.ide.editors/undomanager.js | 8 +++++--- plugins/c9.ide.ui/widgets.tree.js | 5 +++-- 6 files changed, 34 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 3f643434..51ab32d1 100644 --- a/package.json +++ b/package.json @@ -85,7 +85,7 @@ "c9.ide.configuration": "#a9066299a2", "c9.ide.dialog.wizard": "#7667ec79a8", "c9.ide.fontawesome": "#781602c5d8", - "c9.ide.format": "#b0bb91a623", + "c9.ide.format": "#33ebd01914", "c9.ide.help.support": "#e95f98f87c", "c9.ide.imgeditor": "#66a9733dc1", "c9.ide.immediate": "#18c23aa730", @@ -108,6 +108,8 @@ "c9.ide.save": "#e00549cb0f", "c9.ide.scm": "#38d2b48b31", "c9.ide.terminal.monitor": "#b76f1c9f24", + "c9.ide.test": "#d312a01ac6", + "c9.ide.test.mocha": "#79ff886c04", "c9.ide.theme.flat": "#2de8414db7", "c9.ide.threewaymerge": "#229382aa0b", "c9.ide.undo": "#b028bcb4d5", diff --git a/plugins/c9.ide.editors/editors.js b/plugins/c9.ide.editors/editors.js index 4068104d..510e3273 100644 --- a/plugins/c9.ide.editors/editors.js +++ b/plugins/c9.ide.editors/editors.js @@ -10,6 +10,9 @@ define(function(require, module, exports) { var Plugin = imports.Plugin; var menus = imports.menus; + var extname = require("path").extname; + var basename = require("path").basename; + /***** Initialization *****/ var plugin = new Plugin("Ajax.org", main.consumes); @@ -54,9 +57,20 @@ define(function(require, module, exports) { return editor; } + function editorSupportsFile(type, path) { + var extensions = findEditor(type).fileExtensions; + var ext = extname(path).substr(1).toLowerCase(); + var filename = basename(path).toLowerCase(); + return ~extensions.indexOf(path) + || ~extensions.indexOf(filename) + || ~extensions.indexOf(ext) ? true : false; + } + function findEditorByFilename(fn) { - var ext = fn.substr(fn.lastIndexOf(".") + 1).toLowerCase(); + var ext = extname(fn).substr(1).toLowerCase(); + var filename = basename(fn).toLowerCase(); var editor = fileExtensions[fn] && fileExtensions[fn][0] + || fileExtensions[filename] && fileExtensions[filename][0] || fileExtensions[ext] && fileExtensions[ext][0] || defaultEditor; @@ -245,6 +259,11 @@ define(function(require, module, exports) { */ findEditorByFilename: findEditorByFilename, + /** + * + */ + editorSupportsFile: editorSupportsFile, + /** * Create an editor instance based on it's type * @param {String} type The type of the editor to create diff --git a/plugins/c9.ide.editors/tab.js b/plugins/c9.ide.editors/tab.js index 1c197575..11c18440 100644 --- a/plugins/c9.ide.editors/tab.js +++ b/plugins/c9.ide.editors/tab.js @@ -7,6 +7,7 @@ define(function(require, module, exports) { var Plugin = imports.Plugin; var Document = imports.Document; var ui = imports.ui; + var alert = imports["dialog.alert"].show; var stylesheet = ui.createStylesheet(); @@ -249,7 +250,7 @@ define(function(require, module, exports) { // var lastType = tab.editorType; amlPane.cloud9pane.createEditor(type, function(err, editor) { var info = {}; - if (editor.isValid(amlTab.document, info) === false) { + if (editor.isValid(amlTab.cloud9tab.document, info) === false) { alert( info.title || "Could not switch editor", info.head || "Could not switch editor because this document is invalid.", diff --git a/plugins/c9.ide.editors/tabmanager.js b/plugins/c9.ide.editors/tabmanager.js index 2d76dbbf..6e9c561b 100644 --- a/plugins/c9.ide.editors/tabmanager.js +++ b/plugins/c9.ide.editors/tabmanager.js @@ -186,13 +186,8 @@ define(function(require, module, exports) { group = node.group; var path = focussedTab && focussedTab.path || ""; - var ext = path.substr(path.lastIndexOf(".") + 1); - var type = node.value; - var extensions = editors.findEditor(type).fileExtensions; - var isAvailable = editors.defaultEditor == type - || extensions.indexOf(ext.toLowerCase()) > -1 - || !extensions.length; + var isAvailable = editors.editorSupportsFile(type, path); node.setAttribute("disabled", !isAvailable); }); diff --git a/plugins/c9.ide.editors/undomanager.js b/plugins/c9.ide.editors/undomanager.js index d3fabb20..a275e5a5 100644 --- a/plugins/c9.ide.editors/undomanager.js +++ b/plugins/c9.ide.editors/undomanager.js @@ -116,9 +116,11 @@ define(function(require, module, exports) { return { mark: mark, position: position, - stack: stack.map(function(item) { - return item.getState ? item.getState() : item; - }) + stack: stack + .filter(function(item){ return item; }) + .map(function(item) { + return item.getState ? item.getState() : item; + }) }; } diff --git a/plugins/c9.ide.ui/widgets.tree.js b/plugins/c9.ide.ui/widgets.tree.js index 9781c2b1..3970bfbb 100644 --- a/plugins/c9.ide.ui/widgets.tree.js +++ b/plugins/c9.ide.ui/widgets.tree.js @@ -16,8 +16,9 @@ define(function(require, exports, module) { if (!options.baseName) options.baseName = "tree"; - if (!options.model) { - var model = new TreeModel(); + var model = options.model; + if (!model) { + model = new TreeModel(); options.model = model; }