зеркало из https://github.com/mozilla/pjs.git
315940 NOT PART OF BUILD - consolidate avi functions into places tree binding, allow tree to filter self/init from query url.
This commit is contained in:
Родитель
6d1bfe1930
Коммит
a7add30863
|
@ -35,15 +35,6 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
// Abstract View Interface:
|
||||
/*
|
||||
|
||||
get selection() {
|
||||
|
||||
},
|
||||
|
||||
*/
|
||||
|
||||
const PLACES_URI = "chrome://browser/content/places/places.xul";
|
||||
|
||||
function LOG(str) {
|
||||
|
@ -62,61 +53,30 @@ const SELECTION_IS_CHANGEABLE = 0x10;
|
|||
const SELECTION_IS_REMOVABLE = 0x20;
|
||||
const SELECTION_IS_MOVABLE = 0x40;
|
||||
|
||||
/**
|
||||
* Implements nsIController, nsICommandController...
|
||||
* @param elements
|
||||
* A list of elements that this controller applies to
|
||||
* @param commandSet
|
||||
* A XUL <commandset> that contains the commands supported by this
|
||||
* controller
|
||||
* @constructor
|
||||
*/
|
||||
function PlacesController(elements, commandSet) {
|
||||
if (!commandSet || !elements)
|
||||
throw Cr.NS_ERROR_NULL_POINTER;
|
||||
|
||||
for (var i = 0; i < elements.length; ++i)
|
||||
elements[i].controllers.appendController(this);
|
||||
}
|
||||
var PlacesController = {
|
||||
};
|
||||
|
||||
PlacesController.prototype.isCommandEnabled =
|
||||
function PC_isCommandEnabled(command) {
|
||||
PlacesController.isCommandEnabled = function PC_isCommandEnabled(command) {
|
||||
LOG("isCommandEnabled: " + command);
|
||||
|
||||
};
|
||||
|
||||
PlacesController.prototype.supportsCommand =
|
||||
function PC_supportsCommand(command) {
|
||||
PlacesController.supportsCommand = function PC_supportsCommand(command) {
|
||||
//LOG("supportsCommand: " + command);
|
||||
return document.getElementById(command) != null;
|
||||
};
|
||||
|
||||
PlacesController.prototype.doCommand =
|
||||
function PC_doCommand(command) {
|
||||
PlacesController.doCommand = function PC_doCommand(command) {
|
||||
LOG("doCommand: " + command);
|
||||
|
||||
};
|
||||
|
||||
PlacesController.prototype.doCommandWithParams =
|
||||
function PC_doCommandWithParams(command) {
|
||||
LOG("doCommandWithParams: " + command);
|
||||
|
||||
};
|
||||
|
||||
PlacesController.prototype.getCommandStateWithParams =
|
||||
function PC_getCommandStateWithParams(command, params) {
|
||||
LOG("getCommandStateWithParams: " + command);
|
||||
|
||||
};
|
||||
|
||||
PlacesController.prototype.onEvent =
|
||||
function PC_onEvent(eventName) {
|
||||
PlacesController.onEvent = function PC_onEvent(eventName) {
|
||||
LOG("onEvent: " + eventName);
|
||||
|
||||
};
|
||||
|
||||
PlacesController.prototype.buildContextMenu =
|
||||
function PC_buildContextMenu(popup) {
|
||||
PlacesController.buildContextMenu = function PC_buildContextMenu(popup) {
|
||||
return true;
|
||||
};
|
||||
|
||||
|
@ -140,20 +100,6 @@ function PC_buildContextMenu(popup) {
|
|||
SELECTION_CONTAINS_REMOVABLE
|
||||
SELECTION_CONTAINS_MOVABLE
|
||||
|
||||
*/
|
||||
|
||||
PlacesController.prototype.QueryInterface =
|
||||
function PC_QueryInterface(iid) {
|
||||
if (!iid.equals(Ci.nsIController) &&
|
||||
!iid.equals(Ci.nsICommandController))
|
||||
throw Cr.NS_ERROR_NO_INTERFACE;
|
||||
return this;
|
||||
};
|
||||
|
||||
var PlacesUtils = {};
|
||||
|
||||
/*
|
||||
|
||||
Given a:
|
||||
- view, via AVI
|
||||
- query
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
.calendar {
|
||||
-moz-binding:url("chrome://browser/content/places/places.xml#calendar");
|
||||
display:-moz-box;
|
||||
-moz-binding: url("chrome://browser/content/places/places.xml#calendar");
|
||||
display: -moz-box;
|
||||
}
|
||||
|
||||
tree {
|
||||
-moz-binding: url("chrome://browser/content/places/places.xml#places-tree");
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,6 @@ var PlacesPage = {
|
|||
_tabbrowser: null,
|
||||
_topWindow: null,
|
||||
_topDocument: null,
|
||||
_populators: { },
|
||||
_bmsvc : null,
|
||||
};
|
||||
|
||||
|
@ -52,40 +51,29 @@ PlacesPage.init = function PP_init() {
|
|||
this._topDocument = this._topWindow.document;
|
||||
this._tabbrowser = this._topWindow.getBrowser();
|
||||
|
||||
// Hook into the tab strip to get notifications about when the Places Page is
|
||||
// selected so that the browser UI can be modified.
|
||||
var self = this;
|
||||
function onTabSelect(event) {
|
||||
self.onTabSelect(event);
|
||||
}
|
||||
this._tabbrowser.mTabContainer.addEventListener("select", onTabSelect, false);
|
||||
|
||||
// Attach the Command Controller to the Places Views.
|
||||
var placesList = document.getElementById("placesList");
|
||||
var placeContent = document.getElementById("placeContent");
|
||||
var placesCommands = document.getElementById("placesCommands");
|
||||
|
||||
this.controller =
|
||||
new PlacesController([placesList, placeContent], placesCommands);
|
||||
var placeContent = document.getElementById("placeContent");
|
||||
placeContent.controllers.appendController(PlacesController);
|
||||
placesList.controllers.appendController(PlacesController);
|
||||
|
||||
const NH = Ci.nsINavHistory;
|
||||
const NHQO = Ci.nsINavHistoryQueryOptions;
|
||||
const TV = Ci.nsITreeView;
|
||||
var places =
|
||||
Cc["@mozilla.org/browser/nav-history;1"].getService(NH);
|
||||
var query = places.getNewQuery();
|
||||
var date = new Date();
|
||||
var options = places.getNewQueryOptions();
|
||||
options.setGroupingMode([NHQO.GROUP_BY_HOST], 1);
|
||||
options.setSortingMode(NHQO.SORT_BY_NONE);
|
||||
options.setResultType(NHQO.RESULT_TYPE_URL);
|
||||
var result = places.executeQuery(query, options);
|
||||
result.QueryInterface(TV);
|
||||
var placeContent = document.getElementById("placeContent");
|
||||
placeContent.view = result;
|
||||
// Attach the History model to the Content View
|
||||
placeContent.queryString = "group=1";
|
||||
|
||||
// Attach the Places model to the Place View
|
||||
const BS = Ci.nsINavBookmarksService;
|
||||
this._bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].getService(BS);
|
||||
var children = this._bmsvc.getFolderChildren(this._bmsvc.placesRoot,
|
||||
BS.FOLDER_CHILDREN);
|
||||
document.getElementById("placesList").view = children.QueryInterface(TV);
|
||||
document.getElementById("placesList").view = children.QueryInterface(Ci.nsITreeView);
|
||||
|
||||
this._showPlacesUI();
|
||||
};
|
||||
|
@ -136,28 +124,11 @@ PlacesPage.applyFilter = function PP_applyFilter(filterString) {
|
|||
this.setFilterCollection("all");
|
||||
}
|
||||
else if (collectionName == "all") {
|
||||
this._buildQuery(filterString);
|
||||
var placeContent = document.getElementById("placeContent");
|
||||
placeContent.filterString = filterString;
|
||||
}
|
||||
};
|
||||
|
||||
PlacesPage._buildQuery = function PP__buildQuery(filterString) {
|
||||
const NH = Ci.nsINavHistory;
|
||||
const NHQO = Ci.nsINavHistoryQueryOptions;
|
||||
var places = Cc["@mozilla.org/browser/nav-history;1"].getService(NH);
|
||||
var query = places.getNewQuery();
|
||||
query.searchTerms = filterString;
|
||||
var options = places.getNewQueryOptions();
|
||||
options.setGroupingMode([NHQO.GROUP_BY_HOST], 1);
|
||||
options.setSortingMode(NHQO.SORT_BY_NONE);
|
||||
options.setResultType(NHQO.RESULT_TYPE_URL);
|
||||
var result = places.executeQuery(query, options);
|
||||
result.QueryInterface(Ci.nsITreeView);
|
||||
var placeContent = document.getElementById("placeContent");
|
||||
placeContent.view = result;
|
||||
placeContent.query = query;
|
||||
placeContent.options = options;
|
||||
};
|
||||
|
||||
PlacesPage._getLoadFunctionForEvent =
|
||||
function PP__getLoadFunctionForEvent(event) {
|
||||
if (event.button != 0)
|
||||
|
|
|
@ -22,50 +22,73 @@
|
|||
|
||||
<binding id="places-tree" extends="chrome://global/content/bindings/tree.xml#tree">
|
||||
<implementation>
|
||||
<property name="selectionFlags">
|
||||
<getter><![CDATA[
|
||||
// XXXben - this should be in the controller itself, not the view!
|
||||
// the view should not be making these determinations!
|
||||
const NHRN = Ci.nsINavHistoryResultNode;
|
||||
function nodeIsURL(node) {
|
||||
return (node.type == NRHN.RESULT_TYPE_URL ||
|
||||
node.type == NRHN.RESULT_TYPE_VISIT);
|
||||
}
|
||||
|
||||
function nodeIsContainer(node) {
|
||||
return !nodeIsURL(node);
|
||||
}
|
||||
|
||||
var flags = 0;
|
||||
var nodes = this.getSelectionNodes();
|
||||
var nodeCount = nodes.length;
|
||||
if (nodeCount == 1 && nodeIsContainer(nodes[0])
|
||||
flags |= SELECTION_IS_OPEN_CONTAINER; // XXXben closed container too!
|
||||
<constructor><![CDATA[
|
||||
this._places =
|
||||
Cc["@mozilla.org/browser/nav-history;1"].
|
||||
getService(Ci.nsINavHistory);
|
||||
]]></constructor>
|
||||
<property name="filterString">
|
||||
<getter><![CDATA[
|
||||
this.view.QueryInterface(Ci.nsINavHistoryResult);
|
||||
var queries = { }, queryCount = { }, options = { };
|
||||
this.view.getSourceQuery(queries, queryCount, options);
|
||||
|
||||
for (var i = 0; i < nodes.length; ++i) {
|
||||
var node = nodes[i];
|
||||
if (nodeIsURL(node))
|
||||
flags |= SELECTION_COTNAINS_URL;
|
||||
else
|
||||
flags |= SELECTION_CONTAINS_CONTAINER;
|
||||
|
||||
if (node.parent.type == Ci.nsINavHistoryResultNode.RESULT_TYPE_FOLDER &&
|
||||
!this.query.hasSearchTerms)
|
||||
flags |= SELECTION_IS_MOVABLE;
|
||||
flags |= SELECTION_IS_CHANGEABLE + SELECTION_IS_REMOVABLE;
|
||||
}
|
||||
return flags;
|
||||
if (queries.value[i].hasSearchTerms)
|
||||
return queries.value[i].searchTerms;
|
||||
return null;
|
||||
]]></getter>
|
||||
<setter><![CDATA[
|
||||
// preserve grouping
|
||||
this.view.QueryInterface(Ci.nsINavHistoryResult);
|
||||
var queries = { }, queryCount = { }, options = { };
|
||||
this.view.getSourceQuery(queries, queryCount, options);
|
||||
|
||||
var query = this._places.getNewQuery();
|
||||
query.searchTerms = val;
|
||||
|
||||
var result = this._places.executeQuery(query, options.value);
|
||||
result.QueryInterface(Ci.nsITreeView);
|
||||
this.view = result;
|
||||
|
||||
return val;
|
||||
]]></setter>
|
||||
</property>
|
||||
|
||||
<property name="queryString">
|
||||
<getter><![CDATA[
|
||||
this.view.QueryInterface(Ci.nsINavHistoryResult);
|
||||
var queries = { }, queryCount = { }, options = { };
|
||||
this.view.getSourceQuery(queries, queryCount, options);
|
||||
|
||||
const NH = Ci.nsINavHistory;
|
||||
return this._places.queriesToQueryString(queries.value,
|
||||
queryCount.value,
|
||||
options.value);
|
||||
]]></getter>
|
||||
<setter><![CDATA[
|
||||
const NH = Ci.nsINavHistory;
|
||||
const NHQO = Ci.nsINavHistoryQueryOptions;
|
||||
var places =
|
||||
Cc["@mozilla.org/browser/nav-history;1"].getService(NH);
|
||||
var queries = { }, queryCount = { }, options = { };
|
||||
this._places.queryStringToQueries(val, queries, queryCount, options);
|
||||
var result = this._places.executeQueries(queries.value,
|
||||
queryCount.value,
|
||||
options.value);
|
||||
result.QueryInterface(Components.interfaces.nsITreeView);
|
||||
this.view = result;
|
||||
return val;
|
||||
]]></setter>
|
||||
</property>
|
||||
|
||||
<property name="hasSelection">
|
||||
<getter><![CDATA[
|
||||
return this.view.selection.getRangeCount() >= 1;
|
||||
]]></getter>
|
||||
</property>
|
||||
|
||||
<property name="hasSelection">
|
||||
<getter>
|
||||
return this.view.selection.getRangeCount() >= 1;
|
||||
</getter>
|
||||
</property>
|
||||
|
||||
<property name="hasSingleSelection">
|
||||
<getter>
|
||||
<getter><![CDATA[
|
||||
var selection = this.view.selection;
|
||||
var rc = selection.getRangeCount();
|
||||
if (rc != 1)
|
||||
|
@ -73,8 +96,7 @@
|
|||
var min = { }, max = { };
|
||||
selection.getRangeAt(0, min, max);
|
||||
return (min.value == max.value);
|
||||
</getter>
|
||||
|
||||
]]></getter>
|
||||
</property>
|
||||
|
||||
<method name="getSelectionNodes">
|
||||
|
@ -113,10 +135,13 @@
|
|||
]]></getter>
|
||||
</property>
|
||||
</implementation>
|
||||
<handlers>
|
||||
<handler event="select"><![CDATA[
|
||||
document.commandDispatcher.updateCommands("select");
|
||||
]]></handler>
|
||||
</handlers>
|
||||
</binding>
|
||||
|
||||
|
||||
|
||||
<binding id="calendar">
|
||||
<content>
|
||||
<xul:vbox class="calendar-box">
|
||||
|
|
|
@ -3,6 +3,7 @@ browser.jar:
|
|||
* content/browser/places/places.xul (content/places.xul)
|
||||
* content/browser/places/places.js (content/places.js)
|
||||
* content/browser/places/places.xml (content/places.xml)
|
||||
* content/browser/places/places.css (content/places.css)
|
||||
* content/browser/places/controller.js (content/controller.js)
|
||||
* content/browser/places/browserShim.js (content-shim/browserShim.js)
|
||||
* content/browser/places/browserShim.xul (content-shim/browserShim.xul)
|
||||
|
|
Загрузка…
Ссылка в новой задаче