Prefs manager TS
This commit is contained in:
@@ -13,7 +13,7 @@ import {
|
||||
Uuids,
|
||||
ComponentArea,
|
||||
ComponentAction,
|
||||
PayloadSource
|
||||
WebPrefKey
|
||||
} from 'snjs';
|
||||
import find from 'lodash/find';
|
||||
import { isDesktopApplication } from '@/utils';
|
||||
@@ -30,7 +30,6 @@ import {
|
||||
StringDeleteNote,
|
||||
StringEmptyTrash
|
||||
} from '@/strings';
|
||||
import { PrefKeys } from '@/services/preferencesManager';
|
||||
import { RawPayload } from '@/../../../../snjs/dist/@types/protocol/payloads/generator';
|
||||
import { ComponentMutator } from '@/../../../../snjs/dist/@types/models';
|
||||
|
||||
@@ -115,9 +114,9 @@ class EditorCtrl extends PureCtrl {
|
||||
onReady: () => this.reloadPreferences()
|
||||
};
|
||||
/** Used by .pug template */
|
||||
this.prefKeyMonospace = PrefKeys.EditorMonospaceEnabled;
|
||||
this.prefKeySpellcheck = PrefKeys.EditorSpellcheck;
|
||||
this.prefKeyMarginResizers = PrefKeys.EditorResizersEnabled;
|
||||
this.prefKeyMonospace = WebPrefKey.EditorMonospaceEnabled;
|
||||
this.prefKeySpellcheck = WebPrefKey.EditorSpellcheck;
|
||||
this.prefKeyMarginResizers = WebPrefKey.EditorResizersEnabled;
|
||||
|
||||
this.editorMenuOnSelect = this.editorMenuOnSelect.bind(this);
|
||||
this.onPanelResizeFinish = this.onPanelResizeFinish.bind(this);
|
||||
@@ -867,13 +866,13 @@ class EditorCtrl extends PureCtrl {
|
||||
onPanelResizeFinish(width: number, left: number, isMaxWidth: boolean) {
|
||||
if (isMaxWidth) {
|
||||
this.application.getPrefsService().setUserPrefValue(
|
||||
PrefKeys.EditorWidth,
|
||||
WebPrefKey.EditorWidth,
|
||||
null
|
||||
);
|
||||
} else {
|
||||
if (width !== undefined && width !== null) {
|
||||
this.application.getPrefsService().setUserPrefValue(
|
||||
PrefKeys.EditorWidth,
|
||||
WebPrefKey.EditorWidth,
|
||||
width
|
||||
);
|
||||
this.leftPanelPuppet!.setWidth!(width);
|
||||
@@ -881,7 +880,7 @@ class EditorCtrl extends PureCtrl {
|
||||
}
|
||||
if (left !== undefined && left !== null) {
|
||||
this.application.getPrefsService().setUserPrefValue(
|
||||
PrefKeys.EditorLeft,
|
||||
WebPrefKey.EditorLeft,
|
||||
left
|
||||
);
|
||||
this.rightPanelPuppet!.setLeft!(left);
|
||||
@@ -891,15 +890,15 @@ class EditorCtrl extends PureCtrl {
|
||||
|
||||
reloadPreferences() {
|
||||
const monospaceEnabled = this.application.getPrefsService().getValue(
|
||||
PrefKeys.EditorMonospaceEnabled,
|
||||
WebPrefKey.EditorMonospaceEnabled,
|
||||
true
|
||||
);
|
||||
const spellcheck = this.application.getPrefsService().getValue(
|
||||
PrefKeys.EditorSpellcheck,
|
||||
WebPrefKey.EditorSpellcheck,
|
||||
true
|
||||
);
|
||||
const marginResizersEnabled = this.application.getPrefsService().getValue(
|
||||
PrefKeys.EditorResizersEnabled,
|
||||
WebPrefKey.EditorResizersEnabled,
|
||||
true
|
||||
);
|
||||
this.setState({
|
||||
@@ -921,7 +920,7 @@ class EditorCtrl extends PureCtrl {
|
||||
this.rightPanelPuppet!.ready
|
||||
) {
|
||||
const width = this.application.getPrefsService().getValue(
|
||||
PrefKeys.EditorWidth,
|
||||
WebPrefKey.EditorWidth,
|
||||
null
|
||||
);
|
||||
if (width != null) {
|
||||
@@ -929,7 +928,7 @@ class EditorCtrl extends PureCtrl {
|
||||
this.rightPanelPuppet!.setWidth!(width);
|
||||
}
|
||||
const left = this.application.getPrefsService().getValue(
|
||||
PrefKeys.EditorLeft,
|
||||
WebPrefKey.EditorLeft,
|
||||
null
|
||||
);
|
||||
if (left != null) {
|
||||
@@ -957,7 +956,7 @@ class EditorCtrl extends PureCtrl {
|
||||
}
|
||||
}
|
||||
|
||||
async togglePrefKey(key: string) {
|
||||
async toggleWebPrefKey(key: string) {
|
||||
(this as any)[key] = !(this as any)[key];
|
||||
this.application.getPrefsService().setUserPrefValue(
|
||||
key,
|
||||
@@ -966,7 +965,7 @@ class EditorCtrl extends PureCtrl {
|
||||
);
|
||||
this.reloadFont();
|
||||
|
||||
if (key === PrefKeys.EditorSpellcheck) {
|
||||
if (key === WebPrefKey.EditorSpellcheck) {
|
||||
/** Allows textarea to reload */
|
||||
await this.setState({
|
||||
noteReady: false
|
||||
@@ -975,7 +974,7 @@ class EditorCtrl extends PureCtrl {
|
||||
noteReady: true
|
||||
});
|
||||
this.reloadFont();
|
||||
} else if (key === PrefKeys.EditorResizersEnabled && (this as any)[key] === true) {
|
||||
} else if (key === WebPrefKey.EditorResizersEnabled && (this as any)[key] === true) {
|
||||
this.$timeout(() => {
|
||||
this.leftPanelPuppet!.flash!();
|
||||
this.rightPanelPuppet!.flash!();
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
import { PanelPuppet, WebDirective } from './../../types';
|
||||
import angular from 'angular';
|
||||
import template from '%/notes.pug';
|
||||
import { ApplicationEvent, ContentType, removeFromArray, SNNote, SNTag } from 'snjs';
|
||||
import { ApplicationEvent, ContentType, removeFromArray, SNNote, SNTag, WebPrefKey } from 'snjs';
|
||||
import { PureCtrl } from '@Controllers/abstract/pure_ctrl';
|
||||
import { AppStateEvent } from '@/services/state';
|
||||
import { KeyboardModifier, KeyboardKey } from '@/services/keyboardManager';
|
||||
import {
|
||||
PrefKeys
|
||||
} from '@/services/preferencesManager';
|
||||
import {
|
||||
PANEL_NAME_NOTES
|
||||
} from '@/controllers/constants';
|
||||
@@ -375,7 +372,7 @@ class NotesCtrl extends PureCtrl {
|
||||
const viewOptions = {} as NotesState;
|
||||
const prevSortValue = this.getState().sortBy;
|
||||
let sortBy = this.application!.getPrefsService().getValue(
|
||||
PrefKeys.SortNotesBy,
|
||||
WebPrefKey.SortNotesBy,
|
||||
NoteSortKey.CreatedAt
|
||||
);
|
||||
if (sortBy === NoteSortKey.UpdatedAt) {
|
||||
@@ -384,27 +381,27 @@ class NotesCtrl extends PureCtrl {
|
||||
}
|
||||
viewOptions.sortBy = sortBy;
|
||||
viewOptions.sortReverse = this.application!.getPrefsService().getValue(
|
||||
PrefKeys.SortNotesReverse,
|
||||
WebPrefKey.SortNotesReverse,
|
||||
false
|
||||
);
|
||||
viewOptions.showArchived = this.application!.getPrefsService().getValue(
|
||||
PrefKeys.NotesShowArchived,
|
||||
WebPrefKey.NotesShowArchived,
|
||||
false
|
||||
);
|
||||
viewOptions.hidePinned = this.application!.getPrefsService().getValue(
|
||||
PrefKeys.NotesHidePinned,
|
||||
WebPrefKey.NotesHidePinned,
|
||||
false
|
||||
);
|
||||
viewOptions.hideNotePreview = this.application!.getPrefsService().getValue(
|
||||
PrefKeys.NotesHideNotePreview,
|
||||
WebPrefKey.NotesHideNotePreview,
|
||||
false
|
||||
);
|
||||
viewOptions.hideDate = this.application!.getPrefsService().getValue(
|
||||
PrefKeys.NotesHideDate,
|
||||
WebPrefKey.NotesHideDate,
|
||||
false
|
||||
);
|
||||
viewOptions.hideTags = this.application!.getPrefsService().getValue(
|
||||
PrefKeys.NotesHideTags,
|
||||
WebPrefKey.NotesHideTags,
|
||||
false
|
||||
);
|
||||
this.setState({
|
||||
@@ -414,7 +411,7 @@ class NotesCtrl extends PureCtrl {
|
||||
this.selectFirstNote();
|
||||
}
|
||||
const width = this.application!.getPrefsService().getValue(
|
||||
PrefKeys.NotesPanelWidth
|
||||
WebPrefKey.NotesPanelWidth
|
||||
);
|
||||
if (width && this.panelPuppet!.ready) {
|
||||
this.panelPuppet!.setWidth!(width);
|
||||
@@ -434,7 +431,7 @@ class NotesCtrl extends PureCtrl {
|
||||
isCollapsed: boolean
|
||||
) {
|
||||
this.application!.getPrefsService().setUserPrefValue(
|
||||
PrefKeys.NotesPanelWidth,
|
||||
WebPrefKey.NotesPanelWidth,
|
||||
newWidth
|
||||
);
|
||||
this.application!.getPrefsService().syncUserPreferences();
|
||||
@@ -658,7 +655,7 @@ class NotesCtrl extends PureCtrl {
|
||||
this.setShowMenuFalse();
|
||||
}
|
||||
|
||||
togglePrefKey(key: string) {
|
||||
toggleWebPrefKey(key: string) {
|
||||
this.application!.getPrefsService().setUserPrefValue(key, !this.state[key]);
|
||||
this.application!.getPrefsService().syncUserPreferences();
|
||||
}
|
||||
@@ -678,7 +675,7 @@ class NotesCtrl extends PureCtrl {
|
||||
toggleReverseSort() {
|
||||
this.selectedMenuItem();
|
||||
this.application!.getPrefsService().setUserPrefValue(
|
||||
PrefKeys.SortNotesReverse,
|
||||
WebPrefKey.SortNotesReverse,
|
||||
!this.getState().sortReverse
|
||||
);
|
||||
this.application!.getPrefsService().syncUserPreferences();
|
||||
@@ -686,7 +683,7 @@ class NotesCtrl extends PureCtrl {
|
||||
|
||||
setSortBy(type: NoteSortKey) {
|
||||
this.application!.getPrefsService().setUserPrefValue(
|
||||
PrefKeys.SortNotesBy,
|
||||
WebPrefKey.SortNotesBy,
|
||||
type
|
||||
);
|
||||
this.application!.getPrefsService().syncUserPreferences();
|
||||
|
||||
@@ -8,12 +8,12 @@ import {
|
||||
ComponentAction,
|
||||
SNSmartTag,
|
||||
ComponentArea,
|
||||
SNComponent
|
||||
SNComponent,
|
||||
WebPrefKey
|
||||
} from 'snjs';
|
||||
import template from '%/tags.pug';
|
||||
import { AppStateEvent } from '@/services/state';
|
||||
import { PANEL_NAME_TAGS } from '@/controllers/constants';
|
||||
import { PrefKeys } from '@/services/preferencesManager';
|
||||
import { STRING_DELETE_TAG } from '@/strings';
|
||||
import { PureCtrl } from '@Controllers/abstract/pure_ctrl';
|
||||
import { UuidString } from '@/../../../../snjs/dist/@types/types';
|
||||
@@ -174,7 +174,7 @@ class TagsPanelCtrl extends PureCtrl {
|
||||
if (!this.panelPuppet.ready) {
|
||||
return;
|
||||
}
|
||||
const width = this.application.getPrefsService().getValue(PrefKeys.TagsPanelWidth);
|
||||
const width = this.application.getPrefsService().getValue(WebPrefKey.TagsPanelWidth);
|
||||
if (width) {
|
||||
this.panelPuppet.setWidth!(width);
|
||||
if (this.panelPuppet.isCollapsed!()) {
|
||||
@@ -193,7 +193,7 @@ class TagsPanelCtrl extends PureCtrl {
|
||||
isCollapsed: boolean
|
||||
) => {
|
||||
this.application.getPrefsService().setUserPrefValue(
|
||||
PrefKeys.TagsPanelWidth,
|
||||
WebPrefKey.TagsPanelWidth,
|
||||
newWidth,
|
||||
true
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user