<commit_before>package org.openmole.gui.client.core.files

import org.openmole.gui.ext.data._
import org.openmole.gui.ext.data.FileExtension._

import scala.scalajs.js
import scalatags.JsDom.all._
import scalatags.JsDom.tags

import scaladget.ace._
import scaladget.bootstrapnative.bsn._
import scaladget.tools._
import org.openmole.gui.ext.data.DataUtils._

import scala.scalajs.js.JSConverters._
import org.openmole.gui.ext.client._
import org.scalajs.dom.raw.Event
import scaladget.bootstrapnative.Popup
import scaladget.bootstrapnative.Popup.{ Manual, PopupPosition }
import rx._

/*
 * Copyright (C) 07/04/15 // <EMAIL>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

object EditorPanelUI {

  def apply(
    treeNodeTabs:         TreeNodeTabs,
    safePath:             SafePath,
    fileType:             FileExtension,
    initCode:             String,
    initHash:             String,
    containerModifierSeq: ModifierSeq   = emptyMod) = {
    val editor = {
      fileType match {
        case OMS   ⇒ new EditorPanelUI(treeNodeTabs, safePath, OMS, containerModifierSeq)
        case SCALA ⇒ new EditorPanelUI(treeNodeTabs, safePath, SCALA, containerModifierSeq)
        case _     ⇒ new EditorPanelUI(treeNodeTabs, safePath, NO_EXTENSION, containerModifierSeq)
      }
    }
    editor.setCode(initCode, initHash)
    editor
  }

  def highlightedFile(ext: FileExtension): Option[HighlightedFile] =
    ext match {
      case OpenMOLEScript  ⇒ Some(HighlightedFile("openmole"))
      case e: EditableFile ⇒ Some(HighlightedFile(e.highlighter))
      case _               ⇒ None
    }

  case class HighlightedFile(highlighter: String)
}

class EditorPanelUI(treeNodeTabs: TreeNodeTabs, safePath: SafePath, fileType: FileExtension, containerModifierSeq: ModifierSeq) {

  implicit val ctx: Ctx.Owner = Ctx.Owner.safe()

  val editor = {
    val edDiv = tags.div(id := "editor").render
    val ed = ace.edit(edDiv)

    js.Dynamic.global.ace.config.set("basePath", "/js")
    js.Dynamic.global.ace.config.set("modePath", "/js")
    js.Dynamic.global.ace.config.set("themePath", "/js")

    ed.setTheme("ace/theme/github")
    ace.require("ace/ext/language_tools")

    EditorPanelUI.highlightedFile(fileType).foreach { h ⇒<commit_msg>[GUI] fix: path of js files<commit_after>package org.openmole.gui.client.core.files

import org.openmole.gui.ext.data._
import org.openmole.gui.ext.data.FileExtension._

import scala.scalajs.js
import scalatags.JsDom.all._
import scalatags.JsDom.tags

import scaladget.ace._
import scaladget.bootstrapnative.bsn._
import scaladget.tools._
import org.openmole.gui.ext.data.DataUtils._

import scala.scalajs.js.JSConverters._
import org.openmole.gui.ext.client._
import org.scalajs.dom.raw.Event
import scaladget.bootstrapnative.Popup
import scaladget.bootstrapnative.Popup.{ Manual, PopupPosition }
import rx._

/*
 * Copyright (C) 07/04/15 // <EMAIL>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

object EditorPanelUI {

  def apply(
    treeNodeTabs:         TreeNodeTabs,
    safePath:             SafePath,
    fileType:             FileExtension,
    initCode:             String,
    initHash:             String,
    containerModifierSeq: ModifierSeq   = emptyMod) = {
    val editor = {
      fileType match {
        case OMS   ⇒ new EditorPanelUI(treeNodeTabs, safePath, OMS, containerModifierSeq)
        case SCALA ⇒ new EditorPanelUI(treeNodeTabs, safePath, SCALA, containerModifierSeq)
        case _     ⇒ new EditorPanelUI(treeNodeTabs, safePath, NO_EXTENSION, containerModifierSeq)
      }
    }
    editor.setCode(initCode, initHash)
    editor
  }

  def highlightedFile(ext: FileExtension): Option[HighlightedFile] =
    ext match {
      case OpenMOLEScript  ⇒ Some(HighlightedFile("openmole"))
      case e: EditableFile ⇒ Some(HighlightedFile(e.highlighter))
      case _               ⇒ None
    }

  case class HighlightedFile(highlighter: String)
}

class EditorPanelUI(treeNodeTabs: TreeNodeTabs, safePath: SafePath, fileType: FileExtension, containerModifierSeq: ModifierSeq) {

  implicit val ctx: Ctx.Owner = Ctx.Owner.safe()

  val editor = {
    val edDiv = tags.div(id := "editor").render
    val ed = ace.edit(edDiv)

    js.Dynamic.global.ace.config.set("basePath", "js")
    js.Dynamic.global.ace.config.set("modePath", "js")
    js.Dynamic.global.ace.config.set("themePath", "js")

    ed.setTheme("ace/theme/github")
    ace.require("ace/ext/language_tools")

    EditorPanelUI.highlightedFile(fileType).foreach { h ⇒
{'fraction_non_alphanumeric': 0.09545375370144574, 'fraction_numerical': 0.002438599547117227, 'mean_word_length': 3.4271395528141864, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '3757328', 'n_tokens_mistral': 1773, 'n_tokens_neox': 1781, 'n_words': 488}