Skip to content

Commit

Permalink
jeremy.herault: adds the possibility to reorder the testCases in the …
Browse files Browse the repository at this point in the history
…testSuite tree just with Drag'n'Drop

git-svn-id: http://selenium.googlecode.com/svn/trunk@8622 07704840-8298-11de-bf8c-fd130f914ac9
  • Loading branch information
jeremy.herault committed Apr 4, 2010
1 parent 967832b commit dd016f8
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 1 deletion.
46 changes: 46 additions & 0 deletions ide/src/extension/content/dnd-observers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2010 Jérémy Hérault
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

//a shorthand writting
const Ci = Components.interfaces;
const Cc = Components.classes;


/**
* Object used to observe DnD on the suiteTree
*/
var suiteTreeDragObserver = {

onDragStart: function (aEvent, aXferData, aDragAction) {

try{
var selectedIndex = document.getElementById('suiteTree').currentIndex;
if (selectedIndex == -1)
return;

aXferData.data = new TransferData();
aXferData.data.addDataForFlavour("text/unicode", selectedIndex.toString());
aDragAction.action = Ci.nsIDragService.DRAGDROP_ACTION_MOVE;

}catch(e){
new Log("DND").error("onDragStart error: "+e);
}
},
onDrop: function (aEvent, aXferData, aDragSession) {},
onDragExit: function (aEvent, aDragSession) {},
onDragOver: function (aEvent, aFlavour, aDragSession) {},
getSupportedFlavours: function() {return null; }
};
4 changes: 3 additions & 1 deletion ide/src/extension/content/selenium-ide-common.xul
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ limitations under the License.
<overlay id="selenium-ide-common"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/x-javascript" src="chrome://global/content/globalOverlay.js"/>
<script type="application/x-javascript" src="chrome://global/content/nsDragAndDrop.js"/>
<script type="application/x-javascript" src="chrome://selenium-ide/content/dnd-observers.js"/>
<script type="application/x-javascript" src="chrome://selenium-ide/content/preferences.js"/>
<!-- import misc.js before tools.js, because both declare a Log object -->
<script type="application/x-javascript" src="chrome://selenium-ide/content/selenium/xpath/misc.js"/>
Expand Down Expand Up @@ -212,7 +214,7 @@ limitations under the License.
<treecols>
<treecol label="&suiteTree.testCase.label;" flex="1" />
</treecols>
<treechildren />
<treechildren ondraggesture="nsDragAndDrop.startDrag(event, suiteTreeDragObserver);"/>
</tree>
<hbox id="suiteProgressBar">
<box id="suiteProgressIndicator" height="16" class="success" />
Expand Down
63 changes: 63 additions & 0 deletions ide/src/extension/content/suiteTreeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,68 @@ objectExtend(SuiteTreeView.prototype, {
if (row == this.currentTestCaseIndex) {
props.AppendElement(XulUtils.atomService.getAtom("currentTestCase"));
}
},

getParentIndex: function(index){return -1;},

getSourceIndexFromDrag: function () {
try{
var dragService = Cc["@mozilla.org/widget/dragservice;1"].
getService().QueryInterface(Ci.nsIDragService);
var dragSession = dragService.getCurrentSession();
var transfer = Cc["@mozilla.org/widget/transferable;1"].
createInstance(Ci.nsITransferable);

transfer.addDataFlavor("text/unicode");
dragSession.getData(transfer, 0);

var dataObj = {};
var len = {};
var sourceIndex = -1;
var out = {};

transfer.getAnyTransferData(out, dataObj, len);

if (dataObj.value) {
sourceIndex = dataObj.value.QueryInterface(Ci.nsISupportsString).data;
sourceIndex = parseInt(sourceIndex.substring(0, len.value));
}

return sourceIndex;

}catch(e){
new Log("DND").error("getSourceIndexFromDrag error: "+e);
}
},

canDrop: function(targetIndex, orientation) {
var sourceIndex = this.getSourceIndexFromDrag();

return (sourceIndex != -1 &&
sourceIndex != targetIndex &&
sourceIndex != (targetIndex + orientation));
},

drop: function(dropIndex, orientation) {
try{
var sourceIndex = this.getSourceIndexFromDrag();

if (dropIndex > sourceIndex) {
if (orientation == Ci.nsITreeView.DROP_BEFORE)
dropIndex--;
}else{
if (orientation == Ci.nsITreeView.DROP_AFTER)
dropIndex++;
}

var removedRow = this.getTestSuite().tests.splice(sourceIndex, 1)[0];
this.getTestSuite().tests.splice(dropIndex, 0, removedRow);

this.treebox.invalidate();
this.selection.clearSelection();
this.selection.select(dropIndex);
}catch(e){
new Log("DND").error("drop error : "+e);
}
}
});

0 comments on commit dd016f8

Please sign in to comment.