IDEA-157763 Settings repository for Initial Wizard

This commit is contained in:
Alexander Lobas
2016-07-11 12:29:19 +03:00
parent b3d4708c2c
commit c55da8fdcb
11 changed files with 292 additions and 19 deletions
@@ -15,6 +15,7 @@
*/
package com.intellij.ide;
import com.intellij.util.ParameterizedRunnable;
import org.jetbrains.annotations.Nullable;
import java.util.Collections;
@@ -28,6 +29,7 @@ public class WelcomeWizardUtil {
private static volatile String ourWizardEditorScheme;
private static volatile Boolean ourAutoScrollToSource;
private static final Set<String> ourFeaturedPluginsToInstall = new HashSet<String>();
private static ParameterizedRunnable ourWizardCreateKeymapRunnable;
public static void setDefaultLAF(String laf) {
ourDefaultLAF = laf;
@@ -47,6 +49,12 @@ public class WelcomeWizardUtil {
public static void setWizardKeymap(@Nullable String keymap) {
ourWizardMacKeymap = keymap;
ourWizardCreateKeymapRunnable = null;
}
public static void setWizardKeymap(@Nullable ParameterizedRunnable runnable) {
ourWizardMacKeymap = null;
ourWizardCreateKeymapRunnable = runnable;
}
@Nullable
@@ -54,6 +62,11 @@ public class WelcomeWizardUtil {
return ourWizardMacKeymap;
}
@Nullable
public static ParameterizedRunnable getWizardCreateKeymapRunnable() {
return ourWizardCreateKeymapRunnable;
}
public static void setWizardEditorScheme(@Nullable String wizardEditorScheme) {
ourWizardEditorScheme = wizardEditorScheme;
}
@@ -0,0 +1,62 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.ide.cloudConfiguration;
import com.intellij.openapi.keymap.KeymapManager;
import com.intellij.util.ParameterizedRunnable;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* @author Alexander Lobas
*/
public class CloudConfigurationManager {
private static final CloudConfigurationProvider EMPTY = new CloudConfigurationProvider() {
@Nullable
@Override
public String getSharedLaf() {
return null;
}
@Nullable
@Override
public String getSharedKeymap() {
return null;
}
@Nullable
@Override
public ParameterizedRunnable<KeymapManager> createSharedKeymap() {
return null;
}
};
private static CloudConfigurationProvider myCustomizeProvider;
@Nullable
public static CloudConfigurationProvider getRawCustomizeProvider() {
return myCustomizeProvider;
}
@NotNull
public static CloudConfigurationProvider getCustomizeProvider() {
return myCustomizeProvider == null ? EMPTY : myCustomizeProvider;
}
public static void setCustomizeProvider(@Nullable CloudConfigurationProvider provider) {
myCustomizeProvider = provider;
}
}
@@ -0,0 +1,34 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.ide.cloudConfiguration;
import com.intellij.openapi.keymap.KeymapManager;
import com.intellij.util.ParameterizedRunnable;
import org.jetbrains.annotations.Nullable;
/**
* @author Alexander Lobas
*/
public interface CloudConfigurationProvider {
@Nullable
String getSharedLaf();
@Nullable
String getSharedKeymap();
@Nullable
ParameterizedRunnable<KeymapManager> createSharedKeymap();
}
@@ -32,6 +32,12 @@ public abstract class AbstractCustomizeWizardStep extends JPanel {
protected static final int SMALL_GAP = 10;
protected static final int GAP = 20;
protected boolean mySkipFirstShowing;
public boolean skipFirstShowing() {
return mySkipFirstShowing;
}
protected abstract String getTitle();
protected abstract String getHTMLHeader();
@@ -69,6 +69,7 @@ public class CustomizeIDEWizardDialog extends DialogWrapper implements ActionLis
AbstractCustomizeWizardStep.applyHeaderFooterStyle(myHeaderLabel);
AbstractCustomizeWizardStep.applyHeaderFooterStyle(myFooterLabel);
init();
skipFirstShowing();
initCurrentStep(true);
setSize(400, 300);
System.setProperty(StartupActionScriptManager.STARTUP_WIZARD_MODE, "true");
@@ -175,6 +176,16 @@ public class CustomizeIDEWizardDialog extends DialogWrapper implements ActionLis
super.doOKAction();
}
private void skipFirstShowing() {
myIndex = 0;
for (AbstractCustomizeWizardStep step : mySteps) {
if (!step.skipFirstShowing()) {
myIndex = mySteps.indexOf(step);
return;
}
}
}
private void initCurrentStep(boolean forward) {
final AbstractCustomizeWizardStep myCurrentStep = mySteps.get(myIndex);
myCurrentStep.beforeShown(forward);
@@ -28,6 +28,9 @@ public class CustomizeIdeaWizardStepsProvider implements CustomizeIDEWizardSteps
if (SystemInfo.isMac) {
steps.add(new CustomizeMacKeyboardLayoutStep());
}
else {
CustomizeMacKeyboardLayoutStep.applySharedKeymap();
}
if (CustomizeDesktopEntryStep.isAvailable()) {
steps.add(new CustomizeDesktopEntryStep("/UbuntuDesktopEntry.png"));
@@ -17,9 +17,12 @@ package com.intellij.ide.customize;
import com.intellij.CommonBundle;
import com.intellij.ide.WelcomeWizardUtil;
import com.intellij.ide.cloudConfiguration.CloudConfigurationManager;
import com.intellij.ide.cloudConfiguration.CloudConfigurationProvider;
import com.intellij.openapi.application.ApplicationNamesInfo;
import com.intellij.openapi.keymap.KeymapManager;
import com.intellij.openapi.ui.VerticalFlowLayout;
import com.intellij.util.ParameterizedRunnable;
import javax.swing.*;
import java.awt.*;
@@ -62,7 +65,40 @@ public class CustomizeMacKeyboardLayoutStep extends AbstractCustomizeWizardStep
ButtonGroup group = new ButtonGroup();
group.add(macRadioButton);
group.add(defaultRadioButton);
macRadioButton.setSelected(true);
String sharedKeymap = CloudConfigurationManager.getCustomizeProvider().getSharedKeymap();
if (sharedKeymap == null || KeymapManager.MAC_OS_X_10_5_PLUS_KEYMAP.equals(sharedKeymap)) {
macRadioButton.setSelected(true);
}
else if (KeymapManager.MAC_OS_X_KEYMAP.equals(sharedKeymap)) {
defaultRadioButton.setSelected(true);
}
else {
JRadioButton button = new JRadioButton("Shared Keymap");
button.setOpaque(false);
JPanel panel = createBigButtonPanel(new VerticalFlowLayout(), button, CustomizeMacKeyboardLayoutStep::applySharedKeymap);
panel.add(button);
panel.add(new JLabel("<html><head>" + style + "</head><body><h3>" + sharedKeymap + " keymap</h3></body></html>"));
add(panel);
group.add(button);
button.setSelected(true);
}
mySkipFirstShowing = sharedKeymap != null;
}
public static void applySharedKeymap() {
CloudConfigurationProvider provider = CloudConfigurationManager.getCustomizeProvider();
String keymap = provider.getSharedKeymap();
if (keymap != null) {
ParameterizedRunnable<KeymapManager> runnable = provider.createSharedKeymap();
if (runnable == null) {
WelcomeWizardUtil.setWizardKeymap(keymap);
}
else {
WelcomeWizardUtil.setWizardKeymap(runnable);
}
}
}
@Override
@@ -17,6 +17,7 @@ package com.intellij.ide.customize;
import com.intellij.CommonBundle;
import com.intellij.ide.WelcomeWizardUtil;
import com.intellij.ide.cloudConfiguration.CloudConfigurationManager;
import com.intellij.ide.ui.LafManager;
import com.intellij.ide.ui.laf.IntelliJLaf;
import com.intellij.ide.ui.laf.LafManagerImpl;
@@ -27,6 +28,8 @@ import com.intellij.openapi.util.IconLoader;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.util.IconUtil;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.awt.*;
@@ -39,8 +42,8 @@ public class CustomizeUIThemeStepPanel extends AbstractCustomizeWizardStep {
public final String name;
public final String previewFileName;
public final String laf;
private Icon icon;
private Icon icon;
public ThemeInfo(String name, String previewFileName, String laf) {
this.name = name;
@@ -64,10 +67,11 @@ public class CustomizeUIThemeStepPanel extends AbstractCustomizeWizardStep {
}
return icon;
}
public void apply() {
}
}
protected static final ThemeInfo AQUA = new ThemeInfo("Default", "Aqua", "com.apple.laf.AquaLookAndFeel");
protected static final ThemeInfo DARCULA = new ThemeInfo("Darcula", "Darcula", DarculaLaf.class.getName());
protected static final ThemeInfo INTELLIJ = new ThemeInfo("IntelliJ", "IntelliJ", IntelliJLaf.class.getName());
@@ -88,9 +92,9 @@ public class CustomizeUIThemeStepPanel extends AbstractCustomizeWizardStep {
myColumnMode = myThemes.size() > 2;
JPanel buttonsPanel = new JPanel(new GridLayout(myColumnMode ? myThemes.size() : 1, myColumnMode ? 1 : myThemes.size(), 5, 5));
ButtonGroup group = new ButtonGroup();
final ThemeInfo myDefaultTheme = myThemes.iterator().next();
final ThemeInfo myDefaultTheme = getDefaultTheme();
for (final ThemeInfo theme: myThemes) {
for (final ThemeInfo theme : myThemes) {
final JRadioButton radioButton = new JRadioButton(theme.name, myDefaultTheme == theme);
radioButton.setOpaque(false);
final JPanel panel = createBigButtonPanel(createSmallBorderLayout(), radioButton, () -> {
@@ -100,7 +104,8 @@ public class CustomizeUIThemeStepPanel extends AbstractCustomizeWizardStep {
panel.setBorder(createSmallEmptyBorder());
panel.add(radioButton, myColumnMode ? BorderLayout.WEST : BorderLayout.NORTH);
Icon icon = theme.getIcon();
final JLabel label = new JLabel(myColumnMode ? IconUtil.scale(IconUtil.cropIcon(icon, icon.getIconWidth() * 2 / 3, icon.getIconHeight() * 2 / 3), .5) : icon);
final JLabel label = new JLabel(
myColumnMode ? IconUtil.scale(IconUtil.cropIcon(icon, icon.getIconWidth() * 2 / 3, icon.getIconHeight() * 2 / 3), .5) : icon);
label.setVerticalAlignment(SwingConstants.TOP);
label.setHorizontalAlignment(SwingConstants.RIGHT);
panel.add(label, BorderLayout.CENTER);
@@ -122,6 +127,33 @@ public class CustomizeUIThemeStepPanel extends AbstractCustomizeWizardStep {
myInitial = false;
}
@NotNull
private ThemeInfo getDefaultTheme() {
String sharedLaf = CloudConfigurationManager.getCustomizeProvider().getSharedLaf();
if (sharedLaf != null) {
ThemeInfo theme = findTheme(sharedLaf);
if (theme == null && AQUA.name.equals(sharedLaf)) {
theme = findTheme(INTELLIJ.name);
}
if (theme != null) {
return theme;
}
}
return myThemes.iterator().next();
}
@Nullable
private ThemeInfo findTheme(@NotNull String name) {
for (ThemeInfo theme : myThemes) {
if (name.equals(theme.name)) {
mySkipFirstShowing = true;
return theme;
}
}
return null;
}
protected void initThemes(Collection<ThemeInfo> result) {
if (SystemInfo.isMac) {
result.add(LafManagerImpl.useIntelliJInsteadOfAqua() ? INTELLIJ : AQUA);
@@ -170,7 +202,6 @@ public class CustomizeUIThemeStepPanel extends AbstractCustomizeWizardStep {
private void applyLaf(ThemeInfo theme, Component component) {
UIManager.LookAndFeelInfo info = new UIManager.LookAndFeelInfo(theme.name, theme.laf);
if (info == null) return;
try {
UIManager.setLookAndFeel(info.getClassName());
String className = info.getClassName();
@@ -192,16 +223,7 @@ public class CustomizeUIThemeStepPanel extends AbstractCustomizeWizardStep {
myPreviewLabel.setBorder(BorderFactory.createLineBorder(UIManager.getColor("Label.disabledForeground")));
}
}
catch (ClassNotFoundException e) {
e.printStackTrace();
}
catch (InstantiationException e) {
e.printStackTrace();
}
catch (IllegalAccessException e) {
e.printStackTrace();
}
catch (UnsupportedLookAndFeelException e) {
catch (Exception e) {
e.printStackTrace();
}
}
@@ -0,0 +1,27 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.keymap.impl;
import org.jetbrains.annotations.NotNull;
import java.util.List;
/**
* @author Alexander Lobas
*/
public interface KeymapChangeListener {
void onShortcutChanged(@NotNull List<String> actionIds);
}
@@ -124,6 +124,8 @@ public class KeymapImpl extends ExternalizableSchemeAdapter implements Keymap {
otherKeymap.cleanShortcutsCache();
List<String> changedActionIds = getChangedActionIds(otherKeymap);
otherKeymap.myActionId2ListOfShortcuts.clear();
otherKeymap.myActionId2ListOfShortcuts.ensureCapacity(myActionId2ListOfShortcuts.size());
myActionId2ListOfShortcuts.forEachEntry(new TObjectObjectProcedure<String, OrderedSet<Shortcut>>() {
@@ -133,9 +135,38 @@ public class KeymapImpl extends ExternalizableSchemeAdapter implements Keymap {
return true;
}
});
if (!ContainerUtil.isEmpty(changedActionIds)) {
otherKeymap.fireShortcutChanged(changedActionIds);
}
return otherKeymap;
}
@Nullable
private List<String> getChangedActionIds(@NotNull KeymapImpl otherKeymap) {
if (!otherKeymap.isInternalKeymapListener()) {
return null;
}
List<String> changedActionIds = new ArrayList<>();
Set<String> oldKeys = otherKeymap.myActionId2ListOfShortcuts.keySet();
Set<String> newKeys = new HashSet<>(myActionId2ListOfShortcuts.keySet());
for (String key : oldKeys) {
if (newKeys.remove(key)) {
if (!Comparing.equal(otherKeymap.myActionId2ListOfShortcuts.get(key), myActionId2ListOfShortcuts.get(key))) {
changedActionIds.add(key);
}
}
else {
changedActionIds.add(key);
}
}
changedActionIds.addAll(newKeys);
return changedActionIds;
}
public boolean equals(Object object) {
if (!(object instanceof Keymap)) return false;
KeymapImpl secondKeymap = (KeymapImpl)object;
@@ -545,6 +576,10 @@ public class KeymapImpl extends ExternalizableSchemeAdapter implements Keymap {
return myKeymapManager;
}
public void setKeymapManager(@NotNull KeymapManagerEx keymapManager) {
myKeymapManager = keymapManager;
}
/**
* @param keymapElement element which corresponds to "keymap" tag.
*/
@@ -747,7 +782,7 @@ public class KeymapImpl extends ExternalizableSchemeAdapter implements Keymap {
* @return string representation of passed mouse shortcut. This method should
* be used only for serializing of the <code>MouseShortcut</code>
*/
private static String getMouseShortcutString(MouseShortcut shortcut) {
public static String getMouseShortcutString(MouseShortcut shortcut) {
if (Registry.is("ide.mac.forceTouch") && shortcut instanceof PressureShortcut) {
return "Force touch";
@@ -889,6 +924,23 @@ public class KeymapImpl extends ExternalizableSchemeAdapter implements Keymap {
myListeners.remove(listener);
}
private boolean isInternalKeymapListener() {
for (Listener listener : myListeners) {
if (listener instanceof KeymapChangeListener) {
return true;
}
}
return false;
}
private void fireShortcutChanged(@NotNull List<String> actionIds) {
for (Listener listener : myListeners) {
if (listener instanceof KeymapChangeListener) {
((KeymapChangeListener)listener).onShortcutChanged(actionIds);
}
}
}
private void fireShortcutChanged(String actionId) {
for (Listener listener : myListeners) {
listener.onShortcutChanged(actionId);
@@ -19,6 +19,7 @@ import com.intellij.ide.WelcomeWizardUtil;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.components.*;
import com.intellij.openapi.keymap.Keymap;
import com.intellij.openapi.keymap.KeymapManager;
import com.intellij.openapi.keymap.KeymapManagerListener;
import com.intellij.openapi.keymap.ex.KeymapManagerEx;
import com.intellij.openapi.options.Scheme;
@@ -27,6 +28,7 @@ import com.intellij.openapi.options.SchemesManager;
import com.intellij.openapi.options.SchemesManagerFactory;
import com.intellij.openapi.util.*;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.ParameterizedRunnable;
import com.intellij.util.containers.ContainerUtil;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
@@ -94,6 +96,11 @@ public class KeymapManagerImpl extends KeymapManagerEx implements PersistentStat
}
mySchemesManager.loadSchemes();
ParameterizedRunnable<KeymapManager> runnable = WelcomeWizardUtil.getWizardCreateKeymapRunnable();
if (runnable != null) {
runnable.run(this);
}
//noinspection AssignmentToStaticFieldFromInstanceMethod
ourKeymapManagerInitialized = true;
}