aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/settings/scan-inputs-controller.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-10-14 19:37:46 -0400
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-10-14 19:43:48 -0400
commitcb566f015aa280499da94126a3f6336c4d8ce0df (patch)
tree91e57b9b1b055c682ab95bafede1b1288885ea5f /ext/bg/js/settings/scan-inputs-controller.js
parentfd945a2119a0bba22c84b77dae1ec829e7495a83 (diff)
Add simple scan input UI (#921)
* Add simple scan input UI * Create helper function * Add controller for old scanning input UI * Add refresh functions * Add abstraction function * Fix incomplete middle mouse support detection * Make scanning inputs update eachother * Fix global declaration order
Diffstat (limited to 'ext/bg/js/settings/scan-inputs-controller.js')
-rw-r--r--ext/bg/js/settings/scan-inputs-controller.js58
1 files changed, 39 insertions, 19 deletions
diff --git a/ext/bg/js/settings/scan-inputs-controller.js b/ext/bg/js/settings/scan-inputs-controller.js
index ec2758cb..fe994aed 100644
--- a/ext/bg/js/settings/scan-inputs-controller.js
+++ b/ext/bg/js/settings/scan-inputs-controller.js
@@ -37,10 +37,10 @@ class ScanInputsController {
this._addButton = document.querySelector('#scan-input-add');
this._addButton.addEventListener('click', this._onAddButtonClick.bind(this), false);
+ this._settingsController.on('scanInputsChanged', this._onScanInputsChanged.bind(this));
this._settingsController.on('optionsChanged', this._onOptionsChanged.bind(this));
- const options = await this._settingsController.getOptions();
- this._onOptionsChanged({options});
+ this.refresh();
}
removeInput(index) {
@@ -51,13 +51,14 @@ class ScanInputsController {
for (let i = index, ii = this._entries.length; i < ii; ++i) {
this._entries[i].index = i;
}
- this._settingsController.modifyProfileSettings([{
+ this._modifyProfileSettings([{
action: 'splice',
path: 'scanning.inputs',
start: index,
deleteCount: 1,
items: []
}]);
+ return true;
}
setProperty(index, property, value) {
@@ -65,8 +66,18 @@ class ScanInputsController {
this._settingsController.setProfileSetting(path, value);
}
+ async refresh() {
+ const options = await this._settingsController.getOptions();
+ this._onOptionsChanged({options});
+ }
+
// Private
+ _onScanInputsChanged({source}) {
+ if (source === this) { return; }
+ this.refresh();
+ }
+
_onOptionsChanged({options}) {
const {inputs} = options.scanning;
@@ -88,26 +99,12 @@ class ScanInputsController {
const include = '';
const exclude = '';
this._addOption(index, include, exclude);
- this._settingsController.modifyProfileSettings([{
+ this._modifyProfileSettings([{
action: 'splice',
path: 'scanning.inputs',
start: index,
deleteCount: 0,
- items: [{
- include,
- exclude,
- types: {mouse: true, touch: false, pen: false},
- options: {
- showAdvanced: false,
- searchTerms: true,
- searchKanji: true,
- scanOnTouchMove: true,
- scanOnPenHover: true,
- scanOnPenPress: true,
- scanOnPenRelease: false,
- preventTouchScrolling: true
- }
- }]
+ items: [ScanInputsController.createDefaultMouseInput(include, exclude)]
}]);
}
@@ -116,6 +113,29 @@ class ScanInputsController {
this._entries.push(field);
field.prepare(this._container, include, exclude);
}
+
+ async _modifyProfileSettings(targets) {
+ await this._settingsController.modifyProfileSettings(targets);
+ this._settingsController.trigger('scanInputsChanged', {source: this});
+ }
+
+ static createDefaultMouseInput(include, exclude) {
+ return {
+ include,
+ exclude,
+ types: {mouse: true, touch: false, pen: false},
+ options: {
+ showAdvanced: false,
+ searchTerms: true,
+ searchKanji: true,
+ scanOnTouchMove: true,
+ scanOnPenHover: true,
+ scanOnPenPress: true,
+ scanOnPenRelease: false,
+ preventTouchScrolling: true
+ }
+ };
+ }
}
class ScanInputField {