diff --git a/src/app/common/configs/keybindings.config.ts b/src/app/common/configs/keybindings.config.ts index 8df1b46..2ca8a05 100644 --- a/src/app/common/configs/keybindings.config.ts +++ b/src/app/common/configs/keybindings.config.ts @@ -45,11 +45,11 @@ export const Keybindings: Array<{}> = [ bindKey: {win: "ctrl-shift-s", mac: "ctrl-shift-s"}, readOnly: false }, { - name: "selectSessionLeft", + name: "selectLeftEditor", bindKey: {win: "ctrl-pageup", mac: "ctrl-pageup"}, readOnly: false }, { - name: "selectSessionRight", + name: "selectRightEditor", bindKey: {win: "ctrl-pagedown", mac: "ctrl-pagedown"}, readOnly: false }, { diff --git a/src/app/common/services/editor/editors.service.ts b/src/app/common/services/editor/editors.service.ts index b0e14ca..22f398e 100644 --- a/src/app/common/services/editor/editors.service.ts +++ b/src/app/common/services/editor/editors.service.ts @@ -13,13 +13,6 @@ import { EditorSettings } from "../../configs/editor.config"; }) export class EditorsService { private messageSubject: ReplaySubject = new ReplaySubject(1); - private activationSubject: ReplaySubject = new ReplaySubject(1); - private switchSessionSubject: ReplaySubject = new ReplaySubject(1); - private closeTabSubject: ReplaySubject = new ReplaySubject(1); - private selectSessionLeftSubject: ReplaySubject = new ReplaySubject(1); - private selectSessionRightSubject: ReplaySubject = new ReplaySubject(1); - private moveSessionLeftSubject: ReplaySubject = new ReplaySubject(1); - private moveSessionRightSubject: ReplaySubject = new ReplaySubject(1); editors: Map>; editorSettings: typeof EditorSettings; @@ -44,68 +37,12 @@ export class EditorsService { } - setData(data: ServiceMessage): void { + sendMessage(data: ServiceMessage): void { this.messageSubject.next(data); } - getData$(): Observable { + getMessage$(): Observable { return this.messageSubject.asObservable(); } - setActiveEditor(data: string): void { - this.activationSubject.next(data); - } - - newActiveEditor$(): Observable { - return this.activationSubject.asObservable(); - } - - setTabToEditor(data: string): void { - this.switchSessionSubject.next(data); - } - - loadTabToEditor$(): Observable { - return this.switchSessionSubject.asObservable(); - } - - closeTab(data: string): void { - this.closeTabSubject.next(data); - } - - closeTabRequested$(): Observable { - return this.closeTabSubject.asObservable(); - } - - moveSessionLeft(data: string): void { - this.moveSessionLeftSubject.next(data); - } - - moveSessionLeftRequested$(): Observable { - return this.moveSessionLeftSubject.asObservable(); - } - - moveSessionRight(data: string): void { - this.moveSessionRightSubject.next(data); - } - - moveSessionRightRequested$(): Observable { - return this.moveSessionRightSubject.asObservable(); - } - - selectSessionLeft(data: string): void { - this.selectSessionLeftSubject.next(data); - } - - selectSessionLeftRequested$(): Observable { - return this.selectSessionLeftSubject.asObservable(); - } - - selectSessionRight(data: string): void { - this.selectSessionRightSubject.next(data); - } - - selectSessionRightRequested$(): Observable { - return this.selectSessionRightSubject.asObservable(); - } - } \ No newline at end of file diff --git a/src/app/common/services/editor/files.service.ts b/src/app/common/services/editor/files.service.ts index e0b242d..6af20f9 100644 --- a/src/app/common/services/editor/files.service.ts +++ b/src/app/common/services/editor/files.service.ts @@ -77,13 +77,13 @@ export class FilesService { } async addTab(file: NewtonFile) { - let message = new ServiceMessage(); - message.action = "create-tab"; - message.message = file.fname; - message.uuid = file.hash; - message.data = file.path; + let message = new ServiceMessage(); + message.action = "create-tab"; + message.fileName = file.fname; + message.fileUUID = file.hash; + message.filePath = file.path; - this.tabsService.setData(message); + this.tabsService.sendMessage(message); } diff --git a/src/app/common/services/editor/tabs/tabs.service.ts b/src/app/common/services/editor/tabs/tabs.service.ts index e26a214..26a118d 100644 --- a/src/app/common/services/editor/tabs/tabs.service.ts +++ b/src/app/common/services/editor/tabs/tabs.service.ts @@ -8,15 +8,16 @@ import { ServiceMessage } from '../../../types/service-message.type'; providedIn: 'root' }) export class TabsService { - private dataSubject: ReplaySubject = new ReplaySubject(1); + private messageSubject: ReplaySubject = new ReplaySubject(1); constructor() {} - setData(data: ServiceMessage): void { - this.dataSubject.next(data); + + sendMessage(data: ServiceMessage): void { + this.messageSubject.next(data); } - getData$(): Observable { - return this.dataSubject.asObservable(); + getMessage$(): Observable { + return this.messageSubject.asObservable(); } } \ No newline at end of file diff --git a/src/app/common/types/service-message.type.ts b/src/app/common/types/service-message.type.ts index b37d4ff..5a23be8 100644 --- a/src/app/common/types/service-message.type.ts +++ b/src/app/common/types/service-message.type.ts @@ -1,6 +1,9 @@ export class ServiceMessage { - action: string = "none"; + action: string = ""; message: string = ""; - uuid!: string; - data: any; + editorUUID: string; + fileName: string; + fileUUID: string; + filePath: string; + rawData: any; } \ No newline at end of file diff --git a/src/app/editor/editors.component.ts b/src/app/editor/editors.component.ts index fe80962..2aec7d5 100644 --- a/src/app/editor/editors.component.ts +++ b/src/app/editor/editors.component.ts @@ -54,87 +54,66 @@ export class EditorsComponent { loadSubscribers() { - this.editorsService.selectSessionLeftRequested$().pipe( + this.editorsService.getMessage$().pipe( takeUntil(this.unsubscribe) - ).subscribe((uuid: string) => { - let editorComponent = this.editorsService.get(uuid); - if (!editorComponent.leftSiblingUUID) return; - let siblingComponent = this.editorsService.get(editorComponent.leftSiblingUUID); - siblingComponent.editor.focus() - }); + ).subscribe((message: ServiceMessage) => { + if (message.action == "select-left-editor") { + let editorComponent = this.editorsService.get(message.editorUUID); + if (!editorComponent.leftSiblingUUID) return; + let siblingComponent = this.editorsService.get(editorComponent.leftSiblingUUID); + siblingComponent.editor.focus() + } else if (message.action == "select-right-editor") { + let editorComponent = this.editorsService.get(message.editorUUID); + if (!editorComponent.rightSiblingUUID) return; + let siblingComponent = this.editorsService.get(editorComponent.rightSiblingUUID); + siblingComponent.editor.focus() + } else if (message.action == "move-session-left") { + let editorComponent = this.editorsService.get(message.editorUUID); + if (!editorComponent.leftSiblingUUID) return; + let siblingComponent = this.editorsService.get(editorComponent.leftSiblingUUID); + let session = editorComponent.editor.getSession(); + let siblingSession = siblingComponent.editor.getSession(); - this.editorsService.selectSessionRightRequested$().pipe( - takeUntil(this.unsubscribe) - ).subscribe((uuid: string) => { - let editorComponent = this.editorsService.get(uuid); - if (!editorComponent.rightSiblingUUID) return; - let siblingComponent = this.editorsService.get(editorComponent.rightSiblingUUID); - siblingComponent.editor.focus() - }); + if (session == siblingSession) return; + siblingComponent.editor.setSession(session); + editorComponent.newBuffer(); + siblingComponent.editor.focus() + } else if (message.action == "move-session-right") { + let editorComponent = this.editorsService.get(message.editorUUID); + if (!editorComponent.rightSiblingUUID) return; + let siblingComponent = this.editorsService.get(editorComponent.rightSiblingUUID); + let session = editorComponent.editor.getSession(); + let siblingSession = siblingComponent.editor.getSession(); - this.editorsService.moveSessionLeftRequested$().pipe( - takeUntil(this.unsubscribe) - ).subscribe((uuid: string) => { - let editorComponent = this.editorsService.get(uuid); - if (!editorComponent.leftSiblingUUID) return; - let siblingComponent = this.editorsService.get(editorComponent.leftSiblingUUID); - let session = editorComponent.editor.getSession(); - let siblingSession = siblingComponent.editor.getSession(); + if (session == siblingSession) return; + siblingComponent.editor.setSession(session); + editorComponent.newBuffer(); + siblingComponent.editor.focus() + } else if (message.action == "set-active-editor") { + this.editorsService.get(this.activeEditor).removeActiveStyling(); + this.activeEditor = message.editorUUID; + this.editorsService.get(this.activeEditor).addActiveStyling(); + } else if (message.action == "set-tab-to-editor") { + let file = this.filesService.get(message.filePath); + let editorComponent = this.getActiveEditorComponent(); + let editor = editorComponent.editor; - if (session == siblingSession) return; - siblingComponent.editor.setSession(session); - editorComponent.newBuffer(); - siblingComponent.editor.focus() - }); + editorComponent.activeFile = file; + editor.setSession(file.session); + } else if (message.action == "close-tab") { + let file = this.filesService.get(message.filePath); + let editors = this.editorsService.getEditorsAsArray(); - this.editorsService.moveSessionRightRequested$().pipe( - takeUntil(this.unsubscribe) - ).subscribe((uuid: string) => { - let editorComponent = this.editorsService.get(uuid); - if (!editorComponent.rightSiblingUUID) return; - let siblingComponent = this.editorsService.get(editorComponent.rightSiblingUUID); - let session = editorComponent.editor.getSession(); - let siblingSession = siblingComponent.editor.getSession(); - - if (session == siblingSession) return; - siblingComponent.editor.setSession(session); - editorComponent.newBuffer(); - siblingComponent.editor.focus() - }); - - this.editorsService.newActiveEditor$().pipe( - takeUntil(this.unsubscribe) - ).subscribe((uuid: string) => { - this.editorsService.get(this.activeEditor).removeActiveStyling(); - this.activeEditor = uuid; - this.editorsService.get(this.activeEditor).addActiveStyling(); - }); - - this.editorsService.loadTabToEditor$().pipe( - takeUntil(this.unsubscribe) - ).subscribe((path: string) => { - let file = this.filesService.get(path); - let editorComponent = this.getActiveEditorComponent(); - let editor = editorComponent.editor; - - editorComponent.activeFile = file; - editor.setSession(file.session); - }); - - this.editorsService.closeTabRequested$().pipe( - takeUntil(this.unsubscribe) - ).subscribe((path: string) => { - let file = this.filesService.get(path); - let editors = this.editorsService.getEditorsAsArray(); - - for (let i = 0; i < editors.length; i++) { - let editorComponent = editors[i].instance; - if (editorComponent.editor.session == file.session) { - editorComponent.newBuffer(); + for (let i = 0; i < editors.length; i++) { + let editorComponent = editors[i].instance; + if (editorComponent.editor.session == file.session) { + editorComponent.newBuffer(); + } } + + this.filesService.delete(file); } - this.filesService.delete(file); }); } diff --git a/src/app/editor/modals/files-modal.component.ts b/src/app/editor/modals/files-modal.component.ts index 358aa10..9ef0190 100644 --- a/src/app/editor/modals/files-modal.component.ts +++ b/src/app/editor/modals/files-modal.component.ts @@ -43,11 +43,11 @@ export class FilesModalComponent { } loadSubscribers() { - this.tabsService.getData$().pipe( + this.tabsService.getMessage$().pipe( takeUntil(this.unsubscribe) ).subscribe((data: ServiceMessage) => { if (data.action === "create-tab") { - this.createFileRow(data.message, data.uuid, data.data); + this.createFileRow(data.fileName, data.fileUUID, data.filePath); } }); @@ -71,7 +71,7 @@ export class FilesModalComponent { } private createFileRow(title: string, uuid: string, path: string): void { - this.files.push({title: title, path: path, uuid: uuid}) + this.files.push({title: title, uuid: uuid, path: path}) } createModal() { diff --git a/src/app/editor/newton-editor/newton-editor.component.ts b/src/app/editor/newton-editor/newton-editor.component.ts index 08cc388..d7505a4 100644 --- a/src/app/editor/newton-editor/newton-editor.component.ts +++ b/src/app/editor/newton-editor/newton-editor.component.ts @@ -16,6 +16,8 @@ import { EditorsService } from '../../common/services/editor/editors.service'; import { NewtonEditorBase } from './newton-editor.base'; +import { ServiceMessage } from '../../common/types/service-message.type'; + @Component({ @@ -115,7 +117,11 @@ export class NewtonEditorComponent extends NewtonEditorBase { }); this.editor.on("focus", () => { - this.editorsService.setActiveEditor(this.uuid); + let message = new ServiceMessage(); + message.action = "set-active-editor"; + message.editorUUID = this.uuid; + + this.editorsService.sendMessage(message); }); this.editor.on("changeSession", (session) => { @@ -141,20 +147,36 @@ export class NewtonEditorComponent extends NewtonEditorBase { this.updateInfoBar(); } - public selectSessionLeft() { - this.editorsService.selectSessionLeft(this.uuid); + public selectLeftEditor() { + let message = new ServiceMessage(); + message.action = "select-left-editor"; + message.editorUUID = this.uuid; + + this.editorsService.sendMessage(message); } - public selectSessionRight() { - this.editorsService.selectSessionRight(this.uuid); + public selectRightEditor() { + let message = new ServiceMessage(); + message.action = "select-right-editor"; + message.editorUUID = this.uuid; + + this.editorsService.sendMessage(message); } public moveSessionLeft() { - this.editorsService.moveSessionLeft(this.uuid); + let message = new ServiceMessage(); + message.action = "move-session-left"; + message.editorUUID = this.uuid; + + this.editorsService.sendMessage(message); } public moveSessionRight() { - this.editorsService.moveSessionRight(this.uuid); + let message = new ServiceMessage(); + message.action = "move-session-right"; + message.editorUUID = this.uuid; + + this.editorsService.sendMessage(message); } } \ No newline at end of file diff --git a/src/app/editor/tabs/tabs.component.ts b/src/app/editor/tabs/tabs.component.ts index 4679c43..9cf8f51 100644 --- a/src/app/editor/tabs/tabs.component.ts +++ b/src/app/editor/tabs/tabs.component.ts @@ -40,11 +40,11 @@ export class TabsComponent { } public ngAfterViewInit(): void { - this.tabsService.getData$().pipe( + this.tabsService.getMessage$().pipe( takeUntil(this.unsubscribe) ).subscribe((data: ServiceMessage) => { if (data.action === "create-tab") { - this.createTab(data.message, data.uuid, data.data); + this.createTab(data.fileName, data.fileUUID, data.filePath); } }); } @@ -55,7 +55,7 @@ export class TabsComponent { } private createTab(title: string, uuid: string, path: string): void { - this.tabs.push({title: title, path: path, uuid: uuid}); + this.tabs.push({title: title, uuid: uuid, path: path}); this.changeDetectorRef.detectChanges(); } @@ -63,11 +63,14 @@ export class TabsComponent { let target = event.target; if ( target.classList.contains("tab") ) { - this.editorsService.setTabToEditor( + this.sendEditorsServiceAMessage( + "set-tab-to-editor", event.srcElement.getAttribute("title") ); + } else if ( target.classList.contains("title") ) { - this.editorsService.setTabToEditor( + this.sendEditorsServiceAMessage( + "set-tab-to-editor", event.srcElement.parentElement.getAttribute("title") ); } else if ( target.classList.contains("close-button") ) { @@ -79,7 +82,7 @@ export class TabsComponent { } closeTab(fpath: string): void { - this.editorsService.closeTab(fpath); + this.sendEditorsServiceAMessage("close-tab", fpath); for (let i = 0; i < this.tabs.length; i++) { if (this.tabs[i].path == fpath) { @@ -94,9 +97,9 @@ export class TabsComponent { let target = event.event.target; let fpath = ""; - if ( target.classList.contains("title") ) { - fpath = target.parentElement.getAttribute("title") - } else if ( target.classList.contains("close-button") ) { + if ( target.classList.contains("title") || + target.classList.contains("close-button") + ) { fpath = target.parentElement.getAttribute("title") } else ( fpath = target.getAttribute("title") @@ -120,4 +123,13 @@ export class TabsComponent { // moveItemInArray(this.tabs, event.previousIndex, event.currentIndex); } + + private sendEditorsServiceAMessage(action: string, fpath: string) { + let message = new ServiceMessage(); + message.action = action; + message.filePath = fpath; + + this.editorsService.sendMessage(message); + } + } \ No newline at end of file