aboutsummaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/SettingData.ts6
-rw-r--r--src/shared/settings/Settings.ts (renamed from src/shared/Settings.ts)121
2 files changed, 77 insertions, 50 deletions
diff --git a/src/shared/SettingData.ts b/src/shared/SettingData.ts
index 8ef8385..2dedfef 100644
--- a/src/shared/SettingData.ts
+++ b/src/shared/SettingData.ts
@@ -1,5 +1,5 @@
import * as operations from './operations';
-import Settings, * as settings from './Settings';
+import Settings from './settings/Settings';
import Keymaps from './settings/Keymaps';
import Search from './settings/Search';
import Properties from './settings/Properties';
@@ -118,7 +118,7 @@ export class JSONTextSettings {
}
toSettings(): Settings {
- return settings.valueOf(JSON.parse(this.json));
+ return Settings.fromJSON(JSON.parse(this.json));
}
toJSONText(): string {
@@ -198,7 +198,7 @@ export class FormSettings {
}
toSettings(): Settings {
- return settings.valueOf({
+ return Settings.fromJSON({
keymaps: this.keymaps.toKeymaps().toJSON(),
search: this.search.toSearchSettings().toJSON(),
properties: this.properties.toJSON(),
diff --git a/src/shared/Settings.ts b/src/shared/settings/Settings.ts
index 2767820..116c7d7 100644
--- a/src/shared/Settings.ts
+++ b/src/shared/settings/Settings.ts
@@ -1,49 +1,76 @@
-import Keymaps from './settings/Keymaps';
-import Search from './settings/Search';
-import Properties from './settings/Properties';
-import Blacklist from './settings/Blacklist';
+import Keymaps, { KeymapsJSON } from './Keymaps';
+import Search, { SearchJSON } from './Search';
+import Properties, { PropertiesJSON } from './Properties';
+import Blacklist, { BlacklistJSON } from './Blacklist';
-export default interface Settings {
- keymaps: Keymaps;
- search: Search;
- properties: Properties;
- blacklist: Blacklist;
-}
+export type SettingsJSON = {
+ keymaps: KeymapsJSON,
+ search: SearchJSON,
+ properties: PropertiesJSON,
+ blacklist: BlacklistJSON,
+};
+
+export default class Settings {
+ public keymaps: Keymaps;
+
+ public search: Search;
-export const valueOf = (o: any): Settings => {
- let settings = { ...DefaultSetting };
- for (let key of Object.keys(o)) {
- switch (key) {
- case 'keymaps':
- settings.keymaps = Keymaps.fromJSON(o.keymaps);
- break;
- case 'search':
- settings.search = Search.fromJSON(o.search);
- break;
- case 'properties':
- settings.properties = Properties.fromJSON(o.properties);
- break;
- case 'blacklist':
- settings.blacklist = Blacklist.fromJSON(o.blacklist);
- break;
- default:
- throw new TypeError('unknown setting: ' + key);
+ public properties: Properties;
+
+ public blacklist: Blacklist;
+
+ constructor({
+ keymaps,
+ search,
+ properties,
+ blacklist,
+ }: {
+ keymaps: Keymaps;
+ search: Search;
+ properties: Properties;
+ blacklist: Blacklist;
+ }) {
+ this.keymaps = keymaps;
+ this.search = search;
+ this.properties = properties;
+ this.blacklist = blacklist;
+ }
+
+ static fromJSON(json: any): Settings {
+ let settings = { ...DefaultSetting };
+ for (let key of Object.keys(json)) {
+ switch (key) {
+ case 'keymaps':
+ settings.keymaps = Keymaps.fromJSON(json.keymaps);
+ break;
+ case 'search':
+ settings.search = Search.fromJSON(json.search);
+ break;
+ case 'properties':
+ settings.properties = Properties.fromJSON(json.properties);
+ break;
+ case 'blacklist':
+ settings.blacklist = Blacklist.fromJSON(json.blacklist);
+ break;
+ default:
+ throw new TypeError('unknown setting: ' + key);
+ }
}
+ return new Settings(settings);
}
- return settings;
-};
-export const toJSON = (settings: Settings): any => {
- return {
- keymaps: settings.keymaps.toJSON(),
- search: settings.search.toJSON(),
- properties: settings.properties.toJSON(),
- blacklist: settings.blacklist.toJSON(),
- };
-};
+ toJSON(): SettingsJSON {
+ return {
+ keymaps: this.keymaps.toJSON(),
+ search: this.search.toJSON(),
+ properties: this.properties.toJSON(),
+ blacklist: this.blacklist.toJSON(),
+ };
+ }
+}
-export const DefaultSetting: Settings = {
- keymaps: Keymaps.fromJSON({
+export const DefaultSetting: Settings = Settings.fromJSON({
+ keymaps: {
'0': { 'type': 'scroll.home' },
':': { 'type': 'command.show' },
'o': { 'type': 'command.show.open', 'alter': false },
@@ -106,8 +133,8 @@ export const DefaultSetting: Settings = {
'N': { 'type': 'find.prev' },
'.': { 'type': 'repeat.last' },
'<S-Esc>': { 'type': 'addon.toggle.enabled' }
- }),
- search: Search.fromJSON({
+ },
+ search: {
default: 'google',
engines: {
'google': 'https://google.com/search?q={}',
@@ -117,11 +144,11 @@ export const DefaultSetting: Settings = {
'twitter': 'https://twitter.com/search?q={}',
'wikipedia': 'https://en.wikipedia.org/w/index.php?search={}'
}
- }),
- properties: Properties.fromJSON({
+ },
+ properties: {
hintchars: 'abcdefghijklmnopqrstuvwxyz',
smoothscroll: false,
complete: 'sbh'
- }),
- blacklist: Blacklist.fromJSON([]),
-};
+ },
+ blacklist: [],
+});