mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-13 05:15:45 +00:00
315940 more D&D support: drag from toolbar. NPOB
This commit is contained in:
parent
98ddf6bb41
commit
b0facf8447
@ -656,6 +656,52 @@ var PlacesController = {
|
||||
return null;
|
||||
},
|
||||
|
||||
/**
|
||||
* Wraps a string in a nsISupportsString wrapper
|
||||
* @param str
|
||||
* The string to wrap
|
||||
* @returns A nsISupportsString object containing a string.
|
||||
*/
|
||||
_wrapString: function PC__wrapString(str) {
|
||||
var s =
|
||||
Cc["@mozilla.org/supports-string;1"].
|
||||
createInstance(Ci.nsISupportsString);
|
||||
s.data = str;
|
||||
return s;
|
||||
},
|
||||
|
||||
/**
|
||||
* Get a TransferDataSet containing the content of the selection that can be
|
||||
* dropped elsewhere.
|
||||
* @returns A TransferDataSet object that can be dragged and dropped
|
||||
* elsewhere.
|
||||
*/
|
||||
getTransferData: function PC_getTransferData() {
|
||||
var nodes = this._activeView.getCopyableSelection();
|
||||
var dataSet = new TransferDataSet();
|
||||
for (var i = 0; i < nodes.length; ++i) {
|
||||
var node = nodes[i];
|
||||
|
||||
var data = new TransferData();
|
||||
var self = this;
|
||||
function addData(type) {
|
||||
data.addDataForFlavour(type, self._wrapString(self.wrapNode(node, type)));
|
||||
}
|
||||
if (this.nodeIsFolder(node) || this.nodeIsQuery(node))
|
||||
addData(TYPE_X_MOZ_PLACE_CONTAINER);
|
||||
else {
|
||||
// This order is _important_! It controls how this and other
|
||||
// applications select data to be inserted based on type.
|
||||
addData(TYPE_X_MOZ_PLACE);
|
||||
addData(TYPE_UNICODE);
|
||||
addData(TYPE_HTML);
|
||||
addData(TYPE_X_MOZ_URL);
|
||||
}
|
||||
dataSet.push(data);
|
||||
}
|
||||
return dataSet;
|
||||
},
|
||||
|
||||
/**
|
||||
* Copy Bookmarks and Folders to the clipboard
|
||||
*/
|
||||
@ -684,45 +730,23 @@ var PlacesController = {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps a string in a nsISupportsString wrapper
|
||||
* @param str
|
||||
* The string to wrap
|
||||
* @returns A nsISupportsString object containing a string.
|
||||
*/
|
||||
function wrapString(str) {
|
||||
var s =
|
||||
Cc["@mozilla.org/supports-string;1"].
|
||||
createInstance(Ci.nsISupportsString);
|
||||
s.data = str;
|
||||
return s;
|
||||
}
|
||||
|
||||
if (pcString) {
|
||||
xferable.addDataFlavor(TYPE_X_MOZ_PLACE_CONTAINER);
|
||||
xferable.setTransferData(TYPE_X_MOZ_PLACE_CONTAINER,
|
||||
wrapString(placeString), placeString.length * 2);
|
||||
}
|
||||
if (placeString) {
|
||||
xferable.addDataFlavor(TYPE_X_MOZ_PLACE);
|
||||
xferable.setTransferData(TYPE_X_MOZ_PLACE, wrapString(placeString),
|
||||
placeString.length * 2);
|
||||
}
|
||||
if (unicodeString) {
|
||||
xferable.addDataFlavor(TYPE_UNICODE);
|
||||
xferable.setTransferData(TYPE_UNICODE, wrapString(unicodeString),
|
||||
unicodeString.length * 2);
|
||||
}
|
||||
if (htmlString) {
|
||||
xferable.addDataFlavor(TYPE_HTML);
|
||||
xferable.setTransferData(TYPE_HTML, wrapString(htmlString),
|
||||
htmlString.length * 2);
|
||||
}
|
||||
if (mozURLString) {
|
||||
xferable.addDataFlavor(TYPE_X_MOZ_URL);
|
||||
xferable.setTransferData(TYPE_X_MOZ_URL, wrapString(mozURLString),
|
||||
mozURLString.length * 2);
|
||||
var self = this;
|
||||
function addData(type, data) {
|
||||
xferable.addDataFlavor(type);
|
||||
xferable.setTransferData(type, self._wrapString(data), data.length * 2);
|
||||
}
|
||||
// This order is _important_! It controls how this and other applications
|
||||
// select data to be inserted based on type.
|
||||
if (pcString)
|
||||
addData(TYPE_X_MOZ_PLACE_CONTAINER, pcString);
|
||||
if (placeString)
|
||||
addData(TYPE_X_MOZ_PLACE, placeString);
|
||||
if (unicodeString)
|
||||
addData(TYPE_UNICODE, unicodeString);
|
||||
if (htmlString)
|
||||
addData(TYPE_HTML, htmlString);
|
||||
if (mozURLString)
|
||||
addData(TYPE_X_MOZ_URL, mozURLString);
|
||||
|
||||
if (pcString || placeString || unicodeString || htmlString ||
|
||||
mozURLString) {
|
||||
@ -884,7 +908,7 @@ var PlacesControllerDragHelper = {
|
||||
* @param orientation
|
||||
* The orientation of the drop
|
||||
*/
|
||||
onDrop: function PCDH_onDrop(view, container, index) {
|
||||
onDrop: function PCDH_onDrop(view, container, index, orientation) {
|
||||
var session = this._getSession();
|
||||
if (!session)
|
||||
return;
|
||||
|
@ -1,6 +1,5 @@
|
||||
#historyCalendar {
|
||||
-moz-binding: url("chrome://browser/content/places/places.xml#calendar");
|
||||
display: -moz-box;
|
||||
}
|
||||
|
||||
#searchFilter {
|
||||
|
@ -97,7 +97,6 @@ var PlacesUIHook = {
|
||||
var PlacesPage = {
|
||||
_content: null,
|
||||
_places: null,
|
||||
_bmsvc : null,
|
||||
|
||||
init: function PP_init() {
|
||||
// Attach the Command Controller to the Places Views.
|
||||
@ -117,7 +116,7 @@ var PlacesPage = {
|
||||
PlacesUIHook.init(this._content);
|
||||
|
||||
// Attach the History model to the Content View
|
||||
this._content.queryString = "group=1";
|
||||
this._content.queryString = "";
|
||||
|
||||
// Attach the Places model to the Place View
|
||||
// XXXben - move this to an attribute/property on the tree view
|
||||
@ -190,7 +189,7 @@ var PlacesPage = {
|
||||
filterCollectionDeck.selectedPanel = document.getElementById(filterButtonID);
|
||||
|
||||
// Hide the Calendar for Bookmark queries.
|
||||
document.getElementById("historyCalendar").hidden = isBookmarks;
|
||||
document.getElementById("historyCalendar").setAttribute("hidden", isBookmarks);
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -151,6 +151,8 @@
|
||||
<setter><![CDATA[
|
||||
var queries = { }, options = { };
|
||||
this._places.queryStringToQueries(val, queries, { }, options);
|
||||
if (!queries.value.length)
|
||||
queries.value = [this._places.getNewQuery()];
|
||||
this.load(queries.value, options.value);
|
||||
return val;
|
||||
]]></setter>
|
||||
@ -307,76 +309,31 @@
|
||||
]]></body>
|
||||
</method>
|
||||
|
||||
<method name="_getTransferData">
|
||||
<body><![CDATA[
|
||||
var result = this.getResult();
|
||||
var selection = this.view.selection;
|
||||
if (selection.count == 0)
|
||||
return null;
|
||||
var dataSet = new TransferDataSet();
|
||||
var rc = selection.getRangeCount();
|
||||
|
||||
for (var i = 0; i < rc; ++i) {
|
||||
var min = { }, max = { };
|
||||
selection.getRangeAt(i, min, max);
|
||||
for (var j = min.value; j <= max.value; ++j) {
|
||||
var node = result.nodeForTreeIndex(j);
|
||||
|
||||
var data = new TransferData();
|
||||
function addData(type) {
|
||||
var s =
|
||||
Cc["@mozilla.org/supports-string;1"].
|
||||
createInstance(Ci.nsISupportsString);
|
||||
s.data = PlacesController.wrapNode(node, type);
|
||||
data.addDataForFlavour(type, s);
|
||||
}
|
||||
if (PlacesController.nodeIsFolder(node) ||
|
||||
PlacesController.nodeIsQuery(node))
|
||||
addData(TYPE_X_MOZ_PLACE_CONTAINER);
|
||||
else {
|
||||
// Order here is _important_!
|
||||
addData(TYPE_X_MOZ_PLACE);
|
||||
addData(TYPE_UNICODE);
|
||||
addData(TYPE_HTML);
|
||||
addData(TYPE_X_MOZ_URL);
|
||||
}
|
||||
dataSet.push(data);
|
||||
}
|
||||
}
|
||||
return dataSet;
|
||||
]]></body>
|
||||
</method>
|
||||
|
||||
<field name="_DNDObserver"><![CDATA[({
|
||||
// XXXben ew.
|
||||
_self: this,
|
||||
onDragStart: function(event, xferData, dragAction) {
|
||||
if (this._self.getAttribute("sortActive") == "true")
|
||||
throw Components.results.NS_OK;
|
||||
xferData.data = this._self._getTransferData();
|
||||
xferData.data = PlacesController.getTransferData();
|
||||
// XXXben - the drag wrapper should do this automatically.
|
||||
if (event.ctrlKey)
|
||||
dragAction.action = Ci.nsIDragService.DRAGDROP_ACTION_COPY;
|
||||
},
|
||||
|
||||
onDragOver: function(event, flavor, dragSession) {
|
||||
if (dragSession.sourceNode == this._self)
|
||||
dragSession.canDrop = true;
|
||||
canDrop: function(event, session) {
|
||||
return this._self._viewObserver.canDrop(-1, -1);
|
||||
},
|
||||
onDragOver: function(event, flavor, session) {
|
||||
},
|
||||
|
||||
_flavorSet: null,
|
||||
getSupportedFlavours: function() {
|
||||
if (!this._flavorSet) {
|
||||
this._flavorSet = new FlavourSet();
|
||||
var flavorSet = new FlavourSet();
|
||||
for (var i = 0; i < this._self.supportedDropTypes.length; ++i)
|
||||
this._flavorSet.appendFlavour(this._self.supportedDropTypes[i]);
|
||||
}
|
||||
return this._flavorSet;
|
||||
}
|
||||
flavorSet.appendFlavour(this._self.supportedDropTypes[i]);
|
||||
return flavorSet;
|
||||
},
|
||||
})]]></field>
|
||||
|
||||
<field name="_viewObserver"><![CDATA[
|
||||
({
|
||||
<field name="_viewObserver"><![CDATA[({
|
||||
_self: this,
|
||||
|
||||
canDrop: function VO_canDrop(index, orientation) {
|
||||
@ -392,13 +349,20 @@
|
||||
const NHRVO = Ci.nsINavHistoryResultViewObserver;
|
||||
var result = this._self.getResult();
|
||||
var view = this._self.view;
|
||||
var node = result.nodeForTreeIndex(index);
|
||||
var node = index != -1 ? result.nodeForTreeIndex(index) : null;
|
||||
var destContainer = null;
|
||||
var destIndex = -1;
|
||||
// If we're dropping _on_ a container, the container is the container
|
||||
// we dropped on, otherwise it's the parent of the drop target.
|
||||
if (view.isContainer(index) && orientation == NHRVO.DROP_ON)
|
||||
if (!node) {
|
||||
// Dropping in some blank area of the view, just use the result as
|
||||
// the container.
|
||||
destContainer = result.folderId;
|
||||
}
|
||||
else if (view.isContainer(index) && orientation == NHRVO.DROP_ON) {
|
||||
// If we're dropping _on_ a container, the container is the
|
||||
// container we dropped on, otherwise it's the parent of the drop
|
||||
// target.
|
||||
destContainer = node.folderId;
|
||||
}
|
||||
else {
|
||||
var destIndex = PlacesController.getIndexOfNode(node);
|
||||
// For non leaves, or when not dropping _on_ a container, drop after
|
||||
@ -421,8 +385,7 @@
|
||||
onPerformAction: function VO_onPerformAction(action) { },
|
||||
onPerformActionOnRow: function VO_onPerformActionOnRow(action, row) { },
|
||||
onPerformActionOnCell: function VO_onPerformActionOnCell(action, row, column) { },
|
||||
})
|
||||
]]></field>
|
||||
})]]></field>
|
||||
|
||||
<method name="_reloadView">
|
||||
<body><![CDATA[
|
||||
@ -501,6 +464,10 @@
|
||||
if (event.target.localName == "treechildren")
|
||||
nsDragAndDrop.startDrag(event, this._DNDObserver);
|
||||
]]></handler>
|
||||
<handler event="dragover"><![CDATA[
|
||||
if (event.target.localName == "treechildren")
|
||||
nsDragAndDrop.dragOver(event, this._DNDObserver);
|
||||
]]></handler>
|
||||
</handlers>
|
||||
</binding>
|
||||
|
||||
|
@ -99,7 +99,8 @@
|
||||
</hbox>
|
||||
<deck id="content" flex="1">
|
||||
<vbox flex="1">
|
||||
<tree id="placeContent" class="placesTree" context="placesContext" flex="1"
|
||||
<tree id="placeContent" class="placesTree" context="placesContext"
|
||||
flex="1" query=""
|
||||
ondblclick="PlacesController.mouseLoadURI(event);"
|
||||
onplacestreereloaded="PlacesPage.onContentChanged();">
|
||||
<treecols>
|
||||
|
@ -181,15 +181,35 @@
|
||||
this._self.init();
|
||||
},
|
||||
})]]></field>
|
||||
<field name="_DNDObserver"><![CDATA[({
|
||||
// XXXben ew.
|
||||
_self: this,
|
||||
onDragStart: function(event, xferData, dragAction) {
|
||||
xferData.data = PlacesController.getTransferData();
|
||||
// XXXben - the drag wrapper should do this automatically.
|
||||
if (event.ctrlKey)
|
||||
dragAction.action = Ci.nsIDragService.DRAGDROP_ACTION_COPY;
|
||||
},
|
||||
})]]></field>
|
||||
</implementation>
|
||||
<handlers>
|
||||
<handler event="click">
|
||||
<handler event="mousedown"><![CDATA[
|
||||
// When the user clicks down on a button, set it as the selection and
|
||||
// tell the controller that we are the active view.
|
||||
if (event.target.localName != "toolbarbutton")
|
||||
return;
|
||||
this._selection = event.target.node;
|
||||
PlacesController.activeView = this;
|
||||
]]></handler>
|
||||
<handler event="click">
|
||||
PlacesController.mouseLoadURI(event);
|
||||
</handler>
|
||||
<handler event="draggesture"><![CDATA[
|
||||
// XXXben ew.
|
||||
if (event.target.localName == "toolbarbutton" &&
|
||||
!event.target.hasAttribute("type"))
|
||||
nsDragAndDrop.startDrag(event, this._DNDObserver);
|
||||
]]></handler>
|
||||
</handlers>
|
||||
</binding>
|
||||
|
||||
|
@ -69,7 +69,7 @@
|
||||
<!ENTITY cmd.sortby_name.accesskey
|
||||
"S">
|
||||
<!ENTITY cmd.new_folder.label
|
||||
"New Folder">
|
||||
"New Folder...">
|
||||
<!ENTITY cmd.new_folder.accesskey
|
||||
"F">
|
||||
<!ENTITY cmd.new_separator.label
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
#placesList {
|
||||
margin: 7px 0px 7px 6px;
|
||||
width: 160px;
|
||||
}
|
||||
|
||||
#placesListChildren::-moz-tree-twisty {
|
||||
|
Loading…
Reference in New Issue
Block a user