module.exports = function(app){
  app.controller("ActiveFilesController", ['$scope', function ($scope) {
    const livewriting = require('livewriting');
    $scope.FileListData = [];

    // Creates initial list of active editors
    for (file of atom.workspace.getTextEditors()) {
      $scope.FileListData.push({
        name : file.getTitle(),
        checked : false,
        disabled : false,
        editor : file
      });
    }

    // Updates list of active text editors if a new file is opened
    atom.workspace.onDidAddPaneItem(function(object){
      $scope.FileListData.push({
        name : object['item'].getTitle(),
        checked : false,
        disabled : false,
        editor : object['item']
      });
      $scope.$apply();
    })

    // Updates list of active text editors if a file is closed
    atom.workspace.onDidDestroyPaneItem(function(object){
      var name_to_delete = object['item'].getTitle();
      var count = 0;
      for(file of $scope.FileListData) {
        if(file.name == name_to_delete){
          if(file.name == $scope.selectedFile.name){ // Added if the window with the editor
            $scope.record_radio(); // being recorded is closed
          }
          $scope.FileListData.splice(count,1);
        }
        count++;
      }
      $scope.$apply();
    })

    // Creates variables for state of recording
    $scope.isRecording = false;
    $scope.recordingMessage = "Please select a file";
    $scope.recordingButtonMessage = "Record";
    // For use when only recording one file at a time
    $scope.selectedFile;
    $scope.isSelected = false;
    $scope.isExpanded = false;

    // Used when using a radio button and only recording one file at a time
    $scope.handle_radio_change = function(file_in){
      if($scope.selectedFile != null){
          $scope.selectedFile.checked = false;
      }
      $scope.selectedFile = file_in;
      $scope.selectedFile.checked = true;
      $scope.isSelected = true;
    }

    // Dropdown button that opens a list of files that are open in the editor
    $scope.dropdown = function(){
      $scope.isExpanded = !$scope.isExpanded;
    }

    // Recording function for when one file is being recorded and radio button is being used
    // Contained withing the dropdown menu of files
    $scope.record_radio = function(){
      $scope.isRecording = !$scope.isRecording;
      if($scope.isRecording == false){
        for (file in $scope.FileListData) {
          $scope.FileListData[file].disabled = false;
        }
        // Call pause function on livewriting for selectedFile -- NEED TO ADD WHEN I LEARN HOW TO
        $scope.isExpanded = true;
        $scope.recordingMessage = "Please select a file";
        $scope.recordingButtonMessage = "Record";
        $scope.selectedFile.checked = false;
        $scope.isSelected = false;
        $scope.selectedFile = null;
      } else {
        for (file in $scope.FileListData) {
          $scope.FileListData[file].disabled = true;
        }
        if($scope.selectedFile.editor.livewriting == null){
          $scope.selectedFile.editor.livewriting = livewriting;
          // MAKE LIVEWRITING MAIN FUNCTION COMMAND -- NEED TO ADD WHEN I LEARN HOW TO
        }
        $scope.isExpanded = false;
        $scope.recordingMessage = "Recording " + $scope.selectedFile.name;
        $scope.recordingButtonMessage = "Stop recording";
      }
    }

    // Recording function for when multiple files are being recorded and checkbox is being used
    $scope.record_checkbox = function(){
      $scope.isRecording = !$scope.isRecording;
      if($scope.isRecording){
        $scope.recordingMessage = "Recording now...";
      } else {
        $scope.recordingMessage = "";
      }
      for (file in $scope.FileListData) {
        if($scope.isRecording == true){
          $scope.FileListData[file].disabled = true;
        } else {
          $scope.FileListData[file].disabled = false;
          if($scope.FileListData[file].checked){
            if($scope.FileListData[file].editor.livewriting == null){
              $scope.FileListData[file].editor.livewriting = livewriting;
            }
          } else {
            if($scope.FileListData[file].editor.livewriting != null){
            }
          }
        }
      }
    }
  }]);
};
console.log("active_files_controller.js");

@@ -1758,16 +1758,191 @@
 le_in)%7B%0A
+      if($scope.selectedFile == file_in)%7B%0A        $scope.selectedFile.checked = false;%0A        $scope.selectedFile = null;%0A        $scope.isSelected = false;%0A      %7D else %7B%0A  
       if
@@ -1964,32 +1964,34 @@
 dFile != null)%7B%0A
+  
           $scope
@@ -2017,24 +2017,26 @@
 ed = false;%0A
+  
       %7D%0A    
@@ -2033,24 +2033,26 @@
     %7D%0A      
+  
 $scope.selec
@@ -2070,16 +2070,18 @@
 ile_in;%0A
+  
       $s
@@ -2116,24 +2116,26 @@
 true;%0A      
+  
 $scope.isSel
@@ -2144,24 +2144,110 @@
 ted = true;%0A
+        $scope.recordingButtonMessage = %22Record %22 + $scope.selectedFile.name;%0A      %7D%0A
     %7D%0A%0A    /

Active files update