1 /* 2 * ConsolePreferencesPane.java 3 * 4 * Copyright (C) 2021 by RStudio, PBC 5 * 6 * Unless you have received this program directly from RStudio pursuant 7 * to the terms of a commercial license agreement with RStudio, then 8 * this program is licensed to you under the terms of version 3 of the 9 * GNU Affero General Public License. This program is distributed WITHOUT 10 * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 12 * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details. 13 * 14 */ 15 package org.rstudio.studio.client.workbench.prefs.views; 16 17 import com.google.gwt.resources.client.ImageResource; 18 import com.google.gwt.user.client.ui.Label; 19 import com.google.inject.Inject; 20 import org.rstudio.core.client.prefs.RestartRequirement; 21 import org.rstudio.core.client.resources.ImageResource2x; 22 import org.rstudio.core.client.widget.NumericValueWidget; 23 import org.rstudio.core.client.widget.SelectWidget; 24 import org.rstudio.studio.client.workbench.model.Session; 25 import org.rstudio.studio.client.workbench.prefs.model.UserPrefs; 26 27 28 public class ConsolePreferencesPane extends PreferencesPane 29 { 30 @Inject ConsolePreferencesPane(UserPrefs prefs, Session session, PreferencesDialogResources res)31 public ConsolePreferencesPane(UserPrefs prefs, 32 Session session, 33 PreferencesDialogResources res) 34 { 35 prefs_ = prefs; 36 res_ = res; 37 38 add(headerLabel("Display")); 39 add(checkboxPref("Show syntax highlighting in console input", prefs_.syntaxColorConsole())); 40 add(checkboxPref("Different color for error or message output (requires restart)", prefs_.highlightConsoleErrors())); 41 add(checkboxPref("Limit visible console output (requires restart)", prefs_.limitVisibleConsole())); 42 NumericValueWidget limitLengthPref = 43 numericPref("Limit output line length to:", prefs_.consoleLineLengthLimit()); 44 add(nudgeRightPlus(limitLengthPref)); 45 46 consoleColorMode_ = new SelectWidget( 47 "ANSI Escape Codes:", 48 new String[] { 49 "Show ANSI colors", 50 "Remove ANSI codes", 51 "Ignore ANSI codes (1.0 behavior)" 52 }, 53 new String[] { 54 UserPrefs.ANSI_CONSOLE_MODE_ON, 55 UserPrefs.ANSI_CONSOLE_MODE_STRIP, 56 UserPrefs.ANSI_CONSOLE_MODE_OFF 57 }, 58 false, 59 true, 60 false); 61 add(consoleColorMode_); 62 63 Label debuggingLabel = headerLabel("Debugging"); 64 spacedBefore(debuggingLabel); 65 add(debuggingLabel); 66 add(spaced(checkboxPref( 67 "Automatically expand tracebacks in error inspector", 68 prefs_.autoExpandErrorTracebacks(), 69 true /*defaultSpaced*/))); 70 71 Label otherLabel = headerLabel("Other"); 72 spacedBefore(otherLabel); 73 add(otherLabel); 74 add(spaced(checkboxPref("Double-click to select words", prefs_.consoleDoubleClickSelect()))); 75 } 76 77 @Override getIcon()78 public ImageResource getIcon() 79 { 80 return new ImageResource2x(res_.iconConsole2x()); 81 } 82 83 @Override getName()84 public String getName() 85 { 86 return "Console"; 87 } 88 89 @Override initialize(UserPrefs prefs)90 protected void initialize(UserPrefs prefs) 91 { 92 consoleColorMode_.setValue(prefs_.ansiConsoleMode().getValue()); 93 initialHighlightConsoleErrors_ = prefs.highlightConsoleErrors().getValue(); 94 initialLimitVisibleConsole_ = prefs.limitVisibleConsole().getValue(); 95 } 96 97 @Override onApply(UserPrefs prefs)98 public RestartRequirement onApply(UserPrefs prefs) 99 { 100 RestartRequirement restartRequirement = super.onApply(prefs); 101 102 prefs_.ansiConsoleMode().setGlobalValue(consoleColorMode_.getValue()); 103 if (prefs_.highlightConsoleErrors().getValue() != initialHighlightConsoleErrors_) 104 { 105 initialHighlightConsoleErrors_ = prefs_.highlightConsoleErrors().getValue(); 106 restartRequirement.setRestartRequired(); 107 } 108 if (!restartRequirement.getDesktopRestartRequired() && !restartRequirement.getUiReloadRequired()) 109 { 110 if (prefs_.limitVisibleConsole().getValue() != initialLimitVisibleConsole_) 111 { 112 initialLimitVisibleConsole_ = prefs_.limitVisibleConsole().getValue(); 113 restartRequirement.setRestartRequired(); 114 } 115 } 116 return restartRequirement; 117 } 118 119 @Override validate()120 public boolean validate() 121 { 122 return true; 123 } 124 125 private boolean initialHighlightConsoleErrors_; 126 private boolean initialLimitVisibleConsole_; 127 private final SelectWidget consoleColorMode_; 128 129 // Injected 130 private final UserPrefs prefs_; 131 private final PreferencesDialogResources res_; 132 } 133