Resubmitting this patch, which adds a editing for livemark URIs as well

as fixing a few small livemark bugs, now that I've fixed a couple reference
leaks in nsLivemarkService (see bugs 333764 and 333784).

NOTE: I expect this to cause an increase in allocations on branch balsa,
since it causes nsLivemarkService to be instantiated to set up the menus.
(nsLivemarkService previously wasn't used in the balsa bloat test)

bug=330063
r=annie.sullivan@gmail.com
sr=ben@mozilla.org


git-svn-id: svn://10.0.0.236/trunk@194326 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
joe%retrovirus.com
2006-04-13 17:20:31 +00:00
parent 310ad3cac7
commit 60817e663a
9 changed files with 278 additions and 39 deletions

View File

@@ -365,12 +365,17 @@ var BookmarksEventHandler = {
var button = target.parentNode;
if (button.getAttribute("livemark") == "true") {
var openHomePage = document.createElement("menuitem");
openHomePage.setAttribute("siteURI", button.getAttribute("siteURI"));
openHomePage.setAttribute("label",
strings.getFormattedString("menuOpenLivemarkOrigin.label",
[button.getAttribute("label")]));
target.appendChild(openHomePage);
// Live bookmarks aren't required to have site URIs
if (button.hasAttribute("siteURI")) {
var openHomePage = document.createElement("menuitem");
openHomePage.setAttribute(
"siteURI", button.getAttribute("siteURI"));
openHomePage.setAttribute(
"label",
strings.getFormattedString("menuOpenLivemarkOrigin.label",
[button.getAttribute("label")]));
target.appendChild(openHomePage);
}
}
var openInTabs = document.createElement("menuitem");

View File

@@ -89,18 +89,32 @@ var BookmarkPropertiesPanel = {
return this.__ios;
},
/**
* The Live Bookmark service for dealing with syndication feed folders.
*/
__livemarks: null,
get _livemarks() {
if (!this.__livemarks) {
this.__livemarks =
Cc["@mozilla.org/browser/livemark-service;1"].
getService(Ci.nsILivemarkService);
}
return this.__livemarks;
},
_bookmarkURI: null,
_bookmarkTitle: "",
_dialogWindow: null,
_parentWindow: null,
_controller: null,
MAX_INDENT_DEPTH: 6, // maximum indentation level of "tag" display
EDIT_BOOKMARK_VARIANT: 0,
ADD_BOOKMARK_VARIANT: 1,
EDIT_HISTORY_VARIANT: 2,
EDIT_FOLDER_VARIANT: 3,
ADD_MULTIPLE_BOOKMARKS_VARIANT: 4,
ADD_LIVEMARK_VARIANT: 5,
EDIT_LIVEMARK_VARIANT: 6,
/**
* The variant identifier for the current instance of the dialog.
@@ -121,6 +135,8 @@ var BookmarkPropertiesPanel = {
switch(this._variant) {
case this.EDIT_FOLDER_VARIANT:
case this.ADD_MULTIPLE_BOOKMARKS_VARIANT:
case this.ADD_LIVEMARK_VARIANT:
case this.EDIT_LIVEMARK_VARIANT:
return false;
default:
return true;
@@ -135,6 +151,7 @@ var BookmarkPropertiesPanel = {
_identifierIsFolderID: function BPP__identifierIsFolderID() {
switch(this._variant) {
case this.EDIT_FOLDER_VARIANT:
case this.EDIT_LIVEMARK_VARIANT:
return true;
default:
return false;
@@ -161,6 +178,8 @@ var BookmarkPropertiesPanel = {
case this.EDIT_HISTORY_VARIANT:
case this.EDIT_FOLDER_VARIANT:
case this.ADD_MULTIPLE_BOOKMARKS_VARIANT:
case this.EDIT_LIVEMARK_VARIANT:
case this.ADD_LIVEMARK_VARIANT:
return false;
default:
return true;
@@ -174,6 +193,8 @@ var BookmarkPropertiesPanel = {
switch(this._variant) {
case this.EDIT_FOLDER_VARIANT:
case this.ADD_MULTIPLE_BOOKMARKS_VARIANT:
case this.EDIT_LIVEMARK_VARIANT:
case this.ADD_LIVEMARK_VARIANT:
return false;
default:
return true;
@@ -189,12 +210,28 @@ var BookmarkPropertiesPanel = {
case this.EDIT_HISTORY_VARIANT:
case this.EDIT_FOLDER_VARIANT:
case this.ADD_MULTIPLE_BOOKMARKS_VARIANT:
case this.ADD_LIVEMARK_VARIANT:
case this.EDIT_LIVEMARK_VARIANT:
return false;
default:
return true;
}
},
/**
* Returns true if the livemark feed and site URI fields are visible.
*/
_areLivemarkURIsVisible: function BPP__areLivemarkURIsVisible() {
switch(this._variant) {
case this.ADD_LIVEMARK_VARIANT:
case this.EDIT_LIVEMARK_VARIANT:
return true;
default:
return false;
}
},
/**
* Returns true if bookmark deletion is possible from the current
* variant of the dialog.
@@ -232,6 +269,7 @@ var BookmarkPropertiesPanel = {
_getAcceptLabel: function BPP__getAcceptLabel() {
switch(this._variant) {
case this.ADD_BOOKMARK_VARIANT:
case this.ADD_LIVEMARK_VARIANT:
return this._strings.getString("dialogAcceptLabelAdd");
case this.ADD_MULTIPLE_BOOKMARKS_VARIANT:
return this._strings.getString("dialogAcceptLabelAddMulti");
@@ -254,6 +292,8 @@ var BookmarkPropertiesPanel = {
return this._strings.getString("dialogTitleFolderEdit");
case this.ADD_MULTIPLE_BOOKMARKS_VARIANT:
return this._strings.getString("dialogTitleAddMulti");
case this.ADD_LIVEMARK_VARIANT:
return this._strings.getString("dialogTitleAddLivemark");
default:
return this._strings.getString("dialogTitleBookmarkEdit");
}
@@ -271,6 +311,7 @@ var BookmarkPropertiesPanel = {
switch(this._variant) {
case this.ADD_MULTIPLE_BOOKMARKS_VARIANT:
case this.EDIT_FOLDER_VARIANT:
case this.EDIT_LIVEMARK_VARIANT:
return "single";
default:
return "multiple";
@@ -316,8 +357,14 @@ var BookmarkPropertiesPanel = {
return this.ADD_MULTIPLE_BOOKMARKS_VARIANT;
}
else { /* Assume "edit" */
if (typeof(identifier) == "number")
return this.EDIT_FOLDER_VARIANT;
if (typeof(identifier) == "number") {
if (this._livemarks.isLivemark(identifier)) {
return this.EDIT_LIVEMARK_VARIANT;
}
else {
return this.EDIT_FOLDER_VARIANT;
}
}
if (this._bms.isBookmarked(identifier)) {
return this.EDIT_BOOKMARK_VARIANT;
@@ -410,6 +457,29 @@ var BookmarkPropertiesPanel = {
this._folderTree._load([query], options);
},
/**
* This is a shorter form of getElementById for the dialog document.
* Given a XUL element ID from the dialog, returns the corresponding
* DOM element.
*
* @param XUL element ID
* @returns corresponding DOM element, or null if none found
*/
_element: function BPP__element(id) {
return this._dialogWindow.document.getElementById(id);
},
/**
* Hides the XUL element with the given ID.
*
* @param string ID of the XUL element to hide
*/
_hide: function BPP__hide(id) {
this._element(id).setAttribute("hidden", "true");
},
/**
* This method fills in the data values for the fields in the dialog.
*/
@@ -433,9 +503,9 @@ var BookmarkPropertiesPanel = {
"true";
}
var nurl = document.getElementById("editURLBar");
var nurl = this._element("editURLBar");
var titlebox = document.getElementById("editTitleBox");
var titlebox = this._element("editTitleBox");
titlebox.value = this._bookmarkTitle;
@@ -449,28 +519,36 @@ var BookmarkPropertiesPanel = {
nurl.setAttribute("disabled", "true");
}
else {
var locationRow = document.getElementById("locationRow");
locationRow.setAttribute("hidden", "true");
this._hide("locationRow");
}
if (this._areLivemarkURIsVisible()) {
if (this._identifierIsFolderID()) {
var feedURI = this._livemarks.getFeedURI(this._folderId);
if (feedURI)
this._element("editLivemarkFeedLocationBox").value = feedURI.spec;
var siteURI = this._livemarks.getSiteURI(this._folderId);
if (siteURI)
this._element("editLivemarkSiteLocationBox").value = siteURI.spec;
}
} else {
this._hide("livemarkFeedLocationRow");
this._hide("livemarkSiteLocationRow");
}
if (this._isShortcutVisible()) {
var shortcutbox =
this._dialogWindow.document.getElementById("editShortcutBox");
var shortcutbox = this._element("editShortcutBox");
shortcutbox.value = this._bms.getKeywordForURI(this._bookmarkURI);
}
else {
var shortcutRow =
this._dialogWindow.document.getElementById("shortcutRow");
shortcutRow.setAttribute("hidden", "true");
this._hide("shortcutRow");
}
if (this._isFolderEditable()) {
this._folderTree.selectFolders([this._bms.bookmarksRoot]);
}
else {
var folderRow =
this._dialogWindow.document.getElementById("folderRow");
folderRow.setAttribute("hidden", "true");
this._hide("folderRow");
}
},
@@ -535,14 +613,71 @@ var BookmarkPropertiesPanel = {
this._controller.tm.doTransaction(aggregate);
},
/**
* This method checks the current state of the input fields in the
* dialog, and if any of them are in an invalid state, it will disable
* the submit button. This method should be called after every
* significant change to the input.
*/
validateChanges: function BPP_validateChanges() {
this._dialogWindow.document.documentElement.getButton("accept").disabled =
!this._inputIsValid();
},
/**
* This method checks to see if the input fields are in a valid state.
*
* @returns true if the input is valid, false otherwise
*/
_inputIsValid: function BPP__inputIsValid() {
// When in multiple select mode, it's possible to deselect all rows,
// but you have to file your bookmark in at least one folder.
if (this._isFolderEditable()) {
if (this._folderTree.getSelectionNodes().length == 0)
return false;
}
if (this._isURIEditable() && !this._containsValidURI("editURLBar"))
return false;
// Feed Location has to be a valid URI;
// Site Location has to be a valid URI or empty
if (this._areLivemarkURIsVisible()) {
if (!this._containsValidURI("editLivemarkFeedLocationBox"))
return false;
if (!this._containsValidURI("editLivemarkSiteLocationBox") &&
(this._element("editLivemarkSiteLocationBox").value.length > 0))
return false;
}
return true;
},
/**
* Determines whether the XUL textbox with the given ID contains a
* string that can be converted into an nsIURI.
*
* @param textboxID the ID of the textbox element whose contents we'll test
*
* @returns true if the textbox contains a valid URI string, false otherwise
*/
_containsValidURI: function BPP__containsValidURI(textboxID) {
try {
var uri = this._uri(this._element(textboxID).value);
} catch (e) {
return false;
}
return true;
},
/**
* Save any changes that might have been made while the properties dialog
* was open.
*/
_saveChanges: function PBD_saveChanges() {
_saveChanges: function BPP__saveChanges() {
var transactions = [];
var urlbox = this._dialogWindow.document.getElementById("editURLBar");
var titlebox = this._dialogWindow.document.getElementById("editTitleBox");
var urlbox = this._element("editURLBar");
var titlebox = this._element("editTitleBox");
var newURI = this._bookmarkURI;
if (this._identifierIsURI() && this._isURIEditable())
newURI = this._uri(urlbox.value);
@@ -588,13 +723,34 @@ var BookmarkPropertiesPanel = {
if (this._identifierIsURI())
transactions.push(
new PlacesEditItemTitleTransaction(newURI, titlebox.value));
else if (this._identifierIsFolderID())
else if (this._identifierIsFolderID()) {
if (this._areLivemarkURIsVisible()) {
if (this._identifierIsFolderID()) {
var feedURIString =
this._element("editLivemarkFeedLocationBox").value;
var feedURI = this._uri(feedURIString);
transactions.push(
new PlacesEditLivemarkFeedURITransaction(this._folderId, feedURI));
// Site Location is empty, we can set its URI to null
var siteURI = null;
var siteURIString =
this._element("editLivemarkSiteLocationBox").value;
if (siteURIString.length > 0)
siteURI = this._uri(siteURIString);
transactions.push(
new PlacesEditLivemarkSiteURITransaction(this._folderId, siteURI));
}
}
transactions.push(
new PlacesEditFolderTitleTransaction(this._folderId, titlebox.value));
}
if (this._isShortcutVisible()) {
var shortcutbox =
this._dialogWindow.document.getElementById("editShortcutBox");
this._element("editShortcutBox");
transactions.push(
new PlacesEditBookmarkKeywordTransaction(this._bookmarkURI,
shortcutbox.value));

View File

@@ -50,7 +50,26 @@
<label value="&bookmark.property.location;" align="middle"/>
</hbox>
</vbox>
<textbox id="editURLBar" size="10"/>
<textbox id="editURLBar" size="10"
onchange="BookmarkPropertiesPanel.validateChanges()"/>
</row>
<row id="livemarkFeedLocationRow">
<vbox align="end">
<hbox align="center" flex="1">
<label value="&livemark.property.feed_uri;" align="middle"/>
</hbox>
</vbox>
<textbox id="editLivemarkFeedLocationBox"
onchange="BookmarkPropertiesPanel.validateChanges()"/>
</row>
<row id="livemarkSiteLocationRow">
<vbox align="end">
<hbox align="center" flex="1">
<label value="&livemark.property.site_uri;" align="middle"/>
</hbox>
</vbox>
<textbox id="editLivemarkSiteLocationBox"
onchange="BookmarkPropertiesPanel.validateChanges()"/>
</row>
<row id="shortcutRow">
<vbox align="end">
@@ -73,7 +92,8 @@
type="places"
place="place:&amp;folder=1&amp;group=3&amp;excludeItems=1"
hidecolumnpicker="true"
seltype="multiple">
seltype="multiple"
onselect="BookmarkPropertiesPanel.validateChanges()">
<treecols>
<treecol id="title"
flex="1"

View File

@@ -2221,6 +2221,8 @@ function PlacesBaseTransaction() {
PlacesBaseTransaction.prototype = {
bookmarks: Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
getService(Ci.nsINavBookmarksService),
livemarks: Cc["@mozilla.org/browser/livemark-service;1"].
getService(Ci.nsILivemarkService),
LOG: LOG,
redoTransaction: function PIT_redoTransaction() {
throw Cr.NS_ERROR_NOT_IMPLEMENTED;
@@ -2595,3 +2597,49 @@ PlacesEditBookmarkKeywordTransaction.prototype = {
this.bookmarks.setKeywordForURI(this._uri, this._oldKeyword);
}
};
/**
* Edit a live bookmark's site URI.
*/
function PlacesEditLivemarkSiteURITransaction(folderId, uri) {
this._folderId = folderId;
this._newURI = uri;
this._oldURI = null;
this.redoTransaction = this.doTransaction;
}
PlacesEditLivemarkSiteURITransaction.prototype = {
__proto__: PlacesBaseTransaction.prototype,
doTransaction: function PELSUT_doTransaction() {
this._oldURI = this.livemarks.getSiteURI(this._folderId);
this.livemarks.setSiteURI(this._folderId, this._newURI);
},
undoTransaction: function PELSUT_undoTransaction() {
this.livemarks.setSiteURI(this._folderId, this._oldURI);
}
};
/**
* Edit a live bookmark's feed URI.
*/
function PlacesEditLivemarkFeedURITransaction(folderId, uri) {
this._folderId = folderId;
this._newURI = uri;
this._oldURI = null;
this.redoTransaction = this.doTransaction;
}
PlacesEditLivemarkFeedURITransaction.prototype = {
__proto__: PlacesBaseTransaction.prototype,
doTransaction: function PELFUT_doTransaction() {
this._oldURI = this.livemarks.getFeedURI(this._folderId);
this.livemarks.setFeedURI(this._folderId, this._newURI);
this.livemarks.reloadLivemarkFolder(this._folderId);
},
undoTransaction: function PELFUT_undoTransaction() {
this.livemarks.setFeedURI(this._folderId, this._oldURI);
this.livemarks.reloadLivemarkFolder(this._folderId);
}
};

View File

@@ -196,12 +196,13 @@
var bms =
Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
getService(Ci.nsINavBookmarksService);
var folderURI = bms.getFolderURI(folder);
var anno =
Cc["@mozilla.org/browser/annotation-service;1"].
getService(Ci.nsIAnnotationService);
var siteURI = anno.getAnnotationString(folderURI, "livemark/siteURI");
element.setAttribute("siteURI", siteURI);
var lms =
Cc["@mozilla.org/browser/livemark-service;1"].
getService(Ci.nsILivemarkService);
var siteURI = lms.getSiteURI(folder);
if (siteURI) {
element.setAttribute("siteURI", siteURI.spec);
}
}
var popup = document.createElementNS(XULNS, "menupopup");

View File

@@ -77,6 +77,9 @@
this._anno =
Cc["@mozilla.org/browser/annotation-service;1"].
getService(Ci.nsIAnnotationService);
this._lms =
Cc["@mozilla.org/browser/livemark-service;1"].
getService(Ci.nsILivemarkService);
this._bms.addObserver(this._observer, false);
var t = this;
@@ -179,9 +182,10 @@
if (PlacesController.nodeIsLivemarkContainer(child)) {
button.setAttribute("livemark", "true");
var folder = asFolder(child).folderId;
var folderURI = this._bms.getFolderURI(folder);
var siteURI = this._anno.getAnnotationString(folderURI, "livemark/siteURI");
button.setAttribute("siteURI", siteURI);
var siteURI = this._lms.getSiteURI(folder);
if (siteURI) {
button.setAttribute("siteURI", siteURI.spec);
}
}
var popup = document.createElementNS(XULNS, "menupopup");
popup.setAttribute("type", "places");
@@ -733,7 +737,7 @@
return function() { meth.apply(obj, arguments); }
}
setTimeout(hitch(this._self, this._self._rebuild), 1);
},
}
})]]></field>

View File

@@ -466,7 +466,7 @@ nsLivemarkService::SetFeedURI(PRInt64 aContainer, nsIURI *aFeedURI)
// Now update our internal table
PRInt32 livemarkIndex = GetLivemarkIndex(aContainer);
NS_ENSURE_TRUE(livemarkIndex == -1, NS_ERROR_FAILURE);
NS_ENSURE_TRUE(livemarkIndex > -1, NS_ERROR_FAILURE);
mLivemarks[livemarkIndex]->feedURI = aFeedURI;

View File

@@ -12,6 +12,10 @@
"Folder List">
<!ENTITY bookmark.property.parents
"Visible In">
<!ENTITY livemark.property.feed_uri
"Feed Location">
<!ENTITY livemark.property.site_uri
"Site Location">
<!ENTITY cmd.delete_bookmark.label
"Delete Bookmark">
<!ENTITY cmd.accept.edit

View File

@@ -6,3 +6,4 @@ dialogTitleAddMulti=Bookmark All Tabs
dialogTitleBookmarkEdit=Bookmark Properties
dialogTitleHistoryEdit=Viewed Page Properties
dialogTitleFolderEdit=Edit Folder Properties
dialogTitleAddLivemark=Add Live Bookmark