forked from yacut/brackets-nodejs-integration
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
117 lines (106 loc) · 3.57 KB
/
utils.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
/*global brackets,$*/
'use strict';
define(function (require, exports) {
var file_system = brackets.getModule('filesystem/FileSystem');
exports.mkdirp = function (path) {
var dir = file_system.getDirectoryForPath(path);
var promise = $.Deferred();
dir.exists(function (dir_exists_err, exists) {
if (dir_exists_err) {
console.error(dir_exists_err);
}
if (!exists) {
var parentFolder = path.replace(/\/+\s*$/, '').split('/').slice(0, -1).join('/');
exports.mkdirp(parentFolder).then(function () {
dir.create(function (err) {
if (err) {
promise.reject(err);
}
else {
promise.resolve();
}
});
})
.fail(function (err) {
promise.reject(err);
});
}
else {
promise.resolve();
}
});
return promise;
};
exports.create_file = function (file, content) {
var promise = $.Deferred();
file.write(content, {}, function (err) {
if (err) {
promise.reject(err);
}
else {
promise.resolve();
}
});
return promise;
};
function get_merge_view_height(merge_view) {
function editorHeight(editor) {
if (!editor) {
return 0;
}
return editor.getScrollInfo().height;
}
return Math.max(editorHeight(merge_view.leftOriginal()),
editorHeight(merge_view.editor()),
editorHeight(merge_view.rightOriginal()));
}
exports.resize_merge_view = function (merge_view) {
var height = get_merge_view_height(merge_view);
for (;;) {
if (merge_view.leftOriginal()) {
merge_view.leftOriginal().setSize(null, height);
}
merge_view.editor().setSize(null, height);
if (merge_view.rightOriginal()) {
merge_view.rightOriginal().setSize(null, height);
}
var new_height = get_merge_view_height(merge_view);
if (new_height >= height) {
break;
}
else {
height = new_height;
}
}
merge_view.wrap.style.height = height + 'px';
};
exports.show_popup_message = function (message, disable_auto_hide) {
var _$indicator = $('#brackets-nodejs-integration-runner-indicator');
_$indicator.twipsy('hide').removeData('twipsy');
var options = {
placement: 'left',
trigger: 'manual',
autoHideDelay: 5000,
title: function () {
return message;
}
};
_$indicator.twipsy(options).twipsy('show');
if (!disable_auto_hide) {
setTimeout(function () {
if (_$indicator.data('twipsy')) {
_$indicator.twipsy('hide').removeData('twipsy');
}
}, 5000);
}
};
exports.uuid = function () {
function s4() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
}
return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
s4() + '-' + s4() + s4() + s4();
};
});