chore: rename editor model to note controller

This commit is contained in:
Mo
2021-12-27 18:46:56 -06:00
parent 54e5fc9184
commit 15aea42d4f
12 changed files with 184 additions and 182 deletions

View File

@@ -2,7 +2,7 @@ import { Bridge } from '@/services/bridge';
import { storage, StorageKey } from '@/services/localStorage';
import { WebApplication } from '@/ui_models/application';
import { AccountMenuState } from '@/ui_models/app_state/account_menu_state';
import { Editor } from '@/ui_models/editor';
import { NoteController } from '@/ui_models/note_controller';
import { isDesktopApplication } from '@/utils';
import {
ApplicationEvent,
@@ -226,9 +226,9 @@ export class AppState {
storage.set(StorageKey.ShowBetaWarning, true);
}
async createEditor(title?: string) {
async openNewNote(title?: string) {
if (!this.multiEditorSupport) {
this.closeActiveEditor();
this.closeActiveNoteController();
}
const activeTagUuid = this.selectedTag
? this.selectedTag.isSmartTag
@@ -236,37 +236,37 @@ export class AppState {
: this.selectedTag.uuid
: undefined;
await this.application.editorGroup.createEditor(
await this.application.noteControllerGroup.createNoteController(
undefined,
title,
activeTagUuid
);
}
getActiveEditor() {
return this.application.editorGroup.editors[0];
getActiveNoteController() {
return this.application.noteControllerGroup.noteControllers[0];
}
getEditors() {
return this.application.editorGroup.editors;
getNoteControllers() {
return this.application.noteControllerGroup.noteControllers;
}
closeEditor(editor: Editor) {
this.application.editorGroup.closeEditor(editor);
closeNoteController(controller: NoteController) {
this.application.noteControllerGroup.closeController(controller);
}
closeActiveEditor() {
this.application.editorGroup.closeActiveEditor();
closeActiveNoteController() {
this.application.noteControllerGroup.closeActiveController();
}
closeAllEditors() {
this.application.editorGroup.closeAllEditors();
closeAllNoteControllers() {
this.application.noteControllerGroup.closeAllControllers();
}
editorForNote(note: SNNote) {
for (const editor of this.getEditors()) {
if (editor.note.uuid === note.uuid) {
return editor;
noteControllerForNote(note: SNNote) {
for (const controller of this.getNoteControllers()) {
if (controller.note.uuid === note.uuid) {
return controller;
}
}
}
@@ -275,31 +275,31 @@ export class AppState {
this.application.streamItems(
[ContentType.Note, ContentType.Tag],
async (items, source) => {
/** Close any editors for deleted/trashed/archived notes */
/** Close any note controllers for deleted/trashed/archived notes */
if (source === PayloadSource.PreSyncSave) {
const notes = items.filter(
(candidate) => candidate.content_type === ContentType.Note
) as SNNote[];
for (const note of notes) {
const editor = this.editorForNote(note);
if (!editor) {
const noteController = this.noteControllerForNote(note);
if (!noteController) {
continue;
}
if (note.deleted) {
this.closeEditor(editor);
this.closeNoteController(noteController);
} else if (
note.trashed &&
!this.selectedTag?.isTrashTag &&
!this.searchOptions.includeTrashed
) {
this.closeEditor(editor);
this.closeNoteController(noteController);
} else if (
note.archived &&
!this.selectedTag?.isArchiveTag &&
!this.searchOptions.includeArchived &&
!this.application.getPreference(PrefKey.NotesShowArchived, false)
) {
this.closeEditor(editor);
this.closeNoteController(noteController);
}
}
}

View File

@@ -48,7 +48,7 @@ export class NoteTagsState {
}
get activeNote(): SNNote | undefined {
return this.appState.notes.activeEditor?.note;
return this.appState.notes.activeNoteController?.note;
}
get autocompleteTagHintVisible(): boolean {

View File

@@ -17,7 +17,7 @@ import {
runInAction,
} from 'mobx';
import { WebApplication } from '../application';
import { Editor } from '../editor';
import { NoteController } from '../note_controller';
import { AppState } from './app_state';
export class NotesState {
@@ -68,8 +68,8 @@ export class NotesState {
);
}
get activeEditor(): Editor | undefined {
return this.application.editorGroup.editors[0];
get activeNoteController(): NoteController | undefined {
return this.application.noteControllerGroup.noteControllers[0];
}
get selectedNotesCount(): number {
@@ -151,13 +151,13 @@ export class NotesState {
}
if (this.selectedNotesCount === 1) {
await this.openEditor(Object.keys(this.selectedNotes)[0]);
await this.openNote(Object.keys(this.selectedNotes)[0]);
}
}
}
private async openEditor(noteUuid: string): Promise<void> {
if (this.activeEditor?.note?.uuid === noteUuid) {
private async openNote(noteUuid: string): Promise<void> {
if (this.activeNoteController?.note?.uuid === noteUuid) {
return;
}
@@ -167,11 +167,11 @@ export class NotesState {
return;
}
if (this.activeEditor) {
this.application.editorGroup.closeActiveEditor();
if (this.activeNoteController) {
this.application.noteControllerGroup.closeActiveController();
}
await this.application.editorGroup.createEditor(noteUuid);
await this.application.noteControllerGroup.createNoteController(noteUuid);
this.appState.noteTags.reloadTags();
await this.onActiveEditorChanged();

View File

@@ -70,7 +70,7 @@ export class NotesViewState {
appObservers.push(
application.streamItems(ContentType.Note, () => {
this.reloadNotes();
const activeNote = this.appState.notes.activeEditor?.note;
const activeNote = this.appState.notes.activeNoteController?.note;
if (this.application.getAppState().notes.selectedNotesCount < 2) {
if (activeNote) {
const discarded = activeNote.deleted || activeNote.trashed;
@@ -102,7 +102,7 @@ export class NotesViewState {
this.reloadPreferences();
}, ApplicationEvent.PreferencesChanged),
application.addEventObserver(async () => {
this.appState.closeAllEditors();
this.appState.closeAllNoteControllers();
this.selectFirstNote();
this.setCompletedFullSync(false);
}, ApplicationEvent.SignedIn),
@@ -112,7 +112,7 @@ export class NotesViewState {
this.notes.length === 0 &&
this.appState.selectedTag?.isAllTag &&
this.noteFilterText === '' &&
!this.appState.notes.activeEditor
!this.appState.notes.activeNoteController
) {
this.createPlaceholderNote();
}
@@ -192,7 +192,7 @@ export class NotesViewState {
}
get activeEditorNote() {
return this.appState.notes.activeEditor?.note;
return this.appState.notes.activeNoteController?.note;
}
reloadPanelTitle = () => {
@@ -325,7 +325,7 @@ export class NotesViewState {
if (this.isFiltering) {
title = this.noteFilterText;
}
await this.appState.createEditor(title);
await this.appState.openNewNote(title);
this.reloadNotes();
this.appState.noteTags.reloadTags();
};
@@ -433,7 +433,7 @@ export class NotesViewState {
if (note) {
this.selectNote(note, false, false);
} else {
this.appState.closeActiveEditor();
this.appState.closeActiveNoteController();
}
};
@@ -464,7 +464,7 @@ export class NotesViewState {
};
handleEditorChange = async () => {
const activeNote = this.appState.getActiveEditor()?.note;
const activeNote = this.appState.getActiveNoteController()?.note;
if (activeNote && activeNote.conflictOf) {
this.application.changeAndSaveItem(activeNote.uuid, (mutator) => {
mutator.conflictOf = undefined;
@@ -502,7 +502,7 @@ export class NotesViewState {
this.activeEditorNote &&
!this.notes.includes(this.activeEditorNote)
) {
this.appState.closeActiveEditor();
this.appState.closeActiveNoteController();
}
}
};