0b4e173e551e7062863e68c128bf08918d74de1d.svn-base 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * Ext JS Library 2.0 Copyright(c) 2006-2007, Ext JS, LLC. licensing@extjs.com
  3. *
  4. * http://extjs.com/license
  5. */
  6. Ext.grid.CellSelectionModel = function(A) {
  7. Ext.apply(this, A);
  8. this.selection = null;
  9. this.addEvents("beforecellselect", "cellselect", "selectionchange");
  10. Ext.grid.CellSelectionModel.superclass.constructor.call(this)
  11. };
  12. Ext.extend(Ext.grid.CellSelectionModel, Ext.grid.AbstractSelectionModel, {
  13. initEvents : function() {
  14. this.grid.on("cellmousedown", this.handleMouseDown, this);
  15. this.grid.getGridEl().on(Ext.isIE ? "keydown" : "keypress",
  16. this.handleKeyDown, this);
  17. var A = this.grid.view;
  18. A.on("refresh", this.onViewChange, this);
  19. A.on("rowupdated", this.onRowUpdated, this);
  20. A.on("beforerowremoved", this.clearSelections, this);
  21. A.on("beforerowsinserted", this.clearSelections, this);
  22. if (this.grid.isEditor) {
  23. this.grid.on("beforeedit", this.beforeEdit, this)
  24. }
  25. },
  26. beforeEdit : function(A) {
  27. this.select(A.row, A.column, false, true, A.record)
  28. },
  29. onRowUpdated : function(A, B, C) {
  30. if (this.selection && this.selection.record == C) {
  31. A.onCellSelect(B, this.selection.cell[1])
  32. }
  33. },
  34. onViewChange : function() {
  35. this.clearSelections(true)
  36. },
  37. getSelectedCell : function() {
  38. return this.selection ? this.selection.cell : null
  39. },
  40. clearSelections : function(B) {
  41. var A = this.selection;
  42. if (A) {
  43. if (B !== true) {
  44. this.grid.view.onCellDeselect(A.cell[0], A.cell[1])
  45. }
  46. this.selection = null;
  47. this.fireEvent("selectionchange", this, null)
  48. }
  49. },
  50. hasSelection : function() {
  51. return this.selection ? true : false
  52. },
  53. handleMouseDown : function(B, D, A, C) {
  54. if (C.button !== 0 || this.isLocked()) {
  55. return
  56. }
  57. this.select(D, A)
  58. },
  59. select : function(F, C, B, E, D) {
  60. if (this.fireEvent("beforecellselect", this, F, C) !== false) {
  61. this.clearSelections();
  62. D = D || this.grid.store.getAt(F);
  63. this.selection = {
  64. record : D,
  65. cell : [F, C]
  66. };
  67. if (!B) {
  68. var A = this.grid.getView();
  69. A.onCellSelect(F, C);
  70. if (E !== true) {
  71. A.focusCell(F, C)
  72. }
  73. }
  74. this.fireEvent("cellselect", this, F, C);
  75. this.fireEvent("selectionchange", this, this.selection)
  76. }
  77. },
  78. isSelectable : function(C, B, A) {
  79. return !A.isHidden(B)
  80. },
  81. handleKeyDown : function(F) {
  82. if (!F.isNavKeyPress()) {
  83. return
  84. }
  85. var E = this.grid, J = this.selection;
  86. if (!J) {
  87. F.stopEvent();
  88. var I = E.walkCells(0, 0, 1, this.isSelectable, this);
  89. if (I) {
  90. this.select(I[0], I[1])
  91. }
  92. return
  93. }
  94. var B = this;
  95. var H = function(M, K, L) {
  96. return E.walkCells(M, K, L, B.isSelectable, B)
  97. };
  98. var C = F.getKey(), A = J.cell[0], G = J.cell[1];
  99. var D;
  100. switch (C) {
  101. case F.TAB :
  102. if (F.shiftKey) {
  103. D = H(A, G - 1, -1)
  104. } else {
  105. D = H(A, G + 1, 1)
  106. }
  107. break;
  108. case F.DOWN :
  109. D = H(A + 1, G, 1);
  110. break;
  111. case F.UP :
  112. D = H(A - 1, G, -1);
  113. break;
  114. case F.RIGHT :
  115. D = H(A, G + 1, 1);
  116. break;
  117. case F.LEFT :
  118. D = H(A, G - 1, -1);
  119. break;
  120. case F.ENTER :
  121. if (E.isEditor && !E.editing) {
  122. E.startEditing(A, G);
  123. F.stopEvent();
  124. return
  125. }
  126. break
  127. }
  128. if (D) {
  129. this.select(D[0], D[1]);
  130. F.stopEvent()
  131. }
  132. },
  133. acceptsNav : function(C, B, A) {
  134. return !A.isHidden(B) && A.isCellEditable(B, C)
  135. },
  136. onEditorKey : function(E, D) {
  137. var B = D.getKey(), F, C = this.grid, A = C.activeEditor;
  138. if (B == D.TAB) {
  139. if (D.shiftKey) {
  140. F = C.walkCells(A.row, A.col - 1, -1, this.acceptsNav,
  141. this)
  142. } else {
  143. F = C.walkCells(A.row, A.col + 1, 1, this.acceptsNav,
  144. this)
  145. }
  146. D.stopEvent()
  147. } else {
  148. if (B == D.ENTER) {
  149. A.completeEdit();
  150. D.stopEvent()
  151. } else {
  152. if (B == D.ESC) {
  153. D.stopEvent();
  154. A.cancelEdit()
  155. }
  156. }
  157. }
  158. if (F) {
  159. C.startEditing(F[0], F[1])
  160. }
  161. }
  162. });