Commit c2a2ac18 authored by Matthew Coufal's avatar Matthew Coufal Committed by Susan Rati Lane

Make "Display hidden components in Viewer" checkbox screen-dependent (#1852)

* Cache checkbox state for each screen
* Make hidden components checkbox screen-dependent
parent 9ae15246
...@@ -23,6 +23,8 @@ import java.util.Collections; ...@@ -23,6 +23,8 @@ import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
/** /**
* Abstract superclass for all project editors. * Abstract superclass for all project editors.
...@@ -50,6 +52,7 @@ public abstract class ProjectEditor extends Composite { ...@@ -50,6 +52,7 @@ public abstract class ProjectEditor extends Composite {
private final HashMap<String,String> locationHashMap = new HashMap<String,String>(); private final HashMap<String,String> locationHashMap = new HashMap<String,String>();
private final DeckPanel deckPanel; private final DeckPanel deckPanel;
private FileEditor selectedFileEditor; private FileEditor selectedFileEditor;
private final TreeMap<String, Boolean> screenHashMap = new TreeMap<String, Boolean>();
/** /**
* Creates a {@code ProjectEditor} instance. * Creates a {@code ProjectEditor} instance.
...@@ -99,6 +102,41 @@ public abstract class ProjectEditor extends Composite { ...@@ -99,6 +102,41 @@ public abstract class ProjectEditor extends Composite {
*/ */
protected abstract void onHide(); protected abstract void onHide();
public final void setScreenCheckboxState(String screen, Boolean isChecked) {
screenHashMap.put(screen, isChecked);
}
public final Boolean getScreenCheckboxState(String screen) {
return screenHashMap.get(screen);
}
public final String getScreenCheckboxMapString() {
String screenCheckboxMap = "";
int count = 0;
Set<String> screens = screenHashMap.keySet();
int size = screens.size();
for (String screen : screens) {
Boolean isChecked = screenHashMap.get(screen);
if (isChecked == null) {
continue;
}
String isCheckedString = (isChecked) ? "True" : "False";
String separator = (count == size) ? "" : " ";
screenCheckboxMap += screen + ":" + isCheckedString + separator;
}
return screenCheckboxMap;
}
public final void buildScreenHashMap(String screenCheckboxMap) {
String[] pairs = screenCheckboxMap.split(" ");
for (String pair : pairs) {
String[] mapping = pair.split(":");
String screen = mapping[0];
Boolean isChecked = Boolean.parseBoolean(mapping[1]);
screenHashMap.put(screen, isChecked);
}
}
/** /**
* Adds a file editor to this project editor. * Adds a file editor to this project editor.
* *
......
...@@ -10,6 +10,7 @@ import com.google.gwt.event.dom.client.ChangeEvent; ...@@ -10,6 +10,7 @@ import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler; import com.google.gwt.event.dom.client.ChangeHandler;
import static com.google.appinventor.client.Ode.MESSAGES; import static com.google.appinventor.client.Ode.MESSAGES;
import com.google.appinventor.client.editor.ProjectEditor; import com.google.appinventor.client.editor.ProjectEditor;
import com.google.appinventor.client.editor.simple.components.MockComponent;
import com.google.appinventor.client.editor.simple.components.MockForm; import com.google.appinventor.client.editor.simple.components.MockForm;
import com.google.appinventor.client.editor.simple.palette.SimplePaletteItem; import com.google.appinventor.client.editor.simple.palette.SimplePaletteItem;
import com.google.appinventor.client.explorer.project.ComponentDatabaseChangeListener; import com.google.appinventor.client.explorer.project.ComponentDatabaseChangeListener;
...@@ -24,7 +25,6 @@ import com.google.gwt.user.client.ui.VerticalPanel; ...@@ -24,7 +25,6 @@ import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget; import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.client.ui.ListBox; import com.google.gwt.user.client.ui.ListBox;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -65,22 +65,28 @@ public final class SimpleVisibleComponentsPanel extends Composite implements Dro ...@@ -65,22 +65,28 @@ public final class SimpleVisibleComponentsPanel extends Composite implements Dro
checkboxShowHiddenComponents = new CheckBox(MESSAGES.showHiddenComponentsCheckbox()) { checkboxShowHiddenComponents = new CheckBox(MESSAGES.showHiddenComponentsCheckbox()) {
@Override @Override
protected void onLoad() { protected void onLoad() {
// onLoad is called immediately after a widget becomes attached to the browser's document. // Get project settings
boolean showHiddenComponents = Boolean.parseBoolean( String screenCheckboxMap = projectEditor.getProjectSettingsProperty(
projectEditor.getProjectSettingsProperty(
SettingsConstants.PROJECT_YOUNG_ANDROID_SETTINGS, SettingsConstants.PROJECT_YOUNG_ANDROID_SETTINGS,
SettingsConstants.YOUNG_ANDROID_SETTINGS_SHOW_HIDDEN_COMPONENTS)); SettingsConstants.YOUNG_ANDROID_SETTINGS_SCREEN_CHECKBOX_STATE_MAP
checkboxShowHiddenComponents.setValue(showHiddenComponents); );
if (screenCheckboxMap != null && !screenCheckboxMap.equals("")) {
projectEditor.buildScreenHashMap(screenCheckboxMap);
Boolean isChecked = projectEditor.getScreenCheckboxState(form.getTitle());
checkboxShowHiddenComponents.setValue(isChecked);
}
} }
}; };
checkboxShowHiddenComponents.addValueChangeHandler(new ValueChangeHandler<Boolean>() { checkboxShowHiddenComponents.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
@Override @Override
public void onValueChange(ValueChangeEvent<Boolean> event) { public void onValueChange(ValueChangeEvent<Boolean> event) {
boolean isChecked = event.getValue(); // auto-unbox from Boolean to boolean boolean isChecked = event.getValue();
projectEditor.setScreenCheckboxState(form.getTitle(), isChecked);
projectEditor.changeProjectSettingsProperty( projectEditor.changeProjectSettingsProperty(
SettingsConstants.PROJECT_YOUNG_ANDROID_SETTINGS, SettingsConstants.PROJECT_YOUNG_ANDROID_SETTINGS,
SettingsConstants.YOUNG_ANDROID_SETTINGS_SHOW_HIDDEN_COMPONENTS, SettingsConstants.YOUNG_ANDROID_SETTINGS_SCREEN_CHECKBOX_STATE_MAP,
isChecked ? "True" : "False"); projectEditor.getScreenCheckboxMapString()
);
if (form != null) { if (form != null) {
form.refresh(); form.refresh();
} }
...@@ -125,6 +131,10 @@ public final class SimpleVisibleComponentsPanel extends Composite implements Dro ...@@ -125,6 +131,10 @@ public final class SimpleVisibleComponentsPanel extends Composite implements Dro
initWidget(phoneScreen); initWidget(phoneScreen);
} }
public boolean isHiddenComponentsCheckboxChecked() {
return checkboxShowHiddenComponents.getValue();
}
// get width and height stored in user settings, and change the preview size. // get width and height stored in user settings, and change the preview size.
private void getUserSettingChangeSize() { private void getUserSettingChangeSize() {
String val = projectEditor.getProjectSettingsProperty(SettingsConstants.PROJECT_YOUNG_ANDROID_SETTINGS, String val = projectEditor.getProjectSettingsProperty(SettingsConstants.PROJECT_YOUNG_ANDROID_SETTINGS,
......
...@@ -12,6 +12,7 @@ import com.google.appinventor.client.editor.simple.SimpleComponentDatabase; ...@@ -12,6 +12,7 @@ import com.google.appinventor.client.editor.simple.SimpleComponentDatabase;
import com.google.appinventor.client.ComponentsTranslation; import com.google.appinventor.client.ComponentsTranslation;
import com.google.appinventor.client.Images; import com.google.appinventor.client.Images;
import com.google.appinventor.client.Ode; import com.google.appinventor.client.Ode;
import com.google.appinventor.client.editor.ProjectEditor;
import com.google.appinventor.client.editor.simple.SimpleEditor; import com.google.appinventor.client.editor.simple.SimpleEditor;
import com.google.appinventor.client.editor.simple.components.utils.PropertiesUtil; import com.google.appinventor.client.editor.simple.components.utils.PropertiesUtil;
import com.google.appinventor.client.editor.youngandroid.YaBlocksEditor; import com.google.appinventor.client.editor.youngandroid.YaBlocksEditor;
...@@ -1023,11 +1024,8 @@ public abstract class MockComponent extends Composite implements PropertyChangeL ...@@ -1023,11 +1024,8 @@ public abstract class MockComponent extends Composite implements PropertyChangeL
// If this component's visible property is false, we need to check whether to show hidden // If this component's visible property is false, we need to check whether to show hidden
// components. // components.
if (!visible) { if (!visible) {
boolean showHiddenComponents = Boolean.parseBoolean( YaFormEditor formEditor = (YaFormEditor) editor;
editor.getProjectEditor().getProjectSettingsProperty( return formEditor.shouldDisplayHiddenComponents();
SettingsConstants.PROJECT_YOUNG_ANDROID_SETTINGS,
SettingsConstants.YOUNG_ANDROID_SETTINGS_SHOW_HIDDEN_COMPONENTS));
return showHiddenComponents;
} }
} }
return true; return true;
......
...@@ -61,6 +61,10 @@ public final class MockForm extends MockContainer { ...@@ -61,6 +61,10 @@ public final class MockForm extends MockContainer {
private boolean actionBar; private boolean actionBar;
private String backgroundColor; private String backgroundColor;
public String getTitle() {
return title.getText();
}
/* /*
* Creates a new title bar. * Creates a new title bar.
*/ */
......
...@@ -187,6 +187,10 @@ public final class YaFormEditor extends SimpleEditor implements FormChangeListen ...@@ -187,6 +187,10 @@ public final class YaFormEditor extends SimpleEditor implements FormChangeListen
setSize("100%", "100%"); setSize("100%", "100%");
} }
public boolean shouldDisplayHiddenComponents() {
return visibleComponentsPanel.isHiddenComponentsCheckboxChecked();
}
// FileEditor methods // FileEditor methods
@Override @Override
......
...@@ -30,6 +30,9 @@ public final class YoungAndroidSettings extends Settings { ...@@ -30,6 +30,9 @@ public final class YoungAndroidSettings extends Settings {
addProperty(new EditableProperty(this, addProperty(new EditableProperty(this,
SettingsConstants.YOUNG_ANDROID_SETTINGS_SHOW_HIDDEN_COMPONENTS, SettingsConstants.YOUNG_ANDROID_SETTINGS_SHOW_HIDDEN_COMPONENTS,
"False", EditableProperty.TYPE_INVISIBLE)); "False", EditableProperty.TYPE_INVISIBLE));
addProperty(new EditableProperty(this,
SettingsConstants.YOUNG_ANDROID_SETTINGS_SCREEN_CHECKBOX_STATE_MAP,
"", EditableProperty.TYPE_INVISIBLE));
addProperty(new EditableProperty(this, addProperty(new EditableProperty(this,
SettingsConstants.YOUNG_ANDROID_SETTINGS_PHONE_TABLET, SettingsConstants.YOUNG_ANDROID_SETTINGS_PHONE_TABLET,
"False", EditableProperty.TYPE_INVISIBLE)); "False", EditableProperty.TYPE_INVISIBLE));
......
...@@ -45,6 +45,7 @@ public class SettingsConstants { ...@@ -45,6 +45,7 @@ public class SettingsConstants {
// Project settings // Project settings
public static final String YOUNG_ANDROID_SETTINGS_ICON = "Icon"; public static final String YOUNG_ANDROID_SETTINGS_ICON = "Icon";
public static final String YOUNG_ANDROID_SETTINGS_SHOW_HIDDEN_COMPONENTS = "ShowHiddenComponents"; public static final String YOUNG_ANDROID_SETTINGS_SHOW_HIDDEN_COMPONENTS = "ShowHiddenComponents";
public static final String YOUNG_ANDROID_SETTINGS_SCREEN_CHECKBOX_STATE_MAP = "ScreenCheckboxStateMap";
public static final String YOUNG_ANDROID_SETTINGS_PHONE_TABLET = "PhoneTablet"; public static final String YOUNG_ANDROID_SETTINGS_PHONE_TABLET = "PhoneTablet";
public static final String YOUNG_ANDROID_SETTINGS_VERSION_CODE = "VersionCode"; public static final String YOUNG_ANDROID_SETTINGS_VERSION_CODE = "VersionCode";
public static final String YOUNG_ANDROID_SETTINGS_VERSION_NAME = "VersionName"; public static final String YOUNG_ANDROID_SETTINGS_VERSION_NAME = "VersionName";
......
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