RetroZilla/extensions/inspector/resources/content/search/modules/junkImgs/junkImgs.xml
2015-10-20 23:03:22 -04:00

177 lines
5.0 KiB
XML

<?xml version="1.0"?>
<search
title="Find Unused Images in Current Theme"
defaultIcon="chrome://inspector/skin/ImageSearchItem.gif"
xmlns="http://www.mozilla.org/inspector/isml"
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<dialog elements="txfSearchPath" resizable="true"
href="chrome://inspector/content/search/modules/junkImgs/dialog.xul"/>
<columns delimiter="">
<column title="Path" name="path" flex="1" copy="true"/>
</columns>
<contextmenu>
<xul:menuitem label="View..." oncommand="this.search.cmdViewItem()" isEnabled="return true"/>
<xul:menuitem label="Delete File" oncommand="this.search.cmdDeleteItems()" isEnabled="return true"/>
</contextmenu>
<implementation>
<method name="constructor">
<body><![CDATA[
mHashTable = null;
]]></body>
</method>
<property name="progressPercent">
<getter><![CDATA[
return (100 * (this.mFileSearch.directoriesSearched+1)) / this.mDirDepth
]]></getter>
</property>
<property name="progressText">
<getter><![CDATA[
return "blah"
]]></getter>
</property>
<property name="isPastMilestone">
<getter><![CDATA[
var search = this.mFileSearch.directoriesSearched;
var is = search > this.mDirsSearched;
if (is)
this.mDirsSearched = search;
return is;
]]></getter>
</property>
<method name="searchStart">
<parameter name="aMap"/>
<body><![CDATA[
this.mParams = aMap;
this.mDirsSearched = 0;
// hash every image url in the css tree
this.buildCSSImageURLHash();
var fsearch = inSearchUtils.createSearchHelper("file");
this.mFileSearch = fsearch;
var root = inSearchUtils.createLocalFile(aMap.txfSearchPath);
fsearch.searchPath = root;
fsearch.filenameCriteria = "*.gif,*.png,*.jpg";
fsearch.holdResults = false;
fsearch.basePath = aMap.txfSearchPath;
fsearch.returnRelativePaths = true;
this.mDirDepth = fsearch.getDirectoryDepth(root);
var observer = inSearchUtils.createSearchObserver(this, "File");
fsearch.searchAsync(observer);
]]></body>
</method>
<method name="searchStop">
<body><![CDATA[
if (this.mFileSearch)
this.mFileSearch.searchStop();
]]></body>
</method>
<method name="buildCSSImageURLHash">
<body><![CDATA[
var cssSearch = inSearchUtils.createSearchHelper("cssvalue");
cssSearch.returnRelativeURLs = true;
cssSearch.normalizeChromeURLs = true; //this.mParams.cbIsSkin;
cssSearch.addPropertyCriteria("background-image");
cssSearch.addPropertyCriteria("list-style-image");
cssSearch.document = inspector.document;
cssSearch.searchSync(this);
var count = cssSearch.resultCount;
var hash = {};
for (var i = 0; i < count; i++) {
//debug(cssSearch.getStringResultAt(i)+"\n");
hash[cssSearch.getStringResultAt(i)] = 1;
}
this.mHashTable = hash;
]]></body>
</method>
<method name="returnSearchResult">
<parameter name="aFile"/>
<body><![CDATA[
this.module.setResultProperty("path", aFile.path);
this.module.searchResultReady();
]]></body>
</method>
<!-- context menu commands -->
<method name="cmdDeleteItems">
<body><![CDATA[
var mod = this.module;
var svc = mod.searchService;
var count = svc.selectedItemCount;
var idx, path, file;
for (var i = 0; i < count; ++i) {
idx = svc.getSelectedIndex(i);
path = mod.getResultPropertyAt(idx, "path");
file = inSearchUtils.createLocalFile(path);
if (file) {
file.remove(false);
}
}
]]></body>
</method>
<method name="cmdViewItem" defaultCommand="true">
<body><![CDATA[
alert("view");
]]></body>
</method>
<!-- FileSearch observer -->
<method name="onFileSearchStart">
<parameter name="aProcess"/>
<body/>
</method>
<method name="onFileSearchResult">
<parameter name="aProcess"/>
<body><![CDATA[
var fs = this.mFileSearch;
var idx = fs.resultCount-1;
// get the relative-ized path for the file
var path = fs.getStringResultAt(idx);
// check if this path is in the css value hash
if (!this.mHashTable[path])
this.returnSearchResult(fs.getFileResultAt(idx));
]]></body>
</method>
<method name="onFileSearchEnd">
<parameter name="aProcess"/>
<parameter name="aResult"/>
<body><![CDATA[
this.module.searchEnd();
]]></body>
</method>
<method name="onFileSearchError">
<parameter name="aProcess"/>
<parameter name="aMsg"/>
<body/>
</method>
</implementation>
</search>