Pārlūkot izejas kodu

Auto close tab that file is already deleted

Toby Chui 3 gadi atpakaļ
vecāks
revīzija
6abbd94ef9
2 mainītis faili ar 13 papildinājumiem un 0 dzēšanām
  1. 10 0
      web/NotepadA/ace/editor.html
  2. 3 0
      web/NotepadA/index.html

+ 10 - 0
web/NotepadA/ace/editor.html

@@ -42,6 +42,7 @@
 	var lastSave = "";
 	var fontsize = 12;
 	var theme = "github";
+	var tabid = "";
 	var editor = undefined;
 
 	window.onhashchange = function(e){
@@ -58,11 +59,19 @@
 		filename = basename;
 		fontsize = payload.fontsize;
 		theme = payload.theme;
+		tabid = payload.tabid;
 
 		console.log("NotepadA editor loaded: ", payload);
 
 		//Load the content of the file
 		$.get("../../media?file=" + filepath, function(fileContent){
+				if (fileContent.error !== undefined){
+					//Failed to get file
+					setTimeout(function(){
+						parent.removeTab(tabid);
+					},300);
+					return
+				}
 				$("#editor").text(fileContent);
 
 				//Start the editor if not started
@@ -145,6 +154,7 @@
 				console.log("%c[NotepadA] " + filename + " -> Saved!","color:#1265ea");
 				lastSave = code;
 			}else{
+				alert(data.error);
 				console.log(data);
 			}
 		})

+ 3 - 0
web/NotepadA/index.html

@@ -419,6 +419,7 @@ function newEditor(filepath){
     }
 	let tabid = Math.round((new Date()).getTime());
 	let payload = {
+		"tabid": tabid,
 		"theme": theme,
 		"filename": filepath,
 		"fontsize": fontsize,
@@ -453,6 +454,7 @@ function newTab(){
 					loading... <div class="closeBtn">⨯</div>\
 					</div>';
 			let payload = {
+				"tabid": tabid,
 				"theme": theme,
 				"filename": data,
 				"fontsize": fontsize,
@@ -786,6 +788,7 @@ function reloadTab(tabID){
 	var filename = $(object).attr("filename");
 	var codeAreaID = $(object).attr("framematch");
 	let payload = {
+		"tabid": tabID,
 		"theme": theme,
 		"filename": filename,
 		"fontsize": fontsize,