diff options
author | Tor Norbye <tnorbye@google.com> | 2010-11-30 10:52:33 -0800 |
---|---|---|
committer | Android Code Review <code-review@android.com> | 2010-11-30 10:52:33 -0800 |
commit | 935ae86b44c66f0ec0bd80d94b27b2739ef0549a (patch) | |
tree | 3f9c7ca01742d8c7e374dadd7a24f71918a195ba /eclipse | |
parent | c98df372d5ed6d390da09e30a83672041185c252 (diff) | |
parent | ebbea7d896e2c9b7fb21101acfab2476863c5efd (diff) | |
download | sdk-935ae86b44c66f0ec0bd80d94b27b2739ef0549a.zip sdk-935ae86b44c66f0ec0bd80d94b27b2739ef0549a.tar.gz sdk-935ae86b44c66f0ec0bd80d94b27b2739ef0549a.tar.bz2 |
Merge "The rendering target mode should be preserved across IDE sessions"
Diffstat (limited to 'eclipse')
-rw-r--r-- | eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ConfigurationComposite.java | 62 |
1 files changed, 59 insertions, 3 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ConfigurationComposite.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ConfigurationComposite.java index 386fd5f..76eeb7e 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ConfigurationComposite.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ConfigurationComposite.java @@ -202,6 +202,8 @@ public class ConfigurationComposite extends Composite { DockMode dock = DockMode.NONE; /** night mode. Guaranteed to be non null */ NightMode night = NightMode.NOTNIGHT; + /** the version being targeted for rendering */ + IAndroidTarget target; String getData() { StringBuilder sb = new StringBuilder(); @@ -225,6 +227,10 @@ public class ConfigurationComposite extends Composite { sb.append(SEP); sb.append(night.getResourceValue()); sb.append(SEP); + if (target != null) { + sb.append(targetToString(target)); + sb.append(SEP); + } } return sb.toString(); @@ -232,7 +238,7 @@ public class ConfigurationComposite extends Composite { boolean setData(String data) { String[] values = data.split(SEP); - if (values.length == 6) { + if (values.length == 6 || values.length == 7) { for (LayoutDevice d : mDeviceList) { if (d.getName().equals(values[0])) { device = d; @@ -261,6 +267,10 @@ public class ConfigurationComposite extends Composite { night = NightMode.NOTNIGHT; } + if (values.length == 7 && mTargetList != null) { + target = stringToTarget(values[6]); + } + return true; } } @@ -294,8 +304,45 @@ public class ConfigurationComposite extends Composite { sb.append(night.getResourceValue()); sb.append(SEP); + if (target != null) { + sb.append(targetToString(target)); + sb.append(SEP); + } + return sb.toString(); } + + /** + * Returns a String id to represent an {@link IAndroidTarget} which can be translated + * back to an {@link IAndroidTarget} by the matching {@link #stringToTarget}. The id + * will never contain the {@link #SEP} character. + * + * @param target the target to return an id for + * @return an id for the given target; never null + */ + private String targetToString(IAndroidTarget target) { + return target.getFullName().replace(SEP, ""); //$NON-NLS-1$ + } + + /** + * Returns an {@link IAndroidTarget} that corresponds to the given id that was + * originally returned by {@link #targetToString}. May be null, if the platform is no + * longer available, or if the platform list has not yet been initialized. + * + * @param id the id that corresponds to the desired platform + * @return an {@link IAndroidTarget} that matches the given id, or null + */ + private IAndroidTarget stringToTarget(String id) { + if (mTargetList != null && mTargetList.size() > 0) { + for (IAndroidTarget target : mTargetList) { + if (id.equals(targetToString(target))) { + return target; + } + } + } + + return null; + } } /** @@ -595,7 +642,7 @@ public class ConfigurationComposite extends Composite { /** * Sets the reference to the file being edited. - * <p/>The UI is intialized in {@link #onXmlModelLoaded()} which is called as the XML model is + * <p/>The UI is initialized in {@link #onXmlModelLoaded()} which is called as the XML model is * loaded (or reloaded as the SDK/target changes). * * @param file the file being opened @@ -790,11 +837,15 @@ public class ConfigurationComposite extends Composite { mDockCombo.select(DockMode.getIndex(mState.dock)); mNightCombo.select(NightMode.getIndex(mState.night)); + mTargetCombo.select(mTargetList.indexOf(mState.target)); } else { findAndSetCompatibleConfig(false /*favorCurrentConfig*/); mDockCombo.select(0); mNightCombo.select(0); + // We don't want the -first- combobox item, we want the + // default one which is sometimes a different index + //mTargetCombo.select(0); } // update the string showing the config value @@ -1042,6 +1093,11 @@ public class ConfigurationComposite extends Composite { if (index != -1) { mState.night = NightMode.getByIndex(index); } + + index = mTargetCombo.getSelectionIndex(); + if (index != -1) { + mState.target = mTargetList.get(index); + } } } @@ -1050,7 +1106,7 @@ public class ConfigurationComposite extends Composite { */ public void storeState() { try { - QualifiedName qname = new QualifiedName(AdtPlugin.PLUGIN_ID, CONFIG_STATE); //$NON-NLS-1$ + QualifiedName qname = new QualifiedName(AdtPlugin.PLUGIN_ID, CONFIG_STATE); mEditedFile.setPersistentProperty(qname, mState.getData()); } catch (CoreException e) { // pass |