|
|
@ -1,49 +1,76 @@ |
|
|
|
import Keymaps from './settings/Keymaps'; |
|
|
|
import Keymaps, { KeymapsJSON } from './Keymaps'; |
|
|
|
import Search from './settings/Search'; |
|
|
|
import Search, { SearchJSON } from './Search'; |
|
|
|
import Properties from './settings/Properties'; |
|
|
|
import Properties, { PropertiesJSON } from './Properties'; |
|
|
|
import Blacklist from './settings/Blacklist'; |
|
|
|
import Blacklist, { BlacklistJSON } from './Blacklist'; |
|
|
|
|
|
|
|
|
|
|
|
export default interface Settings { |
|
|
|
export type SettingsJSON = { |
|
|
|
|
|
|
|
keymaps: KeymapsJSON, |
|
|
|
|
|
|
|
search: SearchJSON, |
|
|
|
|
|
|
|
properties: PropertiesJSON, |
|
|
|
|
|
|
|
blacklist: BlacklistJSON, |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export default class Settings { |
|
|
|
|
|
|
|
public keymaps: Keymaps; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public search: Search; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public properties: Properties; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public blacklist: Blacklist; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
constructor({ |
|
|
|
|
|
|
|
keymaps, |
|
|
|
|
|
|
|
search, |
|
|
|
|
|
|
|
properties, |
|
|
|
|
|
|
|
blacklist, |
|
|
|
|
|
|
|
}: { |
|
|
|
keymaps: Keymaps; |
|
|
|
keymaps: Keymaps; |
|
|
|
search: Search; |
|
|
|
search: Search; |
|
|
|
properties: Properties; |
|
|
|
properties: Properties; |
|
|
|
blacklist: Blacklist; |
|
|
|
blacklist: Blacklist; |
|
|
|
|
|
|
|
}) { |
|
|
|
|
|
|
|
this.keymaps = keymaps; |
|
|
|
|
|
|
|
this.search = search; |
|
|
|
|
|
|
|
this.properties = properties; |
|
|
|
|
|
|
|
this.blacklist = blacklist; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export const valueOf = (o: any): Settings => { |
|
|
|
static fromJSON(json: any): Settings { |
|
|
|
let settings = { ...DefaultSetting }; |
|
|
|
let settings = { ...DefaultSetting }; |
|
|
|
for (let key of Object.keys(o)) { |
|
|
|
for (let key of Object.keys(json)) { |
|
|
|
switch (key) { |
|
|
|
switch (key) { |
|
|
|
case 'keymaps': |
|
|
|
case 'keymaps': |
|
|
|
settings.keymaps = Keymaps.fromJSON(o.keymaps); |
|
|
|
settings.keymaps = Keymaps.fromJSON(json.keymaps); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 'search': |
|
|
|
case 'search': |
|
|
|
settings.search = Search.fromJSON(o.search); |
|
|
|
settings.search = Search.fromJSON(json.search); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 'properties': |
|
|
|
case 'properties': |
|
|
|
settings.properties = Properties.fromJSON(o.properties); |
|
|
|
settings.properties = Properties.fromJSON(json.properties); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 'blacklist': |
|
|
|
case 'blacklist': |
|
|
|
settings.blacklist = Blacklist.fromJSON(o.blacklist); |
|
|
|
settings.blacklist = Blacklist.fromJSON(json.blacklist); |
|
|
|
break; |
|
|
|
break; |
|
|
|
default: |
|
|
|
default: |
|
|
|
throw new TypeError('unknown setting: ' + key); |
|
|
|
throw new TypeError('unknown setting: ' + key); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return settings; |
|
|
|
return new Settings(settings); |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export const toJSON = (settings: Settings): any => { |
|
|
|
toJSON(): SettingsJSON { |
|
|
|
return { |
|
|
|
return { |
|
|
|
keymaps: settings.keymaps.toJSON(), |
|
|
|
keymaps: this.keymaps.toJSON(), |
|
|
|
search: settings.search.toJSON(), |
|
|
|
search: this.search.toJSON(), |
|
|
|
properties: settings.properties.toJSON(), |
|
|
|
properties: this.properties.toJSON(), |
|
|
|
blacklist: settings.blacklist.toJSON(), |
|
|
|
blacklist: this.blacklist.toJSON(), |
|
|
|
}; |
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export const DefaultSetting: Settings = { |
|
|
|
export const DefaultSetting: Settings = Settings.fromJSON({ |
|
|
|
keymaps: Keymaps.fromJSON({ |
|
|
|
keymaps: { |
|
|
|
'0': { 'type': 'scroll.home' }, |
|
|
|
'0': { 'type': 'scroll.home' }, |
|
|
|
':': { 'type': 'command.show' }, |
|
|
|
':': { 'type': 'command.show' }, |
|
|
|
'o': { 'type': 'command.show.open', 'alter': false }, |
|
|
|
'o': { 'type': 'command.show.open', 'alter': false }, |
|
|
@ -106,8 +133,8 @@ export const DefaultSetting: Settings = { |
|
|
|
'N': { 'type': 'find.prev' }, |
|
|
|
'N': { 'type': 'find.prev' }, |
|
|
|
'.': { 'type': 'repeat.last' }, |
|
|
|
'.': { 'type': 'repeat.last' }, |
|
|
|
'<S-Esc>': { 'type': 'addon.toggle.enabled' } |
|
|
|
'<S-Esc>': { 'type': 'addon.toggle.enabled' } |
|
|
|
}), |
|
|
|
}, |
|
|
|
search: Search.fromJSON({ |
|
|
|
search: { |
|
|
|
default: 'google', |
|
|
|
default: 'google', |
|
|
|
engines: { |
|
|
|
engines: { |
|
|
|
'google': 'https://google.com/search?q={}', |
|
|
|
'google': 'https://google.com/search?q={}', |
|
|
@ -117,11 +144,11 @@ export const DefaultSetting: Settings = { |
|
|
|
'twitter': 'https://twitter.com/search?q={}', |
|
|
|
'twitter': 'https://twitter.com/search?q={}', |
|
|
|
'wikipedia': 'https://en.wikipedia.org/w/index.php?search={}' |
|
|
|
'wikipedia': 'https://en.wikipedia.org/w/index.php?search={}' |
|
|
|
} |
|
|
|
} |
|
|
|
}), |
|
|
|
}, |
|
|
|
properties: Properties.fromJSON({ |
|
|
|
properties: { |
|
|
|
hintchars: 'abcdefghijklmnopqrstuvwxyz', |
|
|
|
hintchars: 'abcdefghijklmnopqrstuvwxyz', |
|
|
|
smoothscroll: false, |
|
|
|
smoothscroll: false, |
|
|
|
complete: 'sbh' |
|
|
|
complete: 'sbh' |
|
|
|
}), |
|
|
|
}, |
|
|
|
blacklist: Blacklist.fromJSON([]), |
|
|
|
blacklist: [], |
|
|
|
}; |
|
|
|
}); |