From 5e249da0f82e061258cf6b713caaeca0afc713ca Mon Sep 17 00:00:00 2001 From: Tor Norbye Date: Mon, 27 Aug 2012 12:11:03 -0700 Subject: 31340: ADT default for opening editors in textual mode When you reopen a file you've already opened in the past, ADT will open the file on the same page (graphical or XML) that you left it at. However, new files are always opened graphically. This changeset will change this such that if you manually switch to XML, new files opened from that point open in XML, and if you switch to graphical mode, new files are opened in graphical mode. This will hopefully help those users who prefer to work in XML mode without negatively impacting those who prefer to work in graphical mode. Change-Id: Ib229b22c31899c1cd9520e6ab48f5902d2782844 --- .../adt/internal/editors/AndroidXmlEditor.java | 4 ++++ .../eclipse/adt/internal/preferences/AdtPrefs.java | 25 ++++++++++++++++++++++ 2 files changed, 29 insertions(+) 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 50b5505..ea3f30b 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 @@ -427,6 +427,8 @@ public abstract class AndroidXmlEditor extends FormEditor implements IResourceCh // 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()) { + setActivePage(mTextPageIndex); } } @@ -483,6 +485,8 @@ public abstract class AndroidXmlEditor extends FormEditor implements IResourceCh // ignore } } + + AdtPrefs.getPrefs().setLastSwitchedToXml(newPageIndex == mTextPageIndex); } /** 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 380c925..3020851 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 @@ -52,6 +52,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_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$ @@ -86,6 +87,7 @@ public final class AdtPrefs extends AbstractPreferenceInitializer { private String mPalette; private boolean mFormatGuiXml; + private boolean mLastSwitchedToXml; private boolean mCustomXmlFormatter; private boolean mUseEclipseIndent; private boolean mRemoveEmptyLines; @@ -195,6 +197,10 @@ 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_USE_CUSTOM_XML_FORMATTER.equals(property)) { mCustomXmlFormatter = mStore.getBoolean(PREFS_USE_CUSTOM_XML_FORMATTER); } @@ -461,4 +467,23 @@ public final class AdtPrefs extends AbstractPreferenceInitializer { AdtPlugin.log(e, "Get default debug keystore path failed"); //$NON-NLS-1$ } } + + /** 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; + } + + /** + * Set whether the most recent page switch was to XML + * + * @param xml whether the last manual page switch was to XML + */ + public void setLastSwitchedToXml(boolean xml) { + if (xml != mLastSwitchedToXml) { + mLastSwitchedToXml = xml; + IPreferenceStore store = AdtPlugin.getDefault().getPreferenceStore(); + store.setValue(PREFS_LINT_ON_SAVE, xml); + } + } } -- cgit v1.1