Skip to content

Commit f400ad3

Browse files
author
FezVrasta
committed
Added Git-FTP init support.
1 parent 5be6e34 commit f400ad3

5 files changed

Lines changed: 94 additions & 61 deletions

File tree

less/brackets-git.less

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@
240240
display: inline-block;
241241
width: 100%;
242242
}
243-
.trash-icon {
243+
.trash-icon, .gitftp-init-remote {
244244
opacity: 0;
245245
background-image: none !important;
246246
width: 16px;
@@ -254,7 +254,12 @@
254254
font-weight: bold;
255255
}
256256
}
257-
&:hover .trash-icon {
257+
.gitftp-init-remote {
258+
position: relative;
259+
top: 2px;
260+
right: 4px;
261+
}
262+
&:hover .trash-icon, &:hover .gitftp-init-remote {
258263
opacity: 1;
259264
}
260265
}

nls/root/strings.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ define({
3535
CLONE_REPOSITORY: "Clone repository",
3636
CREATE_NEW_BRANCH: "Create new branch\u2026",
3737
CREATE_NEW_REMOTE: "Create new remote\u2026",
38-
CREATE_NEW_GITFTP_REMOTE: "Create new Git-FTP remote\u2026",
38+
CREATE_NEW_GITFTP_SCOPE: "Create new Git-FTP remote\u2026",
3939
CUSTOM_TERMINAL_COMMAND: "Custom terminal command (sample: gnome-terminal or complete path to executable)",
4040
CUSTOM_TERMINAL_COMMAND_HINT: "Sample arguments: --window --working-directory=$1<br>$1 in arguments will be replaced by current project directory.",
4141
DATE_FORMAT: "YYYY-MM-DD HH:mm:ss",
@@ -57,9 +57,9 @@ define({
5757
ENTER_USERNAME: "Enter username:",
5858
ENTER_REMOTE_GIT_URL: "Enter Git URL of the repository you want to clone:",
5959
ENTER_REMOTE_NAME: "Enter name of the new remote:",
60-
ENTER_GITFTP_REMOTE_NAME: "Enter name of the new Git-FTP remote:",
60+
ENTER_GITFTP_SCOPE_NAME: "Enter name of the new Git-FTP remote:",
6161
ENTER_REMOTE_URL: "Enter URL of the new remote:",
62-
ENTER_GITFTP_REMOTE_URL: "Enter FTP URL of the new Git-FTP remote specifing username and password:",
62+
ENTER_GITFTP_SCOPE_URL: "Enter FTP URL of the new Git-FTP remote specifing username and password:",
6363
ERROR_TERMINAL_NOT_FOUND: "Terminal was not found for your OS, you can define a custom Terminal command in the settings",
6464
EXTENDED_COMMIT_MESSAGE: "EXTENDED",
6565
EXTENSION_WAS_UPDATED_TITLE: "The extension was updated to {0}",
@@ -84,10 +84,11 @@ define({
8484
GITFTP_PUSH_RESPONSE: "Git-FTP Push response",
8585
GIT_SETTINGS: "Git Settings\u2026",
8686
GIT_REMOTES: "Git remotes",
87-
GITFTP_REMOTES: "Git-FTP remotes",
87+
GITFTP_SCOPES: "Git-FTP remotes",
8888
GOTO_PREVIOUS_GIT_CHANGE: "Go to previous Git change",
8989
GOTO_NEXT_GIT_CHANGE: "Go to next Git change",
90-
INIT_GITFTP_REMOTE_NAME: "Initialize Git-FTP remote \"{0}\"?",
90+
INIT_GITFTP_SCOPE: "Initialize Git-FTP remote",
91+
INIT_GITFTP_SCOPE_NAME: "Initialize Git-FTP remote \"{0}\"?",
9192
LAUNCH_BASH_SHORTCUT: "Bash/Terminal shortcut",
9293
LOADING: "Loading\u2026",
9394
LINES: "Lines",

src/Ftp/Ftp.js

Lines changed: 69 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,17 @@ define(function (require) {
1616
GitFtp = require("./GitFtp");
1717

1818
// Module variables
19-
var ftpRemotesTemplate = require("text!src/Ftp/templates/remotes-picker.html"),
19+
var ftpScopesTemplate = require("text!src/Ftp/templates/remotes-picker.html"),
2020
$gitPanel = null,
2121
$remotesDropdown = null;
2222

2323
// Implementation
2424

2525
var attachEvents = _.once(function () {
2626
$gitPanel
27-
.on("click", ".gitftp-remote-new", handleGitFtpRemoteCreation)
28-
.on("click", ".gitftp-remove-remote", function () { handleGitFtpRemoteRemove($(this)); })
27+
.on("click", ".gitftp-remote-new", handleGitFtpScopeCreation)
28+
.on("click", ".gitftp-remove-remote", function () { handleGitFtpScopeRemove($(this)); })
29+
.on("click", ".gitftp-init-remote", function () { handleGitFtpInitScope($(this)); })
2930
.on("click", ".gitftp-push", handleGitFtpPush);
3031
});
3132

@@ -38,10 +39,10 @@ define(function (require) {
3839
}
3940

4041
function handleGitFtpPush() {
41-
var gitFtpRemote = $gitPanel.find(".git-remote-selected").text().trim();
42+
var gitFtpScope = $gitPanel.find(".git-remote-selected").text().trim();
4243
$gitPanel.find(".gitftp-push").prop("disabled", true).addClass("btn-loading");
4344

44-
GitFtp.push(gitFtpRemote).done(function (result) {
45+
GitFtp.push(gitFtpScope).done(function (result) {
4546
Dialogs.showModalDialog(
4647
DefaultDialogs.DIALOG_ID_INFO,
4748
Strings.GITFTP_PUSH_RESPONSE, // title
@@ -56,42 +57,42 @@ define(function (require) {
5657
});
5758
}
5859

59-
function handleGitFtpRemoteCreation() {
60+
function handleGitFtpScopeCreation() {
6061
$gitPanel.find(".git-remotes")
6162
.addClass("btn-loading")
6263
.prop("disabled", true);
6364

64-
return Utils.askQuestion(Strings.CREATE_GITFTP_NEW_REMOTE, Strings.ENTER_GITFTP_REMOTE_NAME)
65+
return Utils.askQuestion(Strings.CREATE_GITFTP_NEW_SCOPE, Strings.ENTER_GITFTP_SCOPE_NAME)
6566
.then(function (name) {
6667
return Utils.askQuestion(
67-
Strings.CREATE_GITFTP_NEW_REMOTE,
68-
Strings.ENTER_GITFTP_REMOTE_URL,
68+
Strings.CREATE_GITFTP_NEW_SCOPE,
69+
Strings.ENTER_GITFTP_SCOPE_URL,
6970
{defaultValue: "ftp://user:passwd@example.org/folder"}
7071
)
7172
.then(function (url) {
7273
return GitFtp.addScope(name, url).then(function () {
7374

7475
// Render the list element of the new remote
7576
// TODO: replace this part with a way to call `Remotes.refreshRemotesPicker()`
76-
var $newRemote = $("<li/>")
77-
.addClass("gitftp-remote")
78-
.append("<a/>")
79-
.find("a")
80-
.attr({href: "#", "data-remote-name": name, "data-type": "ftp"})
81-
.addClass("remote-name")
82-
.append("<span/>")
83-
.find("span")
84-
.addClass("trash-icon gitftp-remove-remote")
85-
.html("&times;")
86-
.end()
87-
.append("<span/>")
88-
.find("span:nth-child(2)")
89-
.addClass("change-remote")
90-
.text(name)
91-
.end()
92-
.end();
93-
94-
$gitPanel.find(".git-remotes-dropdown .ftp-remotes-header").after($newRemote);
77+
var $newScope = $("<li/>")
78+
.addClass("gitftp-remote")
79+
.append("<a/>")
80+
.find("a")
81+
.attr({href: "#", "data-remote-name": name, "data-type": "ftp"})
82+
.addClass("remote-name")
83+
.append("<span/>")
84+
.find("span")
85+
.addClass("trash-icon gitftp-remove-remote")
86+
.html("&times;")
87+
.end()
88+
.append("<span/>")
89+
.find("span:nth-child(2)")
90+
.addClass("change-remote")
91+
.text(name)
92+
.end()
93+
.end();
94+
95+
$gitPanel.find(".git-remotes-dropdown .ftp-remotes-header").after($newScope);
9596

9697
}).catch(function (err) {
9798
ErrorHandler.showError(err, "Git-FTP remote creation failed");
@@ -105,25 +106,25 @@ define(function (require) {
105106
});
106107
}
107108

108-
function handleGitFtpRemoteRemove($this) {
109+
function handleGitFtpScopeRemove($this) {
109110
$gitPanel.find(".git-remotes")
110111
.addClass("btn-loading")
111112
.prop("disabled", true);
112113

113114
var $selectedElement = $this.closest(".remote-name"),
114-
$currentRemote = $gitPanel.find(".git-remote-selected"),
115-
remoteName = $selectedElement.data("remote-name");
115+
$currentScope = $gitPanel.find(".git-remote-selected"),
116+
scopeName = $selectedElement.data("remote-name");
116117

117118
return Utils.askQuestion(
118-
Strings.DELETE_REMOTE,
119-
StringUtils.format(Strings.DELETE_REMOTE_NAME, remoteName),
119+
Strings.DELETE_SCOPE,
120+
StringUtils.format(Strings.DELETE_SCOPE_NAME, scopeName),
120121
{booleanResponse: true}
121122
).then(function (response) {
122123
if (response) {
123-
return GitFtp.removeScope(remoteName).then(function () {
124+
return GitFtp.removeScope(scopeName).then(function () {
124125
$selectedElement.parent().remove();
125-
var newRemote = $gitPanel.find(".git-remotes-dropdown .remote").first().find("a").data("remote-name");
126-
$currentRemote.data("remote-name", newRemote).html(newRemote);
126+
var newScope = $gitPanel.find(".git-remotes-dropdown .remote").first().find("a").data("remote-name");
127+
$currentScope.data("remote-name", newScope).html(newScope);
127128
}).catch(function (err) {
128129
ErrorHandler.showError(err, "Remove scope failed");
129130
});
@@ -135,16 +136,41 @@ define(function (require) {
135136
});
136137
}
137138

138-
function addFtpRemotesToPicker() {
139-
GitFtp.getRemotes().then(function (ftpRemotes) {
139+
function handleGitFtpInitScope($this) {
140+
$gitPanel.find(".git-remotes")
141+
.addClass("btn-loading")
142+
.prop("disabled", true);
143+
144+
var $selectedElement = $this.closest(".remote-name"),
145+
scopeName = $selectedElement.data("remote-name");
146+
147+
return Utils.askQuestion(
148+
Strings.INIT_GITFTP_SCOPE,
149+
StringUtils.format(Strings.INIT_GITFTP_SCOPE_NAME, scopeName),
150+
{booleanResponse: true}
151+
).then(function (response) {
152+
if (response) {
153+
return GitFtp.init(scopeName).then(function () {
154+
}).catch(function (err) {
155+
ErrorHandler.showError(err, "Init scope failed");
156+
});
157+
}
158+
}).finally(function () {
159+
$gitPanel.find(".git-remotes")
160+
.removeClass("btn-loading")
161+
.prop("disabled", false);
162+
});
163+
}
164+
165+
function addFtpScopesToPicker() {
166+
GitFtp.getScopes().then(function (ftpScopes) {
140167

141168
// Pass to Mustache the needed data
142-
var compiledTemplate = Mustache.render(ftpRemotesTemplate, {
169+
var compiledTemplate = Mustache.render(ftpScopesTemplate, {
143170
Strings: Strings,
144-
ftpRemotes: ftpRemotes,
145-
hasFtpRemotes: ftpRemotes.length > 0
171+
ftpScopes: ftpScopes,
172+
hasFtpScopes: ftpScopes.length > 0
146173
});
147-
148174
$remotesDropdown.prepend(compiledTemplate);
149175

150176
}).catch(function (err) {
@@ -158,7 +184,7 @@ define(function (require) {
158184
});
159185

160186
EventEmitter.on(Events.REMOTES_REFRESH_PICKER, function () {
161-
addFtpRemotesToPicker();
187+
addFtpScopesToPicker();
162188
});
163189

164190
});

src/Ftp/GitFtp.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ define(function (require, exports) {
2222
return git(["ftp", "push", "--scope", scope]);
2323
}
2424

25-
function getRemotes() {
25+
function getScopes() {
2626
return git(["config", "--list"]).then(function (stdout) {
2727
return stdout.split("\n").reduce(function (result, row) {
2828
var io = row.indexOf(".url");
@@ -64,10 +64,10 @@ define(function (require, exports) {
6464
}
6565

6666
// Public API
67-
exports.init = init;
68-
exports.push = push;
69-
exports.getRemotes = getRemotes;
70-
exports.addScope = addScope;
67+
exports.init = init;
68+
exports.push = push;
69+
exports.getScopes = getScopes;
70+
exports.addScope = addScope;
7171
exports.removeScope = removeScope;
7272

7373
});
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
<!-- List of Git-FTP remotes defined for the current local repository -->
2-
<li class="dropdown-header ftp-remotes-header">{{Strings.GITFTP_REMOTES}}</li>
3-
{{#hasFtpRemotes}}
4-
{{#ftpRemotes}}
2+
<li class="dropdown-header ftp-remotes-header">{{Strings.GITFTP_SCOPES}}</li>
3+
{{#hasFtpScopes}}
4+
{{#ftpScopes}}
55
<li class="gitftp-remote">
66
<a href="#" data-remote-name="{{name}}" data-type="ftp" class="remote-name">
77
<span class="trash-icon gitftp-remove-remote">&times;</span>
88
<span class="change-remote">{{name}}</span>
9+
<span class="octicon octicon-arrow-up gitftp-init-remote"></span>
910
</a>
1011
</li>
11-
{{/ftpRemotes}}
12-
{{/hasFtpRemotes}}
13-
<li><a class="gitftp-remote-new"><span>{{Strings.CREATE_NEW_GITFTP_REMOTE}}</span></a></li>
12+
{{/ftpScopes}}
13+
{{/hasFtpScopes}}
14+
<li><a class="gitftp-remote-new"><span>{{Strings.CREATE_NEW_GITFTP_SCOPE}}</span></a></li>
1415
<li class="divider"></li>
1516
<li class="dropdown-header git-remotes-header">{{Strings.GIT_REMOTES}}</li>

0 commit comments

Comments
 (0)