Separate option for showing browser buttons in XML files (WEB-44295)

GitOrigin-RevId: f210fc41b5a99c438c29c90c322248fe4eb28485
This commit is contained in:
Dmitry Jemerov
2020-03-10 09:34:33 +00:00
committed by intellij-monorepo-bot
parent bf17d1cd45
commit 2c5810275b
5 changed files with 59 additions and 11 deletions
@@ -43,14 +43,34 @@
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
</component>
<component id="beb5b" class="com.intellij.ui.components.JBCheckBox" binding="showBrowserHover">
<grid id="91c59" binding="browserPopupPanel" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="messages/XmlBundle" key="settings.browsers.show.browser.popup.in.the.editor"/>
</properties>
</component>
<properties/>
<border type="none" title-resource-bundle="messages/XmlBundle" title-key="settings.browsers.show.browser.popup.in.the.editor">
<font/>
</border>
<children>
<component id="beb5b" class="com.intellij.ui.components.JBCheckBox" binding="showBrowserHover">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="messages/XmlBundle" key="settings.browsers.show.browser.popup.html"/>
</properties>
</component>
<component id="f75ff" class="com.intellij.ui.components.JBCheckBox" binding="showBrowserHoverXml">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="messages/XmlBundle" key="settings.browsers.show.browser.popup.xml"/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
<buttonGroups>
@@ -1,4 +1,4 @@
// Copyright 2000-2018 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.ide.browsers;
import com.intellij.ide.GeneralSettings;
@@ -9,6 +9,7 @@ import com.intellij.openapi.ui.ComboBox;
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
import com.intellij.openapi.util.Comparing;
import com.intellij.ui.CollectionComboBoxModel;
import com.intellij.ui.IdeBorderFactory;
import com.intellij.ui.SimpleListCellRenderer;
import com.intellij.ui.TitledSeparator;
import com.intellij.ui.components.JBCheckBox;
@@ -126,6 +127,8 @@ final class BrowserSettingsPanel {
private ComboBox<DefaultBrowserPolicy> defaultBrowserPolicyComboBox;
private JBCheckBox showBrowserHover;
private JBCheckBox showBrowserHoverXml;
private JPanel browserPopupPanel;
private TableModelEditor<ConfigurableWebBrowser> browsersEditor;
@@ -167,6 +170,8 @@ final class BrowserSettingsPanel {
if (text == null) throw new IllegalStateException(String.valueOf(value));
return text;
}));
browserPopupPanel.setBorder(IdeBorderFactory.createTitledBorder(XmlBundle.message("settings.browsers.show.browser.popup.in.the.editor")));
}
private void updateCustomPathTextFieldValue(@NotNull DefaultBrowserPolicy browser) {
@@ -279,7 +284,8 @@ final class BrowserSettingsPanel {
DefaultBrowserPolicy defaultBrowserPolicy = getDefaultBrowser();
if (getDefaultBrowserPolicy(browserManager) != defaultBrowserPolicy ||
browserManager.isShowBrowserHover() != showBrowserHover.isSelected()) {
browserManager.isShowBrowserHover() != showBrowserHover.isSelected() ||
browserManager.isShowBrowserHoverXml() != showBrowserHoverXml.isSelected()) {
return true;
}
@@ -302,6 +308,7 @@ final class BrowserSettingsPanel {
WebBrowserManager browserManager = WebBrowserManager.getInstance();
browserManager.setShowBrowserHover(showBrowserHover.isSelected());
browserManager.setShowBrowserHoverXml(showBrowserHoverXml.isSelected());
browserManager.defaultBrowserPolicy = getDefaultBrowser();
browserManager.setList(browsersEditor.apply());
}
@@ -317,6 +324,7 @@ final class BrowserSettingsPanel {
GeneralSettings settings = GeneralSettings.getInstance();
showBrowserHover.setSelected(browserManager.isShowBrowserHover());
showBrowserHoverXml.setSelected(browserManager.isShowBrowserHoverXml());
browsersEditor.reset(browserManager.getList());
customPathValue = settings.getBrowserPath();
@@ -1,4 +1,4 @@
// 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.ide.browsers;
import com.intellij.openapi.components.PersistentStateComponent;
@@ -60,6 +60,7 @@ public class WebBrowserManager extends SimpleModificationTracker implements Pers
private List<ConfigurableWebBrowser> browsers;
private boolean myShowBrowserHover = true;
private boolean myShowBrowserHoverXml = false;
DefaultBrowserPolicy defaultBrowserPolicy = DefaultBrowserPolicy.SYSTEM;
public WebBrowserManager() {
@@ -121,6 +122,9 @@ public class WebBrowserManager extends SimpleModificationTracker implements Pers
if (!myShowBrowserHover) {
state.setAttribute("showHover", "false");
}
if (myShowBrowserHoverXml) {
state.setAttribute("showHoverXml", "true");
}
if (!browsers.equals(getPredefinedBrowsers())) {
for (ConfigurableWebBrowser browser : browsers) {
@@ -430,7 +434,15 @@ public class WebBrowserManager extends SimpleModificationTracker implements Pers
myShowBrowserHover = showBrowserHover;
}
public void setShowBrowserHoverXml(boolean showBrowserHover) {
myShowBrowserHoverXml = showBrowserHover;
}
public boolean isShowBrowserHover() {
return myShowBrowserHover;
}
public boolean isShowBrowserHoverXml() {
return myShowBrowserHoverXml;
}
}
@@ -1,12 +1,14 @@
// 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.ide.browsers.actions;
import com.intellij.icons.AllIcons;
import com.intellij.ide.browsers.WebBrowser;
import com.intellij.ide.browsers.WebBrowserManager;
import com.intellij.lang.xml.XMLLanguage;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.diff.impl.DiffUtil;
import com.intellij.openapi.editor.Editor;
import com.intellij.psi.PsiFile;
import com.intellij.psi.util.CachedValueProvider;
import com.intellij.xml.XmlBundle;
import org.jetbrains.annotations.NotNull;
@@ -66,7 +68,11 @@ public abstract class OpenInBrowserBaseGroupAction extends ComputableActionGroup
public void update(@NotNull AnActionEvent e) {
Editor editor = e.getData(CommonDataKeys.EDITOR);
final WebBrowserManager browserManager = WebBrowserManager.getInstance();
e.getPresentation().setVisible(browserManager.isShowBrowserHover() && !browserManager.getActiveBrowsers().isEmpty() &&
PsiFile psiFile = e.getData(CommonDataKeys.PSI_FILE);
boolean needShowOnHover = psiFile != null && psiFile.getViewProvider().getBaseLanguage() == XMLLanguage.INSTANCE
? browserManager.isShowBrowserHoverXml()
: browserManager.isShowBrowserHover();
e.getPresentation().setVisible(needShowOnHover && !browserManager.getActiveBrowsers().isEmpty() &&
editor != null && !DiffUtil.isDiffEditor(editor));
}
}
@@ -253,6 +253,8 @@ comments=Comments
disable.emmet=Disable Emmet
edit.emmet.settings=Edit Emmet settings
settings.browsers.show.browser.popup.in.the.editor=Show browser popup in the editor
settings.browsers.show.browser.popup.html=For HTML files
settings.browsers.show.browser.popup.xml=For XML files
emmet.filter.single.line=Single line
checkbox.collapse.xml.tags=XML tags
xml.tag.info.no.attributes=<no attributes>