Просмотр исходного кода

Optimized File Manager on view mode switch selected item will keep in places

Toby Chui 2 лет назад
Родитель
Сommit
5642922386
1 измененных файлов с 34 добавлено и 6 удалено
  1. 34 6
      web/SystemAO/file_system/file_explorer.html

+ 34 - 6
web/SystemAO/file_system/file_explorer.html

@@ -702,8 +702,16 @@
                                 parentdir = parentdir.join("/");
                                 loadListModeFromDB(function(){
                                     listDirectory(parentdir, function(){
-                                        focusFileObject(focusFilename);
-                                    });
+                                        if (focusFilename != ""){
+                                            //Timeout to give the DOM time to render
+                                            //DO NOT REPLACE THIS WITH listDirectoryAndHighlight
+                                            //Additional delay are required on page load
+                                            setTimeout(function(){
+                                                focusFileObject(focusFilename);
+                                            }, 300);
+                                            
+                                        }
+                                    })
                                 });
                             }
                         }
@@ -1877,7 +1885,7 @@
             function changeViewMode(object){
                 var targetMode = $(object).attr("mode");
                 viewMode = targetMode;
-                listDirectory(currentPath);
+                refreshList(undefined, true);
                 updateViewmodeButtons();
                 setPreference("file_explorer/listmode",targetMode)
             }
@@ -1954,8 +1962,8 @@
             function focusFileObject(targetFileName){
                 $(".fileObject").each(function(){
                     if ($(this).attr("filename") == targetFileName){
-                        $(this).addClass("selected");
                         scrollToFileLocation(this);
+                        $(this).addClass("selected");
                     }
                 });
             }
@@ -2104,7 +2112,7 @@
 
             //=================================== FILE OPERATIONS ========================
 
-            function refreshList(callback){
+            function refreshList(callback = undefined, keepSelectedItems = false){
                 if (searchMode == true){
                     //Refresh the search result
                     if ($("#searchInput").val().length >  0){
@@ -2118,8 +2126,28 @@
                     //Desktop mode only, to prevent focus out when ctrl Up
                     ctrlHold = false;
                 }
+
+                let filenameBackups = [];
+                if (keepSelectedItems){
+                    //Backup all the selected filenames
+                    $(".fileObject.selected").each(function(){
+                        filenameBackups.push($(this).attr("filename"));
+                    });
+                }
+                console.log(filenameBackups);
                 updateCtrlDisplay();
-                listDirectory(currentPath, callback);
+                listDirectory(currentPath, function(){
+                    if (keepSelectedItems){
+                        $(".fileObject").each(function(){
+                            if (filenameBackups.includes($(this).attr("filename"))){
+                                $(this).addClass("selected");
+                            }
+                        });
+                    }
+                    if (callback != undefined){
+                        callback();
+                    }
+                });
             }
 
            function zipFile(){