<commit_before>/*
 * UIPrefs.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.model;

import com.google.inject.Inject;
import com.google.inject.Singleton;

import org.rstudio.core.client.Debug;
import org.rstudio.core.client.js.JsObject;
import org.rstudio.core.client.js.JsUtil;
import org.rstudio.studio.client.application.events.EventBus;
import org.rstudio.studio.client.notebook.CompileNotebookPrefs;
import org.rstudio.studio.client.notebookv2.CompileNotebookv2Prefs;
import org.rstudio.studio.client.server.VoidServerRequestCallback;
import org.rstudio.studio.client.workbench.exportplot.model.ExportPlotOptions;
import org.rstudio.studio.client.workbench.model.Session;
import org.rstudio.studio.client.workbench.prefs.events.UiPrefsChangedEvent;
import org.rstudio.studio.client.workbench.prefs.events.UiPrefsChangedHandler;
import org.rstudio.studio.client.workbench.views.plots.model.SavePlotAsPdfOptions;

@Singleton
public class UIPrefs extends UIPrefsAccessor implements UiPrefsChangedHandler
{
   @Inject
   public UIPrefs(Session session, 
                  EventBus eventBus,
                  PrefsServerOperations server)
   {
      super(session.getSessionInfo().getUiPrefs(),
            session.getSessionInfo().getProjectUIPrefs());
      
      session_ = session;
      server_ = server;
      
      eventBus.addHandler(UiPrefsChangedEvent.TYPE, this);
   }
   
   public void writeUIPrefs()
   {
      server_.setUiPrefs(
         session_.getSessionInfo().getUiPrefs(),
         new VoidServerRequestCallback());
   }
   
   @Override
   public void onUiPrefsChanged(UiPrefsChangedEvent e)
   {        
      if (e.getType().equals(UiPrefsChangedEvent.GLOBAL_TYPE))
      {
         // get prefs accessor
         UIPrefsAccessor newUiPrefs = new UIPrefsAccessor(
                                                   e.getUIPrefs(), 
                                                   JsObject.createJsObject());
         
         // show line numbers
         showLineNumbers().setGlobalValue(
                                 newUiPrefs.showLineNumbers().getGlobalValue());
         
         // highlight selected word
         highlightSelectedWord().setGlobalValue(
                           newUiPrefs.highlightSelectedWord().getGlobalValue());
         
         // highlight selected line
         highlightSelectedLine().setGlobalValue(
                          newUiPrefs.highlightSelectedLine().getGlobalValue());
       
         // pane config
         if (!newUiPrefs.paneConfig().getGlobalValue().isEqualTo(
                                 paneConfig().getGlobalValue()))
         {
            paneConfig().setGlobalValue(
                              newUiPrefs.paneConfig().getGlobalValue());
         }
         
         // use spaces for tab
         useSpacesForTab().setGlobalValue(
                          newUiPrefs.useSpacesForTab().getGlobalValue());
           
         // num spacers for tab
         numSpacesForTab().setGlobalValue(
               newUiPrefs.numSpacesForTab().getGlobalValue());
   
         // blinking cursor
         blinkingCursor().setGlobalValue(
               newUiPrefs.blinkingCursor().getGlobalValue());
         
         // show margin
         showMargin().setGlobalValue(
                                 newUiPrefs.showMargin().getGlobalValue());
         
         // print margin column
         printMarginColumn().setGlobalValue(
                              newUiPrefs.printMarginColumn().getGlobalValue());
      
         // show invisibles
         showInvisibles().setGlobalValue(
                              newUiPrefs.showInvisibles().getGlobalValue());
         
         // show indent guides
         showIndentGuides().setGlobalValue(
                              newUiPrefs.showIndentGuides().getGlobalValue());
         
         // use vim mode
         useVimMode().setGlobalValue(
                              newUiPrefs.useVimMode().getGlobalValue());
         
         continueCommentsOnNewline().setGlobalValue(
                              newUiPrefs.continueCommentsOnNewline().getGlobalValue());
         
         // insert matching
         insertMatching().setGlobalValue(
                                 newUiPrefs.insertMatching().getGlobalValue());
              
         codeComplete().setGlobalValue(
                                 newUiPrefs.codeComplete().getGlobalValue());
         
         codeCompleteOther().setGlobalValue(
               newUiPrefs.codeCompleteOther().getGlobalValue());
         
         alwaysCompleteInConsole().setGlobalValue(
                                 newUiPrefs.alwaysCompleteInConsole().getGlobalValue());
         
         alwaysCompleteDelayMs().setGlobalValue(
                                 newUiPrefs.alwaysCompleteDelayMs().getGlobalValue());
         
         alwaysCompleteCharacters().setGlobalValue(
                                 newUiPrefs.alwaysCompleteCharacters().getGlobalValue());
         
         insertParensAfterFunctionCompletion().setGlobalValue(
                                 newUiPrefs.insertParensAfterFunctionCompletion().getGlobalValue());
         
         allowTabMultilineCompletion().setGlobalValue(
                                 newUiPrefs.allowTabMultilineCompletion().getGlobalValue());
         
         enableSnippets().setGlobalValue(
                                 newUiPrefs.enableSnippets().getGlobalValue());
         
         insertSpacesAroundEquals().setGlobalValue(
                                 newUiPrefs.insertSpacesAroundEquals().getGlobalValue());
         
         showSignatureTooltips().setGlobalValue(
                                 newUiPrefs.showSignatureTooltips().getGlobalValue());
         
         
         /* Diagnostics */
         
         // Enable Diagnostics
         
         showDiagnosticsR().setGlobalValue(
               newUiPrefs.showDiagnosticsR().getGlobalValue());
         
         showDiagnosticsCpp().setGlobalValue(
               newUiPrefs.showDiagnosticsCpp().getGlobalValue());
         
         showDiagnosticsOther().setGlobalValue(
               newUiPrefs.showDiagnosticsOther().getGlobalValue());
         
         // Background Linting
         
         diagnosticsOnSave().setGlobalValue(
               newUiPrefs.diagnosticsOnSave().getGlobalValue());
         
         enableBackgroundDiagnostics().setGlobalValue(
               newUiPrefs.enableBackgroundDiagnostics().getGlobalValue());
         
         backgroundDiagnosticsDelayMs().setGlobalValue(
               newUiPrefs.backgroundDiagnosticsDelayMs().getGlobalValue());
         
         // Configure R Linter
         
         enableStyleDiagnostics().setGlobalValue(
               newUiPrefs.enableBackgroundDiagnostics().getGlobalValue());
         
         diagnosticsInRFunctionCalls().setGlobalValue(
               newUiPrefs.diagnosticsInRFunctionCalls().getGlobalValue());
         <commit_msg>fix another mis-synced pref update<commit_after>/*
 * UIPrefs.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.model;

import com.google.inject.Inject;
import com.google.inject.Singleton;

import org.rstudio.core.client.Debug;
import org.rstudio.core.client.js.JsObject;
import org.rstudio.core.client.js.JsUtil;
import org.rstudio.studio.client.application.events.EventBus;
import org.rstudio.studio.client.notebook.CompileNotebookPrefs;
import org.rstudio.studio.client.notebookv2.CompileNotebookv2Prefs;
import org.rstudio.studio.client.server.VoidServerRequestCallback;
import org.rstudio.studio.client.workbench.exportplot.model.ExportPlotOptions;
import org.rstudio.studio.client.workbench.model.Session;
import org.rstudio.studio.client.workbench.prefs.events.UiPrefsChangedEvent;
import org.rstudio.studio.client.workbench.prefs.events.UiPrefsChangedHandler;
import org.rstudio.studio.client.workbench.views.plots.model.SavePlotAsPdfOptions;

@Singleton
public class UIPrefs extends UIPrefsAccessor implements UiPrefsChangedHandler
{
   @Inject
   public UIPrefs(Session session, 
                  EventBus eventBus,
                  PrefsServerOperations server)
   {
      super(session.getSessionInfo().getUiPrefs(),
            session.getSessionInfo().getProjectUIPrefs());
      
      session_ = session;
      server_ = server;
      
      eventBus.addHandler(UiPrefsChangedEvent.TYPE, this);
   }
   
   public void writeUIPrefs()
   {
      server_.setUiPrefs(
         session_.getSessionInfo().getUiPrefs(),
         new VoidServerRequestCallback());
   }
   
   @Override
   public void onUiPrefsChanged(UiPrefsChangedEvent e)
   {        
      if (e.getType().equals(UiPrefsChangedEvent.GLOBAL_TYPE))
      {
         // get prefs accessor
         UIPrefsAccessor newUiPrefs = new UIPrefsAccessor(
                                                   e.getUIPrefs(), 
                                                   JsObject.createJsObject());
         
         // show line numbers
         showLineNumbers().setGlobalValue(
                                 newUiPrefs.showLineNumbers().getGlobalValue());
         
         // highlight selected word
         highlightSelectedWord().setGlobalValue(
                           newUiPrefs.highlightSelectedWord().getGlobalValue());
         
         // highlight selected line
         highlightSelectedLine().setGlobalValue(
                          newUiPrefs.highlightSelectedLine().getGlobalValue());
       
         // pane config
         if (!newUiPrefs.paneConfig().getGlobalValue().isEqualTo(
                                 paneConfig().getGlobalValue()))
         {
            paneConfig().setGlobalValue(
                              newUiPrefs.paneConfig().getGlobalValue());
         }
         
         // use spaces for tab
         useSpacesForTab().setGlobalValue(
                          newUiPrefs.useSpacesForTab().getGlobalValue());
           
         // num spacers for tab
         numSpacesForTab().setGlobalValue(
               newUiPrefs.numSpacesForTab().getGlobalValue());
   
         // blinking cursor
         blinkingCursor().setGlobalValue(
               newUiPrefs.blinkingCursor().getGlobalValue());
         
         // show margin
         showMargin().setGlobalValue(
                                 newUiPrefs.showMargin().getGlobalValue());
         
         // print margin column
         printMarginColumn().setGlobalValue(
                              newUiPrefs.printMarginColumn().getGlobalValue());
      
         // show invisibles
         showInvisibles().setGlobalValue(
                              newUiPrefs.showInvisibles().getGlobalValue());
         
         // show indent guides
         showIndentGuides().setGlobalValue(
                              newUiPrefs.showIndentGuides().getGlobalValue());
         
         // use vim mode
         useVimMode().setGlobalValue(
                              newUiPrefs.useVimMode().getGlobalValue());
         
         continueCommentsOnNewline().setGlobalValue(
                              newUiPrefs.continueCommentsOnNewline().getGlobalValue());
         
         // insert matching
         insertMatching().setGlobalValue(
                                 newUiPrefs.insertMatching().getGlobalValue());
              
         codeComplete().setGlobalValue(
                                 newUiPrefs.codeComplete().getGlobalValue());
         
         codeCompleteOther().setGlobalValue(
               newUiPrefs.codeCompleteOther().getGlobalValue());
         
         alwaysCompleteInConsole().setGlobalValue(
                                 newUiPrefs.alwaysCompleteInConsole().getGlobalValue());
         
         alwaysCompleteDelayMs().setGlobalValue(
                                 newUiPrefs.alwaysCompleteDelayMs().getGlobalValue());
         
         alwaysCompleteCharacters().setGlobalValue(
                                 newUiPrefs.alwaysCompleteCharacters().getGlobalValue());
         
         insertParensAfterFunctionCompletion().setGlobalValue(
                                 newUiPrefs.insertParensAfterFunctionCompletion().getGlobalValue());
         
         allowTabMultilineCompletion().setGlobalValue(
                                 newUiPrefs.allowTabMultilineCompletion().getGlobalValue());
         
         enableSnippets().setGlobalValue(
                                 newUiPrefs.enableSnippets().getGlobalValue());
         
         insertSpacesAroundEquals().setGlobalValue(
                                 newUiPrefs.insertSpacesAroundEquals().getGlobalValue());
         
         showSignatureTooltips().setGlobalValue(
                                 newUiPrefs.showSignatureTooltips().getGlobalValue());
         
         
         /* Diagnostics */
         
         // Enable Diagnostics
         
         showDiagnosticsR().setGlobalValue(
               newUiPrefs.showDiagnosticsR().getGlobalValue());
         
         showDiagnosticsCpp().setGlobalValue(
               newUiPrefs.showDiagnosticsCpp().getGlobalValue());
         
         showDiagnosticsOther().setGlobalValue(
               newUiPrefs.showDiagnosticsOther().getGlobalValue());
         
         // Background Linting
         
         diagnosticsOnSave().setGlobalValue(
               newUiPrefs.diagnosticsOnSave().getGlobalValue());
         
         enableBackgroundDiagnostics().setGlobalValue(
               newUiPrefs.enableBackgroundDiagnostics().getGlobalValue());
         
         backgroundDiagnosticsDelayMs().setGlobalValue(
               newUiPrefs.backgroundDiagnosticsDelayMs().getGlobalValue());
         
         // Configure R Linter
         
         enableStyleDiagnostics().setGlobalValue(
               newUiPrefs.enableStyleDiagnostics().getGlobalValue());
         
         diagnosticsInRFunctionCalls().setGlobalValue(
               newUiPrefs.diagnosticsInRFunctionCalls().getGlobalValue());
         
{'fraction_non_alphanumeric': 0.08727008071986238, 'fraction_numerical': 0.001455604075691412, 'mean_word_length': 1.9429517133956387, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 34, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5565076', 'n_tokens_mistral': 3754, 'n_tokens_neox': 3708, 'n_words': 536}