Skip to content

Commit

Permalink
Make "Display hidden components in Viewer" checkbox screen-dependent (#…
Browse files Browse the repository at this point in the history
…1852)

* Cache checkbox state for each screen
* Make hidden components checkbox screen-dependent
  • Loading branch information
Matthew Coufal authored and SusanRatiLane committed Oct 10, 2019
1 parent 9ae1524 commit c2a2ac1
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 16 deletions.
Expand Up @@ -23,6 +23,8 @@
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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -99,6 +102,41 @@ public ProjectEditor(ProjectRootNode projectRootNode) {
*/
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.
*
Expand Down
Expand Up @@ -10,6 +10,7 @@
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;
Expand All @@ -24,7 +25,6 @@
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.client.ui.ListBox;


import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -65,22 +65,28 @@ public SimpleVisibleComponentsPanel(final SimpleEditor editor,
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(
SettingsConstants.PROJECT_YOUNG_ANDROID_SETTINGS,
SettingsConstants.YOUNG_ANDROID_SETTINGS_SHOW_HIDDEN_COMPONENTS));
checkboxShowHiddenComponents.setValue(showHiddenComponents);
// Get project settings
String screenCheckboxMap = projectEditor.getProjectSettingsProperty(
SettingsConstants.PROJECT_YOUNG_ANDROID_SETTINGS,
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.PROJECT_YOUNG_ANDROID_SETTINGS,
SettingsConstants.YOUNG_ANDROID_SETTINGS_SCREEN_CHECKBOX_STATE_MAP,
projectEditor.getScreenCheckboxMapString()
);
if (form != null) {
form.refresh();
}
Expand Down Expand Up @@ -125,6 +131,10 @@ public void onChange(ChangeEvent event) {
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,
Expand Down
Expand Up @@ -12,6 +12,7 @@
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;
Expand Down Expand Up @@ -1023,11 +1024,8 @@ private boolean showComponentInDesigner() {
// 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;
Expand Down
Expand Up @@ -61,6 +61,10 @@ private class TitleBar extends Composite {
private boolean actionBar;
private String backgroundColor;

public String getTitle() {
return title.getText();
}

/*
* Creates a new title bar.
*/
Expand Down
Expand Up @@ -187,6 +187,10 @@ public DropTarget[] getDropTargets() {
setSize("100%", "100%");
}

public boolean shouldDisplayHiddenComponents() {
return visibleComponentsPanel.isHiddenComponentsCheckboxChecked();
}

// FileEditor methods

@Override
Expand Down
Expand Up @@ -30,6 +30,9 @@ public YoungAndroidSettings(Project project) {
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));
Expand Down
Expand Up @@ -45,6 +45,7 @@ private 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";
Expand Down

0 comments on commit c2a2ac1

Please sign in to comment.