diff --git a/platform/editor-ui-ex/src/com/intellij/openapi/editor/colors/impl/AppEditorFontOptions.java b/platform/editor-ui-ex/src/com/intellij/openapi/editor/colors/impl/AppEditorFontOptions.java index 98c1fa403cca..a8b0b8cb1808 100644 --- a/platform/editor-ui-ex/src/com/intellij/openapi/editor/colors/impl/AppEditorFontOptions.java +++ b/platform/editor-ui-ex/src/com/intellij/openapi/editor/colors/impl/AppEditorFontOptions.java @@ -22,6 +22,7 @@ import com.intellij.openapi.components.State; import com.intellij.openapi.components.Storage; import com.intellij.openapi.editor.colors.EditorFontCache; import com.intellij.openapi.editor.colors.FontPreferences; +import com.intellij.openapi.editor.colors.ModifiableFontPreferences; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -64,6 +65,10 @@ public class AppEditorFontOptions implements PersistentStateComponent EditorFontCache.getInstance().reset()); } + private static void copyState(PersistentFontPreferences state, @NotNull ModifiableFontPreferences fontPreferences) { + fontPreferences.clear(); + int fontSize = UISettings.restoreFontSize(state.FONT_SIZE, state.FONT_SCALE); + fontPreferences.register(state.FONT_FAMILY, fontSize); + fontPreferences.setLineSpacing(state.LINE_SPACING); + fontPreferences.setUseLigatures(state.USE_LIGATURES); + if (state.SECONDARY_FONT_FAMILY != null) { + fontPreferences.register(state.SECONDARY_FONT_FAMILY, fontSize); + } + } + + public static void initDefaults(@NotNull ModifiableFontPreferences fontPreferences) { + copyState(PersistentFontPreferences.getDefaultState(), fontPreferences); + } + @NotNull public FontPreferences getFontPreferences() { return myFontPreferences; diff --git a/platform/lang-impl/src/com/intellij/application/options/editor/fonts/AppEditorFontConfigurable.java b/platform/lang-impl/src/com/intellij/application/options/editor/fonts/AppEditorFontConfigurable.java index 1bac5d01168f..f58269f46c70 100644 --- a/platform/lang-impl/src/com/intellij/application/options/editor/fonts/AppEditorFontConfigurable.java +++ b/platform/lang-impl/src/com/intellij/application/options/editor/fonts/AppEditorFontConfigurable.java @@ -77,10 +77,7 @@ public class AppEditorFontConfigurable implements SearchableConfigurable, NoScro @Override public void reset() { getStoredPreferences().copyTo(getUIFontPreferences()); - AppEditorFontOptionsPanel optionsPanel = getFontPanel().getOptionsPanel(); - optionsPanel.updateWarning(); - optionsPanel.updateOptionsList(); - getFontPanel().updatePreview(); + getFontPanel().getOptionsPanel().updateOnChangedFont(); } @NotNull diff --git a/platform/lang-impl/src/com/intellij/application/options/editor/fonts/AppEditorFontOptionsPanel.java b/platform/lang-impl/src/com/intellij/application/options/editor/fonts/AppEditorFontOptionsPanel.java index e18127ea1bb7..7f36acb1b33c 100644 --- a/platform/lang-impl/src/com/intellij/application/options/editor/fonts/AppEditorFontOptionsPanel.java +++ b/platform/lang-impl/src/com/intellij/application/options/editor/fonts/AppEditorFontOptionsPanel.java @@ -17,12 +17,16 @@ package com.intellij.application.options.editor.fonts; import com.intellij.application.options.colors.AbstractFontOptionsPanel; import com.intellij.application.options.colors.ColorAndFontOptions; +import com.intellij.application.options.colors.ColorAndFontSettingsListener; import com.intellij.icons.AllIcons; import com.intellij.ide.DataManager; import com.intellij.openapi.application.ApplicationBundle; import com.intellij.openapi.editor.colors.EditorColorsManager; import com.intellij.openapi.editor.colors.EditorColorsScheme; import com.intellij.openapi.editor.colors.FontPreferences; +import com.intellij.openapi.editor.colors.ModifiableFontPreferences; +import com.intellij.openapi.editor.colors.impl.AppEditorFontOptions; +import com.intellij.openapi.editor.colors.impl.FontPreferencesImpl; import com.intellij.openapi.options.Configurable; import com.intellij.openapi.options.ex.Settings; import com.intellij.ui.HoverHyperlinkLabel; @@ -34,14 +38,20 @@ import javax.swing.*; import javax.swing.event.HyperlinkEvent; import javax.swing.event.HyperlinkListener; import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; public class AppEditorFontOptionsPanel extends AbstractFontOptionsPanel { private final EditorColorsScheme myScheme; private JPanel myWarningPanel; private JLabel myEditorFontLabel; + private JButton myRestoreButton; + private FontPreferences myDefaultPreferences; protected AppEditorFontOptionsPanel(EditorColorsScheme scheme) { myScheme = scheme; + myDefaultPreferences = new FontPreferencesImpl(); + AppEditorFontOptions.initDefaults((ModifiableFontPreferences)myDefaultPreferences); updateOptionsList(); } @@ -57,9 +67,44 @@ public class AppEditorFontOptionsPanel extends AbstractFontOptionsPanel { topPanel.add(myWarningPanel, c); c.gridy = 1; topPanel.add(createFontSettingsPanel(), c); + c.insets = JBUI.insets(5, 0, 0, 0); + c.fill = GridBagConstraints.HORIZONTAL; + c.gridy = 2; + topPanel.add(new JSeparator(), c); + c.gridy = 3; + c.fill = GridBagConstraints.NONE; + myRestoreButton = new JButton(ApplicationBundle.message("settings.editor.font.restored.defaults")); + myRestoreButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + restoreDefaults(); + } + }); + addListener(new ColorAndFontSettingsListener.Abstract() { + @Override + public void fontChanged() { + updateWarning(); + updateRestoreButtonState(); + } + }); + topPanel.add(myRestoreButton, c); return topPanel; } + private void restoreDefaults() { + AppEditorFontOptions.initDefaults((ModifiableFontPreferences)getFontPreferences()); + updateOnChangedFont(); + } + + public void updateOnChangedFont() { + updateOptionsList(); + fireFontChanged(); + } + + private void updateRestoreButtonState() { + myRestoreButton.setEnabled(!myDefaultPreferences.equals(getFontPreferences())); + } + private JPanel createMessagePanel() { JPanel messagePanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); messagePanel.add(new JLabel(AllIcons.General.BalloonWarning)); diff --git a/platform/platform-resources-en/src/messages/ApplicationBundle.properties b/platform/platform-resources-en/src/messages/ApplicationBundle.properties index 0e48fd0fafff..231ba43fd0d4 100644 --- a/platform/platform-resources-en/src/messages/ApplicationBundle.properties +++ b/platform/platform-resources-en/src/messages/ApplicationBundle.properties @@ -540,6 +540,7 @@ error.scheme.must.have.a.name=Scheme must have a name error.illegal.scheme.name=Illegal scheme name error.a.scheme.with.this.name.already.exists.or.was.deleted.without.applying.the.changes=A scheme with this name already exists or was deleted without applying the changes title.select.font=Select Font +settings.editor.font.restored.defaults=Restore Defaults settings.editor.font.overwrite=Use color scheme font instead of the settings.editor.console.font.overwrite=Use console font instead of the action.apply.editor.font.settings=Apply editor font settings