do not use Experiments if app not yet initialized

GitOrigin-RevId: 66a813c45f7ed2e07a84d2c1ed8c8cbf4c91d11a
This commit is contained in:
Vladimir Krivosheev
2020-01-13 12:39:24 +00:00
committed by intellij-monorepo-bot
parent b3925082fe
commit d0ac9c47aa
5 changed files with 20 additions and 26 deletions
@@ -4,7 +4,6 @@ package com.intellij.openapi.application;
import com.intellij.diagnostic.LoadingState;
import com.intellij.ide.util.PropertiesComponent;
import com.intellij.openapi.components.Service;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.extensions.ExtensionPointName;
import com.intellij.openapi.util.text.StringUtil;
@@ -49,11 +48,7 @@ public final class Experiments {
@NotNull
public static Experiments getInstance() {
if (ApplicationManager.getApplication() == null) {
// usages from UI Designer preview where no application available
return new Experiments();
}
return ServiceManager.getService(Experiments.class);
return ApplicationManager.getApplication().getService(Experiments.class);
}
public boolean isFeatureEnabled(@NotNull String featureId) {
@@ -1,6 +1,7 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.ui;
import com.intellij.diagnostic.LoadingState;
import com.intellij.icons.AllIcons;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.actionSystem.AnActionEvent;
@@ -8,7 +9,6 @@ import com.intellij.openapi.actionSystem.CustomShortcutSet;
import com.intellij.openapi.actionSystem.ShortcutSet;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.Experiments;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
import com.intellij.openapi.keymap.KeymapUtil;
import com.intellij.openapi.project.DumbAwareAction;
@@ -22,6 +22,7 @@ import com.intellij.ui.components.fields.ExtendableTextComponent;
import com.intellij.util.ui.StartupUiUtil;
import com.intellij.util.ui.UIUtil;
import com.intellij.util.ui.accessibility.ScreenReader;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -34,19 +35,22 @@ import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
public class ComponentWithBrowseButton<Comp extends JComponent> extends JPanel implements Disposable {
private static final Logger LOG = Logger.getInstance(ComponentWithBrowseButton.class);
private final Comp myComponent;
private final FixedSizeButton myBrowseButton;
private boolean myButtonEnabled = true;
@ApiStatus.Internal
public static boolean isUseInlineBrowserButton() {
return !LoadingState.COMPONENTS_REGISTERED.isOccurred() || Experiments.getInstance().isFeatureEnabled("inline.browse.button");
}
public ComponentWithBrowseButton(@NotNull Comp component, @Nullable ActionListener browseActionListener) {
super(new BorderLayout(SystemInfo.isMac || StartupUiUtil.isUnderDarcula() ? 0 : 2, 0));
myComponent = component;
// required! otherwise JPanel will occasionally gain focus instead of the component
setFocusable(false);
boolean inlineBrowseButton = myComponent instanceof ExtendableTextComponent && Experiments.getInstance().isFeatureEnabled("inline.browse.button");
boolean inlineBrowseButton = myComponent instanceof ExtendableTextComponent && isUseInlineBrowserButton();
if (inlineBrowseButton) {
((ExtendableTextComponent)myComponent).addExtension(ExtendableTextComponent.Extension.create(
getDefaultIcon(), getHoveredIcon(), getIconTooltip(), this::notifyActionListeners));
@@ -1,10 +1,9 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.ui;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.Experiments;
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
import com.intellij.openapi.fileChooser.FileChooserFactory;
@@ -48,7 +47,7 @@ public class TextFieldWithBrowseButton extends ComponentWithBrowseButton<JTextFi
public TextFieldWithBrowseButton(ActionListener browseActionListener, Disposable parent) {
// to prevent field to be infinitely resized in grid-box layouts
this(Experiments.getInstance().isFeatureEnabled("inline.browse.button") ? new ExtendableTextField(10) : new JBTextField(10),
this(ComponentWithBrowseButton.isUseInlineBrowserButton() ? new ExtendableTextField(10) : new JBTextField(10),
browseActionListener, parent);
}
@@ -1,19 +1,18 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.ui;
import com.intellij.icons.AllIcons;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonShortcuts;
import com.intellij.openapi.actionSystem.CustomShortcutSet;
import com.intellij.openapi.application.Experiments;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.keymap.KeymapUtil;
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.ui.ComponentWithBrowseButton;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.FixedSizeButton;
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
import com.intellij.ui.components.fields.ExtendableTextComponent;
import com.intellij.util.PlatformIcons;
import com.intellij.util.ui.JBUI;
import org.jetbrains.annotations.NotNull;
@@ -33,7 +32,7 @@ public abstract class AbstractFieldPanel extends JPanel {
protected ArrayList<JButton> myButtons = new ArrayList<>(1);
protected JLabel myLabel;
private ActionListener myBrowseButtonActionListener;
private String myViewerDialogTitle;
private final String myViewerDialogTitle;
private String myLabelText;
private TextFieldWithBrowseButton.MyDoClickAction myDoClickAction;
@@ -110,7 +109,7 @@ public abstract class AbstractFieldPanel extends JPanel {
this.add(myComponent, new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, JBUI.emptyInsets(), 0, 0));
if (myBrowseButtonActionListener != null) {
if (Experiments.getInstance().isFeatureEnabled("inline.browse.button") && myComponent instanceof ExtendableTextComponent) {
if (myComponent instanceof ExtendableTextComponent && ComponentWithBrowseButton.isUseInlineBrowserButton()) {
((ExtendableTextComponent)myComponent).addExtension(ExtendableTextComponent.Extension.create(
getDefaultIcon(), getHoveredIcon(), getIconTooltip(), this::notifyActionListener));
new DumbAwareAction() {
@@ -136,7 +135,7 @@ public abstract class AbstractFieldPanel extends JPanel {
myDoClickAction = new TextFieldWithBrowseButton.MyDoClickAction(showViewerButton);
}
showViewerButton.setFocusable(false);
showViewerButton.setIcon(PlatformIcons.OPEN_EDIT_DIALOG_ICON);
showViewerButton.setIcon(AllIcons.Actions.ShowViewer);
showViewerButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
@@ -175,10 +174,6 @@ public abstract class AbstractFieldPanel extends JPanel {
myBrowseButtonActionListener = browseButtonActionListener;
}
public void setViewerDialogTitle(String viewerDialogTitle) {
myViewerDialogTitle = viewerDialogTitle;
}
public void setLabelText(String labelText) {
myLabelText = labelText;
}
@@ -1,6 +1,7 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.wm.impl;
import com.intellij.diagnostic.LoadingState;
import com.intellij.execution.configurations.GeneralCommandLine;
import com.intellij.execution.util.ExecUtil;
import com.intellij.ide.IdeEventQueue;
@@ -796,7 +797,7 @@ public final class GlobalMenuLinux implements LinuxGlobalMenuEventHandler, Dispo
if (!SystemInfo.isLinux ||
ApplicationManager.getApplication() == null || ApplicationManager.getApplication().isUnitTestMode() ||
Registry.is("linux.native.menu.force.disable") ||
!Experiments.getInstance().isFeatureEnabled("linux.native.menu") ||
(LoadingState.COMPONENTS_REGISTERED.isOccurred() && !Experiments.getInstance().isFeatureEnabled("linux.native.menu")) ||
!JnaLoader.isLoaded() ||
isUnderVMWithSwiftPluginInstalled()) {
return null;