-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
131 lines (115 loc) · 4.63 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
define(function (require, exports, module) {
"use strict";
var AppInit = brackets.getModule("utils/AppInit"),
ExtensionUtils = brackets.getModule("utils/ExtensionUtils"),
WorkspaceManager = brackets.getModule("view/WorkspaceManager"),
Mustache = brackets.getModule("thirdparty/mustache/mustache"),
panelsContainerHtml = require("text!src/htmlContent/panels-container.html"),
panelHeaderHtml = require("text!src/htmlContent/panel-header.html"),
PANEL_ID = "brackets-panels-hack",
ID_PREFIX = "tab-";
var container = Mustache.render(panelsContainerHtml),
$container = $(container);
function hideAll() {
var ids = WorkspaceManager.getAllPanelIDs();
ids.forEach(function (id) {
var panel = WorkspaceManager.getPanelForID(id);
if (panel.isVisible()) {
panel.hide();
}
});
}
function hijack(panel, panelId, tabId) {
var $panel = panel.$panel;
var title = $panel.find(".toolbar.simple-toolbar-layout > .title").text();
if (!title) {
title = panelId.replace(/(?:brackets\W?)|\Wpanel$/g, "");
title = title.substring(title.lastIndexOf(".") + 1);
}
var header = Mustache.render(panelHeaderHtml, {
tabId: tabId,
panelId: panelId,
title: title
}),
$header = $(header);
var panelShow = panel.show;
panel.show = function () {
hideAll();
$header.addClass("active");
return panelShow.apply(panel, arguments);
};
var panelHide = panel.hide;
panel.hide = function () {
$header.removeClass("active");
return panelHide.apply(panel, arguments);
};
$header.find("a").on("click", function () {
if (panel.isVisible()) {
panel.hide();
} else {
hideAll();
panel.show();
}
});
$container.find(".nav-tabs").append($header);
panel.$panel.insertBefore("#" + PANEL_ID);
}
AppInit.htmlReady(function () {
ExtensionUtils.loadStyleSheet(module, "src/styles/nav-tabs-override.less");
ExtensionUtils.loadStyleSheet(module, "src/styles/style.css");
$container.insertBefore("#status-bar");
var codeHintID = "errors",
codeHintPanel = WorkspaceManager.getPanelForID(codeHintID),
codeHintShow = $("#problems-panel").data("show"),
codeHintHide = $("#problems-panel").data("hide");
$("#problems-panel").data("show", function () {
hideAll();
var $header = $container.find(".nav-tabs #" + ID_PREFIX + "code-hints");
$header.addClass("active");
return codeHintShow.apply(null, arguments);
});
$("#problems-panel").data("hide", function () {
var $header = $container.find(".nav-tabs #" + ID_PREFIX + "code-hints");
$header.removeClass("active");
return codeHintHide.apply(null, arguments);
});
hijack(codeHintPanel, "Code Hints", ID_PREFIX + "code-hints");
$("#status-inspection").insertBefore("#" + PANEL_ID + " #" + ID_PREFIX + "code-hints > a > p");
var searchID = "find-in-files.results",
searchPanel = WorkspaceManager.getPanelForID(searchID);
hijack(searchPanel, "Search", ID_PREFIX + "search");
var createBottomPanel = WorkspaceManager.createBottomPanel;
WorkspaceManager.createBottomPanel = function (id, $panel, height) {
var panel = createBottomPanel.apply(null, [id, $panel, undefined]);
hijack(panel, id, ID_PREFIX + id);
return panel;
};
});
var iconCSS = {
width: "24px",
height: "18px",
display: "block",
padding: 0,
"mix-blend-mode": "difference",
"background-position": "-3px -3px"
};
function tryMoveIcon(panelId, iconId) {
var icon = $("#main-toolbar .buttons #" + iconId);
if (!icon || !icon.length) {
return false;
}
icon.css(iconCSS);
icon.insertBefore("#" + PANEL_ID + " #" + ID_PREFIX + panelId + " > a > p");
return true;
}
AppInit.appReady(function () {
var ids = WorkspaceManager.getAllPanelIDs();
ids.forEach(function (panelId) {
var iconId = panelId + "-icon";
if (!tryMoveIcon(panelId, iconId)) {
var iconId = panelId.replace(/panel$/, "icon");
tryMoveIcon(panelId, iconId);
}
});
});
});