Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions less/brackets-git.less
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@
display: inline-block;
width: 100%;
}
.trash-icon {
.trash-icon, .gitftp-init-remote {
opacity: 0;
background-image: none !important;
width: 16px;
Expand All @@ -254,7 +254,12 @@
font-weight: bold;
}
}
&:hover .trash-icon {
.gitftp-init-remote {
position: relative;
top: 2px;
right: 4px;
}
&:hover .trash-icon, &:hover .gitftp-init-remote {
opacity: 1;
}
}
Expand Down
11 changes: 6 additions & 5 deletions nls/root/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ define({
CLONE_REPOSITORY: "Clone repository",
CREATE_NEW_BRANCH: "Create new branch\u2026",
CREATE_NEW_REMOTE: "Create new remote\u2026",
CREATE_NEW_GITFTP_REMOTE: "Create new Git-FTP remote\u2026",
CREATE_NEW_GITFTP_SCOPE: "Create new Git-FTP remote\u2026",
CUSTOM_TERMINAL_COMMAND: "Custom terminal command (sample: gnome-terminal or complete path to executable)",
CUSTOM_TERMINAL_COMMAND_HINT: "Sample arguments: --window --working-directory=$1<br>$1 in arguments will be replaced by current project directory.",
DATE_FORMAT: "YYYY-MM-DD HH:mm:ss",
Expand All @@ -57,9 +57,9 @@ define({
ENTER_USERNAME: "Enter username:",
ENTER_REMOTE_GIT_URL: "Enter Git URL of the repository you want to clone:",
ENTER_REMOTE_NAME: "Enter name of the new remote:",
ENTER_GITFTP_REMOTE_NAME: "Enter name of the new Git-FTP remote:",
ENTER_GITFTP_SCOPE_NAME: "Enter name of the new Git-FTP remote:",
ENTER_REMOTE_URL: "Enter URL of the new remote:",
ENTER_GITFTP_REMOTE_URL: "Enter FTP URL of the new Git-FTP remote specifing username and password:",
ENTER_GITFTP_SCOPE_URL: "Enter FTP URL of the new Git-FTP remote specifing username and password:",
ERROR_TERMINAL_NOT_FOUND: "Terminal was not found for your OS, you can define a custom Terminal command in the settings",
EXTENDED_COMMIT_MESSAGE: "EXTENDED",
EXTENSION_WAS_UPDATED_TITLE: "The extension was updated to {0}",
Expand All @@ -84,10 +84,11 @@ define({
GITFTP_PUSH_RESPONSE: "Git-FTP Push response",
GIT_SETTINGS: "Git Settings\u2026",
GIT_REMOTES: "Git remotes",
GITFTP_REMOTES: "Git-FTP remotes",
GITFTP_SCOPES: "Git-FTP remotes",
GOTO_PREVIOUS_GIT_CHANGE: "Go to previous Git change",
GOTO_NEXT_GIT_CHANGE: "Go to next Git change",
INIT_GITFTP_REMOTE_NAME: "Initialize Git-FTP remote \"{0}\"?",
INIT_GITFTP_SCOPE: "Initialize Git-FTP remote",
INIT_GITFTP_SCOPE_NAME: "Initialize Git-FTP remote \"{0}\"?",
LAUNCH_BASH_SHORTCUT: "Bash/Terminal shortcut",
LOADING: "Loading\u2026",
LINES: "Lines",
Expand Down
112 changes: 69 additions & 43 deletions src/Ftp/Ftp.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@ define(function (require) {
GitFtp = require("./GitFtp");

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

// Implementation

var attachEvents = _.once(function () {
$gitPanel
.on("click", ".gitftp-remote-new", handleGitFtpRemoteCreation)
.on("click", ".gitftp-remove-remote", function () { handleGitFtpRemoteRemove($(this)); })
.on("click", ".gitftp-remote-new", handleGitFtpScopeCreation)
.on("click", ".gitftp-remove-remote", function () { handleGitFtpScopeRemove($(this)); })
.on("click", ".gitftp-init-remote", function () { handleGitFtpInitScope($(this)); })
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These handlers should be called the same way (chose one). Currently gitftp-remote-new is different from gitftp-remove-remote and gitftp-init-remote

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? I don't need $(this) in handleGitFtpScopeCreation

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just rename the other two to
.on("click", ".gitftp-remove-remote", handleGitFtpScopeRemove)
and on the first line do
var $this = $(this);
OR have

.on("click", ".gitftp-remote-new", function () { handleGitFtpScopeCreation(); })

It looks more consistent this way. That's all.
Having .on("click", ".gitftp-remote-new", handleGitFtpScopeCreation) makes me think you want to pass the event from jQuery into arguments

.on("click", ".gitftp-push", handleGitFtpPush);
});

Expand All @@ -38,10 +39,10 @@ define(function (require) {
}

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

GitFtp.push(gitFtpRemote).done(function (result) {
GitFtp.push(gitFtpScope).done(function (result) {
Dialogs.showModalDialog(
DefaultDialogs.DIALOG_ID_INFO,
Strings.GITFTP_PUSH_RESPONSE, // title
Expand All @@ -56,42 +57,42 @@ define(function (require) {
});
}

function handleGitFtpRemoteCreation() {
function handleGitFtpScopeCreation() {
$gitPanel.find(".git-remotes")
.addClass("btn-loading")
.prop("disabled", true);

return Utils.askQuestion(Strings.CREATE_GITFTP_NEW_REMOTE, Strings.ENTER_GITFTP_REMOTE_NAME)
return Utils.askQuestion(Strings.CREATE_GITFTP_NEW_SCOPE, Strings.ENTER_GITFTP_SCOPE_NAME)
.then(function (name) {
return Utils.askQuestion(
Strings.CREATE_GITFTP_NEW_REMOTE,
Strings.ENTER_GITFTP_REMOTE_URL,
Strings.CREATE_GITFTP_NEW_SCOPE,
Strings.ENTER_GITFTP_SCOPE_URL,
{defaultValue: "ftp://user:passwd@example.org/folder"}
)
.then(function (url) {
return GitFtp.addScope(name, url).then(function () {

// Render the list element of the new remote
// TODO: replace this part with a way to call `Remotes.refreshRemotesPicker()`
var $newRemote = $("<li/>")
.addClass("gitftp-remote")
.append("<a/>")
.find("a")
.attr({href: "#", "data-remote-name": name, "data-type": "ftp"})
.addClass("remote-name")
.append("<span/>")
.find("span")
.addClass("trash-icon gitftp-remove-remote")
.html("&times;")
.end()
.append("<span/>")
.find("span:nth-child(2)")
.addClass("change-remote")
.text(name)
.end()
.end();

$gitPanel.find(".git-remotes-dropdown .ftp-remotes-header").after($newRemote);
var $newScope = $("<li/>")
.addClass("gitftp-remote")
.append("<a/>")
.find("a")
.attr({href: "#", "data-remote-name": name, "data-type": "ftp"})
.addClass("remote-name")
.append("<span/>")
.find("span")
.addClass("trash-icon gitftp-remove-remote")
.html("&times;")
.end()
.append("<span/>")
.find("span:nth-child(2)")
.addClass("change-remote")
.text(name)
.end()
.end();

$gitPanel.find(".git-remotes-dropdown .ftp-remotes-header").after($newScope);

}).catch(function (err) {
ErrorHandler.showError(err, "Git-FTP remote creation failed");
Expand All @@ -105,25 +106,25 @@ define(function (require) {
});
}

function handleGitFtpRemoteRemove($this) {
function handleGitFtpScopeRemove($this) {
$gitPanel.find(".git-remotes")
.addClass("btn-loading")
.prop("disabled", true);

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

return Utils.askQuestion(
Strings.DELETE_REMOTE,
StringUtils.format(Strings.DELETE_REMOTE_NAME, remoteName),
Strings.DELETE_SCOPE,
StringUtils.format(Strings.DELETE_SCOPE_NAME, scopeName),
{booleanResponse: true}
).then(function (response) {
if (response) {
return GitFtp.removeScope(remoteName).then(function () {
return GitFtp.removeScope(scopeName).then(function () {
$selectedElement.parent().remove();
var newRemote = $gitPanel.find(".git-remotes-dropdown .remote").first().find("a").data("remote-name");
$currentRemote.data("remote-name", newRemote).html(newRemote);
var newScope = $gitPanel.find(".git-remotes-dropdown .remote").first().find("a").data("remote-name");
$currentScope.data("remote-name", newScope).html(newScope);
}).catch(function (err) {
ErrorHandler.showError(err, "Remove scope failed");
});
Expand All @@ -135,16 +136,41 @@ define(function (require) {
});
}

function addFtpRemotesToPicker() {
GitFtp.getRemotes().then(function (ftpRemotes) {
function handleGitFtpInitScope($this) {
$gitPanel.find(".git-remotes")
.addClass("btn-loading")
.prop("disabled", true);

var $selectedElement = $this.closest(".remote-name"),
scopeName = $selectedElement.data("remote-name");

return Utils.askQuestion(
Strings.INIT_GITFTP_SCOPE,
StringUtils.format(Strings.INIT_GITFTP_SCOPE_NAME, scopeName),
{booleanResponse: true}
).then(function (response) {
if (response) {
return GitFtp.init(scopeName).then(function () {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why empty function here?

}).catch(function (err) {
ErrorHandler.showError(err, "Init scope failed");
});
}
}).finally(function () {
$gitPanel.find(".git-remotes")
.removeClass("btn-loading")
.prop("disabled", false);
});
}

function addFtpScopesToPicker() {
GitFtp.getScopes().then(function (ftpScopes) {

// Pass to Mustache the needed data
var compiledTemplate = Mustache.render(ftpRemotesTemplate, {
var compiledTemplate = Mustache.render(ftpScopesTemplate, {
Strings: Strings,
ftpRemotes: ftpRemotes,
hasFtpRemotes: ftpRemotes.length > 0
ftpScopes: ftpScopes,
hasFtpScopes: ftpScopes.length > 0
});

$remotesDropdown.prepend(compiledTemplate);

}).catch(function (err) {
Expand All @@ -158,7 +184,7 @@ define(function (require) {
});

EventEmitter.on(Events.REMOTES_REFRESH_PICKER, function () {
addFtpRemotesToPicker();
addFtpScopesToPicker();
});

});
10 changes: 5 additions & 5 deletions src/Ftp/GitFtp.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ define(function (require, exports) {
return git(["ftp", "push", "--scope", scope]);
}

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

// Public API
exports.init = init;
exports.push = push;
exports.getRemotes = getRemotes;
exports.addScope = addScope;
exports.init = init;
exports.push = push;
exports.getScopes = getScopes;
exports.addScope = addScope;
exports.removeScope = removeScope;

});
13 changes: 7 additions & 6 deletions src/Ftp/templates/remotes-picker.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
<!-- List of Git-FTP remotes defined for the current local repository -->
<li class="dropdown-header ftp-remotes-header">{{Strings.GITFTP_REMOTES}}</li>
{{#hasFtpRemotes}}
{{#ftpRemotes}}
<li class="dropdown-header ftp-remotes-header">{{Strings.GITFTP_SCOPES}}</li>
{{#hasFtpScopes}}
{{#ftpScopes}}
<li class="gitftp-remote">
<a href="#" data-remote-name="{{name}}" data-type="ftp" class="remote-name">
<span class="trash-icon gitftp-remove-remote">&times;</span>
<span class="change-remote">{{name}}</span>
<span class="octicon octicon-arrow-up gitftp-init-remote" title="{{Strings.INIT_GITFTP_SCOPE}}"></span>
</a>
</li>
{{/ftpRemotes}}
{{/hasFtpRemotes}}
<li><a class="gitftp-remote-new"><span>{{Strings.CREATE_NEW_GITFTP_REMOTE}}</span></a></li>
{{/ftpScopes}}
{{/hasFtpScopes}}
<li><a class="gitftp-remote-new"><span>{{Strings.CREATE_NEW_GITFTP_SCOPE}}</span></a></li>
<li class="divider"></li>
<li class="dropdown-header git-remotes-header">{{Strings.GIT_REMOTES}}</li>