<commit_before>/*global $,cyberDojo*/

var cyberDojo = (function(cd, $) {
  "use strict";
  
  cd.newFile = function(title) {
    // Append three random chars to the end of the filename.
    // There is no excuse not to rename it!
    cd.newFileContent('newfile_' + cd.random3(), 'Please rename me!');
  };

  //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

  cd.deleteFile = function(title, avatarName) {
    cd.deleteFilePrompt(title, avatarName, true);
  };

  //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

  cd.renameFile = function(title, avatarName) {
    var oldFilename = cd.currentFilename();
    var div = $('<div>', {
      'class': 'panel'
    });
    var input = $('<input>', {
      type: 'text',
      id: 'renamer',
      name: 'renamer',
      value: oldFilename
    });

    div.append(cd.centeredDiv(cd.avatarImage(avatarName, 50)));
    div.append('<div>&nbsp;</div>');
    div.append(cd.centeredDiv(input));
	
    var renamer = $('<div>')
      .html(div)
      .dialog({
		autoOpen: false,
		width: 350,
		title: cd.dialogTitle(title),
		modal: true,
		buttons: [
		  {
			id: 'rename_ok',
			text: 'ok',
			disabled: true,
			click: function() {
			  console.log("CLICKED");
			  var newFilename = $.trim(input.val());
			  cd.renameFileFromTo(avatarName, oldFilename, newFilename);
			  $(this).remove();
		    }
		  },
		  {
			id: 'rename_cancel',
			text: 'cancel',
			click: function() {
			  $(this).remove();
			}
		  }
		]
      });
	
	input.keyup(function(event) {
	  var newFilename = $.trim(input.val());
      var renameOk = $('#rename_ok');
      event.preventDefault();
	  if (cd.isValidFilename(newFilename))  {
        renameOk.button('enable');
		if (event.keyCode === $.ui.keyCode.ENTER) {
		 cd.renameFileFromTo(avatarName, oldFilename, newFilename);		
		 renamer.remove();
		}  		
	  } else {
        renameOk.button('disable');
	  }
    });
		
    renamer.dialog('open');
    var end = oldFilename.lastIndexOf('.');
    if (end === -1) {
      end = oldFilename.length;
    }
    input[0].setSelectionRange(0, end);
  };
  
  //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

  cd.newFileContent = function(filename, content) {
	var newFile = cd.makeNewFile(filename, content);
    $('#visible_files_container').append(newFile);
    cd.bindLineNumbers(filename);      
    cd.rebuildFilenameList();
    cd.loadFile(filename);
  };

  //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

  cd.deleteFilePrompt = function(title, avatarName, ask) {
    var filename = cd.currentFilename();
    var div = $(cd.divPanel(''));
    div.append(cd.centeredDiv(cd.avatarImage(avatarName, 50)));
    div.append('<div>&nbsp;</div>');
    div.append(cd.centeredDiv(cd.fakeFilenameButton(filename)));
    if (ask) {
      var deleter = $('<div>')
		.html(div)
		.dialog({
		  autoOpen: false,
		  width: 350,
		  title: cd.dialogTitle(title),
		  modal: true,
		  buttons: {
			ok: function() {
			  cd.doDelete(filename);
			  $(this).dialog('close');
			},
			cancel: function() {
			  $(this).dialog('close');
			}
		  }
		});    
      deleter.dialog('open');
    }
	else {
      cd.doDelete(filename);
    }
  };

  //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

  cd.doDelete = function(filename) {
	var i, filenames, notBoring;
    cd.fileDiv(filename).remove();    
    filenames = cd.rebuildFilenameList();
    // cyber-dojo.sh & output cannot be deleted so
    // there is always at least one file. But
	// they are boring files, and so is instructions
	// so try to avoid those three...
	for (i = 0; i < filenames.length; i++) {<commit_msg>removed avatar image from delete-file/rename-file dialogs<commit_after>/*global $,cyberDojo*/

var cyberDojo = (function(cd, $) {
  "use strict";
  
  cd.newFile = function(title) {
    // Append three random chars to the end of the filename.
    // There is no excuse not to rename it!
    cd.newFileContent('newfile_' + cd.random3(), 'Please rename me!');
  };

  //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

  cd.deleteFile = function(title, avatarName) {
    cd.deleteFilePrompt(title, avatarName, true);
  };

  //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

  cd.renameFile = function(title, avatarName) {
    var oldFilename = cd.currentFilename();
    var div = $('<div>', {
      'class': 'panel'
    });
    var input = $('<input>', {
      type: 'text',
      id: 'renamer',
      name: 'renamer',
      value: oldFilename
    });

    div.append(cd.centeredDiv(input));
	
    var renamer = $('<div>')
      .html(div)
      .dialog({
		autoOpen: false,
		width: 350,
		title: cd.dialogTitle(title),
		modal: true,
		buttons: [
		  {
			id: 'rename_ok',
			text: 'ok',
			disabled: true,
			click: function() {
			  console.log("CLICKED");
			  var newFilename = $.trim(input.val());
			  cd.renameFileFromTo(avatarName, oldFilename, newFilename);
			  $(this).remove();
		    }
		  },
		  {
			id: 'rename_cancel',
			text: 'cancel',
			click: function() {
			  $(this).remove();
			}
		  }
		]
      });
	
	input.keyup(function(event) {
	  var newFilename = $.trim(input.val());
      var renameOk = $('#rename_ok');
      event.preventDefault();
	  if (cd.isValidFilename(newFilename))  {
        renameOk.button('enable');
		if (event.keyCode === $.ui.keyCode.ENTER) {
		 cd.renameFileFromTo(avatarName, oldFilename, newFilename);		
		 renamer.remove();
		}  		
	  } else {
        renameOk.button('disable');
	  }
    });
		
    renamer.dialog('open');
    var end = oldFilename.lastIndexOf('.');
    if (end === -1) {
      end = oldFilename.length;
    }
    input[0].setSelectionRange(0, end);
  };
  
  //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

  cd.newFileContent = function(filename, content) {
	var newFile = cd.makeNewFile(filename, content);
    $('#visible_files_container').append(newFile);
    cd.bindLineNumbers(filename);      
    cd.rebuildFilenameList();
    cd.loadFile(filename);
  };

  //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

  cd.deleteFilePrompt = function(title, avatarName, ask) {
    var filename = cd.currentFilename();
    var div = $(cd.divPanel(''));
    div.append(cd.centeredDiv(cd.fakeFilenameButton(filename)));
    if (ask) {
      var deleter = $('<div>')
		.html(div)
		.dialog({
		  autoOpen: false,
		  width: 350,
		  title: cd.dialogTitle(title),
		  modal: true,
		  buttons: {
			ok: function() {
			  cd.doDelete(filename);
			  $(this).remove();
			},
			cancel: function() {
			  $(this).remove();
			}
		  }
		});    
      deleter.dialog('open');
    }
	else {
      cd.doDelete(filename);
    }
  };

  //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

  cd.doDelete = function(filename) {
	var i, filenames, notBoring;
    cd.fileDiv(filename).remove();    
    filenames = cd.rebuildFilenameList();
    // cyber-dojo.sh & output cannot be deleted so
    // there is always at least one file. But
	// they are boring files, and so is instructions
	// so try to avoid those three...
	for (i = 0; i < filenames.length; i++) {
{'fraction_non_alphanumeric': 0.19840604026845637, 'fraction_numerical': 0.003635346756152125, 'mean_word_length': 1.9866388308977037, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 40, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3869686', 'n_tokens_mistral': 2750, 'n_tokens_neox': 2516, 'n_words': 453}