When using various bookmark commands, now prompt for arguments. Prevent invalid arguments (for example, disallow deletion of the "Personal Toolbar Folder").

git-svn-id: svn://10.0.0.236/trunk@63856 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
rjc%netscape.com 2000-03-23 10:33:03 +00:00
parent 4d9f5aa998
commit 000d6c680a
3 changed files with 128 additions and 33 deletions

View File

@ -336,6 +336,14 @@ function doDelete(promptFlag)
if (!node) continue;
var ID = node.getAttribute("id");
if (!ID) continue;
// don't allow deletion of various "special" folders
if ((ID == "NC:BookmarksRoot") || (ID == "NC:PersonalToolbarFolder") ||
(ID == "NC:IEFavoritesRoot"))
{
continue;
}
var parentID = node.parentNode.parentNode.getAttribute("ref");
if (!parentID) parentID = node.parentNode.parentNode.getAttribute("id");
if (!parentID) continue;
@ -691,6 +699,37 @@ function doContextCmd(cmdName)
{
debug("doContextCmd start: cmd='" + cmdName + "'");
var bundle = srGetStrBundle("chrome://bookmarks/locale/bookmark.properties");
// do some prompting/confirmation for various bookmark commands that we know about;
// if we have values to pass it, they are added to the arguments array
var nameVal = "", urlVal = "";
if (cmdName == "http://home.netscape.com/NC-rdf#command?cmd=newbookmark")
{
var promptStr = bundle.GetStringFromName("NewBookmarkURLPrompt");
urlVal = prompt(promptStr, "");
if (!urlVal || urlVal=="") return(false);
promptStr = bundle.GetStringFromName("NewBookmarkNamePrompt");
nameVal = prompt(promptStr, "");
if (!nameVal || nameVal=="") return(false);
}
else if (cmdName == "http://home.netscape.com/NC-rdf#command?cmd=newfolder")
{
var promptStr = bundle.GetStringFromName("NewFolderNamePrompt");
nameVal = prompt(promptStr, "");
if (!nameVal || nameVal=="") return(false);
}
else if ((cmdName == "http://home.netscape.com/NC-rdf#command?cmd=deletebookmark") ||
(cmdName == "http://home.netscape.com/NC-rdf#command?cmd=deletebookmarkfolder") ||
(cmdName == "http://home.netscape.com/NC-rdf#command?cmd=deletebookmarkseparator"))
{
var promptStr = bundle.GetStringFromName("DeleteItems");
if (!confirm(promptStr)) return(false);
}
var treeNode = document.getElementById("bookmarksTree");
if (!treeNode) return(false);
var db = treeNode.database;
@ -718,9 +757,13 @@ function doContextCmd(cmdName)
var argumentsInstance = Components.classes["component://netscape/supports-array"].createInstance();
var argumentsArray = argumentsInstance.QueryInterface(Components.interfaces.nsISupportsArray);
// get argument (parent)
// get various arguments (parent, name)
var parentArc = rdf.GetResource("http://home.netscape.com/NC-rdf#parent");
if (!parentArc) return(false);
if (!parentArc) return(false);
var nameArc = rdf.GetResource("http://home.netscape.com/NC-rdf#Name");
if (!nameArc) return(false);
var urlArc = rdf.GetResource("http://home.netscape.com/NC-rdf#URL");
if (!urlArc) return(false);
var select_list = treeNode.selectedItems;
debug("# of Nodes selected: " + select_list.length);
@ -773,9 +816,24 @@ function doContextCmd(cmdName)
var parentNode = rdf.GetResource(parentURI, true);
if (!parentNode) return(false);
// add parent arc and node into arguments array
// add arguments into arguments array
argumentsArray.AppendElement(parentArc);
argumentsArray.AppendElement(parentNode);
if ((nameVal) && (nameVal != ""))
{
var nameLiteral = rdf.GetLiteral(nameVal);
if (!nameLiteral) return(false);
argumentsArray.AppendElement(nameArc);
argumentsArray.AppendElement(nameLiteral);
}
if ((urlVal) && (urlVal != ""))
{
var urlLiteral = rdf.GetLiteral(urlVal);
if (!urlLiteral) return(false);
argumentsArray.AppendElement(urlArc);
argumentsArray.AppendElement(urlLiteral);
}
}
// do the command
@ -784,18 +842,3 @@ function doContextCmd(cmdName)
debug("doContextCmd ends.");
return(true);
}
function dumpAttributes(node) {
debug("Attributes for " + node.nodeName);
debug("type=" + node.nodeType);
debug("value=" + node.nodeValue);
var attributes = node.attributes
if (!attributes || attributes.length == 0) {
debug("no attributes")
}
for (var ii=0; ii < attributes.length; ii++) {
var attr = attributes.item(ii)
debug("att "+ii+": "+ attr.name +"="+attr.value)
}
}

View File

@ -34,6 +34,10 @@ ImportedNetPositiveBookmarks = Imported NetPositive Bookmarks
DefaultPersonalToolbarFolder = Personal Toolbar Folder
NewBookmarkURLPrompt = Enter a URL for the new bookmark:
NewBookmarkNamePrompt = Enter a name for the new bookmark:
NewFolderNamePrompt = Enter a name for the new folder:
DeleteItems = Delete the selected item(s)?
WebPageUpdated = The following web page has been updated:

View File

@ -1570,7 +1570,7 @@ nsresult GetBookmarkToPing(nsIRDFResource **theBookmark);
nsIRDFResource *property, const char *htmlAttrib, PRBool isFirst);
PRBool CanAccept(nsIRDFResource* aSource, nsIRDFResource* aProperty, nsIRDFNode* aTarget);
nsresult getArgumentN(nsISupportsArray *arguments, nsIRDFResource *res, PRInt32 offset, nsIRDFResource **argValue);
nsresult getArgumentN(nsISupportsArray *arguments, nsIRDFResource *res, PRInt32 offset, nsIRDFNode **argValue);
nsresult insertBookmarkItem(nsIRDFResource *src, nsISupportsArray *aArguments, PRInt32 parentArgIndex, nsIRDFResource *objType);
nsresult deleteBookmarkItem(nsIRDFResource *src, nsISupportsArray *aArguments, PRInt32 parentArgIndex, nsIRDFResource *objType);
@ -3287,7 +3287,8 @@ nsBookmarksService::GetAllCmds(nsIRDFResource* source,
{
cmdArray->AppendElement(kNC_BookmarkCommand_DeleteBookmark);
}
if (isBookmarkFolder && (source != kNC_BookmarksRoot))
if (isBookmarkFolder && (source != kNC_BookmarksRoot) &&
(source != kNC_PersonalToolbarFolder) && (source != kNC_IEFavoritesRoot))
{
cmdArray->AppendElement(kNC_BookmarkCommand_DeleteBookmarkFolder);
}
@ -3319,7 +3320,7 @@ nsBookmarksService::IsCommandEnabled(nsISupportsArray/*<nsIRDFResource>*/* aSour
nsresult
nsBookmarksService::getArgumentN(nsISupportsArray *arguments, nsIRDFResource *res,
PRInt32 offset, nsIRDFResource **argValue)
PRInt32 offset, nsIRDFNode **argValue)
{
nsresult rv;
PRUint32 loop, numArguments;
@ -3347,7 +3348,7 @@ nsBookmarksService::getArgumentN(nsISupportsArray *arguments, nsIRDFResource *re
nsCOMPtr<nsISupports> aValue = arguments->ElementAt(loop + 1);
if (!aSource) return(NS_ERROR_NULL_POINTER);
nsCOMPtr<nsIRDFResource> val = do_QueryInterface(aValue);
nsCOMPtr<nsIRDFNode> val = do_QueryInterface(aValue);
if (!val) return(NS_ERROR_NO_INTERFACE);
*argValue = val;
@ -3373,9 +3374,12 @@ nsBookmarksService::insertBookmarkItem(nsIRDFResource *src, nsISupportsArray *aA
}
else
{
nsCOMPtr<nsIRDFNode> aNode;
if (NS_FAILED(rv = getArgumentN(aArguments, kNC_Parent,
parentArgIndex, getter_AddRefs(argParent))))
parentArgIndex, getter_AddRefs(aNode))))
return(rv);
argParent = do_QueryInterface(aNode);
if (!argParent) return(NS_ERROR_NO_INTERFACE);
}
nsCOMPtr<nsIRDFContainer> container;
if (NS_FAILED(rv = nsComponentManager::CreateInstance(kRDFContainerCID, nsnull,
@ -3390,19 +3394,61 @@ nsBookmarksService::insertBookmarkItem(nsIRDFResource *src, nsISupportsArray *aA
return(rv);
}
nsCOMPtr<nsIRDFResource> newElement;
if (NS_FAILED(rv = BookmarkParser::CreateAnonymousResource(&newElement)))
return(rv);
// set a default name for bookmarks/folders
nsAutoString newName;
if (objType == kNC_Bookmark) getLocaleString("NewBookmark", newName);
else if (objType == kNC_Folder)
if ((objType == kNC_Bookmark) || (objType == kNC_Folder))
{
nsCOMPtr<nsIRDFNode> nameNode;
if (NS_SUCCEEDED(rv = getArgumentN(aArguments, kNC_Name, parentArgIndex, getter_AddRefs(nameNode))))
{
nsCOMPtr<nsIRDFLiteral> nameLiteral = do_QueryInterface(nameNode);
if (nameLiteral)
{
const PRUnichar *nameUni = nsnull;
nameLiteral->GetValueConst(&nameUni);
if (nameUni)
{
newName = nameUni;
}
}
}
}
if (newName.Length() == 0)
{
// get a default name
if (objType == kNC_Bookmark) getLocaleString("NewBookmark", newName);
else if (objType == kNC_Folder) getLocaleString("NewFolder", newName);
}
nsCOMPtr<nsIRDFResource> newElement;
if (objType == kNC_Bookmark)
{
nsCOMPtr<nsIRDFNode> bookmarkNode;
if (NS_SUCCEEDED(rv = getArgumentN(aArguments, kNC_URL, parentArgIndex, getter_AddRefs(bookmarkNode))))
{
nsCOMPtr<nsIRDFLiteral> bookmarkURLLiteral = do_QueryInterface(bookmarkNode);
if (!bookmarkURLLiteral) return(NS_ERROR_NO_INTERFACE);
const PRUnichar *urlUni = nsnull;
bookmarkURLLiteral->GetValueConst(&urlUni);
if (urlUni)
{
rv = gRDF->GetUnicodeResource(urlUni, getter_AddRefs(newElement));
if (NS_FAILED(rv)) return(rv);
}
}
}
if (!newElement)
{
if (NS_FAILED(rv = BookmarkParser::CreateAnonymousResource(&newElement)))
return(rv);
}
if (objType == kNC_Folder)
{
if (NS_FAILED(rv = gRDFC->MakeSeq(mInner, newElement, nsnull)))
return(rv);
getLocaleString("NewFolder", newName);
}
if (newName.Length() > 0)
@ -3436,10 +3482,12 @@ nsBookmarksService::deleteBookmarkItem(nsIRDFResource *src, nsISupportsArray *aA
{
nsresult rv;
nsCOMPtr<nsIRDFResource> argParent;
nsCOMPtr<nsIRDFNode> aNode;
if (NS_FAILED(rv = getArgumentN(aArguments, kNC_Parent,
parentArgIndex, getter_AddRefs(argParent))))
parentArgIndex, getter_AddRefs(aNode))))
return(rv);
nsCOMPtr<nsIRDFResource> argParent = do_QueryInterface(aNode);
if (!argParent) return(NS_ERROR_NO_INTERFACE);
// make sure its an object of the correct type (bookmark, folder, separator, ...)
PRBool isCorrectObjectType = PR_FALSE;