mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Profile
This commit is contained in:
+18
-4
@@ -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<Profile> 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<Profile>() {
|
||||
@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<Profile> profiles = new ArrayList<Profile>(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();
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -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());
|
||||
|
||||
+14
-6
@@ -50,8 +50,9 @@ import java.util.Map;
|
||||
public class ProfileList implements PersistentStateComponent<ProfileList.ProfileState> {
|
||||
private final LayoutDeviceManager myLayoutDeviceManager = new LayoutDeviceManager();
|
||||
private final Map<Module, Sdk> myModule2Sdk = new HashMap<Module, Sdk>();
|
||||
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<ProfileList.Profile
|
||||
return ServiceManager.getService(project, ProfileList.class);
|
||||
}
|
||||
|
||||
public Sdk getModuleSdk(Module module) {
|
||||
public synchronized Sdk getModuleSdk(Module module) {
|
||||
return myModule2Sdk.get(module);
|
||||
}
|
||||
|
||||
@@ -83,20 +84,19 @@ public class ProfileList implements PersistentStateComponent<ProfileList.Profile
|
||||
}
|
||||
}
|
||||
|
||||
private void updatePlatform() {
|
||||
private synchronized void updatePlatform() {
|
||||
DesignerEditorPanel designer = DesignerToolWindowManager.getInstance(myProject).getActiveDesigner();
|
||||
if (designer instanceof AndroidDesignerEditorPanel) {
|
||||
Module module = designer.getModule();
|
||||
Sdk prevSdk = myModule2Sdk.get(module);
|
||||
Sdk newSdk = ModuleRootManager.getInstance(module).getSdk();
|
||||
|
||||
if (newSdk != null
|
||||
&& (newSdk.getSdkType() instanceof AndroidSdkType ||
|
||||
(prevSdk != null && prevSdk.getSdkType() instanceof AndroidSdkType))
|
||||
&& !newSdk.equals(prevSdk)) {
|
||||
|
||||
AndroidSdkAdditionalData additionalData = (AndroidSdkAdditionalData)newSdk.getSdkAdditionalData();
|
||||
AndroidPlatform newPlatform = additionalData != null ? additionalData.getAndroidPlatform() : null;
|
||||
((AndroidDesignerEditorPanel)designer).getProfileAction().getProfileManager().update(newPlatform);
|
||||
((AndroidDesignerEditorPanel)designer).getProfileAction().getProfileManager().update(newSdk);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,6 +133,14 @@ public class ProfileList implements PersistentStateComponent<ProfileList.Profile
|
||||
return getFullProfile();
|
||||
}
|
||||
|
||||
public int getVersion() {
|
||||
return myVersion;
|
||||
}
|
||||
|
||||
public void addVersion() {
|
||||
myVersion++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProfileState getState() {
|
||||
return myState;
|
||||
|
||||
+26
-8
@@ -48,6 +48,9 @@ public class ProfileManager {
|
||||
|
||||
private final Module myModule;
|
||||
private final Runnable myRefreshAction;
|
||||
private final Runnable mySelectionRunnable;
|
||||
|
||||
private Sdk mySdk;
|
||||
|
||||
private final AbstractComboBoxAction<LayoutDevice> myDeviceAction;
|
||||
private final AbstractComboBoxAction<LayoutDeviceConfiguration> 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) {
|
||||
|
||||
+1
@@ -53,6 +53,7 @@ public abstract class AbstractComboBoxAction<T> extends ComboBoxAction {
|
||||
if (selection == null && !myItems.isEmpty()) {
|
||||
mySelection = myItems.get(0);
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
public void clearSelection() {
|
||||
|
||||
Reference in New Issue
Block a user