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;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
/**
* Abstract superclass for all project editors.
......@@ -50,6 +52,7 @@ public abstract class ProjectEditor extends Composite {
private final HashMap<String,String> locationHashMap = new HashMap<String,String>();
private final DeckPanel deckPanel;
private FileEditor selectedFileEditor;
private final TreeMap<String, Boolean> screenHashMap = new TreeMap<String, Boolean>();
/**
* Creates a {@code ProjectEditor} instance.
......@@ -99,6 +102,41 @@ public abstract class ProjectEditor extends Composite {
*/
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.
*
......
......@@ -10,6 +10,7 @@ import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import static com.google.appinventor.client.Ode.MESSAGES;
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.palette.SimplePaletteItem;
import com.google.appinventor.client.explorer.project.ComponentDatabaseChangeListener;
......@@ -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.ListBox;
import java.util.List;
import java.util.Map;
......@@ -65,22 +65,28 @@ public final class SimpleVisibleComponentsPanel extends Composite implements Dro
checkboxShowHiddenComponents = new CheckBox(MESSAGES.showHiddenComponentsCheckbox()) {
@Override
protected void onLoad() {
// onLoad is called immediately after a widget becomes attached to the browser's document.
boolean showHiddenComponents = Boolean.parseBoolean(
projectEditor.getProjectSettingsProperty(
// Get project settings
String screenCheckboxMap = projectEditor.getProjectSettingsProperty(
SettingsConstants.PROJECT_YOUNG_ANDROID_SETTINGS,
SettingsConstants.YOUNG_ANDROID_SETTINGS_SHOW_HIDDEN_COMPONENTS));
checkboxShowHiddenComponents.setValue(showHiddenComponents);
SettingsConstants.YOUNG_ANDROID_SETTINGS_SCREEN_CHECKBOX_STATE_MAP
);
if (screenCheckboxMap != null && !screenCheckboxMap.equals("")) {
projectEditor.buildScreenHashMap(screenCheckboxMap);
Boolean isChecked = projectEditor.getScreenCheckboxState(form.getTitle());
checkboxShowHiddenComponents.setValue(isChecked);
}
}
};
checkboxShowHiddenComponents.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
@Override
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(
SettingsConstants.PROJECT_YOUNG_ANDROID_SETTINGS,
SettingsConstants.YOUNG_ANDROID_SETTINGS_SHOW_HIDDEN_COMPONENTS,
isChecked ? "True" : "False");
SettingsConstants.YOUNG_ANDROID_SETTINGS_SCREEN_CHECKBOX_STATE_MAP,
projectEditor.getScreenCheckboxMapString()
);
if (form != null) {
form.refresh();
}
......@@ -125,6 +131,10 @@ public final class SimpleVisibleComponentsPanel extends Composite implements Dro
initWidget(phoneScreen);
}
public boolean isHiddenComponentsCheckboxChecked() {
return checkboxShowHiddenComponents.getValue();
}
// get width and height stored in user settings, and change the preview size.
private void getUserSettingChangeSize() {
String val = projectEditor.getProjectSettingsProperty(SettingsConstants.PROJECT_YOUNG_ANDROID_SETTINGS,
......
......@@ -12,6 +12,7 @@ import com.google.appinventor.client.editor.simple.SimpleComponentDatabase;
import com.google.appinventor.client.ComponentsTranslation;
import com.google.appinventor.client.Images;
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.components.utils.PropertiesUtil;
import com.google.appinventor.client.editor.youngandroid.YaBlocksEditor;
......@@ -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
// components.
if (!visible) {
boolean showHiddenComponents = Boolean.parseBoolean(
editor.getProjectEditor().getProjectSettingsProperty(
SettingsConstants.PROJECT_YOUNG_ANDROID_SETTINGS,
SettingsConstants.YOUNG_ANDROID_SETTINGS_SHOW_HIDDEN_COMPONENTS));
return showHiddenComponents;
YaFormEditor formEditor = (YaFormEditor) editor;
return formEditor.shouldDisplayHiddenComponents();
}
}
return true;
......
......@@ -61,6 +61,10 @@ public final class MockForm extends MockContainer {
private boolean actionBar;
private String backgroundColor;
public String getTitle() {
return title.getText();
}
/*
* Creates a new title bar.
*/
......
......@@ -187,6 +187,10 @@ public final class YaFormEditor extends SimpleEditor implements FormChangeListen
setSize("100%", "100%");
}
public boolean shouldDisplayHiddenComponents() {
return visibleComponentsPanel.isHiddenComponentsCheckboxChecked();
}
// FileEditor methods
@Override
......
......@@ -30,6 +30,9 @@ public final class YoungAndroidSettings extends Settings {
addProperty(new EditableProperty(this,
SettingsConstants.YOUNG_ANDROID_SETTINGS_SHOW_HIDDEN_COMPONENTS,
"False", EditableProperty.TYPE_INVISIBLE));
addProperty(new EditableProperty(this,
SettingsConstants.YOUNG_ANDROID_SETTINGS_SCREEN_CHECKBOX_STATE_MAP,
"", EditableProperty.TYPE_INVISIBLE));
addProperty(new EditableProperty(this,
SettingsConstants.YOUNG_ANDROID_SETTINGS_PHONE_TABLET,
"False", EditableProperty.TYPE_INVISIBLE));
......
......@@ -45,6 +45,7 @@ public class SettingsConstants {
// Project settings
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_SCREEN_CHECKBOX_STATE_MAP = "ScreenCheckboxStateMap";
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_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