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 { ...@@ -870,7 +870,9 @@ public class Ode implements EntryPoint {
@Override @Override
public void onProjectsLoaded() { public void onProjectsLoaded() {
projectManager.removeProjectManagerEventListener(this); projectManager.removeProjectManagerEventListener(this);
openPreviousProject(); if (shouldAutoloadLastProject()) {
openPreviousProject();
}
// This handles any built-in templates stored in /war // This handles any built-in templates stored in /war
// Retrieve template data stored in war/templates folder and // Retrieve template data stored in war/templates folder and
...@@ -1530,6 +1532,23 @@ public class Ode implements EntryPoint { ...@@ -1530,6 +1532,23 @@ public class Ode implements EntryPoint {
return user; 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. * Returns user dyslexic font setting.
* *
...@@ -1553,6 +1572,28 @@ public class Ode implements EntryPoint { ...@@ -1553,6 +1572,28 @@ public class Ode implements EntryPoint {
userSettings.saveSettings(null); 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. * Helper method to create push buttons.
* *
......
...@@ -693,6 +693,14 @@ public interface OdeMessages extends Messages, AutogeneratedOdeMessages { ...@@ -693,6 +693,14 @@ public interface OdeMessages extends Messages, AutogeneratedOdeMessages {
@Description("User Settings") @Description("User Settings")
String settingsTabName(); 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") @DefaultMessage("Enable OpenDyslexic")
@Description("Switch to enable OpenDyslexic") @Description("Switch to enable OpenDyslexic")
String enableOpenDyslexic(); String enableOpenDyslexic();
......
...@@ -411,26 +411,18 @@ public class ProjectToolbar extends Toolbar { ...@@ -411,26 +411,18 @@ public class ProjectToolbar extends Toolbar {
setButtonEnabled(WIDGET_NAME_NEW, false); setButtonEnabled(WIDGET_NAME_NEW, false);
setButtonEnabled(WIDGET_NAME_DELETE, false); setButtonEnabled(WIDGET_NAME_DELETE, false);
setButtonEnabled(WIDGET_NAME_PUBLISH_OR_UPDATE, false); setButtonEnabled(WIDGET_NAME_PUBLISH_OR_UPDATE, false);
Ode.getInstance().getTopToolbar().fileDropDown.setItemEnabled(MESSAGES.exportProjectMenuItem(), Ode.getInstance().getTopToolbar().updateMenuState(numSelectedProjects, numProjects);
numSelectedProjects > 0);
Ode.getInstance().getTopToolbar().fileDropDown.setItemEnabled(MESSAGES.exportAllProjectsMenuItem(),
numSelectedProjects > 0);
return; return;
} }
setButtonEnabled(WIDGET_NAME_DELETE, numSelectedProjects > 0); setButtonEnabled(WIDGET_NAME_DELETE, numSelectedProjects > 0);
setButtonEnabled(WIDGET_NAME_PUBLISH_OR_UPDATE, numSelectedProjects == 1); setButtonEnabled(WIDGET_NAME_PUBLISH_OR_UPDATE, numSelectedProjects == 1);
if(numSelectedProjects == 1 && ProjectListBox.getProjectListBox().getProjectList() if (numSelectedProjects == 1 && ProjectListBox.getProjectListBox().getProjectList()
.getSelectedProjects().get(0).isPublished()){ .getSelectedProjects().get(0).isPublished()){
setButtonText(WIDGET_NAME_PUBLISH_OR_UPDATE, MESSAGES.updateGalleryAppButton()); setButtonText(WIDGET_NAME_PUBLISH_OR_UPDATE, MESSAGES.updateGalleryAppButton());
}else{ } else {
setButtonText(WIDGET_NAME_PUBLISH_OR_UPDATE, MESSAGES.publishToGalleryButton()); setButtonText(WIDGET_NAME_PUBLISH_OR_UPDATE, MESSAGES.publishToGalleryButton());
} }
Ode.getInstance().getTopToolbar().fileDropDown.setItemEnabled(MESSAGES.deleteProjectMenuItem(), Ode.getInstance().getTopToolbar().updateMenuState(numSelectedProjects, numProjects);
numSelectedProjects > 0);
Ode.getInstance().getTopToolbar().fileDropDown.setItemEnabled(MESSAGES.exportProjectMenuItem(),
numSelectedProjects > 0);
Ode.getInstance().getTopToolbar().fileDropDown.setItemEnabled(MESSAGES.exportAllProjectsMenuItem(),
numSelectedProjects > 0);
} }
public void updateTrashButtons() { public void updateTrashButtons() {
......
...@@ -35,6 +35,8 @@ public final class GeneralSettings extends Settings { ...@@ -35,6 +35,8 @@ public final class GeneralSettings extends Settings {
EditableProperty.TYPE_INVISIBLE)); EditableProperty.TYPE_INVISIBLE));
addProperty(new EditableProperty(this, SettingsConstants.USER_DYSLEXIC_FONT, "false", addProperty(new EditableProperty(this, SettingsConstants.USER_DYSLEXIC_FONT, "false",
EditableProperty.TYPE_INVISIBLE)); EditableProperty.TYPE_INVISIBLE));
addProperty(new EditableProperty(this, SettingsConstants.USER_AUTOLOAD_PROJECT, "true",
EditableProperty.TYPE_INVISIBLE));
} }
@Override @Override
......
...@@ -184,7 +184,11 @@ public class DropDownButton extends TextButton { ...@@ -184,7 +184,11 @@ public class DropDownButton extends TextButton {
} }
public void addItem(DropDownItem item) { 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) { public void removeItem(String itemName) {
......
...@@ -28,6 +28,7 @@ public class SettingsConstants { ...@@ -28,6 +28,7 @@ public class SettingsConstants {
public static final String DISABLED_USER_URL = "DisabledUserUrl"; public static final String DISABLED_USER_URL = "DisabledUserUrl";
public static final String USER_LAST_LOCALE = "LastLocale"; public static final String USER_LAST_LOCALE = "LastLocale";
public static final String USER_DYSLEXIC_FONT = "DyslexicFont"; public static final String USER_DYSLEXIC_FONT = "DyslexicFont";
public static final String USER_AUTOLOAD_PROJECT = "AutoloadLastProject";
public static final String SPLASH_SETTINGS = "SplashSettings"; 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