Skip to content

Commit

Permalink
Resolved #5 and resolved #44. Removed annoying "pre-release" label.
Browse files Browse the repository at this point in the history
  • Loading branch information
rafajaques committed May 18, 2016
1 parent f573eec commit c1de25c
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 38 deletions.
5 changes: 5 additions & 0 deletions css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ body{
display: block;
font-size: 13px;
}
#run-version{
display: block;
color:#7a7a7a;
font-size:11px;
}

/**
* Content - The main space
Expand Down
5 changes: 1 addition & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@
</head>
<body>

<!-- Pre-release warning -->
<div style="color:#f00;background-color:#fff;font-weight:bold;position:fixed;right:0;bottom:0;z-index:1000;padding:5px;border-top-left-radius:5px;opacity:0.4">Pre-release</div>

<!-- Sidebar -->
<div id="sidebar">
<!-- Menu -->
<ul>
<li data-event="sidebar-run"><span class="glyphicon glyphicon-play" aria-hidden="true"></span> <span data-string="Run code"></span></li>
<li data-event="sidebar-run"><span class="glyphicon glyphicon-play" aria-hidden="true"></span> <span data-string="Run code"></span> <span id="run-version"></span></li>
<li data-event="sidebar-clear"><span class="glyphicon glyphicon-erase" aria-hidden="true"></span> <span data-string="Clear"></span></li>
<li data-event="sidebar-import"><span class="glyphicon glyphicon-open-file" aria-hidden="true"></span> <span data-string="Import from file"></span></li>
<li data-event="sidebar-presentation"><span class="glyphicon glyphicon-blackboard" aria-hidden="true"></span> <span data-string="Presentation mode"></span></li>
Expand Down
104 changes: 76 additions & 28 deletions js/binary.operations.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,35 @@ function binaryAdd() {
var version = binaryGetVersion(path, true);

// Oops! Invalid PHP binary!
if (!version)
if (!version) {
dialog.showErrorBox(i18n.__("Error"), i18n.__("Invalid PHP binary"));
return;
}

// Save new version to config
conf.set("php.versions." + version, path);

// Is this our first?
if (binaryGetCount() == 1) {
// Please, set it as our new default
binarySetNewDefault();
}

// Update list
binaryUpdateList();
}
}

function binaryRemove() {

function binaryRemove(version) {
conf.del("php.versions." + version)
// Are you deleting your default version?
if (conf.get("php.default") == version) {
binarySetNewDefault();
}
}

function binaryMakeDefault(version) {
conf.set("php.default", binaryConvertVersionToSave(version));
binarySetNewDefault(binaryConvertVersionToSave(version));
}

function binaryConvertVersionToSave(version) {
Expand Down Expand Up @@ -66,23 +78,79 @@ function binaryGetVersion(path, replaced) {
}
}

function binaryGetCount() {
return Object.keys(conf.get("php.versions")).length;
}

/**
* Commands from modal
*/
function makeDefaultVersion(version) {
binaryMakeDefault(version);
binaryUpdateList();
php_path = conf.get("php.versions." + conf.get("php.default"));
}

function removeVersion(version) {
var opt = dialog.showMessageBox({
"type": "question",
"title": i18n.__("Are you sure?"),
"message": i18n.__("Removing {{version}} version. Are you sure?", {"version": binaryConvertVersionToShow(version)}),
"buttons": [i18n.__("Yes"), i18n.__("No")],
});

// Yes = 0; No = 1
if (opt == 0) {
binaryRemove(version);
binaryUpdateList();
}
}

function binarySetNewDefault(which) {
if (which) {
conf.set("php.default", which);
} else if (binaryGetCount()) {
// Set first option on the list as default (if we have any)
var v_keys = Object.keys(conf.get("php.versions"));
conf.set("php.default", v_keys[0]);
} else {
conf.del("php.default");
}
updatePhpPath();
}

function updatePhpPath() {
// Change php_path variable for runner
php_path = conf.get("php.versions." + conf.get("php.default"));

// Change PHP version number shown in app
$("#run-version").html(phpGetCurrVersion());
}

/**
* Get current version
*/
function phpGetCurrVersion() {
return binaryConvertVersionToShow(conf.get("php.default"));
}

/**
* Binary list functions
*/
function binaryUpdateList() {
$("#binary-list").empty();

var versions = conf.get("php.versions");
var inUse = conf.get("php.default");
var in_use = conf.get("php.default");

for (var v in versions) {
$("#binary-list").append(binaryLineGetTemplate(v, versions[v], (inUse == v)));
$("#binary-list").append(binaryLineGetTemplate(v, versions[v], (in_use == v)));
}
}

function binaryLineGetTemplate(version, path, inUse) {
function binaryLineGetTemplate(version, path, in_use) {
return [
'<tr ' + (inUse ? 'class="info"' : '') + '>',
'<tr ' + (in_use ? 'class="info"' : '') + '>',
' <td>' + binaryConvertVersionToShow(version) + '</td>',
' <td>' + path + '</td>',
' <td class="text-right">',
Expand All @@ -98,23 +166,3 @@ function binaryLineGetTemplate(version, path, inUse) {
'</tr>'
].join("\n");
}

/**
* Commands from modal
*/
function makeDefaultVersion(version) {
binaryMakeDefault(version);
binaryUpdateList();
php_path = conf.get("php.versions." + conf.get("php.default"));
}

function removeVersion(version) {
var opt = dialog.showMessageBox({
"type": "question",
"title": i18n.__("Are you sure?"),
"message": i18n.__("Removing {{version}} version. Are you sure?", {"version": binaryConvertVersionToShow(version)}),
"buttons": [i18n.__("Yes"), i18n.__("No")],
});

console.log(opt);
}
10 changes: 9 additions & 1 deletion js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ const settings_default = {
}

// Editor
var php_path = conf.get("php.versions." + conf.get("php.default"));
var php_path;
var editor = ace.edit("editor");
updatePhpPath();
editor.$blockScrolling = Infinity;
editor.commands.removeCommand("showSettingsMenu"); // Prevents ACE bindings at Cmd + ,

Expand Down Expand Up @@ -145,6 +146,13 @@ function renderApp(refresh) {
*/
// Sends code to PHP
function runCode() {

// Is there any PHP for us to work with?
if (!php_path) {
setOutput(i18n.__("Error") + ": " + i18n.__("You don't have any PHP binary. Add one using the settings screen and try again."));
return;
}

setBusy(true);
editor.focus();

Expand Down
8 changes: 7 additions & 1 deletion locales/da.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,11 @@
"Presentation": "Presentation",
"Try to open secondary window in another display": "Try to open secondary window in another display",
"Single Display Mode": "Single Display Mode",
"Multi Display Mode": "Multi Display Mode"
"Multi Display Mode": "Multi Display Mode",
"Invalid PHP binary": "Invalid PHP binary",
"Version": "Version",
"Are you sure?": "Are you sure?",
"Removing {{version}} version. Are you sure?": "Removing {{version}} version. Are you sure?",
"OK": "OK",
"You don't have any PHP binary. Add one using the settings screen and try again.": "You don't have any PHP binary. Add one using the settings screen and try again."
}
8 changes: 7 additions & 1 deletion locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,11 @@
"Presentation": "Presentation",
"Try to open secondary window in another display": "Try to open secondary window in another display",
"Single Display Mode": "Single Display Mode",
"Multi Display Mode": "Multi Display Mode"
"Multi Display Mode": "Multi Display Mode",
"Invalid PHP binary": "Invalid PHP binary",
"Version": "Version",
"Are you sure?": "Are you sure?",
"Removing {{version}} version. Are you sure?": "Removing {{version}} version. Are you sure?",
"OK": "OK",
"You don't have any PHP binary. Add one using the settings screen and try again.": "You don't have any PHP binary. Add one using the settings screen and try again."
}
8 changes: 7 additions & 1 deletion locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,11 @@
"Presentation": "Presentation",
"Try to open secondary window in another display": "Try to open secondary window in another display",
"Single Display Mode": "Single Display Mode",
"Multi Display Mode": "Multi Display Mode"
"Multi Display Mode": "Multi Display Mode",
"Invalid PHP binary": "Invalid PHP binary",
"Version": "Version",
"Are you sure?": "Are you sure?",
"Removing {{version}} version. Are you sure?": "Removing {{version}} version. Are you sure?",
"OK": "OK",
"You don't have any PHP binary. Add one using the settings screen and try again.": "You don't have any PHP binary. Add one using the settings screen and try again."
}
8 changes: 7 additions & 1 deletion locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,11 @@
"Presentation": "Presentation",
"Try to open secondary window in another display": "Try to open secondary window in another display",
"Single Display Mode": "Single Display Mode",
"Multi Display Mode": "Multi Display Mode"
"Multi Display Mode": "Multi Display Mode",
"Invalid PHP binary": "Invalid PHP binary",
"Version": "Version",
"Are you sure?": "Are you sure?",
"Removing {{version}} version. Are you sure?": "Removing {{version}} version. Are you sure?",
"OK": "OK",
"You don't have any PHP binary. Add one using the settings screen and try again.": "You don't have any PHP binary. Add one using the settings screen and try again."
}
4 changes: 3 additions & 1 deletion locales/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,7 @@
"Invalid PHP binary": "Binário PHP inválido",
"Version": "Versão",
"Are you sure?": "Tem certeza?",
"Removing {{version}} version. Are you sure?": "Removendo versão {{version}}. Tem certeza?"
"Removing {{version}} version. Are you sure?": "Removendo versão {{version}}. Tem certeza?",
"OK": "OK",
"You don't have any PHP binary. Add one using the settings screen and try again.": "Você não possui nenhum binário PHP. Adicione um na tela de configurações e tente novamente."
}

0 comments on commit c1de25c

Please sign in to comment.