forked from spocke/php-debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
150 lines (127 loc) · 3.98 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/**
* Main model for the brackets plugin.
*/
define(function(require, exports, module) {
var ExtensionUtils = brackets.getModule("utils/ExtensionUtils"),
panel = require('./lib/panel'),
console = require('./lib/console'),
xdebug = require('./lib/xdebug'),
commands = require('./lib/commands'),
tree = require('./lib/tree'),
editor = require('./lib/editor'),
Menus = brackets.getModule("command/Menus"),
AppInit = brackets.getModule("utils/AppInit"),
CommandManager = brackets.getModule("command/CommandManager"),
NodeDomain = brackets.getModule("utils/NodeDomain"),
EditorManager = brackets.getModule("editor/EditorManager"),
PreferencesManager = brackets.getModule("preferences/PreferencesManager");
var moduleName = "php-debugger";
var nodeDomain = new NodeDomain(moduleName, ExtensionUtils.getModulePath(module, "./node/main"));
var TOGGLE_PANEL_CMD = moduleName + ".togglePanel";
var TOGGLE_BREAKPOINT_CMD = moduleName + ".toggleBreakPoint";
CommandManager.register("PHP Debugger", TOGGLE_PANEL_CMD, commands.toggle.bind(commands));
CommandManager.register("Toggle Breakpoint", TOGGLE_BREAKPOINT_CMD, function() {
var editor = EditorManager.getCurrentFullEditor();
var selection = editor.getSelection();
commands.toggleBreakPoint({
line: selection.start.line
});
});
var menu = Menus.getMenu(Menus.AppMenuBar.VIEW_MENU);
menu.addMenuItem(TOGGLE_PANEL_CMD);
var stateManager = PreferencesManager.stateManager.getPrefixedSystem(moduleName);
ExtensionUtils.loadStyleSheet(module, "main.less");
var prefs = PreferencesManager.getExtensionPrefs(moduleName);
var contextMenu = Menus.getContextMenu(Menus.ContextMenuIds.EDITOR_MENU);
contextMenu.addMenuItem(TOGGLE_BREAKPOINT_CMD);
function initKeyboardOverride() {
// Override keys only when the debugger is connected
$(document).on('keydown keypress', function(e) {
if (!xdebug.isConnected()) {
return;
}
switch (e.keyCode) {
case 121: // F11
e.preventDefault();
commands.step_over();
break;
case 122: // F12
e.preventDefault();
commands.step_into();
break;
}
});
}
function initSideBar() {
var $icon = $('<a href="#" id="phpdebugger-sidebar-icon" title="PHP Debugger"></a>');
$icon.appendTo($("#main-toolbar .buttons"));
$icon.on('click', function() {
commands.toggle();
});
}
function initModules() {
panel.init();
console.init({
debug: prefs.get('debug')
});
xdebug.init({
nodeDomain: nodeDomain,
port: prefs.get('port'),
idekey: prefs.get('idekey'),
debug: prefs.get('debug')
});
commands.init();
tree.init();
editor.init();
}
function bindEvents() {
$(editor).on('change', function() {
commands.stop();
});
$(editor).on('breakPointAdded', function(e, breakPoint) {
if (xdebug.isConnected()) {
return xdebug.execute("breakpoint_set", {
t: "line",
n: breakPoint.line + 1,
f: breakPoint.fullPath
}).done(function($elm) {
breakPoint.serverId = $elm.attr('id');
});
}
});
$(editor).on('breakPointRemoved', function(e, breakPoint) {
if (xdebug.isConnected()) {
return xdebug.execute("breakpoint_remove", {
d: breakPoint.serverId
});
}
});
$(panel).on('cmd', function(e, data) {
var cmdFunc = commands[data.cmd];
if (cmdFunc) {
cmdFunc(data.args, data.elm);
} else {
console.log("Error: " + data.cmd + " not found.");
}
});
$(panel).on('stateChange', function(e, state) {
stateManager.set('panelVisibility', state);
CommandManager.get(TOGGLE_PANEL_CMD).setChecked(state);
CommandManager.get(TOGGLE_BREAKPOINT_CMD).setEnabled(state);
$('#phpdebugger-sidebar-icon').toggleClass("phpdebugger-sidebar-icon-active", state);
});
}
function handleViewState() {
var visibleState = stateManager.get('panelVisibility');
if (visibleState || typeof visibleState == "undefined") {
commands.open();
}
}
AppInit.appReady(function() {
initKeyboardOverride();
initModules();
bindEvents();
initSideBar();
handleViewState();
});
});