module.exports = function(app){
  app.controller("ActiveFilesController", ['$scope','$window', function ($scope, $window) {
    const livewriting = require('livewriting');
    $scope.FileListData = [];
    $scope.isRecording = false;
    $scope.recordingMessage = "Please select a file";
    $scope.recordingButtonMessage = "Record";
    $scope.selectedFile;
    $scope.isSelected = false;
    $scope.isExpanded = false;
    for (file of atom.workspace.getTextEditors()) {
      $scope.FileListData.push({
        name : file.getTitle(),
        checked : false,
        disabled : false,
        editor : file
      });
    }

    atom.workspace.onDidAddPaneItem(function(object){
      $scope.FileListData.push({
        name : object['item'].getTitle(),
        checked : false,
        disabled : $scope.isRecording,
        editor : object['item']
      });
      $scope.$apply();
    })

    atom.workspace.onDidDestroyPaneItem(function(object){
      var name_to_delete = object['item'].getTitle();
      if(name_to_delete == $scope.selectedFile.name){
        if($scope.isRecording)
          $scope.stopRecording();
        else
          $scope.handle_radio_change($scope.selectedFile);
      }
      var count = 0;
      for(file of $scope.FileListData) {
        if(file.name == name_to_delete)
          $scope.FileListData.splice(count,1);
        count++;
      }
      if($scope.FileListData.length == 0)
        $scope.isExpanded = false;
      $scope.$apply();
    })

    $scope.handle_radio_change = function(file_in){
      if($scope.selectedFile == file_in){
        $scope.selectedFile.checked = false;
        $scope.selectedFile = null;
        $scope.isSelected = false;
        $scope.recordingButtonMessage = "Please select a file";
      } else {
        if($scope.selectedFile != null){
            $scope.selectedFile.checked = false;
        }
        $scope.selectedFile = file_in;
        $scope.selectedFile.checked = true;
        $scope.isSelected = true;
        $scope.recordingButtonMessage = "Record " + $scope.selectedFile.name;
      }
    }

    $scope.stopRecording = function(){
      if($window.confirm("Do you wish to save this recording?")){
        $scope.saveJSON();
      }
      for (file in $scope.FileListData)
        $scope.FileListData[file].disabled = false;
      $scope.recordingMessage = "Please select a file";
      $scope.recordingButtonMessage = "Record";
      $scope.selectedFile.checked = false;
      $scope.isRecording = false;
      $scope.isExpanded = false;
      $scope.isSelected = false;
      $scope.selectedFile = null;
    }

    $scope.startRecording = function(){
      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.isRecording = true;
      $scope.recordingMessage = "Recording " + $scope.selectedFile.name;
      $scope.recordingButtonMessage = "Stop recording";
    }

    $scope.saveJSON = function(){
      var File, file_to_create, file_path, directory_to_create, dir_path, date;
      Directory = require('atom').Directory;
      file_path = $scope.selectedFile.editor.getPath();
      dir_path = file_path.substring(0,file_path.lastIndexOf("/"));
      directory_to_create = new Directory(dir_path + "/.lw-recordings");
      if(directory_to_create.exists() == false)
        directory_to_create.create();
      File = require('atom').File;
      file_to_create = new File(directory_to_create.getPath() + "/lw~" +
        $scope.selectedFile.name + "~" + (new Date()).getTime() + ".txt");
      file_to_create.create();
    }

    $scope.dropdown = function(){
      $scope.isExpanded = !$scope.isExpanded;
    }

    $scope.record = function(){
      $scope.isRecording = !$scope.isRecording;
      if($scope.isRecording == false){
        $scope.stopRecording();
      } else {
        $scope.startRecording();
      }
    }

  }]);
};
console.log("active_files_controller.js");

@@ -995,24 +995,55 @@
 getTitle();%0A
+      if($scope.isSelected)%7B%0A  
       if(nam
@@ -1084,32 +1084,34 @@
 .name)%7B%0A        
+  
 if($scope.isReco
@@ -1117,16 +1117,18 @@
 ording)%0A
+  
         
@@ -1149,24 +1149,26 @@
 ecording();%0A
+  
         else
@@ -1174,24 +1174,26 @@
 e%0A          
+  
 $scope.handl
@@ -1229,16 +1229,26 @@
 dFile);%0A
+        %7D%0A
       %7D%0A

Fix error with deleting pane