Cleanup AppUserStore

Simplify KeyState/Focused as Scope enum
This commit is contained in:
djmaze 2021-03-16 16:06:16 +01:00
parent 62cb918180
commit eff92c3152
27 changed files with 177 additions and 232 deletions

View file

@ -1,4 +1,4 @@
import { KeyState } from 'Common/Enums';
import { Scope } from 'Common/Enums';
import { i18n } from 'Common/Translator';
import { AbstractViewPopup } from 'Knoin/AbstractViews';
@ -18,7 +18,6 @@ class AskPopupView extends AbstractViewPopup {
this.bFocusYesOnShow = true;
this.bDisabeCloseOnEsc = true;
this.sDefaultKeyScope = KeyState.PopupAsk;
}
clearPopup() {
@ -81,8 +80,8 @@ class AskPopupView extends AbstractViewPopup {
}
onBuild() {
// shortcuts.add('tab', 'shift', KeyState.PopupAsk, () => {
shortcuts.add('tab,arrowright,arrowleft', '', KeyState.PopupAsk, () => {
// shortcuts.add('tab', 'shift', Scope.Ask, () => {
shortcuts.add('tab,arrowright,arrowleft', '', Scope.Ask, () => {
let btn = this.querySelector('.buttonYes');
if (btn.matches(':focus')) {
btn = this.querySelector('.buttonNo');
@ -91,7 +90,7 @@ class AskPopupView extends AbstractViewPopup {
return false;
});
shortcuts.add('escape', '', KeyState.PopupAsk, () => {
shortcuts.add('escape', '', Scope.Ask, () => {
this.noClick();
return false;
});

View file

@ -1,7 +1,7 @@
import ko from 'ko';
import {
KeyState,
Scope,
Notification,
UploadErrorCode
} from 'Common/Enums';
@ -125,10 +125,9 @@ class ComposePopupView extends AbstractViewPopup {
this.sLastFocusedField = 'to';
this.allowContacts = !!AppUserStore.contactsIsAllowed();
this.allowContacts = AppUserStore.contactsIsAllowed();
this.bSkipNextHide = false;
this.composeInEdit = AppUserStore.composeInEdit;
this.editorDefaultType = SettingsUserStore.editorDefaultType;
this.capaOpenPGP = PgpUserStore.capaOpenPGP;
@ -218,7 +217,6 @@ class ComposePopupView extends AbstractViewPopup {
});
this.bDisabeCloseOnEsc = true;
this.sDefaultKeyScope = KeyState.Compose;
this.tryToClosePopup = this.tryToClosePopup.debounce(200);
@ -1133,42 +1131,42 @@ class ComposePopupView extends AbstractViewPopup {
onBuild(dom) {
this.initUploader();
shortcuts.add('q', 'meta', KeyState.Compose, ()=>false);
shortcuts.add('w', 'meta', KeyState.Compose, ()=>false);
shortcuts.add('q', 'meta', Scope.Compose, ()=>false);
shortcuts.add('w', 'meta', Scope.Compose, ()=>false);
shortcuts.add('m,contextmenu', '', KeyState.Compose, e => this.popupMenu(e));
shortcuts.add('m', 'ctrl', KeyState.Compose, e => this.popupMenu(e));
shortcuts.add('m,contextmenu', '', Scope.Compose, e => this.popupMenu(e));
shortcuts.add('m', 'ctrl', Scope.Compose, e => this.popupMenu(e));
shortcuts.add('escape,close', '', KeyState.Compose, () => {
shortcuts.add('escape,close', '', Scope.Compose, () => {
this.skipCommand();
return false;
});
shortcuts.add('arrowdown', 'meta', KeyState.Compose, () => {
shortcuts.add('arrowdown', 'meta', Scope.Compose, () => {
this.skipCommand();
return false;
});
shortcuts.add('s', 'meta', KeyState.Compose, () => {
shortcuts.add('s', 'meta', Scope.Compose, () => {
this.saveCommand();
return false;
});
shortcuts.add('save', KeyState.Compose, () => {
shortcuts.add('save', Scope.Compose, () => {
this.saveCommand();
return false;
});
if (Settings.app('allowCtrlEnterOnCompose')) {
shortcuts.add('enter', 'meta', KeyState.Compose, () => {
shortcuts.add('enter', 'meta', Scope.Compose, () => {
this.sendCommand();
return false;
});
}
shortcuts.add('mailsend', '', KeyState.Compose, () => {
shortcuts.add('mailsend', '', Scope.Compose, () => {
this.sendCommand();
return false;
});
shortcuts.add('escape,close', 'shift', KeyState.Compose, () => {
shortcuts.add('escape,close', 'shift', Scope.Compose, () => {
this.modalVisibility() && this.tryToClosePopup();
return false;
});

View file

@ -2,7 +2,7 @@ import ko from 'ko';
import { pString, defaultOptionsAfterRender } from 'Common/Utils';
import { KeyState } from 'Common/Enums';
import { Scope } from 'Common/Enums';
import { i18n } from 'Common/Translator';
import { PgpUserStore } from 'Stores/User/Pgp';
@ -88,8 +88,6 @@ class ComposeOpenPgpPopupView extends AbstractViewPopup {
}
});
this.sDefaultKeyScope = KeyState.PopupComposeOpenPGP;
this.defaultOptionsAfterRender = defaultOptionsAfterRender;
this.deletePublickKey = this.deletePublickKey.bind(this);
@ -290,8 +288,8 @@ class ComposeOpenPgpPopupView extends AbstractViewPopup {
}
onBuild() {
// shortcuts.add('tab', 'shift', KeyState.PopupComposeOpenPGP, () => {
shortcuts.add('tab', '', KeyState.PopupComposeOpenPGP, () => {
// shortcuts.add('tab', 'shift', Scope.ComposeOpenPgp, () => {
shortcuts.add('tab', '', Scope.ComposeOpenPgp, () => {
let btn = this.querySelector('.inputPassword');
if (btn.matches(':focus')) {
btn = this.querySelector('.buttonDo');

View file

@ -3,7 +3,7 @@ import ko from 'ko';
import {
SaveSettingsStep,
Notification,
KeyState
Scope
} from 'Common/Enums';
import { ComposeType } from 'Common/EnumsUser';
@ -94,8 +94,6 @@ class ContactsPopupView extends AbstractViewPopup {
// this.saveCommandDebounce = _.debounce(this.saveCommand.bind(this), 1000);
this.sDefaultKeyScope = KeyState.ContactList;
const
// propertyFocused = property => !property.isValid() && !property.focused(),
pagecount = () => Math.max(1, Math.ceil(this.contactsCount() / CONTACTS_PER_PAGE));
@ -490,14 +488,14 @@ class ContactsPopupView extends AbstractViewPopup {
}
onBuild(dom) {
this.selector.init(dom.querySelector('.b-list-content'), KeyState.ContactList);
this.selector.init(dom.querySelector('.b-list-content'), Scope.Contacts);
shortcuts.add('delete', '', KeyState.ContactList, () => {
shortcuts.add('delete', '', Scope.Contacts, () => {
this.deleteCommand();
return false;
});
shortcuts.add('c,w', '', KeyState.ContactList, () => {
shortcuts.add('c,w', '', Scope.Contacts, () => {
this.newMessageCommand();
return false;
});

View file

@ -1,11 +1,10 @@
import { KeyState } from 'Common/Enums';
import { Scope } from 'Common/Enums';
import { AbstractViewPopup } from 'Knoin/AbstractViews';
class KeyboardShortcutsHelpPopupView extends AbstractViewPopup {
constructor() {
super('KeyboardShortcutsHelp');
this.sDefaultKeyScope = KeyState.PopupKeyboardShortcutsHelp;
}
onBuild(dom) {
@ -13,7 +12,7 @@ class KeyboardShortcutsHelpPopupView extends AbstractViewPopup {
// shortcuts.add('tab', 'shift',
shortcuts.add('tab,arrowleft,arrowright', '',
KeyState.PopupKeyboardShortcutsHelp,
Scope.KeyboardShortcutsHelp,
((event, handler)=>{
if (event && handler) {
const tabs = dom.querySelectorAll('.nav.nav-tabs > li'),

View file

@ -1,7 +1,7 @@
import ko from 'ko';
import { pString } from 'Common/Utils';
import { KeyState } from 'Common/Enums';
import { Scope } from 'Common/Enums';
import { decorateKoCommands } from 'Knoin/Knoin';
import { AbstractViewPopup } from 'Knoin/AbstractViews';
@ -20,8 +20,6 @@ class MessageOpenPgpPopupView extends AbstractViewPopup {
this.resultCallback = null;
this.sDefaultKeyScope = KeyState.PopupMessageOpenPGP;
decorateKoCommands(this, {
doCommand: self => !self.submitRequest()
});
@ -77,8 +75,8 @@ class MessageOpenPgpPopupView extends AbstractViewPopup {
}
onBuild(oDom) {
// shortcuts.add('tab', 'shift', KeyState.PopupMessageOpenPGP, () => {
shortcuts.add('tab', '', KeyState.PopupMessageOpenPGP, () => {
// shortcuts.add('tab', 'shift', Scope.MessageOpenPgp, () => {
shortcuts.add('tab', '', Scope.MessageOpenPgp, () => {
let btn = this.querySelector('.inputPassword');
if (btn.matches(':focus')) {
btn = this.querySelector('.buttonDo');

View file

@ -1,6 +1,6 @@
import ko from 'ko';
import { KeyState, Notification } from 'Common/Enums';
import { Scope, Notification } from 'Common/Enums';
import { getNotification, i18n } from 'Common/Translator';
import Remote from 'Remote/Admin/Fetch';
@ -27,7 +27,7 @@ class PluginPopupView extends AbstractViewPopup {
this.hasConfiguration = ko.computed(() => 0 < this.configures().length);
this.bDisabeCloseOnEsc = true;
this.sDefaultKeyScope = KeyState.All;
this.sDefaultScope = Scope.All;
this.tryToClosePopup = this.tryToClosePopup.debounce(200);
@ -101,7 +101,7 @@ class PluginPopupView extends AbstractViewPopup {
}
onBuild() {
shortcuts.add('escape', '', KeyState.All, () => {
shortcuts.add('escape', '', Scope.All, () => {
if (this.modalVisibility()) {
this.tryToClosePopup();
}

View file

@ -1,4 +1,4 @@
import { KeyState } from 'Common/Enums';
import { Scope } from 'Common/Enums';
import { doc } from 'Common/Globals';
import { AbstractViewPopup } from 'Knoin/AbstractViews';
@ -10,8 +10,6 @@ class ViewOpenPgpKeyPopupView extends AbstractViewPopup {
key: '',
keyDom: null
});
this.sDefaultKeyScope = KeyState.PopupViewOpenPGP;
}
clearPopup() {
@ -38,7 +36,7 @@ class ViewOpenPgpKeyPopupView extends AbstractViewPopup {
}
onBuild() {
shortcuts.add('a', 'meta', KeyState.PopupViewOpenPGP, () => {
shortcuts.add('a', 'meta', Scope.ViewOpenPgpKey, () => {
this.selectKey();
return false;
});