📄 selection.js
字号:
//<deselectList : function (list) { this.selectList(list, false);},//> @method selection.selectAll()// Select ALL records of the list// @group selection//// @return (boolean) true == selection actually changed, false == no change// @visibility external//<selectAll : function () { return this.selectRange(0, this.data.getLength());},//> @method selection.deselectAll()// Deselect ALL records of the list// @group selection//// @return (boolean) true == selection actually changed, false == no change// @visibility external//<deselectAll : function () { return this.deselectList(this.getSelection());},//> @method selection.selectItem()// Select a particular item by its position in the list//// @param position (number) index of the item to be selected// @return (boolean) true == selection actually changed, false == no change// @group selection// @visibility external//<selectItem : function (position) { return this.selectRange(position, position+1);},//> @method selection.deselectItem()// Deselect a particular item by its position in the list//// @param position (number) index of the item to be selected// @return (boolean) true == selection actually changed, false == no change// @group selection// @visibility external//<deselectItem : function (position) { return this.deselectRange(position, position+1);},//> @method selection.selectRange()// Select range of records from <code>start</code> to <code>end</code>, non-inclusive.// @group selection//// @param start (number) start index to select// @param end (number) end index (non-inclusive)// @param [newState] (boolean) optional new selection state to set. True means// selected, false means unselected. Defaults to true.//// @return (boolean) true == selection actually changed, false == no change// @visibility external//<selectRange : function (start, end, newState) { if (newState == null) newState = true; if (isc.isA.ResultSet != null && isc.isA.ResultSet(this.data) && !this.data.rangeIsLoaded(start, end)) { isc.warn("Can't select that many records at once.<br><br>" + "Please try working in smaller batches."); return false; // no change } return this.selectList(this.data.getRange(start, end), newState);},//> @method selection.deselectRange()// Deselect range of records from <code>start</code> to <code>end</code>, non-inclusive//// @group selection//// @param start (number) start index to select// @param end (number) end index (non-inclusive)//// @return (boolean) true == selection actually changed, false == no change// @visibility external//<deselectRange : function (start, end) { return this.selectRange(start, end, false);},// DOCFIX: this methods shouldn't require the "target", a Canvas. Need to fix that before we make// them public.//> @method selection.selectOnMouseDown() (A)// Update the selection as the result of a mouseDown event.// Handles shift, control, etc. key selection as well.// Call this from a mouseDown handler.//// @group selection, mouseEvents//// @param target (Canvas) target object// @param position (number) position where mouse went down on//// @return (boolean) true == selection was changed, false == no change//<selectOnMouseDown : function (target, recordNum) { // modify selection according to the specified style (defaulting to multiple selection) var selectionType = target.selectionType || isc.Selection.MULTIPLE; // if the target's selectionType is NONE, just bail if (selectionType == isc.Selection.NONE) return false; // remember mouseDown location in case we start drag selecting this.startRow = this.lastRow = recordNum; //>DEBUG this.logDebug("selectOnMouseDown: recordNum: " + recordNum); //<DEBUG var record = this.data.get(recordNum), recordSelected = this.isSelected(record), selection = this.getSelection(); // prevent mouse-based selection of the LOADING record. This doesn't make sense and create // client-side JS errors very easily. if (Array.isLoading(record)) return false; // clear flags for deselecting records on mouseUp // these are set in the simple and normal cases below (3 and 5) // see selectOnMouseUp() for details this.deselectRecordOnMouseUp = false; this.deselectOthersOnMouseUp = false; // In Windows ctrl-click works allows multiple independent row selection/deselection // In Mac the equivalent functionality occurs with the Apple key (meta key), since // on that platform ctrl+click == right click var metaKeyDown = (isc.Browser.isMac ? isc.EventHandler.metaKeyDown() : isc.EventHandler.ctrlKeyDown()), shiftKeyDown = isc.EH.shiftKeyDown(); // Case 1: SINGLE selection if (selectionType == isc.Selection.SINGLE) { // On ctrl+click allow deselection if (metaKeyDown && recordSelected) this.deselect(record); else if (!recordSelected) this.selectSingle(record); return true; // Case 2: Shift-selection (select contiguous range of records) } else if (shiftKeyDown) { // if nothing was selected, if (selection.length == 0) { // simply select that record this.select(record); return true; // otherwise since something was selected } else { // select a range of records var firstRecord = this.data.indexOf(selection[0]), lastRecord = this.data.indexOf(selection.last()) ; // if the clicked record is the last record or beyond if (recordNum >= lastRecord) { // select from the firstRecord to the clicked record this.selectRange(firstRecord, recordNum + 1); // else if the clicked record is the first record or before } else if (recordNum <= firstRecord) { // select from the clicked record to the lastRecord this.selectRange(recordNum, lastRecord + 1); // otherwise it's in between the start and end record } else { // select from the firstRecord to the clicked record this.selectRange(firstRecord, recordNum + 1); // and deselect form the clickedRecord + 1 to the lastRecord this.deselectRange(recordNum + 1, lastRecord +1); } return true; } // Case 3: SIMPLE selection (toggle selection of this record, but defer deselection until // mouseUp) } else if (selectionType == isc.Selection.SIMPLE) { if (!recordSelected) { this.select(record); return true; } else { this.deselectRecordOnMouseUp = true; return false; } // Case 4: meta-key selection in a multiple selection range // (simply toggle selection of this record) } else if (metaKeyDown) { this.setSelected(record, !recordSelected); return true; // Case 5: normal selection (no modifier keys) in a multiple selection range } else { if (!recordSelected) { // if you click outside of the selection, select the new record and deselect // everything else this.selectSingle(record); return true; } else if (isc.EventHandler.rightButtonDown()) { // never deselect if you right click on the selection, unless you start drag // selecting this.deselectOnDragMove = true; return false; } else { // simpleDeselect mode: this mode is designed to make it easy to entirely get rid // of your selection, so you don't have to know about ctrl-clicking. In a // nutshell, if you click on the existing selection, it will be entirely // deselected. if (this.dragSelection) { if (this.simpleDeselect) { // if you click on the selection, deselect the entire selection including // the clicked-on cell. Later, if a drag begins, select the clicked-on // cell. this.deselectAll(); this.selectOriginOnDragMove = true; return true; } // for a drag selection, deselect others immediately; otherwise we'll be // dragging out a new selection within/overlapping with an existing selection, // which we only want to do on a ctrl-click. This matches Excel. this.selectSingle(record); return true; } else { if (this.simpleDeselect) { // deselect everything on mouseUp, including the cell clicked on this.deselectAllOnMouseUp = true; } else { // if we click in a multiple selection, deselect everything but the // clicked-on item, but don't do it until mouseUp in order to allow // dragging the current selection. This matches Windows Explorer. this.deselectOthersOnMouseUp = (selection.length > 1); } return false; } } }},//> @method selection.selectOnDragMove() (A)// During drag selection, update the selection as a result of a dragMove event//// @group selection, mouseEvents//// @param target (Canvas) target object// @param position (number) position where mouse went down on//// @return (boolean) true == selection was changed, false == no change////<selectOnDragMove : function (target, currRow) { var startRow = this.startRow, lastRow = this.lastRow; // If the mouse has moved further away from the start position since the last dragMove, select // more cells. If it's moved closer to the start position, deselect cells. if (currRow < 0) { //>DEBUG this.logWarn("selectOnDragMove: got negative coordinate: " + currRow); //<DEBUG return; } if (currRow == lastRow) return; // no change if (this.selectOriginOnDragMove) { this.select(this.data.getItem(startRow)); this.selectOriginOnDragMove = false; } else if (this.deselectOnDragMove || this.deselectAllOnMouseUp || this.deselectOthersOnMouseUp) { // deselect on dragMove is for right-dragging. The others flags are failsafes in case you // use drag selection without setting the flag. this.selectSingle(this.data.getItem(startRow)); this.deselectAllOnMouseUp = this.deselectOthersOnMouseUp = this.deselectOnDragMove = false; } if ((currRow > startRow && startRow > lastRow) || (lastRow > startRow && startRow > currRow)) { //this.logWarn("dragged from one side of start to the other"); // dragged from one side of start to the other this.deselectAll(); // select from start to current inclusive if (startRow > currRow) { this.selectRange(currRow, startRow+1); } else { this.selectRange(startRow, currRow+1); } } else if (startRow >= lastRow && lastRow > currRow) { //this.logWarn("increasing selection on the left of start"); // increasing selection on the left of start this.selectRange(currRow, lastRow); } else if (startRow >= currRow && currRow > lastRow) { //this.logWarn("decreasing selection on the left of start"); // decreasing selection on the left of start this.deselectRange(lastRow, currRow); } else if (startRow <= currRow && currRow < lastRow) { //this.logWarn("decreasing selection on the right of start"); // decreasing selection on the right of start this.deselectRange(currRow+1, lastRow+1); } else if (startRow <= lastRow && lastRow < currRow) { //this.logWarn("increasing selection on the right of start"); // increasing selection on the right of start this.selectRange(lastRow, currRow+1); //>DEBUG } else { this.logWarn("dragMove case not handled: lastRow: " + lastRow + ", currRow: " + currRow + ", startRow " + startRow); //<DEBUG } this.lastRow = currRow;},//> @method selection.selectOnMouseUp() (A)s// @group selection, mouseEvents// Update the selection as the result of a mouseUp event.// We currently use this to defer deselection for drag-and-drop of multiple records.// Call this from a mouseUp handler.// @see ListGrid.mouseUp()//// @param target (Canvas) target object// @param recordNum (number) record number mouse went down on//// @return (boolean) true == selection was changed, false == no change//<selectOnMouseUp : function (target, recordNum) { // if the target's selectionType is NONE, just bail if (target.selectionType == isc.Selection.NONE) return false; //>DEBUG this.logDebug("selectOnMouseUp: recordNum: " + recordNum); //<DEBUG // JMD 020828: // If multiselection is on and no modifier keys are down, we need to // deselect any rows other than the one that is clicked. BUT, we can't do this in // selectOnMouseDown() because the user might be clicking on a row in a multiple selection // to initiate a drag operation with all of the selected rows. So in selectOnMouseDown() // we set a deselectOthersOnMouseUp flag that we can check here and do the deselection // if necessary. // Similarly, if SIMPLE selection is enabled we don't want to deselect the current // record if the user is initiating a drag. We set a deselectRecordOnMouseUp flag for in this case. // // We never deselect anything on rightMouseUp since you would right click to show a context menu // to operate on the current selection. if (this.deselectOthersOnMouseUp) { this.selectSingle(this.data.getItem(recordNum)); this.deselectOthersOnMouseUp = false; return true; } else if (this.deselectRecordOnMouseUp) { this.deselect(this.data.getItem(recordNum)); this.deselectRecordOnMouseUp = false; return true; } else if (this.deselectAllOnMouseUp) { this.deselectAll(); this.deselectAllOnMouseUp = false; return true; } else return false;}}); // END isc.Selection.addMethods()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -