gt:       Label serializationLabel = headerLabel("Serialization");
context: /*
   * EditingPreferencesPane.java
   *
   * Copyright (C) 2009-12 by RStudio, Inc.
   *
   * Unless you have received this program directly from RStudio pursuant
   * to the terms of a commercial license agreement with RStudio, then
   * this program is licensed to you under the terms of version 3 of the
   * GNU Affero General Public License. This program is distributed WITHOUT
   * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
   * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
   * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
   *
   */
  package org.rstudio.studio.client.workbench.prefs.views;
  
  import com.google.gwt.dom.client.Style.Unit;
  import com.google.gwt.event.dom.client.ChangeEvent;
  import com.google.gwt.event.dom.client.ChangeHandler;
  import com.google.gwt.event.dom.client.ClickEvent;
  import com.google.gwt.event.dom.client.ClickHandler;
  import com.google.gwt.event.logical.shared.ValueChangeEvent;
  import com.google.gwt.event.logical.shared.ValueChangeHandler;
  import com.google.gwt.resources.client.ImageResource;
  import com.google.gwt.user.client.ui.CheckBox;
  import com.google.gwt.user.client.ui.HorizontalPanel;
  import com.google.gwt.user.client.ui.Label;
  import com.google.gwt.user.client.ui.VerticalPanel;
  import com.google.inject.Inject;
  
  import org.rstudio.core.client.StringUtil;
  import org.rstudio.core.client.command.KeyboardShortcut;
  import org.rstudio.core.client.command.ShortcutManager;
  import org.rstudio.core.client.prefs.PreferencesDialogBaseResources;
  import org.rstudio.core.client.theme.DialogTabLayoutPanel;
  import org.rstudio.core.client.widget.HelpButton;
  import org.rstudio.core.client.widget.ModifyKeyboardShortcutsWidget;
  import org.rstudio.core.client.widget.NumericValueWidget;
  import org.rstudio.core.client.widget.OperationWithInput;
  import org.rstudio.core.client.widget.SelectWidget;
  import org.rstudio.core.client.widget.SmallButton;
  import org.rstudio.core.client.widget.TextBoxWithButton;
  import org.rstudio.studio.client.common.DiagnosticsHelpLink;
  import org.rstudio.studio.client.common.HelpLink;
  import org.rstudio.studio.client.common.SimpleRequestCallback;
  import org.rstudio.studio.client.workbench.prefs.model.EditingPrefs;
  import org.rstudio.studio.client.workbench.prefs.model.RPrefs;
  import org.rstudio.studio.client.workbench.prefs.model.UIPrefs;
  import org.rstudio.studio.client.workbench.prefs.model.UIPrefsAccessor;
  import org.rstudio.studio.client.workbench.snippets.ui.EditSnippetsDialog;
  import org.rstudio.studio.client.workbench.views.source.editors.text.FoldStyle;
  import org.rstudio.studio.client.workbench.views.source.editors.text.IconvListResult;
  import org.rstudio.studio.client.workbench.views.source.editors.text.ui.ChooseEncodingDialog;
  import org.rstudio.studio.client.workbench.views.source.model.SourceServerOperations;
  
  public class EditingPreferencesPane extends PreferencesPane
  {
     @Inject
     public EditingPreferencesPane(UIPrefs prefs,
                                   SourceServerOperations server,
                                   PreferencesDialogResources res)
     {
        prefs_ = prefs;
        server_ = server;
        PreferencesDialogBaseResources baseRes = PreferencesDialogBaseResources.INSTANCE;
        
        VerticalPanel editingPanel = new VerticalPanel();
        editingPanel.add(headerLabel("General"));
        editingPanel.add(tight(spacesForTab_ = checkboxPref("Insert spaces for tab", prefs.useSpacesForTab())));
        editingPanel.add(indent(tabWidth_ = numericPref("Tab width", prefs.numSpacesForTab())));   
        editingPanel.add(checkboxPref("Insert matching parens/quotes", prefs_.insertMatching()));
        editingPanel.add(checkboxPref("Auto-indent code after paste", prefs_.reindentOnPaste()));
        editingPanel.add(checkboxPref("Vertically align arguments in auto-indent", prefs_.verticallyAlignArgumentIndent()));
        editingPanel.add(checkboxPref("Soft-wrap R source files", prefs_.softWrapRFiles()));
        editingPanel.add(checkboxPref(
              "Continue comment when inserting new line",
              prefs_.continueCommentsOnNewline(),
              "When enabled, pressing enter will continue comments on new lines. Press Shift + Enter to exit a comment."));
        
        delimiterSurroundWidget_ = new SelectWidget(
              "Surround selection on text insertion:",
              new String[] {
                    "Never",
                    "Quotes",
                    "Quotes & Brackets"
              },
              new String[] {
                    UIPrefsAccessor.EDITOR_SURROUND_SELECTION_NEVER,
                    UIPrefsAccessor.EDITOR_SURROUND_SELECTION_QUOTES,
                    UIPrefsAccessor.EDITOR_SURROUND_SELECTION_QUOTES_AND_BRACKETS
              },
              false,
              true,
              false);
        editingPanel.add(delimiterSurroundWidget_);
        
        HorizontalPanel keyboardPanel = new HorizontalPanel();
        editorMode_ = new SelectWidget(
              "Keybindings:",
              new String[] {
                    "Default",
                    "Vim",
                    "Emacs"
              },
              new String[] {
                    UIPrefsAccessor.EDITOR_KEYBINDINGS_DEFAULT,
                    UIPrefsAccessor.EDITOR_KEYBINDINGS_VIM,
                    UIPrefsAccessor.EDITOR_KEYBINDINGS_EMACS
              },
              false,
              true,
              false);
        
        keyboardPanel.add(editorMode_);
        SmallButton editShortcuts = new SmallButton("Modify Keyboard Shortcuts...");
        editShortcuts.getElement().getStyle().setMarginLeft(15, Unit.PX);
        editShortcuts.addClickHandler(new ClickHandler() {
           @Override
           public void onClick(ClickEvent event)
           {
              new ModifyKeyboardShortcutsWidget().showModal();
           }         
        });
        keyboardPanel.add(editShortcuts);
        
        
        lessSpaced(keyboardPanel);
        editingPanel.add(keyboardPanel);
         
        Label executionLabel = headerLabel("Execution");
        editingPanel.add(executionLabel);
        executionLabel.getElement().getStyle().setMarginTop(8, Unit.PX);
        editingPanel.add(checkboxPref("Always save R scripts before sourcing", prefs.saveBeforeSourcing()));
        editingPanel.add(checkboxPref("Focus console after executing from source", prefs_.focusConsoleAfterExec()));
        
      
        
        Label snippetsLabel = headerLabel("Snippets");
        snippetsLabel.getElement().getStyle().setMarginTop(8, Unit.PX);
        editingPanel.add(snippetsLabel);
        
        HorizontalPanel panel = new HorizontalPanel();
        CheckBox enableSnippets = checkboxPref("Enable code snippets", prefs_.enableSnippets());
        panel.add(enableSnippets);
       
        SmallButton editSnippets = new SmallButton("Edit Snippets...");
        editSnippets.getElement().getStyle().setMarginTop(1, Unit.PX);
        editSnippets.getElement().getStyle().setMarginLeft(5, Unit.PX);
        editSnippets.addClickHandler(new ClickHandler() {
           @Override
           public void onClick(ClickEvent event)
           {
              new EditSnippetsDialog().showModal();
           }
        });
        panel.add(editSnippets);
        
        HelpButton snippetHelp = new HelpButton("code_snippets");
        snippetHelp.getElement().getStyle().setMarginTop(2, Unit.PX);
        snippetHelp.getElement().getStyle().setMarginLeft(6, Unit.PX);
        panel.add(snippetHelp);
        
        editingPanel.add(panel);
        
        
        VerticalPanel displayPanel = new VerticalPanel();
        displayPanel.add(headerLabel("General"));
        displayPanel.add(checkboxPref("Highlight selected word", prefs.highlightSelectedWord()));
        displayPanel.add(checkboxPref("Highlight selected line", prefs.highlightSelectedLine()));
        displayPanel.add(checkboxPref("Show line numbers", prefs.showLineNumbers()));
        displayPanel.add(tight(showMargin_ = checkboxPref("Show margin", prefs.showMargin())));
        displayPanel.add(indent(marginCol_ = numericPref("Margin column", prefs.printMarginColumn())));
        displayPanel.add(checkboxPref("Show whitespace characters", prefs_.showInvisibles()));
        displayPanel.add(checkboxPref("Show indent guides", prefs_.showIndentGuides()));
        displayPanel.add(checkboxPref("Blinking cursor", prefs_.blinkingCursor()));
        displayPanel.add(checkboxPref("Show syntax highlighting in console input", prefs_.syntaxColorConsole()));
        displayPanel.add(checkboxPref("Allow scroll past end of document", prefs_.scrollPastEndOfDocument()));
        displayPanel.add(extraSpaced(checkboxPref("Highlight R function calls", prefs_.highlightRFunctionCalls())));
         
        foldMode_ = new SelectWidget(
              "Fold Style:",
              new String[] {
                    "Start Only",
                    "Start and End"
              },
              new String[] {
                    FoldStyle.FOLD_MARK_BEGIN_ONLY,
                    FoldStyle.FOLD_MARK_BEGIN_AND_END
              },
              false,
              true,
              false);
        
        displayPanel.add(foldMode_);
        
        displayPanel.add(headerLabel("Console"));
        NumericValueWidget limitLengthPref =
              numericPref("Limit length of lines displayed in console to:", prefs_.truncateLongLinesInConsoleHistory());
        limitLengthPref.setWidth("36px");
        displayPanel.add(limitLengthPref);
        
        VerticalPanel savePanel = new VerticalPanel();
        
        savePanel.add(headerLabel("General"));
        savePanel.add(checkboxPref("Ensure that source files end with newline", prefs_.autoAppendNewline()));
        savePanel.add(checkboxPref("Strip trailing horizontal whitespace when saving", prefs_.stripTrailingWhitespace()));
  
  