diff --git a/plugins/android-designer/src/com/intellij/android/designer/actions/ProfileAction.java b/plugins/android-designer/src/com/intellij/android/designer/actions/ProfileAction.java index 3994478d9d5a..5eded8514911 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/actions/ProfileAction.java +++ b/plugins/android-designer/src/com/intellij/android/designer/actions/ProfileAction.java @@ -23,6 +23,7 @@ import com.intellij.android.designer.profile.ProfileManager; import com.intellij.designer.actions.AbstractComboBoxAction; import com.intellij.openapi.actionSystem.DefaultActionGroup; import com.intellij.openapi.actionSystem.Presentation; +import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.ui.DialogWrapper; import java.util.ArrayList; @@ -43,10 +44,19 @@ public class ProfileAction { private final AbstractComboBoxAction myProfileAction; private final DefaultActionGroup myActionGroup = new DefaultActionGroup(); private final ProfileList myProfileList; + private int myVersion; public ProfileAction(AndroidDesignerEditorPanel designer, Runnable refreshAction) { myDesigner = designer; - myProfileManager = new ProfileManager(myDesigner.getModule(), refreshAction); + + myProfileList = ProfileList.getInstance(myDesigner.getProject()); + + myProfileManager = new ProfileManager(myDesigner.getModule(), refreshAction, new Runnable() { + @Override + public void run() { + myProfileList.addVersion(); + } + }); myProfileAction = new AbstractComboBoxAction() { @Override @@ -74,8 +84,6 @@ public class ProfileAction { } }; - myProfileList = ProfileList.getInstance(myDesigner.getProject()); - DefaultActionGroup designerActionGroup = myDesigner.getActionPanel().getActionGroup(); designerActionGroup.add(myProfileAction); designerActionGroup.add(myActionGroup); @@ -88,6 +96,8 @@ public class ProfileAction { } private void updateActions() { + myVersion = myProfileList.getVersion(); + List profiles = new ArrayList(myProfileList.getProfiles()); profiles.add(myProfileList.getFullProfile()); profiles.add(EDIT_PROFILE); @@ -133,11 +143,15 @@ public class ProfileAction { if (dialog.getExitCode() == DialogWrapper.OK_EXIT_CODE) { myProfileList.setProfiles(dialog.getResult()); + myProfileList.addVersion(); updateActions(); } } public void externalUpdate() { - // TODO + Sdk sdk = myProfileList.getModuleSdk(myDesigner.getModule()); + if ((sdk != null && !sdk.equals(myProfileManager.getSdk())) || myVersion != myProfileList.getVersion()) { + updateActions(); + } } } \ No newline at end of file diff --git a/plugins/android-designer/src/com/intellij/android/designer/profile/ProfileDialog.java b/plugins/android-designer/src/com/intellij/android/designer/profile/ProfileDialog.java index d6da61b2d94a..2f5ba0a5e954 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/profile/ProfileDialog.java +++ b/plugins/android-designer/src/com/intellij/android/designer/profile/ProfileDialog.java @@ -113,7 +113,7 @@ public class ProfileDialog extends DialogWrapper { decorator.setUpAction(null); decorator.setDownAction(null); - myProfileManager = new ProfileManager(module, EmptyRunnable.INSTANCE); + myProfileManager = new ProfileManager(module, EmptyRunnable.INSTANCE, EmptyRunnable.INSTANCE); myContentPanel = new JPanel(new GridBagLayout()); diff --git a/plugins/android-designer/src/com/intellij/android/designer/profile/ProfileList.java b/plugins/android-designer/src/com/intellij/android/designer/profile/ProfileList.java index 89f7832ba95c..beac64cdd0e6 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/profile/ProfileList.java +++ b/plugins/android-designer/src/com/intellij/android/designer/profile/ProfileList.java @@ -50,8 +50,9 @@ import java.util.Map; public class ProfileList implements PersistentStateComponent { private final LayoutDeviceManager myLayoutDeviceManager = new LayoutDeviceManager(); private final Map myModule2Sdk = new HashMap(); - private ProfileState myState = new ProfileState(); private final Project myProject; + private ProfileState myState = new ProfileState(); + private int myVersion; public ProfileList(Project project) { myProject = project; @@ -72,7 +73,7 @@ public class ProfileList implements PersistentStateComponent myDeviceAction; private final AbstractComboBoxAction myDeviceConfigurationAction; @@ -63,9 +66,10 @@ public class ProfileManager { private Profile myProfile; - public ProfileManager(Module module, Runnable refreshAction) { + public ProfileManager(Module module, Runnable refreshAction, Runnable selectionRunnable) { myModule = module; myRefreshAction = refreshAction; + mySelectionRunnable = selectionRunnable; myLayoutDeviceManager = ProfileList.getInstance(module.getProject()).getLayoutDeviceManager(); @@ -91,7 +95,7 @@ public class ProfileManager { myLayoutDeviceManager.saveUserDevices(); } - updatePlatform(getPlatform()); + updatePlatform(getPlatform(null)); String deviceName = dialog.getSelectedDeviceName(); if (deviceName != null) { @@ -118,6 +122,7 @@ public class ProfileManager { updateDevice(item); } + mySelectionRunnable.run(); myRefreshAction.run(); return item != CUSTOM_DEVICE; } @@ -132,6 +137,7 @@ public class ProfileManager { @Override protected boolean selectionChanged(LayoutDeviceConfiguration item) { updateDeviceConfiguration(item); + mySelectionRunnable.run(); myRefreshAction.run(); return true; } @@ -142,6 +148,7 @@ public class ProfileManager { protected boolean selectionChanged(IAndroidTarget item) { updateTarget(item); updateThemes(); + mySelectionRunnable.run(); return true; } }; @@ -150,6 +157,7 @@ public class ProfileManager { @Override protected boolean selectionChanged(LocaleData item) { updateLocale(item); + mySelectionRunnable.run(); myRefreshAction.run(); return true; } @@ -159,6 +167,7 @@ public class ProfileManager { @Override protected boolean selectionChanged(UiMode item) { myProfile.setDockMode(item.getResourceValue()); + mySelectionRunnable.run(); myRefreshAction.run(); return true; } @@ -168,6 +177,7 @@ public class ProfileManager { @Override protected boolean selectionChanged(NightMode item) { myProfile.setNightMode(item.getResourceValue()); + mySelectionRunnable.run(); myRefreshAction.run(); return true; } @@ -197,6 +207,7 @@ public class ProfileManager { @Override protected boolean selectionChanged(ThemeData item) { updateTheme(item); + mySelectionRunnable.run(); myRefreshAction.run(); return true; } @@ -228,7 +239,7 @@ public class ProfileManager { myThemeAction.clearSelection(); } else { - update(getPlatform()); + update(null); } } @@ -242,10 +253,11 @@ public class ProfileManager { myThemeAction.update(); } - public void update(@Nullable AndroidPlatform platform) { + public void update(@Nullable Sdk sdk) { + mySdk = sdk; if (myProfile != null) { updateLocales(); - updatePlatform(platform); + updatePlatform(getPlatform(sdk)); updateThemes(); myDockModeAction.setItems(Arrays.asList(UiMode.values()), UiMode.getEnum(myProfile.getDockMode())); myNightModeAction.setItems(Arrays.asList(NightMode.values()), NightMode.getEnum(myProfile.getNightMode())); @@ -256,6 +268,11 @@ public class ProfileManager { return myModule; } + @Nullable + public Sdk getSdk() { + return mySdk; + } + @Nullable public LayoutDeviceConfiguration getSelectedDeviceConfiguration() { return myDeviceConfigurationAction.getSelection(); @@ -557,7 +574,6 @@ public class ProfileManager { } myThemeAction.setItems(themes, newTheme); - myThemeAction.update(); updateTheme(newTheme); myRefreshAction.run(); } @@ -569,8 +585,10 @@ public class ProfileManager { } @Nullable - public AndroidPlatform getPlatform() { - Sdk sdk = ModuleRootManager.getInstance(myModule).getSdk(); + private AndroidPlatform getPlatform(@Nullable Sdk sdk) { + if (sdk == null) { + sdk = ProfileList.getInstance(myModule.getProject()).getModuleSdk(myModule); + } if (sdk != null && sdk.getSdkType() instanceof AndroidSdkType) { AndroidSdkAdditionalData additionalData = (AndroidSdkAdditionalData)sdk.getSdkAdditionalData(); if (additionalData != null) { diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/actions/AbstractComboBoxAction.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/actions/AbstractComboBoxAction.java index 899521aaf1a9..ddc1a4dff076 100644 --- a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/actions/AbstractComboBoxAction.java +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/actions/AbstractComboBoxAction.java @@ -53,6 +53,7 @@ public abstract class AbstractComboBoxAction extends ComboBoxAction { if (selection == null && !myItems.isEmpty()) { mySelection = myItems.get(0); } + update(); } public void clearSelection() {