Changeset 37

Show
Ignore:
Timestamp:
2007-01-23 06:17:31 (2 years ago)
Author:
MaierMan
Message:

different enumerations
sorting

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/components/filterManager.idl

    r34 r37  
    4848        attribute string label; 
    4949        attribute string test; 
    50         [readonly] attribute string regex; 
     50        attribute boolean isRegex; 
    5151        attribute boolean active; 
    52         attribute boolean isRegex; 
    5352        attribute unsigned long type; 
    54          
     53        boolean match(in string test); 
    5554        void save(); 
    5655        void remove(); 
     
    6463  void reload(); 
    6564         
    66         nsISimpleEnumerator enumerate(); 
     65        nsISimpleEnumerator enumAll(); 
     66        nsISimpleEnumerator enumActive(in unsigned long type); 
    6767        dtaIFilter getFilter(in string id); 
     68         
     69        boolean matchActive(in string test, in unsigned long type); 
    6870         
    6971        void create(in string label, in string test, in boolean active, in unsigned long type, in boolean regex); 
  • trunk/components/filterManager.js

    r34 r37  
    3535 * ***** END LICENSE BLOCK ***** */ 
    3636  
    37 // Components.classes['@tn123.ath.cx/dtamod/filtermanager;1'].getService(Components.interfaces.dtaIFilterManager).count
     37// Components.classes['@tn123.ath.cx/dtamod/filtermanager;1'].getService(Components.interfaces.dtaIFilterManager).matchActive('hallo.jpg', 1)
    3838 
    3939const CC = Components.classes; 
    4040const CI = Components.interfaces; 
    4141const error = Components.utils.reportError; 
     42 
     43function include(uri) { 
     44        CC["@mozilla.org/moz/jssubscript-loader;1"] 
     45                .getService(CI.mozIJSSubScriptLoader) 
     46                .loadSubScript(uri); 
     47} 
     48 
     49include("chrome://dta/content/common/regconvert.js"); 
    4250 
    4351// no not create DTA_Filter yourself, managed by DTA_FilterManager 
     
    7381                        iid.equals(CI.nsISupports) 
    7482                        || iid.equals(CI.nsIClassInfo) 
    75                         || iid.equals(CI.nsIDTAFilter) 
     83                        || iid.equals(CI.dtaIFilter) 
    7684                ) { 
    7785                        return this; 
     
    120128                this._modified = true; 
    121129        }, 
    122         // exported 
    123         get regex() { 
    124                 return this._regex; 
    125         }, 
    126130         
    127131        // exported 
     
    168172                 
    169173        _createRegex: function F_createRegex() { 
    170                 // XXX 
     174                this._regex = this._isRegex ? DTA_regToRegExp(this._test) : DTA_strToRegExp(this._test); 
    171175        }, 
    172176 
     
    175179        }, 
    176180 
     181        match: function F_match(str) { 
     182                return str.search(this._regex) != -1; 
     183        }, 
    177184         
    178185        /** 
     
    237244        this._filters = filters; 
    238245        this._idx = 0; 
     246        this._filters.sort(function(a,b) { 
     247                if (a.defFilter && !b.defFilter) { 
     248                        return -1; 
     249                } 
     250                else if (!a.defFilter && b.defFilter) { 
     251                        return 1; 
     252                } 
     253                else if (a.defFilter) { 
     254                        if (a.id < b.id) { 
     255                                return -1; 
     256                        } 
     257                        return 1; 
     258                } 
     259                var i = a.label.toLower(), ii = b.label.toLower(); 
     260                return i < ii ? -1 : (i > ii ? 1 : 0); 
     261        }); 
    239262} 
    240263FilterEnumerator.prototype = { 
     
    356379        }, 
    357380         
    358         enumerate: function FM_enumerate() { 
     381        enumAll: function FM_enumAll() { 
    359382                var a = []; 
    360383                for (x in this._filters) { 
     
    363386                return new FilterEnumerator(a); 
    364387        }, 
     388        enumActive: function FM_enumActive(type) { 
     389                var a = []; 
     390                for (x in this._filters) { 
     391                        if (this._filters[x].active && this._filters[x].type & type) { 
     392                                a.push(this._filters[x]); 
     393                        } 
     394                } 
     395                return new FilterEnumerator(a); 
     396        }, 
    365397         
    366398        getFilter: function FM_getFilter(id) { 
     
    369401                } 
    370402                return null; 
    371         },       
     403        }, 
     404 
     405        matchActive: function FM_matchActive(test, type) { 
     406                var e = this.enumActive(type); 
     407                // we're a friend :p 
     408                return e._filters.some(function(i) { return i.match(test); }); 
     409        }, 
     410         
    372411        create: function FM_create(label, test, active, type, isRegex) { 
    373412                 
     
    402441         
    403442        save: function FM_save() { 
    404  
    405                 var e = this.enumerate(); 
     443                var e = this.enumAll(); 
    406444                while (e.hasMoreElements()) { 
    407445                        var f = e.getNext(); 
  • trunk/components/privacycontrol.js

    r6 r37  
    131131      .getBranch('extensions.dta.'); 
    132132 
    133     // add more if needed 
    134     const toClear = Array('directory', 'dropdown.directory-current', 'dropdown.directory-history'); 
    135  
    136     for (var i = 0; i < toClear.length; ++i) { 
    137       try { 
    138         prefs.clearUserPref(toClear[i]); 
    139       } catch (ex) {} 
    140     } 
     133                ['directory', 'filter'].forEach(function(e) { prefs.clearUserPref(e); }); 
    141134  }, 
    142135 
     
    250243 
    251244function NSGetModule(mgr, spec) { 
     245        dump("PC getModule"); 
    252246  return module; 
    253247}