diff --git a/.gitignore b/.gitignore index 8cf05519..1171d6d8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,30 +1,41 @@ -lib-cov -*.seed -*.csv -*.dat -*.out -*.pid -*.gz +# Logs +logs +*.log +# Runtime data pids -logs -results +*.pid +*.seed + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directory +# Deployed apps should consider commenting this line out: +# see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git +node_modules -npm-debug.log -settings.json -/node_modules/ -/appBuilds/ -/client/build/ -.addons +# Bower Vendors +editor/vendors -/.env +# All installed packages +packages/* +!packages/.gitkeep -/.tmp/ +# Build output +build -/addons/cb.files.editor/ace/ -**/addon-built.js -**/node_modules/ -*/**/addon-built.js -*/**/node_modules/ -/extras/ +# Tmp directory +.tmp +# Packages for testing +test/packages \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..6e5919de --- /dev/null +++ b/.travis.yml @@ -0,0 +1,3 @@ +language: node_js +node_js: + - "0.10" diff --git a/CHANGES b/CHANGES.md similarity index 100% rename from CHANGES rename to CHANGES.md diff --git a/Gruntfile.js b/Gruntfile.js deleted file mode 100644 index e1270702..00000000 --- a/Gruntfile.js +++ /dev/null @@ -1,274 +0,0 @@ -module.exports = function (grunt) { - var fs = require('fs'); - var path = require("path"); - var pkg = require("./package.json"); - var _ = require('lodash'); - - // Path to the client src - var clientPath = path.resolve(__dirname, "client"); - - // Constants - var NW_VERSION = "0.8.4"; - - // Load grunt modules - grunt.loadNpmTasks('hr.js'); - grunt.loadNpmTasks('grunt-exec'); - grunt.loadNpmTasks('grunt-contrib-compress'); - grunt.loadNpmTasks('grunt-contrib-clean'); - grunt.loadNpmTasks('grunt-contrib-copy'); - - // Init GRUNT configuraton - grunt.initConfig({ - pkg: grunt.file.readJSON('package.json'), - hr: { - build: { - // Base directory for the application - "base": clientPath, - - // Application name - "name": "Codebox", - - // Mode debug - "debug": process.env.CLIENT_DEBUG != null, - - // Main entry point for application - "main": "main", - "index": grunt.file.read(path.resolve(clientPath, "index.html")), - - // Build output directory - "build": path.resolve(clientPath, "build"), - - // Static files mappage - "static": { - "images": path.resolve(clientPath, "resources", "images"), - "fonts": path.resolve(clientPath, "resources", "fonts") - }, - - // Stylesheet entry point - "style": path.resolve(clientPath, "resources/stylesheets/main.less"), - - // Modules paths - 'paths': { - 'moment': 'vendors/moment' - }, - "shim": { - 'resources/resources': { - deps: [ - 'vendors/bootstrap/carousel', - 'vendors/bootstrap/dropdown', - 'vendors/bootstrap/button', - 'vendors/bootstrap/modal', - 'vendors/bootstrap/affix', - 'vendors/bootstrap/alert', - 'vendors/bootstrap/collapse', - 'vendors/bootstrap/tooltip', - 'vendors/bootstrap/popover', - 'vendors/bootstrap/scrollspy', - 'vendors/bootstrap/tab', - 'vendors/bootstrap/transition', - 'vendors/taphold' - ] - }, - 'vendors/socket.io': { - exports: 'io' - }, - 'vendors/crypto': { - exports: 'CryptoJS' - }, - 'vendors/diff_match_patch': { - exports: 'diff_match_patch' - }, - 'vendors/mousetrap': { - exports: 'Mousetrap' - }, - 'vendors/filer': { - exports: 'Filer', - deps: [ - 'vendors/idb.filesystem' - ] - } - }, - 'args': { - 'version': pkg.version, - 'debug': process.env.CLIENT_DEBUG != null - }, - 'options': { - - } - } - }, - exec: { - publish: { - command: "npm publish", - cwd: '.tmp/', - stdout: true, - stderr: true - }, - build_files_editor: { - command: "npm install", - cwd: './addons/cb.files.editor/', - stdout: true, - stderr: true - }, - clean_addons: { - command: "rm -rf */**/addon-built.js ./addons/**/node_modules", - cwd: '.', - stdout: true, - stderr: true - }, - clean_addons_tmp: { - command: "rm -rf */**/addon-built.js", - cwd: '.tmp/', - stdout: true, - stderr: true - } - }, - copy: { - // Copy most files over - tmp: { - expand: true, - dot: false, - cwd: './', - dest: '.tmp/', - src: [ - // Most files except the ones below - "./**", - - // Ignore gitignore - "!.gitignore", - - // Ignore dev related things - "!./tmp/**", - "!./.git/**", - "!./.addons/**", - "!./appBuilds/**", - - // grunt.file.copy duplicates symbolic and hard links - // so we need to copy it with the shell - "!./extras/**", - - // Only take "./client/build" - "!./client/**", - "./client/build/**", - - // Ignore some build time only modules - "./node_modules/.bin/**", - "!./node_modules/grunt/**", - "!./node_modules/grunt-*/**", - "!./node_modules/hr.js/**", - - // Exclude test directories from node modules - "!./node_modules/**/test/**", - ], - - // Preserve permissions - options: { - mode: true - } - } - }, - compress: { - tmp: { - options: { - mode: 'gzip', - pretty: true - }, - expand: true, - src: [ - // Codebox Built addons - '.tmp/addons/*/addon-built.js', - - // Ace source - '.tmp/addons/cb.files.editor/ace/**', - - // HR.js application - '.tmp/client/build/static/application.{js,css}' - ], - filter: function(src) { - // Compressable file formats - if(!_.contains([ - 'js', - 'css', - 'svg', - 'less', - 'html', - 'snippets' - ], - path.extname(src).slice(1) - )) return false; - try { - // We don't want to gzip tiny files - // Skip files < 10kb - return fs.statSync(src).size > 10*1024; - } catch(err) {} - return false; - } - } - }, - clean: { - tmp: ['.tmp/'] - }, - buildAddons: { - tmp: { - addonsFolder: ".tmp/addons/" - }, - dev: { - addonsFolder: "./addons/", - force: false - } - } - }); - - // Load in any and all tasks in the `tasks` folder - grunt.loadTasks('tasks'); - - // Rebuild all addons - grunt.registerTask('rebuildAddons', [ - 'exec:clean_addons', - 'buildAddons:dev' - ]); - - // Build - grunt.registerTask('build', [ - 'hr', - 'exec:build_files_editor', - 'buildAddons:dev' - ]); - - // Build tmp directory - grunt.registerTask('tmp', [ - 'build', - 'clean:tmp', - 'copy:tmp', - 'exec:clean_addons_tmp', - 'buildAddons:tmp', - 'compress:tmp' - ]); - - // Publish to NPM - grunt.registerTask('publish', [ - 'tmp', - 'exec:publish', - 'clean:tmp' - ]); - - // Run - grunt.registerTask('run', function() { - var done = this.async(); - var options = this.options({}); - - grunt.util.spawn({ - cmd: "node", - opts: { - cwd: path.resolve(__dirname), - stdio: 'inherit' - }, - args: ["./bin/codebox.js", "run"] - }, done); - }); - - grunt.registerTask('default', [ - 'build', - 'run' - ]); -}; diff --git a/README.md b/README.md index 01266b44..52f8fab9 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,9 @@ # Codebox > "Open source cloud & desktop IDE." +[![Build Status](https://travis-ci.org/CodeboxIDE/codebox.png?branch=master)](https://travis-ci.org/CodeboxIDE/codebox) +[![NPM version](https://badge.fury.io/js/codebox.svg)](http://badge.fury.io/js/codebox) + Codebox is a complete and modular Cloud IDE. It can run on any unix-like machine (Linux, Mac OS X). It is an open source component of [codebox.io](https://www.codebox.io) (Cloud IDE as a Service). The IDE can run on your desktop (Linux or Mac), on your server or the cloud. You can use the [codebox.io](https://www.codebox.io) service to host and manage IDE instances. @@ -38,6 +41,16 @@ Use this command to run and open Codebox IDE. By default, Codebox uses GIT to id Others comand line options are available and can be list with: ```codebox --help```. For deeper configuration, take a look at the documentation about [environment variables](http://help.codebox.io/ide/env.html). +#### Command line options + +``` +-h, --help output usage information +-V, --version output the version number +-r, --root [path] Root folder for the workspace, default is current directory +-t, --templates [list] Configuration templates, separated by commas +-p, --port [port] HTTP port +``` + #### Need help? The IDE's documentation can be found at [help.codebox.io](http://help.codebox.io). Feel free to ask any questions or signal problems by adding issues. @@ -56,3 +69,5 @@ The IDE's documentation can be found at [help.codebox.io](http://help.codebox.io * **Twitter:** [@CodeboxIO](https://twitter.com/CodeboxIO) * **Blog:** [blog.codebox.io](http://blog.codebox.io) * **Youtube:** [Codebox Channel](http://www.youtube.com/channel/UCWocQwS2VmDS3Ej0LQYWVIw) + + diff --git a/addons/cb.debug/client.js b/addons/cb.debug/client.js deleted file mode 100644 index 54e005de..00000000 --- a/addons/cb.debug/client.js +++ /dev/null @@ -1,72 +0,0 @@ -define([ - "views/tab", - "settings" -], function(DebugTab, settings) { - var Q = codebox.require("hr/promise"); - var _ = codebox.require("hr/utils"); - var File = codebox.require("models/file"); - var toolbar = codebox.require("core/commands/toolbar"); - var dialogs = codebox.require("utils/dialogs"); - var files = codebox.require("core/files"); - var tabs = codebox.require("core/tabs"); - var box = codebox.require("core/box"); - var debugManager = codebox.require("core/debug/manager"); - - // Add files handler - var filesHandler = files.addHandler("debug", { - icon: "bug", - name: "Debug", - valid: function(file) { - return (!file.isDirectory()); - }, - open: function(file) { - if (file.path() != settings.user.get("path")) { - settings.user.set("path", file.path()); - settings.user.save(); - } - - return debugManager.open() - .then(function(dbg) { - return tabs.add(DebugTab, { - 'dbg': dbg, - 'path': file.path(), - 'tool': settings.user.get("tool") == "auto" ? null : settings.user.get("tool"), - 'argument': settings.user.get("argument") - }, { - 'type': "debug", - 'section': "debug" - }); - }); - } - }); - - // Debugging command - toolbar.register("debug.open", { - category: "Debug", - title: "Debugger", - description: "Open Debugger", - icons: { - 'default': "bug", - }, - offline: false, - shortcuts: [ - "alt+d" - ] - }, function(path) { - path = path || settings.user.get("path"); - - if (!path) { - dialogs.alert("No file specified", "Click left on a file and select 'Debug' to open it with the debugger, it'll be saved in your settings as last debugged file."); - return; - } - - var f = new File(); - - return f.getByPath(path) - .then(function() { - return filesHandler.open(f); - }, function() { - dialogs.alert("File not found", "File "+_.escape(path)+" doesn't exists. Click left on an another file and select 'Debug' to open it with the debugger."); - }); - }); -}); \ No newline at end of file diff --git a/addons/cb.debug/package.json b/addons/cb.debug/package.json deleted file mode 100644 index 040b64d1..00000000 --- a/addons/cb.debug/package.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "name": "cb.debug", - "version": "0.1.0", - "title": "Debug", - "description": "Debugger integration inside codebox", - "homepage": "https://github.com/FriendCode/codebox", - "license": "Apache", - "author": { - "name": "Codebox", - "email": "contact@friendco.de", - "url": "https://www.codebox.io" - }, - "client": { - "main": "client" - }, - "engines": { - "codebox": ">=0.7.0" - } -} \ No newline at end of file diff --git a/addons/cb.debug/settings.js b/addons/cb.debug/settings.js deleted file mode 100644 index 35657580..00000000 --- a/addons/cb.debug/settings.js +++ /dev/null @@ -1,42 +0,0 @@ -define([], function() { - var settings = codebox.require("core/settings"); - - // Add settings - return settings.add({ - 'namespace': "debug", - 'title': "Debug", - 'defaults': { - 'path': "", - 'argument': null, - 'tool': "auto" - }, - 'fields': { - 'path': { - 'label': 'File Path', - 'type': "text", - 'help': "Click left on a file and select 'debug' to update this file." - }, - 'argument': { - 'label': 'Arguments', - 'type': "text", - 'help': "Arguments to run the file with." - }, - 'tool': { - 'label': 'Debugger', - 'type': "select", - 'help': "Force the use of a specific debugger.", - 'options': { - 'auto': "Auto", - 'pdb': "Python Debugger", - 'gdb': "Native Debugger (GDB)", - - // Still unstable: - /* - 'jdb': "Java Debugger", - 'rdb': "Ruby Debugger" - */ - } - } - } - }); -}); \ No newline at end of file diff --git a/addons/cb.debug/stylesheets/tab.less b/addons/cb.debug/stylesheets/tab.less deleted file mode 100644 index f25aeb6b..00000000 --- a/addons/cb.debug/stylesheets/tab.less +++ /dev/null @@ -1,99 +0,0 @@ -.addon-debugger-tab { - .component-grid .grid-section { - .grid-resize-bar-h, .grid-resize-bar-v { - background: rgba(0,0,0, 0.1); - } - } - - .debug-section { - h4 { - display: block; - width: 100%; - background: rgba(0,0,0,.05); - font-size: 14px; - padding: 6px 8px; - margin: 0px; - } - - .table-container { - position: absolute; - top: 27px; - bottom: 0px; - left: 0px; - right: 0px; - display: block; - margin: 0px; - overflow: auto; - } - - .table { - margin: 0px; - - tr { - td, th { - border-top-color: rgba(0,0,0, 0.05); - - a { - color: inherit; - } - } - } - } - - &.debug-console { - .line { - padding-bottom: 3px; - border-bottom: 1px solid rgba(0,0,0, 0.05); - - * { - line-height: 1.4em; - font-size: 14px; - } - - i { - float: left; - width: 24px; - text-align: center; - } - - pre { - margin: 0px; - padding: 0px; - background: none; - color: inherit; - border: none; - display: block; - margin-left: 24px; - font-family: inherit; - } - - &.error { - color: #a94442; - } - &.input { - padding-top: 3px; - padding-bottom: 0px; - border-color: transparent; - } - - input, input:focus { - color: inherit; - background: transparent; - box-shadow: none; - font-size: 14px; - line-height: 1.4em; - padding: 0px; - margin: 0px; - height: 19px; - margin-right: 24px; - width: 90%; - border: none; - } - } - - .console-body { - - } - } - } -} \ No newline at end of file diff --git a/addons/cb.debug/views/backtrace.js b/addons/cb.debug/views/backtrace.js deleted file mode 100644 index 906dc216..00000000 --- a/addons/cb.debug/views/backtrace.js +++ /dev/null @@ -1,35 +0,0 @@ -define([ - "views/section" -], function(DebugSection) { - var _ = codebox.require("hr/utils"); - var $ = codebox.require("hr/dom"); - var hr = codebox.require("hr/hr"); - var rpc = codebox.require("core/backends/rpc"); - - var BacktraceSection = DebugSection.extend({ - title: "Backtrace", - formats: [ - { - id: "filename", - title: "File", - type: "file" - }, - { - id: "line", - title: "Line" - } - ], - - update: function() { - var that = this; - - return this.dbg.backtrace() - .then(function(stack) { - that.clearLines(); - _.each(stack, that.addLine, that); - }); - } - }); - - return BacktraceSection; -}); diff --git a/addons/cb.debug/views/breakpoints.js b/addons/cb.debug/views/breakpoints.js deleted file mode 100644 index 15a16211..00000000 --- a/addons/cb.debug/views/breakpoints.js +++ /dev/null @@ -1,39 +0,0 @@ -define([ - "views/section" -], function(DebugSection) { - var _ = codebox.require("hr/utils"); - var $ = codebox.require("hr/dom"); - var hr = codebox.require("hr/hr"); - var rpc = codebox.require("core/backends/rpc"); - - var BreakpointsSection = DebugSection.extend({ - title: "Breakpoints", - formats: [ - { - id: "num", - title: "#" - }, - { - id: "filename", - title: "File", - type: "file" - }, - { - id: "line", - title: "Line" - } - ], - - update: function() { - var that = this; - - return this.dbg.breakpoints() - .then(function(breakpoints) { - that.clearLines(); - _.each(breakpoints, that.addLine, that); - }); - } - }); - - return BreakpointsSection; -}); diff --git a/addons/cb.debug/views/console.js b/addons/cb.debug/views/console.js deleted file mode 100644 index 718740f5..00000000 --- a/addons/cb.debug/views/console.js +++ /dev/null @@ -1,107 +0,0 @@ -define([], function() { - var _ = codebox.require("hr/utils"); - var $ = codebox.require("hr/dom"); - var hr = codebox.require("hr/hr"); - - var ConsoleSection = hr.View.extend({ - className: "debug-section debug-console", - title: "Console", - defaults: { - dbg: null - }, - events: { - "click": "focus" - }, - logIcons: { - 'log': "fa fa-blank", - 'input': "fa fa-angle-right", - 'error': "fa fa-times-circle" - }, - - initialize: function(options) { - var that = this; - ConsoleSection.__super__.initialize.apply(this, arguments); - - // Debugger client - this.dbg = this.options.dbg; - - this.$title = $("

", { - 'text': this.title - }); - - this.$container = $("
", { - 'class': "table-container" - }); - - this.$body = $("
", { - 'class': "console-body" - }); - - this.$input = $("", { - 'class': "form-control input-sm", - 'keyup': function(e) { - var key = e.which || e.keyCode; - var code = $(e.currentTarget).val(); - - if (key == 13) { - /* ENTER */ - e.preventDefault(); - - that.eval(code); - $(e.currentTarget).val(""); - } - } - }); - - - this.$body.appendTo(this.$container); - this.$input.appendTo($("
", { - 'class': "line input", - 'html': '' - }).appendTo(this.$container)); - - this.$title.appendTo(this.$el); - this.$container.appendTo(this.$el); - - return this; - }, - - addLine: function(output) { - var $line = $("
", { - 'class': "line "+output.type - }); - var $pre = $("
", {
-                'text': output.content
-            });
-            var $icon = $("", {
-                'class': this.logIcons[output.type]
-            });
-
-            $icon.appendTo($line);
-            $pre.appendTo($line);
-
-            $line.appendTo(this.$body);
-
-            // Scroll
-            this.$container.animate({ scrollTop: this.$container[0].scrollHeight}, 100);
-        },
-
-        // Eval some code
-        eval: function(code) {
-            this.addLine({
-                type: "input",
-                content: code
-            });
-            return this.dbg.eval(code)
-            .then(_.bind(this.addLine, this));
-        },
-
-        // Focus the console
-        focus: function(e) {
-            if (e) e.preventDefault();
-            this.$input.focus();
-        }
-    });
-
-    return ConsoleSection;
-});
diff --git a/addons/cb.debug/views/locals.js b/addons/cb.debug/views/locals.js
deleted file mode 100644
index 650bb79d..00000000
--- a/addons/cb.debug/views/locals.js
+++ /dev/null
@@ -1,39 +0,0 @@
-define([
-    "views/section"
-], function(DebugSection) {
-    var _ = codebox.require("hr/utils");
-    var $ = codebox.require("hr/dom");
-    var hr = codebox.require("hr/hr");
-    var rpc = codebox.require("core/backends/rpc");
-
-    var LocalsSection = DebugSection.extend({
-        title: "Locals",
-        formats: [
-            {
-                id: "name",
-                title: "Name"
-            },
-            {
-                id: "value",
-                title: "Value"
-            }
-        ],
-
-        update: function() {
-            var that = this;
-            
-            return this.dbg.locals()
-            .then(function(locals) {
-                that.clearLines();
-                _.each(locals, function(value, key) {
-                    that.addLine({
-                        'name': key,
-                        'value': value
-                    });
-                });
-            });
-        }
-    });
-
-    return LocalsSection;
-});
diff --git a/addons/cb.debug/views/section.js b/addons/cb.debug/views/section.js
deleted file mode 100644
index 55222b31..00000000
--- a/addons/cb.debug/views/section.js
+++ /dev/null
@@ -1,100 +0,0 @@
-define([], function() {
-    var _ = codebox.require("hr/utils");
-    var $ = codebox.require("hr/dom");
-    var hr = codebox.require("hr/hr");
-
-    var files = codebox.require("core/files");
-
-    var DebugSection = hr.View.extend({
-        className: "debug-section",
-        defaults: {
-            dbg: null
-        },
-        events: {},
-        formats: [],
-
-        initialize: function(options) {
-            DebugSection.__super__.initialize.apply(this, arguments);
-            
-            // Debugger client
-            this.dbg = this.options.dbg;
-
-            this.$title = $("

", { - 'text': this.title - }); - - this.$container = $("
", { - 'class': "table-container" - }); - - this.$table = $("", { - 'class': "table" - }); - - this.$title.appendTo(this.$el); - this.$container.appendTo(this.$el); - this.$table.appendTo(this.$container); - - this.clearLines(); - - return this; - }, - - // Render - render: function() { - return this.ready(); - }, - - // Clear items - clearLines: function() { - this.$table.empty(); - - // Initiliaze format - var $line = $(""); - - _.each(this.formats, function(key) { - $(""); - - _.each(this.formats, function(key) { - var $e; - var value = item[key.id]; - - if (key.type == "file") { - $e = $("", { - 'href': "#", - 'text': value, - 'click': function(e) { - e.preventDefault(); - files.open(value, { - line: item.line - }); - } - }) - } else { - $e = $("", { - 'text': value - }); - } - - $e.appendTo($("
", { - 'text': key.title - }).appendTo($line); - }); - $line.appendTo(this.$table); - }, - - // Add an item - addLine: function(item) { - var $line = $("
").appendTo($line)); - }); - $line.appendTo(this.$table); - }, - - // Update content - update: function() { - // to defined - } - }); - - return DebugSection; -}); diff --git a/addons/cb.debug/views/tab.js b/addons/cb.debug/views/tab.js deleted file mode 100644 index dcff112b..00000000 --- a/addons/cb.debug/views/tab.js +++ /dev/null @@ -1,201 +0,0 @@ -define([ - "views/section", - "views/locals", - "views/backtrace", - "views/breakpoints", - "views/console", - "less!stylesheets/tab.less" -], function( DebugSection, LocalsSection, BacktraceSection, BreakpointsSection, ConsoleSection) { - var _ = codebox.require("hr/utils"); - var $ = codebox.require("hr/dom"); - var hr = codebox.require("hr/hr"); - var Command = codebox.require("models/command"); - var Tab = codebox.require("views/tabs/base"); - var box = codebox.require("core/box"); - var user = codebox.require("core/user"); - var dialogs = codebox.require("utils/dialogs"); - var debugManager = codebox.require("core/debug/manager"); - - var GridView = codebox.require("views/grid"); - - var DebugTab = Tab.extend({ - className: Tab.prototype.className+ " addon-debugger-tab", - defaults: { - - }, - menuTitle: "Debugger", - events: { - - }, - - initialize: function(options) { - var that = this; - DebugTab.__super__.initialize.apply(this, arguments); - - this.dbg = this.options.dbg; - - - // Create sections - this.console = new ConsoleSection({ - dbg: this.dbg - }); - this.locals = new LocalsSection({ - dbg: this.dbg - }); - this.backtrace = new BacktraceSection({ - dbg: this.dbg - }); - this.breakpoints = new BreakpointsSection({ - dbg: this.dbg - }); - - // Listen events - this.listenTo(this.dbg, "close", function() { - this.closeTab(); - }); - this.listenTo(this.dbg, "update", function() { - this.updateState(); - }); - this.listenTo(this.dbg, "error", function(err) { - this.console.addLine({ - type: "error", - content: err.message || err - }); - }); - this.listenTo(this.dbg, "log", function(message) { - this.console.addLine({ - type: "log", - content: message - }); - }); - - // Create grids for sections - this.gridV = new GridView({ - columns: 1 - }); - this.gridH = new GridView({ - columns: 1000 - }); - - this.gridH.addView(this.breakpoints); - this.gridH.addView(this.backtrace); - this.gridH.addView(this.locals); - - this.gridV.addView(this.gridH); - this.gridV.addView(this.console); - this.gridV.appendTo(this); - - - // Base commands: start, stop, next, continue, restart - this.commandStart = new Command({}, { - title: "Start", - action: function() { - that.dbg.start(that.options.argument); - } - }); - this.commandStop = new Command({}, { - title: "Stop", - action: function() { - that.dbg.stop(); - } - }); - this.commandNext = new Command({}, { - title: "Next", - action: function() { - that.dbg.next(); - } - }); - this.commandContinue = new Command({}, { - title: "Continue", - action: function() { - that.dbg.cont(); - } - }); - this.commandRestart = new Command({}, { - title: "Restart", - action: function() { - that.dbg.restart(); - } - }); - - // Describe debug tab - this.setTabTitle("Debugger "+this.options.path); - - // Tab menu - this.menu - .menuSection([ - this.commandStart, - this.commandStop, - this.commandRestart - ]) - .menuSection([ - this.commandNext, - this.commandContinue - ]) - .menuSection([ - { - 'type': "checkbox", - 'title': "Exit", - 'action': function(state) { - that.closeTab(); - } - } - ]); - - // Statusbar menu - this.statusbar.add([ - this.commandRestart, - this.commandContinue, - this.commandNext, - this.commandStop, - this.commandStart - ]); - - // Start debugger - this.dbg.init({ - 'tool': this.options.tool, - 'path': this.options.path, - 'breakpoints': debugManager.breakpoints.all() - }); - - // Bind event on breakponts changements - this.listenTo(debugManager.breakpoints, "change", function(e) { - if (e.change == "add") { - this.dbg.breakpointAdd({ - 'path': e.path, - 'line': e.line - }); - } else { - var point = this.dbg.getBreakpoint({ - 'path': e.path, - 'line': e.line - }); - - if (point) this.dbg.breakpointRemove(point.num); - } - }); - - // Bind close tab - this.on("tab:close", function() { - this.dbg.close(); - }, this); - - return this; - }, - - // Render - render: function() { - return this.ready(); - }, - - - // Update debugegr state: stack, locals - updateState: function() { - this.locals.update(); - this.backtrace.update(); - this.breakpoints.update(); - } - }); - - return DebugTab; -}); diff --git a/addons/cb.deploy/client.js b/addons/cb.deploy/client.js deleted file mode 100644 index 34de51eb..00000000 --- a/addons/cb.deploy/client.js +++ /dev/null @@ -1,240 +0,0 @@ -define([], function() { - var Q = codebox.require("hr/promise"); - var _ = codebox.require("hr/utils"); - var dialogs = codebox.require("utils/dialogs"); - var box = codebox.require("core/box"); - var rpc = codebox.require("core/backends/rpc"); - var Command = codebox.require("models/command"); - var menu = codebox.require("core/commands/menu"); - var user = codebox.require("core/user"); - - var CryptoJS = codebox.require("vendors/crypto"); - - // Settings for deployment - var settings = user.settings("deploymentSolutions"); - - // Return list of solutions - var getSolutionTypes = function() { - return rpc.execute("deploy/solutions"); - }; - - // Return infos for a specific solution type - var getSolutionType = function(id) { - return getSolutionTypes().then(function(_types) { - var s = _.find(_types, function(_type) { - return _type.id == id; - }); - if (!s) throw "Invalid solution type"; - return s; - }); - }; - - // Id for a solution name - var solutionId = function(name) { - return CryptoJS.MD5(name).toString(); - }; - - // Add a solution - var addSolution = function(name, solution) { - var solutions = settings.get("solutions", {}); - var id = solutionId(name); - if (solutions[id]) return Q.reject("Solution already exists"); - solutions[id] = { - 'name': name, - 'type': solution, - 'settings': {} - }; - settings.set("solutions", solutions); - return settings.save().then(function() { - return solutions[id]; - }); - }; - - // Remove a solution - var removeSolution = function(id) { - var solutions = settings.get("solutions", {}); - if (!solutions[id]) return Q.reject("Invalid solution"); - delete solutions[id]; - settings.set("solutions", solutions); - return settings.save(); - }; - - // Run a solution - var runSolution = function(solution, actionId) { - if (_.isString(solution)) solution = getSolution(solution); - - return rpc.execute("deploy/run", { - 'solution': solution.type, - 'action': actionId, - 'config': solution.settings - }) - .then(function(data) { - // Handle shells - if (data.shellId) { - box.openTerminal(data.shellId, { - id: "deploy."+solutionId(solution.name)+"."+actionId, - title: data.title || "Deployment to "+solution.name+" ("+actionId+")", - icons: { - 'default': "fa-cloud-upload", - } - }); - } - // Handle message - else if (data.message) { - dialogs.alert("Deployment to "+solution.name+" ("+actionId+")", data.message); - } - }, function(err) { - dialogs.alert("Error with "+solution.name, err.message || err); - }); - }; - - // Return solution informations by its id - var getSolution = function(id) { - var solutions = settings.get("solutions", {}); - return solutions[id]; - }; - - var setSolutionSettings = function(id, _settings) { - var solutions = settings.get("solutions", {}); - solutions[id].settings = _settings; - settings.set("solutions", solutions); - }; - - // Open settings for a solution - var openSettings = function(id) { - var solution = getSolution(id); - return getSolutionType(solution.type).then(function(_type) { - return dialogs.fields("Configuration for "+_.escape(solution.name), _type.settings, solution.settings); - }) - .then(function(newSettings) { - setSolutionSettings(id, newSettings); - return settings.save(); - }); - }; - - // Command to add a new deployment solution - var addCommand = Command.register("deploy.solutions.add", { - category: "Deployment", - title: "Add Solution", - description: "Add a solution", - offline: false, - action: function(page) { - getSolutionTypes().then(function(solutionTypes) { - return dialogs.fields("Add Deployment Solution", { - name: { - type: "text", - label: "Label" - }, - solution: { - type: "select", - label: "Type", - options: _.object(_.map(solutionTypes, function(solution) { - return [ - solution.id, - solution.name - ]; - })) - } - }); - }) - .then(function(data) { - if (!data.name || !data.solution) throw "Need 'name' and 'solution'"; - return addSolution(data.name, data.solution); - }) - .then(function(solution) { - return openSettings(solutionId(solution.name)); - }); - } - }); - - // Command to remove a solution - var removeCommand = Command.register("deploy.solutions.remove", { - category: "Deployment", - title: "Remove Solution", - description: "Remove a solution", - offline: false, - action: function() { - dialogs.select("Remove Deployment Solution", - "Select a solution, this solution and its configuration will be removed from your settings.", - _.chain(settings.get("solutions", {})) - .map(function(solution, id) { - return [id, solution.name] - }) - .object() - .value()).then(removeSolution); - } - }); - - // Deploy Menu - var deployMenu = menu.register("deploy", { - title: "Deploy", - position: 90, - offline: false - }); - - // Update list of solutions - var updateSolutions = function() { - return getSolutionTypes().then(function(_types) { - var solutions = settings.get("solutions", {}); - - deployMenu.clearMenu(); - - // Add command to create new solutions - deployMenu.menuSection(_.compact([ - addCommand, - _.size(solutions) > 0 ? removeCommand : null - ])); - - // Add all solutions - if (_.size(solutions) == 0) return; - deployMenu.menuSection( - _.chain(solutions) - .map(function(solution, solutionId) { - var solutionType = _.find(_types, function(_type) { - return _type.id == solution.type; - }); - if (!solutionType) return null; - - var command = Command.register({ - title: solution.name, - type: "menu", - offline: false, - action: function() { - openSettings(solutionId(solution.name)); - } - }); - - command.menuSection( - _.map(solutionType.actions, function(action) { - return { - title: action.name, - offline: false, - action: function() { - return runSolution(solution, action.id); - } - }; - }) - ); - - command.menuSection([ - { - title: "Configure", - offline: false, - action: function() { - openSettings(solutionId); - } - } - ]); - - return command; - }) - .compact() - .value() - ); - }); - - }; - - updateSolutions(); - settings.change(updateSolutions); -}); \ No newline at end of file diff --git a/addons/cb.deploy/package.json b/addons/cb.deploy/package.json deleted file mode 100644 index c341704f..00000000 --- a/addons/cb.deploy/package.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "name": "cb.deploy", - "version": "0.1.0", - "title": "Project", - "description": "Deployment menu for all solutions", - "homepage": "https://github.com/FriendCode/codebox", - "license": "Apache", - "author": { - "name": "Codebox", - "email": "contact@friendco.de", - "url": "https://www.codebox.io" - }, - "client": { - "main": "client" - }, - "engines": { - "codebox": ">=0.7.0" - } -} \ No newline at end of file diff --git a/addons/cb.files.editor/ace.js b/addons/cb.files.editor/ace.js deleted file mode 100644 index 7090ee09..00000000 --- a/addons/cb.files.editor/ace.js +++ /dev/null @@ -1,10 +0,0 @@ -define([ - "ace/ace", - - // All the ace extensions we used - "ace/ext-modelist", - "ace/ext-language_tools", - "ace/ext-whitespace" -], function() { - return window.ace; -}); \ No newline at end of file diff --git a/addons/cb.files.editor/build.sh b/addons/cb.files.editor/build.sh deleted file mode 100755 index e6b2524b..00000000 --- a/addons/cb.files.editor/build.sh +++ /dev/null @@ -1,55 +0,0 @@ -#!/bin/bash - -# This script will prepare ace for running properly - -RM_EXTENSIONS=(elastic_tabstops_lite chromevox statusbar emmet error_marker keybinding_menu old_ie textarea themelist static_highlight split spellcheck settings_menu) -RM_LANG=(abap cobol forth mushcode vbscript tcl velocity pascal powershell asciidoc apache_conf ada soy_template verilog vhdl autohotkey batchfile c9search) - -# Sed like command using perl -# We need this because on OS X, sed does not support ignoring case -function PSED { - perl -C -e 'use utf8;' -i -pe $1 $2 -} - -# Remove useless extensions -for ext in ${RM_EXTENSIONS[*]} -do - echo "Remove extension $ext" - rm -f ace/ext-$ext.js -done - -# Remove languages -for lang in ${RM_LANG[*]} -do - echo "Remove language $lang" - - # Remove the files - rm -f "ace/mode-$lang.js" "ace/snippets/$lang.js" "ace/worker-$lang.js" - - # Remove any references in ext-modelist - - # Remove extension mapping - PSED "s/,?${lang}\:\[\"[^\"]+?\"\]//gi" ace/ext-modelist.js - - # Remove readable name mapping - PSED "s/,?${lang}\:\"\w+\"//gi" ace/ext-modelist.js -done - -# Cleanup our previous replaces -# Remove any bad comas left over from modelist -PSED "s/\{,/{/gi" ace/ext-modelist.js -PSED "s/,\}/{/gi" ace/ext-modelist.js - -# Detect empty snippets -# using the value of their 'snippetText' variable -SREGEX="snippetText=(\"\"|\'\')" - -# Remove empty snippet files -find ./ace/snippets -name "*.js" -print | \ -xargs grep -E ${SREGEX} -l | \ -xargs rm -f - - -# Remove useless themes -echo "Removes themes" -rm -rf ace/theme-*.js \ No newline at end of file diff --git a/addons/cb.files.editor/client.js b/addons/cb.files.editor/client.js deleted file mode 100644 index 9619f770..00000000 --- a/addons/cb.files.editor/client.js +++ /dev/null @@ -1,28 +0,0 @@ -define([ - "ace", - "editor/view" -], function(ace, FileEditorView) { - var $ = codebox.require("hr/dom"); - var commands = codebox.require("core/commands/toolbar"); - var files = codebox.require("core/files"); - - var aceconfig = ace.require("ace/config"); - aceconfig.set("basePath", "static/addons/cb.files.editor/ace"); - - // Add files handler - files.addHandler("ace", { - 'name': "Edit", - 'fallback': true, - 'setActive': true, - 'position': 5, - 'View': FileEditorView, - 'valid': function(file) { - return (!file.isDirectory()); - } - }); - - // Return globals - return { - 'ace': ace - }; -}); \ No newline at end of file diff --git a/addons/cb.files.editor/download_ace.sh b/addons/cb.files.editor/download_ace.sh deleted file mode 100755 index 02e24e97..00000000 --- a/addons/cb.files.editor/download_ace.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash - -# Ace version to pull -ACE_VERSION="ec3677e978de275bbe1ff8f21f4a157bdb9b8f9e" -ACE_URL="https://github.com/FriendCode/ace-builds/archive/${ACE_VERSION}.tar.gz" - -# Ace build we want to keep -ACE_SUB="src-min-noconflict" - -# Current folder -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - -# Destination folder -DEST="${DIR}/ace" - -# Make sure $DEST exists -mkdir -p ${DEST} - -# Check if it's already downloaded -if [ -f "${DEST}/ace.js" ]; then - echo "Ace is already downloaded" - echo "'rm -rf ace' if you want to redownload" - exit 0 -fi - -# Download tar.gz and pipe to tar -# decompressing it to $DEST -wget -O - ${ACE_URL} | tar -xzv -C ${DEST} --strip-components=2 ace-builds-${ACE_VERSION}/${ACE_SUB} diff --git a/addons/cb.files.editor/editor/breakpoints.js b/addons/cb.files.editor/editor/breakpoints.js deleted file mode 100644 index 8bad72b9..00000000 --- a/addons/cb.files.editor/editor/breakpoints.js +++ /dev/null @@ -1,102 +0,0 @@ -define([], function() { - var hr = codebox.require("hr/hr"); - - var EditorBreakpoints = hr.Class.extend({ - initialize: function() { - var that = this; - EditorBreakpoints.__super__.initialize.apply(this, arguments); - - this.editor = this.options.editor; - this.$editor = this.editor.editor; - - // Breakpoints list change, it signals the change to the box - this.$editor.session.on("changeBreakpoint", function() { - that.signalBreakpoints(); - }); - - // Add remove breakpoints by clicking the gutter - this.$editor.on("guttermousedown", function(e) { - var target = e.domEvent.target; - if (target.className.indexOf("ace_gutter-cell") == -1) - return; - if (!e.editor.isFocused()) - return; - if (e.clientX > 25 + target.getBoundingClientRect().left) - return; - - var row = e.getDocumentPosition().row; - - if (that.hasBreakpoint(row)) { - e.editor.session.clearBreakpoint(row) - } else { - e.editor.session.setBreakpoint(row); - } - e.stop(); - }); - - // Document change -> update breakpoints list - this.$editor.session.doc.on("change", function(e) { - var delta = e.data; - var range = delta.range; - var changed = false; - - if (range.end.row == range.start.row) - return; - - var len, firstRow; - len = range.end.row - range.start.row; - if (delta.action == "insertText") { - firstRow = range.start.column ? range.start.row + 1 : range.start.row; - } - else { - firstRow = range.start.row; - } - - if (delta.action[0] == "i") { - var args = Array(len); - args.unshift(firstRow, 0); - changed = true; - that.$editor.session.$breakpoints.splice.apply(that.$editor.session.$breakpoints, args); - } - else { - var rem = that.$editor.session.$breakpoints.splice(firstRow + 1, len); - - if (!that.$editor.session.$breakpoints[firstRow]) { - for (var i = rem.length; i--; ) { - if (rem[i]) { - changed = true; - that.$editor.session.$breakpoints[firstRow] = rem[i]; - break; - } - } - } - } - - if (changed) that.signalBreakpoints(); - }); - }, - - // Return list of active breakpoints in ace - getBreakpoints: function() { - return _.chain(this.$editor.session.getBreakpoints() || {}) - .map(function(value, key) { - if (!value) return null; - return parseInt(key)+1; - }) - .compact() - .value(); - }, - - // Check if has breakpoint at a line - hasBreakpoint: function(row) { - return _.contains(this.getBreakpoints(), row+1) - }, - - // Signal breakpoints list - signalBreakpoints: function() { - this.editor.model.setBreakpoints(this.getBreakpoints()); - } - }); - - return EditorBreakpoints; -}); \ No newline at end of file diff --git a/addons/cb.files.editor/editor/codecomplete.js b/addons/cb.files.editor/editor/codecomplete.js deleted file mode 100644 index 8f2fe97a..00000000 --- a/addons/cb.files.editor/editor/codecomplete.js +++ /dev/null @@ -1,31 +0,0 @@ -define([ - "ace" -], function(ace) { - var rpc = codebox.require("core/backends/rpc"); - var langTools = ace.require("ace/ext/language_tools"); - - var normalizeTag = function(tag) { - return { - 'name': tag.name, - 'value': tag.name, - 'score': 0, - 'meta': tag.meta || "" - }; - }; - - langTools.addCompleter({ - getCompletions: function(editor, session, pos, prefix, callback) { - if (prefix.length === 0) { callback(null, []); return } - - rpc.execute("codecomplete/get", { - 'query': prefix - }).then(function(data) { - callback(null, _.map(data.results, normalizeTag)); - }, function(err) { - callback(err); - }); - } - }); - - return {}; -}); \ No newline at end of file diff --git a/addons/cb.files.editor/editor/jshint.js b/addons/cb.files.editor/editor/jshint.js deleted file mode 100644 index 194bd2fe..00000000 --- a/addons/cb.files.editor/editor/jshint.js +++ /dev/null @@ -1,48 +0,0 @@ -define([], function() { - var File = codebox.require("models/file"); - var box = codebox.require("core/box"); - var Q = codebox.require("hr/promise"); - var _ = codebox.require("hr/utils"); - - var jshintFile = new File(); - - // Read the JSHint configuration from a file - var readJshintSettings = _.memoize(function() { - // Get file - return jshintFile.getByPath("/.jshintrc") - .then(function() { - //Read file - return jshintFile.read(); - }) - .then(function(content) { - // Parse JSON - return JSON.parse(content); - }); - }); - - // Apply JSHint config from a file to an editor - var applyJshintSettings = function(editor) { - var session = editor.session; - if (session.getMode().$id != "ace/mode/javascript") return Q.reject(new Error("Not a javascript editor")); - if (!session.$worker) return Q.reject(new Error("No JSHint worker")); - - return readJshintSettings() - .then(function(options) { - if (session.$worker) { - //session.$worker.send("changeOptions",[ {undef: true}]) - // or - session.$worker.send("setOptions",[options]) - } - return options; - }); - }; - - // Clear memoize cache when file change - jshintFile.on("file:change", function(e) { - readJshintSettings.cache = {}; - }); - - return { - 'applySettings': applyJshintSettings - }; -}); \ No newline at end of file diff --git a/addons/cb.files.editor/editor/settings.js b/addons/cb.files.editor/editor/settings.js deleted file mode 100644 index 61e696dd..00000000 --- a/addons/cb.files.editor/editor/settings.js +++ /dev/null @@ -1,93 +0,0 @@ -define([], function() { - var settings = codebox.require("core/settings"); - - // Add settings - var userSettings = settings.add({ - 'namespace': "editor", - 'title': "Code Editor", - 'defaults': { - 'theme': "github", - 'fontsize': "12", - 'printmargincolumn': 80, - 'showinvisibles': false, - 'showprintmargin': false, - 'highlightactiveline': false, - 'wraplimitrange': 80, - 'enablesoftwrap': false, - 'enablesofttabs': true, - 'stripspaces': false, - 'autocollaboration': true, - 'tabsize': 4, - 'keyboard': "textinput" - }, - 'fields': { - 'keyboard': { - 'label': "Keyboard mode", - 'type': "select", - 'options': { - "vim": "Vim", - "emacs": "Emacs", - "textinput": "Default" - } - }, - 'fontsize': { - 'label': "Font Size", - 'type': "number", - 'min': 10, - 'max': 30, - 'step': 1 - }, - 'printmargincolumn': { - 'label': "Print Margin Column", - 'type': "number", - 'min': 0, - 'max': 1000, - 'step': 1 - }, - 'wraplimitrange': { - 'label': "Wrap Limit Range", - 'type': "number", - 'min': 0, - 'max': 1000, - 'step': 1 - }, - 'autocollaboration': { - 'label': "Auto enable realtime collaboration", - 'type': "checkbox" - }, - 'showprintmargin': { - 'label': "Show Print Margin", - 'type': "checkbox" - }, - 'showinvisibles': { - 'label': "Show Invisibles", - 'type': "checkbox" - }, - 'highlightactiveline': { - 'label': "Highlight Active Line", - 'type': "checkbox" - }, - 'enablesoftwrap': { - 'label': "Enable Soft Wrap", - 'type': "checkbox" - }, - 'enablesofttabs': { - 'label': "Use Soft Tabs", - 'type': "checkbox" - }, - 'stripspaces': { - 'label': "Strip Whitespaces", - 'type': "checkbox" - }, - 'tabsize': { - 'label': "Tab Size", - 'type': "number", - 'min': 0, - 'max': 1000, - 'step': 1 - } - } - }); - - return userSettings; -}); \ No newline at end of file diff --git a/addons/cb.files.editor/editor/view.js b/addons/cb.files.editor/editor/view.js deleted file mode 100644 index fd723f82..00000000 --- a/addons/cb.files.editor/editor/view.js +++ /dev/null @@ -1,583 +0,0 @@ -define([ - "ace", - "editor/breakpoints", - "editor/codecomplete", - "editor/jshint", - "editor/settings", - "theme/textmate", - "text!templates/file.html", - "less!stylesheets/file.less", -], function(ace, Breakpoints, codecomplete, jshint, editorSettings, aceDefaultTheme, templateFile) { - var _ = codebox.require("hr/utils"); - var $ = codebox.require("hr/dom"); - var hr = codebox.require("hr/hr"); - var alerts = codebox.require("utils/alerts"); - var FilesTabView = codebox.require("views/files/tab"); - var FileSync = codebox.require("utils/filesync"); - var user = codebox.require("core/user"); - var menu = codebox.require("core/commands/menu"); - var settings = codebox.require("core/settings"); - var Command = codebox.require("models/command"); - var themes = codebox.require("core/themes"); - var box = codebox.require("core/box"); - var collaborators = codebox.require("core/collaborators"); - var keyboard = codebox.require("utils/keyboard"); - var debugManager = codebox.require("core/debug/manager"); - - var logging = hr.Logger.addNamespace("editor"); - - // Import ace - var aceRange = ace.require("ace/range"); - var aceModes = ace.require("ace/ext/modelist"); - var aceLangs = ace.require("ace/ext/language_tools"); - var aceWhitespace = ace.require("ace/ext/whitespace"); - - - var FileEditorView = FilesTabView.extend({ - className: "addon-files-aceeditor", - templateLoader: "text", - template: templateFile, - defaults: {}, - events: {}, - shortcuts: { - "mod+s": "saveFile", - "mod+r": "runFile", - "mod+f": "searchInFile" - }, - - // Constructor - initialize: function() { - var that = this; - FileEditorView.__super__.initialize.apply(this, arguments); - - this.markersS = {}; - this.markersC = {}; - this._op_set = false; - - // Syntax menu command - var syntaxMenu = new Command({}, { - 'title': "Syntax", - 'type': "menu" - }); - syntaxMenu.menu.add(_.map(aceModes.modesByName, function(mode, name) { - return { - 'title': mode.caption, - 'action': function() { - that.setMode(name); - } - } - })); - - // Toggle collaboration - this.collaborationToggle = new Command({}, { - 'type': "checkbox", - 'title': "Toggle Collaboration Mode", - 'flags': this.model.isNewfile() ? "hidden": "", - 'offline': false, - 'action': function(state) { - that.editor - that.sync.updateEnv({ - 'sync': state - }); - } - }); - - // Collaborators - this.collaboratorsMenu = new Command({}, { - 'title': "Collaborators", - 'type': "menu", - 'flags': "disabled" - }); - - // Statusbar - this.editorStatusCommand = new Command({}, { - 'title': "Line 1, Column 1", - 'type': "label" - }); - this.tab.statusbar.add(this.editorStatusCommand); - this.tab.statusbar.add(this.collaboratorsMenu); - this.tab.statusbar.add(syntaxMenu); - - // Tab menu - this.tab.menu.menuSection([ - { - 'type': "action", - 'title': "Save", - 'shortcuts': [ - "mod+s" - ], - 'bindKeyboard': false, - 'action': function() { - that.sync.save(); - } - }, - { - 'type': "action", - 'title': "Run File", - 'shortcuts': [ - "mod+r" - ], - 'flags': this.model.isNewfile() ? "disabled": "", - 'bindKeyboard': false, - 'action': function() { - that.model.run(); - } - } - ]).menuSection([ - this.collaborationToggle, - syntaxMenu - ]).menuSection([ - { - 'title': "Convert Indentation to Spaces", - 'action': function() { - aceWhitespace.convertIndentation(that.editor.session, " ", editorSettings.user.get("tabsize", 4)); - } - }, - { - 'title': "Convert Indentation to Tabs", - 'action': function() { - aceWhitespace.convertIndentation(that.editor.session, "\t", 1); - } - }, - { - 'title':"Strip Whitespaces", - 'action': function() { - that.stripspaces(); - } - } - ]).menuSection([ - this.collaboratorsMenu - ]).menuSection([{ - 'type': "action", - 'title': "Settings", - 'offline': false, - 'action': function() { - settings.open("editor"); - } - }]); - - // Create sync - this.sync = new FileSync(); - this.sync.on("update:env", function(options) { - if (options.reset) { - this._op_set = true; - this.editor.setValue(""); - this._op_set = false; - } - this.collaborationToggle.toggleFlag("active", options.sync); - this.collaboratorsMenu.toggleFlag("disabled", !options.sync); - }, this); - - // Create base ace editor instance and configure it - this.$editor = $("
", { - 'class': "editor-ace" - }); - this.editor = ace.edit(this.$editor.get(0)); - var $doc = this.editor.session.doc; - - // Set base options - this.editor.session.setUseWorker(true); - this.editor.setOptions({ - enableBasicAutocompletion: true, - enableSnippets: true - }); - - // Force unix newline mode (for cursor position calcul) - $doc.setNewLineMode("unix"); - this.setOptions(); - - // Debug and Breakpoints - this.breakpoints = new Breakpoints({ - editor: this - }); - - // Read-only when debugger is active - this.listenTo(debugManager, "state", function(state) { - this.editor.setReadOnly(state); - }); - this.editor.setReadOnly(debugManager.isActive()); - - // Show active debug line - this.listenTo(debugManager, "position", this.updateDebugLine); - this.updateDebugLine(); - - // Bind settings changement - var update = function() { - var ops = _.extend({}, { - "mode": this.options.mode, - "readonly": this.options.readonly - }); - this.setOptions(ops); - }; - editorSettings.user.change(update, this); - user.settings("themes").change(update, this); - - // Bind editor changement -> sync - this.editor.getSession().selection.on('changeSelection', function(){ - var selection = that.editor.getSelectionRange(); - that.sync.updateUserSelection(selection.start.column, selection.start.row, selection.end.column, selection.end.row); - }); - this.editor.getSession().selection.on('changeCursor', function(){ - var cursor = that.editor.getSession().getSelection().getCursor(); - that.sync.updateUserCursor(cursor.column, cursor.row); - that.editorStatusCommand.set("title", "Line "+(cursor.row+1)+", Column "+(cursor.column+1)); - }); - this.editor.getSession().on("changeMode", function() { - jshint.applySettings(that.editor); - }); - - - // Clear command on Windows/ChromeOS Ctrl-Shift-P - this.editor.commands.addCommands([{ - name: "commandpalette", - bindKey: { - win: "Ctrl-Shift-P", - mac: "Command-Shift-P" - }, - exec: function(editor, line) { - return false; - }, - readOnly: true - }]); - - // Send change - $doc.on('change', function(d) { - if (that._op_set) return; - that.sync.updateContent(that.editor.session.getValue()); - }); - - // Bind sync -> editor - this.sync.on("file:mode", function(mode) { - this.setMode(mode) - }, this); - this.sync.on("content", function(content, oldcontent, patches) { - var selection, cursor_lead, cursor_anchor, scroll_y, operations; - - // if resync patches is null - patches = patches || []; - - // Calcul operaitons from patch - operations = this.sync.patchesToOps(patches); - - // Do some operations on selection to preserve selection - selection = this.editor.getSession().getSelection(); - - scroll_y = this.editor.getSession().getScrollTop(); - - cursor_lead = selection.getSelectionLead(); - cursor_lead = this.sync.cursorApplyOps({ - x: cursor_lead.column, - y: cursor_lead.row - }, operations, oldcontent); - - cursor_anchor = selection.getSelectionAnchor(); - cursor_anchor = this.sync.cursorApplyOps({ - x: cursor_anchor.column, - y: cursor_anchor.row - }, operations, oldcontent); - - // Set editor content - this._op_set = true; - - // Apply ace delta all in once - $doc.applyDeltas( - _.map(operations, function(op) { - return { - action: op.type+"Text", - range: { - start: that.posFromIndex(op.index), - end: that.posFromIndex(op.index + op.content.length) - }, - text: op.content - } - }) - ); - - // Check document content is as expected - if ($doc.getValue() != content) { - logging.error("Invalid operation ", content, $doc.getValue()); - $doc.setValue(content); - this.sync.sendSync(); - } - this._op_set = false; - - // Move cursors - this.editor.getSession().setScrollTop(scroll_y); - - cursor_anchor = this.sync.cursorPosByindex(cursor_anchor, content); - this.editor.getSession().getSelection().setSelectionAnchor(cursor_anchor.y, cursor_anchor.x); - - cursor_lead = this.sync.cursorPosByindex(cursor_lead, content); - this.editor.getSession().getSelection().selectTo(cursor_lead.y, cursor_lead.x); - }, this); - - // Participant cursor moves - this.sync.on("cursor:move", function(cId, c) { - var name, range = new aceRange.Range(c.y, c.x, c.y, c.x+1); - - // Remove old cursor - if (this.markersC[cId]) this.editor.getSession().removeMarker(this.markersC[cId]); - - // Calcul name - name = cId - var participant = collaborators.getById(cId); - if (participant) name = participant.get("name"); - - // Add new cursor - this.markersC[cId] = this.editor.getSession().addMarker(range, "marker-cursor marker-"+c.color.replace("#", ""), function(html, range, left, top, config){ - html.push("
" - + "
 "+name+" 
" - + "
 
"); - }, true); - }, this); - - // Participant selection - this.sync.on("selection:move", function(cId, c) { - var range = new aceRange.Range(c.start.y, c.start.x, c.end.y, c.end.x); - if (this.markersS[cId]) this.editor.getSession().removeMarker(this.markersS[cId]); - this.markersS[cId] = this.editor.getSession().addMarker(range, "marker-selection marker-"+c.color.replace("#", ""), "line", false); - }, this); - - // Remove a cursor/selection - this.sync.on("cursor:remove selection:remove", function(cId) { - if (this.markersC[cId]) this.editor.getSession().removeMarker(this.markersC[cId]); - if (this.markersS[cId]) this.editor.getSession().removeMarker(this.markersS[cId]); - delete this.markersC[cId]; - delete this.markersS[cId] - }, this); - - // Participants list change - this.sync.on("participants", function() { - this.collaboratorsMenu.set("label", _.size(this.sync.participants)); - this.collaboratorsMenu.menu.reset(_.map(this.sync.participants, function(participant) { - return { - 'type': "action", - 'title': participant.user.get("name"), - 'action': function() { - that.editor.getSession().getSelection().setSelectionAnchor(participant.cursor.y, participant.cursor.x); - that.editor.getSession().getSelection().selectTo(participant.cursor.y, participant.cursor.x); - that.editor.focus(); - } - } - })); - }, this); - - // Parent tab - this.tab.on("tab:layout", function() { - this.editor.resize(); - this.editor.renderer.updateFull(); - }, this); - this.tab.on("tab:state", function(state) { - if (state) this.focus(); - }, this); - this.tab.on("tab:close", function() { - // Clear breakpoints - this.model.clearBreakpoints(); - - // Finish sync - this.sync.close(); - - // Destroy the editor - this.editor.destroy(); - - // Destroy events and instance - this.off(); - this.stopListening(); - }, this); - - // Bind editor sync state changements - this.sync.on("sync:state", function(state) { - this.editor.setReadOnly(!state); - if (!state) { - this.tab.setTabState("warning", true); - } else { - this.tab.setTabState("warning", false); - } - }, this); - this.sync.on("mode", function(mode) { - this.tab.setTabState("sync", mode == this.sync.modes.SYNC); - }, this); - this.sync.on("close", function(mode) { - this.tab.closeTab(); - }, this); - this.sync.on("error", function(err) { - alerts.show("Error: "+(err.message || err), 3000); - }, this); - - this.sync.on("sync:modified", function(state) { - this.tab.setTabState("modified", state); - }, this); - - this.sync.on("sync:loading", function(state) { - this.tab.setTabState("loading", state); - }, this); - - this.sync.once("content", function() { - this.adaptOptions(); - }, this); - - // Define file for code editor - this.sync.setFile(this.model, { - 'sync': editorSettings.user.get("autocollaboration") ? collaborators.size() > 1 : false - }); - - // Options chnagements - this.on("file:options", this.adaptOptions, this); - - this.focus(); - - var $input = this.editor.textInput.getElement(); - var handleKeyEvent = function(e) { - if (!e.altKey && !e.ctrlKey && !e.metaKey) return; - keyboard.enableKeyEvent(e); - }; - $input.addEventListener('keypress', handleKeyEvent, false); - $input.addEventListener('keydown', handleKeyEvent, false); - $input.addEventListener('keyup', handleKeyEvent, false); - }, - - // Finish rendering - finish: function() { - this.$editor.appendTo(this.$(".editor-inner")); - this.editor.resize(); - this.editor.renderer.updateFull(); - - return FileEditorView.__super__.finish.apply(this, arguments); - }, - - // Focus editor - focus: function() { - this.editor.resize(); - this.editor.renderer.updateFull(); - this.editor.focus(); - return this; - }, - - // Define editor options - setOptions: function(opts) { - var that = this; - this.options = _.defaults(opts || {}, editorSettings.user.all({}), { - mode: "text", - fontsize: "12", - printmargincolumn: 80, - showprintmargin: false, - showinvisibles: false, - highlightactiveline: false, - wraplimitrange: 80, - enablesoftwrap: false, - keyboard: "textinput", - enablesofttabs: true, - tabsize: 4 - }); - - // Ste mode - this.setMode(this.options.mode); - - // Det keyboard mode - ace.config.loadModule(["keybinding", "ace/keyboard/"+this.options.keyboard], function(binding) { - if (binding && binding.handler) that.editor.setKeyboardHandler(binding.handler); - }); - - this.editor.setTheme(themes.current().editor.theme || aceDefaultTheme); - this.$editor.css("font-size", this.options.fontsize+"px"); - this.editor.setPrintMarginColumn(this.options.printmargincolumn); - this.editor.setShowPrintMargin(this.options.showprintmargin); - this.editor.setShowInvisibles(this.options.showinvisibles); - this.editor.setHighlightActiveLine(this.options.highlightactiveline); - this.editor.getSession().setUseWrapMode(this.options.enablesoftwrap); - this.editor.getSession().setWrapLimitRange(this.options.wraplimitrange, this.options.wraplimitrange); - this.editor.getSession().setUseSoftTabs(this.options.enablesofttabs); - this.editor.getSession().setTabSize(this.options.tabsize); - return this; - }, - - // Define mdoe option - setMode: function(lang) { - this.options.mode = lang; - this.editor.getSession().setMode("ace/mode/"+lang); - }, - - // Get position (row, column) from index in file - posFromIndex: function(index) { - var row, lines; - lines = this.editor.session.doc.getAllLines(); - for (row = 0; row < lines.length; row++) { - var line = lines[row]; - if (index <= (line.length)) break; - index = index - (line.length + 1); - } - - return { - 'row': row, - 'column': index - }; - }, - - // (action) Save file - saveFile: function(e) { - if (e) e.preventDefault(); - - if (editorSettings.user.get("stripspaces")) { - this.stripspaces(); - } - - this.sync.save(); - }, - - stripspaces: function(e) { - if (e) e.preventDefault(); - - // strip all whitespaces from the current document - var doc = this.editor.session.doc; - var lines = doc.getAllLines(); - - for (var i = 0; i < lines.length; ++i) { - var index = lines[i].search(/\s+$/); - if (index !== -1 && index != 0) - doc.removeInLine(i, index, lines[i].length); - } - }, - - // (action) Run this file - runFile: function(e) { - if (e) e.preventDefault(); - this.model.run(); - }, - - // (action) Open search box - searchInFile: function(e) { - if (e) e.preventDefault(); - this.editor.execCommand("find"); - }, - - // Show active line in debug - updateDebugLine: function() { - var position = debugManager.getPosition(); - - // Clear previous marker - if (this.debugMarker != null) { - this.editor.session.removeMarker(this.debugMarker); - this.debugMarker = null; - } - if (position && position.filename == this.model.path()) { - this.debugMarker = this.editor.session.addMarker(new aceRange.Range(parseInt(position.line) - 1, 0, parseInt(position.line) - 1, 2000), "marker-debug", "line", false); - console.log(this.debugMarker); - } - }, - - // Update current line according to options - adaptOptions: function() { - if (this.fileOptions.line) { - this.editor.gotoLine(this.fileOptions.line); - } else if (this.fileOptions.pattern) { - this.editor.find(this.fileOptions.pattern,{ - regExp: false, - backwards: false, - wrap: true - }); - } - } - }); - - return FileEditorView; -}); diff --git a/addons/cb.files.editor/package.json b/addons/cb.files.editor/package.json deleted file mode 100644 index afa3e10d..00000000 --- a/addons/cb.files.editor/package.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "name": "cb.files.editor", - "version": "0.1.1", - "title": "Code Editor", - "description": "Code Editor with ACE.", - "homepage": "https://github.com/FriendCode/codebox", - "license": "Apache", - "author": { - "name": "Codebox", - "email": "contact@friendco.de", - "url": "https://www.codebox.io" - }, - "client": { - "main": "client", - "provides": [ - "ace" - ], - "resources": [ - "ace/**" - ] - }, - "scripts": { - "postinstall": "./download_ace.sh && ./build.sh" - }, - "engines": { - "codebox": ">=0.7.0" - } -} diff --git a/addons/cb.files.editor/stylesheets/file.less b/addons/cb.files.editor/stylesheets/file.less deleted file mode 100644 index 528ada77..00000000 --- a/addons/cb.files.editor/stylesheets/file.less +++ /dev/null @@ -1,114 +0,0 @@ -.mixin-cursor-color(@color) { - @pseudo-selector: ~".marker-@{color}"; - @{pseudo-selector} { - &.marker-selection { - background: ~"#@{color}"; - } - } -} - -.addon-files-aceeditor { - .file-participants { - a { - position: relative; - overflow: hidden; - padding: 6px 10px; - border-left: 6px solid #eee; - } - } - - .editor-inner { - .editor-ace { - -webkit-font-smoothing: subpixel-antialiased; - font-smoothing: subpixel-antialiased; - - position: absolute !important; - top: 0px; - bottom: 0px; - left: 0px; - right: 0px; - border-radius: 0px; - padding: 0px; - - .marker-debug { - position: absolute; - background: #5e9ef3; - opacity: .5; - width: 100% !important; - } - - .marker-cursor { - position: absolute; - border-left: 2px solid red; - opacity: 1; - } - - .marker-selection { - position: absolute; - background: red; - opacity: 0.2; - } - .mixin-cursor-color("1abc9c"); - .mixin-cursor-color("9b59b6"); - .mixin-cursor-color("e67e22"); - .mixin-cursor-color("16a085"); - .mixin-cursor-color("c0392b"); - .mixin-cursor-color("2980b9"); - .mixin-cursor-color("f39c12"); - .mixin-cursor-color("8e44ad"); - - .marker-cursor { - position: absolute; - z-index: 5; - border-left: 2px solid #0ff; - margin-left: -1px; - right: 5px; - text-align: right; - color: #ff0; - border-bottom: 1px dotted rgba(0,255,255,0.30); - } - .marker-cursor-nametag { - position: absolute; - bottom: -1px; - right: 0px; - text-align: right; - color: #fff; - background: #0ff; - padding: 0px; - padding-left: 3px; - padding-right: 3px; - opacity: 1; - font-family: Arial, sans-serif; - font-weight: 600; - pointer-events: auto; - cursor: help; - } - .marker-cursor-nametag-flag { - position: absolute; - bottom: 0px; - left: -6px; - width: 0px; - height: 0px; - border: 3px solid rgba(0,255,255,0.00); - border-right: 3px solid #0ff; - border-bottom: 3px solid #0ff; - } - - .ace_gutter-cell.ace_breakpoint { - position: relative; - - &:before { - content: " "; - width: 10px; - height: 10px; - border-radius: 16px; - border: 2px solid #fff; - position: absolute; - left: 4px; - background: #5E9EF3; - top: 3px; - } - } - } - } -} diff --git a/addons/cb.files.editor/templates/file.html b/addons/cb.files.editor/templates/file.html deleted file mode 100644 index cbb2e425..00000000 --- a/addons/cb.files.editor/templates/file.html +++ /dev/null @@ -1,3 +0,0 @@ -
-
-
\ No newline at end of file diff --git a/addons/cb.files.editor/theme/textmate.js b/addons/cb.files.editor/theme/textmate.js deleted file mode 100644 index 1f0fa775..00000000 --- a/addons/cb.files.editor/theme/textmate.js +++ /dev/null @@ -1,10 +0,0 @@ -define([ - "less!theme/textmate.less" -], function(cssContent) { - - return { - 'isDark': false, - 'cssClass': "ace-tm", - 'cssText': cssContent - } -}); \ No newline at end of file diff --git a/addons/cb.files.editor/theme/textmate.less b/addons/cb.files.editor/theme/textmate.less deleted file mode 100644 index 269f85cf..00000000 --- a/addons/cb.files.editor/theme/textmate.less +++ /dev/null @@ -1,182 +0,0 @@ - - -.ace_editor { - /* Search dialog */ - .ace_search, .ace_search.right { - right: 0px; - left: 0px; - max-width: none; - bottom: 0px; - top: auto; - border: 1px solid; - border-radius: 0px; - padding: 0px; - box-shadow: 2px 3px 5px rgba(0,0,0,.2); - - font-smoothing: subpixel-antialiased; - -webkit-font-smoothing: subpixel-antialiased; - - .ace_searchbtn_close { - margin: 9px 5px 0px 5px; - } - - .ace_search_field { - } - - .ace_search_form, .ace_replace_form { - border-radius: 0px; - margin: 4px; - } - - .ace_search_options { - text-align: left; - display: inline-block; - float: right; - margin: 0px; - padding: 4px; - height: 24px; - } - - .ace_button { - border-radius: 0px; - padding: 2px 4px; - margin: 0 3px 0 0; - display: inline-block; - } - - .ace_searchbtn, .ace_replacebtn{ - padding: 0px 5px; - border-radius: 0px; - } - } - - &.ace-tm { - background-color: #FFFFFF; - color: #4D4D4C; - - .ace_gutter { - background: transparent; - color: #4D4D4C - } - - .ace_print-margin { - width: 1px; - background: #f6f6f6 - } - - .ace_cursor { - color: #AEAFAD - } - - .ace_marker-layer .ace_selection { - background: #eaeaea; - } - - &.ace_multiselect .ace_selection.ace_start { - box-shadow: 0 0 3px 0px #FFFFFF; - border-radius: 2px - } - - .ace_marker-layer .ace_step { - background: rgb(255, 255, 0) - } - - .ace_marker-layer .ace_bracket { - margin: -1px 0 0 -1px; - border: 1px solid #D1D1D1 - } - - .ace_marker-layer .ace_active-line { - background: #EFEFEF - } - - .ace_gutter-active-line { - background-color : transparent; - } - - .ace_marker-layer .ace_selected-word { - border: 1px solid #D6D6D6 - } - - .ace_invisible { - color: #D1D1D1 - } - - .ace_keyword, - .ace_meta, - .ace_storage, - .ace_storage.ace_type, - .ace_support.ace_type { - color: #8959A8 - } - - .ace_keyword.ace_operator { - color: #3E999F - } - - .ace_constant.ace_character, - .ace_constant.ace_language, - .ace_constant.ace_numeric, - .ace_keyword.ace_other.ace_unit, - .ace_support.ace_constant, - .ace_variable.ace_parameter { - color: #F5871F - } - - .ace_constant.ace_other { - color: #666969 - } - - .ace_invalid { - color: #FFFFFF; - background-color: #C82829 - } - - .ace_invalid.ace_deprecated { - color: #FFFFFF; - background-color: #8959A8 - } - - .ace_fold { - background-color: #4271AE; - border-color: #4D4D4C - } - - .ace_entity.ace_name.ace_function, - .ace_support.ace_function, - .ace_variable { - color: #4271AE - } - - .ace_support.ace_class, - .ace_support.ace_type { - color: #C99E00 - } - - .ace_heading, - .ace_string { - color: #718C00 - } - - .ace_entity.ace_name.ace_tag, - .ace_entity.ace_other.ace_attribute-name, - .ace_meta.ace_tag, - .ace_string.ace_regexp, - .ace_variable { - color: #C82829 - } - - .ace_comment { - color: #8E908C - } - - .ace_indent-guide { - background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAACCAYAAACZgbYnAAAAE0lEQVQImWP4////f4bdu3f/BwAlfgctduB85QAAAABJRU5ErkJggg==) right repeat-y - } - - .ace_search { - border-color: #cbcbcb; - background: #e5e5e5; - } - } -} \ No newline at end of file diff --git a/addons/cb.files.image/client.js b/addons/cb.files.image/client.js deleted file mode 100644 index 899274be..00000000 --- a/addons/cb.files.image/client.js +++ /dev/null @@ -1,19 +0,0 @@ -define([ - "views/image" -], function(FileImageView) { - var _ = codebox.require("hr/utils"); - var files = codebox.require("core/files"); - - var imageExts = [ - ".png", ".jpg", ".gif", ".tiff", ".jpeg", ".bmp", ".webp", ".svg" - ]; - - files.addHandler("imageviewer", { - name: "Image Viewer", - position: 1, - View: FileImageView, - valid: function(file) { - return (!file.isDirectory() && _.contains(imageExts, file.extension())); - } - }); -}); \ No newline at end of file diff --git a/addons/cb.files.image/package.json b/addons/cb.files.image/package.json deleted file mode 100644 index 5364b006..00000000 --- a/addons/cb.files.image/package.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "name": "cb.files.image", - "version": "0.0.1", - "title": "Image Viewer", - "description": "Images files viewer (png, jpeg, gif).", - "homepage": "https://github.com/FriendCode/codebox", - "license": "Apache", - "author": { - "name": "Codebox", - "email": "contact@friendco.de", - "url": "https://www.codebox.io" - }, - "client": { - "main": "client" - }, - "engines": { - "codebox": ">=0.7.0" - } -} diff --git a/addons/cb.files.image/stylesheets/image.less b/addons/cb.files.image/stylesheets/image.less deleted file mode 100644 index 8e5abe6b..00000000 --- a/addons/cb.files.image/stylesheets/image.less +++ /dev/null @@ -1,5 +0,0 @@ -.addon-files-aceeditor { - .image { - - } -} \ No newline at end of file diff --git a/addons/cb.files.image/templates/image.html b/addons/cb.files.image/templates/image.html deleted file mode 100644 index 40e7dc5f..00000000 --- a/addons/cb.files.image/templates/image.html +++ /dev/null @@ -1 +0,0 @@ -
\ No newline at end of file diff --git a/addons/cb.files.image/views/image.js b/addons/cb.files.image/views/image.js deleted file mode 100644 index 9b0182ce..00000000 --- a/addons/cb.files.image/views/image.js +++ /dev/null @@ -1,19 +0,0 @@ -define([ - "text!templates/image.html", - "less!stylesheets/image.less" -], function(templateFile) { - var _ = codebox.require("hr/utils"); - var $ = codebox.require("hr/dom"); - var hr = codebox.require("hr/hr"); - var Dialogs = codebox.require("utils/dialogs"); - var FilesBaseView = codebox.require("views/files/base"); - - var FileImageView = FilesBaseView.extend({ - className: "addon-files-imageviewer", - templateLoader: "text", - template: templateFile, - events: {} - }); - - return FileImageView; -}); \ No newline at end of file diff --git a/addons/cb.files.preview/client.js b/addons/cb.files.preview/client.js deleted file mode 100644 index d6c621ba..00000000 --- a/addons/cb.files.preview/client.js +++ /dev/null @@ -1,35 +0,0 @@ -define([ - "views/preview_html", - "views/preview_markdown" -], function(PreviewHtml, PreviewMarkdown) { - var _ = codebox.require("hr/utils"); - var files = codebox.require("core/files"); - - var htmlExts = [ - ".html", ".htm" - ]; - - files.addHandler("preview", { - name: "HTML Preview", - icon: "eye", - position: 10, - View: PreviewHtml, - valid: function(file) { - return (!file.isDirectory() && _.contains(htmlExts, file.extension())); - } - }); - - var markdownExts = [ - ".md", ".markdown", ".txt" - ]; - - files.addHandler("preview-markdown", { - name: "Markdown Preview", - icon: "eye", - position: 10, - View: PreviewMarkdown, - valid: function(file) { - return (!file.isDirectory() && _.contains(markdownExts, file.extension())); - } - }); -}); \ No newline at end of file diff --git a/addons/cb.files.preview/package.json b/addons/cb.files.preview/package.json deleted file mode 100644 index a9f506a6..00000000 --- a/addons/cb.files.preview/package.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "name": "cb.files.preview", - "version": "0.0.1", - "title": "HTML / Markdown Preview", - "description": "Adds option to preview files in a new tab.", - "homepage": "https://github.com/invokr/codebox", - "license": "Apache", - "author": { - "name": "Robin Dietrich", - "email": "me@invokr.org", - "url": "https://github.com/invokr" - }, - "client": { - "main": "client" - }, - "engines": { - "codebox": ">=0.7.0" - }, - "dependencies": { - "markdown": "0.5.0" - } -} diff --git a/addons/cb.files.preview/settings.js b/addons/cb.files.preview/settings.js deleted file mode 100644 index d1b4a1fa..00000000 --- a/addons/cb.files.preview/settings.js +++ /dev/null @@ -1,17 +0,0 @@ -define([], function() { - var settings = codebox.require("core/settings"); - - return settings.add({ - 'namespace': "preview", - 'title': "Preview", - 'defaults': { - 'refresh': true - }, - 'fields': { - 'refresh': { - 'label': "Reload on Save", - 'type': "checkbox" - } - } - }); -}); \ No newline at end of file diff --git a/addons/cb.files.preview/stylesheets/preview.less b/addons/cb.files.preview/stylesheets/preview.less deleted file mode 100644 index bc878aa7..00000000 --- a/addons/cb.files.preview/stylesheets/preview.less +++ /dev/null @@ -1,19 +0,0 @@ -.addon-files-previewviewer { - height: 100%; - - iframe { - border: 0px; - width: 100%; - height: 100%; - background-color: #fff; - } - - .markdown { - border: 0px; - width: 100%; - height: 100%; - background-color: #fff; - margin-top: 1px; - padding: 3px; - } -} \ No newline at end of file diff --git a/addons/cb.files.preview/templates/preview_html.html b/addons/cb.files.preview/templates/preview_html.html deleted file mode 100644 index bcc3b8c9..00000000 --- a/addons/cb.files.preview/templates/preview_html.html +++ /dev/null @@ -1,3 +0,0 @@ -
- -
\ No newline at end of file diff --git a/addons/cb.files.preview/templates/preview_markdown.html b/addons/cb.files.preview/templates/preview_markdown.html deleted file mode 100644 index 6595a5bb..00000000 --- a/addons/cb.files.preview/templates/preview_markdown.html +++ /dev/null @@ -1 +0,0 @@ -
\ No newline at end of file diff --git a/addons/cb.files.preview/views/preview_html.js b/addons/cb.files.preview/views/preview_html.js deleted file mode 100644 index 9fc20ef9..00000000 --- a/addons/cb.files.preview/views/preview_html.js +++ /dev/null @@ -1,52 +0,0 @@ -define([ - "settings", - "text!templates/preview_html.html", - "less!stylesheets/preview.less" -], function(settings, templateFile) { - var _ = codebox.require("hr/utils"); - var $ = codebox.require("hr/dom"); - var box = codebox.require("core/box"); - var FilesTabView = codebox.require("views/files/tab"); - - var PreviewView = FilesTabView.extend({ - className: "addon-files-previewviewer", - templateLoader: "text", - template: templateFile, - events: {}, - - initialize: function() { - PreviewView.__super__.initialize.apply(this, arguments); - var that = this; - - // add refresh menu option - this.tab.menu.menuSection([ - { - 'type': "action", - 'title': "Refresh", - 'shortcuts': [ - "mod+r" - ], - 'bindKeyboard': true, - 'action': function() { - that.refresh(); - } - } - ]); - - // bind save event - box.on("box:watch:change:update", function() { - if (settings.user.get("refresh")) { - that.refresh(); - } - }, this); - - return this; - }, - - refresh: function() { - $(this.$el).find("iframe").attr('src', function ( i, val ) { return val; }); - } - }); - - return PreviewView; -}); diff --git a/addons/cb.files.preview/views/preview_markdown.js b/addons/cb.files.preview/views/preview_markdown.js deleted file mode 100644 index 7fe530f5..00000000 --- a/addons/cb.files.preview/views/preview_markdown.js +++ /dev/null @@ -1,58 +0,0 @@ -define([ - "settings", - "node_modules/markdown/lib/markdown", - "text!templates/preview_markdown.html", - "less!stylesheets/preview.less" -], function(settings, _markdown, templateFile) { - var _ = codebox.require("hr/utils"); - var $ = codebox.require("hr/dom"); - var box = codebox.require("core/box"); - var FilesTabView = codebox.require("views/files/tab"); - - var markdown = window.markdown; - - var MarkdownView = FilesTabView.extend({ - className: "addon-files-previewviewer", - templateLoader: "text", - template: templateFile, - events: {}, - - initialize: function() { - MarkdownView.__super__.initialize.apply(this, arguments); - var that = this; - - // add refresh menu option - this.tab.menu.menuSection([ - { - 'type': "action", - 'title': "Refresh", - 'shortcuts': [ - "mod+r" - ], - 'bindKeyboard': true, - 'action': function() { - that.refresh(); - } - } - ]); - - this.model.on("file:change:update", function() { - if (settings.user.get("refresh")) { - that.refresh(); - } - }, this); - - this.refresh(); - return this; - }, - - refresh: function() { - var that = this; - this.model.download().then(function (content) { - that.$el.html("
"+markdown.toHTML(content)+"
"); - }); - } - }); - - return MarkdownView; -}); diff --git a/addons/cb.git/client.js b/addons/cb.git/client.js deleted file mode 100644 index 15277921..00000000 --- a/addons/cb.git/client.js +++ /dev/null @@ -1,251 +0,0 @@ -define(["views/dialog"], function(GitDialog) { - var Q = codebox.require("hr/promise"); - var commands = codebox.require("core/commands/toolbar"); - var app = codebox.require("core/app"); - var box = codebox.require("core/box"); - var dialogs = codebox.require("utils/dialogs"); - var menu = codebox.require("core/commands/menu"); - var box = codebox.require("core/box"); - var Command = codebox.require("models/command"); - var rpc = codebox.require("core/backends/rpc"); - var operations = codebox.require("core/operations"); - - // Check git status - var updateStatus = function() { - return rpc.execute("git/status") - .then(function() { - updateMenu(true); - return updateBranchesMenu(false); - }, function(err) { - updateMenu(false); - }) - }; - - // Branches menu - var branchesMenu = Command.register({ - 'title': "Switch To Branch", - 'type': "menu", - 'offline': false - }); - var updateBranchesMenu = function(doUpdateStatus) { - return rpc.execute("git/branches") - .then(function(branches) { - branchesMenu.menu.reset(_.map(branches, function(branch) { - return { - 'title': branch.name, - 'flags': branch.active ? "active" : "", - 'action': function() { - var ref = branch.name; - return operations.start("git.checkout", function(op) { - return rpc.execute("git/checkout", { - 'ref': ref - }) - }, { - title: "Checkout '"+ref+"'" - }) - .then(updateBranchesMenu); - } - } - })); - }, function(err) { - if (doUpdateStatus !== false) updateStatus(); - return Q.reject(err); - }); - }; - - // Handle http auth - var handleHttpAuth = function(method) { - return Q(method()) - .fail(function(err) { - if (err.code == 401) { - // Fields for https auth - var fields = { - username: { - type: "text", - label: "Username" - }, - password: { - type: "password", - label: "Password" - } - }; - - // Passphrase for ssh - if (err.message.toLowerCase().indexOf("authentication") < 0) { - fields = { - passphrase: { - type: "text", - label: "Passphrase" - } - }; - } - - return dialogs.fields("Need authentication:", fields) - .then(method); - } else { - return Q.reject(err); - } - }) - }; - - // Add menu - var gitMenu = menu.register("git", { - title: "Repository", - offline: false - }); - - var updateMenu = function(state) { - // Clear menu - gitMenu.clearMenu(); - - // Invalid repository - if (!state) { - gitMenu.menuSection([ - { - 'title': "No GIT Repository detected", - 'type': "label", - 'icons': { - 'menu': "warning", - } - }, - { - 'title': "Initialize Local Repository", - 'offline': false, - 'action': function() { - return operations.start("git.init", function(op) { - return rpc.execute("git/init") - }, { - title: "Initializing GIT repository" - }); - } - }, - { - 'title': "Clone Remote Repository", - 'offline': false, - 'action': function() { - return operations.start("git.clone", function(op) { - return dialogs.prompt("Clone Remote Repository", "Remote repository URI:") - .then(function(url) { - if (!url) return; - return handleHttpAuth(function(creds) { - return rpc.execute("git/clone", { - 'url': url, - 'auth': creds || {} - }); - }); - }); - }, { - title: "Cloning GIT repository" - }); - } - } - ]); - } else { - gitMenu.menuSection([ - { - 'title': "Commit", - 'shortcuts': ["mod+shift+C"], - 'offline': false, - 'action': function() { - dialogs.open(GitDialog); - } - } - ]).menuSection([ - { - 'title': "Synchronize", - 'shortcuts': ["mod+S"], - 'offline': false, - 'action': function() { - return operations.start("git.sync", function(op) { - return handleHttpAuth(function(creds) { - return rpc.execute("git/sync", { - 'auth': creds || {} - }); - }); - }, { - title: "Pushing & Pulling" - }); - } - }, - { - 'title': "Push", - 'shortcuts': ["mod+P"], - 'offline': false, - 'action': function() { - return operations.start("git.push", function(op) { - return handleHttpAuth(function(creds) { - return rpc.execute("git/push", { - 'auth': creds || {} - }); - }); - }, { - title: "Pushing" - }); - } - }, - { - 'title': "Pull", - 'shortcuts': ["shift+mod+P"], - 'offline': false, - 'action': function() { - return operations.start("git.pull", function(op) { - return handleHttpAuth(function(creds) { - return rpc.execute("git/pull", { - 'auth': creds || {} - }); - }); - }, { - title: "Pulling" - }); - } - } - ]).menuSection([ - branchesMenu, - { - 'title': "Refresh branches", - 'offline': false, - 'action': updateBranchesMenu, - } - ]).menuSection([ - { - 'title': "Create a branch", - 'offline': false, - 'action': function() { - dialogs.prompt("Create a branch", "Enter the name for the new branch:").then(function(name) { - if (!name) return; - operations.start("git.branch.create", function(op) { - return rpc.execute("git/branch/create", { - 'name': name - }) - }, { - title: "Creating branch '"+name+"'" - }); - }); - } - }, - { - 'title': "Delete a branch", - 'offline': false, - 'action': function() { - dialogs.prompt("Delete a branch", "Enter the name of the branch you want to delete:").then(function(name) { - if (!name) return; - operations.start("git.branch.delete", function(op) { - return rpc.execute("git/branch/delete", { - 'name': name - }) - }, { - title: "Deleting branch '"+name+"'" - }).then(updateBranchesMenu); - }); - } - } - ]); - } - }; - - box.on("box:git", function() { - updateStatus(); - }); - updateStatus(); -}); - diff --git a/addons/cb.git/node/main.js b/addons/cb.git/node/main.js deleted file mode 100644 index f23406be..00000000 --- a/addons/cb.git/node/main.js +++ /dev/null @@ -1,29 +0,0 @@ -// Requires -var _ = require('lodash'); -var Gittle = require('gittle'); -var GitRPCService = require('./service').GitRPCService; - - -function setup(options, imports, register) { - // Import - var rpc = imports.rpc; - var events = imports.events; - var workspace = imports.workspace; - - // Service - var service = new GitRPCService(workspace, events); - - // Register RPC - rpc.register('git', service); - - // Register - register(null, { - "git": { - repo: service.repo, - }, - "git_rpc": service - }); -} - -// Exports -module.exports = setup; diff --git a/addons/cb.git/node/service.js b/addons/cb.git/node/service.js deleted file mode 100644 index 0404ae7d..00000000 --- a/addons/cb.git/node/service.js +++ /dev/null @@ -1,150 +0,0 @@ -// Requires -var Q = require('q'); -var _ = require('lodash'); -var Gittle = require('gittle'); - -function GitRPCService(workspace, events) { - this.workspace = workspace; - this.events = events; - - this.repo = new Gittle(workspace.root); - - _.bindAll(this); -} - -GitRPCService.prototype.init = function(args, meta) { - var that = this; - return Gittle.init(this.workspace.root).then(function(repo) { - that.events.emit('git.init', { - userId: meta.user.userId - }); - - that.repo = repo; - return that.repo.status(); - }); -}; - -GitRPCService.prototype.clone = function(args, meta) { - var that = this; - if (!args.url) throw "Need an url for cloning a repository"; - return Gittle.clone(args.url, this.workspace.root, args.auth || {}).then(function(repo) { - that.events.emit('git.clone', { - userId: meta.user.userId, - url: args.url - }); - - that.repo = repo; - return that.repo.status(); - }); -}; - -GitRPCService.prototype.status = function() { - return this.repo.status(); -}; - -GitRPCService.prototype.sync = function(args, meta) { - var that = this; - return this.repo.sync(null, null, args.auth || {}) - .then(function() { - that.events.emit('git.sync', { - userId: meta.user.userId - }); - }); -}; - -GitRPCService.prototype.push = function(args, meta) { - var that = this; - return this.repo.push(null, null, args.auth || {}) - .then(function() { - that.events.emit('git.push', { - userId: meta.user.userId - }); - }); -}; - -GitRPCService.prototype.pull = function(args, meta) { - var that = this; - return this.repo.pull(null, null, args.auth || {}) - .then(function() { - that.events.emit('git.pull', { - userId: meta.user.userId - }); - }); -}; - -GitRPCService.prototype.commit = function(args, meta) { - var msg = args.message; - var files = args.files || []; - var name = meta.user.name; - var email = meta.user.email; - - if(!_.all([msg, files, name, email])) { - return Q.reject(new Error("Could not commit because arguments are missing and/or invalid")); - } - - var that = this; - return this.repo.commitWith(name, email, msg, files) - .then(function() { - that.events.emit('git.commit', { - userId: meta.user.userId, - - message: msg, - name: name, - email: email, - files: files - }); - }); -}; - -GitRPCService.prototype.commits = function(args) { - return this.repo.commits(args.ref, args.limit, args.skip); -}; - -GitRPCService.prototype.branches = function(args) { - var activeBranch, that = this; - - // Get current active branch - return this.repo.branch().then(function(branch) { - activeBranch = branch; - - // Get all local branches - return that.repo.branches(); - }).then(function(branches) { - return _.map(branches, function(branch) { - return { - 'name': branch.name, - 'active': branch.name == activeBranch.name - } - }); - }) -}; - -GitRPCService.prototype.branch_create = function(args) { - if (!args.name) return Q.reject(new Error("Need a name to create a branch")); - return this.repo.create_branch(args.name); -}; - -GitRPCService.prototype.checkout = function(args) { - if (!args.ref) return Q.reject(new Error("Need a referance (ref) to checkout")); - return this.repo.checkout(args.ref); -}; - -GitRPCService.prototype.branch_delete = function(args) { - if (!args.name) return Q.reject(new Error("Need a name to delete a branch")); - return this.repo.delete_branch(args.name); -}; - -GitRPCService.prototype.commits_pending = function() { - return this.repo.commits_pending(); -}; - -GitRPCService.prototype.diff = function(args) { - return this.repo.diff(args.new, args.old).then(function(diffs) { - return _.map(diffs, function(diff) { - return diff.normalize(); - }) - }); -}; - -// Exports -exports.GitRPCService = GitRPCService; diff --git a/addons/cb.git/package.json b/addons/cb.git/package.json deleted file mode 100644 index 0650cd0d..00000000 --- a/addons/cb.git/package.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "name": "cb.git", - "version": "0.0.3", - "title": "GIT", - "description": "Integration of Git into your workspace.", - "homepage": "https://github.com/FriendCode/codebox", - "license": "Apache", - "author": { - "name": "Codebox", - "email": "contact@friendco.de", - "url": "https://www.codebox.io" - }, - "client": { - "main": "client" - }, - "main": "./node/main", - "plugin": { - "provides": [ - "git", - "git_rpc" - ], - "consumes": [ - "rpc", - "events", - "workspace" - ] - }, - "engines": { - "codebox": ">=0.7.0" - } -} \ No newline at end of file diff --git a/addons/cb.git/stylesheets/git.less b/addons/cb.git/stylesheets/git.less deleted file mode 100644 index 6ee1e81e..00000000 --- a/addons/cb.git/stylesheets/git.less +++ /dev/null @@ -1,64 +0,0 @@ -.addon-git-dialog { - .modal-body { - padding: 0px; - } - .modal-footer { - margin: 0px; - } - - .navbar { - margin: 0px; - } - - .git-changes { - .git-commit { - padding: 15px 10px; - margin: 0px; - background: #f8f8f8; - - textarea { - resize: none; - } - } - - .git-changes-files { - list-style: none; - margin: 0px; - padding: 0px; - - .file { - background: #fdfdfd; - box-shadow: 0px 1px 0px #fff inset; - border-top: 1px solid #ddd; - padding: 6px; - padding-left: 55px; - position: relative; - overflow: hidden; - text-overflow: ellipsis; - white-space: nowrap; - - .file-type { - position: absolute; - display: block; - top: 0px; - left: 0px; - width: 45px; - bottom: 0px; - padding: 6px; - text-align: center; - color: #fff; - - &.type-M { - background: #3498db; - } - &.type-A { - background: #2ecc71; - } - &.type-D { - background: #e74c3c; - } - } - } - } - } -} \ No newline at end of file diff --git a/addons/cb.git/templates/dialog.html b/addons/cb.git/templates/dialog.html deleted file mode 100644 index 299a6aef..00000000 --- a/addons/cb.git/templates/dialog.html +++ /dev/null @@ -1,28 +0,0 @@ - \ No newline at end of file diff --git a/addons/cb.git/views/dialog.js b/addons/cb.git/views/dialog.js deleted file mode 100644 index 139a7fa4..00000000 --- a/addons/cb.git/views/dialog.js +++ /dev/null @@ -1,75 +0,0 @@ -define([ - "text!templates/dialog.html", - "less!stylesheets/git.less" -], function(templateFile) { - var DialogView = codebox.require("views/dialogs/base"); - var box = codebox.require("core/box"); - var rpc = codebox.require("core/backends/rpc"); - var operations = codebox.require("core/operations"); - - var GitDialog = DialogView.extend({ - className: "addon-git-dialog modal fade", - templateLoader: "text", - template: templateFile, - events: _.extend({}, DialogView.prototype.events,{ - "submit form": "submit" - }), - - // Constructor - initialize: function(options) { - var that = this; - GitDialog.__super__.initialize.apply(this, arguments); - - that.git = null; - - rpc.execute("git/status").then(function(status) { - that.git = status; - that.render(); - }); - return this; - }, - - // Template Context - templateContext: function() { - return { - git: this.git - }; - }, - - // Render - render: function() { - if (!this.git) return this; - return GitDialog.__super__.render.apply(this, arguments); - }, - - // Finish rendering - finish: function() { - return GitDialog.__super__.finish.apply(this, arguments); - }, - - // Commit (and sync) - submit: function(e) { - if (e) e.preventDefault(); - - var that = this; - var sync = this.$(".git-commit .btn-git-sync").hasClass("active"); - var message = this.$(".git-commit textarea").val(); - - if (message.length == 0) { - return; - } - - operations.start("git.commit", function(op) { - return rpc.execute("git/commit", { - 'message': message - }); - }, { - title: "Commiting" - }).then(function() { - that.close(); - }) - } - }); - - return GitDialog; -}); \ No newline at end of file diff --git a/addons/cb.help/client.js b/addons/cb.help/client.js deleted file mode 100644 index 62cb0ae1..00000000 --- a/addons/cb.help/client.js +++ /dev/null @@ -1,80 +0,0 @@ -define([ - "text!welcome.md" -], function(welcomeText) { - var hr = codebox.require("hr/hr"); - var app = codebox.require("core/app"); - var menu = codebox.require("core/commands/menu"); - var files = codebox.require("core/files"); - var rpc = codebox.require("core/backends/rpc"); - var Command = codebox.require("models/command"); - - // Help url - var helpUrl = "http://help.codebox.io/"; - - // Command to open changelog - var commandChanges = Command.register("help.changes", { - 'category': "Help", - 'title': "Open Release Notes", - 'action': function(title) { - return rpc.execute("box/changes").then(function(changes) { - return files.openNew(title || "Release Notes", changes.content); - }); - } - }); - - // Command to open welcome - var commandWelcome = Command.register("help.welcome", { - 'category': "Help", - 'title': "Welcome", - 'action': function(title) { - return files.openNew(title || "Welcome.md", welcomeText); - } - }); - - - // Add menu - menu.register("help", { - title: "Help", - position: 100 - }).menuSection([ - commandChanges, - { - 'id': "help.documentation", - 'category': "Help", - 'title': "Documentation", - 'description': "Open Documentation", - 'shortcuts': ['?'], - 'offline': false, - 'action': function() { - window.open(helpUrl); - } - } - ]).menuSection([ - { - 'id': "help.feedback", - 'category': "Help", - 'title': "Submit Feedback", - 'offline': false, - 'action': function() { - window.open("https://github.com/FriendCode/codebox/issues"); - } - } - ]); - - // Open changes if version changes - app.once("ready", function() { - // Show release not if version increased - // If first time show welcome message - - var currentVersion = hr.configs.args.version; - var lastVersion = hr.Storage.get("codeboxVersion"); - - if (lastVersion == null) { - commandWelcome.run(); - } else if (currentVersion != lastVersion) { - commandChanges.run(); - } - hr.Storage.set("codeboxVersion", currentVersion); - }); -}); - diff --git a/addons/cb.help/package.json b/addons/cb.help/package.json deleted file mode 100644 index fe5d8e8d..00000000 --- a/addons/cb.help/package.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "name": "cb.help", - "version": "0.0.1", - "title": "Help", - "description": "Documentation for Codebox", - "homepage": "https://github.com/FriendCode/codebox", - "license": "Apache", - "author": { - "name": "Codebox", - "email": "contact@friendco.de", - "url": "https://www.codebox.io" - }, - "client": { - "main": "client" - }, - "engines": { - "codebox": ">=0.7.0" - } -} \ No newline at end of file diff --git a/addons/cb.help/welcome.md b/addons/cb.help/welcome.md deleted file mode 100644 index c4e4c9d0..00000000 --- a/addons/cb.help/welcome.md +++ /dev/null @@ -1,22 +0,0 @@ -# Welcome to Codebox! - -Here is what you need to know. - -1. This IDE is open source, you can contribute to it on [GitHub](https://github.com/FriendCode/codebox). - -2. If you only remember one thing make it `cmd-shift-P` (or `ctrl-shift-P` on Windows and Linux). This keystroke toggles - the command palette, which lists every command. - -3. We want your feedback! If you have anything positive or negative to say click - on the `Send Feedback` button at the bottom right of this window. - -4. Here is where you can get more help with Codebox - - * The [Codebox docs](http://help.codebox.io/) contain Guides on how to use the IDE. - * Post issues on [GitHub](https://github.com/FriendCode/codebox/issues). - -5. If you ever want to see this buffer again use the command palette - (`cmd-shift-P`) and search for `Welcome`. - -6. If you want to read ChangeLog, use the command palette - (`cmd-shift-P`) and search for `Release Notes`. \ No newline at end of file diff --git a/addons/cb.offline/client.js b/addons/cb.offline/client.js deleted file mode 100644 index 574295f7..00000000 --- a/addons/cb.offline/client.js +++ /dev/null @@ -1,80 +0,0 @@ -define([ - "settings", - "menus" -], function(settings, menus) { - var $ = codebox.require("hr/dom"); - var Q = codebox.require("hr/promise"); - var app = codebox.require("core/app"); - var box = codebox.require("core/box"); - var menu = codebox.require("core/commands/menu"); - var commands = codebox.require("core/commands/toolbar"); - var operations = codebox.require("core/operations"); - var hr = codebox.require("hr/hr"); - var Command = codebox.require("models/command"); - var localfs = codebox.require("core/localfs"); - - var _syncInterval = null; - - - // Run offline cache update operation - var op = operations.start("offline.update", null, { - 'title': "Updating", - 'icons': { - 'default': "fa-cog fa-spin", - }, - 'state': window.applicationCache.status == window.applicationCache.IDLE ? "idle" : "running", - 'progress': 0 - }); - - // Application manifest - $(window.applicationCache).bind('downloading progress', function(e) { - var progress = 0; - if (e && e.originalEvent && e.originalEvent.lengthComputable) { - progress = Math.round(100*e.originalEvent.loaded/e.originalEvent.total); - } - op.state("running"); - op.progress(progress); - }); - $(window.applicationCache).bind('checking', function(e) { - op.state("running"); - op.progress(0); - }); - $(window.applicationCache).bind('noupdate cached obsolete error', function(e) { - op.state("idle"); - }); - - - // Update settings - var updateSettings = function() { - var enabled = settings.user.get("enabled", true); - if (_syncInterval) clearInterval(_syncInterval); - - // Enable sync - localfs.enableSync(settings.user.get("enabled", true)); - - // Set ignored files - localfs.setIgnoredFiles(settings.user.get("syncIgnore", "").split("\n")); - - // Toggle menu - menus.sync.toggleFlag("hidden", !enabled); - - // Run sync every 10min - _syncInterval = setInterval(function() { - localfs.autoSync(); - }, settings.user.get("syncInterval", 10)*60*1000); - }; - - setTimeout(function() { - localfs.sync(); - }, 5*1000); - - // Run sync everytime there is a modification - box.on("box:watch", function() { - localfs.autoSync(); - }); - - // Change settings - settings.user.change(updateSettings); - updateSettings(); -}); - diff --git a/addons/cb.offline/menus.js b/addons/cb.offline/menus.js deleted file mode 100644 index eafdf3a4..00000000 --- a/addons/cb.offline/menus.js +++ /dev/null @@ -1,87 +0,0 @@ -define([], function() { - var box = codebox.require("core/box"); - var menu = codebox.require("core/commands/menu"); - var commands = codebox.require("core/commands/toolbar"); - var operations = codebox.require("core/operations"); - var hr = codebox.require("hr/hr"); - var Command = codebox.require("models/command"); - var localfs = codebox.require("core/localfs"); - var dialogs = codebox.require("utils/dialogs"); - - // Command to check connection - var checkConnection = commands.register("offline.check", { - 'category': "Offline", - 'title': "Check Connection", - 'offline': true, - 'icons': { - 'default': "bolt", - } - }, function() { - hr.Offline.check(); - }); - - // Changes list - var menuListChanges = new Command({}, { - 'title': "Changes", - 'type': "menu", - 'flags': "disabled" - }); - - // Menu Synchronize - var menuSync = menu.register("offline.synchronize", { - title: "Synchronize", - position: 95, - offline: false - }).menuSection([ - checkConnection - ]).menuSection([ - { - 'id': "offline.changes.calcul", - 'category': "Offline", - 'title': "Calcul Changes", - 'offline': false, - 'action': function() { - return localfs.sync(); - } - } - ]).menuSection([ - { - 'id': "offline.changes.reset", - 'category': "Offline", - 'title': "Reset All Changes", - 'offline': false, - 'action': function() { - return localfs.reset(); - } - }, - { - 'id': "offline.changes.apply", - 'category': "Offline", - 'title': "Apply All Changes", - 'offline': false, - 'action': function() { - var n = localfs.changes.size(); - if (n == 0) return; - - dialogs.confirm("Do you really want to apply "+n+" changes?").then(function(yes) { - if (!yes) return; - return localfs.changes.applyAll(); - }); - } - } - ]).menuSection([ - menuListChanges - ]); - - // Changes update - localfs.changes.on("add remove reset", function() { - menuListChanges.toggleFlag("disabled", localfs.changes.size() == 0); - menuListChanges.menu.reset(localfs.changes.map(function(change) { - return change.command(); - })); - }); - - return { - 'sync': menuSync - } -}); \ No newline at end of file diff --git a/addons/cb.offline/package.json b/addons/cb.offline/package.json deleted file mode 100644 index 5fbb6402..00000000 --- a/addons/cb.offline/package.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "name": "cb.offline", - "version": "0.0.1", - "title": "Help", - "description": "Menu for managing offline sync", - "homepage": "https://github.com/FriendCode/codebox", - "license": "Apache", - "author": { - "name": "Codebox", - "email": "contact@friendco.de", - "url": "https://www.codebox.io" - }, - "client": { - "main": "client" - }, - "engines": { - "codebox": ">=0.7.0" - } -} \ No newline at end of file diff --git a/addons/cb.offline/settings.js b/addons/cb.offline/settings.js deleted file mode 100644 index b77d222c..00000000 --- a/addons/cb.offline/settings.js +++ /dev/null @@ -1,30 +0,0 @@ -define([], function() { - var settings = codebox.require("core/settings"); - - // Add settings - return settings.add({ - 'namespace': "offline", - 'title': "Offline", - 'defaults': { - 'enabled': false, - 'syncInterval': 10 - }, - 'fields': { - 'enabled': { - 'label': 'Enable Files Synchronization', - 'type': "checkbox" - }, - 'syncInterval': { - 'label': "Synchronization (minutes)", - 'type': "number", - 'min': 1, - 'max': 1000, - 'step': 1 - }, - 'syncIgnore': { - 'label': "Ignored files (one by line)", - 'type': "textarea" - } - } - }); -}); \ No newline at end of file diff --git a/addons/cb.panel.files/client.js b/addons/cb.panel.files/client.js deleted file mode 100644 index 699a64b4..00000000 --- a/addons/cb.panel.files/client.js +++ /dev/null @@ -1,85 +0,0 @@ -define([ - "views/panel" -], function(PanelFilesView) { - var Command = codebox.require("models/command"); - var commands = codebox.require("core/commands/toolbar"); - var app = codebox.require("core/app"); - var panels = codebox.require("core/panels"); - var files = codebox.require("core/files"); - var menu = codebox.require("core/commands/menu"); - var box = codebox.require("core/box"); - - // Add files panels - var panel = panels.register("files", PanelFilesView, { - title: "Folders" - }); - - // Open files panel - panel.connectCommand(commands.register("files.tree.open", { - category: "Panels", - title: "Files", - description: "Open Files Panel", - icons: { - 'default': "folder-o", - }, - position: 2, - shortcuts: [ - "alt+f" - ] - })); - - // Recents files - var recentFiles = Command.register({ - 'type': "menu", - 'title': "Open Recent" - }); - files.recent.on("add remove reset", function() { - recentFiles.menu.reset(files.recent.map(function(file) { - var path = file.path(); - return { - 'title': file.get("name"), - 'action': function() { - files.open(path); - } - }; - }).reverse()); - }); - - - // Command new file - menu.getById("file").menuSection([ - { - 'id': "files.file.new", - 'category': "Files", - 'title': "New File", - 'shortcuts': ["alt+shift+n"], - 'action': function() { - files.openNew() - } - }, { - 'id': "files.folder.create", - 'category': "Files", - 'title': "New Folder", - 'shortcuts': ["alt+shift+f"], - 'action': function() { - box.root.actionMkdir(); - } - }, - recentFiles - ], { - position: 0 - }).menuSection([ - { - 'id': "workspace.save.zip", - 'category': "Files", - 'title': "Save Project As TAR.GZ", - 'offline': false, - 'action': function() { - window.open("/export/targz"); - } - } - ]); - - // Open panel - panel.open(); -}); \ No newline at end of file diff --git a/addons/cb.panel.files/package.json b/addons/cb.panel.files/package.json deleted file mode 100644 index 069fe5e0..00000000 --- a/addons/cb.panel.files/package.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "name": "cb.panel.files", - "version": "0.1.0", - "title": "Files Panel", - "description": "Files Tree Panel for exploring and managing the filesystem", - "homepage": "https://github.com/FriendCode/codebox", - "license": "Apache", - "author": { - "name": "Codebox", - "email": "contact@friendco.de", - "url": "https://www.codebox.io" - }, - "client": { - "main": "client" - }, - "engines": { - "codebox": ">=0.7.0" - } -} \ No newline at end of file diff --git a/addons/cb.panel.files/settings.js b/addons/cb.panel.files/settings.js deleted file mode 100644 index 95326ed3..00000000 --- a/addons/cb.panel.files/settings.js +++ /dev/null @@ -1,25 +0,0 @@ -define([], function() { - var $ = codebox.require("hr/dom"); - var settings = codebox.require("core/settings"); - - // Add settings - return settings.add({ - 'namespace': "files-panel", - 'title': "Files Explorer Panel", - 'defaults': { - 'openfiles': true, - 'hiddenfiles': true, - 'gitfolder': false - }, - 'fields': { - 'hiddenfiles': { - 'label': "Show Hidden Files", - 'type': "checkbox" - }, - 'gitfolder': { - 'label': "Show GIT Folder", - 'type': "checkbox" - } - } - }); -}); \ No newline at end of file diff --git a/addons/cb.panel.files/stylesheets/files.less b/addons/cb.panel.files/stylesheets/files.less deleted file mode 100644 index 288c2f67..00000000 --- a/addons/cb.panel.files/stylesheets/files.less +++ /dev/null @@ -1,97 +0,0 @@ -.cb-files-tree { - margin: 0px; - padding: 0px; - list-style: none; - - &.root { - - } - - .file-item { - cursor: default; - line-height: 24px; - font-size: 14px; - - &.hr-list-fiter-on { - display: none; - } - - >.files { - display: none; - } - - &.active, &.active:hover { - >.name { - background: rgba(0,0,0, 0.08); - color: inherit; - } - } - - &.disabled { - >.name { - color: #999; - } - } - - &.ui-context-menu { - >.name { - background: rgba(0, 0, 0, 0.15); - } - } - - >.name { - color: inherit; - overflow: hidden; - text-overflow: ellipsis; - white-space: nowrap; - display: block; - z-index: 1; - position: relative; - - &:hover { - background: #5E9EF3; - color: #fff; - } - - >i { - width: 11px; - text-align: center; - - &.file-icon { - margin-right: 3px; - } - - &.invisibile { - color: transparent; - text-shadow: none; - } - } - >.fa-angle-right { - display: inline-block; - } - >.fa-angle-down { - display: none; - } - } - - &.type-directory { - >.name { - /*color: inherit;*/ - } - } - - &.open { - >.files { - display: block; - } - >.name { - >.fa-angle-right { - display: none; - } - >.fa-angle-down { - display: inline-block; - } - } - } - } -} \ No newline at end of file diff --git a/addons/cb.panel.files/stylesheets/panel.less b/addons/cb.panel.files/stylesheets/panel.less deleted file mode 100644 index 6091a148..00000000 --- a/addons/cb.panel.files/stylesheets/panel.less +++ /dev/null @@ -1,9 +0,0 @@ -.cb-panel-files { - position: absolute; - top: 0px; - bottom: 0px; - left: 0px; - width: 100%; - z-index: 10; - overflow-y: auto; -} \ No newline at end of file diff --git a/addons/cb.panel.files/templates/item.html b/addons/cb.panel.files/templates/item.html deleted file mode 100644 index 583ff42e..00000000 --- a/addons/cb.panel.files/templates/item.html +++ /dev/null @@ -1,14 +0,0 @@ - - <% if (file.isDirectory()) { %> - - - - <% } else { %> - - - <% } %> - <%- file.get("name") %> - -<% if (file.isDirectory()) { %> -
-<% } %> \ No newline at end of file diff --git a/addons/cb.panel.files/views/panel.js b/addons/cb.panel.files/views/panel.js deleted file mode 100644 index c4886193..00000000 --- a/addons/cb.panel.files/views/panel.js +++ /dev/null @@ -1,58 +0,0 @@ -define([ - "settings", - "views/tree", - "less!stylesheets/panel.less" -], function(panelSettings, FilesTreeView) { - var _ = codebox.require("hr/utils"); - var $ = codebox.require("hr/dom"); - var hr = codebox.require("hr/hr"); - var box = codebox.require("core/box"); - var files = codebox.require("core/files"); - var search = codebox.require("core/search"); - var ContextMenu = codebox.require("utils/contextmenu"); - var PanelBaseView = codebox.require("views/panels/base"); - - var PanelFilesView = PanelBaseView.extend({ - className: "cb-panel-files", - - initialize: function() { - PanelFilesView.__super__.initialize.apply(this, arguments); - - this.tree = new FilesTreeView.Item({ - model: box.root - }, this); - this.tree.update(); - this.tree.select(); - - - var $rootTree = $("
    ", { - "class": "root-tree cb-files-tree" - }); - $rootTree.appendTo(this.$el); - this.tree.$el.appendTo($rootTree); - - // Offline - hr.Offline.on("state", function() { - this.update(); - }, this); - - // Settings update - panelSettings.user.change(function() { - this.update(); - }, this); - - this.on("tab:layout", function() { - //this.render(); - }, this); - - // Context menu - ContextMenu.add(this.$el, box.root.contextMenu()); - }, - - render: function() { - return this.ready(); - } - }); - - return PanelFilesView; -}); \ No newline at end of file diff --git a/addons/cb.panel.files/views/tree.js b/addons/cb.panel.files/views/tree.js deleted file mode 100644 index 5e782d4d..00000000 --- a/addons/cb.panel.files/views/tree.js +++ /dev/null @@ -1,168 +0,0 @@ -define([ - "settings", - "text!templates/item.html", - "less!stylesheets/files.less" -], function(panelSettings, templateFile) { - var _ = codebox.require("hr/utils"); - var $ = codebox.require("hr/dom"); - var hr = codebox.require("hr/hr"); - var box = codebox.require("core/box"); - var ContextMenu = codebox.require("utils/contextmenu"); - var FilesBaseView = codebox.require("views/files/base"); - - // File item in the tree - var FilesTreeViewItem = FilesBaseView.extend({ - tagName: "li", - className: "file-item", - templateLoader: "text", - template: templateFile, - events: { - "click .name": "select", - "dblclick .name": "open" - }, - - // Constructor - initialize: function(options) { - FilesTreeViewItem.__super__.initialize.apply(this, arguments); - var that = this; - - // View for subfiles - this.subFiles = null; - this.paddingLeft = this.options.paddingLeft || 0; - - // Context menu - ContextMenu.add(this.$el, this.model.contextMenu()); - - box.on("file.active", function(path) { - this.$el.toggleClass("active", this.model.path() == path); - }, this); - - return this; - }, - - render: function() { - if (this.subFiles) this.subFiles.detach(); - return FilesTreeViewItem.__super__.render.apply(this, arguments); - }, - - // Finish rendering - finish: function() { - this.$el.toggleClass("disabled", !this.model.canOpen()); - this.$(">.name").css("padding-left", this.paddingLeft); - this.$el.toggleClass("type-directory", this.model.isDirectory()); - - if (this.subFiles) { - this.subFiles.$el.appendTo(this.$(".files")); - } - return FilesTreeViewItem.__super__.finish.apply(this, arguments); - }, - - // (event) select the file : extend tree - select: function(e) { - if (e != null) { - e.preventDefault(); - e.stopPropagation(); - } - - if (!this.model.canOpen()) { - return; - } - - if (this.model.isDirectory()) { - if (this.subFiles == null) { - this.subFiles = new FilesTreeView({ - "codebox": this.codebox, - "model": this.model, - "paddingLeft": this.paddingLeft+15 - }, this); - this.subFiles.$el.appendTo(this.$(".files")); - this.subFiles.update(); - } - this.$el.toggleClass("open"); - } else { - this.open(); - } - }, - - // (event) open the file or directory - open: function(e) { - if (e != null) { - e.preventDefault(); - e.stopPropagation(); - } - - if (!this.model.canOpen()) { - return; - } - - if (!this.model.isDirectory()) { - this.model.open({ - 'userChoice': false - }); - } else { - this.select(); - } - } - }); - - // Complete files tree - var FilesTreeView = FilesBaseView.extend({ - tagName: "ul", - className: "cb-files-tree", - - // Constructor - initialize: function(options) { - FilesTreeView.__super__.initialize.apply(this, arguments); - var that = this; - - this.countFiles = 0; - this.paddingLeft = this.options.paddingLeft || 10; - - panelSettings.user.change(function() { - this.update(); - }, this); - - return this; - }, - - // Render the files tree - render: function() { - var that = this; - this.$el.toggleClass("root", this.model.isRoot()); - - // Context menu - ContextMenu.add(this.$el, this.model.contextMenu()); - - this.model.listdir().then(function(files) { - that.clearComponents(); - that.empty(); - that.countFiles = 0; - - _.each(files, function(file) { - if ((file.isGit() && !panelSettings.user.get("gitfolder")) - || (file.isHidden() && !panelSettings.user.get("hiddenfiles"))) { - return; - } - - var v = new FilesTreeViewItem({ - "codebox": that.codebox, - "model": file, - "paddingLeft": that.paddingLeft - }); - v.update(); - v.$el.appendTo(that.$el); - that.addComponent("file", v); - - that.countFiles = that.countFiles + 1; - }); - that.trigger("count", that.countFiles); - }); - - return that.ready(); - }, - }, { - 'Item': FilesTreeViewItem - }); - - return FilesTreeView; -}); \ No newline at end of file diff --git a/addons/cb.panel.outline/client.js b/addons/cb.panel.outline/client.js deleted file mode 100644 index ec27fe23..00000000 --- a/addons/cb.panel.outline/client.js +++ /dev/null @@ -1,30 +0,0 @@ -define([ - "settings", - "views/panel" -], function(settings, PanelOutlineView) { - var commands = codebox.require("core/commands/toolbar"); - var app = codebox.require("core/app"); - var panels = codebox.require("core/panels"); - var menu = codebox.require("core/commands/menu"); - var box = codebox.require("core/box"); - - // Add outline panel - var panel = panels.register("outline", PanelOutlineView, { - title: "Outline" - }); - - // Add command to open outline panel - panel.connectCommand(commands.register("outline.open", { - category: "Panels", - title: "Outline", - description: "Open Outline Panel", - icons: { - 'default': "code", - }, - position: 2, - shortcuts: [] - })); - - // Open panel during startup - if (settings.user.get("startup")) panel.open(); -}); \ No newline at end of file diff --git a/addons/cb.panel.outline/package.json b/addons/cb.panel.outline/package.json deleted file mode 100644 index 553911ee..00000000 --- a/addons/cb.panel.outline/package.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "name": "cb.panel.outline", - "version": "0.1.0", - "title": "Outline Panel", - "description": "Panel for exploring tags in current file", - "homepage": "https://github.com/FriendCode/codebox", - "license": "Apache", - "author": { - "name": "Codebox", - "email": "contact@friendco.de", - "url": "https://www.codebox.io" - }, - "client": { - "main": "client" - }, - "engines": { - "codebox": ">=0.7.0" - } -} \ No newline at end of file diff --git a/addons/cb.panel.outline/settings.js b/addons/cb.panel.outline/settings.js deleted file mode 100644 index 078ede4a..00000000 --- a/addons/cb.panel.outline/settings.js +++ /dev/null @@ -1,23 +0,0 @@ -define([], function() { - var settings = codebox.require("core/settings"); - - // Add settings - return settings.add({ - 'namespace': "outline", - 'title': "Outline", - 'defaults': { - 'separator': ".", - 'startup': false - }, - 'fields': { - 'separator': { - 'label': 'Tag Parts Separator', - 'type': "text" - }, - 'startup': { - 'label': 'Show Outline Panel at Startup', - 'type': "checkbox" - } - } - }); -}); \ No newline at end of file diff --git a/addons/cb.panel.outline/stylesheets/panel.less b/addons/cb.panel.outline/stylesheets/panel.less deleted file mode 100644 index 4ac541f2..00000000 --- a/addons/cb.panel.outline/stylesheets/panel.less +++ /dev/null @@ -1,107 +0,0 @@ -.cb-panel-outline { - position: absolute; - top: 0px; - bottom: 0px; - left: 0px; - width: 100%; - z-index: 10; - - .tags-tree { - margin: 0px; - padding: 0px; - list-style: none; - - li { - span { - display: block; - padding: 2px 8px; - cursor: default; - position: relative; - text-overflow: ellipsis; - overflow: hidden; - white-space: nowrap; - - &:hover { - background: rgba(0, 0, 0, 0.05); - } - - &:before { - content: " "; - background: #b55761; - width: 8px; - height: 8px; - position: absolute; - border-radius: 16px; - top: 8px; - left: 19px; - border: 1px solid #000; - } - } - - &.type-v { - span:before { - background: #81a2be; - } - } - &.type-f { - span:before { - background: #9dbe8c; - } - } - - i { - width: 24px; - } - - .tags-tree { - padding-left: 15px; - display: none; - } - - .tag-icon-close { - display: inline-block; - } - .tag-icon-open { - display: none; - } - - &.open { - > .tag-icon-open { - display: inline-block; - } - > .tag-icon-close { - display: none; - } - - > .tags-tree { - display: block; - } - } - } - } - - .outline-file { - > .tags-tree { - position: absolute; - top: 0px; - bottom: 40px; - left: 5px; - right: 5px; - z-index: 10; - overflow-y: auto; - - .alert { - text-align: center; - } - } - - input, input:focus { - position: absolute; - bottom: 6px; - left: 4px; - right: 4px; - width: calc(~"100% - 8px"); - box-shadow: none; - } - } -} \ No newline at end of file diff --git a/addons/cb.panel.outline/views/panel.js b/addons/cb.panel.outline/views/panel.js deleted file mode 100644 index 8db0acee..00000000 --- a/addons/cb.panel.outline/views/panel.js +++ /dev/null @@ -1,13 +0,0 @@ -define([ - "settings", - "views/tags" -], function(panelSettings, TagsView) { - var PanelFileView = codebox.require("views/panels/file"); - - var PanelOutlineView = PanelFileView.extend({ - className: "cb-panel-outline", - FileView: TagsView - }); - - return PanelOutlineView; -}); \ No newline at end of file diff --git a/addons/cb.panel.outline/views/tags.js b/addons/cb.panel.outline/views/tags.js deleted file mode 100644 index 93ddf941..00000000 --- a/addons/cb.panel.outline/views/tags.js +++ /dev/null @@ -1,182 +0,0 @@ -define([ - "settings", - "less!stylesheets/panel.less" -], function(panelSettings) { - var _ = codebox.require("hr/utils"); - var Q = codebox.require("hr/promise"); - var $ = codebox.require("hr/dom"); - var hr = codebox.require("hr/hr"); - var ContextMenu = codebox.require("utils/contextmenu"); - var rpc = codebox.require("core/backends/rpc"); - var box = codebox.require("core/box"); - var files = codebox.require("core/files"); - - var TagsView = hr.View.extend({ - className: "outline-file", - events: { - "click": "onClick", - "keyup input": "onKeyup" - }, - - initialize: function() { - TagsView.__super__.initialize.apply(this, arguments); - - this.$filterInput = $("", { - 'type': "text", - 'class': "form-control input-sm", - "placeholder": "Filter Tags" - }); - this.$tree = $("
      ", { - 'class': "tags-tree" - }); - - this.$filterInput.appendTo(this.$el); - this.$tree.appendTo(this.$el); - }, - - render: function() { - var that = this; - - return this.updateTags() - .fail(function(err) { - that.$tree.html("
      "+(err.message || err)+"
      "); - }) - .fin(function() { - that.ready(); - }); - }, - - // Add tag - addTag: function(tag, $parent, hasChildren) { - var $tags, that = this; - - var open = function() { - files.open(that.options.path, { - // Open content "/^ foo $/"" _> "foo" in editor - pattern: tag.pattern.slice(2, -2) - }); - }; - - var $tag = $("
    • ", { - 'data-tag': tag.name, - 'class': "type-"+(tag.kind || "v"), - 'click': function(e) { - e.stopPropagation(); - - $tag.toggleClass("open"); - if (!hasChildren) open(); - }, - 'dblclick': open - }); - - var $span = $("", { - 'text': tag.showName - }); - $span.appendTo($tag); - - if (hasChildren) { - $tags = $("
        ", { - 'class': "tags-tree" - }).appendTo($tag); - $("", { - 'class': "fa fa-angle-right tag-icon-close" - }).prependTo($span); - $("", { - 'class': "fa fa-angle-down tag-icon-open" - }).prependTo($span); - } else { - $("", { - 'class': "fa fa-blank" - }).prependTo($span); - } - - $tag.appendTo($parent); - - return { - '$tag': $tag, - '$children': $tags - }; - }, - - // Get tag view - getTag: function(name) { - var $tag = this.$("li[data-tag='"+name+"']"); - if ($tag.length == 0) return null; - return $($tag.get(0)); - }, - - // Convert tags as a tree - convertTagsToTree: function(tags) { - var that = this, tree = {}; - var tagSeparator = panelSettings.user.get("separator"); - - _.chain(tags) - .sortBy(function(tag) { - return tag.name.length; - }) - .each(function(tag) { - var parent = tree; - var parts = tag.name.split(tagSeparator); - var _name = _.last(parts); - - _.each(parts, function(part, i) { - if (parent[part]) { - parent = parent[part].children; - } else { - _name = parts.slice(i, parts.length).join(tagSeparator); - return false; - } - }); - - parent[_name] = tag; - parent[_name].showName = _name; - parent[_name].children = {}; - }); - - return tree; - }, - - // Update complete tree - updateTags: function() { - var message = "No outline available for the current file."; - var that = this, tree, path = this.options.path; - - // Clear tree - this.$tree.empty(); - - // No current file - if (!path || path == "/") { - return Q.reject(message); - } - - return rpc.execute("codecomplete/get", { - 'file': path - }) - .then(function(tags) { - if (tags.results.length == 0) return Q.reject(message); - tree = that.convertTagsToTree(tags.results); - - var addChildren = function($parent, tags) { - _.each(tags, function(tag, name) { - var vTag = that.addTag(tag, $parent, _.size(tag.children) > 0); - - addChildren(vTag.$children, tag.children); - }); - } - addChildren(that.$tree, tree); - }); - }, - - onClick: function() { - this.$filterInput.focus(); - }, - onKeyup: function(e) { - var query = this.$filterInput.val().toLowerCase(); - this.$("li").each(function() { - $(this).toggle(!query || $(this).text().toLowerCase().indexOf(query) !== -1); - }); - } - }); - - return TagsView; -}); \ No newline at end of file diff --git a/addons/cb.project/autorun.js b/addons/cb.project/autorun.js deleted file mode 100644 index 2d627f1b..00000000 --- a/addons/cb.project/autorun.js +++ /dev/null @@ -1,146 +0,0 @@ -define([ - 'settings', - 'ports' -], function(settings, ports) { - var _ = codebox.require("hr/utils"); - var commands = codebox.require("core/commands/toolbar"); - var operations = codebox.require("core/operations"); - var box = codebox.require("core/box"); - var dialogs = codebox.require("utils/dialogs"); - var alerts = codebox.require("utils/alerts"); - var Command = codebox.require("models/command"); - - // Currently running terminal - // undefined -> nothing is running - // null -> preparing the run - // {...} _> running - var runningTerm = undefined; - - // Map type -> icon - var typeIcons = { - 'run': "fa-play", - 'build': "fa-cog fa-spin", - 'clean': "fa-eraser" - }; - - // Run command - var runCommand = commands.register("project.run", { - category: "Project", - title: "Run", - icons: { - 'default': "play", - }, - offline: false, - position: 1, - shortcuts: [ - "alt+r" - ] - }, function(options) { - options = _.defaults(options || {}, { - 'ignoreErrors': false - }); - - if (runningTerm !== undefined) { - // For stopping: Close terminal - if (runningTerm != null) { - runningTerm.terminal.closeTab(); - } - - return; - } - - setRunTerminal(null); - - // Run - return box.run({ - 'id': options.id, - 'type': options.type - }) - .then(function(runInfo) { - var op = operations.start("project.run."+runInfo.shellId, null, { - 'title': runInfo.name+" running on port "+runInfo.port, - 'icons': { - 'default': typeIcons[runInfo.type] || "play", - }, - 'action': function() { - // Open the url - window.open(runInfo.url); - - // Check that port is still active - ports.update().then(function(ports) { - var _port = _.find(ports, function(proc) { - return proc.port == runInfo.port; - }); - if (!_port) { - op.destroy(); - } - }); - } - }); - - // Terminal is close: finish the operation - runInfo.terminal.on("tab:close", function() { - op.destroy(); - setRunTerminal(undefined); - }); - - // Set active runningterminal - setRunTerminal(runInfo); - - // Update list of ports - ports.update(); - - // Open url if settings is set for - if (settings.user.get("openrundialog", true)) { - dialogs.confirm("Application is now running on port "+runInfo.port, "Open "+_.escape(runInfo.url)+" in a new window? (This dialog can be disabled in the settings).") - .progress(function(diag) { - diag.once("close", function(result, e) { - if (result) window.open(runInfo.url); - }) - }); - } - }, function(err) { - setRunTerminal(undefined); - - if (!options.ignoreErrors) dialogs.alert("Error running this project", "An error occurred when trying to run this project: "+(err.message || err)); - }); - }); - - var setRunTerminal = function(st) { - var previous = runningTerm; - runningTerm = st; - - // Change command state - if (runningTerm != null) { - runCommand.set({ - 'title': "Stop", - 'icons': { - 'default': "stop" - } - }); - } else { - runCommand.set({ - 'title': "Run", - 'icons': { - 'default': "play" - } - }); - } - - if (previous - && previous.type == "run" - && runningTerm === undefined) { - // Run stop command - return runCommand.run({ - 'type': "stop", - 'ignoreErrors': true - }); - } - }; - - setRunTerminal(undefined); - - return { - 'command': runCommand - } -}); \ No newline at end of file diff --git a/addons/cb.project/client.js b/addons/cb.project/client.js deleted file mode 100644 index 83eff385..00000000 --- a/addons/cb.project/client.js +++ /dev/null @@ -1,77 +0,0 @@ -define([ - 'runner', - 'ports', - 'autorun', - 'samples' -], function(runner, ports, autorun, samples) { - var _ = codebox.require("hr/utils"); - var operations = codebox.require("core/operations"); - var app = codebox.require("core/app"); - var box = codebox.require("core/box"); - var menu = codebox.require("core/commands/menu"); - var dialogs = codebox.require("utils/dialogs"); - var alerts = codebox.require("utils/alerts"); - - // Add samples submenu - menu.getById("file").menuSection([ - samples.command - ]) - - // Add menu - menu.register("project", { - title: "Project", - offline: false - }).menuSection([ - autorun.command, - runner.command - ]).menuSection([ - { - 'id': "project.build", - 'category': "Project", - 'title': "Build", - 'offline': false, - 'action': function() { - return autorun.command.run({ - 'type': "build" - }); - }, - 'shortcuts': [ - "mod+b" - ] - }, - { - 'id': "project.clean", - 'category': "Project", - 'title': "Clean", - 'offline': false, - 'action': function() { - return autorun.command.run({ - 'type': "clean" - }); - }, - 'shortcuts': [ - "mod+shift+k" - ] - } - ]).menuSection([ - { - - 'id': "project.ports.refresh", - 'category': "Project", - 'title': "Refresh Ports", - 'offline': false, - 'action': ports.update - }, - ports.command - ]); - - // Auto-updates - box.on("box:project:define", function() { - runner.update(); - }); - - // Updates list - runner.update(); - ports.update(); - samples.update(); -}); \ No newline at end of file diff --git a/addons/cb.project/package.json b/addons/cb.project/package.json deleted file mode 100644 index 05329674..00000000 --- a/addons/cb.project/package.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "name": "cb.project", - "version": "0.1.0", - "title": "Project", - "description": "Project types manager: autorun, sample", - "homepage": "https://github.com/FriendCode/codebox", - "license": "Apache", - "author": { - "name": "Codebox", - "email": "contact@friendco.de", - "url": "https://www.codebox.io" - }, - "client": { - "main": "client" - }, - "engines": { - "codebox": ">=0.7.0" - } -} \ No newline at end of file diff --git a/addons/cb.project/ports.js b/addons/cb.project/ports.js deleted file mode 100644 index 810b5f71..00000000 --- a/addons/cb.project/ports.js +++ /dev/null @@ -1,43 +0,0 @@ -define([], function() { - var _ = codebox.require("hr/utils"); - var operations = codebox.require("core/operations"); - var box = codebox.require("core/box"); - var dialogs = codebox.require("utils/dialogs"); - var alerts = codebox.require("utils/alerts"); - var Command = codebox.require("models/command"); - - // HTTP Ports - var httpPorts = Command.register("project.ports", { - 'category': "Project", - 'title': "Running Ports", - 'type': "menu", - 'offline': false, - 'search': false - }); - - // Update running ports list - var updatePorts = function() { - return box.procHttp().then(function(ports) { - httpPorts.menu.reset(_.map(ports, function(proc) { - return { - 'title': proc.port, - 'flags': proc.reachable ? "" : "disabled", - 'action': function() { - if (proc.reachable) { - window.open(proc.url); - } else { - dialogs.alert("Your server is not accessible ", "Your server is not accessible externally because it is bound to 'localhost', please bind it to '0.0.0.0' instead"); - } - } - }; - })); - - return ports; - }); - }; - - return { - 'command': httpPorts, - 'update': updatePorts - } -}); \ No newline at end of file diff --git a/addons/cb.project/runner.js b/addons/cb.project/runner.js deleted file mode 100644 index 75b2018f..00000000 --- a/addons/cb.project/runner.js +++ /dev/null @@ -1,42 +0,0 @@ -define([ - 'autorun' -], function(autorun) { - var _ = codebox.require("hr/utils"); - var operations = codebox.require("core/operations"); - var box = codebox.require("core/box"); - var dialogs = codebox.require("utils/dialogs"); - var alerts = codebox.require("utils/alerts"); - var Command = codebox.require("models/command"); - - // Run commands - var runCommands = Command.register("project.run.action", { - 'category': "Project", - 'title': "Perform Action", - 'type': "menu", - 'offline': false, - 'search': false - }); - - // Update runner list - var updateList = function() { - return box.runner().then(function(runner) { - runCommands.menu.reset(_.map(runner, function(_runner) { - return { - 'title': _runner.name, - 'action': function() { - autorun.command.run({ - 'id': _runner.id - }); - } - }; - })); - - return ports; - }); - }; - - return { - 'command': runCommands, - 'update': updateList - } -}); \ No newline at end of file diff --git a/addons/cb.project/samples.js b/addons/cb.project/samples.js deleted file mode 100644 index 052ac478..00000000 --- a/addons/cb.project/samples.js +++ /dev/null @@ -1,49 +0,0 @@ -define([], function() { - var _ = codebox.require("hr/utils"); - var dialogs = codebox.require("utils/dialogs"); - var box = codebox.require("core/box"); - var rpc = codebox.require("core/backends/rpc"); - var Command = codebox.require("models/command"); - - // HTTP Ports - var samplesMenu = Command.register("project.samples", { - 'category': "Project", - 'title': "Use Sample Project", - 'type': "menu", - 'offline': false, - 'search': false - }); - - // Update samples list - var updateSamples = function() { - return rpc.execute("project/supported").then(function(projectTypes) { - samplesMenu.menu.reset( - _.chain(projectTypes) - .map(function(projectType) { - if (!projectType.sample) return null; - - return { - 'title': projectType.name, - 'action': function() { - dialogs.confirm("Replace workspace contents with "+projectType.name+" sample?", - "WARNING: Using a sample will erase the current contents of your workspace. Use only if your workspace is empty or if you want to wipe it").then(function() { - return rpc.execute("project/useSample", { - 'sample': projectType.id - }); - }); - } - }; - }) - .compact() - .value() - ); - - return projectTypes; - }); - }; - - return { - 'command': samplesMenu, - 'update': updateSamples - } -}); \ No newline at end of file diff --git a/addons/cb.project/settings.js b/addons/cb.project/settings.js deleted file mode 100644 index 83df4a46..00000000 --- a/addons/cb.project/settings.js +++ /dev/null @@ -1,19 +0,0 @@ -define([], function() { - var settings = codebox.require("core/settings"); - - // Add settings - return settings.add({ - 'namespace': "project", - 'title': "Project", - 'defaults': { - 'openrundialog': true - }, - 'fields': { - 'openrundialog': { - 'label': "Open Run Dialog", - 'type': "checkbox", - 'help': "Open new window when running application." - }, - } - }); -}); \ No newline at end of file diff --git a/addons/cb.settings/client.js b/addons/cb.settings/client.js deleted file mode 100644 index 570b2122..00000000 --- a/addons/cb.settings/client.js +++ /dev/null @@ -1,29 +0,0 @@ -define(["views/dialog"], function(SettingsDialog) { - var Command = codebox.require("models/command"); - var app = codebox.require("core/app"); - var dialogs = codebox.require("utils/dialogs"); - var menu = codebox.require("core/commands/menu"); - - // Add opening command - var command = Command.register("settings", { - category: "Application", - title: "Settings", - icons: { - 'default': "cog", - }, - shortcuts: [ - "mod+," - ], - position: 100, - offline: false, - action: function(page) { - dialogs.open(SettingsDialog, { - 'page': page, - 'keyboardEnter': false - }); - } - }); - - menu.getById("file").menu.add(command); -}); - diff --git a/addons/cb.settings/package.json b/addons/cb.settings/package.json deleted file mode 100644 index e8283180..00000000 --- a/addons/cb.settings/package.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "name": "cb.settings", - "version": "0.1.2", - "title": "Settings", - "description": "Configuration interface for your workspace.", - "homepage": "https://github.com/FriendCode/codebox", - "license": "Apache", - "author": { - "name": "Codebox", - "email": "contact@friendco.de", - "url": "https://www.codebox.io" - }, - "client": { - "main": "client" - }, - "engines": { - "codebox": ">=0.7.0" - } -} \ No newline at end of file diff --git a/addons/cb.settings/stylesheets/dialog.less b/addons/cb.settings/stylesheets/dialog.less deleted file mode 100644 index 49e53302..00000000 --- a/addons/cb.settings/stylesheets/dialog.less +++ /dev/null @@ -1,57 +0,0 @@ -.addon-settings-dialog { - .modal-dialog { - @media screen and (min-width: 768px) { - width: 760px; - } - } - - .modal-body { - padding: 0px; - position: relative; - width: 100%; - height: 100%; - - .settings-title { - opacity: 0.6; - } - - .settings-menu { - position: absolute; - top: 51px; - left: 0px; - width: 200px; - bottom: 0px; - overflow-y: auto; - background: #f8f8f8; - border-right: 1px solid #ddd; - - .nav-pills>li { - >a { - border-radius: 0px; - color: inherit; - border-left: 3px solid transparent; - } - - &.active { - >a { - border-left-color: #5E9EF3; - background: transparent; - } - } - } - } - - .settings-content { - margin-left: 200px; - min-height: 300px; - } - } - - .modal-footer { - margin-top: 0px; - } - - .settings-basepane { - margin: 20px; - } -} diff --git a/addons/cb.settings/templates/dialog.html b/addons/cb.settings/templates/dialog.html deleted file mode 100644 index 4a6fbc66..00000000 --- a/addons/cb.settings/templates/dialog.html +++ /dev/null @@ -1,34 +0,0 @@ -
        - -
        \ No newline at end of file diff --git a/addons/cb.settings/views/dialog.js b/addons/cb.settings/views/dialog.js deleted file mode 100644 index 147fe33e..00000000 --- a/addons/cb.settings/views/dialog.js +++ /dev/null @@ -1,66 +0,0 @@ -define([ - "text!templates/dialog.html", - "less!stylesheets/dialog.less" -], function(templateFile) { - var _ = codebox.require("hr/utils"); - var $ = codebox.require("hr/dom"); - var DialogView = codebox.require("views/dialogs/base"); - var settings = codebox.require("core/settings"); - - var SettingsDialog = DialogView.extend({ - className: "addon-settings-dialog modal fade", - templateLoader: "text", - template: templateFile, - events: _.extend({}, DialogView.prototype.events,{ - "submit form": "submit", - "shown.bs.tab a[data-toggle='tab']": "changeTab" - }), - - // Template settings - templateContext: function() { - return { - 'settings': settings, - 'tabs': _.pairs(settings.sections), - 'limit': 3 - } - }, - - // Finish rendering - finish: function() { - var that = this; - settings.each(function(tab) { - tab.render(); - tab.$el.appendTo(this.$("#settings-tab-"+tab.namespace)); - }, this); - setTimeout(function() { - if (that.options.page) { - that.$(".settings-menu a[href='#settings-tab-"+that.options.page+"']").tab('show'); - } else { - that.$(".settings-menu a:first").tab('show'); - } - }, 200); - return SettingsDialog.__super__.finish.apply(this, arguments); - }, - - // Update settings - submit: function(e) { - var that = this; - - if (e != null) { - e.preventDefault(); - e.stopPropagation(); - } - - settings.save().fin(function() { - that.close(); - }); - }, - - // Change tab - changeTab: function(e) { - this.$(".settings-title").text($(e.target).text()); - } - }); - - return SettingsDialog; -}); \ No newline at end of file diff --git a/addons/cb.terminal/client.js b/addons/cb.terminal/client.js deleted file mode 100644 index d701295c..00000000 --- a/addons/cb.terminal/client.js +++ /dev/null @@ -1,137 +0,0 @@ -define([ - "node_modules/sh.js/build/sh", - "views/tab" -], function(Terminal, TerminalTab) { - var Command = codebox.require("models/command"); - var commands = codebox.require("core/commands/toolbar"); - var box = codebox.require("core/box"); - var tabs = codebox.require("core/tabs"); - var settings = codebox.require("core/settings"); - var menu = codebox.require("core/commands/menu"); - - // Add settings - settings.add({ - 'namespace': "terminal", - 'title': "Terminal", - 'defaults': { - 'font': "monospace", - 'size': 13, - 'line-height': 1.3, - 'theme': 'monokai_soda' - }, - 'fields': { - 'font': { - 'label': "Font", - 'type': "select", - 'options': { - 'monospace': "Monospace", - 'arial': "Arial", - 'Courier New': "Courier New", - "'MS Sans Serif', Geneva, sans-serif;": "MS Sans Serif", - "'Lucida Sans Unicode', 'Lucida Grande', sans-serif": "Lucida Sans Unicode", - 'monaco': "Monaco (Mac OS)", - 'menlo': "Menlo (Mac OS)", - 'Ubuntu Mono': "Ubuntu Mono (Ubuntu)", - 'Consolas': "Consolas (Windows)", - 'Lucida Console': "Lucida Console (Windows)" - }, - }, - 'size': { - 'label': 'Font size', - 'type': 'number', - 'min': 8, - 'max': 20, - 'step': 1 - }, - 'line-height': { - 'label': 'Line height', - 'type': 'number', - 'min': 1, - 'max': 1.9, - 'step': 0.1 - }, - 'theme': { - 'label': 'Theme', - 'type': 'select', - 'options': _.chain(Terminal.themes.defaults) - .clone() - .map(function(theme, name) { - return [name, name]; - }) - .object() - .value() - } - } - }); - - // Add opening command - var command = commands.register("terminal.open", { - category: "Terminal", - title: "New Terminal", - description: "New Tab Terminal", - icons: { - 'default': "terminal", - }, - offline: false, - shortcuts: [ - "alt+t" - ] - }, function(shellId, options) { - options = _.defaults(options || {}, { - cwd: null - }); - - // Create trminal tab - var tab = tabs.add(TerminalTab, { - 'shellId': shellId, - 'cwd': options.cwd - }, { - 'type': "terminal", - 'section': "terminals" - }); - - // Return the tab - return tab; - }); - - // Restorer for tabs - tabs.addRestorer("terminal", function(tabInfos) { - var tab = tabs.add(TerminalTab, {}, { - 'type': "terminal", - 'section': "terminals" - }); - - return tab; - }); - - // List terminals menu - var terminalsList = Command.register("terminal.list", { - category: "Terminal", - title: "Open Terminals", - type: "menu", - offline: false, - search: false - }); - - var refreshList = function() { - return box.listShells().then(function(shellIds) { - terminalsList.menu.reset(_.map(shellIds, function(shellId) { - return { - title: shellId, - action: function() { - command.run(shellId) - } - } - })); - }); - }; - - // Reset list when events from shells: - box.on("box:shell:open box:shell:exit", refreshList); - - // Add the command to file/tools menu - menu.getById("file").menuSection([ - command, - terminalsList - ]); -}); \ No newline at end of file diff --git a/addons/cb.terminal/package.json b/addons/cb.terminal/package.json deleted file mode 100644 index edcc0d49..00000000 --- a/addons/cb.terminal/package.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "name": "cb.terminal", - "version": "0.0.5", - "title": "Terminal", - "description": "Terminal tab integration into your workspace.", - "homepage": "https://github.com/FriendCode/codebox", - "license": "Apache", - "author": { - "name": "Codebox", - "email": "contact@friendco.de", - "url": "https://www.codebox.io" - }, - "client": { - "main": "client" - }, - "engines": { - "codebox": ">=0.7.0" - }, - "dependencies": { - "sh.js": "git+https://github.com/FriendCode/sh.js#1.1.1" - } -} diff --git a/addons/cb.terminal/stylesheets/tab.less b/addons/cb.terminal/stylesheets/tab.less deleted file mode 100644 index 576007d3..00000000 --- a/addons/cb.terminal/stylesheets/tab.less +++ /dev/null @@ -1,76 +0,0 @@ -.addon-terminal-tab { - position: absolute; - width: 100%; - height: 100%; - background: transparent; - - .tab-panel-body .tab-panel-inner.terminal-body { - background: #000; - border-color: #000; - overflow: auto; - cursor: text; - padding: 0px; - font-weight: bold; - padding: 3px; - overflow: hidden; - - * { - user-select: initial; - -webkit-user-select: initial; - } - - .terminal-container { - position: relative; - width: 100%; - height: 100%; - font-family: Menlo,Monaco,"DejaVu Sans Mono",Consolas,"Andale Mono",monospace; - } - .terminal-container div { - margin: 0px; - padding: 0px; - } - .terminal-container .terminal { - width: 100%; - height: 100%; - font-size: 13px; - line-height: 18px; - } - .terminal-container .terminal-input { - position: absolute; - top: 0; - left: -1000%; - background: rgba(255,255,255,0.75); - color: black; - border: 0; - outline: 0; - width: 100%; - } - .terminal-container .terminal-screen-keys { - position: absolute; - top: 0; - right: 0; - } - .terminal-container .terminal-screen-keys button { - background: -webkit-linear-gradient(top, #eeeef0, #d3d3d9); - border: 1px solid #58575e; - box-shadow: 0 2px 2px rgba(0,0,0,0.25), inset 0 -2px 0 rgba(0,0,0,0.25), inset 0 1px 0 #fff; - border: 1px solid #000; - border-radius: 2px; - padding: 8px; - font-size: 14px; - text-shadow: 0 1px 0 #fff; - } - .terminal-container .terminal-screen-keys button:focus, .terminal-container .terminal-screen-keys button.active { - outline: 0px; - background: -webkit-linear-gradient(top, #ccccd0, #a3a3a9); - } - .terminal-container .terminal-size-indicator { - position: absolute; - bottom: 0; - left: 0; - background-color: rgba(255,255,255,0.75); - color: black; - padding: 0 3px; - } - }; -} \ No newline at end of file diff --git a/addons/cb.terminal/views/tab.js b/addons/cb.terminal/views/tab.js deleted file mode 100644 index 2d4c2193..00000000 --- a/addons/cb.terminal/views/tab.js +++ /dev/null @@ -1,177 +0,0 @@ -define([ - "node_modules/sh.js/build/sh", - "less!stylesheets/tab.less" -], function(Terminal) { - var _ = codebox.require("hr/utils"); - var $ = codebox.require("hr/dom"); - var hr = codebox.require("hr/hr"); - var Tab = codebox.require("views/tabs/base"); - var box = codebox.require("core/box"); - var user = codebox.require("core/user"); - - var settings = user.settings("terminal"); - - var TerminalTab = Tab.extend({ - className: Tab.prototype.className+ " addon-terminal-tab", - defaults: { - shellId: null, - resize: true, - cwd: null - }, - menuTitle: "Terminal", - events: { - 'contextmenu': "clickTerm", - 'click': "clickTerm", - 'touchstart': "clickTerm" - }, - - initialize: function(options) { - var that = this; - TerminalTab.__super__.initialize.apply(this, arguments); - this.connected = false; - this.setTabState("loading", true); - - // Init menu - this.menu.menuSection([ - { - 'type': "checkbox", - 'title': "Exit", - 'action': function(state) { - that.closeTab(); - } - } - ]); - - // Init rendering - this.term_el = $("
        ", { - 'class': "tab-panel-inner terminal-body" - }).appendTo($("
        ", {"class": "tab-panel-body"}).appendTo(this.$el)).get(0); - - // New terminal - this.term = new Terminal({ - cols: 80, - rows: 24, - theme: settings.get("theme", 'default') - }); - this.term.open(this.term_el); - - this.interval = setInterval(_.bind(this.resize, this), 2000); - - // Init codebox stream - this.sessionId = this.options.shellId || _.uniqueId("term"); - this.shell = box.openShell({ - 'shellId': this.options.shellId ? this.sessionId : this.sessionId+"-"+(new Date()).getSeconds(), - 'cwd': this.options.cwd - }); - - this.on("tab:close", function() { - clearInterval(this.interval); - this.shell.disconnect(); - this.term.destroy(); - }, this); - - this.on("tab:state", function(state) { - if (state) { - this.focus(); - } - }, this); - this.on("tab:layout", function() { - that.resize(); - }, this); - - this.setTabTitle("Terminal - "+this.sessionId); - - - this.shell.once('data', function() { - that.setTabState("loading", false); - that.resize(); - }); - - this.shell.on('data', function(chunk) { - that.write(chunk); - }); - - this.shell.on("connect", function() { - that.connected = true; - that.trigger("terminal:ready"); - }, this); - - this.shell.on('disconnect', function() { - that.writeln("Connection closed"); - that.closeTab(); - }); - - // Connect term - this.term.on('data', function(data) { - that.shell.write(data); - }); - this.term.on("resize", function(w, h) { - that.shell.resize(w, h); - }); - - this.shell.connect(); - - setTimeout(function() { - that.focus(); - }, 300); - return this; - }, - - // Render - render: function() { - this.$el.css({ - "font-family": settings.get("font", "monospace"), - "font-size": settings.get("size", 13)+'px', - "line-height": settings.get("line-height", 1.3) - }); - $(this.term_el).css({ - 'background': this.term.colors[256], - 'border-color': this.term.colors[256] - }); - - return this.ready(); - }, - - // Resize the terminal - resize: function() { - if (!this.options.resize) { return false; } - - var w = this.$el.width(); - var h = this.$el.height(); - - if (w != this._width || h != this._height) { - this._width = w; - this._height = h; - this.term.sizeToFit(); - } - - return this; - }, - - // Focus - focus: function() { - this.term.focus(); - }, - - // Write - write: function(content) { - this.term.write(content); - return this; - }, - - // Write a line - writeln: function(line) { - return this.write(line+"\r\n"); - }, - - // Block propagation of clicks to sublevel - clickTerm: function(e) { - e.stopPropagation(); - - // We stop propagation so we need to active the tab manually - this.openTab(); - } - }); - - return TerminalTab; -}); diff --git a/addons/cb.theme.dark/ace/theme.js b/addons/cb.theme.dark/ace/theme.js deleted file mode 100644 index 4c4c049f..00000000 --- a/addons/cb.theme.dark/ace/theme.js +++ /dev/null @@ -1,10 +0,0 @@ -define([ - "less!ace/theme.less" -], function(cssContent) { - - return { - 'isDark': true, - 'cssClass': "ace-codebox-dark", - 'cssText': cssContent - } -}); \ No newline at end of file diff --git a/addons/cb.theme.dark/ace/theme.less b/addons/cb.theme.dark/ace/theme.less deleted file mode 100644 index c824a690..00000000 --- a/addons/cb.theme.dark/ace/theme.less +++ /dev/null @@ -1,206 +0,0 @@ -.ace_editor.ace-codebox-dark { - background-color: #2b303b; - color: #C5C8C6; - - .ace_gutter { - background: #2b303b; - color: #757a84 - } - - .ace_print-margin { - width: 1px; - background: #333d46 - } - - .ace_cursor { - color: #AEAFAD - } - - .ace_marker-layer .ace_selection { - background: #3d4550; - } - - &.ace_multiselect .ace_selection.ace_start { - box-shadow: 0 0 3px 0px #1D1F21; - border-radius: 2px - } - - .ace_marker-layer .ace_step { - background: rgb(102, 82, 0) - } - - .ace_marker-layer .ace_bracket { - margin: -1px 0 0 -1px; - border: 1px solid #4B4E55 - } - - .ace_marker-layer .ace_active-line { - background: #333d46 - } - - .ace_gutter-active-line { - background-color: #333d46; - } - - .ace_marker-layer .ace_selected-word { - border: 1px solid #373B41 - } - - .ace_invisible { - color: #4B4E55 - } - - .ace_keyword, - .ace_meta, - .ace_storage, - .ace_storage.ace_type, - .ace_support.ace_type { - color: #B294BB - } - - .ace_keyword.ace_operator { - color: #8ABEB7 - } - - .ace_constant.ace_character, - .ace_constant.ace_language, - .ace_constant.ace_numeric, - .ace_keyword.ace_other.ace_unit, - .ace_support.ace_constant, - .ace_variable.ace_parameter { - color: #cc856c - } - - .ace_constant.ace_other { - color: #CED1CF - } - - .ace_invalid { - color: #CED2CF; - background-color: #DF5F5F - } - - .ace_invalid.ace_deprecated { - color: #CED2CF; - background-color: #B798BF - } - - .ace_fold { - background-color: #81A2BE; - border-color: #757a84 - } - - .ace_entity.ace_name.ace_function, - .ace_support.ace_function, - .ace_variable { - color: #81A2BE - } - - .ace_support.ace_class, - .ace_support.ace_type { - color: #F0C674 - } - - .ace_heading, - .ace_string { - color: #9dbe8c - } - - .ace_entity.ace_name.ace_tag, - .ace_entity.ace_other.ace_attribute-name, - .ace_meta.ace_tag, - .ace_string.ace_regexp, - .ace_variable { - color: #b55761 - } - - .ace_comment { - color: #969896 - } - - .ace_indent-guide { - background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAACCAYAAACZgbYnAAAAEklEQVQImWNgYGBgYHB3d/8PAAOIAdULw8qMAAAAAElFTkSuQmCC) right repeat-y; - } - - /* Autocomplete dialog */ - &.ace_autocomplete { - width: 280px; - z-index: 200000; - background: #323d46; - color: #65737e; - border: none; - position: fixed; - box-shadow: 2px 3px 5px rgba(0,0,0,.2); - line-height: 2; - - font-smoothing: subpixel-antialiased; - -webkit-font-smoothing: subpixel-antialiased; - - .ace_marker-layer .ace_active-line { - background-color: #4f5b67; - z-index: 1; - } - .ace_text-layer .ace_selected, - .ace_text-layer .ace_selected .ace_rightAlignedText{ - color: #a1adba; - } - .ace_line-hover { - border: none; - margin-top: -1px; - background: none; - } - .ace_line-hover { - position: absolute; - z-index: 2; - } - .ace_rightAlignedText { - color: #65737e; - font-style: italic; - display: inline-block; - position: absolute; - right: 4px; - text-align: right; - z-index: -1; - } - .ace_completion-highlight{ - color: #c0c5ce; - } - } - - /* Search dialog */ - .ace_search { - border-color: transparent; - background: #1c1f25; - color: #65737e; - - .ace_searchbtn_close { - &:hover { - background-color: #323d46; - color: #65737e; - } - } - - .ace_search_field { - background: #323d46; - color: #65737e; - border-color: transparent; - } - - .ace_search_form, .ace_replace_form { - background-color: #323d46; - color: #65737e; - border-color: transparent; - } - - .ace_button { - background-color: #323d46; - color: #65737e; - } - - .ace_searchbtn, .ace_replacebtn{ - background-color: #323d46; - color: #65737e; - border-color: transparent; - } - } -} diff --git a/addons/cb.theme.dark/main.js b/addons/cb.theme.dark/main.js deleted file mode 100644 index a8e988b9..00000000 --- a/addons/cb.theme.dark/main.js +++ /dev/null @@ -1,128 +0,0 @@ -define([ - 'ace/theme' -], function(aceTheme) { - var themes = codebox.require("core/themes"); - - var bgDarker = "#1a1d24"; - var colorDarker = "#505c66"; - - var bgDark = "#222830"; - var colorDark = "#64737e"; - - var bgNormal = "#1c1f25"; - var colorNormal = "#dfe0e6"; - - var bgLight = "#2b303b"; - var colorLight = "#dadfe6"; - - themes.add({ - id: "dark", - title: "Dark", - - editor: { - 'theme': aceTheme - }, - styles: { - // Top menubar - menubar: { - 'background': bgDarker, - 'color': colorDark, - 'border-color': "#111", - - button: { - 'border-color': bgNormal - } - }, - - // Statusbar - statusbar: { - 'background': bgDarker, - 'color': colorDark, - 'border-color': "#111", - - button: { - 'border-color': bgNormal - } - }, - - // Lateral bar panels - lateralbar: { - 'background': bgDark, - - commands: { - 'background': bgDark, - 'color': colorLight - }, - body: { - 'color': colorDark - } - }, - - // Body - body: { - 'background': bgDark, - 'color': colorDark - }, - - // Tabs - tabs: { - section: { - 'border-color': bgDark - }, - header: { - 'background': bgDark, - 'color': colorDark - }, - content: { - 'background': bgLight - }, - tab: { - '&.active': { - 'background': bgLight, - 'color': colorLight - } - } - }, - - // Operations - operations: { - operation: { - 'background': bgLight, - 'color': "#fff", - 'border-color': "transparent" - } - }, - - // Alerts - alerts: { - alert: { - 'background': bgLight, - 'color': colorLight, - 'border-color': "transparent" - } - }, - - // Palette - palette: { - 'background': bgDark, - 'border-color': bgDarker, - - input: { - 'background': bgLight, - 'border-color': bgDarker, - 'color': colorLight - }, - - results: { - 'background': bgLight, - 'border-color': bgDarker, - 'color': colorLight, - - command: { - 'border-color': bgDarker - } - } - } - } - }); -}); \ No newline at end of file diff --git a/addons/cb.theme.dark/package.json b/addons/cb.theme.dark/package.json deleted file mode 100644 index e5d40d00..00000000 --- a/addons/cb.theme.dark/package.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "name": "cb.theme.dark", - "version": "0.0.1", - "title": "Dark Theme", - "description": "Dark and gray theme.", - "homepage": "https://github.com/FriendCode/codebox", - "license": "Apache", - "author": { - "name": "Codebox", - "email": "contact@friendco.de", - "url": "https://www.codebox.io" - }, - "client": { - "main": "main" - }, - "engines": { - "codebox": ">=0.7.0" - } -} \ No newline at end of file diff --git a/bin/codebox.js b/bin/codebox.js index 5051d6e6..4710a5d6 100755 --- a/bin/codebox.js +++ b/bin/codebox.js @@ -1,155 +1,119 @@ -#!/usr/bin/env node +#! /usr/bin/env node -var Q = require('q'); -var _ = require('lodash'); -var cli = require('commander'); -var path = require('path'); +var _ = require("lodash"); +var path = require("path"); +var program = require('commander'); var open = require("open"); -var Gittle = require('gittle'); -var pkg = require('../package.json'); -var codebox = require("../index.js"); +var pkg = require("../package.json"); +var codebox = require("../lib"); -// Codebox git repo: use to identify the user -var codeboxGitRepo = new Gittle(path.resolve(__dirname, "..")); +var gitconfig = require('../lib/utils/gitconfig'); -// Options -cli.option('-p, --port [http port]', 'Port to run the IDE'); -cli.option('-n, --hostname [http hostname]', 'Hostname to run the IDE'); -cli.option('-t, --title [project title]', 'Title for the project.'); -cli.option('-s, --sample [project type]', 'Replace directory content by a sample (warning: erase content).'); -cli.option('-o, --open', 'Open the IDE in your favorite browser'); -cli.option('-e, --email [email address]', 'Email address to use as a default authentication'); -cli.option('-u, --users [list users]', 'List of coma seperated users and password (formatted as "username:password")'); - - -// An authentication hook that uses a dictionary of users -function usersAuthHook(users) { - return function(data) { - if (!data.email || !data.token) { - return Q.reject(new Error("Need 'token' and 'email' for auth hook")); - } - - var userId = data.email; - - if (!users[userId] || data.token != users[userId]) { - return Q.reject(new Error("Invalid user !")); - } - - return { - 'userId': userId, - 'name': userId, - 'token': data.token, - 'email': data.email - }; - }; +function printError(err) { + console.log(err.stack || err.message || err); + process.exit(1); } -// Command 'run' -cli.command('run [folder]') -.description('Run a Codebox into a specific folder.') -.action(function(projectDirectory) { - var that = this; - var prepare = Q(); - - // Codebox.io settings - that.box = process.env.CODEBOXIO_BOXID; - that.key = process.env.CODEBOXIO_TOKEN; - that.codeboxio = process.env.CODEBOXIO_HOST || "https://api.codebox.io"; - - // Default options - that.directory = projectDirectory || process.env.WORKSPACE_DIR || "./"; - that.title = that.title || process.env.WORKSPACE_NAME; - that.port = that.port || process.env.PORT || 8000; - that.hostname = that.hostname || "0.0.0.0"; +program +.version(pkg.version) +.on('--help', function(){ + console.log(' Examples:'); + console.log(''); + console.log(' $ codebox run ./myfolder'); + console.log(''); +}); - var users = !that.users ? {} : _.object(_.map(that.users.split(','), function(x) { +//// Run Codebox +//// +program +.command('run [root]') +.description('run codebox') +.option('-t, --templates [list]', 'Configuration templates, separated by commas', "") +.option('-p, --port [port]', 'HTTP port', 3000) +.option('-o, --open', 'Open the IDE in your favorite browser') +.option('-e, --email [email address]', 'Email address to use as a default authentication') +.option('-u, --users [list users]', 'List of coma seperated users and password (formatted as "username:password")', function (val) { + return _.object(_.map((val || "").split(','), function(x) { // x === 'username:password' return x.split(':', 2); })); - - - var config = { - 'root': that.directory, - 'title': that.title, - 'server': { - 'port': parseInt(that.port), - 'hostname': that.hostname - }, - 'users': { - 'defaultEmail': that.email - }, - 'project': { - 'forceSample': that.sample +}, {}) +.action(function(root, opts) { + // Generate configration + var options = { + root: path.resolve(process.cwd(), root || "./"), + port: opts.port, + auth: { + users: opts.users } }; - // Use Codebox.io - if (that.box && that.codeboxio && that.key) { - _.extend(config, { - 'workspace': { - 'id': that.box - }, - 'hooks': { - 'auth': that.codeboxio+"/api/box/"+that.box+"/auth", - 'events': that.codeboxio+"/api/box/"+that.box+"/events", - 'settings': that.codeboxio+"/api/account/settings", - 'addons': that.codeboxio+"/api/addons/valid" - }, - 'webhook': { - 'authToken': that.key - }, - 'proc': { - 'urlPattern': 'http://web-%d.' + that.box + '.vm1.dynobox.io' - }, - 'users': { - // Don't use default git user - 'gitDefault': false - } + codebox.start(options) + .then(function() { + if (program.email) return program.email; + + // Path to user's .gitconfig file + var configPath = path.join( + process.env.HOME, + '.gitconfig' + ); + + // Codebox git repo: use to identify the user + return gitconfig(configPath) + .get("user") + .get("email") + .fail(function() { + return ""; }); - } else if(!_.isEmpty(users)) { - _.extend(config, { - 'public': false, - 'hooks': { - 'auth': usersAuthHook(users) - } - }); - } - - // Auth user using git - prepare.fin(function() { - // Start Codebox - return codebox.start(config).then(function() { - var url = "http://localhost:"+that.port; - - console.log("\nCodebox is running at",url); + }) + .then(function(email) { + var token = opts.users[email] || Math.random().toString(36).substring(7); + var url = "http://localhost:"+options.port; - if (that.open) { - open(url); - } - }, function(err) { - console.error('Error initializing CodeBox'); - console.error(err); - console.error(err.stack); + console.log("\nCodebox is running at", url); - // Kill process - process.exit(1); - }); + if (program.open) open(url+"/?email="+email+"&token="+token); }) + .fail(printError); }); -cli.on('--help', function(){ - console.log(' Version: %s', pkg.version); - console.log(''); - console.log(' Examples:'); - console.log(''); - console.log(' $ codebox run'); - console.log(' $ codebox run ./myProject'); - console.log(''); - console.log(' Use option --open to directly open the IDE in your browser:'); - console.log(' $ codebox run ./myProject --open'); - console.log(''); +//// Install packages +//// +program +.command('install') +.description('pre-install packages') +.option('-r, --root [path]', 'Root folder to store packages') +.option('-p, --packages ', 'Comma separated list of packages to install', function (val) { + return _.chain(val.split(",")) + .compact() + .map(function(pkgref) { + var parts = pkgref.split(":"); + var name = _.first(parts); + var url = parts.slice(1).join(":"); + if (!name || !url) throw "Packages need to be formatted as 'name:url'"; + + return [name,url]; + }) + .object() + .value() +}, []) +.action(function(opts) { + codebox.prepare({ + packages: { + root: opts.root? path.resolve(process.cwd(), opts.root) : undefined, + install: opts.packages, + defaults: null + } + }) + .then(function() { + process.exit(0); + }) + .fail(printError); }); -cli.version(pkg.version).parse(process.argv); -if (!cli.args.length) cli.help(); +program.parse(process.argv); + +if (!process.argv.slice(2).length) { + program.outputHelp(); +} diff --git a/client/collections/addons.js b/client/collections/addons.js deleted file mode 100644 index b4b4bca6..00000000 --- a/client/collections/addons.js +++ /dev/null @@ -1,233 +0,0 @@ -define([ - "hr/promise", - "hr/utils", - "hr/hr", - "core/backends/rpc", - "models/addon", - "utils/dialogs" -], function(Q, _, hr, rpc, Addon, dialogs) { - var Addons = hr.Collection.extend({ - model: Addon, - defaults: _.defaults({ - loader: "getInstalled", - loaderArgs: [], - }, hr.Collection.prototype.defaults), - - // Constructor - initialize: function() { - Addons.__super__.initialize.apply(this, arguments); - - this.resolved = {}; - this.provides = {}; - - return this; - }, - - // Get installed addons - getInstalled: function(options) { - var that = this; - - options = _.defaults(options || {}, {}); - - return rpc.execute("addons/list").then(function(data) { - that.add(_.values(data)); - }); - }, - - // Get by name - getByName: function(name) { - return this.find(function(addon) { - return addon.get("name") == name; - }); - }, - - // Check addons is installed - isInstalled: function(name) { - if (!_.isString(name)) name = name.get("name"); - - return this.getByName(name) != null; - }, - - // Check addons is a default addon - isDefault: function(name) { - if (!_.isString(name)) name = name.get("name"); - - var m = this.getByName(name); - if (m == null) return false; - return m.get("default"); - }, - - // Check is updated - isUpdated: function(addon) { - var m = this.getByName(addon.get("name")); - if (!m) return true; - return m.version() >= addon.version(); - }, - - // Get addon state - getState: function(name) { - if (!_.isString(name)) name = name.get("name"); - - var m = this.getByName(name); - if (m == null) return null; - return m.get("state"); - }, - - // Install an addon - install: function(git) { - var that = this; - - return rpc.execute("addons/install", { - 'git': git - }).then(function(data) { - that.reset([]); - return that.getInstalled(); - }); - }, - uninstall: function(name) { - var that = this; - - return rpc.execute("addons/uninstall", { - 'name': name - }).then(function() { - that.reset([]); - return that.getInstalled(); - }); - }, - - // Extract from engineer, order addons for loading - checkCycles: function() { - var that = this; - var plugins = this.map(function(addon, index) { - return { - name: addon.get("name"), - provides: addon.get("client.provides", []).concat(), - consumes: addon.get("client.consumes", []).concat(), - i: index - }; - }); - - var changed = true; - var sorted = []; - - while(plugins.length && changed) { - changed = false; - - plugins.concat().forEach(function(plugin) { - var consumes = plugin.consumes.concat(); - - var resolvedAll = true; - for (var i=0; i 0) { - var e = new Error("Error with "+_.size(errors)+" addons"); - e.addonsError = errors; - return Q.reject(e); - } - return Q(); - }); - }, - - // Get addons from an index - loadFromIndex: function(indexUrl) { - var cached, that = this, indexKey = indexUrl; - var box = require("core/box"); - - var resetCollection = function(index) { - that.reset(_.map(index.addons, function(addon) { - return _.extend(addon['package'], { - 'git': addon.git - }); - })); - return Q(index); - }; - - cached = hr.Cache.get("addons", indexKey); - if (cached) return resetCollection(cached); - - return rpc.execute("addons/registry", { - 'url': indexUrl - }) - .then(function(index) { - hr.Cache.set("addons", indexKey, index, 60*60); - return resetCollection(index); - }); - } - }); - - return Addons; -}); \ No newline at end of file diff --git a/client/collections/changes.js b/client/collections/changes.js deleted file mode 100644 index 2105e18e..00000000 --- a/client/collections/changes.js +++ /dev/null @@ -1,27 +0,0 @@ -define([ - "hr/utils", - "hr/hr", - "models/change" -], function(_, hr, Change) { - var Changes = hr.Collection.extend({ - model: Change, - - // Sort comparator - comparator: function(command) { - return command.get("path", "").length; - }, - - // Apply all - applyAll: function() { - console.log("apply all changes", this.size()); - return this.reduce(function(prev, change) { - console.log("next ", change, prev); - return prev.then(function() { - return change.apply(); - }) - }, Q()); - } - }); - - return Changes; -}); \ No newline at end of file diff --git a/client/collections/commands.js b/client/collections/commands.js deleted file mode 100644 index 4c3780ac..00000000 --- a/client/collections/commands.js +++ /dev/null @@ -1,16 +0,0 @@ -define([ - "hr/utils", - "hr/hr", - "models/command" -], function(_, hr, Command) { - var Commands = hr.Collection.extend({ - model: Command, - - // Sort comparator - comparator: function(command) { - return command.get("position", 2); - } - }); - - return Commands; -}); \ No newline at end of file diff --git a/client/collections/files.js b/client/collections/files.js deleted file mode 100644 index 6c51e8dc..00000000 --- a/client/collections/files.js +++ /dev/null @@ -1,11 +0,0 @@ -define([ - "hr/utils", - "hr/hr", - "models/file" -], function(_, hr, File) { - var Files = hr.Collection.extend({ - model: File - }); - - return Files; -}); \ No newline at end of file diff --git a/client/collections/operations.js b/client/collections/operations.js deleted file mode 100644 index 95486c2b..00000000 --- a/client/collections/operations.js +++ /dev/null @@ -1,66 +0,0 @@ -define([ - "hr/utils", - "hr/hr", - "hr/promise", - "models/operation", - "utils/dialogs" -], function(_, hr, Q, Operation, dialogs) { - var Operations = hr.Collection.extend({ - model: Operation, - - // Sort comparator - comparator: function(command) { - return command.get("progress", 0); - }, - - // Get by id - getById: function(opId) { - return this.find(function(op) { - return op.id == opId; - }); - }, - - // Start an operation - start: function(opId, startMethod, properties, options) { - var op, d; - - options = _.defaults({}, options || {}, { - 'unique': true - }); - - op = this.getById(opId); - - if (op) return Q.reject(new Error("An operation with this id is already running: "+opId)); - - op = new Operation({}, _.extend({ - 'id': opId - }, properties || {})); - - this.add(op); - - if (startMethod) { - d = startMethod(op); - - // Error during the operation - d.fail(function(err) { - dialogs.alert("Error during an operation ("+_.escape(opId)+")", err.message || err); - }); - - // Progress - d.progress(function(p) { - if (_.isNumber(p)) op.progress(p); - }); - - // Destroy the operation - d.fin(function() { - op.destroy(); - }); - return d; - } else { - return op; - } - } - }); - - return Operations; -}); \ No newline at end of file diff --git a/client/collections/tabs.js b/client/collections/tabs.js deleted file mode 100644 index 20f6b6f4..00000000 --- a/client/collections/tabs.js +++ /dev/null @@ -1,25 +0,0 @@ -define([ - "hr/utils", - "hr/hr", - "models/tab" -], function(_, hr, Tab) { - var Tabs = hr.Collection.extend({ - model: Tab, - - // Return a tab by its id - getById: function(id) { - return this.find(function(tab) { - return tab.id == id; - }); - }, - - // Return current active tab - getActive: function() { - return this.find(function(tab) { - return tab.get("active"); - }); - }, - }); - - return Tabs; -}); \ No newline at end of file diff --git a/client/collections/users.js b/client/collections/users.js deleted file mode 100644 index 106c2c41..00000000 --- a/client/collections/users.js +++ /dev/null @@ -1,27 +0,0 @@ -define([ - "hr/utils", - "hr/hr", - "core/backends/rpc", - "models/user" -], function(_, hr, rpc, User) { - var Users = hr.Collection.extend({ - model: User, - - // Return an user from the collection by its user id - getById: function(userId) { - return this.find(function(model) { - return model.get("userId") == userId; - }) - }, - - // Get list of collaborators from the box - getCollaborators: function() { - var that = this; - return rpc.execute("users/list").then(function(data) { - that.reset(data); - }); - } - }); - - return Users; -}); \ No newline at end of file diff --git a/client/core/addons.js b/client/core/addons.js deleted file mode 100644 index 01c2b53e..00000000 --- a/client/core/addons.js +++ /dev/null @@ -1,59 +0,0 @@ -define([ - 'hr/hr', - 'hr/promise', - 'models/command', - 'collections/commands', - 'collections/addons', - 'utils/dialogs', - 'core/operations' -], function (hr, Q, Command, Commands, Addons, dialogs, operations) { - // Collection for all installed addons - var addons = new Addons(); - - // Command to install with an url - Command.register("addons.install", { - category: "Add-ons", - title: "Install", - description: "Install with GIT Url", - offline: false, - action: function(url) { - return Q() - .then(function() { - if (url) return url; - return dialogs.prompt("Install a new addon", "GIT url for the addon:", ""); - }) - .then(function(_url) { - return operations.start("addon.install", function(op) { - return addons.install(_url); - }, { - title: "Installing add-on" - }); - }) - } - }); - - // Command to uninstall from a name - Command.register("addons.uninstall", { - category: "Add-ons", - title: "Uninstall", - description: "Uninstall with name", - offline: false, - search: false, - action: function(name) { - return Q() - .then(function() { - if (name) return name; - return dialogs.prompt("Uninstall an addon", "Name of the addon:", ""); - }) - .then(function(_name) { - return operations.start("addon.uninstall", function(op) { - return addons.uninstall(_name); - }, { - title: "Uninstalling add-on" - }); - }) - } - }); - - return addons; -}); \ No newline at end of file diff --git a/client/core/app.js b/client/core/app.js deleted file mode 100644 index 65e1aa1c..00000000 --- a/client/core/app.js +++ /dev/null @@ -1,252 +0,0 @@ -define([ - 'hr/hr', - 'utils/url', - 'utils/dialogs', - 'utils/alerts', - 'utils/loading', - 'views/grid', - 'text!resources/templates/main.html', - 'core/box', - 'core/session', - 'core/addons', - 'core/box', - 'core/files', - 'core/commands/toolbar', - 'core/commands/menu', - 'core/commands/statusbar', - 'core/commands/palette', - 'core/tabs', - 'core/panels', - 'core/operations', - 'core/localfs', - 'core/themes', - 'core/search/commands', - 'core/search/files', - 'core/search/tags', - 'core/search/addons', - 'core/search/code' -], function (hr, url, dialogs, alerts, loading, GridView, templateFile, -box, session, addons, box, files, commands, menu, statusbar, palette, tabs, panels, operations, localfs, themes) { - - // Define base application - var Application = hr.Application.extend({ - name: "Codebox", - template: templateFile, - metas: { - "robots": "noindex, nofollow", - "description": "Cloud IDE on a box.", - "apple-mobile-web-app-capable": "yes", - "apple-mobile-web-app-status-bar-style": "black", - "viewport": "width=device-width, initial-scale=1, user-scalable=no" - }, - links: { - "icon": hr.Urls.static("images/icons/32.png"), - "apple-touch-icon": hr.Urls.static("images/icons/ios.png") - }, - events: { - "click .cb-login .login-box #login-submit": "actionLoginBox" - }, - - // Constructor - initialize: function() { - Application.__super__.initialize.apply(this, arguments); - this._autologin = true; - this.loginError = null; - - // Init base grid for UI - this.grid = new GridView({ - columns: 1000 - }); - - // Add lateral bar: panels and operations - var v = this.grid.addView(new hr.View(), { - width: 18 - }); - panels.$el.appendTo(v.$el); - operations.$el.appendTo(v.$el); - - // Add operations - operations.on("add remove reset", function() { - setTimeout(function() { - panels.$el.css("bottom", operations.$el.height()); - }, 200); - }); - - // Add tabs - this.grid.addView(tabs); - - // Default tab: new file - tabs.on("tabs:default tabs:opennew", function() { - files.openNew(); - }, this); - - // Offline: state/update - hr.Offline.on("state", function(state) { - if (!state) { - alerts.show("Caution: Connection lost, Workspace is now in Offline mode", 5000); - if (!localfs.isSyncEnabled()) { - dialogs.alert("Caution: Connection lost", "Offline file synchronization is not enabled for this workspace, enable it first when online."); - } - } else { - dialogs.confirm("Connection detected", "Save changes before refreshing. Do you want to refresh now (unsaved changes will be lost) ?") - .then(function() { - location.reload(); - }); - } - }); - hr.Offline.on("update", function() { - location.reload(); - }); - - // Title changed - box.on("change:name", function() { - this.title(box.get("name")); - }, this); - - return this; - }, - - // Template rendering context - templateContext: function() { - return { - 'email': hr.Cookies.get("email"), - 'token': hr.Cookies.get("token"), - 'loginError': this.loginError - }; - }, - - // Render the application - render: function() { - var email = hr.Cookies.get("email"); - var password = hr.Cookies.get("token"); - - if (!box.isAuth() && ((email && password) || (email && box.get("public"))) && this._autologin) { - this.doLogin(email, password); - return; - } - return Application.__super__.render.apply(this, arguments); - }, - - // Finish rendering - finish: function() { - var that = this; - - if (box.isAuth()) { - // Add menu - menu.$el.appendTo(this.$(".cb-menubar")); - menu.render(); - - // Add statusbar - statusbar.$el.appendTo(this.$(".cb-statusbar")); - statusbar.render(); - - // Add commands - commands.$el.appendTo(this.$(".cb-commands")); - commands.render(); - - // Add grid - this.grid.$el.appendTo(this.$(".cb-body")); - - // Add palette - palette.$el.appendTo(this.$(".cb-body")); - palette.render(); - - // Load addons - loading.show(addons.loadAll()).fail(function(err) { - return dialogs.alert("Error loading Add-ons", - "

        Error when initializing addons." + - " Please check addons states using the addons manager and reinstall problematic add-ons.

        " + - "

        Error message: "+ (err.message || err) +"

        " + - _.map(err.addonsError || [], function(error) { - return "

        - "+_.escape(error.addon)+": "+(error.error.message || error.error)+"

        "; - }).join("\n")); - }) - .fin(themes.init) - .fin(function() { - // Load new addons - addons.on("add", function(addon) { - addon.load(); - }); - - // Check update - hr.Offline.checkUpdate(); - - // Trigger event that app is ready - that.trigger("ready"); - - // Open new file if not files opened by addons and no restored tabs - tabs.restoreTabs() - .then(function(_n) { - if (files.active.size() == 0 && _n == 0) files.openNew(); - }); - }); - } - return Application.__super__.finish.apply(this, arguments); - }, - - // Login to box - actionLoginBox: function(e) { - var that = this; - if (e) { - e.preventDefault(); - } - - var email = this.$(".login-box #login-email").val(); - var password = this.$(".login-box #login-token").val(); - - this.doLogin(email, password); - }, - - // Do login - doLogin: function(email, password) { - var that = this; - - // If public: generate a random password - if (box.get("public")) { - password = Math.random().toString(36).substring(8); - } - - // Clear errors - this.$(".login-box .form-group").removeClass("has-error"); - - // No email - if (!email) { - this.$(".login-box #login-email").parent(".form-group").addClass("has-error"); - return Q.reject(new Error("No email")); - } - - // No password - if (!password) { - this.$(".login-box #login-token").parent(".form-group").addClass("has-error"); - return Q.reject(new Error("No password")); - } - - return session.start(email, password).then(function() { - hr.Cookies.set("email", email); - hr.Cookies.set("token", password); - - that.render(); - }).fail(function(err) { - that._autologin = false; - that.loginError = err; - - loading.stop(); - that.render(); - }); - }, - - // Toggle mode - toggleMode: function(mode, st) { - $("#codebox").toggleClass("mode-"+mode, st); - st = this.hasMode(mode); - $(".cb-active-mode-"+mode).toggleClass("active", st); - $(".cb-inactive-mode-"+mode).toggleClass("active", !st); - }, - hasMode: function(mode, st) { - return $("#codebox").hasClass("mode-"+mode); - } - }); - - var app = new Application(); - return app; -}); diff --git a/client/core/backends/rpc.js b/client/core/backends/rpc.js deleted file mode 100644 index b61e572e..00000000 --- a/client/core/backends/rpc.js +++ /dev/null @@ -1,43 +0,0 @@ -define([ - 'hr/hr' -], function(hr) { - var rpc = new hr.Backend({ - prefix: "rpc" - }); - - rpc.defaultMethod({ - execute: function(args, options, method) { - options = _.defaults({}, options || {}, { - dataType: "json", - options: { - 'headers': { - 'Content-type': 'application/json' - } - } - }); - - return hr.Requests.post("rpc/"+method, JSON.stringify(args), options).then(function(data) { - if (!data.ok) return Q.reject(new Error(data.error)); - return Q(data.data); - }, function(err) { - try { - var errContent = JSON.parse(err.httpRes); - var e = new Error(errContent.error || err.message); - e.code = errContent.code || err.status || 500; - return Q.reject(e); - } catch(e) { - return Q.reject(err); - } - }); - } - }); - - // Cached methods - rpc.addCachedMethod('box/status'); - rpc.addCachedMethod('box/changes'); - rpc.addCachedMethod('auth/join'); - rpc.addCachedMethod('addons/list'); - rpc.addCachedMethod('users/list'); - - return rpc; -}); \ No newline at end of file diff --git a/client/core/backends/vfs.js b/client/core/backends/vfs.js deleted file mode 100644 index 0d1ade59..00000000 --- a/client/core/backends/vfs.js +++ /dev/null @@ -1,176 +0,0 @@ -define([ - 'hr/utils', - 'hr/hr', - 'utils/url', - 'core/localfs' -], function(_, hr, Url, localfs) { - var logger = hr.Logger.addNamespace("vfs"); - - // Create backend - var vfs = new hr.Backend({ - prefix: "vfs" - }); - - // Emulate a vfs event - var triggerWatchEvent = function(name, path, data) { - var eventName = "watch.change."+name; - vfs.trigger("event:"+eventName, { - 'event': eventName, - 'data': _.extend({}, { - 'path': path, - 'change': name, - 'source': "fakeVfs" - }, data) - }); - }; - - // Refresh all vfs when offlien change - hr.Offline.on("state", function() { - triggerWatchEvent("folder", "/"); - }); - - // Map vfs method -> http request method - var methodsMap = { - "listdir": "getJSON", - "write": "put", - "mkdir": "put", - "create": "put", - "special": "post", - "remove": "delete", - "read": "get" - }; - - // Base method when connection is on - vfs.defaultMethod({ - execute: function(args, options, method) { - if (args && method != "write") args = JSON.stringify(args); - if (!options.url) return Q.reject(new Error("VFS requests need 'url' option")); - if (!methodsMap[method]) return Q.reject(new Error("Invalid VFS request: "+method)); - - logger.log(method+": "+options.url); - return hr.Requests[methodsMap[method]](options.url, args, options); - }, - after: function(args, results, options, method) { - var path = localfs.urlToPath(options.url); - switch (method) { - case "remove": - triggerWatchEvent("delete", path); - break; - case "special": - // Rename - if (args.renameFrom) { - triggerWatchEvent("delete", args.renameFrom); - triggerWatchEvent("create", path); - } else if (args.copyFrom){ - triggerWatchEvent("create", path); - } - - break; - case "create": - triggerWatchEvent("create", path); - break; - case "mkdir": - triggerWatchEvent("create", path); - break; - case "write": - triggerWatchEvent("update", path); - break; - } - } - }); - - // Read a file content - vfs.addMethod('read', { - fallback: function(args, options) { - var path = localfs.urlToPath(options.url); - return localfs.read(path); - }, - after: function(args, results, options) { - - } - }); - - // Create a new file - vfs.addMethod('create', { - fallback: function(args, options) { - var path = localfs.urlToPath(options.url); - return localfs.create(path, args); - }, - after: function(args, results, options) { - localfs.autoSync(); - } - }); - - // Create a new directory - vfs.addMethod('mkdir', { - fallback: function(args, options) { - var path = localfs.urlToPath(options.url); - return localfs.mkdir(path, args); - }, - after: function(args, results, options) { - localfs.autoSync(); - } - }); - - // Write a file content - vfs.addMethod('write', { - fallback: function(args, options) { - var path = localfs.urlToPath(options.url); - return localfs.write(path, args); - }, - after: function(args, results, options) { - localfs.autoSync(); - } - }); - - // Rename a file - vfs.addMethod('special', { - fallback: function(args, options) { - // Rename - if (args.renameFrom) { - var to = localfs.urlToPath(options.url); - var from = args.renameFrom; - - if (!from) return Q.reject("need 'renameFrom'"); - return localfs.mv(from, to); - } - // Copy - else if (args.copyFrom) { - var to = localfs.urlToPath(options.url); - var from = args.copyFrom; - - if (!from) return Q.reject("need 'copyFrom'"); - return localfs.cp(from, to); - } else { - return Q.reject("Invalid special operations"); - } - }, - after: function(args, results, options) { - localfs.autoSync(); - } - }); - - // Remove a file or directory - vfs.addMethod('remove', { - fallback: function(args, options) { - var path = localfs.urlToPath(options.url); - return localfs.rm(path, args); - }, - after: function(args, results, options) { - localfs.autoSync(); - } - }); - - // List a directory - vfs.addMethod('listdir', { - fallback: function(args, options) { - var path = localfs.urlToPath(options.url); - return localfs.ls(path); - }, - after: function(args, results, options) { - - } - }); - - return vfs; -}); \ No newline at end of file diff --git a/client/core/box.js b/client/core/box.js deleted file mode 100644 index cfdf1687..00000000 --- a/client/core/box.js +++ /dev/null @@ -1,20 +0,0 @@ -define([ - 'hr/promise', - 'hr/hr', - 'models/box', - 'core/search', - 'core/collaborators' -], function (Q, hr, Codebox, search, collaborators) { - // Current box - var box = new Codebox(); - - // Bind collaborators changement - box.on("box:users:add", function(e) { - collaborators.add(e.data); - }); - box.on("box:users:remove", function(e) { - collaborators.remove(collaborators.getById(e.data.userId)); - }); - - return box; -}); \ No newline at end of file diff --git a/client/core/collaborators.js b/client/core/collaborators.js deleted file mode 100644 index 7de8e885..00000000 --- a/client/core/collaborators.js +++ /dev/null @@ -1,19 +0,0 @@ -define([ - 'hr/utils', - 'hr/hr', - 'collections/users', - 'utils/alerts' -], function (_, hr, Users, alerts) { - // Collection for all current collaborators - var collaborators = new Users(); - - collaborators.on("add", function(user) { - alerts.show(user.get("name")+" just joined the workspace", 5000); - }); - - collaborators.on("remove", function(user) { - alerts.show(user.get("name")+" just left the workspace", 5000); - }); - - return collaborators; -}); \ No newline at end of file diff --git a/client/core/commands/menu.js b/client/core/commands/menu.js deleted file mode 100644 index 9c4d8557..00000000 --- a/client/core/commands/menu.js +++ /dev/null @@ -1,50 +0,0 @@ -define([ - 'hr/utils', - 'hr/hr', - 'views/commands/menubar', - 'core/box', - 'core/panels', - 'core/tabs', - 'core/session', - 'core/localfs', - 'core/settings' -], function (_, hr, MenubarView, box, panels, tabs, session, localfs, settings) { - // Collection for all menu commands - var menu = new MenubarView(); - - menu.register("view", { - title: "View", - position: 5 - }).menuSection({ - 'id': "themes.settings", - 'category': "View", - 'title': "Settings", - 'description': "Open Theme and View Settings", - 'offline': false, - 'action': function() { - settings.open("themes"); - } - }).menuSection([ - panels.panelsCommand - ]).menuSection([ - tabs.layoutCommand - ]); - - menu.register("file", { - title: "File", - position: 0 - }).menuSection([{ - 'id': "quit", - 'category': "Application", - 'title': "Quit", - 'description': "Close Current Session", - 'shortcuts': [ - "alt+q" - ], - 'action': session.exit - }], { - 'position': 1000 - }); - - return menu; -}); \ No newline at end of file diff --git a/client/core/commands/palette.js b/client/core/commands/palette.js deleted file mode 100644 index fa426d07..00000000 --- a/client/core/commands/palette.js +++ /dev/null @@ -1,26 +0,0 @@ -define([ - 'views/commands/palette', - 'core/commands/toolbar', - 'core/search' -], function (PaletteView, commands, search) { - - var palette = new PaletteView({ - searchHandler: _.bind(search.query, search) - }); - - commands.register("palette.toggle", { - title: "Palette", - description: "Toggle Command Palette", - icons: { - 'default': "search", - }, - position: 0, - shortcuts: [ - "mod+shift+p", "alt+s" - ] - }, function() { - palette.toggle(); - }); - - return palette; -}); \ No newline at end of file diff --git a/client/core/commands/statusbar.js b/client/core/commands/statusbar.js deleted file mode 100644 index 7ec36f6d..00000000 --- a/client/core/commands/statusbar.js +++ /dev/null @@ -1,20 +0,0 @@ -define([ - 'hr/utils', - 'hr/hr', - 'views/commands/statusbar' -], function (_, hr, StatusbarView) { - // Collection for all statusbar commands - var statusbar = new StatusbarView(); - - // Feedback - statusbar.register("statusbar.sendfeedback", { - title: "Send Feedback", - position: 5, - offline: false, - search: false - }, function() { - window.open("https://github.com/FriendCode/codebox/issues"); - }); - - return statusbar; -}); \ No newline at end of file diff --git a/client/core/commands/toolbar.js b/client/core/commands/toolbar.js deleted file mode 100644 index 0fe133e3..00000000 --- a/client/core/commands/toolbar.js +++ /dev/null @@ -1,11 +0,0 @@ -define([ - 'hr/utils', - 'hr/hr', - 'views/commands/toolbar', - 'core/search', -], function (_, hr, CommandsToolbar, search) { - // Collection for all toolbar commands - var commands = new CommandsToolbar(); - - return commands; -}); \ No newline at end of file diff --git a/client/core/debug/breakpoints.js b/client/core/debug/breakpoints.js deleted file mode 100644 index 55485fcc..00000000 --- a/client/core/debug/breakpoints.js +++ /dev/null @@ -1,47 +0,0 @@ -define([ - "hr/hr", - "hr/utils" -], function(hr, _) { - - var Breakpoints = hr.Class.extend({ - initialize: function() { - Breakpoints.__super__.initialize.apply(this, arguments); - - // map filename -> array of int - this.breakpoints = {}; - }, - - // Signal change for a breakpoint - signalChange: function(change, path, line) { - this.trigger("change:"+change, { - 'change': change, - 'path': path, - 'line': line - }); - }, - - // Return all breakpoints - all: function() { - return _.clone(this.breakpoints); - }, - - // Get breakpoints for a file - getFileBreakpoints: function(path) { - return this.breakpoints[path] || []; - }, - - // When breakpoints changed for a file - setFileBreakpoints: function(path, breakpoints) { - var oldBreakpoints = this.breakpoints[path] || []; - this.breakpoints[path] = _.clone(breakpoints); - - var added = _.difference(this.breakpoints[path], oldBreakpoints); - var removed = _.difference(oldBreakpoints, this.breakpoints[path]); - - _.each(added, _.partial(_.bind(this.signalChange, this), "add", path)); - _.each(removed, _.partial(_.bind(this.signalChange, this), "remove", path)); - } - }); - - return Breakpoints; -}); \ No newline at end of file diff --git a/client/core/debug/manager.js b/client/core/debug/manager.js deleted file mode 100644 index 307d5a35..00000000 --- a/client/core/debug/manager.js +++ /dev/null @@ -1,60 +0,0 @@ -define([ - "hr/hr", - "hr/promise", - "core/debug/session", - "core/debug/breakpoints" -], function(hr, Q, DebuggerSession, DebuggerBreakpoints) { - - var Debugger = hr.Class.extend({ - initialize: function(options) { - Debugger.__super__.initialize.apply(this, arguments); - - // Active debugger - this.activeDebugger = null; - - // Debugegr running - this.state = false; - - // Current breakpoints - this.breakpoints = new DebuggerBreakpoints(); - }, - - // Open a debugger session - open: function() { - if (this.isActive()) { - // already an active debugger -> close it - return this.activeDebugger.close() - .then(_.bind(function() { - return this.open(); - }, this)); - } - - this.activeDebugger = new DebuggerSession(); - this.trigger("state", true); - - this.listenTo(this.activeDebugger, "close", function() { - this.activeDebugger = null; - this.trigger("state", false); - this.trigger("position", null); - }); - this.listenTo(this.activeDebugger, "position", function(position) { - this.trigger("position", position); - }); - - return Q(this.activeDebugger); - }, - - // Return if debug is active - isActive: function(st) { - return this.activeDebugger != null; - }, - - // Get current debug position - getPosition: function() { - if (!this.isActive()) return null; - return this.activeDebugger.position; - } - }); - - return new Debugger(); -}); \ No newline at end of file diff --git a/client/core/debug/session.js b/client/core/debug/session.js deleted file mode 100644 index 9de9b077..00000000 --- a/client/core/debug/session.js +++ /dev/null @@ -1,198 +0,0 @@ -define([ - "hr/hr", - "hr/promise", - "core/backends/rpc" -], function(hr, Q, rpc) { - - var DebuggerSession = hr.Class.extend({ - initialize: function(options) { - DebuggerSession.__super__.initialize.apply(this, arguments); - - // Session id for this debugger - this.id = null; - - // Breakpoints - this._breakpoints = []; - - // Position - this.position = null; - }, - - // Initialize the debugger - init: function(args) { - var that = this; - return rpc.execute("debug/init", args) - .then(function(dbg) { - that.id = dbg.id; - that.trigger("update:init"); - }); - }, - - // Close debugger - close: function() { - var that = this; - if (!that.id) return Q.reject(new Error("Session not yet initialized")); - - return this.execute("close") - .then(function() { - that.id = null; - that.trigger("close"); - that.stopListening(); - that.off(); - }); - }, - - // Execute a RPC requests - execute: function(method, args, options) { - var that = this; - options = _.defaults(options || {}, { - error: true - }); - - return rpc.execute("debug/"+method, _.extend(args || {}, { - 'id': this.id - })) - .then(function(data) { - return data; - }, - function(err) { - if (options.error) that.trigger("error", err); - return Q.reject(err); - }); - }, - - // Get locals - locals: function() { - return this.execute("locals"); - }, - - // Get breakpoints - breakpoints: function() { - var that = this; - - return this.execute("breakpoints") - .then(function(list) { - that._breakpoints = list; - return list; - }); - }, - - // Get backtrace - backtrace: function() { - return this.execute("backtrace") - .then(_.bind(function(trace) { - this.position = _.last(trace); - this.trigger("position", this.position); - - return trace; - }, this)); - }, - - // Get a breapoint id from its location - getBreakpoint: function(location) { - return _.find(this._breakpoints, function(point) { - return point.filename == location.path && point.line == location.line; - }); - }, - - // Add a breakpoint - breakpointAdd: function(args) { - var that = this; - return this.execute("breakpoint/add", args) - .then(function(point) { - that.trigger("update:breakpoints:add"); - return point; - }); - }, - - // Remove a breakpoint - breakpointRemove: function(num) { - var that = this; - - return this.execute("breakpoint/clear", { - 'num': num - }) - .then(function(point) { - that.trigger("update:breakpoints:clear"); - return point; - }); - }, - - // Start - start: function(arg) { - var that = this; - return this.execute("start", { - 'arg': arg - }) - .then(function(output) { - that.trigger("log", output); - that.trigger("update:start"); - }); - }, - - // Stop - stop: function() { - var that = this; - return this.execute("stop") - .then(function(output) { - that.trigger("log", output); - that.trigger("update:stop"); - }); - }, - - // Next - next: function() { - var that = this; - return this.execute("next") - .then(function(output) { - that.trigger("log", output); - that.trigger("update:next"); - }); - }, - - // Continue - cont: function() { - var that = this; - return this.execute("cont") - .then(function(output) { - that.trigger("log", output); - that.trigger("update:cont"); - }); - }, - - // Restart - restart: function() { - var that = this; - return this.execute("restart") - .then(function(output) { - that.trigger("log", output); - that.trigger("update:restart"); - }); - }, - - // Eval code - eval: function(code) { - var that = this; - - var handle = function(type, data) { - that.trigger("update:eval:"+type); - return { - 'type': type, - 'content': data.message || data - }; - }; - - return this.execute("eval", { - 'code': code - }, { - 'error': false - }) - .then( - _.partial(handle, "log"), - _.partial(handle, "error") - ); - }, - }); - - return DebuggerSession; -}); \ No newline at end of file diff --git a/client/core/files.js b/client/core/files.js deleted file mode 100644 index 510016b4..00000000 --- a/client/core/files.js +++ /dev/null @@ -1,255 +0,0 @@ -define([ - 'hr/promise', - 'hr/utils', - 'hr/hr', - 'models/file', - 'collections/files', - 'core/user', - 'core/box', - 'core/tabs', - 'core/settings', - 'utils/dialogs', - 'views/tabs/file', - 'views/files/base', - 'views/files/tab' -], function(Q, _, hr, File, Files, user, box, tabs, settings, dialogs, FileTab) { - var logging = hr.Logger.addNamespace("files"); - - // Settings for files manager - var settings = settings.add({ - 'namespace': "files", - 'title': "Files", - 'fields': {} - }); - var userSettings = user.settings("files"); - - // Recent files - var recentFiles = new Files(); - recentFiles.on("add", function() { - // Limit collection size - if (recentFiles.size() > 20) recentFiles.shift(); - }); - - // Active files - var activeFiles = new Files(); - - // Files handlers map - var handlers = {}; - - // Restorer for tabs - tabs.addRestorer("file", function(tabInfos) { - var parts = tabInfos.id.split(":"); - var handlerId = parts[0]; - var path = parts.slice(1).join(":"); - - var newFile = path.indexOf("temporary") == 0; - if (!newFile) { - return openFile(path.replace("file://", "")) - .then(function() { - return tabs.getById(tabInfos.id); - }); - } - - return null; - }); - - // Add handler - var addHandler = function(handlerId, handler) { - if (!handler - || !handlerId - || !handler.name - || !handler.valid - || (!handler.View && !handler.open)) { - throw "Invalid files handler format"; - } - - handler = _.defaults(handler, { - // Mark this file as active when open with - 'setActive': false, - - // Fallback when no correct handler - 'fallback': false, - - // Priority of this handler - 'position': 10 - }); - - handler.id = handlerId; - - if (handler.View) { - handler.open = function(file, fileOptions) { - var path = file.path(); - var uniqueId = handler.id+":"+file.syncEnvId(); - - // Add files as open - if (handler.setActive) activeFiles.add(file); - - // Add new tab - var tab = tabs.add(FileTab, { - "model": file, - "handler": handler, - 'fileOptions': fileOptions - }, { - "uniqueId": uniqueId, - "type": "file", - }); - - // Focus tab -> set active file - tab.on("tab:state", function(state) { - if (state) box.setActiveFile(file); - }); - - // Close tab -> close active file - tab.on("tab:close", function(state) { - if (handler.setActive) activeFiles.remove(file); - }); - - tab.setFileOptions(fileOptions); - }; - } - - // Add settings - settings.setField(handlerId, { - 'label': handler.name, - 'type': "checkbox", - 'default': true - }); - - // Register handler - handlers[handlerId] = handler; - - return handlers[handlerId]; - }; - - // Get handler for a file - var getHandlers = function(file) { - return _.chain(handlers) - .filter(function(handler) { - return userSettings.get(handler.id, true) && handler.valid(file); - }) - .sortBy(function(handler) { - return handler.position || 10; - }) - .value(); - }; - - // get fallback handlers for a file - var getFallbacks = function(file) { - return _.filter(handlers, function(handler) { - return userSettings.get(handler.id, true) && handler.fallback == true; - }); - }; - - // Open file with handler - var openFileHandler = function(handler, file, fileOptions) { - // Add to recent files - if (!file.isNewfile()) recentFiles.add(file); - - // Options for the file handler - fileOptions = _.defaults(fileOptions || {}, { - line: null, - pattern: null - }); - - return Q(handler.open(file, fileOptions)).then(function() { - box.setActiveFile(file); - }); - }; - - // Select to open a file with any handler - var openFileWith = function(file, fileOptions) { - var choices = {}; - _.each(handlers, function(handler) { - choices[handler.id] = handler.name; - }); - - if (_.size(choices) == 0) { - return Q.reject(new Error("No handlers for this file")); - } - - return dialogs.select("Can't open this file", "Sorry, No handler has been found to open this file. Try to find and install an add-on to manage this file or select one of the following handlers:", choices).then(function(value) { - var handler = handlers[value]; - return Q(openFileHandler(handler, file, fileOptions)); - }); - }; - - // Open a file - var openFile = function(file, options) { - options = _.defaults({}, options || {}, { - 'userChoice': null, - 'useFallback': true, - 'line': null - }); - - // Options for the file handler - var fileOptions = _.pick(options, ["line", "pattern"]); - - if (_.isString(file)) { - var nfile = new File({ - 'codebox': box - }); - return nfile.getByPath(file).then(function() { - return openFile(nfile, options); - }); - } - - var possibleHandlers = getHandlers(file); - - // Get fallbacks - if (_.size(possibleHandlers) == 0 && options.useFallback) { - possibleHandlers = getFallbacks(); - } - - // All choices - if (_.size(possibleHandlers) == 0) { - return openFileWith(file, fileOptions); - } - - if (_.size(possibleHandlers) == 1 || (options.userChoice != true)) { - return Q(openFileHandler(_.first(possibleHandlers), file, fileOptions)); - } - - var choices = {}; - _.each(possibleHandlers, function(handler) { - choices[handler.id] = handler.name; - }) - - if (_.size(choices) == 0) { - return Q.reject(new Error("No handlers for this file")); - } - - return dialogs.select("Open with...", "Select one of the following handlers to open this file:", choices).then(function(value) { - var handler = handlers[value]; - return Q(openFileHandler(handler, file, fileOptions)); - }); - }; - - // Open a new file - var openNew = function(name, content, options) { - name = name || "untitled"; - - // Create a temporary file - var f = new File({ - 'newFileContent': content || "", - 'codebox': box - }, { - 'name': name, - 'size': 0, - 'mtime': 0, - 'mime': "text/plain", - 'href': location.protocol+"//"+location.host+"/vfs/"+name, - 'exists': false - }); - - return openFile(f, options); - }; - - return { - 'addHandler': addHandler, - 'getHandlers': getHandlers, - 'open': openFile, - 'openNew': openNew, - 'recent': recentFiles, - 'active': activeFiles - }; -}); \ No newline at end of file diff --git a/client/core/globals.js b/client/core/globals.js deleted file mode 100644 index 2912459c..00000000 --- a/client/core/globals.js +++ /dev/null @@ -1,7 +0,0 @@ -define(['require'], function (require) { - window.codebox = { - 'require': require - }; - - return window.codebox; -}); \ No newline at end of file diff --git a/client/core/localfs.js b/client/core/localfs.js deleted file mode 100644 index 00210a5a..00000000 --- a/client/core/localfs.js +++ /dev/null @@ -1,519 +0,0 @@ -define([ - 'hr/utils', - 'hr/hr', - 'utils/url', - 'vendors/filer', - 'core/operations', - 'utils/alerts', - 'collections/changes' -], function(_, hr, Url, Filer, operations, alerts, Changes) { - var logger = hr.Logger.addNamespace("localfs"); - - // Base folder for localfs - var base = "/"; - var _isInit = false; - var _syncIsEnable = false; - var _ignoredFiles = []; - var changes = new Changes(); - - // Constant mime type for a directory - var MIME_DIRECTORY = "inode/directory"; - - // Duration for sync (ms) - syncDuration = 1*60*1000; - - - // Create fs interface - var filer = new Filer(); - - var fsCall = function(method, args, context) { - if (!_syncIsEnable) return Q.reject(new Error("Offline synchronization is disabled")); - if (_.isUndefined(args)) args = []; - if (!_.isArray(args)) args = [args]; - - var d = Q.defer(); - args.push(function() { - if (arguments.length == 1) return d.resolve(arguments[0]); - d.resolve(arguments); - }); - args.push(function(err) { - logger.error("Error occurs: ", method.name, err); - d.reject(err); - }) - - try { - method.apply(context, args); - } catch(err) { - d.reject(err); - } - - return d.promise; - }; - - /* - * Init the localfs - */ - var initFs = function(baseDir) { - base = "/"+baseDir; - logger.log("base is", base); - return Q(); - }; - - /* - * Enable/Disable sync - */ - var enableSync = function(state) { - _syncIsEnable = state != undefined? state : true; - }; - - /* - * Set ignored files list - */ - var setIgnoredFiles = function(files) { - _ignoredFiles = files || []; - _ignoredFiles.push("/.git") - _ignoredFiles = _.compact(_ignoredFiles); - _ignoredFiles = _.uniq(_ignoredFiles); - _ignoredFiles = _.map(_ignoredFiles, function(p) { - if (p[0] != "/") p = "/"+p; - return p; - }); - }; - - var prepareFs = function() { - if (_isInit) return Q(); - return fsCall(filer.init, { - persistent: true, - size: 10 * 1024 * 1024 - }, filer) - .then(function() { - logger.log("fs is ready"); - _isInit = true; - return Q(); - }); - }; - - var needFsReady = function(fn) { - return function() { - var args = arguments; - return prepareFs().then(function() { - return fn.apply(fn, args); - }); - }; - } - - /* - * Adapt path - */ - var adaptPath = function(path) { - path = base+path; - path = path.replace("//", "/"); - return path; - } - - /* - * Convert a vfs url in a path - */ - var urlToPath = function(url) { - var basePath = window.location.pathname; - basePath = basePath.substring(0, basePath.lastIndexOf("/")+1) + "vfs/"; - var path = url.substr(basePath.length-1); - if (path.length == 0) path = '/'; - if (path[0] != '/') path = "/" + path; - return path; - }; - - /* - * Test if path is ignored files - */ - var isIgnoredFile = function(path) { - return _.reduce(_ignoredFiles, function(state, ignoredPath) { - if (state) return state; - if (path.indexOf(ignoredPath) == 0) return true; - }, false); - }; - - /* - * Return informations about a fileentry - */ - var getEntryInfos = needFsReady(function(fEntry) { - return fsCall(fEntry.getMetadata, [], fEntry).then(function(metadata) { - var path = fEntry.fullPath.replace(base, "/").replace("//", "/"); - var url = location.protocol+"//"+location.host+"/vfs"+path; - - if (fEntry.isDirectory) url = url + "/"; - - return { - "name": fEntry.name, - "size": metadata.size, - "mtime": metadata.modificationTime.getTime(), - "mime": fEntry.isDirectory ? MIME_DIRECTORY : "application/octet-stream", - "href": url, - "exportUrl": fEntry.toURL(), - "offline": true, - '_fullPath': path - }; - }) - }); - - /* - * List a directory - */ - var listDir = needFsReady(function(path, adapt) { - path = (adapt == false) ? path : adaptPath(path); - - logger.log("ls:", path); - return fsCall(filer.ls, path, filer).then(function(entries) { - return Q.all(_.map(entries, function(entry) { - return getEntryInfos(entry); - })) - }).then(function(entries) { - return entries; - }, function(err) { - logger.error("ls:", err); - }); - }); - - /* - * Create a file - */ - var createFile = needFsReady(function(path) { - path = adaptPath(path); - logger.log("create:", path); - return fsCall(filer.create, [path, true], filer); - }); - - /* - * Write file - */ - var writeFile = needFsReady(function(path, data) { - path = adaptPath(path); - logger.log("write:", path); - return fsCall(filer.write, [path, { - 'data': data || "" - }], filer); - }); - - /* - * Open a file - */ - var openFile = needFsReady(function(path) { - path = adaptPath(path); - logger.log("open:", path); - return fsCall(filer.getEntry, [path], filer).then(function(fEntry) { - return getEntryInfos(fEntry); - }) - }); - - /* - * Read a file - */ - var readFile = needFsReady(function(path) { - path = adaptPath(path); - logger.log("read:", path); - return fsCall(filer.open, [path], filer).then(function(file) { - var d = Q.defer(); - - var reader = new FileReader(); - reader.onerror = function(err) { - d.reject(err); - }; - reader.onload = function(e) { - d.resolve(reader.result); - }; - reader.readAsText(file); - - return d.promise; - }); - }); - - /* - * Create a file - */ - var createDirectory = needFsReady(function(path) { - path = adaptPath(path); - logger.log("mkdir:", path); - return fsCall(filer.mkdir, [path, false], filer); - }); - - /* - * Move a file - */ - var move = needFsReady(function(from, to) { - from = adaptPath(from); - to = adaptPath(to); - - logger.log("move:", from, "to", to); - return fsCall(filer.mv, [from, '.', to], filer); - }); - - /* - * Copy a file - */ - var copy = needFsReady(function(from, to) { - from = adaptPath(from); - to = adaptPath(to); - - logger.log("copy:", from, "to", to); - return fsCall(filer.cp, [from, '.', to], filer); - }); - - /* - * Remove a file or directory - */ - var remove = needFsReady(function(path, adapt) { - path = (adapt == false) ? path : adaptPath(path); - - logger.log("remove:", path); - return fsCall(filer.rm, [path], filer); - }); - - /* - * Return changes - */ - var getChanges = needFsReady(function() { - var File = require("models/file"); - var box = require("core/box"); - changes.reset([]); - - if (!_syncIsEnable) return Q(changes); - - var addChange = function(path, type, args) { - if (isIgnoredFile(path)) { - return; - } - logger.log("change:",type,path); - changes.add(_.extend(args || {}, { - 'path': path, - 'time': Date.now(), - 'type': type || "M" - })); - } - - var getDirChanges = function(path) { - var localEntries, boxEntries, currentEntryInfos, fp; - if (isIgnoredFile(path)) { - return Q(); - } - - logger.log("get changes in:", path); - - // File in the workspace - fp = new File(); - - return openFile(path).then(function(infos) { - return listDir(path); - }).then(function(entries) { - // Entry in the browser - localEntries = entries; - - // Get file on the workspace - return fp.getByPath(path).fail(function() { - return Q(); - }); - }).then(function() { - if (fp.isDirectory()) { - return fp.listdir(); - } - return Q([]); - }).then(function(entries) { - // Entries on the boxes - boxEntries = entries; - }).then(function() { - // Eliminate old useless entries - return Q.all(_.map(boxEntries, function(boxFile) { - if (isIgnoredFile(boxFile.path())) return Q(); - - var localEntry = _.find(localEntries, function(localEntry) { - return localEntry.name == boxFile.get("name"); - }); - - // File don't exists and box file older than current directory - if (!localEntry && boxFile.get("mtime") < currentEntryInfos.mtime) { - // -> Remove the file on the box - addChange(boxFile.path(), "remove"); - } - - // Do nothing - return Q(); - })); - }).then(function() { - // Update entries and create new entries - return Q.all(_.map(localEntries, function(localEntry) { - var entryIsDir = localEntry.mime == MIME_DIRECTORY; - var boxFile = _.find(boxEntries, function(boxFile) { - return localEntry.name == boxFile.get("name"); - }); - - if (!boxFile) { - // Create file - if (!entryIsDir) { - addChange(localEntry._fullPath, "create"); - } else { - addChange(localEntry._fullPath, "mkdir"); - } - } else if (!entryIsDir && boxFile.get("mtime") < localEntry.mtime) { - // Check modification - return readFile(localEntry._fullPath).then(function(content) { - return boxFile.read().then(function(vfsContent) { - if (vfsContent == content) { - // Same content - return Q(); - } - addChange(localEntry._fullPath, "write", { - 'content': content - }); - }) - }); - } - - if (entryIsDir) { - return getDirChanges(localEntry._fullPath); - } - - // Do nothing - return Q(); - })); - }).fail(function(err) { - logger.error("Error during sync: ", err); - }); - }; - - return operations.start("files.sync.changes", function(op) { - return getDirChanges("/").then(function() { - return Q(changes); - }); - }, { - title: "Calculating Offline Changes" - }); - }); - - /* - * Sync a file in the box fs with the local fs - * - * this will download the files and saved them in the localfs - */ - var syncFileBoxToLocal = needFsReady(function() { - var box = require("core/box"); - - var doSync = function(fp) { - var path = fp.path(); - if (isIgnoredFile(path)) return Q(); - - logger.log("sync:box->local:", path); - - if (fp.isDirectory()) { - // Create the directory - return createDirectory(path).then(function() { - // List subfiles - return fp.listdir(); - }).then(function(files) { - // Recursively sync files and directory - return Q.all(_.map(files, function(f) { - return doSync(f); - })); - }); - } else { - // Read file content - return fp.read().then(function(content) { - // Write file content - return writeFile(path, content); - }); - } - }; - return operations.start("files.sync.download", function(op) { - logger.warn("Start sync: box->local"); - - return listDir("/", false).then(function(rootFiles) { - return Q.all(_.map(rootFiles, function(fp) { - return remove("/"+fp.name, false); - })); - }).then(function() { - return doSync(box.root); - }, function() { - return doSync(box.root) - }).then(function() { - changes.reset([]); - logger.warn("Finished sync: box->local"); - }); - }, { - title: "Updating Offline Cache" - }); - }); - - /* - * Global sync: - * -> if never sync: download everything - * -> if already sync: upload changes and download last changes - */ - var sync = needFsReady(function(options) { - options = _.defaults({}, options || {}, { - - }); - - var previousChanges = changes.size(); - - if (hr.Offline.isConnected()) { - var endT, startT = Date.now(); - return openFile("/").then(function(infos) { - return getChanges(); - }, function() { - return createDirectory("/"); - }).then(function() { - if (changes.size() > 0) { - if (changes.size() == previousChanges) return Q.reject(new Error("Offline changes not synced")); - alerts.show(changes.size()+" changes made offline need to be synced manually", 5000); - return Q.reject(new Error("Offline changes not synced")); - } - return syncFileBoxToLocal(); - }).then(function() { - //Calcul duration - endT = Date.now(); - syncDuration = _.max([endT - startT, 5000]); - updateAutoSync(); - return syncDuration; - }, function(err) { - logger.error("Sync error:", err); - }); - } else { - return Q.reject(new Error("Can't synchronize when offline")); - } - }); - - /* - * Auto sync allow to resync the localfs every interval - */ - var autoSync = null; - var updateAutoSync = function() { - syncDuration = _.max([syncDuration, 5*60*1000]); - logger.log("sync took ", syncDuration/1000,"seconds"); - autoSync = _.throttle(function() { - sync(); - }, 2*syncDuration); - }; - updateAutoSync(); - - return { - 'changes': changes, - 'urlToPath': urlToPath, - 'init': initFs, - 'ls': listDir, - 'create': createFile, - 'mkdir': createDirectory, - 'write': writeFile, - 'read': readFile, - 'mv': move, - 'cp': copy, - 'rm': remove, - 'reset': syncFileBoxToLocal, - 'sync': sync, - 'autoSync': function() { - return autoSync(); - }, - 'enableSync': enableSync, - 'isSyncEnabled': function() { return _syncIsEnable; }, - 'filer': filer, - 'syncDuration': syncDuration, - 'setIgnoredFiles': setIgnoredFiles - }; -}); \ No newline at end of file diff --git a/client/core/operations.js b/client/core/operations.js deleted file mode 100644 index 93892c0d..00000000 --- a/client/core/operations.js +++ /dev/null @@ -1,6 +0,0 @@ -define([ - 'views/operations/manager' -], function (Operations) { - var operations = new Operations(); - return operations; -}); \ No newline at end of file diff --git a/client/core/panels.js b/client/core/panels.js deleted file mode 100644 index b3aa8e03..00000000 --- a/client/core/panels.js +++ /dev/null @@ -1,6 +0,0 @@ -define([ - 'views/panels/manager' -], function (PanelsView) { - var panels = new PanelsView(); - return panels; -}); \ No newline at end of file diff --git a/client/core/search.js b/client/core/search.js deleted file mode 100644 index fb666991..00000000 --- a/client/core/search.js +++ /dev/null @@ -1,121 +0,0 @@ -define([ - 'hr/hr', - 'hr/dom', - 'hr/utils', - 'hr/promise', - 'models/command', - 'core/user', - 'core/settings' -],function(hr, $, _, Q, Command, user, settings) { - var logging = hr.Logger.addNamespace("search"); - - var Search = hr.Class.extend({ - defaults: {}, - - // Constructor - initialize: function(){ - Search.__super__.initialize.apply(this, arguments); - - // Search handlers - this.handlers = {}; - - // Settings - this.settings = settings.add({ - 'namespace': "search", - 'title': "Search", - 'fields': {} - }); - - return this; - }, - - /* - * Add a search handler - * @name: name for the search handler - * @getter: method which returns a promise with results - */ - handler: function(infos, getter) { - if (!infos.id || !infos.title) { - throw new Error("Need 'id' and 'title' to define a search handler"); - } - - // Define handler - this.handlers[infos.id] = _.defaults({ - 'getter': getter - }, infos, {}); - - // Define settings - this.settings.setField(infos.id, { - 'label': infos.title, - 'type': "checkbox", - 'default': true - }); - - logging.log("add search handler", infos.id); - - return this; - }, - - /* - * Normalize result - */ - normResult: function(handler, result) { - if (result instanceof Command) { - return result; - } else { - return new Command({}, _.defaults(result, { - 'category': handler.title - })); - } - }, - - /* - * Search by query - */ - query: function(query) { - var that = this; - var errors = []; - var d = Q.defer(); - var n = _.size(this.handlers), i = 0; - - _.each(this.handlers, function(handler, name) { - var done = function(results) { - i = i + 1; - if (results) { - d.notify({ - 'category': { - 'title': handler.title - }, - 'results': _.chain(results) - .map(_.partial(that.normResult, handler)) - .value(), - 'query': query - }); - } - if (i == n) { - if (errors.length == 0) { - d.resolve(n); - } else { - d.reject(errors); - } - } - }; - - if (!user.get("settings.search."+name, true)) return done(); - - Q() - .then(function() { - return handler.getter(query); - }) - .then(done, function(err) { - errors.push(err); - return done(); - }); - }); - - return d.promise; - } - }); - - return (new Search()); -}); \ No newline at end of file diff --git a/client/core/search/addons.js b/client/core/search/addons.js deleted file mode 100644 index d6f9c036..00000000 --- a/client/core/search/addons.js +++ /dev/null @@ -1,111 +0,0 @@ -define([ - 'hr/promise', - 'hr/utils', - 'hr/hr', - 'models/command', - 'collections/addons', - 'core/box', - 'core/addons', - 'core/search', - 'core/settings', - 'utils/string' -], function(Q, _, hr, Command, Addons, box, addons, search, settings, string) { - - var addonsSettings = settings.add({ - 'namespace': "manager", - 'title': "Addons", - 'defaults': { - 'registry': "https://api.codebox.io" - }, - 'fields': { - 'registry': { - 'label': "Registry", - 'type': "text" - } - } - }); - - // Filter a collection fo addons by a query to search for - var filterAddonsByQuery = function(_addons, query) { - return _addons.filter(function(addon) { - var text = [ - addon.get("name"), - addon.get("description") - ].join(" "); - return (string.score("Add-ons", query) > 0 - || string.score(text, query) > 0); - }); - }; - - // Transform an addon to a basic command - var addonToCommand = function(preText, addon, callback) { - return { - 'category': "Add-ons", - 'title': preText+" "+addon.get("name"), - 'label': addon.get("version")+ " - "+addon.get("author.name"), - 'icons': { - 'search': "puzzle-piece" - }, - 'offline': false, - 'action': callback - }; - }; - - // Transform an addon to an install command - var addonToInstallCommand = function(addon) { - var preText = "Install"; - if (addons.isInstalled(addon)) { - if (!addons.isUpdated(addon)) { - preText = "Update"; - } else { - return null; - } - } - return addonToCommand(preText, addon, function() { - return Command.run("addons.install", addon.get("git")); - }); - }; - - // Transform an addon to an uninstall command - var addonToUninstallCommand = function(addon) { - if (addons.isDefault(addon)) return null; - return addonToCommand("Uninstall", addon, function() { - return Command.run("addons.uninstall", addon.get("name")); - }); - }; - - // Search for add-ons to uninstall - search.handler({ - 'id': "addons:uninstall", - 'title': "Uninstall Add-ons" - }, function(query) { - if (!query) return []; - - return _.chain( - filterAddonsByQuery(addons, query) - ) - .map(addonToUninstallCommand) - .compact() - .value(); - }); - - // Search for add-ons to install/update - search.handler({ - 'id': "addons:install", - 'title': "Install Add-ons" - }, function(query) { - if (!query) return []; - - var addonsIndex = new Addons(); - - return addonsIndex.loadFromIndex(addonsSettings.user.get("registry")) - .then(function() { - return _.chain( - filterAddonsByQuery(addonsIndex, query) - ) - .map(addonToInstallCommand) - .compact() - .value(); - }); - }); -}); \ No newline at end of file diff --git a/client/core/search/code.js b/client/core/search/code.js deleted file mode 100644 index 8ca5a855..00000000 --- a/client/core/search/code.js +++ /dev/null @@ -1,155 +0,0 @@ -define([ - 'hr/promise', - 'hr/utils', - 'hr/hr', - 'models/command', - 'core/commands/menu', - 'core/backends/rpc', - 'core/search', - 'core/files', - 'utils/dialogs' -], function(Q, _, hr, Command, menu, rpc, search, files, dialogs) { - var logging = hr.Logger.addNamespace("codeSearch"); - var OPTIONS = [ - 'query', 'path', 'casesensitive', 'replacement', 'pattern', 'maxresults', - 'wholeword', 'regexp', 'replaceAll' - ]; - - - // Normalize results as a buffer - var normResults = function(results) { - // Header - var buffer = 'Searching 1 file for "'+results.options.query+'"'; - if (results.options.casesensitive) buffer += " (case sensitive)" - buffer += '\n\n'; - - _.each(results.files, function(lines, path) { - buffer += path+"\n"; - _.each(lines, function(line) { - buffer += line.line+" "+line.content+"\n"; - }); - buffer += '\n\n'; - }); - - // Footer - buffer += results.matches+" matches across "+_.size(results.files)+" files"; - - return buffer; - }; - - // Do a basic search - var searchCode = function(options) { - options = _.extend({}, options || {}); - return rpc.execute("search/code", _.pick(options, OPTIONS)); - }; - - - - var searchCommandHandler = function(title, fields, forceOptions) { - return function(args) { - if (_.isString(args)) args = {'query': args}; - args = _.defaults(args || {}, {}); - - var doSearch = function(_args) { - return searchCode(_.extend(_args, forceOptions || {})) - .then(function(results) { - return normResults(results); - }, function(err) { - logging.error("error", err); - return "Error during search: "+(err.message || err); - }) - .then(function(buffer) { - return files.openNew("Find Results", buffer); - }); - }; - - if (!args.query) { - return dialogs.fields(title, fields, args) - .then(doSearch); - } - - return doSearch(args); - } - }; - - - // Command search code - var commandSearch = Command.register("code.search", { - title: "Find in Files", - category: "Find", - shortcuts: [ - "mod+shift+f" - ], - action: searchCommandHandler("Find in Files", { - 'query': { - 'label': "Find", - 'type': "text" - }, - 'path': { - 'label': "Where", - 'type': "text" - }, - 'regexp': { - 'label': "Regular expression", - 'type': "checkbox" - }, - 'casesensitive': { - 'label': "Case sensitive", - 'type': "checkbox" - }, - 'wholeword': { - 'label': "Whole word", - 'type': "checkbox" - } - }) - }); - - // Command replace code - var commandReplace = Command.register("code.replace", { - title: "Replace in Files", - category: "Find", - shortcuts: [], - action: searchCommandHandler("Find and Replace in Files", { - 'query': { - 'label': "Find", - 'type': "text" - }, - 'path': { - 'label': "Where", - 'type': "text" - }, - 'replacement': { - 'label': "Replace", - 'type': "text" - }, - 'regexp': { - 'label': "Regular expression", - 'type': "checkbox" - }, - 'casesensitive': { - 'label': "Case Sensitive", - 'type': "checkbox" - }, - 'wholeword': { - 'label': "Whole word", - 'type': "checkbox" - } - }, { - replaceAll: true - }) - }) - - - // Create find menu - menu.register("find", { - title: "Find", - position: 5 - }).menuSection([ - commandSearch, - commandReplace - ]); - - return { - search: searchCode - }; -}); \ No newline at end of file diff --git a/client/core/search/commands.js b/client/core/search/commands.js deleted file mode 100644 index fc38bff3..00000000 --- a/client/core/search/commands.js +++ /dev/null @@ -1,29 +0,0 @@ -define([ - 'hr/promise', - 'hr/utils', - 'hr/hr', - 'models/command', - 'core/search' -], function(Q, _, hr, Command, search) { - // Search for commands - search.handler({ - 'id': "commands", - 'title': "Command" - }, function(query) { - return Command.all.filter(function(command) { - return ( - // Only action - command.get("type") == "action" - - // Accept to be visible in search bar - && command.get("search") - - // Not disabled (offline, ...) - && !command.hasFlag("disabled") - - // Fit the current search - && (!query || command.textScore(query) > 0) - ); - }); - }); -}); \ No newline at end of file diff --git a/client/core/search/files.js b/client/core/search/files.js deleted file mode 100644 index d57fe684..00000000 --- a/client/core/search/files.js +++ /dev/null @@ -1,54 +0,0 @@ -define([ - 'hr/promise', - 'hr/utils', - 'hr/hr', - 'core/box', - 'core/search', - 'core/files' -], function(Q, _, hr, box, search, files) { - // Search for files - search.handler({ - 'id': "files", - 'title': "Files" - }, function(query) { - if (!query) return []; - - return box.searchFiles(query) - .then(function(data) { - return Q(_.map(data.files, _.bind(function(path) { - var filename = _.last(path.split("/")); - if (filename.length == 0) filename = path; - - return { - "title": path, - "icons": { - "search": "file-o" - }, - "action": _.bind(function() { - files.open(path); - }, this) - }; - }, this))); - }); - }); - - // Search for recent opned files - search.handler({ - 'id': "recentfiles", - 'title': "Recent Files" - }, function(query) { - return files.recent.map(function(file) { - return { - "category": "Recent Files", - "title": file.path(), - "position": 0, - "icons": { - "search": "file-o" - }, - "action": _.bind(function() { - files.open(file); - }, this) - }; - }); - }); -}); \ No newline at end of file diff --git a/client/core/search/tags.js b/client/core/search/tags.js deleted file mode 100644 index a26f4bb0..00000000 --- a/client/core/search/tags.js +++ /dev/null @@ -1,40 +0,0 @@ -define([ - 'hr/promise', - 'hr/utils', - 'hr/hr', - 'core/backends/rpc', - 'core/search', - 'core/files' -], function(Q, _, hr, rpc, search, files) { - var normalizeTag = function(tag) { - return { - "title": tag.name, - "label": tag.file, - "icons": { - "search": "code" - }, - "action": _.bind(function() { - files.open(tag.file, { - // Open content "/^ foo $/"" _> "foo" in editor - pattern: tag.pattern.slice(2, -2) - }); - }, this) - }; - }; - - // Search for files - search.handler({ - 'id': "tags", - 'title': "Tags" - }, function(query) { - if (!query) return []; - - return rpc.execute("codecomplete/get", { - 'query': query - }).then(function(data) { - return _.map(data.results, normalizeTag); - }, function() { - return Q([]); - }); - }); -}); \ No newline at end of file diff --git a/client/core/session.js b/client/core/session.js deleted file mode 100644 index 3d843db9..00000000 --- a/client/core/session.js +++ /dev/null @@ -1,66 +0,0 @@ -define([ - "hr/utils", - "hr/hr", - "core/user", - "core/box", - "core/addons", - "core/collaborators", - "core/backends/rpc", - "core/localfs" -], function(_, hr, user, box, addons, collaborators, rpc, localfs) { - // Extend template context - hr.Template.extendContext({ - 'session': { - 'user': user, - 'box': box, - 'addons': addons, - 'collaborators': collaborators - } - }); - - // Redefine check for connection status - hr.Offline.check = function() { - return rpc.execute("box/ping").then(function(data) { - hr.Offline.setState(data.ping == true); - if (!hr.Offline.isConnected()) { - return Q.reject(new Error("No connected")); - } - }, function() { - hr.Offline.setState(false); - }) - }; - - return { - // Prepare session - prepare: function() { - return hr.Offline.check().then(function() { - return box.status(); - }).then(function() { - return localfs.init(box.get("name")); - }); - }, - - // Start session - start: function(email, token) { - var that = this; - - return box.auth({ - 'email': email, - 'token': token - }, user).then(function() { - // Get installed addons - return addons.getInstalled(); - }).then(function() { - // Get collaborators - return collaborators.getCollaborators(); - }); - }, - - // Logout - exit: function() { - hr.Cookies.remove("email"); - hr.Cookies.remove("token"); - location.reload(); - } - }; -}); \ No newline at end of file diff --git a/client/core/settings.js b/client/core/settings.js deleted file mode 100644 index e92c973e..00000000 --- a/client/core/settings.js +++ /dev/null @@ -1,78 +0,0 @@ -define([ - 'hr/hr', - 'models/command', - 'core/user', - 'views/settings/base' -], function (hr, Command, user, SettingsPageView) { - - /* - * This module define a unify way - * to manage user settings. - */ - - var logging = hr.Logger.addNamespace("settings"); - - var settings = { - sections: {}, - - /* - * Define a new settings tab - * Tab: View for the tab - */ - add: function(Tab, options) { - var section, namespace; - if (!_.isFunction(Tab)) { - options = Tab; - Tab = SettingsPageView; - } - - var tab = new Tab(options); - - var namespace = tab.namespace || "main"; - - logging.log("add settings tab", namespace); - settings.sections[namespace] = tab; - - var defaults = options.defaults || {}; - var currentValues = user.get("settings."+namespace, {}); - currentValues = _.defaults(currentValues, defaults); - user.set("settings."+namespace, currentValues); - - return tab; - }, - - /* - * For all tabs - */ - each: function(callback, context) { - _.each(settings.sections, callback, context); - }, - - /* - * Save settings - */ - save: function() { - var data = {}; - this.each(function(tab) { - data[tab.namespace] = tab.submit(); - }); - return user.saveSettings(_.extend({}, user.get("settings"), data)); - }, - - /* - * Open a settings page - */ - open: function(page) { - Command.run("settings", page); - }, - - /* - * User settings - */ - user: function(namespace) { - return user.settings(namespace); - } - }; - - return settings; -}); \ No newline at end of file diff --git a/client/core/tabs.js b/client/core/tabs.js deleted file mode 100644 index 561e1ec6..00000000 --- a/client/core/tabs.js +++ /dev/null @@ -1,6 +0,0 @@ -define([ - 'views/tabs/manager' -], function (TabsView) { - var tabs = new TabsView(); - return tabs; -}); \ No newline at end of file diff --git a/client/core/themes.js b/client/core/themes.js deleted file mode 100644 index ff406837..00000000 --- a/client/core/themes.js +++ /dev/null @@ -1,161 +0,0 @@ -define([ - 'hr/hr', - 'hr/dom', - 'hr/utils', - 'utils/css', - 'core/settings', - 'core/user' -], function (hr, $, _, css, settings, user) { - var logger = hr.Logger.addNamespace("themes"); - - - // User settings - var userSettings = user.settings("themes"); - - // Map of themes - var currentTheme = null; - var themes = {}; - - // CSS dom - var $css = $("" ).appendTo($("body")); - }; - var resetCursor = _.partial(setCursor, null); - - var DropArea = hr.Class.extend({ - defaults: { - // View for this area - view: null, - - // Class when drop data - className: "dragover", - - // Draggable type - dragType: null, - - // Handler for drop - handler: null, - - // Contrain elastic - constrain: null - }, - - initialize: function() { - DropArea.__super__.initialize.apply(this, arguments); - var that = this; - - this.view = this.options.view; - this.$el = this.view.$el; - - this.dragType = this.options.dragType; - - this.$el.on(events["enter"], function(e) { - if (that.dragType.isDragging()) { - e.stopPropagation(); - that.dragType.enterDropArea(that); - that.$el.addClass("dragover"); - } - }); - - this.$el.on(events["leave"], function(e) { - that.$el.removeClass("dragover"); - that.dragType.exitDropArea(); - }); - - this.on("drop", function() { - that.$el.removeClass("dragover"); - }); - - if (this.options.handler) this.on("drop", this.options.handler); - } - }); - - var DraggableType = hr.Class.extend({ - initialize: function() { - DraggableType.__super__.initialize.apply(this, arguments); - - // Data transfered - this.data = null; - - // State - this.state = true; - - // Drop handler - this.drop = []; - }, - - // Toggle enable/disable drag and drop - toggle: function(st) { - this.state = st; - return this; - }, - - // Is currently dragging data - isDragging: function() { - return this.data != null; - }, - - // Get drop - getDrop: function() { - return (this.drop.length > 0)? this.drop[this.drop.length - 1] : null; - }, - - // Enter drop area - enterDropArea: function(area) { - //console.log("enter drop", this.drop.length, area.$el.get(0)); - this.drop.push(area); - }, - - // Exit drop area - exitDropArea: function() { - this.drop.pop(); - //console.log("exit drop", this.drop.length); - }, - - // Enable drag and drop in a object - enableDrag: function(options) { - var that = this, $document = $(document), $el, data; - - options = _.defaults(options || {}, { - // View to drag - view: null, - - // Element to drag - el: null, - - // Data to transfer - data: null, - - // Base drop area - baseDropArea: null, - - // Before dragging - start: null, - - // Cursor - cursor: "copy" - }); - if (options.el) $el = $(options.el); - if (options.view) $el = options.view.$el, data = options.view; - if (options.data) data = options.data; - - $el.on(events["start"], function(e) { - if (e.type == 'mousedown' && e.originalEvent.button != 0) return; - if (!that.state) return; - e.preventDefault(); - - var dx, dy, hasMove = false; - - // origin mouse - var oX = e.pageX; - var oY = e.pageY; - - // origin element - var poX = $el.offset().left; - var poY = $el.offset().top; - - // element new position - var ex, ey, ew, eh; - ew = $el.width(); - eh = $el.height(); - - // Contrain element - var cw, ch, cx, cy; - - that.drop = []; - if (options.baseDropArea) that.enterDropArea(options.baseDropArea); - that.data = data; - - if (options.start) options.start(); - - var f = function(e) { - var _drop = that.getDrop(); - - dx = oX - e.pageX; - dy = oY - e.pageY; - - if (Math.abs(dx) > 20 || Math.abs(dy) > 20) { - if (!hasMove) { - setCursor(options.cursor); - $el.addClass("move"); - } - hasMove = true; - } - - ex = poX - dx; - ey = poY - dy; - - if (_drop && _drop.options.constrain) { - cw = _drop.$el.width(); - ch = _drop.$el.height(); - cx = _drop.$el.offset().left; - cy = _drop.$el.offset().top; - - if (Math.abs(ey - cy) < 50) ey = cy; - if (Math.abs((ey + eh) - (cy+ch)) < 50) ey = cy + ch - eh; - if (Math.abs(ex - cx) < 50) ex = cx; - if (Math.abs((ex + ew) - (cx+cw)) < 50) ex = cx + cw - ew; - } - - $el.css({ - 'left': ex, - 'top': ey - }); - }; - - $document.on(events["move"], f); - $document.one(events["stop"], function(e) { - $document.unbind(events["move"], f); - resetCursor(); - - var _drop = that.getDrop(); - - if (hasMove && (!options.baseDropArea || !_drop || (options.baseDropArea.cid != _drop.cid))) { - if (_drop) { - _drop.trigger("drop", that.data); - } - that.trigger("drop", _drop, that.data); - } - - that.data = null; - that.drop = []; - - $el.removeClass("move"); - $el.css({ - 'left': "auto", - 'top': "auto" - }); - }); - }); - } - }); - - return { - events: events, - cursor: { - set: setCursor, - reset: resetCursor - }, - DropArea: DropArea, - DraggableType: DraggableType - }; -}); \ No newline at end of file diff --git a/client/utils/filesync.js b/client/utils/filesync.js deleted file mode 100644 index 72374447..00000000 --- a/client/utils/filesync.js +++ /dev/null @@ -1,876 +0,0 @@ -define([ - "hr/promise", - "hr/hr", - "vendors/diff_match_patch", - "utils/hash", - "core/user", - "core/collaborators", - "utils/dialogs" -], function(Q, hr, diff_match_patch, hash, user, collaborators, dialogs) { - var logging = hr.Logger.addNamespace("filesync"); - - // hash method for patch - var _hash = function(s) { - return hash.hex32(hash.crc32(s)); - }; - - var FileSync = hr.Class.extend({ - defaults: { - 'file': null, - 'colors': [ - "#1abc9c", - "#9b59b6", - "#e67e22", - "#16a085", - "#c0392b", - "#2980b9", - "#f39c12", - "#8e44ad" - ] - }, - modes: { - ASYNC: "async", - SYNC: "sync", - READONLY: "readonly" - }, - - // Constructor - initialize: function() { - FileSync.__super__.initialize.apply(this, arguments); - - // Diff/Patch calculoator - this.diff = new diff_match_patch(); - - // Current selections - this.selections = {}; - - // Current cursors - this.cursors = {}; - this.synced = false; - - // File model for this sync - this.file = null; - - // Environment id used for sync - this.envId = null; - this.envOptions = null; - - // Mode for edition - this.mode = this.modes.SYNC; - - // Ping has been received - this.ping = false; - - // List of participants - this.participants = []; - - // Synchronization state - this.syncState = false; - this.timeOfLastLocalChange = Date.now(); - - // Modified state - this.modified = false; - - // Add timer for ping - this.timer = setInterval(_.bind(this._intervalPing, this), 15*1000); - - // Patch queue - this.patchQueue = new hr.Queue({ - task: this.patchContent, - context: this - }); - - // Init file - if (this.options.file) { - this.setFile(this.options.file); - } - - // Offline sync - hr.Offline.on("state", function(state) { - if (hr.Offline.isConnected()) return; - if (this.envId) this.updateEnv(this.envId, _.extend({}, this.envOptions, { - reset: false - })); - }, this); - }, - - // Change mode - setMode: function(mode) { - this.mode = mode; - this.trigger("mode", mode); - }, - - /* - * Return current mode - */ - getMode: function() { - return this.mode; - }, - - // Update current user cursor - updateUserCursor: function(x, y) { - if (!this.isSync()) return this; - return this.sendCursor(x, y); - }, - - // Update current user selection - updateUserSelection: function(sx, sy, ex, ey) { - if (!this.isSync()) return this; - return this.sendSelection(sx, sy, ex, ey); - }, - - /* - * Update content of the document (for all collaborators) - * Call this method when you detec a change in the editor, ... - */ - updateContent: function(value) { - if (!value || this.isReadonly()) return; - - // Old content hash - this.hash_value_t0 = this.hash_value_t1; - - // New content hash - this.content_value_t1 = value; - this.hash_value_t1 = _hash(this.content_value_t1); - - // Create patch - var patch_list = this.diff.patch_make(this.content_value_t0, this.content_value_t1); - var patch_text = this.diff.patch_toText(patch_list); - - // Update value - this.content_value_t0 = this.content_value_t1; - - // Send patch - this.timeOfLastLocalChange = Date.now(); - this.sendPatch(patch_text, this.hash_value_t0, this.hash_value_t1); - - this.file.modifiedState(true); - }, - - - // Maintain connection with ping - _intervalPing: function(){ - if (!this.isSync()) return; - if (this.synced == false) { - this.sendSync(); - } else { - this.sendPing(); - this.setSyncState(this.ping == true); - this.ping = false; - } - }, - - /* - * Return true if syncronization is on - */ - isSync: function() { - return (this.envId != null && this.getMode() == this.modes.SYNC); - }, - - /* - * Return true if readonly - */ - isReadonly: function() { - return this.getMode() == this.modes.READONLY; - }, - - /* - * Return true if syncronization is established - */ - isSyncStable: function() { - return (this.isSync() && this.syncState); - }, - - /* - * Define file content - */ - setContent: function(content) { - var oldcontent, oldmode_sync = this.sync; - - // Stop sync and update content - this.sync = false; - - // Calcul patches - var patches = this.diff.patch_make(this.content_value_t0, content); - - // Calcul new hash - this.hash_value_t1 = _hash(content); - - oldcontent = this.content_value_t0; - this.content_value_t0 = content; - this.content_value_t1 = content; - - // Trigger event to signal we have new content - this.trigger("content", content, oldcontent, patches); - - // Return to previous sync mode - this.sync = oldmode_sync; - - return this; - }, - - /* - * Apply patch to content - */ - patchContent: function(patch_data) { - logging.log("receive patch ", patch_data); - - // Check patch - if (!patch_data - || !patch_data.patch - || !patch_data.hashs.before - || !patch_data.hashs.after) { - logging.error("Invalid patch data"); - return false; - } - - // Check old hash - if (this.hash_value_t1 == patch_data.hashs.after) { - // Same content - return false; - } - - // Apply on text - var patches = this.diff.patch_fromText(patch_data.patch); - var results = this.diff.patch_apply(patches, this.content_value_t0); - - // Test patch application (results[1] contains a list of boolean for patch results) - if (results.length < 2 - || _.compact(results[1]).length != results[1].length) { - logging.error("invalid application of ", patches, results); - this.sendSync(); - return false; - } - - var newtext = results[0]; - var newtext_hash = _hash(newtext); - - // Check new hash if last changes from this user is older than 2sec - if ((Date.now() - this.timeOfLastLocalChange) > 2000 - && newtext_hash != patch_data.hashs.after) { - logging.warn("invalid version -> resync"); - this.sendSync(); - return false; - } - - // Set editor content - this.setContent(newtext); - return true; - }, - - /* - * Convert patch to a list of operations - * Format for an operation: - * { - * type: "insert" or "remove", - * content: "operation content", - * index: (int) position for this operation in the file - * } - */ - patchesToOps: function(patches) { - return _.chain(patches) - .map(function(change, i) { - var diffIndex = change.start1; - - return _.map(change.diffs, function(diff, a) { - var content = diff[1]; - var diffType = diff[0]; - - diffType = diffType > 0 ? "insert" : - (diffType == 0 ? null : "remove"); - - var op = !diffType? null : { - 'type': diffType, - 'content': content, - 'index': diffIndex - }; - - if (!diffType) { - diffIndex = diffIndex + content.length; - } else { - diffIndex = diffIndex + content.length; - } - return op; - }); - }) - .flatten() - .compact() - .value(); - }, - - /* - * Update synchronization environement - */ - updateEnv: function(envId, options) { - var self = this; - - // Send close to previous session - this.send("close"); - - if (_.isObject(envId)) { - options = envId; - envId = this.envId; - } - - options = _.defaults({}, options || {}, { - sync: false, - reset: false - }); - - if (!envId) return this; - if (this.file.isNewfile() || !hr.Offline.isConnected()) options.sync = false; - options.reset = options.sync? false : options.reset; - - this.envOptions = options - this.envId = envId; - - logging.log("update env with", this.envId, options, hr.Offline.isConnected()); - - this.content_value_t0 = this.content_value_t0 || ""; - this.content_value_t1 = this.content_value_t1 || ""; - - if (options.reset) { - this.hash_value_t0 = null; - this.hash_value_t1 = null; - this.content_value_t0 = ""; - this.content_value_t1 = ""; - } - - // Signal update - this.trigger("update:env", options); - - // Reset participants - this.setParticipants([]); - - // Start sync - if (!options.sync) { - if (options.reset) { - this.setMode(self.modes.READONLY); - - this.file.download().then(function(content) { - self.file.modifiedState(false); - - // Update content - self.setContent(content); - - // Enable sync - self.setMode(self.modes.ASYNC); - }, function(err) { - logging.error("Error for offline sync: ", err); - self.trigger("close"); - }); - } else { - this.setMode(self.modes.ASYNC); - this.setContent(this.content_value_t1 || ""); - } - } else { - /// Online sync - self.setMode(self.modes.SYNC); - - this.socket().then(function(socket) { - logging.log("creating socket"); - socket.on('connect', function() { - logging.log("socket connect"); - }); - socket.on('connect_failed', function() { - logging.warn("socket connect failed"); - }); - socket.on('disconnect', function() { - logging.log("socket disconnect"); - self.setSyncState(false); - }); - socket.on('connecting', function() { - logging.log("socket connecting ..."); - }); - socket.on('message', function(data) { - if (!self.isSync()) return; - - //logging.log("socket receive packet ", data); - self.ping = true; - - // Calid data - if (data.action == null || data.environment == null || self.envId != data.environment) { - return; - } - - // Changement file - if (data.path && (!self.file || data.path != self.file.path())) { - self.trigger("file:path", data.path); - } - - switch (data.action) { - case "cursor": - if (data.from != user.get("userId")) { - self.cursorMove(data.from, data.cursor.x, data.cursor.y); - } - break; - case "select": - if (data.from != user.get("userId")) { - self.selectionMove(data.from, data.start.x, data.start.y, data.end.x, data.end.y); - } - break; - case "participants": - if (data.participants != null) { - self.setParticipants(data.participants) - } - break; - case "sync": - if (data.content != null) { - self.setContent(data.content); - self.synced = true; - } - if (data.participants != null) { - self.setParticipants(data.participants) - } - if (data.state != null) { - self.file.modifiedState(data.state); - } - break; - case "patch": - self.patchQueue.defer(data); - break; - case "modified": - if (data.state != null) { - self.file.modifiedState(data.state); - } - break; - } - self.setSyncState(true); - }); - - if (self.file != null && !self.file.isNewfile()) { - self.sendLoad(self.file.path()); - } else { - self.sendSync(); - } - }); - } - }, - - /* - * Set file for the synschronization - */ - setFile: function(file, options) { - options = _.defaults({}, options || {}, { - sync: false, - reset: true, - autoload: true - }); - - if (!file.isValid()) { - logging.error("invalid file for sync ", file); - return; - } - - logging.log("init file with options ", options); - - this.file = file; - - if (this.file != null) { - this.file.on("set", _.partial(this.setFile, this.file, options), this); - this.file.on("modified", this.trigger.bind(this, "sync:modified")); - this.file.on("loading", this.trigger.bind(this, "sync:loading")); - - this.trigger("file:mode", this.file.mode()); - if (options.autoload) { - this.on("file:path", function(path) { - this.file.getByPath(path); - }, this); - } - - this.updateEnv(this.file.syncEnvId(), options); - } - }, - - /* - * Return a socket for this connexion - */ - socket: function() { - var that = this; - - var box = require("core/box"); - - if (this._socket) return Q(this._socket); - if (this.envId != null) { - return box.socket("filesync").then(function(s) { - that._socket = s; - return that._socket; - }) - } else { - throw new Error("need 'envId' to create sync socket"); - } - }, - - /* - * Close connexion with the server - */ - closeSocket: function() { - var that = this; - if (!this._socket) return; - this_socket = null; - }, - - /* - * Enable realtime syncronization - */ - setSyncState: function(st) { - this.syncState = st; - this.trigger("sync:state", this.syncState); - return this; - }, - - /* - * Move a cursor to a position by id - * @id : cursor id - * @x : position x of the cursor (column) - * @y : position y of the cursor (line) - */ - cursorMove: function(id, x, y) { - if (user.get("userId") == id) { - return this; - } - - this.cursors[id] = { - 'x': x, - 'y': y, - 'color': this.participantColor(id) - }; - this.trigger("cursor:move", id, this.cursors[id]); - return this; - }, - - /* - * Move a selection to a range by id - * @id : cursor id - * @sx : position start x of the selection (column) - * @sy : position start y of the selection (line) - * @ex : position end x of the selection (column) - * @ey : position end y of the selection (line) - */ - selectionMove: function(id, sx, sy, ex, ey) { - if (user.get("userId") == id) { - return this; - } - - this.selections[id] = { - 'color': this.participantColor(id), - 'start': { - 'x': sx, - 'y': sy - }, - 'end': { - 'x': ex, - 'y': ey - } - }; - this.trigger("selection:move", id, this.selections[id]); - return this; - }, - - /* - * Return a cursor position by text index - * @index : index of the cursor in the text - */ - cursorPosByindex: function(index, content) { - var x = 0; - var y = 0; - - content = content || this.content_value_t0; - - if (index < 0) - { - return [x,y]; - } - - for (var i = 0; i< content.length; i++){ - var c = content[i]; - if (index == i){ - break; - } - x = x +1; - if (c == "\n"){ - x = 0; - y = y +1; - } - } - return { - 'x': x, - 'y': y - }; - }, - - /* - * Return index by cursor position - * @cx : cursor position x (column) - * @cy : cursor position y (line) - */ - cursorIndexBypos: function(cx, cy, content){ - var x = 0; - var y = 0; - var index = 0; - - content = content || this.content_value_t0; - - for (var i = 0; i< content.length; i++){ - index = i; - var c = content[i]; - if (cx == x && cy == y){ - break; - } - x = x +1; - if (c == "\n"){ - x = 0; - y = y +1; - } - } - return index; - }, - - /* - * Apply patches to a cursor - * @cursor : cursor object {x:, y:} - * @operations: operations to paply - */ - cursorApplyOps: function(cursor, operations, content){ - var cursorIndex, diff; - - content = content || this.content_value_t0; - operations = operations || []; - - cursorIndex = this.cursorIndexBypos(cursor.x, cursor.y, content); - - for (var i in operations) { - var op = operations[i]; - - if (cursorIndex < op.index) { - // Before operations -> ignore - } else { - diff = (op.type == "insert") ? 1 : -1; - cursorIndex = cursorIndex + diff * op.content.length; - } - } - - return cursorIndex; - }, - - /* - * Set lists of participants - */ - setParticipants: function(participants) { - // Update participants list - this.participants = _.chain(participants) - .map(function(participant, i) { - participant.user = collaborators.getById(participant.userId); - if (!participant.user) { - logging.error("participant non user:", participant.userId); - return null; - } - - // Color for this participant - participant.color = this.options.colors[i % this.options.colors.length]; - - return participant; - }, this) - .compact() - .value(); - - this.participantIds = _.pluck(participants, "userId"); - logging.log("update participants", this.participantIds); - - // Signal participant update - this.trigger("participants"); - - // Clear old participants cursors - _.each(this.cursors, function(cursor, cId) { - if (_.contains(this.participantIds, cId)) return; - - this.trigger("cursor:remove", cId); - delete this.cursors[cId]; - }, this); - _.each(this.selections, function(cursor, cId) { - if (_.contains(this.participantIds, cId)) return; - - this.trigger("selection:remove", cId); - delete this.selections[cId]; - }, this); - - // Update all participants cursor/selection - _.each(this.participants, function(participant) { - this.cursorMove(participant.userId, participant.cursor.x, participant.cursor.y); - this.selectionMove(participant.userId, - participant.selection.start.x, participant.selection.start.y, - participant.selection.end.x, participant.selection.end.y); - }, this); - - return this; - }, - - /* - * Get participant color - */ - participantColor: function(pid) { - return _.reduce(this.participants, function(color, participant) { - if (participant.userId == pid) { - return participant.color; - } - return color; - }, "#ff0000"); - }, - - /* - * Send to server - * @action : action to send - * @data : data for this action - */ - send: function(action, data) { - if (!this.isSync()) return this; - - if (this.envId != null && action != null) { - data = _.extend({}, data || {}, { - 'action': action, - 'from': user.get("userId"), - 'token': user.get("token"), - 'environment': this.envId - }); - - //logging.log("send packet", data); - this.socket().then(function(socket) { - socket.json.send(data); - }) - } else { - this.setSyncState(false); - } - return this; - }, - - /* - * Send patch to the server - * @patch : patch to send - * @hash0 : hash before patch - * @hash1 : hash after patch - */ - sendPatch: function(patch, hash0, hash1) { - return this.send("patch", { - "patch": patch, - "hashs": { - "before": hash0, - "after": hash1 - } - }); - }, - - /* - * Send cursor positions to the server - * @cx : position x of the cursor - * @cy : position y of the cursor - */ - sendCursor: function(cx, cy) { - if (cx == null || cy == null) { - return; - } - return this.send("cursor", { - "cursor": { - "x": cx, - "y": cy - } - }); - }, - - /* - * Send selection to the server - * @sx : position start x of the selection (column) - * @sy : position start y of the selection (line) - * @ex : position end x of the selection (column) - * @ey : position end y of the selection (line) - */ - sendSelection: function(sx, sy, ex, ey) { - if (sx == null || sy == null || ex == null || ey == null) { - return; - } - return this.send("select", { - "start": { - "x": sx, - "y": sy - }, - "end": { - "x": ex, - "y": ey - } - }); - }, - - /* - * Send ping to the server - */ - sendPing: function() { - return this.send("ping"); - }, - - /* - * Send laod to the server to laod a file - */ - sendLoad: function(path) { - return this.send("load", { - 'path': path - }); - }, - - /* - * Send request to absolute sync to the server - */ - sendSync: function() { - this.send("sync"); - return true; - }, - - /* - * Save the file - */ - save: function() { - var that = this; - - // If online use the socket event "save" - var doSave = function(args) { - that.send("save", args); - return Q(); - }; - - // If aync mode - if (this.getMode() == this.modes.ASYNC) { - doSave = function(args) { - return that.file.write(that.content_value_t1, args.path) - .then(function(newPath) { - that.file.modifiedState(false); - if (newPath != that.file.path()) { - that.trigger("file:path", newPath); - } - }, function(err) { - that.trigger("error", err); - }); - }; - } - - if (this.file.isNewfile()) { - return dialogs.prompt("Save as", "", this.file.filename()).then(function(name) { - return doSave({ - 'path': name - }) - }); - } else { - return doSave({}); - } - }, - - /* - * Close the connection - */ - close: function() { - clearInterval(this.timer); - this.file.modifiedState(false); - this.send("close"); - this.off(); - }, - }); - - return FileSync; -}); \ No newline at end of file diff --git a/client/utils/gravatar.js b/client/utils/gravatar.js deleted file mode 100644 index f08e7585..00000000 --- a/client/utils/gravatar.js +++ /dev/null @@ -1,19 +0,0 @@ -define([ - 'hr/hr', - 'hr/utils', - 'utils/hash' -], function (hr, _, hash) { - return { - get: function(email, options) { - options = _.defaults({}, options || {}, { - 'size': 64, - 'defaultImage': 'mm' - }); - - return "https://secure.gravatar.com/avatar/" - + hash.md5(email.toLowerCase().trim()) - + "?size=" + options.size - + "&default=" + encodeURIComponent(options.defaultImage); - } - }; -}); \ No newline at end of file diff --git a/client/utils/hash.js b/client/utils/hash.js deleted file mode 100644 index 0f982f72..00000000 --- a/client/utils/hash.js +++ /dev/null @@ -1,270 +0,0 @@ -define([ - 'vendors/crypto' -], function (CryptoJS) { - var crc32table = "00000000 77073096 EE0E612C 990951BA 076DC419 706AF48F E963A535 9E6495A3 0EDB8832 79DCB8A4 E0D5E91E 97D2D988 09B64C2B 7EB17CBD E7B82D07 90BF1D91 1DB71064 6AB020F2 F3B97148 84BE41DE 1ADAD47D 6DDDE4EB F4D4B551 83D385C7 136C9856 646BA8C0 FD62F97A 8A65C9EC 14015C4F 63066CD9 FA0F3D63 8D080DF5 3B6E20C8 4C69105E D56041E4 A2677172 3C03E4D1 4B04D447 D20D85FD A50AB56B 35B5A8FA 42B2986C DBBBC9D6 ACBCF940 32D86CE3 45DF5C75 DCD60DCF ABD13D59 26D930AC 51DE003A C8D75180 BFD06116 21B4F4B5 56B3C423 CFBA9599 B8BDA50F 2802B89E 5F058808 C60CD9B2 B10BE924 2F6F7C87 58684C11 C1611DAB B6662D3D 76DC4190 01DB7106 98D220BC EFD5102A 71B18589 06B6B51F 9FBFE4A5 E8B8D433 7807C9A2 0F00F934 9609A88E E10E9818 7F6A0DBB 086D3D2D 91646C97 E6635C01 6B6B51F4 1C6C6162 856530D8 F262004E 6C0695ED 1B01A57B 8208F4C1 F50FC457 65B0D9C6 12B7E950 8BBEB8EA FCB9887C 62DD1DDF 15DA2D49 8CD37CF3 FBD44C65 4DB26158 3AB551CE A3BC0074 D4BB30E2 4ADFA541 3DD895D7 A4D1C46D D3D6F4FB 4369E96A 346ED9FC AD678846 DA60B8D0 44042D73 33031DE5 AA0A4C5F DD0D7CC9 5005713C 270241AA BE0B1010 C90C2086 5768B525 206F85B3 B966D409 CE61E49F 5EDEF90E 29D9C998 B0D09822 C7D7A8B4 59B33D17 2EB40D81 B7BD5C3B C0BA6CAD EDB88320 9ABFB3B6 03B6E20C 74B1D29A EAD54739 9DD277AF 04DB2615 73DC1683 E3630B12 94643B84 0D6D6A3E 7A6A5AA8 E40ECF0B 9309FF9D 0A00AE27 7D079EB1 F00F9344 8708A3D2 1E01F268 6906C2FE F762575D 806567CB 196C3671 6E6B06E7 FED41B76 89D32BE0 10DA7A5A 67DD4ACC F9B9DF6F 8EBEEFF9 17B7BE43 60B08ED5 D6D6A3E8 A1D1937E 38D8C2C4 4FDFF252 D1BB67F1 A6BC5767 3FB506DD 48B2364B D80D2BDA AF0A1B4C 36034AF6 41047A60 DF60EFC3 A867DF55 316E8EEF 4669BE79 CB61B38C BC66831A 256FD2A0 5268E236 CC0C7795 BB0B4703 220216B9 5505262F C5BA3BBE B2BD0B28 2BB45A92 5CB36A04 C2D7FFA7 B5D0CF31 2CD99E8B 5BDEAE1D 9B64C2B0 EC63F226 756AA39C 026D930A 9C0906A9 EB0E363F 72076785 05005713 95BF4A82 E2B87A14 7BB12BAE 0CB61B38 92D28E9B E5D5BE0D 7CDCEFB7 0BDBDF21 86D3D2D4 F1D4E242 68DDB3F8 1FDA836E 81BE16CD F6B9265B 6FB077E1 18B74777 88085AE6 FF0F6A70 66063BCA 11010B5C 8F659EFF F862AE69 616BFFD3 166CCF45 A00AE278 D70DD2EE 4E048354 3903B3C2 A7672661 D06016F7 4969474D 3E6E77DB AED16A4A D9D65ADC 40DF0B66 37D83BF0 A9BCAE53 DEBB9EC5 47B2CF7F 30B5FFE9 BDBDF21C CABAC28A 53B39330 24B4A3A6 BAD03605 CDD70693 54DE5729 23D967BF B3667A2E C4614AB8 5D681B02 2A6F2B94 B40BBE37 C30C8EA1 5A05DF1B 2D02EF8D"; - - var utf8Encode = function (string) { - string = string.replace(/\r\n/g,"\n"); - var utftext = ""; - - for (var n = 0; n < string.length; n++) { - - var c = string.charCodeAt(n); - - if (c < 128) { - utftext += String.fromCharCode(c); - } - else if((c > 127) && (c < 2048)) { - utftext += String.fromCharCode((c >> 6) | 192); - utftext += String.fromCharCode((c & 63) | 128); - } - else { - utftext += String.fromCharCode((c >> 12) | 224); - utftext += String.fromCharCode(((c >> 6) & 63) | 128); - utftext += String.fromCharCode((c & 63) | 128); - } - - } - - return utftext; - }; - - /** - * Convert value as 8-bit unsigned integer to 2 digit hexadecimal number. - */ - var hex8 = function(val) - { - var n = val & 0xFF, - str = n.toString(16).toUpperCase() - ; - - while(str.length < 2) - str = "0" + str; - - return str; - }; - - /** - * Convert value as 16-bit unsigned integer to 4 digit hexadecimal number. - */ - var hex16 = function(val) - { - return hex8(val >> 8) + hex8(val); - }; - - /** - * Convert value as 32-bit unsigned integer to 8 digit hexadecimal number. - */ - var hex32 = function(val) - { - return hex16(val >> 16) + hex16(val); - }; - - var crc32= function(str) { - str = utf8Encode(str); - - var crc = 0; - var x = 0; - var y = 0; - - crc = crc ^ (-1); - for (var i = 0, iTop = str.length; i < iTop; i++) { - y = (crc ^ str.charCodeAt(i)) & 0xFF; - x = "0x" + crc32table.substr(y * 9, 8); - crc = (crc >>> 8) ^ x; - } - - return (crc ^ (-1)).toString(); - }; - - var md5 = function(str) { - return String(CryptoJS.MD5(str)) - }; - - "use strict"; - - /*\ - |*| - |*| Base64 / binary data / UTF-8 strings utilities - |*| - |*| https://developer.mozilla.org/en-US/docs/Web/JavaScript/Base64_encoding_and_decoding - |*| - \*/ - - /* Array of bytes to base64 string decoding */ - - function b64ToUint6 (nChr) { - - return nChr > 64 && nChr < 91 ? - nChr - 65 - : nChr > 96 && nChr < 123 ? - nChr - 71 - : nChr > 47 && nChr < 58 ? - nChr + 4 - : nChr === 43 ? - 62 - : nChr === 47 ? - 63 - : - 0; - - } - - function base64DecToArr (sBase64, nBlocksSize) { - - var - sB64Enc = sBase64.replace(/[^A-Za-z0-9\+\/]/g, ""), nInLen = sB64Enc.length, - nOutLen = nBlocksSize ? Math.ceil((nInLen * 3 + 1 >> 2) / nBlocksSize) * nBlocksSize : nInLen * 3 + 1 >> 2, taBytes = new Uint8Array(nOutLen); - - for (var nMod3, nMod4, nUint24 = 0, nOutIdx = 0, nInIdx = 0; nInIdx < nInLen; nInIdx++) { - nMod4 = nInIdx & 3; - nUint24 |= b64ToUint6(sB64Enc.charCodeAt(nInIdx)) << 18 - 6 * nMod4; - if (nMod4 === 3 || nInLen - nInIdx === 1) { - for (nMod3 = 0; nMod3 < 3 && nOutIdx < nOutLen; nMod3++, nOutIdx++) { - taBytes[nOutIdx] = nUint24 >>> (16 >>> nMod3 & 24) & 255; - } - nUint24 = 0; - - } - } - - return taBytes; - } - - /* Base64 string to array encoding */ - - function uint6ToB64 (nUint6) { - - return nUint6 < 26 ? - nUint6 + 65 - : nUint6 < 52 ? - nUint6 + 71 - : nUint6 < 62 ? - nUint6 - 4 - : nUint6 === 62 ? - 43 - : nUint6 === 63 ? - 47 - : - 65; - - } - - function base64EncArr (aBytes) { - - var nMod3, sB64Enc = ""; - - for (var nLen = aBytes.length, nUint24 = 0, nIdx = 0; nIdx < nLen; nIdx++) { - nMod3 = nIdx % 3; - if (nIdx > 0 && (nIdx * 4 / 3) % 76 === 0) { sB64Enc += "\r\n"; } - nUint24 |= aBytes[nIdx] << (16 >>> nMod3 & 24); - if (nMod3 === 2 || aBytes.length - nIdx === 1) { - sB64Enc += String.fromCharCode(uint6ToB64(nUint24 >>> 18 & 63), uint6ToB64(nUint24 >>> 12 & 63), uint6ToB64(nUint24 >>> 6 & 63), uint6ToB64(nUint24 & 63)); - nUint24 = 0; - } - } - - return sB64Enc.replace(/A(?=A$|$)/g, "="); - - } - - /* UTF-8 array to DOMString and vice versa */ - - function UTF8ArrToStr (aBytes) { - - var sView = ""; - - for (var nPart, nLen = aBytes.length, nIdx = 0; nIdx < nLen; nIdx++) { - nPart = aBytes[nIdx]; - sView += String.fromCharCode( - nPart > 251 && nPart < 254 && nIdx + 5 < nLen ? /* six bytes */ - /* (nPart - 252 << 32) is not possible in ECMAScript! So...: */ - (nPart - 252) * 1073741824 + (aBytes[++nIdx] - 128 << 24) + (aBytes[++nIdx] - 128 << 18) + (aBytes[++nIdx] - 128 << 12) + (aBytes[++nIdx] - 128 << 6) + aBytes[++nIdx] - 128 - : nPart > 247 && nPart < 252 && nIdx + 4 < nLen ? /* five bytes */ - (nPart - 248 << 24) + (aBytes[++nIdx] - 128 << 18) + (aBytes[++nIdx] - 128 << 12) + (aBytes[++nIdx] - 128 << 6) + aBytes[++nIdx] - 128 - : nPart > 239 && nPart < 248 && nIdx + 3 < nLen ? /* four bytes */ - (nPart - 240 << 18) + (aBytes[++nIdx] - 128 << 12) + (aBytes[++nIdx] - 128 << 6) + aBytes[++nIdx] - 128 - : nPart > 223 && nPart < 240 && nIdx + 2 < nLen ? /* three bytes */ - (nPart - 224 << 12) + (aBytes[++nIdx] - 128 << 6) + aBytes[++nIdx] - 128 - : nPart > 191 && nPart < 224 && nIdx + 1 < nLen ? /* two bytes */ - (nPart - 192 << 6) + aBytes[++nIdx] - 128 - : /* nPart < 127 ? */ /* one byte */ - nPart - ); - } - - return sView; - - } - - function strToUTF8Arr (sDOMStr) { - - var aBytes, nChr, nStrLen = sDOMStr.length, nArrLen = 0; - - /* mapping... */ - - for (var nMapIdx = 0; nMapIdx < nStrLen; nMapIdx++) { - nChr = sDOMStr.charCodeAt(nMapIdx); - nArrLen += nChr < 0x80 ? 1 : nChr < 0x800 ? 2 : nChr < 0x10000 ? 3 : nChr < 0x200000 ? 4 : nChr < 0x4000000 ? 5 : 6; - } - - aBytes = new Uint8Array(nArrLen); - - /* transcription... */ - - for (var nIdx = 0, nChrIdx = 0; nIdx < nArrLen; nChrIdx++) { - nChr = sDOMStr.charCodeAt(nChrIdx); - if (nChr < 128) { - /* one byte */ - aBytes[nIdx++] = nChr; - } else if (nChr < 0x800) { - /* two bytes */ - aBytes[nIdx++] = 192 + (nChr >>> 6); - aBytes[nIdx++] = 128 + (nChr & 63); - } else if (nChr < 0x10000) { - /* three bytes */ - aBytes[nIdx++] = 224 + (nChr >>> 12); - aBytes[nIdx++] = 128 + (nChr >>> 6 & 63); - aBytes[nIdx++] = 128 + (nChr & 63); - } else if (nChr < 0x200000) { - /* four bytes */ - aBytes[nIdx++] = 240 + (nChr >>> 18); - aBytes[nIdx++] = 128 + (nChr >>> 12 & 63); - aBytes[nIdx++] = 128 + (nChr >>> 6 & 63); - aBytes[nIdx++] = 128 + (nChr & 63); - } else if (nChr < 0x4000000) { - /* five bytes */ - aBytes[nIdx++] = 248 + (nChr >>> 24); - aBytes[nIdx++] = 128 + (nChr >>> 18 & 63); - aBytes[nIdx++] = 128 + (nChr >>> 12 & 63); - aBytes[nIdx++] = 128 + (nChr >>> 6 & 63); - aBytes[nIdx++] = 128 + (nChr & 63); - } else /* if (nChr <= 0x7fffffff) */ { - /* six bytes */ - aBytes[nIdx++] = 252 + /* (nChr >>> 32) is not possible in ECMAScript! So...: */ (nChr / 1073741824); - aBytes[nIdx++] = 128 + (nChr >>> 24 & 63); - aBytes[nIdx++] = 128 + (nChr >>> 18 & 63); - aBytes[nIdx++] = 128 + (nChr >>> 12 & 63); - aBytes[nIdx++] = 128 + (nChr >>> 6 & 63); - aBytes[nIdx++] = 128 + (nChr & 63); - } - } - - return aBytes; - - } - - return { - 'crc32': crc32, - 'md5': md5, - 'hex8': hex8, - 'hex16': hex16, - 'hex32': hex32, - 'atob': function(s) { - return UTF8ArrToStr(base64DecToArr(s)); - }, - 'btoa': function(s) { - return base64EncArr(strToUTF8Arr(s)); - } - }; -}); diff --git a/client/utils/keyboard.js b/client/utils/keyboard.js deleted file mode 100644 index cd8c0857..00000000 --- a/client/utils/keyboard.js +++ /dev/null @@ -1,119 +0,0 @@ -define([ - 'hr/hr', - 'hr/utils', - 'vendors/mousetrap' -], function (hr, _, Mousetrap) { - var originalStopCallback = Mousetrap.stopCallback; - Mousetrap.stopCallback = function(e, element) { - if (e.mousetrap) { - return false; - } - return originalStopCallback(e, element); - }; - - /** - * Keyboard shortcuts manager - * - * @class - * @constructor - */ - var Keyboard = hr.Class.extend({ - initialize: function() { - this.bindings = {}; - return this; - }, - - /** - * Enable keyboard shortcut for a specific event - * - * @param {jqueryEvent} e - */ - enableKeyEvent: function(e) { - e.mousetrap = true; - }, - - /* - * Bind keyboard shortcuts to callback - - * @param {string|array} keys shortcut or list of shortcuts - * @param {function} callback function to call for this shortcut - * @param {object} context object which is binding key - */ - bind: function(keys, callback, context) { - // List of shortcuts for same action - if (_.isArray(keys)) { - _.each(keys, function(key) { this.bind(key, callback) }, this); - return; - } - - // Map shortcut -> action - if (_.isObject(keys)) { - _.each(keys, function(method, key) { - this.bind(key, method, callback); - }, this) - return; - } - - // Bind - if (this.bindings[keys] == null) { - this.bindings[keys] = new hr.Class(); - Mousetrap.bind(keys, _.bind(function(e) { - this.bindings[keys].trigger("action", e); - }, this)); - } - context.listenTo(this.bindings[keys], "action", callback); - return; - }, - - /* - * Prevent default browser shortcut - - * @param {string|array} keys shortcut to ignore - */ - preventDefault: function(keys) { - return this.bind(keys, function(e) { - e.preventDefault(); - }, this); - }, - - /* - * Convert shortcut or list of shortcut to a string - - * @param {string|array} shortcut shortcut or list of shortcuts - * @return {string} - */ - toText: function(shortcut) { - if (_.isArray(shortcut)) shortcut = _.first(shortcut); - if (!shortcut) return null; - - var isMac = /Mac|iPod|iPhone|iPad/.test(navigator.platform); - - // Replace mod by equivalent for mac or windows - shortcut = shortcut.replace("mod", isMac ? '⌘' : 'ctrl'); - - // Replace ctrl - shortcut = shortcut.replace("ctrl", "⌃"); - - // Replace shift - shortcut = shortcut.replace("shift", "⇧"); - - if (isMac) { - shortcut = shortcut.replace("alt", "⌥"); - } else { - shortcut = shortcut.replace("alt", "⎇"); - } - - // Replace + - shortcut = shortcut.replace(/\+/g, " "); - - return shortcut.toUpperCase(); - } - }); - - var keyboard = new Keyboard(); - - // Prevent some browser default keyboard interactions - keyboard.preventDefault("mod+r"); - - return keyboard; -}); \ No newline at end of file diff --git a/client/utils/languages.js b/client/utils/languages.js deleted file mode 100644 index 0e16fcac..00000000 --- a/client/utils/languages.js +++ /dev/null @@ -1,1533 +0,0 @@ -define([ - 'hr/utils' -], function (_) { - var Languages = { - /* Initialize */ - init: function() { - _.each(Languages.LIST, function(infos, lang) { - Languages.LIST[lang].lang = lang; - }) - }, - - - /* - * Return informations about a language - * @lang : name of the language - */ - get_infos: function(lang) { - return Languages.LIST[lang]; - }, - - /* - * Return color for the language - * @infos : language infos - */ - get_color_byinfos: function(infos, def) { - var color = def; - if (infos == null) { - return def; - } - if (infos.color != null) { - return infos.color; - } - if (infos.group != null && infos.group != infos.lang) { - return Languages.get_color(infos.group, def); - } - return def; - }, - - /* - * Return color for the language - * @lang : name of the language - */ - get_color: function(lang, def) { - var infos = Languages.get_infos(lang); - return Languages.get_color_byinfos(infos, def) - }, - - /* - * Return color for the language - * @ext : file extension - */ - get_color_byext: function(ext, def) { - var infos = Languages.get_byextension(ext); - return Languages.get_color_byinfos(infos, def) - }, - - /* - * Return language infos by extension - * @extension : extension of the file - */ - get_byextension: function(extension) { - var name = extension.replace(".", ""); - extension = extension.toLowerCase(); - return _.find(_.values(Languages.LIST), function(lang) { - - if (lang.primary_extension.toLowerCase() == extension) { - return true; - } - return _.contains(_.map(lang.extensions || [], function(ext) { - return ext.toLowerCase(); - }), extension) - || _.contains(lang.filenames, name); - }); - }, - - /* - * Return mode of edition by extension - * @extension : extension of the file - */ - get_mode_byextension: function(extension) { - var lang = Languages.get_byextension(extension); - if (lang != null && lang.ace_mode != null) { - return lang.ace_mode; - } else { - return "text"; - } - }, - - /* - * Return suggestion - */ - get_autosuggestions: function(query) { - query = query.toLowerCase(); - return _.reduce(Languages.LIST, function(list, infos, language) { - if (language.toLowerCase().search(query) >= 0) { - list.push({ - name: language, - value: language - }) - } - return list; - }, []); - }, - - LIST: { - "ASP":{ - "aliases":[ - "aspx", - "aspx-vb" - ], - "color":"#6a40fd", - "extensions":[ - ".asax", - ".ascx", - ".ashx", - ".asmx", - ".aspx", - ".axd" - ], - "lexer":"aspx-vb", - "primary_extension":".asp", - "search_term":"aspx-vb", - "type":"programming" - }, - "ActionScript":{ - "aliases":[ - "as3" - ], - "color":"#e3491a", - "lexer":"ActionScript 3", - "primary_extension":".as", - "search_term":"as3", - "type":"programming" - }, - "Ada":{ - "color":"#02f88c", - "extensions":[ - ".ads" - ], - "primary_extension":".adb", - "type":"programming" - }, - "ApacheConf":{ - "aliases":[ - "apache" - ], - "primary_extension":".apacheconf", - "type":"markup" - }, - "Apex":{ - "lexer":"Text only", - "primary_extension":".cls", - "type":"programming" - }, - "AppleScript":{ - "aliases":[ - "osascript" - ], - "primary_extension":".applescript", - "type":"programming" - }, - "Arc":{ - "color":"#ca2afe", - "lexer":"Text only", - "primary_extension":".arc", - "type":"programming" - }, - "Arduino":{ - "color":"#bd79d1", - "lexer":"C++", - "primary_extension":".ino", - "type":"programming" - }, - "Assembly":{ - "aliases":[ - "nasm" - ], - "color":"#a67219", - "lexer":"NASM", - "primary_extension":".asm", - "search_term":"nasm", - "type":"programming" - }, - "Augeas":{ - "primary_extension":".aug", - "type":"programming" - }, - "AutoHotkey":{ - "aliases":[ - "ahk" - ], - "color":"#6594b9", - "lexer":"autohotkey", - "primary_extension":".ahk", - "type":"programming" - }, - "Batchfile":{ - "aliases":[ - "bat" - ], - "extensions":[ - ".cmd" - ], - "group":"Shell", - "primary_extension":".bat", - "search_term":"bat", - "type":"programming" - }, - "Befunge":{ - "primary_extension":".befunge" - }, - "BlitzMax":{ - "primary_extension":".bmx" - }, - "Boo":{ - "color":"#d4bec1", - "primary_extension":".boo", - "type":"programming" - }, - "Brainfuck":{ - "extensions":[ - ".bf" - ], - "primary_extension":".b" - }, - "Bro":{ - "primary_extension":".bro", - "type":"programming" - }, - "C":{ - "ace_mode":"c_cpp", - "color":"#555", - "extensions":[ - ".w", - ".h" - ], - "primary_extension":".c", - "type":"programming" - }, - "C#":{ - "ace_mode":"csharp", - "aliases":[ - "csharp" - ], - "color":"#5a25a2", - "primary_extension":".cs", - "search_term":"csharp", - "type":"programming" - }, - "C++":{ - "ace_mode":"c_cpp", - "aliases":[ - "cpp" - ], - "color":"#f34b7d", - "extensions":[ - ".c", - ".c++", - ".cxx", - ".h", - ".h++", - ".hh", - ".hxx", - ".hpp", - ".tcc", - ".cc" - ], - "primary_extension":".cpp", - "search_term":"cpp", - "type":"programming" - }, - "C-ObjDump":{ - "lexer":"c-objdump", - "primary_extension":".c-objdump", - "type":"data" - }, - "C2hs Haskell":{ - "aliases":[ - "c2hs" - ], - "group":"Haskell", - "lexer":"Haskell", - "primary_extension":".chs", - "type":"programming" - }, - "CMake":{ - "extensions":[ - ".cmake.in" - ], - "filenames":[ - "CMakeLists.txt" - ], - "primary_extension":".cmake" - }, - "CSS":{ - "ace_mode":"css", - "primary_extension":".css" - }, - "Ceylon":{ - "lexer":"Text only", - "primary_extension":".ceylon", - "type":"programming" - }, - "ChucK":{ - "lexer":"Java", - "primary_extension":".ck" - }, - "Clojure":{ - "ace_mode":"clojure", - "color":"#db5855", - "extensions":[ - ".cljs" - ], - "primary_extension":".clj", - "type":"programming" - }, - "CoffeeScript":{ - "ace_mode":"coffee", - "aliases":[ - "coffee", - "coffee-script" - ], - "color":"#244776", - "extensions":[ - "._coffee" - ], - "filenames":[ - "Cakefile" - ], - "primary_extension":".coffee", - "type":"programming" - }, - "ColdFusion":{ - "ace_mode":"coldfusion", - "aliases":[ - "cfm" - ], - "color":"#ed2cd6", - "extensions":[ - ".cfc" - ], - "lexer":"Coldfusion HTML", - "primary_extension":".cfm", - "search_term":"cfm", - "type":"programming" - }, - "Common Lisp":{ - "aliases":[ - "lisp" - ], - "color":"#3fb68b", - "extensions":[ - ".lsp", - ".ny" - ], - "primary_extension":".lisp", - "type":"programming" - }, - "Coq":{ - "primary_extension":".coq", - "type":"programming" - }, - "Cpp-ObjDump":{ - "extensions":[ - ".c++objdump", - ".cxx-objdump" - ], - "lexer":"cpp-objdump", - "primary_extension":".cppobjdump", - "type":"data" - }, - "Cucumber":{ - "lexer":"Gherkin", - "primary_extension":".feature" - }, - "Cython":{ - "extensions":[ - ".pxd", - ".pxi" - ], - "group":"Python", - "primary_extension":".pyx", - "type":"programming" - }, - "D":{ - "color":"#fcd46d", - "extensions":[ - ".di" - ], - "primary_extension":".d", - "type":"programming", - "ace_mode":"d" - }, - "D-ObjDump":{ - "lexer":"d-objdump", - "primary_extension":".d-objdump", - "type":"data" - }, - "DCPU-16 ASM":{ - "aliases":[ - "dasm16" - ], - "extensions":[ - ".dasm" - ], - "lexer":"dasm16", - "primary_extension":".dasm16", - "type":"programming" - }, - "Darcs Patch":{ - "aliases":[ - "dpatch" - ], - "extensions":[ - ".dpatch" - ], - "primary_extension":".darcspatch", - "search_term":"dpatch" - }, - "Dart":{ - "primary_extension":".dart", - "ace_mode": "dart", - "color":"#98BAD6", - "type":"programming" - }, - "Delphi":{ - "color":"#b0ce4e", - "extensions":[ - ".lpr" - ], - "primary_extension":".pas", - "type":"programming" - }, - "Diff":{ - "primary_extension":".diff" - }, - "Dylan":{ - "color":"#3ebc27", - "primary_extension":".dylan", - "type":"programming" - }, - "Ecere Projects":{ - "group":"JavaScript", - "lexer":"JSON", - "primary_extension":".epj", - "type":"data" - }, - "Ecl":{ - "color":"#8a1267", - "extensions":[ - ".eclxml" - ], - "lexer":"ECL", - "primary_extension":".ecl", - "type":"programming" - }, - "Eiffel":{ - "color":"#946d57", - "lexer":"Text only", - "primary_extension":".e", - "type":"programming" - }, - "Elixir":{ - "color":"#6e4a7e", - "extensions":[ - ".exs" - ], - "primary_extension":".ex", - "type":"programming" - }, - "Elm":{ - "group":"Haskell", - "lexer":"Haskell", - "primary_extension":".elm", - "type":"programming" - }, - "Emacs Lisp":{ - "aliases":[ - "elisp", - "emacs" - ], - "color":"#c065db", - "extensions":[ - ".emacs" - ], - "lexer":"Scheme", - "primary_extension":".el", - "type":"programming" - }, - "Erlang":{ - "color":"#949e0e", - "extensions":[ - ".hrl" - ], - "primary_extension":".erl", - "type":"programming" - }, - "F#":{ - "color":"#b845fc", - "extensions":[ - ".fsi", - ".fsx" - ], - "lexer":"FSharp", - "primary_extension":".fs", - "search_term":"ocaml", - "type":"programming" - }, - "FORTRAN":{ - "color":"#4d41b1", - "extensions":[ - ".F", - ".F03", - ".F08", - ".F77", - ".F90", - ".F95", - ".FOR", - ".FPP", - ".f", - ".f03", - ".f08", - ".f77", - ".f95", - ".for", - ".fpp" - ], - "lexer":"Fortran", - "primary_extension":".f90", - "type":"programming" - }, - "Factor":{ - "color":"#636746", - "primary_extension":".factor", - "type":"programming" - }, - "Fancy":{ - "color":"#7b9db4", - "extensions":[ - ".fancypack" - ], - "filenames":[ - "Fakefile" - ], - "primary_extension":".fy", - "type":"programming" - }, - "Fantom":{ - "color":"#dbded5", - "primary_extension":".fan", - "type":"programming" - }, - "Forth":{ - "color":"#341708", - "extensions":[ - ".forth", - ".fth" - ], - "lexer":"Text only", - "primary_extension":".fth", - "type":"programming" - }, - "GAS":{ - "extensions":[ - ".S" - ], - "group":"Assembly", - "primary_extension":".s", - "type":"programming" - }, - "Genshi":{ - "primary_extension":".kid" - }, - "Gentoo Ebuild":{ - "group":"Shell", - "lexer":"Bash", - "primary_extension":".ebuild" - }, - "Gentoo Eclass":{ - "group":"Shell", - "lexer":"Bash", - "primary_extension":".eclass" - }, - "Gettext Catalog":{ - "aliases":[ - "pot" - ], - "extensions":[ - ".pot" - ], - "primary_extension":".po", - "search_term":"pot", - "searchable":false - }, - "Go":{ - "color":"#8d04eb", - "primary_extension":".go", - "type":"programming", - "ace_mode":"golang" - }, - "Gosu":{ - "color":"#82937f", - "primary_extension":".gs", - "type":"programming" - }, - "Groff":{ - "extensions":[ - ".1", - ".2", - ".3", - ".4", - ".5", - ".6", - ".7" - ], - "primary_extension":".man" - }, - "Groovy":{ - "ace_mode":"groovy", - "color":"#e69f56", - "primary_extension":".groovy", - "type":"programming" - }, - "Groovy Server Pages":{ - "aliases":[ - "gsp" - ], - "group":"Groovy", - "lexer":"Java Server Page", - "primary_extension":".gsp" - }, - "HTML":{ - "ace_mode":"html", - "aliases":[ - "xhtml" - ], - "extensions":[ - ".htm", - ".xhtml" - ], - "primary_extension":".html", - "type":"markup" - }, - "HTML+Django":{ - "extensions":[ - ".mustache" - ], - "group":"HTML", - "lexer":"HTML+Django/Jinja", - "primary_extension":".mustache", - "type":"markup" - }, - "HTML+ERB":{ - "aliases":[ - "erb" - ], - "extensions":[ - ".html.erb" - ], - "group":"HTML", - "lexer":"RHTML", - "primary_extension":".erb", - "type":"markup" - }, - "HTML+PHP":{ - "group":"HTML", - "primary_extension":".phtml", - "type":"markup" - }, - "HTTP":{ - "primary_extension":".http", - "type":"data" - }, - "Haml":{ - "group":"HTML", - "primary_extension":".haml", - "type":"markup" - }, - "Handlebars":{ - "lexer":"Text only", - "primary_extension":".handlebars", - "type":"markup" - }, - "Haskell":{ - "color":"#29b544", - "extensions":[ - ".hsc" - ], - "primary_extension":".hs", - "type":"programming" - }, - "Haxe":{ - "ace_mode":"haxe", - "color":"#346d51", - "extensions":[ - ".hxsl" - ], - "lexer":"haXe", - "primary_extension":".hx", - "type":"programming" - }, - "INI":{ - "extensions":[ - ".cfg", - ".ini", - ".prefs", - ".properties" - ], - "primary_extension":".ini", - "type":"data" - }, - "IRC log":{ - "aliases":[ - "irc" - ], - "extensions":[ - ".weechatlog" - ], - "lexer":"IRC logs", - "primary_extension":".irclog", - "search_term":"irc" - }, - "Io":{ - "color":"#a9188d", - "primary_extension":".io", - "type":"programming" - }, - "Ioke":{ - "color":"#078193", - "primary_extension":".ik", - "type":"programming" - }, - "JSON":{ - "ace_mode":"json", - "group":"JavaScript", - "primary_extension":".json", - "searchable":false, - "type":"data" - }, - "Java":{ - "ace_mode":"java", - "color":"#b07219", - "extensions":[ - ".pde" - ], - "primary_extension":".java", - "type":"programming" - }, - "Java Server Pages":{ - "aliases":[ - "jsp" - ], - "group":"Java", - "lexer":"Java Server Page", - "primary_extension":".jsp", - "search_term":"jsp" - }, - "JavaScript":{ - "ace_mode":"javascript", - "aliases":[ - "js", - "node" - ], - "color":"#f15501", - "extensions":[ - "._js", - ".bones", - ".jake", - ".jsfl", - ".jsm", - ".jss", - ".jsx", - ".pac", - ".sjs", - ".ssjs" - ], - "filenames":[ - "Jakefile" - ], - "primary_extension":".js", - "type":"programming" - }, - "Julia":{ - "primary_extension":".jl", - "type":"programming" - }, - "Kotlin":{ - "extensions":[ - ".ktm", - ".kts" - ], - "primary_extension":".kt", - "type":"programming" - }, - "LLVM":{ - "primary_extension":".ll" - }, - "Lasso":{ - "ace_mode":"lasso", - "color":"#2584c3", - "extensions":[ - ".inc", - ".las", - ".lasso9", - ".ldml" - ], - "lexer":"Lasso", - "primary_extension":".lasso", - "type":"programming" - }, - "Less":{ - "ace_mode":"less", - "group":"CSS", - "lexer":"CSS", - "primary_extension":".less", - "type":"markup" - }, - "LilyPond":{ - "extensions":[ - ".ily" - ], - "lexer":"Text only", - "primary_extension":".ly" - }, - "Literate Haskell":{ - "aliases":[ - "lhs" - ], - "group":"Haskell", - "primary_extension":".lhs", - "search_term":"lhs", - "type":"programming" - }, - "LiveScript":{ - "ace_mode":"ls", - "aliases":[ - "ls" - ], - "color":"#499886", - "extensions":[ - "._ls" - ], - "filenames":[ - "Slakefile" - ], - "primary_extension":".ls", - "type":"programming" - }, - "Logtalk":{ - "primary_extension":".lgt", - "type":"programming" - }, - "Lua":{ - "ace_mode":"lua", - "color":"#fa1fa1", - "extensions":[ - ".nse", - ".pd_lua" - ], - "primary_extension":".lua", - "type":"programming" - }, - "Makefile":{ - "aliases":[ - "make" - ], - "extensions":[ - ".mak", - ".mk" - ], - "filenames":[ - "makefile", - "Makefile", - "GNUmakefile" - ], - "primary_extension":".mak" - }, - "Mako":{ - "extensions":[ - ".mao" - ], - "primary_extension":".mako" - }, - "Markdown":{ - "ace_mode":"markdown", - "extensions":[ - ".markdown", - ".mkd", - ".mkdown", - ".ron" - ], - "lexer":"Text only", - "primary_extension":".md", - "type":"markup", - "wrap":true - }, - "Matlab":{ - "color":"#bb92ac", - "primary_extension":".matlab", - "type":"programming" - }, - "Max":{ - "aliases":[ - "max/msp", - "maxmsp" - ], - "color":"#ce279c", - "lexer":"Text only", - "primary_extension":".mxt", - "search_term":"max/msp", - "type":"programming" - }, - "MiniD":{ - "primary_extension":".minid", - "searchable":false - }, - "Mirah":{ - "color":"#c7a938", - "extensions":[ - ".duby", - ".mir", - ".mirah" - ], - "lexer":"Ruby", - "primary_extension":".druby", - "search_term":"ruby", - "type":"programming" - }, - "Moocode":{ - "lexer":"MOOCode", - "primary_extension":".moo" - }, - "MoonScript":{ - "primary_extension":".moon", - "type":"programming" - }, - "Myghty":{ - "primary_extension":".myt" - }, - "Nemerle":{ - "color":"#0d3c6e", - "primary_extension":".n", - "type":"programming" - }, - "Nginx":{ - "lexer":"Nginx configuration file", - "primary_extension":".nginxconf", - "type":"markup" - }, - "Nimrod":{ - "color":"#37775b", - "extensions":[ - ".nimrod" - ], - "primary_extension":".nim", - "type":"programming" - }, - "Nu":{ - "aliases":[ - "nush" - ], - "color":"#c9df40", - "filenames":[ - "Nukefile" - ], - "lexer":"Scheme", - "primary_extension":".nu", - "type":"programming" - }, - "NumPy":{ - "extensions":[ - ".numpyw", - ".numsc" - ], - "group":"Python", - "primary_extension":".numpy" - }, - "OCaml":{ - "ace_mode":"ocaml", - "color":"#3be133", - "extensions":[ - ".mli", - ".mll", - ".mly" - ], - "primary_extension":".ml", - "type":"programming" - }, - "ObjDump":{ - "lexer":"objdump", - "primary_extension":".objdump", - "type":"data" - }, - "Objective-C":{ - "aliases":[ - "obj-c", - "objc" - ], - "color":"#438eff", - "extensions":[ - ".mm" - ], - "primary_extension":".m", - "type":"programming" - }, - "Objective-J":{ - "aliases":[ - "obj-j" - ], - "color":"#ff0c5a", - "extensions":[ - ".sj" - ], - "primary_extension":".j", - "type":"programming" - }, - "Omgrofl":{ - "color":"#cabbff", - "extensions":[ - ".omgrofl" - ], - "lexer":"Text only", - "primary_extension":".omgrofl", - "type":"programming" - }, - "Opa":{ - "primary_extension":".opa", - "type":"programming" - }, - "OpenCL":{ - "group":"C", - "lexer":"C", - "primary_extension":".cl", - "type":"programming" - }, - "OpenEdge ABL":{ - "aliases":[ - "progress", - "openedge", - "abl" - ], - "primary_extension":".p", - "type":"programming" - }, - "PHP":{ - "ace_mode":"php", - "color":"#6e03c1", - "extensions":[ - ".aw", - ".ctp", - ".php3", - ".php4", - ".php5", - ".phpt" - ], - "filenames":[ - "Phakefile" - ], - "primary_extension":".php", - "type":"programming" - }, - "Hack":{ - "ace_mode":"php", - "color":"#6e03c1", - "primary_extension":".hh", - "type":"programming" - }, - "Parrot":{ - "color":"#f3ca0a", - "lexer":"Text only", - "primary_extension":".parrot", - "type":"programming" - }, - "Parrot Assembly":{ - "aliases":[ - "pasm" - ], - "group":"Parrot", - "lexer":"Text only", - "primary_extension":".pasm", - "type":"programming" - }, - "Parrot Internal Representation":{ - "aliases":[ - "pir" - ], - "group":"Parrot", - "lexer":"Text only", - "primary_extension":".pir", - "type":"programming" - }, - "Perl":{ - "ace_mode":"perl", - "color":"#0298c3", - "extensions":[ - ".PL", - ".perl", - ".ph", - ".plx", - ".pm6", - ".pod", - ".psgi" - ], - "primary_extension":".pl", - "type":"programming" - }, - "PowerShell":{ - "ace_mode":"powershell", - "aliases":[ - "posh" - ], - "primary_extension":".ps1", - "type":"programming" - }, - "Prolog":{ - "color":"#74283c", - "extensions":[ - ".pro" - ], - "primary_extension":".prolog", - "type":"programming" - }, - "Puppet":{ - "color":"#cc5555", - "extensions":[ - ".pp" - ], - "filenames":[ - "Modulefile" - ], - "primary_extension":".pp", - "type":"programming" - }, - "Pure Data":{ - "color":"#91de79", - "lexer":"Text only", - "primary_extension":".pd", - "type":"programming" - }, - "Python":{ - "ace_mode":"python", - "color":"#3581ba", - "extensions":[ - ".pyw", - ".wsgi", - ".xpy" - ], - "filenames":[ - "wscript" - ], - "primary_extension":".py", - "type":"programming" - }, - "Python traceback":{ - "group":"Python", - "lexer":"Python Traceback", - "primary_extension":".pytb", - "searchable":false, - "type":"data" - }, - "R":{ - "color":"#198ce7", - "lexer":"S", - "primary_extension":".r", - "type":"programming", - "ace_mode":"r" - }, - "RHTML":{ - "group":"HTML", - "primary_extension":".rhtml", - "type":"markup" - }, - "Racket":{ - "color":"#ae17ff", - "extensions":[ - ".rktd", - ".rktl" - ], - "lexer":"Racket", - "primary_extension":".rkt", - "type":"programming" - }, - "Raw token data":{ - "aliases":[ - "raw" - ], - "primary_extension":".raw", - "search_term":"raw" - }, - "Rebol":{ - "color":"#358a5b", - "extensions":[ - ".r2", - ".r3" - ], - "lexer":"REBOL", - "primary_extension":".rebol", - "type":"programming" - }, - "Redcode":{ - "primary_extension":".cw" - }, - "Ruby":{ - "ace_mode":"ruby", - "aliases":[ - "jruby", - "macruby", - "rake", - "rb", - "rbx" - ], - "color":"#701516", - "extensions":[ - ".builder", - ".gemspec", - ".god", - ".irbrc", - ".podspec", - ".rbuild", - ".rbw", - ".rbx", - ".ru", - ".thor", - ".watchr" - ], - "filenames":[ - "Gemfile", - "Guardfile", - "Podfile", - "Thorfile", - "Vagrantfile" - ], - "primary_extension":".rb", - "type":"programming" - }, - "Rust":{ - "color":"#dea584", - "lexer":"Text only", - "primary_extension":".rs", - "type":"programming" - }, - "SCSS":{ - "ace_mode":"scss", - "group":"CSS", - "primary_extension":".scss", - "type":"markup" - }, - "SQL":{ - "ace_mode":"sql", - "primary_extension":".sql", - "searchable":false, - "type":"data" - }, - "Sage":{ - "group":"Python", - "lexer":"Python", - "primary_extension":".sage", - "type":"programming" - }, - "Sass":{ - "group":"CSS", - "primary_extension":".sass", - "type":"markup" - }, - "Scala":{ - "ace_mode":"scala", - "color":"#7dd3b0", - "primary_extension":".scala", - "type":"programming" - }, - "Scheme":{ - "color":"#1e4aec", - "extensions":[ - ".sls", - ".ss" - ], - "primary_extension":".scm", - "type":"programming" - }, - "Scilab":{ - "primary_extension":".sci", - "type":"programming" - }, - "Self":{ - "color":"#0579aa", - "lexer":"Text only", - "primary_extension":".self", - "type":"programming" - }, - "Shell":{ - "ace_mode":"sh", - "aliases":[ - "sh", - "bash", - "zsh" - ], - "filenames": [ - "Dockerfile" - ], - "color":"#5861ce", - "lexer":"Bash", - "primary_extension":".sh", - "search_term":"bash", - "type":"programming" - }, - "Smalltalk":{ - "color":"#596706", - "primary_extension":".st", - "type":"programming" - }, - "Smarty":{ - "primary_extension":".tpl" - }, - "Standard ML":{ - "aliases":[ - "sml" - ], - "color":"#dc566d", - "primary_extension":".sml", - "type":"programming" - }, - "SuperCollider":{ - "color":"#46390b", - "lexer":"Text only", - "primary_extension":".sc", - "type":"programming" - }, - "Tcl":{ - "color":"#e4cc98", - "primary_extension":".tcl", - "type":"programming" - }, - "Tcsh":{ - "extensions":[ - ".csh" - ], - "group":"Shell", - "primary_extension":".tcsh", - "type":"programming" - }, - "TeX":{ - "ace_mode":"latex", - "aliases":[ - "latex" - ], - "extensions":[ - ".aux", - ".dtx", - ".ins", - ".ltx", - ".sty", - ".toc" - ], - "primary_extension":".tex", - "type":"markup" - }, - "Tea":{ - "primary_extension":".tea", - "type":"markup" - }, - "Textile":{ - "ace_mode":"textile", - "lexer":"Text only", - "primary_extension":".textile", - "type":"markup", - "wrap":true - }, - "Turing":{ - "color":"#45f715", - "extensions":[ - ".tu" - ], - "lexer":"Text only", - "primary_extension":".t", - "type":"programming" - }, - "Twig":{ - "group":"PHP", - "lexer":"HTML+Django/Jinja", - "primary_extension":".twig", - "type":"markup" - }, - "VHDL":{ - "color":"#543978", - "lexer":"vhdl", - "primary_extension":".vhdl", - "type":"programming" - }, - "Vala":{ - "color":"#ee7d06", - "extensions":[ - ".vapi" - ], - "primary_extension":".vala", - "type":"programming" - }, - "Verilog":{ - "color":"#848bf3", - "lexer":"verilog", - "primary_extension":".v", - "type":"programming" - }, - "VimL":{ - "aliases":[ - "vim" - ], - "color":"#199c4b", - "filenames":[ - "vimrc", - "gvimrc" - ], - "primary_extension":".vim", - "search_term":"vim", - "type":"programming" - }, - "Visual Basic":{ - "color":"#945db7", - "extensions":[ - ".bas", - ".frx", - ".vba", - ".vbs" - ], - "lexer":"VB.net", - "primary_extension":".vb", - "type":"programming" - }, - "XML":{ - "ace_mode":"xml", - "aliases":[ - "rss", - "xsd", - "xsl", - "wsdl" - ], - "extensions":[ - ".ccxml", - ".glade", - ".grxml", - ".kml", - ".mxml", - ".plist", - ".rdf", - ".rss", - ".scxml", - ".svg", - ".vxml", - ".wsdl", - ".wxi", - ".wxl", - ".wxs", - ".xaml", - ".xlf", - ".xliff", - ".xsd", - ".xsl", - ".xul" - ], - "filenames":[ - ".classpath", - ".project" - ], - "primary_extension":".xml", - "type":"markup" - }, - "XQuery":{ - "color":"#2700e2", - "extensions":[ - ".xq", - ".xqy" - ], - "primary_extension":".xquery", - "type":"programming" - }, - "XS":{ - "lexer":"C", - "primary_extension":".xs" - }, - "XSLT":{ - "group":"XML", - "primary_extension":".xslt", - "type":"markup" - }, - "YAML":{ - "aliases":[ - "yml" - ], - "extensions":[ - ".yaml" - ], - "filenames":[ - "Procfile" - ], - "primary_extension":".yml", - "type":"markup", - "ace_mode":"yaml" - }, - "eC":{ - "extensions":[ - ".eh" - ], - "primary_extension":".ec", - "search_term":"ec", - "type":"programming" - }, - "mupad":{ - "lexer":"MuPAD", - "primary_extension":".mu" - }, - "ooc":{ - "color":"#b0b77e", - "lexer":"Ooc", - "primary_extension":".ooc", - "type":"programming" - }, - "reStructuredText":{ - "aliases":[ - "rst" - ], - "extensions":[ - ".rest" - ], - "primary_extension":".rst", - "search_term":"rst", - "type":"markup", - "wrap":true - } - } - - }; - - return Languages; -}); \ No newline at end of file diff --git a/client/utils/loading.js b/client/utils/loading.js deleted file mode 100644 index 61a6ad52..00000000 --- a/client/utils/loading.js +++ /dev/null @@ -1,34 +0,0 @@ -define([ - 'hr/dom', - 'hr/utils' -], function ($, _) { - return { - show: function(p, message) { - $(".cb-loading-alert").show(); - - if (_.isString(p)) { - message = p; - p = null; - } - - if (message) { - $(".cb-loading-alert .cb-loading-message").html(message); - } - - if (p) { - p.fin(function() { - return Q.delay(300); - }).fin(function() { - $(".cb-loading-alert").hide(); - $(".cb-loading-alert .cb-loading-message").html(""); - }); - } - - return p; - }, - stop: function() { - $(".cb-loading-alert").hide(); - $(".cb-loading-alert .cb-loading-message").html(""); - } - }; -}); \ No newline at end of file diff --git a/client/utils/string.js b/client/utils/string.js deleted file mode 100644 index bde74a24..00000000 --- a/client/utils/string.js +++ /dev/null @@ -1,100 +0,0 @@ -define([ - 'hr/hr' -], function (hr) { - /** - * Scores a string against another string. - * score('Hello World', 'he'); //=> 0.5931818181818181 - * score('Hello World', 'Hello'); //=> 0.7318181818181818 - */ - var score = function(string, word, fuzziness) { - // If the string is equal to the word, perfect match. - if (string == word) return 1; - - //if it's not a perfect match and is empty return 0 - if( word == "") return 0; - - var runningScore = 0, - charScore, - finalScore, - lString = string.toLowerCase(), - strLength = string.length, - lWord = word.toLowerCase(), - wordLength = word.length, - idxOf, - startAt = 0, - fuzzies = 1, - fuzzyFactor; - - // Cache fuzzyFactor for speed increase - if (fuzziness) fuzzyFactor = 1 - fuzziness; - - // Walk through word and add up scores. - // Code duplication occurs to prevent checking fuzziness inside for loop - if (fuzziness) { - for (var i = 0; i < wordLength; ++i) { - - // Find next first case-insensitive match of a character. - idxOf = lString.indexOf(lWord[i], startAt); - - if (-1 === idxOf) { - fuzzies += fuzzyFactor; - continue; - } else if (startAt === idxOf) { - // Consecutive letter & start-of-string Bonus - charScore = 0.7; - } else { - charScore = 0.1; - - // Acronym Bonus - // Weighing Logic: Typing the first character of an acronym is as if you - // preceded it with two perfect character matches. - if (string[idxOf - 1] === ' ') charScore += 0.8; - } - - // Same case bonus. - if (string[idxOf] === word[i]) charScore += 0.1; - - // Update scores and startAt position for next round of indexOf - runningScore += charScore; - startAt = idxOf + 1; - } - } else { - for (var i = 0; i < wordLength; ++i) { - - idxOf = lString.indexOf(lWord[i], startAt); - - if (-1 === idxOf) { - return 0; - } else if (startAt === idxOf) { - charScore = 0.7; - } else { - charScore = 0.1; - if (string[idxOf - 1] === ' ') charScore += 0.8; - } - - if (string[idxOf] === word[i]) charScore += 0.1; - - runningScore += charScore; - startAt = idxOf + 1; - } - } - - // Reduce penalty for longer strings. - finalScore = 0.5 * (runningScore / strLength + runningScore / wordLength) / fuzzies; - - if ((lWord[0] === lString[0]) && (finalScore < 0.85)) { - finalScore += 0.15; - } - - return finalScore; - }; - - var endsWith = function(s, suffix) { - return s.indexOf(suffix, s.length - suffix.length) !== -1; - }; - - return { - 'score': score, - 'endsWith': endsWith - }; -}); \ No newline at end of file diff --git a/client/utils/uploader.js b/client/utils/uploader.js deleted file mode 100644 index 256a71f4..00000000 --- a/client/utils/uploader.js +++ /dev/null @@ -1,178 +0,0 @@ -define([ - 'hr/hr', - 'hr/promise', - 'hr/dom', - 'hr/utils' -],function(hr, Q, $, _) { - var logging = hr.Logger.addNamespace("uploader"); - - try { - if (XMLHttpRequest.prototype.sendAsBinary){} else { - XMLHttpRequest.prototype.sendAsBinary = function(datastr) { - function byteValue(x) { - return x.charCodeAt(0) & 0xff; - } - var ords = Array.prototype.map.call(datastr, byteValue); - var ui8a = new Uint8Array(ords); - this.send(ui8a); - } - } - } catch(e) {} - - var Uploader = hr.Class.extend({ - defaults: { - directory: null - }, - - /* - * Constructor for the uploader - */ - initialize: function(){ - Uploader.__super__.initialize.apply(this, arguments); - - this.directory = this.options.directory - this.codebox = this.directory.codebox; - this.lock = false; - this.maxFileSize = 10*1048576; - - return this; - }, - - /* - * Connect to a input file - */ - connect: function(input) { - var self = this; - input.on("change", function(e) { - e.preventDefault(); - self.upload(this.files); - }); - }, - - - /* - * Run upload - * @files : html5 files - */ - upload: function(files) { - var d = Q.defer(); - var totalFilesSize = 0; - var that = this; - - if (that.lock == true) { - return Q.reject("Upload already in progress"); - } - - // Calcul total files size - totalFilesSize = _.reduce(files, function(memo, file){ return memo + (file.size != null ? file.size : 0); }, 0); - - _.reduce(files, function(d, file) { - return d.then(function() { - return that.uploadFile(file); - }); - }, Q({})).then(function() { - d.resolve(); - }, function(err) { - d.reject(err); - }, function(progress) { - d.notify(progress); - }); - - return d.promise; - }, - - /* - * Upload one file - */ - uploadFile: function(file) { - var that = this; - var d = Q.defer(); - var filename = file.webkitRelativePath || file.name; - - var error = function(err) { - logging.error("error uploading", filename, ":", err); - that.trigger("error", err); - that.lock = false; - d.reject(err); - } - - var progress = function(percent) { - logging.log("notify ", filename, percent); - that.trigger("state", percent); - d.notify({ - 'filename': filename, - 'percent': percent - }); - }; - - var end = function(text) { - logging.log("end", text); - that.trigger("end", text); - that.lock = false; - d.resolve(text); - }; - - if (file.name == "." || file.name == "..") { - return Q(); - } - - if (file.name == null || file.size == null || file.size >= that.maxFileSize) { - return Q.reject(new Error("Invalid file or file too big")); - } - - that.lock = true; - - logging.log("upload file ", filename, " in ", that.directory.exportUrl(), file.size,"/", file.size); - - var send = function(e){ - var xhr = new XMLHttpRequest(), - upload = xhr.upload, - start_time = new Date().getTime(), - uploadurl = that.directory.exportUrl()+filename; - - if (e.target.result == null) { - error(new Error("Error reading file")); - return; - } - - logging.log("start uploading ", filename); - - upload.file = file; - upload.downloadStartTime = start_time; - upload.currentStart = start_time; - upload.currentProgress = 0; - upload.startData = 0; - upload.addEventListener("progress",function(e){ - if (e.lengthComputable) { - var percentage = Math.round((e.loaded * 100) / file.size); - progress(percentage); - } - }, false); - - xhr.open("PUT", uploadurl, true); - xhr.onreadystatechange = function(e){ - if (xhr.status != 200) { - error(new Error(xhr.status+": "+xhr.responseText)); - e.preventDefault(); - return; - } - }; - xhr.sendAsBinary(e.target.result); - progress(0); - xhr.onload = function() { - if (xhr.status == 200) { - end(xhr.responseText || ""); - } - } - }; - - var reader = new FileReader(); - reader.onloadend = send; - reader.readAsBinaryString(file); - - return d.promise; - } - }); - - return Uploader; -}); \ No newline at end of file diff --git a/client/utils/url.js b/client/utils/url.js deleted file mode 100644 index 5571e209..00000000 --- a/client/utils/url.js +++ /dev/null @@ -1,74 +0,0 @@ -define([ - 'hr/hr' -], function (hr) { - - - return URL = { - /* - * Parse query string - */ - parseQueryString: function(){ - var assoc = {}; - var keyValues = location.search.slice(1).split('&'); - var decode = function(s){ - return decodeURIComponent(s.replace(/\+/g, ' ')); - }; - - for (var i = 0; i < keyValues.length; ++i) { - var key = keyValues[i].split('='); - if (1 < key.length) { - assoc[decode(key[0])] = decode(key[1]); - } - } - - return assoc; - }, - - /* - * Parse an url in a dict with : - * 'source', 'scheme', 'authority', 'userInfo', 'user', 'pass', 'host', 'port', - * 'relative', 'path', 'directory', 'file', 'query', 'fragment' - */ - parse: function(url) { - var m = String(url).replace(/^\s+|\s+$/g, '').match(/^([^:\/?#]+:)?(\/\/(?:[^:@]*(?::[^:@]*)?@)?(([^:\/?#]*)(?::(\d*))?))?([^?#]*)(\?[^#]*)?(#[\s\S]*)?/); - // authority = '//' + user + ':' + pass '@' + hostname + ':' port - return (m ? { - href : m[0] || '', - protocol : m[1] || '', - authority: m[2] || '', - host : m[3] || '', - hostname : m[4] || '', - port : m[5] || '', - pathname : m[6] || '', - search : m[7] || '', - hash : m[8] || '' - } : null); - }, - - absolutize: function (base, href) { - function removeDotSegments(input) { - var output = []; - input.replace(/^(\.\.?(\/|$))+/, '') - .replace(/\/(\.(\/|$))+/g, '/') - .replace(/\/\.\.$/, '/../') - .replace(/\/?[^\/]*/g, function (p) { - if (p === '/..') { - output.pop(); - } else { - output.push(p); - } - }); - return output.join('').replace(/^\//, input.charAt(0) === '/' ? '/' : ''); - } - - href = URL.parse(href || ''); - base = URL.parse(base || ''); - - return !href || !base ? null : (href.protocol || base.protocol) + - (href.protocol || href.authority ? href.authority : base.authority) + - removeDotSegments(href.protocol || href.authority || href.pathname.charAt(0) === '/' ? href.pathname : (href.pathname ? ((base.authority && !base.pathname ? '/' : '') + base.pathname.slice(0, base.pathname.lastIndexOf('/') + 1) + href.pathname) : base.pathname)) + - (href.protocol || href.authority || href.pathname ? href.search : (href.search || base.search)) + - href.hash; - } - }; -}); \ No newline at end of file diff --git a/client/vendors/bootstrap/affix.js b/client/vendors/bootstrap/affix.js deleted file mode 100755 index c7be96e1..00000000 --- a/client/vendors/bootstrap/affix.js +++ /dev/null @@ -1,126 +0,0 @@ -/* ======================================================================== - * Bootstrap: affix.js v3.0.0 - * http://twbs.github.com/bootstrap/javascript.html#affix - * ======================================================================== - * Copyright 2012 Twitter, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ======================================================================== */ - - -+function ($) { "use strict"; - - // AFFIX CLASS DEFINITION - // ====================== - - var Affix = function (element, options) { - this.options = $.extend({}, Affix.DEFAULTS, options) - this.$window = $(window) - .on('scroll.bs.affix.data-api', $.proxy(this.checkPosition, this)) - .on('click.bs.affix.data-api', $.proxy(this.checkPositionWithEventLoop, this)) - - this.$element = $(element) - this.affixed = - this.unpin = null - - this.checkPosition() - } - - Affix.RESET = 'affix affix-top affix-bottom' - - Affix.DEFAULTS = { - offset: 0 - } - - Affix.prototype.checkPositionWithEventLoop = function () { - setTimeout($.proxy(this.checkPosition, this), 1) - } - - Affix.prototype.checkPosition = function () { - if (!this.$element.is(':visible')) return - - var scrollHeight = $(document).height() - var scrollTop = this.$window.scrollTop() - var position = this.$element.offset() - var offset = this.options.offset - var offsetTop = offset.top - var offsetBottom = offset.bottom - - if (typeof offset != 'object') offsetBottom = offsetTop = offset - if (typeof offsetTop == 'function') offsetTop = offset.top() - if (typeof offsetBottom == 'function') offsetBottom = offset.bottom() - - var affix = this.unpin != null && (scrollTop + this.unpin <= position.top) ? false : - offsetBottom != null && (position.top + this.$element.height() >= scrollHeight - offsetBottom) ? 'bottom' : - offsetTop != null && (scrollTop <= offsetTop) ? 'top' : false - - if (this.affixed === affix) return - if (this.unpin) this.$element.css('top', '') - - this.affixed = affix - this.unpin = affix == 'bottom' ? position.top - scrollTop : null - - this.$element.removeClass(Affix.RESET).addClass('affix' + (affix ? '-' + affix : '')) - - if (affix == 'bottom') { - this.$element.offset({ top: document.body.offsetHeight - offsetBottom - this.$element.height() }) - } - } - - - // AFFIX PLUGIN DEFINITION - // ======================= - - var old = $.fn.affix - - $.fn.affix = function (option) { - return this.each(function () { - var $this = $(this) - var data = $this.data('bs.affix') - var options = typeof option == 'object' && option - - if (!data) $this.data('bs.affix', (data = new Affix(this, options))) - if (typeof option == 'string') data[option]() - }) - } - - $.fn.affix.Constructor = Affix - - - // AFFIX NO CONFLICT - // ================= - - $.fn.affix.noConflict = function () { - $.fn.affix = old - return this - } - - - // AFFIX DATA-API - // ============== - - $(window).on('load', function () { - $('[data-spy="affix"]').each(function () { - var $spy = $(this) - var data = $spy.data() - - data.offset = data.offset || {} - - if (data.offsetBottom) data.offset.bottom = data.offsetBottom - if (data.offsetTop) data.offset.top = data.offsetTop - - $spy.affix(data) - }) - }) - -}(window.jQuery); diff --git a/client/vendors/bootstrap/alert.js b/client/vendors/bootstrap/alert.js deleted file mode 100755 index 663029ed..00000000 --- a/client/vendors/bootstrap/alert.js +++ /dev/null @@ -1,98 +0,0 @@ -/* ======================================================================== - * Bootstrap: alert.js v3.0.0 - * http://twbs.github.com/bootstrap/javascript.html#alerts - * ======================================================================== - * Copyright 2013 Twitter, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ======================================================================== */ - - -+function ($) { "use strict"; - - // ALERT CLASS DEFINITION - // ====================== - - var dismiss = '[data-dismiss="alert"]' - var Alert = function (el) { - $(el).on('click', dismiss, this.close) - } - - Alert.prototype.close = function (e) { - var $this = $(this) - var selector = $this.attr('data-target') - - if (!selector) { - selector = $this.attr('href') - selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') // strip for ie7 - } - - var $parent = $(selector) - - if (e) e.preventDefault() - - if (!$parent.length) { - $parent = $this.hasClass('alert') ? $this : $this.parent() - } - - $parent.trigger(e = $.Event('close.bs.alert')) - - if (e.isDefaultPrevented()) return - - $parent.removeClass('in') - - function removeElement() { - $parent.trigger('closed.bs.alert').remove() - } - - $.support.transition && $parent.hasClass('fade') ? - $parent - .one($.support.transition.end, removeElement) - .emulateTransitionEnd(150) : - removeElement() - } - - - // ALERT PLUGIN DEFINITION - // ======================= - - var old = $.fn.alert - - $.fn.alert = function (option) { - return this.each(function () { - var $this = $(this) - var data = $this.data('bs.alert') - - if (!data) $this.data('bs.alert', (data = new Alert(this))) - if (typeof option == 'string') data[option].call($this) - }) - } - - $.fn.alert.Constructor = Alert - - - // ALERT NO CONFLICT - // ================= - - $.fn.alert.noConflict = function () { - $.fn.alert = old - return this - } - - - // ALERT DATA-API - // ============== - - $(document).on('click.bs.alert.data-api', dismiss, Alert.prototype.close) - -}(window.jQuery); diff --git a/client/vendors/bootstrap/button.js b/client/vendors/bootstrap/button.js deleted file mode 100755 index fc73b555..00000000 --- a/client/vendors/bootstrap/button.js +++ /dev/null @@ -1,109 +0,0 @@ -/* ======================================================================== - * Bootstrap: button.js v3.0.0 - * http://twbs.github.com/bootstrap/javascript.html#buttons - * ======================================================================== - * Copyright 2013 Twitter, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ======================================================================== */ - - -+function ($) { "use strict"; - - // BUTTON PUBLIC CLASS DEFINITION - // ============================== - - var Button = function (element, options) { - this.$element = $(element) - this.options = $.extend({}, Button.DEFAULTS, options) - } - - Button.DEFAULTS = { - loadingText: 'loading...' - } - - Button.prototype.setState = function (state) { - var d = 'disabled' - var $el = this.$element - var val = $el.is('input') ? 'val' : 'html' - var data = $el.data() - - state = state + 'Text' - - if (!data.resetText) $el.data('resetText', $el[val]()) - - $el[val](data[state] || this.options[state]) - - // push to event loop to allow forms to submit - setTimeout(function () { - state == 'loadingText' ? - $el.addClass(d).attr(d, d) : - $el.removeClass(d).removeAttr(d); - }, 0) - } - - Button.prototype.toggle = function () { - var $parent = this.$element.closest('[data-toggle="buttons"]') - - if ($parent.length) { - var $input = this.$element.find('input') - .prop('checked', !this.$element.hasClass('active')) - .trigger('change') - if ($input.prop('type') === 'radio') $parent.find('.active').removeClass('active') - } - - this.$element.toggleClass('active') - } - - - // BUTTON PLUGIN DEFINITION - // ======================== - - var old = $.fn.button - - $.fn.button = function (option) { - return this.each(function () { - var $this = $(this) - var data = $this.data('bs.button') - var options = typeof option == 'object' && option - - if (!data) $this.data('bs.button', (data = new Button(this, options))) - - if (option == 'toggle') data.toggle() - else if (option) data.setState(option) - }) - } - - $.fn.button.Constructor = Button - - - // BUTTON NO CONFLICT - // ================== - - $.fn.button.noConflict = function () { - $.fn.button = old - return this - } - - - // BUTTON DATA-API - // =============== - - $(document).on('click.bs.button.data-api', '[data-toggle^=button]', function (e) { - var $btn = $(e.target) - if (!$btn.hasClass('btn')) $btn = $btn.closest('.btn') - $btn.button('toggle') - e.preventDefault() - }) - -}(window.jQuery); diff --git a/client/vendors/bootstrap/carousel.js b/client/vendors/bootstrap/carousel.js deleted file mode 100755 index d8c4c243..00000000 --- a/client/vendors/bootstrap/carousel.js +++ /dev/null @@ -1,217 +0,0 @@ -/* ======================================================================== - * Bootstrap: carousel.js v3.0.0 - * http://twbs.github.com/bootstrap/javascript.html#carousel - * ======================================================================== - * Copyright 2012 Twitter, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ======================================================================== */ - - -+function ($) { "use strict"; - - // CAROUSEL CLASS DEFINITION - // ========================= - - var Carousel = function (element, options) { - this.$element = $(element) - this.$indicators = this.$element.find('.carousel-indicators') - this.options = options - this.paused = - this.sliding = - this.interval = - this.$active = - this.$items = null - - this.options.pause == 'hover' && this.$element - .on('mouseenter', $.proxy(this.pause, this)) - .on('mouseleave', $.proxy(this.cycle, this)) - } - - Carousel.DEFAULTS = { - interval: 5000 - , pause: 'hover' - , wrap: true - } - - Carousel.prototype.cycle = function (e) { - e || (this.paused = false) - - this.interval && clearInterval(this.interval) - - this.options.interval - && !this.paused - && (this.interval = setInterval($.proxy(this.next, this), this.options.interval)) - - return this - } - - Carousel.prototype.getActiveIndex = function () { - this.$active = this.$element.find('.item.active') - this.$items = this.$active.parent().children() - - return this.$items.index(this.$active) - } - - Carousel.prototype.to = function (pos) { - var that = this - var activeIndex = this.getActiveIndex() - - if (pos > (this.$items.length - 1) || pos < 0) return - - if (this.sliding) return this.$element.one('slid', function () { that.to(pos) }) - if (activeIndex == pos) return this.pause().cycle() - - return this.slide(pos > activeIndex ? 'next' : 'prev', $(this.$items[pos])) - } - - Carousel.prototype.pause = function (e) { - e || (this.paused = true) - - if (this.$element.find('.next, .prev').length && $.support.transition.end) { - this.$element.trigger($.support.transition.end) - this.cycle(true) - } - - this.interval = clearInterval(this.interval) - - return this - } - - Carousel.prototype.next = function () { - if (this.sliding) return - return this.slide('next') - } - - Carousel.prototype.prev = function () { - if (this.sliding) return - return this.slide('prev') - } - - Carousel.prototype.slide = function (type, next) { - var $active = this.$element.find('.item.active') - var $next = next || $active[type]() - var isCycling = this.interval - var direction = type == 'next' ? 'left' : 'right' - var fallback = type == 'next' ? 'first' : 'last' - var that = this - - if (!$next.length) { - if (!this.options.wrap) return - $next = this.$element.find('.item')[fallback]() - } - - this.sliding = true - - isCycling && this.pause() - - var e = $.Event('slide.bs.carousel', { relatedTarget: $next[0], direction: direction }) - - if ($next.hasClass('active')) return - - if (this.$indicators.length) { - this.$indicators.find('.active').removeClass('active') - this.$element.one('slid', function () { - var $nextIndicator = $(that.$indicators.children()[that.getActiveIndex()]) - $nextIndicator && $nextIndicator.addClass('active') - }) - } - - if ($.support.transition && this.$element.hasClass('slide')) { - this.$element.trigger(e) - if (e.isDefaultPrevented()) return - $next.addClass(type) - $next[0].offsetWidth // force reflow - $active.addClass(direction) - $next.addClass(direction) - $active - .one($.support.transition.end, function () { - $next.removeClass([type, direction].join(' ')).addClass('active') - $active.removeClass(['active', direction].join(' ')) - that.sliding = false - setTimeout(function () { that.$element.trigger('slid') }, 0) - }) - .emulateTransitionEnd(600) - } else { - this.$element.trigger(e) - if (e.isDefaultPrevented()) return - $active.removeClass('active') - $next.addClass('active') - this.sliding = false - this.$element.trigger('slid') - } - - isCycling && this.cycle() - - return this - } - - - // CAROUSEL PLUGIN DEFINITION - // ========================== - - var old = $.fn.carousel - - $.fn.carousel = function (option) { - return this.each(function () { - var $this = $(this) - var data = $this.data('bs.carousel') - var options = $.extend({}, Carousel.DEFAULTS, $this.data(), typeof option == 'object' && option) - var action = typeof option == 'string' ? option : options.slide - - if (!data) $this.data('bs.carousel', (data = new Carousel(this, options))) - if (typeof option == 'number') data.to(option) - else if (action) data[action]() - else if (options.interval) data.pause().cycle() - }) - } - - $.fn.carousel.Constructor = Carousel - - - // CAROUSEL NO CONFLICT - // ==================== - - $.fn.carousel.noConflict = function () { - $.fn.carousel = old - return this - } - - - // CAROUSEL DATA-API - // ================= - - $(document).on('click.bs.carousel.data-api', '[data-slide], [data-slide-to]', function (e) { - var $this = $(this), href - var $target = $($this.attr('data-target') || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7 - var options = $.extend({}, $target.data(), $this.data()) - var slideIndex = $this.attr('data-slide-to') - if (slideIndex) options.interval = false - - $target.carousel(options) - - if (slideIndex = $this.attr('data-slide-to')) { - $target.data('bs.carousel').to(slideIndex) - } - - e.preventDefault() - }) - - $(window).on('load', function () { - $('[data-ride="carousel"]').each(function () { - var $carousel = $(this) - $carousel.carousel($carousel.data()) - }) - }) - -}(window.jQuery); diff --git a/client/vendors/bootstrap/collapse.js b/client/vendors/bootstrap/collapse.js deleted file mode 100755 index 92cc0bc7..00000000 --- a/client/vendors/bootstrap/collapse.js +++ /dev/null @@ -1,179 +0,0 @@ -/* ======================================================================== - * Bootstrap: collapse.js v3.0.0 - * http://twbs.github.com/bootstrap/javascript.html#collapse - * ======================================================================== - * Copyright 2012 Twitter, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ======================================================================== */ - - -+function ($) { "use strict"; - - // COLLAPSE PUBLIC CLASS DEFINITION - // ================================ - - var Collapse = function (element, options) { - this.$element = $(element) - this.options = $.extend({}, Collapse.DEFAULTS, options) - this.transitioning = null - - if (this.options.parent) this.$parent = $(this.options.parent) - if (this.options.toggle) this.toggle() - } - - Collapse.DEFAULTS = { - toggle: true - } - - Collapse.prototype.dimension = function () { - var hasWidth = this.$element.hasClass('width') - return hasWidth ? 'width' : 'height' - } - - Collapse.prototype.show = function () { - if (this.transitioning || this.$element.hasClass('in')) return - - var startEvent = $.Event('show.bs.collapse') - this.$element.trigger(startEvent) - if (startEvent.isDefaultPrevented()) return - - var actives = this.$parent && this.$parent.find('> .panel > .in') - - if (actives && actives.length) { - var hasData = actives.data('bs.collapse') - if (hasData && hasData.transitioning) return - actives.collapse('hide') - hasData || actives.data('bs.collapse', null) - } - - var dimension = this.dimension() - - this.$element - .removeClass('collapse') - .addClass('collapsing') - [dimension](0) - - this.transitioning = 1 - - var complete = function () { - this.$element - .removeClass('collapsing') - .addClass('in') - [dimension]('auto') - this.transitioning = 0 - this.$element.trigger('shown.bs.collapse') - } - - if (!$.support.transition) return complete.call(this) - - var scrollSize = $.camelCase(['scroll', dimension].join('-')) - - this.$element - .one($.support.transition.end, $.proxy(complete, this)) - .emulateTransitionEnd(350) - [dimension](this.$element[0][scrollSize]) - } - - Collapse.prototype.hide = function () { - if (this.transitioning || !this.$element.hasClass('in')) return - - var startEvent = $.Event('hide.bs.collapse') - this.$element.trigger(startEvent) - if (startEvent.isDefaultPrevented()) return - - var dimension = this.dimension() - - this.$element - [dimension](this.$element[dimension]()) - [0].offsetHeight - - this.$element - .addClass('collapsing') - .removeClass('collapse') - .removeClass('in') - - this.transitioning = 1 - - var complete = function () { - this.transitioning = 0 - this.$element - .trigger('hidden.bs.collapse') - .removeClass('collapsing') - .addClass('collapse') - } - - if (!$.support.transition) return complete.call(this) - - this.$element - [dimension](0) - .one($.support.transition.end, $.proxy(complete, this)) - .emulateTransitionEnd(350) - } - - Collapse.prototype.toggle = function () { - this[this.$element.hasClass('in') ? 'hide' : 'show']() - } - - - // COLLAPSE PLUGIN DEFINITION - // ========================== - - var old = $.fn.collapse - - $.fn.collapse = function (option) { - return this.each(function () { - var $this = $(this) - var data = $this.data('bs.collapse') - var options = $.extend({}, Collapse.DEFAULTS, $this.data(), typeof option == 'object' && option) - - if (!data) $this.data('bs.collapse', (data = new Collapse(this, options))) - if (typeof option == 'string') data[option]() - }) - } - - $.fn.collapse.Constructor = Collapse - - - // COLLAPSE NO CONFLICT - // ==================== - - $.fn.collapse.noConflict = function () { - $.fn.collapse = old - return this - } - - - // COLLAPSE DATA-API - // ================= - - $(document).on('click.bs.collapse.data-api', '[data-toggle=collapse]', function (e) { - var $this = $(this), href - var target = $this.attr('data-target') - || e.preventDefault() - || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '') //strip for ie7 - var $target = $(target) - var data = $target.data('bs.collapse') - var option = data ? 'toggle' : $this.data() - var parent = $this.attr('data-parent') - var $parent = parent && $(parent) - - if (!data || !data.transitioning) { - if ($parent) $parent.find('[data-toggle=collapse][data-parent="' + parent + '"]').not($this).addClass('collapsed') - $this[$target.hasClass('in') ? 'addClass' : 'removeClass']('collapsed') - } - - $target.collapse(option) - }) - -}(window.jQuery); diff --git a/client/vendors/bootstrap/dropdown.js b/client/vendors/bootstrap/dropdown.js deleted file mode 100755 index 6093f11a..00000000 --- a/client/vendors/bootstrap/dropdown.js +++ /dev/null @@ -1,154 +0,0 @@ -/* ======================================================================== - * Bootstrap: dropdown.js v3.0.0 - * http://twbs.github.com/bootstrap/javascript.html#dropdowns - * ======================================================================== - * Copyright 2012 Twitter, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ======================================================================== */ - - -+function ($) { "use strict"; - - // DROPDOWN CLASS DEFINITION - // ========================= - - var backdrop = '.dropdown-backdrop' - var toggle = '[data-toggle=dropdown]' - var Dropdown = function (element) { - var $el = $(element).on('click.bs.dropdown', this.toggle) - } - - Dropdown.prototype.toggle = function (e) { - var $this = $(this) - - if ($this.is('.disabled, :disabled')) return - - var $parent = getParent($this) - var isActive = $parent.hasClass('open') - - clearMenus() - - if (!isActive) { - if ('ontouchstart' in document.documentElement && !$parent.closest('.navbar-nav').length) { - // if mobile we we use a backdrop because click events don't delegate - $('