source: branches/testa/js/bookmarkmgr.js @ 23

Last change on this file since 23 was 23, checked in by anonymous, 6 years ago

init

File size: 1.0 KB
Line 
1class BookmarkMgr {
2    constructor( max_display_name_length ) {
3        this.paths = []
4        this.items = {}
5        this.max_display_name_length = max_display_name_length
6    }
7
8    add( path , display_name ){
9        let result = this.paths.indexOf( path )
10        if( result < 0 ){
11            this.paths.push( path )
12            this.items[ path ] = new Bookmark( path , this.max_display_name_length , display_name )
13        }
14        return this.items[ path ]
15    }
16
17    remove( path ){
18        let result = this.paths.indexOf( path )
19        if( result >= 0 ){
20            delete this.items[ path ]
21            delete this.paths[ result ]
22        }
23    }
24
25    display_name( path ){
26        let result = this.paths.indexOf( path )
27        let disp = null
28        if( result >= 0 ){
29            disp = this.items[ path ].display_name
30        }
31        return disp
32    }
33
34    get_paths(){
35        return this.paths
36    }
37
38    get_display_names(){
39        const array = thils.paths
40        return array.map( function( path ){
41            return this.items[ path ].display_name
42        } )
43    }
44
45    get_restricted_display_name( path ){
46        return path.substr( -this.max_display_name_length )
47    }
48}
Note: See TracBrowser for help on using the repository browser.