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;
|
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
|
* Copy Bookmarks and Folders to the clipboard
|
||||||
*/
|
*/
|
||||||
@ -684,45 +730,23 @@ var PlacesController = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
var self = this;
|
||||||
* Wraps a string in a nsISupportsString wrapper
|
function addData(type, data) {
|
||||||
* @param str
|
xferable.addDataFlavor(type);
|
||||||
* The string to wrap
|
xferable.setTransferData(type, self._wrapString(data), data.length * 2);
|
||||||
* @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);
|
|
||||||
}
|
}
|
||||||
|
// 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 ||
|
if (pcString || placeString || unicodeString || htmlString ||
|
||||||
mozURLString) {
|
mozURLString) {
|
||||||
@ -884,7 +908,7 @@ var PlacesControllerDragHelper = {
|
|||||||
* @param orientation
|
* @param orientation
|
||||||
* The orientation of the drop
|
* The orientation of the drop
|
||||||
*/
|
*/
|
||||||
onDrop: function PCDH_onDrop(view, container, index) {
|
onDrop: function PCDH_onDrop(view, container, index, orientation) {
|
||||||
var session = this._getSession();
|
var session = this._getSession();
|
||||||
if (!session)
|
if (!session)
|
||||||
return;
|
return;
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
#historyCalendar {
|
#historyCalendar {
|
||||||
-moz-binding: url("chrome://browser/content/places/places.xml#calendar");
|
-moz-binding: url("chrome://browser/content/places/places.xml#calendar");
|
||||||
display: -moz-box;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#searchFilter {
|
#searchFilter {
|
||||||
|
@ -97,7 +97,6 @@ var PlacesUIHook = {
|
|||||||
var PlacesPage = {
|
var PlacesPage = {
|
||||||
_content: null,
|
_content: null,
|
||||||
_places: null,
|
_places: null,
|
||||||
_bmsvc : null,
|
|
||||||
|
|
||||||
init: function PP_init() {
|
init: function PP_init() {
|
||||||
// Attach the Command Controller to the Places Views.
|
// Attach the Command Controller to the Places Views.
|
||||||
@ -117,7 +116,7 @@ var PlacesPage = {
|
|||||||
PlacesUIHook.init(this._content);
|
PlacesUIHook.init(this._content);
|
||||||
|
|
||||||
// Attach the History model to the Content View
|
// Attach the History model to the Content View
|
||||||
this._content.queryString = "group=1";
|
this._content.queryString = "";
|
||||||
|
|
||||||
// Attach the Places model to the Place View
|
// Attach the Places model to the Place View
|
||||||
// XXXben - move this to an attribute/property on the tree view
|
// XXXben - move this to an attribute/property on the tree view
|
||||||
@ -190,7 +189,7 @@ var PlacesPage = {
|
|||||||
filterCollectionDeck.selectedPanel = document.getElementById(filterButtonID);
|
filterCollectionDeck.selectedPanel = document.getElementById(filterButtonID);
|
||||||
|
|
||||||
// Hide the Calendar for Bookmark queries.
|
// Hide the Calendar for Bookmark queries.
|
||||||
document.getElementById("historyCalendar").hidden = isBookmarks;
|
document.getElementById("historyCalendar").setAttribute("hidden", isBookmarks);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -151,6 +151,8 @@
|
|||||||
<setter><![CDATA[
|
<setter><![CDATA[
|
||||||
var queries = { }, options = { };
|
var queries = { }, options = { };
|
||||||
this._places.queryStringToQueries(val, queries, { }, options);
|
this._places.queryStringToQueries(val, queries, { }, options);
|
||||||
|
if (!queries.value.length)
|
||||||
|
queries.value = [this._places.getNewQuery()];
|
||||||
this.load(queries.value, options.value);
|
this.load(queries.value, options.value);
|
||||||
return val;
|
return val;
|
||||||
]]></setter>
|
]]></setter>
|
||||||
@ -307,76 +309,31 @@
|
|||||||
]]></body>
|
]]></body>
|
||||||
</method>
|
</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[({
|
<field name="_DNDObserver"><![CDATA[({
|
||||||
// XXXben ew.
|
// XXXben ew.
|
||||||
_self: this,
|
_self: this,
|
||||||
onDragStart: function(event, xferData, dragAction) {
|
onDragStart: function(event, xferData, dragAction) {
|
||||||
if (this._self.getAttribute("sortActive") == "true")
|
if (this._self.getAttribute("sortActive") == "true")
|
||||||
throw Components.results.NS_OK;
|
throw Components.results.NS_OK;
|
||||||
xferData.data = this._self._getTransferData();
|
xferData.data = PlacesController.getTransferData();
|
||||||
// XXXben - the drag wrapper should do this automatically.
|
// XXXben - the drag wrapper should do this automatically.
|
||||||
if (event.ctrlKey)
|
if (event.ctrlKey)
|
||||||
dragAction.action = Ci.nsIDragService.DRAGDROP_ACTION_COPY;
|
dragAction.action = Ci.nsIDragService.DRAGDROP_ACTION_COPY;
|
||||||
},
|
},
|
||||||
|
canDrop: function(event, session) {
|
||||||
onDragOver: function(event, flavor, dragSession) {
|
return this._self._viewObserver.canDrop(-1, -1);
|
||||||
if (dragSession.sourceNode == this._self)
|
},
|
||||||
dragSession.canDrop = true;
|
onDragOver: function(event, flavor, session) {
|
||||||
},
|
},
|
||||||
|
|
||||||
_flavorSet: null,
|
|
||||||
getSupportedFlavours: function() {
|
getSupportedFlavours: function() {
|
||||||
if (!this._flavorSet) {
|
var flavorSet = new FlavourSet();
|
||||||
this._flavorSet = new FlavourSet();
|
|
||||||
for (var i = 0; i < this._self.supportedDropTypes.length; ++i)
|
for (var i = 0; i < this._self.supportedDropTypes.length; ++i)
|
||||||
this._flavorSet.appendFlavour(this._self.supportedDropTypes[i]);
|
flavorSet.appendFlavour(this._self.supportedDropTypes[i]);
|
||||||
}
|
return flavorSet;
|
||||||
return this._flavorSet;
|
},
|
||||||
}
|
|
||||||
})]]></field>
|
})]]></field>
|
||||||
|
|
||||||
<field name="_viewObserver"><![CDATA[
|
<field name="_viewObserver"><![CDATA[({
|
||||||
({
|
|
||||||
_self: this,
|
_self: this,
|
||||||
|
|
||||||
canDrop: function VO_canDrop(index, orientation) {
|
canDrop: function VO_canDrop(index, orientation) {
|
||||||
@ -392,13 +349,20 @@
|
|||||||
const NHRVO = Ci.nsINavHistoryResultViewObserver;
|
const NHRVO = Ci.nsINavHistoryResultViewObserver;
|
||||||
var result = this._self.getResult();
|
var result = this._self.getResult();
|
||||||
var view = this._self.view;
|
var view = this._self.view;
|
||||||
var node = result.nodeForTreeIndex(index);
|
var node = index != -1 ? result.nodeForTreeIndex(index) : null;
|
||||||
var destContainer = null;
|
var destContainer = null;
|
||||||
var destIndex = -1;
|
var destIndex = -1;
|
||||||
// If we're dropping _on_ a container, the container is the container
|
if (!node) {
|
||||||
// we dropped on, otherwise it's the parent of the drop target.
|
// Dropping in some blank area of the view, just use the result as
|
||||||
if (view.isContainer(index) && orientation == NHRVO.DROP_ON)
|
// 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;
|
destContainer = node.folderId;
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
var destIndex = PlacesController.getIndexOfNode(node);
|
var destIndex = PlacesController.getIndexOfNode(node);
|
||||||
// For non leaves, or when not dropping _on_ a container, drop after
|
// For non leaves, or when not dropping _on_ a container, drop after
|
||||||
@ -421,8 +385,7 @@
|
|||||||
onPerformAction: function VO_onPerformAction(action) { },
|
onPerformAction: function VO_onPerformAction(action) { },
|
||||||
onPerformActionOnRow: function VO_onPerformActionOnRow(action, row) { },
|
onPerformActionOnRow: function VO_onPerformActionOnRow(action, row) { },
|
||||||
onPerformActionOnCell: function VO_onPerformActionOnCell(action, row, column) { },
|
onPerformActionOnCell: function VO_onPerformActionOnCell(action, row, column) { },
|
||||||
})
|
})]]></field>
|
||||||
]]></field>
|
|
||||||
|
|
||||||
<method name="_reloadView">
|
<method name="_reloadView">
|
||||||
<body><![CDATA[
|
<body><![CDATA[
|
||||||
@ -501,6 +464,10 @@
|
|||||||
if (event.target.localName == "treechildren")
|
if (event.target.localName == "treechildren")
|
||||||
nsDragAndDrop.startDrag(event, this._DNDObserver);
|
nsDragAndDrop.startDrag(event, this._DNDObserver);
|
||||||
]]></handler>
|
]]></handler>
|
||||||
|
<handler event="dragover"><![CDATA[
|
||||||
|
if (event.target.localName == "treechildren")
|
||||||
|
nsDragAndDrop.dragOver(event, this._DNDObserver);
|
||||||
|
]]></handler>
|
||||||
</handlers>
|
</handlers>
|
||||||
</binding>
|
</binding>
|
||||||
|
|
||||||
|
@ -99,7 +99,8 @@
|
|||||||
</hbox>
|
</hbox>
|
||||||
<deck id="content" flex="1">
|
<deck id="content" flex="1">
|
||||||
<vbox 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);"
|
ondblclick="PlacesController.mouseLoadURI(event);"
|
||||||
onplacestreereloaded="PlacesPage.onContentChanged();">
|
onplacestreereloaded="PlacesPage.onContentChanged();">
|
||||||
<treecols>
|
<treecols>
|
||||||
|
@ -181,15 +181,35 @@
|
|||||||
this._self.init();
|
this._self.init();
|
||||||
},
|
},
|
||||||
})]]></field>
|
})]]></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>
|
</implementation>
|
||||||
<handlers>
|
<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")
|
if (event.target.localName != "toolbarbutton")
|
||||||
return;
|
return;
|
||||||
this._selection = event.target.node;
|
this._selection = event.target.node;
|
||||||
PlacesController.activeView = this;
|
PlacesController.activeView = this;
|
||||||
|
]]></handler>
|
||||||
|
<handler event="click">
|
||||||
PlacesController.mouseLoadURI(event);
|
PlacesController.mouseLoadURI(event);
|
||||||
</handler>
|
</handler>
|
||||||
|
<handler event="draggesture"><![CDATA[
|
||||||
|
// XXXben ew.
|
||||||
|
if (event.target.localName == "toolbarbutton" &&
|
||||||
|
!event.target.hasAttribute("type"))
|
||||||
|
nsDragAndDrop.startDrag(event, this._DNDObserver);
|
||||||
|
]]></handler>
|
||||||
</handlers>
|
</handlers>
|
||||||
</binding>
|
</binding>
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@
|
|||||||
<!ENTITY cmd.sortby_name.accesskey
|
<!ENTITY cmd.sortby_name.accesskey
|
||||||
"S">
|
"S">
|
||||||
<!ENTITY cmd.new_folder.label
|
<!ENTITY cmd.new_folder.label
|
||||||
"New Folder">
|
"New Folder...">
|
||||||
<!ENTITY cmd.new_folder.accesskey
|
<!ENTITY cmd.new_folder.accesskey
|
||||||
"F">
|
"F">
|
||||||
<!ENTITY cmd.new_separator.label
|
<!ENTITY cmd.new_separator.label
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
#placesList {
|
#placesList {
|
||||||
margin: 7px 0px 7px 6px;
|
margin: 7px 0px 7px 6px;
|
||||||
|
width: 160px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#placesListChildren::-moz-tree-twisty {
|
#placesListChildren::-moz-tree-twisty {
|
||||||
|
Loading…
Reference in New Issue
Block a user