-
-
Notifications
You must be signed in to change notification settings - Fork 194
Expand file tree
/
Copy pathHelpCommandHandlers.js
More file actions
182 lines (159 loc) · 8.58 KB
/
HelpCommandHandlers.js
File metadata and controls
182 lines (159 loc) · 8.58 KB
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/*
* GNU AGPL-3.0 License
*
* Copyright (c) 2021 - present core.ai . All rights reserved.
* Original work Copyright (c) 2012 - 2021 Adobe Systems Incorporated. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
* for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://opensource.org/licenses/AGPL-3.0.
*
*/
define(function (require, exports, module) {
var AppInit = require("utils/AppInit"),
BuildInfoUtils = require("utils/BuildInfoUtils"),
CommandManager = require("command/CommandManager"),
Commands = require("command/Commands"),
Dialogs = require("widgets/Dialogs"),
FileUtils = require("file/FileUtils"),
NativeApp = require("utils/NativeApp"),
Strings = require("strings"),
StringUtils = require("utils/StringUtils"),
ManageLicenses = require("services/manage-licenses"),
AboutDialogTemplate = require("text!htmlContent/about-dialog.html"),
ContributorsTemplate = require("text!htmlContent/contributors-list.html"),
Mustache = require("thirdparty/mustache/mustache");
// make sure the global brackets variable is loaded
require("utils/Global");
/**
* This is the thirdparty API's (GitHub) maximum contributors per page limit
* @const {number}
*/
var CONTRIBUTORS_PER_PAGE = 100;
var buildInfo;
function _handleLinkMenuItem(url) {
return function () {
if (!url) {
return;
}
NativeApp.openURLInDefaultBrowser(url);
};
}
function _handleShowExtensionsFolder() {
brackets.app.showExtensionsFolder(
FileUtils.convertToNativePath(decodeURI(window.location.href)),
function (err) {} /* Ignore errors */
);
}
function _handleAboutDialog() {
var templateVars = {
ABOUT_ICON: brackets.config.about_icon,
APP_NAME_ABOUT_BOX: brackets.config.app_name_about,
BUILD_TIMESTAMP: brackets.config.build_timestamp,
BUILD_INFO: buildInfo || "",
Strings: Strings
};
Dialogs.showModalDialogUsingTemplate(Mustache.render(AboutDialogTemplate, templateVars));
// Get containers
var $dlg = $(".about-dialog.instance"),
$contributors = $dlg.find(".about-contributors"),
$spinner = $dlg.find(".spinner"),
contributorsUrl = brackets.config.contributors_url,
page;
if (contributorsUrl.indexOf("{1}") !== -1) { // pagination enabled
page = 1;
}
$spinner.addClass("spin");
function loadContributors(rawUrl, page, contributors, deferred) {
deferred = deferred || new $.Deferred();
contributors = contributors || [];
var url = StringUtils.format(rawUrl, CONTRIBUTORS_PER_PAGE, page);
$.ajax({
url: url,
dataType: "json",
cache: false
})
.done(function (response) {
contributors = contributors.concat(response || []);
if (page && response.length === CONTRIBUTORS_PER_PAGE) {
loadContributors(rawUrl, page + 1, contributors, deferred);
} else {
deferred.resolve(contributors);
}
})
.fail(function () {
if (contributors.length) { // we weren't able to fetch this page, but previous fetches were successful
deferred.resolve(contributors);
} else {
deferred.reject();
}
});
return deferred.promise();
}
loadContributors(contributorsUrl, page) // Load the contributors
.done(function (allContributors) {
// Populate the contributors data
var totalContributors = allContributors.length,
contributorsCount = 0;
allContributors.forEach(function (contributor) {
// remove any UrlParams delivered via the GitHub API
contributor.avatar_url = contributor.avatar_url.split("?")[0];
});
$contributors.html(Mustache.render(ContributorsTemplate, allContributors));
// This is used to create an opacity transition when each image is loaded
$contributors.find("img").one("load", function () {
$(this).css("opacity", 1);
// Count the contributors loaded and hide the spinner once all are loaded
contributorsCount++;
if (contributorsCount >= totalContributors) {
$spinner.removeClass("spin");
}
}).each(function () {
if (this.complete) {
$(this).trigger("load");
}
});
})
.fail(function () {
$spinner.removeClass("spin");
$contributors.html(Mustache.render("<p class='dialog-message'>{{ABOUT_TEXT_LINE6}}</p>", Strings));
});
}
// Read "build number" SHAs off disk immediately at APP_READY, instead
// of later, when they may have been updated to a different version
AppInit.appReady(function () {
BuildInfoUtils.getBracketsSHA().done(function (branch, sha, isRepo) {
// If we've successfully determined a "build number" via .git metadata, add it to dialog
sha = sha ? sha.substr(0, 9) : "";
if (branch || sha) {
buildInfo = StringUtils.format("({0} {1})", branch, sha).trim();
}
});
});
const getProString = `${Strings.CMD_GET_PRO}<i class='fa fa-feather' style='margin-left: 4px;'></i>`;
CommandManager.register(Strings.CMD_HOW_TO_USE_BRACKETS, Commands.HELP_HOW_TO_USE_BRACKETS, _handleLinkMenuItem(brackets.config.how_to_use_url));
CommandManager.register(Strings.CMD_DOCS, Commands.HELP_DOCS, _handleLinkMenuItem(brackets.config.docs_url));
CommandManager.register(Strings.CMD_SUPPORT, Commands.HELP_SUPPORT, _handleLinkMenuItem(brackets.config.support_url));
CommandManager.register(Strings.CMD_GET_PRO, Commands.HELP_GET_PRO, _handleLinkMenuItem(brackets.config.purchase_url), {
htmlName: getProString
});
CommandManager.register(Strings.CMD_MANAGE_LICENSES, Commands.HELP_MANAGE_LICENSES, ManageLicenses.showManageLicensesDialog);
CommandManager.register(Strings.CMD_SUGGEST, Commands.HELP_SUGGEST, _handleLinkMenuItem(brackets.config.suggest_feature_url));
CommandManager.register(Strings.CMD_REPORT_ISSUE, Commands.HELP_REPORT_ISSUE, _handleLinkMenuItem(brackets.config.report_issue_url));
CommandManager.register(Strings.CMD_RELEASE_NOTES, Commands.HELP_RELEASE_NOTES, _handleLinkMenuItem(brackets.config.release_notes_url));
CommandManager.register(Strings.CMD_GET_INVOLVED, Commands.HELP_GET_INVOLVED, _handleLinkMenuItem(brackets.config.get_involved_url));
CommandManager.register(Strings.CMD_SHOW_EXTENSIONS_FOLDER, Commands.HELP_SHOW_EXT_FOLDER, _handleShowExtensionsFolder);
CommandManager.register(Strings.CMD_HOMEPAGE, Commands.HELP_HOMEPAGE, _handleLinkMenuItem(brackets.config.homepage_url));
CommandManager.register(Strings.CMD_TWITTER, Commands.HELP_TWITTER, _handleLinkMenuItem(brackets.config.twitter_url));
CommandManager.register(Strings.CMD_YOUTUBE, Commands.HELP_YOUTUBE, _handleLinkMenuItem(brackets.config.youtube_url));
CommandManager.register(Strings.CMD_ABOUT, Commands.HELP_ABOUT, _handleAboutDialog);
});