Skip to content

Commit

Permalink
Add refresh companion item to connect menu
Browse files Browse the repository at this point in the history
  • Loading branch information
kalsheikh authored and ewpatton committed Jan 2, 2020
1 parent a29c047 commit ae9e02d
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 11 deletions.
Expand Up @@ -603,6 +603,10 @@ public interface OdeMessages extends Messages, AutogeneratedOdeMessages {
@Description("Hard Reset the Emulator.") @Description("Hard Reset the Emulator.")
String hardResetConnectionsMenuItem(); String hardResetConnectionsMenuItem();


@DefaultMessage("Refresh Companion Screen")
@Description("Refresh the companion screen.")
String refreshCompanionMenuItem();

//Build //Build
@DefaultMessage("Build") @DefaultMessage("Build")
@Description("Label of the button leading to build related cascade items") @Description("Label of the button leading to build related cascade items")
Expand Down
Expand Up @@ -88,6 +88,7 @@ public class TopToolbar extends Composite {
private static final String WIDGET_NAME_USB_BUTTON = "Usb"; private static final String WIDGET_NAME_USB_BUTTON = "Usb";
private static final String WIDGET_NAME_RESET_BUTTON = "Reset"; private static final String WIDGET_NAME_RESET_BUTTON = "Reset";
private static final String WIDGET_NAME_HARDRESET_BUTTON = "HardReset"; private static final String WIDGET_NAME_HARDRESET_BUTTON = "HardReset";
private static final String WIDGET_NAME_REFRESHCOMPANION_BUTTON = "RefreshCompanion";
private static final String WIDGET_NAME_PROJECT = "Project"; private static final String WIDGET_NAME_PROJECT = "Project";
private static final String WIDGET_NAME_SETTINGS = "Settings"; private static final String WIDGET_NAME_SETTINGS = "Settings";
private static final String WIDGET_NAME_AUTOLOAD = "Autoload Last Project"; private static final String WIDGET_NAME_AUTOLOAD = "Autoload Last Project";
Expand Down Expand Up @@ -253,6 +254,9 @@ private void createConnectMenu() {
connectItems.add(new DropDownItem(WIDGET_NAME_USB_BUTTON, MESSAGES.usbMenuItem(), connectItems.add(new DropDownItem(WIDGET_NAME_USB_BUTTON, MESSAGES.usbMenuItem(),
new UsbAction())); new UsbAction()));
connectItems.add(null); connectItems.add(null);
connectItems.add(new DropDownItem(WIDGET_NAME_REFRESHCOMPANION_BUTTON, MESSAGES.refreshCompanionMenuItem(),
new RefreshCompanionAction()));
connectItems.add(null);
connectItems.add(new DropDownItem(WIDGET_NAME_RESET_BUTTON, MESSAGES.resetConnectionsMenuItem(), connectItems.add(new DropDownItem(WIDGET_NAME_RESET_BUTTON, MESSAGES.resetConnectionsMenuItem(),
new ResetAction())); new ResetAction()));
connectItems.add(new DropDownItem(WIDGET_NAME_HARDRESET_BUTTON, MESSAGES.hardResetConnectionsMenuItem(), connectItems.add(new DropDownItem(WIDGET_NAME_HARDRESET_BUTTON, MESSAGES.hardResetConnectionsMenuItem(),
Expand Down Expand Up @@ -485,6 +489,15 @@ public void execute() {
} }
} }


private class RefreshCompanionAction implements Command {
@Override
public void execute() {
if (Ode.getInstance().okToConnect()) {
replUpdate();
}
}
}

private class BarcodeAction implements Command { private class BarcodeAction implements Command {


private boolean secondBuildserver = false; private boolean secondBuildserver = false;
Expand Down Expand Up @@ -966,10 +979,12 @@ private void updateConnectToDropDownButton(boolean isEmulatorRunning, boolean is
connectDropDown.setItemEnabled(MESSAGES.AICompanionMenuItem(), true); connectDropDown.setItemEnabled(MESSAGES.AICompanionMenuItem(), true);
connectDropDown.setItemEnabled(MESSAGES.emulatorMenuItem(), true); connectDropDown.setItemEnabled(MESSAGES.emulatorMenuItem(), true);
connectDropDown.setItemEnabled(MESSAGES.usbMenuItem(), true); connectDropDown.setItemEnabled(MESSAGES.usbMenuItem(), true);
connectDropDown.setItemEnabled(MESSAGES.refreshCompanionMenuItem(), false);
} else { } else {
connectDropDown.setItemEnabled(MESSAGES.AICompanionMenuItem(), false); connectDropDown.setItemEnabled(MESSAGES.AICompanionMenuItem(), false);
connectDropDown.setItemEnabled(MESSAGES.emulatorMenuItem(), false); connectDropDown.setItemEnabled(MESSAGES.emulatorMenuItem(), false);
connectDropDown.setItemEnabled(MESSAGES.usbMenuItem(), false); connectDropDown.setItemEnabled(MESSAGES.usbMenuItem(), false);
connectDropDown.setItemEnabled(MESSAGES.refreshCompanionMenuItem(), true);
} }
} }


Expand Down Expand Up @@ -1027,6 +1042,17 @@ private void replHardReset() {
updateConnectToDropDownButton(false, false, false); updateConnectToDropDownButton(false, false, false);
} }


private void replUpdate() {
DesignToolbar.DesignProject currentProject = Ode.getInstance().getDesignToolbar().getCurrentProject();
if (currentProject == null) {
OdeLog.wlog("DesignToolbar.currentProject is null. "
+ "Ignoring attempt to refresh companion screen.");
return;
}
DesignToolbar.Screen screen = currentProject.screens.get(currentProject.currentScreen);
((YaBlocksEditor)screen.blocksEditor).sendComponentData(true);
}

/** /**
* Enables and/or disables buttons based on how many projects exist * Enables and/or disables buttons based on how many projects exist
* (in the case of "Download All Projects") or are selected (in the case * (in the case of "Download All Projects") or are selected (in the case
Expand Down
Expand Up @@ -265,12 +265,16 @@ public String getYail(String formJson, String packageName) throws YailGeneration
* @throws YailGenerationException if there was a problem generating the Yail * @throws YailGenerationException if there was a problem generating the Yail
*/ */
public void sendComponentData(String formJson, String packageName) throws YailGenerationException { public void sendComponentData(String formJson, String packageName) throws YailGenerationException {
sendComponentData(formJson, packageName, false);
}

public void sendComponentData(String formJson, String packageName, boolean force) throws YailGenerationException {
if (!currentForm.equals(formName)) { // Not working on the current form... if (!currentForm.equals(formName)) { // Not working on the current form...
OdeLog.log("Not working on " + currentForm + " (while sending for " + formName + ")"); OdeLog.log("Not working on " + currentForm + " (while sending for " + formName + ")");
return; return;
} }
try { try {
doSendJson(formJson, packageName); doSendJson(formJson, packageName, force);
} catch (JavaScriptException e) { } catch (JavaScriptException e) {
throw new YailGenerationException(e.getDescription(), formName); throw new YailGenerationException(e.getDescription(), formName);
} }
Expand Down Expand Up @@ -805,9 +809,13 @@ public native String doGetYail(String formJson, String packageName) /*-{
.getFormYail(formJson, packageName); .getFormYail(formJson, packageName);
}-*/; }-*/;


public native void doSendJson(String formJson, String packageName) /*-{ public void doSendJson(String formJson, String packageName) {
doSendJson(formJson, packageName, false);
};

public native void doSendJson(String formJson, String packageName, boolean force) /*-{
Blockly.ReplMgr.sendFormData(formJson, packageName, Blockly.ReplMgr.sendFormData(formJson, packageName,
this.@com.google.appinventor.client.editor.youngandroid.BlocklyPanel::workspace); this.@com.google.appinventor.client.editor.youngandroid.BlocklyPanel::workspace, force);
}-*/; }-*/;


public native void doResetYail() /*-{ public native void doResetYail() /*-{
Expand Down
Expand Up @@ -312,9 +312,12 @@ public void getBlocksImage(Callback<String, String> callback) {
} }


public synchronized void sendComponentData() { public synchronized void sendComponentData() {
sendComponentData(false);
}

public synchronized void sendComponentData(boolean force) {
try { try {
blocksArea.sendComponentData(myFormEditor.encodeFormAsJsonString(true), blocksArea.sendComponentData(myFormEditor.encodeFormAsJsonString(true), packageNameFromPath(getFileId()), force);
packageNameFromPath(getFileId()));
} catch (YailGenerationException e) { } catch (YailGenerationException e) {
e.printStackTrace(); e.printStackTrace();
} }
Expand Down
13 changes: 7 additions & 6 deletions appinventor/blocklyeditor/src/replmgr.js
Expand Up @@ -99,8 +99,9 @@ Blockly.ReplMgr.isConnected = function() {
/** /**
* Build YAIL for sending to the companion. * Build YAIL for sending to the companion.
* @param {Blockly.WorkspaceSvg} workspace * @param {Blockly.WorkspaceSvg} workspace
* @param {boolean=} opt_force
*/ */
Blockly.ReplMgr.buildYail = function(workspace) { Blockly.ReplMgr.buildYail = function(workspace, opt_force) {
var phoneState; var phoneState;
var code = []; var code = [];
var blocks; var blocks;
Expand Down Expand Up @@ -157,7 +158,7 @@ Blockly.ReplMgr.buildYail = function(workspace) {


code = code.join('\n'); code = code.join('\n');


if (phoneState.componentYail != code) { if (phoneState.componentYail != code || opt_force) {
// We need to send all of the component cruft (sorry) // We need to send all of the component cruft (sorry)
needinitialize = true; needinitialize = true;
phoneState.blockYail = {}; // Sorry, have to send the blocks again. phoneState.blockYail = {}; // Sorry, have to send the blocks again.
Expand Down Expand Up @@ -246,21 +247,21 @@ Blockly.ReplMgr.buildYail = function(workspace) {
} }
}; };


Blockly.ReplMgr.sendFormData = function(formJson, packageName, workspace) { Blockly.ReplMgr.sendFormData = function(formJson, packageName, workspace, opt_force) {
top.ReplState.phoneState.formJson = formJson; top.ReplState.phoneState.formJson = formJson;
top.ReplState.phoneState.packageName = packageName; top.ReplState.phoneState.packageName = packageName;
var context = this; var context = this;
var poller = function() { // Keep track of "this" var poller = function() { // Keep track of "this"
context.polltimer = null; context.polltimer = null;
return context.pollYail.call(context, workspace); return context.pollYail.call(context, workspace, opt_force);
}; };
if (this.polltimer) { // We have one running, punt it. if (this.polltimer) { // We have one running, punt it.
clearTimeout(this.polltimer); clearTimeout(this.polltimer);
} }
this.polltimer = setTimeout(poller, 500); this.polltimer = setTimeout(poller, 500);
}; };


Blockly.ReplMgr.pollYail = function(workspace) { Blockly.ReplMgr.pollYail = function(workspace, opt_force) {
var RefreshAssets = top.AssetManager_refreshAssets; var RefreshAssets = top.AssetManager_refreshAssets;
try { try {
if (window === undefined) // If window is gone, then we are a zombie timer firing if (window === undefined) // If window is gone, then we are a zombie timer firing
Expand All @@ -269,7 +270,7 @@ Blockly.ReplMgr.pollYail = function(workspace) {
return; return;
} }
if (top.ReplState.state == this.rsState.CONNECTED) { if (top.ReplState.state == this.rsState.CONNECTED) {
this.buildYail(workspace); this.buildYail(workspace, opt_force);
} }
if (top.ReplState.state == this.rsState.CONNECTED) { if (top.ReplState.state == this.rsState.CONNECTED) {
RefreshAssets(function() {}); RefreshAssets(function() {});
Expand Down

0 comments on commit ae9e02d

Please sign in to comment.