<commit_before>// Globals
var active_file,
	current_buffer, 
	debugData,
	tree,
	lstor,
	workspace,
	worker,
	HOST,
	SOURCE;
	canvas_size = {
		width: 0,
		height: 0
	};

init_local_storage();

/** document.ready
 *
 */
$(document).ready(function() {
	
	init_ace();
	
	init_canvas();	
	
	init_jquery_ui();

	init_editor_events();

    load_file_tree();

    init_toolbar();

    document.getElementById('file-picker').addEventListener('change', handleFileSelect, false);

});

/** init_local_storage
 * Sets up localStorage (lstor), creating default workspace if none
 * already exists in lstor. Initilizes workspace buffer object from lstor.
 */
function init_local_storage() {

	// abbreviation for window.localStorage
	lstor = window.localStorage;

	// If no workspace is represented in the lstor, create a default:
	if (lstor.getItem("scales_workspace")) {
		// nothing
	} else {
		lstor.setItem("scales_workspace", "[{\"title\":\"default.scala\",\"key\":\"1\",\"contents\":\"this is the contents of the file\",\"language\":\"scala\",\"dirty\":false},{\"title\":\"resource.scala\",\"key\":\"2\",\"contents\":\"/*This is an example of a second file in your project.*/\",\"language\":\"scala\",\"dirty\":false}]");
	}

	// Populate the workspace buffer from the lstor:
	workspace = JSON.parse(lstor.getItem("scales_workspace"));
}

/** load_file_tree
 * Initializes fancy tree element using the urrent workspace object
 * as its JSON source.
 */
function load_file_tree() {

	// Create the fancytree object:
    $('#tree').fancytree({	
		extensions: ["themeroller","edit"],
		source: workspace,
		debugLevel: 0,
		// When a node is activated (clicked/keyboard):
		activate: function(event, data){
			var node = data.node;
			// If this is the first file activated this session:
			if (editor.getReadOnly()) {
				// Enable the ACE editor:		
				editor.setReadOnly(false);
			} else {
				// Else, the user has just switched from another file	
			}
             // Set active_file to the newly activated file:
			active_file = node;	
			// Load document contents into editor:
			editor.setValue(workspace[get_index()].contents);
		}, 
		// Allow file renaming:
		edit: {
			triggerStart: ["f2", "dblclick", "shift+click", "mac+enter"],
			beforeClose: function(event, data){
			// Return false to prevent cancel/save (data.input is available)
			},
			beforeEdit: function(event, data){
			// Return false to prevent edit mode
			},
			close: function(event, data){
			// Editor was removed
			},
			edit: function(event, data){
			// Editor was opened (available as data.input)
			console.log("Edit");
			},
			save: function(event, data){
				// Save data.input.val() or return false to keep editor open
				if (data.input.val().length > 0) {
					workspace[data.node.key-1].title = data.input.val();
					$('#save-changes-button').trigger("click");
				} else {
					return false;
				}
			}
		},
    });

	// Initialize global variable tree to the fancyTree object:
	tree  = $("#tree").fancytree("getTree");
}

/** init_toolbar
 * Creates event listeners for the icons in the toolbar
 */
function init_toolbar() {
	
	// New File (Split button)

	// Blank file	
	$('#new-file-button').click( function() {
		// New file
		file_name = prompt("Enter a name for the file:");
		if (file_name) {
            workspace.push({
                "title": file_name,
                "language": "scala",
                "key": tree.count() +1,
                "contents": "",
                "dirty": false
            });
		}
  
		// Save the workspace to local storage
		$('#save-changes-button').trigger("click");
	
	}); 

	$('#from-disk').click( function() {
		$('#file-picker').click();
	});

	$('#from-gist').click( function() {
		var gistid = prompt("Please enter the Gist ID:", "b0229e0949df3fd3da99");
		open_gist(gistid);
	});


	// Save Changes button
	// Saves the current workspace buffer into the local storage object
	$('#save-changes-button').click( function() {
		lstor.setItem("scales_workspace", JSON.stringify(workspace));
		console.log("clicked.");
		tree.reload();
	});

	// Zoom out button
	// Decreases editor font size
	$('#zoom-out-button').click( function() {
		editor.setOption('fontSize', editor.getOption('fontSize') - 2);
	});

	// Zoom In button
	// Increases editor font size
	$('#zoom-in-button').click( function() {
		editor.setOption('fontSize', editor.getOption('fontSize') + 2);
	});
	// Editor Options button
	// Shows ace's options menu
	$('#editor-options-button').click( function() {
		editor.execCommand("showSettingsMenu");
	});
	// Build & Run button
	// Executes XHR's to dynamically load and run javascript files
	// created by the server.
	$('#build-run-button').click( function() {
		HOST = "/compile";
		// Save the workspace to local storage
		$('save-changes-button').click();

		// Send the source code to the compiler and execute the result:
		var build_request = $.ajax({<commit_msg>Default project = main.scala (one file).<commit_after>// Globals
var active_file,
	current_buffer, 
	debugData,
	tree,
	lstor,
	workspace,
	worker,
	HOST,
	SOURCE;
	canvas_size = {
		width: 0,
		height: 0
	};

init_local_storage();

/** document.ready
 *
 */
$(document).ready(function() {
	
	init_ace();
	
	init_canvas();	
	
	init_jquery_ui();

	init_editor_events();

    load_file_tree();

    init_toolbar();

    document.getElementById('file-picker').addEventListener('change', handleFileSelect, false);

});

/** init_local_storage
 * Sets up localStorage (lstor), creating default workspace if none
 * already exists in lstor. Initilizes workspace buffer object from lstor.
 */
function init_local_storage() {

	// abbreviation for window.localStorage
	lstor = window.localStorage;

	// If no workspace is represented in the lstor, create a default:
	if (lstor.getItem("scales_workspace")) {
		// nothing
	} else {
		lstor.setItem("scales_workspace", "[{\"title\":\"main.scala\",\"key\":\"1\",\"contents\":\"//You must have a main.scala\" ,\"language\":\"scala\",\"dirty\":false}]");
	}

	// Populate the workspace buffer from the lstor:
	workspace = JSON.parse(lstor.getItem("scales_workspace"));
}

/** load_file_tree
 * Initializes fancy tree element using the urrent workspace object
 * as its JSON source.
 */
function load_file_tree() {

	// Create the fancytree object:
    $('#tree').fancytree({	
		extensions: ["themeroller","edit"],
		source: workspace,
		debugLevel: 0,
		// When a node is activated (clicked/keyboard):
		activate: function(event, data){
			var node = data.node;
			// If this is the first file activated this session:
			if (editor.getReadOnly()) {
				// Enable the ACE editor:		
				editor.setReadOnly(false);
			} else {
				// Else, the user has just switched from another file	
			}
             // Set active_file to the newly activated file:
			active_file = node;	
			// Load document contents into editor:
			editor.setValue(workspace[get_index()].contents);
		}, 
		// Allow file renaming:
		edit: {
			triggerStart: ["f2", "dblclick", "shift+click", "mac+enter"],
			beforeClose: function(event, data){
			// Return false to prevent cancel/save (data.input is available)
			},
			beforeEdit: function(event, data){
			// Return false to prevent edit mode
			},
			close: function(event, data){
			// Editor was removed
			},
			edit: function(event, data){
			// Editor was opened (available as data.input)
			console.log("Edit");
			},
			save: function(event, data){
				// Save data.input.val() or return false to keep editor open
				if (data.input.val().length > 0) {
					workspace[data.node.key-1].title = data.input.val();
					$('#save-changes-button').trigger("click");
				} else {
					return false;
				}
			}
		},
    });

	// Initialize global variable tree to the fancyTree object:
	tree  = $("#tree").fancytree("getTree");
}

/** init_toolbar
 * Creates event listeners for the icons in the toolbar
 */
function init_toolbar() {
	
	// New File (Split button)

	// Blank file	
	$('#new-file-button').click( function() {
		// New file
		file_name = prompt("Enter a name for the file:");
		if (file_name) {
            workspace.push({
                "title": file_name,
                "language": "scala",
                "key": tree.count() +1,
                "contents": "",
                "dirty": false
            });
		}
  
		// Save the workspace to local storage
		$('#save-changes-button').trigger("click");
	
	}); 

	$('#from-disk').click( function() {
		$('#file-picker').click();
	});

	$('#from-gist').click( function() {
		var gistid = prompt("Please enter the Gist ID:", "b0229e0949df3fd3da99");
		open_gist(gistid);
	});


	// Save Changes button
	// Saves the current workspace buffer into the local storage object
	$('#save-changes-button').click( function() {
		if (workspace) {
			lstor.setItem("scales_workspace", JSON.stringify(workspace));
		}
		tree.reload();
	});

	// Zoom out button
	// Decreases editor font size
	$('#zoom-out-button').click( function() {
		editor.setOption('fontSize', editor.getOption('fontSize') - 2);
	});

	// Zoom In button
	// Increases editor font size
	$('#zoom-in-button').click( function() {
		editor.setOption('fontSize', editor.getOption('fontSize') + 2);
	});
	// Editor Options button
	// Shows ace's options menu
	$('#editor-options-button').click( function() {
		editor.execCommand("showSettingsMenu");
	});
	// Build & Run button
	// Executes XHR's to dynamically load and run javascript files
	// created by the server.
	$('#build-run-button').click( function() {
		HOST = "/compile";
		// Save the workspace to local storage
		$('save-changes-button').click();

		// Send the source code to the compiler and execute the result:
		var build_request = $.ajax({
{'fraction_non_alphanumeric': 0.16018518518518518, 'fraction_numerical': 0.004629629629629629, 'mean_word_length': 3.2302001740644037, 'pattern_counts': {'":': 25, '<': 3, '<?xml version=': 0, '>': 5, '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': '1518600', 'n_tokens_mistral': 3319, 'n_tokens_neox': 2977, 'n_words': 815}