Skip to content
Permalink
Browse files

Add refresh companion item to connect menu

  • Loading branch information
kalsheikh authored and ewpatton committed Jan 2, 2020
1 parent a29c047 commit ae9e02dd11c64f311e5e08b86d27412555f5ed62
@@ -603,6 +603,10 @@
@Description("Hard Reset the Emulator.")
String hardResetConnectionsMenuItem();

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

//Build
@DefaultMessage("Build")
@Description("Label of the button leading to build related cascade items")
@@ -88,6 +88,7 @@
private static final String WIDGET_NAME_USB_BUTTON = "Usb";
private static final String WIDGET_NAME_RESET_BUTTON = "Reset";
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_SETTINGS = "Settings";
private static final String WIDGET_NAME_AUTOLOAD = "Autoload Last Project";
@@ -253,6 +254,9 @@ private void createConnectMenu() {
connectItems.add(new DropDownItem(WIDGET_NAME_USB_BUTTON, MESSAGES.usbMenuItem(),
new UsbAction()));
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(),
new ResetAction()));
connectItems.add(new DropDownItem(WIDGET_NAME_HARDRESET_BUTTON, MESSAGES.hardResetConnectionsMenuItem(),
@@ -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 boolean secondBuildserver = false;
@@ -966,10 +979,12 @@ private void updateConnectToDropDownButton(boolean isEmulatorRunning, boolean is
connectDropDown.setItemEnabled(MESSAGES.AICompanionMenuItem(), true);
connectDropDown.setItemEnabled(MESSAGES.emulatorMenuItem(), true);
connectDropDown.setItemEnabled(MESSAGES.usbMenuItem(), true);
connectDropDown.setItemEnabled(MESSAGES.refreshCompanionMenuItem(), false);
} else {
connectDropDown.setItemEnabled(MESSAGES.AICompanionMenuItem(), false);
connectDropDown.setItemEnabled(MESSAGES.emulatorMenuItem(), false);
connectDropDown.setItemEnabled(MESSAGES.usbMenuItem(), false);
connectDropDown.setItemEnabled(MESSAGES.refreshCompanionMenuItem(), true);
}
}

@@ -1027,6 +1042,17 @@ private void replHardReset() {
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
* (in the case of "Download All Projects") or are selected (in the case
@@ -265,12 +265,16 @@ public String getYail(String formJson, String packageName) throws YailGeneration
* @throws YailGenerationException if there was a problem generating the Yail
*/
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...
OdeLog.log("Not working on " + currentForm + " (while sending for " + formName + ")");
return;
}
try {
doSendJson(formJson, packageName);
doSendJson(formJson, packageName, force);
} catch (JavaScriptException e) {
throw new YailGenerationException(e.getDescription(), formName);
}
@@ -805,9 +809,13 @@ public native String doGetYail(String formJson, String 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,
this.@com.google.appinventor.client.editor.youngandroid.BlocklyPanel::workspace);
this.@com.google.appinventor.client.editor.youngandroid.BlocklyPanel::workspace, force);
}-*/;

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

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

public synchronized void sendComponentData(boolean force) {
try {
blocksArea.sendComponentData(myFormEditor.encodeFormAsJsonString(true),
packageNameFromPath(getFileId()));
blocksArea.sendComponentData(myFormEditor.encodeFormAsJsonString(true), packageNameFromPath(getFileId()), force);
} catch (YailGenerationException e) {
e.printStackTrace();
}
@@ -99,8 +99,9 @@ Blockly.ReplMgr.isConnected = function() {
/**
* Build YAIL for sending to the companion.
* @param {Blockly.WorkspaceSvg} workspace
* @param {boolean=} opt_force
*/
Blockly.ReplMgr.buildYail = function(workspace) {
Blockly.ReplMgr.buildYail = function(workspace, opt_force) {
var phoneState;
var code = [];
var blocks;
@@ -157,7 +158,7 @@ Blockly.ReplMgr.buildYail = function(workspace) {

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

if (phoneState.componentYail != code) {
if (phoneState.componentYail != code || opt_force) {
// We need to send all of the component cruft (sorry)
needinitialize = true;
phoneState.blockYail = {}; // Sorry, have to send the blocks again.
@@ -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.packageName = packageName;
var context = this;
var poller = function() { // Keep track of "this"
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.
clearTimeout(this.polltimer);
}
this.polltimer = setTimeout(poller, 500);
};

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

0 comments on commit ae9e02d

Please sign in to comment.
You can’t perform that action at this time.