diff options
author | Tor Norbye <tnorbye@google.com> | 2012-09-19 09:09:10 -0700 |
---|---|---|
committer | android code review <noreply-gerritcodereview@google.com> | 2012-09-19 09:09:11 -0700 |
commit | 0be1d50d12ff9f241c2d9afc9e62da7f323aae5b (patch) | |
tree | 70e7c571631c6e37b7eb3e71e3308083d00b39bb /eclipse/plugins | |
parent | ff8d9cddc0e8ff107870046df64fda1622bd10d4 (diff) | |
parent | 630d28af94d1d7f5f791e49d8504a16b7f4559a4 (diff) | |
download | sdk-0be1d50d12ff9f241c2d9afc9e62da7f323aae5b.zip sdk-0be1d50d12ff9f241c2d9afc9e62da7f323aae5b.tar.gz sdk-0be1d50d12ff9f241c2d9afc9e62da7f323aae5b.tar.bz2 |
Merge "Improve last editor mode handling"
Diffstat (limited to 'eclipse/plugins')
8 files changed, 110 insertions, 29 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/BaseViewRule.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/BaseViewRule.java index a7dd7d4..a555ef4 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/BaseViewRule.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/BaseViewRule.java @@ -95,7 +95,7 @@ public class BaseViewRule extends AbstractViewRule { @Override public boolean onInitialize(@NonNull String fqcn, @NonNull IClientRulesEngine engine) { - this.mRulesEngine = engine; + mRulesEngine = engine; // This base rule can handle any class so we don't need to filter on // FQCN. Derived classes should do so if they can handle some @@ -785,7 +785,7 @@ public class BaseViewRule extends AbstractViewRule { public EnumPropertyChoiceProvider(Prop property) { super(); - this.mProperty = property; + mProperty = property; } @Override diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/LinearLayoutRule.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/LinearLayoutRule.java index e6f4a4e..d7a3026 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/LinearLayoutRule.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/LinearLayoutRule.java @@ -631,8 +631,8 @@ public class LinearLayoutRule extends BaseLayoutRule { private int mPosition; public MatchPos(int distance, int position) { - this.mDistance = distance; - this.mPosition = position; + mDistance = distance; + mPosition = position; } @Override @@ -682,10 +682,10 @@ public class LinearLayoutRule extends BaseLayoutRule { public LinearDropData(List<MatchPos> indexes, int numPositions, boolean isVertical, int selfPos) { - this.mIndexes = indexes; - this.mNumPositions = numPositions; - this.mVertical = isVertical; - this.mSelfPos = selfPos; + mIndexes = indexes; + mNumPositions = numPositions; + mVertical = isVertical; + mSelfPos = selfPos; } @Override @@ -706,7 +706,7 @@ public class LinearLayoutRule extends BaseLayoutRule { } private void setCurrX(Integer currX) { - this.mCurrX = currX; + mCurrX = currX; } private Integer getCurrX() { @@ -714,7 +714,7 @@ public class LinearLayoutRule extends BaseLayoutRule { } private void setCurrY(Integer currY) { - this.mCurrY = currY; + mCurrY = currY; } private Integer getCurrY() { @@ -726,7 +726,7 @@ public class LinearLayoutRule extends BaseLayoutRule { } private void setInsertPos(int insertPos) { - this.mInsertPos = insertPos; + mInsertPos = insertPos; } private int getInsertPos() { @@ -738,7 +738,7 @@ public class LinearLayoutRule extends BaseLayoutRule { } private void setWidth(Integer width) { - this.mWidth = width; + mWidth = width; } private Integer getWidth() { @@ -746,7 +746,7 @@ public class LinearLayoutRule extends BaseLayoutRule { } private void setHeight(Integer height) { - this.mHeight = height; + mHeight = height; } private Integer getHeight() { diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/AndroidXmlEditor.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/AndroidXmlEditor.java index 6098483..fcfdfd1 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/AndroidXmlEditor.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/AndroidXmlEditor.java @@ -452,11 +452,43 @@ public abstract class AndroidXmlEditor extends FormEditor { // first page rather than crash the editor load. Logging the error is enough. AdtPlugin.log(e, "Selecting page '%s' in AndroidXmlEditor failed", defaultPageId); } - } else if (AdtPrefs.getPrefs().isLastSwitchedToXml()) { + } else if (AdtPrefs.getPrefs().isXmlEditorPreferred(getPersistenceCategory())) { setActivePage(mTextPageIndex); } } + /** The layout editor */ + public static final int CATEGORY_LAYOUT = 1 << 0; + /** The manifest editor */ + public static final int CATEGORY_MANIFEST = 1 << 1; + /** Any other XML editor */ + public static final int CATEGORY_OTHER = 1 << 2; + + /** + * Returns the persistence category to use for this editor; this should be + * one of the {@code CATEGORY_} constants such as {@link #CATEGORY_MANIFEST}, + * {@link #CATEGORY_LAYOUT}, {@link #CATEGORY_OTHER}, ... + * <p> + * The persistence category is used to group editors together when it comes + * to certain types of persistence metadata. For example, whether this type + * of file was most recently edited graphically or with an XML text editor. + * We'll open new files in the same text or graphical mode as the last time + * the user edited a file of the same persistence category. + * <p> + * Before we added the persistence category, we had a single boolean flag + * recording whether the XML files were most recently edited graphically or + * not. However, this meant that users can't for example prefer to edit + * Manifest files graphically and string files via XML. By splitting the + * editors up into categories, we can track the mode at a finer granularity, + * and still allow similar editors such as those used for animations and + * colors to be treated the same way. + * + * @return the persistence category constant + */ + protected int getPersistenceCategory() { + return CATEGORY_OTHER; + } + /** * Removes all the pages from the editor. */ @@ -511,7 +543,8 @@ public abstract class AndroidXmlEditor extends FormEditor { } } - AdtPrefs.getPrefs().setLastSwitchedToXml(newPageIndex == mTextPageIndex); + boolean isTextPage = newPageIndex == mTextPageIndex; + AdtPrefs.getPrefs().setXmlEditorPreferred(getPersistenceCategory(), isTextPage); } /** diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/common/CommonXmlDelegate.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/common/CommonXmlDelegate.java index b6cbf2c..d9ee8a5 100755 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/common/CommonXmlDelegate.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/common/CommonXmlDelegate.java @@ -18,6 +18,7 @@ package com.android.ide.eclipse.adt.internal.editors.common; import com.android.annotations.NonNull; import com.android.annotations.Nullable; +import com.android.ide.eclipse.adt.internal.editors.AndroidXmlEditor; import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode; import com.android.resources.ResourceFolderType; @@ -235,4 +236,14 @@ public abstract class CommonXmlDelegate { public String delegateGetPartName() { return null; } + + /** + * Returns the persistence category, as described in + * {@link AndroidXmlEditor#getPersistenceCategory}. + * + * @return the persistence category to use for this editor + */ + public int delegateGetPersistenceCategory() { + return AndroidXmlEditor.CATEGORY_OTHER; + } } diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/common/CommonXmlEditor.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/common/CommonXmlEditor.java index 7fb820c..be06d38 100755 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/common/CommonXmlEditor.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/common/CommonXmlEditor.java @@ -368,6 +368,14 @@ public class CommonXmlEditor extends AndroidXmlEditor implements IShowEditorInpu } @Override + protected int getPersistenceCategory() { + if (mDelegate != null) { + return mDelegate.delegateGetPersistenceCategory(); + } + return CATEGORY_OTHER; + } + + @Override public void initUiRootNode(boolean force) { if (mDelegate != null) { mDelegate.delegateInitUiRootNode(force); diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/LayoutEditorDelegate.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/LayoutEditorDelegate.java index e10c33b..fc81ac4 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/LayoutEditorDelegate.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/LayoutEditorDelegate.java @@ -22,6 +22,7 @@ import com.android.annotations.VisibleForTesting; import com.android.annotations.VisibleForTesting.Visibility; import com.android.ide.eclipse.adt.AdtConstants; import com.android.ide.eclipse.adt.AdtPlugin; +import com.android.ide.eclipse.adt.internal.editors.AndroidXmlEditor; import com.android.ide.eclipse.adt.internal.editors.XmlEditorMultiOutline; import com.android.ide.eclipse.adt.internal.editors.common.CommonXmlDelegate; import com.android.ide.eclipse.adt.internal.editors.common.CommonXmlEditor; @@ -686,6 +687,11 @@ public class LayoutEditorDelegate extends CommonXmlDelegate } @Override + public int delegateGetPersistenceCategory() { + return AndroidXmlEditor.CATEGORY_LAYOUT; + } + + @Override public void delegatePostPageChange(int newPageIndex) { super.delegatePostPageChange(newPageIndex); diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/manifest/ManifestEditor.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/manifest/ManifestEditor.java index 69a6b84..b1bfa88 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/manifest/ManifestEditor.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/manifest/ManifestEditor.java @@ -121,6 +121,11 @@ public final class ManifestEditor extends AndroidXmlEditor { } } + @Override + protected int getPersistenceCategory() { + return CATEGORY_MANIFEST; + } + /** * Return the root node of the UI element hierarchy, which here * is the "manifest" node. diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/preferences/AdtPrefs.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/preferences/AdtPrefs.java index d624cb7..8526ad9 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/preferences/AdtPrefs.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/preferences/AdtPrefs.java @@ -18,6 +18,7 @@ package com.android.ide.eclipse.adt.internal.preferences; import com.android.ide.eclipse.adt.AdtPlugin; +import com.android.ide.eclipse.adt.internal.editors.AndroidXmlEditor; import com.android.ide.eclipse.adt.internal.editors.formatting.XmlFormatStyle; import com.android.prefs.AndroidLocation.AndroidLocationException; import com.android.sdklib.internal.build.DebugKeyProvider; @@ -52,7 +53,7 @@ public final class AdtPrefs extends AbstractPreferenceInitializer { public final static String PREFS_MONITOR_DENSITY = AdtPlugin.PLUGIN_ID + ".monitorDensity"; //$NON-NLS-1$ public final static String PREFS_FORMAT_GUI_XML = AdtPlugin.PLUGIN_ID + ".formatXml"; //$NON-NLS-1$ - public final static String PREFS_LAST_SWITCHED_TO_XML = AdtPlugin.PLUGIN_ID + ".lastXml"; //$NON-NLS-1$ + public final static String PREFS_PREFER_XML = AdtPlugin.PLUGIN_ID + ".xmlEditor"; //$NON-NLS-1$ public final static String PREFS_USE_CUSTOM_XML_FORMATTER = AdtPlugin.PLUGIN_ID + ".androidForm"; //$NON-NLS-1$ public final static String PREFS_PALETTE_MODE = AdtPlugin.PLUGIN_ID + ".palette"; //$NON-NLS-1$ @@ -88,7 +89,6 @@ public final class AdtPrefs extends AbstractPreferenceInitializer { private String mPalette; private boolean mFormatGuiXml; - private boolean mLastSwitchedToXml; private boolean mCustomXmlFormatter; private boolean mUseEclipseIndent; private boolean mRemoveEmptyLines; @@ -99,6 +99,7 @@ public final class AdtPrefs extends AbstractPreferenceInitializer { private boolean mLintOnExport; private AttributeSortOrder mAttributeSort; private boolean mSharedLayoutEditor; + private int mPreferXmlEditor; public static enum BuildVerbosity { /** Build verbosity "Always". Those messages are always displayed, even in silent mode */ @@ -199,8 +200,8 @@ public final class AdtPrefs extends AbstractPreferenceInitializer { mFormatGuiXml = mStore.getBoolean(PREFS_FORMAT_GUI_XML); } - if (property == null || PREFS_LAST_SWITCHED_TO_XML.equals(property)) { - mLastSwitchedToXml = mStore.getBoolean(PREFS_LAST_SWITCHED_TO_XML); + if (property == null || PREFS_PREFER_XML.equals(property)) { + mPreferXmlEditor = mStore.getInt(PREFS_PREFER_XML); } if (property == null || PREFS_USE_CUSTOM_XML_FORMATTER.equals(property)) { @@ -502,22 +503,39 @@ public final class AdtPrefs extends AbstractPreferenceInitializer { } } - /** Returns whether the most recent page switch was to XML - * @return whether the most recent page switch was to XML */ - public boolean isLastSwitchedToXml() { - return mLastSwitchedToXml; + /** + * Returns whether the most recent page switch was to XML + * + * @param editorType the editor to check a preference for; corresponds to + * one of the persistence class ids returned by + * {@link AndroidXmlEditor#getPersistenceCategory} + * @return whether the most recent page switch in the given editor was to + * XML + */ + public boolean isXmlEditorPreferred(int editorType) { + return (mPreferXmlEditor & editorType) != 0; } /** - * Set whether the most recent page switch was to XML + * Set whether the most recent page switch for a given editor type was to + * XML * - * @param xml whether the last manual page switch was to XML + * @param editorType the editor to check a preference for; corresponds to + * one of the persistence class ids returned by + * {@link AndroidXmlEditor#getPersistenceCategory} + * @param xml whether the last manual page switch in the given editor type + * was to XML */ - public void setLastSwitchedToXml(boolean xml) { - if (xml != mLastSwitchedToXml) { - mLastSwitchedToXml = xml; + public void setXmlEditorPreferred(int editorType, boolean xml) { + if (xml != isXmlEditorPreferred(editorType)) { + if (xml) { + mPreferXmlEditor |= editorType; + } else { + mPreferXmlEditor &= ~editorType; + } + assert ((mPreferXmlEditor & editorType) != 0) == xml; IPreferenceStore store = AdtPlugin.getDefault().getPreferenceStore(); - store.setValue(PREFS_LINT_ON_SAVE, xml); + store.setValue(PREFS_PREFER_XML, xml); } } } |