<commit_before>/**
 * @file QtInterface.ts
 * @copyright 2016-2018 Perforce Software, Inc. and its subsidiaries.
 * Released under LGPL License.
 * License: http://www.tinymce.com/license
 */
import {getJQueryBody, SPTinyMCEInterface, findClosestAnchorNode, findChildAnchorNode} from 'shims/sptinymceinterface';

//////////////////////////////////////////////////////////////////////////
// Utility function to apply css to the editor body
//////////////////////////////////////////////////////////////////////////
const applyCSS = (cssPairs) => {
  const $editorBody = getJQueryBody();
  cssPairs.forEach(([key, value]) => $editorBody.css(key, value));
};

//////////////////////////////////////////////////////////////////////////
// Editor configuration settings
//////////////////////////////////////////////////////////////////////////

// Whether the editor is in readonly mode
let bReadOnly;
// Palette color settings
let textEditColor: string = '', textReadOnlyColor: string = '';
let windowEditColor: string = '', windowReadOnlyColor: string = '';
// Width setting
let widthSetting = -1;

// Applies the current palette
const applyPalette = () => {
  const [textColor, windowColor] = bReadOnly ? [textReadOnlyColor, windowReadOnlyColor] : [textEditColor, windowEditColor];
  if (textColor && windowColor) {
    applyCSS([
      ['color', textColor],
      ['background-color', windowColor]
    ]);
  }
};
// Applies the width and overflow to the editor
const applyWidth = (widthStr, overflowStr) => {
  applyCSS([
    ['width', widthStr],
    ['overflow', overflowStr]
  ]);
};

//////////////////////////////////////////////////////////////////////////
// Editor initial load handlers
//////////////////////////////////////////////////////////////////////////

// Loads the default font settings
const loadDefaultFont = (fontJSON) => {
  const {family, ptSize} = fontJSON;
  applyCSS([
    ['font-family', family],
    ['font-size', `${ptSize}pt`]
  ]);
};
// Loads the palette settings
const loadPalette = (windowEdit, windowReadOnly, textEdit, textReadOnly) => {
  windowEditColor = windowEdit;
  textReadOnlyColor = textReadOnly;
  textEditColor = textEdit;
  windowReadOnlyColor = windowReadOnly;
  applyPalette();
};

//////////////////////////////////////////////////////////////////////////
// Editor configuration change handlers
//////////////////////////////////////////////////////////////////////////

// Applies readonly mode to the editor
const applyReadOnlyMode = (editor) => {
  editor.setMode('readonly');
  editor.settings.object_resizing = false;
  // In setMode, TinyMCE creates a '_clickBlocker' object, that does exactly what you'd expect for anchor tags.
  // Since in the native client, we still want the user to be able to click hyperlinks, we need to unbind this.
  if (editor._clickBlocker) {
    editor._clickBlocker.unbind();
    editor._clickBlocker = null;
  }
};
// Applies edit mode to the editor
const applyEditMode = (editor) => {
  editor.setMode('design');
  editor.settings.object_resizing = true;
};
// Sets the editor to be readonly or edit mode
const setReadOnly = (editor, readOnly) => {
  if (readOnly !== bReadOnly) {
    bReadOnly = readOnly;
    bReadOnly ? applyReadOnlyMode(editor) : applyEditMode(editor);
    applyPalette();
  }
};
// Prevent drag events from being handled natively<commit_msg>Added readonly set to 1 workaround<commit_after>/**
 * @file QtInterface.ts
 * @copyright 2016-2018 Perforce Software, Inc. and its subsidiaries.
 * Released under LGPL License.
 * License: http://www.tinymce.com/license
 */
import {getJQueryBody, SPTinyMCEInterface, findClosestAnchorNode, findChildAnchorNode} from 'shims/sptinymceinterface';

//////////////////////////////////////////////////////////////////////////
// Utility function to apply css to the editor body
//////////////////////////////////////////////////////////////////////////
const applyCSS = (cssPairs) => {
  const $editorBody = getJQueryBody();
  cssPairs.forEach(([key, value]) => $editorBody.css(key, value));
};

//////////////////////////////////////////////////////////////////////////
// Editor configuration settings
//////////////////////////////////////////////////////////////////////////

// Whether the editor is in readonly mode
let bReadOnly;
// Palette color settings
let textEditColor: string = '', textReadOnlyColor: string = '';
let windowEditColor: string = '', windowReadOnlyColor: string = '';
// Width setting
let widthSetting = -1;

// Applies the current palette
const applyPalette = () => {
  const [textColor, windowColor] = bReadOnly ? [textReadOnlyColor, windowReadOnlyColor] : [textEditColor, windowEditColor];
  if (textColor && windowColor) {
    applyCSS([
      ['color', textColor],
      ['background-color', windowColor]
    ]);
  }
};
// Applies the width and overflow to the editor
const applyWidth = (widthStr, overflowStr) => {
  applyCSS([
    ['width', widthStr],
    ['overflow', overflowStr]
  ]);
};

//////////////////////////////////////////////////////////////////////////
// Editor initial load handlers
//////////////////////////////////////////////////////////////////////////

// Loads the default font settings
const loadDefaultFont = (fontJSON) => {
  const {family, ptSize} = fontJSON;
  applyCSS([
    ['font-family', family],
    ['font-size', `${ptSize}pt`]
  ]);
};
// Loads the palette settings
const loadPalette = (windowEdit, windowReadOnly, textEdit, textReadOnly) => {
  windowEditColor = windowEdit;
  textReadOnlyColor = textReadOnly;
  textEditColor = textEdit;
  windowReadOnlyColor = windowReadOnly;
  applyPalette();
};

//////////////////////////////////////////////////////////////////////////
// Editor configuration change handlers
//////////////////////////////////////////////////////////////////////////

// Applies readonly mode to the editor
const applyReadOnlyMode = (editor) => {
  editor.setMode('readonly');
  editor.settings.object_resizing = false;
  // In setMode, TinyMCE creates a '_clickBlocker' object, that does exactly what you'd expect for anchor tags.
  // Since in the native client, we still want the user to be able to click hyperlinks, we need to unbind this.
  if (editor._clickBlocker) {
    editor._clickBlocker.unbind();
    editor._clickBlocker = null;
  }
  editor.readonly = 1;
};
// Applies edit mode to the editor
const applyEditMode = (editor) => {
  editor.setMode('design');
  editor.settings.object_resizing = true;
};
// Sets the editor to be readonly or edit mode
const setReadOnly = (editor, readOnly) => {
  if (readOnly !== bReadOnly) {
    bReadOnly = readOnly;
    bReadOnly ? applyReadOnlyMode(editor) : applyEditMode(editor);
    applyPalette();
  }
};
// Prevent drag events from being handled natively
{'fraction_non_alphanumeric': 0.2753258293838863, 'fraction_numerical': 0.002962085308056872, 'mean_word_length': 1.9854111405835544, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7915', 'n_tokens_mistral': 1676, 'n_tokens_neox': 1671, 'n_words': 508}