<commit_before>$(window).load( function () {
  global.window = window;
  global.$ = $;
  global.gui = require('nw.gui');

  Mousetrap.bind( 'mod+d', function () { global.gui.Window.get().showDevTools(); return false; } );
  Mousetrap.bind( 'mod+o', function () { $('#openFile').click(); return false; } );
  Mousetrap.bind( 'mod+s', function () { saveFile(); return false; } );
  //Mousetrap.bind( 'mod+q', function () { global.gui.Window.get().close(); return false; } );
  Mousetrap.bind( 'mod+q', function () { saveSafeClose(); return false; } );
  Mousetrap.bind( 'pagedown', function () { $('#nextPage').click(); return false; } );
  Mousetrap.bind( 'pageup', function () { $('#prevPage').click(); return false; } );

  //Mousetrap.bind( 'mod+g', function () { $('#xpg image').toggleClass('gammafilter'); return false; } );

  /// Confirm that changes will be saved on exit ///
  function saveSafeClose() {
    //alert( 'window closing ...' );
    if ( typeof global.pageCanvas !== 'undefined' && global.pageCanvas.hasChanged() )
      if ( confirm('WARNING: Modifications will be saved on exit! Select Cancel to discard them.') )
        $('#saveFile').click();
    global.gui.Window.get().close();
  }
  global.gui.Window.get().on( 'close', saveSafeClose ); // @todo Bug: not working?

  /// Create OSX menubar ///
  var gui = require('nw.gui');
  if ( process.platform === "darwin" ) {
    var mb = new global.gui.Menu( { type: 'menubar' } );
    mb.createMacBuiltin( global.gui.App.manifest.window.title, {} );
    global.gui.Window.get().menu = mb;
  }

  //global.gui.Window.get().maximize();

  /// Resize container when window size changes ///
  var container = $('#container');
  function setHeight() {
    container.css( 'height', $(window).innerHeight() );
    //$.stylesheet('#xpg_styles { #container }').css( 'height', $(document).innerHeight() ); // Doesn't work with <!DOCTYPE html>, why?
  }
  setHeight();
  $(window).resize(setHeight);
  window.setTimeout( function () { global.pageCanvas.fitPage(); }, 200 );

  /// Make controls resizable ///
  $('#controls').click( function () { window.setTimeout( function () { $('html').css('cursor',''); }, 50 ); } ); // interact.js resize cursor bug
  interact('#controls')
    .resizable( { edges: { left: false, right: false, bottom: false, top: true } } )
    .on( 'resizemove', function ( event ) {
        var controlsHeight = event.rect.height/$(window).innerHeight();
        $.stylesheet('#xpg_styles { #controls }').css( 'height', (100*controlsHeight)+'%' );
        $.stylesheet('#xpg_styles { #xpg }').css( 'height', (100*(1-controlsHeight))+'%' );
        //$('#controls').css( 'height', (100*controlsHeight)+'%' );
        //$('#xpg').css( 'height', (100*(1-controlsHeight))+'%' );
        global.pageCanvas.adjustViewBox();
      } );

  /// Create PageCanvas instance ///
  global.pageCanvas = new global.PageCanvas( 'xpg',
    { handleHref: '../css/handle.svg#bullseye',
      stylesId: 'xpg_styles',
      textareaId: 'xpg_textedit',
      page2svgHref: '../xslt/page2svg.xslt',
      svg2pageHref: '../xslt/svg2page.xslt',
      sortattrHref: '../xslt/sortattr.xslt',
      onError: function ( err ) { alert(err.message+"\n"+err.stack); throw err; },
      onFirstChange: function () { $('#saveFile').prop( 'disabled', false ); },
      onUnload: function () { $('#saveFile').prop( 'disabled', true ); $('#stateInfo span').text('-'); },
      onSelect: function ( elem ) {
          //var g = $(elem).closest('g');
          var
          g = $(elem).closest('g'),
          text = g.find('> text');
          $('#selectedType').text(g.attr('class').replace(/ .*/,''));
          $('#selectedId').text(g.attr('id'));
          if ( text.length !== 0 ) {
            text = global.pageCanvas.cfg.textFormatter(text.html());
            $('#xpg_textedit').val(text);
          }
          $('.selectedParentLine').removeClass('selectedParentLine');
          $('.selectedParentRegion').removeClass('selectedParentRegion');
          g.parents('.TextLine').addClass('selectedParentLine');
          g.parents('.TextRegion').addClass('selectedParentRegion');
        },
      onUnselect: function () {
          $('#selectedType').text('-');
          $('#selectedId').text('-');
          $('#xpg_textedit').val('');
          //$('.selectedParentLine').removeClass('selectedParentLine');
          //$('.selectedParentRegion').removeClass('selectedParentRegion');
        },
      onClone: function ( clone ) {
          clone
            .find('.selectedParentLine, .selectedParentRegion')
            .removeClass('selectedParentLine selectedParentRegion');
        },
      delConfirm: function ( elem ) {
          var
          id = $(elem).attr('id'),
          type = $(elem).attr('class').replace(/ .*/,'');
          return confirm('WARNING: You are about to remove '+type+' with id '+id+'. Continue?');
        },
      onValidText: function () { $('#xpg_textedit').css('background-color',''); },
      onInvalidText: function () { $('#xpg_textedit').css('background-color','red'); },
      onInvalidTextUnselect: function ( err ) { alert('Invalid XML text: '+err.message); }
    } );

  /// Setup page number navigation ///
  $('#pageNum').keyup( function ( event ) { if ( event.keyCode == 13 ) loadFile(); } );
  $('#prevPage').click( function () { changePage(-1); } );
  $('#nextPage').click( function () { changePage(1); } );
  function changePage( offset ) {
    if ( global.pageCanvas.hasChanged() )
      if ( confirm('WARNING: Modifications will be saved on page change! Select Cancel to discard them.') )
        $('#saveFile').click();
    var fileNum = parseInt($('#pageNum').val()) + offset;
    if ( isNaN(fileNum) )
      fileNum = 1;
    else if ( fileNum <= 0 )
      fileNum = fileList.length + fileNum ;<commit_msg>added drag and drop support to svn-canvas<commit_after>$(window).load( function () {
  global.window = window;
  global.$ = $;
  global.gui = require('nw.gui');

  Mousetrap.bind( 'mod+d', function () { global.gui.Window.get().showDevTools(); return false; } );
  Mousetrap.bind( 'mod+o', function () { $('#openFile').click(); return false; } );
  Mousetrap.bind( 'mod+s', function () { saveFile(); return false; } );
  //Mousetrap.bind( 'mod+q', function () { global.gui.Window.get().close(); return false; } );
  Mousetrap.bind( 'mod+q', function () { saveSafeClose(); return false; } );
  Mousetrap.bind( 'pagedown', function () { $('#nextPage').click(); return false; } );
  Mousetrap.bind( 'pageup', function () { $('#prevPage').click(); return false; } );

  //Mousetrap.bind( 'mod+g', function () { $('#xpg image').toggleClass('gammafilter'); return false; } );

  /// Confirm that changes will be saved on exit ///
  function saveSafeClose() {
    //alert( 'window closing ...' );
    if ( typeof global.pageCanvas !== 'undefined' && global.pageCanvas.hasChanged() )
      if ( confirm('WARNING: Modifications will be saved on exit! Select Cancel to discard them.') )
        $('#saveFile').click();
    global.gui.Window.get().close();
  }
  global.gui.Window.get().on( 'close', saveSafeClose ); // @todo Bug: not working?

  /// Create OSX menubar ///
  var gui = require('nw.gui');
  if ( process.platform === "darwin" ) {
    var mb = new global.gui.Menu( { type: 'menubar' } );
    mb.createMacBuiltin( global.gui.App.manifest.window.title, {} );
    global.gui.Window.get().menu = mb;
  }

  //global.gui.Window.get().maximize();

  /// Resize container when window size changes ///
  var container = $('#container');
  function setHeight() {
    container.css( 'height', $(window).innerHeight() );
    //$.stylesheet('#xpg_styles { #container }').css( 'height', $(document).innerHeight() ); // Doesn't work with <!DOCTYPE html>, why?
  }
  setHeight();
  $(window).resize(setHeight);
  window.setTimeout( function () { global.pageCanvas.fitPage(); }, 200 );

  /// Make controls resizable ///
  $('#controls').click( function () { window.setTimeout( function () { $('html').css('cursor',''); }, 50 ); } ); // interact.js resize cursor bug
  interact('#controls')
    .resizable( { edges: { left: false, right: false, bottom: false, top: true } } )
    .on( 'resizemove', function ( event ) {
        var controlsHeight = event.rect.height/$(window).innerHeight();
        $.stylesheet('#xpg_styles { #controls }').css( 'height', (100*controlsHeight)+'%' );
        $.stylesheet('#xpg_styles { #xpg }').css( 'height', (100*(1-controlsHeight))+'%' );
        //$('#controls').css( 'height', (100*controlsHeight)+'%' );
        //$('#xpg').css( 'height', (100*(1-controlsHeight))+'%' );
        global.pageCanvas.adjustViewBox();
      } );

  /// Create PageCanvas instance ///
  global.pageCanvas = new global.PageCanvas( 'xpg',
    { handleHref: '../css/handle.svg#bullseye',
      stylesId: 'xpg_styles',
      textareaId: 'xpg_textedit',
      page2svgHref: '../xslt/page2svg.xslt',
      svg2pageHref: '../xslt/svg2page.xslt',
      sortattrHref: '../xslt/sortattr.xslt',
      onError: function ( err ) { alert(err.message+"\n"+err.stack); throw err; },
      onFirstChange: function () { $('#saveFile').prop( 'disabled', false ); },
      onUnload: function () { $('#saveFile').prop( 'disabled', true ); $('#stateInfo span').text('-'); },
      onSelect: function ( elem ) {
          //var g = $(elem).closest('g');
          var
          g = $(elem).closest('g'),
          text = g.find('> text');
          $('#selectedType').text(g.attr('class').replace(/ .*/,''));
          $('#selectedId').text(g.attr('id'));
          if ( text.length !== 0 ) {
            text = global.pageCanvas.cfg.textFormatter(text.html());
            $('#xpg_textedit').val(text);
          }
          $('.selected-parent-line').removeClass('selected-parent-line');
          $('.selected-parent-region').removeClass('selected-parent-region');
          g.parents('.TextLine').addClass('selected-parent-line');
          g.parents('.TextRegion').addClass('selected-parent-region');
        },
      onUnselect: function () {
          $('#selectedType').text('-');
          $('#selectedId').text('-');
          $('#xpg_textedit').val('');
          //$('.selected-parent-line').removeClass('selected-parent-line');
          //$('.selected-parent-region').removeClass('selected-parent-region');
        },
      onClone: function ( clone ) {
          clone
            .find('.selected-parent-line, .selected-parent-region')
            .removeClass('selected-parent-line selected-parent-region');
        },
      delConfirm: function ( elem ) {
          var
          id = $(elem).attr('id'),
          type = $(elem).attr('class').replace(/ .*/,'');
          return confirm('WARNING: You are about to remove '+type+' with id '+id+'. Continue?');
        },
      onValidText: function () { $('#xpg_textedit').css('background-color',''); },
      onInvalidText: function () { $('#xpg_textedit').css('background-color','red'); },
      onInvalidTextUnselect: function ( err ) { alert('Invalid XML text: '+err.message); }
    } );

  /// Setup page number navigation ///
  $('#pageNum').keyup( function ( event ) { if ( event.keyCode == 13 ) loadFile(); } );
  $('#prevPage').click( function () { changePage(-1); } );
  $('#nextPage').click( function () { changePage(1); } );
  function changePage( offset ) {
    if ( global.pageCanvas.hasChanged() )
      if ( confirm('WARNING: Modifications will be saved on page change! Select Cancel to discard them.') )
        $('#saveFile').click();
    var fileNum = parseInt($('#pageNum').val()) + offset;
    if ( isNaN(fileNum) )
      fileNum = 1;
    else if ( fileNum <= 0 )
      fileNum = fileList.length + fileNum ;
{'fraction_non_alphanumeric': 0.21167321825329002, 'fraction_numerical': 0.00512732866176722, 'mean_word_length': 3.0494809688581315, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2294765', 'n_tokens_mistral': 3568, 'n_tokens_neox': 3513, 'n_words': 718}