Parcourir la source

Fix context menu on trashbin

Toby Chui il y a 7 heures
Parent
commit
a16e8c39b9

+ 6 - 0
src/system/locale/desktop.json

@@ -154,6 +154,7 @@
                 "tray/tasks": "背景任務",
                 "dock/emptyTrash/title": "要清空垃圾箱嗎?",
                 "dock/emptyTrash/text": "垃圾箱中的所有項目將被永久刪除,且無法復原。",
+                "dock/emptyTrash/cancel": "取消",
                 "": ""
             },
             "placeholder": {
@@ -312,6 +313,7 @@
                 "tray/tasks": "背景任務",
                 "dock/emptyTrash/title": "要清空垃圾箱嗎?",
                 "dock/emptyTrash/text": "垃圾箱中的所有項目將被永久刪除,且無法復原。",
+                "dock/emptyTrash/cancel": "取消",
                 "": ""
             },
             "placeholder": {
@@ -470,6 +472,7 @@
                 "tray/tasks": "后台任务",
                 "dock/emptyTrash/title": "要清空回收站吗?",
                 "dock/emptyTrash/text": "回收站中的所有项目将被永久删除,且无法恢复。",
+                "dock/emptyTrash/cancel": "取消",
                 "": ""
             },
             "placeholder": {
@@ -629,6 +632,7 @@
                 "tray/tasks": "Background tasks",
                 "dock/emptyTrash/title": "Empty the trash bin?",
                 "dock/emptyTrash/text": "Everything in the trash bin is deleted permanently. This cannot be undone.",
+                "dock/emptyTrash/cancel": "Cancel",
                 "": ""
             },
             "placeholder": {
@@ -788,6 +792,7 @@
                 "tray/tasks": "バックグラウンドタスク",
                 "dock/emptyTrash/title": "ごみ箱を空にしますか?",
                 "dock/emptyTrash/text": "ごみ箱の項目はすべて完全に削除されます。この操作は元に戻せません。",
+                "dock/emptyTrash/cancel": "キャンセル",
                 "": ""
             },
             "placeholder": {
@@ -947,6 +952,7 @@
                 "tray/tasks": "백그라운드 작업",
                 "dock/emptyTrash/title": "휴지통을 비우시겠습니까?",
                 "dock/emptyTrash/text": "휴지통의 모든 항목이 영구적으로 삭제됩니다. 이 작업은 되돌릴 수 없습니다.",
+                "dock/emptyTrash/cancel": "취소",
                 "": ""
             },
             "placeholder": {

+ 2 - 2
src/web/script/desktop/PROPOSAL.md

@@ -111,8 +111,8 @@ As built in phase 1:
   lift and a name tooltip.
 - **Right click** on a dock icon: its windows, *New Window* (or *Open*),
   *Keep in Dock* / *Remove from Dock*, *Close* / *Close All*; the menu opens
-  above the dock. The trash has *Open* and *Empty Trash Bin* (confirmed in
-  an in-page dialog, greyed out while the trash is empty).
+  above the dock. The trash has *Open* and *Empty Trash Bin* (confirmed inside
+  the trash menu itself, greyed out while the trash is empty).
 - **Tray** (D1), a smaller capsule at the bottom right: background tasks, a
   server icon and the clock (notifications and calendar). The server icon
   opens the quick access panel (section 5): server status, quick settings

+ 19 - 0
src/web/script/desktop/contextmenu.css

@@ -149,6 +149,25 @@
     color: var(--dt-text-muted);
 }
 
+/* A question asked inside the menu (the dock trash: Empty Trash Bin) */
+#contextmenu .menuConfirm {
+    max-width: 260px;
+    padding: 6px 10px 4px 10px;
+    white-space: normal;
+}
+
+#contextmenu .menuConfirmTitle {
+    font-weight: 600;
+    color: var(--dt-text);
+}
+
+#contextmenu .menuConfirmText {
+    margin-top: 3px;
+    font-size: 12px;
+    line-height: 1.45;
+    color: var(--dt-text-muted);
+}
+
 #contextmenu .menuDivider,
 #subcontextmenu .menuDivider {
     height: 1px;

+ 54 - 15
src/web/script/desktop/dock.js

@@ -858,25 +858,47 @@ function dockSetTrashFull(full){
     $("#contextmenu .item.emptyTrash").toggleClass("disabled", !full);
 }
 
-//Delete everything in the trash for good, after the user confirmed it
+//Delete everything in the trash for good (the user confirmed it in the trash menu)
 function dockEmptyTrash(){
-    ssConfirm({
-        title: applocale.getString("dock/emptyTrash/title", "Empty the trash bin?"),
-        text: applocale.getString("dock/emptyTrash/text", "Everything in the trash bin is deleted permanently. This cannot be undone."),
-        confirmLabel: lcontex("Empty Trash Bin"),
-        danger: true
-    }, function(){
-        $.get("system/file_system/clearTrash", function(data){
-            if (data && data.error !== undefined){
-                ssAlert({title: lcontex("Empty Trash Bin"), text: data.error});
-            }
-            dockRefreshTrash();
-        }).fail(function(){
-            dockRefreshTrash();
-        });
+    $.get("system/file_system/clearTrash", function(data){
+        if (data && data.error !== undefined){
+            ssAlert({title: lcontex("Empty Trash Bin"), text: data.error});
+        }
+        dockRefreshTrash();
+    }).fail(function(){
+        dockRefreshTrash();
     });
 }
 
+/*
+    Ask before emptying the trash inside the trash menu itself, instead of a
+    dialog in the middle of the screen: the confirm row opens right where the
+    pointer already is. The menu stays anchored above the trash icon.
+    fromKeyboard puts the keyboard focus on Cancel, the safe choice.
+*/
+var dockEmptyTrashAskedAt = 0;
+function dockShowEmptyTrashConfirm(fromKeyboard){
+    var menu = $("#contextmenu");
+    dockEmptyTrashAskedAt = Date.now();
+    contextMenuHideSub();
+    menu.empty();
+    var ask = $('<div class="menuConfirm"></div>');
+    ask.append($('<div class="menuConfirmTitle"></div>').text(applocale.getString("dock/emptyTrash/title", "Empty the trash bin?")));
+    ask.append($('<div class="menuConfirmText"></div>').text(applocale.getString("dock/emptyTrash/text", "Everything in the trash bin is deleted permanently. This cannot be undone.")));
+    menu.append(ask);
+    addContextMenuSeperator(menu);
+    var cancel = addContextMenuItem(menu, escapeNotificationText(applocale.getString("dock/emptyTrash/cancel", "Cancel")), undefined, "dockMenuCancelEmptyTrash", false);
+    addContextMenuItem(menu, lcontex("Empty Trash Bin"), undefined, "dockMenuConfirmEmptyTrash", false, {
+        danger: true,
+        disabled: !$("#dockTrash").hasClass("full")
+    }).addClass("emptyTrash");
+    contextMenuRefreshLayout(menu);
+    dockPlaceContextMenu($("#dockTrash"));
+    if (fromKeyboard){
+        contextMenuSetHot(cancel[0]);
+    }
+}
+
 /*
     Pick the empty or full trash icon. trashState stops at the first trashed
     item; a server without it (built before the dock) gets asked for the full
@@ -1054,6 +1076,8 @@ function dockMenuPinApp(target, event){
 //Put the open context menu above a dock item, centred on it
 function dockPlaceContextMenu(item){
     var menu = $("#contextmenu");
+    //Measure away from the screen edge: there wrapping text makes the menu taller
+    menu.css({left: 0, top: 0});
     var itemRect = $(item)[0].getBoundingClientRect();
     var dockTop = $("#navimenu")[0].getBoundingClientRect().top;
     var left = itemRect.left + itemRect.width / 2 - menu.outerWidth() / 2;
@@ -1100,10 +1124,25 @@ function dockMenuOpenTrash(target, event){
 }
 
 function dockMenuEmptyTrash(target, event){
+    //A click carries a pointer position, Enter on the row does not
+    var fromKeyboard = event == undefined || event.detail === 0;
+    dockShowEmptyTrashConfirm(fromKeyboard);
+}
+
+function dockMenuConfirmEmptyTrash(target, event){
+    //The confirm row opens under the pointer: the second click of a double
+    //click on Empty Trash Bin must not answer the question
+    if ((event && event.detail > 1) || Date.now() - dockEmptyTrashAskedAt < 400){
+        return;
+    }
     hideAllContextMenus();
     dockEmptyTrash();
 }
 
+function dockMenuCancelEmptyTrash(target, event){
+    hideAllContextMenus();
+}
+
 /*
     Start (called by initDesktop)
 */