Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shell panel rewrite - Phase 1 #42

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
14 changes: 14 additions & 0 deletions .jslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"node": true,
"nomen": true,
"regexp": true,
"todo": true,
"vars": true,
"unparam": true,
"globals": {
"$": true,
"document": true,
"brackets": true,
"define": true
}
}
7 changes: 7 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ module.exports = function(grunt) {
src: ["**/*"],
dest: "node/node_modules/tree-kill/",
filter: "isFile"
},
{
expand: true,
cwd: "node_modules/ansi-webkit/",
src: ["**/*"],
dest: "node/node_modules/ansi-webkit/",
filter: "isFile"
}
]
}
Expand Down
Binary file removed images/hdy.brackets.shell.logo.png
Binary file not shown.
20 changes: 20 additions & 0 deletions images/hdy.brackets.shell.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed images/hdy.brackets.shell.toolbar.on.png
Binary file not shown.
Binary file removed images/hdy.brackets.shell.toolbar.png
Binary file not shown.
103 changes: 52 additions & 51 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,67 +1,68 @@
/*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true,
indent: 4, maxerr: 50 */
/*global define, $, brackets */
/*global define, brackets */

define(function (require, exports, module) {
"use strict";

var AppInit = brackets.getModule("utils/AppInit"),
ExtensionUtils = brackets.getModule("utils/ExtensionUtils"),
ProjectManager = brackets.getModule("project/ProjectManager"),
PreferencesManager = brackets.getModule("preferences/PreferencesManager"),
Preferences = PreferencesManager.getExtensionPrefs("hdy.brackets-shell"),
$icon = $("<a class='hdy-shell-icon' href='#'> </a>")
.attr("title", "Shell")
.appendTo($("#main-toolbar .buttons"));
var ExtensionUtils = brackets.getModule("utils/ExtensionUtils"),

Application = require("application"),
OnlineUsers = require("online");

// Default theme if not defined
if(Preferences.get("dark") === undefined) {
Preferences.definePreference("dark", "boolean", false);
Preferences.set("dark", false);
Preferences.save();
}

// Default projectTracking if not defined
if(Preferences.get("trackProject") === undefined) {
Preferences.definePreference("trackProject", "boolean", true);
Preferences.set("trackProject", true);
Preferences.save();
}

if(Preferences.get("shell") === undefined) {
Preferences.definePreference("shell", "string", "cmd.exe");
if (brackets.platform === "win") {
Preferences.set("shell", "cmd.exe");
} else {
Preferences.set("shell", "/bin/sh");
}
Preferences.save();
}
ExtensionUtils.loadStyleSheet(module, "styles/bracketsShell.less");

AppInit.appReady(function () {
Application.boot();

var projectWatcher = require("projectWatcher"),
commandShell = require("shellPanel");
OnlineUsers.init();

require('./online').init();

ExtensionUtils.loadStyleSheet(module, "styles/shellPanel.css");
$icon.on("click", commandShell.toggle);

commandShell.hide();
commandShell.setDirectory(projectWatcher.cleanPath(ProjectManager.getProjectRoot().fullPath));
// Default theme if not defined
// if(Preferences.get("dark") === undefined) {
// Preferences.definePreference("dark", "boolean", false);
// Preferences.set("dark", false);
// Preferences.save();
// }

if (Preferences.get("trackProject")) {
projectWatcher.register(function(cwd) {
if (cwd) {
commandShell.setDirectory(cwd);
}
});
}
// Default projectTracking if not defined
// if(Preferences.get("trackProject") === undefined) {
// Preferences.definePreference("trackProject", "boolean", true);
// Preferences.set("trackProject", true);
// Preferences.save();
// }

projectWatcher.watch();
// if(Preferences.get("shell") === undefined) {
// Preferences.definePreference("shell", "string", "cmd.exe");
// if (brackets.platform === "win") {
// Preferences.set("shell", "cmd.exe");
// } else {
// Preferences.set("shell", "/bin/sh");
// }
// Preferences.save();
// }

});
// AppInit.appReady(function () {
//
// var projectWatcher = require("projectWatcher"),
// ShellPanelView = require("views/shellPanelView"),
// commandShell = new ShellPanelView("My Title", projectWatcher.cleanPath(ProjectManager.getProjectRoot().fullPath));
//
// require('./online').init();
//
// ExtensionUtils.loadStyleSheet(module, "styles/shellPanel.css");
// $icon.on("click", commandShell.toggle);
//
// commandShell.hide();
//
// if (Preferences.get("trackProject")) {
// projectWatcher.register(function(cwd) {
// if (cwd) {
// commandShell.cwd = cwd;
// }
// });
// }
//
// projectWatcher.watch();
//
// });

});
50 changes: 50 additions & 0 deletions modules/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true,
indent: 4, maxerr: 50 */
/*global define, brackets */

define(function (require, exports, module) {
"use strict";

var Menus = brackets.getModule("command/Menus"),

Strings = require("strings"),
MenuItem = require("menuItem"),
CommandId = require("commandId"),
ExtensionBarButton = require("extensionBarButton"),
Panel = require("panel"),
PanelState = require("panelState"),
Tabs = require("tabs"),

_viewShellMenuItem,
_viewShellButton,
_panel,
_tabs;

module.exports.boot = function() {

_panel = new Panel("hdy-brackets-shell-panel",
Strings.APPLICATION_TITLE,
"shellTemplate",
PanelState.Closed);

_viewShellButton = new ExtensionBarButton("hdy-shell-toolbar-icon",
Strings.TOOLTIP_TOOLBAR_ICON);

_viewShellMenuItem = new MenuItem(CommandId.VIEW_SHELL_COMMAND,
Strings.MENU_VIEW_SHELL,
Menus.AppMenuBar.VIEW_MENU,
Menus.LAST_IN_SECTION,
Menus.MenuSection.VIEW_HIDESHOW_COMMANDS);

_tabs = new Tabs("hdy-brackets-shell-tabs", "tabsTemplate");

_panel.register(_viewShellButton);
_panel.register(_viewShellMenuItem);
_panel.controls.push(_tabs);

_panel.draw();


};

});
14 changes: 14 additions & 0 deletions modules/commandId.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true,
indent: 4, maxerr: 50 */
/*global define */

define(function (require, exports, module) {
"use strict";

module.exports = {

"VIEW_SHELL_COMMAND": "hdy.brackets.shell"

};

});
45 changes: 45 additions & 0 deletions modules/control.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true,
indent: 4, maxerr: 50 */
/*global define */

define(function (require, exports, module) {
"use strict";

var Control = function(id) {

this.children = [];
this.id = id;

};

Control.prototype = {

add: function (child) {

this.children.push(child);

},

remove: function (child) {

var length = this.children.length;
for (var i = 0; i < length; i++) {
if (this.children[i] === child) {
this.children.splice(i, 1);
return;
}
}
},

getChild: function (i) {
return this.children[i];
},

hasChildren: function () {
return this.children.length > 0;
}
};

module.exports = Control;

});
16 changes: 16 additions & 0 deletions modules/exception.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true,
indent: 4, maxerr: 50 */
/*global define */

define(function (require, exports, module) {
"use strict";

var Exception = function(message) {

this.message = "hdyException: " + message;

};

module.exports = Exception;

});
43 changes: 43 additions & 0 deletions modules/extensionBarButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true,
indent: 4, maxerr: 50 */
/*global define, $ */

define(function (require, exports, module) {
"use strict";

var PanelState = require("panelState");

function ExtensionBarButton(id, tooltip) {

var self = this,
_state = PanelState.Closed;

self.id = id;
self.panel = undefined;
self.$icon = $("<a id='" + id + "' href='#'></a>")
.attr("title", tooltip);
self.$icon.appendTo($("#main-toolbar .buttons"));

self.setState = function(state) {

_state = state;
self.$icon.removeClass();
self.$icon.addClass(state);

};

self.$icon.on("click", function() {

var state = (_state === PanelState.Closed) ? PanelState.Open : PanelState.Closed;

if (self.panel) {
self.panel.setState(state);
}
});

}

module.exports = ExtensionBarButton;

});

43 changes: 43 additions & 0 deletions modules/menuItem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true,
indent: 4, maxerr: 50 */
/*global define, brackets */

define(function (require, exports, module) {
"use strict";

var CommandManager = brackets.getModule("command/CommandManager"),
Menus = brackets.getModule("command/Menus"),

PanelState = require("panelState");

function MenuItem(id, name, menu, position, section) {

var self = this,
_command,
_commandCallback = function() {

var state = !_command.getChecked() ? PanelState.Open : PanelState.Closed;

if (self.panel) {
self.panel.setState(state);
}

};

self.id = id;
self.panel = undefined;
self.setState = function(state) {

_command.setChecked(state === PanelState.Open);

};

_command = CommandManager.register(name, id, _commandCallback);
var viewMenu = Menus.getMenu(menu);
viewMenu.addMenuItem(id, "F4", position, section);

}

module.exports = MenuItem;

});