Mostly aligned subscription messaging pattern

This commit is contained in:
2025-06-18 22:35:28 -05:00
parent 5c7dff5d2b
commit 53bbfe2bc7
9 changed files with 127 additions and 173 deletions

View File

@@ -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);
});
}

View File

@@ -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() {

View File

@@ -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);
}
}

View File

@@ -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);
}
}