Small "Search Editor" changes.

This commit is contained in:
rjc%netscape.com 2000-04-14 09:58:05 +00:00
Родитель e495d8bf34
Коммит ff29427bd7
8 изменённых файлов: 152 добавлений и 23 удалений

Просмотреть файл

@ -64,6 +64,7 @@ CHROME_L10N = \
locale/en-US/internetresults.dtd \
locale/en-US/search.dtd \
locale/en-US/search-editor.dtd \
locale/en-US/search-editor.properties \
locale/en-US/search-panel.dtd \
locale/en-US/search-panel.properties \
$(NULL)

Просмотреть файл

@ -1,9 +1,9 @@
en-US:search.dtd
en-US:search-editor.dtd
en-US:search-editor.properties
en-US:search-panel.dtd
en-US:find.dtd
en-US:findresults.dtd
en-US:internet.dtd
en-US:internetresults.dtd
en-US:search-panel.properties

Просмотреть файл

@ -26,6 +26,7 @@
<!ENTITY allengines.label "All Engines">
<!ENTITY engine.column.label "Search Engines">
<!ENTITY category.label "Category:">
<!ENTITY done.label "Done">
<!ENTITY add.label "&lt;-- Add --">
<!ENTITY remove.label "Remove">

Просмотреть файл

@ -0,0 +1,4 @@
NewCategoryPrompt=Enter the new category name:
RenameCategoryPrompt=Enter the new category name:
RemoveCategoryPrompt=Delete this category?
RemoveEnginePrompt=Remove the selected search engine(s) from this category?

Просмотреть файл

@ -64,6 +64,7 @@ CHROME_L10N = \
.\locale\en-US\internetresults.dtd \
.\locale\en-US\search.dtd \
.\locale\en-US\search-editor.dtd \
.\locale\en-US\search-editor.properties \
.\locale\en-US\search-panel.dtd \
.\locale\en-US\search-panel.properties \
$(NULL)

Просмотреть файл

@ -26,15 +26,28 @@
// global(s)
var bundle = srGetStrBundle("chrome://search/locale/search-editor.properties");
var pref = null;
var RDF = null;
var RDFC = null;
var catDS = null;
try
{
pref = Components.classes["component://netscape/preferences"].getService();
if (pref) pref = pref.QueryInterface( Components.interfaces.nsIPref );
RDF = Components.classes["component://netscape/rdf/rdf-service"].getService();
if (RDF) RDF = RDF.QueryInterface(Components.interfaces.nsIRDFService);
RDFC = Components.classes["component://netscape/rdf/container"].getService();
if (RDFC) RDFC = RDFC.QueryInterface(Components.interfaces.nsIRDFContainer);
}
catch(e)
{
pref = null;
RDF = null;
RDFC = null;
}
@ -49,15 +62,12 @@ function debug(msg)
function doLoad()
{
// set up action buttons
doSetOKCancel(Commit, Cancel);
// adjust category popup
var internetSearch = Components.classes["component://netscape/rdf/datasource?name=internetsearch"].getService();
if (internetSearch) internetSearch = internetSearch.QueryInterface(Components.interfaces.nsIInternetSearchService);
if (internetSearch)
{
var catDS = internetSearch.GetCategoryDataSource();
catDS = internetSearch.GetCategoryDataSource();
if (catDS) catDS = catDS.QueryInterface(Components.interfaces.nsIRDFDataSource);
if (catDS)
{
@ -129,16 +139,19 @@ function doLoad()
function Cancel()
{
// Ignore any changes.
window.close();
}
function Commit()
{
// flush
if (catDS)
{
var flushableDS = catDS.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource);
if (flushableDS)
{
flushableDS.Flush();
}
}
window.close();
}
@ -236,6 +249,8 @@ function AddEngine()
function RemoveEngine()
{
var promptStr = bundle.GetStringFromName("RemoveEnginePrompt");
if (!confirm(promptStr)) return(false);
return(true);
}
@ -243,13 +258,57 @@ function RemoveEngine()
function MoveUp()
{
return(true);
return MoveDelta(-1);
}
function MoveDown()
{
return MoveDelta(1);
}
function MoveDelta(delta)
{
var engineList = document.getElementById("engineList");
if (!engineList) return(false);
var select_list = engineList.selectedItems;
if (!select_list) return(false)
if (select_list.length != 1) return(false);
var ref = engineList.getAttribute("ref");
if ((!ref) || (ref == "")) return(false);
var categoryRes = RDF.GetResource(ref);
if (!categoryRes) return(false);
var id = select_list[0].getAttribute("id");
if ((!id) || (id == "")) return(false);
var idRes = RDF.GetResource(id);
if (!idRes) return(false);
RDFC.Init(catDS, categoryRes);
var nodeIndex = RDFC.IndexOf(idRes);
if (nodeIndex < 1) return(false); // how did that happen?
var numItems = RDFC.GetCount();
var newPos = -1;
if (((delta == -1) && (nodeIndex > 1)) ||
((delta == 1) && (nodeIndex < numItems)))
{
newPos = nodeIndex + delta;
RDFC.RemoveElementAt(nodeIndex, true, idRes);
}
if (newPos > 0)
{
RDFC.InsertElementAt(idRes, newPos, true);
}
selectItems(engineList, ref, id);
return(true);
}
@ -257,6 +316,9 @@ function MoveDown()
function NewCategory()
{
var promptStr = bundle.GetStringFromName("NewCategoryPrompt");
var name = prompt(promptStr, "");
if ((!name) || (name == "")) return(false);
return(true);
}
@ -264,6 +326,36 @@ function NewCategory()
function RenameCategory()
{
var categoryList = document.getElementById( "categoryList" );
var currentName = categoryList.selectedItem.getAttribute("value");
var promptStr = bundle.GetStringFromName("RenameCategoryPrompt");
var name = prompt(promptStr, currentName);
if ((!name) || (name == "") || (name == currentName)) return(false);
var currentCatID = categoryList.selectedItem.getAttribute("id");
var currentCatRes = RDF.GetResource(currentCatID);
if (!currentCatRes) return(false);
var titleRes = RDF.GetResource("http://home.netscape.com/NC-rdf#title");
if (!titleRes) return(false);
var newName = RDF.GetLiteral(name);
if (!newName) return(false);
var oldName = catDS.GetTarget(currentCatRes, titleRes, true);
if (oldName) oldName = oldName.QueryInterface(Components.interfaces.nsIRDFLiteral);
if (oldName)
{
catDS.Change(currentCatRes, titleRes, oldName, newName);
}
else
{
catDS.Assert(currentCatRes, titleRes, newName, true);
}
// force popup to update
chooseCategory(categoryList.selectedItem);
return(true);
}
@ -271,5 +363,35 @@ function RenameCategory()
function RemoveCategory()
{
var promptStr = bundle.GetStringFromName("RemoveCategoryPrompt");
if (!confirm(promptStr)) return(false);
return(true);
}
function selectItems(treeRoot, containerID, targetID)
{
var select_list = treeRoot.getElementsByAttribute("id", targetID);
for (var x=0; x<select_list.length; x++)
{
var node = select_list[x];
if (!node) continue;
var parent = node.parentNode.parentNode;
if (!parent) continue;
var id = parent.getAttribute("ref");
if (!id || id=="")
{
id = parent.getAttribute("id");
}
if (!id || id=="") continue;
if (id == containerID)
{
node.setAttribute("selected", "true");
break;
}
}
}

Просмотреть файл

@ -42,7 +42,7 @@
onload="doLoad()" onunload="doUnload()"
>
<html:script language="Javascript" src="chrome://global/content/globalOverlay.js"/>
<html:script language="Javascript" src="chrome://global/content/strres.js"/>
<html:script language="Javascript" src="chrome://search/content/search-editor.js" />
<titledbox orient="vertical" flex="1" >
@ -78,11 +78,11 @@
</treechildren>
</template>
<treecol id="EngineColumn" rdf:resource="http://home.netscape.com/NC-rdf#Name" sortActive="true" sortDirection="ascending" />
<treecol id="EngineColumn" rdf:resource="http://home.netscape.com/NC-rdf#Name" />
<treehead>
<treerow>
<treecell observes="EngineColumn" align="center" value="&engine.column.label;" resource="http://home.netscape.com/NC-rdf#Name" onclick="return doSort('EngineColumn', null);" sortActive="true" sortDirection="ascending" flex="1"/>
<treecell observes="EngineColumn" align="center" value="&engine.column.label;" resource="http://home.netscape.com/NC-rdf#Name" flex="1"/>
</treerow>
</treehead>
</tree>
@ -98,8 +98,8 @@
<!-- The 'reorder' buttons -->
<box id="reorder" align="vertical" autostretch="never">
<spring flex="1"/>
<button oncommand="MoveUp();" id="up" class="up small" />
<button oncommand="MoveDown();" id="down" class="down small" />
<titledbutton oncommand="MoveUp();" id="up" class="up small dialog toolbar-non-iconic" />
<titledbutton oncommand="MoveDown();" id="down" class="down small dialog toolbar-non-iconic" />
<spring flex="1"/>
</box>
@ -138,7 +138,7 @@
<box autostretch="never">
<spring flex="1"/>
<box id="okCancelButtons"/>
<titledbutton id="done.button" onclick="Commit()" value="&done.label;" class="dialog toolbar-non-iconic" />
</box>
</window>

Просмотреть файл

@ -33,9 +33,9 @@
onload="SearchPanelStartup();"
onunload="SearchPanelShutdown();">
<html:script src="chrome://global/content/strres.js"/>
<html:script src="chrome://search/content/search-panel.js" />
<html:script src="chrome://search/content/shared.js" />
<html:script language="Javascript" src="chrome://global/content/strres.js"/>
<html:script language="Javascript" src="chrome://search/content/search-panel.js" />
<html:script language="Javascript" src="chrome://search/content/shared.js" />
<popupset>
<popup id="contextual" oncreate="return fillContextMenu('contextual', 'Tree');" >