Commit e76e792e authored by Evan W. Patton's avatar Evan W. Patton Committed by Jeffrey Schiller

Implement option to disable project auto load

Autoload behavior can be overriden per session by including
autoload=false or autoload=true in the query string when loading App
Inventor.

This commit also refactors the menu construction into individual
pieces so that they can be called to be reconfigured. At the moment,
this feature is only used for the Settings menu, but it makes the
creation of each menu independent of any other menu.

Change-Id: Id220991cef5f7643465ef9648f663a52be1486ae
parent a5efc617
......@@ -870,7 +870,9 @@ public class Ode implements EntryPoint {
@Override
public void onProjectsLoaded() {
projectManager.removeProjectManagerEventListener(this);
openPreviousProject();
if (shouldAutoloadLastProject()) {
openPreviousProject();
}
// This handles any built-in templates stored in /war
// Retrieve template data stored in war/templates folder and
......@@ -1530,6 +1532,23 @@ public class Ode implements EntryPoint {
return user;
}
/**
* Checks whether autoloading of the user's previous project should be
* performed.
*
* @return true if autoloading should be performed, otherwise false.
*/
public boolean shouldAutoloadLastProject() {
String autoloadParam = Window.Location.getParameter("autoload");
if ("false".equalsIgnoreCase(autoloadParam)) {
return false;
} else if ("true".equalsIgnoreCase(autoloadParam)) {
return true;
}
return getUserAutoloadProject();
}
/**
* Returns user dyslexic font setting.
*
......@@ -1553,6 +1572,28 @@ public class Ode implements EntryPoint {
userSettings.saveSettings(null);
}
/**
* Checks whether the user has autoloading enabled in their settings.
*
* @return true if autoloading is enabled, otherwise false.
*/
public static boolean getUserAutoloadProject() {
String value = userSettings.getSettings(SettingsConstants.USER_GENERAL_SETTINGS)
.getPropertyValue(SettingsConstants.USER_AUTOLOAD_PROJECT);
return Boolean.parseBoolean(value);
}
/**
* Sets whether to use autoloading for the current user.
*
* @param enable true if autoloading should be enabled or false if it should be disabled.
*/
public static void setUserAutoloadProject(boolean enable) {
userSettings.getSettings(SettingsConstants.USER_GENERAL_SETTINGS)
.changePropertyValue(SettingsConstants.USER_AUTOLOAD_PROJECT, Boolean.toString(enable));
userSettings.saveSettings(null);
}
/**
* Helper method to create push buttons.
*
......
......@@ -693,6 +693,14 @@ public interface OdeMessages extends Messages, AutogeneratedOdeMessages {
@Description("User Settings")
String settingsTabName();
@DefaultMessage("Enable Project Autoload")
@Description("Menu item to enable automatic loading of projects when App Inventor is opened.")
String enableAutoload();
@DefaultMessage("Disable Project Autoload")
@Description("Menu item to disable automatic loading of projects when App Inventor is opened.")
String disableAutoload();
@DefaultMessage("Enable OpenDyslexic")
@Description("Switch to enable OpenDyslexic")
String enableOpenDyslexic();
......
......@@ -7,7 +7,6 @@
package com.google.appinventor.client;
import com.google.appinventor.client.boxes.ProjectListBox;
import com.google.appinventor.client.boxes.ViewerBox;
import com.google.appinventor.client.editor.youngandroid.BlocklyPanel;
import com.google.appinventor.client.editor.youngandroid.YaBlocksEditor;
import com.google.appinventor.client.explorer.commands.BuildCommand;
......@@ -47,7 +46,6 @@ import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.Window.Location;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
......@@ -55,7 +53,6 @@ import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
......@@ -93,6 +90,7 @@ public class TopToolbar extends Composite {
private static final String WIDGET_NAME_HARDRESET_BUTTON = "HardReset";
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";
private static final String WIDGET_NAME_DYSLEXIC_FONT = "DyslexicFont";
private static final String WIDGET_NAME_HELP = "Help";
private static final String WIDGET_NAME_ABOUT = "About";
......@@ -110,12 +108,6 @@ public class TopToolbar extends Composite {
private static final String WIDGET_NAME_IMPORTTEMPLATE = "ImportTemplate";
private static final String WIDGET_NAME_EXPORTALLPROJECTS = "ExportAllProjects";
private static final String WIDGET_NAME_EXPORTPROJECT = "ExportProject";
private static final String WIDGET_NAME_COMPONENTS = "Components";
private static final String WIDGET_NAME_MY_COMPONENTS = "MyComponents";
private static final String WIDGET_NAME_START_NEW_COMPONENT = "StartNewComponent";
private static final String WIDGET_NAME_IMPORT_COMPONENT = "ImportComponent";
private static final String WIDGET_NAME_BUILD_COMPONENT = "BuildComponent";
private static final String WIDGET_NAME_UPLOAD_COMPONENT = "UploadComponent";
private static final String WIDGET_NAME_ADMIN = "Admin";
private static final String WIDGET_NAME_USER_ADMIN = "UserAdmin";
......@@ -124,12 +116,12 @@ public class TopToolbar extends Composite {
private static final String WINDOW_OPEN_FEATURES = "menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes";
private static final String WINDOW_OPEN_LOCATION = "_ai2";
public DropDownButton fileDropDown;
public DropDownButton connectDropDown;
public DropDownButton buildDropDown;
public DropDownButton helpDropDown;
public DropDownButton adminDropDown;
public DropDownButton settingsDropDown;
private DropDownButton fileDropDown;
private DropDownButton connectDropDown;
private DropDownButton buildDropDown;
private DropDownButton helpDropDown;
private DropDownButton adminDropDown;
private DropDownButton settingsDropDown;
private boolean isReadOnly;
/**
......@@ -156,17 +148,63 @@ public class TopToolbar extends Composite {
HorizontalPanel toolbar = new HorizontalPanel();
toolbar.setVerticalAlignment(HorizontalPanel.ALIGN_MIDDLE);
List<DropDownItem> fileItems = Lists.newArrayList();
List<DropDownItem> componentItems = Lists.newArrayList();
List<DropDownItem> connectItems = Lists.newArrayList();
List<DropDownItem> buildItems = Lists.newArrayList();
List<DropDownItem> settingsItems = Lists.newArrayList();
List<DropDownItem> helpItems = Lists.newArrayList();
// Should the UI be in read only mode?
isReadOnly = Ode.getInstance().isReadOnly();
// File -> {New Project; Save; Save As; Checkpoint; |; Delete this Project; My Projects;}
// Create the TopToolbar drop down menus.
fileDropDown = makeButton(WIDGET_NAME_PROJECT, MESSAGES.projectsTabName());
connectDropDown = makeButton(WIDGET_NAME_CONNECT_TO, MESSAGES.connectTabName());
buildDropDown = makeButton(WIDGET_NAME_BUILD, MESSAGES.buildTabName());
settingsDropDown = makeButton(WIDGET_NAME_SETTINGS, MESSAGES.settingsTabName());
helpDropDown = makeButton(WIDGET_NAME_HELP, MESSAGES.helpTabName());
createProjectsMenu();
createConnectMenu();
createBuildMenu();
createSettingsMenu();
createHelpMenu();
// Add the Buttons to the Toolbar.
toolbar.add(fileDropDown);
toolbar.add(connectDropDown);
toolbar.add(buildDropDown);
toolbar.add(settingsDropDown);
toolbar.add(helpDropDown);
//Only if logged in as an admin, add the Admin Button
if (Ode.getInstance().getUser().getIsAdmin()) {
adminDropDown = makeButton(WIDGET_NAME_ADMIN, MESSAGES.adminTabName());
createAdminMenu();
toolbar.add(adminDropDown);
}
initWidget(toolbar);
}
public void updateMenuState(int numSelectedProjects, int numProjects) {
boolean allowDelete = !isReadOnly && numSelectedProjects > 0;
boolean allowExport = numSelectedProjects > 0;
boolean allowExportAll = numProjects > 0;
fileDropDown.setItemEnabled(MESSAGES.deleteProjectMenuItem(), allowDelete);
fileDropDown.setItemEnabled(MESSAGES.exportProjectMenuItem(), allowExport);
fileDropDown.setItemEnabled(MESSAGES.exportAllProjectsMenuItem(), allowExportAll);
}
private DropDownButton makeButton(String id, String text) {
DropDownButton button = new DropDownButton(id, text, new ArrayList<DropDownItem>(), false);
button.setStyleName("ode-TopPanelButton");
return button;
}
private void refreshMenu(DropDownButton menu, List<DropDownItem> items) {
menu.clearAllItems(); // ensure we start with a clean slate
for (DropDownItem i : items) {
menu.addItem(i);
}
}
private void createProjectsMenu() {
List<DropDownItem> fileItems = Lists.newArrayList();
fileItems.add(new DropDownItem(WIDGET_NAME_MY_PROJECTS, MESSAGES.projectMenuItem(),
new SwitchToProjectAction()));
fileItems.add(null);
......@@ -176,7 +214,7 @@ public class TopToolbar extends Composite {
fileItems.add(new DropDownItem(WIDGET_NAME_IMPORTPROJECT, MESSAGES.importProjectMenuItem(),
new ImportProjectAction()));
fileItems.add(new DropDownItem(WIDGET_NAME_IMPORTTEMPLATE, MESSAGES.importTemplateButton(),
new ImportTemplateAction()));
new ImportTemplateAction()));
fileItems.add(new DropDownItem(WIDGET_NAME_DELETE, MESSAGES.deleteProjectButton(),
new DeleteAction()));
fileItems.add(null);
......@@ -203,8 +241,11 @@ public class TopToolbar extends Composite {
fileItems.add(new DropDownItem(WIDGET_NAME_DELETE_KEYSTORE, MESSAGES.deleteKeystoreMenuItem(),
new DeleteKeystoreAction()));
}
refreshMenu(fileDropDown, fileItems);
}
// Connect -> {Connect to Companion; Connect to Emulator; Connect to USB; Reset Connections}
private void createConnectMenu() {
List<DropDownItem> connectItems = Lists.newArrayList();
connectItems.add(new DropDownItem(WIDGET_NAME_WIRELESS_BUTTON,
MESSAGES.AICompanionMenuItem(), new WirelessAction()));
connectItems.add(new DropDownItem(WIDGET_NAME_EMULATOR_BUTTON,
......@@ -216,8 +257,11 @@ public class TopToolbar extends Composite {
new ResetAction()));
connectItems.add(new DropDownItem(WIDGET_NAME_HARDRESET_BUTTON, MESSAGES.hardResetConnectionsMenuItem(),
new HardResetAction()));
refreshMenu(connectDropDown, connectItems);
}
// Build -> {Show Barcode; Download to Computer; Generate YAIL only when logged in as an admin}
private void createBuildMenu() {
List<DropDownItem> buildItems = Lists.newArrayList();
buildItems.add(new DropDownItem(WIDGET_NAME_BUILD_BARCODE, MESSAGES.showBarcodeMenuItem(),
new BarcodeAction(false)));
buildItems.add(new DropDownItem(WIDGET_NAME_BUILD_DOWNLOAD, MESSAGES.downloadToComputerMenuItem(),
......@@ -250,20 +294,34 @@ public class TopToolbar extends Composite {
buildItems.add(new DropDownItem(WIDGET_NAME_BUILD_YAIL, MESSAGES.generateYailMenuItem(),
new GenerateYailAction()));
}
refreshMenu(buildDropDown, buildItems);
}
// Settings -> {Enable OpenDyslexic}
if (Ode.getInstance().getUserDyslexicFont()) {
settingsItems.add(new DropDownItem(WIDGET_NAME_DYSLEXIC_FONT, MESSAGES.disableOpenDyslexic(), new SetFontRegularAction()));
private void createSettingsMenu() {
List<DropDownItem> settingsItems = Lists.newArrayList();
if (Ode.getUserAutoloadProject()) {
settingsItems.add(new DropDownItem(WIDGET_NAME_AUTOLOAD, MESSAGES.disableAutoload(),
new DisableAutoloadAction()));
} else {
settingsItems.add(new DropDownItem(WIDGET_NAME_AUTOLOAD, MESSAGES.enableAutoload(),
new EnableAutoloadAction()));
}
if (Ode.getUserDyslexicFont()) {
settingsItems.add(new DropDownItem(WIDGET_NAME_DYSLEXIC_FONT, MESSAGES.disableOpenDyslexic(),
new SetFontRegularAction()));
} else {
settingsItems.add(new DropDownItem(WIDGET_NAME_DYSLEXIC_FONT, MESSAGES.enableOpenDyslexic(), new SetFontDyslexicAction()));
settingsItems.add(new DropDownItem(WIDGET_NAME_DYSLEXIC_FONT, MESSAGES.enableOpenDyslexic(),
new SetFontDyslexicAction()));
}
refreshMenu(settingsDropDown, settingsItems);
}
// Help -> {About, Library, Get Started, Tutorials, Troubleshooting, Forums, Report an Issue,
// Companion Information, Show Splash Screen}
private void createHelpMenu() {
List<DropDownItem> helpItems = Lists.newArrayList();
helpItems.add(new DropDownItem(WIDGET_NAME_ABOUT, MESSAGES.aboutMenuItem(),
new AboutAction()));
helpItems.add(null);
Config config = Ode.getInstance().getSystemConfig();
Config config = Ode.getSystemConfig();
String libraryUrl = config.getLibraryUrl();
if (!Strings.isNullOrEmpty(libraryUrl)) {
helpItems.add(new DropDownItem(WIDGET_NAME_LIBRARY, MESSAGES.libraryMenuItem(),
......@@ -307,52 +365,21 @@ public class TopToolbar extends Composite {
new CompanionUpdateAction()));
helpItems.add(new DropDownItem(WIDGET_NAME_SHOWSPLASH, MESSAGES.showSplashMenuItem(),
new ShowSplashAction()));
refreshMenu(helpDropDown, helpItems);
}
// Create the TopToolbar drop down menus.
fileDropDown = new DropDownButton(WIDGET_NAME_PROJECT, MESSAGES.projectsTabName(),
fileItems, false);
connectDropDown = new DropDownButton(WIDGET_NAME_CONNECT_TO, MESSAGES.connectTabName(),
connectItems, false);
buildDropDown = new DropDownButton(WIDGET_NAME_BUILD, MESSAGES.buildTabName(),
buildItems, false);
settingsDropDown = new DropDownButton(WIDGET_NAME_SETTINGS, MESSAGES.settingsTabName(),
settingsItems, false);
helpDropDown = new DropDownButton(WIDGET_NAME_HELP, MESSAGES.helpTabName(),
helpItems, false);
// Set the DropDown Styles
fileDropDown.setStyleName("ode-TopPanelButton");
connectDropDown.setStyleName("ode-TopPanelButton");
buildDropDown.setStyleName("ode-TopPanelButton");
settingsDropDown.setStyleName("ode-TopPanelButton");
helpDropDown.setStyleName("ode-TopPanelButton");
// Add the Buttons to the Toolbar.
toolbar.add(fileDropDown);
toolbar.add(connectDropDown);
toolbar.add(buildDropDown);
toolbar.add(settingsDropDown);
// Commented out language switching until we have a clean Chinese translation. (AFM)
toolbar.add(helpDropDown);
//Only if logged in as an admin, add the Admin Button
if (Ode.getInstance().getUser().getIsAdmin()) {
List<DropDownItem> adminItems = Lists.newArrayList();
adminItems.add(new DropDownItem(WIDGET_NAME_DOWNLOAD_USER_SOURCE,
MESSAGES.downloadUserSourceMenuItem(), new DownloadUserSourceAction()));
adminItems.add(new DropDownItem(WIDGET_NAME_SWITCH_TO_DEBUG,
MESSAGES.switchToDebugMenuItem(), new SwitchToDebugAction()));
adminItems.add(new DropDownItem(WIDGET_NAME_USER_ADMIN,
"User Admin", new SwitchToUserAdminAction()));
adminDropDown = new DropDownButton(WIDGET_NAME_ADMIN, MESSAGES.adminTabName(), adminItems,
false);
adminDropDown.setStyleName("ode-TopPanelButton");
toolbar.add(adminDropDown);
private void createAdminMenu() {
if (adminDropDown == null) {
return; // the button won't exist if the user isn't an admin
}
initWidget(toolbar);
List<DropDownItem> adminItems = Lists.newArrayList();
adminItems.add(new DropDownItem(WIDGET_NAME_DOWNLOAD_USER_SOURCE,
MESSAGES.downloadUserSourceMenuItem(), new DownloadUserSourceAction()));
adminItems.add(new DropDownItem(WIDGET_NAME_SWITCH_TO_DEBUG,
MESSAGES.switchToDebugMenuItem(), new SwitchToDebugAction()));
adminItems.add(new DropDownItem(WIDGET_NAME_USER_ADMIN,
"User Admin", new SwitchToUserAdminAction()));
refreshMenu(adminDropDown, adminItems);
}
// -----------------------------
......@@ -765,6 +792,22 @@ public class TopToolbar extends Composite {
}
}
private class EnableAutoloadAction implements Command {
@Override
public void execute() {
Ode.getInstance().setUserAutoloadProject(true);
createSettingsMenu();
}
}
private class DisableAutoloadAction implements Command {
@Override
public void execute() {
Ode.getInstance().setUserAutoloadProject(false);
createSettingsMenu();
}
}
private static class SetFontDyslexicAction implements Command {
@Override
public void execute() {
......
......@@ -411,26 +411,18 @@ public class ProjectToolbar extends Toolbar {
setButtonEnabled(WIDGET_NAME_NEW, false);
setButtonEnabled(WIDGET_NAME_DELETE, false);
setButtonEnabled(WIDGET_NAME_PUBLISH_OR_UPDATE, false);
Ode.getInstance().getTopToolbar().fileDropDown.setItemEnabled(MESSAGES.exportProjectMenuItem(),
numSelectedProjects > 0);
Ode.getInstance().getTopToolbar().fileDropDown.setItemEnabled(MESSAGES.exportAllProjectsMenuItem(),
numSelectedProjects > 0);
Ode.getInstance().getTopToolbar().updateMenuState(numSelectedProjects, numProjects);
return;
}
setButtonEnabled(WIDGET_NAME_DELETE, numSelectedProjects > 0);
setButtonEnabled(WIDGET_NAME_PUBLISH_OR_UPDATE, numSelectedProjects == 1);
if(numSelectedProjects == 1 && ProjectListBox.getProjectListBox().getProjectList()
if (numSelectedProjects == 1 && ProjectListBox.getProjectListBox().getProjectList()
.getSelectedProjects().get(0).isPublished()){
setButtonText(WIDGET_NAME_PUBLISH_OR_UPDATE, MESSAGES.updateGalleryAppButton());
}else{
} else {
setButtonText(WIDGET_NAME_PUBLISH_OR_UPDATE, MESSAGES.publishToGalleryButton());
}
Ode.getInstance().getTopToolbar().fileDropDown.setItemEnabled(MESSAGES.deleteProjectMenuItem(),
numSelectedProjects > 0);
Ode.getInstance().getTopToolbar().fileDropDown.setItemEnabled(MESSAGES.exportProjectMenuItem(),
numSelectedProjects > 0);
Ode.getInstance().getTopToolbar().fileDropDown.setItemEnabled(MESSAGES.exportAllProjectsMenuItem(),
numSelectedProjects > 0);
Ode.getInstance().getTopToolbar().updateMenuState(numSelectedProjects, numProjects);
}
public void updateTrashButtons() {
......
......@@ -35,6 +35,8 @@ public final class GeneralSettings extends Settings {
EditableProperty.TYPE_INVISIBLE));
addProperty(new EditableProperty(this, SettingsConstants.USER_DYSLEXIC_FONT, "false",
EditableProperty.TYPE_INVISIBLE));
addProperty(new EditableProperty(this, SettingsConstants.USER_AUTOLOAD_PROJECT, "true",
EditableProperty.TYPE_INVISIBLE));
}
@Override
......
......@@ -184,7 +184,11 @@ public class DropDownButton extends TextButton {
}
public void addItem(DropDownItem item) {
items.add(menu.addItem(item.caption, true, item.command));
if (item == null) {
menu.addSeparator();
} else {
items.add(menu.addItem(item.caption, true, item.command));
}
}
public void removeItem(String itemName) {
......
......@@ -28,6 +28,7 @@ public class SettingsConstants {
public static final String DISABLED_USER_URL = "DisabledUserUrl";
public static final String USER_LAST_LOCALE = "LastLocale";
public static final String USER_DYSLEXIC_FONT = "DyslexicFont";
public static final String USER_AUTOLOAD_PROJECT = "AutoloadLastProject";
public static final String SPLASH_SETTINGS = "SplashSettings";
......
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