Quellcode durchsuchen

Optimized UX for rename on desktop

tobychui vor 3 Jahren
Ursprung
Commit
4f59c27e97
1 geänderte Dateien mit 44 neuen und 20 gelöschten Zeilen
  1. 44 20
      web/desktop.system

+ 44 - 20
web/desktop.system

@@ -1980,8 +1980,12 @@
 
             if (renameMode == true){
                 //Exit rename mode if the target is not on the editing launchIcon
-                console.log(evt.target);
-                if ($(evt.target).is("body") || $(evt.target).attr("id") == "dbg1" || $(evt.target).attr("id") == "dbg2"){
+                //console.log(evt.target);
+                var isBackground = false;
+                if ($(evt.target).attr("id") && $(evt.target).attr("id").length >= 4 &&  $(evt.target).attr("id").substr(0, 3) == "dbg"){
+                    isBackground = true;
+                }
+                if ($(evt.target).is("body") || isBackground){
                     //End rename mode
                     exitRenameMode();
                 }
@@ -4070,7 +4074,6 @@
                 }
                 
             }
-
             hideAllContextMenus();
         
             //Clicked on a launch icon.
@@ -5119,7 +5122,7 @@
                 originalName = filedata.ShortcutName;
             }
             $(object).find(".launchIconText").hide();
-            $(object).append(`<textarea class="renameInput ${desktopIconSize}" type="text" ondragstart="return false;" dblclick="event.stopImmediatePropagation(); event.stopImmediatePropagation();"maxlength="32">${originalName}</textarea>`);
+            $(object).append(`<textarea class="renameInput ${desktopIconSize}" type="text" onkeydown="handleRenameKeydown(event);" ondragstart="return false;" dblclick="event.stopImmediatePropagation(); event.stopImmediatePropagation();"maxlength="32">${originalName}</textarea>`);
             $(object).find(".renameInput")[0].select();
             var index = originalName.lastIndexOf(".");
             console.log(index);
@@ -5138,6 +5141,15 @@
             window.ime.focus = $(object).find(".renameInput")[0];
         }
 
+        //Handle enter keypress on the rename textarea
+        function handleRenameKeydown(e){
+            if (e.keyCode == 13){
+                //Enter pressed
+                e.preventDefault();
+                exitRenameMode();
+            }
+        }
+
         function exitRenameMode() {
             if (renameMode) {
                 $(".launchIcon").attr("draggable", "true");
@@ -5174,6 +5186,16 @@
                         }else{
                             //Normal typed files / folder. Rename the object
                             let currentInputTextArea = $(this);
+
+                            //Check if new filename is identaical to the old filename
+                            var originalFilename = $(this).parent().attr("filename");
+                            console.log("Launch Icon object", $(this).parent());
+
+                            if (newFilename == originalFilename){
+                                //Filename has no changes
+                                currentInputTextArea.remove();
+                                return;
+                            }
                             generateCSRFToken(function(csrftoken){
                                 $.ajax({
                                     url: "./system/file_system/fileOpr",
@@ -5332,24 +5354,26 @@
             let closestGridIndexLocation = closestLocation[1];
 
             //Request backend to generate the new file
-            $.ajax({
-                url: "system/file_system/newItem",
-                data: {type: "file",src: "user:/Desktop/",filename: newfn, csrft: token},
-                success: function(data){
-                    if (data.error !== undefined){
-                        alert(data.error);
-                    }else{
-                        //Set the icon location
-                        setIconDesktopLocation(newfn, closestGridIndexLocation[0], closestGridIndexLocation[1], function(){
-                            //Refresh the desktop
-                            refresh(function(){
-                                var targetNewFile = getObjectFromGridLocation(closestGridIndexLocation[0], closestGridIndexLocation[1]);
-                                console.log("Renaming ", targetNewFile);
-                                enableRenameOnLaunchIconObject(targetNewFile);
+            generateCSRFToken(function(token){
+                $.ajax({
+                    url: "system/file_system/newItem",
+                    data: {type: "file",src: "user:/Desktop/",filename: newfn, csrft: token},
+                    success: function(data){
+                        if (data.error !== undefined){
+                            alert(data.error);
+                        }else{
+                            //Set the icon location
+                            setIconDesktopLocation(newfn, closestGridIndexLocation[0], closestGridIndexLocation[1], function(){
+                                //Refresh the desktop
+                                refresh(function(){
+                                    var targetNewFile = getObjectFromGridLocation(closestGridIndexLocation[0], closestGridIndexLocation[1]);
+                                    console.log("Renaming ", targetNewFile);
+                                    enableRenameOnLaunchIconObject(targetNewFile);
+                                });
                             });
-                        });
+                        }
                     }
-                }
+                });
             });
             hideAllContextMenus();
         }