﻿// Copyright (C) 2007 Xtensive LLC.
// All rights reserved.
// For conditions of distribution and use, see license.
// Created by: Alexander Ilyin
// Created:    2007.09.25

Ext.namespace("Xtensive");

// config:
//    gridPanel : GridPanel

Xtensive.GridPanelContextMenu = function(config) {
  Xtensive.GridPanelContextMenu.superclass.constructor.call(this, config);
  this.gridPanel.on('rowcontextmenu', this.onContextMenu, this);
};

Ext.extend(Xtensive.GridPanelContextMenu, Ext.menu.Menu, {
  initComponent: function() {
    Xtensive.GridPanelContextMenu.superclass.initComponent.call(this);
    this.addEvents('showing');
  },

  onContextMenu: function(grid, rowIndex, e) {
    e.stopEvent();
    var sm = grid.getSelectionModel();
    if (sm != null && sm.selectRow) {
      if (!sm.isSelected(rowIndex))
        sm.selectRow(rowIndex, false); // false = do not keep selection.
    }
    this.showAt(e.getXY());
  }
});

if (typeof (Sys) !== 'undefined')
  Sys.Application.notifyScriptLoaded();