Commit b4394335 authored by josmas's avatar josmas Committed by Evan W. Patton

Changes to _destructive_ Dialog buttons. Fix for #1174

parent 55330e01
......@@ -246,8 +246,9 @@ public abstract class MockComponent extends Composite implements PropertyChangeL
hide();
}
});
Button okButton = new Button(MESSAGES.okButton());
okButton.addClickHandler(new ClickHandler() {
Button deleteButton = new Button(MESSAGES.deleteButton());
deleteButton.addStyleName("destructive-action");
deleteButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
hide();
......@@ -256,7 +257,7 @@ public abstract class MockComponent extends Composite implements PropertyChangeL
});
HorizontalPanel buttonPanel = new HorizontalPanel();
buttonPanel.add(cancelButton);
buttonPanel.add(okButton);
buttonPanel.add(deleteButton);
buttonPanel.setSize("100%", "24px");
contentPanel.add(buttonPanel);
contentPanel.setSize("320px", "100%");
......
......@@ -328,12 +328,14 @@ public class BlocklyPanel extends HTMLPanel {
* @param mess The message to display
* @param buttonName The string to display in the "OK" button.
* @param size 0 or 1. 0 makes a smaller box 1 makes a larger box.
* @param destructive Indicates if the button should be styled as a destructive action.
* @param callback an opague JavaScriptObject that contains the
* callback function provided by the Javascript code.
* @return The created dialog box.
*/
public static DialogBox createDialog(String title, String mess, final String buttonName, final String cancelButtonName, int size, final JavaScriptObject callback) {
public static DialogBox createDialog(String title, String mess, final String buttonName, Boolean destructive,
final String cancelButtonName, int size, final JavaScriptObject callback) {
final DialogBox dialogBox = new DialogBox();
dialogBox.setStylePrimaryName("ode-DialogBox");
dialogBox.setText(title);
......@@ -350,16 +352,6 @@ public class BlocklyPanel extends HTMLPanel {
HTML message = new HTML(mess);
message.setStyleName("DialogBox-message");
HorizontalPanel holder = new HorizontalPanel();
if (buttonName != null) { // If buttonName and cancelButtonName are null
Button ok = new Button(buttonName); // We won't have any buttons and other
ok.addClickHandler(new ClickHandler() { // code is needed to dismiss us
@Override
public void onClick(ClickEvent event) {
doCallBack(callback, buttonName);
}
});
holder.add(ok);
}
if (cancelButtonName != null) {
Button cancel = new Button(cancelButtonName);
cancel.addClickHandler(new ClickHandler() {
......@@ -370,6 +362,19 @@ public class BlocklyPanel extends HTMLPanel {
});
holder.add(cancel);
}
if (buttonName != null) { // If buttonName and cancelButtonName are null
Button ok = new Button(buttonName); // We won't have any buttons and other
if (destructive) {
ok.addStyleName("destructive-action");
}
ok.addClickHandler(new ClickHandler() { // code is needed to dismiss us
@Override
public void onClick(ClickEvent event) {
doCallBack(callback, buttonName);
}
});
holder.add(ok);
}
DialogBoxContents.add(message);
DialogBoxContents.add(holder);
dialogBox.setWidget(DialogBoxContents);
......@@ -574,7 +579,7 @@ public class BlocklyPanel extends HTMLPanel {
$wnd.BlocklyPanel_popScreen =
$entry(@com.google.appinventor.client.editor.youngandroid.BlocklyPanel::popScreen());
$wnd.BlocklyPanel_createDialog =
$entry(@com.google.appinventor.client.editor.youngandroid.BlocklyPanel::createDialog(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILcom/google/gwt/core/client/JavaScriptObject;));
$entry(@com.google.appinventor.client.editor.youngandroid.BlocklyPanel::createDialog(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Boolean;Ljava/lang/String;ILcom/google/gwt/core/client/JavaScriptObject;));
$wnd.BlocklyPanel_hideDialog =
$entry(@com.google.appinventor.client.editor.youngandroid.BlocklyPanel::HideDialog(Lcom/google/gwt/user/client/ui/DialogBox;));
$wnd.BlocklyPanel_setDialogContent =
......
......@@ -725,6 +725,18 @@ select {
box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.15), 0 1px 2px rgba(0, 0, 0, 0.05);
}
.destructive-action {
background: red;
color: white;
text-shadow: none;
}
.destructive-action:hover {
background: #FF6666;
color: white;
text-shadow: none;
}
.ya-Toolbar .ode-TextButton {
font-size: 11px;
}
......
......@@ -406,7 +406,7 @@ Blockly.Backpack.prototype.openBackpackDoc = function(e) {
backpackDoc.callback = function() {
var dialog = new Blockly.Util.Dialog(Blockly.Msg.BACKPACK_DOC_TITLE,
Blockly.Msg.BACKPACK_DOCUMENTATION,
Blockly.Msg.REPL_OK, null, 0,
Blockly.Msg.REPL_OK, false, null, 0,
function() {
dialog.hide();
});
......
......@@ -69,7 +69,7 @@ Blockly.confirmDeletion = function(callback) {
var msg = Blockly.Msg.WARNING_DELETE_X_BLOCKS.replace('%1', String(descendantCount));
var cancelButton = top.BlocklyPanel_getOdeMessage('cancelButton');
var deleteButton = top.BlocklyPanel_getOdeMessage('deleteButton');
var dialog = new Blockly.Util.Dialog(Blockly.Msg.CONFIRM_DELETE, msg, deleteButton, cancelButton, 0, function(button) {
var dialog = new Blockly.Util.Dialog(Blockly.Msg.CONFIRM_DELETE, msg, deleteButton, true, cancelButton, 0, function(button) {
dialog.hide();
if (button == deleteButton) {
Blockly.mainWorkspace.playAudio('delete');
......
......@@ -184,7 +184,7 @@ Blockly.unprefixName = function (name) {
Blockly.localNamePrefix,
Blockly.loopParameterPrefix,
Blockly.loopRangeParameterPrefix];
for (i=0; i < prefixes.length; i++) {
for (var i=0; i < prefixes.length; i++) {
if (name.indexOf(prefixes[i]) == 0) {
// name begins with prefix
return [prefixes[i], name.substring(prefixes[i].length + Blockly.menuSeparator.length)]
......
......@@ -362,7 +362,7 @@ Blockly.ReplMgr.putYail = (function() {
if (work.failure) {
work.failure(Blockly.Msg.REPL_NETWORK_CONNECTION_ERROR);
}
var dialog = new Blockly.Util.Dialog(Blockly.Msg.REPL_NETWORK_ERROR, Blockly.Msg.REPL_NETWORK_ERROR_RESTART, Blockly.Msg.REPL_OK, null, 0,
var dialog = new Blockly.Util.Dialog(Blockly.Msg.REPL_NETWORK_ERROR, Blockly.Msg.REPL_NETWORK_ERROR_RESTART, Blockly.Msg.REPL_OK, false, null, 0,
function() {
dialog.hide();
context.hardreset(context.formName);
......@@ -394,7 +394,7 @@ Blockly.ReplMgr.putYail = (function() {
if (!Blockly.ReplMgr.acceptablePackage(json["package"])) {
dialog = new Blockly.Util.Dialog(Blockly.Msg.REPL_COMPANION_VERSION_CHECK,
Blockly.Msg.REPL_COMPANION_WRONG_PACKAGE,
Blockly.Msg.REPL_OK, null, 0, function() {
Blockly.Msg.REPL_OK, false, null, 0, function() {
dialog.hide();
});
engine.resetcompanion();
......@@ -427,7 +427,7 @@ Blockly.ReplMgr.putYail = (function() {
return;
}
if (this.readyState == 4) { // Old Companion, doesn't do CORS so we fail to talk to it
var dialog = new Blockly.Util.Dialog(Blockly.Msg.REPL_NETWORK_ERROR, Blockly.Msg.REPL_NETWORK_ERROR_RESTART, Blockly.Msg.REPL_OK, null, 0, function() {
var dialog = new Blockly.Util.Dialog(Blockly.Msg.REPL_NETWORK_ERROR, Blockly.Msg.REPL_NETWORK_ERROR_RESTART, Blockly.Msg.REPL_OK, false, null, 0, function() {
dialog.hide();
});
engine.resetcompanion();
......@@ -487,7 +487,8 @@ Blockly.ReplMgr.putYail = (function() {
if (installer != "com.android.vending" && top.COMPANION_UPDATE_URL) {
var emulator = (rs.replcode == 'emulator'); // Kludgey way to tell
dialog = new Blockly.Util.Dialog(Blockly.Msg.REPL_COMPANION_VERSION_CHECK,
Blockly.Msg.REPL_COMPANION_OUT_OF_DATE + (emulator?Blockly.Msg.REPL_EMULATORS:Blockly.Msg.REPL_DEVICES) + Blockly.Msg.REPL_APPROVE_UPDATE, Blockly.Msg.REPL_OK, cancelButton, 0, function(response) {
Blockly.Msg.REPL_COMPANION_OUT_OF_DATE + (emulator?Blockly.Msg.REPL_EMULATORS:Blockly.Msg.REPL_DEVICES) + Blockly.Msg.REPL_APPROVE_UPDATE,
Blockly.Msg.REPL_OK, false, cancelButton, 0, function(response) {
dialog.hide();
if (response != Blockly.Msg.REPL_NOT_NOW) {
context.triggerUpdate();
......@@ -496,10 +497,10 @@ Blockly.ReplMgr.putYail = (function() {
}
});
} else if (fatal) {
dialog = new Blockly.Util.Dialog(Blockly.Msg.REPL_COMPANION_VERSION_CHECK, Blockly.Msg.REPL_COMPANION_OUT_OF_DATE1 + top.PREFERRED_COMPANION, Blockly.Msg.REPL_OK, null, 0, function() { dialog.hide();});
dialog = new Blockly.Util.Dialog(Blockly.Msg.REPL_COMPANION_VERSION_CHECK, Blockly.Msg.REPL_COMPANION_OUT_OF_DATE1 + top.PREFERRED_COMPANION, Blockly.Msg.REPL_OK, false, null, 0, function() { dialog.hide();});
engine.resetcompanion();
} else {
dialog = new Blockly.Util.Dialog(Blockly.Msg.REPL_COMPANION_VERSION_CHECK, Blockly.Msg.REPL_COMPANION_OUT_OF_DATE_IMMEDIATE, Blockly.Msg.REPL_DISMISS, null, 1, function() { dialog.hide();});
dialog = new Blockly.Util.Dialog(Blockly.Msg.REPL_COMPANION_VERSION_CHECK, Blockly.Msg.REPL_COMPANION_OUT_OF_DATE_IMMEDIATE, Blockly.Msg.REPL_DISMISS, false, null, 1, function() { dialog.hide();});
engine.pollphone();
}
}
......@@ -533,11 +534,11 @@ Blockly.ReplMgr.triggerUpdate = function() {
dialog.setContent(message);
} else {
if (OkButton) {
dialog = new Blockly.Util.Dialog(Blockly.Msg.REPL_SOFTWARE_UPDATE, message, OkButton, null, 0,
dialog = new Blockly.Util.Dialog(Blockly.Msg.REPL_SOFTWARE_UPDATE, message, OkButton, false, null, 0,
function() { dialog.hide();});
okbuttonshowing = true;
} else {
dialog = new Blockly.Util.Dialog(Blockly.Msg.REPL_SOFTWARE_UPDATE, message, null, null, 0, undefined);
dialog = new Blockly.Util.Dialog(Blockly.Msg.REPL_SOFTWARE_UPDATE, message, null, false, null, 0, undefined);
dialog.display();
okbuttonshowing = false;
}
......@@ -778,7 +779,7 @@ Blockly.ReplMgr.startAdbDevice = function(rs, usb) {
} else {
message = Blockly.Msg.REPL_STARTING_EMULATOR;
}
progdialog = new Blockly.Util.Dialog(Blockly.Msg.REPL_CONNECTING, message, Blockly.Msg.REPL_CANCEL, null, 0, function() {
progdialog = new Blockly.Util.Dialog(Blockly.Msg.REPL_CONNECTING, message, Blockly.Msg.REPL_CANCEL, false, null, 0, function() {
progdialog.hide();
clearInterval(interval);
top.ReplState.state = Blockly.ReplMgr.rsState.IDLE;
......@@ -792,7 +793,7 @@ Blockly.ReplMgr.startAdbDevice = function(rs, usb) {
clearInterval(interval); // Stop polling
var giveupButton = Blockly.Msg.REPL_GIVE_UP;
var keepgoingButton = Blockly.Msg.REPL_KEEP_TRYING;
dialog = new Blockly.Util.Dialog(Blockly.Msg.REPL_CONNECTION_FAILURE1, Blockly.Msg.REPL_NO_START_EMULATOR, giveupButton, keepgoingButton, 0, function(response) {
dialog = new Blockly.Util.Dialog(Blockly.Msg.REPL_CONNECTION_FAILURE1, Blockly.Msg.REPL_NO_START_EMULATOR, giveupButton, false, keepgoingButton, 0, function(response) {
dialog.hide();
dialog = null;
if (response == giveupButton) {
......@@ -847,7 +848,7 @@ Blockly.ReplMgr.startAdbDevice = function(rs, usb) {
xhr.send();
first = false;
} else if (first) { // USB
udialog = new Blockly.Util.Dialog(Blockly.Msg.REPL_PLUGGED_IN_Q, Blockly.Msg.REPL_AI_NO_SEE_DEVICE, Blockly.Msg.REPL_OK, null, 0, function() { udialog.hide(); udialog = null;});
udialog = new Blockly.Util.Dialog(Blockly.Msg.REPL_PLUGGED_IN_Q, Blockly.Msg.REPL_AI_NO_SEE_DEVICE, Blockly.Msg.REPL_OK, false, null, 0, function() { udialog.hide(); udialog = null;});
first = false;
}
}
......@@ -860,7 +861,7 @@ Blockly.ReplMgr.startAdbDevice = function(rs, usb) {
}
if (!dialog) {
top.BlocklyPanel_indicateDisconnect();
dialog = new Blockly.Util.Dialog(Blockly.Msg.REPL_HELPER_Q, Blockly.Msg.REPL_HELPER_NOT_RUNNING, Blockly.Msg.REPL_OK, null, 0, function() {
dialog = new Blockly.Util.Dialog(Blockly.Msg.REPL_HELPER_Q, Blockly.Msg.REPL_HELPER_NOT_RUNNING, Blockly.Msg.REPL_OK, false, null, 0, function() {
dialog.hide();
dialog = null;
if (progdialog) {
......@@ -996,7 +997,7 @@ Blockly.ReplMgr.startRepl = function(already, emulator, usb) {
rs.rendezvouscode = this.sha1(rs.replcode);
rs.seq_count = 1; // used for the creating the hmac mac
rs.count = 0;
rs.dialog = new Blockly.Util.Dialog(Blockly.Msg.REPL_CONNECT_TO_COMPANION, this.makeDialogMessage(rs.replcode), Blockly.Msg.REPL_CANCEL, null, 1, function() {
rs.dialog = new Blockly.Util.Dialog(Blockly.Msg.REPL_CONNECT_TO_COMPANION, this.makeDialogMessage(rs.replcode), Blockly.Msg.REPL_CANCEL, false, null, 1, function() {
rs.dialog.hide();
rs.state = Blockly.ReplMgr.rsState.IDLE; // We're punting
rs.connection = null;
......@@ -1104,7 +1105,7 @@ Blockly.ReplMgr.rendPoll = function() {
if (top.ReplState.count > 40) {
top.ReplState.state = this.rsState.IDLE;
top.ReplState.dialog.hide(); // Punt the dialog
dialog = new Blockly.Util.Dialog(Blockly.Msg.REPL_CONNECTION_FAILURE1, Blockly.Msg.REPL_TRY_AGAIN1, Blockly.Msg.REPL_OK, null, 0, function() {
dialog = new Blockly.Util.Dialog(Blockly.Msg.REPL_CONNECTION_FAILURE1, Blockly.Msg.REPL_TRY_AGAIN1, Blockly.Msg.REPL_OK, false, null, 0, function() {
dialog.hide();
});
top.ReplState.url = null;
......@@ -1223,7 +1224,7 @@ Blockly.ReplMgr.hardreset = function(formName, callback) {
Blockly.ReplMgr.ehardreset = function(formName) {
var context = this;
var dialog = new Blockly.Util.Dialog(Blockly.Msg.REPL_DO_YOU_REALLY_Q, Blockly.Msg.REPL_FACTORY_RESET, Blockly.Msg.REPL_OK, Blockly.Msg.REPL_CANCEL, 0, function(response) {
var dialog = new Blockly.Util.Dialog(Blockly.Msg.REPL_DO_YOU_REALLY_Q, Blockly.Msg.REPL_FACTORY_RESET, Blockly.Msg.REPL_OK, true, Blockly.Msg.REPL_CANCEL, 0, function(response) {
dialog.hide();
if (response == Blockly.Msg.REPL_OK) {
context.hardreset(formName, function() {
......
......@@ -26,11 +26,12 @@ Blockly.Util = {};
// argument being passed to the callback. If in the future we need to pass an arugment
// we can worry about adding that functionality.
Blockly.Util.Dialog = function(title, content, buttonName, cancelButtonName, size, callback) {
Blockly.Util.Dialog = function(title, content, buttonName, destructive, cancelButtonName, size, callback) {
this.title = title;
this.content = content;
this.size = size;
this.buttonName = buttonName;
this.destructive = destructive;
this.cancelButtonName = cancelButtonName;
this.callback = callback;
if (this.buttonName) {
......@@ -40,7 +41,7 @@ Blockly.Util.Dialog = function(title, content, buttonName, cancelButtonName, siz
Blockly.Util.Dialog.prototype = {
'display' : function() {
this._dialog = top.BlocklyPanel_createDialog(this.title, this.content, this.buttonName, this.cancelButtonName, this.size, this.callback);
this._dialog = top.BlocklyPanel_createDialog(this.title, this.content, this.buttonName, this.destructive, this.cancelButtonName, this.size, this.callback);
},
'hide' : function() {
if (this._dialog) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment