ソースを参照

[home2] Right-clicking a non-selected entry will select it first

Johan Ahlen 9 年 前
コミット
22fa10c

+ 10 - 0
desktop/core/src/desktop/static/desktop/js/fileBrowser/hueFileEntry.js

@@ -85,6 +85,16 @@
     }
   }
 
+  HueFileEntry.prototype.beforeContextOpen = function () {
+    var self = this;
+    if (! self.selected()) {
+      $.each(self.parent.selectedEntries(), function (idx, entry) {
+        entry.selected(false);
+      });
+      self.selected(true);
+    }
+  };
+
   HueFileEntry.prototype.showSharingModal = function () {
     var self = this;
     if (self.selectedEntry()) {

+ 11 - 4
desktop/core/src/desktop/static/desktop/js/ko.hue-bindings.js

@@ -159,15 +159,19 @@
    *
    * Example:
    *
-   * <div data-bind="contextMenu: '.hue-context-menu'>
+   * <div data-bind="contextMenu: {
+   *   menuSelector: '.hue-context-menu',
+   *   beforeOpen: function () { ... }
+   * }">
    *   <ul class="hue-context-menu">...</ul>
    * </div>
-   * 
+   *
    */
   ko.bindingHandlers.contextMenu = {
-    init: function (element, valueAccessor) {
+    init: function (element, valueAccessor, allBindings, viewModel, bindingContext) {
       var $element = $(element);
-      var $menu = $element.find(valueAccessor());
+      var options = valueAccessor();
+      var $menu = $element.find(options.menuSelector);
       var active = false;
 
       element.addEventListener("contextmenu", function(e) {
@@ -177,6 +181,9 @@
           var sel = window.getSelection();
           sel.removeAllRanges();
         }
+        if (typeof options.beforeOpen === 'function') {
+          options.beforeOpen.bind(viewModel)();
+        }
         $menu.css('top', 0);
         $menu.css('left', 0);
         $menu.css('opacity', 0);

+ 1 - 1
desktop/core/src/desktop/templates/file_browser.mako

@@ -460,7 +460,7 @@ from desktop.views import _ko
       <div class="fb-list" data-bind="with: activeEntry">
         <ul data-bind="foreach: { data: entries, itemHeight: 39, scrollableElement: '.fb-list' }">
           <li data-bind="fileSelect: $parent.entries, folderDroppable: { entries: $parent.entries }, css: { 'fb-selected': selected }">
-            <div style="width: 100%; height: 100%" data-bind="contextMenu: '.hue-context-menu'">
+            <div style="width: 100%; height: 100%" data-bind="contextMenu: { menuSelector: '.hue-context-menu', beforeOpen: beforeContextOpen }">
               <ul class="hue-context-menu">
                 <li><a href="javascript:void(0);" data-bind="click: contextMenuDownload"><i class="fa fa-download"></i> ${ _('Download') }</a></li>
                 <li><a href="javascript:void(0);" data-bind="click: function() { $parent.showDeleteConfirmation(); }"><i class="fa fa-fw fa-times"></i> ${ _('Delete') }</a></li>