|
Last change
on this file since 32 was
25,
checked in by anonymous, 6 years ago
|
|
use localstorage to store/restore settings
|
|
File size:
1.3 KB
|
| Line | |
|---|
| 1 | class 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 = null){ |
|---|
| 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 | get( path ){ |
|---|
| 26 | let ret = null |
|---|
| 27 | let result = this.paths.indexOf( path ) |
|---|
| 28 | if( result >= 0 ){ |
|---|
| 29 | ret = this.items[ path ] |
|---|
| 30 | } |
|---|
| 31 | return ret |
|---|
| 32 | } |
|---|
| 33 | |
|---|
| 34 | display_name( path ){ |
|---|
| 35 | let result = this.paths.indexOf( path ) |
|---|
| 36 | let disp = null |
|---|
| 37 | if( result >= 0 ){ |
|---|
| 38 | disp = this.items[ path ].display_name |
|---|
| 39 | } |
|---|
| 40 | return disp |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | get_paths(){ |
|---|
| 44 | return this.paths |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | get_display_names(){ |
|---|
| 48 | const array = thils.paths |
|---|
| 49 | return array.map( function( path ){ |
|---|
| 50 | return this.items[ path ].display_name |
|---|
| 51 | } ) |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | get_restricted_display_name( path ){ |
|---|
| 55 | return path.substr( -this.max_display_name_length ) |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | get_items() { |
|---|
| 59 | return this.items |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | max_display_name_length(){ |
|---|
| 63 | return this.max_display_name_length |
|---|
| 64 | } |
|---|
| 65 | } |
|---|
Note: See
TracBrowser
for help on using the repository browser.