]> granicus.if.org Git - transmission/commitdiff
Use id when handling hotkeys for specific dialogs
authorSven Depondt <sven@b-bright.be>
Fri, 28 Jul 2017 20:32:18 +0000 (22:32 +0200)
committerSven Depondt <sven@b-bright.be>
Fri, 28 Jul 2017 20:32:18 +0000 (22:32 +0200)
Identifying a dialog by it's header title is kinda dirty and now we use
the dialogs id instead. We also check if the dialog is visible before executing
the hotkey action.

web/javascript/dialog.js
web/javascript/transmission.js

index 13baca3dd7386ae6133a4addb86808d9bdf740d5..9e58c9c3e4ea28c204c188a3077353b8d470e177 100644 (file)
@@ -41,6 +41,11 @@ Dialog.prototype = {
      *
      *--------------------------------------------*/
 
+    executeCallback: function () {
+        this._callback();
+        dialog.hideDialog();
+    },
+
     hideDialog: function () {
         $('body.dialog_showing').removeClass('dialog_showing');
         this._container.hide();
@@ -48,14 +53,16 @@ Dialog.prototype = {
         transmission.updateButtonStates();
     },
 
+    isVisible: function () {
+        return this._container.is(':visible');
+    },
+
     onCancelClicked: function (event) {
         event.data.dialog.hideDialog();
     },
 
     onConfirmClicked: function (event) {
-        var dialog = event.data.dialog;
-        dialog._callback();
-        dialog.hideDialog();
+        event.data.dialog.executeCallback();
     },
 
     /*--------------------------------------------
index bf0ea998a73c266e3260cd5e437de1228158c29e..9cc2436baad0c00b192432e87df2133d9e4bab72 100644 (file)
@@ -505,9 +505,7 @@ Transmission.prototype = {
             }
 
             if (o_key || u_key) {
-                $('body').addClass('open_showing');
-                this.uploadTorrentFile();
-                this.updateButtonStates();
+                this.openTorrentClicked(ev);
                 handled = true;
             }
 
@@ -527,36 +525,61 @@ Transmission.prototype = {
             }
         }
 
+        if (slash_key) {
+            this.showHotkeysDialog();
+            handled = true;
+        }
+
         if (enter_key) {
-            // check if remove dialog
-            if ($('.dialog_heading:visible').text().match("Remove") != null) {
-                $("#dialog_confirm_button").click();
+            // handle other dialogs
+            if (dialog && dialog.isVisible()) {
+                dialog.executeCallback();
                 handled = true;
             }
 
-            // check if upload torrent dialog
-            if ($('.dialog_heading:visible').text() == "Upload Torrent Files") {
+            // handle upload dialog
+            if ($('#upload_container').is(':visible')) {
                 this.confirmUploadClicked();
                 handled = true;
             }
 
-            // check if location dialog
-            if ($('.dialog_heading:visible').text() == "Set Location") {
+            // handle move dialog
+            if ($('#move_container').is(':visible')) {
                 this.confirmMoveClicked();
                 handled = true;
             }
-        }
 
-        if (slash_key) {
-            this.showHotkeysDialog();
-            handled = true;
+            // handle rename dialog
+            if ($('#rename_container').is(':visible')) {
+                this.confirmRenameClicked();
+                handled = true;
+            }
         }
 
         if (esc_key) {
-            this.hideMoveDialog();
-            this.hideUploadDialog();
-            dialog.hideDialog();
-            handled = true;
+            // handle other dialogs
+            if (dialog && dialog.isVisible()) {
+                dialog.hideDialog();
+                handled = true;
+            }
+
+            // handle upload dialog
+            if ($('#upload_container').is(':visible')) {
+                this.hideUploadDialog();
+                handled = true;
+            }
+
+            // handle move dialog
+            if ($('#move_container').is(':visible')) {
+                this.hideMoveDialog();
+                handled = true;
+            }
+
+            // handle rename dialog
+            if ($('#rename_container').is(':visible')) {
+                this.hideRenameDialog();
+                handled = true;
+            }
         }
 
         if ((up_key || dn_key) && rows.length) {